Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper support for SuperFX 8MB ROM emulation #712

Merged
merged 1 commit into from Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion fxemu.cpp
Expand Up @@ -196,7 +196,7 @@ static void FxReset (struct FxInfo_s *psFxInfo)
else
{
b %= GSU.nRomBanks * 2;
GSU.apvRomBank[i] = &GSU.pvRom[(b << 16) + 0x200000];
GSU.apvRomBank[i] = &GSU.pvRom[(b << 16) + 0x800000];
}
}

Expand Down
60 changes: 49 additions & 11 deletions memmap.cpp
Expand Up @@ -1449,6 +1449,10 @@ bool8 CMemory::LoadROMInt (int32 ROMfillSize)
CalculatedSize = ((ROMfillSize + 0x1fff) / 0x2000) * 0x2000;

if (CalculatedSize > 0x400000 &&
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x1320 && // exclude SuperFX
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x1420 &&
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x1520 &&
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x1A20 &&
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x3423 && // exclude SA-1
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x3523 &&
(ROM[0x7fd5] + (ROM[0x7fd6] << 8)) != 0x4332 && // exclude S-DD1
Expand Down Expand Up @@ -3066,24 +3070,58 @@ void CMemory::Map_SuperFXLoROMMap (void)
printf("Map_SuperFXLoROMMap\n");
map_System();

// Replicate the first 2Mb of the ROM at ROM + 2MB such that each 32K
// Replicate the first 2Mb of the ROM at ROM + 8MB such that each 32K
// block is repeated twice in each 64K block.
for (int c = 0; c < 64; c++)
{
memmove(&ROM[0x200000 + c * 0x10000], &ROM[c * 0x8000], 0x8000);
memmove(&ROM[0x208000 + c * 0x10000], &ROM[c * 0x8000], 0x8000);
memmove(&ROM[0x800000 + c * 0x10000], &ROM[c * 0x8000], 0x8000);
memmove(&ROM[0x808000 + c * 0x10000], &ROM[c * 0x8000], 0x8000);
}

map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize);
map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize);
// Check GSU revision (not 100% accurate but it works)
// GSU2
if (CalculatedSize > 0x400000)
{
map_lorom(0x00, 0x3f, 0x8000, 0xffff, 0x200000);
map_lorom_offset(0x80, 0xbf, 0x8000, 0xffff, 0x200000, 0x200000);

map_hirom_offset(0x40, 0x7f, 0x0000, 0xffff, CalculatedSize, 0);
map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0);
map_hirom_offset(0x40, 0x5f, 0x0000, 0xffff, 0x200000, 0);
map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize - 0x400000, 0x400000);

map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x70, 0x70, 0x0000, 0xffff, SRAM);
map_space(0x71, 0x71, 0x0000, 0xffff, SRAM + 0x10000);
map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x70, 0x70, 0x0000, 0xffff, SRAM);
map_space(0x71, 0x71, 0x0000, 0xffff, SRAM + 0x10000);
}
else if (CalculatedSize > 0x200000)
{
map_lorom(0x00, 0x3f, 0x8000, 0xffff, 0x200000);
map_lorom_offset(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize - 0x200000, 0x200000);

map_hirom_offset(0x40, 0x5f, 0x0000, 0xffff, 0x200000, 0);
map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize - 0x200000, 0x200000);

map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x70, 0x70, 0x0000, 0xffff, SRAM);
map_space(0x71, 0x71, 0x0000, 0xffff, SRAM + 0x10000);
}
// GSU1
else
{
map_lorom(0x00, 0x3f, 0x8000, 0xffff, CalculatedSize);
map_lorom(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize);

map_hirom_offset(0x40, 0x5f, 0x0000, 0xffff, CalculatedSize, 0);
map_hirom_offset(0xc0, 0xdf, 0x0000, 0xffff, CalculatedSize, 0);

map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000);
map_space(0x70, 0x70, 0x0000, 0xffff, SRAM);
map_space(0x71, 0x71, 0x0000, 0xffff, SRAM + 0x10000);
map_space(0xf0, 0xf0, 0x0000, 0xffff, SRAM);
map_space(0xf1, 0xf1, 0x0000, 0xffff, SRAM + 0x10000);
}

map_WRAM();

Expand Down
2 changes: 1 addition & 1 deletion memmap.h
Expand Up @@ -15,7 +15,7 @@
struct CMemory
{
enum
{ MAX_ROM_SIZE = 0x800000 };
{ MAX_ROM_SIZE = 0xC00000 };

enum file_formats
{ FILE_ZIP, FILE_JMA, FILE_DEFAULT };
Expand Down