From c02eeaf08cf169e88f708db297e68556b4060a97 Mon Sep 17 00:00:00 2001 From: SaxxonPike Date: Thu, 25 Jul 2019 15:42:09 -0500 Subject: [PATCH] C64: Implement sprite crunch and better vsync rates. --- .../Computers/Commodore64/MOS/Chip6567R56A.cs | 3 +- .../Computers/Commodore64/MOS/Chip6567R8.cs | 3 +- .../Computers/Commodore64/MOS/Chip6569.cs | 3 +- .../Computers/Commodore64/MOS/Chip6572.cs | 3 +- .../Computers/Commodore64/MOS/Vic.Parse.cs | 31 +++++++++---------- .../Commodore64/MOS/Vic.TimingBuilder.cs | 2 +- .../Commodore64/MOS/Vic.VideoProvider.cs | 4 +-- .../Computers/Commodore64/MOS/Vic.cs | 10 +++--- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R56A.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R56A.cs index 5189d725de..7cb3045b17 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R56A.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R56A.cs @@ -30,7 +30,8 @@ return new Vic( Cycles, Lines, Pipeline, - 14318181 / 14, + 14318181, + 14, HblankStart, HblankEnd, Vblankstart, VblankEnd, borderType, diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R8.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R8.cs index 2dd10cbb5a..9ef3b3a328 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R8.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6567R8.cs @@ -30,7 +30,8 @@ return new Vic( Cycles, Lines, Pipeline, - 14318181 / 14, + 14318181, + 14, HblankStart, HblankEnd, VblankStart, VblankEnd, borderType, diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6569.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6569.cs index e0f93f61ef..ac7d0b3187 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6569.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6569.cs @@ -30,7 +30,8 @@ return new Vic( Cycles, Lines, Pipeline, - 17734472 / 18, + 17734472, + 18, HblankStart, HblankEnd, VblankStart, VblankEnd, borderType, diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6572.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6572.cs index e97a668f03..5eae9bb48c 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6572.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Chip6572.cs @@ -30,7 +30,8 @@ return new Vic( Cycles, Lines, Pipeline, - 14328225 / 14, + 14328225, + 14, HblankStart, HblankEnd, VblankStart, VblankEnd, borderType, diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.Parse.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.Parse.cs index 0537bd234d..c534234acd 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.Parse.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.Parse.cs @@ -267,6 +267,20 @@ _borderCheckLEnable = (_parseAct & (PipelineBorderLeft0 | PipelineBorderLeft1)) != 0; _borderCheckREnable = (_parseAct & (PipelineBorderRight0 | PipelineBorderRight1)) != 0; + if ((_parseAct & PipelineUpdateMcBase) != 0) // VIC addendum sprite rule 7 + { + foreach (var spr in _sprites) + { + if (spr.YCrunch) + spr.Mcbase = spr.Mc; + else if (!spr.YExpand) + spr.Mcbase = SpriteCrunchTable[spr.Mcbase]; + + if (spr.Mcbase == 63) + spr.Dma = false; + } + } + foreach (var spr in _sprites) // sprite rule 1 { if (!spr.YExpand) @@ -274,22 +288,7 @@ spr.YCrunch = true; } } - - if ((_parseAct & PipelineUpdateMcBase) != 0) // VIC addendum sprite rule 7 - { - foreach (var spr in _sprites) - { - if (spr.YCrunch) - { - spr.Mcbase = spr.Mc; - if (spr.Mcbase == 63) - { - spr.Dma = false; - } - } - } - } - + if ((_parseAct & PipelineSpriteDma) != 0) // sprite rule 3 { foreach (var spr in _sprites) diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.TimingBuilder.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.TimingBuilder.cs index 03303a3c9f..da2427fcff 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.TimingBuilder.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.TimingBuilder.cs @@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS private static readonly int[] TimingBuilderCycle14Act = { PipelineUpdateVc, 0, - PipelineSpriteCrunch, 0, + PipelineSpriteCrunch, PipelineSpriteCrunch, PipelineUpdateMcBase, 0, }; diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs index 49e90f8c26..7cbdbaf001 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.VideoProvider.cs @@ -50,8 +50,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS public int VirtualHeight { get; private set; } - public int VsyncNumerator => CyclesPerSecond; + public int VsyncNumerator => _cyclesPerSecNum; - public int VsyncDenominator => CyclesPerFrame; + public int VsyncDenominator => CyclesPerFrame * _cyclesPerSecDen; } } diff --git a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.cs b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.cs index b66168b01e..4cba3604d6 100644 --- a/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.cs +++ b/BizHawk.Emulation.Cores/Computers/Commodore64/MOS/Vic.cs @@ -28,7 +28,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS public bool ReadBa() { return _pinBa; } public bool ReadIrq() { return (_irqBuffer & 1) == 0; } - private readonly int _cyclesPerSec; private readonly int[] _rasterXPipeline; private readonly int[] _fetchPipeline; private readonly int[] _baPipeline; @@ -42,8 +41,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS private readonly int _pixelRatioNum; private readonly int _pixelRatioDen; + private readonly int _cyclesPerSecNum; + private readonly int _cyclesPerSecDen; - public Vic(int newCycles, int newLines, IList newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd, C64.BorderType borderType, int pixelRatioNum, int pixelRatioDen) + public Vic(int newCycles, int newLines, IList newPipeline, int cyclesPerSecNum, int cyclesPerSecDen, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd, C64.BorderType borderType, int pixelRatioNum, int pixelRatioDen) { Debug.WriteLine("C64 VIC timings:"); Debug.WriteLine("RX FTCH BA ACT"); @@ -61,7 +62,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS _actPipeline = newPipeline[3]; _totalCycles = newCycles; _totalLines = newLines; - _cyclesPerSec = newCyclesPerSec; + _cyclesPerSecNum = cyclesPerSecNum; + _cyclesPerSecDen = cyclesPerSecDen; ConfigureBlanking(newLines, hblankStart, hblankEnd, vblankStart, vblankEnd, borderType); @@ -184,8 +186,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS public int CyclesPerFrame => _totalCycles * _totalLines; - public int CyclesPerSecond => _cyclesPerSec; - public void ExecutePhase1() { // phi1