1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Adds an allocator for pixels.

This commit is contained in:
Thomas Harte 2021-06-15 22:03:41 -04:00
parent 5fc91effb5
commit e94e051c87
2 changed files with 35 additions and 9 deletions

View File

@ -179,23 +179,35 @@ void Nick::run_for(HalfCycles duration) {
if(state_ == State::Border) { if(state_ == State::Border) {
border_duration_ += next_event - window; border_duration_ += next_event - window;
} else { } else {
// TODO: something proper here. if(!allocated_pointer_) {
uint16_t *const colour_pointer = reinterpret_cast<uint16_t *>(crt_.begin_data(1)); flush_pixels();
if(colour_pointer) *colour_pointer = 0xfff; pixel_pointer_ = allocated_pointer_ = reinterpret_cast<uint16_t *>(crt_.begin_data(allocation_size));
crt_.output_level(next_event - window); }
// TODO: real pixels.
if(allocated_pointer_) {
for(int c = 0; c < next_event - window; c++) {
pixel_pointer_[0] = uint16_t(0xfff ^ (window + c));
++pixel_pointer_;
}
} else {
pixel_pointer_ += next_event - window;
}
pixel_duration_ += next_event - window;
if(pixel_pointer_ - allocated_pointer_ == allocation_size) {
flush_pixels();
}
} }
window = next_event; window = next_event;
if(window == left_margin_) { if(window == left_margin_) {
flush_border(); flush_border();
state_ = State::Pixels; state_ = State::Pixels;
// TODO: probably allocate some pixels here?
} }
if(window == right_margin_) { if(window == right_margin_) {
flush_pixels();
state_ = State::Border; state_ = State::Border;
// TODO: probably output pixels here?
} }
} }
} }
@ -205,7 +217,7 @@ void Nick::run_for(HalfCycles duration) {
if(state_ == State::Border) { if(state_ == State::Border) {
flush_border(); flush_border();
} else { } else {
// TODO: output pixels. flush_pixels();
} }
} }
} }
@ -236,6 +248,14 @@ void Nick::flush_border() {
border_duration_ = 0; border_duration_ = 0;
} }
void Nick::flush_pixels() {
if(!pixel_duration_) return;
crt_.output_data(pixel_duration_, size_t(pixel_pointer_ - allocated_pointer_));
pixel_duration_ = 0;
pixel_pointer_ = nullptr;
allocated_pointer_ = nullptr;
}
// MARK: - CRT passthroughs. // MARK: - CRT passthroughs.
void Nick::set_scan_target(Outputs::Display::ScanTarget *scan_target) { void Nick::set_scan_target(Outputs::Display::ScanTarget *scan_target) {

View File

@ -66,6 +66,12 @@ class Nick {
// An accumulator for border output regions. // An accumulator for border output regions.
int border_duration_ = 0; int border_duration_ = 0;
void flush_border(); void flush_border();
// The destination for new pixels.
static constexpr int allocation_size = 320;
uint16_t *pixel_pointer_ = nullptr, *allocated_pointer_ = nullptr;
int pixel_duration_ = 0;
void flush_pixels();
}; };