changed 163 175 176 178 192

This commit is contained in:
sin365 2024-08-06 17:49:14 +08:00
parent ba1ac5d5c2
commit 44311f075b
5 changed files with 655 additions and 470 deletions

View File

@ -11,229 +11,229 @@ 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;
}
*/
{
//BYTE strobe;
//BYTE security;
//BYTE trigger;
//BYTE rom_type;
MemoryUtility.ZEROMEMORY(reg, reg.Length);
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()
{
}
}
//BYTE reg[2];
BYTE[] reg = new byte[3];
BYTE strobe, trigger;
ushort security;
BYTE rom_type;
INT www, index;
public Mapper163(NES parent) : base(parent)
{
}
static Int32[] index_adjust = new Int32[]{ -1, -1, -1, -1, 2, 4, 6, 8 };
static Int16[] step_table = new Int16[] {
7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,
60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,
307,337,371,408,449,494,544,598,658,724,796,876,963,1060,
1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024,3327,
3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,
11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767
};
BYTE adpcm_decoder(BYTE data)
{
int sb, delta;
int cur_sample = 0;
if ((data & 8) != 0) sb = 1; else sb = 0;
data &= 7;
delta = (step_table[index] * data) / 4 + step_table[index] / 8;
if (sb == 1) delta = -delta;
cur_sample += delta;
if (cur_sample > 32767) cur_sample = 32767;
else if (cur_sample < -32768) cur_sample = -32768;
else cur_sample = cur_sample;
index += index_adjust[data];
if (index < 0) index = 0;
if (index > 88) index = 88;
return (byte)(cur_sample & 0xff);
}
//void Mapper163::Reset()
public override void Reset()
{
index = 0;
reg[1] = 0xFF;
strobe = 1;
security = trigger = reg[0] = 0x00;
rom_type = 0;
SetPROM_32K_Bank(15);
// jedi_table_init();
uint 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]
|| crc == 0x696D98E3)
{ // San Guo Zhi Lv Bu Zhuan (NJ040) (Ch) [dump]
rom_type = 1;
}
if (crc == 0xEFF96E8A)
{ // Mo Shou Shi Jie E Mo Lie Ren (NJ097) (Ch) [dump]
rom_type = 2;
}
www = 0;
}
///BYTE Mapper163::ReadLow(WORD addr)
public override byte ReadLow(ushort addr)
{
// DEBUGOUT( "ReadLow - addr= %04x\n", addr );
if ((addr >= 0x5000 && addr < 0x6000))
{
switch (addr & 0x7700)
{
case 0x5100:
return (byte)security;
break;
case 0x5500:
if (trigger!=0)
return (byte)security;
else
return 0;
break;
}
return 4;
}
else if (addr >= 0x6000)
{
return CPU_MEM_BANK[addr >> 13][addr & 0x1FFF];
}
return base.ReadLow(addr);
}
//void Mapper163::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
// if(addr==0x5200) DEBUGOUT( "WriteLow - addr= %04x ; dat= %03x\n", addr, data );
if ((addr >= 0x4020 && addr < 0x6000))
{
if (addr == 0x5101)
{
if (strobe !=0 && data == 0)
{
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) == 0 && (nes.ppu.GetScanlineNo() < 128))
SetCRAM_8K_Bank(0);
if (rom_type == 1) SetCRAM_8K_Bank(0);
break;
case 0x5100:
reg[2] = data;
// nes.apu.Write(0x4011,(decode(reg[0]&0xf)<<3));
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 ((addr >= 0x7900 && addr <= 0x79FF))
{
// WAVRAM[addr&0xFF] = data;
// if(addr==0x79FF){
// memcpy( YWRAM+(www*256), WAVRAM, 256);
// www++;
// }
// nes.apu.Write(0x4011,(adpcm_decoder(data)));
nes.apu.Write(0x4011, data);
}
}
}
//void Mapper163::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
// DEBUGOUT( "Write - addr= %04x ; dat= %03x\n", addr, data );
}
//void Mapper163::HSync(int scanline)
public override void HSync(int scanline)
{
if ((reg[1] & 0x80) !=0 && 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 (rom_type == 2) SetCRAM_4K_Bank(4, 1);
}
}
}
}
///void Mapper163::PPU_Latch(WORD addr)
//{
// if (DirectInput.m_Sw[DIK_PAUSE])
// {
// nes.Dump_YWRAM();
// }
//}
//void Mapper163::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
p[0] = reg[0];
p[1] = reg[1];
}
//void Mapper163::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
reg[0] = p[0];
reg[1] = p[1];
}
}
}

