Skip to content

Commit

Permalink
Merge pull request #1 from libretro/HLE_BIOS
Browse files Browse the repository at this point in the history
HLE BIOS, activated in case of an invalid BIOS rom file.
Tested with commercial games.
  • Loading branch information
LLeny committed Sep 11, 2013
2 parents cf6338c + 952603f commit 2e814dc
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 8 deletions.
5 changes: 1 addition & 4 deletions libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions lynx/Rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ extern CErrorInterface *gError;

CRom::CRom(const char *romfile)
{
mWriteEnable=FALSE;
mWriteEnable = FALSE;
mValid = FALSE;
strncpy(mFileName,romfile,1024);
Reset();

Expand All @@ -71,13 +72,16 @@ CRom::CRom(const char *romfile)
if((fp=fopen(mFileName,"rb"))==NULL)
{
fprintf(stderr, "Invalid ROM.\n");
return;
}

// Read in the 512 bytes

if(fread(mRomData,sizeof(char),ROM_SIZE,fp)!=ROM_SIZE)
{
fprintf(stderr, "Invalid ROM.\n");
fclose(fp);
return;
}

fclose(fp);
Expand All @@ -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)
Expand Down
56 changes: 56 additions & 0 deletions lynx/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lynx/cart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
1 change: 1 addition & 0 deletions lynx/rom.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CRom : public CLynxBase

public:
bool mWriteEnable;
bool mValid;
private:
UBYTE mRomData[ROM_SIZE];
char mFileName[1024];
Expand Down
1 change: 1 addition & 0 deletions lynx/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2e814dc

Please sign in to comment.