PCE: Revert aa7cee1. This looks to resolve the following: #1333 #1303 #1287 #1231 #1203 and *maybe* #1266

This commit is contained in:
Asnivor 2018-09-26 10:27:23 +01:00
parent c64eff6baa
commit 4a2d9dd0f1
3 changed files with 30 additions and 76 deletions

View File

@ -22,8 +22,6 @@ namespace BizHawk.Emulation.Cores.PCEngine
public int BackgroundY; public int BackgroundY;
public int RCRCounter; public int RCRCounter;
public int ActiveLine; public int ActiveLine;
public bool latch_bgy;
public int ActiveDisplayStartLine;
public int HBlankCycles = 79; public int HBlankCycles = 79;
public bool PerformSpriteLimit; public bool PerformSpriteLimit;
@ -33,28 +31,10 @@ namespace BizHawk.Emulation.Cores.PCEngine
public void ExecFrame(bool render) public void ExecFrame(bool render)
{ {
Array.Clear(FrameBuffer, 0, FrameBuffer.Length); if (MultiResHack > 0 && render)
Array.Clear(FrameBuffer, 0, FrameBuffer.Length);
ActiveDisplayStartLine = DisplayStartLine; int 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) while (true)
{ {
@ -79,7 +59,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
} }
} }
cpu.Execute(24); cpu.Execute(HBlankCycles);
if (InActiveDisplay) if (InActiveDisplay)
{ {
@ -87,21 +67,10 @@ namespace BizHawk.Emulation.Cores.PCEngine
BackgroundY = Registers[BYR]; BackgroundY = Registers[BYR];
else else
{ {
if (latch_bgy)
{
BackgroundY = Registers[BYR];
latch_bgy = false;
}
BackgroundY++; BackgroundY++;
BackgroundY &= 0x01FF; BackgroundY &= 0x01FF;
} }
}
cpu.Execute(HBlankCycles - 24);
if (InActiveDisplay)
{
if (render) RenderScanLine(); if (render) RenderScanLine();
} }
@ -138,8 +107,8 @@ namespace BizHawk.Emulation.Cores.PCEngine
public void RenderScanLine() public void RenderScanLine()
{ {
if ((ScanLine >= pce.Settings.Bottom_Line) || if (((ActiveLine + ViewStartLine) >= pce.Settings.Bottom_Line) ||
(ScanLine < pce.Settings.Top_Line)) ((ActiveLine + ViewStartLine) < pce.Settings.Top_Line))
return; return;
RenderBackgroundScanline(pce.Settings.ShowBG1); RenderBackgroundScanline(pce.Settings.ShowBG1);
@ -157,7 +126,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
int p = vce.Palette[256]; int p = vce.Palette[256];
fixed (int* FBptr = FrameBuffer) fixed (int* FBptr = FrameBuffer)
{ {
int* dst = FBptr + (ScanLine - pce.Settings.Top_Line) * FramePitch; int* dst = FBptr + (ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch;
for (int i = 0; i < FrameWidth; i++) for (int i = 0; i < FrameWidth; i++)
*dst++ = p; *dst++ = p;
} }
@ -181,7 +150,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
// pointer to the BAT and the framebuffer for this line // pointer to the BAT and the framebuffer for this line
ushort* BatRow = VRAMptr + yTile * BatWidth; ushort* BatRow = VRAMptr + yTile * BatWidth;
int* dst = FBptr + (ScanLine - pce.Settings.Top_Line) * FramePitch; int* dst = FBptr + (ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch;
// parameters that change per tile // parameters that change per tile
ushort BatEnt; ushort BatEnt;
@ -235,7 +204,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
if (BackgroundEnabled == false) if (BackgroundEnabled == false)
{ {
for (int i = 0; i < FrameWidth; i++) for (int i = 0; i < FrameWidth; i++)
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + i] = vce.Palette[256]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + i] = vce.Palette[256];
return; return;
} }
@ -259,10 +228,10 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte c = PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs]; byte c = PatternBuffer[(tileNo * 64) + (yOfs * 8) + xOfs];
if (c == 0) if (c == 0)
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + x] = vce.Palette[0]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + x] = vce.Palette[0];
else else
{ {
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + x] = show ? vce.Palette[paletteBase + c] : vce.Palette[0]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + x] = show ? vce.Palette[paletteBase + c] : vce.Palette[0];
PriorityBuffer[x] = 1; PriorityBuffer[x] = 1;
} }
} }
@ -394,7 +363,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
InterSpritePriorityBuffer[xs] = 1; InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show) if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
} }
} }
} }
@ -411,7 +380,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
InterSpritePriorityBuffer[xs] = 1; InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show) if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
} }
} }
@ -432,7 +401,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
InterSpritePriorityBuffer[xs] = 1; InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show) if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
} }
} }
if (width == 32) if (width == 32)
@ -448,7 +417,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
InterSpritePriorityBuffer[xs] = 1; InterSpritePriorityBuffer[xs] = 1;
if ((priority || PriorityBuffer[xs] == 0) && show) if ((priority || PriorityBuffer[xs] == 0) && show)
FrameBuffer[((ScanLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel]; FrameBuffer[((ActiveLine + ViewStartLine - pce.Settings.Top_Line) * FramePitch) + xs] = vce.Palette[paletteBase + pixel];
} }
} }
} }

