nes-fiddle around with board irq signal tracking system. break every NES savestate. fix a desync bug in a bunch of mappers
This commit is contained in:
parent
690fb786a5
commit
1d254c3705
|
@ -39,6 +39,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
byte[] ROM { get; set; }
|
||||
byte[] VROM { get; set; }
|
||||
void SyncState(Serializer ser);
|
||||
bool IRQSignal { get; }
|
||||
|
||||
//mixes the board's custom audio into the supplied sample buffer
|
||||
void ApplyCustomAudio(short[] samples);
|
||||
|
@ -74,13 +75,17 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("vram", ref vram, true);
|
||||
ser.Sync("wram", ref wram, true);
|
||||
for (int i = 0; i < 4; i++) ser.Sync("mirroring" + i, ref mirroring[i]);
|
||||
ser.Sync("irq_signal", ref irq_signal);
|
||||
}
|
||||
|
||||
public virtual void SyncIRQ(bool flag)
|
||||
{
|
||||
NES.irq_cart = flag;
|
||||
IRQSignal = flag;
|
||||
}
|
||||
|
||||
private bool irq_signal;
|
||||
public bool IRQSignal { get { return irq_signal; } set { irq_signal = value; } }
|
||||
|
||||
public virtual void Dispose() { }
|
||||
|
||||
int[] mirroring = new int[4];
|
||||
|
|
|
@ -53,11 +53,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_asserted", ref irq_asserted);
|
||||
ser.Sync("clock_counter", ref clock_counter);
|
||||
|
||||
if (ser.IsReader)
|
||||
{
|
||||
SyncPRG();
|
||||
SyncIrq();
|
||||
}
|
||||
SyncPRG();
|
||||
SyncIrq();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
@ -169,7 +166,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIrq()
|
||||
{
|
||||
NES.irq_cart = irq_asserted;
|
||||
IRQSignal = irq_asserted;
|
||||
}
|
||||
|
||||
void ClockCPU()
|
||||
|
|
|
@ -66,12 +66,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("last_nt_read", ref last_nt_read);
|
||||
ser.Sync("EXRAM", ref EXRAM, false);
|
||||
|
||||
if (ser.IsReader)
|
||||
{
|
||||
SyncPRGBanks();
|
||||
SyncCHRBanks();
|
||||
SyncMultiplier();
|
||||
}
|
||||
SyncPRGBanks();
|
||||
SyncCHRBanks();
|
||||
SyncMultiplier();
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
@ -451,7 +449,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = (irq_pending && irq_enabled);
|
||||
IRQSignal = (irq_pending && irq_enabled);
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_counter", ref irq_counter);
|
||||
ser.Sync("irq_reload", ref irq_reload);
|
||||
ser.Sync("clock_counter", ref clock_counter);
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
@ -89,7 +90,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = irq_asserted;
|
||||
IRQSignal = irq_asserted;
|
||||
}
|
||||
|
||||
public override byte ReadPRG(int addr)
|
||||
|
|
|
@ -74,6 +74,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
public void Sync()
|
||||
{
|
||||
SyncIRQ();
|
||||
if (prg_mode)
|
||||
{
|
||||
prg_regs_8k[0] = 0xFE;
|
||||
|
@ -138,7 +139,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
Sync();
|
||||
}
|
||||
|
||||
protected virtual void SyncIRQ()
|
||||
//some MMC3 variants pass along the irq signal differently (primarily different delay)
|
||||
//this is overrideable so that those boards can get signals whenever this mmc3 base class code manipulates the irq line
|
||||
public virtual void SyncIRQ()
|
||||
{
|
||||
board.SyncIRQ(irq_pending);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_enabled", ref irq_enabled);
|
||||
ser.Sync("irq_asserted", ref irq_asserted);
|
||||
ser.Sync("clock_counter", ref clock_counter);
|
||||
SyncIrq();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
@ -171,7 +172,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIrq()
|
||||
{
|
||||
NES.irq_cart = irq_asserted;
|
||||
IRQSignal = irq_asserted;
|
||||
}
|
||||
|
||||
void ClockCPU()
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_enabled", ref irq_enabled);
|
||||
ser.Sync("irq_cycles", ref irq_cycles);
|
||||
ser.Sync("irq_pending", ref irq_pending);
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
@ -256,7 +257,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = (irq_pending && irq_enabled);
|
||||
IRQSignal = (irq_pending && irq_enabled);
|
||||
}
|
||||
|
||||
void TriggerIRQ()
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_enable", ref irq_enable);
|
||||
ser.Sync("irq_asserted", ref irq_asserted);
|
||||
ser.Sync("clock_counter", ref clock_counter);
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
@ -63,7 +64,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = irq_asserted;
|
||||
IRQSignal = irq_asserted;
|
||||
}
|
||||
|
||||
public override void WritePRG(int addr, byte value)
|
||||
|
|
|
@ -54,8 +54,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_reload_pending", ref irq_reload_pending);
|
||||
ser.Sync("separator_counter", ref separator_counter);
|
||||
|
||||
if (ser.IsReader)
|
||||
Sync();
|
||||
Sync();
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
@ -83,6 +82,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void Sync()
|
||||
{
|
||||
SyncIRQ();
|
||||
|
||||
if (prg_mode)
|
||||
{
|
||||
prg_banks_8k[0] = regs[0xF] & prg_bank_mask_8k;
|
||||
|
@ -189,7 +190,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public override byte ReadPRG(int addr)
|
||||
{
|
||||
int bank_8k = addr >> 13;
|
||||
|
@ -216,7 +216,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = irq_pending;
|
||||
IRQSignal = irq_pending;
|
||||
}
|
||||
|
||||
void ClockIRQ()
|
||||
|
|
|
@ -38,14 +38,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.EndSection();
|
||||
}
|
||||
|
||||
protected override void SyncIRQ()
|
||||
public override void SyncIRQ()
|
||||
{
|
||||
if (irq_pending && !pending)
|
||||
delay = 12; //supposed to be 4 cpu clocks
|
||||
if (!irq_pending)
|
||||
{
|
||||
delay = 0;
|
||||
board.NES.irq_cart = false;
|
||||
board.IRQSignal = false;
|
||||
}
|
||||
pending = irq_pending;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
{
|
||||
delay--;
|
||||
if(delay==0)
|
||||
board.NES.irq_cart = true;
|
||||
board.IRQSignal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,11 +51,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_prescaler", ref irq_prescaler);
|
||||
ser.Sync("extra_vrom", ref extra_vrom);
|
||||
|
||||
if (ser.IsReader)
|
||||
{
|
||||
SyncPRG();
|
||||
SyncCHR();
|
||||
}
|
||||
SyncPRG();
|
||||
SyncCHR();
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
void SyncPRG()
|
||||
|
@ -93,7 +91,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = (irq_pending && irq_enabled);
|
||||
IRQSignal = (irq_pending && irq_enabled);
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
|
|
@ -36,11 +36,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_reload", ref irq_reload);
|
||||
ser.Sync("irq_counter", ref irq_counter);
|
||||
ser.Sync("irq_cycles", ref irq_cycles);
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = (irq_pending && irq_enabled);
|
||||
IRQSignal = (irq_pending && irq_enabled);
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
|
|
@ -43,10 +43,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_counter", ref irq_counter);
|
||||
ser.Sync("irq_prescaler", ref irq_prescaler);
|
||||
|
||||
if (ser.IsReader)
|
||||
{
|
||||
SyncPRG();
|
||||
}
|
||||
SyncPRG();
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
void SyncPRG()
|
||||
|
@ -59,7 +57,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = (irq_pending && irq_enabled);
|
||||
IRQSignal = (irq_pending && irq_enabled);
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
|
|
@ -43,11 +43,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irq_reload", ref irq_reload);
|
||||
ser.Sync("irq_counter", ref irq_counter);
|
||||
ser.Sync("irq_prescaler", ref irq_prescaler);
|
||||
SyncIRQ();
|
||||
}
|
||||
|
||||
void SyncIRQ()
|
||||
{
|
||||
NES.irq_cart = (irq_pending && irq_enabled);
|
||||
IRQSignal = (irq_pending && irq_enabled);
|
||||
}
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
|
|
|
@ -24,15 +24,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
INESBoard board; //the board hardware that is currently driving things
|
||||
public bool SoundOn = true;
|
||||
int sprdma_countdown; //used to
|
||||
bool _irq_apu, _irq_cart; //various irq signals that get merged to the cpu irq pin
|
||||
bool _irq_apu; //various irq signals that get merged to the cpu irq pin
|
||||
|
||||
//irq state management
|
||||
public bool irq_apu { get { return _irq_apu; } set { _irq_apu = value; sync_irq(); } }
|
||||
public bool irq_cart { get { return _irq_cart; } set { _irq_cart = value; sync_irq(); } }
|
||||
void sync_irq()
|
||||
{
|
||||
cpu.IRQ = _irq_apu || _irq_cart;
|
||||
}
|
||||
public bool irq_apu { get { return _irq_apu; } set { _irq_apu = value; } }
|
||||
|
||||
//user configuration
|
||||
int[,] palette = new int[64,3];
|
||||
|
@ -119,10 +114,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
if(cpu_deadcounter>0)
|
||||
if (cpu_deadcounter > 0)
|
||||
cpu_deadcounter--;
|
||||
else
|
||||
{
|
||||
cpu.IRQ = _irq_apu || board.IRQSignal;
|
||||
cpu.ExecuteOne();
|
||||
}
|
||||
|
||||
if (SoundOn) apu.RunOne(); //THIS ISNT SAFE!!!!!!!!! SOUND MUST ALWAYS RUN!!!!
|
||||
ppu.PostCpuInstructionOne();
|
||||
|
|
|
@ -590,12 +590,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("CIRAM", ref CIRAM, false);
|
||||
ser.Sync("cpu_accumulate", ref cpu_accumulate);
|
||||
ser.Sync("_irq_apu", ref _irq_apu);
|
||||
ser.Sync("_irq_cart", ref _irq_cart);
|
||||
ser.Sync("sprdma_countdown", ref sprdma_countdown);
|
||||
ser.Sync("cpu_step", ref cpu_step);
|
||||
ser.Sync("cpu_stepcounter", ref cpu_stepcounter);
|
||||
ser.Sync("cpu_deadcounter", ref cpu_deadcounter);
|
||||
sync_irq();
|
||||
board.SyncState(ser);
|
||||
ppu.SyncState(ser);
|
||||
apu.SyncState(ser);
|
||||
|
|
Loading…
Reference in New Issue