commodore64: video is now more cycle accurate on NTSC

This commit is contained in:
saxxonpike 2012-11-22 15:48:48 +00:00
parent e70a387ffb
commit 710f8f07c9
3 changed files with 45 additions and 8 deletions

View File

@ -17,6 +17,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ {
pipelineGAccess = false; pipelineGAccess = false;
pipelineMemoryBusy = false; pipelineMemoryBusy = false;
advanceX = true;
foreach (Action a in pipeline[cycle]) foreach (Action a in pipeline[cycle])
a(); a();
@ -420,6 +421,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ // 61 { // 61
PipelineCycle, PipelineCycle,
PipelineFetchSprite1P, PipelineFetchSprite1P,
PipelineDisableAdvanceX,
PipelineRender PipelineRender
}, },
new Action[] new Action[]
@ -454,7 +456,6 @@ namespace BizHawk.Emulation.Computers.Commodore64
PipelineCycle, PipelineCycle,
PipelineIRQ0, PipelineIRQ0,
PipelineFetchSprite3P, PipelineFetchSprite3P,
PipelineBadlineDelay,
PipelineRender PipelineRender
}, },
new Action[] new Action[]
@ -462,7 +463,6 @@ namespace BizHawk.Emulation.Computers.Commodore64
PipelineCycle, PipelineCycle,
PipelineIRQ1, PipelineIRQ1,
PipelineFetchSprite3S, PipelineFetchSprite3S,
PipelineBadlineDelay,
PipelineRender PipelineRender
}, },
new Action[] new Action[]
@ -542,6 +542,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ // 14 { // 14
PipelineCycle, PipelineCycle,
PipelineDramRefresh, PipelineDramRefresh,
PipelineBadlineDelay,
PipelineRender PipelineRender
}, },
new Action[] new Action[]
@ -783,7 +784,6 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ // 54 { // 54
PipelineCycle, PipelineCycle,
PipelineFetchC, PipelineFetchC,
PipelineSpriteMYEFlip,
PipelineSpriteEnable0, PipelineSpriteEnable0,
PipelineRender PipelineRender
}, },
@ -791,6 +791,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
{ // 55 { // 55
PipelineCycle, PipelineCycle,
PipelineSpriteEnable1, PipelineSpriteEnable1,
PipelineSpriteMYEFlip,
PipelineIdle, PipelineIdle,
PipelineRender PipelineRender
}, },
@ -878,6 +879,11 @@ namespace BizHawk.Emulation.Computers.Commodore64
sprites[i].MxYEToggle = true; sprites[i].MxYEToggle = true;
} }
private void PipelineDisableAdvanceX()
{
advanceX = false;
}
private void PipelineDramRefresh() private void PipelineDramRefresh()
{ {
mem.VicRead((ushort)refreshAddress); mem.VicRead((ushort)refreshAddress);
@ -1072,14 +1078,20 @@ namespace BizHawk.Emulation.Computers.Commodore64
private void PipelineIRQ0() private void PipelineIRQ0()
{ {
if (RASTER == rasterInterruptLine && RASTER > 0) if (!rasterInterruptTriggered && RASTER == rasterInterruptLine && RASTER > 0)
{
IRST = true; IRST = true;
rasterInterruptTriggered = true;
}
} }
private void PipelineIRQ1() private void PipelineIRQ1()
{ {
if (RASTER == 0 && rasterInterruptLine == 0) if (!rasterInterruptTriggered && RASTER == 0 && rasterInterruptLine == 0)
{
IRST = true; IRST = true;
rasterInterruptTriggered = true;
}
} }
private void PipelinePlot() private void PipelinePlot()
@ -1259,6 +1271,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
private void PipelineRasterAdvance() private void PipelineRasterAdvance()
{ {
rasterInterruptTriggered = false;
RASTER++; RASTER++;
if (RASTER == rasterLines) if (RASTER == rasterLines)
{ {
@ -1332,9 +1345,25 @@ namespace BizHawk.Emulation.Computers.Commodore64
plotterBufferIndex = 0; plotterBufferIndex = 0;
bitmapColumn++; bitmapColumn++;
rasterX++; if (advanceX)
if (rasterX >= rasterWidth) {
rasterX -= rasterWidth; rasterX++;
if (rasterX >= rasterWidth)
rasterX -= rasterWidth;
}
}
}
private void PipelineSetBA(bool val)
{
if (val)
{
if (fetchCounter == 0)
fetchCounter = 4;
}
else
{
fetchCounter = 0;
} }
} }

View File

@ -71,6 +71,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
private bool spritePriority; private bool spritePriority;
private VicIINewSprite[] sprites; private VicIINewSprite[] sprites;
private bool advanceX;
private bool badline; private bool badline;
private int bitmapColumn; private int bitmapColumn;
private byte bitmapData; private byte bitmapData;
@ -88,6 +89,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
private byte colorDataBus; private byte colorDataBus;
private byte[] colorMemory; private byte[] colorMemory;
private bool displayEnabled; private bool displayEnabled;
private int fetchCounter;
private int graphicsMode; private int graphicsMode;
private bool idle; private bool idle;
private int plotterBufferIndex; private int plotterBufferIndex;
@ -97,6 +99,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
private int plotterPixel; private int plotterPixel;
private int[] plotterPixelBuffer; private int[] plotterPixelBuffer;
private int rasterInterruptLine; private int rasterInterruptLine;
private bool rasterInterruptTriggered;
private int rasterLeft; private int rasterLeft;
private int rasterLines; private int rasterLines;
private int rasterWidth; private int rasterWidth;
@ -565,6 +568,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
switch (addr) switch (addr)
{ {
case 0x11: case 0x11:
rasterInterruptTriggered = false;
rasterInterruptLine &= 0xFF; rasterInterruptLine &= 0xFF;
rasterInterruptLine |= (val & 0x80) << 1; rasterInterruptLine |= (val & 0x80) << 1;
// raster upper bit can't be changed, save and restore the value // raster upper bit can't be changed, save and restore the value
@ -576,6 +580,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
break; break;
case 0x12: case 0x12:
// raster interrupt lower 8 bits // raster interrupt lower 8 bits
rasterInterruptTriggered = false;
rasterInterruptLine &= 0x100; rasterInterruptLine &= 0x100;
rasterInterruptLine |= (val & 0xFF); rasterInterruptLine |= (val & 0xFF);
break; break;

View File

@ -44,6 +44,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
ser.Sync("YSCROLL", ref YSCROLL); ser.Sync("YSCROLL", ref YSCROLL);
// state // state
ser.Sync("ADVANCEX", ref advanceX);
ser.Sync("BADLINE", ref badline); ser.Sync("BADLINE", ref badline);
ser.Sync("BITMAPCOLUMN", ref bitmapColumn); ser.Sync("BITMAPCOLUMN", ref bitmapColumn);
ser.Sync("BITMAPDATA", ref bitmapData); ser.Sync("BITMAPDATA", ref bitmapData);
@ -57,6 +58,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
ser.Sync("COLORDATABUS", ref colorDataBus); ser.Sync("COLORDATABUS", ref colorDataBus);
ser.Sync("COLORMEM", ref colorMemory, false); ser.Sync("COLORMEM", ref colorMemory, false);
ser.Sync("DISPLAYENABLED", ref displayEnabled); ser.Sync("DISPLAYENABLED", ref displayEnabled);
ser.Sync("FETCHCOUNTER", ref fetchCounter);
ser.Sync("IDLE", ref idle); ser.Sync("IDLE", ref idle);
ser.Sync("PLOTTERBUFFERINDEX", ref plotterBufferIndex); ser.Sync("PLOTTERBUFFERINDEX", ref plotterBufferIndex);
ser.Sync("PLOTTERDATA", ref plotterData); ser.Sync("PLOTTERDATA", ref plotterData);
@ -65,6 +67,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
ser.Sync("PLOTTERPIXEL", ref plotterPixel); ser.Sync("PLOTTERPIXEL", ref plotterPixel);
ser.Sync("PLOTTERPIXELBUFFER", ref plotterPixelBuffer, false); ser.Sync("PLOTTERPIXELBUFFER", ref plotterPixelBuffer, false);
ser.Sync("RASTERINTERRUPTLINE", ref rasterInterruptLine); ser.Sync("RASTERINTERRUPTLINE", ref rasterInterruptLine);
ser.Sync("RASTERINTERRUPTTRIGGERED", ref rasterInterruptTriggered);
ser.Sync("RASTERX", ref rasterX); ser.Sync("RASTERX", ref rasterX);
ser.Sync("REFRESHADDRESS", ref refreshAddress); ser.Sync("REFRESHADDRESS", ref refreshAddress);