From 392b0acb58d04098cdf896515e52ad7038e1af63 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 19 Jan 2023 15:09:16 -0500 Subject: [PATCH] Pull everything out of `master_system_` struct. Now that it's inherently collected in the relevant `Storage`. --- Components/9918/Implementation/9918.cpp | 44 ++++++++++----------- Components/9918/Implementation/9918Base.hpp | 39 +++++++++--------- Components/9918/Implementation/Draw.hpp | 4 +- Components/9918/Implementation/Fetch.hpp | 20 +++++----- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/Components/9918/Implementation/9918.cpp b/Components/9918/Implementation/9918.cpp index 8bf87691d..3ea99a45a 100644 --- a/Components/9918/Implementation/9918.cpp +++ b/Components/9918/Implementation/9918.cpp @@ -178,9 +178,9 @@ void TMS9918::run_for(const HalfCycles cycles) { if constexpr (is_sega_vdp(personality)) { if(this->write_pointer_.column < 61 && end_column >= 61) { if(!this->write_pointer_.row) { - this->master_system_.latched_vertical_scroll = this->master_system_.vertical_scroll; + Storage::latched_vertical_scroll_ = Storage::vertical_scroll_; - if(this->master_system_.mode4_enable) { + if(Storage::mode4_enable_) { this->mode_timing_.pixel_lines = 192; if(this->mode2_enable_ && this->mode1_enable_) this->mode_timing_.pixel_lines = 224; if(this->mode2_enable_ && this->mode3_enable_) this->mode_timing_.pixel_lines = 240; @@ -191,7 +191,7 @@ void TMS9918::run_for(const HalfCycles cycles) { this->mode_timing_.end_of_frame_interrupt_position.row = this->mode_timing_.pixel_lines + 1; } } - line_buffer.latched_horizontal_scroll = this->master_system_.horizontal_scroll; + line_buffer.latched_horizontal_scroll = Storage::horizontal_scroll_; } } @@ -230,13 +230,13 @@ void TMS9918::run_for(const HalfCycles cycles) { // It is otherwise decremented. if constexpr (is_sega_vdp(personality)) { if(this->write_pointer_.row >= 0 && this->write_pointer_.row <= this->mode_timing_.pixel_lines) { - --this->line_interrupt_counter; - if(this->line_interrupt_counter == 0xff) { + --this->line_interrupt_counter_; + if(this->line_interrupt_counter_ == 0xff) { this->line_interrupt_pending_ = true; - this->line_interrupt_counter = this->line_interrupt_target; + this->line_interrupt_counter_ = this->line_interrupt_target_; } } else { - this->line_interrupt_counter = this->line_interrupt_target; + this->line_interrupt_counter_ = this->line_interrupt_target_; } } @@ -575,12 +575,12 @@ void Base::write_register(uint8_t value) { switch(value) { case 0: if constexpr (is_sega_vdp(personality)) { - Storage::master_system_.vertical_scroll_lock = low_write_ & 0x80; - Storage::master_system_.horizontal_scroll_lock = low_write_ & 0x40; - Storage::master_system_.hide_left_column = low_write_ & 0x20; + Storage::vertical_scroll_lock_ = low_write_ & 0x80; + Storage::horizontal_scroll_lock_ = low_write_ & 0x40; + Storage::hide_left_column_ = low_write_ & 0x20; enable_line_interrupts_ = low_write_ & 0x10; - Storage::master_system_.shift_sprites_8px_left = low_write_ & 0x08; - Storage::master_system_.mode4_enable = low_write_ & 0x04; + Storage::shift_sprites_8px_left_ = low_write_ & 0x08; + Storage::mode4_enable_ = low_write_ & 0x04; } mode2_enable_ = low_write_ & 0x02; break; @@ -602,7 +602,7 @@ void Base::write_register(uint8_t value) { pattern_name_address_ = size_t((low_write_ & 0xf) << 10) | 0x3ff; if constexpr (is_sega_vdp(personality)) { - Storage::master_system_.pattern_name_address = pattern_name_address_ | ((personality == TMS::SMSVDP) ? 0x000 : 0x400); + Storage::pattern_name_address_ = pattern_name_address_ | ((personality == TMS::SMSVDP) ? 0x000 : 0x400); } break; @@ -617,14 +617,14 @@ void Base::write_register(uint8_t value) { case 5: sprite_attribute_table_address_ = size_t((low_write_ & 0x7f) << 7) | 0x7f; if constexpr (is_sega_vdp(personality)) { - Storage::master_system_.sprite_attribute_table_address = sprite_attribute_table_address_ | ((personality == TMS::SMSVDP) ? 0x00 : 0x80); + Storage::sprite_attribute_table_address_ = sprite_attribute_table_address_ | ((personality == TMS::SMSVDP) ? 0x00 : 0x80); } break; case 6: sprite_generator_table_address_ = size_t((low_write_ & 0x07) << 11) | 0x7ff; if constexpr (is_sega_vdp(personality)) { - Storage::master_system_.sprite_generator_table_address = sprite_generator_table_address_ | ((personality == TMS::SMSVDP) ? 0x0000 : 0x1800); + Storage::sprite_generator_table_address_ = sprite_generator_table_address_ | ((personality == TMS::SMSVDP) ? 0x0000 : 0x1800); } break; @@ -635,7 +635,7 @@ void Base::write_register(uint8_t value) { case 8: if constexpr (is_sega_vdp(personality)) { - Storage::master_system_.horizontal_scroll = low_write_; + Storage::horizontal_scroll_ = low_write_; } else { LOG("Unknown TMS write: " << int(low_write_) << " to " << int(value)); } @@ -643,7 +643,7 @@ void Base::write_register(uint8_t value) { case 9: if constexpr (is_sega_vdp(personality)) { - Storage::master_system_.vertical_scroll = low_write_; + Storage::vertical_scroll_ = low_write_; } else { LOG("Unknown TMS write: " << int(low_write_) << " to " << int(value)); } @@ -651,7 +651,7 @@ void Base::write_register(uint8_t value) { case 10: if constexpr (is_sega_vdp(personality)) { - line_interrupt_target = low_write_; + line_interrupt_target_ = low_write_; } else { LOG("Unknown TMS write: " << int(low_write_) << " to " << int(value)); } @@ -837,11 +837,11 @@ HalfCycles TMS9918::get_next_sequence_point() const { // If there is still time for a line interrupt this frame, that'll be it; // otherwise it'll be on the next frame, supposing there's ever time for // it at all. - if(line_of_next_interrupt_threshold + this->line_interrupt_counter <= this->mode_timing_.pixel_lines) { - next_line_interrupt_row = line_of_next_interrupt_threshold + this->line_interrupt_counter; + if(line_of_next_interrupt_threshold + this->line_interrupt_counter_ <= this->mode_timing_.pixel_lines) { + next_line_interrupt_row = line_of_next_interrupt_threshold + this->line_interrupt_counter_; } else { - if(this->line_interrupt_target <= this->mode_timing_.pixel_lines) - next_line_interrupt_row = this->mode_timing_.total_lines + this->line_interrupt_target; + if(this->line_interrupt_target_ <= this->mode_timing_.pixel_lines) + next_line_interrupt_row = this->mode_timing_.total_lines + this->line_interrupt_target_; } } diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index 6a219bc41..273d87a25 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -147,24 +147,25 @@ template struct Storage struct Base: public Storage { @@ -285,8 +286,8 @@ template struct Base: public Storage { uint8_t sprite_terminator = 0xd0; } mode_timing_; - uint8_t line_interrupt_target = 0xff; - uint8_t line_interrupt_counter = 0; + uint8_t line_interrupt_target_ = 0xff; + uint8_t line_interrupt_counter_ = 0; bool enable_line_interrupts_ = false; bool line_interrupt_pending_ = false; @@ -317,7 +318,7 @@ template struct Base: public Storage { } if constexpr (is_sega_vdp(personality)) { - if(Storage::master_system_.mode4_enable) { + if(Storage::mode4_enable_) { return ScreenMode::SMSMode4; } } diff --git a/Components/9918/Implementation/Draw.hpp b/Components/9918/Implementation/Draw.hpp index f997c3ace..f0eef02d3 100644 --- a/Components/9918/Implementation/Draw.hpp +++ b/Components/9918/Implementation/Draw.hpp @@ -143,7 +143,7 @@ void Base::draw_sms(int start, int end, uint32_t cram_dot) { */ int tile_start = start, tile_end = end; int tile_offset = start; - if(read_pointer_.row >= 16 || !Storage::master_system_.horizontal_scroll_lock) { + if(read_pointer_.row >= 16 || !Storage::horizontal_scroll_lock_) { for(int c = start; c < (line_buffer.latched_horizontal_scroll & 7); ++c) { colour_buffer[c] = 16 + background_colour_; ++tile_offset; @@ -276,7 +276,7 @@ void Base::draw_sms(int start, int end, uint32_t cram_dot) { // If the VDP is set to hide the left column and this is the final call that'll come // this line, hide it. if(end == 256) { - if(Storage::master_system_.hide_left_column) { + if(Storage::hide_left_column_) { pixel_origin_[0] = pixel_origin_[1] = pixel_origin_[2] = pixel_origin_[3] = pixel_origin_[4] = pixel_origin_[5] = pixel_origin_[6] = pixel_origin_[7] = Storage::colour_ram_[16 + background_colour_]; diff --git a/Components/9918/Implementation/Fetch.hpp b/Components/9918/Implementation/Fetch.hpp index 1e3697623..11b3bd7f0 100644 --- a/Components/9918/Implementation/Fetch.hpp +++ b/Components/9918/Implementation/Fetch.hpp @@ -324,12 +324,12 @@ template void Base::fetch_sms(int start, int end) { #define sprite_fetch(sprite) {\ line_buffer.active_sprites[sprite].x = \ ram_[\ - Storage::master_system_.sprite_attribute_table_address & size_t(0x3f80 | (line_buffer.active_sprites[sprite].index << 1))\ - ] - (Storage::master_system_.shift_sprites_8px_left ? 8 : 0); \ + Storage::sprite_attribute_table_address_ & size_t(0x3f80 | (line_buffer.active_sprites[sprite].index << 1))\ + ] - (Storage::shift_sprites_8px_left_ ? 8 : 0); \ const uint8_t name = ram_[\ - Storage::master_system_.sprite_attribute_table_address & size_t(0x3f81 | (line_buffer.active_sprites[sprite].index << 1))\ + Storage::sprite_attribute_table_address_ & size_t(0x3f81 | (line_buffer.active_sprites[sprite].index << 1))\ ] & (sprites_16x16_ ? ~1 : ~0);\ - const size_t graphic_location = Storage::master_system_.sprite_generator_table_address & size_t(0x2000 | (name << 5) | (line_buffer.active_sprites[sprite].row << 2)); \ + const size_t graphic_location = Storage::sprite_generator_table_address_ & size_t(0x2000 | (name << 5) | (line_buffer.active_sprites[sprite].row << 2)); \ line_buffer.active_sprites[sprite].image[0] = ram_[graphic_location]; \ line_buffer.active_sprites[sprite].image[1] = ram_[graphic_location+1]; \ line_buffer.active_sprites[sprite].image[2] = ram_[graphic_location+2]; \ @@ -348,8 +348,8 @@ template void Base::fetch_sms(int start, int end) { #define sprite_y_read(location, sprite) \ slot(location): \ - posit_sprite(sprite_selection_buffer, sprite, ram_[Storage::master_system_.sprite_attribute_table_address & ((sprite) | 0x3f00)], write_pointer_.row); \ - posit_sprite(sprite_selection_buffer, sprite+1, ram_[Storage::master_system_.sprite_attribute_table_address & ((sprite + 1) | 0x3f00)], write_pointer_.row); \ + posit_sprite(sprite_selection_buffer, sprite, ram_[Storage::sprite_attribute_table_address_ & ((sprite) | 0x3f00)], write_pointer_.row); \ + posit_sprite(sprite_selection_buffer, sprite+1, ram_[Storage::sprite_attribute_table_address_ & ((sprite + 1) | 0x3f00)], write_pointer_.row); \ #define fetch_tile_name(column, row_info) {\ const size_t scrolled_column = (column - horizontal_offset) & 0x1f;\ @@ -393,16 +393,16 @@ template void Base::fetch_sms(int start, int end) { // Determine the coarse horizontal scrolling offset; this isn't applied on the first two lines if the programmer has requested it. LineBuffer &line_buffer = line_buffers_[write_pointer_.row]; LineBuffer &sprite_selection_buffer = line_buffers_[(write_pointer_.row + 1) % mode_timing_.total_lines]; - const int horizontal_offset = (write_pointer_.row >= 16 || !Storage::master_system_.horizontal_scroll_lock) ? (line_buffer.latched_horizontal_scroll >> 3) : 0; + const int horizontal_offset = (write_pointer_.row >= 16 || !Storage::horizontal_scroll_lock_) ? (line_buffer.latched_horizontal_scroll >> 3) : 0; // Limit address bits in use if this is a SMS2 mode. const bool is_tall_mode = mode_timing_.pixel_lines != 192; - const size_t pattern_name_address = Storage::master_system_.pattern_name_address | (is_tall_mode ? 0x800 : 0); + const size_t pattern_name_address = Storage::pattern_name_address_ | (is_tall_mode ? 0x800 : 0); const size_t pattern_name_offset = is_tall_mode ? 0x100 : 0; // Determine row info for the screen both (i) if vertical scrolling is applied; and (ii) if it isn't. // The programmer can opt out of applying vertical scrolling to the right-hand portion of the display. - const int scrolled_row = (write_pointer_.row + Storage::master_system_.latched_vertical_scroll) % (is_tall_mode ? 256 : 224); + const int scrolled_row = (write_pointer_.row + Storage::latched_vertical_scroll_) % (is_tall_mode ? 256 : 224); struct RowInfo { size_t pattern_address_base; size_t sub_row[2]; @@ -412,7 +412,7 @@ template void Base::fetch_sms(int start, int end) { {size_t((scrolled_row & 7) << 2), 28 ^ size_t((scrolled_row & 7) << 2)} }; RowInfo row_info; - if(Storage::master_system_.vertical_scroll_lock) { + if(Storage::vertical_scroll_lock_) { row_info.pattern_address_base = (pattern_name_address & size_t(((write_pointer_.row & ~7) << 3) | 0x3800)) - pattern_name_offset; row_info.sub_row[0] = size_t((write_pointer_.row & 7) << 2); row_info.sub_row[1] = 28 ^ size_t((write_pointer_.row & 7) << 2);