comparison render_sdl.c @ 413:36fbbced25c2

Initial work on interlace
author Mike Pavone <pavone@retrodev.com>
date Sat, 22 Jun 2013 21:19:43 -0700
parents c1bddeadc566
children 8c60c8c09a0f
comparison
equal deleted inserted replaced
412:00d5a2b532f4 413:36fbbced25c2
145 sample_rate = actual.freq; 145 sample_rate = actual.freq;
146 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples); 146 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples);
147 SDL_PauseAudio(0); 147 SDL_PauseAudio(0);
148 } 148 }
149 149
150 uint16_t blankbuf[320*240];
151
150 void render_context(vdp_context * context) 152 void render_context(vdp_context * context)
151 { 153 {
152 uint8_t *buf_8; 154 uint8_t *buf_8;
153 uint16_t *buf_16; 155 uint16_t *buf_16;
154 uint32_t *buf_32; 156 uint32_t *buf_32;
164 if (repeat_x > repeat_y) { 166 if (repeat_x > repeat_y) {
165 repeat_x = repeat_y; 167 repeat_x = repeat_y;
166 } else { 168 } else {
167 repeat_y = repeat_x; 169 repeat_y = repeat_x;
168 } 170 }
171 int othermask = repeat_y >> 1;
172 uint16_t *otherbuf = (context->regs[REG_MODE_4] & BIT_INTERLACE) ? context->evenbuf : blankbuf;
169 switch (screen->format->BytesPerPixel) { 173 switch (screen->format->BytesPerPixel) {
170 case 2: 174 case 2:
171 buf_16 = (uint16_t *)screen->pixels; 175 buf_16 = (uint16_t *)screen->pixels;
172 for (int y = 0; y < 240; y++) { 176 for (int y = 0; y < 240; y++) {
173 for (int i = 0; i < repeat_y; i++,buf_16 += screen->pitch/2) { 177 for (int i = 0; i < repeat_y; i++,buf_16 += screen->pitch/2) {
174 uint16_t *line = buf_16; 178 uint16_t *line = buf_16;
175 uint16_t *src_line = context->framebuf + y * 320; 179 uint16_t *src_line = (i & othermask ? otherbuf : context->oddbuf) + y * 320;
176 for (int x = 0; x < 320; x++) { 180 for (int x = 0; x < 320; x++) {
177 uint16_t color = color_map[*(src_line++) & 0xFFF]; 181 uint16_t color = color_map[*(src_line++) & 0xFFF];
178 for (int j = 0; j < repeat_x; j++) { 182 for (int j = 0; j < repeat_x; j++) {
179 *(line++) = color; 183 *(line++) = color;
180 } 184 }
186 buf_8 = (uint8_t *)screen->pixels; 190 buf_8 = (uint8_t *)screen->pixels;
187 for (int y = 0; y < 240; y++) { 191 for (int y = 0; y < 240; y++) {
188 for (int i = 0; i < repeat_y; i++,buf_8 += screen->pitch) { 192 for (int i = 0; i < repeat_y; i++,buf_8 += screen->pitch) {
189 uint8_t *line = buf_8; 193 uint8_t *line = buf_8;
190 for (int x = 0; x < 320; x++) { 194 for (int x = 0; x < 320; x++) {
191 uint16_t gen_color = context->framebuf[y * 320 + x]; 195 uint16_t gen_color = context->oddbuf[y * 320 + x];
192 b = ((gen_color >> 8) & 0xE) * 18; 196 b = ((gen_color >> 8) & 0xE) * 18;
193 g = ((gen_color >> 4) & 0xE) * 18; 197 g = ((gen_color >> 4) & 0xE) * 18;
194 r = (gen_color& 0xE) * 18; 198 r = (gen_color& 0xE) * 18;
195 for (int j = 0; j < repeat_x; j++) { 199 for (int j = 0; j < repeat_x; j++) {
196 *(buf_8+screen->format->Rshift/8) = r; 200 *(buf_8+screen->format->Rshift/8) = r;
206 buf_32 = (uint32_t *)screen->pixels; 210 buf_32 = (uint32_t *)screen->pixels;
207 211
208 for (int y = 0; y < 240; y++) { 212 for (int y = 0; y < 240; y++) {
209 for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) { 213 for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) {
210 uint32_t *line = buf_32; 214 uint32_t *line = buf_32;
211 uint16_t *src_line = context->framebuf + y * 320; 215 uint16_t *src_line = (i & othermask ? otherbuf : context->oddbuf) + y * 320;
212 for (int x = 0; x < 320; x++) { 216 for (int x = 0; x < 320; x++) {
213 uint32_t color; 217 uint32_t color;
214 if (!render_dbg) { 218 if (!render_dbg) {
215 color = color_map[*(src_line++) & 0xFFF]; 219 color = color_map[*(src_line++) & 0xFFF];
216 } else if(render_dbg == 2) { 220 } else if(render_dbg == 2) {
220 color = color_map[context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] & 0xF) ]]; 224 color = color_map[context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] & 0xF) ]];
221 } else { 225 } else {
222 color = color_map[context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] >> 4) ]]; 226 color = color_map[context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] >> 4) ]];
223 } 227 }
224 }else { 228 }else {
225 uint16_t gen_color = context->framebuf[y * 320 + x]; 229 uint16_t gen_color = context->oddbuf[y * 320 + x];
226 r = g = b = 0; 230 r = g = b = 0;
227 switch(gen_color & FBUF_SRC_MASK) 231 switch(gen_color & FBUF_SRC_MASK)
228 { 232 {
229 case FBUF_SRC_A: 233 case FBUF_SRC_A:
230 g = 127; 234 g = 127;
269 } 273 }
270 if ( SDL_MUSTLOCK(screen) ) { 274 if ( SDL_MUSTLOCK(screen) ) {
271 SDL_UnlockSurface(screen); 275 SDL_UnlockSurface(screen);
272 } 276 }
273 SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h); 277 SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h);
278 if (context->regs[REG_MODE_4] & BIT_INTERLACE)
279 {
280 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf;
281 }
274 } 282 }
275 283
276 void render_wait_quit(vdp_context * context) 284 void render_wait_quit(vdp_context * context)
277 { 285 {
278 SDL_Event event; 286 SDL_Event event;