From 735586f5f8858a550d3c2cf2c925a3c4e7d14f03 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 19 Oct 2019 21:20:34 -0400 Subject: [PATCH 1/3] Corrects tabs; adds potential output_border optimisation. --- Machines/AmstradCPC/AmstradCPC.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index c570b341a..ace3aaa52 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -222,9 +222,9 @@ class CRTCBusHandler { if(cycles_) { switch(previous_output_mode_) { default: - case OutputMode::Blank: crt_.output_blank(cycles_ * 16); break; + case OutputMode::Blank: crt_.output_blank(cycles_ * 16); break; case OutputMode::Sync: crt_.output_sync(cycles_ * 16); break; - case OutputMode::Border: output_border(cycles_); break; + case OutputMode::Border: output_border(cycles_); break; case OutputMode::ColourBurst: crt_.output_default_colour_burst(cycles_ * 16); break; case OutputMode::Pixels: crt_.output_data(cycles_ * 16, size_t(cycles_ * 16 / pixel_divider_)); @@ -256,7 +256,8 @@ class CRTCBusHandler { ((state.refresh_address & 0x3000) << 2) ); - // fetch two bytes and translate into pixels + // Fetch two bytes and translate into pixels. Guaranteed: the mode can change only at + // hsync, so there's no risk of pixel_pointer_ passing 320 without hitting 320. switch(mode_) { case 0: reinterpret_cast(pixel_pointer_)[0] = mode0_output_[ram_[address]]; @@ -369,9 +370,14 @@ class CRTCBusHandler { private: void output_border(int length) { - uint8_t *colour_pointer = static_cast(crt_.begin_data(1)); - if(colour_pointer) *colour_pointer = border_; - crt_.output_level(length * 16); + assert(length >= 0); + if(border_) { + uint8_t *const colour_pointer = static_cast(crt_.begin_data(1)); + if(colour_pointer) *colour_pointer = border_; + crt_.output_level(length * 16); + } else { + crt_.output_blank(length * 16); + } } #define Mode0Colour0(c) ((c & 0x80) >> 7) | ((c & 0x20) >> 3) | ((c & 0x08) >> 2) | ((c & 0x02) << 2) From 684644420ae440d0de803a543367cca75b873124 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 20 Oct 2019 17:22:41 -0400 Subject: [PATCH 2/3] Increases scan buffer availability. --- Outputs/OpenGL/ScanTarget.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Outputs/OpenGL/ScanTarget.hpp b/Outputs/OpenGL/ScanTarget.hpp index ce7d671a7..cfe415ed3 100644 --- a/Outputs/OpenGL/ScanTarget.hpp +++ b/Outputs/OpenGL/ScanTarget.hpp @@ -123,8 +123,8 @@ class ScanTarget: public Outputs::Display::ScanTarget { /// A pointer to the first thing not yet submitted for display. std::atomic read_pointers_; - // Maintains a buffer of the most recent 3072 scans. - std::array scan_buffer_; + /// Maintains a buffer of the most recent scans. + std::array scan_buffer_; // Maintains a list of composite scan buffer coordinates; the Line struct // is transported to the GPU in its entirety; the LineMetadatas live in CPU From 95c45b551595da6af32f5ec016e643c7ea1b5517 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 20 Oct 2019 17:22:56 -0400 Subject: [PATCH 3/3] This can be const. --- Machines/AmstradCPC/AmstradCPC.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index ace3aaa52..76d234613 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -249,7 +249,7 @@ class CRTCBusHandler { // the CPC shuffles output lines as: // MA13 MA12 RA2 RA1 RA0 MA9 MA8 MA7 MA6 MA5 MA4 MA3 MA2 MA1 MA0 CCLK // ... so form the real access address. - uint16_t address = + const uint16_t address = static_cast( ((state.refresh_address & 0x3ff) << 1) | ((state.row_address & 0x7) << 11) | @@ -257,7 +257,8 @@ class CRTCBusHandler { ); // Fetch two bytes and translate into pixels. Guaranteed: the mode can change only at - // hsync, so there's no risk of pixel_pointer_ passing 320 without hitting 320. + // hsync, so there's no risk of pixel_pointer_ overrunning 320 output pixels without + // exactly reaching 320 output pixels. switch(mode_) { case 0: reinterpret_cast(pixel_pointer_)[0] = mode0_output_[ram_[address]]; @@ -285,9 +286,9 @@ class CRTCBusHandler { } - // flush the current buffer pixel if full; the CRTC allows many different display + // Flush the current buffer pixel if full; the CRTC allows many different display // widths so it's not necessarily possible to predict the correct number in advance - // and using the upper bound could lead to inefficient behaviour + // and using the upper bound could lead to inefficient behaviour. if(pixel_pointer_ == pixel_data_ + 320) { crt_.output_data(cycles_ * 16, size_t(cycles_ * 16 / pixel_divider_)); pixel_pointer_ = pixel_data_ = nullptr; @@ -371,6 +372,9 @@ class CRTCBusHandler { private: void output_border(int length) { assert(length >= 0); + + // A black border can be output via crt_.output_blank for a minor performance + // win; otherwise paint whatever the border colour really is. if(border_) { uint8_t *const colour_pointer = static_cast(crt_.begin_data(1)); if(colour_pointer) *colour_pointer = border_;