nes ppu view infrastructure changes, not complete

This commit is contained in:
goyuken 2014-12-17 00:35:59 +00:00
parent 84f1ba2dd4
commit 665ead318b
7 changed files with 158 additions and 33 deletions

View File

@ -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;

View File

@ -28,6 +28,8 @@ namespace BizHawk.Client.EmuHawk
[RequiredService]
private NES _nes { get; set; }
[RequiredService]
private INESPPUViewable xxx { get; set; }
public NesPPU()
{

View File

@ -485,7 +485,9 @@
<Compile Include="Consoles\Nintendo\NES\FDS\FDSAudio.cs" />
<Compile Include="Consoles\Nintendo\NES\FDS\RamAdapter.cs" />
<Compile Include="Consoles\Nintendo\NES\iNES.cs" />
<Compile Include="Consoles\Nintendo\NES\INESPPUViewable.cs" />
<Compile Include="Consoles\Nintendo\NES\NES.cs" />
<Compile Include="Consoles\Nintendo\NES\NES.INESPPUViewable.cs" />
<Compile Include="Consoles\Nintendo\NES\NESControllers.cs" />
<Compile Include="Consoles\Nintendo\NES\Palettes.cs" />
<Compile Include="Consoles\Nintendo\NES\PPU.cs" />

View File

@ -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);
}
/// <summary>
/// use with caution
/// </summary>
/// <returns></returns>
public byte[] GetExRAMArray()
{
return EXRAM;
}
public bool ExAttrActive { get { return exram_mode == 1; } }
public override void SyncState(Serializer ser)

View File

@ -59,15 +59,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
return board;
}
/// <summary>
/// for debugging only!
/// </summary>
/// <returns></returns>
public int[] GetCompiledPalette()
{
return palette_compiled;
}
public void Dispose()
{
if (magicSoundProvider != null)

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Nintendo.NES
{
/// <summary>
/// supports the PPU and NT viewers. do not modify any returned arrays!
/// </summary>
public interface INESPPUViewable
{
/// <summary>
/// get the 512 color overall palette in use
/// </summary>
/// <returns></returns>
int[] GetPalette();
/// <summary>
/// true if bg tile indexes start at 0x1000 instead of 0x0000
/// </summary>
bool BGBaseHigh { get; }
/// <summary>
/// get the first 0x3000 bytes of ppu data
/// </summary>
/// <returns></returns>
byte[] GetPPUBus();
/// <summary>
/// get the 32 byte palette ram
/// </summary>
/// <returns></returns>
byte[] GetPalRam();
/// <summary>
/// return one byte of PPU bus data
/// </summary>
/// <param name="addr"></param>
/// <returns></returns>
byte PeekPPU(int addr);
/// <summary>
/// get MMC5 extile source data
/// </summary>
/// <returns></returns>
byte[] GetExTiles();
/// <summary>
/// true if MMC5 and ExAttr mode is active
/// </summary>
bool ExActive { get; }
/// <summary>
/// get MMC5 exram for exattr mode
/// </summary>
/// <returns></returns>
byte[] GetExRam();
}
}

View File

@ -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();
}
}
}
}