From 975ead5d0135459ab14462dda006bb07168ba843 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 28 Jan 2023 13:54:26 -0500 Subject: [PATCH] Edge towards not assuming graphics mode. Much more to do here. --- Components/9918/Implementation/9918Base.hpp | 35 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index 55761f639..6df32333d 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -584,10 +584,36 @@ template struct Base: public Storage { return; } - // TODO: undo assumption of Graphics Mode 5, pervasively but starting here. - const unsigned int address = - (Storage::command_->location.v[0] >> 2) + - (Storage::command_->location.v[1] << 7); + // Compute the affected address and pixel + unsigned address; + uint8_t mask; + switch(this->screen_mode_) { + default: + case ScreenMode::YamahaGraphics4: // 256 pixels @ 4bpp + address = + (Storage::command_->location.v[0] >> 1) + + (Storage::command_->location.v[1] << 7); + mask = 0xf0 >> ((Storage::command_->location.v[0] & 1) << 2); + break; + case ScreenMode::YamahaGraphics5: // 512 pixels @ 2bpp + address = + (Storage::command_->location.v[0] >> 2) + + (Storage::command_->location.v[1] << 7); + mask = 0xc0 >> ((Storage::command_->location.v[0] & 3) << 1); + break; + case ScreenMode::YamahaGraphics6: // 512 pixels @ 4bpp + address = + (Storage::command_->location.v[0] >> 1) + + (Storage::command_->location.v[1] << 8); + mask = 0xf0 >> ((Storage::command_->location.v[0] & 1) << 2); + break; + case ScreenMode::YamahaGraphics7: // 256 pixels @ 8bpp + address = + (Storage::command_->location.v[0] >> 0) + + (Storage::command_->location.v[1] << 8); + mask = 0xff; + break; + } switch(Storage::next_command_step_) { // Duplicative, but keeps the compiler happy. @@ -606,7 +632,6 @@ template struct Base: public Storage { packed_colour |= packed_colour << 2; packed_colour |= packed_colour << 4; - const uint8_t mask = 0xc0 >> ((Storage::command_->location.v[0] & 3) << 1); Storage::command_latch_ &= ~mask; Storage::command_latch_ |= packed_colour & mask; ram_[address] = Storage::command_latch_;