comparison render_sdl.c @ 43:3fc57e1a2c56

Add debug render mode and fix vertical flip bit for bg tiles
author Mike Pavone <pavone@retrodev.com>
date Sun, 09 Dec 2012 18:40:45 -0800
parents 2e15fa26fe58
children 3b79cbcf6846
comparison
equal deleted inserted replaced
42:6653e67a6811 43:3fc57e1a2c56
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <stdio.h> 3 #include <stdio.h>
4 #include "render.h" 4 #include "render.h"
5 5
6 SDL_Surface *screen; 6 SDL_Surface *screen;
7 uint8_t render_dbg = 0;
7 8
8 void render_init(int width, int height) 9 void render_init(int width, int height)
9 { 10 {
10 if (SDL_Init(SDL_INIT_VIDEO) < 0) { 11 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
11 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); 12 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
86 for (int y = 0; y < 240; y++) { 87 for (int y = 0; y < 240; y++) {
87 for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) { 88 for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) {
88 uint32_t *line = buf_32; 89 uint32_t *line = buf_32;
89 for (int x = 0; x < 320; x++) { 90 for (int x = 0; x < 320; x++) {
90 uint16_t gen_color = context->framebuf[y * 320 + x]; 91 uint16_t gen_color = context->framebuf[y * 320 + x];
91 b = ((gen_color >> 8) & 0xE) * 18; 92 if (render_dbg) {
92 g = ((gen_color >> 4) & 0xE) * 18; 93 r = g = b = 0;
93 r = (gen_color& 0xE) * 18; 94 switch(gen_color & FBUF_SRC_MASK)
95 {
96 case FBUF_SRC_A:
97 g = 127;
98 break;
99 case FBUF_SRC_W:
100 g = 127;
101 b = 127;
102 break;
103 case FBUF_SRC_B:
104 b = 127;
105 break;
106 case FBUF_SRC_S:
107 r = 127;
108 break;
109 case FBUF_SRC_BG:
110 r = 127;
111 b = 127;
112 }
113 if (gen_color & FBUF_BIT_PRIORITY) {
114 b *= 2;
115 g *= 2;
116 r *= 2;
117 }
118 } else {
119 b = ((gen_color >> 8) & 0xE) * 18;
120 g = ((gen_color >> 4) & 0xE) * 18;
121 r = (gen_color& 0xE) * 18;
122 }
94 for (int j = 0; j < repeat_x; j++) { 123 for (int j = 0; j < repeat_x; j++) {
95 *(line++) = SDL_MapRGB(screen->format, r, g, b); 124 *(line++) = SDL_MapRGB(screen->format, r, g, b);
96 } 125 }
97 } 126 }
98 } 127 }
103 SDL_UnlockSurface(screen); 132 SDL_UnlockSurface(screen);
104 } 133 }
105 SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h); 134 SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h);
106 } 135 }
107 136
108 void render_wait_quit() 137 void render_wait_quit(vdp_context * context)
109 { 138 {
110 SDL_Event event; 139 SDL_Event event;
111 while(SDL_WaitEvent(&event)) { 140 while(SDL_WaitEvent(&event)) {
112 switch (event.type) { 141 switch (event.type) {
142 case SDL_KEYDOWN:
143 if (event.key.keysym.sym == SDLK_LEFTBRACKET) {
144 render_dbg = !render_dbg;
145 render_context(context);
146 }
147 break;
113 case SDL_QUIT: 148 case SDL_QUIT:
114 return; 149 return;
115 } 150 }
116 } 151 }
117 } 152 }