View File

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

View File

@ -101,7 +101,6 @@ namespace BizHawk.Emulation.Cores.PCEngine
const int DCR = 15; const int DCR = 15;
int EffectivePriorityMode = 0; int EffectivePriorityMode = 0;
int ScanLine;
int FrameHeight; int FrameHeight;
int FrameWidth; int FrameWidth;
@ -123,14 +122,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
EffectivePriorityMode = 0; EffectivePriorityMode = 0;
} }
Array.Clear(FrameBuffer, 0, FrameBuffer.Length);
// Latch frame dimensions and framebuffer, for purely dumb reasons // Latch frame dimensions and framebuffer, for purely dumb reasons
FrameWidth = VDC1.BufferWidth; FrameWidth = VDC1.BufferWidth;
FrameHeight = VDC1.BufferHeight; FrameHeight = VDC1.BufferHeight;
FrameBuffer = VDC1.GetVideoBuffer(); FrameBuffer = VDC1.GetVideoBuffer();
ScanLine = 0; int ScanLine = 0;
int ActiveDisplayStartLine = VDC1.DisplayStartLine; int ActiveDisplayStartLine = VDC1.DisplayStartLine;
while (true) while (true)
@ -186,18 +183,6 @@ namespace BizHawk.Emulation.Cores.PCEngine
} }
else 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++;
VDC1.BackgroundY &= 0x01FF; VDC1.BackgroundY &= 0x01FF;
VDC2.BackgroundY++; VDC2.BackgroundY++;
@ -260,12 +245,12 @@ namespace BizHawk.Emulation.Cores.PCEngine
private void RenderScanLine() private void RenderScanLine()
{ {
if ((ScanLine >= PCE.Settings.Bottom_Line) || if (((VDC1.ActiveLine + VDC1.ViewStartLine) >= PCE.Settings.Bottom_Line) ||
(ScanLine < PCE.Settings.Top_Line)) ((VDC1.ActiveLine + VDC1.ViewStartLine) < PCE.Settings.Top_Line))
{ {
return; return;
} }
InitializeScanLine(ScanLine); InitializeScanLine(VDC1.ActiveLine);
switch (EffectivePriorityMode) switch (EffectivePriorityMode)
{ {
@ -290,7 +275,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
Array.Clear(PriorityBuffer, 0, FrameWidth); Array.Clear(PriorityBuffer, 0, FrameWidth);
// Initialize scanline to background color // Initialize scanline to background color
for (int i = 0; i < FrameWidth; i++) for (int i = 0; i < FrameWidth; i++)
FrameBuffer[((scanline) * FrameWidth) + i] = VCE.Palette[256]; FrameBuffer[((scanline + VDC1.ViewStartLine) * FrameWidth) + i] = VCE.Palette[256];
} }
private unsafe void RenderBackgroundScanline(VDC vdc, byte priority, bool show) private unsafe void RenderBackgroundScanline(VDC vdc, byte priority, bool show)
@ -314,7 +299,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
// pointer to the BAT and the framebuffer for this line // pointer to the BAT and the framebuffer for this line
ushort* BatRow = VRAMptr + yTile * vdc.BatWidth; ushort* BatRow = VRAMptr + yTile * vdc.BatWidth;
int* dst = FBptr + (ScanLine - PCE.Settings.Top_Line) * FrameWidth; int* dst = FBptr + (vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth;
// parameters that change per tile // parameters that change per tile
ushort BatEnt; ushort BatEnt;
@ -470,7 +455,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority; byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority) if (PriorityBuffer[xs] < myPriority)
{ {
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel]; if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority; PriorityBuffer[xs] = myPriority;
} }
} }
@ -489,7 +474,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority; byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority) if (PriorityBuffer[xs] < myPriority)
{ {
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel]; if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority; PriorityBuffer[xs] = myPriority;
} }
} }
@ -511,7 +496,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority; byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority) if (PriorityBuffer[xs] < myPriority)
{ {
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel]; if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority; PriorityBuffer[xs] = myPriority;
} }
} }
@ -529,7 +514,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
byte myPriority = priority ? highPriority : lowPriority; byte myPriority = priority ? highPriority : lowPriority;
if (PriorityBuffer[xs] < myPriority) if (PriorityBuffer[xs] < myPriority)
{ {
if (show) FrameBuffer[((ScanLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel]; if (show) FrameBuffer[((vdc.ActiveLine + vdc.ViewStartLine - PCE.Settings.Top_Line) * FrameWidth) + xs] = VCE.Palette[paletteBase + pixel];
PriorityBuffer[xs] = myPriority; PriorityBuffer[xs] = myPriority;
} }
} }