From d16b79073e98b145ac2f62cb86483069222050f1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 5 Jul 2016 17:27:02 -0400 Subject: [PATCH] Further fleshing out: added a serial port for the serial bus. --- Machines/Commodore/1540/Commodore1540.cpp | 22 +++++++++++++++++++++ Machines/Commodore/1540/Commodore1540.hpp | 24 +++++++++++++++++++++++ Machines/Commodore/Vic-20/Vic20.cpp | 4 ++++ Machines/Commodore/Vic-20/Vic20.hpp | 3 --- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Machines/Commodore/1540/Commodore1540.cpp b/Machines/Commodore/1540/Commodore1540.cpp index f53fa0527..14ed86671 100644 --- a/Machines/Commodore/1540/Commodore1540.cpp +++ b/Machines/Commodore/1540/Commodore1540.cpp @@ -11,6 +11,19 @@ using namespace Commodore::C1540; +Machine::Machine() +{ + _serialPortVIA.reset(new SerialPortVIA); + _serialPort.reset(new SerialPort); + _serialPort->set_serial_port_via(_serialPortVIA); +} + +void Machine::set_serial_bus(std::shared_ptr<::Commodore::Serial::Bus> serial_bus) +{ + _serialPort->set_serial_bus(serial_bus); + serial_bus->add_port(_serialPort); +} + unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { if(address < 0x800) @@ -25,6 +38,15 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin if(isReadOperation(operation)) *value = _rom[address & 0x3fff]; } + else if(address >= 0x1800 && address <= 0x180f) + { + if(isReadOperation(operation)) + *value = _serialPortVIA->get_register(address); + else + _serialPortVIA->set_register(address, *value); + } + + _serialPortVIA->run_for_half_cycles(2); return 1; } diff --git a/Machines/Commodore/1540/Commodore1540.hpp b/Machines/Commodore/1540/Commodore1540.hpp index 1e5608986..2975edd3e 100644 --- a/Machines/Commodore/1540/Commodore1540.hpp +++ b/Machines/Commodore/1540/Commodore1540.hpp @@ -11,21 +11,45 @@ #include "../../../Processors/6502/CPU6502.hpp" #include "../../../Components/6522/6522.hpp" +#include "../SerialBus.hpp" namespace Commodore { namespace C1540 { +class SerialPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { + public: + using MOS6522IRQDelegate::set_interrupt_status; +}; + +class SerialPort : public ::Commodore::Serial::Port { + public: + void set_input(::Commodore::Serial::Line line, bool value) { + } + + void set_serial_port_via(std::shared_ptr serialPortVIA) { + _serialPortVIA = serialPortVIA; + } + + private: + std::weak_ptr _serialPortVIA; +}; + class Machine: public CPU6502::Processor { public: + Machine(); unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); void set_rom(const uint8_t *rom); + void set_serial_bus(std::shared_ptr<::Commodore::Serial::Bus> serial_bus); private: uint8_t _ram[0x800]; uint8_t _rom[0x4000]; + + std::shared_ptr _serialPortVIA; + std::shared_ptr _serialPort; }; } diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index ba463e594..fb616ec80 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -335,5 +335,9 @@ void Tape::process_input_pulse(Storage::Tape::Pulse pulse) void Machine::set_disc() { + // construct the 1540 _c1540.reset(new ::Commodore::C1540::Machine); + + // attach it to the serial bus + _c1540->set_serial_bus(_serialBus); } diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 9f625531e..386001b61 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -60,9 +60,6 @@ enum JoystickInput { Fire = 0x20 }; -class UserPortVIA; -class KeyboardVIA; - class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { public: uint8_t get_port_input(Port port) {