diff vdp.c @ 41:e591004487bc

More correct window support, maybe
author Mike Pavone <pavone@retrodev.com>
date Sun, 09 Dec 2012 17:10:08 -0800
parents 7368a7071908
children 6653e67a6811
line wrap: on
line diff
--- a/vdp.c	Sun Dec 09 17:05:13 2012 -0800
+++ b/vdp.c	Sun Dec 09 17:10:08 2012 -0800
@@ -187,48 +187,46 @@
 			top_line = 0; bottom_line = 241;
 		#else
 		if (context->regs[REG_WINDOW_H] & WINDOW_RIGHT) {
+			left_col = (context->regs[REG_WINDOW_H] & 0x1F) * 2;
+			right_col = 42;
+		} else {
 			left_col = 0;
 			right_col = (context->regs[REG_WINDOW_H] & 0x1F) * 2;
 			if (right_col) {
 				right_col += 2;
 			}
-		} else {
-			left_col = (context->regs[REG_WINDOW_H] & 0x1F) * 2;
-			right_col = 42;
 		}
-		if (column >= left_col && column < right_col) {
-			uint16_t top_line, bottom_line;
-			if (context->regs[REG_WINDOW_V] & WINDOW_DOWN) {
-				top_line = (context->regs[REG_WINDOW_V] & 0x1F) * 8;
-				bottom_line = 241;
-			} else {
-				top_line = 0;
-				bottom_line = (context->regs[REG_WINDOW_V] & 0x1F) * 8;
-			}
-			if (line >= top_line && line < bottom_line) {
+		uint16_t top_line, bottom_line;
+		if (context->regs[REG_WINDOW_V] & WINDOW_DOWN) {
+			top_line = (context->regs[REG_WINDOW_V] & 0x1F) * 8;
+			bottom_line = 241;
+		} else {
+			top_line = 0;
+			bottom_line = (context->regs[REG_WINDOW_V] & 0x1F) * 8;
+		}
+		if ((column >= left_col && column < right_col) || (line >= top_line && line < bottom_line)) {
 		#endif
-				uint16_t address = context->regs[REG_WINDOW] << 10;
-				uint16_t line_offset, offset, mask;
-				if (context->latched_mode & BIT_H40) {
-					address &= 0xF000;
-					line_offset = (((line/* - top_line */) / 8) * 64 * 2) & 0xFFF;
-					mask = 0x7F;
-					
-				} else {
-					address &= 0xF800;
-					line_offset = (((line/* - top_line*/) / 8) * 32 * 2) & 0xFFF;
-					mask = 0x3F;
-				}
-				offset = address + line_offset + (((column - 2/* - left_col*/) * 2) & mask);
-				context->col_1 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
-				printf("Window | top: %d, bot: %d, left: %d, right: %d, base: %X, line: %X offset: %X, tile: %X, reg: %X\n", top_line, bottom_line, left_col, right_col, address, line_offset, offset, ((context->col_1 & 0x3FF) << 5), context->regs[REG_WINDOW]);
-				offset = address + line_offset + (((column - 1/* - left_col*/) * 2) & mask);
-				context->col_2 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
-				context->v_offset = (line/* - top_line*/) & 0x7;
-				context->flags |= FLAG_WINDOW;
-				return;
+			uint16_t address = context->regs[REG_WINDOW] << 10;
+			uint16_t line_offset, offset, mask;
+			if (context->latched_mode & BIT_H40) {
+				address &= 0xF000;
+				line_offset = (((line/* - top_line */) / 8) * 64 * 2) & 0xFFF;
+				mask = 0x7F;
+				
+			} else {
+				address &= 0xF800;
+				line_offset = (((line/* - top_line*/) / 8) * 32 * 2) & 0xFFF;
+				mask = 0x3F;
+			}
+			offset = address + line_offset + (((column - 2/* - left_col*/) * 2) & mask);
+			context->col_1 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
+			printf("Window | top: %d, bot: %d, left: %d, right: %d, base: %X, line: %X offset: %X, tile: %X, reg: %X\n", top_line, bottom_line, left_col, right_col, address, line_offset, offset, ((context->col_1 & 0x3FF) << 5), context->regs[REG_WINDOW]);
+			offset = address + line_offset + (((column - 1/* - left_col*/) * 2) & mask);
+			context->col_2 = (context->vdpmem[offset] << 8) | context->vdpmem[offset+1];
+			context->v_offset = (line/* - top_line*/) & 0x7;
+			context->flags |= FLAG_WINDOW;
+			return;
 	#if !ALWAYS_WINDOW
-			}
 		}
 		context->flags &= ~FLAG_WINDOW;
 	#endif