diff --git a/Components/9918/9918.cpp b/Components/9918/9918.cpp index 2fe0fb186..410870019 100644 --- a/Components/9918/9918.cpp +++ b/Components/9918/9918.cpp @@ -712,6 +712,13 @@ void Base::draw_tms_text(int start, int end) { void Base::draw_sms(int start, int end) { const bool is_end = end == 256; + // If this is the very start of the line, clear the background + // priority mask — it will be a bitfield in which 1s indicate locations + // where the background should take priority over the sprites. + if(!start) { + memset(master_system_.background_priority_mask, 0, sizeof(master_system_.background_priority_mask)); + } + // Shift the output window by the fine scroll amount, and fill in // any border pixels that leaves on the left-hand side. if(row_ >= 16 || !master_system_.horizontal_scroll_lock) { diff --git a/Components/9918/Implementation/9918Base.hpp b/Components/9918/Implementation/9918Base.hpp index 992ae5026..b56933d08 100644 --- a/Components/9918/Implementation/9918Base.hpp +++ b/Components/9918/Implementation/9918Base.hpp @@ -154,10 +154,13 @@ class Base { // then the appropriate status information will be set. int maximum_visible_sprites = 4; - // + // Set the position, in cycles, of the two interrupts, + // within a line. int end_of_frame_interrupt_position = 342; int line_interrupt_position = -1; + // Enables or disabled the recognition of 0xd0 as a sprite + // list terminator. bool allow_sprite_terminator = true; } mode_timing_; @@ -201,6 +204,7 @@ class Base { } names[32]; uint8_t tile_graphics[32][4]; size_t next_column = 0; + uint32_t background_priority_mask[9]; } master_system_; // Holds results of sprite data fetches that occur on this @@ -406,7 +410,7 @@ class Base { template void fetch_tms_text(int start, int end) { #define fetch_tile_name(location, column) slot(location): pattern_names_[column] = ram_[row_base + column]; -#define fetch_tile_pattern(location, column) slot(location): pattern_buffer_[column] = ram_[row_offset + static_cast(pattern_names_[column] << 3)]; +#define fetch_tile_pattern(location, column) slot(location): pattern_buffer_[column] = ram_[row_offset + size_t(pattern_names_[column] << 3)]; #define fetch_column(location, column) \ fetch_tile_name(location, column); \ @@ -425,8 +429,8 @@ class Base { fetch_columns_4(location, column); \ fetch_columns_4(location+12, column+4); - const size_t row_base = pattern_name_address_ & static_cast(row_ >> 3) * 40; - const size_t row_offset = pattern_generator_table_address_ & (row_ & 7); + const size_t row_base = pattern_name_address_ & (0x3c00 | static_cast(row_ >> 3) * 40); + const size_t row_offset = pattern_generator_table_address_ & (0x3800 | (row_ & 7)); switch(start) { default: