From d7c1f5b18a5e2b968885c5233d98cbd1f6a84255 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 11 Jun 2016 11:50:37 -0400 Subject: [PATCH] Made an attempt at hooking up the '2' and '4' keys. A mostly unsuccessful attempt. 2 does nothing, 4 clears the screen. --- Machines/Vic-20/Vic20.hpp | 38 +++++++++++++++++++ .../Mac/Clock Signal/Wrappers/CSElectron.h | 3 +- .../Clock Signal/Wrappers/CSKeyboardMachine.h | 2 + .../Mac/Clock Signal/Wrappers/CSVic20.mm | 7 ++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Machines/Vic-20/Vic20.hpp b/Machines/Vic-20/Vic20.hpp index 05092f96c..7fa8dbdc6 100644 --- a/Machines/Vic-20/Vic20.hpp +++ b/Machines/Vic-20/Vic20.hpp @@ -22,10 +22,47 @@ enum ROMSlot { ROMSlotCharacters, }; + +#define key(line, mask) (((mask) << 3) | (line)) + +enum Key: uint16_t { + Key2 = key(7, 0x80), Key4 = key(7, 0x40) +}; + class UserPortVIA: public MOS::MOS6522 { }; class KeyboardVIA: public MOS::MOS6522 { + public: + void set_key_state(Key key, bool isPressed) { + if(isPressed) + _columns[key & 0x07] &= ~(key >> 3); + else + _columns[key & 0x07] |= (key >> 3); + } + + // to satisfy MOS::MOS6522 + uint8_t get_port_input(int port) { + if(!port) { + uint8_t result = 0xff; + for(int c = 0; c < 8; c++) + { + if(!(_activation_mask&(1 << c))) result &= _columns[c]; + } + return result; + } + + return 0xff; + } + + void set_port_output(int port, uint8_t value) { + if(port) _activation_mask = value; + } + + KeyboardVIA() : _columns{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} {} + private: + uint8_t _columns[8]; + uint8_t _activation_mask; }; class Machine: public CPU6502::Processor, public CRTMachine::Machine, public MOS::MOS6522Delegate { @@ -34,6 +71,7 @@ class Machine: public CPU6502::Processor, public CRTMachine::Machine, p void set_rom(ROMSlot slot, size_t length, const uint8_t *data); void add_prg(size_t length, const uint8_t *data); + void set_key_state(Key key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); } // to satisfy CPU6502::Processor unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h index 7f546434f..1de8ac9e0 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h @@ -6,8 +6,7 @@ // Copyright © 2016 Thomas Harte. All rights reserved. // -#include "CSMachine.h" -#import "KeyCodes.h" +#import "CSMachine.h" #import "CSKeyboardMachine.h" @interface CSElectron : CSMachine diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSKeyboardMachine.h b/OSBindings/Mac/Clock Signal/Wrappers/CSKeyboardMachine.h index bba3b77b7..34f3dea0f 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSKeyboardMachine.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSKeyboardMachine.h @@ -6,6 +6,8 @@ // Copyright © 2016 Thomas Harte. All rights reserved. // +#import "KeyCodes.h" + @protocol CSKeyboardMachine - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm index cee3469d3..cd9209d60 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSVic20.mm @@ -39,6 +39,13 @@ } - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed { + @synchronized(self) { + switch(key) + { + case VK_ANSI_2: _vic20.set_key_state(Vic20::Key::Key2, isPressed); break; + case VK_ANSI_4: _vic20.set_key_state(Vic20::Key::Key4, isPressed); break; + } + } } - (void)clearAllKeys {