nes-make MMC1 work like the other mappers, instead of the very first mapper i made, which is to say, stupidly. TL;DR, speed it up 50%

This commit is contained in:
zeromus 2013-07-27 23:31:29 +00:00
parent 1280e47fed
commit cf655f3f54
1 changed files with 43 additions and 17 deletions

View File

@ -42,6 +42,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
SyncCHR();
}
public void Dispose()
{
chr_banks_4k.Dispose();
prg_banks_16k.Dispose();
}
public void SyncState(Serializer ser)
{
scnt.SyncState(ser);
@ -55,7 +61,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
ser.SyncEnum("mirror", ref mirror);
SyncCHR();
//ser.Sync("chr_banks_4k", ref chr_banks_4k, false);
SyncPRG();
}
public enum Rev
@ -78,7 +84,9 @@ namespace BizHawk.Emulation.Consoles.Nintendo
int wram_disable;
int prg;
int[] chr_banks_4k = new int[2];
//regenerable state
IntBuffer chr_banks_4k = new IntBuffer(2);
IntBuffer prg_banks_16k = new IntBuffer(4);
public class MMC1_SerialController
{
@ -144,6 +152,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
{
scnt.Write(addr, value);
SyncCHR();
SyncPRG();
}
//logical register writes, called from the serial controller
@ -186,31 +195,42 @@ namespace BizHawk.Emulation.Consoles.Nintendo
}
}
public int Get_PRGBank(int addr)
void SyncPRG()
{
int PRG_A14 = (addr >> 14) & 1;
if (prg_mode == 0)
if (PRG_A14 == 0)
return prg;
{
//switch 32kb
prg_banks_16k[0] = prg & ~1;
prg_banks_16k[1] = (prg & ~1) + 1;
}
else
{
//switch 16KB at...
if (prg_slot == 0)
{
//...$C000:
prg_banks_16k[0] = 0x1F;
prg_banks_16k[1] = prg;
}
else
{
//"not tested very well yet! had to guess!
return prg + 1;
//...$8000:
prg_banks_16k[0] = (prg & ~1) + 1;
prg_banks_16k[1] = 0x1F;
}
else if (prg_slot == 0)
if (PRG_A14 == 0)
return 0;
else return prg;
else
if (PRG_A14 == 0)
return prg;
else return 0xF;
}
}
public int Get_PRGBank(int addr)
{
int bank_16k = addr >> 14;
bank_16k = prg_banks_16k[bank_16k];
return bank_16k;
}
public int Get_CHRBank_4K(int addr)
{
int bank_4k = addr >> 12;
int ofs = addr & ((1 << 12) - 1);
bank_4k = chr_banks_4k[bank_4k];
return bank_4k;
}
@ -384,6 +404,12 @@ namespace BizHawk.Emulation.Consoles.Nintendo
ppuclock = pputimeout;
}
public override void Dispose()
{
base.Dispose();
mmc1.Dispose();
}
} //class SxROM