Skip to content

Commit

Permalink
Added an option to select the system priority when a ROM supports bot…
Browse files Browse the repository at this point in the history
…h DMG and GBC modes.
  • Loading branch information
hi-ban committed Jan 15, 2020
1 parent 16f13f2 commit 034ecc6
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 28 deletions.
6 changes: 5 additions & 1 deletion dist/gcw0/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Here is a list of the available config options:
Shows or hides the FPS counter.
Default is "Off".

- Select Scaler:
- Scaler:
Allows to select between a range of scalers.
Default is "No Scaling".

Expand All @@ -74,6 +74,10 @@ Here is a list of the available config options:
with the same name as the ROM file, and it
will load the default border if it fails.

- System:
Allows to select the system priority when
a ROM supports both DMG and GBC modes.

- Boot Logos:
Allows to use GB/GBC BIOS files to display
the splashscreen logo when loading a game.
Expand Down
6 changes: 5 additions & 1 deletion dist/retrofw/gambatte.man.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Here is a list of the available config options:
Shows or hides the FPS counter.
Default is "Off".

- Select Scaler:
- Scaler:
Allows to select between a range of scalers.
Default is "No Scaling".

Expand All @@ -74,6 +74,10 @@ Here is a list of the available config options:
with the same name as the ROM file, and it
will load the default border if it fails.

- System:
Allows to select the system priority when
a ROM supports both DMG and GBC modes.

- Boot Logos:
Allows to use GB/GBC BIOS files to display
the splashscreen logo when loading a game.
Expand Down
2 changes: 1 addition & 1 deletion gambatte_sdl/builddate.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILDDATE "20200111-133838"
#define BUILDDATE "20200115-012225"
7 changes: 6 additions & 1 deletion gambatte_sdl/libmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Mix_Chunk *menusound_move = NULL;
Mix_Chunk *menusound_ok = NULL;

