C64: Get rid of all the pixel buffer/delay hacks in the VIC.

This commit is contained in:
SaxxonPike 2019-07-25 10:52:10 -05:00
parent 361860361a
commit 58b7630f71
5 changed files with 29 additions and 70 deletions

View File

@ -27,7 +27,7 @@
private const int VideoMode100 = 4;
private const int VideoModeInvalid = -1;
private const int SrMask1 = 0x40000;
private const int SrMask0 = 0x40000;
private const int SrSpriteMask = SrSpriteMask2;
private const int SrSpriteMask1 = 0x400000;
private const int SrSpriteMask2 = SrSpriteMask1 << 1;
@ -65,16 +65,16 @@
#endregion
// render graphics
if ((_srColorEnable & SrMask1) != 0)
if ((_srColorEnable & SrMask0) != 0)
{
_pixel = ((_srColor0 & SrMask1) >> 18) |
((_srColor1 & SrMask1) >> 17) |
((_srColor2 & SrMask1) >> 16) |
((_srColor3 & SrMask1) >> 15);
_pixel = ((_srColor0 & SrMask0) >> 18) |
((_srColor1 & SrMask0) >> 17) |
((_srColor2 & SrMask0) >> 16) |
((_srColor3 & SrMask0) >> 15);
}
else
{
switch (((_srColor0 & SrMask1) >> 18) | ((_srColor1 & SrMask1) >> 17))
switch (((_srColor0 & SrMask0) >> 18) | ((_srColor1 & SrMask0) >> 17))
{
case 1:
_pixel = _idle ? 0 : _backgroundColor1;
@ -171,7 +171,7 @@
}
// sprite-data collision
if (!_borderOnVertical && (_srData1 & SrMask1) != 0)
if (!_borderOnVertical && (_srData1 & SrMask0) != 0)
{
_spr.CollideData = true;
_intSpriteDataCollision = true;
@ -180,7 +180,7 @@
// sprite priority logic
if (_spr.Priority)
{
_pixel = (_srData1 & SrMask1) != 0 ? _pixel : _sprPixel;
_pixel = (_srData1 & SrMask0) != 0 ? _pixel : _sprPixel;
}
else
{
@ -190,29 +190,16 @@
}
}
#region POST-RENDER BORDER
// border doesn't work with the background buffer
_borderPixel = _pixBorderBuffer[_pixBufferBorderIndex];
_pixBorderBuffer[_pixBufferBorderIndex] = _borderColor;
#endregion
// plot pixel if within viewing area
if (_renderEnabled)
{
_bufferPixel = (_borderOnShiftReg & 0x80000) != 0 ? _borderPixel : _pixBuffer[_pixBufferIndex];
_buf[_bufOffset] = Palette[_bufferPixel];
_bufOffset++;
_bufferPixel = (_borderOnVertical || _borderOnMain) ? _borderColor : _pixel;
//_bufferPixel = ((_rasterX & 0xF) == 0) ? _rasterX >> 4 : _bufferPixel;
_buf[_bufOffset++] = Palette[_bufferPixel & 0xF];
if (_bufOffset == _bufLength)
_bufOffset = 0;
}
_borderOnShiftReg <<= 1;
_borderOnShiftReg |= (_borderOnVertical || _borderOnMain) ? 1 : 0;
_pixBuffer[_pixBufferIndex] = _pixel;
_pixBufferIndex++;
_pixBufferBorderIndex++;
if (!_rasterXHold)
_rasterX++;
@ -223,16 +210,6 @@
_srData1 <<= 1;
_srColorEnable <<= 1;
}
if (_pixBufferBorderIndex >= PixBorderBufferSize)
{
_pixBufferBorderIndex = 0;
}
if (_pixBufferIndex >= PixBufferSize)
{
_pixBufferIndex = 0;
}
}
}
}

View File

@ -149,8 +149,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_bufferC[i] = 0;
}
_pixBufferIndex = 0;
_pixBufferBorderIndex = 0;
UpdateBorder();
}
@ -200,10 +198,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ser.Sync(nameof(_pinAec), ref _pinAec);
ser.Sync(nameof(_pinBa), ref _pinBa);
ser.Sync(nameof(_parseIsSprCrunch), ref _parseIsSprCrunch);
ser.Sync(nameof(_pixBorderBuffer), ref _pixBorderBuffer, useNull: false);
ser.Sync(nameof(_pixBufferBorderIndex), ref _pixBufferBorderIndex);
ser.Sync(nameof(_pixBuffer), ref _pixBuffer, useNull: false);
ser.Sync(nameof(_pixBufferIndex), ref _pixBufferIndex);
ser.Sync(nameof(_pointerCb), ref _pointerCb);
ser.Sync(nameof(_pointerVm), ref _pointerVm);
ser.Sync(nameof(_rasterInterruptLine), ref _rasterInterruptLine);

