Skip to content

Commit

Permalink
Add support for Lord of the Dungeon (cartridge with SRAM)
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Dec 8, 2023
1 parent d71744d commit 0b5784b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/Cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Cartridge::Cartridge()
m_szFileName[0] = 0;
m_iROMBankCount = 0;
m_bPAL = false;
m_bSRAM = false;
m_iCRC = 0;
}

Expand All @@ -59,6 +60,7 @@ void Cartridge::Reset()
m_szFileName[0] = 0;
m_iROMBankCount = 0;
m_bPAL = false;
m_bSRAM = false;
m_iCRC = 0;
}

Expand All @@ -72,6 +74,11 @@ bool Cartridge::IsPAL() const
return m_bPAL;
}

bool Cartridge::HasSRAM() const
{
return m_bSRAM;
}

bool Cartridge::IsValidROM() const
{
return m_bValidROM;
Expand Down Expand Up @@ -306,6 +313,7 @@ bool Cartridge::LoadFromBuffer(const u8* buffer, int size)
bool Cartridge::GatherMetadata(u32 crc)
{
m_bPAL = false;
m_bSRAM = false;

Log("ROM Size: %d KB", m_iROMSize / 1024);

Expand Down Expand Up @@ -372,6 +380,12 @@ void Cartridge::GetInfoFromDB(u32 crc)
found = true;

Log("ROM found in database: %s. CRC: %X", kGameDatabase[i].title, crc);

if (kGameDatabase[i].mode & GC_GameDBMode_SRAM)
{
Log("Cartridge with SRAM");
m_bSRAM = true;
}
}
else
i++;
Expand Down
2 changes: 2 additions & 0 deletions src/Cartridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Cartridge
void Reset();
u32 GetCRC() const;
bool IsPAL() const;
bool HasSRAM() const;
bool IsValidROM() const;
bool IsReady() const;
CartridgeTypes GetType() const;
Expand Down Expand Up @@ -80,6 +81,7 @@ class Cartridge
int m_iROMBankCount;
bool m_bPAL;
u32 m_iCRC;
bool m_bSRAM;
};

#endif /* CARTRIDGE_H */
14 changes: 13 additions & 1 deletion src/Memory_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,23 @@ inline void Memory::Write(u16 address, u8 value)
case 0x8000:
case 0xA000:
case 0xC000:
case 0xE000:
{
Log("--> ** Attempting to write on ROM: %X %X", address, value);
break;
}
case 0xE000:
{
if (m_pCartridge->HasSRAM() && (address >= 0xE000) && (address < 0xE800))
{
u8* pRom = m_pCartridge->GetROM();
pRom[(address + 0x800) & 0x7FFF] = value;
}
else
{
Log("--> ** Attempting to write on ROM: %X %X", address, value);
}
break;
}
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/game_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
#ifndef GAME_DB_H
#define GAME_DB_H

enum GC_GameDBMode
{
GC_GameDBMode_None = 0,
GC_GameDBMode_SRAM = 1,
};

struct GC_GameDBEntry
{
u32 crc;
const char* title;
u32 crc;
const char* title;
GC_GameDBMode mode;
};

const GC_GameDBEntry kGameDatabase[] =
{
{0xFFFFFFFF, "xxx"},
{0, 0}
{0xFEE15196, "Lord of the Dungeon", GC_GameDBMode_SRAM},
{0x1053F610, "Lord of the Dungeon", GC_GameDBMode_SRAM},
{0, 0, GC_GameDBMode_None}
};

const uint32_t kCRC32_tab[] =
Expand Down

0 comments on commit 0b5784b

Please sign in to comment.