From 92754ace7a03f9df256415525ab403bc55f03e2e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 29 Jan 2017 22:16:23 -0500 Subject: [PATCH] Some mild fixes get me up to having a rolling screen of vertical lines. Which is what I was hoping for right now! --- Machines/Atari2600/Atari2600.cpp | 4 +- Machines/Atari2600/TIA.cpp | 43 ++++++++++++++++--- Machines/Atari2600/TIA.hpp | 8 +++- .../xcschemes/Clock Signal.xcscheme | 1 - 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index cd67696a0..7f7f70ea6 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -130,8 +130,8 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin } else { const uint16_t decodedAddress = address & 0x3f; switch(decodedAddress) { - case 0x00: update_video(); tia_->set_vsync(!!(*value & 0x02)); break; - case 0x01: update_video(); tia_->set_vblank(!!(*value & 0x02)); break; + case 0x00: update_video(); tia_->set_sync(!!(*value & 0x02)); break; + case 0x01: update_video(); tia_->set_blank(!!(*value & 0x02)); break; case 0x02: set_ready_line(true); diff --git a/Machines/Atari2600/TIA.cpp b/Machines/Atari2600/TIA.cpp index 0a515bea1..2dbdd4c03 100644 --- a/Machines/Atari2600/TIA.cpp +++ b/Machines/Atari2600/TIA.cpp @@ -11,12 +11,17 @@ using namespace Atari2600; namespace { const int cycles_per_line = 228; + + const int sync_flag = 0x1; + const int blank_flag = 0x2; } TIA::TIA() : horizontal_counter_(0), output_cursor_(0), - pixel_target_(nullptr) + pixel_target_(nullptr), + requested_output_mode_(0), + output_mode_(0) { crt_.reset(new Outputs::CRT::CRT(cycles_per_line * 2 + 1, 1, Outputs::CRT::DisplayType::NTSC60, 1)); crt_->set_output_device(Outputs::CRT::Television); @@ -95,12 +100,14 @@ void TIA::run_for_cycles(int number_of_cycles) } } -void TIA::set_vsync(bool vsync) +void TIA::set_sync(bool sync) { + requested_output_mode_ = (requested_output_mode_ & ~sync_flag) | (sync ? sync_flag : 0); } -void TIA::set_vblank(bool vblank) +void TIA::set_blank(bool blank) { + requested_output_mode_ = (requested_output_mode_ & ~blank_flag) | (blank ? blank_flag : 0); } void TIA::reset_horizontal_counter() @@ -230,7 +237,12 @@ void TIA::output_for_cycles(int number_of_cycles) 8 cycles: blank or pixels, depending on whether the blank extend bit is set 152 cycles: pixels */ +// if(output_mode_ != requested_output_mode_) +// { +// // flush the old output +// } horizontal_counter_ += number_of_cycles; + if(!output_cursor_ && horizontal_counter_ >= 16) { crt_->output_blank(32); @@ -248,7 +260,7 @@ void TIA::output_for_cycles(int number_of_cycles) } if(output_cursor_ == 48 && horizontal_counter_ >= 68) { - crt_->output_default_colour_burst(40); + crt_->output_blank(40); output_cursor_ = 68; } if(horizontal_counter_ > 68) @@ -272,10 +284,29 @@ void TIA::output_for_cycles(int number_of_cycles) } } horizontal_counter_ %= cycles_per_line; + output_cursor_ %= cycles_per_line; } void TIA::output_line() { - // TODO: optimise special case - output_for_cycles(cycles_per_line); + output_mode_ = requested_output_mode_; + switch(output_mode_) + { + default: + // TODO: optimise special case + output_for_cycles(cycles_per_line); + break; + case sync_flag: + case sync_flag | blank_flag: + crt_->output_sync(32); + crt_->output_blank(32); + crt_->output_sync(392); + break; + case blank_flag: + crt_->output_blank(32); + crt_->output_sync(32); + crt_->output_default_colour_burst(32); + crt_->output_blank(360); + break; + } } diff --git a/Machines/Atari2600/TIA.hpp b/Machines/Atari2600/TIA.hpp index b79fb3274..e5ec60a17 100644 --- a/Machines/Atari2600/TIA.hpp +++ b/Machines/Atari2600/TIA.hpp @@ -26,8 +26,8 @@ class TIA { void run_for_cycles(int number_of_cycles); void set_output_mode(OutputMode output_mode); - void set_vsync(bool vsync); - void set_vblank(bool vblank); + void set_sync(bool sync); + void set_blank(bool blank); void reset_horizontal_counter(); // Reset is delayed by four cycles. int get_cycles_until_horizontal_blank(unsigned int from_offset); @@ -68,7 +68,11 @@ class TIA { std::shared_ptr crt_; int horizontal_counter_; + int output_cursor_; + int output_mode_; + int requested_output_mode_; + uint8_t *pixel_target_; void output_for_cycles(int number_of_cycles); diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme index 08fb44b13..6cceb313b 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -69,7 +69,6 @@ useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" - enableAddressSanitizer = "YES" debugServiceExtension = "internal" allowLocationSimulation = "NO">