1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Reduces code duplication slightly.

This commit is contained in:
Thomas Harte 2021-03-21 20:34:58 -04:00
parent 388b136980
commit 6482303063

View File

@ -103,92 +103,73 @@ template <VideoTiming timing> class Video {
if(line < 3) { if(line < 3) {
// Output sync line. // Output sync line.
crt_.output_sync(cycles_this_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 { } else {
// Output pixel line. if((line < first_line) || (line >= first_line+192)) {
if(offset < 256) { // Output plain border line.
const int pixel_duration = std::min(256, end_offset) - offset; if(offset < sync_position) {
const int border_duration = std::min(sync_position, end_offset) - offset;
if(!offset) { output_border(border_duration);
const int pixel_line = line - first_line; offset += border_duration;
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);
} }
} else {
// Output pixel line.
if(offset < 256) {
const int pixel_duration = std::min(256, end_offset) - offset;
if(pixel_target_) { if(!offset) {
const int start_column = offset >> 3; const int pixel_line = line - first_line;
const int end_column = (offset + pixel_duration) >> 3;
for(int column = start_column; column < end_column; column++) {
const uint8_t attributes = memory_[attribute_address_];
constexpr uint8_t masks[] = {0, 0xff}; pixel_target_ = crt_.begin_data(256);
const uint8_t pixels = memory_[pixel_address_] ^ masks[flash_mask_ & (attributes >> 7)]; 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] = { if(pixel_target_) {
palette[(attributes & 0x78) >> 3], const int start_column = offset >> 3;
palette[((attributes & 0x40) >> 3) | (attributes & 0x07)], 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]; constexpr uint8_t masks[] = {0, 0xff};
pixel_target_[1] = colours[(pixels >> 6) & 1]; const uint8_t pixels = memory_[pixel_address_] ^ masks[flash_mask_ & (attributes >> 7)];
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_; const uint8_t colours[2] = {
++attribute_address_; 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 && offset < sync_position && end_offset > offset) {
if(offset == 256) { const int border_duration = std::min(sync_position, end_offset) - offset;
crt_.output_data(256); output_border(border_duration);
pixel_target_ = nullptr; offset += border_duration;
} }
} }
if(offset >= 256 && offset < sync_position && end_offset > offset) { // Output the common tail to border and pixel lines: sync, blank, colour burst, border.
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) { 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; const int sync_duration = std::min(sync_position + sync_length, end_offset) - offset;
crt_.output_sync(sync_duration); crt_.output_sync(sync_duration);
offset += sync_duration; offset += sync_duration;
@ -206,7 +187,7 @@ template <VideoTiming timing> class Video {
offset += burst_duration; 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; const int border_duration = end_offset - offset;
output_border(border_duration); output_border(border_duration);
} }