// Default config values
int selectedscaler = 0, showfps = 0, ghosting = 1, biosenabled = 0, colorfilter = 0, gameiscgb = 0, buttonlayout = 0, stereosound = 0;
int selectedscaler = 0, showfps = 0, ghosting = 1, biosenabled = 0, colorfilter = 0, gameiscgb = 0, buttonlayout = 0, stereosound = 0, prefercgb = 0;
uint32_t menupalblack = 0x000000, menupaldark = 0x505450, menupallight = 0xA8A8A8, menupalwhite = 0xF8FCF8;
int filtervalue[12] = {135, 20, 0, 25, 0, 125, 20, 25, 0, 20, 105, 30};
std::string dmgbordername = "DEFAULT", gbcbordername = "DEFAULT", palname = "DEFAULT", filtername = "NONE", currgamename = "default";
Expand Down Expand Up @@ -2026,6 +2026,7 @@ void saveConfig(int pergame){
"FILTERNAME %s\n"
"DMGBORDERNAME %s\n"
"GBCBORDERNAME %s\n"
"PREFERCGB %d\n"
"BIOSENABLED %d\n"
"GHOSTING %d\n"
"BUTTONLAYOUT %d\n"
Expand All @@ -2036,6 +2037,7 @@ void saveConfig(int pergame){
filtername.c_str(),
dmgbordername.c_str(),
gbcbordername.c_str(),
prefercgb,
biosenabled,
ghosting,
buttonlayout,
Expand Down Expand Up @@ -2129,6 +2131,9 @@ void loadConfig(){
}
strcpy(charvalue, arg);
gbcbordername = std::string(charvalue);
} else if (!strcmp(line, "PREFERCGB")) {
sscanf(arg, "%d", &value);
prefercgb = value;
} else if (!strcmp(line, "BIOSENABLED")) {
sscanf(arg, "%d", &value);
biosenabled = value;
Expand Down
2 changes: 1 addition & 1 deletion gambatte_sdl/libmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extern SDL_Surface *menuscreen;
extern SDL_Surface *surface_menuinout;
extern SDL_Surface *textoverlay;
extern SDL_Surface *textoverlaycolored;
extern int selectedscaler, showfps, ghosting, biosenabled, colorfilter, gameiscgb, buttonlayout, stereosound;
extern int selectedscaler, showfps, ghosting, biosenabled, colorfilter, gameiscgb, buttonlayout, stereosound, prefercgb;
extern uint32_t menupalblack, menupaldark, menupallight, menupalwhite;
extern int filtervalue[12];
extern std::string dmgbordername, gbcbordername, palname, filtername, currgamename, homedir, ipuscaling;
Expand Down
65 changes: 55 additions & 10 deletions gambatte_sdl/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,14 @@ static void callback_selecteddmggame(menu_t *caller_menu) {
playMenuSound_ok();
SDL_Delay(250);
gamename = gamelist[caller_menu->selected_entry]->d_name;
currgamename = strip_Extension(gamename);
loadConfig();
std::string fullgamepath = (gamedir + "/gb/");
fullgamepath += (gamename);
if (gambatte_p->load(fullgamepath.c_str(),0 + 0 + 0) < 0) {
if (gambatte_p->load(fullgamepath.c_str(),0 + 0 + 0, prefercgb) < 0) {
printf("failed to load ROM: %s\n", fullgamepath.c_str());
} else {
currgamename = strip_Extension(gamename);
clearAllCheats(); //clear all cheatcodes from menus
loadConfig();
if(gambatte_p->isCgb()){
gameiscgb = 1;
loadFilter(filtername);
Expand Down Expand Up @@ -551,14 +551,14 @@ static void callback_selectedgbcgame(menu_t *caller_menu) {
playMenuSound_ok();
SDL_Delay(250);
gamename = gamelist[caller_menu->selected_entry]->d_name;
currgamename = strip_Extension(gamename);
loadConfig();
std::string fullgamepath = (gamedir + "/gbc/");
fullgamepath += (gamename);
if (gambatte_p->load(fullgamepath.c_str(),0 + 0 + 0) < 0) {
if (gambatte_p->load(fullgamepath.c_str(),0 + 0 + 0, prefercgb) < 0) {
printf("failed to load ROM: %s\n", fullgamepath.c_str());
} else {
currgamename = strip_Extension(gamename);
clearAllCheats(); //clear all cheatcodes from menus
loadConfig();
if(gambatte_p->isCgb()){
gameiscgb = 1;
loadFilter(filtername);
Expand Down Expand Up @@ -719,6 +719,7 @@ static void callback_dmgpalette(menu_t *caller_menu);
static void callback_colorfilter(menu_t *caller_menu);
static void callback_dmgborderimage(menu_t *caller_menu);
static void callback_gbcborderimage(menu_t *caller_menu);
static void callback_system(menu_t *caller_menu);
static void callback_usebios(menu_t *caller_menu);
static void callback_ghosting(menu_t *caller_menu);
static void callback_buttonlayout(menu_t *caller_menu);
Expand Down Expand Up @@ -746,7 +747,7 @@ static void callback_settings(menu_t *caller_menu) {
menu_entry->callback = callback_showfps;

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "Select Scaler");
menu_entry_set_text(menu_entry, "Scaler");
menu_add_entry(menu, menu_entry);
menu_entry->callback = callback_scaler;

Expand All @@ -772,6 +773,11 @@ static void callback_settings(menu_t *caller_menu) {
menu_entry->callback = callback_gbcborderimage;
}

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "System");
menu_add_entry(menu, menu_entry);
menu_entry->callback = callback_system;

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "Boot logos");
menu_add_entry(menu, menu_entry);
Expand All @@ -798,7 +804,7 @@ static void callback_settings(menu_t *caller_menu) {
menu_entry->selectable = 0;

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "Save global settings");
menu_entry_set_text(menu_entry, "Save as default");
menu_add_entry(menu, menu_entry);
menu_entry->callback = callback_saveconfig_confirm;

Expand Down Expand Up @@ -832,7 +838,7 @@ static void callback_saveconfig_confirm(menu_t *caller_menu) {
menu->back_callback = callback_back;

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "Save global");
menu_entry_set_text(menu_entry, "Save default");
menu_add_entry(menu, menu_entry);
menu_entry->selectable = 0;
menu_entry->callback = callback_saveconfig_apply;
Expand Down Expand Up @@ -1141,7 +1147,7 @@ static void callback_scaler(menu_t *caller_menu) {
menu = new_menu();

menu_set_header(menu, menu_main_title.c_str());
menu_set_title(menu, "Select Scaler");
menu_set_title(menu, "Scaler");
menu->back_callback = callback_back;

menu_entry = new_menu_entry(0);
Expand Down Expand Up @@ -1651,6 +1657,45 @@ static void callback_selectedgbcborder(menu_t *caller_menu) {
}
}

/* ==================== SYSTEM MENU =========================== */

static void callback_selectedsystem(menu_t *caller_menu);

static void callback_system(menu_t *caller_menu) {

menu_t *menu;
menu_entry_t *menu_entry;
(void) caller_menu;
menu = new_menu();

menu_set_header(menu, menu_main_title.c_str());
menu_set_title(menu, "System");
menu->back_callback = callback_back;

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "Priority DMG");
menu_add_entry(menu, menu_entry);
menu_entry->callback = callback_selectedsystem;

menu_entry = new_menu_entry(0);
menu_entry_set_text(menu_entry, "Priority GBC");
menu_add_entry(menu, menu_entry);
menu_entry->callback = callback_selectedsystem;

menu->selected_entry = prefercgb;

playMenuSound_in();
menu_main(menu);

delete_menu(menu);
}

static void callback_selectedsystem(menu_t *caller_menu) {
playMenuSound_ok();
prefercgb = caller_menu->selected_entry;
caller_menu->quit = 1;
}

/* ==================== BOOT LOGOS MENU =========================== */

static void callback_selectedbios(menu_t *caller_menu);
Expand Down
5 changes: 3 additions & 2 deletions gambatte_sdl/src/gambatte_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ int GambatteSdl::exec(int const argc, char const *const argv[]) {
}
}

loadConfig(); // load config.cfg file on startup
loadConfig(); // load default.cfg file on startup

for (std::size_t i = 0; i < inputOption.numMappings(); ++i) {
std::pair<InputId, InputGetter::Button> m;
Expand Down Expand Up @@ -916,7 +916,8 @@ int GambatteSdl::exec(int const argc, char const *const argv[]) {
gambatte.load(argv[loadIndex],
gbaCgbOption.isSet() * GB::GBA_CGB
+ forceDmgOption.isSet() * GB::FORCE_DMG
+ multicartCompatOption.isSet() * GB::MULTICART_COMPAT)) {
+ multicartCompatOption.isSet() * GB::MULTICART_COMPAT,
prefercgb)) {
std::printf("failed to load ROM %s: %s\n", argv[loadIndex], to_string(error).c_str());
return EXIT_FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion libgambatte/include/gambatte.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GB {
* @param flags ORed combination of LoadFlags.
* @return 0 on success, negative value on failure.
*/
LoadRes load(std::string const &romfile, unsigned flags = 0);
LoadRes load(std::string const &romfile, unsigned flags = 0, int preferCGB = 0);

/**
* Emulates until at least 'samples' audio samples are produced in the
Expand Down
4 changes: 2 additions & 2 deletions libgambatte/src/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class CPU {
mem_.setOsdElement(osdElement);
}

LoadRes load(std::string const &romfile, bool forceDmg, bool multicartCompat) {
return mem_.loadROM(romfile, forceDmg, multicartCompat);
LoadRes load(std::string const &romfile, bool forceDmg, bool multicartCompat, int preferCGB) {
return mem_.loadROM(romfile, forceDmg, multicartCompat, preferCGB);
}

bool loaded() const { return mem_.loaded(); }
Expand Down
5 changes: 3 additions & 2 deletions libgambatte/src/gambatte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ void GB::setSaveDir(std::string const &sdir) {
p_->cpu.setSaveDir(sdir);
}

LoadRes GB::load(std::string const &romfile, unsigned const flags) {
LoadRes GB::load(std::string const &romfile, unsigned const flags, int const preferCGB) {
if (p_->cpu.loaded())
p_->cpu.saveSavedata();

LoadRes const loadres = p_->cpu.load(romfile,
flags & FORCE_DMG,
flags & MULTICART_COMPAT);
flags & MULTICART_COMPAT,
preferCGB);
if (loadres == LOADRES_OK) {
//SaveState state;
//p_->cpu.setStatePtrs(state);
Expand Down
26 changes: 24 additions & 2 deletions libgambatte/src/mem/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ static bool presumedMulti64Mbc1(unsigned char const header[], unsigned rombanks)

LoadRes Cartridge::loadROM(std::string const &romfile,
bool const forceDmg,
bool const multicartCompat)
bool const multicartCompat,
int const preferCGB)
{
scoped_ptr<File> const rom(newFileInstance(romfile));
if (rom->fail())
Expand Down Expand Up @@ -608,7 +609,28 @@ LoadRes Cartridge::loadROM(std::string const &romfile,
}*/

rambanks = numRambanksFromH14x(header[0x147], header[0x149]);
cgb = header[0x0143] >> 7 & (1 ^ forceDmg);

switch (header[0x0143]) {
case 0x80://Game is CGB/DMG compatible.
printf("CART TYPE: GBC/DMG\n");
if (preferCGB == 1) {
cgb = true;
} else {
cgb = false;
}
break;
case 0xC0://Game is CGB only.
printf("CART TYPE: GBC\n");
cgb = true;
break;
default://Game is DMG.
printf("CART TYPE: DMG\n");
cgb = false;
break;
}
if(forceDmg){
cgb = false;
}
}

std::size_t const filesize = rom->size();
Expand Down
2 changes: 1 addition & 1 deletion libgambatte/src/mem/cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Cartridge {
void saveSavedata();
std::string const saveBasePath() const;
void setSaveDir(std::string const &dir);
LoadRes loadROM(std::string const &romfile, bool forceDmg, bool multicartCompat);
LoadRes loadROM(std::string const &romfile, bool forceDmg, bool multicartCompat, int preferCGB);
char const * romTitle() const { return reinterpret_cast<char const *>(memptrs_.romdata() + 0x134); }
class PakInfo const pakInfo(bool multicartCompat) const;
void setGameGenie(std::string const &codes);
Expand Down
4 changes: 2 additions & 2 deletions libgambatte/src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,8 @@ void Memory::nontrivial_write(unsigned const p, unsigned const data, unsigned lo
ioamhram_[p - 0xFE00] = data;
}

LoadRes Memory::loadROM(std::string const &romfile, bool const forceDmg, bool const multicartCompat) {
if (LoadRes const fail = cart_.loadROM(romfile, forceDmg, multicartCompat))
LoadRes Memory::loadROM(std::string const &romfile, bool const forceDmg, bool const multicartCompat, int const preferCGB) {
if (LoadRes const fail = cart_.loadROM(romfile, forceDmg, multicartCompat, preferCGB))
return fail;

psg_.init(cart_.isCgb());
Expand Down
2 changes: 1 addition & 1 deletion libgambatte/src/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Memory {

unsigned long event(unsigned long cycleCounter);
unsigned long resetCounters(unsigned long cycleCounter);
LoadRes loadROM(std::string const &romfile, bool forceDmg, bool multicartCompat);
LoadRes loadROM(std::string const &romfile, bool forceDmg, bool multicartCompat, int preferCGB);
void setSaveDir(std::string const &dir) { cart_.setSaveDir(dir); }
void setInputGetter(InputGetter *getInput) { getInput_ = getInput; }
void setEndtime(unsigned long cc, unsigned long inc);
Expand Down

0 comments on commit 034ecc6

Please sign in to comment.