From dbba216ec701e2cfec106f032c5272c10fb35a13 Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Sat, 3 Nov 2012 07:05:07 +0000 Subject: [PATCH] Commodore64 CIA - registers implemented --- .../Computers/Commodore64/Cia.cs | 70 +++++++++++-------- .../Computers/Commodore64/MemBus.cs | 12 +++- .../Computers/Commodore64/VicII.cs | 3 +- 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/BizHawk.Emulation/Computers/Commodore64/Cia.cs b/BizHawk.Emulation/Computers/Commodore64/Cia.cs index 7139809590..ab2bbc3336 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cia.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cia.cs @@ -8,13 +8,42 @@ namespace BizHawk.Emulation.Computers.Commodore64 public class Cia { public int cycles; + public bool flagPin; + public bool interrupt; public byte[] regs; - - public Cia() + public bool serialData; + public bool serialReady; + public int shiftRegisterCycles; + public bool shiftRegisterInterrupt; + public bool shiftRegisterInterruptEnabled; + public bool shiftRegisterIsOutput; + public bool timeOfDayAlarmInterrupt; + public bool timeOfDayAlarmInterruptEnabled; + public bool underflowTimerAInterrupt; + public bool underflowTimerAInterruptEnabled; + public bool underflowTimerBInterrupt; + public bool underflowTimerBInterruptEnabled; + + public Func ReadPortA; + public Func ReadPortB; + public Action WritePortA; + public Action WritePortB; + + public Cia(Func funcReadPortA, Func funcReadPortB, Action actWritePortA, Action actWritePortB) { regs = new byte[0x10]; } + static public byte DummyReadPort() + { + return 0xFF; + } + + static public void DummyWritePort(byte val, byte direction) + { + // do nothing + } + public void PerformCycle() { unchecked @@ -30,38 +59,21 @@ namespace BizHawk.Emulation.Computers.Commodore64 switch (addr & 0x0F) { case 0x00: + result = ReadPortA(); break; case 0x01: - break; - case 0x02: - break; - case 0x03: - break; - case 0x04: - break; - case 0x05: - break; - case 0x06: - break; - case 0x07: - break; - case 0x08: - break; - case 0x09: - break; - case 0x0A: - break; - case 0x0B: - break; - case 0x0C: + result = ReadPortB(); break; case 0x0D: - break; - case 0x0E: - break; - case 0x0F: + result = regs[addr]; + shiftRegisterInterrupt = false; + timeOfDayAlarmInterrupt = false; + underflowTimerAInterrupt = false; + underflowTimerBInterrupt = false; + interrupt = false; break; default: + result = regs[addr]; break; } @@ -73,8 +85,10 @@ namespace BizHawk.Emulation.Computers.Commodore64 switch (addr & 0x0F) { case 0x00: + WritePortA(val, regs[0x02]); break; case 0x01: + WritePortB(val, regs[0x03]); break; case 0x02: break; diff --git a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs index b8d02d6501..c3d71ee455 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MemBus.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MemBus.cs @@ -266,7 +266,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 result = sid.Read(addr); break; case MemoryBusDesignation.ColorRam: - result = (byte)((busData & 0xF0) | (colorRam[addr & 0x03FF])); + result = ReadColorRam(addr); break; case MemoryBusDesignation.Cia1: result = cia1.Read(addr); @@ -301,6 +301,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 return result; } + public byte ReadColorRam(ushort addr) + { + return (byte)((busData & 0xF0) | (colorRam[addr & 0x03FF])); + } + public void UpdateLayout() { bool loRom = ((cpu01 & 0x01) != 0); @@ -390,6 +395,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 } } + public byte VicRead(ushort addr) + { + return Read(addr); + } + public void WipeMemory() { for (int i = 0; i < 0x10000; i += 0x80) diff --git a/BizHawk.Emulation/Computers/Commodore64/VicII.cs b/BizHawk.Emulation/Computers/Commodore64/VicII.cs index 4c331e9b3f..39faf14bae 100644 --- a/BizHawk.Emulation/Computers/Commodore64/VicII.cs +++ b/BizHawk.Emulation/Computers/Commodore64/VicII.cs @@ -153,8 +153,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 if (rasterInterruptEnabled && (rasterOffsetY == rasterInterruptLine) && (rasterOffsetX == 0)) { - // removed for now - //rasterInterrupt = true; + rasterInterrupt = true; } interrupt =