Skip to content

Commit

Permalink
wswan: Loosen WW/FLASH detection requirements, fix 0xCE port emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Oct 20, 2024
1 parent c1ccc3c commit 71499d9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion mednafen/src/wswan/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,11 @@ static const RegGroupType V30MZRegsGroup =
static const RegType MiscRegs[] =
{
{ 0, 0, "------BNK------", "", 0xFFFF },
{ MEMORY_GSREG_BNK1SLCT, 3, "Bnk1Select", "???", 1 },
{ MEMORY_GSREG_BNK1SLCT, 3, "Bnk1Select", "SRAM Bank Selector for 64KiB bank 0x1", 1 },
{ MEMORY_GSREG_BNK2SLCT, 3, "Bnk2Select", "ROM Bank Selector for 64KiB bank 0x2", 1 },
{ MEMORY_GSREG_BNK3SLCT, 3, "Bnk3Select", "ROM Bank Selector for 64KiB bank 0x3", 1 },
{ MEMORY_GSREG_ROMBBSLCT, 3, "RomBSelect", "ROM Bank Base Selector for 64KiB banks 0x4-0xF", 1 },
{ MEMORY_GSREG_FLASHSLCT, 3, "FlashSlect", "SRAM/Flash Bank Toggle", 1 },

{ 0, 0, "------IRQ------", "", 0xFFFF },
{ 0x8000 | INT_GSREG_IASSERTED, 4, "IrqAssert", "Interrupt Asserted", 1 },
Expand Down
8 changes: 6 additions & 2 deletions mednafen/src/wswan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ static void Load(GameFile* gf)
{
IsWSR = false;

if(rom_size == 524288 && !memcmp(&wsCartROM[0x70000], "ELISA", 5) && crc32(0, &wsCartROM[0x7FFF0], 0x10) == 0x0d05ed64)
if(rom_size == 0x80000 && !memcmp(&wsCartROM[0x70000], "ELISA", 5)
&& wsCartROM[0x7fff6] == 0x00 // Publisher ID
&& wsCartROM[0x7fff8] == 0x00 // Game ID
&& wsCartROM[0x7fffb] == 0x04 // Save format
&& wsCartROM[0x7fffd] == 0x01) // Mapper
{
uint32 crc32_sans_l64k = crc32(0, wsCartROM, 0x70000);
uint32 bl[] = { 0x63f00316, 0x60fd569b, 0xe11538f8 };
Expand All @@ -310,7 +314,7 @@ static void Load(GameFile* gf)
}
}

MDFN_printf(_("ROM: %uKiB\n"), real_rom_size / 1024);
MDFN_printf(_("%s %uKiB\n"), IsWW ? "FLASH:" : "ROM: ", real_rom_size / 1024);
md5_context md5;
md5.starts();
md5.update(wsCartROM, rom_size);
Expand Down
19 changes: 12 additions & 7 deletions mednafen/src/wswan/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ static INLINE void WriteMem(uint32 A, uint8 V)
{
//if((offset | (BankSelector[1] << 16)) >= 0x38000)
// printf("%08x\n", offset | (BankSelector[1] << 16));
if(WW && (BankSelector[1] & 0x08))
if(WW && WW_FlashLock)
{
if(WW_FlashLock != 0x00)
{
uint32 rom_addr = offset | (BankSelector[1] << 16);

//printf("Write: %08x %02x\n", rom_addr, V);
Expand Down Expand Up @@ -153,7 +151,6 @@ static INLINE void WriteMem(uint32 A, uint8 V)
if(V == 0xF0)
WW_FWSM = WW_FWSM_READ;
break;
}
}
}
else if(sram_size)
Expand Down Expand Up @@ -184,7 +181,7 @@ static INLINE uint8 ReadMem(uint32 A)
{
case 0: return wsRAM[offset];

case 1: if(WW && (BankSelector[1] & 0x08))
case 1: if(WW && WW_FlashLock)
{
uint32 rom_addr = (offset | (BankSelector[1] << 16));
uint8 ret = wsCartROM[rom_addr & 524287];
Expand Down Expand Up @@ -455,7 +452,7 @@ static INLINE void WritePort(uint32 IOPort, uint8 V)
}

if(WW && IOPort == 0xCE)
WW_FlashLock = V;
WW_FlashLock = V & 0x01;
}

MDFN_FASTCALL void WSwan_writemem20(uint32 A, uint8 V)
Expand Down Expand Up @@ -636,7 +633,7 @@ static void PutAddressSpaceBytes(const char *name, uint32 Address, uint32 Length
WSwan_GfxWSCPaletteRAMWrite(offset & (wsRAMSize - 1), *Buffer);
break;
case 1:
if(IsWW && (BankSelector[1] & 0x08))
if(IsWW && WW_FlashLock)
{
uint32 rom_addr = (offset | (BankSelector[1] << 16));
wsCartROM[rom_addr & 524287] = *Buffer;
Expand Down Expand Up @@ -707,6 +704,10 @@ uint32 WSwan_MemoryGetRegister(const unsigned int id, char *special, const uint3
case MEMORY_GSREG_BNK3SLCT:
ret = BankSelector[3];
break;

case MEMORY_GSREG_FLASHSLCT:
ret = WW_FlashLock;
break;
}

return(ret);
Expand All @@ -731,6 +732,10 @@ void WSwan_MemorySetRegister(const unsigned int id, uint32 value)
case MEMORY_GSREG_BNK3SLCT:
BankSelector[3] = value;
break;

case MEMORY_GSREG_FLASHSLCT:
WW_FlashLock = value;
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions mednafen/src/wswan/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum
MEMORY_GSREG_BNK1SLCT,
MEMORY_GSREG_BNK2SLCT,
MEMORY_GSREG_BNK3SLCT,
MEMORY_GSREG_FLASHSLCT
};


Expand Down

0 comments on commit 71499d9

Please sign in to comment.