From e58a488add76885bf0fa45a6ca19722cffd45ed9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 3 Mar 2023 23:06:52 -0500 Subject: [PATCH] Rotate command-engine addresses in modes 6 and 7. --- Components/9918/Implementation/9918Base.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index de78245c7..e51847f47 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -266,6 +266,10 @@ template struct Base: public Storage { return ScreenMode::Blank; } + static AddressT rotate(AddressT address) { + return AddressT((address >> 1) | (address << 16)) & memory_mask(personality); + } + AddressT command_address(Vector location) const { if constexpr (is_yamaha_vdp(personality)) { switch(this->screen_mode_) { @@ -283,16 +287,16 @@ template struct Base: public Storage { ); case ScreenMode::YamahaGraphics6: // 512 pixels @ 4bpp - return AddressT( + return rotate(AddressT( (location.v[0] >> 1) + (location.v[1] << 8) - ); + )); case ScreenMode::YamahaGraphics7: // 256 pixels @ 8bpp - return AddressT( + return rotate(AddressT( (location.v[0] >> 0) + (location.v[1] << 8) - ); + )); } } else { return 0; @@ -459,7 +463,7 @@ template struct Base: public Storage { // Rotate address one to the right as the hardware accesses // the underlying banks of memory alternately but presents // them as if linear. - address = (address >> 1) | (address << 16); + address = rotate(address); } // Also check whether expansion RAM is the true target here.