diff --git a/BizHawk.Emulation/Computers/Commodore64/_VicIINewPipeline.cs b/BizHawk.Emulation/Computers/Commodore64/_VicIINewPipeline.cs index a13f2ad1d3..7e1cccd2ae 100644 --- a/BizHawk.Emulation/Computers/Commodore64/_VicIINewPipeline.cs +++ b/BizHawk.Emulation/Computers/Commodore64/_VicIINewPipeline.cs @@ -17,6 +17,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 { pipelineGAccess = false; pipelineMemoryBusy = false; + advanceX = true; foreach (Action a in pipeline[cycle]) a(); @@ -420,6 +421,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 { // 61 PipelineCycle, PipelineFetchSprite1P, + PipelineDisableAdvanceX, PipelineRender }, new Action[] @@ -454,7 +456,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 PipelineCycle, PipelineIRQ0, PipelineFetchSprite3P, - PipelineBadlineDelay, PipelineRender }, new Action[] @@ -462,7 +463,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 PipelineCycle, PipelineIRQ1, PipelineFetchSprite3S, - PipelineBadlineDelay, PipelineRender }, new Action[] @@ -542,6 +542,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 { // 14 PipelineCycle, PipelineDramRefresh, + PipelineBadlineDelay, PipelineRender }, new Action[] @@ -783,7 +784,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 { // 54 PipelineCycle, PipelineFetchC, - PipelineSpriteMYEFlip, PipelineSpriteEnable0, PipelineRender }, @@ -791,6 +791,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 { // 55 PipelineCycle, PipelineSpriteEnable1, + PipelineSpriteMYEFlip, PipelineIdle, PipelineRender }, @@ -878,6 +879,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 sprites[i].MxYEToggle = true; } + private void PipelineDisableAdvanceX() + { + advanceX = false; + } + private void PipelineDramRefresh() { mem.VicRead((ushort)refreshAddress); @@ -1072,14 +1078,20 @@ namespace BizHawk.Emulation.Computers.Commodore64 private void PipelineIRQ0() { - if (RASTER == rasterInterruptLine && RASTER > 0) + if (!rasterInterruptTriggered && RASTER == rasterInterruptLine && RASTER > 0) + { IRST = true; + rasterInterruptTriggered = true; + } } private void PipelineIRQ1() { - if (RASTER == 0 && rasterInterruptLine == 0) + if (!rasterInterruptTriggered && RASTER == 0 && rasterInterruptLine == 0) + { IRST = true; + rasterInterruptTriggered = true; + } } private void PipelinePlot() @@ -1259,6 +1271,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 private void PipelineRasterAdvance() { + rasterInterruptTriggered = false; RASTER++; if (RASTER == rasterLines) { @@ -1332,9 +1345,25 @@ namespace BizHawk.Emulation.Computers.Commodore64 plotterBufferIndex = 0; bitmapColumn++; - rasterX++; - if (rasterX >= rasterWidth) - rasterX -= rasterWidth; + if (advanceX) + { + rasterX++; + if (rasterX >= rasterWidth) + rasterX -= rasterWidth; + } + } + } + + private void PipelineSetBA(bool val) + { + if (val) + { + if (fetchCounter == 0) + fetchCounter = 4; + } + else + { + fetchCounter = 0; } } diff --git a/BizHawk.Emulation/Computers/Commodore64/_VicIIRegs.cs b/BizHawk.Emulation/Computers/Commodore64/_VicIIRegs.cs index 6afbf6c7cc..aebeb32a6b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/_VicIIRegs.cs +++ b/BizHawk.Emulation/Computers/Commodore64/_VicIIRegs.cs @@ -71,6 +71,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 private bool spritePriority; private VicIINewSprite[] sprites; + private bool advanceX; private bool badline; private int bitmapColumn; private byte bitmapData; @@ -88,6 +89,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 private byte colorDataBus; private byte[] colorMemory; private bool displayEnabled; + private int fetchCounter; private int graphicsMode; private bool idle; private int plotterBufferIndex; @@ -97,6 +99,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 private int plotterPixel; private int[] plotterPixelBuffer; private int rasterInterruptLine; + private bool rasterInterruptTriggered; private int rasterLeft; private int rasterLines; private int rasterWidth; @@ -565,6 +568,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 switch (addr) { case 0x11: + rasterInterruptTriggered = false; rasterInterruptLine &= 0xFF; rasterInterruptLine |= (val & 0x80) << 1; // raster upper bit can't be changed, save and restore the value @@ -576,6 +580,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 break; case 0x12: // raster interrupt lower 8 bits + rasterInterruptTriggered = false; rasterInterruptLine &= 0x100; rasterInterruptLine |= (val & 0xFF); break; diff --git a/BizHawk.Emulation/Computers/Commodore64/_VicState.cs b/BizHawk.Emulation/Computers/Commodore64/_VicState.cs index 0fba9a0251..82f639d4c7 100644 --- a/BizHawk.Emulation/Computers/Commodore64/_VicState.cs +++ b/BizHawk.Emulation/Computers/Commodore64/_VicState.cs @@ -44,6 +44,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 ser.Sync("YSCROLL", ref YSCROLL); // state + ser.Sync("ADVANCEX", ref advanceX); ser.Sync("BADLINE", ref badline); ser.Sync("BITMAPCOLUMN", ref bitmapColumn); ser.Sync("BITMAPDATA", ref bitmapData); @@ -57,6 +58,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 ser.Sync("COLORDATABUS", ref colorDataBus); ser.Sync("COLORMEM", ref colorMemory, false); ser.Sync("DISPLAYENABLED", ref displayEnabled); + ser.Sync("FETCHCOUNTER", ref fetchCounter); ser.Sync("IDLE", ref idle); ser.Sync("PLOTTERBUFFERINDEX", ref plotterBufferIndex); ser.Sync("PLOTTERDATA", ref plotterData); @@ -65,6 +67,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 ser.Sync("PLOTTERPIXEL", ref plotterPixel); ser.Sync("PLOTTERPIXELBUFFER", ref plotterPixelBuffer, false); ser.Sync("RASTERINTERRUPTLINE", ref rasterInterruptLine); + ser.Sync("RASTERINTERRUPTTRIGGERED", ref rasterInterruptTriggered); ser.Sync("RASTERX", ref rasterX); ser.Sync("REFRESHADDRESS", ref refreshAddress);