From 020dedb1a0c541d9cba2ec3653db317c807e3c27 Mon Sep 17 00:00:00 2001 From: saxxonpike Date: Thu, 15 Nov 2012 08:36:06 +0000 Subject: [PATCH] commodore64: updated directional dataport, keyboard input now works fully- commands can be executed in BASIC --- .../Computers/Commodore64/C64.core.cs | 2 + .../Computers/Commodore64/DataPort.cs | 65 +++++++++++++++---- .../Computers/Commodore64/Input.cs | 10 +-- .../Computers/Commodore64/PRGFile.cs | 35 ---------- 4 files changed, 62 insertions(+), 50 deletions(-) diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.core.cs b/BizHawk.Emulation/Computers/Commodore64/C64.core.cs index 78eb1f66ef..3094e2101e 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.core.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.core.cs @@ -75,6 +75,8 @@ namespace BizHawk.Emulation.Computers.Commodore64 // initailize input input = new Input( new DataPortConnector[] { cia0.ConnectPort(0), cia0.ConnectPort(1) } ); + cia0.AttachWriteHook(0, input.WritePortA); + cia0.AttachWriteHook(1, input.WritePortB); // initialize media switch (extension.ToUpper()) diff --git a/BizHawk.Emulation/Computers/Commodore64/DataPort.cs b/BizHawk.Emulation/Computers/Commodore64/DataPort.cs index 5f95699bbd..038065f5e1 100644 --- a/BizHawk.Emulation/Computers/Commodore64/DataPort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/DataPort.cs @@ -11,13 +11,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 private bool[] connected = new bool[2]; private byte[] direction = new byte[2]; private byte[] latch = new byte[2]; + private List servingHooks = new List(); private List writeHooks = new List(); public DataPortBus() { connectors = new DataPortConnector[2]; - connectors[0] = new DataPortConnector(ReadData0, ReadDirection0, WriteData0, WriteDirection0); - connectors[1] = new DataPortConnector(ReadData1, ReadDirection1, WriteData1, WriteDirection1); + connectors[0] = new DataPortConnector(ReadData0, ReadDirection0, ReadRemoteData0, WriteData0, WriteDirection0); + connectors[1] = new DataPortConnector(ReadData1, ReadDirection1, ReadRemoteData1, WriteData1, WriteDirection1); connected[0] = false; connected[1] = false; direction[0] = 0x00; @@ -29,6 +30,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 public void AttachWriteHook(Action act) { writeHooks.Add(act); + servingHooks.Add(0); + } + + private void ClearHooks() + { + int count = servingHooks.Count; + for (int i = 0; i < count; i++) + servingHooks[i]--; } public DataPortConnector Connect() @@ -64,6 +73,24 @@ namespace BizHawk.Emulation.Computers.Commodore64 } } + private void ExecuteWriteHooks() + { + int count = servingHooks.Count; + for (int i = 0; i < count; i++) + { + if (servingHooks[i] == 0) + { + servingHooks[i]++; + writeHooks[i](); + } + else + { + servingHooks[i]++; + } + } + ClearHooks(); + } + private byte ReadData0() { if (connected[1]) @@ -90,34 +117,40 @@ namespace BizHawk.Emulation.Computers.Commodore64 return direction[1]; } + private byte ReadRemoteData0() + { + return latch[1]; + } + + private byte ReadRemoteData1() + { + return latch[0]; + } + private void WriteData0(byte val) { latch[0] &= (byte)~direction[0]; latch[0] |= (byte)(val & direction[0]); - foreach (Action hook in writeHooks) - hook(); + ExecuteWriteHooks(); } private void WriteData1(byte val) { latch[1] &= (byte)~direction[1]; latch[1] |= (byte)(val & direction[1]); - foreach (Action hook in writeHooks) - hook(); + ExecuteWriteHooks(); } private void WriteDirection0(byte val) { direction[0] = val; - foreach (Action hook in writeHooks) - hook(); + ExecuteWriteHooks(); } private void WriteDirection1(byte val) { direction[1] = val; - foreach (Action hook in writeHooks) - hook(); + ExecuteWriteHooks(); } } @@ -125,13 +158,15 @@ namespace BizHawk.Emulation.Computers.Commodore64 { private Func ReadData; private Func ReadDirection; + private Func ReadRemoteData; private Action WriteData; private Action WriteDirection; - public DataPortConnector(Func newReadData, Func newReadDirection, Action newWriteData, Action newWriteDirection) + public DataPortConnector(Func newReadData, Func newReadDirection, Func newReadRemoteData, Action newWriteData, Action newWriteDirection) { ReadData = newReadData; ReadDirection = newReadDirection; + ReadRemoteData = newReadRemoteData; WriteData = newWriteData; WriteDirection = newWriteDirection; } @@ -160,6 +195,14 @@ namespace BizHawk.Emulation.Computers.Commodore64 } } + public byte RemoteData + { + get + { + return ReadRemoteData(); + } + } + public DataPortListener Listener() { return new DataPortListener(ReadData, ReadDirection); diff --git a/BizHawk.Emulation/Computers/Commodore64/Input.cs b/BizHawk.Emulation/Computers/Commodore64/Input.cs index d1b7453b10..a7d8baa647 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Input.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Input.cs @@ -65,6 +65,8 @@ namespace BizHawk.Emulation.Computers.Commodore64 result |= controller[keyboardMatrix[row, 5]] ? (byte)0x00 : (byte)0x20; result |= controller[keyboardMatrix[row, 6]] ? (byte)0x00 : (byte)0x40; result |= controller[keyboardMatrix[row, 7]] ? (byte)0x00 : (byte)0x80; + if (result != 0xFF) + row = row; return result; } @@ -101,17 +103,17 @@ namespace BizHawk.Emulation.Computers.Commodore64 ports[1].Data = port1result; } - public void WritePortA(byte data) + public void WritePortA() { // keyboard matrix column select - keyboardColumnData = data; + keyboardColumnData = ports[0].RemoteData; UpdatePortData(); } - public void WritePortB(byte data) + public void WritePortB() { // keyboard matrix row select - keyboardRowData = data; + keyboardRowData = ports[1].RemoteData; UpdatePortData(); } } diff --git a/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs b/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs index 245a40df46..30e9a8f4ca 100644 --- a/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs +++ b/BizHawk.Emulation/Computers/Commodore64/PRGFile.cs @@ -33,41 +33,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 mem.Write((ushort)(address & 0xFFFF), data[i]); address++; } - - if (data[0x06] == 0x9E) - { - // sys command - bool isNumber = false; - int sysAddress = 0; - int sysIndex = 0x07; - while (data[sysIndex] != 0) - { - if (!isNumber) - { - if (data[sysIndex] >= 0x30 && data[sysIndex] <= 0x39) - { - isNumber = true; - } - else - { - sysIndex++; - } - } - if (isNumber) - { - sysAddress *= 10; - sysAddress += (data[sysIndex] & 0xF); - sysIndex++; - if (data[sysIndex] < 0x30 || data[sysIndex] > 0x39) - break; - } - } - if (sysAddress > 0 && sysAddress < 0x10000) - { - cpu.PC = (ushort)sysAddress; - } - } - loaded = true; }