Mercurial > repos > blastem
annotate render_sdl.c @ 59:32650c77008a
ecx was getting clobbered before the relevant temp value was used in some cases during memory reads
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 18 Dec 2012 22:56:04 -0800 |
parents | 8317f174d916 |
children | a6dd5b7a971b |
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" |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 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
|
7 uint8_t render_dbg = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
9 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
|
10 |
33
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
11 void render_init(int width, int height) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 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
|
15 exit(1); |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 atexit(SDL_Quit); |
33
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
18 printf("width: %d, height: %d\n", width, height); |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
19 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
|
20 if (!screen) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 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
|
22 exit(1); |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 if (screen->format->BytesPerPixel < 2) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 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
|
26 exit(1); |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
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 void render_context(vdp_context * context) |
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 uint8_t *buf_8; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 uint16_t *buf_16; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 uint32_t *buf_32; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 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
|
36 last_frame = SDL_GetTicks(); |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 if (SDL_MUSTLOCK(screen)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 if (SDL_LockSurface(screen) < 0) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
33
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
42 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
|
43 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
|
44 if (repeat_x > repeat_y) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
45 repeat_x = repeat_y; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
46 } else { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
47 repeat_y = repeat_x; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
48 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 switch (screen->format->BytesPerPixel) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 case 2: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 buf_16 = (uint16_t *)screen->pixels; |
33
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
52 for (int y = 0; y < 240; y++) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
53 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
|
54 uint16_t *line = buf_16; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
55 for (int x = 0; x < 320; x++) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
56 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
|
57 b = ((gen_color >> 8) & 0xE) * 18; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
58 g = ((gen_color >> 4) & 0xE) * 18; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
59 r = (gen_color& 0xE) * 18; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
60 for (int j = 0; j < repeat_x; j++) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
61 *(line++) = SDL_MapRGB(screen->format, r, g, b); |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
62 } |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
63 } |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
64 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 break; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 case 3: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 buf_8 = (uint8_t *)screen->pixels; |
33
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
69 for (int y = 0; y < 240; y++) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
70 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
|
71 uint8_t *line = buf_8; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
72 for (int x = 0; x < 320; x++) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
73 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
|
74 b = ((gen_color >> 8) & 0xE) * 18; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
75 g = ((gen_color >> 4) & 0xE) * 18; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
76 r = (gen_color& 0xE) * 18; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
77 for (int j = 0; j < repeat_x; j++) { |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
78 *(buf_8+screen->format->Rshift/8) = r; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
79 *(buf_8+screen->format->Gshift/8) = g; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
80 *(buf_8+screen->format->Bshift/8) = b; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
81 buf_8 += 3; |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
82 } |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
83 } |
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
84 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 break; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 case 4: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 buf_32 = (uint32_t *)screen->pixels; |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
89 |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
90 for (int y = 0; y < 240; y++) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
91 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
|
92 uint32_t *line = buf_32; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
93 for (int x = 0; x < 320; x++) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
94 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
|
95 if (render_dbg == 1) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
96 r = g = b = 0; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
97 switch(gen_color & FBUF_SRC_MASK) |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
98 { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
99 case FBUF_SRC_A: |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
100 g = 127; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
101 break; |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
102 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
|
103 g = 127; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
104 b = 127; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
105 break; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
106 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
|
107 b = 127; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
108 break; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
109 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
|
110 r = 127; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
111 break; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
112 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
|
113 r = 127; |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
114 b = 127; |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
115 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
116 if (gen_color & FBUF_BIT_PRIORITY) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
117 b *= 2; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
118 g *= 2; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
119 r *= 2; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
120 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
121 } else { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
122 if (render_dbg == 2) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
123 gen_color = context->cram[(y/30)*8 + x/40]; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
124 } |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 } |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
129 for (int j = 0; j < repeat_x; j++) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
130 *(line++) = SDL_MapRGB(screen->format, r, g, b); |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
131 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
132 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
133 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
134 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
135 break; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
136 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 if ( SDL_MUSTLOCK(screen) ) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 SDL_UnlockSurface(screen); |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 } |
33
2e15fa26fe58
Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents:
28
diff
changeset
|
140 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
|
141 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
143 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 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
|
148 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
|
149 if (event.key.keysym.sym == SDLK_LEFTBRACKET) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
150 render_dbg++; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
151 if (render_dbg == 3) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
152 render_dbg = 0; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
153 } |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
154 render_context(context); |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
155 } |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
156 break; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
163 #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
|
164 #define MIN_DELAY 10 |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
165 |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
166 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
|
167 { |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
168 SDL_Event event; |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
169 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
|
170 switch (event.type) { |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
171 case SDL_KEYDOWN: |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
172 //TODO: Update emulated gamepads |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
173 if (event.key.keysym.sym == SDLK_LEFTBRACKET) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
174 render_dbg++; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
175 if (render_dbg == 3) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
176 render_dbg = 0; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
177 } |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
178 } else if(event.key.keysym.sym == SDLK_t) { |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
179 FILE * outfile = fopen("state.gst", "wb"); |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
180 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
|
181 vdp_save_state(context, outfile); |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
182 fclose(outfile); |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
183 puts("state saved to state.gst"); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
184 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
185 break; |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
186 case SDL_QUIT: |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
187 exit(0); |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
188 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
189 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
190 //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
|
191 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
|
192 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
|
193 if (current < desired) { |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
194 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
|
195 //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
|
196 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
|
197 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
|
198 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
199 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
|
200 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
201 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
202 render_context(context); |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
203 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
204 |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
205 |