diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index 0943c596d..09a10a954 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -302,13 +302,24 @@ void CRT::output_blank(unsigned int number_of_cycles) void CRT::output_level(unsigned int number_of_cycles) { _openGL_output_builder->lock_output(); - Scan scan { - .type = Scan::Type::Level, - .number_of_cycles = number_of_cycles, - .tex_x = _openGL_output_builder->get_last_write_x_posititon(), - .tex_y = _openGL_output_builder->get_last_write_y_posititon() - }; - output_scan(&scan); + if(!_openGL_output_builder->input_buffer_is_full()) + { + Scan scan { + .type = Scan::Type::Level, + .number_of_cycles = number_of_cycles, + .tex_x = _openGL_output_builder->get_last_write_x_posititon(), + .tex_y = _openGL_output_builder->get_last_write_y_posititon() + }; + output_scan(&scan); + } + else + { + Scan scan { + .type = Scan::Type::Blank, + .number_of_cycles = number_of_cycles + }; + output_scan(&scan); + } _openGL_output_builder->unlock_output(); } @@ -328,8 +339,9 @@ void CRT::output_colour_burst(unsigned int number_of_cycles, uint8_t phase, uint void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider) { _openGL_output_builder->lock_output(); - if(_openGL_output_builder->reduce_previous_allocation_to(number_of_cycles / source_divider)) + if(!_openGL_output_builder->input_buffer_is_full()) { + _openGL_output_builder->reduce_previous_allocation_to(number_of_cycles / source_divider); Scan scan { .type = Scan::Type::Data, .number_of_cycles = number_of_cycles, @@ -341,7 +353,11 @@ void CRT::output_data(unsigned int number_of_cycles, unsigned int source_divider } else { - output_blank(number_of_cycles); + Scan scan { + .type = Scan::Type::Blank, + .number_of_cycles = number_of_cycles + }; + output_scan(&scan); } _openGL_output_builder->unlock_output(); } diff --git a/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp b/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp index eecae0ee3..9cc3eae84 100644 --- a/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp +++ b/Outputs/CRT/Internals/CRTInputBufferBuilder.cpp @@ -41,9 +41,14 @@ void CRTInputBufferBuilder::allocate_write_area(size_t required_length) } } -bool CRTInputBufferBuilder::reduce_previous_allocation_to(size_t actual_length) +bool CRTInputBufferBuilder::is_full() { - if(_next_write_y_position == InputBufferBuilderHeight) return false; + return (_next_write_y_position == InputBufferBuilderHeight); +} + +void CRTInputBufferBuilder::reduce_previous_allocation_to(size_t actual_length) +{ + if(_next_write_y_position == InputBufferBuilderHeight) return; uint8_t *const image_pointer = _image.get(); @@ -68,8 +73,6 @@ bool CRTInputBufferBuilder::reduce_previous_allocation_to(size_t actual_length) // return any allocated length that wasn't actually used to the available pool _next_write_x_position -= (_last_allocation_amount - actual_length); - - return true; } uint8_t *CRTInputBufferBuilder::get_image_pointer() diff --git a/Outputs/CRT/Internals/CRTInputBufferBuilder.hpp b/Outputs/CRT/Internals/CRTInputBufferBuilder.hpp index 55d3ea792..39afba9d0 100644 --- a/Outputs/CRT/Internals/CRTInputBufferBuilder.hpp +++ b/Outputs/CRT/Internals/CRTInputBufferBuilder.hpp @@ -23,7 +23,7 @@ struct CRTInputBufferBuilder { CRTInputBufferBuilder(size_t bytes_per_pixel); void allocate_write_area(size_t required_length); - bool reduce_previous_allocation_to(size_t actual_length); + void reduce_previous_allocation_to(size_t actual_length); uint16_t get_and_finalise_current_line(); uint8_t *get_image_pointer(); @@ -36,6 +36,8 @@ struct CRTInputBufferBuilder { size_t get_bytes_per_pixel(); + bool is_full(); + private: // where pixel data will be put to the next time a write is requested uint16_t _next_write_x_position, _next_write_y_position; diff --git a/Outputs/CRT/Internals/CRTOpenGL.hpp b/Outputs/CRT/Internals/CRTOpenGL.hpp index c4cc534d3..7c72cf909 100644 --- a/Outputs/CRT/Internals/CRTOpenGL.hpp +++ b/Outputs/CRT/Internals/CRTOpenGL.hpp @@ -173,9 +173,14 @@ class OpenGLOutputBuilder { return _buffer_builder->get_write_target(); } - inline bool reduce_previous_allocation_to(size_t actual_length) + inline void reduce_previous_allocation_to(size_t actual_length) { - return _buffer_builder->reduce_previous_allocation_to(actual_length); + _buffer_builder->reduce_previous_allocation_to(actual_length); + } + + inline bool input_buffer_is_full() + { + return _buffer_builder->is_full(); } inline uint16_t get_last_write_x_posititon()