Skip to content

Commit

Permalink
Better handling 768KB roms
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 4, 2025
1 parent bf86405 commit a6be35d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
57 changes: 42 additions & 15 deletions src/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*
*/

#include "cartridge.h"
#include "miniz/miniz.h"
#include "game_db.h"
#include <string>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include "cartridge.h"
#include "miniz/miniz.h"
#include "game_db.h"

Cartridge::Cartridge()
{
Expand Down Expand Up @@ -185,6 +186,8 @@ bool Cartridge::LoadFromBuffer(const u8* buffer, int size)
Debug("MCGENJIN mapper detected.");
}

assert((size % 0x2000) == 0);

if ((size % 0x2000) != 0)
{
Log("Invalid size found: %d (0x%X) bytes", size, size);
Expand All @@ -196,12 +199,6 @@ bool Cartridge::LoadFromBuffer(const u8* buffer, int size)

GatherROMInfo();

if (m_is_sgx)
{
Log("SuperGrafx (SGX) games are not supported yet.");
return false;
}

InitRomMAP();

m_ready = true;
Expand Down Expand Up @@ -300,11 +297,17 @@ void Cartridge::GatherInfoFromDB()
found = true;
Log("ROM found in database: %s. CRC: %08X", k_game_database[i].title, m_crc);

if (k_game_database[i].flags & GG_GAMEDB_SGX)
if (k_game_database[i].flags & GG_GAMEDB_SGX_REQUIRED)
{
m_is_sgx = true;
Log("ROM is a SuperGrafx (SGX) game.");
}

if (k_game_database[i].flags & GG_GAMEDB_SGX_OPTIONAL)
{
m_is_sgx = true;
Log("ROM is a SuperGrafx (SGX) optional game.");
}
}
else
i++;
Expand All @@ -318,8 +321,10 @@ void Cartridge::GatherInfoFromDB()

void Cartridge::InitRomMAP()
{
if(m_rom_size == 0x60000)
if (m_rom_bank_count == 0x30)
{
Debug("Mapping 384KB ROM");

for(int x = 0; x < 64; x++)
{
int bank = x & 0x1F;
Expand All @@ -329,13 +334,15 @@ void Cartridge::InitRomMAP()

for(int x = 64; x < 128; x++)
{
int bank = (x & 0x0F) + 32;
int bank = (x & 0x0F) + 0x20;
int bank_address = bank * 0x2000;
m_rom_map[x] = &m_rom[bank_address];
}
}
else if (m_rom_size == 0x80000)
else if (m_rom_bank_count == 0x40)
{
Debug("Mapping 512KB ROM");

for(int x = 0; x < 64; x++)
{
int bank = x & 0x3F;
Expand All @@ -345,16 +352,36 @@ void Cartridge::InitRomMAP()

for(int x = 64; x < 128; x++)
{
int bank = (x & 0x1F) + 32;
int bank = (x & 0x1F) + 0x20;
int bank_address = bank * 0x2000;
m_rom_map[x] = &m_rom[bank_address];
}
}
else if (m_rom_bank_count == 0x60)
{
Debug("Mapping 768KB ROM");

for(int x = 0; x < 64; x++)
{
int bank = x & 0x3F;
int bank_address = bank * 0x2000;
m_rom_map[x] = &m_rom[bank_address];
}

for(int x = 64; x < 128; x++)
{
int bank = (x & 0x1F) + 0x40;
int bank_address = bank * 0x2000;
m_rom_map[x] = &m_rom[bank_address];
}
}
else
{
Debug("Default mapping ROM");

for(int x = 0; x < 128; x++)
{
int bank = x % (m_rom_size / 0x2000);
int bank = x % m_rom_bank_count;
int bank_address = bank * 0x2000;
m_rom_map[x] = &m_rom[bank_address];
}
Expand Down
25 changes: 17 additions & 8 deletions src/game_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

#include "common.h"

#define GG_GAMEDB_NONE 0x00
#define GG_GAMEDB_SGX 0x01
#define GG_GAMEDB_NONE 0x00
#define GG_GAMEDB_SGX_REQUIRED 0x01
#define GG_GAMEDB_SGX_OPTIONAL 0x02
#define GG_GAMEDB_SF2_MAPPER 0x04

struct GG_Game_DB_Entry
{
Expand All @@ -34,12 +36,19 @@ struct GG_Game_DB_Entry

const GG_Game_DB_Entry k_game_database[] =
{
{ 0xBEBFE042, "Darius Plus (J) (SGX)", GG_GAMEDB_SGX},
{ 0x4C2126B0, "Aldynes (J) (SGX)", GG_GAMEDB_SGX},
{ 0x8C4588E2, "1941 - Counter Attack (J) (SGX)", GG_GAMEDB_SGX},
{ 0x1F041166, "Madouou Granzort (J) (SGX)", GG_GAMEDB_SGX},
{ 0xB486A8ED, "Daimakaimura (J) (SGX)", GG_GAMEDB_SGX},
{ 0x3B13AF61, "Battle Ace (J) (SGX)", GG_GAMEDB_SGX},
// SGX
{ 0x8C4588E2, "1941 - Counter Attack (J) (SGX)", GG_GAMEDB_SGX_REQUIRED},
{ 0x4C2126B0, "Aldynes (J) (SGX)", GG_GAMEDB_SGX_REQUIRED},
{ 0x3B13AF61, "Battle Ace (J) (SGX)", GG_GAMEDB_SGX_REQUIRED},
{ 0xB486A8ED, "Daimakaimura (J) (SGX)", GG_GAMEDB_SGX_REQUIRED},
{ 0x1F041166, "Madouou Granzort (J) (SGX)", GG_GAMEDB_SGX_REQUIRED},

// OPTIONAL SGX
{ 0xBEBFE042, "Darius Plus (J) (SGX)", GG_GAMEDB_SGX_OPTIONAL},

// SF2 MAPPER
{ 0xD15CB6BB, "Street Fighter II' - Champion Edition (J)", GG_GAMEDB_SF2_MAPPER},

{0, 0, GG_GAMEDB_NONE}
};

Expand Down

0 comments on commit a6be35d

Please sign in to comment.