Skip to content

Commit

Permalink
Fix extension checking and SG-1000 8KB RAM mapper
Browse files Browse the repository at this point in the history
- Fix extension checking; files with two-character extensions like .sg are now working.
- The SG-1000 8KB RAM expansion mapper is now functioning and runs most games.
- Add SG-1000 games that use the expansion card: Rally-X, Bomberman, Yie Ar Kung Fu II, Road Fighter, TwinBee, and Knightmare.
  • Loading branch information
jfroco committed Oct 13, 2024
1 parent b83fe4b commit b5cbc72
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 22 deletions.
32 changes: 21 additions & 11 deletions Src/Memory/romMapperSg1000RamExpander.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,27 @@ static void destroy(RomMapperSg1000RamExpander* rm)
free(rm->romData);
free(rm);
}


static UInt8 read(RomMapperSg1000RamExpander* rm, UInt16 address)
{
return rm->ram2[address & rm->mask2];
}


static UInt8 read_ram1(RomMapperSg1000RamExpander* rm, UInt16 address)
{
return rm->ram1[address - 0x2000];
}

static void write(RomMapperSg1000RamExpander* rm, UInt16 address, UInt8 value)
{
rm->ram2[address & rm->mask2] = value;
}

static void write_ram1(RomMapperSg1000RamExpander* rm, UInt16 address, UInt8 value)
{
rm->ram1[address-0x2000] = value;
}

