From 0182b0483a1f244e60fc3bc03349f2f0eb3648d6 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 29 Jun 2016 19:13:24 -0400 Subject: [PATCH] Added a 'power on' flag that is set automatically at construction but can be declined. Saves all that stuff of every machine having to set and then unset the RST line, and fixes an Electron bug related to that. --- Components/6560/6560.cpp | 2 +- Machines/Atari2600/Atari2600.cpp | 3 --- Machines/Electron/Electron.cpp | 2 -- Machines/Vic-20/Vic20.cpp | 3 --- Processors/6502/CPU6502.hpp | 16 ++++++++++++++-- Processors/6502/CPU6502AllRAM.cpp | 1 + 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Components/6560/6560.cpp b/Components/6560/6560.cpp index 373cfc684..78fc24e97 100644 --- a/Components/6560/6560.cpp +++ b/Components/6560/6560.cpp @@ -69,7 +69,7 @@ void MOS6560::set_output_mode(OutputMode output_mode) chrominances = ntsc_chrominances; display_type = Outputs::CRT::NTSC60; _timing.cycles_per_line = 65; - _timing.line_counter_increment_offset = 65 - 36; // TODO: 36 is from memory; need to look up. + _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; diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index af59e0fba..a757f25f8 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -28,7 +28,6 @@ Machine::Machine() : _is_pal_region(false) { memset(_collisions, 0xff, sizeof(_collisions)); - set_reset_line(true); setup_reported_collisions(); for(int vbextend = 0; vbextend < 2; vbextend++) @@ -414,8 +413,6 @@ void Machine::output_pixels(unsigned int count) unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { - set_reset_line(false); - uint8_t returnValue = 0xff; unsigned int cycles_run_for = 3; diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index c65516912..9e25a30b8 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -55,7 +55,6 @@ Machine::Machine() : memset(_roms[c], 0xff, 16384); _tape.set_delegate(this); - set_reset_line(true); } void Machine::setup_output(float aspect_ratio) @@ -86,7 +85,6 @@ void Machine::close_output() unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { unsigned int cycles = 1; - set_reset_line(false); if(address < 0x8000) { diff --git a/Machines/Vic-20/Vic20.cpp b/Machines/Vic-20/Vic20.cpp index 440994230..59083df3c 100644 --- a/Machines/Vic-20/Vic20.cpp +++ b/Machines/Vic-20/Vic20.cpp @@ -18,7 +18,6 @@ Machine::Machine() : _userPortVIA.set_delegate(this); _keyboardVIA.set_delegate(this); _tape.set_delegate(this); - set_reset_line(true); } Machine::~Machine() @@ -28,8 +27,6 @@ Machine::~Machine() unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { - set_reset_line(false); - // test for PC at F92F if(_use_fast_tape_hack && address == 0xf92f && operation == CPU6502::BusOperation::ReadOpcode) { diff --git a/Processors/6502/CPU6502.hpp b/Processors/6502/CPU6502.hpp index 629955077..4fa8acf63 100644 --- a/Processors/6502/CPU6502.hpp +++ b/Processors/6502/CPU6502.hpp @@ -459,6 +459,8 @@ template class Processor { Reset = 0x80, IRQ = 0x40, NMI = 0x20, + + PowerOn = 0x10, }; uint8_t _interrupt_requests; @@ -539,7 +541,7 @@ template class Processor { _interruptFlag(Flag::Interrupt), _s(0), _nextBusOperation(BusOperation::None), - _interrupt_requests(0) + _interrupt_requests(InterruptRequestFlags::PowerOn) { // 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 @@ -587,7 +589,8 @@ template class Processor { if(!_scheduledPrograms[scheduleProgramsReadPointer]) {\ scheduleProgramsReadPointer = _scheduleProgramsWritePointer = scheduleProgramProgramCounter = 0;\ if(_interrupt_requests) {\ - if(_interrupt_requests & InterruptRequestFlags::Reset) {\ + 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;\ @@ -1196,6 +1199,15 @@ template class Processor { return !!(_interrupt_requests & InterruptRequestFlags::Reset); } + /*! + This emulation automatically sets itself up in power-on state at creation, which has the effect of triggering a + reset at the first opportunity. Use @c set_power_on to disable that behaviour. + */ + inline void set_power_on(bool active) + { + _interrupt_requests = (_interrupt_requests & ~InterruptRequestFlags::PowerOn) | (active ? InterruptRequestFlags::PowerOn : 0); + } + /*! Sets the current level of the IRQ line. diff --git a/Processors/6502/CPU6502AllRAM.cpp b/Processors/6502/CPU6502AllRAM.cpp index 95df536c2..2b8805973 100644 --- a/Processors/6502/CPU6502AllRAM.cpp +++ b/Processors/6502/CPU6502AllRAM.cpp @@ -16,6 +16,7 @@ AllRAMProcessor::AllRAMProcessor() : _timestamp(0) {} int AllRAMProcessor::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value) { + set_power_on(false); _timestamp++; if(isReadOperation(operation)) {