PCE: update some graphics properties

This commit is contained in:
alyosha-tas 2018-03-20 10:40:14 -04:00
parent 39e78db39c
commit aa7cee1bb7
3 changed files with 70 additions and 29 deletions

View File

@ -22,6 +22,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
public int BackgroundY;
public int RCRCounter;
public int ActiveLine;
public bool latch_bgy;
public int ActiveDisplayStartLine;
public int HBlankCycles = 79;
public bool PerformSpriteLimit;
@ -31,10 +33,28 @@ namespace BizHawk.Emulation.Cores.PCEngine
public void ExecFrame(bool render)
{
if (MultiResHack > 0 && render)
Array.Clear(FrameBuffer, 0, FrameBuffer.Length);
Array.Clear(FrameBuffer, 0, FrameBuffer.Length);
int ActiveDisplayStartLine = DisplayStartLine;
ActiveDisplayStartLine = DisplayStartLine;
/*
Console.Write("VDS: ");
Console.Write((Registers[VPR] >> 8));
Console.Write(" VSW: ");
Console.Write((Registers[VPR] & 0xFF));
Console.Write(" VDR: ");
Console.Write((Registers[VDW] & 0xFF));
Console.Write(" VCR: ");
Console.Write((Registers[VCR] & 0xFF));
Console.Write(" HDS: ");
Console.Write((Registers[HSR] >> 8));
Console.Write(" HSW: ");
Console.Write((Registers[HSR] & 0xFF));
Console.Write(" HDE: ");
Console.Write((Registers[HDR] >> 8));
Console.Write(" HDW: ");
Console.WriteLine((Registers[HDR] & 0xFF));
*/
while (true)
{
@ -67,6 +87,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
BackgroundY = Registers[BYR];
else
{
if (latch_bgy)
{
BackgroundY = Registers[BYR];
latch_bgy = false;
}
BackgroundY++;
BackgroundY &= 0x01FF;
}
@ -107,8 +133,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
public void RenderScanLine()
{
if (((ActiveLine + ViewStartLine) >= pce.Settings.Bottom_Line) ||
((ActiveLine + ViewStartLine) < pce.Settings.Top_Line))
if ((ScanLine >= pce.Settings.Bottom_Line) ||
(ScanLine < pce.Settings.Top_Line))
return;
RenderBackgroundScanline(pce.Settings.ShowBG1);
@ -126,7 +152,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
int p = vce.Palette[256];
fixed (int* FBptr = FrameBuffer)
{
int* dst = FBptr + (ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch;
int* dst = FBptr + (ScanLine - pce.Settings.Top_Line) * FramePitch;
for (int i = 0; i < FrameWidth; i++)
*dst++ = p;
}
@ -150,7 +176,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
// pointer to the BAT and the framebuffer for this line
ushort* BatRow = VRAMptr + yTile * BatWidth;
int* dst = FBptr + (ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch;
int* dst = FBptr + (ScanLine - pce.Settings.Top_Line) * FramePitch;
// parameters that change per tile
ushort BatEnt;
@ -204,7 +230,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
if (BackgroundEnabled == false)
{
for (int i = 0; i < FrameWidth; i++)
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + i] = vce.Palette[256];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + i] = vce.Palette[256];
return;
}
@ -228,10 +254,10 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte c = PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs];
if (c == 0)
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + x] = vce.Palette[0];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + x] = vce.Palette[0];
else
{
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + x] = show ? vce.Palette[paletteBase + c] : vce.Palette[0];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + x] = show ? vce.Palette[paletteBase + c] : vce.Palette[0];
PriorityBuffer[x] = 1;
}
}
@ -363,7 +389,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
}
}
}
@ -380,7 +406,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
}
}
@ -401,7 +427,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
}
}
if (width == 32)
@ -417,7 +443,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
}
}
}

View File

