AxibugEmuOnline/Core/VirtualNes.Core/Mapper/Mapper073.cs

97 lines
2.8 KiB
C#
Raw Permalink Normal View History

//////////////////////////////////////////////////////////////////////////
// Mapper073 Konami VRC3 //
//////////////////////////////////////////////////////////////////////////
using System;
using static VirtualNes.Core.CPU;
using static VirtualNes.MMU;
using BYTE = System.Byte;
using INT = System.Int32;
namespace VirtualNes.Core
{
public class Mapper073 : Mapper
{
BYTE irq_enable;
INT irq_counter;
public Mapper073(NES parent) : base(parent)
{
}
public override void Reset()
{
irq_enable = 0;
irq_counter = 0;
SetPROM_32K_Bank(0, 1, PROM_8K_SIZE - 2, PROM_8K_SIZE - 1);
}
//void Mapper073::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
switch (addr)
{
case 0xF000:
SetPROM_16K_Bank(4, data);
break;
case 0x8000:
irq_counter = (irq_counter & 0xFFF0) | (data & 0x0F);
break;
case 0x9000:
irq_counter = (irq_counter & 0xFF0F) | ((data & 0x0F) << 4);
break;
case 0xA000:
irq_counter = (irq_counter & 0xF0FF) | ((data & 0x0F) << 8);
break;
case 0xB000:
irq_counter = (irq_counter & 0x0FFF) | ((data & 0x0F) << 12);
break;
case 0xC000:
irq_enable = (byte)(data & 0x02);
nes.cpu.ClrIRQ(IRQ_MAPPER);
break;
case 0xD000:
nes.cpu.ClrIRQ(IRQ_MAPPER);
break;
}
}
//void Mapper073::Clock(INT cycles)
public override void Clock(int cycles)
{
if (irq_enable != 0)
{
if ((irq_counter += cycles) >= 0xFFFF)
{
irq_enable = 0;
irq_counter &= 0xFFFF;
nes.cpu.SetIRQ(IRQ_MAPPER);
}
}
}
//void Mapper073::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
p[0] = irq_enable;
//*(INT*)&p[1] = irq_counter;
BitConverter.GetBytes(irq_counter).CopyTo(p, 1);
}
//void Mapper073::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
irq_enable = p[0];
//irq_counter = *(INT*)&p[1];
irq_counter = BitConverter.ToInt32(p, 1);
}
public override bool IsStateSave()
{
return true;
}
}
}