int romMapperSg1000RamExpanderCreate(const char* filename, UInt8* romData,
int size, int slot, int sslot, int startPage, int type)
{
Expand All @@ -96,19 +106,19 @@ int romMapperSg1000RamExpanderCreate(const char* filename, UInt8* romData,
int pages = size / 0x2000 + ((size & 0x1fff) ? 1 : 0);
int i;

if (size != 0x8000 || startPage != 0) {
return 0;
}
// Some ROMs are 48KB
// if (size != 0x8000 || startPage != 0) {
// return 0;
// }

rm = malloc(sizeof(RomMapperSg1000RamExpander));

rm->deviceHandle = deviceManagerRegister(type, &callbacks, rm);
slotRegister(slot, sslot, startPage, pages, read, read, write, destroy, rm);

rm->romData = malloc(pages * 0x2000);
memcpy(rm->romData, romData, size);
memset(rm->ram1, sizeof(rm->ram1), 0xff);
memset(rm->ram2, sizeof(rm->ram2), 0xff);
memset(rm->ram1, 0xff, sizeof(rm->ram1));
memset(rm->ram2, 0xff, sizeof(rm->ram2));

rm->slot = slot;
rm->sslot = sslot;
Expand All @@ -118,15 +128,15 @@ int romMapperSg1000RamExpanderCreate(const char* filename, UInt8* romData,
for (i = 0; i < pages; i++) {
if (i + startPage >= 2) slot = 0;
if (type == ROM_SG1000_RAMEXPANDER_A && i + startPage == 1) {
slotMapPage(slot, sslot, i + startPage, rm->ram1, 1, 1);
slotRegister(slot, sslot, i + startPage, 1, read_ram1, read_ram1, write_ram1, destroy, rm);
}
else {
slotMapPage(slot, sslot, i + startPage, rm->romData + 0x2000 * i, 1, 0);
}
}

slotMapPage(slot, sslot, 6, NULL, 0, 0);
slotMapPage(slot, sslot, 7, NULL, 0, 0);
slotMapPage(0, 0, 6, rm->ram2, 1, 1);
slotMapPage(0, 0, 7, rm->ram2, 1, 1);

return 1;
}
Expand Down
22 changes: 11 additions & 11 deletions libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,39 +122,39 @@ int get_media_type(const char* filename)

strcpy(workram, filename);
lower_string(workram);
extension = workram + strlen(workram) - 4;
extension = workram + strlen(workram) - 3;

if(strcmp(extension, ".dsk") == 0){
if(strcmp(extension, "dsk") == 0){
if (is_auto)
strcpy(msx_type, "MSX2+");
return MEDIA_TYPE_DISK;
}
else if(strcmp(extension, ".m3u") == 0){
else if(strcmp(extension, "m3u") == 0){
if (is_auto)
strcpy(msx_type, "MSX2+");
return MEDIA_TYPE_DISK_BUNDLE;
}
else if(strcmp(extension, ".cas") == 0){
else if(strcmp(extension, "cas") == 0){
if (is_auto)
strcpy(msx_type, "MSX2+");
return MEDIA_TYPE_TAPE;
}
else if(strcmp(extension, ".rom") == 0){
else if(strcmp(extension, "rom") == 0){
if (is_auto)
strcpy(msx_type, "MSX2+");
return MEDIA_TYPE_CART;
}
else if(strcmp(extension, ".mx1") == 0){
else if(strcmp(extension, "mx1") == 0){
if (is_auto)
strcpy(msx_type, "MSX2+");
return MEDIA_TYPE_CART;
}
else if(strcmp(extension, ".mx2") == 0){
else if(strcmp(extension, "mx2") == 0){
if (is_auto)
strcpy(msx_type, "MSX2+");
return MEDIA_TYPE_CART;
}
else if(strcmp(extension, ".col") == 0){
else if(strcmp(extension, "col") == 0){
if (is_auto){
is_coleco = true;
strcpy(msx_type, "COL - ColecoVision");
Expand Down Expand Up @@ -182,7 +182,7 @@ int get_media_type(const char* filename)
}
return MEDIA_TYPE_CART;
}
else if(strcmp(extension, ".sf7") == 0){
else if(strcmp(extension, "sf7") == 0){
if (is_auto){
is_sega = true;
strcpy(msx_type, "SEGA - SF-7000");
Expand All @@ -196,7 +196,7 @@ int get_media_type(const char* filename)
}
return MEDIA_TYPE_CART;
}
else if(strcmp(extension, ".omv") == 0){
else if(strcmp(extension, "omv") == 0){
if (is_auto){
is_sega = true;
strcpy(msx_type, "Othello Multivision");
Expand Down Expand Up @@ -899,7 +899,7 @@ bool retro_load_game(const struct retro_game_info *info)
if (info)
extract_directory(base_dir, info->path, sizeof(base_dir));

check_variables(); // msx_type from configuration
check_variables(); // msx_type from configuration

if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
strcpy(properties_dir, dir);
Expand Down
133 changes: 133 additions & 0 deletions system/bluemsx/Databases/segadb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3278,4 +3278,137 @@ f0f128b25e5557e660d936995e6bf25c8ebd17e5</hash>
</systemrom>
</dump>
</software>
<software>
<title xml:lang="en">Rally-X</title>
<system>Sega</system>
<company>DahJee</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">0c1957a5faae5254c69f3331e79d87499dd7cf48</hash>
</rom>
</dump>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">21770691191b62bafec9099bbe0f9942f5480f83</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">Tank Battalion</title>
<system>Sega</system>
<company>DahJee</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">0ca3b740b28266a2a606127ed8967c684b67cb44</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">Yie Ar Kung-Fu II</title>
<system>Sega</system>
<company>DahJee</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">44fb2dca3774f859f0ae0ad4d809a67f760cf9ae</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">*Bomberman Special</title>
<system>Sega</system>
<company>DahJee</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">d1d56bcd996df94458f5901dc537a5e30021256b</hash>
</rom>
</dump>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">455838571dd8287d491431e03269b0ccd292c8b8</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">Legend of Kage</title>
<system>Sega</system>
<company>DahJee</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">902dbb122bf0efc76604a876c3fae51c074bdc6a</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">Road Fighter</title>
<system>Sega</system>
<company>Jumbo</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">4f1a139974e3db27af5973bc9572ed68acd6ea68</hash>
</rom>
</dump>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">2755f74019dc94559fd0c2248e2ecb7f48879b90</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">Knightmare</title>
<system>Sega</system>
<company>Jumbo</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">babdb6b109b20e81c28cd892c2042723e9cbff49</hash>
</rom>
</dump>
</software>
<software>
<title xml:lang="en">TwinBee</title>
<system>Sega</system>
<company>Jumbo</company>
<year>1986</year>
<country>TW</country>
<dump>
<original value="false" />
<rom>
<type>sg1000ramA</type>
<hash algo="sha1">a8c30043c145e63f79a3265dde167529f0e08d49</hash>
</rom>
</dump>
</software>
</softwaredb>

0 comments on commit b5cbc72

Please sign in to comment.