changeset 26:a7c2b92d8056

Fix management of context->sprite_draws so the sprite layer only draws when it should
author Mike Pavone <pavone@retrodev.com>
date Sat, 08 Dec 2012 16:46:47 -0800
parents 4d0c20ad815a
children aa1c47fab3f1
files vdp.c
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/vdp.c	Sat Dec 08 16:16:18 2012 -0800
+++ b/vdp.c	Sat Dec 08 16:46:47 2012 -0800
@@ -21,13 +21,14 @@
 	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 @@
 			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 @@
 		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 @@
 			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 @@
 		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 @@
 	}
 	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 @@
 	}
 	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 @@
 	{
 	//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 @@
 	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;