View File

@ -5,10 +5,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
public sealed partial class Vic
{
private const int BorderLeft38 = 0x023;
private const int BorderLeft40 = 0x01C;
private const int BorderRight38 = 0x153;
private const int BorderRight40 = 0x15C;
private const int BorderLeft38 = 0x01F;
private const int BorderLeft40 = 0x018;
private const int BorderRight38 = 0x14F;
private const int BorderRight40 = 0x158;
private const int BorderTop25 = 0x033;
private const int BorderTop24 = 0x037;
private const int BorderBottom25 = 0x0FB;

View File

@ -7,18 +7,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
private static readonly int BgColor = Colors.ARGB(0, 0, 0);
private int[] _buf;
private int _bufHeight;
private int _bufLength;
private int _bufOffset;
private int _bufWidth;
private const int PixBufferSize = 24;
private const int PixBorderBufferSize = 12;
private int[] _pixBuffer;
private int _pixBufferIndex;
private int[] _pixBorderBuffer;
private int _pixBufferBorderIndex;
// palette
// feos: these are the colors that come from pepto's final render at http://www.pepto.de/projects/colorvic/
@ -47,9 +37,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int BackgroundColor => BgColor;
public int BufferHeight => _bufHeight;
public int BufferHeight { get; private set; }
public int BufferWidth => _bufWidth;
public int BufferWidth { get; private set; }
public int[] GetVideoBuffer()
{

View File

@ -78,8 +78,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_sprite6 = _sprites[6];
_sprite7 = _sprites[7];
_bufferC = new int[40];
_pixBuffer = new int[PixBufferSize];
_pixBorderBuffer = new int[PixBorderBufferSize];
}
private void ConfigureBlanking(int lines, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd,
@ -115,22 +113,22 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
case C64.BorderType.SmallProportional:
_vblank = true;
_hblank = true;
newHblankStart = 0x158 + PixBufferSize + hBorderSize;
newHblankEnd = 0x018 + PixBufferSize - hBorderSize;
newHblankStart = 0x158 + hBorderSize;
newHblankEnd = 0x018 - hBorderSize;
newVblankStart = 0xFA + vBorderSize;
newVblankEnd = 0x32 - vBorderSize;
break;
case C64.BorderType.SmallFixed:
_vblank = true;
_hblank = true;
newHblankStart = 0x158 + PixBufferSize + hBorderSize;
newHblankEnd = 0x018 + PixBufferSize - hBorderSize;
newHblankStart = 0x158 + hBorderSize;
newHblankEnd = 0x018 - hBorderSize;
newVblankStart = 0xFA + hBorderSize;
newVblankEnd = 0x32 - hBorderSize;
break;
case C64.BorderType.None:
newHblankStart = 0x158 + PixBufferSize;
newHblankEnd = 0x018 + PixBufferSize;
newHblankStart = 0x158;
newHblankEnd = 0x018;
newVblankStart = 0xFA;
newVblankEnd = 0x32;
_vblank = true;
@ -155,12 +153,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_hblankEndCheckXRaster = newHblankEnd & 0xFFC;
_vblankStart = newVblankStart;
_vblankEnd = newVblankEnd;
_bufWidth = TimingBuilder_ScreenWidth(_rasterXPipeline, newHblankStart, newHblankEnd);
_bufHeight = TimingBuilder_ScreenHeight(newVblankStart, newVblankEnd, lines);
_buf = new int[_bufWidth * _bufHeight];
BufferWidth = TimingBuilder_ScreenWidth(_rasterXPipeline, newHblankStart, newHblankEnd);
BufferHeight = TimingBuilder_ScreenHeight(newVblankStart, newVblankEnd, lines);
_buf = new int[BufferWidth * BufferHeight];
_bufLength = _buf.Length;
VirtualWidth = _bufWidth * _pixelRatioNum / _pixelRatioDen;
VirtualHeight = _bufHeight;
VirtualWidth = BufferWidth * _pixelRatioNum / _pixelRatioDen;
VirtualHeight = BufferHeight;
}
private int WrapValue(int min, int max, int val)