From be37d1dc5339d481ced0a3983bec35890b66275e Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Mon, 3 Dec 2012 06:08:12 +0000 Subject: [PATCH] commodore64: crop screen, fix sound pulsewidth register writing (it was being processed as 16 bits instead of 12) --- .../Commodore64/MOS/Sid.SyncSoundProvider.cs | 21 ++++++++++++--- .../Computers/Commodore64/MOS/Sid.cs | 10 +++---- .../Commodore64/MOS/Vic.VideoProvider.cs | 9 ++++--- .../Computers/Commodore64/MOS/Vic.cs | 26 ++++++++++++++----- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs index 8293f50c7e..46e856d17c 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.SyncSoundProvider.cs @@ -9,14 +9,27 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { public void GetSamples(out short[] samples, out int nsamp) { - samples = buffer; - nsamp = (int)bufferIndex; - bufferIndex = 0; + if (bufferIndex > bufferReadOffset) + samples = new short[bufferIndex - bufferReadOffset]; + else + samples = new short[bufferIndex + (bufferLength - bufferReadOffset)]; + + nsamp = samples.Length; + for (uint i = 0; i < nsamp; i++) + { + samples[i] = buffer[bufferReadOffset]; + if (bufferReadOffset != bufferIndex) + bufferReadOffset++; + if (bufferReadOffset == bufferLength) + bufferReadOffset = 0; + } + nsamp /= 2; } public void DiscardSamples() { - // todo + bufferIndex = 0; + bufferReadOffset = 0; } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs index 1cbeb3701a..06a4b9c952 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs @@ -488,7 +488,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } set { - pulseWidth &= 0xFF00; + pulseWidth &= 0x0F00; pulseWidth |= value & 0x00FF; } } @@ -502,7 +502,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS set { pulseWidth &= 0x00FF; - pulseWidth |= (value & 0x00FF) << 8; + pulseWidth |= (value & 0x000F) << 8; } } @@ -639,9 +639,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS voices[i].Synchronize(voices[syncNextTable[i]], voices[syncPrevTable[i]]); // get output - voiceOutput[0] = voices[0].Output(voices[1]); - voiceOutput[1] = voices[1].Output(voices[2]); - voiceOutput[2] = voices[2].Output(voices[0]); + voiceOutput[0] = voices[0].Output(voices[2]); + voiceOutput[1] = voices[1].Output(voices[0]); + voiceOutput[2] = voices[2].Output(voices[1]); envelopeOutput[0] = envelopes[0].Level; envelopeOutput[1] = envelopes[1].Level; envelopeOutput[2] = envelopes[2].Level; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs index 43c1a40ccf..eb8968c80b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; @@ -11,6 +12,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS private int bufHeight; private uint bufLength; private uint bufOffset; + private Point bufPoint; + private Rectangle bufRect; private int bufWidth; // palette @@ -41,12 +44,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public int BufferHeight { - get { return bufHeight; } + get { return bufRect.Height; } } public int BufferWidth { - get { return bufWidth; } + get { return bufRect.Width; } } public int[] GetVideoBuffer() @@ -56,7 +59,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public int VirtualWidth { - get { return bufWidth; } + get { return bufRect.Width; } } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs index b778840c15..b7e6c2e35e 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; @@ -147,11 +148,12 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS cyclesPerSec = newCyclesPerSec; pixelBufferDelay = 12; pixelBackgroundBufferDelay = 4; + bufRect = new Rectangle(136 - 24, 51 - 24, 320 + 48, 200 + 48); + buf = new int[bufRect.Width * bufRect.Height]; + bufLength = (uint)buf.Length; bufWidth = (int)(totalCycles * 8); bufHeight = (int)(totalLines); - buf = new int[bufWidth * bufHeight]; - bufLength = (uint)buf.Length; sprites = new Sprite[8]; for (uint i = 0; i < 8; i++) @@ -618,10 +620,22 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // recall pixel from buffer pixel = pixelBuffer[pixelBufferIndex]; - buf[bufOffset] = palette[pixel]; - bufOffset++; - if (bufOffset == bufLength) - bufOffset = 0; + // plot pixel if within viewing area + if (bufRect.Contains(bufPoint)) + { + buf[bufOffset] = palette[pixel]; + bufOffset++; + if (bufOffset == bufLength) + bufOffset = 0; + } + bufPoint.X++; + if (bufPoint.X == bufWidth) + { + bufPoint.X = 0; + bufPoint.Y++; + if (bufPoint.Y == bufHeight) + bufPoint.Y = 0; + } // put the pixel from the background buffer into the main buffer pixel = pixelBackgroundBuffer[pixelBackgroundBufferIndex];