diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs
index 9bf59dc5f4..565588e3f3 100644
--- a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs
+++ b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.cs
@@ -5,6 +5,7 @@ using System.Drawing.Imaging;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Cores.Nintendo.NES;
+using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
@@ -14,6 +15,10 @@ namespace BizHawk.Client.EmuHawk
// Show Scroll Lines + UI Toggle
[RequiredService]
private NES _nes { get; set; }
+ [RequiredService]
+ private INESPPUViewable xxx { get; set; }
+ [RequiredService]
+ private IEmulator _emu { get; set; }
private readonly NES.PPU.DebugCallback _callback = new NES.PPU.DebugCallback();
@@ -84,11 +89,11 @@ namespace BizHawk.Client.EmuHawk
private unsafe void GenerateExAttr(int* dst, int pitch, byte[] palram, byte[] ppumem, byte[] exram)
{
- byte[] chr = _nes.GetBoard().VROM ?? _nes.GetBoard().VRAM;
+ byte[] chr = xxx.GetExTiles();
int chr_mask = chr.Length - 1;
fixed (byte* chrptr = chr, palptr = palram, ppuptr = ppumem, exptr = exram)
- fixed (int* finalpal = _nes.GetCompiledPalette())
+ fixed (int* finalpal = xxx.GetPalette())
{
DrawExNT(dst, pitch, palptr, ppuptr + 0x2000, exptr, chrptr, chr_mask, finalpal);
DrawExNT(dst + 256, pitch, palptr, ppuptr + 0x2400, exptr, chrptr, chr_mask, finalpal);
@@ -101,9 +106,9 @@ namespace BizHawk.Client.EmuHawk
private unsafe void GenerateAttr(int* dst, int pitch, byte[] palram, byte[] ppumem)
{
fixed (byte* palptr = palram, ppuptr = ppumem)
- fixed (int* finalpal = _nes.GetCompiledPalette())
+ fixed (int* finalpal = xxx.GetPalette())
{
- byte* chrptr = ppuptr + (_nes.ppu.reg_2000.bg_pattern_hi ? 0x1000 : 0);
+ byte* chrptr = ppuptr + (xxx.BGBaseHigh ? 0x1000 : 0);
DrawNT(dst, pitch, palptr, ppuptr + 0x2000, chrptr, finalpal);
DrawNT(dst + 256, pitch, palptr, ppuptr + 0x2400, chrptr, finalpal);
dst += pitch * 240;
@@ -163,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
return;
}
- if (now == false && _nes.Frame % RefreshRate.Value != 0)
+ if (now == false && _emu.Frame % RefreshRate.Value != 0)
{
return;
}
@@ -177,26 +182,13 @@ namespace BizHawk.Client.EmuHawk
var pitch = bmpdata.Stride / 4;
// Buffer all the data from the ppu, because it will be read multiple times and that is slow
- var ppuBuffer = new byte[0x3000];
- for (var i = 0; i < 0x3000; i++)
- {
- ppuBuffer[i] = _nes.ppu.ppubus_peek(i);
- }
+ var ppuBuffer = xxx.GetPPUBus();
- var palram = new byte[0x20];
- for (var i = 0; i < 0x20; i++)
- {
- palram[i] = _nes.ppu.PALRAM[i];
- }
+ var palram = xxx.GetPalRam();
- var board = _nes.GetBoard();
- if (board is ExROM && (board as ExROM).ExAttrActive)
+ if (xxx.ExActive)
{
- byte[] exram = new byte[1024];
- var md = _nes.MemoryDomains["ExRAM"];
- for (int i = 0; i < 1024; i++)
- exram[i] = md.PeekByte(i);
-
+ byte[] exram = xxx.GetExRam();
GenerateExAttr(dptr, pitch, palram, ppuBuffer, exram);
}
else
@@ -372,7 +364,7 @@ namespace BizHawk.Client.EmuHawk
XYLabel.Text = TileX + " : " + TileY;
int PPUAddress = 0x2000 + (NameTable * 0x400) + ((TileY % 30) * 32) + (TileX % 32);
PPUAddressLabel.Text = string.Format("{0:X4}", PPUAddress);
- int TileID = _nes.ppu.ppubus_read(PPUAddress, true);
+ int TileID = xxx.PeekPPU(PPUAddress);
TileIDLabel.Text = string.Format("{0:X2}", TileID);
TableLabel.Text = NameTable.ToString();
@@ -389,7 +381,7 @@ namespace BizHawk.Client.EmuHawk
int tx = px >> 3;
int ty = py >> 3;
int atbyte_ptr = ntaddr + 0x3C0 + ((ty >> 2) << 3) + (tx >> 2);
- int at = _nes.ppu.ppubus_peek(atbyte_ptr + 0x2000);
+ int at = xxx.PeekPPU(atbyte_ptr + 0x2000);
if ((ty & 2) != 0) at >>= 4;
if ((tx & 2) != 0) at >>= 2;
at &= 0x03;
diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs b/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs
index 281ca090ba..85f2863b81 100644
--- a/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs
+++ b/BizHawk.Client.EmuHawk/tools/NES/NESPPU.cs
@@ -28,6 +28,8 @@ namespace BizHawk.Client.EmuHawk
[RequiredService]
private NES _nes { get; set; }
+ [RequiredService]
+ private INESPPUViewable xxx { get; set; }
public NesPPU()
{
diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
index 973b804500..0e1ba4b304 100644
--- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
+++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
@@ -485,7 +485,9 @@
+
+
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs
index 2b89099702..a19af89b18 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/ExROM.cs
@@ -52,6 +52,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
return new MemoryDomain("ExRAM", EXRAM.Length, MemoryDomain.Endian.Little, (addr) => EXRAM[addr], (addr, val) => EXRAM[addr] = val);
}
+ ///
+ /// use with caution
+ ///
+ ///
+ public byte[] GetExRAMArray()
+ {
+ return EXRAM;
+ }
+
public bool ExAttrActive { get { return exram_mode == 1; } }
public override void SyncState(Serializer ser)
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs
index c4be599036..8fab5a042e 100644
--- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Core.cs
@@ -59,15 +59,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
return board;
}
- ///
- /// for debugging only!
- ///
- ///
- public int[] GetCompiledPalette()
- {
- return palette_compiled;
- }
-
public void Dispose()
{
if (magicSoundProvider != null)
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/INESPPUViewable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/INESPPUViewable.cs
new file mode 100644
index 0000000000..ce0feadb49
--- /dev/null
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/INESPPUViewable.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BizHawk.Emulation.Cores.Nintendo.NES
+{
+ ///
+ /// supports the PPU and NT viewers. do not modify any returned arrays!
+ ///
+ public interface INESPPUViewable
+ {
+ ///
+ /// get the 512 color overall palette in use
+ ///
+ ///
+ int[] GetPalette();
+
+ ///
+ /// true if bg tile indexes start at 0x1000 instead of 0x0000
+ ///
+ bool BGBaseHigh { get; }
+
+ ///
+ /// get the first 0x3000 bytes of ppu data
+ ///
+ ///
+ byte[] GetPPUBus();
+
+ ///
+ /// get the 32 byte palette ram
+ ///
+ ///
+ byte[] GetPalRam();
+
+ ///
+ /// return one byte of PPU bus data
+ ///
+ ///
+ ///
+ byte PeekPPU(int addr);
+
+ ///
+ /// get MMC5 extile source data
+ ///
+ ///
+ byte[] GetExTiles();
+
+ ///
+ /// true if MMC5 and ExAttr mode is active
+ ///
+ bool ExActive { get; }
+
+ ///
+ /// get MMC5 exram for exattr mode
+ ///
+ ///
+ byte[] GetExRam();
+ }
+}
diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.INESPPUViewable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.INESPPUViewable.cs
new file mode 100644
index 0000000000..691993979e
--- /dev/null
+++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.INESPPUViewable.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BizHawk.Emulation.Cores.Nintendo.NES
+{
+ partial class NES : INESPPUViewable
+ {
+ public int[] GetPalette()
+ {
+ return palette_compiled;
+ }
+
+ public bool BGBaseHigh
+ {
+ get { return ppu.reg_2000.bg_pattern_hi; }
+ }
+
+ public byte[] GetPPUBus()
+ {
+ byte[] ret = new byte[0x3000];
+ for (int i = 0; i < 0x3000; i++)
+ {
+ ret[i] = ppu.ppubus_peek(i);
+ }
+ return ret;
+ }
+
+ public byte[] GetPalRam()
+ {
+ return ppu.PALRAM;
+ }
+
+ public byte PeekPPU(int addr)
+ {
+ return board.PeekPPU(addr);
+ }
+
+ public byte[] GetExTiles()
+ {
+ if (board is ExROM)
+ {
+ return board.VROM ?? board.VRAM;
+ }
+ else
+ {
+ throw new InvalidOperationException();
+ }
+ }
+
+ public bool ExActive
+ {
+ get { return board is ExROM && (board as ExROM).ExAttrActive; }
+ }
+
+ public byte[] GetExRam()
+ {
+ if (board is ExROM)
+ {
+ return (board as ExROM).GetExRAMArray();
+ }
+ else
+ {
+ throw new InvalidOperationException();
+ }
+ }
+ }
+}