From 2f1b597e8c9a509610cc67525d8ba2c6020ed8f1 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Fri, 26 May 2023 21:30:41 +0300 Subject: [PATCH] Sprite buffer checks --- custom.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/custom.cpp b/custom.cpp index fa8a8fb7..0731d44f 100644 --- a/custom.cpp +++ b/custom.cpp @@ -551,7 +551,8 @@ int bogusframe; /* Recording of custom chip register changes. */ static int current_change_set; -static struct sprite_entry sprite_entries[2][MAX_SPR_PIXELS / 32]; +#define MAX_SPRITE_ENTRIES ((MAXVPOS + MAXVPOS_WRAPLINES) * 16) +static struct sprite_entry sprite_entries[2][MAX_SPRITE_ENTRIES]; static struct color_change color_changes[2][MAX_REG_CHANGE]; struct decision line_decisions[2 * (MAXVPOS + MAXVPOS_WRAPLINES) + 1]; @@ -559,7 +560,7 @@ static struct draw_info line_drawinfo[2][2 * (MAXVPOS + MAXVPOS_WRAPLINES) + 1]; #define COLOR_TABLE_SIZE (MAXVPOS + MAXVPOS_WRAPLINES) * 2 static struct color_entry color_tables[2][COLOR_TABLE_SIZE]; -static int next_sprite_entry = 0, last_sprite_entry = 0, end_sprite_entry; +static int next_sprite_entry = 0, end_sprite_entry; static int prev_next_sprite_entry; static int next_sprite_forced = 1; static int spixels_max; @@ -5588,7 +5589,7 @@ static void record_sprite(int num, int sprxp, uae_u16 *data, uae_u16 *datb, unsi /* Try to coalesce entries if they aren't too far apart */ /* Don't coelesce 64-bit wide sprites, needed to support FMODE change tricks */ - if (!next_sprite_forced && e[-1].max + spr_width >= sprxp) { + if (next_sprite_entry > 0 && !next_sprite_forced && e[-1].max + spr_width >= sprxp) { e--; } else { next_sprite_entry++; @@ -11510,17 +11511,17 @@ void init_hardware_for_drawing_frame(void) int first_pixel = prev_sprite_entries[0].first_pixel; int npixels = prev_sprite_entries[prev_next_sprite_entry].first_pixel - first_pixel; if (npixels > 0) { - memset(spixels + first_pixel, 0, npixels * sizeof * spixels); - memset(spixstate.stb + first_pixel, 0, npixels * sizeof * spixstate.stb); + memset(spixels + first_pixel, 0, npixels * sizeof *spixels); + memset(spixstate.stb + first_pixel, 0, npixels * sizeof *spixstate.stb); if (aga_mode) { - memset(spixstate.stbfm + first_pixel, 0, npixels * sizeof * spixstate.stbfm); + memset(spixstate.stbfm + first_pixel, 0, npixels * sizeof *spixstate.stbfm); } } } + prev_next_sprite_entry = next_sprite_entry; next_sprite_entry = 0; - last_sprite_entry = MAX_SPR_PIXELS - 1; - end_sprite_entry = MAX_SPR_PIXELS - 2; + end_sprite_entry = MAX_SPRITE_ENTRIES - 2; spixels_max = sizeof(spixels) / sizeof(*spixels) - MAX_PIXELS_PER_LINE; next_lineno = calculate_lineno(vpos); -- 2.47.3