From 4da737135d8e9c3bca629def39704325140597ec Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Fri, 21 Feb 2025 12:36:25 -0700 Subject: [PATCH] fixed zelda line weirdness --- include/ppu.h | 1 + lib/ppu_pipeline.c | 8 ++++---- lib/ppu_sm.c | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/ppu.h b/include/ppu.h index 6a9c39f..dcc1941 100644 --- a/include/ppu.h +++ b/include/ppu.h @@ -40,6 +40,7 @@ typedef struct { u8 map_x; u8 tile_y; u8 fifo_x; + u8 lo_scroll_x; } pixel_fifo_context; typedef struct { diff --git a/lib/ppu_pipeline.c b/lib/ppu_pipeline.c index 8a214d8..c4d331a 100644 --- a/lib/ppu_pipeline.c +++ b/lib/ppu_pipeline.c @@ -41,7 +41,7 @@ u32 pixel_fifo_pop() { u32 fetch_sprite_pixels(int bit, u32 color, u8 bg_color) { for (int i = 0; i < ppu_get_context()->fetched_entry_count; i++) { int sp_x = (ppu_get_context()->fetched_entries[i].x - 8) + - ((lcd_get_context()->scroll_x % 8)); + ((ppu_get_context()->pfc.lo_scroll_x)); if(ppu_get_context()->rendering_window) { sp_x = (ppu_get_context()->fetched_entries[i].x - 8); } @@ -92,7 +92,7 @@ bool pipeline_fifo_add() { return false; } - int x = ppu_get_context()->pfc.fetch_x - (8 - lcd_get_context()->scroll_x % 8); + int x = ppu_get_context()->pfc.fetch_x - (8 - ppu_get_context()->pfc.lo_scroll_x); for (int i=0; i<8; i++) { int bit = 7 - i; @@ -121,7 +121,7 @@ void pipeline_load_sprite_tile() { oam_line_entry *le = ppu_get_context()->line_sprites; while(le) { - int sp_x = (le->entry.x - 8) + (lcd_get_context()->scroll_x % 8); + int sp_x = (le->entry.x - 8) + (ppu_get_context()->pfc.lo_scroll_x); if ((sp_x >= ppu_get_context()->pfc.fetch_x && sp_x < ppu_get_context()->pfc.fetch_x + 8) || ((sp_x + 8) >= ppu_get_context()->pfc.fetch_x && (sp_x + 8) < ppu_get_context()->pfc.fetch_x + 8)) { @@ -292,7 +292,7 @@ void pipeline_push_pixel() { ppu_get_context()->pfc.pushed_x++; }else { - if(ppu_get_context()->pfc.line_x >= (lcd_get_context()->scroll_x % 8)) { + if(ppu_get_context()->pfc.line_x >= (ppu_get_context()->pfc.lo_scroll_x)) { ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x + (lcd_get_context()->ly * XRES)] = interpolate(ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x + (lcd_get_context()->ly * XRES)], pixel_data); diff --git a/lib/ppu_sm.c b/lib/ppu_sm.c index 239198e..1986be1 100644 --- a/lib/ppu_sm.c +++ b/lib/ppu_sm.c @@ -94,6 +94,7 @@ void ppu_mode_oam() { } if(ppu_get_context()->line_ticks == 1) { + ppu_get_context()->pfc.lo_scroll_x = lcd_get_context()->scroll_x & 0b111; //read oam on the first tick only... ppu_get_context()->line_sprites = 0; ppu_get_context()->line_sprite_count = 0;