nes: add ClockCPU() to INESBoard, for boards that count M2 cycles, and changed some mappers to use it. Mappers that need more inspection: Mapper027, SxROM, VRC2_4, VRC6, VRC7
This commit is contained in:
parent
59664959f1
commit
0d515dafdf
|
@ -23,6 +23,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
//gets called once per PPU clock, for boards with complex behaviour which must be monitoring clock (i.e. mmc3 irq counter)
|
||||
void ClockPPU();
|
||||
//gets called once per CPU clock; typically for boards with M2 counters
|
||||
void ClockCPU();
|
||||
|
||||
byte ReadPRG(int addr);
|
||||
byte ReadPPU(int addr); byte PeekPPU(int addr);
|
||||
|
@ -72,6 +74,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
public abstract bool Configure(NES.EDetectionOrigin origin);
|
||||
public virtual void ClockPPU() { }
|
||||
public virtual void ClockCPU() { }
|
||||
|
||||
public CartInfo Cart { get { return NES.cart; } }
|
||||
public NES NES { get; set; }
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
IRQSignal = irq_asserted;
|
||||
}
|
||||
|
||||
void ClockCPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
irq_counter--;
|
||||
if (irq_counter == 0x0000)
|
||||
|
@ -179,6 +179,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public override void ClockPPU()
|
||||
{
|
||||
clock_counter++;
|
||||
|
@ -187,7 +188,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ClockCPU();
|
||||
clock_counter = 0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public override byte ReadPRG(int addr)
|
||||
{
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public override void ClockPPU()
|
||||
{
|
||||
clock_counter++;
|
||||
|
@ -76,12 +76,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ClockCPU();
|
||||
clock_counter = 0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
void ClockCPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if(irq_counter==0) return;
|
||||
if(!irq_counter_enabled) return;
|
||||
if (irq_counter == 0) return;
|
||||
if (!irq_counter_enabled) return;
|
||||
irq_counter--;
|
||||
if (irq_counter != 0) return;
|
||||
irq_asserted = true;
|
||||
|
|
|
@ -220,12 +220,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
ppuclock++;
|
||||
if (ppuclock == 3)
|
||||
{
|
||||
ppuclock = 0;
|
||||
//ppuclock++;
|
||||
//if (ppuclock == 3)
|
||||
//{
|
||||
//ppuclock = 0;
|
||||
if (!irqcountpaused)
|
||||
{
|
||||
int newclock = irqclock - 1;
|
||||
|
@ -237,7 +237,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
else
|
||||
irqclock = newclock;
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -59,14 +59,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (irqactive)
|
||||
{
|
||||
irqcnt++;
|
||||
if (irqcnt >= 4096 * 3)
|
||||
if (irqcnt >= 4096)
|
||||
{
|
||||
irqcnt = 4096 * 3;
|
||||
irqcnt = 4096;
|
||||
IRQSignal = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,16 +79,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
return ROM[addr | prg << 13];
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (irqenable)
|
||||
{
|
||||
irqcnt++;
|
||||
|
||||
if (irqcnt >= 32768 * 3)
|
||||
irqcnt -= 32768 * 3;
|
||||
if (irqcnt >= 32768)
|
||||
irqcnt -= 32768;
|
||||
|
||||
IRQSignal = irqcnt >= 24576 * 3;
|
||||
IRQSignal = irqcnt >= 24576;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
IRQSignal = irq_asserted;
|
||||
}
|
||||
|
||||
void ClockCPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (!irq_countdown) return;
|
||||
irq_counter--;
|
||||
|
@ -189,6 +189,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public override void ClockPPU()
|
||||
{
|
||||
clock_counter++;
|
||||
|
@ -197,7 +198,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ClockCPU();
|
||||
clock_counter = 0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public override byte ReadPRG(int addr)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
{
|
||||
int prg = 0;
|
||||
int chr = 0;
|
||||
int irqclock = 2048 * 3;
|
||||
int irqclock = 2048;
|
||||
|
||||
public override bool Configure(NES.EDetectionOrigin origin)
|
||||
{
|
||||
|
@ -95,14 +95,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.Sync("irqclock", ref irqclock);
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (irqclock == 2048 * 3 - 1)
|
||||
if (irqclock == 2048 - 1)
|
||||
{
|
||||
irqclock++;
|
||||
IRQSignal = true;
|
||||
}
|
||||
else if (irqclock < 2048 * 3 - 1)
|
||||
else if (irqclock < 2048 - 1)
|
||||
{
|
||||
irqclock++;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
base.SyncIRQ(irq_ready);
|
||||
}
|
||||
|
||||
private void IRQ_Tick()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (irq_enable)
|
||||
{
|
||||
|
@ -100,6 +100,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public override void ClockPPU()
|
||||
{
|
||||
ppu_cyclecount++;
|
||||
|
@ -109,6 +110,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
IRQ_Tick();
|
||||
base.ClockPPU();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -302,21 +302,21 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
else irq_counter++;
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (irq_enabled)
|
||||
{
|
||||
irq_cycles--;
|
||||
if (irq_cycles == 0)
|
||||
{
|
||||
irq_cycles += 3;
|
||||
//irq_cycles--;
|
||||
//if (irq_cycles == 0)
|
||||
//{
|
||||
//irq_cycles += 3;
|
||||
ClockIRQ();
|
||||
}
|
||||
//}
|
||||
}
|
||||
if (audio != null)
|
||||
{
|
||||
audio_cycles++;
|
||||
if (audio_cycles == 15 * 3)
|
||||
if (audio_cycles == 15)
|
||||
{
|
||||
audio_cycles = 0;
|
||||
audio.Clock();
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
|
||||
|
||||
void ClockCPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (!irq_enable) return;
|
||||
if (irq_counter == 0)
|
||||
|
@ -143,6 +143,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
else return base.ReadPPU(addr);
|
||||
}
|
||||
|
||||
/*
|
||||
public override void ClockPPU()
|
||||
{
|
||||
clock_counter++;
|
||||
|
@ -151,6 +152,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
clock_counter = 0;
|
||||
ClockCPU();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,8 +135,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
void ClockIRQ()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if (!irq_enabled) return;
|
||||
if (irq_mode)
|
||||
{
|
||||
//8 bit mode
|
||||
|
@ -170,6 +171,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public override void ClockPPU()
|
||||
{
|
||||
if (!irq_enabled) return;
|
||||
|
@ -180,7 +182,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
irq_cycles += 3;
|
||||
ClockIRQ();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
|
@ -222,6 +222,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
|
||||
apu.RunOne();
|
||||
board.ClockCPU();
|
||||
ppu.PostCpuInstructionOne();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
#region state
|
||||
RamAdapter diskdrive;
|
||||
FDSAudio audio;
|
||||
/// <summary>0-2, how many ppu cycles since audio was last triggered</summary>
|
||||
int audioclock;
|
||||
/// <summary>currently loaded side of the .FDS image, 0 based</summary>
|
||||
int? currentside = null;
|
||||
/// <summary>collection of diffs (as provided by the RamAdapter) for each side in the .FDS image</summary>
|
||||
|
@ -60,7 +58,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
ser.BeginSection("audio");
|
||||
audio.SyncState(ser);
|
||||
ser.EndSection();
|
||||
ser.Sync("audioclock", ref audioclock);
|
||||
{
|
||||
// silly little hack
|
||||
int tmp = currentside != null ? (int)currentside : 1234567;
|
||||
|
@ -216,9 +213,6 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
bool timerirq { get { return _timerirq; } set { _timerirq = value; SetIRQ(); } }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public override void WriteEXP(int addr, byte value)
|
||||
{
|
||||
//if (addr == 0x0025)
|
||||
|
@ -244,7 +238,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
break;
|
||||
case 0x0022:
|
||||
timerreg = (byte)(value & 3);
|
||||
timervalue = timerlatch * 3;
|
||||
timervalue = timerlatch;
|
||||
break;
|
||||
case 0x0023:
|
||||
diskenable = (value & 1) != 0;
|
||||
|
@ -314,7 +308,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
return ret;
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
public override void ClockCPU()
|
||||
{
|
||||
if ((timerreg & 2) != 0 && timervalue > 0)
|
||||
{
|
||||
|
@ -323,7 +317,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
{
|
||||
if ((timerreg & 1) != 0)
|
||||
{
|
||||
timervalue = timerlatch * 3;
|
||||
timervalue = timerlatch;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -334,14 +328,13 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
timerirq = true;
|
||||
}
|
||||
}
|
||||
audio.Clock();
|
||||
}
|
||||
|
||||
public override void ClockPPU()
|
||||
{
|
||||
diskdrive.Clock();
|
||||
diskirq = diskdrive.irq;
|
||||
audioclock++;
|
||||
if (audioclock == 3)
|
||||
{
|
||||
audioclock = 0;
|
||||
audio.Clock();
|
||||
}
|
||||
}
|
||||
|
||||
public override byte ReadWRAM(int addr)
|
||||
|
|
Loading…
Reference in New Issue