Bootloader and gba mode work together,fixed string = null bug

This commit is contained in:
meepingsnesroms 2017-02-03 11:23:58 -08:00
parent f0bdfa0ce0
commit e4abf1dbcc
3 changed files with 21 additions and 9 deletions

View File

@ -25,10 +25,17 @@ static bool gbc_mode;
static void patch_gbc_to_gba_mode(){
/*moves one jump over another and puts ld b,0x01 into the original position*/
uint16_t patchloc = 0xF2;
uint8_t patch[0x7] = {0xCD,0xD0,0x05/*<-call systemsetup*/,0x06,0x01/*<-ld b,0x1*/,0x00/*<-nop*/,0x00/*<-nop*/};
memcpy(bootromswapspace + patchloc,patch,0x7);
}
//this is the only retroarch specific function,everything else can just be copied over //this is the only retroarch specific function,everything else can just be copied over
static std::string get_bootloader_path(std::string bootloadername){ static std::string get_bootloader_path(std::string bootloadername){
std::string path; std::string path;
if(bootrompath != NULL){ if(bootrompath[0] != 0){
path = bootrompath; path = bootrompath;
if(path[path.length() - 1] != '/')path += '/'; if(path[path.length() - 1] != '/')path += '/';
path += bootloadername; path += bootloadername;
@ -47,7 +54,7 @@ bool have_bootloader(bool isgbc){
return exist(path); return exist(path);
} }
bool loadbootloader(bool isgbc){ bool loadbootloader(bool isgbc,bool isgba){
unsigned int size; unsigned int size;
std::string path; std::string path;
int n = 0; int n = 0;
@ -71,6 +78,10 @@ bool loadbootloader(bool isgbc){
using_bootloader = true; using_bootloader = true;
gbc_mode = isgbc; gbc_mode = isgbc;
if(isgba){//patch bootloader to fake gba mode
patch_gbc_to_gba_mode();
}
//backup rom segment that is shared with bootloader //backup rom segment that is shared with bootloader
memcpy(rombackup,(uint8_t*)addrspace_start,size); memcpy(rombackup,(uint8_t*)addrspace_start,size);
@ -88,6 +99,7 @@ void resetbootloader(){
has_called_FF50 = false; has_called_FF50 = false;
addrspace_start = NULL; addrspace_start = NULL;
using_bootloader = false; using_bootloader = false;
gbc_mode = false;
} }
void set_bootrom_directory(char* dir){ void set_bootrom_directory(char* dir){

View File

@ -1,6 +1,6 @@
//load the rom then call the loadbootloader() function before execution starts //load the rom then call the loadbootloader() function before execution starts
bool have_bootloader(bool isgbc); bool have_bootloader(bool isgbc);
bool loadbootloader(bool isgbc); bool loadbootloader(bool isgbc,bool isgba);
void resetbootloader(); void resetbootloader();
void set_bootrom_directory(char* dir); void set_bootrom_directory(char* dir);

View File

@ -61,13 +61,13 @@ void GB::reset() {
p_->cpu.setStatePtrs(state); p_->cpu.setStatePtrs(state);
setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode); setInitState(state, p_->cpu.isCgb(), p_->gbaCgbMode);
if(bootloaderexists && !p_->gbaCgbMode){ if(bootloaderexists){
resetbootloader(); resetbootloader();
set_address_space_start((void*)p_->cpu.rombank0_ptr()); set_address_space_start((void*)p_->cpu.rombank0_ptr());
loadbootloader(p_->cpu.isCgb()); loadbootloader(p_->cpu.isCgb(), p_->gbaCgbMode);
state.cpu.pc = 0x0000; state.cpu.pc = 0x0000;
//the hw registers must be zeroed out to prevent the logo from being garbled //the hw registers must be zeroed out to prevent the logo from being garbled
memset((void*)(state.mem.ioamhram.get() + 0x100),0x00,0x100); memset((void*)(state.mem.ioamhram.get() + 0x100), 0x00, 0x100);
} }
p_->cpu.loadState(state); p_->cpu.loadState(state);
@ -93,13 +93,13 @@ void GB::Priv::on_load_succeeded(unsigned flags)
cpu.setStatePtrs(state); cpu.setStatePtrs(state);
setInitState(state, cpu.isCgb(), gbaCgbMode); setInitState(state, cpu.isCgb(), gbaCgbMode);
if(bootloaderexists && !gbaCgbMode){ if(bootloaderexists){
resetbootloader(); resetbootloader();
set_address_space_start((void*)cpu.rombank0_ptr()); set_address_space_start((void*)cpu.rombank0_ptr());
loadbootloader(cpu.isCgb()); loadbootloader(cpu.isCgb(), gbaCgbMode);
state.cpu.pc = 0x0000; state.cpu.pc = 0x0000;
//the hw registers must be zeroed out to prevent the logo from being garbled //the hw registers must be zeroed out to prevent the logo from being garbled
memset((void*)(state.mem.ioamhram.get() + 0x100),0x00,0x100); memset((void*)(state.mem.ioamhram.get() + 0x100), 0x00, 0x100);
} }
cpu.loadState(state); cpu.loadState(state);