View File

@ -18,51 +18,51 @@ namespace VirtualNes.Core
}
public override void Reset()
{
SetPROM_16K_Bank(4, 0);
SetPROM_16K_Bank(6, 0);
reg_dat = 0;
{
SetPROM_16K_Bank(4, 0);
SetPROM_16K_Bank(6, 0);
reg_dat = 0;
if (VROM_1K_SIZE != 0)
{
SetVROM_8K_Bank(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);
}
}
//BYTE Mapper175::Read(WORD addr)
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;
}
}
//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()
public override bool IsStateSave()
{
return true;
}

View File

@ -1,53 +1,233 @@
using static VirtualNes.MMU;
//////////////////////////////////////////////////////////////////////////
// Mapper176 ShuQiYu / HengGe / WaiXing //
//////////////////////////////////////////////////////////////////////////
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;
BYTE reg5000;
BYTE reg5001;
BYTE reg5010;
BYTE reg5011;
BYTE reg5013;
BYTE reg5FF1;
BYTE reg5FF2;
BYTE we_sram;
BYTE SBW, sp_rom;
public Mapper176(NES parent) : base(parent)
{
}
public override void Reset()
{
//prg = ~0;
prg = unchecked((byte)(~0));
chr = 0;
Sync();
if (PROM_16K_SIZE > 32)
{
SetPROM_32K_Bank(0, 1, (PROM_8K_SIZE / 2) - 2, (PROM_8K_SIZE / 2) - 1); //For 1M byte Cartridge
}
else
{
SetPROM_32K_Bank(0, 1, PROM_8K_SIZE - 2, PROM_8K_SIZE - 1);
}
// SetPROM_32K_Bank( PROM_8K_SIZE-4, PROM_8K_SIZE-3, PROM_8K_SIZE-2, PROM_8K_SIZE-1 );
if (VROM_1K_SIZE!=0) SetVROM_8K_Bank(0);
reg5000 = 0;
reg5001 = 0;
reg5010 = 0;
reg5011 = 0;
reg5013 = 0;
reg5FF1 = 0;
reg5FF2 = 0;
we_sram = 0;
SBW = 0;
sp_rom = 0;
uint crc = nes.rom.GetPROM_CRC();
if (crc == 0x095D8678 //[ES-0122] Shuang Yue Zhuan (C)
|| crc == 0xD5F7AAEF)
{ //[ES-XXXX] Shen Feng Jian (C)
sp_rom = 1;
nes.SetSAVERAM_SIZE(32 * 1024);
}
/*
crc == 0x416C07A1 //[ES-1006] Meng Huan Zhi Xing IV (C) & WXN-梦幻之星 √
crc == 0x94782FBD //[ES-1057] San Guo Zhi - Xiong Ba Tian Xia (C)
crc == 0xF9863ADF //[ES-1066] Xi Chu Ba Wang (C)
crc == 0xB511C04B //[ES-1071] San Xia Wu Yi (C)
crc == 0x1923A8C5 //[ES-1087] Shui Hu Shen Shou (C) & WXN-水浒神兽(fix) √
crc == 0x095D8678 //[ES-0122] Shuang Yue Zhuan (C)
crc == 0x8f6ab5ac //WXN-三国忠烈传 √
crc == 0x99051cb5 //WXN-雄霸天下 √
crc == 0xf29c8186 //WXN-大富翁2-上海大亨 √
crc == 0xc768098b //WXN-三侠五义 √
crc == 0x49f22159 //WXN-超级大富翁 √
crc == 0xf354d847 //WXN-格兰帝亚 √
crc == 0x5ee2ef97 //WXN-帝国时代(fix) √
crc == 0x977d22c3 //WXN-破釜沉舟(fix) √
crc == 0xf1d803f3 //WXN-西楚霸王(fix) √
crc == 0x85dd49b6 //WXN-口袋金(fix) √
crc == 0x97b82f53 //WXN-爆笑三国(fix) √
crc == 0xce2ea530 //WXN-宠物翡翠(fix) √
*/
}
void Sync()
//BYTE Mapper176::ReadLow(WORD addr)
public override byte ReadLow(ushort addr)
{
//setprg8r(0x10,0x6000,0);
SetPROM_32K_Bank(prg >> 1);
SetVROM_8K_Bank(chr);
if (sp_rom == 1)
{
if (addr >= 0x6000)
{
switch (we_sram)
{
case 0xE4:
case 0xEC: return WRAM[(addr & 0x1FFF) + 0x0000];
case 0xE5:
case 0xED: return WRAM[(addr & 0x1FFF) + 0x2000];
case 0xE6:
case 0xEE: return WRAM[(addr & 0x1FFF) + 0x4000];
case 0xE7:
case 0xEF: return WRAM[(addr & 0x1FFF) + 0x6000];
default: return CPU_MEM_BANK[addr >> 13][addr & 0x1FFF];
}
}
}
return base.ReadLow(addr);
}
//void Mapper176::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
// DEBUGOUT("Address=%04X Data=%02X\n", addr&0xFFFF, data&0xFF );
switch (addr)
{
case 0x5000:
reg5000 = data;
break;
case 0x5001: //[ES-1006] Meng Huan Zhi Xing IV (C)
reg5001 = data;
if (SBW!=0) SetPROM_32K_Bank(reg5001);
break;
case 0x5010:
reg5010 = data;
if (reg5010 == 0x24) SBW = 1;
break;
case 0x5011:
reg5011 = (byte)(data >> 1);
if (SBW!=0) SetPROM_32K_Bank(reg5011);
break;
case 0x5013:
reg5013 = data;
break;
case 0x5ff1:
prg = data; Sync();
reg5FF1 = (byte)(data >> 1);
SetPROM_32K_Bank(reg5FF1);
break;
case 0x5ff2:
chr = data; Sync();
break;
default:
reg5FF2 = data;
SetVROM_8K_Bank(reg5FF2);
break;
}
if (addr >= 0x6000)
if (sp_rom == 1)
{
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
if (addr >= 0x6000)
{
switch (we_sram)
{
case 0xE4: //CPU_MEM_BANK
case 0xEC: //CPU_MEM_BANK
WRAM[(addr & 0x1FFF) + 0x0000] = data;
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
break;
case 0xE5: //SRAM
case 0xED: //SRAM
WRAM[(addr & 0x1FFF) + 0x2000] = data;
break;
case 0xE6:
case 0xEE:
WRAM[(addr & 0x1FFF) + 0x4000] = data;
break;
case 0xE7:
case 0xEF:
WRAM[(addr & 0x1FFF) + 0x6000] = data;
break;
default:
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
break;
}
}
}
else
{
if (addr >= 0x6000)
{
// if ( we_sram == 0 ){
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
// }
}
}
}
//void Mapper176::Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
// DEBUGOUT("Address=%04X Data=%02X\n", addr&0xFFFF, data&0xFF );
if (addr == 0xa000)
{
data &= 0x03;
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);
}
if (addr == 0xa001)
{
// we_sram = data & 0x03;
we_sram = data;
}
}
//void Mapper176::SaveState(LPBYTE p)
public override void SaveState(byte[] p)
{
p[0] = reg5000;
p[1] = reg5001;
p[2] = reg5010;
p[3] = reg5011;
p[4] = reg5013;
p[5] = reg5FF1;
p[6] = reg5FF2;
p[7] = we_sram;
p[8] = SBW;
p[9] = sp_rom;
}
//void Mapper176::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
reg5000 = p[0];
reg5001 = p[1];
reg5010 = p[2];
reg5011 = p[3];
reg5013 = p[4];
reg5FF1 = p[5];
reg5FF2 = p[6];
we_sram = p[7];
SBW = p[8];
sp_rom = p[9];
}
public override bool IsStateSave()

