From a2786e6266ad9bd36d2c9bef871a901292c014fb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 4 Feb 2023 21:14:20 -0500 Subject: [PATCH] Invest Colour with its own logic, including potential emptiness. --- Components/9918/Implementation/9918.cpp | 12 +------ Components/9918/Implementation/9918Base.hpp | 8 ++--- .../9918/Implementation/YamahaCommands.hpp | 31 +++++++++++++++---- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index 80c67c833..1eb761350 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -829,17 +829,7 @@ void Base::commit_register(int reg, uint8_t value) { case 43: Storage::command_context_.size.template set<1, true>(value); break; case 44: - Storage::command_context_.colour = value; - Storage::command_context_.colour4bpp = uint8_t( - (value & 0xf) | - (value << 4) - ); - Storage::command_context_.colour2bpp = uint8_t( - (value & 0x3) | - ((value & 0x3) << 2) | - ((value & 0x3) << 4) | - ((value & 0x3) << 6) - ); + Storage::command_context_.colour.set(value); // Check whether a command was blocked on this. if( diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index 663a3cd83..ba6071335 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -683,21 +683,21 @@ template struct Base: public Storage { return std::make_pair( 0xf0 >> ((location.v[0] & 1) << 2), - Storage::command_context_.colour4bpp + Storage::command_context_.colour.colour4bpp ); case ScreenMode::YamahaGraphics5: // 512 pixels @ 2bpp return std::make_pair( 0xc0 >> ((location.v[0] & 3) << 1), - Storage::command_context_.colour2bpp + Storage::command_context_.colour.colour2bpp ); case ScreenMode::YamahaGraphics7: // 256 pixels @ 8bpp return std::make_pair( 0xff, - Storage::command_context_.colour + Storage::command_context_.colour.colour ); } } else { @@ -786,7 +786,7 @@ template struct Base: public Storage { break; case CommandStep::WriteByte: - ram_[command_address(context.destination)] = context.colour; + ram_[command_address(context.destination)] = context.colour.colour; Storage::command_->advance(pixels_per_byte(this->underlying_mode_)); Storage::update_command_step(access_column); break; diff --git a/Components/9918/Implementation/YamahaCommands.hpp b/Components/9918/Implementation/YamahaCommands.hpp index 9d844698e..415338b0b 100644 --- a/Components/9918/Implementation/YamahaCommands.hpp +++ b/Components/9918/Implementation/YamahaCommands.hpp @@ -42,18 +42,37 @@ struct Vector { } }; +struct Colour { + void set(uint8_t value) { + colour = value; + colour4bpp = uint8_t((value & 0xf) | (value << 4)); + colour2bpp = uint8_t((colour4bpp & 0x33) | ((colour4bpp & 0x33) << 2)); + } + + void reset() { + colour = 0x00; + colour4bpp = 0xff; + } + + bool has_value() { + return (colour & 0x3) == (colour4bpp & 0x3); + } + + /// Colour as written by the CPU. + uint8_t colour = 0x00; + /// The low four bits of the CPU-written colour, repeated twice. + uint8_t colour4bpp = 0xff; + /// The low two bits of the CPU-written colour, repeated four times. + uint8_t colour2bpp = 0xff; +}; + struct CommandContext { Vector source; Vector destination; Vector size; uint8_t arguments = 0; - /// Colour as written by the CPU. - uint8_t colour = 0; - /// The low four bits of the CPU-written colour, repeated twice. - uint8_t colour4bpp = 0; - /// The low two bits of the CPU-written colour, repeated four times. - uint8_t colour2bpp = 0; + Colour colour; enum class LogicalOperation { Copy = 0b0000,