diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index da56b83a..e74e5ab3 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -338,10 +338,7 @@ void lynx_initialize_system(const char* gamepath) char romfilename[1024]; - if(!lynx_romfilename(romfilename)) - { - return; - } + lynx_romfilename(romfilename); lynx = new CSystem(gamepath, romfilename); diff --git a/lynx/Rom.cpp b/lynx/Rom.cpp index 50c5b89d..406a0cd3 100644 --- a/lynx/Rom.cpp +++ b/lynx/Rom.cpp @@ -57,7 +57,8 @@ extern CErrorInterface *gError; CRom::CRom(const char *romfile) { - mWriteEnable=FALSE; + mWriteEnable = FALSE; + mValid = FALSE; strncpy(mFileName,romfile,1024); Reset(); @@ -71,6 +72,7 @@ CRom::CRom(const char *romfile) if((fp=fopen(mFileName,"rb"))==NULL) { fprintf(stderr, "Invalid ROM.\n"); + return; } // Read in the 512 bytes @@ -78,6 +80,8 @@ CRom::CRom(const char *romfile) if(fread(mRomData,sizeof(char),ROM_SIZE,fp)!=ROM_SIZE) { fprintf(stderr, "Invalid ROM.\n"); + fclose(fp); + return; } fclose(fp); @@ -100,10 +104,12 @@ CRom::CRom(const char *romfile) gError->Warning("FAKE LYNXBOOT.IMG - CARTRIDGES WILL NOT WORK\n\n" "PLEASE READ THE ACCOMPANYING README.TXT FILE\n\n" "(Do not email the author asking for this image)\n"); - break; + return; } } } + + mValid = TRUE; } void CRom::Reset(void) diff --git a/lynx/System.cpp b/lynx/System.cpp index 790847f3..e3f88cae 100644 --- a/lynx/System.cpp +++ b/lynx/System.cpp @@ -322,6 +322,57 @@ bool CSystem::IsZip(char *filename) return FALSE; } +void CSystem::HLE_BIOS_init() +{ + fprintf(stderr, "[handy] HLE_BIOS_Init\r\n"); + + unsigned char buffer[8]; + + int blocksize = (1 + mCart->mMaskBank0) / 256; + + int blockcount = 0x100 - mCart->Peek(0); + int start = 1 + blockcount * 51; + + int loadaddr; + + if(blockcount == 1) // cc65 + { + for (int i = 0; i < 0x97; ++i) //2nd loader to 0xFB68 + { + Poke_CPU(0xFB68 + i, mCart->Peek(start + i)); + } + + loadaddr = 0xFB68; + } + else // epyx + { + blockcount = 0x100 - mCart->Peek(start); + start += 1 + blockcount * 51; + + int dir_idx = 1; + + for (int i = 0; i < 8; ++i) //exec directory + { + buffer[i] = mCart->Peek(start + (dir_idx * 8) + i); + } + + int offset = ((int)buffer[0]) * blocksize + (((int)buffer[2]) << 8) + buffer[1]; + + loadaddr = (((int)buffer[5]) << 8) + buffer[4]; + int filesize = (((int)buffer[7]) << 8) + buffer[6]; + + for (int i = 0; i < filesize; ++i) + { + Poke_CPU(i + loadaddr, mCart->Peek(offset + i)); + } + } + + C6502_REGS regs; + mCpu->GetRegs(regs); + regs.PC=(UWORD)loadaddr; + mCpu->SetRegs(regs); +} + void CSystem::Reset(void) { gSystemCycleCount=0; @@ -356,6 +407,11 @@ void CSystem::Reset(void) mSusie->Reset(); mCpu->Reset(); + if(!mRom->mValid) + { + HLE_BIOS_init(); + } + // Homebrew hashup if(mFileType==HANDY_FILETYPE_HOMEBREW) diff --git a/lynx/cart.h b/lynx/cart.h index d1053b16..dc482c8c 100644 --- a/lynx/cart.h +++ b/lynx/cart.h @@ -138,11 +138,12 @@ class CCart : public CLynxBase ULONG mWriteEnableBank0; ULONG mWriteEnableBank1; ULONG mCartRAM; + ULONG mMaskBank0; + ULONG mMaskBank1; private: EMMODE mBank; - ULONG mMaskBank0; - ULONG mMaskBank1; + UBYTE *mCartBank0; UBYTE *mCartBank1; char mName[33]; diff --git a/lynx/rom.h b/lynx/rom.h index 9ca75186..13a9367c 100644 --- a/lynx/rom.h +++ b/lynx/rom.h @@ -77,6 +77,7 @@ class CRom : public CLynxBase public: bool mWriteEnable; + bool mValid; private: UBYTE mRomData[ROM_SIZE]; char mFileName[1024]; diff --git a/lynx/system.h b/lynx/system.h index 5f642baf..1c856c02 100644 --- a/lynx/system.h +++ b/lynx/system.h @@ -188,6 +188,7 @@ class CSystem : public CSystemBase ~CSystem(); public: + void HLE_BIOS_init(); void Reset(void); size_t MemoryContextSave(const char* tmpfilename, char *context); bool MemoryContextLoad(const char *context, size_t size);