View File

@ -1,8 +1,10 @@
using static VirtualNes.MMU;
//////////////////////////////////////////////////////////////////////////
// Mapper178 Education / WaiXing_FS305 //
//////////////////////////////////////////////////////////////////////////
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
@ -10,63 +12,66 @@ namespace VirtualNes.Core
public class Mapper178 : Mapper
{
BYTE[] reg = new byte[3];
BYTE banknum;
public Mapper178(NES parent) : base(parent)
BYTE banknum;
BYTE OP_rom;
public Mapper178(NES parent) : base(parent)
{
}
public override void Reset()
{
reg[0] = 0;
reg[1] = 0;
reg[2] = 0;
banknum = 0;
SetBank_CPU();
}
{
reg[0] = 0;
reg[1] = 0;
reg[2] = 0;
banknum = 0;
SetBank_CPU();
OP_rom = 0;
//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;
}
}
uint crc = nes.rom.GetPROM_CRC();
if (crc == 0x925926BC //[ES-XXXX] Kou Dai Zuan Shi Zhi Chong Wu Xiao Jing Ling 2 (C)
|| crc == 0xB0B13DBD) //[ES-XXXX] Chong Wu Fei Cui Zhi Chong Wu Xiao Jing Ling IV (C)
{
OP_rom = 1;
}
}
//void Write(WORD addr, BYTE data)
public override void Write(ushort addr, byte data)
{
// SetPROM_32K_Bank( data );
}
//void Mapper178::WriteLow(WORD addr, BYTE data)
public override void WriteLow(ushort addr, byte data)
{
// if( addr >= 0x4000 && addr <= 0x5FFF ) DEBUGOUT("Address=%04X Data=%02X\n", addr&0xFFFF, data&0xFF );
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);
if (OP_rom!=0) reg[0] = (byte)(data << 2);
SetBank_CPU();
}
else if (addr == 0x4802)
{
reg[1] = (byte)(data << 2);
if (OP_rom!=0) reg[1] = data;
SetBank_CPU();
}
else if (addr == 0x4803)
{
//unknown
reg[2] = data;
}
else if (addr >= 0x6000)
{
CPU_MEM_BANK[addr >> 13][addr & 0x1FFF] = data;
}
}
void SetBank_CPU()
{
banknum = (byte)((reg[0] + reg[1]) & 0x0f);
SetPROM_32K_Bank(banknum);
}
public override bool IsStateSave()
{
return true;
}
}
void SetBank_CPU()
{
banknum = (byte)(reg[0] | reg[1]);
// DEBUGOUT("Bank=%02X\n", banknum&0xFF );
SetPROM_32K_Bank(banknum);
}
}
}

View File

@ -13,43 +13,43 @@ 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 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)
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();
for (byte 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();
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;
}
we_sram = 0; // Disable
irq_enable = 0; // Disable
irq_counter = 0;
irq_latch = 0;
irq_request = 0;
}
//BYTE Mapper192::ReadLow(WORD addr)
@ -81,116 +81,116 @@ namespace VirtualNes.Core
//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() );
//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 (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;
}
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);
}
}
}
}
}
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()
{
@ -298,7 +298,7 @@ namespace VirtualNes.Core
//void Mapper192::LoadState(LPBYTE p)
public override void LoadState(byte[] p)
{
for (INT i = 0; i < 8; i++)
for (byte i = 0; i < 8; i++)
{
reg[i] = p[i];
}