@ -48,8 +48,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
public int RequestedFrameWidth => ((Registers[HDR] & 0x3F) + 1) * 8;
public int RequestedFrameHeight => (Registers[VDW] & 0x1FF) + 1;
public int DisplayStartLine => (Registers[VPR] >> 8) + (Registers[VPR] & 0x1F);
public int ViewStartLine => (Registers[VPR] >> 8) + 2;
public int DisplayStartLine => (Registers[VPR] >> 8) + 3 + (Registers[VPR] & 0x1F);
private const int MAWR = 0; // Memory Address Write Register
private const int MARR = 1; // Memory Address Read Register
@ -118,8 +117,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
Registers[RegisterLatch] &= 0xFF00;
Registers[RegisterLatch] |= value;
if (RegisterLatch == BYR)
BackgroundY = Registers[BYR] & 0x1FF;
if (RegisterLatch == BYR) { latch_bgy = true; }
//BackgroundY = Registers[BYR] & 0x1FF;
RegisterCommit(RegisterLatch, msbComplete: false);
}
@ -154,7 +153,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
break;
case BYR:
Registers[BYR] &= 0x1FF;
BackgroundY = Registers[BYR];
latch_bgy = true;
//BackgroundY = Registers[BYR];
break;
case HDR: // Horizontal Display Register - update framebuffer size
FrameWidth = RequestedFrameWidth;

View File

@ -101,6 +101,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
const int DCR = 15;
int EffectivePriorityMode = 0;
int ScanLine;
int FrameHeight;
int FrameWidth;
@ -122,12 +123,14 @@ namespace BizHawk.Emulation.Cores.PCEngine
EffectivePriorityMode = 0;
}
Array.Clear(FrameBuffer, 0, FrameBuffer.Length);
// Latch frame dimensions and framebuffer, for purely dumb reasons
FrameWidth = VDC1.BufferWidth;
FrameHeight = VDC1.BufferHeight;
FrameBuffer = VDC1.GetVideoBuffer();
int ScanLine = 0;
ScanLine = 0;
int ActiveDisplayStartLine = VDC1.DisplayStartLine;
while (true)
@ -183,6 +186,18 @@ namespace BizHawk.Emulation.Cores.PCEngine
}
else
{
if (VDC1.latch_bgy)
{
VDC1.BackgroundY = VDC2.Registers[BYR];
VDC1.latch_bgy = false;
}
if (VDC2.latch_bgy)
{
VDC2.BackgroundY = VDC2.Registers[BYR];
VDC2.latch_bgy = false;
}
VDC1.BackgroundY++;
VDC1.BackgroundY &= 0x01FF;
VDC2.BackgroundY++;
@ -239,12 +254,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
private void RenderScanLine()
{
if (((VDC1.ActiveLine + VDC1.ViewStartLine) >= PCE.Settings.Bottom_Line) ||
((VDC1.ActiveLine + VDC1.ViewStartLine) < PCE.Settings.Top_Line))
if ((ScanLine >= PCE.Settings.Bottom_Line) ||
(ScanLine < PCE.Settings.Top_Line))
{
return;
}
InitializeScanLine(VDC1.ActiveLine);
InitializeScanLine(ScanLine);
switch (EffectivePriorityMode)
{
@ -269,7 +284,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
Array.Clear(PriorityBuffer, 0, FrameWidth);
// Initialize scanline to background color
for (int i = 0; i < FrameWidth; i++)
FrameBuffer[((scanline + VDC1.ViewStartLine) * FrameWidth) + i] = VCE.Palette[256];
FrameBuffer[((scanline) * FrameWidth) + i] = VCE.Palette[256];
}
private unsafe void RenderBackgroundScanline(VDC vdc, byte priority, bool show)
@ -293,7 +308,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{
// pointer to the BAT and the framebuffer for this line
ushort* BatRow = VRAMptr + yTile * vdc.BatWidth;
int* dst = FBptr + (vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth;
int* dst = FBptr + (ScanLine - PCE.Settings.Top_Line) * FrameWidth;
// parameters that change per tile
ushort BatEnt;
@ -449,7 +464,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority)
{
if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority;
}
}
@ -468,7 +483,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority)
{
if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority;
}
}
@ -490,7 +505,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority)
{
if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority;
}
}
@ -508,7 +523,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority)
{
if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority;
}
}