Skip to content

Commit

Permalink
Merge pull request #178 from jfroco/master
Browse files Browse the repository at this point in the history
Fix extension checking and SG-1000 8KB RAM mapper
  • Loading branch information
LibretroAdmin authored Oct 17, 2024
2 parents b83fe4b + ad3c38a commit d898cd7
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 57 deletions.
42 changes: 24 additions & 18 deletions Src/Memory/romMapperSg1000RamExpander.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <string.h>
#include <stdio.h>


typedef struct {
int deviceHandle;
UInt8* romData;
Expand Down Expand Up @@ -77,17 +76,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 & 0x1fff];
}

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 & 0x1fff] = value;
}

int romMapperSg1000RamExpanderCreate(const char* filename, UInt8* romData,
int size, int slot, int sslot, int startPage, int type)
{
Expand All @@ -96,37 +105,34 @@ 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;
rm->startPage = startPage;
rm->mask2 = ROM_SG1000_RAMEXPANDER_A ? 0x0400 : 0x2000;
rm->mask2 = (type == ROM_SG1000_RAMEXPANDER_A) ? 0x3FF: 0x1FFF;

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);
}
else {
if (type == ROM_SG1000_RAMEXPANDER_A && i + startPage == 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);
slotRegister(0, 0, 6, 2, read, read, write, destroy, rm);

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
Loading

0 comments on commit d898cd7

Please sign in to comment.