1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-03 11:30:02 +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) {
// 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 <VideoTiming timing> 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);
}