1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-21 17:16:44 +00:00

Adjust for style.

This commit is contained in:
Thomas Harte
2025-11-17 17:15:26 -05:00
parent b3a9e39be3
commit 332b37063f
2 changed files with 50 additions and 36 deletions
@@ -17,7 +17,10 @@
using namespace Commodore::C1540;
namespace {
ROM::Name rom_name(Personality personality) {
// MARK: - Construction, including ROM requests.
ROM::Name rom_name(const Personality personality) {
switch(personality) {
default:
case Personality::C1540: return ROM::Name::Commodore1540;
@@ -26,11 +29,11 @@ ROM::Name rom_name(Personality personality) {
}
}
ROM::Request Machine::rom_request(Personality personality) {
ROM::Request Machine::rom_request(const Personality personality) {
return ROM::Request(rom_name(personality));
}
MachineBase::MachineBase(Personality personality, const ROM::Map &roms) :
MachineBase::MachineBase(const Personality personality, const ROM::Map &roms) :
Storage::Disk::Controller(1000000),
m6502_(*this),
drive_VIA_(drive_VIA_port_handler_),
@@ -58,12 +61,10 @@ MachineBase::MachineBase(Personality personality, const ROM::Map &roms) :
std::memcpy(rom_, rom->second.data(), std::min(sizeof(rom_), rom->second.size()));
}
Machine::Machine(Personality personality, const ROM::Map &roms) :
Machine::Machine(const Personality personality, const ROM::Map &roms) :
MachineBase(personality, roms) {}
void Machine::set_serial_bus(Commodore::Serial::Bus &serial_bus) {
Commodore::Serial::attach(serial_port_, serial_bus);
}
// MARK: - 6502 bus.
template <CPU::MOS6502Mk2::BusOperation operation, typename AddressT>
Cycles MachineBase::perform(const AddressT address, CPU::MOS6502Mk2::data_t<operation> value) {
@@ -106,34 +107,41 @@ Cycles MachineBase::perform(const AddressT address, CPU::MOS6502Mk2::data_t<oper
return Cycles(1);
}
void Machine::run_for(const Cycles cycles) {
m6502_.run_for(cycles);
const bool drive_motor = drive_VIA_port_handler_.motor_enabled();
get_drive().set_motor_on(drive_motor);
if(drive_motor) {
Storage::Disk::Controller::run_for(cycles);
}
}
// MARK: - External attachments.
void Machine::set_serial_bus(Commodore::Serial::Bus &serial_bus) {
Commodore::Serial::attach(serial_port_, serial_bus);
}
void Machine::set_disk(std::shared_ptr<Storage::Disk::Disk> disk) {
get_drive().set_disk(disk);
}
void Machine::run_for(const Cycles cycles) {
m6502_.run_for(cycles);
const bool drive_motor = drive_VIA_port_handler_.get_motor_enabled();
get_drive().set_motor_on(drive_motor);
if(drive_motor)
Storage::Disk::Controller::run_for(cycles);
}
void MachineBase::set_activity_observer(Activity::Observer *observer) {
void MachineBase::set_activity_observer(Activity::Observer *const observer) {
drive_VIA_.bus_handler().set_activity_observer(observer);
get_drive().set_activity_observer(observer, "Drive", false);
}
// MARK: - 6522 delegate
// MARK: - 6522 delegate.
void MachineBase::mos6522_did_change_interrupt_status(void *) {
// both VIAs are connected to the IRQ line
m6502_.set<CPU::MOS6502Mk2::Line::IRQ>(serial_port_VIA_.get_interrupt_line() || drive_VIA_.get_interrupt_line());
}
// MARK: - Disk drive
// MARK: - Disk drive.
void MachineBase::process_input_bit(int value) {
void MachineBase::process_input_bit(const int value) {
shift_register_ = (shift_register_ << 1) | value;
if((shift_register_ & 0x3ff) == 0x3ff) {
drive_VIA_port_handler_.set_sync_detected(true);
@@ -145,7 +153,7 @@ void MachineBase::process_input_bit(int value) {
if(bit_window_offset_ == 8) {
drive_VIA_port_handler_.set_data_input(uint8_t(shift_register_));
bit_window_offset_ = 0;
if(drive_VIA_port_handler_.get_should_set_overflow()) {
if(drive_VIA_port_handler_.should_set_overflow()) {
m6502_.set<CPU::MOS6502Mk2::Line::Overflow>(true);
}
}
@@ -169,7 +177,9 @@ void MachineBase::drive_via_did_set_data_density(DriveVIA &, const int density)
template <MOS::MOS6522::Port port>
uint8_t SerialPortVIA::get_port_input() const {
if(port) return port_b_;
if(port) {
return port_b_;
}
return 0xff;
}
@@ -208,13 +218,15 @@ void SerialPortVIA::set_serial_port(Commodore::Serial::Port &port) {
void SerialPortVIA::update_data_line() {
// "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"
serial_port_->set_output(::Commodore::Serial::Line::Data,
Serial::LineLevel(!data_level_output_ && (attention_level_input_ != attention_acknowledge_level_)));
serial_port_->set_output(
::Commodore::Serial::Line::Data,
Serial::LineLevel(!data_level_output_ && (attention_level_input_ != attention_acknowledge_level_))
);
}
// MARK: - DriveVIA
void DriveVIA::set_delegate(Delegate *delegate) {
void DriveVIA::set_delegate(Delegate *const delegate) {
delegate_ = delegate;
}
@@ -228,15 +240,15 @@ void DriveVIA::set_sync_detected(const bool sync_detected) {
port_b_ = (port_b_ & 0x7f) | (sync_detected ? 0x00 : 0x80);
}
void DriveVIA::set_data_input(uint8_t value) {
void DriveVIA::set_data_input(const uint8_t value) {
port_a_ = value;
}
bool DriveVIA::get_should_set_overflow() {
bool DriveVIA::should_set_overflow() {
return should_set_overflow_;
}
bool DriveVIA::get_motor_enabled() {
bool DriveVIA::motor_enabled() {
return drive_motor_;
}
@@ -256,8 +268,8 @@ void DriveVIA::set_port_output(const uint8_t value, uint8_t) {
// Check for a head step.
const 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(step_difference && delegate_) {
delegate_->drive_via_did_step_head(*this, (step_difference == 1) ? 1 : -1);
}
// Check for a change in density.
@@ -267,14 +279,16 @@ void DriveVIA::set_port_output(const uint8_t value, uint8_t) {
}
// Post the LED status.
if(observer_) observer_->set_led_status("Drive", value&8);
if(observer_) {
observer_->set_led_status("Drive", value&8);
}
previous_port_b_output_ = value;
}
}
}
void DriveVIA::set_activity_observer(Activity::Observer *observer) {
void DriveVIA::set_activity_observer(Activity::Observer *const observer) {
observer_ = observer;
if(observer) {
observer->register_led("Drive");
@@ -282,9 +296,9 @@ void DriveVIA::set_activity_observer(Activity::Observer *observer) {
}
}
// MARK: - SerialPort
// MARK: - SerialPort.
void SerialPort::set_input(Serial::Line line, Serial::LineLevel level) {
void SerialPort::set_input(const Serial::Line line, const Serial::LineLevel level) {
serial_port_via_->set_serial_line_state(line, bool(level), *via_);
}
@@ -88,8 +88,8 @@ public:
void set_sync_detected(bool);
void set_data_input(uint8_t);
bool get_should_set_overflow();
bool get_motor_enabled();
bool should_set_overflow();
bool motor_enabled();
template <MOS::MOS6522::Port, MOS::MOS6522::Line>
void set_control_line_output(bool value);