From 063a62372f65ca7a27414d3f755e7b833ca0a096 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 3 Dec 2016 13:14:03 -0500 Subject: [PATCH] The Commodore serial bus and C1540 are now postfix underscorers. --- Machines/Commodore/1540/C1540.cpp | 147 +++++++++++++----------------- Machines/Commodore/1540/C1540.hpp | 54 ++++++----- Machines/Commodore/SerialBus.cpp | 24 ++--- Machines/Commodore/SerialBus.hpp | 30 +++--- 4 files changed, 117 insertions(+), 138 deletions(-) diff --git a/Machines/Commodore/1540/C1540.cpp b/Machines/Commodore/1540/C1540.cpp index 7aedc15a4..91f0ac665 100644 --- a/Machines/Commodore/1540/C1540.cpp +++ b/Machines/Commodore/1540/C1540.cpp @@ -13,21 +13,19 @@ using namespace Commodore::C1540; Machine::Machine() : - _shift_register(0), - Storage::Disk::Controller(1000000, 4, 300) + shift_register_(0), + Storage::Disk::Controller(1000000, 4, 300), + serial_port_(new SerialPort), + serial_port_VIA_(new SerialPortVIA) { - // create a serial port and a VIA to run it - _serialPortVIA.reset(new SerialPortVIA); - _serialPort.reset(new SerialPort); - // attach the serial port to its VIA and vice versa - _serialPort->set_serial_port_via(_serialPortVIA); - _serialPortVIA->set_serial_port(_serialPort); + serial_port_->set_serial_port_via(serial_port_VIA_); + serial_port_VIA_->set_serial_port(serial_port_); // set this instance as the delegate to receive interrupt requests from both VIAs - _serialPortVIA->set_interrupt_delegate(this); - _driveVIA.set_interrupt_delegate(this); - _driveVIA.set_delegate(this); + serial_port_VIA_->set_interrupt_delegate(this); + drive_VIA_.set_interrupt_delegate(this); + drive_VIA_.set_delegate(this); // set a bit rate set_expected_bit_length(Storage::Encodings::CommodoreGCR::length_of_a_bit_in_time_zone(3)); @@ -35,27 +33,11 @@ Machine::Machine() : void Machine::set_serial_bus(std::shared_ptr<::Commodore::Serial::Bus> serial_bus) { - Commodore::Serial::AttachPortAndBus(_serialPort, serial_bus); + Commodore::Serial::AttachPortAndBus(serial_port_, serial_bus); } unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { -// static bool log = false; -// if(operation == CPU6502::BusOperation::ReadOpcode && (address == 0xF3C0)) log = true; -// if(operation == CPU6502::BusOperation::ReadOpcode && log) printf("%04x\n", address); -// if(operation == CPU6502::BusOperation::ReadOpcode) printf("%04x\n", address); -// if(operation == CPU6502::BusOperation::ReadOpcode && (address >= 0xF510 && address <= 0xF553)) 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; - - if(operation == CPU6502::BusOperation::ReadOpcode) - { - log = (address >= 0xE85B && address <= 0xE907) || (address >= 0xE9C9 && address <= 0xEA2D); - if(log) printf("\n%04x: ", address); - } - if(log) printf("[%c %04x] ", isReadOperation(operation) ? 'r' : 'w', address);*/ - /* Memory map (given that I'm unsure yet on any potential mirroring): @@ -67,39 +49,39 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin if(address < 0x800) { if(isReadOperation(operation)) - *value = _ram[address]; + *value = ram_[address]; else - _ram[address] = *value; + ram_[address] = *value; } else if(address >= 0xc000) { if(isReadOperation(operation)) - *value = _rom[address & 0x3fff]; + *value = rom_[address & 0x3fff]; } else if(address >= 0x1800 && address <= 0x180f) { if(isReadOperation(operation)) - *value = _serialPortVIA->get_register(address); + *value = serial_port_VIA_->get_register(address); else - _serialPortVIA->set_register(address, *value); + serial_port_VIA_->set_register(address, *value); } else if(address >= 0x1c00 && address <= 0x1c0f) { if(isReadOperation(operation)) - *value = _driveVIA.get_register(address); + *value = drive_VIA_.get_register(address); else - _driveVIA.set_register(address, *value); + drive_VIA_.set_register(address, *value); } - _serialPortVIA->run_for_cycles(1); - _driveVIA.run_for_cycles(1); + serial_port_VIA_->run_for_cycles(1); + drive_VIA_.run_for_cycles(1); return 1; } void Machine::set_rom(const uint8_t *rom) { - memcpy(_rom, rom, sizeof(_rom)); + memcpy(rom_, rom, sizeof(rom_)); } void Machine::set_disk(std::shared_ptr disk) @@ -112,8 +94,8 @@ void Machine::set_disk(std::shared_ptr disk) void Machine::run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); - set_motor_on(_driveVIA.get_motor_enabled()); - if(_driveVIA.get_motor_enabled()) // TODO: motor speed up/down + set_motor_on(drive_VIA_.get_motor_enabled()); + if(drive_VIA_.get_motor_enabled()) // TODO: motor speed up/down Storage::Disk::Controller::run_for_cycles(number_of_cycles); } @@ -122,29 +104,29 @@ void Machine::run_for_cycles(int number_of_cycles) void Machine::mos6522_did_change_interrupt_status(void *mos6522) { // both VIAs are connected to the IRQ line - set_irq_line(_serialPortVIA->get_interrupt_line() || _driveVIA.get_interrupt_line()); + set_irq_line(serial_port_VIA_->get_interrupt_line() || drive_VIA_.get_interrupt_line()); } #pragma mark - Disk drive void Machine::process_input_bit(int value, unsigned int cycles_since_index_hole) { - _shift_register = (_shift_register << 1) | value; - if((_shift_register & 0x3ff) == 0x3ff) + shift_register_ = (shift_register_ << 1) | value; + if((shift_register_ & 0x3ff) == 0x3ff) { - _driveVIA.set_sync_detected(true); - _bit_window_offset = -1; // i.e. this bit isn't the first within a data window, but the next might be + drive_VIA_.set_sync_detected(true); + bit_window_offset_ = -1; // i.e. this bit isn't the first within a data window, but the next might be } else { - _driveVIA.set_sync_detected(false); + drive_VIA_.set_sync_detected(false); } - _bit_window_offset++; - if(_bit_window_offset == 8) + bit_window_offset_++; + if(bit_window_offset_ == 8) { - _driveVIA.set_data_input((uint8_t)_shift_register); - _bit_window_offset = 0; - if(_driveVIA.get_should_set_overflow()) + drive_VIA_.set_data_input((uint8_t)shift_register_); + bit_window_offset_ = 0; + if(drive_VIA_.get_should_set_overflow()) { set_overflow_line(true); } @@ -171,12 +153,12 @@ void Machine::drive_via_did_set_data_density(void *driveVIA, int density) #pragma mark - SerialPortVIA SerialPortVIA::SerialPortVIA() : - _portB(0x00), _attention_acknowledge_level(false), _attention_level_input(true), _data_level_output(false) + port_b_(0x00), attention_acknowledge_level_(false), attention_level_input_(true), data_level_output_(false) {} uint8_t SerialPortVIA::get_port_input(Port port) { - if(port) return _portB; + if(port) return port_b_; return 0xff; } @@ -184,10 +166,10 @@ void SerialPortVIA::set_port_output(Port port, uint8_t value, uint8_t mask) { if(port) { - std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); + std::shared_ptr<::Commodore::Serial::Port> serialPort = serial_port_.lock(); if(serialPort) { - _attention_acknowledge_level = !(value&0x10); - _data_level_output = (value&0x02); + attention_acknowledge_level_ = !(value&0x10); + data_level_output_ = (value&0x02); serialPort->set_output(::Commodore::Serial::Line::Clock, (::Commodore::Serial::LineLevel)!(value&0x08)); update_data_line(); @@ -200,31 +182,30 @@ void SerialPortVIA::set_serial_line_state(::Commodore::Serial::Line line, bool v switch(line) { default: break; - case ::Commodore::Serial::Line::Data: _portB = (_portB & ~0x01) | (value ? 0x00 : 0x01); break; - case ::Commodore::Serial::Line::Clock: _portB = (_portB & ~0x04) | (value ? 0x00 : 0x04); break; + case ::Commodore::Serial::Line::Data: port_b_ = (port_b_ & ~0x01) | (value ? 0x00 : 0x01); break; + case ::Commodore::Serial::Line::Clock: port_b_ = (port_b_ & ~0x04) | (value ? 0x00 : 0x04); break; case ::Commodore::Serial::Line::Attention: - _attention_level_input = !value; - _portB = (_portB & ~0x80) | (value ? 0x00 : 0x80); + attention_level_input_ = !value; + port_b_ = (port_b_ & ~0x80) | (value ? 0x00 : 0x80); set_control_line_input(Port::A, Line::One, !value); update_data_line(); break; } } -void SerialPortVIA::set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort) +void SerialPortVIA::set_serial_port(const std::shared_ptr<::Commodore::Serial::Port> &serialPort) { - _serialPort = serialPort; + serial_port_ = serialPort; } void SerialPortVIA::update_data_line() { - std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); + std::shared_ptr<::Commodore::Serial::Port> serialPort = serial_port_.lock(); if(serialPort) { // "ATN (Attention) is an input on pin 3 of P2 and P3 that is sensed at PB7 and CA1 of UC3 after being inverted by UA1" serialPort->set_output(::Commodore::Serial::Line::Data, - (::Commodore::Serial::LineLevel)(!_data_level_output - && (_attention_level_input != _attention_acknowledge_level))); + (::Commodore::Serial::LineLevel)(!data_level_output_ && (attention_level_input_ != attention_acknowledge_level_))); } } @@ -232,35 +213,35 @@ void SerialPortVIA::update_data_line() void DriveVIA::set_delegate(Delegate *delegate) { - _delegate = delegate; + delegate_ = delegate; } // write protect tab uncovered -DriveVIA::DriveVIA() : _port_b(0xff), _port_a(0xff), _delegate(nullptr) {} +DriveVIA::DriveVIA() : port_b_(0xff), port_a_(0xff), delegate_(nullptr) {} uint8_t DriveVIA::get_port_input(Port port) { - return port ? _port_b : _port_a; + return port ? port_b_ : port_a_; } void DriveVIA::set_sync_detected(bool sync_detected) { - _port_b = (_port_b & 0x7f) | (sync_detected ? 0x00 : 0x80); + port_b_ = (port_b_ & 0x7f) | (sync_detected ? 0x00 : 0x80); } void DriveVIA::set_data_input(uint8_t value) { - _port_a = value; + port_a_ = value; } bool DriveVIA::get_should_set_overflow() { - return _should_set_overflow; + return should_set_overflow_; } bool DriveVIA::get_motor_enabled() { - return _drive_motor; + return drive_motor_; } void DriveVIA::set_control_line_output(Port port, Line line, bool value) { if(port == Port::A && line == Line::Two) { - _should_set_overflow = value; + should_set_overflow_ = value; } } @@ -268,36 +249,36 @@ void DriveVIA::set_port_output(Port port, uint8_t value, uint8_t direction_mask) if(port) { // record drive motor state - _drive_motor = !!(value&4); + drive_motor_ = !!(value&4); // check for a head step - int step_difference = ((value&3) - (_previous_port_b_output&3))&3; + int step_difference = ((value&3) - (previous_port_b_output_&3))&3; if(step_difference) { - if(_delegate) _delegate->drive_via_did_step_head(this, (step_difference == 1) ? 1 : -1); + if(delegate_) delegate_->drive_via_did_step_head(this, (step_difference == 1) ? 1 : -1); } // check for a change in density - int density_difference = (_previous_port_b_output^value) & (3 << 5); - if(density_difference && _delegate) + int density_difference = (previous_port_b_output_^value) & (3 << 5); + if(density_difference && delegate_) { - _delegate->drive_via_did_set_data_density(this, (value >> 5)&3); + delegate_->drive_via_did_set_data_density(this, (value >> 5)&3); } // TODO: something with the drive LED // printf("LED: %s\n", value&8 ? "On" : "Off"); - _previous_port_b_output = value; + previous_port_b_output_ = value; } } #pragma mark - SerialPort void SerialPort::set_input(::Commodore::Serial::Line line, ::Commodore::Serial::LineLevel level) { - std::shared_ptr serialPortVIA = _serialPortVIA.lock(); + std::shared_ptr serialPortVIA = serial_port_VIA_.lock(); if(serialPortVIA) serialPortVIA->set_serial_line_state(line, (bool)level); } -void SerialPort::set_serial_port_via(std::shared_ptr serialPortVIA) { - _serialPortVIA = serialPortVIA; +void SerialPort::set_serial_port_via(const std::shared_ptr &serialPortVIA) { + serial_port_VIA_ = serialPortVIA; } diff --git a/Machines/Commodore/1540/C1540.hpp b/Machines/Commodore/1540/C1540.hpp index 752684071..04c87281f 100644 --- a/Machines/Commodore/1540/C1540.hpp +++ b/Machines/Commodore/1540/C1540.hpp @@ -41,17 +41,17 @@ class SerialPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQD SerialPortVIA(); - uint8_t get_port_input(Port port); + uint8_t get_port_input(Port); - void set_port_output(Port port, uint8_t value, uint8_t mask); - void set_serial_line_state(::Commodore::Serial::Line line, bool value); + void set_port_output(Port, uint8_t value, uint8_t mask); + void set_serial_line_state(::Commodore::Serial::Line, bool); - void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort); + void set_serial_port(const std::shared_ptr<::Commodore::Serial::Port> &); private: - uint8_t _portB; - std::weak_ptr<::Commodore::Serial::Port> _serialPort; - bool _attention_acknowledge_level, _attention_level_input, _data_level_output; + uint8_t port_b_; + std::weak_ptr<::Commodore::Serial::Port> serial_port_; + bool attention_acknowledge_level_, attention_level_input_, data_level_output_; void update_data_line(); }; @@ -79,7 +79,7 @@ class DriveVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { virtual void drive_via_did_step_head(void *driveVIA, int direction) = 0; virtual void drive_via_did_set_data_density(void *driveVIA, int density) = 0; }; - void set_delegate(Delegate *delegate); + void set_delegate(Delegate *); using MOS6522IRQDelegate::set_interrupt_status; @@ -87,21 +87,21 @@ class DriveVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { uint8_t get_port_input(Port port); - void set_sync_detected(bool sync_detected); - void set_data_input(uint8_t value); + void set_sync_detected(bool); + void set_data_input(uint8_t); bool get_should_set_overflow(); bool get_motor_enabled(); - void set_control_line_output(Port port, Line line, bool value); + void set_control_line_output(Port, Line, bool value); - void set_port_output(Port port, uint8_t value, uint8_t direction_mask); + void set_port_output(Port, uint8_t value, uint8_t direction_mask); private: - uint8_t _port_b, _port_a; - bool _should_set_overflow; - bool _drive_motor; - uint8_t _previous_port_b_output; - Delegate *_delegate; + uint8_t port_b_, port_a_; + bool should_set_overflow_; + bool drive_motor_; + uint8_t previous_port_b_output_; + Delegate *delegate_; }; /*! @@ -109,11 +109,11 @@ class DriveVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { */ class SerialPort : public ::Commodore::Serial::Port { public: - void set_input(::Commodore::Serial::Line line, ::Commodore::Serial::LineLevel level); - void set_serial_port_via(std::shared_ptr serialPortVIA); + void set_input(::Commodore::Serial::Line, ::Commodore::Serial::LineLevel); + void set_serial_port_via(const std::shared_ptr &); private: - std::weak_ptr _serialPortVIA; + std::weak_ptr serial_port_VIA_; }; /*! @@ -152,16 +152,14 @@ class Machine: void drive_via_did_set_data_density(void *driveVIA, int density); private: - uint8_t _ram[0x800]; - uint8_t _rom[0x4000]; + uint8_t ram_[0x800]; + uint8_t rom_[0x4000]; - std::shared_ptr _serialPortVIA; - std::shared_ptr _serialPort; - DriveVIA _driveVIA; + std::shared_ptr serial_port_VIA_; + std::shared_ptr serial_port_; + DriveVIA drive_VIA_; - std::shared_ptr _disk; - - int _shift_register, _bit_window_offset; + int shift_register_, bit_window_offset_; virtual void process_input_bit(int value, unsigned int cycles_since_index_hole); virtual void process_index_hole(); }; diff --git a/Machines/Commodore/SerialBus.cpp b/Machines/Commodore/SerialBus.cpp index 69b187472..ec3757496 100644 --- a/Machines/Commodore/SerialBus.cpp +++ b/Machines/Commodore/SerialBus.cpp @@ -30,14 +30,14 @@ void ::Commodore::Serial::AttachPortAndBus(std::shared_ptr port, std::shar void Bus::add_port(std::shared_ptr port) { - _ports.push_back(port); + ports_.push_back(port); for(int line = (int)ServiceRequest; line <= (int)Reset; line++) { // the addition of a new device may change the line output... set_line_output_did_change((Line)line); // ... but the new device will need to be told the current state regardless - port->set_input((Line)line, _line_levels[line]); + port->set_input((Line)line, line_levels_[line]); } } @@ -45,7 +45,7 @@ void Bus::set_line_output_did_change(Line line) { // i.e. I believe these lines to be open collector LineLevel new_line_level = High; - for(std::weak_ptr port : _ports) + for(std::weak_ptr port : ports_) { std::shared_ptr locked_port = port.lock(); if(locked_port) @@ -55,11 +55,11 @@ void Bus::set_line_output_did_change(Line line) } // post an update only if one occurred - if(new_line_level != _line_levels[line]) + if(new_line_level != line_levels_[line]) { - _line_levels[line] = new_line_level; + line_levels_[line] = new_line_level; - for(std::weak_ptr port : _ports) + for(std::weak_ptr port : ports_) { std::shared_ptr locked_port = port.lock(); if(locked_port) @@ -74,20 +74,20 @@ void Bus::set_line_output_did_change(Line line) void DebugPort::set_input(Line line, LineLevel value) { - _input_levels[line] = value; + input_levels_[line] = value; printf("[Bus] %s is %s\n", StringForLine(line), value ? "high" : "low"); - if(!_incoming_count) + if(!incoming_count_) { - _incoming_count = (!_input_levels[Line::Clock] && !_input_levels[Line::Data]) ? 8 : 0; + 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_byte_ = (incoming_byte_ >> 1) | (input_levels_[Line::Data] ? 0x80 : 0x00); } - _incoming_count--; - if(_incoming_count == 0) printf("[Bus] Observed %02x\n", _incoming_byte); + 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 381e441fd..77642dc06 100644 --- a/Machines/Commodore/SerialBus.hpp +++ b/Machines/Commodore/SerialBus.hpp @@ -48,7 +48,7 @@ namespace Serial { */ class Bus { public: - Bus() : _line_levels{High, High, High, High, High} {} + Bus() : line_levels_{High, High, High, High, High} {} /*! Adds the supplied port to the bus. @@ -62,8 +62,8 @@ namespace Serial { void set_line_output_did_change(Line line); private: - LineLevel _line_levels[5]; - std::vector> _ports; + LineLevel line_levels_[5]; + std::vector> ports_; }; /*! @@ -72,16 +72,16 @@ namespace Serial { */ class Port { public: - Port() : _line_levels{High, High, High, High, High} {} + Port() : line_levels_{High, High, High, High, High} {} /*! Sets the current level of an output line on this serial port. */ void set_output(Line line, LineLevel level) { - if(_line_levels[line] != level) + if(line_levels_[line] != level) { - _line_levels[line] = level; - std::shared_ptr bus = _serial_bus.lock(); + line_levels_[line] = level; + std::shared_ptr bus = serial_bus_.lock(); if(bus) bus->set_line_output_did_change(line); } } @@ -90,7 +90,7 @@ namespace Serial { Gets the previously set level of an output line. */ LineLevel get_output(Line line) { - return _line_levels[line]; + return line_levels_[line]; } /*! @@ -102,12 +102,12 @@ namespace Serial { Sets the supplied serial bus as that to which line levels will be communicated. */ inline void set_serial_bus(std::shared_ptr serial_bus) { - _serial_bus = serial_bus; + serial_bus_ = serial_bus; } private: - std::weak_ptr _serial_bus; - LineLevel _line_levels[5]; + std::weak_ptr serial_bus_; + LineLevel line_levels_[5]; }; /*! @@ -117,12 +117,12 @@ namespace Serial { public: void set_input(Line line, LineLevel value); - DebugPort() : _incoming_count(0) {} + DebugPort() : incoming_count_(0) {} private: - uint8_t _incoming_byte; - int _incoming_count; - LineLevel _input_levels[5]; + uint8_t incoming_byte_; + int incoming_count_; + LineLevel input_levels_[5]; }; }