# HG changeset patch # User Mike Pavone # Date 1355107245 28800 # Node ID 3fc57e1a2c56fd9cd457ac54f13ffcb18bdfb776 # Parent 6653e67a68118c9d6a3f6349f395264eaf3db8f2 Add debug render mode and fix vertical flip bit for bg tiles diff -r 6653e67a6811 -r 3fc57e1a2c56 render.h --- a/render.h Sun Dec 09 17:26:36 2012 -0800 +++ b/render.h Sun Dec 09 18:40:45 2012 -0800 @@ -4,7 +4,7 @@ #include "vdp.h" void render_init(int width, int height); void render_context(vdp_context * context); -void render_wait_quit(); +void render_wait_quit(vdp_context * context); #endif //RENDER_SDL_H_ diff -r 6653e67a6811 -r 3fc57e1a2c56 render_sdl.c --- a/render_sdl.c Sun Dec 09 17:26:36 2012 -0800 +++ b/render_sdl.c Sun Dec 09 18:40:45 2012 -0800 @@ -4,6 +4,7 @@ #include "render.h" SDL_Surface *screen; +uint8_t render_dbg = 0; void render_init(int width, int height) { @@ -88,9 +89,37 @@ uint32_t *line = buf_32; for (int x = 0; x < 320; x++) { uint16_t gen_color = context->framebuf[y * 320 + x]; - b = ((gen_color >> 8) & 0xE) * 18; - g = ((gen_color >> 4) & 0xE) * 18; - r = (gen_color& 0xE) * 18; + if (render_dbg) { + r = g = b = 0; + switch(gen_color & FBUF_SRC_MASK) + { + case FBUF_SRC_A: + g = 127; + break; + case FBUF_SRC_W: + g = 127; + b = 127; + break; + case FBUF_SRC_B: + b = 127; + break; + case FBUF_SRC_S: + r = 127; + break; + case FBUF_SRC_BG: + r = 127; + b = 127; + } + if (gen_color & FBUF_BIT_PRIORITY) { + b *= 2; + g *= 2; + r *= 2; + } + } else { + b = ((gen_color >> 8) & 0xE) * 18; + g = ((gen_color >> 4) & 0xE) * 18; + r = (gen_color& 0xE) * 18; + } for (int j = 0; j < repeat_x; j++) { *(line++) = SDL_MapRGB(screen->format, r, g, b); } @@ -105,11 +134,17 @@ SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h); } -void render_wait_quit() +void render_wait_quit(vdp_context * context) { SDL_Event event; while(SDL_WaitEvent(&event)) { switch (event.type) { + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_LEFTBRACKET) { + render_dbg = !render_dbg; + render_context(context); + } + break; case SDL_QUIT: return; } diff -r 6653e67a6811 -r 3fc57e1a2c56 stateview.c --- a/stateview.c Sun Dec 09 17:26:36 2012 -0800 +++ b/stateview.c Sun Dec 09 18:40:45 2012 -0800 @@ -30,6 +30,6 @@ vdp_run_to_vblank(&context); render_init(width, height); render_context(&context); - render_wait_quit(); + render_wait_quit(&context); return 0; } diff -r 6653e67a6811 -r 3fc57e1a2c56 vdp.c --- a/vdp.c Sun Dec 09 17:26:36 2012 -0800 +++ b/vdp.c Sun Dec 09 18:40:45 2012 -0800 @@ -293,7 +293,7 @@ { uint16_t address = ((col & 0x7FF) << 5); if (col & MAP_BIT_V_FLIP) { - address += 24 - 4 * context->v_offset; + address += 28 - 4 * context->v_offset; } else { address += 4 * context->v_offset; } @@ -342,32 +342,43 @@ col-=2; dst = context->framebuf + line * 320 + col * 8; sprite_buf = context->linebuf + col * 8; + uint16_t a_src; if (context->flags & FLAG_WINDOW) { plane_a = context->tmp_buf_a + SCROLL_BUFFER_DRAW; + a_src = FBUF_SRC_W; } else { plane_a = context->tmp_buf_a + SCROLL_BUFFER_DRAW - (context->hscroll_a & 0xF); + a_src = FBUF_SRC_A; } plane_b = context->tmp_buf_b + SCROLL_BUFFER_DRAW - (context->hscroll_b & 0xF); 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; } - *dst = context->cram[pixel & 0x3F] | ((pixel & BUF_BIT_PRIORITY) ? 0x1000 : 0); + *dst = context->cram[pixel & 0x3F] | ((pixel & BUF_BIT_PRIORITY) ? FBUF_BIT_PRIORITY : 0) | src; } } else { //dst = context->framebuf + line * 320; diff -r 6653e67a6811 -r 3fc57e1a2c56 vdp.h --- a/vdp.h Sun Dec 09 17:26:36 2012 -0800 +++ b/vdp.h Sun Dec 09 18:40:45 2012 -0800 @@ -18,6 +18,14 @@ #define MAX_SPRITES_FRAME 80 #define MAX_SPRITES_FRAME_H32 64 +#define FBUF_BIT_PRIORITY 0x1000 +#define FBUF_SRC_MASK 0xE000 +#define FBUF_SRC_A 0x0000 +#define FBUF_SRC_W 0x2000 +#define FBUF_SRC_B 0x4000 +#define FBUF_SRC_S 0x6000 +#define FBUF_SRC_BG 0x8000 + enum { REG_MODE_1=0, REG_MODE_2,