diff --git a/Components/6522/6522.hpp b/Components/6522/6522.hpp index 4660d75f7..d3885cfbd 100644 --- a/Components/6522/6522.hpp +++ b/Components/6522/6522.hpp @@ -57,64 +57,64 @@ template class MOS6522 { switch(address) { case 0x0: - _registers.output[1] = value; - static_cast(this)->set_port_output(Port::B, value, _registers.data_direction[1]); // TODO: handshake + registers_.output[1] = value; + static_cast(this)->set_port_output(Port::B, value, registers_.data_direction[1]); // TODO: handshake - _registers.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | ((_registers.peripheral_control&0x20) ? 0 : InterruptFlag::CB2ActiveEdge)); + registers_.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | ((registers_.peripheral_control&0x20) ? 0 : InterruptFlag::CB2ActiveEdge)); reevaluate_interrupts(); break; case 0xf: case 0x1: - _registers.output[0] = value; - static_cast(this)->set_port_output(Port::A, value, _registers.data_direction[0]); // TODO: handshake + registers_.output[0] = value; + static_cast(this)->set_port_output(Port::A, value, registers_.data_direction[0]); // TODO: handshake - _registers.interrupt_flags &= ~(InterruptFlag::CA1ActiveEdge | ((_registers.peripheral_control&0x02) ? 0 : InterruptFlag::CB2ActiveEdge)); + registers_.interrupt_flags &= ~(InterruptFlag::CA1ActiveEdge | ((registers_.peripheral_control&0x02) ? 0 : InterruptFlag::CB2ActiveEdge)); reevaluate_interrupts(); break; // // No handshake, so write directly -// _registers.output[0] = value; +// registers_.output[0] = value; // static_cast(this)->set_port_output(0, value); // break; case 0x2: - _registers.data_direction[1] = value; + registers_.data_direction[1] = value; break; case 0x3: - _registers.data_direction[0] = value; + registers_.data_direction[0] = value; break; // Timer 1 - case 0x6: case 0x4: _registers.timer_latch[0] = (_registers.timer_latch[0]&0xff00) | value; break; + case 0x6: case 0x4: registers_.timer_latch[0] = (registers_.timer_latch[0]&0xff00) | value; break; case 0x5: case 0x7: - _registers.timer_latch[0] = (_registers.timer_latch[0]&0x00ff) | (uint16_t)(value << 8); - _registers.interrupt_flags &= ~InterruptFlag::Timer1; + registers_.timer_latch[0] = (registers_.timer_latch[0]&0x00ff) | (uint16_t)(value << 8); + registers_.interrupt_flags &= ~InterruptFlag::Timer1; if(address == 0x05) { - _registers.next_timer[0] = _registers.timer_latch[0]; - _timer_is_running[0] = true; + registers_.next_timer[0] = registers_.timer_latch[0]; + timer_is_running_[0] = true; } reevaluate_interrupts(); break; // Timer 2 - case 0x8: _registers.timer_latch[1] = value; break; + case 0x8: registers_.timer_latch[1] = value; break; case 0x9: - _registers.interrupt_flags &= ~InterruptFlag::Timer2; - _registers.next_timer[1] = _registers.timer_latch[1] | (uint16_t)(value << 8); - _timer_is_running[1] = true; + registers_.interrupt_flags &= ~InterruptFlag::Timer2; + registers_.next_timer[1] = registers_.timer_latch[1] | (uint16_t)(value << 8); + timer_is_running_[1] = true; reevaluate_interrupts(); break; // Shift - case 0xa: _registers.shift = value; break; + case 0xa: registers_.shift = value; break; // Control case 0xb: - _registers.auxiliary_control = value; + registers_.auxiliary_control = value; break; case 0xc: // printf("Peripheral control %02x\n", value); - _registers.peripheral_control = value; + registers_.peripheral_control = value; // TODO: simplify below; trying to avoid improper logging of unimplemented warnings in input mode if(value & 0x08) @@ -139,14 +139,14 @@ template class MOS6522 { // Interrupt control case 0xd: - _registers.interrupt_flags &= ~value; + registers_.interrupt_flags &= ~value; reevaluate_interrupts(); break; case 0xe: if(value&0x80) - _registers.interrupt_enable |= value; + registers_.interrupt_enable |= value; else - _registers.interrupt_enable &= ~value; + registers_.interrupt_enable &= ~value; reevaluate_interrupts(); break; } @@ -160,41 +160,41 @@ template class MOS6522 { switch(address) { case 0x0: - _registers.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | InterruptFlag::CB2ActiveEdge); + registers_.interrupt_flags &= ~(InterruptFlag::CB1ActiveEdge | InterruptFlag::CB2ActiveEdge); reevaluate_interrupts(); - return get_port_input(Port::B, _registers.data_direction[1], _registers.output[1]); + return get_port_input(Port::B, registers_.data_direction[1], registers_.output[1]); case 0xf: // TODO: handshake, latching case 0x1: - _registers.interrupt_flags &= ~(InterruptFlag::CA1ActiveEdge | InterruptFlag::CA2ActiveEdge); + registers_.interrupt_flags &= ~(InterruptFlag::CA1ActiveEdge | InterruptFlag::CA2ActiveEdge); reevaluate_interrupts(); - return get_port_input(Port::A, _registers.data_direction[0], _registers.output[0]); + return get_port_input(Port::A, registers_.data_direction[0], registers_.output[0]); - case 0x2: return _registers.data_direction[1]; - case 0x3: return _registers.data_direction[0]; + case 0x2: return registers_.data_direction[1]; + case 0x3: return registers_.data_direction[0]; // Timer 1 case 0x4: - _registers.interrupt_flags &= ~InterruptFlag::Timer1; + registers_.interrupt_flags &= ~InterruptFlag::Timer1; reevaluate_interrupts(); - return _registers.timer[0] & 0x00ff; - case 0x5: return _registers.timer[0] >> 8; - case 0x6: return _registers.timer_latch[0] & 0x00ff; - case 0x7: return _registers.timer_latch[0] >> 8; + return registers_.timer[0] & 0x00ff; + case 0x5: return registers_.timer[0] >> 8; + case 0x6: return registers_.timer_latch[0] & 0x00ff; + case 0x7: return registers_.timer_latch[0] >> 8; // Timer 2 case 0x8: - _registers.interrupt_flags &= ~InterruptFlag::Timer2; + registers_.interrupt_flags &= ~InterruptFlag::Timer2; reevaluate_interrupts(); - return _registers.timer[1] & 0x00ff; - case 0x9: return _registers.timer[1] >> 8; + return registers_.timer[1] & 0x00ff; + case 0x9: return registers_.timer[1] >> 8; - case 0xa: return _registers.shift; + case 0xa: return registers_.shift; - case 0xb: return _registers.auxiliary_control; - case 0xc: return _registers.peripheral_control; + case 0xb: return registers_.auxiliary_control; + case 0xc: return registers_.peripheral_control; - case 0xd: return _registers.interrupt_flags | (get_interrupt_line() ? 0x80 : 0x00); - case 0xe: return _registers.interrupt_enable | 0x80; + case 0xd: return registers_.interrupt_flags | (get_interrupt_line() ? 0x80 : 0x00); + case 0xe: return registers_.interrupt_enable | 0x80; } return 0xff; @@ -205,65 +205,65 @@ template class MOS6522 { switch(line) { case Line::One: - if( value != _control_inputs[port].line_one && - value == !!(_registers.peripheral_control & (port ? 0x10 : 0x01)) + if( value != control_inputs_[port].line_one && + value == !!(registers_.peripheral_control & (port ? 0x10 : 0x01)) ) { - _registers.interrupt_flags |= port ? InterruptFlag::CB1ActiveEdge : InterruptFlag::CA1ActiveEdge; + registers_.interrupt_flags |= port ? InterruptFlag::CB1ActiveEdge : InterruptFlag::CA1ActiveEdge; reevaluate_interrupts(); } - _control_inputs[port].line_one = value; + control_inputs_[port].line_one = value; break; case Line::Two: // TODO: output modes, but probably elsewhere? - if( value != _control_inputs[port].line_two && // i.e. value has changed ... - !(_registers.peripheral_control & (port ? 0x80 : 0x08)) && // ... and line is input ... - value == !!(_registers.peripheral_control & (port ? 0x40 : 0x04)) // ... and it's either high or low, as required + if( value != control_inputs_[port].line_two && // i.e. value has changed ... + !(registers_.peripheral_control & (port ? 0x80 : 0x08)) && // ... and line is input ... + value == !!(registers_.peripheral_control & (port ? 0x40 : 0x04)) // ... and it's either high or low, as required ) { - _registers.interrupt_flags |= port ? InterruptFlag::CB2ActiveEdge : InterruptFlag::CA2ActiveEdge; + registers_.interrupt_flags |= port ? InterruptFlag::CB2ActiveEdge : InterruptFlag::CA2ActiveEdge; reevaluate_interrupts(); } - _control_inputs[port].line_two = value; + control_inputs_[port].line_two = value; break; } } #define phase2() \ - _registers.last_timer[0] = _registers.timer[0];\ - _registers.last_timer[1] = _registers.timer[1];\ + registers_.last_timer[0] = registers_.timer[0];\ + registers_.last_timer[1] = registers_.timer[1];\ \ - if(_registers.timer_needs_reload)\ + if(registers_.timer_needs_reload)\ {\ - _registers.timer_needs_reload = false;\ - _registers.timer[0] = _registers.timer_latch[0];\ + registers_.timer_needs_reload = false;\ + registers_.timer[0] = registers_.timer_latch[0];\ }\ else\ - _registers.timer[0] --;\ + registers_.timer[0] --;\ \ - _registers.timer[1] --; \ - if(_registers.next_timer[0] >= 0) { _registers.timer[0] = (uint16_t)_registers.next_timer[0]; _registers.next_timer[0] = -1; }\ - if(_registers.next_timer[1] >= 0) { _registers.timer[1] = (uint16_t)_registers.next_timer[1]; _registers.next_timer[1] = -1; }\ + registers_.timer[1] --; \ + if(registers_.next_timer[0] >= 0) { registers_.timer[0] = (uint16_t)registers_.next_timer[0]; registers_.next_timer[0] = -1; }\ + if(registers_.next_timer[1] >= 0) { registers_.timer[1] = (uint16_t)registers_.next_timer[1]; registers_.next_timer[1] = -1; }\ // IRQ is raised on the half cycle after overflow #define phase1() \ - if((_registers.timer[1] == 0xffff) && !_registers.last_timer[1] && _timer_is_running[1])\ + if((registers_.timer[1] == 0xffff) && !registers_.last_timer[1] && timer_is_running_[1])\ {\ - _timer_is_running[1] = false;\ - _registers.interrupt_flags |= InterruptFlag::Timer2;\ + timer_is_running_[1] = false;\ + registers_.interrupt_flags |= InterruptFlag::Timer2;\ reevaluate_interrupts();\ }\ \ - if((_registers.timer[0] == 0xffff) && !_registers.last_timer[0] && _timer_is_running[0])\ + if((registers_.timer[0] == 0xffff) && !registers_.last_timer[0] && timer_is_running_[0])\ {\ - _registers.interrupt_flags |= InterruptFlag::Timer1;\ + registers_.interrupt_flags |= InterruptFlag::Timer1;\ reevaluate_interrupts();\ \ - if(_registers.auxiliary_control&0x40)\ - _registers.timer_needs_reload = true;\ + if(registers_.auxiliary_control&0x40)\ + registers_.timer_needs_reload = true;\ else\ - _timer_is_running[0] = false;\ + timer_is_running_[0] = false;\ } /*! @@ -281,7 +281,7 @@ template class MOS6522 { */ inline void run_for_half_cycles(unsigned int number_of_cycles) { - if(_is_phase2) + if(is_phase2_) { phase2(); number_of_cycles--; @@ -297,11 +297,11 @@ template class MOS6522 { if(number_of_cycles) { phase1(); - _is_phase2 = true; + is_phase2_ = true; } else { - _is_phase2 = false; + is_phase2_ = false; } } @@ -326,14 +326,14 @@ template class MOS6522 { /*! @returns @c true if the IRQ line is currently active; @c false otherwise. */ inline bool get_interrupt_line() { - uint8_t interrupt_status = _registers.interrupt_flags & _registers.interrupt_enable & 0x7f; + uint8_t interrupt_status = registers_.interrupt_flags & registers_.interrupt_enable & 0x7f; return !!interrupt_status; } MOS6522() : - _timer_is_running{false, false}, - _last_posted_interrupt_status(false), - _is_phase2(false) + timer_is_running_{false, false}, + last_posted_interrupt_status_(false), + is_phase2_(false) {} private: @@ -351,16 +351,16 @@ template class MOS6522 { } // Phase toggle - bool _is_phase2; + bool is_phase2_; // Delegate and communications - bool _last_posted_interrupt_status; + bool last_posted_interrupt_status_; inline void reevaluate_interrupts() { bool new_interrupt_status = get_interrupt_line(); - if(new_interrupt_status != _last_posted_interrupt_status) + if(new_interrupt_status != last_posted_interrupt_status_) { - _last_posted_interrupt_status = new_interrupt_status; + last_posted_interrupt_status_ = new_interrupt_status; static_cast(this)->set_interrupt_status(new_interrupt_status); } } @@ -382,15 +382,15 @@ template class MOS6522 { interrupt_flags(0), interrupt_enable(0), last_timer{0, 0}, timer_needs_reload(false), next_timer{-1, -1} {} - } _registers; + } registers_; // control state struct { bool line_one, line_two; - } _control_inputs[2]; + } control_inputs_[2]; // Internal state other than the registers - bool _timer_is_running[2]; + bool timer_is_running_[2]; }; /*! @@ -404,18 +404,18 @@ class MOS6522IRQDelegate { virtual void mos6522_did_change_interrupt_status(void *mos6522) = 0; }; - void set_interrupt_delegate(Delegate *delegate) + inline void set_interrupt_delegate(Delegate *delegate) { - _delegate = delegate; + delegate_ = delegate; } - void set_interrupt_status(bool new_status) + inline void set_interrupt_status(bool new_status) { - if(_delegate) _delegate->mos6522_did_change_interrupt_status(this); + if(delegate_) delegate_->mos6522_did_change_interrupt_status(this); } private: - Delegate *_delegate; + Delegate *delegate_; }; } diff --git a/Components/6532/6532.hpp b/Components/6532/6532.hpp index 0b42515bf..acf57f66d 100644 --- a/Components/6532/6532.hpp +++ b/Components/6532/6532.hpp @@ -27,8 +27,8 @@ namespace MOS { */ template class MOS6532 { public: - inline void set_ram(uint16_t address, uint8_t value) { _ram[address&0x7f] = value; } - inline uint8_t get_ram(uint16_t address) { return _ram[address & 0x7f]; } + inline void set_ram(uint16_t address, uint8_t value) { ram_[address&0x7f] = value; } + inline uint8_t get_ram(uint16_t address) { return ram_[address & 0x7f]; } inline void set_register(int address, uint8_t value) { @@ -36,13 +36,13 @@ template class MOS6532 { switch(decodedAddress) { // Port output case 0x00: case 0x02: - _port[decodedAddress / 2].output = value; - static_cast(this)->set_port_output(decodedAddress / 2, _port[decodedAddress/2].output, _port[decodedAddress / 2].output_mask); + port_[decodedAddress / 2].output = value; + static_cast(this)->set_port_output(decodedAddress / 2, port_[decodedAddress/2].output, port_[decodedAddress / 2].output_mask); set_port_did_change(decodedAddress / 2); break; case 0x01: case 0x03: - _port[decodedAddress / 2].output_mask = value; - static_cast(this)->set_port_output(decodedAddress / 2, _port[decodedAddress/2].output, _port[decodedAddress / 2].output_mask); + port_[decodedAddress / 2].output_mask = value; + static_cast(this)->set_port_output(decodedAddress / 2, port_[decodedAddress/2].output, port_[decodedAddress / 2].output_mask); set_port_did_change(decodedAddress / 2); break; @@ -50,16 +50,16 @@ template class MOS6532 { case 0x04: case 0x05: case 0x06: case 0x07: if(address & 0x10) { - _timer.writtenShift = _timer.activeShift = (decodedAddress - 0x04) * 3 + (decodedAddress / 0x07); // i.e. 0, 3, 6, 10 - _timer.value = ((unsigned int)(value) << _timer.activeShift) | ((1 << _timer.activeShift)-1); - _timer.interrupt_enabled = !!(address&0x08); - _interrupt_status &= ~InterruptFlag::Timer; + timer_.writtenShift = timer_.activeShift = (decodedAddress - 0x04) * 3 + (decodedAddress / 0x07); // i.e. 0, 3, 6, 10 + timer_.value = ((unsigned int)(value) << timer_.activeShift) | ((1 << timer_.activeShift)-1); + timer_.interrupt_enabled = !!(address&0x08); + interrupt_status_ &= ~InterruptFlag::Timer; evaluate_interrupts(); } else { - _a7_interrupt.enabled = !!(address&0x2); - _a7_interrupt.active_on_positive = !!(address & 0x01); + a7_interrupt_.enabled = !!(address&0x2); + a7_interrupt_.active_on_positive = !!(address & 0x01); } break; } @@ -74,25 +74,25 @@ template class MOS6532 { { const int port = decodedAddress / 2; uint8_t input = static_cast(this)->get_port_input(port); - return (input & ~_port[port].output_mask) | (_port[port].output & _port[port].output_mask); + return (input & ~port_[port].output_mask) | (port_[port].output & port_[port].output_mask); } break; case 0x01: case 0x03: - return _port[decodedAddress / 2].output_mask; + return port_[decodedAddress / 2].output_mask; break; // Timer and interrupt control case 0x04: case 0x06: { - uint8_t value = (uint8_t)(_timer.value >> _timer.activeShift); - _timer.interrupt_enabled = !!(address&0x08); - _interrupt_status &= ~InterruptFlag::Timer; + uint8_t value = (uint8_t)(timer_.value >> timer_.activeShift); + timer_.interrupt_enabled = !!(address&0x08); + interrupt_status_ &= ~InterruptFlag::Timer; evaluate_interrupts(); - if(_timer.activeShift != _timer.writtenShift) { - unsigned int shift = _timer.writtenShift - _timer.activeShift; - _timer.value = (_timer.value << shift) | ((1 << shift) - 1); - _timer.activeShift = _timer.writtenShift; + if(timer_.activeShift != timer_.writtenShift) { + unsigned int shift = timer_.writtenShift - timer_.activeShift; + timer_.value = (timer_.value << shift) | ((1 << shift) - 1); + timer_.activeShift = timer_.writtenShift; } return value; @@ -101,8 +101,8 @@ template class MOS6532 { case 0x05: case 0x07: { - uint8_t value = _interrupt_status; - _interrupt_status &= ~InterruptFlag::PA7; + uint8_t value = interrupt_status_; + interrupt_status_ &= ~InterruptFlag::PA7; evaluate_interrupts(); return value; } @@ -115,39 +115,39 @@ template class MOS6532 { inline void run_for_cycles(unsigned int number_of_cycles) { // permit counting _to_ zero; counting _through_ zero initiates the other behaviour - if(_timer.value >= number_of_cycles) { - _timer.value -= number_of_cycles; + if(timer_.value >= number_of_cycles) { + timer_.value -= number_of_cycles; } else { - number_of_cycles -= _timer.value; - _timer.value = 0x100 - number_of_cycles; - _timer.activeShift = 0; - _interrupt_status |= InterruptFlag::Timer; + number_of_cycles -= timer_.value; + timer_.value = 0x100 - number_of_cycles; + timer_.activeShift = 0; + interrupt_status_ |= InterruptFlag::Timer; evaluate_interrupts(); } } MOS6532() : - _interrupt_status(0), - _port{{.output_mask = 0, .output = 0}, {.output_mask = 0, .output = 0}}, - _a7_interrupt({.last_port_value = 0, .enabled = false}), - _interrupt_line(false) + interrupt_status_(0), + port_{{.output_mask = 0, .output = 0}, {.output_mask = 0, .output = 0}}, + a7_interrupt_({.last_port_value = 0, .enabled = false}), + interrupt_line_(false) {} inline void set_port_did_change(int port) { if(!port) { - uint8_t new_port_a_value = (get_port_input(0) & ~_port[0].output_mask) | (_port[0].output & _port[0].output_mask); - uint8_t difference = new_port_a_value ^ _a7_interrupt.last_port_value; - _a7_interrupt.last_port_value = new_port_a_value; + uint8_t new_port_a_value = (get_port_input(0) & ~port_[0].output_mask) | (port_[0].output & port_[0].output_mask); + uint8_t difference = new_port_a_value ^ a7_interrupt_.last_port_value; + a7_interrupt_.last_port_value = new_port_a_value; if(difference&0x80) { if( - ((new_port_a_value&0x80) && _a7_interrupt.active_on_positive) || - (!(new_port_a_value&0x80) && !_a7_interrupt.active_on_positive) + ((new_port_a_value&0x80) && a7_interrupt_.active_on_positive) || + (!(new_port_a_value&0x80) && !a7_interrupt_.active_on_positive) ) { - _interrupt_status |= InterruptFlag::PA7; + interrupt_status_ |= InterruptFlag::PA7; evaluate_interrupts(); } } @@ -156,34 +156,34 @@ template class MOS6532 { inline bool get_inerrupt_line() { - return _interrupt_line; + return interrupt_line_; } private: - uint8_t _ram[128]; + uint8_t ram_[128]; struct { unsigned int value; unsigned int activeShift, writtenShift; bool interrupt_enabled; - } _timer; + } timer_; struct { bool enabled; bool active_on_positive; uint8_t last_port_value; - } _a7_interrupt; + } a7_interrupt_; struct { uint8_t output_mask, output; - } _port[2]; + } port_[2]; - uint8_t _interrupt_status; + uint8_t interrupt_status_; enum InterruptFlag: uint8_t { Timer = 0x80, PA7 = 0x40 }; - bool _interrupt_line; + bool interrupt_line_; // expected to be overridden uint8_t get_port_input(int port) { return 0xff; } @@ -192,10 +192,10 @@ template class MOS6532 { inline void evaluate_interrupts() { - _interrupt_line = - ((_interrupt_status&InterruptFlag::Timer) && _timer.interrupt_enabled) || - ((_interrupt_status&InterruptFlag::PA7) && _a7_interrupt.enabled); - set_irq_line(_interrupt_line); + interrupt_line_ = + ((interrupt_status_&InterruptFlag::Timer) && timer_.interrupt_enabled) || + ((interrupt_status_&InterruptFlag::PA7) && a7_interrupt_.enabled); + set_irq_line(interrupt_line_); } }; diff --git a/Components/6560/6560.cpp b/Components/6560/6560.cpp index 8882decd3..a11a3825f 100644 --- a/Components/6560/6560.cpp +++ b/Components/6560/6560.cpp @@ -11,23 +11,23 @@ using namespace MOS; Speaker::Speaker() : - _volume(0), - _control_registers{0, 0, 0, 0}, - _shift_registers{0, 0, 0, 0}, - _counters{2, 1, 0, 0} // create a slight phase offset for the three channels + volume_(0), + control_registers_{0, 0, 0, 0}, + shift_registers_{0, 0, 0, 0}, + counters_{2, 1, 0, 0} // create a slight phase offset for the three channels {} void Speaker::set_volume(uint8_t volume) { enqueue([=]() { - _volume = volume; + volume_ = volume; }); } void Speaker::set_control(int channel, uint8_t value) { enqueue([=]() { - _control_registers[channel] = value; + control_registers_[channel] = value; }); } @@ -99,9 +99,9 @@ static uint8_t noise_pattern[] = { 0xf0, 0xe1, 0xe0, 0x78, 0x70, 0x38, 0x3c, 0x3e, 0x1e, 0x3c, 0x1e, 0x1c, 0x70, 0x3c, 0x38, 0x3f, }; -#define shift(r) _shift_registers[r] = (_shift_registers[r] << 1) | (((_shift_registers[r]^0x80)&_control_registers[r]) >> 7) -#define increment(r) _shift_registers[r] = (_shift_registers[r]+1)%8191 -#define update(r, m, up) _counters[r]++; if((_counters[r] >> m) == 0x80) { up(r); _counters[r] = (unsigned int)(_control_registers[r]&0x7f) << m; } +#define shift(r) shift_registers_[r] = (shift_registers_[r] << 1) | (((shift_registers_[r]^0x80)&control_registers_[r]) >> 7) +#define increment(r) shift_registers_[r] = (shift_registers_[r]+1)%8191 +#define update(r, m, up) counters_[r]++; if((counters_[r] >> m) == 0x80) { up(r); counters_[r] = (unsigned int)(control_registers_[r]&0x7f) << m; } // Note on slightly askew test: as far as I can make out, if the value in the register is 0x7f then what's supposed to happen // is that the 0x7f is loaded, on the next clocked cycle the Vic spots a 0x7f, pumps the output, reloads, etc. No increment // ever occurs. It's conditional. I don't really want two conditionals if I can avoid it so I'm incrementing regardless and @@ -120,11 +120,11 @@ void Speaker::get_samples(unsigned int number_of_samples, int16_t *target) // this sums the output of all three sounds channels plus a DC offset for volume; // TODO: what's the real ratio of this stuff? target[c] = ( - (_shift_registers[0]&1) + - (_shift_registers[1]&1) + - (_shift_registers[2]&1) + - ((noise_pattern[_shift_registers[3] >> 3] >> (_shift_registers[3]&7))&(_control_registers[3] >> 7)&1) - ) * _volume * 700 + _volume * 44; + (shift_registers_[0]&1) + + (shift_registers_[1]&1) + + (shift_registers_[2]&1) + + ((noise_pattern[shift_registers_[3] >> 3] >> (shift_registers_[3]&7))&(control_registers_[3] >> 7)&1) + ) * volume_ * 700 + volume_ * 44; } } diff --git a/Components/6560/6560.hpp b/Components/6560/6560.hpp index 1211f66ff..62d9bc050 100644 --- a/Components/6560/6560.hpp +++ b/Components/6560/6560.hpp @@ -26,10 +26,10 @@ class Speaker: public ::Outputs::Filter { void skip_samples(unsigned int number_of_samples); private: - unsigned int _counters[4]; - unsigned int _shift_registers[4]; - uint8_t _control_registers[4]; - uint8_t _volume; + unsigned int counters_[4]; + unsigned int shift_registers_[4]; + uint8_t control_registers_[4]; + uint8_t volume_; }; /*! @@ -43,15 +43,15 @@ class Speaker: public ::Outputs::Filter { template class MOS6560 { public: MOS6560() : - _crt(new Outputs::CRT::CRT(65*4, 4, Outputs::CRT::NTSC60, 1)), - _speaker(new Speaker), - _horizontal_counter(0), - _vertical_counter(0), - _cycles_since_speaker_update(0), - _is_odd_frame(false), - _is_odd_line(false) + crt_(new Outputs::CRT::CRT(65*4, 4, Outputs::CRT::NTSC60, 1)), + speaker_(new Speaker), + horizontal_counter_(0), + vertical_counter_(0), + cycles_since_speaker_update_(0), + is_odd_frame_(false), + is_odd_line_(false) { - _crt->set_composite_sampling_function( + crt_->set_composite_sampling_function( "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)" "{" "uint c = texture(texID, coordinate).r;" @@ -69,11 +69,11 @@ template class MOS6560 { void set_clock_rate(double clock_rate) { - _speaker->set_input_rate((float)(clock_rate / 4.0)); + speaker_->set_input_rate((float)(clock_rate / 4.0)); } - std::shared_ptr get_crt() { return _crt; } - std::shared_ptr get_speaker() { return _speaker; } + std::shared_ptr get_crt() { return crt_; } + std::shared_ptr get_speaker() { return speaker_; } enum OutputMode { PAL, NTSC @@ -84,7 +84,7 @@ template class MOS6560 { */ void set_output_mode(OutputMode output_mode) { - _output_mode = output_mode; + output_mode_ = output_mode; uint8_t luminances[16] = { // range is 0–4 0, 4, 1, 3, 2, 2, 1, 3, 2, 1, 2, 1, 2, 3, 2, 3 @@ -105,38 +105,38 @@ template class MOS6560 { case OutputMode::PAL: chrominances = pal_chrominances; display_type = Outputs::CRT::PAL50; - _timing.cycles_per_line = 71; - _timing.line_counter_increment_offset = 0; - _timing.lines_per_progressive_field = 312; - _timing.supports_interlacing = false; + timing_.cycles_per_line = 71; + timing_.line_counter_increment_offset = 0; + timing_.lines_per_progressive_field = 312; + timing_.supports_interlacing = false; break; case OutputMode::NTSC: chrominances = ntsc_chrominances; display_type = Outputs::CRT::NTSC60; - _timing.cycles_per_line = 65; - _timing.line_counter_increment_offset = 65 - 33; // TODO: this is a bit of a hack; separate vertical and horizontal counting - _timing.lines_per_progressive_field = 261; - _timing.supports_interlacing = true; + timing_.cycles_per_line = 65; + timing_.line_counter_increment_offset = 65 - 33; // TODO: this is a bit of a hack; separate vertical and horizontal counting + timing_.lines_per_progressive_field = 261; + timing_.supports_interlacing = true; break; } - _crt->set_new_display_type((unsigned int)(_timing.cycles_per_line*4), display_type); -// _crt->set_visible_area(Outputs::CRT::Rect(0.1f, 0.1f, 0.8f, 0.8f)); + crt_->set_new_display_type((unsigned int)(timing_.cycles_per_line*4), display_type); +// crt_->set_visible_area(Outputs::CRT::Rect(0.1f, 0.1f, 0.8f, 0.8f)); // switch(output_mode) // { // case OutputMode::PAL: -// _crt->set_visible_area(_crt->get_rect_for_area(16, 237, 15*4, 55*4, 4.0f / 3.0f)); +// crt_->set_visible_area(crt_->get_rect_for_area(16, 237, 15*4, 55*4, 4.0f / 3.0f)); // break; // case OutputMode::NTSC: -// _crt->set_visible_area(_crt->get_rect_for_area(16, 237, 11*4, 55*4, 4.0f / 3.0f)); +// crt_->set_visible_area(crt_->get_rect_for_area(16, 237, 11*4, 55*4, 4.0f / 3.0f)); // break; // } for(int c = 0; c < 16; c++) { - _colours[c] = (uint8_t)((luminances[c] << 4) | chrominances[c]); + colours_[c] = (uint8_t)((luminances[c] << 4) | chrominances[c]); } } @@ -146,88 +146,88 @@ template class MOS6560 { inline void run_for_cycles(unsigned int number_of_cycles) { // keep track of the amount of time since the speaker was updated; lazy updates are applied - _cycles_since_speaker_update += number_of_cycles; + cycles_since_speaker_update_ += number_of_cycles; while(number_of_cycles--) { // keep an old copy of the vertical count because that test is a cycle later than the actual changes - int previous_vertical_counter = _vertical_counter; + int previous_vertical_counter = vertical_counter_; // keep track of internal time relative to this scanline - _horizontal_counter++; - _full_frame_counter++; - if(_horizontal_counter == _timing.cycles_per_line) + horizontal_counter_++; + full_frame_counter_++; + if(horizontal_counter_ == timing_.cycles_per_line) { - if(_horizontal_drawing_latch) + if(horizontal_drawing_latch_) { - _current_character_row++; + current_character_row_++; if( - (_current_character_row == 16) || - (_current_character_row == 8 && !_registers.tall_characters) + (current_character_row_ == 16) || + (current_character_row_ == 8 && !registers_.tall_characters) ) { - _current_character_row = 0; - _current_row++; + current_character_row_ = 0; + current_row_++; } - _pixel_line_cycle = -1; - _columns_this_line = -1; - _column_counter = -1; + pixel_line_cycle_ = -1; + columns_this_line_ = -1; + column_counter_ = -1; } - _horizontal_counter = 0; - if(_output_mode == OutputMode::PAL) _is_odd_line ^= true; - _horizontal_drawing_latch = false; + horizontal_counter_ = 0; + if(output_mode_ == OutputMode::PAL) is_odd_line_ ^= true; + horizontal_drawing_latch_ = false; - _vertical_counter ++; - if(_vertical_counter == (_registers.interlaced ? (_is_odd_frame ? 262 : 263) : _timing.lines_per_progressive_field)) + vertical_counter_ ++; + if(vertical_counter_ == (registers_.interlaced ? (is_odd_frame_ ? 262 : 263) : timing_.lines_per_progressive_field)) { - _vertical_counter = 0; - _full_frame_counter = 0; + vertical_counter_ = 0; + full_frame_counter_ = 0; - if(_output_mode == OutputMode::NTSC) _is_odd_frame ^= true; - _current_row = 0; - _rows_this_field = -1; - _vertical_drawing_latch = false; - _base_video_matrix_address_counter = 0; - _current_character_row = 0; + if(output_mode_ == OutputMode::NTSC) is_odd_frame_ ^= true; + current_row_ = 0; + rows_this_field_ = -1; + vertical_drawing_latch_ = false; + base_video_matrix_address_counter_ = 0; + current_character_row_ = 0; } } // check for vertical starting events - _vertical_drawing_latch |= _registers.first_row_location == (previous_vertical_counter >> 1); - _horizontal_drawing_latch |= _vertical_drawing_latch && (_horizontal_counter == _registers.first_column_location); + vertical_drawing_latch_ |= registers_.first_row_location == (previous_vertical_counter >> 1); + horizontal_drawing_latch_ |= vertical_drawing_latch_ && (horizontal_counter_ == registers_.first_column_location); - if(_pixel_line_cycle >= 0) _pixel_line_cycle++; - switch(_pixel_line_cycle) + if(pixel_line_cycle_ >= 0) pixel_line_cycle_++; + switch(pixel_line_cycle_) { case -1: - if(_horizontal_drawing_latch) + if(horizontal_drawing_latch_) { - _pixel_line_cycle = 0; - _video_matrix_address_counter = _base_video_matrix_address_counter; + pixel_line_cycle_ = 0; + video_matrix_address_counter_ = base_video_matrix_address_counter_; } break; - case 1: _columns_this_line = _registers.number_of_columns; break; - case 2: if(_rows_this_field < 0) _rows_this_field = _registers.number_of_rows; break; - case 3: if(_current_row < _rows_this_field) _column_counter = 0; break; + case 1: columns_this_line_ = registers_.number_of_columns; break; + case 2: if(rows_this_field_ < 0) rows_this_field_ = registers_.number_of_rows; break; + case 3: if(current_row_ < rows_this_field_) column_counter_ = 0; break; } uint16_t fetch_address = 0x1c; - if(_column_counter >= 0 && _column_counter < _columns_this_line*2) + if(column_counter_ >= 0 && column_counter_ < columns_this_line_*2) { - if(_column_counter&1) + if(column_counter_&1) { - fetch_address = _registers.character_cell_start_address + (_character_code*(_registers.tall_characters ? 16 : 8)) + _current_character_row; + fetch_address = registers_.character_cell_start_address + (character_code_*(registers_.tall_characters ? 16 : 8)) + current_character_row_; } else { - fetch_address = (uint16_t)(_registers.video_matrix_start_address + _video_matrix_address_counter); - _video_matrix_address_counter++; + fetch_address = (uint16_t)(registers_.video_matrix_start_address + video_matrix_address_counter_); + video_matrix_address_counter_++; if( - (_current_character_row == 15) || - (_current_character_row == 7 && !_registers.tall_characters) + (current_character_row_ == 15) || + (current_character_row_ == 7 && !registers_.tall_characters) ) { - _base_video_matrix_address_counter = _video_matrix_address_counter; + base_video_matrix_address_counter_ = video_matrix_address_counter_; } } } @@ -242,99 +242,99 @@ template class MOS6560 { // divide the byte it is set for 3:1 and then continue as usual. // determine output state; colour burst and sync timing are currently a guess - if(_horizontal_counter > _timing.cycles_per_line-4) _this_state = State::ColourBurst; - else if(_horizontal_counter > _timing.cycles_per_line-7) _this_state = State::Sync; + if(horizontal_counter_ > timing_.cycles_per_line-4) this_state_ = State::ColourBurst; + else if(horizontal_counter_ > timing_.cycles_per_line-7) this_state_ = State::Sync; else { - _this_state = (_column_counter >= 0 && _column_counter < _columns_this_line*2) ? State::Pixels : State::Border; + this_state_ = (column_counter_ >= 0 && column_counter_ < columns_this_line_*2) ? State::Pixels : State::Border; } // apply vertical sync if( - (_vertical_counter < 3 && (_is_odd_frame || !_registers.interlaced)) || - (_registers.interlaced && + (vertical_counter_ < 3 && (is_odd_frame_ || !registers_.interlaced)) || + (registers_.interlaced && ( - (_vertical_counter == 0 && _horizontal_counter > 32) || - (_vertical_counter == 1) || (_vertical_counter == 2) || - (_vertical_counter == 3 && _horizontal_counter <= 32) + (vertical_counter_ == 0 && horizontal_counter_ > 32) || + (vertical_counter_ == 1) || (vertical_counter_ == 2) || + (vertical_counter_ == 3 && horizontal_counter_ <= 32) ) )) - _this_state = State::Sync; + this_state_ = State::Sync; // update the CRT - if(_this_state != _output_state) + if(this_state_ != output_state_) { - switch(_output_state) + switch(output_state_) { - case State::Sync: _crt->output_sync(_cycles_in_state * 4); break; - case State::ColourBurst: _crt->output_colour_burst(_cycles_in_state * 4, (_is_odd_frame || _is_odd_line) ? 128 : 0, 0); break; - case State::Border: output_border(_cycles_in_state * 4); break; - case State::Pixels: _crt->output_data(_cycles_in_state * 4, 1); break; + case State::Sync: crt_->output_sync(cycles_in_state_ * 4); break; + case State::ColourBurst: crt_->output_colour_burst(cycles_in_state_ * 4, (is_odd_frame_ || is_odd_line_) ? 128 : 0, 0); break; + case State::Border: output_border(cycles_in_state_ * 4); break; + case State::Pixels: crt_->output_data(cycles_in_state_ * 4, 1); break; } - _output_state = _this_state; - _cycles_in_state = 0; + output_state_ = this_state_; + cycles_in_state_ = 0; pixel_pointer = nullptr; - if(_output_state == State::Pixels) + if(output_state_ == State::Pixels) { - pixel_pointer = _crt->allocate_write_area(260); + pixel_pointer = crt_->allocate_write_area(260); } } - _cycles_in_state++; + cycles_in_state_++; - if(_this_state == State::Pixels) + if(this_state_ == State::Pixels) { - if(_column_counter&1) + if(column_counter_&1) { - _character_value = pixel_data; + character_value_ = pixel_data; if(pixel_pointer) { - uint8_t cell_colour = _colours[_character_colour & 0x7]; - if(!(_character_colour&0x8)) + uint8_t cell_colour = colours_[character_colour_ & 0x7]; + if(!(character_colour_&0x8)) { uint8_t colours[2]; - if(_registers.invertedCells) + if(registers_.invertedCells) { colours[0] = cell_colour; - colours[1] = _registers.backgroundColour; + colours[1] = registers_.backgroundColour; } else { - colours[0] = _registers.backgroundColour; + colours[0] = registers_.backgroundColour; colours[1] = cell_colour; } - pixel_pointer[0] = colours[(_character_value >> 7)&1]; - pixel_pointer[1] = colours[(_character_value >> 6)&1]; - pixel_pointer[2] = colours[(_character_value >> 5)&1]; - pixel_pointer[3] = colours[(_character_value >> 4)&1]; - pixel_pointer[4] = colours[(_character_value >> 3)&1]; - pixel_pointer[5] = colours[(_character_value >> 2)&1]; - pixel_pointer[6] = colours[(_character_value >> 1)&1]; - pixel_pointer[7] = colours[(_character_value >> 0)&1]; + pixel_pointer[0] = colours[(character_value_ >> 7)&1]; + pixel_pointer[1] = colours[(character_value_ >> 6)&1]; + pixel_pointer[2] = colours[(character_value_ >> 5)&1]; + pixel_pointer[3] = colours[(character_value_ >> 4)&1]; + pixel_pointer[4] = colours[(character_value_ >> 3)&1]; + pixel_pointer[5] = colours[(character_value_ >> 2)&1]; + pixel_pointer[6] = colours[(character_value_ >> 1)&1]; + pixel_pointer[7] = colours[(character_value_ >> 0)&1]; } else { - uint8_t colours[4] = {_registers.backgroundColour, _registers.borderColour, cell_colour, _registers.auxiliary_colour}; + uint8_t colours[4] = {registers_.backgroundColour, registers_.borderColour, cell_colour, registers_.auxiliary_colour}; pixel_pointer[0] = - pixel_pointer[1] = colours[(_character_value >> 6)&3]; + pixel_pointer[1] = colours[(character_value_ >> 6)&3]; pixel_pointer[2] = - pixel_pointer[3] = colours[(_character_value >> 4)&3]; + pixel_pointer[3] = colours[(character_value_ >> 4)&3]; pixel_pointer[4] = - pixel_pointer[5] = colours[(_character_value >> 2)&3]; + pixel_pointer[5] = colours[(character_value_ >> 2)&3]; pixel_pointer[6] = - pixel_pointer[7] = colours[(_character_value >> 0)&3]; + pixel_pointer[7] = colours[(character_value_ >> 0)&3]; } pixel_pointer += 8; } } else { - _character_code = pixel_data; - _character_colour = colour_data; + character_code_ = pixel_data; + character_colour_ = colour_data; } - _column_counter++; + column_counter_++; } } } @@ -350,31 +350,31 @@ template class MOS6560 { void set_register(int address, uint8_t value) { address &= 0xf; - _registers.direct_values[address] = value; + registers_.direct_values[address] = value; switch(address) { case 0x0: - _registers.interlaced = !!(value&0x80) && _timing.supports_interlacing; - _registers.first_column_location = value & 0x7f; + registers_.interlaced = !!(value&0x80) && timing_.supports_interlacing; + registers_.first_column_location = value & 0x7f; break; case 0x1: - _registers.first_row_location = value; + registers_.first_row_location = value; break; case 0x2: - _registers.number_of_columns = value & 0x7f; - _registers.video_matrix_start_address = (uint16_t)((_registers.video_matrix_start_address & 0x3c00) | ((value & 0x80) << 2)); + registers_.number_of_columns = value & 0x7f; + registers_.video_matrix_start_address = (uint16_t)((registers_.video_matrix_start_address & 0x3c00) | ((value & 0x80) << 2)); break; case 0x3: - _registers.number_of_rows = (value >> 1)&0x3f; - _registers.tall_characters = !!(value&0x01); + registers_.number_of_rows = (value >> 1)&0x3f; + registers_.tall_characters = !!(value&0x01); break; case 0x5: - _registers.character_cell_start_address = (uint16_t)((value & 0x0f) << 10); - _registers.video_matrix_start_address = (uint16_t)((_registers.video_matrix_start_address & 0x0200) | ((value & 0xf0) << 6)); + registers_.character_cell_start_address = (uint16_t)((value & 0x0f) << 10); + registers_.video_matrix_start_address = (uint16_t)((registers_.video_matrix_start_address & 0x0200) | ((value & 0xf0) << 6)); break; case 0xa: @@ -382,26 +382,26 @@ template class MOS6560 { case 0xc: case 0xd: update_audio(); - _speaker->set_control(address - 0xa, value); + speaker_->set_control(address - 0xa, value); break; case 0xe: update_audio(); - _registers.auxiliary_colour = _colours[value >> 4]; - _speaker->set_volume(value & 0xf); + registers_.auxiliary_colour = colours_[value >> 4]; + speaker_->set_volume(value & 0xf); break; case 0xf: { - uint8_t new_border_colour = _colours[value & 0x07]; - if(_this_state == State::Border && new_border_colour != _registers.borderColour) + uint8_t new_border_colour = colours_[value & 0x07]; + if(this_state_ == State::Border && new_border_colour != registers_.borderColour) { - output_border(_cycles_in_state * 4); - _cycles_in_state = 0; + output_border(cycles_in_state_ * 4); + cycles_in_state_ = 0; } - _registers.invertedCells = !((value >> 3)&1); - _registers.borderColour = new_border_colour; - _registers.backgroundColour = _colours[value >> 4]; + registers_.invertedCells = !((value >> 3)&1); + registers_.borderColour = new_border_colour; + registers_.backgroundColour = colours_[value >> 4]; } break; @@ -418,24 +418,24 @@ template class MOS6560 { uint8_t get_register(int address) { address &= 0xf; - int current_line = (_full_frame_counter + _timing.line_counter_increment_offset) / _timing.cycles_per_line; + int current_line = (full_frame_counter_ + timing_.line_counter_increment_offset) / timing_.cycles_per_line; switch(address) { - default: return _registers.direct_values[address]; - case 0x03: return (uint8_t)(current_line << 7) | (_registers.direct_values[3] & 0x7f); + default: return registers_.direct_values[address]; + case 0x03: return (uint8_t)(current_line << 7) | (registers_.direct_values[3] & 0x7f); case 0x04: return (current_line >> 1) & 0xff; } } private: - std::shared_ptr _crt; + std::shared_ptr crt_; - std::shared_ptr _speaker; - unsigned int _cycles_since_speaker_update; + std::shared_ptr speaker_; + unsigned int cycles_since_speaker_update_; void update_audio() { - _speaker->run_for_cycles(_cycles_since_speaker_update >> 2); - _cycles_since_speaker_update &= 3; + speaker_->run_for_cycles(cycles_since_speaker_update_ >> 2); + cycles_since_speaker_update_ &= 3; } // register state @@ -448,41 +448,41 @@ template class MOS6560 { bool invertedCells; uint8_t direct_values[16]; - } _registers; + } registers_; // output state enum State { Sync, ColourBurst, Border, Pixels - } _this_state, _output_state; - unsigned int _cycles_in_state; + } this_state_, output_state_; + unsigned int cycles_in_state_; // counters that cover an entire field - int _horizontal_counter, _vertical_counter, _full_frame_counter; + int horizontal_counter_, vertical_counter_, full_frame_counter_; // latches dictating start and length of drawing - bool _vertical_drawing_latch, _horizontal_drawing_latch; - int _rows_this_field, _columns_this_line; + bool vertical_drawing_latch_, horizontal_drawing_latch_; + int rows_this_field_, columns_this_line_; // current drawing position counter - int _pixel_line_cycle, _column_counter; - int _current_row; - uint16_t _current_character_row; - uint16_t _video_matrix_address_counter, _base_video_matrix_address_counter; + int pixel_line_cycle_, column_counter_; + int current_row_; + uint16_t current_character_row_; + uint16_t video_matrix_address_counter_, base_video_matrix_address_counter_; // data latched from the bus - uint8_t _character_code, _character_colour, _character_value; + uint8_t character_code_, character_colour_, character_value_; - bool _is_odd_frame, _is_odd_line; + bool is_odd_frame_, is_odd_line_; // lookup table from 6560 colour index to appropriate PAL/NTSC value - uint8_t _colours[16]; + uint8_t colours_[16]; uint8_t *pixel_pointer; void output_border(unsigned int number_of_cycles) { - uint8_t *colour_pointer = _crt->allocate_write_area(1); - if(colour_pointer) *colour_pointer = _registers.borderColour; - _crt->output_level(number_of_cycles); + uint8_t *colour_pointer = crt_->allocate_write_area(1); + if(colour_pointer) *colour_pointer = registers_.borderColour; + crt_->output_level(number_of_cycles); } struct { @@ -490,8 +490,8 @@ template class MOS6560 { int line_counter_increment_offset; int lines_per_progressive_field; bool supports_interlacing; - } _timing; - OutputMode _output_mode; + } timing_; + OutputMode output_mode_; }; } diff --git a/Components/AY38910/AY38910.cpp b/Components/AY38910/AY38910.cpp index b5a0641b4..93534d872 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -11,14 +11,14 @@ using namespace GI; AY38910::AY38910() : - _selected_register(0), - _tone_counters{0, 0, 0}, _tone_periods{0, 0, 0}, _tone_outputs{0, 0, 0}, - _noise_shift_register(0xffff), _noise_period(0), _noise_counter(0), _noise_output(0), - _envelope_divider(0), _envelope_period(0), _envelope_position(0), - _master_divider(0), - _output_registers{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + selected_register_(0), + tone_counters_{0, 0, 0}, tone_periods_{0, 0, 0}, tone_outputs_{0, 0, 0}, + noise_shift_register_(0xffff), noise_period_(0), noise_counter_(0), noise_output_(0), + envelope_divider_(0), envelope_period_(0), envelope_position_(0), + master_divider_(0), + output_registers_{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} { - _output_registers[8] = _output_registers[9] = _output_registers[10] = 0; + output_registers_[8] = output_registers_[9] = output_registers_[10] = 0; // set up envelope lookup tables for(int c = 0; c < 16; c++) @@ -28,39 +28,39 @@ AY38910::AY38910() : switch(c) { case 0: case 1: case 2: case 3: case 9: - _envelope_shapes[c][p] = (p < 16) ? (p^0xf) : 0; - _envelope_overflow_masks[c] = 0x1f; + envelope_shapes_[c][p] = (p < 16) ? (p^0xf) : 0; + envelope_overflow_masks_[c] = 0x1f; break; case 4: case 5: case 6: case 7: case 15: - _envelope_shapes[c][p] = (p < 16) ? p : 0; - _envelope_overflow_masks[c] = 0x1f; + envelope_shapes_[c][p] = (p < 16) ? p : 0; + envelope_overflow_masks_[c] = 0x1f; break; case 8: - _envelope_shapes[c][p] = (p & 0xf) ^ 0xf; - _envelope_overflow_masks[c] = 0x00; + envelope_shapes_[c][p] = (p & 0xf) ^ 0xf; + envelope_overflow_masks_[c] = 0x00; break; case 12: - _envelope_shapes[c][p] = (p & 0xf); - _envelope_overflow_masks[c] = 0x00; + envelope_shapes_[c][p] = (p & 0xf); + envelope_overflow_masks_[c] = 0x00; break; case 10: - _envelope_shapes[c][p] = (p & 0xf) ^ ((p < 16) ? 0xf : 0x0); - _envelope_overflow_masks[c] = 0x00; + envelope_shapes_[c][p] = (p & 0xf) ^ ((p < 16) ? 0xf : 0x0); + envelope_overflow_masks_[c] = 0x00; break; case 14: - _envelope_shapes[c][p] = (p & 0xf) ^ ((p < 16) ? 0x0 : 0xf); - _envelope_overflow_masks[c] = 0x00; + envelope_shapes_[c][p] = (p & 0xf) ^ ((p < 16) ? 0x0 : 0xf); + envelope_overflow_masks_[c] = 0x00; break; case 11: - _envelope_shapes[c][p] = (p < 16) ? (p^0xf) : 0xf; - _envelope_overflow_masks[c] = 0x1f; + envelope_shapes_[c][p] = (p < 16) ? (p^0xf) : 0xf; + envelope_overflow_masks_[c] = 0x1f; break; case 13: - _envelope_shapes[c][p] = (p < 16) ? p : 0xf; - _envelope_overflow_masks[c] = 0x1f; + envelope_shapes_[c][p] = (p < 16) ? p : 0xf; + envelope_overflow_masks_[c] = 0x1f; break; } } @@ -71,9 +71,9 @@ AY38910::AY38910() : float root_two = sqrtf(2.0f); for(int v = 0; v < 16; v++) { - _volumes[v] = (int)(max_volume / powf(root_two, (float)(v ^ 0xf))); + volumes_[v] = (int)(max_volume / powf(root_two, (float)(v ^ 0xf))); } - _volumes[0] = 0; + volumes_[0] = 0; } void AY38910::set_clock_rate(double clock_rate) @@ -84,21 +84,21 @@ void AY38910::set_clock_rate(double clock_rate) void AY38910::get_samples(unsigned int number_of_samples, int16_t *target) { int c = 0; - while((_master_divider&15) && c < number_of_samples) + while((master_divider_&15) && c < number_of_samples) { - target[c] = _output_volume; - _master_divider++; + target[c] = output_volume_; + master_divider_++; c++; } while(c < number_of_samples) { #define step_channel(c) \ - if(_tone_counters[c]) _tone_counters[c]--;\ + if(tone_counters_[c]) tone_counters_[c]--;\ else\ {\ - _tone_outputs[c] ^= 1;\ - _tone_counters[c] = _tone_periods[c];\ + tone_outputs_[c] ^= 1;\ + tone_counters_[c] = tone_periods_[c];\ } // update the tone channels @@ -110,48 +110,48 @@ void AY38910::get_samples(unsigned int number_of_samples, int16_t *target) // ... the noise generator. This recomputes the new bit repeatedly but harmlessly, only shifting // it into the official 17 upon divider underflow. - if(_noise_counter) _noise_counter--; + if(noise_counter_) noise_counter_--; else { - _noise_counter = _noise_period; - _noise_output ^= _noise_shift_register&1; - _noise_shift_register |= ((_noise_shift_register ^ (_noise_shift_register >> 3))&1) << 17; - _noise_shift_register >>= 1; + noise_counter_ = noise_period_; + noise_output_ ^= noise_shift_register_&1; + noise_shift_register_ |= ((noise_shift_register_ ^ (noise_shift_register_ >> 3))&1) << 17; + noise_shift_register_ >>= 1; } // ... and the envelope generator. Table based for pattern lookup, with a 'refill' step — a way of // implementing non-repeating patterns by locking them to table position 0x1f. - if(_envelope_divider) _envelope_divider--; + if(envelope_divider_) envelope_divider_--; else { - _envelope_divider = _envelope_period; - _envelope_position ++; - if(_envelope_position == 32) _envelope_position = _envelope_overflow_masks[_output_registers[13]]; + envelope_divider_ = envelope_period_; + envelope_position_ ++; + if(envelope_position_ == 32) envelope_position_ = envelope_overflow_masks_[output_registers_[13]]; } evaluate_output_volume(); for(int ic = 0; ic < 16 && c < number_of_samples; ic++) { - target[c] = _output_volume; + target[c] = output_volume_; c++; - _master_divider++; + master_divider_++; } } - _master_divider &= 15; + master_divider_ &= 15; } void AY38910::evaluate_output_volume() { - int envelope_volume = _envelope_shapes[_output_registers[13]][_envelope_position]; + int envelope_volume = envelope_shapes_[output_registers_[13]][envelope_position_]; // The output level for a channel is: // 1 if neither tone nor noise is enabled; // 0 if either tone or noise is enabled and its value is low. // The tone/noise enable bits use inverse logic — 0 = on, 1 = off — permitting the OR logic below. -#define tone_level(c, tone_bit) (_tone_outputs[c] | (_output_registers[7] >> tone_bit)) -#define noise_level(c, noise_bit) (_noise_output | (_output_registers[7] >> noise_bit)) +#define tone_level(c, tone_bit) (tone_outputs_[c] | (output_registers_[7] >> tone_bit)) +#define noise_level(c, noise_bit) (noise_output_ | (output_registers_[7] >> noise_bit)) #define level(c, tone_bit, noise_bit) tone_level(c, tone_bit) & noise_level(c, noise_bit) & 1 const int channel_levels[3] = { @@ -163,7 +163,7 @@ void AY38910::evaluate_output_volume() // Channel volume is a simple selection: if the bit at 0x10 is set, use the envelope volume; otherwise use the lower four bits #define channel_volume(c) \ - ((_output_registers[c] >> 4)&1) * envelope_volume + (((_output_registers[c] >> 4)&1)^1) * (_output_registers[c]&0xf) + ((output_registers_[c] >> 4)&1) * envelope_volume + (((output_registers_[c] >> 4)&1)^1) * (output_registers_[c]&0xf) const int volumes[3] = { channel_volume(8), @@ -173,24 +173,24 @@ void AY38910::evaluate_output_volume() #undef channel_volume // Mix additively. - _output_volume = (int16_t)( - _volumes[volumes[0]] * channel_levels[0] + - _volumes[volumes[1]] * channel_levels[1] + - _volumes[volumes[2]] * channel_levels[2] + output_volume_ = (int16_t)( + volumes_[volumes[0]] * channel_levels[0] + + volumes_[volumes[1]] * channel_levels[1] + + volumes_[volumes[2]] * channel_levels[2] ); } void AY38910::select_register(uint8_t r) { - _selected_register = r & 0xf; + selected_register_ = r & 0xf; } void AY38910::set_register_value(uint8_t value) { - _registers[_selected_register] = value; - if(_selected_register < 14) + registers_[selected_register_] = value; + if(selected_register_ < 14) { - int selected_register = _selected_register; + int selected_register = selected_register_; enqueue([=] () { uint8_t masked_value = value; switch(selected_register) @@ -201,34 +201,34 @@ void AY38910::set_register_value(uint8_t value) int channel = selected_register >> 1; if(selected_register & 1) - _tone_periods[channel] = (_tone_periods[channel] & 0xff) | (uint16_t)((value&0xf) << 8); + tone_periods_[channel] = (tone_periods_[channel] & 0xff) | (uint16_t)((value&0xf) << 8); else - _tone_periods[channel] = (_tone_periods[channel] & ~0xff) | value; - _tone_counters[channel] = _tone_periods[channel]; + tone_periods_[channel] = (tone_periods_[channel] & ~0xff) | value; + tone_counters_[channel] = tone_periods_[channel]; } break; case 6: - _noise_period = value & 0x1f; - _noise_counter = _noise_period; + noise_period_ = value & 0x1f; + noise_counter_ = noise_period_; break; case 11: - _envelope_period = (_envelope_period & ~0xff) | value; - _envelope_divider = _envelope_period; + envelope_period_ = (envelope_period_ & ~0xff) | value; + envelope_divider_ = envelope_period_; break; case 12: - _envelope_period = (_envelope_period & 0xff) | (int)(value << 8); - _envelope_divider = _envelope_period; + envelope_period_ = (envelope_period_ & 0xff) | (int)(value << 8); + envelope_divider_ = envelope_period_; break; case 13: masked_value &= 0xf; - _envelope_position = 0; + envelope_position_ = 0; break; } - _output_registers[selected_register] = masked_value; + output_registers_[selected_register] = masked_value; evaluate_output_volume(); }); } @@ -244,22 +244,22 @@ uint8_t AY38910::get_register_value() 0xe0, 0xe0, 0xe0, 0x00, 0x00, 0xf0, 0x00, 0x00 }; - return _registers[_selected_register] | register_masks[_selected_register]; + return registers_[selected_register_] | register_masks[selected_register_]; } uint8_t AY38910::get_port_output(bool port_b) { - return _registers[port_b ? 15 : 14]; + return registers_[port_b ? 15 : 14]; } void AY38910::set_data_input(uint8_t r) { - _data_input = r; + data_input_ = r; } uint8_t AY38910::get_data_output() { - return _data_output; + return data_output_; } void AY38910::set_control_lines(ControlLines control_lines) @@ -277,15 +277,15 @@ void AY38910::set_control_lines(ControlLines control_lines) case (int)(BCDIR | BC2): new_state = Write; break; } - if(new_state != _control_state) + if(new_state != control_state_) { - _control_state = new_state; + control_state_ = new_state; switch(new_state) { default: break; - case LatchAddress: select_register(_data_input); break; - case Write: set_register_value(_data_input); break; - case Read: _data_output = get_register_value(); break; + case LatchAddress: select_register(data_input_); break; + case Write: set_register_value(data_input_); break; + case Read: data_output_ = get_register_value(); break; } } } diff --git a/Components/AY38910/AY38910.hpp b/Components/AY38910/AY38910.hpp index 11f0045c6..4b35e395a 100644 --- a/Components/AY38910/AY38910.hpp +++ b/Components/AY38910/AY38910.hpp @@ -51,42 +51,42 @@ class AY38910: public ::Outputs::Filter { void get_samples(unsigned int number_of_samples, int16_t *target); private: - int _selected_register; - uint8_t _registers[16], _output_registers[16]; + int selected_register_; + uint8_t registers_[16], output_registers_[16]; - int _master_divider; + int master_divider_; - int _tone_periods[3]; - int _tone_counters[3]; - int _tone_outputs[3]; + int tone_periods_[3]; + int tone_counters_[3]; + int tone_outputs_[3]; - int _noise_period; - int _noise_counter; - int _noise_shift_register; - int _noise_output; + int noise_period_; + int noise_counter_; + int noise_shift_register_; + int noise_output_; - int _envelope_period; - int _envelope_divider; - int _envelope_position; - int _envelope_shapes[16][32]; - int _envelope_overflow_masks[16]; + int envelope_period_; + int envelope_divider_; + int envelope_position_; + int envelope_shapes_[16][32]; + int envelope_overflow_masks_[16]; - int _volumes[16]; + int volumes_[16]; enum ControlState { Inactive, LatchAddress, Read, Write - } _control_state; + } control_state_; void select_register(uint8_t r); void set_register_value(uint8_t value); uint8_t get_register_value(); - uint8_t _data_input, _data_output; + uint8_t data_input_, data_output_; - int16_t _output_volume; + int16_t output_volume_; inline void evaluate_output_volume(); }; diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 72b4c2bca..d2af0dd6f 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -18,18 +18,18 @@ namespace { } Machine::Machine() : - _horizontalTimer(0), - _lastOutputStateDuration(0), - _lastOutputState(OutputState::Sync), - _rom(nullptr), - _tiaInputValue{0xff, 0xff}, - _upcomingEventsPointer(0), - _objectCounterPointer(0), - _stateByTime(_stateByExtendTime[0]), - _cycles_since_speaker_update(0), - _is_pal_region(false) + horizontal_timer_(0), + last_output_state_duration_(0), + last_output_state_(OutputState::Sync), + rom_(nullptr), + tia_input_value_{0xff, 0xff}, + upcoming_events_pointer_(0), + object_counter_pointer_(0), + state_by_time_(state_by_extend_time_[0]), + cycles_since_speaker_update_(0), + is_pal_region_(false) { - memset(_collisions, 0xff, sizeof(_collisions)); + memset(collisions_, 0xff, sizeof(collisions_)); setup_reported_collisions(); for(int vbextend = 0; vbextend < 2; vbextend++) @@ -51,7 +51,7 @@ Machine::Machine() : default: state = OutputState::Pixel; break; } - _stateByExtendTime[vbextend][c] = state; + state_by_extend_time_[vbextend][c] = state; } } set_clock_rate(NTSC_clock_rate); @@ -59,12 +59,12 @@ Machine::Machine() : void Machine::setup_output(float aspect_ratio) { - _speaker.reset(new Speaker); - _crt.reset(new Outputs::CRT::CRT(228, 1, 263, Outputs::CRT::ColourSpace::YIQ, 228, 1, 1)); - _crt->set_output_device(Outputs::CRT::Television); + speaker_.reset(new Speaker); + crt_.reset(new Outputs::CRT::CRT(228, 1, 263, Outputs::CRT::ColourSpace::YIQ, 228, 1, 1)); + crt_->set_output_device(Outputs::CRT::Television); // this is the NTSC phase offset function; see below for PAL - _crt->set_composite_sampling_function( + crt_->set_composite_sampling_function( "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)" "{" "uint c = texture(texID, coordinate).r;" @@ -74,13 +74,13 @@ void Machine::setup_output(float aspect_ratio) "float phaseOffset = 6.283185308 * float(iPhase - 1u) / 13.0;" "return mix(float(y) / 14.0, step(1, iPhase) * cos(phase + phaseOffset), amplitude);" "}"); - _speaker->set_input_rate((float)(get_clock_rate() / 38.0)); + speaker_->set_input_rate((float)(get_clock_rate() / 38.0)); } void Machine::switch_region() { // the PAL function - _crt->set_composite_sampling_function( + crt_->set_composite_sampling_function( "float composite_sample(usampler2D texID, vec2 coordinate, vec2 iCoordinate, float phase, float amplitude)" "{" "uint c = texture(texID, coordinate).r;" @@ -93,39 +93,39 @@ void Machine::switch_region() "return mix(float(y) / 14.0, step(4, (iPhase + 2u) & 15u) * cos(phase + phaseOffset), amplitude);" "}"); - _crt->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1); + crt_->set_new_timing(228, 312, Outputs::CRT::ColourSpace::YUV, 228, 1); - _is_pal_region = true; - _speaker->set_input_rate((float)(get_clock_rate() / 38.0)); + is_pal_region_ = true; + speaker_->set_input_rate((float)(get_clock_rate() / 38.0)); set_clock_rate(PAL_clock_rate); } void Machine::close_output() { - _crt = nullptr; + crt_ = nullptr; } Machine::~Machine() { - delete[] _rom; + delete[] rom_; close_output(); } void Machine::update_timers(int mask) { - unsigned int upcomingPointerPlus4 = (_upcomingEventsPointer + 4)%number_of_upcoming_events; + unsigned int upcoming_pointer_plus_4 = (upcoming_events_pointer_ + 4)%number_of_upcoming_events; - _objectCounterPointer = (_objectCounterPointer + 1)%number_of_recorded_counters; - ObjectCounter *oneClockAgo = _objectCounter[(_objectCounterPointer - 1 + number_of_recorded_counters)%number_of_recorded_counters]; - ObjectCounter *twoClocksAgo = _objectCounter[(_objectCounterPointer - 2 + number_of_recorded_counters)%number_of_recorded_counters]; - ObjectCounter *now = _objectCounter[_objectCounterPointer]; + object_counter_pointer_ = (object_counter_pointer_ + 1)%number_of_recorded_counters; + ObjectCounter *oneClockAgo = object_counter_[(object_counter_pointer_ - 1 + number_of_recorded_counters)%number_of_recorded_counters]; + ObjectCounter *twoClocksAgo = object_counter_[(object_counter_pointer_ - 2 + number_of_recorded_counters)%number_of_recorded_counters]; + ObjectCounter *now = object_counter_[object_counter_pointer_]; // grab the background now, for application in four clocks - if(mask & (1 << 5) && !(_horizontalTimer&3)) + if(mask & (1 << 5) && !(horizontal_timer_&3)) { - unsigned int offset = 4 + _horizontalTimer - (horizontalTimerPeriod - 160); - _upcomingEvents[upcomingPointerPlus4].updates |= Event::Action::Playfield; - _upcomingEvents[upcomingPointerPlus4].playfieldPixel = _playfield[(offset >> 2)%40]; + unsigned int offset = 4 + horizontal_timer_ - (horizontalTimerPeriod - 160); + upcoming_events_[upcoming_pointer_plus_4].updates |= Event::Action::Playfield; + upcoming_events_[upcoming_pointer_plus_4].playfield_pixel = playfield_[(offset >> 2)%40]; } if(mask & (1 << 4)) @@ -150,7 +150,7 @@ void Machine::update_timers(int mask) // update the count now[c].count = (oneClockAgo[c].count + 1)%160; - uint8_t repeatMask = _playerAndMissileSize[c&1] & 7; + uint8_t repeatMask = player_and_missile_size_[c&1] & 7; ObjectCounter *rollover; ObjectCounter *equality; @@ -181,9 +181,9 @@ void Machine::update_timers(int mask) if( (rollover[c].count == 159) || - (_hasSecondCopy[c&1] && equality[c].count == 16) || - (_hasThirdCopy[c&1] && equality[c].count == 32) || - (_hasFourthCopy[c&1] && equality[c].count == 64) + (has_second_copy_[c&1] && equality[c].count == 16) || + (has_third_copy_[c&1] && equality[c].count == 32) || + (has_fourth_copy_[c&1] && equality[c].count == 64) ) { now[c].pixel = 0; @@ -199,16 +199,16 @@ void Machine::update_timers(int mask) uint8_t Machine::get_output_pixel() { - ObjectCounter *now = _objectCounter[_objectCounterPointer]; + ObjectCounter *now = object_counter_[object_counter_pointer_]; // get the playfield pixel - unsigned int offset = _horizontalTimer - (horizontalTimerPeriod - 160); - uint8_t playfieldColour = ((_playfieldControl&6) == 2) ? _playerColour[offset / 80] : _playfieldColour; + unsigned int offset = horizontal_timer_ - (horizontalTimerPeriod - 160); + uint8_t playfieldColour = ((playfield_control_&6) == 2) ? player_colour_[offset / 80] : playfield_colour_; // ball pixel uint8_t ballPixel = 0; - if(now[4].pixel < _ballSize) { - ballPixel = _ballGraphicsEnable[_ballGraphicsSelector]; + if(now[4].pixel < ball_size_) { + ballPixel = ball_graphics_enable_[ball_graphics_selector_]; } // determine the player and missile pixels @@ -216,33 +216,33 @@ uint8_t Machine::get_output_pixel() uint8_t missilePixels[2] = { 0, 0 }; for(int c = 0; c < 2; c++) { - if(_playerGraphics[c] && now[c].pixel < 8) { - playerPixels[c] = (_playerGraphics[_playerGraphicsSelector[c]][c] >> (now[c].pixel ^ _playerReflectionMask[c])) & 1; + if(player_graphics_[c] && now[c].pixel < 8) { + playerPixels[c] = (player_graphics_[player_graphics_selector_[c]][c] >> (now[c].pixel ^ player_reflection_mask_[c])) & 1; } - if(!_missileGraphicsReset[c] && now[c+2].pixel < _missileSize[c]) { - missilePixels[c] = _missileGraphicsEnable[c]; + if(!missile_graphics_reset_[c] && now[c+2].pixel < missile_size_[c]) { + missilePixels[c] = missile_graphics_enable_[c]; } } // accumulate collisions - int pixel_mask = playerPixels[0] | (playerPixels[1] << 1) | (missilePixels[0] << 2) | (missilePixels[1] << 3) | (ballPixel << 4) | (_playfieldOutput << 5); - _collisions[0] |= _reportedCollisions[pixel_mask][0]; - _collisions[1] |= _reportedCollisions[pixel_mask][1]; - _collisions[2] |= _reportedCollisions[pixel_mask][2]; - _collisions[3] |= _reportedCollisions[pixel_mask][3]; - _collisions[4] |= _reportedCollisions[pixel_mask][4]; - _collisions[5] |= _reportedCollisions[pixel_mask][5]; - _collisions[6] |= _reportedCollisions[pixel_mask][6]; - _collisions[7] |= _reportedCollisions[pixel_mask][7]; + int pixel_mask = playerPixels[0] | (playerPixels[1] << 1) | (missilePixels[0] << 2) | (missilePixels[1] << 3) | (ballPixel << 4) | (playfield_output_ << 5); + collisions_[0] |= reported_collisions_[pixel_mask][0]; + collisions_[1] |= reported_collisions_[pixel_mask][1]; + collisions_[2] |= reported_collisions_[pixel_mask][2]; + collisions_[3] |= reported_collisions_[pixel_mask][3]; + collisions_[4] |= reported_collisions_[pixel_mask][4]; + collisions_[5] |= reported_collisions_[pixel_mask][5]; + collisions_[6] |= reported_collisions_[pixel_mask][6]; + collisions_[7] |= reported_collisions_[pixel_mask][7]; // apply appropriate priority to pick a colour - uint8_t playfieldPixel = _playfieldOutput | ballPixel; - uint8_t outputColour = playfieldPixel ? playfieldColour : _backgroundColour; + uint8_t playfield_pixel = playfield_output_ | ballPixel; + uint8_t outputColour = playfield_pixel ? playfieldColour : background_colour_; - if(!(_playfieldControl&0x04) || !playfieldPixel) { - if(playerPixels[1] || missilePixels[1]) outputColour = _playerColour[1]; - if(playerPixels[0] || missilePixels[0]) outputColour = _playerColour[0]; + if(!(playfield_control_&0x04) || !playfield_pixel) { + if(playerPixels[1] || missilePixels[1]) outputColour = player_colour_[1]; + if(playerPixels[0] || missilePixels[0]) outputColour = player_colour_[0]; } // return colour @@ -253,32 +253,32 @@ void Machine::setup_reported_collisions() { for(int c = 0; c < 64; c++) { - memset(_reportedCollisions[c], 0, 8); + memset(reported_collisions_[c], 0, 8); int playerPixels[2] = { c&1, (c >> 1)&1 }; int missilePixels[2] = { (c >> 2)&1, (c >> 3)&1 }; int ballPixel = (c >> 4)&1; - int playfieldPixel = (c >> 5)&1; + int playfield_pixel = (c >> 5)&1; if(playerPixels[0] | playerPixels[1]) { - _reportedCollisions[c][0] |= ((missilePixels[0] & playerPixels[1]) << 7) | ((missilePixels[0] & playerPixels[0]) << 6); - _reportedCollisions[c][1] |= ((missilePixels[1] & playerPixels[0]) << 7) | ((missilePixels[1] & playerPixels[1]) << 6); + reported_collisions_[c][0] |= ((missilePixels[0] & playerPixels[1]) << 7) | ((missilePixels[0] & playerPixels[0]) << 6); + reported_collisions_[c][1] |= ((missilePixels[1] & playerPixels[0]) << 7) | ((missilePixels[1] & playerPixels[1]) << 6); - _reportedCollisions[c][2] |= ((playfieldPixel & playerPixels[0]) << 7) | ((ballPixel & playerPixels[0]) << 6); - _reportedCollisions[c][3] |= ((playfieldPixel & playerPixels[1]) << 7) | ((ballPixel & playerPixels[1]) << 6); + reported_collisions_[c][2] |= ((playfield_pixel & playerPixels[0]) << 7) | ((ballPixel & playerPixels[0]) << 6); + reported_collisions_[c][3] |= ((playfield_pixel & playerPixels[1]) << 7) | ((ballPixel & playerPixels[1]) << 6); - _reportedCollisions[c][7] |= ((playerPixels[0] & playerPixels[1]) << 7); + reported_collisions_[c][7] |= ((playerPixels[0] & playerPixels[1]) << 7); } - if(playfieldPixel | ballPixel) { - _reportedCollisions[c][4] |= ((playfieldPixel & missilePixels[0]) << 7) | ((ballPixel & missilePixels[0]) << 6); - _reportedCollisions[c][5] |= ((playfieldPixel & missilePixels[1]) << 7) | ((ballPixel & missilePixels[1]) << 6); + if(playfield_pixel | ballPixel) { + reported_collisions_[c][4] |= ((playfield_pixel & missilePixels[0]) << 7) | ((ballPixel & missilePixels[0]) << 6); + reported_collisions_[c][5] |= ((playfield_pixel & missilePixels[1]) << 7) | ((ballPixel & missilePixels[1]) << 6); - _reportedCollisions[c][6] |= ((playfieldPixel & ballPixel) << 7); + reported_collisions_[c][6] |= ((playfield_pixel & ballPixel) << 7); } if(missilePixels[0] & missilePixels[1]) - _reportedCollisions[c][7] |= (1 << 6); + reported_collisions_[c][7] |= (1 << 6); } } @@ -286,103 +286,103 @@ void Machine::output_pixels(unsigned int count) { while(count--) { - if(_upcomingEvents[_upcomingEventsPointer].updates) + if(upcoming_events_[upcoming_events_pointer_].updates) { // apply any queued changes and flush the record - if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::HMoveSetup) + if(upcoming_events_[upcoming_events_pointer_].updates & Event::Action::HMoveSetup) { // schedule an extended left border - _stateByTime = _stateByExtendTime[1]; + state_by_time_ = state_by_extend_time_[1]; // clear any ongoing moves - if(_hMoveFlags) + if(hmove_flags_) { for(int c = 0; c < number_of_upcoming_events; c++) { - _upcomingEvents[c].updates &= ~(Event::Action::HMoveCompare | Event::Action::HMoveDecrement); + upcoming_events_[c].updates &= ~(Event::Action::HMoveCompare | Event::Action::HMoveDecrement); } } // schedule new moves - _hMoveFlags = 0x1f; - _hMoveCounter = 15; + hmove_flags_ = 0x1f; + hmove_counter_ = 15; // follow-through into a compare immediately - _upcomingEvents[_upcomingEventsPointer].updates |= Event::Action::HMoveCompare; + upcoming_events_[upcoming_events_pointer_].updates |= Event::Action::HMoveCompare; } - if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::HMoveCompare) + if(upcoming_events_[upcoming_events_pointer_].updates & Event::Action::HMoveCompare) { for(int c = 0; c < 5; c++) { - if(((_objectMotion[c] >> 4)^_hMoveCounter) == 7) + if(((object_motions_[c] >> 4)^hmove_counter_) == 7) { - _hMoveFlags &= ~(1 << c); + hmove_flags_ &= ~(1 << c); } } - if(_hMoveFlags) + if(hmove_flags_) { - if(_hMoveCounter) _hMoveCounter--; - _upcomingEvents[(_upcomingEventsPointer+4)%number_of_upcoming_events].updates |= Event::Action::HMoveCompare; - _upcomingEvents[(_upcomingEventsPointer+2)%number_of_upcoming_events].updates |= Event::Action::HMoveDecrement; + if(hmove_counter_) hmove_counter_--; + upcoming_events_[(upcoming_events_pointer_+4)%number_of_upcoming_events].updates |= Event::Action::HMoveCompare; + upcoming_events_[(upcoming_events_pointer_+2)%number_of_upcoming_events].updates |= Event::Action::HMoveDecrement; } } - if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::HMoveDecrement) + if(upcoming_events_[upcoming_events_pointer_].updates & Event::Action::HMoveDecrement) { - update_timers(_hMoveFlags); + update_timers(hmove_flags_); } - if(_upcomingEvents[_upcomingEventsPointer].updates & Event::Action::ResetCounter) + if(upcoming_events_[upcoming_events_pointer_].updates & Event::Action::ResetCounter) { - _objectCounter[_objectCounterPointer][_upcomingEvents[_upcomingEventsPointer].counter].count = 0; + object_counter_[object_counter_pointer_][upcoming_events_[upcoming_events_pointer_].counter].count = 0; } // zero out current update event - _upcomingEvents[_upcomingEventsPointer].updates = 0; + upcoming_events_[upcoming_events_pointer_].updates = 0; } // progress to next event - _upcomingEventsPointer = (_upcomingEventsPointer + 1)%number_of_upcoming_events; + upcoming_events_pointer_ = (upcoming_events_pointer_ + 1)%number_of_upcoming_events; // determine which output state is currently active - OutputState primary_state = _stateByTime[_horizontalTimer >> 2]; + OutputState primary_state = state_by_time_[horizontal_timer_ >> 2]; OutputState effective_state = primary_state; // update pixel timers if(primary_state == OutputState::Pixel) update_timers(~0); // update the background chain - if(_horizontalTimer >= 64 && _horizontalTimer <= 160+64 && !(_horizontalTimer&3)) + if(horizontal_timer_ >= 64 && horizontal_timer_ <= 160+64 && !(horizontal_timer_&3)) { - _playfieldOutput = _nextPlayfieldOutput; - _nextPlayfieldOutput = _playfield[(_horizontalTimer - 64) >> 2]; + playfield_output_ = next_playfield_output_; + next_playfield_output_ = playfield_[(horizontal_timer_ - 64) >> 2]; } // if vsync is enabled, output the opposite of the automatic hsync output; // also honour the vertical blank flag - if(_vSyncEnabled) { + if(vsync_enabled_) { effective_state = (effective_state = OutputState::Sync) ? OutputState::Blank : OutputState::Sync; - } else if(_vBlankEnabled && effective_state == OutputState::Pixel) { + } else if(vblank_enabled_ && effective_state == OutputState::Pixel) { effective_state = OutputState::Blank; } // decide what that means needs to be communicated to the CRT - _lastOutputStateDuration++; - if(effective_state != _lastOutputState) { - switch(_lastOutputState) { - case OutputState::Blank: _crt->output_blank(_lastOutputStateDuration); break; - case OutputState::Sync: _crt->output_sync(_lastOutputStateDuration); break; - case OutputState::ColourBurst: _crt->output_colour_burst(_lastOutputStateDuration, 96, 0); break; - case OutputState::Pixel: _crt->output_data(_lastOutputStateDuration, 1); break; + last_output_state_duration_++; + if(effective_state != last_output_state_) { + switch(last_output_state_) { + case OutputState::Blank: crt_->output_blank(last_output_state_duration_); break; + case OutputState::Sync: crt_->output_sync(last_output_state_duration_); break; + case OutputState::ColourBurst: crt_->output_colour_burst(last_output_state_duration_, 96, 0); break; + case OutputState::Pixel: crt_->output_data(last_output_state_duration_, 1); break; } - _lastOutputStateDuration = 0; - _lastOutputState = effective_state; + last_output_state_duration_ = 0; + last_output_state_ = effective_state; if(effective_state == OutputState::Pixel) { - _outputBuffer = _crt->allocate_write_area(160); + output_buffer_ = crt_->allocate_write_area(160); } else { - _outputBuffer = nullptr; + output_buffer_ = nullptr; } } @@ -390,19 +390,19 @@ void Machine::output_pixels(unsigned int count) if(effective_state == OutputState::Pixel) { uint8_t colour = get_output_pixel(); - if(_outputBuffer) + if(output_buffer_) { - *_outputBuffer = colour; - _outputBuffer++; + *output_buffer_ = colour; + output_buffer_++; } } // advance horizontal timer, perform reset actions if desired - _horizontalTimer = (_horizontalTimer + 1) % horizontalTimerPeriod; - if(!_horizontalTimer) + horizontal_timer_ = (horizontal_timer_ + 1) % horizontalTimerPeriod; + if(!horizontal_timer_) { // switch back to a normal length left border - _stateByTime = _stateByExtendTime[0]; + state_by_time_ = state_by_extend_time_[0]; set_ready_line(false); } } @@ -418,47 +418,47 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // effect until the next read; therefore it isn't safe to assume that signalling ready immediately // skips to the end of the line. if(operation == CPU6502::BusOperation::Ready) { - unsigned int distance_to_end_of_ready = horizontalTimerPeriod - _horizontalTimer; + unsigned int distance_to_end_of_ready = horizontalTimerPeriod - horizontal_timer_; cycles_run_for = distance_to_end_of_ready; } output_pixels(cycles_run_for); - _cycles_since_speaker_update += cycles_run_for; + cycles_since_speaker_update_ += cycles_run_for; if(operation != CPU6502::BusOperation::Ready) { // check for a paging access - if(_rom_size > 4096 && ((address & 0x1f00) == 0x1f00)) { - uint8_t *base_ptr = _romPages[0]; - uint8_t first_paging_register = (uint8_t)(0xf8 - (_rom_size >> 14)*2); + if(rom_size_ > 4096 && ((address & 0x1f00) == 0x1f00)) { + uint8_t *base_ptr = rom_pages_[0]; + uint8_t first_paging_register = (uint8_t)(0xf8 - (rom_size_ >> 14)*2); const uint8_t paging_register = address&0xff; if(paging_register >= first_paging_register) { const uint16_t selected_page = paging_register - first_paging_register; - if(selected_page * 4096 < _rom_size) { - base_ptr = &_rom[selected_page * 4096]; + if(selected_page * 4096 < rom_size_) { + base_ptr = &rom_[selected_page * 4096]; } } - if(base_ptr != _romPages[0]) { - _romPages[0] = base_ptr; - _romPages[1] = base_ptr + 1024; - _romPages[2] = base_ptr + 2048; - _romPages[3] = base_ptr + 3072; + if(base_ptr != rom_pages_[0]) { + rom_pages_[0] = base_ptr; + rom_pages_[1] = base_ptr + 1024; + rom_pages_[2] = base_ptr + 2048; + rom_pages_[3] = base_ptr + 3072; } } // check for a ROM read if((address&0x1000) && isReadOperation(operation)) { - returnValue &= _romPages[(address >> 10)&3][address&1023]; + returnValue &= rom_pages_[(address >> 10)&3][address&1023]; } // check for a RAM access if((address&0x1280) == 0x80) { if(isReadOperation(operation)) { - returnValue &= _mos6532.get_ram(address); + returnValue &= mos6532_.get_ram(address); } else { - _mos6532.set_ram(address, *value); + mos6532_.set_ram(address, *value); } } @@ -475,7 +475,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0x05: // missile 1 / playfield / ball collisions case 0x06: // ball / playfield collisions case 0x07: // player / player, missile / missile collisions - returnValue &= _collisions[decodedAddress]; + returnValue &= collisions_[decodedAddress]; break; case 0x08: @@ -487,23 +487,23 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0x0c: case 0x0d: - returnValue &= _tiaInputValue[decodedAddress - 0x0c]; + returnValue &= tia_input_value_[decodedAddress - 0x0c]; break; } } else { const uint16_t decodedAddress = address & 0x3f; switch(decodedAddress) { case 0x00: - _vSyncEnabled = !!(*value & 0x02); + vsync_enabled_ = !!(*value & 0x02); break; - case 0x01: _vBlankEnabled = !!(*value & 0x02); break; + case 0x01: vblank_enabled_ = !!(*value & 0x02); break; case 0x02: - if(_horizontalTimer) set_ready_line(true); + if(horizontal_timer_) set_ready_line(true); break; case 0x03: // Reset is delayed by four cycles. - _horizontalTimer = horizontalTimerPeriod - 4; + horizontal_timer_ = horizontalTimerPeriod - 4; // TODO: audio will now be out of synchronisation — fix break; @@ -511,117 +511,117 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0x04: case 0x05: { int entry = decodedAddress - 0x04; - _playerAndMissileSize[entry] = *value; - _missileSize[entry] = 1 << ((*value >> 4)&3); + player_and_missile_size_[entry] = *value; + missile_size_[entry] = 1 << ((*value >> 4)&3); uint8_t repeatMask = (*value)&7; - _hasSecondCopy[entry] = (repeatMask == 1) || (repeatMask == 3); - _hasThirdCopy[entry] = (repeatMask == 2) || (repeatMask == 3) || (repeatMask == 6); - _hasFourthCopy[entry] = (repeatMask == 4) || (repeatMask == 6); + has_second_copy_[entry] = (repeatMask == 1) || (repeatMask == 3); + has_third_copy_[entry] = (repeatMask == 2) || (repeatMask == 3) || (repeatMask == 6); + has_fourth_copy_[entry] = (repeatMask == 4) || (repeatMask == 6); } break; case 0x06: - case 0x07: _playerColour[decodedAddress - 0x06] = *value; break; - case 0x08: _playfieldColour = *value; break; - case 0x09: _backgroundColour = *value; break; + case 0x07: player_colour_[decodedAddress - 0x06] = *value; break; + case 0x08: playfield_colour_ = *value; break; + case 0x09: background_colour_ = *value; break; case 0x0a: { - uint8_t old_playfield_control = _playfieldControl; - _playfieldControl = *value; - _ballSize = 1 << ((_playfieldControl >> 4)&3); + uint8_t old_playfield_control = playfield_control_; + playfield_control_ = *value; + ball_size_ = 1 << ((playfield_control_ >> 4)&3); // did the mirroring bit change? - if((_playfieldControl^old_playfield_control)&1) { - if(_playfieldControl&1) { - for(int c = 0; c < 20; c++) _playfield[c+20] = _playfield[19-c]; + if((playfield_control_^old_playfield_control)&1) { + if(playfield_control_&1) { + for(int c = 0; c < 20; c++) playfield_[c+20] = playfield_[19-c]; } else { - memcpy(&_playfield[20], _playfield, 20); + memcpy(&playfield_[20], playfield_, 20); } } } break; case 0x0b: - case 0x0c: _playerReflectionMask[decodedAddress - 0x0b] = (*value)&8 ? 0 : 7; break; + case 0x0c: player_reflection_mask_[decodedAddress - 0x0b] = (*value)&8 ? 0 : 7; break; case 0x0d: - _playfield[0] = ((*value) >> 4)&1; - _playfield[1] = ((*value) >> 5)&1; - _playfield[2] = ((*value) >> 6)&1; - _playfield[3] = (*value) >> 7; + playfield_[0] = ((*value) >> 4)&1; + playfield_[1] = ((*value) >> 5)&1; + playfield_[2] = ((*value) >> 6)&1; + playfield_[3] = (*value) >> 7; - if(_playfieldControl&1) { - for(int c = 0; c < 4; c++) _playfield[39-c] = _playfield[c]; + if(playfield_control_&1) { + for(int c = 0; c < 4; c++) playfield_[39-c] = playfield_[c]; } else { - memcpy(&_playfield[20], _playfield, 4); + memcpy(&playfield_[20], playfield_, 4); } break; case 0x0e: - _playfield[4] = (*value) >> 7; - _playfield[5] = ((*value) >> 6)&1; - _playfield[6] = ((*value) >> 5)&1; - _playfield[7] = ((*value) >> 4)&1; - _playfield[8] = ((*value) >> 3)&1; - _playfield[9] = ((*value) >> 2)&1; - _playfield[10] = ((*value) >> 1)&1; - _playfield[11] = (*value)&1; + playfield_[4] = (*value) >> 7; + playfield_[5] = ((*value) >> 6)&1; + playfield_[6] = ((*value) >> 5)&1; + playfield_[7] = ((*value) >> 4)&1; + playfield_[8] = ((*value) >> 3)&1; + playfield_[9] = ((*value) >> 2)&1; + playfield_[10] = ((*value) >> 1)&1; + playfield_[11] = (*value)&1; - if(_playfieldControl&1) { - for(int c = 0; c < 8; c++) _playfield[35-c] = _playfield[c+4]; + if(playfield_control_&1) { + for(int c = 0; c < 8; c++) playfield_[35-c] = playfield_[c+4]; } else { - memcpy(&_playfield[24], &_playfield[4], 8); + memcpy(&playfield_[24], &playfield_[4], 8); } break; case 0x0f: - _playfield[19] = (*value) >> 7; - _playfield[18] = ((*value) >> 6)&1; - _playfield[17] = ((*value) >> 5)&1; - _playfield[16] = ((*value) >> 4)&1; - _playfield[15] = ((*value) >> 3)&1; - _playfield[14] = ((*value) >> 2)&1; - _playfield[13] = ((*value) >> 1)&1; - _playfield[12] = (*value)&1; + playfield_[19] = (*value) >> 7; + playfield_[18] = ((*value) >> 6)&1; + playfield_[17] = ((*value) >> 5)&1; + playfield_[16] = ((*value) >> 4)&1; + playfield_[15] = ((*value) >> 3)&1; + playfield_[14] = ((*value) >> 2)&1; + playfield_[13] = ((*value) >> 1)&1; + playfield_[12] = (*value)&1; - if(_playfieldControl&1) { - for(int c = 0; c < 8; c++) _playfield[27-c] = _playfield[c+12]; + if(playfield_control_&1) { + for(int c = 0; c < 8; c++) playfield_[27-c] = playfield_[c+12]; } else { - memcpy(&_playfield[32], &_playfield[12], 8); + memcpy(&playfield_[32], &playfield_[12], 8); } break; case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: - _upcomingEvents[(_upcomingEventsPointer + 4)%number_of_upcoming_events].updates |= Event::Action::ResetCounter; - _upcomingEvents[(_upcomingEventsPointer + 4)%number_of_upcoming_events].counter = decodedAddress - 0x10; + upcoming_events_[(upcoming_events_pointer_ + 4)%number_of_upcoming_events].updates |= Event::Action::ResetCounter; + upcoming_events_[(upcoming_events_pointer_ + 4)%number_of_upcoming_events].counter = decodedAddress - 0x10; break; case 0x15: case 0x16: update_audio(); - _speaker->set_control(decodedAddress - 0x15, *value); + speaker_->set_control(decodedAddress - 0x15, *value); break; case 0x17: case 0x18: update_audio(); - _speaker->set_divider(decodedAddress - 0x17, *value); + speaker_->set_divider(decodedAddress - 0x17, *value); break; case 0x19: case 0x1a: update_audio(); - _speaker->set_volume(decodedAddress - 0x19, *value); + speaker_->set_volume(decodedAddress - 0x19, *value); break; case 0x1c: - _ballGraphicsEnable[1] = _ballGraphicsEnable[0]; + ball_graphics_enable_[1] = ball_graphics_enable_[0]; case 0x1b: { int index = decodedAddress - 0x1b; - _playerGraphics[0][index] = *value; - _playerGraphics[1][index^1] = _playerGraphics[0][index^1]; + player_graphics_[0][index] = *value; + player_graphics_[1][index^1] = player_graphics_[0][index^1]; } break; case 0x1d: case 0x1e: - _missileGraphicsEnable[decodedAddress - 0x1d] = ((*value) >> 1)&1; + missile_graphics_enable_[decodedAddress - 0x1d] = ((*value) >> 1)&1; // printf("e:%02x <- %c\n", decodedAddress - 0x1d, ((*value)&1) ? 'E' : '-'); break; case 0x1f: - _ballGraphicsEnable[0] = ((*value) >> 1)&1; + ball_graphics_enable_[0] = ((*value) >> 1)&1; break; case 0x20: @@ -629,23 +629,23 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0x22: case 0x23: case 0x24: - _objectMotion[decodedAddress - 0x20] = *value; + object_motions_[decodedAddress - 0x20] = *value; break; - case 0x25: _playerGraphicsSelector[0] = (*value)&1; break; - case 0x26: _playerGraphicsSelector[1] = (*value)&1; break; - case 0x27: _ballGraphicsSelector = (*value)&1; break; + case 0x25: player_graphics_selector_[0] = (*value)&1; break; + case 0x26: player_graphics_selector_[1] = (*value)&1; break; + case 0x27: ball_graphics_selector_ = (*value)&1; break; case 0x28: case 0x29: { // TODO: this should properly mean setting a flag and propagating later, I think? int index = decodedAddress - 0x28; - if(!(*value&0x02) && _missileGraphicsReset[index]) + if(!(*value&0x02) && missile_graphics_reset_[index]) { - _objectCounter[_objectCounterPointer][index + 2].count = _objectCounter[_objectCounterPointer][index].count; + object_counter_[object_counter_pointer_][index + 2].count = object_counter_[object_counter_pointer_][index].count; - uint8_t repeatMask = _playerAndMissileSize[index] & 7; + uint8_t repeatMask = player_and_missile_size_[index] & 7; int extra_offset; switch(repeatMask) { @@ -654,9 +654,9 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 7: extra_offset = 10; break; } - _objectCounter[_objectCounterPointer][index + 2].count = (_objectCounter[_objectCounterPointer][index + 2].count + extra_offset)%160; + object_counter_[object_counter_pointer_][index + 2].count = (object_counter_[object_counter_pointer_][index + 2].count + extra_offset)%160; } - _missileGraphicsReset[index] = !!((*value) & 0x02); + missile_graphics_reset_[index] = !!((*value) & 0x02); // printf("r:%02x <- %c\n", decodedAddress - 0x28, ((*value)&2) ? 'R' : '-'); } break; @@ -665,21 +665,21 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // justification for +5: "we need to wait at least 71 [clocks] before the HMOVE operation is complete"; // which will take 16*4 + 2 = 66 cycles from the first compare, implying the first compare must be // in five cycles from now -// int start_pause = ((_horizontalTimer + 3)&3) + 4; - _upcomingEvents[(_upcomingEventsPointer + 5)%number_of_upcoming_events].updates |= Event::Action::HMoveSetup; +// int start_pause = ((horizontal_timer_ + 3)&3) + 4; + upcoming_events_[(upcoming_events_pointer_ + 5)%number_of_upcoming_events].updates |= Event::Action::HMoveSetup; } break; case 0x2b: - _objectMotion[0] = - _objectMotion[1] = - _objectMotion[2] = - _objectMotion[3] = - _objectMotion[4] = 0; + object_motions_[0] = + object_motions_[1] = + object_motions_[2] = + object_motions_[3] = + object_motions_[4] = 0; break; case 0x2c: - _collisions[0] = _collisions[1] = _collisions[2] = - _collisions[3] = _collisions[4] = _collisions[5] = 0x3f; - _collisions[6] = 0x7f; - _collisions[7] = 0x3f; + collisions_[0] = collisions_[1] = collisions_[2] = + collisions_[3] = collisions_[4] = collisions_[5] = 0x3f; + collisions_[6] = 0x7f; + collisions_[7] = 0x3f; break; } } @@ -688,9 +688,9 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // check for a PIA access if((address&0x1280) == 0x280) { if(isReadOperation(operation)) { - returnValue &= _mos6532.get_register(address); + returnValue &= mos6532_.get_register(address); } else { - _mos6532.set_register(address, *value); + mos6532_.set_register(address, *value); } } @@ -699,7 +699,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin } } - _mos6532.run_for_cycles(cycles_run_for / 3); + mos6532_.run_for_cycles(cycles_run_for / 3); return cycles_run_for / 3; } @@ -707,19 +707,19 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin void Machine::set_digital_input(Atari2600DigitalInput input, bool state) { switch (input) { - case Atari2600DigitalInputJoy1Up: _mos6532.update_port_input(0, 0x10, state); break; - case Atari2600DigitalInputJoy1Down: _mos6532.update_port_input(0, 0x20, state); break; - case Atari2600DigitalInputJoy1Left: _mos6532.update_port_input(0, 0x40, state); break; - case Atari2600DigitalInputJoy1Right: _mos6532.update_port_input(0, 0x80, state); break; + case Atari2600DigitalInputJoy1Up: mos6532_.update_port_input(0, 0x10, state); break; + case Atari2600DigitalInputJoy1Down: mos6532_.update_port_input(0, 0x20, state); break; + case Atari2600DigitalInputJoy1Left: mos6532_.update_port_input(0, 0x40, state); break; + case Atari2600DigitalInputJoy1Right: mos6532_.update_port_input(0, 0x80, state); break; - case Atari2600DigitalInputJoy2Up: _mos6532.update_port_input(0, 0x01, state); break; - case Atari2600DigitalInputJoy2Down: _mos6532.update_port_input(0, 0x02, state); break; - case Atari2600DigitalInputJoy2Left: _mos6532.update_port_input(0, 0x04, state); break; - case Atari2600DigitalInputJoy2Right: _mos6532.update_port_input(0, 0x08, state); break; + case Atari2600DigitalInputJoy2Up: mos6532_.update_port_input(0, 0x01, state); break; + case Atari2600DigitalInputJoy2Down: mos6532_.update_port_input(0, 0x02, state); break; + case Atari2600DigitalInputJoy2Left: mos6532_.update_port_input(0, 0x04, state); break; + case Atari2600DigitalInputJoy2Right: mos6532_.update_port_input(0, 0x08, state); break; // TODO: latching - case Atari2600DigitalInputJoy1Fire: if(state) _tiaInputValue[0] &= ~0x80; else _tiaInputValue[0] |= 0x80; break; - case Atari2600DigitalInputJoy2Fire: if(state) _tiaInputValue[1] &= ~0x80; else _tiaInputValue[1] |= 0x80; break; + case Atari2600DigitalInputJoy1Fire: if(state) tia_input_value_[0] &= ~0x80; else tia_input_value_[0] |= 0x80; break; + case Atari2600DigitalInputJoy2Fire: if(state) tia_input_value_[1] &= ~0x80; else tia_input_value_[1] |= 0x80; break; default: break; } @@ -728,11 +728,11 @@ void Machine::set_digital_input(Atari2600DigitalInput input, bool state) void Machine::set_switch_is_enabled(Atari2600Switch input, bool state) { switch(input) { - case Atari2600SwitchReset: _mos6532.update_port_input(1, 0x01, state); break; - case Atari2600SwitchSelect: _mos6532.update_port_input(1, 0x02, state); break; - case Atari2600SwitchColour: _mos6532.update_port_input(1, 0x08, state); break; - case Atari2600SwitchLeftPlayerDifficulty: _mos6532.update_port_input(1, 0x40, state); break; - case Atari2600SwitchRightPlayerDifficulty: _mos6532.update_port_input(1, 0x80, state); break; + case Atari2600SwitchReset: mos6532_.update_port_input(1, 0x01, state); break; + case Atari2600SwitchSelect: mos6532_.update_port_input(1, 0x02, state); break; + case Atari2600SwitchColour: mos6532_.update_port_input(1, 0x08, state); break; + case Atari2600SwitchLeftPlayerDifficulty: mos6532_.update_port_input(1, 0x40, state); break; + case Atari2600SwitchRightPlayerDifficulty: mos6532_.update_port_input(1, 0x80, state); break; } } @@ -742,48 +742,36 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) Storage::Cartridge::Cartridge::Segment segment = target.cartridges.front()->get_segments().front(); size_t length = segment.data.size(); - _rom_size = 1024; - while(_rom_size < length && _rom_size < 32768) _rom_size <<= 1; + rom_size_ = 1024; + while(rom_size_ < length && rom_size_ < 32768) rom_size_ <<= 1; - delete[] _rom; - - _rom = new uint8_t[_rom_size]; + delete[] rom_; + rom_ = new uint8_t[rom_size_]; size_t offset = 0; - const size_t copy_step = std::min(_rom_size, length); - while(offset < _rom_size) + const size_t copy_step = std::min(rom_size_, length); + while(offset < rom_size_) { - size_t copy_length = std::min(copy_step, _rom_size - offset); - memcpy(&_rom[offset], &segment.data[0], copy_length); + size_t copy_length = std::min(copy_step, rom_size_ - offset); + memcpy(&rom_[offset], &segment.data[0], copy_length); offset += copy_length; } - size_t romMask = _rom_size - 1; - _romPages[0] = _rom; - _romPages[1] = &_rom[1024 & romMask]; - _romPages[2] = &_rom[2048 & romMask]; - _romPages[3] = &_rom[3072 & romMask]; + size_t romMask = rom_size_ - 1; + rom_pages_[0] = rom_; + rom_pages_[1] = &rom_[1024 & romMask]; + rom_pages_[2] = &rom_[2048 & romMask]; + rom_pages_[3] = &rom_[3072 & romMask]; } #pragma mark - Audio void Machine::update_audio() { - unsigned int audio_cycles = _cycles_since_speaker_update / 114; + unsigned int audio_cycles = cycles_since_speaker_update_ / 114; -// static unsigned int total_cycles = 0; -// total_cycles += audio_cycles; -// static time_t logged_time = 0; -// time_t time_now = time(nullptr); -// if(time_now - logged_time > 0) -// { -// printf("[s] %ld : %d\n", time_now - logged_time, total_cycles); -// total_cycles = 0; -// logged_time = time_now; -// } - - _speaker->run_for_cycles(audio_cycles); - _cycles_since_speaker_update %= 114; + speaker_->run_for_cycles(audio_cycles); + cycles_since_speaker_update_ %= 114; } void Machine::synchronise() @@ -791,133 +779,3 @@ void Machine::synchronise() update_audio(); } -Atari2600::Speaker::Speaker() -{ - _poly4_counter[0] = _poly4_counter[1] = 0x00f; - _poly5_counter[0] = _poly5_counter[1] = 0x01f; - _poly9_counter[0] = _poly9_counter[1] = 0x1ff; -} - -Atari2600::Speaker::~Speaker() -{ -} - -void Atari2600::Speaker::set_volume(int channel, uint8_t volume) -{ - enqueue([=]() { - _volume[channel] = volume & 0xf; - }); -} - -void Atari2600::Speaker::set_divider(int channel, uint8_t divider) -{ - enqueue([=]() { - _divider[channel] = divider & 0x1f; - _divider_counter[channel] = 0; - }); -} - -void Atari2600::Speaker::set_control(int channel, uint8_t control) -{ - enqueue([=]() { - _control[channel] = control & 0xf; - }); -} - -#define advance_poly4(c) _poly4_counter[channel] = (_poly4_counter[channel] >> 1) | (((_poly4_counter[channel] << 3) ^ (_poly4_counter[channel] << 2))&0x008) -#define advance_poly5(c) _poly5_counter[channel] = (_poly5_counter[channel] >> 1) | (((_poly5_counter[channel] << 4) ^ (_poly5_counter[channel] << 2))&0x010) -#define advance_poly9(c) _poly9_counter[channel] = (_poly9_counter[channel] >> 1) | (((_poly9_counter[channel] << 4) ^ (_poly9_counter[channel] << 8))&0x100) - -void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *target) -{ - for(unsigned int c = 0; c < number_of_samples; c++) - { - target[c] = 0; - for(int channel = 0; channel < 2; channel++) - { - _divider_counter[channel] ++; - int level = 0; - switch(_control[channel]) - { - case 0x0: case 0xb: // constant 1 - level = 1; - break; - - case 0x4: case 0x5: // div2 tone - level = (_divider_counter[channel] / (_divider[channel]+1))&1; - break; - - case 0xc: case 0xd: // div6 tone - level = (_divider_counter[channel] / ((_divider[channel]+1)*3))&1; - break; - - case 0x6: case 0xa: // div31 tone - level = (_divider_counter[channel] / (_divider[channel]+1))%30 <= 18; - break; - - case 0xe: // div93 tone - level = (_divider_counter[channel] / ((_divider[channel]+1)*3))%30 <= 18; - break; - - case 0x1: // 4-bit poly - level = _poly4_counter[channel]&1; - if(_divider_counter[channel] == _divider[channel]+1) - { - _divider_counter[channel] = 0; - advance_poly4(channel); - } - break; - - case 0x2: // 4-bit poly div31 - level = _poly4_counter[channel]&1; - if(_divider_counter[channel]%(30*(_divider[channel]+1)) == 18) - { - advance_poly4(channel); - } - break; - - case 0x3: // 5/4-bit poly - level = _output_state[channel]; - if(_divider_counter[channel] == _divider[channel]+1) - { - if(_poly5_counter[channel]&1) - { - _output_state[channel] = _poly4_counter[channel]&1; - advance_poly4(channel); - } - advance_poly5(channel); - } - break; - - case 0x7: case 0x9: // 5-bit poly - level = _poly5_counter[channel]&1; - if(_divider_counter[channel] == _divider[channel]+1) - { - _divider_counter[channel] = 0; - advance_poly5(channel); - } - break; - - case 0xf: // 5-bit poly div6 - level = _poly5_counter[channel]&1; - if(_divider_counter[channel] == (_divider[channel]+1)*3) - { - _divider_counter[channel] = 0; - advance_poly5(channel); - } - break; - - case 0x8: // 9-bit poly - level = _poly9_counter[channel]&1; - if(_divider_counter[channel] == _divider[channel]+1) - { - _divider_counter[channel] = 0; - advance_poly9(channel); - } - break; - } - - target[c] += _volume[channel] * 1024 * level; - } - } -} diff --git a/Machines/Atari2600/Atari2600.hpp b/Machines/Atari2600/Atari2600.hpp index daeab499a..b0320a267 100644 --- a/Machines/Atari2600/Atari2600.hpp +++ b/Machines/Atari2600/Atari2600.hpp @@ -12,8 +12,9 @@ #include #include "../../Processors/6502/CPU6502.hpp" -#include "../../Components/6532/6532.hpp" #include "../CRTMachine.hpp" +#include "PIA.hpp" +#include "Speaker.hpp" #include "../ConfigurationTarget.hpp" #include "Atari2600Inputs.h" @@ -23,56 +24,6 @@ namespace Atari2600 { const unsigned int number_of_upcoming_events = 6; const unsigned int number_of_recorded_counters = 7; -class Speaker: public ::Outputs::Filter { - public: - Speaker(); - ~Speaker(); - - void set_volume(int channel, uint8_t volume); - void set_divider(int channel, uint8_t divider); - void set_control(int channel, uint8_t control); - - void get_samples(unsigned int number_of_samples, int16_t *target); - - private: - uint8_t _volume[2]; - uint8_t _divider[2]; - uint8_t _control[2]; - - int _poly4_counter[2]; - int _poly5_counter[2]; - int _poly9_counter[2]; - int _output_state[2]; - - int _divider_counter[2]; - - int _pattern_periods[16]; - int _patterns[16][512]; -}; - -class PIA: public MOS::MOS6532 { - public: - inline uint8_t get_port_input(int port) - { - return _portValues[port]; - } - - inline void update_port_input(int port, uint8_t mask, bool set) - { - if(set) _portValues[port] &= ~mask; else _portValues[port] |= mask; - set_port_did_change(port); - } - - PIA() : - _portValues{0xff, 0xff} - {} - - private: - uint8_t _portValues[2]; - -}; - - class Machine: public CPU6502::Processor, public CRTMachine::Machine, @@ -95,26 +46,26 @@ class Machine: // to satisfy CRTMachine::Machine virtual void setup_output(float aspect_ratio); virtual void close_output(); - virtual std::shared_ptr get_crt() { return _crt; } - virtual std::shared_ptr get_speaker() { return _speaker; } + virtual std::shared_ptr get_crt() { return crt_; } + virtual std::shared_ptr get_speaker() { return speaker_; } virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); } // TODO: different rate for PAL private: - uint8_t *_rom, *_romPages[4]; - size_t _rom_size; + uint8_t *rom_, *rom_pages_[4]; + size_t rom_size_; // the RIOT - PIA _mos6532; + PIA mos6532_; // playfield registers - uint8_t _playfieldControl; - uint8_t _playfieldColour; - uint8_t _backgroundColour; - uint8_t _playfield[41]; + uint8_t playfield_control_; + uint8_t playfield_colour_; + uint8_t background_colour_; + uint8_t playfield_[41]; // ... and derivatives - int _ballSize, _missileSize[2]; + int ball_size_, missile_size_[2]; // delayed clock events enum OutputState { @@ -136,12 +87,12 @@ class Machine: int updates; OutputState state; - uint8_t playfieldPixel; + uint8_t playfield_pixel; int counter; - Event() : updates(0), playfieldPixel(0) {} - } _upcomingEvents[number_of_upcoming_events]; - unsigned int _upcomingEventsPointer; + Event() : updates(0), playfield_pixel(0) {} + } upcoming_events_[number_of_upcoming_events]; + unsigned int upcoming_events_pointer_; // object counters struct ObjectCounter { @@ -150,74 +101,73 @@ class Machine: int broad_pixel; // for sprite objects, a count of cycles since the last counter reset; otherwise unused ObjectCounter() : count(0), pixel(0), broad_pixel(0) {} - } _objectCounter[number_of_recorded_counters][5]; - unsigned int _objectCounterPointer; + } object_counter_[number_of_recorded_counters][5]; + unsigned int object_counter_pointer_; // the latched playfield output - uint8_t _playfieldOutput, _nextPlayfieldOutput; + uint8_t playfield_output_, next_playfield_output_; // player registers - uint8_t _playerColour[2]; - uint8_t _playerReflectionMask[2]; - uint8_t _playerGraphics[2][2]; - uint8_t _playerGraphicsSelector[2]; - bool _playerStart[2]; + uint8_t player_colour_[2]; + uint8_t player_reflection_mask_[2]; + uint8_t player_graphics_[2][2]; + uint8_t player_graphics_selector_[2]; // object flags - bool _hasSecondCopy[2]; - bool _hasThirdCopy[2]; - bool _hasFourthCopy[2]; - uint8_t _objectMotion[5]; // the value stored to this counter's motion register + bool has_second_copy_[2]; + bool has_third_copy_[2]; + bool has_fourth_copy_[2]; + uint8_t object_motions_[5]; // the value stored to this counter's motion register // player + missile registers - uint8_t _playerAndMissileSize[2]; + uint8_t player_and_missile_size_[2]; // missile registers - uint8_t _missileGraphicsEnable[2]; - bool _missileGraphicsReset[2]; + uint8_t missile_graphics_enable_[2]; + bool missile_graphics_reset_[2]; // ball registers - uint8_t _ballGraphicsEnable[2]; - uint8_t _ballGraphicsSelector; + uint8_t ball_graphics_enable_[2]; + uint8_t ball_graphics_selector_; // graphics output - unsigned int _horizontalTimer; - bool _vSyncEnabled, _vBlankEnabled; + unsigned int horizontal_timer_; + bool vsync_enabled_, vblank_enabled_; // horizontal motion control - uint8_t _hMoveCounter; - uint8_t _hMoveFlags; + uint8_t hmove_counter_; + uint8_t hmove_flags_; // joystick state - uint8_t _tiaInputValue[2]; + uint8_t tia_input_value_[2]; // collisions - uint8_t _collisions[8]; + uint8_t collisions_[8]; void output_pixels(unsigned int count); uint8_t get_output_pixel(); void update_timers(int mask); // outputs - std::shared_ptr _crt; - std::shared_ptr _speaker; + std::shared_ptr crt_; + std::shared_ptr speaker_; // current mode - bool _is_pal_region; + bool is_pal_region_; // speaker backlog accumlation counter - unsigned int _cycles_since_speaker_update; + unsigned int cycles_since_speaker_update_; void update_audio(); // latched output state - unsigned int _lastOutputStateDuration; - OutputState _stateByExtendTime[2][57]; - OutputState *_stateByTime; - OutputState _lastOutputState; - uint8_t *_outputBuffer; + unsigned int last_output_state_duration_; + OutputState state_by_extend_time_[2][57]; + OutputState *state_by_time_; + OutputState last_output_state_; + uint8_t *output_buffer_; // lookup table for collision reporting - uint8_t _reportedCollisions[64][8]; + uint8_t reported_collisions_[64][8]; void setup_reported_collisions(); }; diff --git a/Machines/Atari2600/PIA.hpp b/Machines/Atari2600/PIA.hpp new file mode 100644 index 000000000..2faa80242 --- /dev/null +++ b/Machines/Atari2600/PIA.hpp @@ -0,0 +1,40 @@ +// +// PIA.h +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef Atari2600_PIA_h +#define Atari2600_PIA_h + +#include "../../Components/6532/6532.hpp" + +namespace Atari2600 { + +class PIA: public MOS::MOS6532 { + public: + inline uint8_t get_port_input(int port) + { + return port_values_[port]; + } + + inline void update_port_input(int port, uint8_t mask, bool set) + { + if(set) port_values_[port] &= ~mask; else port_values_[port] |= mask; + set_port_did_change(port); + } + + PIA() : + port_values_{0xff, 0xff} + {} + + private: + uint8_t port_values_[2]; + +}; + +} + +#endif /* PIA_h */ diff --git a/Machines/Atari2600/Speaker.cpp b/Machines/Atari2600/Speaker.cpp new file mode 100644 index 000000000..a304fa29b --- /dev/null +++ b/Machines/Atari2600/Speaker.cpp @@ -0,0 +1,137 @@ +// +// Speaker.cpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#include "Speaker.hpp" + +using namespace Atari2600; + +Atari2600::Speaker::Speaker() : + poly4_counter_{0x00f, 0x00f}, + poly5_counter_{0x01f, 0x01f}, + poly9_counter_{0x1ff, 0x1ff} +{} + +void Atari2600::Speaker::set_volume(int channel, uint8_t volume) +{ + enqueue([=]() { + volume_[channel] = volume & 0xf; + }); +} + +void Atari2600::Speaker::set_divider(int channel, uint8_t divider) +{ + enqueue([=]() { + divider_[channel] = divider & 0x1f; + divider_counter_[channel] = 0; + }); +} + +void Atari2600::Speaker::set_control(int channel, uint8_t control) +{ + enqueue([=]() { + control_[channel] = control & 0xf; + }); +} + +#define advance_poly4(c) poly4_counter_[channel] = (poly4_counter_[channel] >> 1) | (((poly4_counter_[channel] << 3) ^ (poly4_counter_[channel] << 2))&0x008) +#define advance_poly5(c) poly5_counter_[channel] = (poly5_counter_[channel] >> 1) | (((poly5_counter_[channel] << 4) ^ (poly5_counter_[channel] << 2))&0x010) +#define advance_poly9(c) poly9_counter_[channel] = (poly9_counter_[channel] >> 1) | (((poly9_counter_[channel] << 4) ^ (poly9_counter_[channel] << 8))&0x100) + +void Atari2600::Speaker::get_samples(unsigned int number_of_samples, int16_t *target) +{ + for(unsigned int c = 0; c < number_of_samples; c++) + { + target[c] = 0; + for(int channel = 0; channel < 2; channel++) + { + divider_counter_[channel] ++; + int level = 0; + switch(control_[channel]) + { + case 0x0: case 0xb: // constant 1 + level = 1; + break; + + case 0x4: case 0x5: // div2 tone + level = (divider_counter_[channel] / (divider_[channel]+1))&1; + break; + + case 0xc: case 0xd: // div6 tone + level = (divider_counter_[channel] / ((divider_[channel]+1)*3))&1; + break; + + case 0x6: case 0xa: // div31 tone + level = (divider_counter_[channel] / (divider_[channel]+1))%30 <= 18; + break; + + case 0xe: // div93 tone + level = (divider_counter_[channel] / ((divider_[channel]+1)*3))%30 <= 18; + break; + + case 0x1: // 4-bit poly + level = poly4_counter_[channel]&1; + if(divider_counter_[channel] == divider_[channel]+1) + { + divider_counter_[channel] = 0; + advance_poly4(channel); + } + break; + + case 0x2: // 4-bit poly div31 + level = poly4_counter_[channel]&1; + if(divider_counter_[channel]%(30*(divider_[channel]+1)) == 18) + { + advance_poly4(channel); + } + break; + + case 0x3: // 5/4-bit poly + level = output_state_[channel]; + if(divider_counter_[channel] == divider_[channel]+1) + { + if(poly5_counter_[channel]&1) + { + output_state_[channel] = poly4_counter_[channel]&1; + advance_poly4(channel); + } + advance_poly5(channel); + } + break; + + case 0x7: case 0x9: // 5-bit poly + level = poly5_counter_[channel]&1; + if(divider_counter_[channel] == divider_[channel]+1) + { + divider_counter_[channel] = 0; + advance_poly5(channel); + } + break; + + case 0xf: // 5-bit poly div6 + level = poly5_counter_[channel]&1; + if(divider_counter_[channel] == (divider_[channel]+1)*3) + { + divider_counter_[channel] = 0; + advance_poly5(channel); + } + break; + + case 0x8: // 9-bit poly + level = poly9_counter_[channel]&1; + if(divider_counter_[channel] == divider_[channel]+1) + { + divider_counter_[channel] = 0; + advance_poly9(channel); + } + break; + } + + target[c] += volume_[channel] * 1024 * level; + } + } +} diff --git a/Machines/Atari2600/Speaker.hpp b/Machines/Atari2600/Speaker.hpp new file mode 100644 index 000000000..b5bf42488 --- /dev/null +++ b/Machines/Atari2600/Speaker.hpp @@ -0,0 +1,41 @@ +// +// Speaker.hpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef Atari2600_Speaker_hpp +#define Atari2600_Speaker_hpp + +#include "../../Outputs/Speaker.hpp" + +namespace Atari2600 { + +class Speaker: public ::Outputs::Filter { + public: + Speaker(); + + void set_volume(int channel, uint8_t volume); + void set_divider(int channel, uint8_t divider); + void set_control(int channel, uint8_t control); + + void get_samples(unsigned int number_of_samples, int16_t *target); + + private: + uint8_t volume_[2]; + uint8_t divider_[2]; + uint8_t control_[2]; + + int poly4_counter_[2]; + int poly5_counter_[2]; + int poly9_counter_[2]; + int output_state_[2]; + + int divider_counter_[2]; +}; + +} + +#endif /* Speaker_hpp */ 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]; }; } diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 48617d124..b5cc31670 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -15,28 +15,28 @@ using namespace Commodore::Vic20; Machine::Machine() : - _rom(nullptr), - _is_running_at_zero_cost(false), - _tape(1022727) + rom_(nullptr), + is_running_at_zero_cost_(false), + tape_(1022727) { // create 6522s, serial port and bus - _userPortVIA.reset(new UserPortVIA); - _keyboardVIA.reset(new KeyboardVIA); - _serialPort.reset(new SerialPort); - _serialBus.reset(new ::Commodore::Serial::Bus); + user_port_via_.reset(new UserPortVIA); + keyboard_via_.reset(new KeyboardVIA); + serial_port_.reset(new SerialPort); + serial_bus_.reset(new ::Commodore::Serial::Bus); // wire up the serial bus and serial port - Commodore::Serial::AttachPortAndBus(_serialPort, _serialBus); + Commodore::Serial::AttachPortAndBus(serial_port_, serial_bus_); // wire up 6522s and serial port - _userPortVIA->set_serial_port(_serialPort); - _keyboardVIA->set_serial_port(_serialPort); - _serialPort->set_user_port_via(_userPortVIA); + user_port_via_->set_serial_port(serial_port_); + keyboard_via_->set_serial_port(serial_port_); + serial_port_->set_user_port_via(user_port_via_); // wire up the 6522s, tape and machine - _userPortVIA->set_interrupt_delegate(this); - _keyboardVIA->set_interrupt_delegate(this); - _tape.set_delegate(this); + user_port_via_->set_interrupt_delegate(this); + keyboard_via_->set_interrupt_delegate(this); + tape_.set_delegate(this); // establish the memory maps set_memory_size(MemorySize::Default); @@ -44,44 +44,44 @@ Machine::Machine() : // set the NTSC clock rate set_region(NTSC); // _debugPort.reset(new ::Commodore::Serial::DebugPort); -// _debugPort->set_serial_bus(_serialBus); -// _serialBus->add_port(_debugPort); +// _debugPort->set_serial_bus(serial_bus_); +// serial_bus_->add_port(_debugPort); } void Machine::set_memory_size(MemorySize size) { - memset(_processorReadMemoryMap, 0, sizeof(_processorReadMemoryMap)); - memset(_processorWriteMemoryMap, 0, sizeof(_processorWriteMemoryMap)); + memset(processor_read_memory_map_, 0, sizeof(processor_read_memory_map_)); + memset(processor_write_memory_map_, 0, sizeof(processor_write_memory_map_)); switch(size) { default: break; case ThreeKB: - write_to_map(_processorReadMemoryMap, _expansionRAM, 0x0000, 0x1000); - write_to_map(_processorWriteMemoryMap, _expansionRAM, 0x0000, 0x1000); + write_to_map(processor_read_memory_map_, expansion_ram_, 0x0000, 0x1000); + write_to_map(processor_write_memory_map_, expansion_ram_, 0x0000, 0x1000); break; case ThirtyTwoKB: - write_to_map(_processorReadMemoryMap, _expansionRAM, 0x0000, 0x8000); - write_to_map(_processorWriteMemoryMap, _expansionRAM, 0x0000, 0x8000); + write_to_map(processor_read_memory_map_, expansion_ram_, 0x0000, 0x8000); + write_to_map(processor_write_memory_map_, expansion_ram_, 0x0000, 0x8000); break; } // install the system ROMs and VIC-visible memory - write_to_map(_processorReadMemoryMap, _userBASICMemory, 0x0000, sizeof(_userBASICMemory)); - write_to_map(_processorReadMemoryMap, _screenMemory, 0x1000, sizeof(_screenMemory)); - write_to_map(_processorReadMemoryMap, _colorMemory, 0x9400, sizeof(_colorMemory)); - write_to_map(_processorReadMemoryMap, _characterROM, 0x8000, sizeof(_characterROM)); - write_to_map(_processorReadMemoryMap, _basicROM, 0xc000, sizeof(_basicROM)); - write_to_map(_processorReadMemoryMap, _kernelROM, 0xe000, sizeof(_kernelROM)); + write_to_map(processor_read_memory_map_, user_basic_memory_, 0x0000, sizeof(user_basic_memory_)); + write_to_map(processor_read_memory_map_, screen_memory_, 0x1000, sizeof(screen_memory_)); + write_to_map(processor_read_memory_map_, colour_memory_, 0x9400, sizeof(colour_memory_)); + write_to_map(processor_read_memory_map_, character_rom_, 0x8000, sizeof(character_rom_)); + write_to_map(processor_read_memory_map_, basic_rom_, 0xc000, sizeof(basic_rom_)); + write_to_map(processor_read_memory_map_, kernel_rom_, 0xe000, sizeof(kernel_rom_)); - write_to_map(_processorWriteMemoryMap, _userBASICMemory, 0x0000, sizeof(_userBASICMemory)); - write_to_map(_processorWriteMemoryMap, _screenMemory, 0x1000, sizeof(_screenMemory)); - write_to_map(_processorWriteMemoryMap, _colorMemory, 0x9400, sizeof(_colorMemory)); + write_to_map(processor_write_memory_map_, user_basic_memory_, 0x0000, sizeof(user_basic_memory_)); + write_to_map(processor_write_memory_map_, screen_memory_, 0x1000, sizeof(screen_memory_)); + write_to_map(processor_write_memory_map_, colour_memory_, 0x9400, sizeof(colour_memory_)); // install the inserted ROM if there is one - if(_rom) + if(rom_) { - write_to_map(_processorReadMemoryMap, _rom, _rom_address, _rom_length); + write_to_map(processor_read_memory_map_, rom_, rom_address_, rom_length_); } } @@ -99,7 +99,7 @@ void Machine::write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint1 Machine::~Machine() { - delete[] _rom; + delete[] rom_; } unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) @@ -117,17 +117,17 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // } // run the phase-1 part of this cycle, in which the VIC accesses memory - if(!_is_running_at_zero_cost) _mos6560->run_for_cycles(1); + if(!is_running_at_zero_cost_) mos6560_->run_for_cycles(1); // run the phase-2 part of the cycle, which is whatever the 6502 said it should be if(isReadOperation(operation)) { - uint8_t result = _processorReadMemoryMap[address >> 10] ? _processorReadMemoryMap[address >> 10][address & 0x3ff] : 0xff; + uint8_t result = processor_read_memory_map_[address >> 10] ? processor_read_memory_map_[address >> 10][address & 0x3ff] : 0xff; if((address&0xfc00) == 0x9000) { - if((address&0xff00) == 0x9000) result &= _mos6560->get_register(address); - if((address&0xfc10) == 0x9010) result &= _userPortVIA->get_register(address); - if((address&0xfc20) == 0x9020) result &= _keyboardVIA->get_register(address); + if((address&0xff00) == 0x9000) result &= mos6560_->get_register(address); + if((address&0xfc10) == 0x9010) result &= user_port_via_->get_register(address); + if((address&0xfc20) == 0x9020) result &= keyboard_via_->get_register(address); } *value = result; @@ -135,40 +135,40 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // PC hits the start of the loop that just waits for an interesting tape interrupt to have // occurred then skip both 6522s and the tape ahead to the next interrupt without any further // CPU or 6560 costs. - if(_use_fast_tape_hack && _tape.has_tape() && address == 0xf92f && operation == CPU6502::BusOperation::ReadOpcode) + if(use_fast_tape_hack_ && tape_.has_tape() && address == 0xf92f && operation == CPU6502::BusOperation::ReadOpcode) { - while(!_userPortVIA->get_interrupt_line() && !_keyboardVIA->get_interrupt_line() && !_tape.get_tape()->is_at_end()) + while(!user_port_via_->get_interrupt_line() && !keyboard_via_->get_interrupt_line() && !tape_.get_tape()->is_at_end()) { - _userPortVIA->run_for_cycles(1); - _keyboardVIA->run_for_cycles(1); - _tape.run_for_cycles(1); + user_port_via_->run_for_cycles(1); + keyboard_via_->run_for_cycles(1); + tape_.run_for_cycles(1); } } } else { - uint8_t *ram = _processorWriteMemoryMap[address >> 10]; + uint8_t *ram = processor_write_memory_map_[address >> 10]; if(ram) ram[address & 0x3ff] = *value; if((address&0xfc00) == 0x9000) { - if((address&0xff00) == 0x9000) _mos6560->set_register(address, *value); - if((address&0xfc10) == 0x9010) _userPortVIA->set_register(address, *value); - if((address&0xfc20) == 0x9020) _keyboardVIA->set_register(address, *value); + if((address&0xff00) == 0x9000) mos6560_->set_register(address, *value); + if((address&0xfc10) == 0x9010) user_port_via_->set_register(address, *value); + if((address&0xfc20) == 0x9020) keyboard_via_->set_register(address, *value); } } - _userPortVIA->run_for_cycles(1); - _keyboardVIA->run_for_cycles(1); - if(_typer && operation == CPU6502::BusOperation::ReadOpcode && address == 0xEB1E) + user_port_via_->run_for_cycles(1); + keyboard_via_->run_for_cycles(1); + if(typer_ && operation == CPU6502::BusOperation::ReadOpcode && address == 0xEB1E) { - if(!_typer->type_next_character()) + if(!typer_->type_next_character()) { clear_all_keys(); - _typer.reset(); + typer_.reset(); } } - _tape.run_for_cycles(1); - if(_c1540) _c1540->run_for_cycles(1); + tape_.run_for_cycles(1); + if(c1540_) c1540_->run_for_cycles(1); // If using fast tape then: // if the PC hits 0xf98e, the ROM's tape loading routine, then begin zero cost processing; @@ -181,19 +181,19 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // Note the additional test above for PC hitting 0xf92f, which is a loop in the ROM that waits // for an interesting interrupt. Up there the fast tape hack goes even further in also cutting // the CPU out of the action. - if(_use_fast_tape_hack && _tape.has_tape()) + if(use_fast_tape_hack_ && tape_.has_tape()) { if(address == 0xf98e && operation == CPU6502::BusOperation::ReadOpcode) { - _is_running_at_zero_cost = true; + is_running_at_zero_cost_ = true; set_clock_is_unlimited(true); } if( (address < 0xe000 && operation == CPU6502::BusOperation::ReadOpcode) || - _tape.get_tape()->is_at_end() + tape_.get_tape()->is_at_end() ) { - _is_running_at_zero_cost = false; + is_running_at_zero_cost_ = false; set_clock_is_unlimited(false); } } @@ -205,31 +205,31 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin void Machine::mos6522_did_change_interrupt_status(void *mos6522) { - set_nmi_line(_userPortVIA->get_interrupt_line()); - set_irq_line(_keyboardVIA->get_interrupt_line()); + set_nmi_line(user_port_via_->get_interrupt_line()); + set_irq_line(keyboard_via_->get_interrupt_line()); } #pragma mark - Setup void Machine::set_region(Commodore::Vic20::Region region) { - _region = region; + region_ = region; switch(region) { case PAL: set_clock_rate(1108404); - if(_mos6560) + if(mos6560_) { - _mos6560->set_output_mode(MOS::MOS6560::OutputMode::PAL); - _mos6560->set_clock_rate(1108404); + mos6560_->set_output_mode(MOS::MOS6560::OutputMode::PAL); + mos6560_->set_clock_rate(1108404); } break; case NTSC: set_clock_rate(1022727); - if(_mos6560) + if(mos6560_) { - _mos6560->set_output_mode(MOS::MOS6560::OutputMode::NTSC); - _mos6560->set_clock_rate(1022727); + mos6560_->set_output_mode(MOS::MOS6560::OutputMode::NTSC); + mos6560_->set_clock_rate(1022727); } break; } @@ -237,20 +237,20 @@ void Machine::set_region(Commodore::Vic20::Region region) void Machine::setup_output(float aspect_ratio) { - _mos6560.reset(new Vic6560()); - _mos6560->get_speaker()->set_high_frequency_cut_off(1600); // There is a 1.6Khz low-pass filter in the Vic-20. - set_region(_region); + mos6560_.reset(new Vic6560()); + mos6560_->get_speaker()->set_high_frequency_cut_off(1600); // There is a 1.6Khz low-pass filter in the Vic-20. + set_region(region_); - memset(_mos6560->_videoMemoryMap, 0, sizeof(_mos6560->_videoMemoryMap)); - write_to_map(_mos6560->_videoMemoryMap, _characterROM, 0x0000, sizeof(_characterROM)); - write_to_map(_mos6560->_videoMemoryMap, _userBASICMemory, 0x2000, sizeof(_userBASICMemory)); - write_to_map(_mos6560->_videoMemoryMap, _screenMemory, 0x3000, sizeof(_screenMemory)); - _mos6560->_colorMemory = _colorMemory; + memset(mos6560_->video_memory_map, 0, sizeof(mos6560_->video_memory_map)); + write_to_map(mos6560_->video_memory_map, character_rom_, 0x0000, sizeof(character_rom_)); + write_to_map(mos6560_->video_memory_map, user_basic_memory_, 0x2000, sizeof(user_basic_memory_)); + write_to_map(mos6560_->video_memory_map, screen_memory_, 0x3000, sizeof(screen_memory_)); + mos6560_->colour_memory = colour_memory_; } void Machine::close_output() { - _mos6560 = nullptr; + mos6560_ = nullptr; } void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) @@ -259,12 +259,12 @@ void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) size_t max_length = 0x2000; switch(slot) { - case Kernel: target = _kernelROM; break; - case Characters: target = _characterROM; max_length = 0x1000; break; - case BASIC: target = _basicROM; break; + case Kernel: target = kernel_rom_; break; + case Characters: target = character_rom_; max_length = 0x1000; break; + case BASIC: target = basic_rom_; break; case Drive: - _driveROM.reset(new uint8_t[length]); - memcpy(_driveROM.get(), data, length); + drive_rom_.reset(new uint8_t[length]); + memcpy(drive_rom_.get(), data, length); install_disk_rom(); return; } @@ -288,7 +288,7 @@ void Machine::set_rom(ROMSlot slot, size_t length, const uint8_t *data) // { // _rom = new uint8_t[0x2000]; // memcpy(_rom, &data[2], length - 2); -// write_to_map(_processorReadMemoryMap, _rom, _rom_address, 0x2000); +// write_to_map(processor_read_memory_map_, _rom, _rom_address, 0x2000); // } // else // { @@ -303,19 +303,19 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) { if(target.tapes.size()) { - _tape.set_tape(target.tapes.front()); + tape_.set_tape(target.tapes.front()); } if(target.disks.size()) { // construct the 1540 - _c1540.reset(new ::Commodore::C1540::Machine); + c1540_.reset(new ::Commodore::C1540::Machine); // attach it to the serial bus - _c1540->set_serial_bus(_serialBus); + c1540_->set_serial_bus(serial_bus_); // hand it the disk - _c1540->set_disk(target.disks.front()); + c1540_->set_disk(target.disks.front()); // install the ROM if it was previously set install_disk_rom(); @@ -323,16 +323,16 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) if(target.cartridges.size()) { - _rom_address = 0xa000; + rom_address_ = 0xa000; std::vector rom_image = target.cartridges.front()->get_segments().front().data; - _rom_length = (uint16_t)(rom_image.size()); + rom_length_ = (uint16_t)(rom_image.size()); - _rom = new uint8_t[0x2000]; - memcpy(_rom, rom_image.data(), rom_image.size()); - write_to_map(_processorReadMemoryMap, _rom, _rom_address, 0x2000); + rom_ = new uint8_t[0x2000]; + memcpy(rom_, rom_image.data(), rom_image.size()); + write_to_map(processor_read_memory_map_, rom_, rom_address_, 0x2000); } - if(_should_automatically_load_media) + if(should_automatically_load_media_) { if(target.loadingCommand.length()) // TODO: and automatic loading option enabled { @@ -356,18 +356,18 @@ void Machine::configure_as_target(const StaticAnalyser::Target &target) void Machine::tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape) { - _keyboardVIA->set_control_line_input(KeyboardVIA::Port::A, KeyboardVIA::Line::One, tape->get_input()); + keyboard_via_->set_control_line_input(KeyboardVIA::Port::A, KeyboardVIA::Line::One, tape->get_input()); } #pragma mark - Disc void Machine::install_disk_rom() { - if(_driveROM && _c1540) + if(drive_rom_ && c1540_) { - _c1540->set_rom(_driveROM.get()); - _c1540->run_for_cycles(2000000); - _driveROM.reset(); + c1540_->set_rom(drive_rom_.get()); + c1540_->run_for_cycles(2000000); + drive_rom_.reset(); } } @@ -377,7 +377,7 @@ uint8_t UserPortVIA::get_port_input(Port port) { if(!port) { - return _portA; // TODO: bit 6 should be high if there is no tape, low otherwise + return port_a_; // TODO: bit 6 should be high if there is no tape, low otherwise } return 0xff; } @@ -394,8 +394,8 @@ void UserPortVIA::set_serial_line_state(::Commodore::Serial::Line line, bool val switch(line) { default: break; - case ::Commodore::Serial::Line::Data: _portA = (_portA & ~0x02) | (value ? 0x02 : 0x00); break; - case ::Commodore::Serial::Line::Clock: _portA = (_portA & ~0x01) | (value ? 0x01 : 0x00); break; + case ::Commodore::Serial::Line::Data: port_a_ = (port_a_ & ~0x02) | (value ? 0x02 : 0x00); break; + case ::Commodore::Serial::Line::Clock: port_a_ = (port_a_ & ~0x01) | (value ? 0x01 : 0x00); break; } } @@ -403,7 +403,7 @@ void UserPortVIA::set_joystick_state(JoystickInput input, bool value) { if(input != JoystickInput::Right) { - _portA = (_portA & ~input) | (value ? 0 : input); + port_a_ = (port_a_ & ~input) | (value ? 0 : input); } } @@ -412,22 +412,22 @@ void UserPortVIA::set_port_output(Port port, uint8_t value, uint8_t mask) // Line 7 of port A is inverted and output as serial ATN if(!port) { - std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); + std::shared_ptr<::Commodore::Serial::Port> serialPort = serial_port_.lock(); if(serialPort) serialPort->set_output(::Commodore::Serial::Line::Attention, (::Commodore::Serial::LineLevel)!(value&0x80)); } } -UserPortVIA::UserPortVIA() : _portA(0xbf) {} +UserPortVIA::UserPortVIA() : port_a_(0xbf) {} void UserPortVIA::set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort) { - _serialPort = serialPort; + serial_port_ = serialPort; } #pragma mark - KeyboardVIA -KeyboardVIA::KeyboardVIA() : _portB(0xff) +KeyboardVIA::KeyboardVIA() : port_b_(0xff) { clear_all_keys(); } @@ -435,14 +435,14 @@ KeyboardVIA::KeyboardVIA() : _portB(0xff) void KeyboardVIA::set_key_state(uint16_t key, bool isPressed) { if(isPressed) - _columns[key & 7] &= ~(key >> 3); + columns_[key & 7] &= ~(key >> 3); else - _columns[key & 7] |= (key >> 3); + columns_[key & 7] |= (key >> 3); } void KeyboardVIA::clear_all_keys() { - memset(_columns, 0xff, sizeof(_columns)); + memset(columns_, 0xff, sizeof(columns_)); } uint8_t KeyboardVIA::get_port_input(Port port) @@ -452,26 +452,26 @@ uint8_t KeyboardVIA::get_port_input(Port port) uint8_t result = 0xff; for(int c = 0; c < 8; c++) { - if(!(_activation_mask&(1 << c))) - result &= _columns[c]; + if(!(activation_mask_&(1 << c))) + result &= columns_[c]; } return result; } - return _portB; + return port_b_; } void KeyboardVIA::set_port_output(Port port, uint8_t value, uint8_t mask) { if(port) - _activation_mask = (value & mask) | (~mask); + activation_mask_ = (value & mask) | (~mask); } void KeyboardVIA::set_control_line_output(Port port, Line line, bool value) { if(line == Line::Two) { - std::shared_ptr<::Commodore::Serial::Port> serialPort = _serialPort.lock(); + std::shared_ptr<::Commodore::Serial::Port> serialPort = serial_port_.lock(); if(serialPort) { // CB2 is inverted to become serial data; CA2 is inverted to become serial clock @@ -487,24 +487,24 @@ void KeyboardVIA::set_joystick_state(JoystickInput input, bool value) { if(input == JoystickInput::Right) { - _portB = (_portB & ~input) | (value ? 0 : input); + port_b_ = (port_b_ & ~input) | (value ? 0 : input); } } void KeyboardVIA::set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort) { - _serialPort = serialPort; + serial_port_ = serialPort; } #pragma mark - SerialPort void SerialPort::set_input(::Commodore::Serial::Line line, ::Commodore::Serial::LineLevel level) { - std::shared_ptr userPortVIA = _userPortVIA.lock(); + std::shared_ptr userPortVIA = user_port_via_.lock(); if(userPortVIA) userPortVIA->set_serial_line_state(line, (bool)level); } void SerialPort::set_user_port_via(std::shared_ptr userPortVIA) { - _userPortVIA = userPortVIA; + user_port_via_ = userPortVIA; } diff --git a/Machines/Commodore/Vic-20/Vic20.hpp b/Machines/Commodore/Vic-20/Vic20.hpp index 61d3c62e7..a0fb69bc9 100644 --- a/Machines/Commodore/Vic-20/Vic20.hpp +++ b/Machines/Commodore/Vic-20/Vic20.hpp @@ -89,8 +89,8 @@ class UserPortVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort); private: - uint8_t _portA; - std::weak_ptr<::Commodore::Serial::Port> _serialPort; + uint8_t port_a_; + std::weak_ptr<::Commodore::Serial::Port> serial_port_; }; class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { @@ -112,10 +112,10 @@ class KeyboardVIA: public MOS::MOS6522, public MOS::MOS6522IRQDeleg void set_serial_port(std::shared_ptr<::Commodore::Serial::Port> serialPort); private: - uint8_t _portB; - uint8_t _columns[8]; - uint8_t _activation_mask; - std::weak_ptr<::Commodore::Serial::Port> _serialPort; + uint8_t port_b_; + uint8_t columns_[8]; + uint8_t activation_mask_; + std::weak_ptr<::Commodore::Serial::Port> serial_port_; }; class SerialPort : public ::Commodore::Serial::Port { @@ -124,19 +124,19 @@ class SerialPort : public ::Commodore::Serial::Port { void set_user_port_via(std::shared_ptr userPortVIA); private: - std::weak_ptr _userPortVIA; + std::weak_ptr user_port_via_; }; class Vic6560: public MOS::MOS6560 { public: inline void perform_read(uint16_t address, uint8_t *pixel_data, uint8_t *colour_data) { - *pixel_data = _videoMemoryMap[address >> 10] ? _videoMemoryMap[address >> 10][address & 0x3ff] : 0xff; // TODO - *colour_data = _colorMemory[address & 0x03ff]; + *pixel_data = video_memory_map[address >> 10] ? video_memory_map[address >> 10][address & 0x3ff] : 0xff; // TODO + *colour_data = colour_memory[address & 0x03ff]; } - uint8_t *_videoMemoryMap[16]; - uint8_t *_colorMemory; + uint8_t *video_memory_map[16]; + uint8_t *colour_memory; }; class Machine: @@ -153,34 +153,30 @@ class Machine: void set_rom(ROMSlot slot, size_t length, const uint8_t *data); void configure_as_target(const StaticAnalyser::Target &target); -// void set_prg(const char *file_name, size_t length, const uint8_t *data); -// void set_tape(std::shared_ptr tape); -// void set_disk(std::shared_ptr disk); - void set_key_state(uint16_t key, bool isPressed) { _keyboardVIA->set_key_state(key, isPressed); } - void clear_all_keys() { _keyboardVIA->clear_all_keys(); } + void set_key_state(uint16_t key, bool isPressed) { keyboard_via_->set_key_state(key, isPressed); } + void clear_all_keys() { keyboard_via_->clear_all_keys(); } void set_joystick_state(JoystickInput input, bool isPressed) { - _userPortVIA->set_joystick_state(input, isPressed); - _keyboardVIA->set_joystick_state(input, isPressed); + user_port_via_->set_joystick_state(input, isPressed); + keyboard_via_->set_joystick_state(input, isPressed); } void set_memory_size(MemorySize size); void set_region(Region region); - inline void set_use_fast_tape_hack(bool activate) { _use_fast_tape_hack = activate; } - inline void set_should_automatically_load_media(bool activate) { _should_automatically_load_media = activate; } + inline void set_use_fast_tape_hack(bool activate) { use_fast_tape_hack_ = activate; } + inline void set_should_automatically_load_media(bool activate) { should_automatically_load_media_ = activate; } // to satisfy CPU6502::Processor unsigned int perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value); - void synchronise() { _mos6560->synchronise(); } + void synchronise() { mos6560_->synchronise(); } // to satisfy CRTMachine::Machine virtual void setup_output(float aspect_ratio); virtual void close_output(); - virtual std::shared_ptr get_crt() { return _mos6560->get_crt(); } - virtual std::shared_ptr get_speaker() { return _mos6560->get_speaker(); } + virtual std::shared_ptr get_crt() { return mos6560_->get_crt(); } + virtual std::shared_ptr get_speaker() { return mos6560_->get_speaker(); } virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); } - // TODO: or 1108405 for PAL; see http://www.antimon.org/dl/c64/code/stable.txt // to satisfy MOS::MOS6522::Delegate virtual void mos6522_did_change_interrupt_status(void *mos6522); @@ -192,40 +188,38 @@ class Machine: virtual void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape); private: - uint8_t _characterROM[0x1000]; - uint8_t _basicROM[0x2000]; - uint8_t _kernelROM[0x2000]; - uint8_t _expansionRAM[0x8000]; + uint8_t character_rom_[0x1000]; + uint8_t basic_rom_[0x2000]; + uint8_t kernel_rom_[0x2000]; + uint8_t expansion_ram_[0x8000]; - uint8_t *_rom; - uint16_t _rom_address, _rom_length; + uint8_t *rom_; + uint16_t rom_address_, rom_length_; - uint8_t _userBASICMemory[0x0400]; - uint8_t _screenMemory[0x1000]; - uint8_t _colorMemory[0x0400]; - uint8_t _junkMemory[0x0400]; - std::unique_ptr _driveROM; + uint8_t user_basic_memory_[0x0400]; + uint8_t screen_memory_[0x1000]; + uint8_t colour_memory_[0x0400]; + std::unique_ptr drive_rom_; - uint8_t *_processorReadMemoryMap[64]; - uint8_t *_processorWriteMemoryMap[64]; + uint8_t *processor_read_memory_map_[64]; + uint8_t *processor_write_memory_map_[64]; void write_to_map(uint8_t **map, uint8_t *area, uint16_t address, uint16_t length); - Region _region; + Region region_; - std::unique_ptr _mos6560; - std::shared_ptr _userPortVIA; - std::shared_ptr _keyboardVIA; - std::shared_ptr _serialPort; - std::shared_ptr<::Commodore::Serial::Bus> _serialBus; -// std::shared_ptr<::Commodore::Serial::DebugPort> _debugPort; + std::unique_ptr mos6560_; + std::shared_ptr user_port_via_; + std::shared_ptr keyboard_via_; + std::shared_ptr serial_port_; + std::shared_ptr<::Commodore::Serial::Bus> serial_bus_; // Tape - Storage::Tape::BinaryTapePlayer _tape; - bool _use_fast_tape_hack, _should_automatically_load_media; - bool _is_running_at_zero_cost; + Storage::Tape::BinaryTapePlayer tape_; + bool use_fast_tape_hack_, should_automatically_load_media_; + bool is_running_at_zero_cost_; // Disk - std::shared_ptr<::Commodore::C1540::Machine> _c1540; + std::shared_ptr<::Commodore::C1540::Machine> c1540_; void install_disk_rom(); // Autoload string diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 636c3faab..aee65f36d 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -31,38 +31,35 @@ namespace { static const unsigned int real_time_clock_interrupt_1 = 16704; static const unsigned int real_time_clock_interrupt_2 = 56704; - - static const unsigned int clock_rate_audio_divider = 8; } #define graphics_line(v) ((((v) >> 7) - first_graphics_line + field_divider_line) % field_divider_line) #define graphics_column(v) ((((v) & 127) - first_graphics_cycle + 128) & 127) Machine::Machine() : - _interrupt_control(0), - _interrupt_status(Interrupt::PowerOnReset | Interrupt::TransmitDataEmpty | 0x80), - _frameCycles(0), - _displayOutputPosition(0), - _audioOutputPosition(0), - _current_pixel_line(-1), - _use_fast_tape_hack(false), - _crt(nullptr), - _phase(0) + interrupt_control_(0), + interrupt_status_(Interrupt::PowerOnReset | Interrupt::TransmitDataEmpty | 0x80), + frame_cycles_(0), + display_output_position_(0), + audio_output_position_(0), + current_pixel_line_(-1), + use_fast_tape_hack_(false), + phase_(0) { - memset(_key_states, 0, sizeof(_key_states)); - memset(_palette, 0xf, sizeof(_palette)); + memset(key_states_, 0, sizeof(key_states_)); + memset(palette_, 0xf, sizeof(palette_)); for(int c = 0; c < 16; c++) - memset(_roms[c], 0xff, 16384); + memset(roms_[c], 0xff, 16384); - _tape.set_delegate(this); + tape_.set_delegate(this); set_clock_rate(2000000); } void Machine::setup_output(float aspect_ratio) { - _speaker.reset(new Speaker); - _crt.reset(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1)); - _crt->set_rgb_sampling_function( + speaker_.reset(new Speaker); + crt_.reset(new Outputs::CRT::CRT(crt_cycles_per_line, 8, Outputs::CRT::DisplayType::PAL50, 1)); + crt_->set_rgb_sampling_function( "vec3 rgb_sample(usampler2D sampler, vec2 coordinate, vec2 icoordinate)" "{" "uint texValue = texture(sampler, coordinate).r;" @@ -71,17 +68,17 @@ void Machine::setup_output(float aspect_ratio) "}"); // TODO: as implied below, I've introduced a clock's latency into the graphics pipeline somehow. Investigate. - _crt->set_visible_area(_crt->get_rect_for_area(first_graphics_line - 3, 256, (first_graphics_cycle+1) * crt_cycles_multiplier, 80 * crt_cycles_multiplier, 4.0f / 3.0f)); + crt_->set_visible_area(crt_->get_rect_for_area(first_graphics_line - 3, 256, (first_graphics_cycle+1) * crt_cycles_multiplier, 80 * crt_cycles_multiplier, 4.0f / 3.0f)); // The maximum output frequency is 62500Hz and all other permitted output frequencies are integral divisions of that; // however setting the speaker on or off can happen on any 2Mhz cycle, and probably (?) takes effect immediately. So // run the speaker at a 2000000Hz input rate, at least for the time being. - _speaker->set_input_rate(2000000 / clock_rate_audio_divider); + speaker_->set_input_rate(2000000 / Speaker::clock_rate_divider); } void Machine::close_output() { - _crt = nullptr; + crt_ = nullptr; } unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) @@ -92,29 +89,29 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin { if(isReadOperation(operation)) { - *value = _ram[address]; + *value = ram_[address]; } else { if( ( - ((_frameCycles >= first_graphics_line * cycles_per_line) && (_frameCycles < (first_graphics_line + 256) * cycles_per_line)) || - ((_frameCycles >= (first_graphics_line + field_divider_line) * cycles_per_line) && (_frameCycles < (first_graphics_line + 256 + field_divider_line) * cycles_per_line)) + ((frame_cycles_ >= first_graphics_line * cycles_per_line) && (frame_cycles_ < (first_graphics_line + 256) * cycles_per_line)) || + ((frame_cycles_ >= (first_graphics_line + field_divider_line) * cycles_per_line) && (frame_cycles_ < (first_graphics_line + 256 + field_divider_line) * cycles_per_line)) ) ) update_display(); - _ram[address] = *value; + ram_[address] = *value; } // for the entire frame, RAM is accessible only on odd cycles; in modes below 4 // it's also accessible only outside of the pixel regions - cycles += 1 + (_frameCycles&1); - if(_screen_mode < 4) + cycles += 1 + (frame_cycles_&1); + if(screen_mode_ < 4) { - const int current_line = graphics_line(_frameCycles + (_frameCycles&1)); - const int current_column = graphics_column(_frameCycles + (_frameCycles&1)); - if(current_line < 256 && current_column < 80 && !_isBlankLine) + const int current_line = graphics_line(frame_cycles_ + (frame_cycles_&1)); + const int current_column = graphics_column(frame_cycles_ + (frame_cycles_&1)); + if(current_line < 256 && current_column < 80 && !is_blank_line_) cycles += (unsigned int)(80 - current_column); } } @@ -129,39 +126,39 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin case 0xfe00: if(isReadOperation(operation)) { - *value = _interrupt_status; - _interrupt_status &= ~PowerOnReset; + *value = interrupt_status_; + interrupt_status_ &= ~PowerOnReset; } else { - _interrupt_control = (*value) & ~1; + interrupt_control_ = (*value) & ~1; evaluate_interrupts(); } break; case 0xfe02: if(!isReadOperation(operation)) { - _startScreenAddress = (_startScreenAddress & 0xfe00) | (uint16_t)(((*value) & 0xe0) << 1); - if(!_startScreenAddress) _startScreenAddress |= 0x8000; + start_screen_address_ = (start_screen_address_ & 0xfe00) | (uint16_t)(((*value) & 0xe0) << 1); + if(!start_screen_address_) start_screen_address_ |= 0x8000; } break; case 0xfe03: if(!isReadOperation(operation)) { - _startScreenAddress = (_startScreenAddress & 0x01ff) | (uint16_t)(((*value) & 0x3f) << 9); - if(!_startScreenAddress) _startScreenAddress |= 0x8000; + start_screen_address_ = (start_screen_address_ & 0x01ff) | (uint16_t)(((*value) & 0x3f) << 9); + if(!start_screen_address_) start_screen_address_ |= 0x8000; } break; case 0xfe04: if(isReadOperation(operation)) { - *value = _tape.get_data_register(); - _tape.clear_interrupts(Interrupt::ReceiveDataFull); + *value = tape_.get_data_register(); + tape_.clear_interrupts(Interrupt::ReceiveDataFull); } else { - _tape.set_data_register(*value); - _tape.clear_interrupts(Interrupt::TransmitDataEmpty); + tape_.set_data_register(*value); + tape_.clear_interrupts(Interrupt::TransmitDataEmpty); } break; case 0xfe05: @@ -170,29 +167,29 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin const uint8_t interruptDisable = (*value)&0xf0; if( interruptDisable ) { - if( interruptDisable&0x10 ) _interrupt_status &= ~Interrupt::DisplayEnd; - if( interruptDisable&0x20 ) _interrupt_status &= ~Interrupt::RealTimeClock; - if( interruptDisable&0x40 ) _interrupt_status &= ~Interrupt::HighToneDetect; + if( interruptDisable&0x10 ) interrupt_status_ &= ~Interrupt::DisplayEnd; + if( interruptDisable&0x20 ) interrupt_status_ &= ~Interrupt::RealTimeClock; + if( interruptDisable&0x40 ) interrupt_status_ &= ~Interrupt::HighToneDetect; evaluate_interrupts(); // TODO: NMI } // latch the paged ROM in case external hardware is being emulated - _active_rom = (Electron::ROMSlot)(*value & 0xf); + active_rom_ = (Electron::ROMSlot)(*value & 0xf); // apply the ULA's test if(*value & 0x08) { if(*value & 0x04) { - _keyboard_is_active = false; - _basic_is_active = false; + keyboard_is_active_ = false; + basic_is_active_ = false; } else { - _keyboard_is_active = !(*value & 0x02); - _basic_is_active = !_keyboard_is_active; + keyboard_is_active_ = !(*value & 0x02); + basic_is_active_ = !keyboard_is_active_; } } } @@ -201,8 +198,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin if(!isReadOperation(operation)) { update_audio(); - _speaker->set_divider(*value); - _tape.set_counter(*value); + speaker_->set_divider(*value); + tape_.set_counter(*value); } break; case 0xfe07: @@ -211,16 +208,16 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // update screen mode uint8_t new_screen_mode = ((*value) >> 3)&7; if(new_screen_mode == 7) new_screen_mode = 4; - if(new_screen_mode != _screen_mode) + if(new_screen_mode != screen_mode_) { update_display(); - _screen_mode = new_screen_mode; - switch(_screen_mode) + screen_mode_ = new_screen_mode; + switch(screen_mode_) { - case 0: case 1: case 2: _screenModeBaseAddress = 0x3000; break; - case 3: _screenModeBaseAddress = 0x4000; break; - case 4: case 5: _screenModeBaseAddress = 0x5800; break; - case 6: _screenModeBaseAddress = 0x6000; break; + case 0: case 1: case 2: screen_mode_base_address_ = 0x3000; break; + case 3: screen_mode_base_address_ = 0x4000; break; + case 4: case 5: screen_mode_base_address_ = 0x5800; break; + case 6: screen_mode_base_address_ = 0x6000; break; } } @@ -229,13 +226,13 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin if(new_speaker_is_enabled != speaker_is_enabled_) { update_audio(); - _speaker->set_is_enabled(new_speaker_is_enabled); + speaker_->set_is_enabled(new_speaker_is_enabled); speaker_is_enabled_ = new_speaker_is_enabled; } - _tape.set_is_enabled((*value & 6) != 6); - _tape.set_is_in_input_mode((*value & 6) == 0); - _tape.set_is_running(((*value)&0x40) ? true : false); + tape_.set_is_enabled((*value & 6) != 6); + tape_.set_is_in_input_mode((*value & 6) == 0); + tape_.set_is_running(((*value)&0x40) ? true : false); // TODO: caps lock LED } @@ -256,46 +253,46 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin const uint8_t colour = ~(*value); if(address&1) { - _palette[registers[index][0]] = (_palette[registers[index][0]]&3) | ((colour >> 1)&4); - _palette[registers[index][1]] = (_palette[registers[index][1]]&3) | ((colour >> 0)&4); - _palette[registers[index][2]] = (_palette[registers[index][2]]&3) | ((colour << 1)&4); - _palette[registers[index][3]] = (_palette[registers[index][3]]&3) | ((colour << 2)&4); + palette_[registers[index][0]] = (palette_[registers[index][0]]&3) | ((colour >> 1)&4); + palette_[registers[index][1]] = (palette_[registers[index][1]]&3) | ((colour >> 0)&4); + palette_[registers[index][2]] = (palette_[registers[index][2]]&3) | ((colour << 1)&4); + palette_[registers[index][3]] = (palette_[registers[index][3]]&3) | ((colour << 2)&4); - _palette[registers[index][2]] = (_palette[registers[index][2]]&5) | ((colour >> 4)&2); - _palette[registers[index][3]] = (_palette[registers[index][3]]&5) | ((colour >> 3)&2); + palette_[registers[index][2]] = (palette_[registers[index][2]]&5) | ((colour >> 4)&2); + palette_[registers[index][3]] = (palette_[registers[index][3]]&5) | ((colour >> 3)&2); } else { - _palette[registers[index][0]] = (_palette[registers[index][0]]&6) | ((colour >> 7)&1); - _palette[registers[index][1]] = (_palette[registers[index][1]]&6) | ((colour >> 6)&1); - _palette[registers[index][2]] = (_palette[registers[index][2]]&6) | ((colour >> 5)&1); - _palette[registers[index][3]] = (_palette[registers[index][3]]&6) | ((colour >> 4)&1); + palette_[registers[index][0]] = (palette_[registers[index][0]]&6) | ((colour >> 7)&1); + palette_[registers[index][1]] = (palette_[registers[index][1]]&6) | ((colour >> 6)&1); + palette_[registers[index][2]] = (palette_[registers[index][2]]&6) | ((colour >> 5)&1); + palette_[registers[index][3]] = (palette_[registers[index][3]]&6) | ((colour >> 4)&1); - _palette[registers[index][0]] = (_palette[registers[index][0]]&5) | ((colour >> 2)&2); - _palette[registers[index][1]] = (_palette[registers[index][1]]&5) | ((colour >> 1)&2); + palette_[registers[index][0]] = (palette_[registers[index][0]]&5) | ((colour >> 2)&2); + palette_[registers[index][1]] = (palette_[registers[index][1]]&5) | ((colour >> 1)&2); } // regenerate all palette tables for now #define pack(a, b) (uint8_t)((a << 4) | (b)) for(int byte = 0; byte < 256; byte++) { - uint8_t *target = (uint8_t *)&_paletteTables.forty1bpp[byte]; - target[0] = pack(_palette[(byte&0x80) >> 4], _palette[(byte&0x40) >> 3]); - target[1] = pack(_palette[(byte&0x20) >> 2], _palette[(byte&0x10) >> 1]); + uint8_t *target = (uint8_t *)&palette_tables_.forty1bpp[byte]; + target[0] = pack(palette_[(byte&0x80) >> 4], palette_[(byte&0x40) >> 3]); + target[1] = pack(palette_[(byte&0x20) >> 2], palette_[(byte&0x10) >> 1]); - target = (uint8_t *)&_paletteTables.eighty2bpp[byte]; - target[0] = pack(_palette[((byte&0x80) >> 4) | ((byte&0x08) >> 2)], _palette[((byte&0x40) >> 3) | ((byte&0x04) >> 1)]); - target[1] = pack(_palette[((byte&0x20) >> 2) | ((byte&0x02) >> 0)], _palette[((byte&0x10) >> 1) | ((byte&0x01) << 1)]); + target = (uint8_t *)&palette_tables_.eighty2bpp[byte]; + target[0] = pack(palette_[((byte&0x80) >> 4) | ((byte&0x08) >> 2)], palette_[((byte&0x40) >> 3) | ((byte&0x04) >> 1)]); + target[1] = pack(palette_[((byte&0x20) >> 2) | ((byte&0x02) >> 0)], palette_[((byte&0x10) >> 1) | ((byte&0x01) << 1)]); - target = (uint8_t *)&_paletteTables.eighty1bpp[byte]; - target[0] = pack(_palette[(byte&0x80) >> 4], _palette[(byte&0x40) >> 3]); - target[1] = pack(_palette[(byte&0x20) >> 2], _palette[(byte&0x10) >> 1]); - target[2] = pack(_palette[(byte&0x08) >> 0], _palette[(byte&0x04) << 1]); - target[3] = pack(_palette[(byte&0x02) << 2], _palette[(byte&0x01) << 3]); + target = (uint8_t *)&palette_tables_.eighty1bpp[byte]; + target[0] = pack(palette_[(byte&0x80) >> 4], palette_[(byte&0x40) >> 3]); + target[1] = pack(palette_[(byte&0x20) >> 2], palette_[(byte&0x10) >> 1]); + target[2] = pack(palette_[(byte&0x08) >> 0], palette_[(byte&0x04) << 1]); + target[3] = pack(palette_[(byte&0x02) << 2], palette_[(byte&0x01) << 3]); - _paletteTables.forty2bpp[byte] = pack(_palette[((byte&0x80) >> 4) | ((byte&0x08) >> 2)], _palette[((byte&0x40) >> 3) | ((byte&0x04) >> 1)]); - _paletteTables.eighty4bpp[byte] = pack( _palette[((byte&0x80) >> 4) | ((byte&0x20) >> 3) | ((byte&0x08) >> 2) | ((byte&0x02) >> 1)], - _palette[((byte&0x40) >> 3) | ((byte&0x10) >> 2) | ((byte&0x04) >> 1) | ((byte&0x01) >> 0)]); + palette_tables_.forty2bpp[byte] = pack(palette_[((byte&0x80) >> 4) | ((byte&0x08) >> 2)], palette_[((byte&0x40) >> 3) | ((byte&0x04) >> 1)]); + palette_tables_.eighty4bpp[byte] = pack( palette_[((byte&0x80) >> 4) | ((byte&0x20) >> 3) | ((byte&0x08) >> 2) | ((byte&0x02) >> 1)], + palette_[((byte&0x40) >> 3) | ((byte&0x10) >> 2) | ((byte&0x04) >> 1) | ((byte&0x01) >> 0)]); } #undef pack } @@ -303,7 +300,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin break; case 0xfc04: case 0xfc05: case 0xfc06: case 0xfc07: - if(_plus3 && (address&0x00f0) == 0x00c0) + if(plus3_ && (address&0x00f0) == 0x00c0) { if(is_holding_shift_ && address == 0xfcc4) { @@ -311,17 +308,17 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin set_key_state(KeyShift, false); } if(isReadOperation(operation)) - *value = _plus3->get_register(address); + *value = plus3_->get_register(address); else - _plus3->set_register(address, *value); + plus3_->set_register(address, *value); } break; case 0xfc00: - if(_plus3 && (address&0x00f0) == 0x00c0) + if(plus3_ && (address&0x00f0) == 0x00c0) { if(!isReadOperation(operation)) { - _plus3->set_control_register(*value); + plus3_->set_control_register(*value); } else *value = 1; @@ -334,8 +331,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin if(isReadOperation(operation)) { if( - _use_fast_tape_hack && - _tape.has_tape() && + use_fast_tape_hack_ && + tape_.has_tape() && (operation == CPU6502::BusOperation::ReadOpcode) && ( (address == 0xf4e5) || (address == 0xf4e6) || // double NOPs at 0xf4e5, 0xf6de, 0xf6fa and 0xfa51 @@ -357,41 +354,41 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin uint8_t service_call = (uint8_t)get_value_of_register(CPU6502::Register::X); if(address == 0xf0a8) { - if(!_ram[0x247] && service_call == 14) + if(!ram_[0x247] && service_call == 14) { - _tape.set_delegate(nullptr); + tape_.set_delegate(nullptr); // TODO: handle tape wrap around. int cycles_left_while_plausibly_in_data = 50; - _tape.clear_interrupts(Interrupt::ReceiveDataFull); - while(!_tape.get_tape()->is_at_end()) + tape_.clear_interrupts(Interrupt::ReceiveDataFull); + while(!tape_.get_tape()->is_at_end()) { - _tape.run_for_input_pulse(); + tape_.run_for_input_pulse(); cycles_left_while_plausibly_in_data--; - if(!cycles_left_while_plausibly_in_data) _fast_load_is_in_data = false; - if( (_tape.get_interrupt_status() & Interrupt::ReceiveDataFull) && - (_fast_load_is_in_data || _tape.get_data_register() == 0x2a) + if(!cycles_left_while_plausibly_in_data) fast_load_is_in_data_ = false; + if( (tape_.get_interrupt_status() & Interrupt::ReceiveDataFull) && + (fast_load_is_in_data_ || tape_.get_data_register() == 0x2a) ) break; } - _tape.set_delegate(this); - _tape.clear_interrupts(Interrupt::ReceiveDataFull); - _interrupt_status |= _tape.get_interrupt_status(); + tape_.set_delegate(this); + tape_.clear_interrupts(Interrupt::ReceiveDataFull); + interrupt_status_ |= tape_.get_interrupt_status(); - _fast_load_is_in_data = true; + fast_load_is_in_data_ = true; set_value_of_register(CPU6502::Register::A, 0); - set_value_of_register(CPU6502::Register::Y, _tape.get_data_register()); + set_value_of_register(CPU6502::Register::Y, tape_.get_data_register()); *value = 0x60; // 0x60 is RTS } else - *value = _os[address & 16383]; + *value = os_[address & 16383]; } else *value = 0xea; } else { - *value = _os[address & 16383]; + *value = os_[address & 16383]; } } } @@ -399,22 +396,22 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin { if(isReadOperation(operation)) { - *value = _roms[_active_rom][address & 16383]; - if(_keyboard_is_active) + *value = roms_[active_rom_][address & 16383]; + if(keyboard_is_active_) { *value &= 0xf0; for(int address_line = 0; address_line < 14; address_line++) { - if(!(address&(1 << address_line))) *value |= _key_states[address_line]; + if(!(address&(1 << address_line))) *value |= key_states_[address_line]; } } - if(_basic_is_active) + if(basic_is_active_) { - *value &= _roms[ROMSlotBASIC][address & 16383]; + *value &= roms_[ROMSlotBASIC][address & 16383]; } - } else if(_rom_write_masks[_active_rom]) + } else if(rom_write_masks_[active_rom_]) { - _roms[_active_rom][address & 16383] = *value; + roms_[active_rom_][address & 16383] = *value; } } break; @@ -427,9 +424,9 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // } // const int end_of_field = -// if(_frameCycles < (256 + first_graphics_line) << 7)) +// if(frame_cycles_ < (256 + first_graphics_line) << 7)) - const unsigned int pixel_line_clock = _frameCycles;// + 128 - first_graphics_cycle + 80; + const unsigned int pixel_line_clock = frame_cycles_;// + 128 - first_graphics_cycle + 80; const unsigned int line_before_cycle = graphics_line(pixel_line_clock); const unsigned int line_after_cycle = graphics_line(pixel_line_clock + cycles); @@ -453,30 +450,30 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin signal_interrupt(Interrupt::RealTimeClock); } - _frameCycles += cycles; + frame_cycles_ += cycles; - if(!(_frameCycles&127)) _phase += 64; + if(!(frame_cycles_&127)) phase_ += 64; // deal with frame wraparound by updating the two dependent subsystems // as though the exact end of frame had been hit, then reset those // and allow the frame cycle counter to assume its real value - if(_frameCycles >= cycles_per_frame) + if(frame_cycles_ >= cycles_per_frame) { - unsigned int nextFrameCycles = _frameCycles - cycles_per_frame; - _frameCycles = cycles_per_frame; + unsigned int nextFrameCycles = frame_cycles_ - cycles_per_frame; + frame_cycles_ = cycles_per_frame; update_display(); update_audio(); - _displayOutputPosition = 0; - _audioOutputPosition = 0; - _frameCycles = nextFrameCycles; + display_output_position_ = 0; + audio_output_position_ = 0; + frame_cycles_ = nextFrameCycles; } - if(!(_frameCycles&16383)) + if(!(frame_cycles_&16383)) update_audio(); - _tape.run_for_cycles(cycles); + tape_.run_for_cycles(cycles); - if(_typer) _typer->update((int)cycles); - if(_plus3) _plus3->run_for_cycles(4*cycles); + if(typer_) typer_->update((int)cycles); + if(plus3_) plus3_->run_for_cycles(4*cycles); return cycles; } @@ -485,31 +482,31 @@ void Machine::synchronise() { update_display(); update_audio(); - _speaker->flush(); + speaker_->flush(); } void Machine::configure_as_target(const StaticAnalyser::Target &target) { if(target.tapes.size()) { - _tape.set_tape(target.tapes.front()); + tape_.set_tape(target.tapes.front()); } if(target.disks.size()) { - _plus3.reset(new Plus3); + plus3_.reset(new Plus3); if(target.acorn.has_dfs) { - set_rom(ROMSlot0, _dfs, true); + set_rom(ROMSlot0, dfs_, true); } if(target.acorn.has_adfs) { - set_rom(ROMSlot4, _adfs, true); - set_rom(ROMSlot5, std::vector(_adfs.begin() + 16384, _adfs.end()), true); + set_rom(ROMSlot4, adfs_, true); + set_rom(ROMSlot5, std::vector(adfs_.begin() + 16384, adfs_.end()), true); } - _plus3->set_disk(target.disks.front(), 0); + plus3_->set_disk(target.disks.front(), 0); } ROMSlot slot = ROMSlot12; @@ -535,13 +532,13 @@ void Machine::set_rom(ROMSlot slot, std::vector data, bool is_writeable uint8_t *target = nullptr; switch(slot) { - case ROMSlotDFS: _dfs = data; return; - case ROMSlotADFS: _adfs = data; return; + case ROMSlotDFS: dfs_ = data; return; + case ROMSlotADFS: adfs_ = data; return; - case ROMSlotOS: target = _os; break; + case ROMSlotOS: target = os_; break; default: - target = _roms[slot]; - _rom_write_masks[slot] = is_writeable; + target = roms_[slot]; + rom_write_masks_[slot] = is_writeable; break; } @@ -550,221 +547,221 @@ void Machine::set_rom(ROMSlot slot, std::vector data, bool is_writeable inline void Machine::signal_interrupt(Electron::Interrupt interrupt) { - _interrupt_status |= interrupt; + interrupt_status_ |= interrupt; evaluate_interrupts(); } inline void Machine::clear_interrupt(Electron::Interrupt interrupt) { - _interrupt_status &= ~interrupt; + interrupt_status_ &= ~interrupt; evaluate_interrupts(); } void Machine::tape_did_change_interrupt_status(Tape *tape) { - _interrupt_status = (_interrupt_status & ~(Interrupt::TransmitDataEmpty | Interrupt::ReceiveDataFull | Interrupt::HighToneDetect)) | _tape.get_interrupt_status(); + interrupt_status_ = (interrupt_status_ & ~(Interrupt::TransmitDataEmpty | Interrupt::ReceiveDataFull | Interrupt::HighToneDetect)) | tape_.get_interrupt_status(); evaluate_interrupts(); } inline void Machine::evaluate_interrupts() { - if(_interrupt_status & _interrupt_control) + if(interrupt_status_ & interrupt_control_) { - _interrupt_status |= 1; + interrupt_status_ |= 1; } else { - _interrupt_status &= ~1; + interrupt_status_ &= ~1; } - set_irq_line(_interrupt_status & 1); + set_irq_line(interrupt_status_ & 1); } inline void Machine::update_audio() { - unsigned int difference = _frameCycles - _audioOutputPosition; - _audioOutputPosition = _frameCycles; - _speaker->run_for_cycles(difference / clock_rate_audio_divider); - _audioOutputPositionError = difference % clock_rate_audio_divider; + unsigned int difference = frame_cycles_ - audio_output_position_ + audio_output_position_error_; + audio_output_position_ = frame_cycles_; + speaker_->run_for_cycles(difference / Speaker::clock_rate_divider); + audio_output_position_error_ = difference % Speaker::clock_rate_divider; } inline void Machine::start_pixel_line() { - _current_pixel_line = (_current_pixel_line+1)&255; - if(!_current_pixel_line) + current_pixel_line_ = (current_pixel_line_+1)&255; + if(!current_pixel_line_) { - _startLineAddress = _startScreenAddress; - _current_character_row = 0; - _isBlankLine = false; + start_line_address_ = start_screen_address_; + current_character_row_ = 0; + is_blank_line_ = false; } else { - bool mode_has_blank_lines = (_screen_mode == 6) || (_screen_mode == 3); - _isBlankLine = (mode_has_blank_lines && ((_current_character_row > 7 && _current_character_row < 10) || (_current_pixel_line > 249))); + bool mode_has_blank_lines = (screen_mode_ == 6) || (screen_mode_ == 3); + is_blank_line_ = (mode_has_blank_lines && ((current_character_row_ > 7 && current_character_row_ < 10) || (current_pixel_line_ > 249))); - if(!_isBlankLine) + if(!is_blank_line_) { - _startLineAddress++; + start_line_address_++; - if(_current_character_row > 7) + if(current_character_row_ > 7) { - _startLineAddress += ((_screen_mode < 4) ? 80 : 40) * 8 - 8; - _current_character_row = 0; + start_line_address_ += ((screen_mode_ < 4) ? 80 : 40) * 8 - 8; + current_character_row_ = 0; } } } - _currentScreenAddress = _startLineAddress; - _current_pixel_column = 0; - _initial_output_target = _current_output_target = nullptr; + current_screen_address_ = start_line_address_; + current_pixel_column_ = 0; + initial_output_target_ = current_output_target_ = nullptr; } inline void Machine::end_pixel_line() { - if(_current_output_target) _crt->output_data((unsigned int)((_current_output_target - _initial_output_target) * _current_output_divider), _current_output_divider); - _current_character_row++; + if(current_output_target_) crt_->output_data((unsigned int)((current_output_target_ - initial_output_target_) * current_output_divider_), current_output_divider_); + current_character_row_++; } inline void Machine::output_pixels(unsigned int number_of_cycles) { if(!number_of_cycles) return; - if(_isBlankLine) + if(is_blank_line_) { - _crt->output_blank(number_of_cycles * crt_cycles_multiplier); + crt_->output_blank(number_of_cycles * crt_cycles_multiplier); } else { unsigned int divider = 0; - switch(_screen_mode) + switch(screen_mode_) { case 0: case 3: divider = 2; break; case 1: case 4: case 6: divider = 4; break; case 2: case 5: divider = 8; break; } - if(!_initial_output_target || divider != _current_output_divider) + if(!initial_output_target_ || divider != current_output_divider_) { - if(_current_output_target) _crt->output_data((unsigned int)((_current_output_target - _initial_output_target) * _current_output_divider), _current_output_divider); - _current_output_divider = divider; - _initial_output_target = _current_output_target = _crt->allocate_write_area(640 / _current_output_divider); + if(current_output_target_) crt_->output_data((unsigned int)((current_output_target_ - initial_output_target_) * current_output_divider_), current_output_divider_); + current_output_divider_ = divider; + initial_output_target_ = current_output_target_ = crt_->allocate_write_area(640 / current_output_divider_); } #define get_pixel() \ - if(_currentScreenAddress&32768)\ + if(current_screen_address_&32768)\ {\ - _currentScreenAddress = (_screenModeBaseAddress + _currentScreenAddress)&32767;\ + current_screen_address_ = (screen_mode_base_address_ + current_screen_address_)&32767;\ }\ - _last_pixel_byte = _ram[_currentScreenAddress];\ - _currentScreenAddress = _currentScreenAddress+8 + last_pixel_byte_ = ram_[current_screen_address_];\ + current_screen_address_ = current_screen_address_+8 - switch(_screen_mode) + switch(screen_mode_) { case 0: case 3: - if(_initial_output_target) + if(initial_output_target_) { while(number_of_cycles--) { get_pixel(); - *(uint32_t *)_current_output_target = _paletteTables.eighty1bpp[_last_pixel_byte]; - _current_output_target += 4; - _current_pixel_column++; + *(uint32_t *)current_output_target_ = palette_tables_.eighty1bpp[last_pixel_byte_]; + current_output_target_ += 4; + current_pixel_column_++; } - } else _current_output_target += 4*number_of_cycles; + } else current_output_target_ += 4*number_of_cycles; break; case 1: - if(_initial_output_target) + if(initial_output_target_) { while(number_of_cycles--) { get_pixel(); - *(uint16_t *)_current_output_target = _paletteTables.eighty2bpp[_last_pixel_byte]; - _current_output_target += 2; - _current_pixel_column++; + *(uint16_t *)current_output_target_ = palette_tables_.eighty2bpp[last_pixel_byte_]; + current_output_target_ += 2; + current_pixel_column_++; } - } else _current_output_target += 2*number_of_cycles; + } else current_output_target_ += 2*number_of_cycles; break; case 2: - if(_initial_output_target) + if(initial_output_target_) { while(number_of_cycles--) { get_pixel(); - *_current_output_target = _paletteTables.eighty4bpp[_last_pixel_byte]; - _current_output_target += 1; - _current_pixel_column++; + *current_output_target_ = palette_tables_.eighty4bpp[last_pixel_byte_]; + current_output_target_ += 1; + current_pixel_column_++; } - } else _current_output_target += number_of_cycles; + } else current_output_target_ += number_of_cycles; break; case 4: case 6: - if(_initial_output_target) + if(initial_output_target_) { - if(_current_pixel_column&1) + if(current_pixel_column_&1) { - _last_pixel_byte <<= 4; - *(uint16_t *)_current_output_target = _paletteTables.forty1bpp[_last_pixel_byte]; - _current_output_target += 2; + last_pixel_byte_ <<= 4; + *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + current_output_target_ += 2; number_of_cycles--; - _current_pixel_column++; + current_pixel_column_++; } while(number_of_cycles > 1) { get_pixel(); - *(uint16_t *)_current_output_target = _paletteTables.forty1bpp[_last_pixel_byte]; - _current_output_target += 2; + *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + current_output_target_ += 2; - _last_pixel_byte <<= 4; - *(uint16_t *)_current_output_target = _paletteTables.forty1bpp[_last_pixel_byte]; - _current_output_target += 2; + last_pixel_byte_ <<= 4; + *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + current_output_target_ += 2; number_of_cycles -= 2; - _current_pixel_column+=2; + current_pixel_column_+=2; } if(number_of_cycles) { get_pixel(); - *(uint16_t *)_current_output_target = _paletteTables.forty1bpp[_last_pixel_byte]; - _current_output_target += 2; - _current_pixel_column++; + *(uint16_t *)current_output_target_ = palette_tables_.forty1bpp[last_pixel_byte_]; + current_output_target_ += 2; + current_pixel_column_++; } - } else _current_output_target += 2 * number_of_cycles; + } else current_output_target_ += 2 * number_of_cycles; break; case 5: - if(_initial_output_target) + if(initial_output_target_) { - if(_current_pixel_column&1) + if(current_pixel_column_&1) { - _last_pixel_byte <<= 2; - *_current_output_target = _paletteTables.forty2bpp[_last_pixel_byte]; - _current_output_target += 1; + last_pixel_byte_ <<= 2; + *current_output_target_ = palette_tables_.forty2bpp[last_pixel_byte_]; + current_output_target_ += 1; number_of_cycles--; - _current_pixel_column++; + current_pixel_column_++; } while(number_of_cycles > 1) { get_pixel(); - *_current_output_target = _paletteTables.forty2bpp[_last_pixel_byte]; - _current_output_target += 1; + *current_output_target_ = palette_tables_.forty2bpp[last_pixel_byte_]; + current_output_target_ += 1; - _last_pixel_byte <<= 2; - *_current_output_target = _paletteTables.forty2bpp[_last_pixel_byte]; - _current_output_target += 1; + last_pixel_byte_ <<= 2; + *current_output_target_ = palette_tables_.forty2bpp[last_pixel_byte_]; + current_output_target_ += 1; number_of_cycles -= 2; - _current_pixel_column+=2; + current_pixel_column_+=2; } if(number_of_cycles) { get_pixel(); - *_current_output_target = _paletteTables.forty2bpp[_last_pixel_byte]; - _current_output_target += 1; - _current_pixel_column++; + *current_output_target_ = palette_tables_.forty2bpp[last_pixel_byte_]; + current_output_target_ += 1; + current_pixel_column_++; } - } else _current_output_target += number_of_cycles; + } else current_output_target_ += number_of_cycles; break; } @@ -788,10 +785,10 @@ inline void Machine::update_display() */ - int final_line = _frameCycles >> 7; - while(_displayOutputPosition < _frameCycles) + int final_line = frame_cycles_ >> 7; + while(display_output_position_ < frame_cycles_) { - int line = _displayOutputPosition >> 7; + int line = display_output_position_ >> 7; // Priority one: sync. // =================== @@ -801,8 +798,8 @@ inline void Machine::update_display() { // wait for the line to complete before signalling if(final_line == line) return; - _crt->output_sync(128 * crt_cycles_multiplier); - _displayOutputPosition += 128; + crt_->output_sync(128 * crt_cycles_multiplier); + display_output_position_ += 128; continue; } @@ -811,9 +808,9 @@ inline void Machine::update_display() { // wait for the line to complete before signalling if(final_line == line) return; - _crt->output_sync(64 * crt_cycles_multiplier); - _crt->output_blank(64 * crt_cycles_multiplier); - _displayOutputPosition += 128; + crt_->output_sync(64 * crt_cycles_multiplier); + crt_->output_blank(64 * crt_cycles_multiplier); + display_output_position_ += 128; continue; } @@ -822,10 +819,10 @@ inline void Machine::update_display() { // wait for the line to complete before signalling if(final_line == line) return; - _crt->output_sync(9 * crt_cycles_multiplier); - _crt->output_blank(55 * crt_cycles_multiplier); - _crt->output_sync(64 * crt_cycles_multiplier); - _displayOutputPosition += 128; + crt_->output_sync(9 * crt_cycles_multiplier); + crt_->output_blank(55 * crt_cycles_multiplier); + crt_->output_sync(64 * crt_cycles_multiplier); + display_output_position_ += 128; continue; } @@ -841,9 +838,9 @@ inline void Machine::update_display() line > first_graphics_line+field_divider_line+255) { if(final_line == line) return; - _crt->output_sync(9 * crt_cycles_multiplier); - _crt->output_blank(119 * crt_cycles_multiplier); - _displayOutputPosition += 128; + crt_->output_sync(9 * crt_cycles_multiplier); + crt_->output_blank(119 * crt_cycles_multiplier); + display_output_position_ += 128; continue; } @@ -851,8 +848,8 @@ inline void Machine::update_display() // ======================================== // determine how far we're going from left to right - unsigned int this_cycle = _displayOutputPosition&127; - unsigned int final_cycle = _frameCycles&127; + unsigned int this_cycle = display_output_position_&127; + unsigned int final_cycle = frame_cycles_&127; if(final_line > line) { final_cycle = 128; @@ -869,16 +866,16 @@ inline void Machine::update_display() if(this_cycle < 9) { if(final_cycle < 9) return; - _crt->output_sync(9 * crt_cycles_multiplier); - _displayOutputPosition += 9; + crt_->output_sync(9 * crt_cycles_multiplier); + display_output_position_ += 9; this_cycle = 9; } if(this_cycle < 24) { if(final_cycle < 24) return; - _crt->output_colour_burst((24-9) * crt_cycles_multiplier, _phase, 12); - _displayOutputPosition += 24-9; + crt_->output_colour_burst((24-9) * crt_cycles_multiplier, phase_, 12); + display_output_position_ += 24-9; this_cycle = 24; // TODO: phase shouldn't be zero on every line } @@ -886,8 +883,8 @@ inline void Machine::update_display() if(this_cycle < first_graphics_cycle) { if(final_cycle < first_graphics_cycle) return; - _crt->output_blank((first_graphics_cycle - 24) * crt_cycles_multiplier); - _displayOutputPosition += first_graphics_cycle - 24; + crt_->output_blank((first_graphics_cycle - 24) * crt_cycles_multiplier); + display_output_position_ += first_graphics_cycle - 24; this_cycle = first_graphics_cycle; start_pixel_line(); } @@ -896,7 +893,7 @@ inline void Machine::update_display() { unsigned int length_to_output = std::min(final_cycle, (first_graphics_cycle + 80)) - this_cycle; output_pixels(length_to_output); - _displayOutputPosition += length_to_output; + display_output_position_ += length_to_output; this_cycle += length_to_output; } @@ -904,8 +901,8 @@ inline void Machine::update_display() { if(final_cycle < 128) return; end_pixel_line(); - _crt->output_blank((128 - (first_graphics_cycle + 80)) * crt_cycles_multiplier); - _displayOutputPosition += 128 - (first_graphics_cycle + 80); + crt_->output_blank((128 - (first_graphics_cycle + 80)) * crt_cycles_multiplier); + display_output_position_ += 128 - (first_graphics_cycle + 80); this_cycle = 128; } } @@ -914,7 +911,7 @@ inline void Machine::update_display() void Machine::clear_all_keys() { - memset(_key_states, 0, sizeof(_key_states)); + memset(key_states_, 0, sizeof(key_states_)); } void Machine::set_key_state(uint16_t key, bool isPressed) @@ -926,177 +923,8 @@ void Machine::set_key_state(uint16_t key, bool isPressed) else { if(isPressed) - _key_states[key >> 4] |= key&0xf; + key_states_[key >> 4] |= key&0xf; else - _key_states[key >> 4] &= ~(key&0xf); - } -} - -/* - Speaker -*/ - -void Speaker::get_samples(unsigned int number_of_samples, int16_t *target) -{ - if(_is_enabled) - { - while(number_of_samples--) - { - *target = (int16_t)((_counter / (_divider+1)) * 8192); - target++; - _counter = (_counter + 1) % ((_divider+1) * 2); - } - } - else - { - memset(target, 0, sizeof(int16_t) * number_of_samples); - } -} - -void Speaker::skip_samples(unsigned int number_of_samples) -{ - _counter = (_counter + number_of_samples) % ((_divider+1) * 2); -} - -void Speaker::set_divider(uint8_t divider) -{ - enqueue([=]() { - _divider = divider * 32 / clock_rate_audio_divider; - }); -} - -void Speaker::set_is_enabled(bool is_enabled) -{ - enqueue([=]() { - _is_enabled = is_enabled; - _counter = 0; - }); -} - -/* - Tape -*/ - -Tape::Tape() : - TapePlayer(2000000), - _is_running(false), - _data_register(0), - _delegate(nullptr), - _output({.bits_remaining_until_empty = 0, .cycles_into_pulse = 0}), - _last_posted_interrupt_status(0), - _interrupt_status(0) -{} - -inline void Tape::push_tape_bit(uint16_t bit) -{ - _data_register = (uint16_t)((_data_register >> 1) | (bit << 10)); - - if(_input.minimum_bits_until_full) _input.minimum_bits_until_full--; - if(_input.minimum_bits_until_full == 8) _interrupt_status &= ~Interrupt::ReceiveDataFull; - if(!_input.minimum_bits_until_full) - { - if((_data_register&0x3) == 0x1) - { - _interrupt_status |= Interrupt::ReceiveDataFull; - if(_is_in_input_mode) _input.minimum_bits_until_full = 9; - } - } - - if(_output.bits_remaining_until_empty) _output.bits_remaining_until_empty--; - if(!_output.bits_remaining_until_empty) _interrupt_status |= Interrupt::TransmitDataEmpty; - - if(_data_register == 0x3ff) _interrupt_status |= Interrupt::HighToneDetect; - else _interrupt_status &= ~Interrupt::HighToneDetect; - - evaluate_interrupts(); -} - -inline void Tape::evaluate_interrupts() -{ - if(_last_posted_interrupt_status != _interrupt_status) - { - _last_posted_interrupt_status = _interrupt_status; - if(_delegate) _delegate->tape_did_change_interrupt_status(this); - } -} - -inline void Tape::clear_interrupts(uint8_t interrupts) -{ - _interrupt_status &= ~interrupts; - evaluate_interrupts(); -} - -inline void Tape::set_is_in_input_mode(bool is_in_input_mode) -{ - _is_in_input_mode = is_in_input_mode; -} - -inline void Tape::set_counter(uint8_t value) -{ - _output.cycles_into_pulse = 0; - _output.bits_remaining_until_empty = 0; -} - -inline void Tape::set_data_register(uint8_t value) -{ - _data_register = (uint16_t)((value << 2) | 1); - _output.bits_remaining_until_empty = 9; -} - -inline uint8_t Tape::get_data_register() -{ - return (uint8_t)(_data_register >> 2); -} - -inline void Tape::process_input_pulse(Storage::Tape::Tape::Pulse pulse) -{ - _crossings[0] = _crossings[1]; - _crossings[1] = _crossings[2]; - _crossings[2] = _crossings[3]; - - _crossings[3] = Tape::Unrecognised; - if(pulse.type != Storage::Tape::Tape::Pulse::Zero) - { - float pulse_length = (float)pulse.length.length / (float)pulse.length.clock_rate; - if(pulse_length >= 0.35 / 2400.0 && pulse_length < 0.7 / 2400.0) _crossings[3] = Tape::Short; - if(pulse_length >= 0.35 / 1200.0 && pulse_length < 0.7 / 1200.0) _crossings[3] = Tape::Long; - } - - if(_crossings[0] == Tape::Long && _crossings[1] == Tape::Long) - { - push_tape_bit(0); - _crossings[0] = _crossings[1] = Tape::Recognised; - } - else - { - if(_crossings[0] == Tape::Short && _crossings[1] == Tape::Short && _crossings[2] == Tape::Short && _crossings[3] == Tape::Short) - { - push_tape_bit(1); - _crossings[0] = _crossings[1] = - _crossings[2] = _crossings[3] = Tape::Recognised; - } - } -} - -inline void Tape::run_for_cycles(unsigned int number_of_cycles) -{ - if(_is_enabled) - { - if(_is_in_input_mode) - { - if(_is_running) - { - TapePlayer::run_for_cycles((int)number_of_cycles); - } - } - else - { - _output.cycles_into_pulse += number_of_cycles; - while(_output.cycles_into_pulse > 1664) // 1664 = the closest you can get to 1200 baud if you're looking for something - { // that divides the 125,000Hz clock that the sound divider runs off. - _output.cycles_into_pulse -= 1664; - push_tape_bit(1); - } - } + key_states_[key >> 4] &= ~(key&0xf); } } diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index 15c6b7dfc..38ccaa8ee 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -16,6 +16,9 @@ #include "../CRTMachine.hpp" #include "../Typer.hpp" #include "Plus3.hpp" +#include "Speaker.hpp" +#include "Tape.hpp" +#include "Interrupts.hpp" #include #include @@ -35,15 +38,6 @@ enum ROMSlot: uint8_t { ROMSlotOS, ROMSlotDFS, ROMSlotADFS }; -enum Interrupt: uint8_t { - PowerOnReset = 0x02, - DisplayEnd = 0x04, - RealTimeClock = 0x08, - ReceiveDataFull = 0x10, - TransmitDataEmpty = 0x20, - HighToneDetect = 0x40 -}; - enum Key: uint16_t { KeySpace = 0x0000 | 0x08, KeyCopy = 0x0000 | 0x02, KeyRight = 0x0000 | 0x01, KeyDelete = 0x0010 | 0x08, KeyReturn = 0x0010 | 0x04, KeyDown = 0x0010 | 0x02, KeyLeft = 0x0010 | 0x01, @@ -65,72 +59,6 @@ enum Key: uint16_t { TerminateSequence = 0xffff, NotMapped = 0xfffe, }; -class Tape: public Storage::Tape::TapePlayer { - public: - Tape(); - - inline void run_for_cycles(unsigned int number_of_cycles); - - inline uint8_t get_data_register(); - inline void set_data_register(uint8_t value); - inline void set_counter(uint8_t value); - - inline uint8_t get_interrupt_status() { return _interrupt_status; } - inline void clear_interrupts(uint8_t interrupts); - - class Delegate { - public: - virtual void tape_did_change_interrupt_status(Tape *tape) = 0; - }; - inline void set_delegate(Delegate *delegate) { _delegate = delegate; } - - inline void set_is_running(bool is_running) { _is_running = is_running; } - inline void set_is_enabled(bool is_enabled) { _is_enabled = is_enabled; } - inline void set_is_in_input_mode(bool is_in_input_mode); - - private: - void process_input_pulse(Storage::Tape::Tape::Pulse pulse); - inline void push_tape_bit(uint16_t bit); - inline void get_next_tape_pulse(); - - struct { - int minimum_bits_until_full; - } _input; - struct { - unsigned int cycles_into_pulse; - unsigned int bits_remaining_until_empty; - } _output; - - bool _is_running; - bool _is_enabled; - bool _is_in_input_mode; - - inline void evaluate_interrupts(); - uint16_t _data_register; - - uint8_t _interrupt_status, _last_posted_interrupt_status; - Delegate *_delegate; - - enum { - Long, Short, Unrecognised, Recognised - } _crossings[4]; -}; - -class Speaker: public ::Outputs::Filter { - public: - void set_divider(uint8_t divider); - - void set_is_enabled(bool is_enabled); - - void get_samples(unsigned int number_of_samples, int16_t *target); - void skip_samples(unsigned int number_of_samples); - - private: - unsigned int _counter; - unsigned int _divider; - bool _is_enabled; -}; - /*! @abstract Represents an Acorn Electron. @@ -152,7 +80,7 @@ class Machine: void set_key_state(uint16_t key, bool isPressed); void clear_all_keys(); - inline void set_use_fast_tape_hack(bool activate) { _use_fast_tape_hack = activate; } + inline void set_use_fast_tape_hack(bool activate) { use_fast_tape_hack_ = activate; } // to satisfy ConfigurationTarget::Machine void configure_as_target(const StaticAnalyser::Target &target); @@ -164,8 +92,8 @@ class Machine: // to satisfy CRTMachine::Machine virtual void setup_output(float aspect_ratio); virtual void close_output(); - virtual std::shared_ptr get_crt() { return _crt; } - virtual std::shared_ptr get_speaker() { return _speaker; } + virtual std::shared_ptr get_crt() { return crt_; } + virtual std::shared_ptr get_speaker() { return speaker_; } virtual void run_for_cycles(int number_of_cycles) { CPU6502::Processor::run_for_cycles(number_of_cycles); } // to satisfy Tape::Delegate @@ -189,25 +117,25 @@ class Machine: inline void evaluate_interrupts(); // Things that directly constitute the memory map. - uint8_t _roms[16][16384]; - bool _rom_write_masks[16]; - uint8_t _os[16384], _ram[32768]; - std::vector _dfs, _adfs; + uint8_t roms_[16][16384]; + bool rom_write_masks_[16]; + uint8_t os_[16384], ram_[32768]; + std::vector dfs_, adfs_; // Things affected by registers, explicitly or otherwise. - uint8_t _interrupt_status, _interrupt_control; - uint8_t _palette[16]; - uint8_t _key_states[14]; - ROMSlot _active_rom; - bool _keyboard_is_active, _basic_is_active; - uint8_t _screen_mode; - uint16_t _screenModeBaseAddress; - uint16_t _startScreenAddress; + uint8_t interrupt_status_, interrupt_control_; + uint8_t palette_[16]; + uint8_t key_states_[14]; + ROMSlot active_rom_; + bool keyboard_is_active_, basic_is_active_; + uint8_t screen_mode_; + uint16_t screen_mode_base_address_; + uint16_t start_screen_address_; // Counters related to simultaneous subsystems - unsigned int _frameCycles, _displayOutputPosition; - unsigned int _audioOutputPosition, _audioOutputPositionError; - uint8_t _phase; + unsigned int frame_cycles_, display_output_position_; + unsigned int audio_output_position_, audio_output_position_error_; + uint8_t phase_; struct { uint16_t forty1bpp[256]; @@ -215,30 +143,30 @@ class Machine: uint32_t eighty1bpp[256]; uint16_t eighty2bpp[256]; uint8_t eighty4bpp[256]; - } _paletteTables; + } palette_tables_; // Display generation. - uint16_t _startLineAddress, _currentScreenAddress; - int _current_pixel_line, _current_pixel_column, _current_character_row; - uint8_t _last_pixel_byte; - bool _isBlankLine; + uint16_t start_line_address_, current_screen_address_; + int current_pixel_line_, current_pixel_column_, current_character_row_; + uint8_t last_pixel_byte_; + bool is_blank_line_; // CRT output - uint8_t *_current_output_target, *_initial_output_target; - unsigned int _current_output_divider; + uint8_t *current_output_target_, *initial_output_target_; + unsigned int current_output_divider_; // Tape - Tape _tape; - bool _use_fast_tape_hack; - bool _fast_load_is_in_data; + Tape tape_; + bool use_fast_tape_hack_; + bool fast_load_is_in_data_; // Disk - std::unique_ptr _plus3; + std::unique_ptr plus3_; bool is_holding_shift_; // Outputs - std::shared_ptr _crt; - std::shared_ptr _speaker; + std::shared_ptr crt_; + std::shared_ptr speaker_; bool speaker_is_enabled_; }; diff --git a/Machines/Electron/Interrupts.hpp b/Machines/Electron/Interrupts.hpp new file mode 100644 index 000000000..776667d79 --- /dev/null +++ b/Machines/Electron/Interrupts.hpp @@ -0,0 +1,27 @@ +// +// Interrupts.hpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef Interrupts_h +#define Interrupts_h + +#include + +namespace Electron { + +enum Interrupt: uint8_t { + PowerOnReset = 0x02, + DisplayEnd = 0x04, + RealTimeClock = 0x08, + ReceiveDataFull = 0x10, + TransmitDataEmpty = 0x20, + HighToneDetect = 0x40 +}; + +} + +#endif /* Interrupts_h */ diff --git a/Machines/Electron/Speaker.cpp b/Machines/Electron/Speaker.cpp new file mode 100644 index 000000000..05442f564 --- /dev/null +++ b/Machines/Electron/Speaker.cpp @@ -0,0 +1,48 @@ +// +// Speaker.cpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#include "Speaker.hpp" + +using namespace Electron; + +void Speaker::get_samples(unsigned int number_of_samples, int16_t *target) +{ + if(is_enabled_) + { + while(number_of_samples--) + { + *target = (int16_t)((counter_ / (divider_+1)) * 8192); + target++; + counter_ = (counter_ + 1) % ((divider_+1) * 2); + } + } + else + { + memset(target, 0, sizeof(int16_t) * number_of_samples); + } +} + +void Speaker::skip_samples(unsigned int number_of_samples) +{ + counter_ = (counter_ + number_of_samples) % ((divider_+1) * 2); +} + +void Speaker::set_divider(uint8_t divider) +{ + enqueue([=]() { + divider_ = divider * 32 / clock_rate_divider; + }); +} + +void Speaker::set_is_enabled(bool is_enabled) +{ + enqueue([=]() { + is_enabled_ = is_enabled; + counter_ = 0; + }); +} diff --git a/Machines/Electron/Speaker.hpp b/Machines/Electron/Speaker.hpp new file mode 100644 index 000000000..f61052371 --- /dev/null +++ b/Machines/Electron/Speaker.hpp @@ -0,0 +1,35 @@ +// +// Speaker.hpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef Electron_Speaker_hpp +#define Electron_Speaker_hpp + +#include "../../Outputs/Speaker.hpp" + +namespace Electron { + +class Speaker: public ::Outputs::Filter { + public: + void set_divider(uint8_t divider); + + void set_is_enabled(bool is_enabled); + + void get_samples(unsigned int number_of_samples, int16_t *target); + void skip_samples(unsigned int number_of_samples); + + static const unsigned int clock_rate_divider = 8; + + private: + unsigned int counter_; + unsigned int divider_; + bool is_enabled_; +}; + +} + +#endif /* Speaker_hpp */ diff --git a/Machines/Electron/Tape.cpp b/Machines/Electron/Tape.cpp new file mode 100644 index 000000000..94ed106b2 --- /dev/null +++ b/Machines/Electron/Tape.cpp @@ -0,0 +1,135 @@ +// +// Tape.cpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#include "Tape.hpp" + +using namespace Electron; + +Tape::Tape() : + TapePlayer(2000000), + is_running_(false), + data_register_(0), + delegate_(nullptr), + output_({.bits_remaining_until_empty = 0, .cycles_into_pulse = 0}), + last_posted_interrupt_status_(0), + interrupt_status_(0) +{} + +void Tape::push_tape_bit(uint16_t bit) +{ + data_register_ = (uint16_t)((data_register_ >> 1) | (bit << 10)); + + if(input_.minimum_bits_until_full) input_.minimum_bits_until_full--; + if(input_.minimum_bits_until_full == 8) interrupt_status_ &= ~Interrupt::ReceiveDataFull; + if(!input_.minimum_bits_until_full) + { + if((data_register_&0x3) == 0x1) + { + interrupt_status_ |= Interrupt::ReceiveDataFull; + if(is_in_input_mode_) input_.minimum_bits_until_full = 9; + } + } + + if(output_.bits_remaining_until_empty) output_.bits_remaining_until_empty--; + if(!output_.bits_remaining_until_empty) interrupt_status_ |= Interrupt::TransmitDataEmpty; + + if(data_register_ == 0x3ff) interrupt_status_ |= Interrupt::HighToneDetect; + else interrupt_status_ &= ~Interrupt::HighToneDetect; + + evaluate_interrupts(); +} + +void Tape::evaluate_interrupts() +{ + if(last_posted_interrupt_status_ != interrupt_status_) + { + last_posted_interrupt_status_ = interrupt_status_; + if(delegate_) delegate_->tape_did_change_interrupt_status(this); + } +} + +void Tape::clear_interrupts(uint8_t interrupts) +{ + interrupt_status_ &= ~interrupts; + evaluate_interrupts(); +} + +void Tape::set_is_in_input_mode(bool is_in_input_mode) +{ + is_in_input_mode_ = is_in_input_mode; +} + +void Tape::set_counter(uint8_t value) +{ + output_.cycles_into_pulse = 0; + output_.bits_remaining_until_empty = 0; +} + +void Tape::set_data_register(uint8_t value) +{ + data_register_ = (uint16_t)((value << 2) | 1); + output_.bits_remaining_until_empty = 9; +} + +uint8_t Tape::get_data_register() +{ + return (uint8_t)(data_register_ >> 2); +} + +void Tape::process_input_pulse(Storage::Tape::Tape::Pulse pulse) +{ + crossings_[0] = crossings_[1]; + crossings_[1] = crossings_[2]; + crossings_[2] = crossings_[3]; + + crossings_[3] = Tape::Unrecognised; + if(pulse.type != Storage::Tape::Tape::Pulse::Zero) + { + float pulse_length = (float)pulse.length.length / (float)pulse.length.clock_rate; + if(pulse_length >= 0.35 / 2400.0 && pulse_length < 0.7 / 2400.0) crossings_[3] = Tape::Short; + if(pulse_length >= 0.35 / 1200.0 && pulse_length < 0.7 / 1200.0) crossings_[3] = Tape::Long; + } + + if(crossings_[0] == Tape::Long && crossings_[1] == Tape::Long) + { + push_tape_bit(0); + crossings_[0] = crossings_[1] = Tape::Recognised; + } + else + { + if(crossings_[0] == Tape::Short && crossings_[1] == Tape::Short && crossings_[2] == Tape::Short && crossings_[3] == Tape::Short) + { + push_tape_bit(1); + crossings_[0] = crossings_[1] = + crossings_[2] = crossings_[3] = Tape::Recognised; + } + } +} + +void Tape::run_for_cycles(unsigned int number_of_cycles) +{ + if(is_enabled_) + { + if(is_in_input_mode_) + { + if(is_running_) + { + TapePlayer::run_for_cycles((int)number_of_cycles); + } + } + else + { + output_.cycles_into_pulse += number_of_cycles; + while(output_.cycles_into_pulse > 1664) // 1664 = the closest you can get to 1200 baud if you're looking for something + { // that divides the 125,000Hz clock that the sound divider runs off. + output_.cycles_into_pulse -= 1664; + push_tape_bit(1); + } + } + } +} diff --git a/Machines/Electron/Tape.hpp b/Machines/Electron/Tape.hpp new file mode 100644 index 000000000..a796e7824 --- /dev/null +++ b/Machines/Electron/Tape.hpp @@ -0,0 +1,72 @@ +// +// Tape.hpp +// Clock Signal +// +// Created by Thomas Harte on 03/12/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef Electron_Tape_h +#define Electron_Tape_h + +#include "../../Storage/Tape/Tape.hpp" +#include "Interrupts.hpp" + +#include + +namespace Electron { + +class Tape: public Storage::Tape::TapePlayer { + public: + Tape(); + + void run_for_cycles(unsigned int number_of_cycles); + + uint8_t get_data_register(); + void set_data_register(uint8_t value); + void set_counter(uint8_t value); + + inline uint8_t get_interrupt_status() { return interrupt_status_; } + void clear_interrupts(uint8_t interrupts); + + class Delegate { + public: + virtual void tape_did_change_interrupt_status(Tape *tape) = 0; + }; + inline void set_delegate(Delegate *delegate) { delegate_ = delegate; } + + inline void set_is_running(bool is_running) { is_running_ = is_running; } + inline void set_is_enabled(bool is_enabled) { is_enabled_ = is_enabled; } + void set_is_in_input_mode(bool is_in_input_mode); + + private: + void process_input_pulse(Storage::Tape::Tape::Pulse pulse); + inline void push_tape_bit(uint16_t bit); + inline void get_next_tape_pulse(); + + struct { + int minimum_bits_until_full; + } input_; + struct { + unsigned int cycles_into_pulse; + unsigned int bits_remaining_until_empty; + } output_; + + bool is_running_; + bool is_enabled_; + bool is_in_input_mode_; + + inline void evaluate_interrupts(); + uint16_t data_register_; + + uint8_t interrupt_status_, last_posted_interrupt_status_; + Delegate *delegate_; + + enum { + Long, Short, Unrecognised, Recognised + } crossings_[4]; +}; + +} + +#endif /* Electron_Tape_h */ diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 724563faa..037519eb2 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -140,15 +140,15 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin } } - if(_typer && address == scan_keyboard_address_ && operation == CPU6502::BusOperation::ReadOpcode) + if(typer_ && address == scan_keyboard_address_ && operation == CPU6502::BusOperation::ReadOpcode) { // the Oric 1 misses any key pressed on the very first entry into the read keyboard routine, so don't // do anything until at least the second, regardless of machine if(!keyboard_read_count_) keyboard_read_count_++; - else if(!_typer->type_next_character()) + else if(!typer_->type_next_character()) { clear_all_keys(); - _typer.reset(); + typer_.reset(); } } diff --git a/Machines/Typer.cpp b/Machines/Typer.cpp index 43a527b0d..a6a502972 100644 --- a/Machines/Typer.cpp +++ b/Machines/Typer.cpp @@ -12,32 +12,32 @@ using namespace Utility; Typer::Typer(const char *string, int delay, int frequency, Delegate *delegate) : - _counter(-delay), _frequency(frequency), _string_pointer(0), _delegate(delegate), _phase(0) + counter_(-delay), frequency_(frequency), string_pointer_(0), delegate_(delegate), phase_(0) { size_t string_size = strlen(string) + 3; - _string = (char *)malloc(string_size); - snprintf(_string, strlen(string) + 3, "%c%s%c", Typer::BeginString, string, Typer::EndString); + string_ = (char *)malloc(string_size); + snprintf(string_, strlen(string) + 3, "%c%s%c", Typer::BeginString, string, Typer::EndString); } void Typer::update(int duration) { - if(_string) + if(string_) { - if(_counter < 0 && _counter + duration >= 0) + if(counter_ < 0 && counter_ + duration >= 0) { if(!type_next_character()) { - _delegate->typer_reset(this); + delegate_->typer_reset(this); } } - _counter += duration; - while(_string && _counter > _frequency) + counter_ += duration; + while(string_ && counter_ > frequency_) { - _counter -= _frequency; + counter_ -= frequency_; if(!type_next_character()) { - _delegate->typer_reset(this); + delegate_->typer_reset(this); } } } @@ -45,23 +45,23 @@ void Typer::update(int duration) bool Typer::type_next_character() { - if(_string == nullptr) return false; + if(string_ == nullptr) return false; - if(_delegate->typer_set_next_character(this, _string[_string_pointer], _phase)) + if(delegate_->typer_set_next_character(this, string_[string_pointer_], phase_)) { - _phase = 0; - if(!_string[_string_pointer]) + phase_ = 0; + if(!string_[string_pointer_]) { - free(_string); - _string = nullptr; + free(string_); + string_ = nullptr; return false; } - _string_pointer++; + string_pointer_++; } else { - _phase++; + phase_++; } return true; @@ -69,7 +69,7 @@ bool Typer::type_next_character() Typer::~Typer() { - free(_string); + free(string_); } #pragma mark - Delegate diff --git a/Machines/Typer.hpp b/Machines/Typer.hpp index 4a5958414..2604a6530 100644 --- a/Machines/Typer.hpp +++ b/Machines/Typer.hpp @@ -35,31 +35,31 @@ class Typer { const char EndString = 0x03; // i.e. ASCII end of text private: - char *_string; - int _frequency; - int _counter; - int _phase; - Delegate *_delegate; - size_t _string_pointer; + char *string_; + int frequency_; + int counter_; + int phase_; + Delegate *delegate_; + size_t string_pointer_; }; class TypeRecipient: public Typer::Delegate { public: void set_typer_for_string(const char *string) { - _typer.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), this)); + typer_.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), this)); } void typer_reset(Typer *typer) { clear_all_keys(); - _typer.reset(); + typer_.reset(); } protected: virtual int get_typer_delay() { return 0; } virtual int get_typer_frequency() { return 0; } - std::unique_ptr _typer; + std::unique_ptr typer_; }; } diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 11eccdc41..86fbb6bba 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -383,6 +383,9 @@ 4BD5F1951D13528900631CD1 /* CSBestEffortUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BD5F1941D13528900631CD1 /* CSBestEffortUpdater.m */; }; 4BD69F941D98760000243FE1 /* AcornADF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BD69F921D98760000243FE1 /* AcornADF.cpp */; }; 4BE77A2E1D84ADFB00BC3827 /* File.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BE77A2C1D84ADFB00BC3827 /* File.cpp */; }; + 4BEA525E1DF33323007E74F2 /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEA525D1DF33323007E74F2 /* Tape.cpp */; }; + 4BEA52631DF339D7007E74F2 /* Speaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEA52611DF339D7007E74F2 /* Speaker.cpp */; }; + 4BEA52661DF3472B007E74F2 /* Speaker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEA52641DF3472B007E74F2 /* Speaker.cpp */; }; 4BEE0A6F1D72496600532C7B /* Cartridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE0A6A1D72496600532C7B /* Cartridge.cpp */; }; 4BEE0A701D72496600532C7B /* PRG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE0A6D1D72496600532C7B /* PRG.cpp */; }; 4BEF6AAA1D35CE9E00E73575 /* DigitalPhaseLockedLoopBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BEF6AA91D35CE9E00E73575 /* DigitalPhaseLockedLoopBridge.mm */; }; @@ -892,6 +895,14 @@ 4BD69F931D98760000243FE1 /* AcornADF.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = AcornADF.hpp; sourceTree = ""; }; 4BE77A2C1D84ADFB00BC3827 /* File.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = File.cpp; path = ../../StaticAnalyser/Commodore/File.cpp; sourceTree = ""; }; 4BE77A2D1D84ADFB00BC3827 /* File.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = File.hpp; path = ../../StaticAnalyser/Commodore/File.hpp; sourceTree = ""; }; + 4BEA525D1DF33323007E74F2 /* Tape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Tape.cpp; path = Electron/Tape.cpp; sourceTree = ""; }; + 4BEA525F1DF333D8007E74F2 /* Tape.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = Tape.hpp; path = Electron/Tape.hpp; sourceTree = ""; }; + 4BEA52601DF3343A007E74F2 /* Interrupts.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = Interrupts.hpp; path = Electron/Interrupts.hpp; sourceTree = ""; }; + 4BEA52611DF339D7007E74F2 /* Speaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Speaker.cpp; path = Electron/Speaker.cpp; sourceTree = ""; }; + 4BEA52621DF339D7007E74F2 /* Speaker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Speaker.hpp; path = Electron/Speaker.hpp; sourceTree = ""; }; + 4BEA52641DF3472B007E74F2 /* Speaker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Speaker.cpp; sourceTree = ""; }; + 4BEA52651DF3472B007E74F2 /* Speaker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Speaker.hpp; sourceTree = ""; }; + 4BEA52671DF34909007E74F2 /* PIA.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = PIA.hpp; sourceTree = ""; }; 4BEE0A6A1D72496600532C7B /* Cartridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Cartridge.cpp; sourceTree = ""; }; 4BEE0A6B1D72496600532C7B /* Cartridge.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Cartridge.hpp; sourceTree = ""; }; 4BEE0A6D1D72496600532C7B /* PRG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PRG.cpp; sourceTree = ""; }; @@ -1042,8 +1053,11 @@ isa = PBXGroup; children = ( 4B2E2D971C3A06EC00138695 /* Atari2600.cpp */, - 4B2E2D981C3A06EC00138695 /* Atari2600.hpp */, + 4BEA52641DF3472B007E74F2 /* Speaker.cpp */, 4B2E2D991C3A06EC00138695 /* Atari2600Inputs.h */, + 4B2E2D981C3A06EC00138695 /* Atari2600.hpp */, + 4BEA52651DF3472B007E74F2 /* Speaker.hpp */, + 4BEA52671DF34909007E74F2 /* PIA.hpp */, ); path = Atari2600; sourceTree = ""; @@ -1052,10 +1066,15 @@ isa = PBXGroup; children = ( 4B2E2D9B1C3A070400138695 /* Electron.cpp */, - 4B2E2D9C1C3A070400138695 /* Electron.hpp */, 4B30512E1D98ACC600B4FED8 /* Plus3.cpp */, - 4B30512F1D98ACC600B4FED8 /* Plus3.hpp */, + 4BEA52611DF339D7007E74F2 /* Speaker.cpp */, + 4BEA525D1DF33323007E74F2 /* Tape.cpp */, 4BC8A62B1DCE60E000DAC693 /* Typer.cpp */, + 4B2E2D9C1C3A070400138695 /* Electron.hpp */, + 4BEA52601DF3343A007E74F2 /* Interrupts.hpp */, + 4B30512F1D98ACC600B4FED8 /* Plus3.hpp */, + 4BEA52621DF339D7007E74F2 /* Speaker.hpp */, + 4BEA525F1DF333D8007E74F2 /* Tape.hpp */, ); name = Electron; sourceTree = ""; @@ -2314,6 +2333,7 @@ 4BBF99151C8FBA6F0075DAFB /* CRTOpenGL.cpp in Sources */, 4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */, 4BCF1FA41DADC3DD0039D2E7 /* Oric.cpp in Sources */, + 4BEA525E1DF33323007E74F2 /* Tape.cpp in Sources */, 4BC8A62D1DCE60E000DAC693 /* Typer.cpp in Sources */, 4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */, 4BA799951D8B656E0045123D /* StaticAnalyser.cpp in Sources */, @@ -2335,6 +2355,7 @@ 4B2A332F1DB86869002876E3 /* OricOptionsPanel.swift in Sources */, 4B2A53A11D117D36003C6002 /* CSAtari2600.mm in Sources */, 4BF829661D8F732B001BAE39 /* Disk.cpp in Sources */, + 4BEA52631DF339D7007E74F2 /* Speaker.cpp in Sources */, 4BC5E4921D7ED365008CF980 /* StaticAnalyser.cpp in Sources */, 4BC830D11D6E7C690000A26F /* Tape.cpp in Sources */, 4B69FB441C4D941400B5F0AA /* TapeUEF.cpp in Sources */, @@ -2378,6 +2399,7 @@ 4B30512D1D989E2200B4FED8 /* Drive.cpp in Sources */, 4BCA6CC81D9DD9F000C2D7B2 /* CommodoreROM.cpp in Sources */, 4BA22B071D8817CE0008C640 /* Disk.cpp in Sources */, + 4BEA52661DF3472B007E74F2 /* Speaker.cpp in Sources */, 4BC3B7521CD1956900F86E85 /* OutputShader.cpp in Sources */, 4B4C83701D4F623200CD541F /* D64.cpp in Sources */, 4B5073071DDD3B9400C48FBD /* ArrayBuilder.cpp in Sources */, diff --git a/Outputs/Speaker.hpp b/Outputs/Speaker.hpp index f2830908f..b3c854cbd 100644 --- a/Outputs/Speaker.hpp +++ b/Outputs/Speaker.hpp @@ -40,13 +40,13 @@ class Speaker { float get_ideal_clock_rate_in_range(float minimum, float maximum) { // return twice the cut off, if applicable - if(_high_frequency_cut_off > 0.0f && _input_cycles_per_second >= _high_frequency_cut_off * 3.0f && _input_cycles_per_second <= _high_frequency_cut_off * 3.0f) return _high_frequency_cut_off * 3.0f; + if(high_frequency_cut_off_ > 0.0f && input_cycles_per_second_ >= high_frequency_cut_off_ * 3.0f && input_cycles_per_second_ <= high_frequency_cut_off_ * 3.0f) return high_frequency_cut_off_ * 3.0f; // return exactly the input rate if possible - if(_input_cycles_per_second >= minimum && _input_cycles_per_second <= maximum) return _input_cycles_per_second; + if(input_cycles_per_second_ >= minimum && input_cycles_per_second_ <= maximum) return input_cycles_per_second_; // if the input rate is lower, return the minimum - if(_input_cycles_per_second < minimum) return minimum; + if(input_cycles_per_second_ < minimum) return minimum; // otherwise, return the maximum return maximum; @@ -54,29 +54,29 @@ class Speaker { void set_output_rate(float cycles_per_second, int buffer_size) { - _output_cycles_per_second = cycles_per_second; - if(_buffer_size != buffer_size) + output_cycles_per_second_ = cycles_per_second; + if(buffer_size_ != buffer_size) { - _buffer_in_progress.reset(new int16_t[buffer_size]); - _buffer_size = buffer_size; + buffer_in_progress_.reset(new int16_t[buffer_size]); + buffer_size_ = buffer_size; } set_needs_updated_filter_coefficients(); } void set_output_quality(int number_of_taps) { - _requested_number_of_taps = number_of_taps; + requested_number_of_taps_ = number_of_taps; set_needs_updated_filter_coefficients(); } void set_delegate(Delegate *delegate) { - _delegate = delegate; + delegate_ = delegate; } void set_input_rate(float cycles_per_second) { - _input_cycles_per_second = cycles_per_second; + input_cycles_per_second_ = cycles_per_second; set_needs_updated_filter_coefficients(); } @@ -85,19 +85,19 @@ class Speaker { */ void set_high_frequency_cut_off(float high_frequency) { - _high_frequency_cut_off = high_frequency; + high_frequency_cut_off_ = high_frequency; set_needs_updated_filter_coefficients(); } - Speaker() : _buffer_in_progress_pointer(0), _requested_number_of_taps(0), _high_frequency_cut_off(-1.0), _queue(new Concurrency::AsyncTaskQueue) {} + Speaker() : buffer_in_progress_pointer_(0), requested_number_of_taps_(0), high_frequency_cut_off_(-1.0), _queue(new Concurrency::AsyncTaskQueue) {} /*! Ensures any deferred processing occurs now. */ void flush() { - std::shared_ptr>> queued_functions = _queued_functions; - _queued_functions.reset(); + std::shared_ptr>> queued_functions = queued_functions_; + queued_functions_.reset(); _queue->enqueue([queued_functions] { for(auto function : *queued_functions) { @@ -109,24 +109,24 @@ class Speaker { protected: void enqueue(std::function function) { - if(!_queued_functions) _queued_functions.reset(new std::list>); - _queued_functions->push_back(function); + if(!queued_functions_) queued_functions_.reset(new std::list>); + queued_functions_->push_back(function); } - std::shared_ptr>> _queued_functions; + std::shared_ptr>> queued_functions_; - std::unique_ptr _buffer_in_progress; - float _high_frequency_cut_off; - int _buffer_size; - int _buffer_in_progress_pointer; - int _number_of_taps, _requested_number_of_taps; - bool _coefficients_are_dirty; - Delegate *_delegate; + std::unique_ptr buffer_in_progress_; + float high_frequency_cut_off_; + int buffer_size_; + int buffer_in_progress_pointer_; + int number_of_taps_, requested_number_of_taps_; + bool coefficients_are_dirty_; + Delegate *delegate_; - float _input_cycles_per_second, _output_cycles_per_second; + float input_cycles_per_second_, output_cycles_per_second_; void set_needs_updated_filter_coefficients() { - _coefficients_are_dirty = true; + coefficients_are_dirty_ = true; } void get_samples(unsigned int quantity, int16_t *target) {} @@ -160,26 +160,26 @@ template class Filter: public Speaker { { enqueue([=]() { unsigned int cycles_remaining = input_cycles; - if(_coefficients_are_dirty) update_filter_coefficients(); + if(coefficients_are_dirty_) update_filter_coefficients(); // if input and output rates exactly match, just accumulate results and pass on - if(_input_cycles_per_second == _output_cycles_per_second && _high_frequency_cut_off < 0.0) + if(input_cycles_per_second_ == output_cycles_per_second_ && high_frequency_cut_off_ < 0.0) { while(cycles_remaining) { - unsigned int cycles_to_read = (unsigned int)(_buffer_size - _buffer_in_progress_pointer); + unsigned int cycles_to_read = (unsigned int)(buffer_size_ - buffer_in_progress_pointer_); if(cycles_to_read > cycles_remaining) cycles_to_read = cycles_remaining; - static_cast(this)->get_samples(cycles_to_read, &_buffer_in_progress.get()[_buffer_in_progress_pointer]); - _buffer_in_progress_pointer += cycles_to_read; + static_cast(this)->get_samples(cycles_to_read, &buffer_in_progress_.get()[buffer_in_progress_pointer_]); + buffer_in_progress_pointer_ += cycles_to_read; // announce to delegate if full - if(_buffer_in_progress_pointer == _buffer_size) + if(buffer_in_progress_pointer_ == buffer_size_) { - _buffer_in_progress_pointer = 0; - if(_delegate) + buffer_in_progress_pointer_ = 0; + if(delegate_) { - _delegate->speaker_did_complete_samples(this, _buffer_in_progress.get(), _buffer_size); + delegate_->speaker_did_complete_samples(this, buffer_in_progress_.get(), buffer_size_); } } @@ -190,45 +190,45 @@ template class Filter: public Speaker { } // if the output rate is less than the input rate, use the filter - if(_input_cycles_per_second > _output_cycles_per_second) + if(input_cycles_per_second_ > output_cycles_per_second_) { while(cycles_remaining) { - unsigned int cycles_to_read = (unsigned int)std::min((int)cycles_remaining, _number_of_taps - _input_buffer_depth); - static_cast(this)->get_samples(cycles_to_read, &_input_buffer.get()[_input_buffer_depth]); + unsigned int cycles_to_read = (unsigned int)std::min((int)cycles_remaining, number_of_taps_ - input_buffer_depth_); + static_cast(this)->get_samples(cycles_to_read, &input_buffer_.get()[input_buffer_depth_]); cycles_remaining -= cycles_to_read; - _input_buffer_depth += cycles_to_read; + input_buffer_depth_ += cycles_to_read; - if(_input_buffer_depth == _number_of_taps) + if(input_buffer_depth_ == number_of_taps_) { - _buffer_in_progress.get()[_buffer_in_progress_pointer] = _filter->apply(_input_buffer.get()); - _buffer_in_progress_pointer++; + buffer_in_progress_.get()[buffer_in_progress_pointer_] = filter_->apply(input_buffer_.get()); + buffer_in_progress_pointer_++; // announce to delegate if full - if(_buffer_in_progress_pointer == _buffer_size) + if(buffer_in_progress_pointer_ == buffer_size_) { - _buffer_in_progress_pointer = 0; - if(_delegate) + buffer_in_progress_pointer_ = 0; + if(delegate_) { - _delegate->speaker_did_complete_samples(this, _buffer_in_progress.get(), _buffer_size); + delegate_->speaker_did_complete_samples(this, buffer_in_progress_.get(), buffer_size_); } } // If the next loop around is going to reuse some of the samples just collected, use a memmove to // preserve them in the correct locations (TODO: use a longer buffer to fix that) and don't skip // anything. Otherwise skip as required to get to the next sample batch and don't expect to reuse. - uint64_t steps = _stepper->step(); - if(steps < _number_of_taps) + uint64_t steps = stepper_->step(); + if(steps < number_of_taps_) { - int16_t *input_buffer = _input_buffer.get(); - memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * ((size_t)_number_of_taps - (size_t)steps)); - _input_buffer_depth -= steps; + int16_t *input_buffer = input_buffer_.get(); + memmove(input_buffer, &input_buffer[steps], sizeof(int16_t) * ((size_t)number_of_taps_ - (size_t)steps)); + input_buffer_depth_ -= steps; } else { - if(steps > _number_of_taps) - static_cast(this)->skip_samples((unsigned int)steps - (unsigned int)_number_of_taps); - _input_buffer_depth = 0; + if(steps > number_of_taps_) + static_cast(this)->skip_samples((unsigned int)steps - (unsigned int)number_of_taps_); + input_buffer_depth_ = 0; } } } @@ -241,44 +241,44 @@ template class Filter: public Speaker { } private: - std::unique_ptr _stepper; - std::unique_ptr _filter; + std::unique_ptr stepper_; + std::unique_ptr filter_; - std::unique_ptr _input_buffer; - int _input_buffer_depth; + std::unique_ptr input_buffer_; + int input_buffer_depth_; void update_filter_coefficients() { // make a guess at a good number of taps if this hasn't been provided explicitly - if(_requested_number_of_taps) + if(requested_number_of_taps_) { - _number_of_taps = _requested_number_of_taps; + number_of_taps_ = requested_number_of_taps_; } else { - _number_of_taps = (int)ceilf((_input_cycles_per_second + _output_cycles_per_second) / _output_cycles_per_second); - _number_of_taps *= 2; - _number_of_taps |= 1; + number_of_taps_ = (int)ceilf((input_cycles_per_second_ + output_cycles_per_second_) / output_cycles_per_second_); + number_of_taps_ *= 2; + number_of_taps_ |= 1; } - _coefficients_are_dirty = false; - _buffer_in_progress_pointer = 0; + coefficients_are_dirty_ = false; + buffer_in_progress_pointer_ = 0; - _stepper.reset(new SignalProcessing::Stepper((uint64_t)_input_cycles_per_second, (uint64_t)_output_cycles_per_second)); + stepper_.reset(new SignalProcessing::Stepper((uint64_t)input_cycles_per_second_, (uint64_t)output_cycles_per_second_)); float high_pass_frequency; - if(_high_frequency_cut_off > 0.0) + if(high_frequency_cut_off_ > 0.0) { - high_pass_frequency = std::min((float)_output_cycles_per_second / 2.0f, _high_frequency_cut_off); + high_pass_frequency = std::min((float)output_cycles_per_second_ / 2.0f, high_frequency_cut_off_); } else { - high_pass_frequency = (float)_output_cycles_per_second / 2.0f; + high_pass_frequency = (float)output_cycles_per_second_ / 2.0f; } - _filter.reset(new SignalProcessing::FIRFilter((unsigned int)_number_of_taps, (float)_input_cycles_per_second, 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation)); + filter_.reset(new SignalProcessing::FIRFilter((unsigned int)number_of_taps_, (float)input_cycles_per_second_, 0.0, high_pass_frequency, SignalProcessing::FIRFilter::DefaultAttenuation)); - _input_buffer.reset(new int16_t[_number_of_taps]); - _input_buffer_depth = 0; + input_buffer_.reset(new int16_t[number_of_taps_]); + input_buffer_depth_ = 0; } }; diff --git a/Processors/6502/CPU6502.hpp b/Processors/6502/CPU6502.hpp index 3d6903f24..9f1b4e125 100644 --- a/Processors/6502/CPU6502.hpp +++ b/Processors/6502/CPU6502.hpp @@ -141,15 +141,15 @@ template class Processor { /* Storage for the 6502 registers; F is stored as individual flags. */ - RegisterPair _pc, _lastOperationPC; - uint8_t _a, _x, _y, _s; - uint8_t _carryFlag, _negativeResult, _zeroResult, _decimalFlag, _overflowFlag, _inverseInterruptFlag; + RegisterPair pc_, last_operation_pc_; + uint8_t a_, x_, y_, s_; + uint8_t carry_flag_, negative_result_, zero_result_, decimal_flag_, overflow_flag_, inverse_interrupt_flag_; /* Temporary state for the micro programs. */ - uint8_t _operation, _operand; - RegisterPair _address, _nextAddress; + uint8_t operation_, operand_; + RegisterPair address_, next_address_; /* Up to four programs can be scheduled; each will be carried out in turn. This @@ -158,16 +158,16 @@ template class Processor { Programs should be terminated by an OperationMoveToNextProgram, causing this queue to take that step. */ - const MicroOp *_scheduledPrograms[4]; - unsigned int _scheduleProgramsWritePointer, _scheduleProgramsReadPointer, _scheduleProgramProgramCounter; + const MicroOp *scheduled_programs_[4]; + unsigned int schedule_programs_write_pointer_, schedule_programs_read_pointer_, schedule_program_program_counter_; /* Temporary storage allowing a common dispatch point for calling perform_bus_operation; possibly deferring is no longer of value. */ - BusOperation _nextBusOperation; - uint16_t _busAddress; - uint8_t *_busValue; + BusOperation next_bus_operation_; + uint16_t bus_address_; + uint8_t *bus_value_; /*! Schedules a new program, adding it to the end of the queue. Programs should be @@ -178,8 +178,8 @@ template class Processor { */ inline void schedule_program(const MicroOp *program) { - _scheduledPrograms[_scheduleProgramsWritePointer] = program; - _scheduleProgramsWritePointer = (_scheduleProgramsWritePointer+1)&3; + scheduled_programs_[schedule_programs_write_pointer_] = program; + schedule_programs_write_pointer_ = (schedule_programs_write_pointer_+1)&3; } /*! @@ -191,7 +191,7 @@ template class Processor { */ uint8_t get_flags() { - return _carryFlag | _overflowFlag | (_inverseInterruptFlag ^ Flag::Interrupt) | (_negativeResult & 0x80) | (_zeroResult ? 0 : Flag::Zero) | Flag::Always | _decimalFlag; + return carry_flag_ | overflow_flag_ | (inverse_interrupt_flag_ ^ Flag::Interrupt) | (negative_result_ & 0x80) | (zero_result_ ? 0 : Flag::Zero) | Flag::Always | decimal_flag_; } /*! @@ -203,12 +203,12 @@ template class Processor { */ void set_flags(uint8_t flags) { - _carryFlag = flags & Flag::Carry; - _negativeResult = flags & Flag::Sign; - _zeroResult = (~flags) & Flag::Zero; - _overflowFlag = flags & Flag::Overflow; - _inverseInterruptFlag = (~flags) & Flag::Interrupt; - _decimalFlag = flags & Flag::Decimal; + carry_flag_ = flags & Flag::Carry; + negative_result_ = flags & Flag::Sign; + zero_result_ = (~flags) & Flag::Zero; + overflow_flag_ = flags & Flag::Overflow; + inverse_interrupt_flag_ = (~flags) & Flag::Interrupt; + decimal_flag_ = flags & Flag::Decimal; } /*! @@ -454,10 +454,10 @@ template class Processor { schedule_program(operations[operation]); } - bool _is_jammed; - JamHandler *_jam_handler; + bool is_jammed_; + JamHandler *jam_handler_; - int _cycles_left_to_run; + int cycles_left_to_run_; enum InterruptRequestFlags: uint8_t { Reset = 0x80, @@ -466,13 +466,13 @@ template class Processor { PowerOn = 0x10, }; - uint8_t _interrupt_requests; + uint8_t interrupt_requests_; - bool _ready_is_active; - bool _ready_line_is_enabled; + bool ready_is_active_; + bool ready_line_is_enabled_; - uint8_t _irq_line, _irq_request_history; - bool _nmi_line_is_enabled, _set_overflow_line_is_enabled; + uint8_t irq_line_, irq_request_history_; + bool nmi_line_is_enabled_, set_overflow_line_is_enabled_; /*! Gets the program representing an RST response. @@ -539,27 +539,27 @@ template class Processor { protected: Processor() : - _scheduleProgramsReadPointer(0), - _scheduleProgramsWritePointer(0), - _is_jammed(false), - _jam_handler(nullptr), - _cycles_left_to_run(0), - _ready_line_is_enabled(false), - _ready_is_active(false), - _scheduledPrograms{nullptr, nullptr, nullptr, nullptr}, - _inverseInterruptFlag(0), - _s(0), - _nextBusOperation(BusOperation::None), - _interrupt_requests(InterruptRequestFlags::PowerOn), - _irq_line(0), - _nmi_line_is_enabled(false), - _set_overflow_line_is_enabled(false) + schedule_programs_read_pointer_(0), + schedule_programs_write_pointer_(0), + is_jammed_(false), + jam_handler_(nullptr), + cycles_left_to_run_(0), + ready_line_is_enabled_(false), + ready_is_active_(false), + scheduled_programs_{nullptr, nullptr, nullptr, nullptr}, + inverse_interrupt_flag_(0), + s_(0), + next_bus_operation_(BusOperation::None), + interrupt_requests_(InterruptRequestFlags::PowerOn), + irq_line_(0), + nmi_line_is_enabled_(false), + set_overflow_line_is_enabled_(false) { // only the interrupt flag is defined upon reset but get_flags isn't going to // mask the other flags so we need to do that, at least - _carryFlag &= Flag::Carry; - _decimalFlag &= Flag::Decimal; - _overflowFlag &= Flag::Overflow; + carry_flag_ &= Flag::Carry; + decimal_flag_ &= Flag::Decimal; + overflow_flag_ &= Flag::Overflow; } public: @@ -590,24 +590,24 @@ template class Processor { // These plus program below act to give the compiler permission to update these values // without touching the class storage (i.e. it explicitly says they need be completely up // to date in this stack frame only); which saves some complicated addressing - unsigned int scheduleProgramsReadPointer = _scheduleProgramsReadPointer; - unsigned int scheduleProgramProgramCounter = _scheduleProgramProgramCounter; - RegisterPair nextAddress = _nextAddress; - BusOperation nextBusOperation = _nextBusOperation; - uint16_t busAddress = _busAddress; - uint8_t *busValue = _busValue; + unsigned int scheduleProgramsReadPointer = schedule_programs_read_pointer_; + unsigned int scheduleProgramProgramCounter = schedule_program_program_counter_; + RegisterPair nextAddress = next_address_; + BusOperation nextBusOperation = next_bus_operation_; + uint16_t busAddress = bus_address_; + uint8_t *busValue = bus_value_; #define checkSchedule(op) \ - if(!_scheduledPrograms[scheduleProgramsReadPointer]) {\ - scheduleProgramsReadPointer = _scheduleProgramsWritePointer = scheduleProgramProgramCounter = 0;\ - if(_interrupt_requests) {\ - if(_interrupt_requests & (InterruptRequestFlags::Reset | InterruptRequestFlags::PowerOn)) {\ - _interrupt_requests &= ~InterruptRequestFlags::PowerOn;\ + if(!scheduled_programs_[scheduleProgramsReadPointer]) {\ + scheduleProgramsReadPointer = schedule_programs_write_pointer_ = scheduleProgramProgramCounter = 0;\ + if(interrupt_requests_) {\ + if(interrupt_requests_ & (InterruptRequestFlags::Reset | InterruptRequestFlags::PowerOn)) {\ + interrupt_requests_ &= ~InterruptRequestFlags::PowerOn;\ schedule_program(get_reset_program());\ - } else if(_interrupt_requests & InterruptRequestFlags::NMI) {\ - _interrupt_requests &= ~InterruptRequestFlags::NMI;\ + } else if(interrupt_requests_ & InterruptRequestFlags::NMI) {\ + interrupt_requests_ &= ~InterruptRequestFlags::NMI;\ schedule_program(get_nmi_program());\ - } else if(_interrupt_requests & InterruptRequestFlags::IRQ) {\ + } else if(interrupt_requests_ & InterruptRequestFlags::IRQ) {\ schedule_program(get_irq_program());\ } \ } else {\ @@ -617,23 +617,23 @@ template class Processor { } #define bus_access() \ - _interrupt_requests = (_interrupt_requests & ~InterruptRequestFlags::IRQ) | _irq_request_history; \ - _irq_request_history = _irq_line & _inverseInterruptFlag; \ + interrupt_requests_ = (interrupt_requests_ & ~InterruptRequestFlags::IRQ) | irq_request_history_; \ + irq_request_history_ = irq_line_ & inverse_interrupt_flag_; \ number_of_cycles -= static_cast(this)->perform_bus_operation(nextBusOperation, busAddress, busValue); \ nextBusOperation = BusOperation::None; \ if(number_of_cycles <= 0) break; checkSchedule(); - number_of_cycles += _cycles_left_to_run; - const MicroOp *program = _scheduledPrograms[scheduleProgramsReadPointer]; + number_of_cycles += cycles_left_to_run_; + const MicroOp *program = scheduled_programs_[scheduleProgramsReadPointer]; while(number_of_cycles > 0) { - while (_ready_is_active && number_of_cycles > 0) { + while (ready_is_active_ && number_of_cycles > 0) { number_of_cycles -= static_cast(this)->perform_bus_operation(BusOperation::Ready, busAddress, busValue); } - if(!_ready_is_active) + if(!ready_is_active_) { if(nextBusOperation != BusOperation::None) { @@ -655,414 +655,414 @@ template class Processor { #pragma mark - Fetch/Decode case CycleFetchOperation: { - _lastOperationPC = _pc; -// printf("%04x x:%02x\n", _pc.full, _x); - _pc.full++; - read_op(_operation, _lastOperationPC.full); + last_operation_pc_ = pc_; +// printf("%04x x:%02x\n", pc_.full, x_); + pc_.full++; + read_op(operation_, last_operation_pc_.full); // static int last_cycles_left_to_run = 0; // static bool printed_map[256] = {false}; -// if(!printed_map[_operation]) { -// printed_map[_operation] = true; -// if(last_cycles_left_to_run > _cycles_left_to_run) -// printf("%02x %d\n", _operation, last_cycles_left_to_run - _cycles_left_to_run); +// if(!printed_map[operation_]) { +// printed_map[operation_] = true; +// if(last_cycles_left_to_run > cycles_left_to_run_) +// printf("%02x %d\n", operation_, last_cycles_left_to_run - cycles_left_to_run_); // else -// printf("%02x\n", _operation); +// printf("%02x\n", operation_); // } -// last_cycles_left_to_run = _cycles_left_to_run; +// last_cycles_left_to_run = cycles_left_to_run_; } break; case CycleFetchOperand: - read_mem(_operand, _pc.full); + read_mem(operand_, pc_.full); break; case OperationDecodeOperation: -// printf("d %02x\n", _operation); - decode_operation(_operation); +// printf("d %02x\n", operation_); + decode_operation(operation_); continue; case OperationMoveToNextProgram: - _scheduledPrograms[scheduleProgramsReadPointer] = NULL; + scheduled_programs_[scheduleProgramsReadPointer] = NULL; scheduleProgramsReadPointer = (scheduleProgramsReadPointer+1)&3; scheduleProgramProgramCounter = 0; checkSchedule(); - program = _scheduledPrograms[scheduleProgramsReadPointer]; + program = scheduled_programs_[scheduleProgramsReadPointer]; continue; #define push(v) \ {\ - uint16_t targetAddress = _s | 0x100; _s--;\ + uint16_t targetAddress = s_ | 0x100; s_--;\ write_mem(v, targetAddress);\ } - case CycleIncPCPushPCH: _pc.full++; // deliberate fallthrough - case CyclePushPCH: push(_pc.bytes.high); break; - case CyclePushPCL: push(_pc.bytes.low); break; - case CyclePushOperand: push(_operand); break; - case CyclePushA: push(_a); break; + case CycleIncPCPushPCH: pc_.full++; // deliberate fallthrough + case CyclePushPCH: push(pc_.bytes.high); break; + case CyclePushPCL: push(pc_.bytes.low); break; + case CyclePushOperand: push(operand_); break; + case CyclePushA: push(a_); break; case CycleNoWritePush: { - uint16_t targetAddress = _s | 0x100; _s--; - read_mem(_operand, targetAddress); + uint16_t targetAddress = s_ | 0x100; s_--; + read_mem(operand_, targetAddress); } break; #undef push - case CycleReadFromS: throwaway_read(_s | 0x100); break; - case CycleReadFromPC: throwaway_read(_pc.full); break; + case CycleReadFromS: throwaway_read(s_ | 0x100); break; + case CycleReadFromPC: throwaway_read(pc_.full); break; case OperationBRKPickVector: // NMI can usurp BRK-vector operations - nextAddress.full = (_interrupt_requests & InterruptRequestFlags::NMI) ? 0xfffa : 0xfffe; - _interrupt_requests &= ~InterruptRequestFlags::NMI; // TODO: this probably doesn't happen now? + nextAddress.full = (interrupt_requests_ & InterruptRequestFlags::NMI) ? 0xfffa : 0xfffe; + interrupt_requests_ &= ~InterruptRequestFlags::NMI; // TODO: this probably doesn't happen now? continue; case OperationNMIPickVector: nextAddress.full = 0xfffa; continue; case OperationRSTPickVector: nextAddress.full = 0xfffc; continue; - case CycleReadVectorLow: read_mem(_pc.bytes.low, nextAddress.full); break; - case CycleReadVectorHigh: read_mem(_pc.bytes.high, nextAddress.full+1); break; - case OperationSetI: _inverseInterruptFlag = 0; continue; + case CycleReadVectorLow: read_mem(pc_.bytes.low, nextAddress.full); break; + case CycleReadVectorHigh: read_mem(pc_.bytes.high, nextAddress.full+1); break; + case OperationSetI: inverse_interrupt_flag_ = 0; continue; - case CyclePullPCL: _s++; read_mem(_pc.bytes.low, _s | 0x100); break; - case CyclePullPCH: _s++; read_mem(_pc.bytes.high, _s | 0x100); break; - case CyclePullA: _s++; read_mem(_a, _s | 0x100); break; - case CyclePullOperand: _s++; read_mem(_operand, _s | 0x100); break; - case OperationSetFlagsFromOperand: set_flags(_operand); continue; - case OperationSetOperandFromFlagsWithBRKSet: _operand = get_flags() | Flag::Break; continue; - case OperationSetOperandFromFlags: _operand = get_flags(); continue; - case OperationSetFlagsFromA: _zeroResult = _negativeResult = _a; continue; + case CyclePullPCL: s_++; read_mem(pc_.bytes.low, s_ | 0x100); break; + case CyclePullPCH: s_++; read_mem(pc_.bytes.high, s_ | 0x100); break; + case CyclePullA: s_++; read_mem(a_, s_ | 0x100); break; + case CyclePullOperand: s_++; read_mem(operand_, s_ | 0x100); break; + case OperationSetFlagsFromOperand: set_flags(operand_); continue; + case OperationSetOperandFromFlagsWithBRKSet: operand_ = get_flags() | Flag::Break; continue; + case OperationSetOperandFromFlags: operand_ = get_flags(); continue; + case OperationSetFlagsFromA: zero_result_ = negative_result_ = a_; continue; - case CycleIncrementPCAndReadStack: _pc.full++; throwaway_read(_s | 0x100); break; - case CycleReadPCLFromAddress: read_mem(_pc.bytes.low, _address.full); break; - case CycleReadPCHFromAddress: _address.bytes.low++; read_mem(_pc.bytes.high, _address.full); break; + case CycleIncrementPCAndReadStack: pc_.full++; throwaway_read(s_ | 0x100); break; + case CycleReadPCLFromAddress: read_mem(pc_.bytes.low, address_.full); break; + case CycleReadPCHFromAddress: address_.bytes.low++; read_mem(pc_.bytes.high, address_.full); break; case CycleReadAndIncrementPC: { - uint16_t oldPC = _pc.full; - _pc.full++; + uint16_t oldPC = pc_.full; + pc_.full++; throwaway_read(oldPC); } break; #pragma mark - JAM case CycleScheduleJam: { - _is_jammed = true; + is_jammed_ = true; static const MicroOp jam[] = JAM; schedule_program(jam); - if(_jam_handler) { - _jam_handler->processor_did_jam(this, _pc.full - 1); - checkSchedule(_is_jammed = false; program = _scheduledPrograms[scheduleProgramsReadPointer]); + if(jam_handler_) { + jam_handler_->processor_did_jam(this, pc_.full - 1); + checkSchedule(is_jammed_ = false; program = scheduled_programs_[scheduleProgramsReadPointer]); } } continue; #pragma mark - Bitwise - case OperationORA: _a |= _operand; _negativeResult = _zeroResult = _a; continue; - case OperationAND: _a &= _operand; _negativeResult = _zeroResult = _a; continue; - case OperationEOR: _a ^= _operand; _negativeResult = _zeroResult = _a; continue; + case OperationORA: a_ |= operand_; negative_result_ = zero_result_ = a_; continue; + case OperationAND: a_ &= operand_; negative_result_ = zero_result_ = a_; continue; + case OperationEOR: a_ ^= operand_; negative_result_ = zero_result_ = a_; continue; #pragma mark - Load and Store - case OperationLDA: _a = _negativeResult = _zeroResult = _operand; continue; - case OperationLDX: _x = _negativeResult = _zeroResult = _operand; continue; - case OperationLDY: _y = _negativeResult = _zeroResult = _operand; continue; - case OperationLAX: _a = _x = _negativeResult = _zeroResult = _operand; continue; + case OperationLDA: a_ = negative_result_ = zero_result_ = operand_; continue; + case OperationLDX: x_ = negative_result_ = zero_result_ = operand_; continue; + case OperationLDY: y_ = negative_result_ = zero_result_ = operand_; continue; + case OperationLAX: a_ = x_ = negative_result_ = zero_result_ = operand_; continue; - case OperationSTA: _operand = _a; continue; - case OperationSTX: _operand = _x; continue; - case OperationSTY: _operand = _y; continue; - case OperationSAX: _operand = _a & _x; continue; - case OperationSHA: _operand = _a & _x & (_address.bytes.high+1); continue; - case OperationSHX: _operand = _x & (_address.bytes.high+1); continue; - case OperationSHY: _operand = _y & (_address.bytes.high+1); continue; - case OperationSHS: _s = _a & _x; _operand = _s & (_address.bytes.high+1); continue; + case OperationSTA: operand_ = a_; continue; + case OperationSTX: operand_ = x_; continue; + case OperationSTY: operand_ = y_; continue; + case OperationSAX: operand_ = a_ & x_; continue; + case OperationSHA: operand_ = a_ & x_ & (address_.bytes.high+1); continue; + case OperationSHX: operand_ = x_ & (address_.bytes.high+1); continue; + case OperationSHY: operand_ = y_ & (address_.bytes.high+1); continue; + case OperationSHS: s_ = a_ & x_; operand_ = s_ & (address_.bytes.high+1); continue; case OperationLXA: - _a = _x = (_a | 0xee) & _operand; - _negativeResult = _zeroResult = _a; + a_ = x_ = (a_ | 0xee) & operand_; + negative_result_ = zero_result_ = a_; continue; #pragma mark - Compare case OperationCMP: { - const uint16_t temp16 = _a - _operand; - _negativeResult = _zeroResult = (uint8_t)temp16; - _carryFlag = ((~temp16) >> 8)&1; + const uint16_t temp16 = a_ - operand_; + negative_result_ = zero_result_ = (uint8_t)temp16; + carry_flag_ = ((~temp16) >> 8)&1; } continue; case OperationCPX: { - const uint16_t temp16 = _x - _operand; - _negativeResult = _zeroResult = (uint8_t)temp16; - _carryFlag = ((~temp16) >> 8)&1; + const uint16_t temp16 = x_ - operand_; + negative_result_ = zero_result_ = (uint8_t)temp16; + carry_flag_ = ((~temp16) >> 8)&1; } continue; case OperationCPY: { - const uint16_t temp16 = _y - _operand; - _negativeResult = _zeroResult = (uint8_t)temp16; - _carryFlag = ((~temp16) >> 8)&1; + const uint16_t temp16 = y_ - operand_; + negative_result_ = zero_result_ = (uint8_t)temp16; + carry_flag_ = ((~temp16) >> 8)&1; } continue; #pragma mark - BIT case OperationBIT: - _zeroResult = _operand & _a; - _negativeResult = _operand; - _overflowFlag = _operand&Flag::Overflow; + zero_result_ = operand_ & a_; + negative_result_ = operand_; + overflow_flag_ = operand_&Flag::Overflow; continue; #pragma mark ADC/SBC (and INS) case OperationINS: - _operand++; // deliberate fallthrough + operand_++; // deliberate fallthrough case OperationSBC: - if(_decimalFlag) { - const uint16_t notCarry = _carryFlag ^ 0x1; - const uint16_t decimalResult = (uint16_t)_a - (uint16_t)_operand - notCarry; + if(decimal_flag_) { + const uint16_t notCarry = carry_flag_ ^ 0x1; + const uint16_t decimalResult = (uint16_t)a_ - (uint16_t)operand_ - notCarry; uint16_t temp16; - temp16 = (_a&0xf) - (_operand&0xf) - notCarry; + temp16 = (a_&0xf) - (operand_&0xf) - notCarry; if(temp16 > 0xf) temp16 -= 0x6; temp16 = (temp16&0x0f) | ((temp16 > 0x0f) ? 0xfff0 : 0x00); - temp16 += (_a&0xf0) - (_operand&0xf0); + temp16 += (a_&0xf0) - (operand_&0xf0); - _overflowFlag = ( ( (decimalResult^_a)&(~decimalResult^_operand) )&0x80) >> 1; - _negativeResult = (uint8_t)temp16; - _zeroResult = (uint8_t)decimalResult; + overflow_flag_ = ( ( (decimalResult^a_)&(~decimalResult^operand_) )&0x80) >> 1; + negative_result_ = (uint8_t)temp16; + zero_result_ = (uint8_t)decimalResult; if(temp16 > 0xff) temp16 -= 0x60; - _carryFlag = (temp16 > 0xff) ? 0 : Flag::Carry; - _a = (uint8_t)temp16; + carry_flag_ = (temp16 > 0xff) ? 0 : Flag::Carry; + a_ = (uint8_t)temp16; continue; } else { - _operand = ~_operand; + operand_ = ~operand_; } // deliberate fallthrough case OperationADC: - if(_decimalFlag) { - const uint16_t decimalResult = (uint16_t)_a + (uint16_t)_operand + (uint16_t)_carryFlag; + if(decimal_flag_) { + const uint16_t decimalResult = (uint16_t)a_ + (uint16_t)operand_ + (uint16_t)carry_flag_; - uint8_t low_nibble = (_a & 0xf) + (_operand & 0xf) + _carryFlag; + uint8_t low_nibble = (a_ & 0xf) + (operand_ & 0xf) + carry_flag_; if(low_nibble >= 0xa) low_nibble = ((low_nibble + 0x6) & 0xf) + 0x10; - uint16_t result = (uint16_t)(_a & 0xf0) + (uint16_t)(_operand & 0xf0) + (uint16_t)low_nibble; - _negativeResult = (uint8_t)result; - _overflowFlag = (( (result^_a)&(result^_operand) )&0x80) >> 1; + uint16_t result = (uint16_t)(a_ & 0xf0) + (uint16_t)(operand_ & 0xf0) + (uint16_t)low_nibble; + negative_result_ = (uint8_t)result; + overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1; if(result >= 0xa0) result += 0x60; - _carryFlag = (result >> 8) ? 1 : 0; - _a = (uint8_t)result; - _zeroResult = (uint8_t)decimalResult; + carry_flag_ = (result >> 8) ? 1 : 0; + a_ = (uint8_t)result; + zero_result_ = (uint8_t)decimalResult; } else { - const uint16_t result = (uint16_t)_a + (uint16_t)_operand + (uint16_t)_carryFlag; - _overflowFlag = (( (result^_a)&(result^_operand) )&0x80) >> 1; - _negativeResult = _zeroResult = _a = (uint8_t)result; - _carryFlag = (result >> 8)&1; + const uint16_t result = (uint16_t)a_ + (uint16_t)operand_ + (uint16_t)carry_flag_; + overflow_flag_ = (( (result^a_)&(result^operand_) )&0x80) >> 1; + negative_result_ = zero_result_ = a_ = (uint8_t)result; + carry_flag_ = (result >> 8)&1; } // fix up in case this was INS - if(cycle == OperationINS) _operand = ~_operand; + if(cycle == OperationINS) operand_ = ~operand_; continue; #pragma mark - Shifts and Rolls case OperationASL: - _carryFlag = _operand >> 7; - _operand <<= 1; - _negativeResult = _zeroResult = _operand; + carry_flag_ = operand_ >> 7; + operand_ <<= 1; + negative_result_ = zero_result_ = operand_; continue; case OperationASO: - _carryFlag = _operand >> 7; - _operand <<= 1; - _a |= _operand; - _negativeResult = _zeroResult = _a; + carry_flag_ = operand_ >> 7; + operand_ <<= 1; + a_ |= operand_; + negative_result_ = zero_result_ = a_; continue; case OperationROL: { - const uint8_t temp8 = (uint8_t)((_operand << 1) | _carryFlag); - _carryFlag = _operand >> 7; - _operand = _negativeResult = _zeroResult = temp8; + const uint8_t temp8 = (uint8_t)((operand_ << 1) | carry_flag_); + carry_flag_ = operand_ >> 7; + operand_ = negative_result_ = zero_result_ = temp8; } continue; case OperationRLA: { - const uint8_t temp8 = (uint8_t)((_operand << 1) | _carryFlag); - _carryFlag = _operand >> 7; - _operand = temp8; - _a &= _operand; - _negativeResult = _zeroResult = _a; + const uint8_t temp8 = (uint8_t)((operand_ << 1) | carry_flag_); + carry_flag_ = operand_ >> 7; + operand_ = temp8; + a_ &= operand_; + negative_result_ = zero_result_ = a_; } continue; case OperationLSR: - _carryFlag = _operand & 1; - _operand >>= 1; - _negativeResult = _zeroResult = _operand; + carry_flag_ = operand_ & 1; + operand_ >>= 1; + negative_result_ = zero_result_ = operand_; continue; case OperationLSE: - _carryFlag = _operand & 1; - _operand >>= 1; - _a ^= _operand; - _negativeResult = _zeroResult = _a; + carry_flag_ = operand_ & 1; + operand_ >>= 1; + a_ ^= operand_; + negative_result_ = zero_result_ = a_; continue; case OperationASR: - _a &= _operand; - _carryFlag = _a & 1; - _a >>= 1; - _negativeResult = _zeroResult = _a; + a_ &= operand_; + carry_flag_ = a_ & 1; + a_ >>= 1; + negative_result_ = zero_result_ = a_; continue; case OperationROR: { - const uint8_t temp8 = (uint8_t)((_operand >> 1) | (_carryFlag << 7)); - _carryFlag = _operand & 1; - _operand = _negativeResult = _zeroResult = temp8; + const uint8_t temp8 = (uint8_t)((operand_ >> 1) | (carry_flag_ << 7)); + carry_flag_ = operand_ & 1; + operand_ = negative_result_ = zero_result_ = temp8; } continue; case OperationRRA: { - const uint8_t temp8 = (uint8_t)((_operand >> 1) | (_carryFlag << 7)); - _carryFlag = _operand & 1; - _operand = temp8; + const uint8_t temp8 = (uint8_t)((operand_ >> 1) | (carry_flag_ << 7)); + carry_flag_ = operand_ & 1; + operand_ = temp8; } continue; - case OperationDecrementOperand: _operand--; continue; - case OperationIncrementOperand: _operand++; continue; + case OperationDecrementOperand: operand_--; continue; + case OperationIncrementOperand: operand_++; continue; - case OperationCLC: _carryFlag = 0; continue; - case OperationCLI: _inverseInterruptFlag = Flag::Interrupt; continue; - case OperationCLV: _overflowFlag = 0; continue; - case OperationCLD: _decimalFlag = 0; continue; + case OperationCLC: carry_flag_ = 0; continue; + case OperationCLI: inverse_interrupt_flag_ = Flag::Interrupt; continue; + case OperationCLV: overflow_flag_ = 0; continue; + case OperationCLD: decimal_flag_ = 0; continue; - case OperationSEC: _carryFlag = Flag::Carry; continue; - case OperationSEI: _inverseInterruptFlag = 0; continue; - case OperationSED: _decimalFlag = Flag::Decimal; continue; + case OperationSEC: carry_flag_ = Flag::Carry; continue; + case OperationSEI: inverse_interrupt_flag_ = 0; continue; + case OperationSED: decimal_flag_ = Flag::Decimal; continue; - case OperationINC: _operand++; _negativeResult = _zeroResult = _operand; continue; - case OperationDEC: _operand--; _negativeResult = _zeroResult = _operand; continue; - case OperationINX: _x++; _negativeResult = _zeroResult = _x; continue; - case OperationDEX: _x--; _negativeResult = _zeroResult = _x; continue; - case OperationINY: _y++; _negativeResult = _zeroResult = _y; continue; - case OperationDEY: _y--; _negativeResult = _zeroResult = _y; continue; + case OperationINC: operand_++; negative_result_ = zero_result_ = operand_; continue; + case OperationDEC: operand_--; negative_result_ = zero_result_ = operand_; continue; + case OperationINX: x_++; negative_result_ = zero_result_ = x_; continue; + case OperationDEX: x_--; negative_result_ = zero_result_ = x_; continue; + case OperationINY: y_++; negative_result_ = zero_result_ = y_; continue; + case OperationDEY: y_--; negative_result_ = zero_result_ = y_; continue; case OperationANE: - _a = (_a | 0xee) & _operand & _x; - _negativeResult = _zeroResult = _a; + a_ = (a_ | 0xee) & operand_ & x_; + negative_result_ = zero_result_ = a_; continue; case OperationANC: - _a &= _operand; - _negativeResult = _zeroResult = _a; - _carryFlag = _a >> 7; + a_ &= operand_; + negative_result_ = zero_result_ = a_; + carry_flag_ = a_ >> 7; continue; case OperationLAS: - _a = _x = _s = _s & _operand; - _negativeResult = _zeroResult = _a; + a_ = x_ = s_ = s_ & operand_; + negative_result_ = zero_result_ = a_; continue; #pragma mark - Addressing Mode Work case CycleAddXToAddressLow: - nextAddress.full = _address.full + _x; - _address.bytes.low = nextAddress.bytes.low; - if(_address.bytes.high != nextAddress.bytes.high) { - throwaway_read(_address.full); + nextAddress.full = address_.full + x_; + address_.bytes.low = nextAddress.bytes.low; + if(address_.bytes.high != nextAddress.bytes.high) { + throwaway_read(address_.full); break; } continue; case CycleAddXToAddressLowRead: - nextAddress.full = _address.full + _x; - _address.bytes.low = nextAddress.bytes.low; - throwaway_read(_address.full); + nextAddress.full = address_.full + x_; + address_.bytes.low = nextAddress.bytes.low; + throwaway_read(address_.full); break; case CycleAddYToAddressLow: - nextAddress.full = _address.full + _y; - _address.bytes.low = nextAddress.bytes.low; - if(_address.bytes.high != nextAddress.bytes.high) { - throwaway_read(_address.full); + nextAddress.full = address_.full + y_; + address_.bytes.low = nextAddress.bytes.low; + if(address_.bytes.high != nextAddress.bytes.high) { + throwaway_read(address_.full); break; } continue; case CycleAddYToAddressLowRead: - nextAddress.full = _address.full + _y; - _address.bytes.low = nextAddress.bytes.low; - throwaway_read(_address.full); + nextAddress.full = address_.full + y_; + address_.bytes.low = nextAddress.bytes.low; + throwaway_read(address_.full); break; case OperationCorrectAddressHigh: - _address.full = nextAddress.full; + address_.full = nextAddress.full; continue; case CycleIncrementPCFetchAddressLowFromOperand: - _pc.full++; - read_mem(_address.bytes.low, _operand); + pc_.full++; + read_mem(address_.bytes.low, operand_); break; case CycleAddXToOperandFetchAddressLow: - _operand += _x; - read_mem(_address.bytes.low, _operand); + operand_ += x_; + read_mem(address_.bytes.low, operand_); break; case CycleIncrementOperandFetchAddressHigh: - _operand++; - read_mem(_address.bytes.high, _operand); + operand_++; + read_mem(address_.bytes.high, operand_); break; case CycleIncrementPCReadPCHLoadPCL: // deliberate fallthrough - _pc.full++; + pc_.full++; case CycleReadPCHLoadPCL: { - uint16_t oldPC = _pc.full; - _pc.bytes.low = _operand; - read_mem(_pc.bytes.high, oldPC); + uint16_t oldPC = pc_.full; + pc_.bytes.low = operand_; + read_mem(pc_.bytes.high, oldPC); } break; case CycleReadAddressHLoadAddressL: - _address.bytes.low = _operand; _pc.full++; - read_mem(_address.bytes.high, _pc.full); + address_.bytes.low = operand_; pc_.full++; + read_mem(address_.bytes.high, pc_.full); break; case CycleLoadAddressAbsolute: { - uint16_t nextPC = _pc.full+1; - _pc.full += 2; - _address.bytes.low = _operand; - read_mem(_address.bytes.high, nextPC); + uint16_t nextPC = pc_.full+1; + pc_.full += 2; + address_.bytes.low = operand_; + read_mem(address_.bytes.high, nextPC); } break; case OperationLoadAddressZeroPage: - _pc.full++; - _address.full = _operand; + pc_.full++; + address_.full = operand_; continue; case CycleLoadAddessZeroX: - _pc.full++; - _address.full = (_operand + _x)&0xff; - throwaway_read(_operand); + pc_.full++; + address_.full = (operand_ + x_)&0xff; + throwaway_read(operand_); break; case CycleLoadAddessZeroY: - _pc.full++; - _address.full = (_operand + _y)&0xff; - throwaway_read(_operand); + pc_.full++; + address_.full = (operand_ + y_)&0xff; + throwaway_read(operand_); break; - case OperationIncrementPC: _pc.full++; continue; - case CycleFetchOperandFromAddress: read_mem(_operand, _address.full); break; - case CycleWriteOperandToAddress: write_mem(_operand, _address.full); break; - case OperationCopyOperandFromA: _operand = _a; continue; - case OperationCopyOperandToA: _a = _operand; continue; + case OperationIncrementPC: pc_.full++; continue; + case CycleFetchOperandFromAddress: read_mem(operand_, address_.full); break; + case CycleWriteOperandToAddress: write_mem(operand_, address_.full); break; + case OperationCopyOperandFromA: operand_ = a_; continue; + case OperationCopyOperandToA: a_ = operand_; continue; #pragma mark - Branching -#define BRA(condition) _pc.full++; if(condition) schedule_program(doBranch) +#define BRA(condition) pc_.full++; if(condition) schedule_program(doBranch) - case OperationBPL: BRA(!(_negativeResult&0x80)); continue; - case OperationBMI: BRA(_negativeResult&0x80); continue; - case OperationBVC: BRA(!_overflowFlag); continue; - case OperationBVS: BRA(_overflowFlag); continue; - case OperationBCC: BRA(!_carryFlag); continue; - case OperationBCS: BRA(_carryFlag); continue; - case OperationBNE: BRA(_zeroResult); continue; - case OperationBEQ: BRA(!_zeroResult); continue; + case OperationBPL: BRA(!(negative_result_&0x80)); continue; + case OperationBMI: BRA(negative_result_&0x80); continue; + case OperationBVC: BRA(!overflow_flag_); continue; + case OperationBVS: BRA(overflow_flag_); continue; + case OperationBCC: BRA(!carry_flag_); continue; + case OperationBCS: BRA(carry_flag_); continue; + case OperationBNE: BRA(zero_result_); continue; + case OperationBEQ: BRA(!zero_result_); continue; case CycleAddSignedOperandToPC: - nextAddress.full = (uint16_t)(_pc.full + (int8_t)_operand); - _pc.bytes.low = nextAddress.bytes.low; - if(nextAddress.bytes.high != _pc.bytes.high) { - uint16_t halfUpdatedPc = _pc.full; - _pc.full = nextAddress.full; + nextAddress.full = (uint16_t)(pc_.full + (int8_t)operand_); + pc_.bytes.low = nextAddress.bytes.low; + if(nextAddress.bytes.high != pc_.bytes.high) { + uint16_t halfUpdatedPc = pc_.full; + pc_.full = nextAddress.full; throwaway_read(halfUpdatedPc); break; } @@ -1072,45 +1072,45 @@ template class Processor { #pragma mark - Transfers - case OperationTXA: _zeroResult = _negativeResult = _a = _x; continue; - case OperationTYA: _zeroResult = _negativeResult = _a = _y; continue; - case OperationTXS: _s = _x; continue; - case OperationTAY: _zeroResult = _negativeResult = _y = _a; continue; - case OperationTAX: _zeroResult = _negativeResult = _x = _a; continue; - case OperationTSX: _zeroResult = _negativeResult = _x = _s; continue; + case OperationTXA: zero_result_ = negative_result_ = a_ = x_; continue; + case OperationTYA: zero_result_ = negative_result_ = a_ = y_; continue; + case OperationTXS: s_ = x_; continue; + case OperationTAY: zero_result_ = negative_result_ = y_ = a_; continue; + case OperationTAX: zero_result_ = negative_result_ = x_ = a_; continue; + case OperationTSX: zero_result_ = negative_result_ = x_ = s_; continue; case OperationARR: - if(_decimalFlag) { - _a &= _operand; - uint8_t unshiftedA = _a; - _a = (uint8_t)((_a >> 1) | (_carryFlag << 7)); - _zeroResult = _negativeResult = _a; - _overflowFlag = (_a^(_a << 1))&Flag::Overflow; + if(decimal_flag_) { + a_ &= operand_; + uint8_t unshiftedA = a_; + a_ = (uint8_t)((a_ >> 1) | (carry_flag_ << 7)); + zero_result_ = negative_result_ = a_; + overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow; - if((unshiftedA&0xf) + (unshiftedA&0x1) > 5) _a = ((_a + 6)&0xf) | (_a & 0xf0); + if((unshiftedA&0xf) + (unshiftedA&0x1) > 5) a_ = ((a_ + 6)&0xf) | (a_ & 0xf0); - _carryFlag = ((unshiftedA&0xf0) + (unshiftedA&0x10) > 0x50) ? 1 : 0; - if(_carryFlag) _a += 0x60; + carry_flag_ = ((unshiftedA&0xf0) + (unshiftedA&0x10) > 0x50) ? 1 : 0; + if(carry_flag_) a_ += 0x60; } else { - _a &= _operand; - _a = (uint8_t)((_a >> 1) | (_carryFlag << 7)); - _negativeResult = _zeroResult = _a; - _carryFlag = (_a >> 6)&1; - _overflowFlag = (_a^(_a << 1))&Flag::Overflow; + a_ &= operand_; + a_ = (uint8_t)((a_ >> 1) | (carry_flag_ << 7)); + negative_result_ = zero_result_ = a_; + carry_flag_ = (a_ >> 6)&1; + overflow_flag_ = (a_^(a_ << 1))&Flag::Overflow; } continue; case OperationSBX: - _x &= _a; - uint16_t difference = _x - _operand; - _x = (uint8_t)difference; - _negativeResult = _zeroResult = _x; - _carryFlag = ((difference >> 8)&1)^1; + x_ &= a_; + uint16_t difference = x_ - operand_; + x_ = (uint8_t)difference; + negative_result_ = zero_result_ = x_; + carry_flag_ = ((difference >> 8)&1)^1; continue; } - if(_ready_line_is_enabled && isReadOperation(nextBusOperation)) { - _ready_is_active = true; + if(ready_line_is_enabled_ && isReadOperation(nextBusOperation)) { + ready_is_active_ = true; break; } bus_access(); @@ -1118,13 +1118,13 @@ template class Processor { } } - _cycles_left_to_run = number_of_cycles; - _scheduleProgramsReadPointer = scheduleProgramsReadPointer; - _scheduleProgramProgramCounter = scheduleProgramProgramCounter; - _nextAddress = nextAddress; - _nextBusOperation = nextBusOperation; - _busAddress = busAddress; - _busValue = busValue; + cycles_left_to_run_ = number_of_cycles; + schedule_programs_read_pointer_ = scheduleProgramsReadPointer; + schedule_program_program_counter_ = scheduleProgramProgramCounter; + next_address_ = nextAddress; + next_bus_operation_ = nextBusOperation; + bus_address_ = busAddress; + bus_value_ = busValue; static_cast(this)->synchronise(); } @@ -1147,14 +1147,14 @@ template class Processor { uint16_t get_value_of_register(Register r) { switch (r) { - case Register::ProgramCounter: return _pc.full; - case Register::LastOperationAddress: return _lastOperationPC.full; - case Register::StackPointer: return _s; + case Register::ProgramCounter: return pc_.full; + case Register::LastOperationAddress: return last_operation_pc_.full; + case Register::StackPointer: return s_; case Register::Flags: return get_flags(); - case Register::A: return _a; - case Register::X: return _x; - case Register::Y: return _y; - case Register::S: return _s; + case Register::A: return a_; + case Register::X: return x_; + case Register::Y: return y_; + case Register::S: return s_; default: return 0; } } @@ -1170,13 +1170,13 @@ template class Processor { void set_value_of_register(Register r, uint16_t value) { switch (r) { - case Register::ProgramCounter: _pc.full = value; break; - case Register::StackPointer: _s = (uint8_t)value; break; + case Register::ProgramCounter: pc_.full = value; break; + case Register::StackPointer: s_ = (uint8_t)value; break; case Register::Flags: set_flags((uint8_t)value); break; - case Register::A: _a = (uint8_t)value; break; - case Register::X: _x = (uint8_t)value; break; - case Register::Y: _y = (uint8_t)value; break; - case Register::S: _s = (uint8_t)value; break; + case Register::A: a_ = (uint8_t)value; break; + case Register::X: x_ = (uint8_t)value; break; + case Register::Y: y_ = (uint8_t)value; break; + case Register::S: s_ = (uint8_t)value; break; default: break; } } @@ -1187,13 +1187,13 @@ template class Processor { */ void return_from_subroutine() { - _s++; - static_cast(this)->perform_bus_operation(CPU6502::BusOperation::Read, 0x100 | _s, &_pc.bytes.low); _s++; - static_cast(this)->perform_bus_operation(CPU6502::BusOperation::Read, 0x100 | _s, &_pc.bytes.high); - _pc.full++; + s_++; + static_cast(this)->perform_bus_operation(CPU6502::BusOperation::Read, 0x100 | s_, &pc_.bytes.low); s_++; + static_cast(this)->perform_bus_operation(CPU6502::BusOperation::Read, 0x100 | s_, &pc_.bytes.high); + pc_.full++; - if(_is_jammed) { - _scheduledPrograms[0] = _scheduledPrograms[1] = _scheduledPrograms[2] = _scheduledPrograms[3] = nullptr; + if(is_jammed_) { + scheduled_programs_[0] = scheduled_programs_[1] = scheduled_programs_[2] = scheduled_programs_[3] = nullptr; } } @@ -1205,10 +1205,10 @@ template class Processor { inline void set_ready_line(bool active) { if(active) { - _ready_line_is_enabled = true; + ready_line_is_enabled_ = true; } else { - _ready_line_is_enabled = false; - _ready_is_active = false; + ready_line_is_enabled_ = false; + ready_is_active_ = false; } } @@ -1219,7 +1219,7 @@ template class Processor { */ inline void set_reset_line(bool active) { - _interrupt_requests = (_interrupt_requests & ~InterruptRequestFlags::Reset) | (active ? InterruptRequestFlags::Reset : 0); + interrupt_requests_ = (interrupt_requests_ & ~InterruptRequestFlags::Reset) | (active ? InterruptRequestFlags::Reset : 0); } /*! @@ -1229,7 +1229,7 @@ template class Processor { */ inline bool get_is_resetting() { - return !!(_interrupt_requests & (InterruptRequestFlags::Reset | InterruptRequestFlags::PowerOn)); + return !!(interrupt_requests_ & (InterruptRequestFlags::Reset | InterruptRequestFlags::PowerOn)); } /*! @@ -1238,7 +1238,7 @@ template class Processor { */ inline void set_power_on(bool active) { - _interrupt_requests = (_interrupt_requests & ~InterruptRequestFlags::PowerOn) | (active ? InterruptRequestFlags::PowerOn : 0); + interrupt_requests_ = (interrupt_requests_ & ~InterruptRequestFlags::PowerOn) | (active ? InterruptRequestFlags::PowerOn : 0); } /*! @@ -1248,7 +1248,7 @@ template class Processor { */ inline void set_irq_line(bool active) { - _irq_line = active ? Flag::Interrupt : 0; + irq_line_ = active ? Flag::Interrupt : 0; } /*! @@ -1259,9 +1259,9 @@ template class Processor { inline void set_overflow_line(bool active) { // a leading edge will set the overflow flag - if(active && !_set_overflow_line_is_enabled) - _overflowFlag = Flag::Overflow; - _set_overflow_line_is_enabled = active; + if(active && !set_overflow_line_is_enabled_) + overflow_flag_ = Flag::Overflow; + set_overflow_line_is_enabled_ = active; } /*! @@ -1272,9 +1272,9 @@ template class Processor { inline void set_nmi_line(bool active) { // NMI is edge triggered, not level - if(active && !_nmi_line_is_enabled) - _interrupt_requests |= InterruptRequestFlags::NMI; - _nmi_line_is_enabled = active; + if(active && !nmi_line_is_enabled_) + interrupt_requests_ |= InterruptRequestFlags::NMI; + nmi_line_is_enabled_ = active; } /*! @@ -1285,7 +1285,7 @@ template class Processor { */ inline bool is_jammed() { - return _is_jammed; + return is_jammed_; } /*! @@ -1295,7 +1295,7 @@ template class Processor { */ inline void set_jam_handler(JamHandler *handler) { - _jam_handler = handler; + jam_handler_ = handler; } }; diff --git a/Storage/Cartridge/Cartridge.hpp b/Storage/Cartridge/Cartridge.hpp index 19e4a48d2..50ce20830 100644 --- a/Storage/Cartridge/Cartridge.hpp +++ b/Storage/Cartridge/Cartridge.hpp @@ -51,10 +51,10 @@ class Cartridge { std::vector data; }; - const std::list &get_segments() { return _segments; } + const std::list &get_segments() { return segments_; } protected: - std::list _segments; + std::list segments_; }; } diff --git a/Storage/Cartridge/Formats/BinaryDump.cpp b/Storage/Cartridge/Formats/BinaryDump.cpp index 37e2a8ea7..4d3d8a111 100644 --- a/Storage/Cartridge/Formats/BinaryDump.cpp +++ b/Storage/Cartridge/Formats/BinaryDump.cpp @@ -28,7 +28,7 @@ BinaryDump::BinaryDump(const char *file_name) fclose(file); // enshrine - _segments.emplace_back( + segments_.emplace_back( ::Storage::Cartridge::Cartridge::Segment::UnknownAddress, ::Storage::Cartridge::Cartridge::Segment::UnknownAddress, std::move(contents)); diff --git a/Storage/Cartridge/Formats/PRG.cpp b/Storage/Cartridge/Formats/PRG.cpp index 43b5c85df..ac787e75c 100644 --- a/Storage/Cartridge/Formats/PRG.cpp +++ b/Storage/Cartridge/Formats/PRG.cpp @@ -46,5 +46,5 @@ PRG::PRG(const char *file_name) if(!Storage::Cartridge::Encodings::CommodoreROM::isROM(contents)) throw ErrorNotROM; - _segments.emplace_back(0xa000, 0xa000 + data_length, std::move(contents)); + segments_.emplace_back(0xa000, 0xa000 + data_length, std::move(contents)); } diff --git a/Storage/Disk/DigitalPhaseLockedLoop.cpp b/Storage/Disk/DigitalPhaseLockedLoop.cpp index d397ffaef..4f806fcc1 100644 --- a/Storage/Disk/DigitalPhaseLockedLoop.cpp +++ b/Storage/Disk/DigitalPhaseLockedLoop.cpp @@ -13,58 +13,58 @@ using namespace Storage; DigitalPhaseLockedLoop::DigitalPhaseLockedLoop(int clocks_per_bit, int tolerance, size_t length_of_history) : - _clocks_per_bit(clocks_per_bit), - _tolerance(tolerance), + clocks_per_bit_(clocks_per_bit), + tolerance_(tolerance), - _phase(0), - _window_length(clocks_per_bit), + phase_(0), + window_length_(clocks_per_bit), - _phase_error_pointer(0) + phase_error_pointer_(0) { - _phase_error_history.reset(new std::vector(length_of_history, 0)); + phase_error_history_.reset(new std::vector(length_of_history, 0)); } void DigitalPhaseLockedLoop::run_for_cycles(int number_of_cycles) { - _phase += number_of_cycles; - if(_phase >= _window_length) + phase_ += number_of_cycles; + if(phase_ >= window_length_) { - int windows_crossed = _phase / _window_length; + int windows_crossed = phase_ / window_length_; // check whether this triggers any 0s, if anybody cares - if(_delegate) + if(delegate_) { - if(_window_was_filled) windows_crossed--; + if(window_was_filled_) windows_crossed--; for(int c = 0; c < windows_crossed; c++) - _delegate->digital_phase_locked_loop_output_bit(0); + delegate_->digital_phase_locked_loop_output_bit(0); } - _window_was_filled = false; - _phase %= _window_length; + window_was_filled_ = false; + phase_ %= window_length_; } } void DigitalPhaseLockedLoop::add_pulse() { - if(!_window_was_filled) + if(!window_was_filled_) { - if(_delegate) _delegate->digital_phase_locked_loop_output_bit(1); - _window_was_filled = true; - post_phase_error(_phase - (_window_length >> 1)); + if(delegate_) delegate_->digital_phase_locked_loop_output_bit(1); + window_was_filled_ = true; + post_phase_error(phase_ - (window_length_ >> 1)); } } void DigitalPhaseLockedLoop::post_phase_error(int error) { // use a simple spring mechanism as a lowpass filter for phase - _phase -= (error + 1) >> 1; + phase_ -= (error + 1) >> 1; // use the average of the last few errors to affect frequency - std::vector *phase_error_history = _phase_error_history.get(); + std::vector *phase_error_history = phase_error_history_.get(); size_t phase_error_history_size = phase_error_history->size(); - (*phase_error_history)[_phase_error_pointer] = error; - _phase_error_pointer = (_phase_error_pointer + 1)%phase_error_history_size; + (*phase_error_history)[phase_error_pointer_] = error; + phase_error_pointer_ = (phase_error_pointer_ + 1)%phase_error_history_size; int total_error = 0; for(size_t c = 0; c < phase_error_history_size; c++) @@ -72,6 +72,6 @@ void DigitalPhaseLockedLoop::post_phase_error(int error) total_error += (*phase_error_history)[c]; } int denominator = (int)(phase_error_history_size * 4); - _window_length += (total_error + (denominator >> 1)) / denominator; - _window_length = std::max(std::min(_window_length, _clocks_per_bit + _tolerance), _clocks_per_bit - _tolerance); + window_length_ += (total_error + (denominator >> 1)) / denominator; + window_length_ = std::max(std::min(window_length_, clocks_per_bit_ + tolerance_), clocks_per_bit_ - tolerance_); } diff --git a/Storage/Disk/DigitalPhaseLockedLoop.hpp b/Storage/Disk/DigitalPhaseLockedLoop.hpp index da257b445..9ecd660f2 100644 --- a/Storage/Disk/DigitalPhaseLockedLoop.hpp +++ b/Storage/Disk/DigitalPhaseLockedLoop.hpp @@ -46,22 +46,22 @@ class DigitalPhaseLockedLoop { }; void set_delegate(Delegate *delegate) { - _delegate = delegate; + delegate_ = delegate; } private: - Delegate *_delegate; + Delegate *delegate_; void post_phase_error(int error); - std::unique_ptr> _phase_error_history; - size_t _phase_error_pointer; + std::unique_ptr> phase_error_history_; + size_t phase_error_pointer_; - int _phase; - int _window_length; - bool _window_was_filled; + int phase_; + int window_length_; + bool window_was_filled_; - int _clocks_per_bit; - int _tolerance; + int clocks_per_bit_; + int tolerance_; }; } diff --git a/Storage/Disk/DiskController.cpp b/Storage/Disk/DiskController.cpp index 48fea4305..f8b727eca 100644 --- a/Storage/Disk/DiskController.cpp +++ b/Storage/Disk/DiskController.cpp @@ -11,14 +11,14 @@ using namespace Storage::Disk; Controller::Controller(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute) : - _clock_rate(clock_rate * clock_rate_multiplier), - _clock_rate_multiplier(clock_rate_multiplier), + clock_rate_(clock_rate * clock_rate_multiplier), + clock_rate_multiplier_(clock_rate_multiplier), TimedEventLoop(clock_rate * clock_rate_multiplier) { - _rotational_multiplier.length = 60; - _rotational_multiplier.clock_rate = revolutions_per_minute; - _rotational_multiplier.simplify(); + rotational_multiplier_.length = 60; + rotational_multiplier_.clock_rate = revolutions_per_minute; + rotational_multiplier_.simplify(); // seed this class with a PLL, any PLL, so that it's safe to assume non-nullptr later Time one; @@ -27,38 +27,38 @@ Controller::Controller(unsigned int clock_rate, unsigned int clock_rate_multipli void Controller::setup_track() { - _track = _drive->get_track(); + track_ = drive_->get_track(); Time offset; - if(_track && _time_into_track.length > 0) + if(track_ && time_into_track_.length > 0) { - Time time_found = _track->seek_to(_time_into_track).simplify(); - offset = (_time_into_track - time_found).simplify(); - _time_into_track = time_found; + Time time_found = track_->seek_to(time_into_track_).simplify(); + offset = (time_into_track_ - time_found).simplify(); + time_into_track_ = time_found; } else { - offset = _time_into_track; - _time_into_track.set_zero(); + offset = time_into_track_; + time_into_track_.set_zero(); } - reset_timer_to_offset(offset * _rotational_multiplier); + reset_timer_to_offset(offset * rotational_multiplier_); get_next_event(); } void Controller::run_for_cycles(int number_of_cycles) { - if(_drive && _drive->has_disk() && _motor_is_on) + if(drive_ && drive_->has_disk() && motor_is_on_) { - if(!_track) setup_track(); - number_of_cycles *= _clock_rate_multiplier; + if(!track_) setup_track(); + number_of_cycles *= clock_rate_multiplier_; while(number_of_cycles) { int cycles_until_next_event = (int)get_cycles_until_next_event(); int cycles_to_run_for = std::min(cycles_until_next_event, number_of_cycles); - _cycles_since_index_hole += (unsigned int)cycles_to_run_for; + cycles_since_index_hole_ += (unsigned int)cycles_to_run_for; number_of_cycles -= cycles_to_run_for; - _pll->run_for_cycles(cycles_to_run_for); + pll_->run_for_cycles(cycles_to_run_for); TimedEventLoop::run_for_cycles(cycles_to_run_for); } } @@ -68,31 +68,31 @@ void Controller::run_for_cycles(int number_of_cycles) void Controller::get_next_event() { - if(_track) - _current_event = _track->get_next_event(); + if(track_) + current_event_ = track_->get_next_event(); else { - _current_event.length.length = 1; - _current_event.length.clock_rate = 1; - _current_event.type = Track::Event::IndexHole; + current_event_.length.length = 1; + current_event_.length.clock_rate = 1; + current_event_.type = Track::Event::IndexHole; } // divide interval, which is in terms of a rotation of the disk, by rotation speed, and // convert it into revolutions per second - set_next_event_time_interval(_current_event.length * _rotational_multiplier); + set_next_event_time_interval(current_event_.length * rotational_multiplier_); } void Controller::process_next_event() { - switch(_current_event.type) + switch(current_event_.type) { case Track::Event::FluxTransition: - _pll->add_pulse(); - _time_into_track += _current_event.length; + pll_->add_pulse(); + time_into_track_ += current_event_.length; break; case Track::Event::IndexHole: - _cycles_since_index_hole = 0; - _time_into_track.set_zero(); + cycles_since_index_hole_ = 0; + time_into_track_.set_zero(); process_index_hole(); break; } @@ -103,57 +103,57 @@ void Controller::process_next_event() void Controller::set_expected_bit_length(Time bit_length) { - _bit_length = bit_length; + bit_length_ = bit_length; // this conversion doesn't need to be exact because there's a lot of variation to be taken // account of in rotation speed, air turbulence, etc, so a direct conversion will do - int clocks_per_bit = (int)((bit_length.length * _clock_rate) / bit_length.clock_rate); - _pll.reset(new DigitalPhaseLockedLoop(clocks_per_bit, clocks_per_bit / 5, 3)); - _pll->set_delegate(this); + int clocks_per_bit = (int)((bit_length.length * clock_rate_) / bit_length.clock_rate); + pll_.reset(new DigitalPhaseLockedLoop(clocks_per_bit, clocks_per_bit / 5, 3)); + pll_->set_delegate(this); } void Controller::digital_phase_locked_loop_output_bit(int value) { - process_input_bit(value, _cycles_since_index_hole); + process_input_bit(value, cycles_since_index_hole_); } #pragma mark - Drive actions bool Controller::get_is_track_zero() { - if(!_drive) return false; - return _drive->get_is_track_zero(); + if(!drive_) return false; + return drive_->get_is_track_zero(); } bool Controller::get_drive_is_ready() { - if(!_drive) return false; - return _drive->has_disk(); + if(!drive_) return false; + return drive_->has_disk(); } void Controller::step(int direction) { - if(_drive) _drive->step(direction); + if(drive_) drive_->step(direction); invalidate_track(); } void Controller::set_motor_on(bool motor_on) { - _motor_is_on = motor_on; + motor_is_on_ = motor_on; } bool Controller::get_motor_on() { - return _motor_is_on; + return motor_is_on_; } void Controller::set_drive(std::shared_ptr drive) { - _drive = drive; + drive_ = drive; invalidate_track(); } void Controller::invalidate_track() { - _track = nullptr; + track_ = nullptr; } diff --git a/Storage/Disk/DiskController.hpp b/Storage/Disk/DiskController.hpp index 67779c7e9..498e7bdca 100644 --- a/Storage/Disk/DiskController.hpp +++ b/Storage/Disk/DiskController.hpp @@ -81,20 +81,20 @@ class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop virtual bool get_drive_is_ready(); private: - Time _bit_length; - unsigned int _clock_rate; - unsigned int _clock_rate_multiplier; - Time _rotational_multiplier; + Time bit_length_; + unsigned int clock_rate_; + unsigned int clock_rate_multiplier_; + Time rotational_multiplier_; - std::shared_ptr _pll; - std::shared_ptr _drive; - std::shared_ptr _track; - unsigned int _cycles_since_index_hole; + std::shared_ptr pll_; + std::shared_ptr drive_; + std::shared_ptr track_; + unsigned int cycles_since_index_hole_; inline void get_next_event(); - Track::Event _current_event; - Time _time_into_track; - bool _motor_is_on; + Track::Event current_event_; + Time time_into_track_; + bool motor_is_on_; void setup_track(); }; diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 564dee21b..d50371262 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -12,35 +12,35 @@ using namespace Storage::Disk; Drive::Drive() - : _head_position(0), _head(0) {} + : head_position_(0), head_(0) {} void Drive::set_disk(std::shared_ptr disk) { - _disk = disk; + disk_ = disk; } bool Drive::has_disk() { - return (bool)_disk; + return (bool)disk_; } bool Drive::get_is_track_zero() { - return _head_position == 0; + return head_position_ == 0; } void Drive::step(int direction) { - _head_position = std::max(_head_position + direction, 0); + head_position_ = std::max(head_position_ + direction, 0); } void Drive::set_head(unsigned int head) { - _head = head; + head_ = head; } std::shared_ptr Drive::get_track() { - if(_disk) return _disk->get_track_at_position(_head, (unsigned int)_head_position); + if(disk_) return disk_->get_track_at_position(head_, (unsigned int)head_position_); return nullptr; } diff --git a/Storage/Disk/Drive.hpp b/Storage/Disk/Drive.hpp index e63434f7f..0555b5107 100644 --- a/Storage/Disk/Drive.hpp +++ b/Storage/Disk/Drive.hpp @@ -47,9 +47,9 @@ class Drive { std::shared_ptr get_track(); private: - std::shared_ptr _disk; - int _head_position; - unsigned int _head; + std::shared_ptr disk_; + int head_position_; + unsigned int head_; }; diff --git a/Storage/Disk/PCMTrack.cpp b/Storage/Disk/PCMTrack.cpp index 509dae780..a0107de05 100644 --- a/Storage/Disk/PCMTrack.cpp +++ b/Storage/Disk/PCMTrack.cpp @@ -13,7 +13,7 @@ using namespace Storage::Disk; PCMTrack::PCMTrack(std::vector segments) { - _segments = std::move(segments); + segments_ = std::move(segments); fix_length(); } @@ -21,7 +21,7 @@ PCMTrack::PCMTrack(PCMSegment segment) { segment.length_of_a_bit.length = 1; segment.length_of_a_bit.clock_rate = 1; - _segments.push_back(std::move(segment)); + segments_.push_back(std::move(segment)); fix_length(); } @@ -29,54 +29,54 @@ PCMTrack::Event PCMTrack::get_next_event() { // find the next 1 in the input stream, keeping count of length as we go, and assuming it's going // to be a flux transition - _next_event.type = Track::Event::FluxTransition; - _next_event.length.length = 0; - while(_segment_pointer < _segments.size()) + next_event_.type = Track::Event::FluxTransition; + next_event_.length.length = 0; + while(segment_pointer_ < segments_.size()) { - unsigned int clock_multiplier = _track_clock_rate / _segments[_segment_pointer].length_of_a_bit.clock_rate; - unsigned int bit_length = clock_multiplier * _segments[_segment_pointer].length_of_a_bit.length; + unsigned int clock_multiplier = track_clock_rate_ / segments_[segment_pointer_].length_of_a_bit.clock_rate; + unsigned int bit_length = clock_multiplier * segments_[segment_pointer_].length_of_a_bit.length; - const uint8_t *segment_data = &_segments[_segment_pointer].data[0]; - while(_bit_pointer < _segments[_segment_pointer].number_of_bits) + const uint8_t *segment_data = &segments_[segment_pointer_].data[0]; + while(bit_pointer_ < segments_[segment_pointer_].number_of_bits) { // for timing simplicity, bits are modelled as happening at the end of their window // TODO: should I account for the converse bit ordering? Or can I assume MSB first? - int bit = segment_data[_bit_pointer >> 3] & (0x80 >> (_bit_pointer&7)); - _bit_pointer++; - _next_event.length.length += bit_length; + int bit = segment_data[bit_pointer_ >> 3] & (0x80 >> (bit_pointer_&7)); + bit_pointer_++; + next_event_.length.length += bit_length; - if(bit) return _next_event; + if(bit) return next_event_; } - _bit_pointer = 0; - _segment_pointer++; + bit_pointer_ = 0; + segment_pointer_++; } // check whether we actually reached the index hole - if(_segment_pointer == _segments.size()) + if(segment_pointer_ == segments_.size()) { - _segment_pointer = 0; - _next_event.type = Track::Event::IndexHole; + segment_pointer_ = 0; + next_event_.type = Track::Event::IndexHole; } - return _next_event; + return next_event_; } Storage::Time PCMTrack::seek_to(Time time_since_index_hole) { - _segment_pointer = 0; + segment_pointer_ = 0; // pick a common clock rate for counting time on this track and multiply up the time being sought appropriately Time time_so_far; - time_so_far.clock_rate = NumberTheory::least_common_multiple(_next_event.length.clock_rate, time_since_index_hole.clock_rate); + time_so_far.clock_rate = NumberTheory::least_common_multiple(next_event_.length.clock_rate, time_since_index_hole.clock_rate); time_since_index_hole.length *= time_so_far.clock_rate / time_since_index_hole.clock_rate; time_since_index_hole.clock_rate = time_so_far.clock_rate; - while(_segment_pointer < _segments.size()) + while(segment_pointer_ < segments_.size()) { // determine how long this segment is in terms of the master clock - unsigned int clock_multiplier = time_so_far.clock_rate / _next_event.length.clock_rate; - unsigned int bit_length = ((clock_multiplier / _track_clock_rate) / _segments[_segment_pointer].length_of_a_bit.clock_rate) * _segments[_segment_pointer].length_of_a_bit.length; - unsigned int time_in_this_segment = bit_length * _segments[_segment_pointer].number_of_bits; + unsigned int clock_multiplier = time_so_far.clock_rate / next_event_.length.clock_rate; + unsigned int bit_length = ((clock_multiplier / track_clock_rate_) / segments_[segment_pointer_].length_of_a_bit.clock_rate) * segments_[segment_pointer_].length_of_a_bit.length; + unsigned int time_in_this_segment = bit_length * segments_[segment_pointer_].number_of_bits; // if this segment goes on longer than the time being sought, end here unsigned int time_remaining = time_since_index_hole.length - time_so_far.length; @@ -86,7 +86,7 @@ Storage::Time PCMTrack::seek_to(Time time_since_index_hole) unsigned int time_found = time_remaining - (time_remaining % bit_length); // resolve that into the stateful bit count - _bit_pointer = 1 + (time_remaining / bit_length); + bit_pointer_ = 1 + (time_remaining / bit_length); // update and return the time sought to time_so_far.length += time_found; @@ -95,7 +95,7 @@ Storage::Time PCMTrack::seek_to(Time time_since_index_hole) // otherwise, accumulate time and keep moving time_so_far.length += time_in_this_segment; - _segment_pointer++; + segment_pointer_++; } return time_since_index_hole; } @@ -103,19 +103,19 @@ Storage::Time PCMTrack::seek_to(Time time_since_index_hole) void PCMTrack::fix_length() { // find the least common multiple of all segment clock rates - _track_clock_rate = _segments[0].length_of_a_bit.clock_rate; - for(size_t c = 1; c < _segments.size(); c++) + track_clock_rate_ = segments_[0].length_of_a_bit.clock_rate; + for(size_t c = 1; c < segments_.size(); c++) { - _track_clock_rate = NumberTheory::least_common_multiple(_track_clock_rate, _segments[c].length_of_a_bit.clock_rate); + track_clock_rate_ = NumberTheory::least_common_multiple(track_clock_rate_, segments_[c].length_of_a_bit.clock_rate); } // thereby determine the total length, storing it to next_event as the track-total divisor - _next_event.length.clock_rate = 0; - for(size_t c = 0; c < _segments.size(); c++) + next_event_.length.clock_rate = 0; + for(size_t c = 0; c < segments_.size(); c++) { - unsigned int multiplier = _track_clock_rate / _segments[c].length_of_a_bit.clock_rate; - _next_event.length.clock_rate += _segments[c].length_of_a_bit.length * _segments[c].number_of_bits * multiplier; + unsigned int multiplier = track_clock_rate_ / segments_[c].length_of_a_bit.clock_rate; + next_event_.length.clock_rate += segments_[c].length_of_a_bit.length * segments_[c].number_of_bits * multiplier; } - _segment_pointer = _bit_pointer = 0; + segment_pointer_ = bit_pointer_ = 0; } diff --git a/Storage/Disk/PCMTrack.hpp b/Storage/Disk/PCMTrack.hpp index 36d464e50..3922827b2 100644 --- a/Storage/Disk/PCMTrack.hpp +++ b/Storage/Disk/PCMTrack.hpp @@ -52,21 +52,21 @@ class PCMTrack: public Track { private: // storage for the segments that describe this track - std::vector _segments; + std::vector segments_; // a helper to determine the overall track clock rate and it's length void fix_length(); // the event perpetually returned; impliedly contains the length of the entire track // as its clock rate, per the need for everything on a Track to sum to a length of 1 - PCMTrack::Event _next_event; + PCMTrack::Event next_event_; // contains the master clock rate - unsigned int _track_clock_rate; + unsigned int track_clock_rate_; // a pointer to the first bit to consider as the next event - size_t _segment_pointer; - size_t _bit_pointer; + size_t segment_pointer_; + size_t bit_pointer_; }; } diff --git a/Storage/Tape/Parsers/Acorn.cpp b/Storage/Tape/Parsers/Acorn.cpp index fb10c5708..35865a88f 100644 --- a/Storage/Tape/Parsers/Acorn.cpp +++ b/Storage/Tape/Parsers/Acorn.cpp @@ -12,7 +12,7 @@ using namespace Storage::Tape::Acorn; Parser::Parser() : ::Storage::Tape::Parser(), - _crc(0x1021, 0x0000) {} + crc_(0x1021, 0x0000) {} int Parser::get_next_bit(const std::shared_ptr &tape) { @@ -38,7 +38,7 @@ int Parser::get_next_byte(const std::shared_ptr &tape) set_error_flag(); return -1; } - _crc.add((uint8_t)value); + crc_.add((uint8_t)value); return value; } @@ -56,8 +56,8 @@ int Parser::get_next_word(const std::shared_ptr &tape) return result; } -void Parser::reset_crc() { _crc.reset(); } -uint16_t Parser::get_crc() { return _crc.get_value(); } +void Parser::reset_crc() { crc_.reset(); } +uint16_t Parser::get_crc() { return crc_.get_value(); } void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse) { diff --git a/Storage/Tape/Parsers/Acorn.hpp b/Storage/Tape/Parsers/Acorn.hpp index c59162076..71f3ecccc 100644 --- a/Storage/Tape/Parsers/Acorn.hpp +++ b/Storage/Tape/Parsers/Acorn.hpp @@ -38,7 +38,7 @@ class Parser: public Storage::Tape::Parser { private: void process_pulse(Storage::Tape::Tape::Pulse pulse); void inspect_waves(const std::vector &waves); - NumberTheory::CRC16 _crc; + NumberTheory::CRC16 crc_; }; } diff --git a/Storage/Tape/Parsers/Commodore.cpp b/Storage/Tape/Parsers/Commodore.cpp index d286b7110..332550638 100644 --- a/Storage/Tape/Parsers/Commodore.cpp +++ b/Storage/Tape/Parsers/Commodore.cpp @@ -13,9 +13,9 @@ using namespace Storage::Tape::Commodore; Parser::Parser() : Storage::Tape::Parser(), - _wave_period(0.0f), - _previous_was_high(false), - _parity_byte(0) {} + wave_period_(0.0f), + previous_was_high_(false), + parity_byte_(0) {} /*! Advances to the next block on the tape, treating it as a header, then consumes, parses, and returns it. @@ -193,9 +193,9 @@ void Parser::expect_byte(const std::shared_ptr &tape, uint8 if(next_byte != value) set_error_flag(); } -void Parser::reset_parity_byte() { _parity_byte = 0; } -uint8_t Parser::get_parity_byte() { return _parity_byte; } -void Parser::add_parity_byte(uint8_t byte) { _parity_byte ^= byte; } +void Parser::reset_parity_byte() { parity_byte_ = 0; } +uint8_t Parser::get_parity_byte() { return parity_byte_; } +void Parser::add_parity_byte(uint8_t byte) { parity_byte_ ^= byte; } /*! Proceeds to the next word marker then returns the result of @c get_next_byte_contents. @@ -255,19 +255,19 @@ void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse) // medium: 262µs => 0.000524s cycle // long: 342µs => 0.000684s cycle bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High; - if(!is_high && _previous_was_high) + if(!is_high && previous_was_high_) { - if(_wave_period >= 0.000764) push_wave(WaveType::Unrecognised); - else if(_wave_period >= 0.000604) push_wave(WaveType::Long); - else if(_wave_period >= 0.000444) push_wave(WaveType::Medium); - else if(_wave_period >= 0.000284) push_wave(WaveType::Short); + if(wave_period_ >= 0.000764) push_wave(WaveType::Unrecognised); + else if(wave_period_ >= 0.000604) push_wave(WaveType::Long); + else if(wave_period_ >= 0.000444) push_wave(WaveType::Medium); + else if(wave_period_ >= 0.000284) push_wave(WaveType::Short); else push_wave(WaveType::Unrecognised); - _wave_period = 0.0f; + wave_period_ = 0.0f; } - _wave_period += pulse.length.get_float(); - _previous_was_high = is_high; + wave_period_ += pulse.length.get_float(); + previous_was_high_ = is_high; } /*! diff --git a/Storage/Tape/Parsers/Commodore.hpp b/Storage/Tape/Parsers/Commodore.hpp index 5714b2dbc..ebde8066d 100644 --- a/Storage/Tape/Parsers/Commodore.hpp +++ b/Storage/Tape/Parsers/Commodore.hpp @@ -94,7 +94,7 @@ class Parser: public Storage::Tape::Parser { */ void expect_byte(const std::shared_ptr &tape, uint8_t value); - uint8_t _parity_byte; + uint8_t parity_byte_; void reset_parity_byte(); uint8_t get_parity_byte(); void add_parity_byte(uint8_t byte); @@ -122,8 +122,8 @@ class Parser: public Storage::Tape::Parser { a long, medium, short or unrecognised wave period. */ void process_pulse(Storage::Tape::Tape::Pulse pulse); - bool _previous_was_high; - float _wave_period; + bool previous_was_high_; + float wave_period_; /*! Per the contract with StaticAnalyser::TapeParser; produces any of a word marker, an end-of-block marker, diff --git a/Storage/Tape/Parsers/Oric.cpp b/Storage/Tape/Parsers/Oric.cpp index 0c9f7f10e..8a2f10a72 100644 --- a/Storage/Tape/Parsers/Oric.cpp +++ b/Storage/Tape/Parsers/Oric.cpp @@ -12,8 +12,8 @@ using namespace Storage::Tape::Oric; int Parser::get_next_byte(const std::shared_ptr &tape, bool use_fast_encoding) { - _detection_mode = use_fast_encoding ? FastZero : SlowZero; - _cycle_length = 0.0f; + detection_mode_ = use_fast_encoding ? FastZero : SlowZero; + cycle_length_ = 0.0f; int result = 0; int bit_count = 0; @@ -21,7 +21,7 @@ int Parser::get_next_byte(const std::shared_ptr &tape, bool { SymbolType symbol = get_next_symbol(tape); if(!bit_count && symbol != SymbolType::Zero) continue; - _detection_mode = use_fast_encoding ? FastData : SlowData; + detection_mode_ = use_fast_encoding ? FastData : SlowData; result |= ((symbol == SymbolType::One) ? 1 : 0) << bit_count; bit_count++; } @@ -31,7 +31,7 @@ int Parser::get_next_byte(const std::shared_ptr &tape, bool bool Parser::sync_and_get_encoding_speed(const std::shared_ptr &tape) { - _detection_mode = Sync; + detection_mode_ = Sync; while(!tape->is_at_end()) { SymbolType symbol = get_next_symbol(tape); @@ -52,22 +52,22 @@ void Parser::process_pulse(Storage::Tape::Tape::Pulse pulse) const float maximum_long_length = 0.001456f; bool wave_is_high = pulse.type == Storage::Tape::Tape::Pulse::High; - if(!_wave_was_high && wave_is_high != _wave_was_high) + if(!wave_was_high_ && wave_is_high != wave_was_high_) { - if(_cycle_length < maximum_short_length) push_wave(WaveType::Short); - else if(_cycle_length < maximum_medium_length) push_wave(WaveType::Medium); - else if(_cycle_length < maximum_long_length) push_wave(WaveType::Long); + if(cycle_length_ < maximum_short_length) push_wave(WaveType::Short); + else if(cycle_length_ < maximum_medium_length) push_wave(WaveType::Medium); + else if(cycle_length_ < maximum_long_length) push_wave(WaveType::Long); else push_wave(WaveType::Unrecognised); - _cycle_length = 0.0f; + cycle_length_ = 0.0f; } - _wave_was_high = wave_is_high; - _cycle_length += pulse.length.get_float(); + wave_was_high_ = wave_is_high; + cycle_length_ += pulse.length.get_float(); } void Parser::inspect_waves(const std::vector &waves) { - switch(_detection_mode) + switch(detection_mode_) { case FastZero: if(waves.empty()) return; diff --git a/Storage/Tape/Parsers/Oric.hpp b/Storage/Tape/Parsers/Oric.hpp index 9891a8a99..790b92539 100644 --- a/Storage/Tape/Parsers/Oric.hpp +++ b/Storage/Tape/Parsers/Oric.hpp @@ -41,9 +41,9 @@ class Parser: public Storage::Tape::Parser { FastZero, SlowZero, Sync - } _detection_mode; - bool _wave_was_high; - float _cycle_length; + } detection_mode_; + bool wave_was_high_; + float cycle_length_; struct Pattern { diff --git a/Storage/Tape/Tape.cpp b/Storage/Tape/Tape.cpp index 90b48e160..f8c5e1af3 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -21,23 +21,23 @@ TapePlayer::TapePlayer(unsigned int input_clock_rate) : void Storage::Tape::Tape::seek(Time &seek_time) { - _current_time.set_zero(); - _next_time.set_zero(); - while(_next_time < seek_time) get_next_pulse(); + current_time_.set_zero(); + next_time_.set_zero(); + while(next_time_ < seek_time) get_next_pulse(); } void Storage::Tape::Tape::reset() { - _current_time.set_zero(); - _next_time.set_zero(); + current_time_.set_zero(); + next_time_.set_zero(); virtual_reset(); } Tape::Pulse Tape::get_next_pulse() { Tape::Pulse pulse = virtual_get_next_pulse(); - _current_time = _next_time; - _next_time += pulse.length; + current_time_ = next_time_; + next_time_ += pulse.length; return pulse; } @@ -45,34 +45,34 @@ Tape::Pulse Tape::get_next_pulse() void TapePlayer::set_tape(std::shared_ptr tape) { - _tape = tape; + tape_ = tape; reset_timer(); get_next_pulse(); } std::shared_ptr TapePlayer::get_tape() { - return _tape; + return tape_; } bool TapePlayer::has_tape() { - return (bool)_tape; + return (bool)tape_; } void TapePlayer::get_next_pulse() { // get the new pulse - if(_tape) - _current_pulse = _tape->get_next_pulse(); + if(tape_) + current_pulse_ = tape_->get_next_pulse(); else { - _current_pulse.length.length = 1; - _current_pulse.length.clock_rate = 1; - _current_pulse.type = Tape::Pulse::Zero; + current_pulse_.length.length = 1; + current_pulse_.length.clock_rate = 1; + current_pulse_.type = Tape::Pulse::Zero; } - set_next_event_time_interval(_current_pulse.length); + set_next_event_time_interval(current_pulse_.length); } void TapePlayer::run_for_cycles(int number_of_cycles) @@ -90,19 +90,19 @@ void TapePlayer::run_for_input_pulse() void TapePlayer::process_next_event() { - process_input_pulse(_current_pulse); + process_input_pulse(current_pulse_); get_next_pulse(); } #pragma mark - Binary Player BinaryTapePlayer::BinaryTapePlayer(unsigned int input_clock_rate) : - TapePlayer(input_clock_rate), _motor_is_running(false) + TapePlayer(input_clock_rate), motor_is_running_(false) {} void BinaryTapePlayer::set_motor_control(bool enabled) { - _motor_is_running = enabled; + motor_is_running_ = enabled; } void BinaryTapePlayer::set_tape_output(bool set) @@ -112,26 +112,26 @@ void BinaryTapePlayer::set_tape_output(bool set) bool BinaryTapePlayer::get_input() { - return _input_level; + return input_level_; } void BinaryTapePlayer::run_for_cycles(int number_of_cycles) { - if(_motor_is_running) TapePlayer::run_for_cycles(number_of_cycles); + if(motor_is_running_) TapePlayer::run_for_cycles(number_of_cycles); } void BinaryTapePlayer::set_delegate(Delegate *delegate) { - _delegate = delegate; + delegate_ = delegate; } void BinaryTapePlayer::process_input_pulse(Storage::Tape::Tape::Pulse pulse) { bool new_input_level = pulse.type == Tape::Pulse::Low; - if(_input_level != new_input_level) + if(input_level_ != new_input_level) { - _input_level = new_input_level; - if(_delegate) _delegate->tape_did_change_input(this); + input_level_ = new_input_level; + if(delegate_) delegate_->tape_did_change_input(this); } } diff --git a/Storage/Tape/Tape.hpp b/Storage/Tape/Tape.hpp index 14053a7a2..7ed5920da 100644 --- a/Storage/Tape/Tape.hpp +++ b/Storage/Tape/Tape.hpp @@ -53,13 +53,13 @@ class Tape { virtual bool is_at_end() = 0; /// @returns the amount of time preceeding the most recently-returned pulse. - virtual Time get_current_time() { return _current_time; } + virtual Time get_current_time() { return current_time_; } /// Advances or reverses the tape to the last time before or at @c time from which a pulse starts. virtual void seek(Time &time); private: - Time _current_time, _next_time; + Time current_time_, next_time_; virtual Pulse virtual_get_next_pulse() = 0; virtual void virtual_reset() = 0; @@ -90,8 +90,8 @@ class TapePlayer: public TimedEventLoop { private: inline void get_next_pulse(); - std::shared_ptr _tape; - Tape::Pulse _current_pulse; + std::shared_ptr tape_; + Tape::Pulse current_pulse_; }; /*! @@ -118,10 +118,10 @@ class BinaryTapePlayer: public TapePlayer { void set_delegate(Delegate *delegate); protected: - Delegate *_delegate; + Delegate *delegate_; virtual void process_input_pulse(Storage::Tape::Tape::Pulse pulse); - bool _input_level; - bool _motor_is_running; + bool input_level_; + bool motor_is_running_; }; } diff --git a/Storage/TimedEventLoop.cpp b/Storage/TimedEventLoop.cpp index d420fd082..1d4a6369f 100644 --- a/Storage/TimedEventLoop.cpp +++ b/Storage/TimedEventLoop.cpp @@ -13,12 +13,12 @@ using namespace Storage; TimedEventLoop::TimedEventLoop(unsigned int input_clock_rate) : - _input_clock_rate(input_clock_rate) {} + input_clock_rate_(input_clock_rate) {} void TimedEventLoop::run_for_cycles(int number_of_cycles) { - _cycles_until_event -= number_of_cycles; - while(_cycles_until_event <= 0) + cycles_until_event_ -= number_of_cycles; + while(cycles_until_event_ <= 0) { process_next_event(); } @@ -26,13 +26,13 @@ void TimedEventLoop::run_for_cycles(int number_of_cycles) unsigned int TimedEventLoop::get_cycles_until_next_event() { - return (unsigned int)std::max(_cycles_until_event, 0); + return (unsigned int)std::max(cycles_until_event_, 0); } void TimedEventLoop::reset_timer() { - _subcycles_until_event.set_zero(); - _cycles_until_event = 0; + subcycles_until_event_.set_zero(); + cycles_until_event_ = 0; } void TimedEventLoop::reset_timer_to_offset(Time offset) @@ -49,10 +49,10 @@ void TimedEventLoop::jump_to_next_event() void TimedEventLoop::set_next_event_time_interval(Time interval) { // Calculate [interval]*[input clock rate] + [subcycles until this event]. - int64_t denominator = (int64_t)interval.clock_rate * (int64_t)_subcycles_until_event.clock_rate; + int64_t denominator = (int64_t)interval.clock_rate * (int64_t)subcycles_until_event_.clock_rate; int64_t numerator = - (int64_t)_subcycles_until_event.clock_rate * (int64_t)_input_clock_rate * (int64_t)interval.length + - (int64_t)interval.clock_rate * (int64_t)_subcycles_until_event.length; + (int64_t)subcycles_until_event_.clock_rate * (int64_t)input_clock_rate_ * (int64_t)interval.length + + (int64_t)interval.clock_rate * (int64_t)subcycles_until_event_.length; // Simplify now, to prepare for stuffing into possibly 32-bit quantities int64_t common_divisor = NumberTheory::greatest_common_divisor(numerator % denominator, denominator); @@ -61,9 +61,9 @@ void TimedEventLoop::set_next_event_time_interval(Time interval) // So this event will fire in the integral number of cycles from now, putting us at the remainder // number of subcycles - _cycles_until_event = (int)(numerator / denominator); - _subcycles_until_event.length = (unsigned int)(numerator % denominator); - _subcycles_until_event.clock_rate = (unsigned int)denominator; + cycles_until_event_ = (int)(numerator / denominator); + subcycles_until_event_.length = (unsigned int)(numerator % denominator); + subcycles_until_event_.clock_rate = (unsigned int)denominator; } Time TimedEventLoop::get_time_into_next_event() diff --git a/Storage/TimedEventLoop.hpp b/Storage/TimedEventLoop.hpp index c939a7827..962b495c7 100644 --- a/Storage/TimedEventLoop.hpp +++ b/Storage/TimedEventLoop.hpp @@ -90,10 +90,9 @@ namespace Storage { Time get_time_into_next_event(); private: - unsigned int _input_clock_rate; - int _cycles_until_event; - Time _subcycles_until_event; - Time _event_interval; + unsigned int input_clock_rate_; + int cycles_until_event_; + Time subcycles_until_event_; }; }