From 0d8af010b6b56598a7657977e1cde1a9271b535c Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 28 Sep 2018 22:37:10 -0400 Subject: [PATCH] Takes a stab at tile reversal and vertical scrolling. --- Components/9918/9918.cpp | 19 ++++++++++++++++--- Components/9918/Implementation/9918Base.hpp | 11 ++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Components/9918/9918.cpp b/Components/9918/9918.cpp index b69eb3922..b3123e6a3 100644 --- a/Components/9918/9918.cpp +++ b/Components/9918/9918.cpp @@ -437,18 +437,19 @@ void TMS9918::run_for(const HalfCycles cycles) { if(pixel_target_) { const int pixels_left = pixels_end - output_column_; const int pixel_location = output_column_ - first_pixel_column_; + const int reverses[2] = {0, 7}; for(int c = 0; c < pixels_left; ++c) { const int column = (pixel_location + c) >> 3; - const int shift = 4 + ((pixel_location + c) & 7); + const int shift = 4 + (((pixel_location + c) & 7) ^ reverses[(master_system_.names[column].flags&2) >> 1]); int value = (( ((master_system_.tile_graphics[column][0] << shift) & 0x800) | ((master_system_.tile_graphics[column][1] << (shift - 1)) & 0x400) | ((master_system_.tile_graphics[column][2] << (shift - 2)) & 0x200) | - (master_system_.tile_graphics[column][3] << (shift - 3)) + ((master_system_.tile_graphics[column][3] << (shift - 3)) & 0x100) ) >> 8) << 4; - pixel_target_[c] = (value << 24) | (value << 16) | (value << 8) | value; + pixel_target_[c] = static_cast((value << 24) | (value << 16) | (value << 8) | value); } pixel_target_ += pixels_left; } @@ -766,6 +767,18 @@ void TMS9918::set_register(int address, uint8_t value) { text_colour_ = low_write_ >> 4; background_colour_ = low_write_ & 0xf; break; + + case 8: + if(is_sega_vdp(personality_)) { + master_system_.horizontal_scroll = low_write_; + } + break; + + case 9: + if(is_sega_vdp(personality_)) { + master_system_.vertical_scroll = low_write_; + } + break; } } else { // This is a write to the RAM pointer. diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index b9acf0a47..7fe0c541d 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -126,6 +126,9 @@ class Base { } names[32]; uint8_t tile_graphics[32][4]; size_t next_column = 0; + + uint8_t horizontal_scroll = 0; + uint8_t vertical_scroll = 0; } master_system_; enum class ScreenMode { @@ -218,7 +221,7 @@ class Base { #define fetch_tile_name(column) {\ size_t address = pattern_address_base + ((column) << 1); \ master_system_.names[column].flags = ram_[address+1]; \ - master_system_.names[column].offset = static_cast((((master_system_.names[column].flags&1) << 8) | ram_[address]) << 5) + sub_row; \ + master_system_.names[column].offset = static_cast((((master_system_.names[column].flags&1) << 8) | ram_[address]) << 5) + sub_row[(master_system_.names[column].flags&4) >> 2]; \ } #define fetch_tile(column) {\ @@ -265,8 +268,10 @@ class Base { - column n+3, tile graphic first word - column n+3, tile graphic second word */ - const size_t pattern_address_base = (pattern_name_address_ | size_t(0x3ff)) & static_cast(((row_ & ~7) << 3) | 0x3800); - const size_t sub_row = static_cast((row_ & 7) << 2); + + const int scrolled_row = (row_ + master_system_.vertical_scroll) % 224; + const size_t pattern_address_base = (pattern_name_address_ | size_t(0x3ff)) & static_cast(((scrolled_row & ~7) << 3) | 0x3800); + const size_t sub_row[2] = {static_cast((scrolled_row & 7) << 2), 28 ^ static_cast((scrolled_row & 7) << 2)}; switch(start) { default: