diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 0581efb55b..cc04200b3e 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -91,6 +91,7 @@ Code + Code diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs index ecd97ea62f..59b0ebb516 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs @@ -100,7 +100,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo } } - int ApplyMirroring(int addr) + protected int ApplyMirroring(int addr) { int block = (addr >> 10) & 3; block = mirroring[block]; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs new file mode 100644 index 0000000000..69a1dcf406 --- /dev/null +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs @@ -0,0 +1,125 @@ +using System; +using System.IO; +using System.Diagnostics; + +namespace BizHawk.Emulation.Consoles.Nintendo +{ + //AKA mapper 068 + + //After Burner 2 + //Maharaja + + class Sunsoft4 : NES.NESBoardBase + { + //configuration + int prg_bank_mask, chr_bank_mask, nt_bank_mask; + + //state + ByteBuffer chr_regs_2k = new ByteBuffer(4); + ByteBuffer nt_regs = new ByteBuffer(2); + ByteBuffer prg_regs_16k = new ByteBuffer(2); + bool flag_m, flag_r; + + public override void Dispose() + { + base.Dispose(); + chr_regs_2k.Dispose(); + nt_regs.Dispose(); + prg_regs_16k.Dispose(); + } + + public override bool Configure(NES.EDetectionOrigin origin) + { + //configure + switch (Cart.board_type) + { + case "SUNSOFT-4": + AssertPrg(128); AssertChr(128,256); AssertVram(0); AssertWram(8); + break; + default: + return false; + } + + SetMirrorType(EMirrorType.Vertical); + prg_regs_16k[1] = 0xFF; + prg_bank_mask = Cart.prg_size / 16 - 1; + chr_bank_mask = Cart.chr_size / 2 - 1; + nt_bank_mask = Cart.chr_size - 1; + return true; + } + + public override byte ReadPRG(int addr) + { + int bank_16k = addr >> 14; + int ofs = addr & ((1 << 14) - 1); + bank_16k = prg_regs_16k[bank_16k]; + bank_16k &= prg_bank_mask; + addr = (bank_16k << 14) | ofs; + return ROM[addr]; + } + + public override byte ReadPPU(int addr) + { + if (addr < 0x2000) + { + //chr comes from normal chr mapping + int bank_2k = addr >> 11; + int ofs = addr & ((1 << 11) - 1); + bank_2k = chr_regs_2k[bank_2k]; + bank_2k &= chr_bank_mask; + addr = (bank_2k << 11) | ofs; + return VROM[addr]; + } + else + { + //nametable may come from "NT-ROM" + //which means from extra CHR data starting at bank 0x80 + if (flag_r) + { + addr = ApplyMirroring(addr); + int bank_1k = (addr >> 10) & 3; + int ofs = addr & ((1 << 10) - 1); + bank_1k = nt_regs[bank_1k] + 0x80; + bank_1k &= nt_bank_mask; + addr = (bank_1k << 10) | ofs; + return VROM[addr]; + } + else return base.ReadPPU(addr); + } + } + + public override void WritePRG(int addr, byte value) + { + switch (addr & 0xF000) + { + case 0x0000: //$8000 + chr_regs_2k[0] = value; + break; + case 0x1000: //$9000 + chr_regs_2k[1] = value; + break; + case 0x2000: //$A000 + chr_regs_2k[2] = value; + break; + case 0x3000: //$B000 + chr_regs_2k[3] = value; + break; + case 0x4000: //$C000 + nt_regs[0] = (byte)(value & 0x7F); + break; + case 0x5000: //$D000 + nt_regs[1] = (byte)(value & 0x7F); + break; + case 0x6000: //$E000 + flag_m = (value & 1) != 0; + flag_r = ((value >> 4) & 1) != 0; + if (flag_m) SetMirrorType(EMirrorType.Horizontal); + else SetMirrorType(EMirrorType.Vertical); + break; + case 0x7000: //$F000 + prg_regs_16k[0] = value; + break; + } + } + } +} \ No newline at end of file diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs index 55cc4f5093..5f811050d4 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/iNES.cs @@ -91,6 +91,7 @@ static string ClassifyTable = @" 13 32 0 8 16 NES-CPROM; videomation 66 64 16 8 0 NES-MHROM; super mario bros / duck hunt 66 128 32 8 0 NES-GNROM; gumshoe +68 128 256 8 0 SUNSOFT-4; After Burner 2 (J) "; } diff --git a/BizHawk.MultiClient/output/gamedb.txt b/BizHawk.MultiClient/output/gamedb.txt index 72b6028865..1df246dae7 100644 --- a/BizHawk.MultiClient/output/gamedb.txt +++ b/BizHawk.MultiClient/output/gamedb.txt @@ -2263,6 +2263,7 @@ D4448D09BBFDE687C04F9E3310E023AB ti83_1.rom TI83 initPC=6ce ;--nes--; ;these games seem to be in goodNES but not bootgod's DB sha1:22E6986903141495BA4589AC65982F3FB4D0E37B Adventures of Lolo (U) NES board=NES-SEROM;PRG=32;CHR=32 +sha1:99C18C91F051BFBA6836A7B6B213C77569D83767 After Burner 2 (J) NES board=SUNSOFT-4;PRG=128;CHR=256;WRAM=8 sha1:CF655333DCE649A3C7060E9989860F2FC74E473A Demon Sword (U) NES board=NES-SL1ROM;PRG=128;CHR=128 sha1:7786BA1FE8E7E9E542EEB13CF2A6E2A1AD7F696D Metal Gear (U) NES board=KONAMI-UNROM;PRG=128 sha1:894F20405286F5F75133CE4648300E2C67972B40 Solomon's Key (U) NES board=NES-CNROM;PRG=32;CHR=32