Addon Special Lost Mapper 162,163,175,176,178,192,195,199,216

This commit is contained in:
sin365 2024-08-04 22:31:39 +08:00
parent f39ceedb0f
commit d5c8b8dc83
19 changed files with 1599 additions and 2 deletions

View File

@ -0,0 +1,131 @@
//////////////////////////////////////////////////////////////////////////
// Mapper162 Pocket Monster Gold //
//////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper162 : Mapper
{
BYTE reg5000;
BYTE reg5100;
BYTE reg5200;
BYTE reg5300;
public Mapper162(NES parent) : base(parent)
{
}
public override void Reset()
{
reg5000 = 0;
reg5100 = 0;
reg5200 = 0;
reg5300 = 7;
SetBank_CPU();
SetBank_PPU();
}
//void Mapper162::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
if (addr == 0x5000)
{
reg5000 = data;
SetBank_CPU();
SetBank_PPU();
}
else if (addr == 0x5100)
{
reg5100 = data;
SetBank_CPU();
SetBank_PPU();
}
else if (addr == 0x5200)
{
reg5200 = data;
SetBank_CPU();
SetBank_PPU();
}
else if (addr == 0x5300)
{
reg5300 = data;
}
else if (addr >= 0x6000)
{
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
}
else
{
DEBUGOUT("write to %04x:%02x\n", addr, data);
}
}
void SetBank_CPU()
{
BYTE bank = 0;
switch (reg5300)
{
case 4:
bank = (byte)((((reg5000 & 0xF) + ((reg5100 & 3) >> 1)) | ((reg5200 & 1) << 4)));
break;
case 7:
bank = (byte)(((reg5000 & 0xF) | ((reg5200 & 1) << 4)));
break;
}
SetPROM_32K_Bank((byte)bank);
}
void SetBank_PPU()
{
SetCRAM_8K_Bank(0);
}
//void Mapper162::HSync(int scanline)
public override void HSync(int scanline)
{
if ((reg5000 & 0x80) != 0 && nes.ppu.IsDispON())
{
if (scanline < 127)
{
// SetCRAM_4K_Bank(0, 0);
SetCRAM_4K_Bank(4, 0);
}
else if (scanline < 240)
{
// SetCRAM_4K_Bank(0, 1);
SetCRAM_4K_Bank(4, 1);
}
}
}
//void Mapper162::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
p[0] = reg5000;
p[1] = reg5100;
p[2] = reg5200;
p[3] = reg5300;
}
//void Mapper162::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
reg5000 = p[0];
reg5100 = p[1];
reg5200 = p[2];
reg5300 = p[3];
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2817bc9b8d92a134795cf9f72eff80bb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,238 @@
//////////////////////////////////////////////////////////////////////////
// Mapper163 NanJing Games //
//////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper163 : Mapper
{
//BYTE strobe;
//BYTE security;
//BYTE trigger;
//BYTE rom_type;
//BYTE reg[2];
BYTE laststrobe, trigger;
BYTE[] reg = new byte[8];
public Mapper163(NES parent) : base(parent)
{
/*
reg[1] = 0xFF;
strobe = 1;
security = trigger = reg[0] = 0x00;
rom_type = 0;
SetPROM_32K_Bank(15);
DWORD crc = nes.rom.GetPROM_CRC();
if( crc == 0xb6a10d5d ) { // Hu Lu Jin Gang (NJ039) (Ch) [dump]
SetPROM_32K_Bank(0);
}
if( crc == 0xf52468e7 ) { // San Guo Wu Shuang - Meng Jiang Zhuan (NJ047) (Ch) [dump]
rom_type = 1;
}
*/
memset(reg, 0, 8);
laststrobe = 1;
SetPROM_32K_Bank((reg[0] << 4) | (reg[1] & 0xF));
//SetPROM_32K_Bank(0);
SetCRAM_8K_Bank(0);
}
//BYTE Mapper163::ReadLow(WORD A)
public override byte ReadLow(ushort A)
{
/*
if((addr>=0x5000 && addr<0x6000))
{
switch (addr & 0x7700)
{
case 0x5100:
return security;
break;
case 0x5500:
if(trigger)
return security;
else
return 0;
break;
}
return 4;
}
else if( addr>=0x6000 ) {
return CPU_MEM_BANK[addr>>13][addr&0x1FFF];
}
return Mapper::ReadLow( addr );
*/
if ((A < 0x6000) && (A >= 0x5000))
{
switch (A & 0x7700)
{
case 0x5100: return (byte)(reg[2] | reg[0] | reg[1] | reg[3] ^ 0xff); break;
case 0x5500:
if (trigger != 0)
return (byte)(reg[2] | reg[1]); // Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games
else
return 0;
}
return 4;
}
else
return base.ReadLow(A);
}
//void Mapper163::WriteLow(WORD A, BYTE V)
public override void WriteLow(ushort A, byte V)
{
/*
if((addr>=0x4020 && addr<0x6000))
{
DEBUGOUT("W %.4X %.2X\n",addr,data);
if(addr==0x5101){
if(strobe && !data){
trigger ^= 1;
// trigger ^= 0xFF;
}
strobe = data;
}else if(addr==0x5100 && data==6){
SetPROM_32K_Bank(3);
}
else{
switch (addr & 0x7300)
{
case 0x5000:
reg[1]=data;
SetPROM_32K_Bank( (reg[1] & 0xF) | (reg[0] << 4) );
if(!(reg[1]&0x80)&&(nes.ppu.GetScanlineNo()<128))
SetCRAM_8K_Bank(0);
if(rom_type==1) SetCRAM_8K_Bank(0);
break;
case 0x5200:
reg[0]=data;
SetPROM_32K_Bank( (reg[1] & 0xF) | (reg[0] << 4) );
break;
case 0x5300:
security=data;
break;
}
}
}
else if( addr>=0x6000 ) {
CPU_MEM_BANK[addr>>13][addr&0x1FFF] = data;
}
*/
if ((A < 0x6000) && (A >= 0x5000))
{
if (A == 0x5300)
{
A = (ushort)(A + 1 - 1);
}
if (A == 0x5101)
{
if (laststrobe != 0 && V == 0)
{
trigger ^= 1;
}
laststrobe = V;
}
else if (A == 0x5100 && V == 6) //damn thoose protected games
SetPROM_32K_Bank(3);
else
{
switch (A & 0x7300)
{
case 0x5200: reg[0] = V; SetPROM_32K_Bank((reg[0] << 4) | reg[1] & 0xF); SetCRAM_8K_Bank(0); break;
case 0x5000: reg[1] = V; SetPROM_32K_Bank((reg[0] << 4) | reg[1] & 0xF); SetCRAM_8K_Bank(0); if ((reg[1] & 0x80) == 0 && (nes.GetScanline() < 128)) SetCRAM_8K_Bank(0); break;
case 0x5300: reg[2] = V; break;
case 0x5100: reg[3] = V; SetPROM_32K_Bank((reg[0] << 4) | reg[1] & 0xF); SetCRAM_8K_Bank(0); break;
}
}
}
//071
else if ((A & 0xFF00) == 0x4800)
{
//512KרÓÃ
if (PROM_8K_SIZE == 64)
{
reg[A & 3] = V;
if (A == 0x4802)
SetPROM_32K_Bank(((reg[1] >> 1) & 3) | (reg[2] << 2));
}
}
else
base.WriteLow(A, V);
}
//void Mapper163::HSync(int scanline)
public override void HSync(int scanline)
{
//sline = scanline;
/*
if( (reg[1]&0x80) && nes.ppu.IsDispON() ) {
if(scanline==127){
SetCRAM_4K_Bank(0, 1);
SetCRAM_4K_Bank(4, 1);
}
if (rom_type==1){
if(scanline<127){
SetCRAM_4K_Bank(0, 0);
SetCRAM_4K_Bank(4, 0);
}
}else{
if(scanline==239){
SetCRAM_4K_Bank(0, 0);
SetCRAM_4K_Bank(4, 0);
}
}
}
*/
if ((reg[1] & 0x80) != 0)
{
if (scanline == 239)
{
SetCRAM_4K_Bank(0, 0);
SetCRAM_4K_Bank(4, 0);
}
else if (scanline == 127)
{
SetCRAM_4K_Bank(0, 1);
SetCRAM_4K_Bank(4, 1);
}
}
}
//void Mapper163::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
//p[0] = reg[0];
//p[1] = reg[1];
for (byte i = 0; i < 8; i++)
p[i] = reg[i];
p[8] = laststrobe;
p[9] = trigger;
}
//void Mapper163::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
//reg[0] = p[0];
//reg[1] = p[1];
for (byte i = 0; i < 8; i++)
reg[i] = p[i];
laststrobe = p[8];
trigger = p[9];
}
public override void Reset()
{
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 843d6eb1b2987f94ea295eda54522756
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,71 @@
//////////////////////////////////////////////////////////////////////////
// Mapper175 15-in-1 (Kaiser) //
//////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper175 : Mapper
{
BYTE reg_dat;
public Mapper175(NES parent) : base(parent)
{
}
public override void Reset()
{
SetPROM_16K_Bank(4, 0);
SetPROM_16K_Bank(6, 0);
reg_dat = 0;
if (VROM_1K_SIZE != 0)
{
SetVROM_8K_Bank(0);
}
}
//void Mapper175::Read(WORD addr, BYTE data)
public override void Read(ushort addr, byte data)
{
if (addr == 0xFFFC)
{
SetPROM_16K_Bank(4, reg_dat & 0x0F);
SetPROM_8K_Bank(6, (reg_dat & 0x0F) * 2);
}
}
//void Mapper175::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
switch (addr)
{
case 0x8000:
if ((data & 0x04) != 0)
{
SetVRAM_Mirror(VRAM_HMIRROR);
}
else
{
SetVRAM_Mirror(VRAM_VMIRROR);
}
break;
case 0xA000:
reg_dat = data;
SetPROM_8K_Bank(7, (reg_dat & 0x0F) * 2 + 1);
SetVROM_8K_Bank(reg_dat & 0x0F);
break;
}
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 68d93abdcd8d7774ababf7b66976ee49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,58 @@
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
using System.Runtime.ConstrainedExecution;
namespace VirtualNes.Core
{
public class Mapper176 : Mapper
{
BYTE prg, chr;
public Mapper176(NES parent) : base(parent)
{
}
public override void Reset()
{
//prg = ~0;
prg = (~0);
chr = 0;
Sync();
}
void Sync()
{
//setprg8r(0x10,0x6000,0);
SetPROM_32K_Bank(prg >> 1);
SetVROM_8K_Bank(chr);
}
//void Mapper176::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
switch (addr)
{
case 0x5ff1:
prg = data; Sync();
break;
case 0x5ff2:
chr = data; Sync();
break;
default:
break;
}
if (addr >= 0x6000)
{
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
}
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9551cda80f1ab24993914b62a660fac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,72 @@
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper178 : Mapper
{
BYTE[] reg = new byte[3];
BYTE banknum;
public Mapper178(NES parent) : base(parent)
{
}
public override void Reset()
{
reg[0] = 0;
reg[1] = 0;
reg[2] = 0;
banknum = 0;
SetBank_CPU();
}
//void Mapper178::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
if (addr == 0x4800)
{
if ((data & 0x01) != 0) SetVRAM_Mirror(VRAM_HMIRROR);
else SetVRAM_Mirror(VRAM_VMIRROR);
}
else if (addr == 0x4801)
{
reg[0] = (byte)((data >> 1) & 0x0f);
SetBank_CPU();
}
else if (addr == 0x4802)
{
reg[1] = (byte)((data << 2) & 0x0f);
// SetBank_CPU();
}
else if (addr == 0x4803)
{
//unknown
}
else if (addr >= 0x6000)
{
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
}
}
//void Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
// SetPROM_32K_Bank( data );
}
void SetBank_CPU()
{
banknum = (byte)((reg[0] + reg[1]) & 0x0f);
SetPROM_32K_Bank(banknum);
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d281debb02f40d648b6b2d7355eec34b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,324 @@
//////////////////////////////////////////////////////////////////////////
// Mapper192 WaiXingTypeC Base ON Nintendo MMC3 //
//////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper192 : Mapper
{
BYTE[] reg = new byte[8];
BYTE prg0, prg1;
BYTE chr01, chr23, chr4, chr5, chr6, chr7;
BYTE we_sram;
BYTE irq_type;
BYTE irq_enable;
BYTE irq_counter;
BYTE irq_latch;
BYTE irq_request;
public Mapper192(NES parent) : base(parent)
{
}
public override void Reset()
{
for (INT i = 0; i < 8; i++)
{
reg[i] = 0x00;
}
prg0 = 0;
prg1 = 1;
SetBank_CPU();
chr01 = 0;
chr23 = 2;
chr4 = 4;
chr5 = 5;
chr6 = 6;
chr7 = 7;
SetBank_PPU();
we_sram = 0; // Disable
irq_enable = 0; // Disable
irq_counter = 0;
irq_latch = 0;
irq_request = 0;
}
//BYTE Mapper192::ReadLow(WORD addr)
public override byte ReadLow(ushort addr)
{
if (addr >= 0x5000 && addr <= 0x5FFF)
{
return XRAM[addr - 0x4000];
}
else
{
return base.ReadLow(addr);
}
}
//void Mapper192::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
if (addr >= 0x5000 && addr <= 0x5FFF)
{
XRAM[addr - 0x4000] = data;
}
else
{
base.WriteLow(addr, data);
}
}
//void Mapper192::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
//DEBUGOUT( "MPRWR A=%04X D=%02X L=%3d CYC=%d\n", addr&0xFFFF, data&0xFF, nes.GetScanline(), nes.cpu.GetTotalCycles() );
switch (addr & 0xE001)
{
case 0x8000:
reg[0] = data;
SetBank_CPU();
SetBank_PPU();
break;
case 0x8001:
reg[1] = data;
switch (reg[0] & 0x07)
{
case 0x00:
chr01 = data;
SetBank_PPU();
break;
case 0x01:
chr23 = data;
SetBank_PPU();
break;
case 0x02:
chr4 = data;
SetBank_PPU();
break;
case 0x03:
chr5 = data;
SetBank_PPU();
break;
case 0x04:
chr6 = data;
SetBank_PPU();
break;
case 0x05:
chr7 = data;
SetBank_PPU();
break;
case 0x06:
prg0 = data;
SetBank_CPU();
break;
case 0x07:
prg1 = data;
SetBank_CPU();
break;
}
break;
case 0xA000:
reg[2] = data;
if (!nes.rom.Is4SCREEN())
{
if ((data & 0x01) != 0) SetVRAM_Mirror(VRAM_HMIRROR);
else SetVRAM_Mirror(VRAM_VMIRROR);
}
break;
case 0xA001:
reg[3] = data;
break;
case 0xC000:
reg[4] = data;
irq_counter = data;
irq_request = 0;
break;
case 0xC001:
reg[5] = data;
irq_latch = data;
irq_request = 0;
break;
case 0xE000:
reg[6] = data;
irq_enable = 0;
irq_request = 0;
nes.cpu.ClrIRQ(IRQ_MAPPER);
break;
case 0xE001:
reg[7] = data;
irq_enable = 1;
irq_request = 0;
break;
}
}
//void Mapper192::HSync(INT scanline)
public override void HSync(int scanline)
{
if ((scanline >= 0 && scanline <= 239))
{
if (nes.ppu.IsDispON())
{
if (irq_enable != 0 && irq_request == 0)
{
if (scanline == 0)
{
if (irq_counter != 0)
{
irq_counter--;
}
}
if ((irq_counter--) == 0)
{
irq_request = 0xFF;
irq_counter = irq_latch;
nes.cpu.SetIRQ(IRQ_MAPPER);
}
}
}
}
}
void SetBank_CPU()
{
if ((reg[0] & 0x40) != 0)
{
SetPROM_32K_Bank(PROM_8K_SIZE - 2, prg1, prg0, PROM_8K_SIZE - 1);
}
else
{
SetPROM_32K_Bank(prg0, prg1, PROM_8K_SIZE - 2, PROM_8K_SIZE - 1);
}
}
void SetBank_PPU()
{
if (VROM_1K_SIZE != 0)
{
if ((reg[0] & 0x80) != 0)
{
// SetVROM_8K_Bank( chr4, chr5, chr6, chr7,
// chr01, chr01+1, chr23, chr23+1 );
SetBank_PPUSUB(4, chr01 + 0);
SetBank_PPUSUB(5, chr01 + 1);
SetBank_PPUSUB(6, chr23 + 0);
SetBank_PPUSUB(7, chr23 + 1);
SetBank_PPUSUB(0, chr4);
SetBank_PPUSUB(1, chr5);
SetBank_PPUSUB(2, chr6);
SetBank_PPUSUB(3, chr7);
}
else
{
// SetVROM_8K_Bank( chr01, chr01+1, chr23, chr23+1,
// chr4, chr5, chr6, chr7 );
SetBank_PPUSUB(0, chr01 + 0);
SetBank_PPUSUB(1, chr01 + 1);
SetBank_PPUSUB(2, chr23 + 0);
SetBank_PPUSUB(3, chr23 + 1);
SetBank_PPUSUB(4, chr4);
SetBank_PPUSUB(5, chr5);
SetBank_PPUSUB(6, chr6);
SetBank_PPUSUB(7, chr7);
}
}
else
{
if ((reg[0] & 0x80) != 0)
{
SetCRAM_1K_Bank(4, (chr01 + 0));
SetCRAM_1K_Bank(5, (chr01 + 1));
SetCRAM_1K_Bank(6, (chr23 + 0));
SetCRAM_1K_Bank(7, (chr23 + 1));
SetCRAM_1K_Bank(0, chr4);
SetCRAM_1K_Bank(1, chr5);
SetCRAM_1K_Bank(2, chr6);
SetCRAM_1K_Bank(3, chr7);
}
else
{
SetCRAM_1K_Bank(0, (chr01 + 0));
SetCRAM_1K_Bank(1, (chr01 + 1));
SetCRAM_1K_Bank(2, (chr23 + 0));
SetCRAM_1K_Bank(3, (chr23 + 1));
SetCRAM_1K_Bank(4, chr4);
SetCRAM_1K_Bank(5, chr5);
SetCRAM_1K_Bank(6, chr6);
SetCRAM_1K_Bank(7, chr7);
}
}
}
void SetBank_PPUSUB(int bank, int page)
{
if ((page & 0xFC) == 0x08)
{
SetCRAM_1K_Bank((byte)bank, page);
}
else
{
SetVROM_1K_Bank((byte)bank, page);
}
}
//void Mapper192::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
for (byte i = 0; i < 8; i++)
{
p[i] = reg[i];
}
p[8] = prg0;
p[9] = prg1;
p[10] = chr01;
p[11] = chr23;
p[12] = chr4;
p[13] = chr5;
p[14] = chr6;
p[15] = chr7;
p[16] = irq_enable;
p[17] = irq_counter;
p[18] = irq_latch;
p[19] = irq_request;
}
//void Mapper192::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
for (INT i = 0; i < 8; i++)
{
reg[i] = p[i];
}
prg0 = p[8];
prg1 = p[9];
chr01 = p[10];
chr23 = p[11];
chr4 = p[12];
chr5 = p[13];
chr6 = p[14];
chr7 = p[15];
irq_enable = p[16];
irq_counter = p[17];
irq_latch = p[18];
irq_request = p[19];
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebb5af01672a4364ab26bd0ce4543f07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,324 @@
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper195 : Mapper
{
BYTE[] reg = new BYTE[8];
BYTE prg0, prg1;
BYTE chr01, chr23, chr4, chr5, chr6, chr7;
BYTE we_sram;
BYTE irq_type;
BYTE irq_enable;
BYTE irq_counter;
BYTE irq_latch;
BYTE irq_request;
public Mapper195(NES parent) : base(parent)
{
}
public override void Reset()
{
for (INT i = 0; i < 8; i++)
{
reg[i] = 0x00;
}
prg0 = 0;
prg1 = 1;
SetBank_CPU();
chr01 = 0;
chr23 = 2;
chr4 = 4;
chr5 = 5;
chr6 = 6;
chr7 = 7;
SetBank_PPU();
we_sram = 0; // Disable
irq_enable = 0; // Disable
irq_counter = 0;
irq_latch = 0;
irq_request = 0;
}
//BYTE Mapper195::ReadLow(WORD addr)
public override byte ReadLow(ushort addr)
{
if (addr >= 0x5000 && addr <= 0x5FFF)
{
return XRAM[addr - 0x4000];
}
else
{
return base.ReadLow(addr);
}
}
//void Mapper195::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
if (addr >= 0x5000 && addr <= 0x5FFF)
{
XRAM[addr - 0x4000] = data;
}
else
{
base.WriteLow(addr, data);
}
}
//void Mapper195::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
//DEBUGOUT( "MPRWR A=%04X D=%02X L=%3d CYC=%d\n", addr&0xFFFF, data&0xFF, nes.GetScanline(), nes.cpu.GetTotalCycles() );
switch (addr & 0xE001)
{
case 0x8000:
reg[0] = data;
SetBank_CPU();
SetBank_PPU();
break;
case 0x8001:
reg[1] = data;
switch (reg[0] & 0x07)
{
case 0x00:
chr01 = data;
SetBank_PPU();
break;
case 0x01:
chr23 = data;
SetBank_PPU();
break;
case 0x02:
chr4 = data;
SetBank_PPU();
break;
case 0x03:
chr5 = data;
SetBank_PPU();
break;
case 0x04:
chr6 = data;
SetBank_PPU();
break;
case 0x05:
chr7 = data;
SetBank_PPU();
break;
case 0x06:
prg0 = data;
SetBank_CPU();
break;
case 0x07:
prg1 = data;
SetBank_CPU();
break;
}
break;
case 0xA000:
reg[2] = data;
if (!nes.rom.Is4SCREEN())
{
if (data == 0) SetVRAM_Mirror(VRAM_VMIRROR);
else if (data == 1) SetVRAM_Mirror(VRAM_HMIRROR);
else if (data == 2) SetVRAM_Mirror(VRAM_MIRROR4L);
else SetVRAM_Mirror(VRAM_MIRROR4H);
}
break;
case 0xA001:
reg[3] = data;
break;
case 0xC000:
reg[4] = data;
irq_counter = data;
irq_request = 0;
break;
case 0xC001:
reg[5] = data;
irq_latch = data;
irq_request = 0;
break;
case 0xE000:
reg[6] = data;
irq_enable = 0;
irq_request = 0;
nes.cpu.ClrIRQ(IRQ_MAPPER);
break;
case 0xE001:
reg[7] = data;
irq_enable = 1;
irq_request = 0;
break;
}
}
//void Mapper195::HSync(INT scanline)
public override void HSync(int scanline)
{
if ((scanline >= 0 && scanline <= 239))
{
if (nes.ppu.IsDispON())
{
if (irq_enable != 0 && irq_request == 0)
{
if (scanline == 0)
{
if (irq_counter != 0)
{
irq_counter--;
}
}
if ((irq_counter--) == 0)
{
irq_request = 0xFF;
irq_counter = irq_latch;
nes.cpu.SetIRQ(IRQ_MAPPER);
}
}
}
}
}
void SetBank_CPU()
{
if ((reg[0] & 0x40) != 0)
{
SetPROM_32K_Bank(PROM_8K_SIZE - 2, prg1, prg0, PROM_8K_SIZE - 1);
}
else
{
SetPROM_32K_Bank(prg0, prg1, PROM_8K_SIZE - 2, PROM_8K_SIZE - 1);
}
}
void SetBank_PPU()
{
if (VROM_1K_SIZE != 0)
{
if ((reg[0] & 0x80) != 0)
{
// SetVROM_8K_Bank( chr4, chr5, chr6, chr7,
// chr01, chr01+1, chr23, chr23+1 );
SetBank_PPUSUB(4, chr01 + 0);
SetBank_PPUSUB(5, chr01 + 1);
SetBank_PPUSUB(6, chr23 + 0);
SetBank_PPUSUB(7, chr23 + 1);
SetBank_PPUSUB(0, chr4);
SetBank_PPUSUB(1, chr5);
SetBank_PPUSUB(2, chr6);
SetBank_PPUSUB(3, chr7);
}
else
{
// SetVROM_8K_Bank( chr01, chr01+1, chr23, chr23+1,
// chr4, chr5, chr6, chr7 );
SetBank_PPUSUB(0, chr01 + 0);
SetBank_PPUSUB(1, chr01 + 1);
SetBank_PPUSUB(2, chr23 + 0);
SetBank_PPUSUB(3, chr23 + 1);
SetBank_PPUSUB(4, chr4);
SetBank_PPUSUB(5, chr5);
SetBank_PPUSUB(6, chr6);
SetBank_PPUSUB(7, chr7);
}
}
else
{
if ((reg[0] & 0x80) != 0)
{
SetCRAM_1K_Bank(4, (chr01 + 0));
SetCRAM_1K_Bank(5, (chr01 + 1));
SetCRAM_1K_Bank(6, (chr23 + 0));
SetCRAM_1K_Bank(7, (chr23 + 1));
SetCRAM_1K_Bank(0, chr4);
SetCRAM_1K_Bank(1, chr5);
SetCRAM_1K_Bank(2, chr6);
SetCRAM_1K_Bank(3, chr7);
}
else
{
SetCRAM_1K_Bank(0, (chr01 + 0));
SetCRAM_1K_Bank(1, (chr01 + 1));
SetCRAM_1K_Bank(2, (chr23 + 0));
SetCRAM_1K_Bank(3, (chr23 + 1));
SetCRAM_1K_Bank(4, chr4);
SetCRAM_1K_Bank(5, chr5);
SetCRAM_1K_Bank(6, chr6);
SetCRAM_1K_Bank(7, chr7);
}
}
}
void SetBank_PPUSUB(int bank, int page)
{
if (page <= 3)
{
SetCRAM_1K_Bank((byte)bank, page);
}
else
{
SetVROM_1K_Bank((byte)bank, page);
}
}
//void Mapper195::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
for (byte i = 0; i < 8; i++)
{
p[i] = reg[i];
}
p[8] = prg0;
p[9] = prg1;
p[10] = chr01;
p[11] = chr23;
p[12] = chr4;
p[13] = chr5;
p[14] = chr6;
p[15] = chr7;
p[16] = irq_enable;
p[17] = irq_counter;
p[18] = irq_latch;
p[19] = irq_request;
}
//void Mapper195::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
for (byte i = 0; i < 8; i++)
{
reg[i] = p[i];
}
prg0 = p[8];
prg1 = p[9];
chr01 = p[10];
chr23 = p[11];
chr4 = p[12];
chr5 = p[13];
chr6 = p[14];
chr7 = p[15];
irq_enable = p[16];
irq_counter = p[17];
irq_latch = p[18];
irq_request = p[19];
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9eac30ce838ece940b11ae5d5e5d6cfb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,246 @@
//////////////////////////////////////////////////////////////////////////
// Mapper199 WaiXingTypeG Base ON Nintendo MMC3 //
//////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper199 : Mapper
{
BYTE[] reg = new byte[8];
BYTE[] prg = new byte[4];
BYTE[] chr = new byte[8];
BYTE we_sram;
BYTE irq_type;
BYTE irq_enable;
BYTE irq_counter;
BYTE irq_latch;
BYTE irq_request;
public Mapper199(NES parent) : base(parent)
{
}
public override void Reset()
{
for (INT i = 0; i < 8; i++)
{
reg[i] = 0x00;
chr[i] = (byte)i;
}
prg[0] = 0x00;
prg[1] = 0x01;
prg[2] = 0x3e;
prg[3] = 0x3f;
SetBank_CPU();
SetBank_PPU();
we_sram = 0;
irq_enable = irq_counter = irq_latch = irq_request = 0;
uint crcP = nes.rom.GetPROM_CRC();
uint crcV = nes.rom.GetVROM_CRC();
if ((crcP == 0xE80D8741) || (crcV == 0x3846520D))
{//ÍâÐÇ°ÔÍõµÄ´ó½
nes.SetRenderMethod( EnumRenderMethod.POST_ALL_RENDER);
}
}
//BYTE Mapper199::ReadLow(WORD addr)
public override byte ReadLow(ushort addr)
{
if (addr >= 0x5000 && addr <= 0x5FFF)
{
return XRAM[addr - 0x4000];
}
else
{
return base.ReadLow(addr);
}
}
//void Mapper199::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
if (addr >= 0x5000 && addr <= 0x5FFF)
{
XRAM[addr - 0x4000] = data;
}
else
{
base.WriteLow(addr, data);
}
}
//void Mapper199::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
//DEBUGOUT( "MPRWR A=%04X D=%02X L=%3d CYC=%d\n", addr&0xFFFF, data&0xFF, nes.GetScanline(), nes.cpu.GetTotalCycles() );
switch (addr & 0xE001)
{
case 0x8000:
reg[0] = data;
SetBank_CPU();
SetBank_PPU();
break;
case 0x8001:
reg[1] = data;
switch (reg[0] & 0x0f)
{
case 0x00: chr[0] = data; SetBank_PPU(); break;
case 0x01: chr[2] = data; SetBank_PPU(); break;
case 0x02:
case 0x03:
case 0x04:
case 0x05: chr[(reg[0] & 0x07) + 2] = data; SetBank_PPU(); break;
case 0x06:
case 0x07:
case 0x08:
case 0x09: prg[(reg[0] & 0x0f) - 6] = data; SetBank_CPU(); break;
case 0x0A: chr[1] = data; SetBank_PPU(); break;
case 0x0B: chr[3] = data; SetBank_PPU(); break;
}
break;
case 0xA000:
reg[2] = data;
//if( !nes.rom.Is4SCREEN() )
{
if (data == 0) SetVRAM_Mirror(VRAM_VMIRROR);
else if (data == 1) SetVRAM_Mirror(VRAM_HMIRROR);
else if (data == 2) SetVRAM_Mirror(VRAM_MIRROR4L);
else SetVRAM_Mirror(VRAM_MIRROR4H);
}
break;
case 0xA001:
reg[3] = data;
break;
case 0xC000:
reg[4] = data;
irq_counter = data;
irq_request = 0;
break;
case 0xC001:
reg[5] = data;
irq_latch = data;
irq_request = 0;
break;
case 0xE000:
reg[6] = data;
irq_enable = 0;
irq_request = 0;
nes.cpu.ClrIRQ(IRQ_MAPPER);
break;
case 0xE001:
reg[7] = data;
irq_enable = 1;
irq_request = 0;
break;
}
}
//void Mapper199::HSync(INT scanline)
public override void HSync(int scanline)
{
if ((scanline >= 0 && scanline <= 239))
{
if (nes.ppu.IsDispON())
{
if (irq_enable != 0 && irq_request == 0)
{
if (scanline == 0)
{
if (irq_counter != 0)
{
irq_counter--;
}
}
if ((irq_counter--) == 0)
{
irq_request = 0xFF;
irq_counter = irq_latch;
nes.cpu.SetIRQ(IRQ_MAPPER);
}
}
}
}
}
void SetBank_CPU()
{
SetPROM_8K_Bank(4, prg[0 ^ (reg[0] >> 5 & ~(0 << 1) & 2)]);
SetPROM_8K_Bank(5, prg[1 ^ (reg[0] >> 5 & ~(1 << 1) & 2)]);
SetPROM_8K_Bank(6, prg[2 ^ (reg[0] >> 5 & ~(2 << 1) & 2)]);
SetPROM_8K_Bank(7, prg[3 ^ (reg[0] >> 5 & ~(3 << 1) & 2)]);
}
void SetBank_PPU()
{
//unsigned int bank = (reg[0] & 0x80) >> 5;
int bank = (reg[0] & 0x80) >> 5;
for (int x = 0; x < 8; x++)
{
if (chr[x] <= 7)
{
SetCRAM_1K_Bank((byte)(x ^ bank), chr[x]);
}
else
{
SetVROM_1K_Bank((byte)(x ^ bank), chr[x]);
}
}
}
//void Mapper199::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
for (INT i = 0; i < 8; i++)
{
p[i] = reg[i];
p[10 + i] = chr[i];
}
p[8] = prg[0];
p[9] = prg[1];
p[18] = irq_enable;
p[19] = irq_counter;
p[20] = irq_latch;
p[21] = irq_request;
p[22] = prg[2];
p[23] = prg[3];
}
//void Mapper199::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
for (INT i = 0; i < 8; i++)
{
reg[i] = p[i];
chr[i] = p[10 + i];
}
prg[0] = p[8];
prg[1] = p[9];
irq_enable = p[18];
irq_counter = p[19];
irq_latch = p[20];
irq_request = p[21];
prg[2] = p[22];
prg[3] = p[23];
}
public override bool IsStateSave()
{
return true;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ef80437f6f5f07b42882cf860f0b2de6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,33 @@
//////////////////////////////////////////////////////////////////////////
// Mapper216 //
//////////////////////////////////////////////////////////////////////////
using static VirtualNes.MMU;
using static VirtualNes.Core.CPU;
using INT = System.Int32;
using BYTE = System.Byte;
using System;
using Codice.CM.Client.Differences;
namespace VirtualNes.Core
{
public class Mapper216 : Mapper
{
public Mapper216(NES parent) : base(parent)
{
}
public override void Reset()
{
SetVROM_8K_Bank(0);
SetPROM_32K_Bank(0);
}
//void Mapper216::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
SetVROM_8K_Bank((addr & 0x0E) >> 1);
SetPROM_32K_Bank(addr & 1);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad42621060166644b8a3d544df5dc2ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -15,8 +15,9 @@ namespace VirtualNes.Core
public Mapper229(NES parent) : base(parent) public Mapper229(NES parent) : base(parent)
{ {
} }
public override void Read(ushort addr, byte data)
{ public override void Reset()
{
SetPROM_32K_Bank(0); SetPROM_32K_Bank(0);
SetVROM_8K_Bank(0); SetVROM_8K_Bank(0);
} }