[BS-X] Flash Support for BS Compatible Games

- Removed write MMC check from S9xSetBSX() [redundant with BSX_Map_FlashIO()]
This commit is contained in:
LuigiBlood 2017-12-17 00:34:53 +01:00
parent d89d7681ad
commit 660b087378

189
bsx.cpp
View File

@ -704,18 +704,20 @@ static void BSX_Map (void)
static uint8 BSX_Get_Bypass_FlashIO (uint32 offset) static uint8 BSX_Get_Bypass_FlashIO (uint32 offset)
{ {
//For games other than BS-X
FlashROM = Memory.ROM + Multi.cartOffsetB;
if (BSX.prevMMC[0x02]) if (BSX.prevMMC[0x02])
{
return (FlashROM[offset & 0x0FFFFF]); return (FlashROM[offset & 0x0FFFFF]);
}
else else
{
return (FlashROM[(offset & 0x1F0000) >> 1 | (offset & 0x7FFF)]); return (FlashROM[(offset & 0x1F0000) >> 1 | (offset & 0x7FFF)]);
}
} }
static void BSX_Set_Bypass_FlashIO (uint32 offset, uint8 byte) static void BSX_Set_Bypass_FlashIO (uint32 offset, uint8 byte)
{ {
//For games other than BS-X
FlashROM = Memory.ROM + Multi.cartOffsetB;
if (BSX.prevMMC[0x02]) if (BSX.prevMMC[0x02])
FlashROM[offset & 0x0FFFFF] = FlashROM[offset & 0x0FFFFF] & byte; FlashROM[offset & 0x0FFFFF] = FlashROM[offset & 0x0FFFFF] & byte;
else else
@ -814,106 +816,105 @@ void S9xSetBSX (uint8 byte, uint32 address)
} }
// Flash Command Handling // Flash Command Handling
if (BSX.MMC[0xC]) {
//Memory Pack Type 1 & 3 & 4
BSX.flash_command <<= 8;
BSX.flash_command |= byte;
switch (BSX.flash_command & 0xFF) //Memory Pack Type 1 & 3 & 4
{ BSX.flash_command <<= 8;
case 0x00: BSX.flash_command |= byte;
case 0xFF:
//Reset to normal
BSX.flash_enable = false;
BSX.flash_bsr = false;
BSX.flash_csr = false;
BSX.flash_gsr = false;
BSX.read_enable = false;
BSX.write_enable = false;
BSX.flash_cmd_done = true;
break;
case 0x10: switch (BSX.flash_command & 0xFF)
case 0x40: {
//Write Byte case 0x00:
BSX.flash_enable = false; case 0xFF:
BSX.flash_bsr = false; //Reset to normal
BSX.flash_csr = true; BSX.flash_enable = false;
BSX.flash_gsr = false; BSX.flash_bsr = false;
BSX.read_enable = false; BSX.flash_csr = false;
BSX.write_enable = true; BSX.flash_gsr = false;
BSX.flash_cmd_done = true; BSX.read_enable = false;
break; BSX.write_enable = false;
BSX.flash_cmd_done = true;
break;
case 0x50: case 0x10:
//Clear Status Register case 0x40:
BSX.flash_enable = false; //Write Byte
BSX.flash_bsr = false; BSX.flash_enable = false;
BSX.flash_csr = false; BSX.flash_bsr = false;
BSX.flash_gsr = false; BSX.flash_csr = true;
BSX.flash_cmd_done = true; BSX.flash_gsr = false;
break; BSX.read_enable = false;
BSX.write_enable = true;
BSX.flash_cmd_done = true;
break;
case 0x70: case 0x50:
//Read CSR //Clear Status Register
BSX.flash_enable = false; BSX.flash_enable = false;
BSX.flash_bsr = false; BSX.flash_bsr = false;
BSX.flash_csr = true; BSX.flash_csr = false;
BSX.flash_gsr = false; BSX.flash_gsr = false;
BSX.read_enable = false; BSX.flash_cmd_done = true;
BSX.write_enable = false; break;
BSX.flash_cmd_done = true;
break;
case 0x71: case 0x70:
//Read Extended Status Registers (Page and Global) //Read CSR
BSX.flash_enable = false; BSX.flash_enable = false;
BSX.flash_bsr = true; BSX.flash_bsr = false;
BSX.flash_csr = false; BSX.flash_csr = true;
BSX.flash_gsr = true; BSX.flash_gsr = false;
BSX.read_enable = false; BSX.read_enable = false;
BSX.write_enable = false; BSX.write_enable = false;
BSX.flash_cmd_done = true; BSX.flash_cmd_done = true;
break; break;
case 0x75: case 0x71:
//Show Page Buffer / Vendor Info //Read Extended Status Registers (Page and Global)
BSX.flash_csr = false; BSX.flash_enable = false;
BSX.read_enable = true; BSX.flash_bsr = true;
BSX.flash_cmd_done = true; BSX.flash_csr = false;
break; BSX.flash_gsr = true;
BSX.read_enable = false;
BSX.write_enable = false;
BSX.flash_cmd_done = true;
break;
case 0xD0: case 0x75:
//DO COMMAND //Show Page Buffer / Vendor Info
switch (BSX.flash_command & 0xFFFF) BSX.flash_csr = false;
{ BSX.read_enable = true;
case 0x20D0: //Block Erase BSX.flash_cmd_done = true;
break;
case 0xD0:
//DO COMMAND
switch (BSX.flash_command & 0xFFFF)
{
case 0x20D0: //Block Erase
uint32 x;
for (x = 0; x < 0x10000; x++) {
//BSX_Set_Bypass_FlashIO(((address & 0xFF0000) + x), 0xFF);
if (BSX.MMC[0x02])
FlashROM[(address & 0x0F0000) + x] = 0xFF;
else
FlashROM[((address & 0x1E0000) >> 1) + x] = 0xFF;
}
break;
case 0xA7D0: //Chip Erase (ONLY IN TYPE 1 AND 4)
if ((flashcard[6] & 0xF0) == 0x10 || (flashcard[6] & 0xF0) == 0x40)
{
uint32 x; uint32 x;
for (x = 0; x < 0x10000; x++) { for (x = 0; x < FLASH_SIZE; x++) {
//BSX_Set_Bypass_FlashIO(((address & 0xFF0000) + x), 0xFF); //BSX_Set_Bypass_FlashIO(x, 0xFF);
if (BSX.MMC[0x02]) FlashROM[x] = 0xFF;
FlashROM[(address & 0x0F0000) + x] = 0xFF;
else
FlashROM[((address & 0x1E0000) >> 1) + x] = 0xFF;
} }
break; }
break;
case 0xA7D0: //Chip Erase (ONLY IN TYPE 1 AND 4) case 0x38D0: //Flashcart Reset
if ((flashcard[6] & 0xF0) == 0x10 || (flashcard[6] & 0xF0) == 0x40) break;
{ }
uint32 x; break;
for (x = 0; x < FLASH_SIZE; x++) {
//BSX_Set_Bypass_FlashIO(x, 0xFF);
FlashROM[x] = 0xFF;
}
}
break;
case 0x38D0: //Flashcart Reset
break;
}
break;
}
} }
} }