diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs index 223ef3be4c..790b3c5219 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/ExROM.cs @@ -13,21 +13,14 @@ using System.Diagnostics; //TODO - tweak nametable / chr viewer to be more useful +//FUTURE - we may need to split this into a separate MMC5 class. but for now it is just a pain. + namespace BizHawk.Emulation.Consoles.Nintendo { - class MMC5 - { - NES.NESBoardBase board; - public MMC5(NES.NESBoardBase board) - { - this.board = board; - } - } - public class ExROM : NES.NESBoardBase { //configuraton - int prg_bank_mask_8k, chr_bank_mask_1k; //board setup (to be isolated from ExROM later into mmc5 class) + int prg_bank_mask_8k, chr_bank_mask_1k; //board setup (to be isolated from mmc5 code later, when we need the separate mmc5 class) //state int irq_target, irq_counter; @@ -51,6 +44,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo public override void SyncState(Serializer ser) { + base.SyncState(ser); ser.Sync("irq_target", ref irq_target); ser.Sync("irq_counter", ref irq_counter); ser.Sync("irq_enabled", ref irq_enabled); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_G101.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_G101.cs index b6b46b70ec..6692073913 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_G101.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_G101.cs @@ -27,6 +27,15 @@ namespace BizHawk.Emulation.Consoles.Nintendo chr_regs_1k.Dispose(); } + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("prg_regs_8k", ref prg_regs_8k); + ser.Sync("chr_regs_1k", ref chr_regs_1k); + ser.Sync("prg_mode", ref chr_regs_1k); + ser.Sync("mirror_mode", ref chr_regs_1k); + } + public override bool Configure(NES.EDetectionOrigin origin) { //configure diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_H3001.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_H3001.cs index 8cb6c14195..2ea1b26f67 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_H3001.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Irem_H3001.cs @@ -30,6 +30,18 @@ namespace BizHawk.Emulation.Consoles.Nintendo chr_regs_1k.Dispose(); } + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("prg_regs_8k", ref prg_regs_8k); + ser.Sync("chr_regs_1k", ref chr_regs_1k); + ser.Sync("irq_counter_enabled", ref irq_counter_enabled); + ser.Sync("irq_asserted", ref irq_asserted); + ser.Sync("irq_counter", ref irq_counter); + ser.Sync("irq_reload", ref irq_reload); + ser.Sync("clock_counter", ref clock_counter); + } + public override bool Configure(NES.EDetectionOrigin origin) { //configure diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs index cdf550580f..827211de5a 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/MMC3_family.cs @@ -20,8 +20,14 @@ using System.Diagnostics; namespace BizHawk.Emulation.Consoles.Nintendo { + // this is the base class for the MMC3 mapper public class Namcot109 : IDisposable { + //state + public int chr_mode, prg_mode, reg_addr; + ByteBuffer chr_regs_1k = new ByteBuffer(8); + ByteBuffer prg_regs_8k = new ByteBuffer(8); + protected NES.NESBoardBase board; public Namcot109(NES.NESBoardBase board) { @@ -52,11 +58,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo prg_regs_8k.Dispose(); } - //state - public int chr_mode, prg_mode, reg_addr; - - ByteBuffer chr_regs_1k = new ByteBuffer(8); - ByteBuffer prg_regs_8k = new ByteBuffer(8); + public virtual void SyncState(Serializer ser) + { + ser.Sync("chr_mode", ref chr_mode); + ser.Sync("prg_mode", ref prg_mode); + ser.Sync("reg_addr", ref reg_addr); + ser.Sync("chr_regs_1k", ref chr_regs_1k); + ser.Sync("prg_regs_8k", ref prg_regs_8k); + } public virtual void WritePRG(int addr, byte value) { @@ -106,16 +115,38 @@ namespace BizHawk.Emulation.Consoles.Nintendo public class MMC3 : Namcot109 { + //state + public byte mirror; + int a12_old; + byte irq_reload, irq_counter; + bool irq_pending, irq_enable; + + //it really seems like these should be the same but i cant seem to unify them. + //theres no sense in delaying the IRQ, so its logic must be tied to the separator. + //the hint, of course, is that the countdown value is the same. + //will someone else try to unify them? + int separator_counter; + int irq_countdown; + + public NES.NESBoardBase.EMirrorType MirrorType { get { return mirror == 0 ? NES.NESBoardBase.EMirrorType.Vertical : NES.NESBoardBase.EMirrorType.Horizontal; } } + public MMC3(NES.NESBoardBase board, int num_prg_banks) : base(board) { } - //state - public NES.NESBoardBase.EMirrorType mirror; - int a12_old; - byte irq_reload, irq_counter; - bool irq_pending, irq_enable; + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("mirror", ref mirror); + ser.Sync("mirror", ref a12_old); + ser.Sync("irq_reload", ref irq_reload); + ser.Sync("irq_counter", ref irq_counter); + ser.Sync("irq_pending", ref irq_pending); + ser.Sync("irq_enable", ref irq_enable); + ser.Sync("separator_counter", ref separator_counter); + ser.Sync("irq_countdown", ref irq_countdown); + } void SyncIRQ() { @@ -132,9 +163,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo break; case 0x2000: //$A000 //mirroring - if ((value & 1) == 0) mirror = NES.NESBoardBase.EMirrorType.Vertical; - else mirror = NES.NESBoardBase.EMirrorType.Horizontal; - board.SetMirrorType(mirror); + mirror = (byte)(value & 1); + board.SetMirrorType(MirrorType); break; case 0x2001: //$A001 //wram enable/protect @@ -189,13 +219,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo } } - //it really seems like these should be the same but i cant seem to unify them. - //theres no sense in delaying the IRQ, so its logic must be tied to the separator. - //the hint, of course, is that the countdown value is the same. - //will someone else try to unify them? - int separator_counter; - int irq_countdown; - public void ClockPPU() { if (separator_counter > 0) @@ -237,6 +260,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo public abstract class MMC3_Family_Board_Base : NES.NESBoardBase { + protected Namcot109 mapper; + //configuration protected int prg_mask, chr_mask; @@ -245,7 +270,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo mapper.Dispose(); } - protected Namcot109 mapper; + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + mapper.SyncState(ser); + } int MapCHR(int addr) { diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/TxROM.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/TxROM.cs index d00adcca5c..c9476b313a 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/TxROM.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/MMC3_family/TxROM.cs @@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo public override void WritePRG(int addr, byte value) { base.WritePRG(addr, value); - SetMirrorType(mmc3.mirror); //often redundant, but gets the job done + SetMirrorType(mmc3.MirrorType); //often redundant, but gets the job done } public override byte[] SaveRam diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs index 69a1dcf406..0f72cae274 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Sunsoft4.cs @@ -28,6 +28,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo prg_regs_16k.Dispose(); } + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("chr_regs_2k", ref chr_regs_2k); + ser.Sync("nt_regs", ref nt_regs); + ser.Sync("prg_regs_16k", ref prg_regs_16k); + ser.Sync("flag_m", ref flag_m); + ser.Sync("flag_r", ref flag_r); + } + public override bool Configure(NES.EDetectionOrigin origin) { //configure diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs index a62a8eea3b..4549ec4302 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Taito_TC0190FMC.cs @@ -28,6 +28,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo chr_regs_1k.Dispose(); } + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("prg_regs_8k", ref prg_regs_8k); + ser.Sync("chr_regs_1k", ref chr_regs_1k); + ser.Sync("mirror_mode", ref mirror_mode); + } + public override bool Configure(NES.EDetectionOrigin origin) { //configure