From fb15f89776b4c9e51e2f44b4e2c7e7843ba08ea4 Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Fri, 23 May 2025 10:06:21 -0600 Subject: [PATCH] Increased sprite limit per pixel to 10 this fixes the sprite ordering issue in zelda --- include/ppu.h | 4 ++-- lib/ppu_pipeline.c | 8 ++++---- lib/ui.c | 17 +++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/ppu.h b/include/ppu.h index dcc1941..c08b3d9 100644 --- a/include/ppu.h +++ b/include/ppu.h @@ -35,7 +35,7 @@ typedef struct { u8 pushed_x; u8 fetch_x; u8 bgw_fetch_data[3]; - u8 fetch_entry_data[6]; //oam data + u8 fetch_entry_data[20]; //oam data u8 map_y; u8 map_x; u8 tile_y; @@ -70,7 +70,7 @@ typedef struct { oam_line_entry line_entry_array[10]; //memory to use for list u8 fetched_entry_count; - oam_entry fetched_entries[3]; //entries fetched during pipeline + oam_entry fetched_entries[10]; //entries fetched during pipeline u8 window_line; pixel_fifo_context pfc; diff --git a/lib/ppu_pipeline.c b/lib/ppu_pipeline.c index 689e14b..497f3b6 100644 --- a/lib/ppu_pipeline.c +++ b/lib/ppu_pipeline.c @@ -104,7 +104,7 @@ bool pipeline_fifo_add() { color = lcd_get_context()->bg_colors[0]; } - if(LCDC_OBJ_ENABLE) { + if(LCDC_OBJ_ENABLE && !ppu_get_context()->debug) { color = fetch_sprite_pixels(bit, color, hi | lo); } @@ -130,8 +130,8 @@ void pipeline_load_sprite_tile() { le = le->next; - if (!le || ppu_get_context()->fetched_entry_count >= 3) { - //max checking 3 sprites on pixels + if (!le || ppu_get_context()->fetched_entry_count >= 10) { + //max checking 10 sprites on pixels break; } } @@ -287,7 +287,7 @@ void pipeline_push_pixel() { } if(ppu_get_context()->rendering_window) { ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x + - (lcd_get_context()->ly * XRES)] = ppu_get_context()->debug ? 0xFF0000 : pixel_data;//interpolate(ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x + + (lcd_get_context()->ly * XRES)] = pixel_data;//interpolate(ppu_get_context()->video_buffer[ppu_get_context()->pfc.pushed_x + //(lcd_get_context()->ly * XRES)], pixel_data); ppu_get_context()->pfc.pushed_x++; diff --git a/lib/ui.c b/lib/ui.c index 730fd7e..eeba5a1 100644 --- a/lib/ui.c +++ b/lib/ui.c @@ -23,6 +23,7 @@ SDL_Window *sdlDebugWindow; SDL_Renderer *sdlDebugRenderer; SDL_Texture *sdlDebugTexture; SDL_Surface *debugScreen; +TTF_Font *sans; static int scale = 4; @@ -32,6 +33,14 @@ void ui_init(){ TTF_Init(); printf("TTF INIT\n"); + char buffer[1024]; + strcpy(buffer, emu_get_context()->app_path); + *strrchr(buffer, '\\') = 0; + strcat(buffer,"/Sans.ttf"); + sans = TTF_OpenFont(buffer, 24); + if ( !sans ) { + printf("Failed to load font: %s\n", TTF_GetError()); + } SDL_CreateWindowAndRenderer(SCREEN_WIDTH, SCREEN_HEIGHT, 0, &sdlWindow, &sdlRenderer); screen = SDL_CreateRGBSurface(0, SCREEN_WIDTH, @@ -138,14 +147,6 @@ void ui_update() { SDL_UpdateTexture(sdlTexture, NULL, screen->pixels, screen->pitch); SDL_RenderClear(sdlRenderer); SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); - char buffer[1024]; - strcpy(buffer, emu_get_context()->app_path); - *strrchr(buffer, '\\') = 0; - strcat(buffer,"/Sans.ttf"); - TTF_Font* sans = TTF_OpenFont(buffer, 24); - if ( !sans ) { - printf("Failed to load font: %s\n", TTF_GetError()); - } SDL_Color text_color = {255,255,255}; int yOffset = 50; int lastY = (yOffset) - (audio_get_context()->sq1_history[audio_get_context()->sq1_index] * 50);