annotate render_sdl.c @ 180:8b846bcff6a2

Fix rendering of sprites at the top edge of screen
author Mike Pavone <pavone@retrodev.com>
date Tue, 08 Jan 2013 09:34:46 -0800
parents a81c548cf353
children 209a37eed3e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <SDL.h>
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdlib.h>
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <stdio.h>
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "render.h"
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
5 #include "blastem.h"
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
6
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
7 SDL_Surface *screen;
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
8 uint8_t render_dbg = 0;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
9 uint8_t debug_pal = 0;
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
10
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
11 uint32_t last_frame = 0;
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
12
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
13 void render_init(int width, int height)
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 exit(1);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
18 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 atexit(SDL_Quit);
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
20 printf("width: %d, height: %d\n", width, height);
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
21 screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_ANYFORMAT);
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
22 if (!screen) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
23 fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError());
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24 exit(1);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
25 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26 if (screen->format->BytesPerPixel < 2) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27 fprintf(stderr, "BlastEm requires at least a 16-bit surface, SDL returned a %d-bit surface\n", screen->format->BytesPerPixel * 8);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 exit(1);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
29 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
30 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
31
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 void render_context(vdp_context * context)
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 uint8_t *buf_8;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
35 uint16_t *buf_16;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 uint32_t *buf_32;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
37 uint8_t b,g,r;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
38 last_frame = SDL_GetTicks();
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
39 if (SDL_MUSTLOCK(screen)) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
40 if (SDL_LockSurface(screen) < 0) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
41 return;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 }
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
44 uint16_t repeat_x = screen->clip_rect.w / 320;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
45 uint16_t repeat_y = screen->clip_rect.h / 240;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
46 if (repeat_x > repeat_y) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
47 repeat_x = repeat_y;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
48 } else {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
49 repeat_y = repeat_x;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
50 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51 switch (screen->format->BytesPerPixel) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
52 case 2:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
53 buf_16 = (uint16_t *)screen->pixels;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
54 for (int y = 0; y < 240; y++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
55 for (int i = 0; i < repeat_y; i++,buf_16 += screen->pitch/2) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
56 uint16_t *line = buf_16;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
57 for (int x = 0; x < 320; x++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
58 uint16_t gen_color = context->framebuf[y * 320 + x];
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
59 b = ((gen_color >> 8) & 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
60 g = ((gen_color >> 4) & 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
61 r = (gen_color& 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
62 for (int j = 0; j < repeat_x; j++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
63 *(line++) = SDL_MapRGB(screen->format, r, g, b);
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
64 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
65 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
66 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 break;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 case 3:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 buf_8 = (uint8_t *)screen->pixels;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
71 for (int y = 0; y < 240; y++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
72 for (int i = 0; i < repeat_y; i++,buf_8 += screen->pitch) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
73 uint8_t *line = buf_8;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
74 for (int x = 0; x < 320; x++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
75 uint16_t gen_color = context->framebuf[y * 320 + x];
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
76 b = ((gen_color >> 8) & 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
77 g = ((gen_color >> 4) & 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
78 r = (gen_color& 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
79 for (int j = 0; j < repeat_x; j++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
80 *(buf_8+screen->format->Rshift/8) = r;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
81 *(buf_8+screen->format->Gshift/8) = g;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
82 *(buf_8+screen->format->Bshift/8) = b;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
83 buf_8 += 3;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
84 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
85 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
86 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 break;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
89 case 4:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
90 buf_32 = (uint32_t *)screen->pixels;
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
91
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
92 for (int y = 0; y < 240; y++) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
93 for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
94 uint32_t *line = buf_32;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
95 for (int x = 0; x < 320; x++) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
96 uint16_t gen_color = context->framebuf[y * 320 + x];
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
97 if (render_dbg == 1) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
98 r = g = b = 0;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
99 switch(gen_color & FBUF_SRC_MASK)
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
100 {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
101 case FBUF_SRC_A:
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
102 g = 127;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
103 break;
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
104 case FBUF_SRC_W:
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
105 g = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
106 b = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
107 break;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
108 case FBUF_SRC_B:
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
109 b = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
110 break;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
111 case FBUF_SRC_S:
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
112 r = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
113 break;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
114 case FBUF_SRC_BG:
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
115 r = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
116 b = 127;
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
117 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
118 if (gen_color & FBUF_BIT_PRIORITY) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
119 b *= 2;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
120 g *= 2;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
121 r *= 2;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
122 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
123 } else {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
124 if (render_dbg == 2) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
125 gen_color = context->cram[(y/30)*8 + x/40];
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
126 } else if(render_dbg == 3) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
127 if (x & 1) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
128 gen_color = context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] & 0xF) ];
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
129 } else {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
130 gen_color = context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] >> 4) ];
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
131 }
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
132 }
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
133 b = ((gen_color >> 8) & 0xE) * 18;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
134 g = ((gen_color >> 4) & 0xE) * 18;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
135 r = (gen_color& 0xE) * 18;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
136 }
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
137 for (int j = 0; j < repeat_x; j++) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
138 *(line++) = SDL_MapRGB(screen->format, r, g, b);
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
139 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
140 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
141 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
142 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
143 break;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
144 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 if ( SDL_MUSTLOCK(screen) ) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146 SDL_UnlockSurface(screen);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
147 }
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
148 SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h);
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
149 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
150
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
151 void render_wait_quit(vdp_context * context)
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
152 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
153 SDL_Event event;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
154 while(SDL_WaitEvent(&event)) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
155 switch (event.type) {
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
156 case SDL_KEYDOWN:
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
157 if (event.key.keysym.sym == SDLK_LEFTBRACKET) {
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
158 render_dbg++;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
159 if (render_dbg == 4) {
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
160 render_dbg = 0;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
161 }
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
162 render_context(context);
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
163 } else if(event.key.keysym.sym == SDLK_RIGHTBRACKET) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
164 debug_pal++;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
165 if (debug_pal == 4) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
166 debug_pal = 0;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
167 }
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
168 }
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
169 break;
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
170 case SDL_QUIT:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
171 return;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
173 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
174 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
175
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
176 #define DPAD_UP 0x01
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
177 #define BUTTON_Z 0x01
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
178 #define DPAD_DOWN 0x02
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
179 #define BUTTON_Y 0x02
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
180 #define DPAD_LEFT 0x04
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
181 #define BUTTON_X 0x04
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
182 #define DPAD_RIGHT 0x08
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
183 #define BUTTON_MODE 0x08
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
184 #define BUTTON_A 0x10
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
185 #define BUTTON_B 0x10
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
186 #define BUTTON_START 0x20
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
187 #define BUTTON_C 0x20
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
188
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
189 #define FRAME_DELAY 16
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
190 #define MIN_DELAY 10
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
191 uint32_t frame_counter = 0;
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
192 uint32_t start = 0;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
193 void wait_render_frame(vdp_context * context)
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
194 {
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
195 FILE * outfile;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
196 SDL_Event event;
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
197 while(SDL_PollEvent(&event)) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
198 switch (event.type) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
199 case SDL_KEYDOWN:
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
200 switch(event.key.keysym.sym)
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
201 {
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
202 case SDLK_LEFTBRACKET:
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
203 render_dbg++;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
204 if (render_dbg == 4) {
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
205 render_dbg = 0;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
206 }
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
207 break;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
208 case SDLK_RIGHTBRACKET:
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
209 debug_pal++;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
210 if (debug_pal == 4) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
211 debug_pal = 0;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
212 }
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
213 break;
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
214 case SDLK_t:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
215 outfile = fopen("state.gst", "wb");
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
216 fwrite("GST\0\0\0\xE0\x40", 1, 8, outfile);
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
217 vdp_save_state(context, outfile);
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
218 fclose(outfile);
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
219 puts("state saved to state.gst");
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
220 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
221 case SDLK_RETURN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
222 gamepad_1.input[GAMEPAD_TH0] |= BUTTON_START;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
223 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
224 case SDLK_UP:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
225 gamepad_1.input[GAMEPAD_TH0] |= DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
226 gamepad_1.input[GAMEPAD_TH1] |= DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
227 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
228 case SDLK_DOWN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
229 gamepad_1.input[GAMEPAD_TH0] |= DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
230 gamepad_1.input[GAMEPAD_TH1] |= DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
231 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
232 case SDLK_LEFT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
233 gamepad_1.input[GAMEPAD_TH1] |= DPAD_LEFT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
234 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
235 case SDLK_RIGHT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
236 gamepad_1.input[GAMEPAD_TH1] |= DPAD_RIGHT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
237 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
238 case SDLK_a:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
239 gamepad_1.input[GAMEPAD_TH0] |= BUTTON_A;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
240 //printf("BUTTON_A Dn | GAMEPAD_TH0: %X\n", gamepad_1.input[GAMEPAD_TH0]);
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
241 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
242 case SDLK_s:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
243 gamepad_1.input[GAMEPAD_TH1] |= BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
244 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
245 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
246 case SDLK_d:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
247 gamepad_1.input[GAMEPAD_TH1] |= BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
248 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
249 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
250 case SDLK_q:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
251 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_X;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
252 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
253 case SDLK_w:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
254 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_Y;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
255 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
256 case SDLK_e:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
257 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_Z;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
258 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
259 case SDLK_f:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
260 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_MODE;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
261 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
262 }
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
263 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
264 case SDL_KEYUP:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
265 switch(event.key.keysym.sym)
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
266 {
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
267 case SDLK_RETURN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
268 gamepad_1.input[GAMEPAD_TH0] &= ~BUTTON_START;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
269 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
270 case SDLK_UP:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
271 gamepad_1.input[GAMEPAD_TH0] &= ~DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
272 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
273 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
274 case SDLK_DOWN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
275 gamepad_1.input[GAMEPAD_TH0] &= ~DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
276 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
277 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
278 case SDLK_LEFT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
279 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_LEFT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
280 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
281 case SDLK_RIGHT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
282 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_RIGHT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
283 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
284 case SDLK_a:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
285 gamepad_1.input[GAMEPAD_TH0] &= ~BUTTON_A;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
286 //printf("BUTTON_A Up | GAMEPAD_TH0: %X\n", gamepad_1.input[GAMEPAD_TH0]);
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
287 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
288 case SDLK_s:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
289 gamepad_1.input[GAMEPAD_TH1] &= ~BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
290 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
291 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
292 case SDLK_d:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
293 gamepad_1.input[GAMEPAD_TH1] &= ~BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
294 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
295 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
296 case SDLK_q:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
297 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_X;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
298 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
299 case SDLK_w:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
300 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_Y;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
301 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
302 case SDLK_e:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
303 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_Z;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
304 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
305 case SDLK_f:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
306 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_MODE;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
307 break;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
308 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
309 break;
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
310 case SDL_QUIT:
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
311 puts("");
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
312 exit(0);
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
313 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
314 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
315 //TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
316 uint32_t current = SDL_GetTicks();
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
317 uint32_t desired = last_frame + FRAME_DELAY;
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
318 if (current < desired) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
319 uint32_t delay = last_frame + FRAME_DELAY - current;
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
320 //TODO: Calculate MIN_DELAY at runtime
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
321 if (delay > MIN_DELAY) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
322 SDL_Delay((delay/MIN_DELAY)*MIN_DELAY);
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
323 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
324 while ((desired) < SDL_GetTicks()) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
325 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
326 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
327 render_context(context);
64
2b1a65f4b85d Cleanup 68K timing code. Temporarily omment out fFPS counter as it was causing segfaults
Mike Pavone <pavone@retrodev.com>
parents: 63
diff changeset
328 /*
2b1a65f4b85d Cleanup 68K timing code. Temporarily omment out fFPS counter as it was causing segfaults
Mike Pavone <pavone@retrodev.com>
parents: 63
diff changeset
329 //TODO: Figure out why this causes segfaults
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
330 frame_counter++;
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
331 if ((last_frame - start) > 1000) {
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
332 if (start) {
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
333 printf("\r%f fps", ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
334 fflush(stdout);
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
335 }
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
336 start = last_frame;
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
337 frame_counter = 0;
64
2b1a65f4b85d Cleanup 68K timing code. Temporarily omment out fFPS counter as it was causing segfaults
Mike Pavone <pavone@retrodev.com>
parents: 63
diff changeset
338 }*/
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
339 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
340
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
341