summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2012-12-09 18:40:45 -0800
committerMike Pavone <pavone@retrodev.com>2012-12-09 18:40:45 -0800
commitaa00a0b53cd984d37d454fd74360216dea966d2a (patch)
treeb210c5c153a6607917c958b0bce2818b4a03d572
parent49f7af811449e4843b2dbef8d66a6963582fb566 (diff)
Add debug render mode and fix vertical flip bit for bg tiles
-rw-r--r--render.h2
-rw-r--r--render_sdl.c43
-rw-r--r--stateview.c2
-rw-r--r--vdp.c15
-rw-r--r--vdp.h8
5 files changed, 62 insertions, 8 deletions
diff --git a/render.h b/render.h
index 73b706d..eab718c 100644
--- a/render.h
+++ b/render.h
@@ -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 --git a/render_sdl.c b/render_sdl.c
index 5d08008..d3e7ef9 100644
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -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 @@ void render_context(vdp_context * context)
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 @@ void render_context(vdp_context * context)
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 --git a/stateview.c b/stateview.c
index d806171..c7b00a8 100644
--- a/stateview.c
+++ b/stateview.c
@@ -30,6 +30,6 @@ int main(int argc, char ** argv)
vdp_run_to_vblank(&context);
render_init(width, height);
render_context(&context);
- render_wait_quit();
+ render_wait_quit(&context);
return 0;
}
diff --git a/vdp.c b/vdp.c
index 7600075..5453f7d 100644
--- a/vdp.c
+++ b/vdp.c
@@ -293,7 +293,7 @@ void render_map(uint16_t col, uint8_t * tmp_buf, vdp_context * context)
{
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 @@ void render_map_output(uint32_t line, int32_t col, vdp_context * context)
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 --git a/vdp.h b/vdp.h
index d4b7f49..6c9bbf1 100644
--- a/vdp.h
+++ b/vdp.h
@@ -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,