From 3239cfb683bb4d679dbfa2a2d3dd5725174230e1 Mon Sep 17 00:00:00 2001 From: Cuyler36 Date: Wed, 15 Jul 2026 18:37:53 -0400 Subject: [PATCH] Match ksNesDrawObjSetupMMC2 Co-authored-by: GRAnimated <23510999+GRAnimated@users.noreply.github.com> --- src/static/Famicom/ks_nes_draw.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/static/Famicom/ks_nes_draw.cpp b/src/static/Famicom/ks_nes_draw.cpp index 6e449d7d..b5189a5f 100644 --- a/src/static/Famicom/ks_nes_draw.cpp +++ b/src/static/Famicom/ks_nes_draw.cpp @@ -307,6 +307,9 @@ set: DCFlushRangeNoSync(wp->draw_ctx.bg_palette_attr_texture, sizeof(wp->draw_ctx.bg_palette_attr_texture)); } +// @HACK - necessary to match ksNesDrawOBJSetupMMC2, need to figure out the real solution... this can't be right +#define ksNesGetOAMEntry(wp, i) (((ksNesCommonWorkObj*)((u8*)(wp) + (i)))->draw_ctx.OAMTable[0]) + void ksNesDrawOBJSetupMMC2(ksNesCommonWorkObj* wp) { u32 i; u32 j; @@ -314,18 +317,16 @@ void ksNesDrawOBJSetupMMC2(ksNesCommonWorkObj* wp) { u32 bank; memset(wp->draw_ctx.mmc2_scanline_latch_tiles, 0, KS_NES_SCANLINE_COUNT * sizeof(u8)); - for (i = 0; i < ARRAY_COUNT(wp->draw_ctx.OAMTable); i++) { + for (i = 0; i < ARRAY_COUNT(wp->draw_ctx.OAMTable) * sizeof(ksNesOAMEntry); i += sizeof(ksNesOAMEntry)) { // ppu_scanline_regs is the scanline state, OAMTable is list of scanline triggers? - if (wp->draw_ctx.OAMTable[i].y_pos >= 236 || (wp->draw_ctx.OAMTable[i].tile_index != ksNes_MMC2_LATCH_HI && wp->draw_ctx.OAMTable[i].tile_index != ksNes_MMC2_LATCH_LO)) { - continue; + if (ksNesGetOAMEntry(wp, i).y_pos < 236 && (ksNesGetOAMEntry(wp, i).tile_index == ksNes_MMC2_LATCH_HI || ksNesGetOAMEntry(wp, i).tile_index == ksNes_MMC2_LATCH_LO)) { + u32 j = ksNesGetOAMEntry(wp, i).y_pos; + u32 maxv = j + 8 + ((wp->draw_ctx.ppu_scanline_regs[j].ppu_ctrl & KS_NES_PPU_CTRL_SPRITE_SIZE) >> 5) * 8; + do { + wp->draw_ctx.mmc2_scanline_latch_tiles[j] = ksNesGetOAMEntry(wp, i).tile_index; + j++; + } while(j < maxv); } - - j = wp->draw_ctx.OAMTable[i].y_pos; - bank = j + 8 + ((wp->draw_ctx.ppu_scanline_regs[j].ppu_ctrl & KS_NES_PPU_CTRL_SPRITE_SIZE) >> 2); - do { - wp->draw_ctx.mmc2_scanline_latch_tiles[j] = wp->draw_ctx.OAMTable[i].tile_index; - j++; - } while(j < bank); } // _0200 is the scanline marker entries