NES - remove a bit more partial class as namespace abuse

This commit is contained in:
adelikat 2015-01-17 21:02:59 +00:00
parent 40bfe91238
commit 3b2c00cf39
10 changed files with 689 additions and 695 deletions

File diff suppressed because it is too large Load Diff

View File

@ -333,50 +333,50 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
return board;
}
public string BoardName { get { return board.GetType().Name; } }
public string BoardName { get { return Board.GetType().Name; } }
void BoardSystemHardReset()
{
INESBoard newboard;
// fds has a unique activation setup
if (board is FDS)
if (Board is FDS)
{
var newfds = new FDS();
var oldfds = board as FDS;
var oldfds = Board as FDS;
newfds.biosrom = oldfds.biosrom;
newfds.SetDiskImage(oldfds.GetDiskImage());
newboard = newfds;
}
else
{
newboard = CreateBoardInstance(board.GetType());
newboard = CreateBoardInstance(Board.GetType());
}
newboard.Create(this);
// i suppose the old board could have changed its initial register values, although it really shouldn't
// you can't use SyncSettings.BoardProperties here because they very well might be different than before
// in case the user actually changed something in the UI
newboard.InitialRegisterValues = board.InitialRegisterValues;
newboard.InitialRegisterValues = Board.InitialRegisterValues;
newboard.Configure(origin);
newboard.ROM = board.ROM;
newboard.VROM = board.VROM;
if (board.WRAM != null)
newboard.WRAM = new byte[board.WRAM.Length];
if (board.VRAM != null)
newboard.VRAM = new byte[board.VRAM.Length];
newboard.ROM = Board.ROM;
newboard.VROM = Board.VROM;
if (Board.WRAM != null)
newboard.WRAM = new byte[Board.WRAM.Length];
if (Board.VRAM != null)
newboard.VRAM = new byte[Board.VRAM.Length];
newboard.PostConfigure();
// the old board's sram must be restored
if (newboard is FDS)
{
var newfds = newboard as FDS;
var oldfds = board as FDS;
var oldfds = Board as FDS;
newfds.StoreSaveRam(oldfds.ReadSaveRam());
}
else if (board.SaveRam != null)
else if (Board.SaveRam != null)
{
Buffer.BlockCopy(board.SaveRam, 0, newboard.SaveRam, 0, board.SaveRam.Length);
Buffer.BlockCopy(Board.SaveRam, 0, newboard.SaveRam, 0, Board.SaveRam.Length);
}
board.Dispose();
board = newboard;
Board.Dispose();
Board = newboard;
}

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public byte[] CIRAM; //AKA nametables
string game_name = string.Empty; //friendly name exposed to user and used as filename base
CartInfo cart; //the current cart prototype. should be moved into the board, perhaps
INESBoard board; //the board hardware that is currently driving things
internal INESBoard Board; //the board hardware that is currently driving things
EDetectionOrigin origin = EDetectionOrigin.None;
int sprdma_countdown;
bool _irq_apu; //various irq signals that get merged to the cpu irq pin
@ -56,7 +56,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
/// <returns></returns>
public INESBoard GetBoard()
{
return board;
return Board;
}
public void Dispose()
@ -106,7 +106,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
samples[i + 1] = samples[i];
//mix in the cart's extra sound circuit
nes.board.ApplyCustomAudio(samples);
nes.Board.ApplyCustomAudio(samples);
}
public void GetSamples(out short[] samples, out int nsamp)
@ -126,7 +126,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
for (int i = 0; i < nsamp * 2; i += 2)
samples[i + 1] = samples[i];
nes.board.ApplyCustomAudio(samples);
nes.Board.ApplyCustomAudio(samples);
}
public void DiscardSamples()
@ -170,9 +170,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
// controls other than the deck
ControllerDefinition.BoolButtons.Add("Power");
ControllerDefinition.BoolButtons.Add("Reset");
if (board is FDS)
if (Board is FDS)
{
var b = board as FDS;
var b = Board as FDS;
ControllerDefinition.BoolButtons.Add("FDS Eject");
for (int i = 0; i < b.NumSides; i++)
ControllerDefinition.BoolButtons.Add("FDS Insert " + i);
@ -244,7 +244,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
lagged = true;
if (resetSignal)
{
board.NESSoftReset();
Board.NESSoftReset();
cpu.NESSoftReset();
apu.NESSoftReset();
ppu.NESSoftReset();
@ -261,9 +261,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
resetSignal = Controller["Reset"];
hardResetSignal = Controller["Power"];
if (board is FDS)
if (Board is FDS)
{
var b = board as FDS;
var b = Board as FDS;
if (Controller["FDS Eject"])
b.Eject();
for (int i = 0; i < b.NumSides; i++)
@ -320,12 +320,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
cpu_deadcounter--;
else
{
cpu.IRQ = _irq_apu || board.IRQSignal;
cpu.IRQ = _irq_apu || Board.IRQSignal;
cpu.ExecuteOne();
}
apu.RunOne();
board.ClockCPU();
Board.ClockCPU();
ppu.PostCpuInstructionOne();
}
}
@ -493,7 +493,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (addr >= 0x4020)
{
ret = board.PeekCart(addr); //easy optimization, since rom reads are so common, move this up (reordering the rest of these elseifs is not easy)
ret = Board.PeekCart(addr); //easy optimization, since rom reads are so common, move this up (reordering the rest of these elseifs is not easy)
}
else if (addr < 0x0800)
{
@ -534,7 +534,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (addr >= 0x8000)
{
ret = board.ReadPRG(addr - 0x8000); //easy optimization, since rom reads are so common, move this up (reordering the rest of these elseifs is not easy)
ret = Board.ReadPRG(addr - 0x8000); //easy optimization, since rom reads are so common, move this up (reordering the rest of these elseifs is not easy)
}
else if (addr < 0x0800)
{
@ -554,11 +554,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
else if (addr < 0x6000)
{
ret = board.ReadEXP(addr - 0x4000);
ret = Board.ReadEXP(addr - 0x4000);
}
else
{
ret = board.ReadWRAM(addr - 0x6000);
ret = Board.ReadWRAM(addr - 0x6000);
}
//handle breakpoints and stuff.
@ -613,15 +613,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
else if (addr < 0x6000)
{
board.WriteEXP(addr - 0x4000, value);
Board.WriteEXP(addr - 0x4000, value);
}
else if (addr < 0x8000)
{
board.WriteWRAM(addr - 0x6000, value);
Board.WriteWRAM(addr - 0x6000, value);
}
else
{
board.WritePRG(addr - 0x8000, value);
Board.WritePRG(addr - 0x8000, value);
}
MemoryCallbacks.CallWrites(addr);

View File

@ -30,46 +30,46 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
domains.Add(CIRAMdomain);
domains.Add(OAMdoman);
if (!(board is FDS) && board.SaveRam != null)
if (!(Board is FDS) && Board.SaveRam != null)
{
var BatteryRam = new MemoryDomain("Battery RAM", board.SaveRam.Length, MemoryDomain.Endian.Little,
addr => board.SaveRam[addr], (addr, value) => board.SaveRam[addr] = value);
var BatteryRam = new MemoryDomain("Battery RAM", Board.SaveRam.Length, MemoryDomain.Endian.Little,
addr => Board.SaveRam[addr], (addr, value) => Board.SaveRam[addr] = value);
domains.Add(BatteryRam);
}
var PRGROM = new MemoryDomain("PRG ROM", cart.prg_size * 1024, MemoryDomain.Endian.Little,
addr => board.ROM[addr], (addr, value) => board.ROM[addr] = value);
addr => Board.ROM[addr], (addr, value) => Board.ROM[addr] = value);
domains.Add(PRGROM);
if (board.VROM != null)
if (Board.VROM != null)
{
var CHRROM = new MemoryDomain("CHR VROM", cart.chr_size * 1024, MemoryDomain.Endian.Little,
addr => board.VROM[addr], (addr, value) => board.VROM[addr] = value);
addr => Board.VROM[addr], (addr, value) => Board.VROM[addr] = value);
domains.Add(CHRROM);
}
if (board.VRAM != null)
if (Board.VRAM != null)
{
var VRAM = new MemoryDomain("VRAM", board.VRAM.Length, MemoryDomain.Endian.Little,
addr => board.VRAM[addr], (addr, value) => board.VRAM[addr] = value);
var VRAM = new MemoryDomain("VRAM", Board.VRAM.Length, MemoryDomain.Endian.Little,
addr => Board.VRAM[addr], (addr, value) => Board.VRAM[addr] = value);
domains.Add(VRAM);
}
if (board.WRAM != null)
if (Board.WRAM != null)
{
var WRAM = new MemoryDomain("WRAM", board.WRAM.Length, MemoryDomain.Endian.Little,
addr => board.WRAM[addr], (addr, value) => board.WRAM[addr] = value);
var WRAM = new MemoryDomain("WRAM", Board.WRAM.Length, MemoryDomain.Endian.Little,
addr => Board.WRAM[addr], (addr, value) => Board.WRAM[addr] = value);
domains.Add(WRAM);
}
// if there were more boards with special ram sets, we'd want to do something more general
if (board is FDS)
if (Board is FDS)
{
domains.Add((board as FDS).GetDiskPeeker());
domains.Add((Board as FDS).GetDiskPeeker());
}
else if (board is ExROM)
else if (Board is ExROM)
{
domains.Add((board as ExROM).GetExRAM());
domains.Add((Board as ExROM).GetExRAM());
}
_memoryDomains = new MemoryDomainList(domains);

View File

@ -50,14 +50,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public byte PeekPPU(int addr)
{
return board.PeekPPU(addr);
return Board.PeekPPU(addr);
}
public byte[] GetExTiles()
{
if (board is ExROM)
if (Board is ExROM)
{
return board.VROM ?? board.VRAM;
return Board.VROM ?? Board.VRAM;
}
else
{
@ -67,14 +67,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public bool ExActive
{
get { return board is ExROM && (board as ExROM).ExAttrActive; }
get { return Board is ExROM && (Board as ExROM).ExAttrActive; }
}
public byte[] GetExRam()
{
if (board is ExROM)
if (Board is ExROM)
{
return (board as ExROM).GetExRAMArray();
return (Board as ExROM).GetExRAMArray();
}
else
{

View File

@ -12,34 +12,34 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{
get
{
if (board == null) return false;
if (board is FDS) return true;
if (board.SaveRam == null) return false;
if (Board == null) return false;
if (Board is FDS) return true;
if (Board.SaveRam == null) return false;
return true;
}
}
public byte[] CloneSaveRam()
{
if (board is FDS)
return (board as FDS).ReadSaveRam();
if (Board is FDS)
return (Board as FDS).ReadSaveRam();
if (board == null || board.SaveRam == null)
if (Board == null || Board.SaveRam == null)
return null;
return (byte[])board.SaveRam.Clone();
return (byte[])Board.SaveRam.Clone();
}
public void StoreSaveRam(byte[] data)
{
if (board is FDS)
if (Board is FDS)
{
(board as FDS).StoreSaveRam(data);
(Board as FDS).StoreSaveRam(data);
return;
}
if (board == null || board.SaveRam == null)
if (Board == null || Board.SaveRam == null)
return;
Array.Copy(data, board.SaveRam, data.Length);
Array.Copy(data, Board.SaveRam, data.Length);
}
}
}

View File

@ -62,8 +62,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ser.Sync("cpu_stepcounter", ref cpu_stepcounter);
ser.Sync("cpu_deadcounter", ref cpu_deadcounter);
ser.BeginSection("Board");
board.SyncState(ser);
if (board is NESBoardBase && !((NESBoardBase)board).SyncStateFlag)
Board.SyncState(ser);
if (Board is NESBoardBase && !((NESBoardBase)Board).SyncStateFlag)
throw new InvalidOperationException("the current NES mapper didnt call base.SyncState");
ser.EndSection();
ppu.SyncState(ser);

View File

@ -46,10 +46,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
BootGodDB.Initialize();
videoProvider = new MyVideoProvider(this);
Init(game, rom, fdsbios);
if (board is FDS)
if (Board is FDS)
{
DriveLightEnabled = true;
(board as FDS).SetDriveLightCallback((val) => DriveLightOn = val);
(Board as FDS).SetDriveLightCallback((val) => DriveLightOn = val);
}
PutSettings((NESSettings)Settings ?? new NESSettings());
@ -60,9 +60,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ser.Register<ITraceable>(Tracer);
ser.Register<IVideoProvider>(videoProvider);
if (board is BANDAI_FCG_1)
if (Board is BANDAI_FCG_1)
{
var reader = (board as BANDAI_FCG_1).reader;
var reader = (Board as BANDAI_FCG_1).reader;
// not all BANDAI FCG 1 boards have a barcode reader
if (reader != null)
ser.Register<DatachBarcode>(reader);
@ -426,15 +426,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
fdsboard.InitialRegisterValues = InitialMapperRegisterValues;
fdsboard.Configure(origin);
board = fdsboard;
Board = fdsboard;
//create the vram and wram if necessary
if (cart.wram_size != 0)
board.WRAM = new byte[cart.wram_size * 1024];
Board.WRAM = new byte[cart.wram_size * 1024];
if (cart.vram_size != 0)
board.VRAM = new byte[cart.vram_size * 1024];
Board.VRAM = new byte[cart.vram_size * 1024];
board.PostConfigure();
Board.PostConfigure();
Console.WriteLine("Using NTSC display type for FDS disk image");
_display_type = Common.DisplayType.NTSC;
@ -608,12 +608,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
LoadWriteLine("END NES rom analysis");
LoadWriteLine("------");
board = CreateBoardInstance(boardType);
Board = CreateBoardInstance(boardType);
cart = choice;
board.Create(this);
board.InitialRegisterValues = InitialMapperRegisterValues;
board.Configure(origin);
Board.Create(this);
Board.InitialRegisterValues = InitialMapperRegisterValues;
Board.Configure(origin);
if (origin == EDetectionOrigin.BootGodDB)
{
@ -647,26 +647,26 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (iNesHeaderInfo != null)
{
//pluck the necessary bytes out of the file
board.ROM = new byte[choice.prg_size * 1024];
Array.Copy(file, 16, board.ROM, 0, board.ROM.Length);
Board.ROM = new byte[choice.prg_size * 1024];
Array.Copy(file, 16, Board.ROM, 0, Board.ROM.Length);
if (choice.chr_size > 0)
{
board.VROM = new byte[choice.chr_size * 1024];
Board.VROM = new byte[choice.chr_size * 1024];
int vrom_offset = iNesHeaderInfo.prg_size * 1024;
// if file isn't long enough for VROM, truncate
int vrom_copy_size = Math.Min(board.VROM.Length, file.Length - 16 - vrom_offset);
Array.Copy(file, 16 + vrom_offset, board.VROM, 0, vrom_copy_size);
if (vrom_copy_size < board.VROM.Length)
LoadWriteLine("Less than the expected VROM was found in the file: {0} < {1}", vrom_copy_size, board.VROM.Length);
int vrom_copy_size = Math.Min(Board.VROM.Length, file.Length - 16 - vrom_offset);
Array.Copy(file, 16 + vrom_offset, Board.VROM, 0, vrom_copy_size);
if (vrom_copy_size < Board.VROM.Length)
LoadWriteLine("Less than the expected VROM was found in the file: {0} < {1}", vrom_copy_size, Board.VROM.Length);
}
if (choice.prg_size != iNesHeaderInfo.prg_size || choice.chr_size != iNesHeaderInfo.chr_size)
LoadWriteLine("Warning: Detected choice has different filesizes than the INES header!");
}
else
{
board.ROM = unif.PRG;
board.VROM = unif.CHR;
Board.ROM = unif.PRG;
Board.VROM = unif.CHR;
}
LoadReport.Flush();
@ -676,11 +676,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//create the vram and wram if necessary
if (cart.wram_size != 0)
board.WRAM = new byte[cart.wram_size * 1024];
Board.WRAM = new byte[cart.wram_size * 1024];
if (cart.vram_size != 0)
board.VRAM = new byte[cart.vram_size * 1024];
Board.VRAM = new byte[cart.vram_size * 1024];
board.PostConfigure();
Board.PostConfigure();
// set up display type

View File

@ -81,8 +81,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//when the ppu issues a write it goes through here and into the game board
public void ppubus_write(int addr, byte value)
{
nes.board.AddressPPU(addr);
nes.board.WritePPU(addr, value);
nes.Board.AddressPPU(addr);
nes.Board.WritePPU(addr, value);
}
//when the ppu issues a read it goes through here and into the game board
@ -92,14 +92,14 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (!reg_2001.PPUON && ppu)
return 0xFF;
nes.board.AddressPPU(addr);
return nes.board.ReadPPU(addr);
nes.Board.AddressPPU(addr);
return nes.Board.ReadPPU(addr);
}
//debug tools peek into the ppu through this
public byte ppubus_peek(int addr)
{
return nes.board.PeekPPU(addr);
return nes.Board.PeekPPU(addr);
}
public enum PPUPHASE
@ -229,7 +229,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
Reg2002_vblank_clear_pending = false;
}
nes.board.ClockPPU();
nes.Board.ClockPPU();
}
}

View File

@ -443,7 +443,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//normally the address isnt observed by the board till it gets clocked by a read or write.
//but maybe thats just because a ppu read/write shoves it on the address bus
//apparently this shoves it on the address bus, too, or else blargg's mmc3 tests dont pass
nes.board.AddressPPU(ppur.get_2007access());
nes.Board.AddressPPU(ppur.get_2007access());
}
vtoggle ^= true;
@ -480,7 +480,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ppur.increment2007(ppur.status.rendering && reg_2001.PPUON, reg_2000.vram_incr32 != 0);
//see comments in $2006
nes.board.AddressPPU(ppur.get_2007access());
nes.Board.AddressPPU(ppur.get_2007access());
}
byte read_2007()
{
@ -502,7 +502,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ppur.increment2007(ppur.status.rendering && reg_2001.PPUON, reg_2000.vram_incr32 != 0);
//see comments in $2006
nes.board.AddressPPU(ppur.get_2007access());
nes.Board.AddressPPU(ppur.get_2007access());
return ret;
}