Skip to content

Commit 8fb7aef

Browse files
committed
MEGA65: workaround for bad sprite Y in NTSC #428
For unknown reasons, Xemu has 7 (logical raster) off with sprite Y coordinates in NTSC mode. I can't find the root cause so I applied a workaround: in NTSC mode an extra xemu-only-internal variable is set which is applied in sprite rendering. In PAL mode, this var is set to zero. Likely, this bug should be fixed in a more sensical way sooner or later. The problem was originally reported by @MirageBD thanks!
1 parent fb12ebf commit 8fb7aef

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

targets/mega65/vic4.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ int vic_readjust_sdl_viewport = 0;
104104
int vic4_disallow_videostd_change = 0; // Disallows programs to change video std via register D06F, bit 7 (emulator internally writing that bit still can change video std though!)
105105
int vic4_registered_screenshot_request = 0;
106106
unsigned int vic_frame_counter, vic_frame_counter_since_boot;
107+
int sprite_y_adjust_xemu_bug = 0; // Unknown reason of sprite-Y bug in Xemu in NTSC. This is a workaround. FIXME: why is it needed?!
107108

108109

109110
// VIC4 Modeline Parameters
@@ -201,6 +202,7 @@ void vic_reset ( void )
201202
vic4_reset_display_counters();
202203
SET_PHYSICAL_RASTER(0);
203204
chary16 = false;
205+
sprite_y_adjust_xemu_bug = 0;
204206
}
205207

206208

@@ -474,6 +476,7 @@ void vic4_open_frame_access ( void )
474476
visible_area_height = SCREEN_HEIGHT_VISIBLE_NTSC;
475477
vicii_first_raster = 7;
476478
REG_SPRITE_Y_ADJUST = 24;
479+
sprite_y_adjust_xemu_bug = 7;
477480
} else {
478481
// --- PAL ---
479482
new_name = PAL_STD_NAME;
@@ -483,6 +486,7 @@ void vic4_open_frame_access ( void )
483486
visible_area_height = SCREEN_HEIGHT_VISIBLE_PAL;
484487
vicii_first_raster = 0;
485488
REG_SPRITE_Y_ADJUST = 0;
489+
sprite_y_adjust_xemu_bug = 0;
486490
}
487491
DEBUGPRINT("VIC4: switching video standard from %s to %s (1MHz line cycle count is %f, frame time is %dusec, max raster is %d, visible area height is %d)" NL, videostd_name, new_name, videostd_1mhz_cycles_per_scanline, videostd_frametime, max_rasters, visible_area_height);
488492
videostd_name = new_name;
@@ -1210,7 +1214,7 @@ static XEMU_INLINE void vic4_do_sprites ( void )
12101214
#ifdef SPRITE_COORD_LATCHING
12111215
sprite_is_being_rendered[sprnum] ? sprite_y_latch[sprnum] :
12121216
#endif
1213-
((SPRITE_V400(sprnum) ? 1 : 2) * (SPRITE_POS_Y(sprnum) - (SPRITE_V400(sprnum) ? 0 : (REG_SPRITE_Y_ADJUST - 2))));
1217+
((SPRITE_V400(sprnum) ? 1 : 2) * (SPRITE_POS_Y(sprnum) - (SPRITE_V400(sprnum) ? 0 : (REG_SPRITE_Y_ADJUST - 2 + sprite_y_adjust_xemu_bug))));
12141218
int sprite_row_in_raster = ycounter - y_display_pos;
12151219
if (!SPRITE_V400(sprnum))
12161220
sprite_row_in_raster = sprite_row_in_raster >> 1;

0 commit comments

Comments
 (0)