From 48b77511bfd2fe77c5c39e45cf93474d48398fd7 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Fri, 2 Jul 2010 13:21:21 +0000 Subject: [PATCH] .fixed a bug with sprite rendering .additional "optimization" --- source/render.c | 37 ++++++++++++++++++------------------- source/vdp.c | 6 +++--- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/source/render.c b/source/render.c index da50ba3..0fb449c 100644 --- a/source/render.c +++ b/source/render.c @@ -1456,19 +1456,18 @@ static void render_bg_im2_vs(int line, int width, int odd) static int spr_over = 0; -static void render_obj(int line, uint8 *buf, uint8 *table) +static void render_obj(uint8 *buf, uint8 *table) { uint8 sizetab[] = {8, 16, 24, 32}; int i, count, column; - int xpos; - int v_line; + int xpos, width; int pixelmax = bitmap.viewport.w; int pixelcount = 0; int masked = 0; uint8 *src, *s, *lb; - uint32 size, width; + uint32 size, v_line; uint32 attr, attr_mask, name, palette, index; object *obj_info = object_info[object_which]; @@ -1500,7 +1499,7 @@ static void render_obj(int line, uint8 *buf, uint8 *table) pixelcount += width; /* draw visible sprites */ - if (((xpos + width) >= 0) && (xpos < pixelmax) && !masked) + if (((xpos + width) > 0) && (xpos < pixelmax) && !masked) { /* sprite attributes + pattern index */ attr = obj_info[count].attr; @@ -1509,7 +1508,7 @@ static void render_obj(int line, uint8 *buf, uint8 *table) name = attr & 0x07FF; /* sprite vertical offset */ - v_line = line - obj_info[count].ypos; + v_line = obj_info[count].ypos; s = &name_lut[((attr >> 3) & 0x300) | (size << 4) | ((v_line & 0x18) >> 1)]; v_line = (v_line & 7) << 3; @@ -1545,19 +1544,18 @@ static void render_obj(int line, uint8 *buf, uint8 *table) spr_over = 0; } -static void render_obj_im2(int line, int odd, uint8 *buf, uint8 *table) +static void render_obj_im2(int odd, uint8 *buf, uint8 *table) { uint8 sizetab[] = {8, 16, 24, 32}; int i, count, column; - int xpos; - int v_line; + int xpos, width; int pixelmax = bitmap.viewport.w; int pixelcount = 0; int masked = 0; uint8 *src, *s, *lb; - uint32 size, width; + uint32 size, v_line; uint32 attr, attr_mask, name, palette, index; uint32 offs; @@ -1590,7 +1588,7 @@ static void render_obj_im2(int line, int odd, uint8 *buf, uint8 *table) pixelcount += width; /* draw visible sprites */ - if (((xpos + width) >= 0) && (xpos < pixelmax) && !masked) + if (((xpos + width) > 0) && (xpos < pixelmax) && !masked) { /* sprite attributes + pattern index */ attr = obj_info[count].attr; @@ -1599,7 +1597,7 @@ static void render_obj_im2(int line, int odd, uint8 *buf, uint8 *table) name = (attr & 0x03FF); /* sprite vertical offset */ - v_line = line - obj_info[count].ypos; + v_line = obj_info[count].ypos; s = &name_lut[((attr >> 3) & 0x300) | (size << 4) | ((v_line & 0x18) >> 1)]; v_line = (((v_line & 7) << 1) | odd) << 3; @@ -1758,13 +1756,13 @@ void render_line(int line) /* Shadow & Highlight */ merge(&nta_buf[0x20], &ntb_buf[0x20], &bg_buf[0x20], lut[2], width); memset(&obj_buf[0x20], 0, width); - render_obj_im2(line, odd, obj_buf, lut[3]); + render_obj_im2(odd, obj_buf, lut[3]); merge(&obj_buf[0x20], &bg_buf[0x20], &lb[0x20], lut[4], width); } else { merge(&nta_buf[0x20], &ntb_buf[0x20], &lb[0x20], lut[0], width); - render_obj_im2(line, odd, lb, lut[1]); + render_obj_im2(odd, lb, lut[1]); } } else @@ -1780,13 +1778,13 @@ void render_line(int line) /* Shadow & Highlight */ merge(&nta_buf[0x20], &ntb_buf[0x20], &bg_buf[0x20], lut[2], width); memset(&obj_buf[0x20], 0, width); - render_obj(line, obj_buf, lut[3]); + render_obj(obj_buf, lut[3]); merge(&obj_buf[0x20], &bg_buf[0x20], &lb[0x20], lut[4], width); } else { merge(&nta_buf[0x20], &ntb_buf[0x20], &lb[0x20], lut[0], width); - render_obj(line, lb, lut[1]); + render_obj(lb, lut[1]); } } @@ -1907,7 +1905,8 @@ void parse_satb(int line) { uint8 sizetab[] = {8, 16, 24, 32}; uint32 link = 0; - uint32 ypos, size, height; + uint32 size, height; + int ypos; uint32 limit = (reg[12] & 1) ? 20 : 16; uint32 total = limit << 2; @@ -1921,11 +1920,11 @@ void parse_satb(int line) do { /* Read ypos & size from internal SAT */ - ypos = (q[link] >> im2_flag) & 0x1FF; + ypos = line - ((q[link] >> im2_flag) & 0x1FF); size = q[link + 1] >> 8; height = sizetab[size & 3]; - if((line >= ypos) && (line < (ypos + height))) + if ((ypos >= 0) && (ypos < height)) { /* Sprite limit (max. 16 or 20 sprites displayed per line) */ if(count == limit) diff --git a/source/vdp.c b/source/vdp.c index 54ebb69..8543a92 100644 --- a/source/vdp.c +++ b/source/vdp.c @@ -681,7 +681,7 @@ static void data_w(unsigned int data) error("[%d(%d)][%d(%d)] CRAM 0x%x write -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, addr, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif uint16 *p = (uint16 *) &cram[(addr & 0x7E)]; - data = PACK_CRAM (data & 0x0EEE); + data = PACK_CRAM (data); if (data != *p) { int index = (addr >> 1) & 0x3F; @@ -690,11 +690,11 @@ static void data_w(unsigned int data) /* update color palette */ /* color entry 0 of each palette is never displayed (transparent pixel) */ if (index & 0x0F) - color_update(index, *p); + color_update(index, data); /* update background color */ if (border == index) - color_update (0x00, *p); + color_update (0x00, data); /* CRAM modified during HBLANK (Striker, Zero the Kamikaze, etc) */ if (!(status & 8) && (reg[1]& 0x40) && (mcycles_68k <= (mcycles_vdp + 860)))