1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-02-20 14:29:11 +00:00

Adjust ownership to avoid passing reference to uninitialised object.

This commit is contained in:
Thomas Harte 2025-01-09 16:27:19 -05:00
parent c679e2c067
commit 56f10a9a52
2 changed files with 16 additions and 16 deletions

View File

@ -33,11 +33,10 @@ ROM::Request Machine::rom_request(Personality personality) {
MachineBase::MachineBase(Personality personality, const ROM::Map &roms) :
Storage::Disk::Controller(1000000),
m6502_(*this),
serial_port_VIA_port_handler_(serial_port_VIA_),
drive_VIA_(drive_VIA_port_handler_),
serial_port_VIA_(serial_port_VIA_port_handler_) {
// Attach the serial port to its VIA and vice versa.
serial_port_.set_serial_port_via(serial_port_VIA_port_handler_);
serial_port_.connect(serial_port_VIA_port_handler_, serial_port_VIA_);
serial_port_VIA_port_handler_.set_serial_port(serial_port_);
// Set this instance as the delegate to receive interrupt requests from both VIAs.
@ -163,8 +162,6 @@ void MachineBase::drive_via_did_set_data_density(void *, const int density) {
// MARK: - SerialPortVIA
SerialPortVIA::SerialPortVIA(MOS::MOS6522::MOS6522<SerialPortVIA> &via) : via_(via) {}
uint8_t SerialPortVIA::get_port_input(MOS::MOS6522::Port port) {
if(port) return port_b_;
return 0xff;
@ -180,7 +177,11 @@ void SerialPortVIA::set_port_output(MOS::MOS6522::Port port, uint8_t value, uint
}
}
void SerialPortVIA::set_serial_line_state(::Commodore::Serial::Line line, bool value) {
void SerialPortVIA::set_serial_line_state(
::Commodore::Serial::Line line,
bool value,
MOS::MOS6522::MOS6522<SerialPortVIA> &via
) {
switch(line) {
default: break;
case ::Commodore::Serial::Line::Data: port_b_ = (port_b_ & ~0x01) | (value ? 0x00 : 0x01); break;
@ -188,7 +189,7 @@ void SerialPortVIA::set_serial_line_state(::Commodore::Serial::Line line, bool v
case ::Commodore::Serial::Line::Attention:
attention_level_input_ = !value;
port_b_ = (port_b_ & ~0x80) | (value ? 0x00 : 0x80);
via_.set_control_line_input(MOS::MOS6522::Port::A, MOS::MOS6522::Line::One, !value);
via.set_control_line_input(MOS::MOS6522::Port::A, MOS::MOS6522::Line::One, !value);
update_data_line();
break;
}
@ -274,9 +275,10 @@ void DriveVIA::set_activity_observer(Activity::Observer *observer) {
// MARK: - SerialPort
void SerialPort::set_input(Serial::Line line, Serial::LineLevel level) {
serial_port_VIA_->set_serial_line_state(line, bool(level));
serial_port_via_->set_serial_line_state(line, bool(level), *via_);
}
void SerialPort::set_serial_port_via(SerialPortVIA &serialPortVIA) {
serial_port_VIA_ = &serialPortVIA;
void SerialPort::connect(SerialPortVIA &serial_port_via, MOS::MOS6522::MOS6522<SerialPortVIA> &via) {
serial_port_via_ = &serial_port_via;
via_ = &via;
}

View File

@ -39,17 +39,14 @@ namespace Commodore::C1540 {
*/
class SerialPortVIA: public MOS::MOS6522::IRQDelegatePortHandler {
public:
SerialPortVIA(MOS::MOS6522::MOS6522<SerialPortVIA> &via);
uint8_t get_port_input(MOS::MOS6522::Port);
void set_port_output(MOS::MOS6522::Port, uint8_t value, uint8_t mask);
void set_serial_line_state(::Commodore::Serial::Line, bool);
void set_serial_line_state(::Commodore::Serial::Line, bool, MOS::MOS6522::MOS6522<SerialPortVIA> &);
void set_serial_port(Commodore::Serial::Port &);
private:
MOS::MOS6522::MOS6522<SerialPortVIA> &via_;
uint8_t port_b_ = 0x0;
Commodore::Serial::Port *serial_port_ = nullptr;
bool attention_acknowledge_level_ = false;
@ -111,11 +108,12 @@ private:
*/
class SerialPort : public ::Commodore::Serial::Port {
public:
void set_input(Commodore::Serial::Line, Commodore::Serial::LineLevel);
void set_serial_port_via(SerialPortVIA &);
void set_input(Commodore::Serial::Line, Commodore::Serial::LineLevel) override;
void connect(SerialPortVIA &, MOS::MOS6522::MOS6522<SerialPortVIA>&);
private:
SerialPortVIA *serial_port_VIA_ = nullptr;
SerialPortVIA *serial_port_via_ = nullptr;
MOS::MOS6522::MOS6522<SerialPortVIA> *via_ = nullptr;
};
class MachineBase: