2024-07-26 17:52:33 +08:00
|
|
|
|
using System;
|
2024-07-23 18:31:59 +08:00
|
|
|
|
|
|
|
|
|
namespace VirtualNes.Core
|
|
|
|
|
{
|
2024-07-25 11:03:58 +08:00
|
|
|
|
public abstract class Mapper
|
2024-07-23 18:31:59 +08:00
|
|
|
|
{
|
2024-07-25 14:03:52 +08:00
|
|
|
|
protected NES nes;
|
2024-07-30 11:57:09 +08:00
|
|
|
|
|
2024-07-25 14:03:52 +08:00
|
|
|
|
public Mapper(NES parent)
|
|
|
|
|
{
|
|
|
|
|
nes = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Dispose() { }
|
|
|
|
|
|
|
|
|
|
public abstract void Reset();
|
|
|
|
|
|
|
|
|
|
// $8000-$FFFF Memory write
|
|
|
|
|
public virtual void Write(ushort addr, byte data) { }
|
|
|
|
|
// $8000-$FFFF Memory read(Dummy)
|
|
|
|
|
public virtual void Read(ushort addr, byte data) { }
|
|
|
|
|
|
|
|
|
|
// $4100-$7FFF Lower Memory read/write
|
|
|
|
|
public virtual byte ReadLow(ushort addr)
|
|
|
|
|
{
|
|
|
|
|
// $6000-$7FFF WRAM
|
|
|
|
|
if (addr >= 0x6000 && addr <= 0x7FFF)
|
|
|
|
|
{
|
2024-07-30 18:53:36 +08:00
|
|
|
|
return MMU.CPU_MEM_BANK[addr >> 13][addr & 0x1FFF];
|
2024-07-25 14:03:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (byte)(addr >> 8);
|
|
|
|
|
}
|
|
|
|
|
public virtual void WriteLow(ushort addr, byte data)
|
|
|
|
|
{
|
|
|
|
|
if (addr >= 0x6000 && addr <= 0x7FFF)
|
|
|
|
|
{
|
2024-07-30 18:53:36 +08:00
|
|
|
|
MMU.CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
|
2024-07-25 14:03:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// $4018-$40FF Extention register read/write
|
|
|
|
|
public virtual byte ExRead(ushort addr) { return 0x00; }
|
|
|
|
|
public virtual void ExWrite(ushort addr, byte data) { }
|
|
|
|
|
|
|
|
|
|
public virtual byte ExCmdRead(EXCMDRD cmd) { return 0x00; }
|
|
|
|
|
public virtual void ExCmdWrite(EXCMDWR cmd, byte data) { }
|
|
|
|
|
|
|
|
|
|
// H sync/V sync/Clock sync
|
|
|
|
|
public virtual void HSync(int scanline) { }
|
|
|
|
|
public virtual void VSync() { }
|
|
|
|
|
public virtual void Clock(int cycles) { }
|
|
|
|
|
// PPU address bus latch
|
|
|
|
|
public virtual void PPU_Latch(ushort addr) { }
|
|
|
|
|
// PPU Character latch
|
|
|
|
|
public virtual void PPU_ChrLatch(ushort addr) { }
|
|
|
|
|
// PPU Extension character/palette
|
|
|
|
|
public virtual void PPU_ExtLatchX(int x) { }
|
|
|
|
|
public virtual void PPU_ExtLatch(ushort addr, ref byte chr_l, ref byte chr_h, ref byte attr) { }
|
|
|
|
|
// For State save
|
|
|
|
|
public virtual bool IsStateSave() { return false; }
|
|
|
|
|
public virtual void SaveState(byte[] p) { }
|
|
|
|
|
public virtual void LoadState(byte[] p) { }
|
|
|
|
|
|
|
|
|
|
// Extension commands
|
|
|
|
|
// For ExCmdRead command
|
|
|
|
|
public enum EXCMDRD
|
|
|
|
|
{
|
|
|
|
|
EXCMDRD_NONE = 0,
|
|
|
|
|
EXCMDRD_DISKACCESS,
|
|
|
|
|
}
|
|
|
|
|
// For ExCmdWrite command
|
|
|
|
|
public enum EXCMDWR
|
|
|
|
|
{
|
|
|
|
|
EXCMDWR_NONE = 0,
|
|
|
|
|
EXCMDWR_DISKINSERT,
|
|
|
|
|
EXCMDWR_DISKEJECT,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Mapper CreateMapper(NES parent, int no)
|
|
|
|
|
{
|
2024-07-29 09:25:19 +08:00
|
|
|
|
//todo : 实现加载mapper
|
2024-07-25 14:03:52 +08:00
|
|
|
|
switch (no)
|
|
|
|
|
{
|
2024-07-30 11:57:09 +08:00
|
|
|
|
case 4:
|
|
|
|
|
return new Mapper004(parent);
|
2024-07-25 14:03:52 +08:00
|
|
|
|
default:
|
2024-07-30 11:57:09 +08:00
|
|
|
|
throw new NotImplementedException($"Mapper#{no:000} is not Impl");
|
2024-07-25 14:03:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-23 18:31:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|