Merge remote-tracking branch 'origin/c64-refactor' into c64-refactor

# Conflicts:
#	BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6510.cs
This commit is contained in:
SaxxonPike 2019-07-12 22:10:08 -05:00
commit 85bc92b688
9 changed files with 238 additions and 245 deletions

View File

@ -524,13 +524,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502
bool interrupt_pending; bool interrupt_pending;
bool branch_irq_hack; //see Uop.RelBranch_Stage3 for more details bool branch_irq_hack; //see Uop.RelBranch_Stage3 for more details
bool Interrupted bool Interrupted => RDY && (NMI || (IRQ && !FlagI));
{
get
{
return RDY && (NMI || (IRQ && !FlagI));
}
}
void FetchDummy() void FetchDummy()
{ {
@ -560,10 +554,6 @@ namespace BizHawk.Emulation.Cores.Components.M6502
void Fetch1() void Fetch1()
{ {
rdy_freeze = !RDY;
if (!RDY)
return;
my_iflag = FlagI; my_iflag = FlagI;
FlagI = iflag_pending; FlagI = iflag_pending;
if (!branch_irq_hack) if (!branch_irq_hack)
@ -672,15 +662,21 @@ namespace BizHawk.Emulation.Cores.Components.M6502
} }
void PushP_Reset() void PushP_Reset()
{ {
ea = ResetVector; rdy_freeze = !RDY;
S--; if (RDY)
FlagI = true; {
ea = ResetVector;
_link.DummyReadMemory((ushort)(S-- + 0x100));
FlagI = true;
}
} }
void PushDummy() void PushDummy()
{ {
S--; rdy_freeze = !RDY;
if (RDY)
{
_link.DummyReadMemory((ushort)(S-- + 0x100));
}
} }
void FetchPCLVector() void FetchPCLVector()
{ {
@ -928,19 +924,19 @@ namespace BizHawk.Emulation.Cores.Components.M6502
} }
void IndIdx_READ_Stage5() void IndIdx_READ_Stage5()
{ {
rdy_freeze = !RDY; if (!alu_temp.Bit(8))
if (RDY)
{ {
if (!alu_temp.Bit(8)) mi++;
ExecuteOneRetry();
return;
}
else
{
rdy_freeze = !RDY;
if (RDY)
{ {
mi++; _link.ReadMemory((ushort) ea);
ExecuteOneRetry(); ea = (ushort) (ea + 0x100);
return;
}
else
{
_link.ReadMemory((ushort)ea);
ea = (ushort)(ea + 0x100);
} }
} }
} }
@ -1196,13 +1192,17 @@ namespace BizHawk.Emulation.Cores.Components.M6502
void NOP() void NOP()
{ {
rdy_freeze = !RDY; rdy_freeze = !RDY;
if (RDY)
{
FetchDummy();
}
} }
void DecS() void DecS()
{ {
rdy_freeze = !RDY; rdy_freeze = !RDY;
if (RDY) if (RDY)
{ {
S--; _link.DummyReadMemory((ushort) (0x100 | --S));
} }
} }
void IncS() void IncS()
@ -1210,7 +1210,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502
rdy_freeze = !RDY; rdy_freeze = !RDY;
if (RDY) if (RDY)
{ {
S++; _link.DummyReadMemory((ushort) (0x100 | S++));
} }
} }
void JSR() void JSR()
@ -2256,19 +2256,18 @@ namespace BizHawk.Emulation.Cores.Components.M6502
} }
void AbsIdx_READ_Stage4() void AbsIdx_READ_Stage4()
{ {
rdy_freeze = !RDY; if (!alu_temp.Bit(8))
if (RDY)
{ {
if (!alu_temp.Bit(8)) mi++;
ExecuteOneRetry();
}
else
{
rdy_freeze = !RDY;
if (RDY)
{ {
mi++; alu_temp = _link.ReadMemory((ushort) ea);
ExecuteOneRetry(); ea = (ushort) (ea + 0x100);
return;
}
else
{
alu_temp = _link.ReadMemory((ushort)ea);
ea = (ushort)(ea + 0x100);
} }
} }
@ -2699,7 +2698,6 @@ namespace BizHawk.Emulation.Cores.Components.M6502
mi = 0; mi = 0;
iflag_pending = FlagI; iflag_pending = FlagI;
ExecuteOneRetry(); ExecuteOneRetry();
return;
} }
void End_BranchSpecial() void End_BranchSpecial()
{ {
@ -2970,7 +2968,7 @@ namespace BizHawk.Emulation.Cores.Components.M6502
public void ExecuteOne() public void ExecuteOne()
{ {
// total cycles now incraments every time a cycle is called to accurately count during RDY // total cycles now increments every time a cycle is called to accurately count during RDY
TotalExecutedCycles++; TotalExecutedCycles++;
if (!rdy_freeze) if (!rdy_freeze)
{ {

View File

@ -97,7 +97,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private void StepOver() private void StepOver()
{ {
var instruction = CpuPeek(_cpu.PC); var instruction = Peek(_cpu.PC);
if (instruction == Jsr) if (instruction == Jsr)
{ {
@ -116,13 +116,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private void StepOut() private void StepOut()
{ {
var instructionsBeforeBailout = 1000000; var instructionsBeforeBailout = 1000000;
var instr = CpuPeek(_cpu.PC); var instr = Peek(_cpu.PC);
_jsrCount = instr == Jsr ? 1 : 0; _jsrCount = instr == Jsr ? 1 : 0;
while (--instructionsBeforeBailout > 0) while (--instructionsBeforeBailout > 0)
{ {
StepInto(); StepInto();
instr = CpuPeek(_cpu.PC); instr = Peek(_cpu.PC);
if (instr == Jsr) if (instr == Jsr)
{ {
_jsrCount++; _jsrCount++;

View File

@ -27,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public string Disassemble(MemoryDomain m, uint addr, out int length) public string Disassemble(MemoryDomain m, uint addr, out int length)
{ {
return MOS6502X.Disassemble((ushort)addr, out length, CpuPeek); return MOS6502X.Disassemble((ushort) addr, out length, a => unchecked((byte) Peek(a)));
} }
} }
} }

View File

@ -67,25 +67,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
set { _cpu.TraceCallback = value; } set { _cpu.TraceCallback = value; }
} }
public void SetOverflow()
{
}
private byte CpuPeek(ushort addr)
{
return unchecked((byte)Peek(addr));
}
private byte CpuRead(ushort addr)
{
return unchecked((byte)Read(addr));
}
private void CpuWrite(ushort addr, byte val)
{
Write(addr, val);
}
public void HardReset() public void HardReset()
{ {
_cpu.NESSoftReset(); _cpu.NESSoftReset();
@ -109,14 +90,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
_cpu.RDY = ReadRdy(); _cpu.RDY = ReadRdy();
if (ReadAec()) // if (!ReadAec())
{ // return;
_cpu.IRQ = !ReadIrq(); _cpu.IRQ = !ReadIrq();
_pinNmiLast = _thisNmi; _pinNmiLast = _thisNmi;
_thisNmi = ReadNmi(); _thisNmi = ReadNmi();
_cpu.NMI |= _pinNmiLast && !_thisNmi; _cpu.NMI |= _pinNmiLast && !_thisNmi;
_cpu.ExecuteOne(); _cpu.ExecuteOne();
}
} }
internal bool AtInstructionStart() internal bool AtInstructionStart()
@ -210,7 +190,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
case 0x0001: case 0x0001:
return PortData; return PortData;
default: default:
return ReadMemory(addr); return ReadAec() ? ReadMemory(addr) : 0xFF;
} }
} }
@ -242,7 +222,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
WriteMemoryPort(addr, val); WriteMemoryPort(addr, val);
break; break;
default: default:
WriteMemory(addr, val); if (ReadAec())
WriteMemory(addr, val);
break; break;
} }
} }

View File

@ -2,7 +2,7 @@
{ {
public sealed partial class Vic public sealed partial class Vic
{ {
private const int BaResetCounter = 4; private const int BaResetCounter = 6;
private const int PipelineUpdateVc = 0x00000001; // vc/rc rule 2 private const int PipelineUpdateVc = 0x00000001; // vc/rc rule 2
private const int PipelineSpriteCrunch = 0x00000002; private const int PipelineSpriteCrunch = 0x00000002;
private const int PipelineUpdateMcBase = 0x00000004; private const int PipelineUpdateMcBase = 0x00000004;
@ -42,6 +42,12 @@
private int _parseBa; private int _parseBa;
private int _parseAct; private int _parseAct;
private bool _parseIsSprCrunch; private bool _parseIsSprCrunch;
private int _parsePixelData;
private int _parsePixelDataIndex;
private int _parseSrData0;
private int _parseSrData1;
private int _parseSrShift;
private bool _parseSrColorEnable;
private void ParseCycle() private void ParseCycle()
{ {
@ -80,8 +86,6 @@
_dataC = 0; _dataC = 0;
_bufferC[_vmli] = _dataC; _bufferC[_vmli] = _dataC;
} }
_srColorSync |= 0x01 << (7 - _xScroll);
break; break;
case FetchTypeGraphics: case FetchTypeGraphics:
// fetch G // fetch G
@ -96,14 +100,102 @@
if (_extraColorModeBuffer) if (_extraColorModeBuffer)
_parseAddr &= AddressMaskEc; _parseAddr &= AddressMaskEc;
_dataG = ReadMemory(_parseAddr); _dataG = ReadMemory(_parseAddr);
_sr |= _dataG << (7 - _xScroll);
_srSync |= 0xAA << (7 - _xScroll);
if (!_idle) if (!_idle)
{ {
_bufferG[_vmli] = _dataG;
_vmli = (_vmli + 1) & 0x3F; _vmli = (_vmli + 1) & 0x3F;
_vc = (_vc + 1) & 0x3FF; _vc = (_vc + 1) & 0x3FF;
} }
// graphics data shift register
_parseSrShift = 7 - _xScroll;
_srData1 &= ~(0xFF << _parseSrShift);
_srActive |= 0xFF << _parseSrShift;
if (_multicolorMode && (_bitmapMode || (_dataC & 0x800) != 0))
{
_parseSrData0 = (_dataG & 0x55) | ((_dataG & 0x55) << 1);
_parseSrData1 = (_dataG & 0xAA) | ((_dataG & 0xAA) >> 1);
}
else
{
_parseSrData0 = _parseSrData1 = _dataG;
}
_srData1 |= _parseSrData1 << _parseSrShift;
if (_bitmapMode && !_multicolorMode)
_parseSrData1 ^= 0xFF;
// graphics color shift register
_srColor0 &= ~(0xFF << _parseSrShift);
_srColor1 &= ~(0xFF << _parseSrShift);
_srColor2 &= ~(0xFF << _parseSrShift);
_srColor3 &= ~(0xFF << _parseSrShift);
for (_parsePixelDataIndex = 7; _parsePixelDataIndex >= 0; _parsePixelDataIndex--)
{
_parsePixelData = ((_parseSrData0 & 0x80) >> 7) | ((_parseSrData1 & 0x80) >> 6);
switch (_videoMode)
{
case VideoMode000:
case VideoMode001:
if (_parsePixelData == 3)
{
_pixel = _idle ? 0 : (_multicolorMode ? _dataC & 0x700 : _dataC) >> 8;
_parseSrColorEnable = true;
}
else
{
_pixel = _parsePixelData;
_parseSrColorEnable = false;
}
break;
case VideoMode010:
case VideoMode011:
_parseSrColorEnable = _parsePixelData != 0;
switch (_parsePixelData)
{
case 0:
_pixel = _backgroundColor0;
break;
case 1:
_pixel = _idle ? 0 : _dataC >> 4;
break;
case 2:
_pixel = _idle ? 0 : _dataC;
break;
default:
_pixel = _idle ? 0 : _dataC >> 8;
break;
}
break;
case VideoMode100:
if (_parsePixelData != 0)
{
_pixel = _idle ? 0 : _dataC >> 8;
_parseSrColorEnable = true;
}
else
{
_pixel = (_dataC & 0xC0) >> 6;
_parseSrColorEnable = false;
}
break;
default:
_parsePixelData = 0;
_pixel = 0;
_parseSrColorEnable = true;
break;
}
_parseSrData0 <<= 1;
_parseSrData1 <<= 1;
_srColor0 |= (_pixel & 1) << (_parseSrShift + _parsePixelDataIndex);
_srColor1 |= ((_pixel >> 1) & 1) << (_parseSrShift + _parsePixelDataIndex);
_srColor2 |= ((_pixel >> 2) & 1) << (_parseSrShift + _parsePixelDataIndex);
_srColor3 |= ((_pixel >> 3) & 1) << (_parseSrShift + _parsePixelDataIndex);
_srColorEnable |= (_parseSrColorEnable ? 1 : 0) << (_parseSrShift + _parsePixelDataIndex);
}
break; break;
case FetchTypeNone: case FetchTypeNone:
// fetch none // fetch none
@ -221,7 +313,6 @@
if ((_parseAct & PipelineUpdateVc) != 0) // VC/RC rule 2 if ((_parseAct & PipelineUpdateVc) != 0) // VC/RC rule 2
{ {
_vc = _vcbase; _vc = _vcbase;
_srColorIndexLatch = 0;
_vmli = 0; _vmli = 0;
if (_badline) if (_badline)
{ {
@ -245,22 +336,21 @@
} }
// perform BA flag manipulation // perform BA flag manipulation
_pinBa = true;
switch (_parseBa) switch (_parseBa)
{ {
case BaTypeNone: case BaTypeNone:
_ba = true;
break; break;
case BaTypeCharacter: case BaTypeCharacter:
_pinBa = !_badline; _ba = !_badline;
break; break;
default: default:
_parseCycleBaSprite0 = _parseBa & BaTypeMaskSprite0; _parseCycleBaSprite0 = _parseBa & BaTypeMaskSprite0;
_parseCycleBaSprite1 = (_parseBa & BaTypeMaskSprite1) >> 4; _parseCycleBaSprite1 = (_parseBa & BaTypeMaskSprite1) >> 4;
_parseCycleBaSprite2 = (_parseBa & BaTypeMaskSprite2) >> 8; _parseCycleBaSprite2 = (_parseBa & BaTypeMaskSprite2) >> 8;
if ((_parseCycleBaSprite0 < 8 && _sprites[_parseCycleBaSprite0].Dma) || _ba = !((_parseCycleBaSprite0 < 8 && _sprites[_parseCycleBaSprite0].Dma) ||
(_parseCycleBaSprite1 < 8 && _sprites[_parseCycleBaSprite1].Dma) || (_parseCycleBaSprite1 < 8 && _sprites[_parseCycleBaSprite1].Dma) ||
(_parseCycleBaSprite2 < 8 && _sprites[_parseCycleBaSprite2].Dma)) (_parseCycleBaSprite2 < 8 && _sprites[_parseCycleBaSprite2].Dma));
_pinBa = false;
break; break;
} }

View File

@ -99,7 +99,7 @@
return 0x01 | ((_pointerVm & 0x3C00) >> 6) | return 0x01 | ((_pointerVm & 0x3C00) >> 6) |
((_pointerCb & 0x7) << 1); ((_pointerCb & 0x7) << 1);
case 0x19: case 0x19:
return 0x70 | (_rasterInterruptTriggered ? 0x01 : 0x00) | return 0x70 | (_intRaster ? 0x01 : 0x00) |
(_intSpriteDataCollision ? 0x02 : 0x00) | (_intSpriteDataCollision ? 0x02 : 0x00) |
(_intSpriteCollision ? 0x04 : 0x00) | (_intSpriteCollision ? 0x04 : 0x00) |
(_intLightPen ? 0x08 : 0x00) | (_intLightPen ? 0x08 : 0x00) |
@ -207,11 +207,7 @@
case 0x19: case 0x19:
// interrupts are cleared by writing a 1 // interrupts are cleared by writing a 1
if ((val & 0x01) != 0) if ((val & 0x01) != 0)
{
_intRaster = false; _intRaster = false;
_rasterInterruptTriggered = false;
}
if ((val & 0x02) != 0) if ((val & 0x02) != 0)
_intSpriteDataCollision = false; _intSpriteDataCollision = false;
if ((val & 0x04) != 0) if ((val & 0x04) != 0)
@ -292,6 +288,27 @@
_extraColorMode = (val & 0x40) != 0; _extraColorMode = (val & 0x40) != 0;
_rasterInterruptLine &= 0xFF; _rasterInterruptLine &= 0xFF;
_rasterInterruptLine |= (val & 0x80) << 1; _rasterInterruptLine |= (val & 0x80) << 1;
if (_rasterLine == FirstDmaLine)
_badlineEnable |= _displayEnable;
if (_badlineEnable)
{
if ((_rasterLine & 0x7) == _yScroll)
{
_badline = true;
_idle = false;
}
else
{
_badline = false;
}
}
else
{
_badline = false;
}
UpdateBorder(); UpdateBorder();
UpdateVideoMode(); UpdateVideoMode();
break; break;

View File

@ -4,18 +4,20 @@
{ {
private int _borderPixel; private int _borderPixel;
private int _bufferPixel; private int _bufferPixel;
private int _ecmPixel;
private int _pixel; private int _pixel;
private int _pixelCounter; private int _pixelCounter;
private int _pixelData;
private int _pixelOwner; private int _pixelOwner;
private Sprite _spr; private Sprite _spr;
private int _sprData; private int _sprData;
private int _sprIndex; private int _sprIndex;
private int _sprPixel; private int _sprPixel;
private int _srSync; private int _srColor0;
private int _srColorSync; private int _srColor1;
private int _srColorIndexLatch; private int _srColor2;
private int _srColor3;
private int _srData1;
private int _srActive;
private int _srColorEnable;
private int _videoMode; private int _videoMode;
private int _borderOnShiftReg; private int _borderOnShiftReg;
@ -26,10 +28,7 @@
private const int VideoMode100 = 4; private const int VideoMode100 = 4;
private const int VideoModeInvalid = -1; private const int VideoModeInvalid = -1;
private const int SrMask1 = 0x20000; private const int SrMask1 = 0x40000;
private const int SrMask2 = SrMask1 << 1;
private const int SrMask3 = SrMask1 | SrMask2;
private const int SrColorMask = 0x8000;
private const int SrSpriteMask = SrSpriteMask2; private const int SrSpriteMask = SrSpriteMask2;
private const int SrSpriteMask1 = 0x400000; private const int SrSpriteMask1 = 0x400000;
private const int SrSpriteMask2 = SrSpriteMask1 << 1; private const int SrSpriteMask2 = SrSpriteMask1 << 1;
@ -47,13 +46,6 @@
_pixelCounter = 4; _pixelCounter = 4;
while (--_pixelCounter >= 0) while (--_pixelCounter >= 0)
{ {
if ((_srColorSync & SrColorMask) != 0)
{
_displayC = _bufferC[_srColorIndexLatch];
_srColorIndexLatch = (_srColorIndexLatch + 1) & 0x3F;
}
#region PRE-RENDER BORDER #region PRE-RENDER BORDER
// check left border // check left border
@ -73,105 +65,33 @@
#endregion #endregion
#region CHARACTER GRAPHICS // render graphics
switch (_videoMode) if ((_srColorEnable & SrMask1) != 0)
{ {
case VideoMode000: _pixel = ((_srColor0 & SrMask1) >> 18) |
_pixelData = _sr & SrMask2; ((_srColor1 & SrMask1) >> 17) |
_pixel = _pixelData != 0 ? _displayC >> 8 : _backgroundColor0; ((_srColor2 & SrMask1) >> 16) |
break; ((_srColor3 & SrMask1) >> 15);
case VideoMode001: }
if ((_displayC & 0x800) != 0) else
{ {
// multicolor 001 switch (((_srColor0 & SrMask1) >> 18) | ((_srColor1 & SrMask1) >> 17))
if ((_srSync & SrMask2) != 0) {
_pixelData = _sr & SrMask3; case 1:
_pixel = _idle ? 0 : _backgroundColor1;
switch (_pixelData) break;
{ case 2:
case 0: _pixel = _idle ? 0 : _backgroundColor2;
_pixel = _backgroundColor0; break;
break; case 3:
case SrMask1: _pixel = _idle ? 0 : _backgroundColor3;
_pixel = _idle ? 0 : _backgroundColor1; break;
break; default:
case SrMask2: _pixel = _backgroundColor0;
_pixel = _idle ? 0 :_backgroundColor2; break;
break; }
default:
_pixel = _idle ? 0 : (_displayC & 0x700) >> 8;
break;
}
}
else
{
// standard 001
_pixelData = _sr & SrMask2;
_pixel = _pixelData != 0 ? (_idle ? 0 : _displayC >> 8) : _backgroundColor0;
}
break;
case VideoMode010:
_pixelData = _sr & SrMask2;
_pixel = _idle ? 0 : _pixelData != 0 ? _displayC >> 4 : _displayC;
break;
case VideoMode011:
if ((_srSync & SrMask2) != 0)
_pixelData = _sr & SrMask3;
switch (_pixelData)
{
case 0:
_pixel = _backgroundColor0;
break;
case SrMask1:
_pixel = _idle ? 0 : _displayC >> 4;
break;
case SrMask2:
_pixel = _idle ? 0 : _displayC;
break;
default:
_pixel = _idle ? 0 : _displayC >> 8;
break;
}
break;
case VideoMode100:
_pixelData = _sr & SrMask2;
if (_pixelData != 0)
{
_pixel = _idle ? 0 : _displayC >> 8;
}
else
{
_ecmPixel = (_displayC & 0xC0) >> 6;
switch (_ecmPixel)
{
case 0:
_pixel = _backgroundColor0;
break;
case 1:
_pixel = _idle ? 0 : _backgroundColor1;
break;
case 2:
_pixel = _idle ? 0 : _backgroundColor2;
break;
default:
_pixel = _idle ? 0 : _backgroundColor3;
break;
}
}
break;
default:
_pixelData = 0;
_pixel = 0;
break;
} }
_pixel &= 0xF;
_sr <<= 1;
_srSync <<= 1;
_srColorSync <<= 1;
#endregion
#region SPRITES
// render sprites // render sprites
_pixelOwner = -1; _pixelOwner = -1;
for (_sprIndex = 0; _sprIndex < 8; _sprIndex++) for (_sprIndex = 0; _sprIndex < 8; _sprIndex++)
@ -252,7 +172,7 @@
} }
// sprite-data collision // sprite-data collision
if (!_borderOnVertical && (_pixelData >= SrMask2)) if (!_borderOnVertical && (_srData1 & SrMask1) != 0)
{ {
_spr.CollideData = true; _spr.CollideData = true;
_intSpriteDataCollision = true; _intSpriteDataCollision = true;
@ -261,7 +181,7 @@
// sprite priority logic // sprite priority logic
if (_spr.Priority) if (_spr.Priority)
{ {
_pixel = _pixelData >= SrMask2 ? _pixel : _sprPixel; _pixel = (_srData1 & SrMask1) != 0 ? _pixel : _sprPixel;
} }
else else
{ {
@ -271,8 +191,6 @@
} }
} }
#endregion
#region POST-RENDER BORDER #region POST-RENDER BORDER
// border doesn't work with the background buffer // border doesn't work with the background buffer
@ -298,6 +216,14 @@
if (!_rasterXHold) if (!_rasterXHold)
_rasterX++; _rasterX++;
_srColor0 <<= 1;
_srColor1 <<= 1;
_srColor2 <<= 1;
_srColor3 <<= 1;
_srData1 <<= 1;
_srActive <<= 1;
_srColorEnable <<= 1;
} }
if (_pixBufferBorderIndex >= PixBorderBufferSize) if (_pixBufferBorderIndex >= PixBorderBufferSize)

View File

@ -8,6 +8,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private int _backgroundColor1; private int _backgroundColor1;
private int _backgroundColor2; private int _backgroundColor2;
private int _backgroundColor3; private int _backgroundColor3;
private bool _ba;
private int _baCount; private int _baCount;
private bool _badline; private bool _badline;
private bool _badlineEnable; private bool _badlineEnable;
@ -22,14 +23,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private int _borderR; private int _borderR;
private int _borderT; private int _borderT;
private int[] _bufferC; private int[] _bufferC;
private int[] _bufferG;
private int _cycle; private int _cycle;
private int _cycleIndex; private int _cycleIndex;
private bool _columnSelect; private bool _columnSelect;
private int _dataC; private int _dataC;
private int _dataG; private int _dataG;
private bool _displayEnable; private bool _displayEnable;
private int _displayC;
private bool _enableIntLightPen; private bool _enableIntLightPen;
private bool _enableIntRaster; private bool _enableIntRaster;
private bool _enableIntSpriteCollision; private bool _enableIntSpriteCollision;
@ -53,6 +52,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private int _rasterInterruptLine; private int _rasterInterruptLine;
private bool _rasterInterruptTriggered; private bool _rasterInterruptTriggered;
private int _rasterLine; private int _rasterLine;
private int _rasterLineInterruptCompare;
private int _rasterX; private int _rasterX;
private bool _rasterXHold; private bool _rasterXHold;
private int _rc; private int _rc;
@ -72,7 +72,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private readonly Sprite _sprite6; private readonly Sprite _sprite6;
private readonly Sprite _sprite7; private readonly Sprite _sprite7;
private readonly Sprite[] _sprites; private readonly Sprite[] _sprites;
private int _sr;
private bool _vblank; private bool _vblank;
private int _vblankEnd; private int _vblankEnd;
private int _vblankStart; private int _vblankStart;
@ -87,6 +86,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_pinAec = true; _pinAec = true;
_pinBa = true; _pinBa = true;
_pinIrq = true; _pinIrq = true;
_ba = true;
_bufOffset = 0; _bufOffset = 0;
@ -130,7 +130,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_spriteSpriteCollisionClearPending = false; _spriteSpriteCollisionClearPending = false;
_spriteMulticolor0 = 0; _spriteMulticolor0 = 0;
_spriteMulticolor1 = 0; _spriteMulticolor1 = 0;
_sr = 0;
_vc = 0; _vc = 0;
_vcbase = 0; _vcbase = 0;
_vmli = 0; _vmli = 0;
@ -149,7 +148,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
for (var i = 0; i < 40; i++) for (var i = 0; i < 40; i++)
{ {
_bufferC[i] = 0; _bufferC[i] = 0;
_bufferG[i] = 0;
} }
_pixBuffer = new int[PixBufferSize]; _pixBuffer = new int[PixBufferSize];
@ -161,13 +159,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
ser.Sync(nameof(_cyclesExecuted), ref _cyclesExecuted);
ser.Sync(nameof(_parseIsSprCrunch), ref _parseIsSprCrunch); ser.Sync(nameof(_parseIsSprCrunch), ref _parseIsSprCrunch);
ser.Sync(nameof(_srSync), ref _srSync);
ser.Sync(nameof(_srColorSync), ref _srColorSync);
ser.Sync(nameof(_srColorIndexLatch), ref _srColorIndexLatch);
ser.Sync(nameof(_videoMode), ref _videoMode); ser.Sync(nameof(_videoMode), ref _videoMode);
ser.Sync(nameof(_borderOnShiftReg), ref _borderOnShiftReg); ser.Sync(nameof(_borderOnShiftReg), ref _borderOnShiftReg);
ser.Sync(nameof(_ba), ref _ba);
ser.Sync(nameof(_backgroundColor0), ref _backgroundColor0); ser.Sync(nameof(_backgroundColor0), ref _backgroundColor0);
ser.Sync(nameof(_backgroundColor1), ref _backgroundColor1); ser.Sync(nameof(_backgroundColor1), ref _backgroundColor1);
ser.Sync(nameof(_backgroundColor2), ref _backgroundColor2); ser.Sync(nameof(_backgroundColor2), ref _backgroundColor2);
@ -186,14 +181,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ser.Sync(nameof(_borderR), ref _borderR); ser.Sync(nameof(_borderR), ref _borderR);
ser.Sync(nameof(_borderT), ref _borderT); ser.Sync(nameof(_borderT), ref _borderT);
ser.Sync(nameof(_bufferC), ref _bufferC, useNull: false); ser.Sync(nameof(_bufferC), ref _bufferC, useNull: false);
ser.Sync(nameof(_bufferG), ref _bufferG, useNull: false);
ser.Sync(nameof(_cycle), ref _cycle); ser.Sync(nameof(_cycle), ref _cycle);
ser.Sync(nameof(_cycleIndex), ref _cycleIndex); ser.Sync(nameof(_cycleIndex), ref _cycleIndex);
ser.Sync(nameof(_columnSelect), ref _columnSelect); ser.Sync(nameof(_columnSelect), ref _columnSelect);
ser.Sync(nameof(_dataC), ref _dataC); ser.Sync(nameof(_dataC), ref _dataC);
ser.Sync(nameof(_dataG), ref _dataG); ser.Sync(nameof(_dataG), ref _dataG);
ser.Sync(nameof(_displayEnable), ref _displayEnable); ser.Sync(nameof(_displayEnable), ref _displayEnable);
ser.Sync(nameof(_displayC), ref _displayC);
ser.Sync(nameof(_enableIntLightPen), ref _enableIntLightPen); ser.Sync(nameof(_enableIntLightPen), ref _enableIntLightPen);
ser.Sync(nameof(_enableIntRaster), ref _enableIntRaster); ser.Sync(nameof(_enableIntRaster), ref _enableIntRaster);
ser.Sync(nameof(_enableIntSpriteCollision), ref _enableIntSpriteCollision); ser.Sync(nameof(_enableIntSpriteCollision), ref _enableIntSpriteCollision);
@ -214,7 +207,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ser.Sync(nameof(_pointerCb), ref _pointerCb); ser.Sync(nameof(_pointerCb), ref _pointerCb);
ser.Sync(nameof(_pointerVm), ref _pointerVm); ser.Sync(nameof(_pointerVm), ref _pointerVm);
ser.Sync(nameof(_rasterInterruptLine), ref _rasterInterruptLine); ser.Sync(nameof(_rasterInterruptLine), ref _rasterInterruptLine);
ser.Sync(nameof(_rasterInterruptTriggered), ref _rasterInterruptTriggered);
ser.Sync(nameof(_rasterLine), ref _rasterLine); ser.Sync(nameof(_rasterLine), ref _rasterLine);
ser.Sync(nameof(_rasterX), ref _rasterX); ser.Sync(nameof(_rasterX), ref _rasterX);
ser.Sync(nameof(_rasterXHold), ref _rasterXHold); ser.Sync(nameof(_rasterXHold), ref _rasterXHold);
@ -234,7 +226,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ser.EndSection(); ser.EndSection();
} }
ser.Sync(nameof(_sr), ref _sr);
ser.Sync(nameof(_vc), ref _vc); ser.Sync(nameof(_vc), ref _vc);
ser.Sync(nameof(_vcbase), ref _vcbase); ser.Sync(nameof(_vcbase), ref _vcbase);
ser.Sync(nameof(_vmli), ref _vmli); ser.Sync(nameof(_vmli), ref _vmli);
@ -245,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
ser.Sync(nameof(_pixBufferIndex), ref _pixBufferIndex); ser.Sync(nameof(_pixBufferIndex), ref _pixBufferIndex);
ser.Sync(nameof(_pixBorderBuffer), ref _pixBorderBuffer, useNull: false); ser.Sync(nameof(_pixBorderBuffer), ref _pixBorderBuffer, useNull: false);
ser.Sync(nameof(_pixBufferBorderIndex), ref _pixBufferBorderIndex); ser.Sync(nameof(_pixBufferBorderIndex), ref _pixBufferBorderIndex);
if (ser.IsReader) if (ser.IsReader)
{ {
UpdateBorder(); UpdateBorder();

View File

@ -36,7 +36,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private readonly int _totalCycles; private readonly int _totalCycles;
private readonly int _totalLines; private readonly int _totalLines;
private int _cyclesExecuted;
private int _hblankStartCheckXRaster; private int _hblankStartCheckXRaster;
private int _hblankEndCheckXRaster; private int _hblankEndCheckXRaster;
@ -81,7 +80,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_sprite7 = _sprites[7]; _sprite7 = _sprites[7];
_bufferC = new int[40]; _bufferC = new int[40];
_bufferG = new int[40];
} }
private void ConfigureBlanking(int lines, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd, private void ConfigureBlanking(int lines, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd,
@ -228,7 +226,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_vc = 0; _vc = 0;
_badlineEnable = false; _badlineEnable = false;
_refreshCounter = 0xFF; _refreshCounter = 0xFF;
_cyclesExecuted = 0;
} }
} }
@ -257,21 +254,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// start of rasterline // start of rasterline
if ((_cycle == RasterIrqLineXCycle && _rasterLine > 0) || (_cycle == RasterIrqLine0Cycle && _rasterLine == 0)) if ((_cycle == RasterIrqLineXCycle && _rasterLine > 0) || (_cycle == RasterIrqLine0Cycle && _rasterLine == 0))
{ {
//_rasterInterruptTriggered = false;
if (_rasterLine == LastDmaLine) if (_rasterLine == LastDmaLine)
_badlineEnable = false; _badlineEnable = false;
// IRQ compares are done here // raster compares are done here
if (_rasterLine == _rasterInterruptLine) if (_rasterLine == _rasterInterruptLine)
{ {
_rasterInterruptTriggered = true; _intRaster = true;
// interrupt needs to be enabled to be set to true
if (_enableIntRaster)
{
_intRaster = true;
}
} }
} }
@ -313,22 +302,21 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// render // render
ParseCycle(); ParseCycle();
UpdateBa();
Render(); Render();
ParseCycle(); ParseCycle();
UpdateBa();
UpdatePins();
Render(); Render();
_extraColorModeBuffer = _extraColorMode; _extraColorModeBuffer = _extraColorMode;
}
// if the BA counter is nonzero, allow CPU bus access private void UpdateBa()
if (_pinBa) {
if (_ba)
_baCount = BaResetCounter; _baCount = BaResetCounter;
else if (_baCount > 0) else if (_baCount >= 0)
_baCount--; _baCount--;
_pinAec = _pinBa || _baCount > 0;
// must always come last
UpdatePins();
_cyclesExecuted++;
} }
private void UpdateBorder() private void UpdateBorder()
@ -348,6 +336,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
(_enableIntLightPen & _intLightPen)); (_enableIntLightPen & _intLightPen));
_pinIrq = irqTemp; _pinIrq = irqTemp;
_pinAec = _ba || _baCount >= 0;
_pinBa = _ba;
} }
private void UpdateVideoMode() private void UpdateVideoMode()