# HG changeset patch # User Mike Pavone # Date 1355033245 28800 # Node ID 2e15fa26fe587d412bd7dbd5828253befb76519f # Parent 8602ad493794bbbe19e4bdb92a6eed859ca7b299 Add support for simple resolution scaling diff -r 8602ad493794 -r 2e15fa26fe58 render.h --- a/render.h Sat Dec 08 21:39:01 2012 -0800 +++ b/render.h Sat Dec 08 22:07:25 2012 -0800 @@ -2,7 +2,7 @@ #define RENDER_SDL_H_ #include "vdp.h" -void render_init(); +void render_init(int width, int height); void render_context(vdp_context * context); void render_wait_quit(); diff -r 8602ad493794 -r 2e15fa26fe58 render_sdl.c --- a/render_sdl.c Sat Dec 08 21:39:01 2012 -0800 +++ b/render_sdl.c Sat Dec 08 22:07:25 2012 -0800 @@ -5,14 +5,15 @@ SDL_Surface *screen; -void render_init() +void render_init(int width, int height) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); - screen = SDL_SetVideoMode(320, 240, 32, SDL_SWSURFACE | SDL_ANYFORMAT); + printf("width: %d, height: %d\n", width, height); + screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_ANYFORMAT); if (!screen) { fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError()); exit(1); @@ -34,59 +35,66 @@ return; } } + uint16_t repeat_x = screen->clip_rect.w / 320; + uint16_t repeat_y = screen->clip_rect.h / 240; + if (repeat_x > repeat_y) { + repeat_x = repeat_y; + } else { + repeat_y = repeat_x; + } + printf("w: %d, h: %d, repeat_x: %d, repeat_y: %d\n", screen->clip_rect.w, screen->clip_rect.h, repeat_x, repeat_y); switch (screen->format->BytesPerPixel) { case 2: buf_16 = (uint16_t *)screen->pixels; - for (int y = 0; y < 240; y++, buf_16 += (screen->pitch/2 - 320)) { - for (int x = 0; x < 320; x++, buf_16++) { - 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; - *buf_16 = SDL_MapRGB(screen->format, r, g, b); - } + for (int y = 0; y < 240; y++) { + for (int i = 0; i < repeat_y; i++,buf_16 += screen->pitch/2) { + uint16_t *line = buf_16; + 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; + for (int j = 0; j < repeat_x; j++) { + *(line++) = SDL_MapRGB(screen->format, r, g, b); + } + } + } } break; case 3: buf_8 = (uint8_t *)screen->pixels; - for (int y = 0; y < 240; y++, buf_8 += (screen->pitch - 320)) { - for (int x = 0; x < 320; x++, buf_8 += 3) { - 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; - *(buf_8+screen->format->Rshift/8) = r; - *(buf_8+screen->format->Gshift/8) = g; - *(buf_8+screen->format->Bshift/8) = b; - } + for (int y = 0; y < 240; y++) { + for (int i = 0; i < repeat_y; i++,buf_8 += screen->pitch) { + uint8_t *line = buf_8; + 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; + for (int j = 0; j < repeat_x; j++) { + *(buf_8+screen->format->Rshift/8) = r; + *(buf_8+screen->format->Gshift/8) = g; + *(buf_8+screen->format->Bshift/8) = b; + buf_8 += 3; + } + } + } } break; case 4: buf_32 = (uint32_t *)screen->pixels; - for (int y = 0; y < 224; y++, buf_32 += (screen->pitch/4 - 320)) { - for (int x = 0; x < 320; x++, buf_32++) { - 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; - *buf_32 = SDL_MapRGB(screen->format, r, g, b); - } - } - for (int y = 224; y < 240; y++, buf_32 += (screen->pitch/4 - 320)) { - for (int x = 0; x < 256; x++, buf_32++) { - uint16_t gen_color = context->cram[x/8 + ((y-224)/8)*32]; - b = ((gen_color >> 8) & 0xE) * 18; - g = ((gen_color >> 4) & 0xE) * 18; - r = (gen_color& 0xE) * 18; - *buf_32 = SDL_MapRGB(screen->format, r, g, b); - } - for (int x = 256; x < 320; x++, buf_32++) { - if ((x/8 & 1) ^ (y/8 & 1)) { - b = g = r = 255; - } else { - b = g = r = 0; - } - *buf_32 = SDL_MapRGB(screen->format, r, g, b); + for (int y = 0; y < 240; y++) { + for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) { + 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; + for (int j = 0; j < repeat_x; j++) { + *(line++) = SDL_MapRGB(screen->format, r, g, b); + } + } } } break; @@ -94,7 +102,7 @@ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } - SDL_UpdateRect(screen, 0, 0, 320, 240); + SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h); } void render_wait_quit() diff -r 8602ad493794 -r 2e15fa26fe58 stateview.c --- a/stateview.c Sat Dec 08 21:39:01 2012 -0800 +++ b/stateview.c Sat Dec 08 22:07:25 2012 -0800 @@ -14,11 +14,21 @@ fprintf(stderr, "Failed to open %s\n", argv[1]); exit(1); } + int width = 320; + int height = 240; + if (argc > 2) { + width = atoi(argv[2]); + if (argc > 3) { + height = atoi(argv[3]); + } else { + height = (width/320) * 240; + } + } vdp_context context; init_vdp_context(&context); vdp_load_savestate(&context, state_file); vdp_run_to_vblank(&context); - render_init(); + render_init(width, height); render_context(&context); render_wait_quit(); return 0;