diff --git a/Machines/Commodore/1540/Commodore1540.cpp b/Machines/Commodore/1540/Commodore1540.cpp index 521e0fdbf..3b4e3db67 100644 --- a/Machines/Commodore/1540/Commodore1540.cpp +++ b/Machines/Commodore/1540/Commodore1540.cpp @@ -30,7 +30,7 @@ void Machine::set_serial_bus(std::shared_ptr<::Commodore::Serial::Bus> serial_bu unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { -// if(operation == CPU6502::BusOperation::ReadOpcode && (address >= 0xE9C9 && address <= 0xEA2D)) printf("%04x\n", address); + if(operation == CPU6502::BusOperation::ReadOpcode && (address >= 0xF556 && address <= 0xF56D)) printf("%04x\n", address); // if(operation == CPU6502::BusOperation::ReadOpcode && (address == 0xE887)) printf("A: %02x\n", get_value_of_register(CPU6502::Register::A)); /* static bool log = false; @@ -56,10 +56,6 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin } else if(address >= 0x1800 && address <= 0x180f) { - if(address == 0x1805) - { - printf("Timer\n"); - } if(isReadOperation(operation)) *value = _serialPortVIA->get_register(address); else diff --git a/Machines/Commodore/1540/Commodore1540.hpp b/Machines/Commodore/1540/Commodore1540.hpp index baa350e69..40af76f4e 100644 --- a/Machines/Commodore/1540/Commodore1540.hpp +++ b/Machines/Commodore/1540/Commodore1540.hpp @@ -91,10 +91,23 @@ class DriveVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { uint8_t get_port_input(Port port) { if(port) { - return 0x7f; // imply not sync, write protect tab uncovered + return 0xff; // imply not sync, write protect tab uncovered } return 0xff; } + + void set_port_output(Port port, uint8_t value, uint8_t direction_mask) { + if(port) + { + if(value&4) + { + printf("Head step: %d\n", value&3); + printf("Motor: %s\n", value&4 ? "On" : "Off"); + printf("LED: %s\n", value&8 ? "On" : "Off"); + printf("Density: %d\n", (value >> 5)&3); + } + } + } }; class SerialPort : public ::Commodore::Serial::Port { diff --git a/Machines/Commodore/SerialBus.cpp b/Machines/Commodore/SerialBus.cpp index d3c3a5659..13ee704b3 100644 --- a/Machines/Commodore/SerialBus.cpp +++ b/Machines/Commodore/SerialBus.cpp @@ -45,14 +45,12 @@ void Bus::set_line_output_did_change(Line line) if(locked_port) { new_line_level = (LineLevel)((bool)new_line_level & (bool)locked_port->get_output(line)); -// printf("[%s] %s is now %s\n", typeid(locked_port).name(), (bool)locked_port->get_output(line) ? "high" : "low"); } } // post an update only if one occurred if(new_line_level != _line_levels[line]) { - printf("[Bus] %s is %s\n", StringForLine(line), new_line_level ? "high" : "low"); _line_levels[line] = new_line_level; for(std::weak_ptr port : _ports) @@ -65,3 +63,25 @@ void Bus::set_line_output_did_change(Line line) } } } + +#pragma mark - The debug port + +void DebugPort::set_input(Line line, LineLevel value) +{ + _input_levels[line] = value; + + printf("[Bus] %s is %s\n", StringForLine(line), value ? "high" : "low"); + if(!_incoming_count) + { + _incoming_count = (!_input_levels[Line::Clock] && !_input_levels[Line::Data]) ? 8 : 0; + } + else + { + if(line == Line::Clock && value) + { + _incoming_byte = (_incoming_byte >> 1) | (_input_levels[Line::Data] ? 0x80 : 0x00); + } + _incoming_count--; + if(_incoming_count == 0) printf("[Bus] Observed %02x\n", _incoming_byte); + } +} diff --git a/Machines/Commodore/SerialBus.hpp b/Machines/Commodore/SerialBus.hpp index 4b2b654f8..78ee5be70 100644 --- a/Machines/Commodore/SerialBus.hpp +++ b/Machines/Commodore/SerialBus.hpp @@ -71,6 +71,18 @@ namespace Serial { LineLevel _line_levels[5]; }; + class DebugPort: public Port { + public: + void set_input(Line line, LineLevel value); + + DebugPort() : _incoming_count(0) {} + + private: + uint8_t _incoming_byte; + int _incoming_count; + LineLevel _input_levels[5]; + }; + } } diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 5a0b6c049..5560a3a06 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -57,6 +57,10 @@ Machine::Machine() : // TEMPORARY: attach a [diskless] 1540 set_disc(); + + _debugPort.reset(new ::Commodore::Serial::DebugPort); + _debugPort->set_serial_bus(_serialBus); + _serialBus->add_port(_debugPort); } void Machine::write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint16_t length) diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index ee7f73800..49f11d6b4 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -295,6 +295,7 @@ class Machine: std::shared_ptr _keyboardVIA; std::shared_ptr _serialPort; std::shared_ptr<::Commodore::Serial::Bus> _serialBus; + std::shared_ptr<::Commodore::Serial::DebugPort> _debugPort; // Tape Tape _tape;