summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2012-12-08 16:46:47 -0800
committerMike Pavone <pavone@retrodev.com>2012-12-08 16:46:47 -0800
commit8208d35c070505eef0d518fea9ff489b2f06202a (patch)
treea5e49377d58bb53c991718cfb4de8b2209b282c5
parent1cd0d0e3873b24dcd8c1347364d9604aab89ddf2 (diff)
Fix management of context->sprite_draws so the sprite layer only draws when it should
-rw-r--r--vdp.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/vdp.c b/vdp.c
index d1e40e5..4d476e8 100644
--- a/vdp.c
+++ b/vdp.c
@@ -21,13 +21,14 @@ void init_vdp_context(vdp_context * context)
context->linebuf = malloc(LINEBUF_SIZE + 48);
context->tmp_buf_a = context->linebuf + LINEBUF_SIZE;
context->tmp_buf_b = context->tmp_buf_a + 24;
+ context->sprite_draws = MAX_DRAWS;
}
void render_sprite_cells(vdp_context * context)
{
if (context->cur_slot >= context->sprite_draws) {
sprite_draw * d = context->sprite_draw_list + context->cur_slot;
- context->cur_slot--;
+
uint16_t dir;
int16_t x;
if (d->h_flip) {
@@ -37,6 +38,8 @@ void render_sprite_cells(vdp_context * context)
x = d->x_pos;
dir = 1;
}
+ printf("Draw Slot %d of %d, Rendering sprite cell from %X to x: %d\n", context->cur_slot, context->sprite_draws, d->address, x);
+ context->cur_slot--;
for (uint16_t address = d->address; address < d->address+4; address++) {
if (x >= 0 && x < 320) {
context->linebuf[x] = (context->vdpmem[address] >> 4) | d->pal_priority;
@@ -63,7 +66,7 @@ void scan_sprite_table(uint32_t line, vdp_context * context)
uint8_t height = ((context->vdpmem[address+2] & 0x3) + 1) * 8;
//printf("Sprite %d | y: %d, height: %d\n", context->sprite_index, y, height);
if (y <= line && line < (y + height)) {
- //printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line);
+ printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line);
context->sprite_info_list[--(context->slot_counter)].size = context->vdpmem[address+2];
context->sprite_info_list[context->slot_counter].index = context->sprite_index;
context->sprite_info_list[context->slot_counter].y = y;
@@ -75,7 +78,7 @@ void scan_sprite_table(uint32_t line, vdp_context * context)
y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]) - 128;
height = ((context->vdpmem[address+2] & 0x3) + 1) * 8;
if (y <= line && line < (y + height)) {
- //printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line);
+ printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line);
context->sprite_info_list[--(context->slot_counter)].size = context->vdpmem[address+2];
context->sprite_info_list[context->slot_counter].index = context->sprite_index;
context->sprite_info_list[context->slot_counter].y = y;
@@ -109,8 +112,9 @@ void read_sprite_x(uint32_t line, vdp_context * context)
if (x) {
x -= 128;
int16_t base_x = x;
- //printf("Sprite %d | x: %d, y: %d, width: %d, height: %d, pal_priority: %X, row: %d, tile addr: %X\n", context->sprite_info_list[context->cur_slot].index, x, context->sprite_info_list[context->cur_slot].y, width, height, pal_priority, row, address);
- for (;width && context->sprite_draws; --width, --context->sprite_draws, x += 8) {
+ printf("Sprite %d | x: %d, y: %d, width: %d, height: %d, pal_priority: %X, row: %d, tile addr: %X\n", context->sprite_info_list[context->cur_slot].index, x, context->sprite_info_list[context->cur_slot].y, width, height, pal_priority, row, address);
+ for (;width && context->sprite_draws; --width, x += 8) {
+ --context->sprite_draws;
context->sprite_draw_list[context->sprite_draws].address = address + ((x-base_x) / 8) * height * 4;
context->sprite_draw_list[context->sprite_draws].x_pos = x;
context->sprite_draw_list[context->sprite_draws].pal_priority = pal_priority;
@@ -150,7 +154,7 @@ void read_map_scroll(uint16_t column, uint16_t vsram_off, uint32_t line, uint16_
}
vscroll &= (context->vsram[(context->regs[REG_MODE_3] & 0x4 ? column : 0) + vsram_off] + line);
context->v_offset = vscroll & 0x7;
- printf("BG | line %d, vsram: %d, vscroll: %d, v_offset: %d\n", line, context->vsram[context->regs[REG_MODE_3] & 0x4 ? column : 0], vscroll, context->v_offset);
+ //printf("%s | line %d, vsram: %d, vscroll: %d, v_offset: %d\n",(vsram_off ? "B" : "A"), line, context->vsram[context->regs[REG_MODE_3] & 0x4 ? column : 0], vscroll, context->v_offset);
vscroll /= 8;
uint16_t hscroll_mask;
uint16_t v_mul;
@@ -176,7 +180,7 @@ void read_map_scroll(uint16_t column, uint16_t vsram_off, uint32_t line, uint16_
}
uint16_t hscroll = (hscroll_val + (column-2) * 8) & hscroll_mask;
uint16_t offset = address + ((vscroll * v_mul + hscroll/4) & 0x1FFF);
- printf("BG | line: %d, col: %d, x: %d, hs_mask %X, v_mul: %d, scr reg: %X, tbl addr: %X\n", line, column, hscroll, hscroll_mask, v_mul, context->regs[REG_SCROLL], offset);
+ //printf("%s | line: %d, col: %d, x: %d, hs_mask %X, v_mul: %d, scr reg: %X, tbl addr: %X\n", (vsram_off ? "B" : "A"), line, column, hscroll, hscroll_mask, v_mul, context->regs[REG_SCROLL], offset);
context->col_1 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
hscroll = (hscroll_val + (column-1) * 8) & hscroll_mask;
offset = address + ((vscroll * v_mul + hscroll/4) & 0x1FFF);
@@ -346,7 +350,7 @@ void vdp_h40(uint32_t line, uint32_t linecyc, vdp_context * context)
{
//sprite render to line buffer starts
case 0:
- context->cur_slot = MAX_DRAWS;
+ context->cur_slot = MAX_DRAWS-1;
memset(context->linebuf, 0, LINEBUF_SIZE);
render_sprite_cells(context);
break;
@@ -480,7 +484,6 @@ void vdp_h40(uint32_t line, uint32_t linecyc, vdp_context * context)
COLUMN_RENDER_BLOCK(38, 192)
COLUMN_RENDER_BLOCK_REFRESH(40, 200)
case 208:
- context->sprite_draws = MAX_DRAWS - context->sprite_draws;
case 209:
external_slot(context);
break;