From 81e6cc34e5b143e2a3b2bc45df52f7d3934f6340 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 7 Jul 2016 06:57:21 -0400 Subject: [PATCH] Per the ROM disassembly, the Vic's VIA outputs are inverted for the benefit of the serial bus. --- Machines/Commodore/Vic-20/Vic20.hpp | 8 +++++--- OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 6a512633c..39ce2b35b 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -92,10 +92,11 @@ class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg } void set_port_output(Port port, uint8_t value, uint8_t mask) { + // Line 7 of port A is inverted and output as serial ATN if(!port) { std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); if(serialPort) - serialPort->set_output(::Commodore::Serial::Line::Attention, (::Commodore::Serial::LineLevel)(value&0x80)); + serialPort->set_output(::Commodore::Serial::Line::Attention, (::Commodore::Serial::LineLevel)!(value&0x80)); } } @@ -153,10 +154,11 @@ class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg if(line == Line::Two) { std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); if(serialPort) { + // CB2 is inverted to become serial data; CA2 is inverted to become serial clock if(port == Port::A) { - serialPort->set_output(::Commodore::Serial::Line::Clock, (::Commodore::Serial::LineLevel)value); + serialPort->set_output(::Commodore::Serial::Line::Clock, (::Commodore::Serial::LineLevel)!value); } else { - serialPort->set_output(::Commodore::Serial::Line::Data, (::Commodore::Serial::LineLevel)value); + serialPort->set_output(::Commodore::Serial::Line::Data, (::Commodore::Serial::LineLevel)!value); } } } diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm index 6407fcd9e..bb0be94d3 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSVic20.mm @@ -144,7 +144,9 @@ using namespace Commodore::Vic20; _vic20.set_key_state((Key)targetKey.integerValue, isPressed); } else + { NSLog(@"Unmapped: %02x", key); + } } break; case VK_Shift: