changeset 230:d3266cee02c9

Implemented shadow hilight mode.
author Mike Pavone <pavone@retrodev.com>
date Mon, 22 Apr 2013 19:39:38 -0700
parents d60837a7d18a
children d9b14fb7e00c
files render_sdl.c vdp.c vdp.h
diffstat 3 files changed, 101 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/render_sdl.c	Sun Apr 21 19:12:48 2013 -0700
+++ b/render_sdl.c	Mon Apr 22 19:39:38 2013 -0700
@@ -34,9 +34,19 @@
     }
     uint8_t b,g,r;
     for (uint16_t color = 0; color < (1 << 12); color++) {
-    	b = levels[(color >> 8) & 0xE];
-		g = levels[(color >> 4) & 0xE];
-		r = levels[color & 0xE];
+    	if (color & FBUF_SHADOW) {
+    		b = levels[(color >> 9) & 0x7];
+			g = levels[(color >> 5) & 0x7];
+			r = levels[(color >> 1) & 0x7];
+    	} else if(color & FBUF_HILIGHT) {
+    		b = levels[((color >> 9) & 0x7) + 7];
+			g = levels[((color >> 5) & 0x7) + 7];
+			r = levels[((color >> 1) & 0x7) + 7];
+    	} else {
+			b = levels[(color >> 8) & 0xE];
+			g = levels[(color >> 4) & 0xE];
+			r = levels[color & 0xE];
+		}
 		color_map[color] = SDL_MapRGB(screen->format, r, g, b);
     }
     min_delay = 0;
--- a/vdp.c	Sun Apr 21 19:12:48 2013 -0700
+++ b/vdp.c	Mon Apr 22 19:39:38 2013 -0700
@@ -14,6 +14,8 @@
 #define BIT_DMA_ENABLE 0x4
 #define BIT_H40        0x1
 
+#define BIT_HILIGHT    0x8
+
 #define SCROLL_BUFFER_SIZE 32
 #define SCROLL_BUFFER_DRAW 16
 
@@ -516,31 +518,91 @@
 		end = dst + 16;
 		uint16_t src;
 		//printf("A | tmp_buf offset: %d\n", 8 - (context->hscroll_a & 0x7));
-		for (; dst < end; ++plane_a, ++plane_b, ++sprite_buf, ++dst) {
-			uint8_t pixel;
-			if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) {
-				pixel = *sprite_buf;
-				src = FBUF_SRC_S;
-			} else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
-				pixel = *plane_a;
-				src = a_src;
-			} else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
-				pixel = *plane_b;
-				src = FBUF_SRC_B;
-			} else if (*sprite_buf & 0xF) {
-				pixel = *sprite_buf;
-				src = FBUF_SRC_S;
-			} else if (*plane_a & 0xF) {
-				pixel = *plane_a;
-				src = a_src;
-			} else if (*plane_b & 0xF){
-				pixel = *plane_b;
-				src = FBUF_SRC_B;
-			} else {
-				pixel = context->regs[REG_BG_COLOR] & 0x3F;
-				src = FBUF_SRC_BG;
+		
+		if (context->regs[REG_MODE_4] & BIT_HILIGHT) {
+			for (; dst < end; ++plane_a, ++plane_b, ++sprite_buf, ++dst) {
+				uint8_t pixel;
+				
+				src = 0;
+				uint8_t sprite_color = *sprite_buf & 0x3F;
+				if (sprite_color == 0x3E || sprite_color == 0x3F) {
+					if (sprite_color == 0x3E) {
+						src |= FBUF_SHADOW;
+					} else {
+						src |= FBUF_HILIGHT;
+					}
+					if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
+						pixel = *plane_a;
+						src |= a_src;
+					} else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
+						pixel = *plane_b;
+						src |= FBUF_SRC_B;
+					} else if (*plane_a & 0xF) {
+						pixel = *plane_a;
+						src |= a_src;
+					} else if (*plane_b & 0xF){
+						pixel = *plane_b;
+						src |= FBUF_SRC_B;
+					} else {
+						pixel = context->regs[REG_BG_COLOR] & 0x3F;
+						src |= FBUF_SRC_BG;
+					}
+				} else {
+					if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) {
+						pixel = *sprite_buf;
+						src = FBUF_SRC_S;
+					} else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
+						pixel = *plane_a;
+						src = a_src;
+					} else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
+						pixel = *plane_b;
+						src = FBUF_SRC_B;
+					} else if (*sprite_buf & 0xF) {
+						pixel = *sprite_buf;
+						src = FBUF_SRC_S;
+						if (*sprite_buf & 0xF != 0xE) {
+							src |= FBUF_SHADOW;
+						}
+					} else if (*plane_a & 0xF) {
+						pixel = *plane_a;
+						src = a_src | FBUF_SHADOW;
+					} else if (*plane_b & 0xF){
+						pixel = *plane_b;
+						src = FBUF_SRC_B | FBUF_SHADOW;
+					} else {
+						pixel = context->regs[REG_BG_COLOR] & 0x3F;
+						src = FBUF_SRC_BG | FBUF_SHADOW;
+					}
+				}
+				*dst = (context->cram[pixel & 0x3F] & 0xEEE) | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src;
 			}
-			*dst = context->cram[pixel & 0x3F] | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src;
+		} else {
+			for (; dst < end; ++plane_a, ++plane_b, ++sprite_buf, ++dst) {
+				uint8_t pixel;
+				if (*sprite_buf & BUF_BIT_PRIORITY && *sprite_buf & 0xF) {
+					pixel = *sprite_buf;
+					src = FBUF_SRC_S;
+				} else if (*plane_a & BUF_BIT_PRIORITY && *plane_a & 0xF) {
+					pixel = *plane_a;
+					src = a_src;
+				} else if (*plane_b & BUF_BIT_PRIORITY && *plane_b & 0xF) {
+					pixel = *plane_b;
+					src = FBUF_SRC_B;
+				} else if (*sprite_buf & 0xF) {
+					pixel = *sprite_buf;
+					src = FBUF_SRC_S;
+				} else if (*plane_a & 0xF) {
+					pixel = *plane_a;
+					src = a_src;
+				} else if (*plane_b & 0xF){
+					pixel = *plane_b;
+					src = FBUF_SRC_B;
+				} else {
+					pixel = context->regs[REG_BG_COLOR] & 0x3F;
+					src = FBUF_SRC_BG;
+				}
+				*dst = context->cram[pixel & 0x3F] | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src;
+			}
 		}
 	} else {
 		//dst = context->framebuf + line * 320;
--- a/vdp.h	Sun Apr 21 19:12:48 2013 -0700
+++ b/vdp.h	Mon Apr 22 19:39:38 2013 -0700
@@ -18,6 +18,8 @@
 #define MAX_SPRITES_FRAME 80
 #define MAX_SPRITES_FRAME_H32 64
 
+#define FBUF_SHADOW 0x0001
+#define FBUF_HILIGHT 0x0010
 #define FBUF_BIT_PRIORITY 0x1000
 #define FBUF_SRC_MASK 0xE000
 #define FBUF_SRC_A 0x0000