diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs index 69991b2f0f..34346c51cc 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs @@ -1,4 +1,5 @@ //TODO - so many integers in the square wave output keep us from exactly unbiasing the waveform. also other waves probably +//TODO - DMC cpu suspending - http://forums.nesdev.com/viewtopic.php?p=62690#p62690 using System; using System.IO; @@ -592,6 +593,11 @@ namespace BizHawk.Emulation.Consoles.Nintendo Clock(); } + SyncSample(); + } + + void SyncSample() + { if (out_silence) sample = 0; else @@ -601,13 +607,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo } } - void SyncSample() - { - //sample = (out_deltacounter - 64) / 4; - //Console.WriteLine("dmc sample: {0}", sample); - //sample -= 64; //unbias - } - void Clock() { if (!out_silence) @@ -692,6 +691,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo break; case 1: out_deltacounter = val & 0x7F; + out_silence = false; //apu.nes.LogLine("~~ out_deltacounter set to {0}", out_deltacounter); SyncSample(); break; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs index d59a0735f9..991d6541b3 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs @@ -188,11 +188,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo public virtual byte ReadWRAM(int addr) { if (wram != null) return wram[addr & wram_mask]; - else return 0xFF; + else return NES.DB; } public virtual void WriteEXP(int addr, byte value) { } - public virtual byte ReadEXP(int addr) { return 0xFF; } + public virtual byte ReadEXP(int addr) { + return NES.DB; + } public virtual void WritePPU(int addr, byte value) { diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs index b403449bd1..4000311ec0 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Core.cs @@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo CartInfo cart; //the current cart prototype. should be moved into the board, perhaps INESBoard board; //the board hardware that is currently driving things public bool SoundOn = true; - int sprdma_countdown; //used to + int sprdma_countdown; bool _irq_apu; //various irq signals that get merged to the cpu irq pin //irq state management @@ -119,7 +119,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo { //its weird that this is 514.. normally itd be 512 (and people would say its wrong) or 513 (and people would say its right) //but 514 passes test 4-irq_and_dma - cpu_deadcounter = 514; + cpu_deadcounter += 514; } } @@ -259,6 +259,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo } } + //old data bus values from previous reads + public byte DB; + public byte ReadMemory(ushort addr) { byte ret; @@ -301,6 +304,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo ret = sysbus_watch[addr].ApplyGameGenie(ret); } + DB = ret; + return ret; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index ce0857388d..cef4a83e12 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -268,7 +268,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo { int ret = value & 1; value >>= 1; - return (byte)ret; + return (byte)(ret | nes.DB); } public override void Update() { @@ -621,7 +621,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo void SyncState(Serializer ser) { + int version = 2; ser.BeginSection("NES"); + ser.Sync("version", ref version); ser.Sync("Frame", ref _frame); ser.Sync("Lag", ref _lagcount); ser.Sync("IsLag", ref islag); @@ -639,6 +641,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo throw new InvalidOperationException("the current NES mapper didnt call base.SyncState"); ppu.SyncState(ser); apu.SyncState(ser); + if (version >= 2) + ser.Sync("DB", ref DB); + ser.EndSection(); }