From 6482303063455129047ec206dc2bcfc33a761385 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 21 Mar 2021 20:34:58 -0400 Subject: [PATCH] Reduces code duplication slightly. --- Machines/Sinclair/ZXSpectrum/Video.hpp | 127 +++++++++++-------------- 1 file changed, 54 insertions(+), 73 deletions(-) diff --git a/Machines/Sinclair/ZXSpectrum/Video.hpp b/Machines/Sinclair/ZXSpectrum/Video.hpp index 891c8bee0..78e7978b5 100644 --- a/Machines/Sinclair/ZXSpectrum/Video.hpp +++ b/Machines/Sinclair/ZXSpectrum/Video.hpp @@ -103,92 +103,73 @@ template class Video { if(line < 3) { // Output sync line. crt_.output_sync(cycles_this_line); - } else if((line < first_line) || (line >= first_line+192)) { - // Output plain border line. - if(offset < sync_position) { - const int border_duration = std::min(sync_position, end_offset) - offset; - output_border(border_duration); - offset += border_duration; - } - - if(offset >= sync_position && offset < sync_position + sync_length && end_offset > offset) { - const int sync_duration = std::min(sync_position + sync_length, end_offset) - offset; - crt_.output_sync(sync_duration); - offset += sync_duration; - } - - if(offset >= sync_position + sync_length && offset < burst_position && end_offset > offset) { - const int blank_duration = std::min(burst_position, end_offset) - offset; - crt_.output_blank(blank_duration); - offset += blank_duration; - } - - if(offset >= burst_position && offset < burst_position+burst_length && end_offset > offset) { - const int burst_duration = std::min(burst_position + burst_length, end_offset) - offset; - crt_.output_colour_burst(burst_duration, line, is_alternate_line_); - offset += burst_duration; - } - - if(offset >= burst_position+burst_length && end_offset > offset) { - const int border_duration = end_offset - offset; - output_border(border_duration); - } } else { - // Output pixel line. - if(offset < 256) { - const int pixel_duration = std::min(256, end_offset) - offset; - - if(!offset) { - const int pixel_line = line - first_line; - - pixel_target_ = crt_.begin_data(256); - attribute_address_ = ((pixel_line / 8) * 32) + 6144; - pixel_address_ = ((pixel_line & 0x07) << 8) | ((pixel_line&0x38) << 2) | ((pixel_line&0xc0) << 5); + if((line < first_line) || (line >= first_line+192)) { + // Output plain border line. + if(offset < sync_position) { + const int border_duration = std::min(sync_position, end_offset) - offset; + output_border(border_duration); + offset += border_duration; } + } else { + // Output pixel line. + if(offset < 256) { + const int pixel_duration = std::min(256, end_offset) - offset; - if(pixel_target_) { - const int start_column = offset >> 3; - const int end_column = (offset + pixel_duration) >> 3; - for(int column = start_column; column < end_column; column++) { - const uint8_t attributes = memory_[attribute_address_]; + if(!offset) { + const int pixel_line = line - first_line; - constexpr uint8_t masks[] = {0, 0xff}; - const uint8_t pixels = memory_[pixel_address_] ^ masks[flash_mask_ & (attributes >> 7)]; + pixel_target_ = crt_.begin_data(256); + attribute_address_ = ((pixel_line / 8) * 32) + 6144; + pixel_address_ = ((pixel_line & 0x07) << 8) | ((pixel_line&0x38) << 2) | ((pixel_line&0xc0) << 5); + } - const uint8_t colours[2] = { - palette[(attributes & 0x78) >> 3], - palette[((attributes & 0x40) >> 3) | (attributes & 0x07)], - }; + if(pixel_target_) { + const int start_column = offset >> 3; + const int end_column = (offset + pixel_duration) >> 3; + for(int column = start_column; column < end_column; column++) { + const uint8_t attributes = memory_[attribute_address_]; - pixel_target_[0] = colours[(pixels >> 7) & 1]; - pixel_target_[1] = colours[(pixels >> 6) & 1]; - pixel_target_[2] = colours[(pixels >> 5) & 1]; - pixel_target_[3] = colours[(pixels >> 4) & 1]; - pixel_target_[4] = colours[(pixels >> 3) & 1]; - pixel_target_[5] = colours[(pixels >> 2) & 1]; - pixel_target_[6] = colours[(pixels >> 1) & 1]; - pixel_target_[7] = colours[(pixels >> 0) & 1]; - pixel_target_ += 8; + constexpr uint8_t masks[] = {0, 0xff}; + const uint8_t pixels = memory_[pixel_address_] ^ masks[flash_mask_ & (attributes >> 7)]; - ++pixel_address_; - ++attribute_address_; + const uint8_t colours[2] = { + palette[(attributes & 0x78) >> 3], + palette[((attributes & 0x40) >> 3) | (attributes & 0x07)], + }; + + pixel_target_[0] = colours[(pixels >> 7) & 1]; + pixel_target_[1] = colours[(pixels >> 6) & 1]; + pixel_target_[2] = colours[(pixels >> 5) & 1]; + pixel_target_[3] = colours[(pixels >> 4) & 1]; + pixel_target_[4] = colours[(pixels >> 3) & 1]; + pixel_target_[5] = colours[(pixels >> 2) & 1]; + pixel_target_[6] = colours[(pixels >> 1) & 1]; + pixel_target_[7] = colours[(pixels >> 0) & 1]; + pixel_target_ += 8; + + ++pixel_address_; + ++attribute_address_; + } + } + + offset += pixel_duration; + if(offset == 256) { + crt_.output_data(256); + pixel_target_ = nullptr; } } - offset += pixel_duration; - if(offset == 256) { - crt_.output_data(256); - pixel_target_ = nullptr; + if(offset >= 256 && offset < sync_position && end_offset > offset) { + const int border_duration = std::min(sync_position, end_offset) - offset; + output_border(border_duration); + offset += border_duration; } } - if(offset >= 256 && offset < sync_position && end_offset > offset) { - const int border_duration = std::min(sync_position, end_offset) - offset; - output_border(border_duration); - offset += border_duration; - } + // Output the common tail to border and pixel lines: sync, blank, colour burst, border. - if(offset >= sync_position && offset < sync_position+sync_length && end_offset > offset) { + if(offset >= sync_position && offset < sync_position + sync_length && end_offset > offset) { const int sync_duration = std::min(sync_position + sync_length, end_offset) - offset; crt_.output_sync(sync_duration); offset += sync_duration; @@ -206,7 +187,7 @@ template class Video { offset += burst_duration; } - if(offset >= burst_position + burst_length && end_offset > offset) { + if(offset >= burst_position+burst_length && end_offset > offset) { const int border_duration = end_offset - offset; output_border(border_duration); }