[BS-X] Fix Memory Mapping, Force BS-X boot

This commit is contained in:
luigiblood 2016-11-08 14:34:53 +01:00
parent 6f2fe7e52b
commit 115c513424
1 changed files with 141 additions and 121 deletions

262
bsx.cpp
View File

@ -190,7 +190,7 @@
//#define BSX_DEBUG
#define BIOS_SIZE 0x100000
#define FLASH_SIZE 0x200000
#define FLASH_SIZE 0x100000
#define PSRAM_SIZE 0x80000
#define Map Memory.Map
@ -222,7 +222,7 @@ static const uint8 flashcard[20] =
{
0x4D, 0x00, 0x50, 0x00, // vendor id
0x00, 0x00, // ?
0x2B, 0x00, // 2MB Flash (1MB = 0x2A)
0x2A, 0x00, // 2MB Flash (1MB = 0x2A)
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
@ -408,13 +408,22 @@ static void map_psram_mirror_sub (uint32 bank)
{
for (c = 0; c < 0x100; c += 16)
{
for (i = c; i < c + 8; i++)
Map[i + bank] = &PSRAM[(c << 11) % PSRAM_SIZE];
if ((bank & 0x7F) >= 0x40)
{
for (i = c; i < c + 8; i++)
Map[i + bank] = &PSRAM[(c << 11) % PSRAM_SIZE];
for (i = c; i < c + 8; i++)
{
BlockIsRAM[i + bank] = TRUE;
BlockIsROM[i + bank] = FALSE;
}
}
for (i = c + 8; i < c + 16; i++)
Map[i + bank] = &PSRAM[(c << 11) % PSRAM_SIZE] - 0x8000;
for (i = c; i < c + 16; i++)
for (i = c + 8; i < c + 16; i++)
{
BlockIsRAM[i + bank] = TRUE;
BlockIsROM[i + bank] = FALSE;
@ -423,42 +432,126 @@ static void map_psram_mirror_sub (uint32 bank)
}
}
static void BSX_Map_PSRAM (void)
static void BSX_Map_PSRAM(void)
{
int c;
int c, i;
// Banks 70->77:0000-FFFF
// FIXME: could be toggled by $03
for (c = 0; c < 0x80; c++)
if (!BSX.MMC[0x02])
{
Map[c + 0x700] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
BlockIsRAM[c + 0x700] = TRUE;
BlockIsROM[c + 0x700] = FALSE;
}
//LoROM Mode
if (!BSX.MMC[0x05] && !BSX.MMC[0x06])
{
//Map PSRAM to 00-0F/80-8F
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x00);
// Banks 20->3F:6000-7FFF mirrors 70->77:6000-7FFF
for (c = 0x200; c < 0x400; c += 16)
if (BSX.MMC[0x04])
map_psram_mirror_sub(0x80);
}
else if (BSX.MMC[0x05] && !BSX.MMC[0x06])
{
//Map PSRAM to 20-2F/A0-AF
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x20);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xA0);
}
else if (!BSX.MMC[0x05] && BSX.MMC[0x06])
{
//Map PSRAM to 40-4F/C0-CF
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x40);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xC0);
}
else
{
//Map PSRAM to 60-6F/E0-EF
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x60);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xE0);
}
//Map PSRAM to 70-7D/F0-FF
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x70);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xF0);
}
else
{
Map[c + 6] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
Map[c + 7] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
BlockIsRAM[c + 6] = TRUE;
BlockIsRAM[c + 7] = TRUE;
BlockIsROM[c + 6] = FALSE;
BlockIsROM[c + 7] = FALSE;
//HiROM Mode
if (!BSX.MMC[0x05] && !BSX.MMC[0x06])
{
//Map PSRAM to 40-47/C0-C7
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x40);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xC0);
}
else if (BSX.MMC[0x05] && !BSX.MMC[0x06])
{
//Map PSRAM to 50-57/D0-D7
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x50);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xD0);
}
else if (!BSX.MMC[0x05] && BSX.MMC[0x06])
{
//Map PSRAM to 60-67/E0-E7
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x60);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xE0);
}
else
{
//Map PSRAM to 70-77/F0-F7
if (BSX.MMC[0x03])
map_psram_mirror_sub(0x70);
if (BSX.MMC[0x04])
map_psram_mirror_sub(0xF0);
}
if (BSX.MMC[0x03])
{
//Map PSRAM to 20->3F:6000-7FFF
for (c = 0x200; c < 0x400; c += 16)
{
Map[c + 6] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
Map[c + 7] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
BlockIsRAM[c + 6] = TRUE;
BlockIsRAM[c + 7] = TRUE;
BlockIsROM[c + 6] = FALSE;
BlockIsROM[c + 7] = FALSE;
}
}
if (BSX.MMC[0x04])
{
//Map PSRAM to A0->BF:6000-7FFF
for (c = 0xA00; c < 0xC00; c += 16)
{
Map[c + 6] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
Map[c + 7] = &PSRAM[((c & 0x70) << 12) % PSRAM_SIZE];
BlockIsRAM[c + 6] = TRUE;
BlockIsRAM[c + 7] = TRUE;
BlockIsROM[c + 6] = FALSE;
BlockIsROM[c + 7] = FALSE;
}
}
}
if (!BSX.MMC[0x05])
// Banks 40->4F:0000-FFFF mirrors 70->77:0000-7FFF
map_psram_mirror_sub(0x40);
if (!BSX.MMC[0x06])
// Banks 50->5F:0000-FFFF mirrors 70->77:0000-7FFF
map_psram_mirror_sub(0x50);
// FIXME
if (!BSX.MMC[0x03])
// Banks 60->6F:0000-FFFF mirrors 70->77:0000-7FFF (?)
map_psram_mirror_sub(0x60);
}
static void BSX_Map_BIOS (void)
@ -553,28 +646,8 @@ static void BSX_Map (void)
memcpy(BSX.prevMMC, BSX.MMC, sizeof(BSX.MMC));
// Do a quick bank change
if (BSX.dirty2 && !BSX.dirty)
{
BSX_Map_Dirty();
BSX_Map_BIOS();
BSX.dirty2 = FALSE;
Memory.map_WriteProtectROM();
return;
}
if (BSX.MMC[0x01])
{
MapROM = PSRAM;
FlashSize = PSRAM_SIZE;
}
else
{
MapROM = FlashROM;
FlashSize = FLASH_SIZE;
}
MapROM = FlashROM;
FlashSize = FLASH_SIZE;
BSX_Map_SNES();
@ -583,12 +656,12 @@ static void BSX_Map (void)
else
BSX_Map_LoROM();
BSX_Map_FlashIO();
BSX_Map_PSRAM();
BSX_Map_SRAM();
BSX_Map_RAM();
BSX_Map_BIOS();
BSX_Map_FlashIO();
BSX_Map_MMC();
// Monitor new register changes
@ -631,7 +704,7 @@ uint8 S9xGetBSX (uint32 address)
uint8 t = 0;
// MMC
if ((bank >= 0x01 && bank <= 0x0E) && (offset == 0x5000))
if ((bank >= 0x01 && bank <= 0x0E))
return (BSX.MMC[bank]);
// Flash IO
@ -679,43 +752,11 @@ void S9xSetBSX (uint8 byte, uint32 address)
uint16 offset = address & 0xFFFF;
// MMC
if ((bank >= 0x01 && bank <= 0x0E) && (offset == 0x5000))
if ((bank >= 0x01 && bank <= 0x0E))
{
switch (bank)
{
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x09:
case 0x0A:
case 0x0B:
case 0x0C:
case 0x0D:
if (BSX.MMC[bank] != byte)
{
BSX.MMC[bank] = byte;
BSX.dirty = TRUE;
}
break;
case 0x07:
case 0x08:
if (BSX.MMC[bank] != byte)
{
BSX.MMC[bank] = byte;
BSX.dirty2 = TRUE;
}
break;
case 0x0E:
BSX.MMC[bank] = byte;
if (byte && (BSX.dirty || BSX.dirty2))
BSX_Map();
break;
}
BSX.MMC[bank] = byte;
if (bank == 0x0E)
BSX_Map();
}
// Flash IO
@ -1073,7 +1114,7 @@ void S9xInitBSX (void)
uint8 *header = r1 ? Memory.ROM + 0x7FC0 : Memory.ROM + 0xFFC0;
FlashMode = (header[0x18] & 0xEF) == 0x20 ? FALSE : TRUE;
FlashSize = (header[0x19] & 0x20) ? PSRAM_SIZE : FLASH_SIZE;
FlashSize = FLASH_SIZE;
#ifdef BSX_DEBUG
for (int i = 0; i <= 0x1F; i++)
@ -1136,32 +1177,11 @@ void S9xResetBSX (void)
memset(BSX.output, 0, sizeof(BSX.output));
// starting from the bios
if (BSX.bootup)
BSX.MMC[0x07] = BSX.MMC[0x08] = 0x80;
else
{
BSX.MMC[0x02] = FlashMode ? 0x80: 0;
BSX.MMC[0x02] = BSX.MMC[0x03] = BSX.MMC[0x05] = BSX.MMC[0x06] = 0x80;
BSX.MMC[0x09] = BSX.MMC[0x0B] = 0x80;
// per bios: run from psram or flash card
if (FlashSize == PSRAM_SIZE)
{
memcpy(PSRAM, FlashROM, PSRAM_SIZE);
BSX.MMC[0x01] = 0x80;
BSX.MMC[0x03] = 0x80;
BSX.MMC[0x04] = 0x80;
BSX.MMC[0x0C] = 0x80;
BSX.MMC[0x0D] = 0x80;
}
else
{
BSX.MMC[0x03] = 0x80;
BSX.MMC[0x05] = 0x80;
BSX.MMC[0x06] = 0x80;
}
BSX.MMC[0x0E] = 0x80;
}
BSX.MMC[0x07] = BSX.MMC[0x08] = 0x80;
BSX.MMC[0x0E] = 0x80;
BSX_Map();
}