From 5473bf37a732ad234427917d2aa387ae2b9488df Mon Sep 17 00:00:00 2001 From: y <12588017+y-ack@users.noreply.github.com> Date: Thu, 25 Apr 2024 21:59:53 -0700 Subject: [PATCH] fix savestates with tile usage + minor reorganization --- src/mame/taito/taito_f3.h | 2 +- src/mame/taito/taito_f3_v.cpp | 67 ++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/mame/taito/taito_f3.h b/src/mame/taito/taito_f3.h index 6a7735aa0cfb5..c2a0264ddcf5e 100644 --- a/src/mame/taito/taito_f3.h +++ b/src/mame/taito/taito_f3.h @@ -367,7 +367,7 @@ class taito_f3_state : public driver_device int m_sprite_lag = 0; u8 m_textram_row_usage[64]{}; u8 m_sprite_pri_row_usage[256]{}; - u8 m_tilemap_row_usage[8][32]{}; + u8 m_tilemap_row_usage[32][8]{}; bitmap_ind8 m_pri_alp_bitmap; bitmap_ind16 m_sprite_framebuffer{}; u16 m_width_mask = 0; diff --git a/src/mame/taito/taito_f3_v.cpp b/src/mame/taito/taito_f3_v.cpp index 830f62172a348..00ee41052a41f 100644 --- a/src/mame/taito/taito_f3_v.cpp +++ b/src/mame/taito/taito_f3_v.cpp @@ -352,9 +352,27 @@ const taito_f3_state::F3config taito_f3_state::f3_config_table[] = { void taito_f3_state::device_post_load() { - /* force a reread of the dynamic tiles in the pixel layer */ + // force a reread of the dynamic tiles in the pixel layer m_gfxdecode->gfx(0)->mark_all_dirty(); m_gfxdecode->gfx(1)->mark_all_dirty(); + + // refresh tile usage indexes + std::fill_n(*m_tilemap_row_usage, 32 * 8, 0); + std::fill_n(m_textram_row_usage, 64, 0); + // playfield blank tiles + for (int offset = 1; offset < 0x4000; offset += 2) { + const int row = m_extend ? BIT(offset, 7, 5) : BIT(offset, 6, 5); + const int tmap = m_extend ? offset >> 12 : offset >> 11; + if (m_pf_ram[offset] != 0) + m_tilemap_row_usage[row][tmap] += 1; + } + // textram blank tiles + for (int offset = 0; offset < 0x1000; offset++) { + const u8 tile = BIT(m_textram[offset], 0, 8); + const int row = BIT(offset, 6, 6); + if (tile != 0) + m_textram_row_usage[row] += 1; + } } /******************************************************************************/ @@ -471,8 +489,8 @@ void taito_f3_state::create_tilemaps(bool extend) for (int i = 0; i < 8; i++) { if (m_tilemap[i]) m_tilemap[i]->set_transparent_pen(0); - std::fill_n(m_tilemap_row_usage[i], 32, 0); } + std::fill_n(*m_tilemap_row_usage, 32 * 8, 0); if (m_extend) { m_width_mask = 0x3ff; // 10 bits @@ -543,26 +561,25 @@ void taito_f3_state::pf_ram_w(offs_t offset, u16 data, u16 mem_mask) { // [.ttt yyyy yxxx xxa|h] non-extend // [.tty yyyy xxxx xxa|h] extend - if (offset & 1 && offset < 0x4000) { - const int row = m_extend ? BIT(offset, 7, 5) : BIT(offset, 6, 5); - const u16 prev_tile = m_pf_ram[offset]; - const int tmap = m_extend ? offset >> 12 : offset >> 11; - - if (prev_tile == 0 && data != 0) - m_tilemap_row_usage[tmap][row] += 1; - else if (prev_tile != 0 && data == 0) - m_tilemap_row_usage[tmap][row] -= 1; - } + const u16 prev_tile = m_pf_ram[offset]; COMBINE_DATA(&m_pf_ram[offset]); - if (m_game_config->extend) { - if (offset < 0x4000) { - m_tilemap[offset >> 12]->mark_tile_dirty((offset & 0xfff) >> 1); + if (offset < 0x4000) { + if (offset & 1) { + const int row = m_extend ? BIT(offset, 7, 5) : BIT(offset, 6, 5); + const int tmap = m_extend ? offset >> 12 : offset >> 11; + if ((prev_tile == 0) && (m_pf_ram[offset] != 0)) + m_tilemap_row_usage[row][tmap] += 1; + else if ((prev_tile != 0) && (m_pf_ram[offset] == 0)) + m_tilemap_row_usage[row][tmap] -= 1; } - } else { - if (offset < 0x4000) + + if (m_game_config->extend) { + m_tilemap[offset >> 12]->mark_tile_dirty((offset & 0xfff) >> 1); + } else { m_tilemap[offset >> 11]->mark_tile_dirty((offset & 0x7ff) >> 1); + } } } @@ -593,15 +610,17 @@ u16 taito_f3_state::textram_r(offs_t offset) void taito_f3_state::textram_w(offs_t offset, u16 data, u16 mem_mask) { - const int row = BIT(offset, 6, 6); - const u16 prev_tile = m_textram[offset]; - if (prev_tile == 0 && data != 0) - m_textram_row_usage[row] += 1; - else if (prev_tile != 0 && data == 0) - m_textram_row_usage[row] -= 1; + const u8 prev_tile = BIT(m_textram[offset], 0, 8); COMBINE_DATA(&m_textram[offset]); + const int row = BIT(offset, 6, 6); + const u8 tile = BIT(m_textram[offset], 0, 8); + if (prev_tile == 0 && tile != 0) + m_textram_row_usage[row] += 1; + else if (prev_tile != 0 && tile == 0) + m_textram_row_usage[row] -= 1; + m_vram_layer->mark_tile_dirty(offset); // dirty the pixel layer too, since it uses palette etc. from text layer @@ -1108,7 +1127,7 @@ inline bool taito_f3_state::used(const sprite_inf &layer, int y) const inline bool taito_f3_state::used(const playfield_inf &layer, int y) const { const int y_adj = m_flipscreen ? 0x1ff - layer.y_index(y) : layer.y_index(y); - return m_tilemap_row_usage[layer.index + (2 * layer.alt_tilemap)][y_adj >> 4] > 0; + return m_tilemap_row_usage[y_adj >> 4][layer.index + (2 * layer.alt_tilemap)] > 0; } void taito_f3_state::scanline_draw(bitmap_rgb32 &bitmap, const rectangle &cliprect)