diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index af4f4db76..a4d8e7523 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -28,7 +28,7 @@ Machine::Machine() : // wire up 6522s and serial port _userPortVIA->set_serial_port(_serialPort); _keyboardVIA->set_serial_port(_serialPort); - _serialPort->set_vias(_userPortVIA, _keyboardVIA); + _serialPort->set_user_port_via(_userPortVIA); // wire up the 6522s, tape and machine _userPortVIA->set_delegate(this); @@ -323,10 +323,3 @@ void Tape::process_input_pulse(Storage::Tape::Pulse pulse) if(_delegate) _delegate->tape_did_change_input(this); } } - -#pragma mark - Serial Port - -void SerialPort::set_input(::Commodore::Serial::Line line, bool value) -{ - printf("Serial port line %d: %s\n", line, value ? "on" : "off"); -} diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index ea91d4516..1791b4034 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -61,20 +61,6 @@ enum JoystickInput { class UserPortVIA; class KeyboardVIA; -class SerialPort : public ::Commodore::Serial::Port { - public: - void set_input(::Commodore::Serial::Line line, bool value); - - void set_vias(std::shared_ptr userPortVIA, std::shared_ptr keyboardVIA) { - _userPortVIA = userPortVIA; - _keyboardVIA = keyboardVIA; - } - - private: - std::weak_ptr _userPortVIA; - std::weak_ptr _keyboardVIA; -}; - class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { public: uint8_t get_port_input(Port port) { @@ -90,6 +76,15 @@ class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg // } } + void set_serial_line_state(::Commodore::Serial::Line line, bool value) { + printf("Serial port line %d: %s\n", line, value ? "on" : "off"); + switch(line) { + default: break; + case ::Commodore::Serial::Line::Data: _portA = (_portA & ~0x02) | (value ? 0 : 0x02); break; + case ::Commodore::Serial::Line::Clock: _portA = (_portA & ~0x01) | (value ? 0 : 0x01); break; + } + } + void set_joystick_state(JoystickInput input, bool value) { if(input != JoystickInput::Right) { @@ -99,7 +94,7 @@ class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg void set_port_output(Port port, uint8_t value, uint8_t mask) { if(!port) { - std::shared_ptr serialPort = _serialPort.lock(); + std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); if(serialPort) serialPort->set_output(::Commodore::Serial::Line::Attention, !(value&0x80)); } } @@ -108,13 +103,13 @@ class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg UserPortVIA() : _portA(0xbf) {} - void set_serial_port(std::shared_ptr serialPort) { + void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort) { _serialPort = serialPort; } private: uint8_t _portA; - std::weak_ptr _serialPort; + std::weak_ptr<::Commodore::Serial::Port> _serialPort; }; class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { @@ -156,7 +151,7 @@ class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg void set_control_line_output(Port port, Line line, bool value) { if(line == Line::Two) { - std::shared_ptr serialPort = _serialPort.lock(); + std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); if(serialPort) { if(port == Port::A) { serialPort->set_output(::Commodore::Serial::Line::Clock, value); @@ -176,7 +171,7 @@ class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg using MOS6522IRQDelegate::set_interrupt_status; - void set_serial_port(std::shared_ptr serialPort) { + void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort) { _serialPort = serialPort; } @@ -184,7 +179,22 @@ class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg uint8_t _portB; uint8_t _columns[8]; uint8_t _activation_mask; - std::weak_ptr _serialPort; + std::weak_ptr<::Commodore::Serial::Port> _serialPort; +}; + +class SerialPort : public ::Commodore::Serial::Port { + public: + void set_input(::Commodore::Serial::Line line, bool value) { + std::shared_ptr userPortVIA = _userPortVIA.lock(); + if(userPortVIA) userPortVIA->set_serial_line_state(line, value); + } + + void set_user_port_via(std::shared_ptr userPortVIA) { + _userPortVIA = userPortVIA; + } + + private: + std::weak_ptr _userPortVIA; }; class Tape: public Storage::TapePlayer {