From 663aeaf5eb6c80eab435d505b438357368bda7b0 Mon Sep 17 00:00:00 2001 From: goyuken Date: Sat, 3 May 2014 17:23:28 +0000 Subject: [PATCH] NES: add mapper31, fix a few small bugs with mapper30. thanks to caitsith6502 for patch --- .../BizHawk.Emulation.Cores.csproj | 1 + .../Consoles/Nintendo/NES/Boards/Mapper030.cs | 36 ++++++----- .../Consoles/Nintendo/NES/Boards/inlnsf.cs | 59 +++++++++++++++++++ 3 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/inlnsf.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index d3a8627e57..523868320b 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -262,6 +262,7 @@ + diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper030.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper030.cs index 454cf1088f..77ef96096d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper030.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/Mapper030.cs @@ -36,18 +36,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { if (flash_rom == null) return; - int[] value = new int[1]; + uint[] value = new uint[1]; int bank = (addr >= 0x4000) ? prg_bank_mask_16k : prg; if (!direct) { Buffer.BlockCopy(flash_rom, (bank << 2 | (addr >> 12) & 3) << 2, value, 0, 4); - value[0]++; + if(value[0] < 0xFFFFFFFF) value[0]++; Buffer.BlockCopy(value, 0, flash_rom, (bank << 2 | (addr >> 12) & 3) << 2, 4); } else { Buffer.BlockCopy(flash_rom, addr << 2, value, 0, 4); - value[0]++; + if (value[0] < 0xFFFFFFFF) value[0]++; Buffer.BlockCopy(value, 0, flash_rom, addr << 2, 4); } } @@ -196,18 +196,24 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { if (flash_mode == flashmode.fm_id) { - if ((addr & 1) == 0) - return 0xBF; - else - switch (Cart.prg_size) - { - case 128: - return 0xB5; - case 256: - return 0xB6; - case 512: - return 0xB7; - } + switch (addr & 0x1FF) + { + case 0: + return 0xBF; + case 1: + switch (Cart.prg_size) + { + case 128: + return 0xB5; + case 256: + return 0xB6; + case 512: + return 0xB7; + } + return 0xFF; //Shouldn't ever reach here, as the size was asserted earlier. + default: + return 0xFF; //Other unknown data is returned from addresses 2-511, in software ID mode, mostly 0xFF. + } } if (get_flash_write_count(addr) > 0) return flash_rom[Cart.prg_size + (bank << 14 | addr & 0x3fff)]; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/inlnsf.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/inlnsf.cs new file mode 100644 index 0000000000..f788e86df5 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/inlnsf.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Nintendo.NES +{ + public class INLNSF : NES.NESBoardBase + { + + // config + int prg_bank_mask_4k; + + // state + int[] prg = new int[8]; + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("prg", ref prg, true); + } + + public override bool Configure(NES.EDetectionOrigin origin) + { + switch (Cart.board_type) + { + case "MAPPER031": + Cart.vram_size = 8; + break; + case "MAPPER0031-00": + AssertVram(8); + break; + default: + return false; + } + SetMirrorType(CalculateMirrorType(Cart.pad_h, Cart.pad_v)); + AssertChr(0); + AssertPrg(16, 32, 64, 128, 256, 512, 1024); + Cart.wram_size = 0; + prg_bank_mask_4k = Cart.prg_size / 4 - 1; + prg[7] = prg_bank_mask_4k; + return true; + } + + public override void WriteEXP(int addr, byte value) + { + if (addr >= 0x1000) + prg[addr & 0x07] = value & prg_bank_mask_4k; + else + base.WriteEXP(addr, value); + } + + public override byte ReadPRG(int addr) + { + return ROM[prg[(addr & 0x7000)>>12] << 12 | addr & 0x0fff]; + } + } +}