annotate render_sdl.c @ 277:765e132edd71

Using push/pop inside translated code is not compatible with the current way the Z80 core returns to the caller
author Mike Pavone <pavone@retrodev.com>
date Fri, 03 May 2013 19:27:32 -0700
parents 9b04b57434b5
children 8e2fa485c0f2
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
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
13 int32_t color_map[1 << 12];
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
14 uint8_t levels[] = {0, 27, 49, 71, 87, 103, 119, 130, 146, 157, 174, 190, 206, 228, 255};
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
15
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
16 uint32_t min_delay;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
17
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
18 void render_init(int width, int height)
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
19 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
20 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
21 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
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 atexit(SDL_Quit);
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
25 printf("width: %d, height: %d\n", width, height);
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
26 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
27 if (!screen) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
28 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
29 exit(1);
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 if (screen->format->BytesPerPixel < 2) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
32 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
33 exit(1);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
34 }
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
35 uint8_t b,g,r;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
36 for (uint16_t color = 0; color < (1 << 12); color++) {
230
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
37 if (color & FBUF_SHADOW) {
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
38 b = levels[(color >> 9) & 0x7];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
39 g = levels[(color >> 5) & 0x7];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
40 r = levels[(color >> 1) & 0x7];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
41 } else if(color & FBUF_HILIGHT) {
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
42 b = levels[((color >> 9) & 0x7) + 7];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
43 g = levels[((color >> 5) & 0x7) + 7];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
44 r = levels[((color >> 1) & 0x7) + 7];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
45 } else {
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
46 b = levels[(color >> 8) & 0xE];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
47 g = levels[(color >> 4) & 0xE];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
48 r = levels[color & 0xE];
d3266cee02c9 Implemented shadow hilight mode.
Mike Pavone <pavone@retrodev.com>
parents: 229
diff changeset
49 }
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
50 color_map[color] = SDL_MapRGB(screen->format, r, g, b);
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
51 }
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
52 min_delay = 0;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
53 for (int i = 0; i < 20; i++) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
54 uint32_t start = SDL_GetTicks();
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
55 SDL_Delay(1);
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
56 uint32_t delay = SDL_GetTicks()-start;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
57 if (delay > min_delay) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
58 min_delay = delay;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
59 }
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
60 }
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
61 if (!min_delay) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
62 min_delay = 1;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
63 }
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
64 printf("minimum delay: %d\n", min_delay);
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
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
67 void render_context(vdp_context * context)
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
68 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 uint8_t *buf_8;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
70 uint16_t *buf_16;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 uint32_t *buf_32;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 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
73 last_frame = SDL_GetTicks();
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 if (SDL_MUSTLOCK(screen)) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
75 if (SDL_LockSurface(screen) < 0) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 return;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
77 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 }
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
79 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
80 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
81 if (repeat_x > repeat_y) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
82 repeat_x = repeat_y;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
83 } else {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
84 repeat_y = repeat_x;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
85 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
86 switch (screen->format->BytesPerPixel) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
87 case 2:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
88 buf_16 = (uint16_t *)screen->pixels;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
89 for (int y = 0; y < 240; y++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
90 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
91 uint16_t *line = buf_16;
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
92 uint16_t *src_line = context->framebuf + y * 320;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
93 for (int x = 0; x < 320; x++) {
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
94 uint16_t color = color_map[*(src_line++) & 0xFFF];
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
95 for (int j = 0; j < repeat_x; j++) {
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
96 *(line++) = color;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
97 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
98 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
99 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 break;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
102 case 3:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
103 buf_8 = (uint8_t *)screen->pixels;
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
104 for (int y = 0; y < 240; y++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
105 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
106 uint8_t *line = buf_8;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
107 for (int x = 0; x < 320; x++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
108 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
109 b = ((gen_color >> 8) & 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
110 g = ((gen_color >> 4) & 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
111 r = (gen_color& 0xE) * 18;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
112 for (int j = 0; j < repeat_x; j++) {
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
113 *(buf_8+screen->format->Rshift/8) = r;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
114 *(buf_8+screen->format->Gshift/8) = g;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
115 *(buf_8+screen->format->Bshift/8) = b;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
116 buf_8 += 3;
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
117 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
118 }
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
119 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
120 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
121 break;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
122 case 4:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
123 buf_32 = (uint32_t *)screen->pixels;
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
124
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
125 for (int y = 0; y < 240; y++) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
126 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
127 uint32_t *line = buf_32;
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
128 uint16_t *src_line = context->framebuf + y * 320;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
129 for (int x = 0; x < 320; x++) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
130 uint32_t color;
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
131 if (!render_dbg) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
132 color = color_map[*(src_line++) & 0xFFF];
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
133 } else if(render_dbg == 2) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
134 color = color_map[context->cram[(y/30)*8 + x/40]];
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
135 } else if(render_dbg == 3) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
136 if (x & 1) {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
137 color = color_map[context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] & 0xF) ]];
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
138 } else {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
139 color = color_map[context->cram[ (debug_pal << 4) | (context->vdpmem[(x/8)*32 + (y/8)*32*40 + (x%8)/2 + (y%8)*4] >> 4) ]];
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
140 }
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
141 }else {
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
142 uint16_t gen_color = context->framebuf[y * 320 + x];
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
143 r = g = b = 0;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
144 switch(gen_color & FBUF_SRC_MASK)
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
145 {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
146 case FBUF_SRC_A:
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
147 g = 127;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
148 break;
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
149 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
150 g = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
151 b = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
152 break;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
153 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
154 b = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
155 break;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
156 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
157 r = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
158 break;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
159 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
160 r = 127;
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
161 b = 127;
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
162 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
163 if (gen_color & FBUF_BIT_PRIORITY) {
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
164 b *= 2;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
165 g *= 2;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
166 r *= 2;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
167 }
234
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
168 if (gen_color & FBUF_SHADOW) {
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
169 b /= 2;
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
170 g /= 2;
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
171 r /= 2;
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
172 } else if(gen_color & FBUF_HILIGHT) {
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
173 b = b ? b : 64;
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
174 g = g ? g : 64;
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
175 r = r ? r : 64;
f456ee23d372 Add shadow/higlight info to debug renderer
Mike Pavone <pavone@retrodev.com>
parents: 230
diff changeset
176 }
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
177 color = SDL_MapRGB(screen->format, r, g, b);
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
178 }
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
179 for (int j = 0; j < repeat_x; j++) {
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
180 *(line++) = color;
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
181 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
182 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
183 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
184 }
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
185 break;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
186 }
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
187 if ( SDL_MUSTLOCK(screen) ) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
188 SDL_UnlockSurface(screen);
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
189 }
33
2e15fa26fe58 Add support for simple resolution scaling
Mike Pavone <pavone@retrodev.com>
parents: 28
diff changeset
190 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
191 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
192
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
193 void render_wait_quit(vdp_context * context)
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
194 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
195 SDL_Event event;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
196 while(SDL_WaitEvent(&event)) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
197 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
198 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
199 if (event.key.keysym.sym == SDLK_LEFTBRACKET) {
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
200 render_dbg++;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
201 if (render_dbg == 4) {
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
202 render_dbg = 0;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
203 }
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
204 render_context(context);
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
205 } else if(event.key.keysym.sym == SDLK_RIGHTBRACKET) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
206 debug_pal++;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
207 if (debug_pal == 4) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
208 debug_pal = 0;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
209 }
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
210 }
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
211 break;
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
212 case SDL_QUIT:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
213 return;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
214 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
216 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
217
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
218 #define DPAD_UP 0x01
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
219 #define BUTTON_Z 0x01
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
220 #define DPAD_DOWN 0x02
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
221 #define BUTTON_Y 0x02
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
222 #define DPAD_LEFT 0x04
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
223 #define BUTTON_X 0x04
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
224 #define DPAD_RIGHT 0x08
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
225 #define BUTTON_MODE 0x08
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
226 #define BUTTON_A 0x10
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
227 #define BUTTON_B 0x10
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
228 #define BUTTON_START 0x20
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
229 #define BUTTON_C 0x20
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
230
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
231 #define FRAME_DELAY 16
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
232 #define MIN_DELAY 5
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
233 uint32_t frame_counter = 0;
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
234 uint32_t start = 0;
237
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
235 extern uint8_t z80_ram[];
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 135
diff changeset
236 int wait_render_frame(vdp_context * context)
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
237 {
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
238 FILE * outfile;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
239 SDL_Event event;
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 135
diff changeset
240 int ret = 0;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
241 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
242 switch (event.type) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
243 case SDL_KEYDOWN:
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
244 switch(event.key.keysym.sym)
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
245 {
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
246 case SDLK_LEFTBRACKET:
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
247 render_dbg++;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
248 if (render_dbg == 4) {
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
249 render_dbg = 0;
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
250 }
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
251 break;
135
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
252 case SDLK_RIGHTBRACKET:
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
253 debug_pal++;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
254 if (debug_pal == 4) {
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
255 debug_pal = 0;
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
256 }
a81c548cf353 Fix 68K->VDP DMA
Mike Pavone <pavone@retrodev.com>
parents: 66
diff changeset
257 break;
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
258 case SDLK_t:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
259 outfile = fopen("state.gst", "wb");
55
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
260 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
261 vdp_save_state(context, outfile);
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
262 fclose(outfile);
8317f174d916 Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents: 54
diff changeset
263 puts("state saved to state.gst");
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
264 break;
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 135
diff changeset
265 case SDLK_u:
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 135
diff changeset
266 ret = 1;
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 135
diff changeset
267 break;
66
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
268 case SDLK_RETURN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
269 gamepad_1.input[GAMEPAD_TH0] |= BUTTON_START;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
270 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
271 case SDLK_UP:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
272 gamepad_1.input[GAMEPAD_TH0] |= DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
273 gamepad_1.input[GAMEPAD_TH1] |= DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
274 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
275 case SDLK_DOWN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
276 gamepad_1.input[GAMEPAD_TH0] |= DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
277 gamepad_1.input[GAMEPAD_TH1] |= DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
278 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
279 case SDLK_LEFT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
280 gamepad_1.input[GAMEPAD_TH1] |= DPAD_LEFT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
281 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
282 case SDLK_RIGHT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
283 gamepad_1.input[GAMEPAD_TH1] |= DPAD_RIGHT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
284 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
285 case SDLK_a:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
286 gamepad_1.input[GAMEPAD_TH0] |= BUTTON_A;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
287 //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
288 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
289 case SDLK_s:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
290 gamepad_1.input[GAMEPAD_TH1] |= BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
291 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
292 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
293 case SDLK_d:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
294 gamepad_1.input[GAMEPAD_TH1] |= BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
295 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
296 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
297 case SDLK_q:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
298 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_X;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
299 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
300 case SDLK_w:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
301 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_Y;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
302 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
303 case SDLK_e:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
304 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_Z;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
305 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
306 case SDLK_f:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
307 gamepad_1.input[GAMEPAD_EXTRA] |= BUTTON_MODE;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
308 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
309 }
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
310 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
311 case SDL_KEYUP:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
312 switch(event.key.keysym.sym)
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
313 {
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
314 case SDLK_RETURN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
315 gamepad_1.input[GAMEPAD_TH0] &= ~BUTTON_START;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
316 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
317 case SDLK_UP:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
318 gamepad_1.input[GAMEPAD_TH0] &= ~DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
319 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_UP;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
320 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
321 case SDLK_DOWN:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
322 gamepad_1.input[GAMEPAD_TH0] &= ~DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
323 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_DOWN;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
324 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
325 case SDLK_LEFT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
326 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_LEFT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
327 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
328 case SDLK_RIGHT:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
329 gamepad_1.input[GAMEPAD_TH1] &= ~DPAD_RIGHT;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
330 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
331 case SDLK_a:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
332 gamepad_1.input[GAMEPAD_TH0] &= ~BUTTON_A;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
333 //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
334 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
335 case SDLK_s:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
336 gamepad_1.input[GAMEPAD_TH1] &= ~BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
337 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_B;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
338 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
339 case SDLK_d:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
340 gamepad_1.input[GAMEPAD_TH1] &= ~BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
341 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_C;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
342 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
343 case SDLK_q:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
344 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_X;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
345 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
346 case SDLK_w:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
347 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_Y;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
348 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
349 case SDLK_e:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
350 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_Z;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
351 break;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
352 case SDLK_f:
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
353 gamepad_1.input[GAMEPAD_EXTRA] &= ~BUTTON_MODE;
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
354 break;
237
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
355 case SDLK_z:{
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
356 FILE * f = fopen("zram.bin", "wb");
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
357 fwrite(z80_ram, 1, 8 * 1024, f);
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
358 fclose(f);
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
359 break;
7ccc4ae86e07 Added key to save Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 234
diff changeset
360 }
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
361 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
362 break;
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
363 case SDL_QUIT:
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
364 puts("");
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
365 exit(0);
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
366 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
367 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
368 //TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS
272
9b04b57434b5 Implement LDI
Mike Pavone <pavone@retrodev.com>
parents: 237
diff changeset
369 /*uint32_t current = SDL_GetTicks();
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
370 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
371 if (current < desired) {
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
372 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
373 //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
374 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
375 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
376 }
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
377 while ((desired) >= SDL_GetTicks()) {
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
378 }
272
9b04b57434b5 Implement LDI
Mike Pavone <pavone@retrodev.com>
parents: 237
diff changeset
379 }*/
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
380 render_context(context);
229
d60837a7d18a Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
381
272
9b04b57434b5 Implement LDI
Mike Pavone <pavone@retrodev.com>
parents: 237
diff changeset
382
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
383 //TODO: Figure out why this causes segfaults
272
9b04b57434b5 Implement LDI
Mike Pavone <pavone@retrodev.com>
parents: 237
diff changeset
384 /*frame_counter++;
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
385 if ((last_frame - start) > 1000) {
272
9b04b57434b5 Implement LDI
Mike Pavone <pavone@retrodev.com>
parents: 237
diff changeset
386 if (start && (last_frame-start)) {
63
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
387 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
388 fflush(stdout);
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
389 }
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
390 start = last_frame;
a6dd5b7a971b Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents: 55
diff changeset
391 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
392 }*/
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 135
diff changeset
393 return ret;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
394 }
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
395
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
396