diff vdp.c @ 22:f090a98ccb7e

Sprites fixed, working on bg planes
author Mike Pavone <pavone@retrodev.com>
date Sat, 08 Dec 2012 11:59:50 -0800
parents 72ce60cb1711
children 3e924bb56560
line wrap: on
line diff
--- a/vdp.c	Sat Dec 08 11:12:17 2012 -0800
+++ b/vdp.c	Sat Dec 08 11:59:50 2012 -0800
@@ -63,7 +63,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 +75,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;
@@ -103,13 +103,15 @@
 		} else {
 			row = line-context->sprite_info_list[context->cur_slot].y;
 		}
-		uint16_t address = ((tileinfo & 0x7FF) << 5) + (row & 0x7) * 4 + (row & 0x18) * width * 4;
+		//uint16_t address = ((tileinfo & 0x7FF) << 5) + (row & 0x7) * 4 + (row & 0x18) * width * 4;
+		uint16_t address = ((tileinfo & 0x7FF) << 5) + row * 4;
 		int16_t x = ((context->vdpmem[att_addr+ 2] & 0x3) << 8) | context->vdpmem[att_addr + 3];
 		if (x) {
 			x -= 128;
-			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, address += 32, x += 8) {
-				context->sprite_draw_list[context->sprite_draws].address = address;
+			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) {
+				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;
 				context->sprite_draw_list[context->sprite_draws].h_flip = (tileinfo & MAP_BIT_H_FLIP) ? 1 : 0;
@@ -172,11 +174,11 @@
 		v_mul = 256;
 		break;
 	}
-	uint16_t hscroll = (hscroll_val + (column-1) * 8) & hscroll_mask;
+	uint16_t hscroll = (hscroll_val + (column-2) * 8) & hscroll_mask;
 	uint16_t offset = address + ((vscroll * v_mul + hscroll/4) & 0x1FFF);
 	//printf("A | 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);
 	context->col_1 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
-	hscroll = (hscroll_val + column * 8) & hscroll_mask;
+	hscroll = (hscroll_val + (column-1) * 8) & hscroll_mask;
 	offset = address + ((vscroll * v_mul + hscroll/4) & 0x1FFF);
 	context->col_2 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
 }