2 |
|
* Display_SDL.h - C64 graphics display, emulator window handling, |
3 |
|
* SDL specific stuff |
4 |
|
* |
5 |
< |
* Frodo (C) 1994-1997,2002-2003 Christian Bauer |
5 |
> |
* Frodo Copyright (C) Christian Bauer |
6 |
|
* |
7 |
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
* it under the terms of the GNU General Public License as published by |
25 |
|
|
26 |
|
#include <SDL.h> |
27 |
|
|
28 |
+ |
#ifdef ENABLE_OPENGL |
29 |
+ |
#include <GL/glew.h> |
30 |
+ |
#endif |
31 |
+ |
|
32 |
+ |
|
33 |
+ |
// Display dimensions including drive LEDs etc. |
34 |
+ |
static const int FRAME_WIDTH = DISPLAY_X; |
35 |
+ |
static const int FRAME_HEIGHT = DISPLAY_Y + 16; |
36 |
|
|
37 |
|
// Display surface |
38 |
|
static SDL_Surface *screen = NULL; |
45 |
|
static struct sigaction pulse_sa; |
46 |
|
static itimerval pulse_tv; |
47 |
|
|
48 |
+ |
// SDL joysticks |
49 |
+ |
static SDL_Joystick *joy[2] = {NULL, NULL}; |
50 |
+ |
|
51 |
|
// Colors for speedometer/drive LEDs |
52 |
|
enum { |
53 |
|
black = 0, |
60 |
|
PALETTE_SIZE = 21 |
61 |
|
}; |
62 |
|
|
63 |
+ |
#ifdef ENABLE_OPENGL |
64 |
+ |
|
65 |
+ |
// Display texture dimensions |
66 |
+ |
static const int TEXTURE_SIZE = 512; // smallest power-of-two that fits DISPLAY_X/Y |
67 |
+ |
|
68 |
+ |
// Texture object for VIC palette |
69 |
+ |
static GLuint palette_tex; |
70 |
+ |
|
71 |
+ |
// Texture object for VIC display |
72 |
+ |
static GLuint vic_tex; |
73 |
+ |
|
74 |
+ |
#endif |
75 |
+ |
|
76 |
|
/* |
77 |
|
C64 keyboard matrix: |
78 |
|
|
97 |
|
int init_graphics(void) |
98 |
|
{ |
99 |
|
// Init SDL |
100 |
< |
if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
100 |
> |
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) { |
101 |
|
fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError()); |
102 |
|
return 0; |
103 |
|
} |
104 |
|
|
81 |
– |
// Open window |
82 |
– |
SDL_WM_SetCaption(VERSION_STRING, "Frodo"); |
83 |
– |
screen = SDL_SetVideoMode(DISPLAY_X, DISPLAY_Y + 17, 8, SDL_DOUBLEBUF); |
84 |
– |
|
105 |
|
return 1; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
+ |
#ifdef ENABLE_OPENGL |
110 |
+ |
/* |
111 |
+ |
* Set direct projection (GL coordinates = window pixel coordinates) |
112 |
+ |
*/ |
113 |
+ |
|
114 |
+ |
static void set_projection() |
115 |
+ |
{ |
116 |
+ |
int width = SDL_GetVideoSurface()->w; |
117 |
+ |
int height = SDL_GetVideoSurface()->h; |
118 |
+ |
|
119 |
+ |
glViewport(0, 0, width, height); |
120 |
+ |
glMatrixMode(GL_PROJECTION); |
121 |
+ |
glLoadIdentity(); |
122 |
+ |
|
123 |
+ |
float aspect = float(width) / float(height); |
124 |
+ |
const float want_aspect = float(FRAME_WIDTH) / float(FRAME_HEIGHT); |
125 |
+ |
int left, right, top, bottom; |
126 |
+ |
if (aspect > want_aspect) { |
127 |
+ |
// Window too wide, center horizontally |
128 |
+ |
top = 0; bottom = FRAME_HEIGHT; |
129 |
+ |
int diff = (int(FRAME_WIDTH * aspect / want_aspect) - FRAME_WIDTH) / 2; |
130 |
+ |
left = -diff; |
131 |
+ |
right = FRAME_WIDTH + diff; |
132 |
+ |
} else { |
133 |
+ |
// Window too high, center vertically |
134 |
+ |
left = 0; right = FRAME_WIDTH; |
135 |
+ |
int diff = (int(FRAME_HEIGHT * want_aspect / aspect) - FRAME_HEIGHT) / 2; |
136 |
+ |
top = -diff; |
137 |
+ |
bottom = FRAME_HEIGHT + diff; |
138 |
+ |
} |
139 |
+ |
glOrtho(left, right, bottom, top, -1, 1); |
140 |
+ |
|
141 |
+ |
glClear(GL_COLOR_BUFFER_BIT); |
142 |
+ |
} |
143 |
+ |
|
144 |
+ |
|
145 |
+ |
/* |
146 |
+ |
* User resized video display (only possible with OpenGL) |
147 |
+ |
*/ |
148 |
+ |
|
149 |
+ |
static void video_resized(int width, int height) |
150 |
+ |
{ |
151 |
+ |
uint32 flags = (ThePrefs.DisplayType == DISPTYPE_SCREEN ? SDL_FULLSCREEN : 0); |
152 |
+ |
flags |= (SDL_ANYFORMAT | SDL_OPENGL | SDL_RESIZABLE); |
153 |
+ |
SDL_SetVideoMode(width, height, 16, flags); |
154 |
+ |
set_projection(); |
155 |
+ |
} |
156 |
+ |
#endif |
157 |
+ |
|
158 |
+ |
|
159 |
|
/* |
160 |
|
* Display constructor |
161 |
|
*/ |
165 |
|
quit_requested = false; |
166 |
|
speedometer_string[0] = 0; |
167 |
|
|
168 |
+ |
// Open window |
169 |
+ |
SDL_WM_SetCaption(VERSION_STRING, "Frodo"); |
170 |
+ |
uint32 flags = (ThePrefs.DisplayType == DISPTYPE_SCREEN ? SDL_FULLSCREEN : 0); |
171 |
+ |
|
172 |
+ |
#ifdef ENABLE_OPENGL |
173 |
+ |
|
174 |
+ |
flags |= (SDL_ANYFORMAT | SDL_OPENGL | SDL_RESIZABLE); |
175 |
+ |
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
176 |
+ |
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
177 |
+ |
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
178 |
+ |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
179 |
+ |
SDL_Surface *real_screen = SDL_SetVideoMode(FRAME_WIDTH * 2, FRAME_HEIGHT * 2, 16, flags); |
180 |
+ |
if (!real_screen) { |
181 |
+ |
fprintf(stderr, "Couldn't initialize OpenGL video output (%s)\n", SDL_GetError()); |
182 |
+ |
exit(1); |
183 |
+ |
} |
184 |
+ |
|
185 |
+ |
// VIC display and UI elements are rendered into an off-screen surface |
186 |
+ |
screen = SDL_CreateRGBSurface(SDL_SWSURFACE, FRAME_WIDTH, FRAME_HEIGHT, 8, 0xff, 0xff, 0xff, 0xff); |
187 |
+ |
|
188 |
+ |
// We need OpenGL 2.0 or higher |
189 |
+ |
GLenum err = glewInit(); |
190 |
+ |
if (err != GLEW_OK) { |
191 |
+ |
fprintf(stderr, "Couldn't initialize GLEW (%s)\n", glewGetErrorString(err)); |
192 |
+ |
exit(1); |
193 |
+ |
} |
194 |
+ |
|
195 |
+ |
if (!glewIsSupported("GL_VERSION_2_0")) { |
196 |
+ |
fprintf(stderr, "Frodo requires OpenGL 2.0 or higher\n"); |
197 |
+ |
exit(1); |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
// Set direct projection |
201 |
+ |
set_projection(); |
202 |
+ |
|
203 |
+ |
// Set GL state |
204 |
+ |
glShadeModel(GL_FLAT); |
205 |
+ |
glDisable(GL_DITHER); |
206 |
+ |
glColor4f(1.0, 1.0, 1.0, 1.0); |
207 |
+ |
|
208 |
+ |
// Create fragment shader for emulating a paletted texture |
209 |
+ |
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER_ARB); |
210 |
+ |
const char * src = |
211 |
+ |
"uniform sampler2D screen;" |
212 |
+ |
"uniform sampler1D palette;" |
213 |
+ |
"const float texSize = 512.0;" // texture size |
214 |
+ |
"const float texel = 1.0 / texSize;" |
215 |
+ |
"void main()" |
216 |
+ |
"{" |
217 |
+ |
#if 0 |
218 |
+ |
// Nearest neighbour |
219 |
+ |
" vec4 idx = texture2D(screen, gl_TexCoord[0].st);" |
220 |
+ |
" gl_FragColor = texture1D(palette, idx.r);" |
221 |
+ |
#else |
222 |
+ |
// Linear interpolation |
223 |
+ |
// (setting the GL_TEXTURE_MAG_FILTER to GL_LINEAR would interpolate |
224 |
+ |
// the color indices which is not what we want; we need to manually |
225 |
+ |
// interpolate the palette values instead) |
226 |
+ |
" vec2 st = gl_TexCoord[0].st - vec2(texel * 0.5, texel * 0.5);" |
227 |
+ |
" vec4 idx00 = texture2D(screen, st);" |
228 |
+ |
" vec4 idx01 = texture2D(screen, st + vec2(0, texel));" |
229 |
+ |
" vec4 idx10 = texture2D(screen, st + vec2(texel, 0));" |
230 |
+ |
" vec4 idx11 = texture2D(screen, st + vec2(texel, texel));" |
231 |
+ |
" vec2 f = fract(st * texSize);" |
232 |
+ |
" vec4 color0 = mix(texture1D(palette, idx00.r), texture1D(palette, idx01.r), f.y);" |
233 |
+ |
" vec4 color1 = mix(texture1D(palette, idx10.r), texture1D(palette, idx11.r), f.y);" |
234 |
+ |
" gl_FragColor = mix(color0, color1, f.x);" |
235 |
+ |
#endif |
236 |
+ |
"}"; |
237 |
+ |
glShaderSource(shader, 1, &src, NULL); |
238 |
+ |
glCompileShader(shader); |
239 |
+ |
|
240 |
+ |
GLint status; |
241 |
+ |
glGetShaderiv(shader, GL_COMPILE_STATUS, &status); |
242 |
+ |
if (status == GL_FALSE) { |
243 |
+ |
GLint logLength = 0; |
244 |
+ |
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); |
245 |
+ |
if (logLength > 0) { |
246 |
+ |
GLchar *log = (GLchar *)malloc(logLength); |
247 |
+ |
GLint actual; |
248 |
+ |
glGetShaderInfoLog(shader, logLength, &actual, log); |
249 |
+ |
fprintf(stderr, "%s\n", log); |
250 |
+ |
exit(1); |
251 |
+ |
} |
252 |
+ |
} |
253 |
+ |
|
254 |
+ |
GLuint program = glCreateProgram(); |
255 |
+ |
glAttachShader(program, shader); |
256 |
+ |
glLinkProgram(program); |
257 |
+ |
glUseProgram(program); |
258 |
+ |
|
259 |
+ |
// Create VIC display texture (8-bit color index in the red channel) |
260 |
+ |
uint8 *tmp = (uint8 *)malloc(TEXTURE_SIZE * TEXTURE_SIZE); |
261 |
+ |
memset(tmp, 0, TEXTURE_SIZE * TEXTURE_SIZE); |
262 |
+ |
|
263 |
+ |
glGenTextures(1, &vic_tex); |
264 |
+ |
glActiveTexture(GL_TEXTURE0); |
265 |
+ |
glBindTexture(GL_TEXTURE_2D, vic_tex); |
266 |
+ |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
267 |
+ |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
268 |
+ |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // don't interpolate color index values |
269 |
+ |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
270 |
+ |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_SIZE, TEXTURE_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, tmp); |
271 |
+ |
glUniform1i(glGetUniformLocation(program, "screen"), 0); |
272 |
+ |
|
273 |
+ |
free(tmp); |
274 |
+ |
|
275 |
+ |
// Create VIC palette texture |
276 |
+ |
tmp = (uint8 *)malloc(256 * 3); |
277 |
+ |
memset(tmp, 0xff, 256 * 3); |
278 |
+ |
for (int i=0; i<16; ++i) { |
279 |
+ |
tmp[i*3+0] = palette_red[i & 0x0f]; |
280 |
+ |
tmp[i*3+1] = palette_green[i & 0x0f]; |
281 |
+ |
tmp[i*3+2] = palette_blue[i & 0x0f]; |
282 |
+ |
} |
283 |
+ |
tmp[fill_gray*3+0] = tmp[fill_gray*3+1] = tmp[fill_gray*3+2] = 0xd0; |
284 |
+ |
tmp[shine_gray*3+0] = tmp[shine_gray*3+1] = tmp[shine_gray*3+2] = 0xf0; |
285 |
+ |
tmp[shadow_gray*3+0] = tmp[shadow_gray*3+1] = tmp[shadow_gray*3+2] = 0x80; |
286 |
+ |
tmp[red*3+0] = 0xf0; |
287 |
+ |
tmp[red*3+1] = tmp[red*3+2] = 0; |
288 |
+ |
tmp[green*3+1] = 0xf0; |
289 |
+ |
tmp[green*3+0] = tmp[green*3+2] = 0; |
290 |
+ |
|
291 |
+ |
glGenTextures(1, &palette_tex); |
292 |
+ |
glActiveTexture(GL_TEXTURE1); |
293 |
+ |
glBindTexture(GL_TEXTURE_1D, palette_tex); |
294 |
+ |
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // don't interpolate palette entries |
295 |
+ |
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
296 |
+ |
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA8, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, tmp); |
297 |
+ |
glUniform1i(glGetUniformLocation(program, "palette"), 1); |
298 |
+ |
|
299 |
+ |
free(tmp); |
300 |
+ |
|
301 |
+ |
#else |
302 |
+ |
|
303 |
+ |
flags |= (SDL_HWSURFACE | SDL_DOUBLEBUF); |
304 |
+ |
screen = SDL_SetVideoMode(FRAME_WIDTH, FRAME_HEIGHT, 8, flags); |
305 |
+ |
|
306 |
+ |
#endif |
307 |
+ |
|
308 |
+ |
// Hide mouse pointer in fullscreen mode |
309 |
+ |
if (ThePrefs.DisplayType == DISPTYPE_SCREEN) |
310 |
+ |
SDL_ShowCursor(0); |
311 |
+ |
|
312 |
|
// LEDs off |
313 |
|
for (int i=0; i<4; i++) |
314 |
|
led_state[i] = old_led_state[i] = LED_OFF; |
316 |
|
// Start timer for LED error blinking |
317 |
|
c64_disp = this; |
318 |
|
pulse_sa.sa_handler = (void (*)(int))pulse_handler; |
319 |
< |
pulse_sa.sa_flags = 0; |
319 |
> |
pulse_sa.sa_flags = SA_RESTART; |
320 |
|
sigemptyset(&pulse_sa.sa_mask); |
321 |
|
sigaction(SIGALRM, &pulse_sa, NULL); |
322 |
|
pulse_tv.it_interval.tv_sec = 0; |
333 |
|
|
334 |
|
C64Display::~C64Display() |
335 |
|
{ |
336 |
+ |
pulse_tv.it_interval.tv_sec = 0; |
337 |
+ |
pulse_tv.it_interval.tv_usec = 0; |
338 |
+ |
pulse_tv.it_value.tv_sec = 0; |
339 |
+ |
pulse_tv.it_value.tv_usec = 0; |
340 |
+ |
setitimer(ITIMER_REAL, &pulse_tv, NULL); |
341 |
+ |
|
342 |
|
SDL_Quit(); |
343 |
+ |
|
344 |
+ |
c64_disp = NULL; |
345 |
|
} |
346 |
|
|
347 |
|
|
351 |
|
|
352 |
|
void C64Display::NewPrefs(Prefs *prefs) |
353 |
|
{ |
354 |
+ |
// Unused, we handle fullscreen/window mode switches in PollKeyboard() |
355 |
|
} |
356 |
|
|
357 |
|
|
413 |
|
draw_string(screen, DISPLAY_X * 4/5 + 8, DISPLAY_Y + 4, "D\x12 11", black, fill_gray); |
414 |
|
draw_string(screen, 24, DISPLAY_Y + 4, speedometer_string, black, fill_gray); |
415 |
|
|
416 |
+ |
#ifdef ENABLE_OPENGL |
417 |
+ |
// Load screen to texture |
418 |
+ |
glActiveTexture(GL_TEXTURE0); |
419 |
+ |
glBindTexture(GL_TEXTURE_2D, vic_tex); |
420 |
+ |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, FRAME_WIDTH, FRAME_HEIGHT, GL_RED, GL_UNSIGNED_BYTE, screen->pixels); |
421 |
+ |
|
422 |
+ |
// Draw textured rectangle |
423 |
+ |
glBegin(GL_QUADS); |
424 |
+ |
glTexCoord2f(0.0, 0.0); |
425 |
+ |
glVertex2f(0.0, 0.0); |
426 |
+ |
glTexCoord2f(float(FRAME_WIDTH) / TEXTURE_SIZE, 0.0); |
427 |
+ |
glVertex2f(float(FRAME_WIDTH), 0.0); |
428 |
+ |
glTexCoord2f(float(FRAME_WIDTH) / TEXTURE_SIZE, float(FRAME_HEIGHT) / TEXTURE_SIZE); |
429 |
+ |
glVertex2f(float(FRAME_WIDTH), float(FRAME_HEIGHT)); |
430 |
+ |
glTexCoord2f(0.0, float(FRAME_HEIGHT) / TEXTURE_SIZE); |
431 |
+ |
glVertex2f(0.0, float(FRAME_HEIGHT)); |
432 |
+ |
glEnd(); |
433 |
+ |
|
434 |
+ |
// Update display |
435 |
+ |
SDL_GL_SwapBuffers(); |
436 |
+ |
#else |
437 |
|
// Update display |
438 |
|
SDL_Flip(screen); |
439 |
+ |
#endif |
440 |
|
} |
441 |
|
|
442 |
|
|
671 |
|
switch (event.key.keysym.sym) { |
672 |
|
|
673 |
|
case SDLK_F9: // F9: Invoke SAM |
674 |
< |
SAM(TheC64); |
674 |
> |
if (ThePrefs.DisplayType == DISPTYPE_WINDOW) // don't invoke in fullscreen mode |
675 |
> |
SAM(TheC64); |
676 |
|
break; |
677 |
|
|
678 |
< |
case SDLK_F10: // F10: Quit |
679 |
< |
quit_requested = true; |
678 |
> |
case SDLK_F10: // F10: Prefs/Quit |
679 |
> |
TheC64->Pause(); |
680 |
> |
if (ThePrefs.DisplayType == DISPTYPE_SCREEN) { // exit fullscreen mode |
681 |
> |
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); |
682 |
> |
SDL_ShowCursor(1); |
683 |
> |
} |
684 |
> |
|
685 |
> |
if (!TheApp->RunPrefsEditor()) { |
686 |
> |
quit_requested = true; |
687 |
> |
} else { |
688 |
> |
if (ThePrefs.DisplayType == DISPTYPE_SCREEN) { // enter fullscreen mode |
689 |
> |
SDL_ShowCursor(0); |
690 |
> |
SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); |
691 |
> |
} |
692 |
> |
} |
693 |
> |
|
694 |
> |
TheC64->Resume(); |
695 |
|
break; |
696 |
|
|
697 |
|
case SDLK_F11: // F11: NMI (Restore) |
733 |
|
translate_key(event.key.keysym.sym, true, key_matrix, rev_matrix, joystick); |
734 |
|
break; |
735 |
|
|
736 |
+ |
#ifdef ENABLE_OPENGL |
737 |
+ |
// Window resized |
738 |
+ |
case SDL_VIDEORESIZE: |
739 |
+ |
video_resized(event.resize.w, event.resize.h); |
740 |
+ |
break; |
741 |
+ |
#endif |
742 |
+ |
|
743 |
|
// Quit Frodo |
744 |
|
case SDL_QUIT: |
745 |
|
quit_requested = true; |
760 |
|
|
761 |
|
|
762 |
|
/* |
763 |
+ |
* Open/close joystick drivers given old and new state of |
764 |
+ |
* joystick preferences |
765 |
+ |
*/ |
766 |
+ |
|
767 |
+ |
void C64::open_close_joystick(int port, int oldjoy, int newjoy) |
768 |
+ |
{ |
769 |
+ |
if (oldjoy != newjoy) { |
770 |
+ |
joy_minx[port] = joy_miny[port] = 32767; // Reset calibration |
771 |
+ |
joy_maxx[port] = joy_maxy[port] = -32768; |
772 |
+ |
if (newjoy) { |
773 |
+ |
joy[port] = SDL_JoystickOpen(newjoy - 1); |
774 |
+ |
if (joy[port] == NULL) |
775 |
+ |
fprintf(stderr, "Couldn't open joystick %d\n", port + 1); |
776 |
+ |
} else { |
777 |
+ |
if (joy[port]) { |
778 |
+ |
SDL_JoystickClose(joy[port]); |
779 |
+ |
joy[port] = NULL; |
780 |
+ |
} |
781 |
+ |
} |
782 |
+ |
} |
783 |
+ |
} |
784 |
+ |
|
785 |
+ |
void C64::open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2) |
786 |
+ |
{ |
787 |
+ |
open_close_joystick(0, oldjoy1, newjoy1); |
788 |
+ |
open_close_joystick(1, oldjoy2, newjoy2); |
789 |
+ |
} |
790 |
+ |
|
791 |
+ |
|
792 |
+ |
/* |
793 |
+ |
* Poll joystick port, return CIA mask |
794 |
+ |
*/ |
795 |
+ |
|
796 |
+ |
uint8 C64::poll_joystick(int port) |
797 |
+ |
{ |
798 |
+ |
uint8 j = 0xff; |
799 |
+ |
|
800 |
+ |
if (port == 0 && (joy[0] || joy[1])) |
801 |
+ |
SDL_JoystickUpdate(); |
802 |
+ |
|
803 |
+ |
if (joy[port]) { |
804 |
+ |
int x = SDL_JoystickGetAxis(joy[port], 0), y = SDL_JoystickGetAxis(joy[port], 1); |
805 |
+ |
|
806 |
+ |
if (x > joy_maxx[port]) |
807 |
+ |
joy_maxx[port] = x; |
808 |
+ |
if (x < joy_minx[port]) |
809 |
+ |
joy_minx[port] = x; |
810 |
+ |
if (y > joy_maxy[port]) |
811 |
+ |
joy_maxy[port] = y; |
812 |
+ |
if (y < joy_miny[port]) |
813 |
+ |
joy_miny[port] = y; |
814 |
+ |
|
815 |
+ |
if (joy_maxx[port] - joy_minx[port] < 100 || joy_maxy[port] - joy_miny[port] < 100) |
816 |
+ |
return 0xff; |
817 |
+ |
|
818 |
+ |
if (x < (joy_minx[port] + (joy_maxx[port]-joy_minx[port])/3)) |
819 |
+ |
j &= 0xfb; // Left |
820 |
+ |
else if (x > (joy_minx[port] + 2*(joy_maxx[port]-joy_minx[port])/3)) |
821 |
+ |
j &= 0xf7; // Right |
822 |
+ |
|
823 |
+ |
if (y < (joy_miny[port] + (joy_maxy[port]-joy_miny[port])/3)) |
824 |
+ |
j &= 0xfe; // Up |
825 |
+ |
else if (y > (joy_miny[port] + 2*(joy_maxy[port]-joy_miny[port])/3)) |
826 |
+ |
j &= 0xfd; // Down |
827 |
+ |
|
828 |
+ |
if (SDL_JoystickGetButton(joy[port], 0)) |
829 |
+ |
j &= 0xef; // Button |
830 |
+ |
} |
831 |
+ |
|
832 |
+ |
return j; |
833 |
+ |
} |
834 |
+ |
|
835 |
+ |
|
836 |
+ |
/* |
837 |
|
* Allocate C64 colors |
838 |
|
*/ |
839 |
|
|
863 |
|
* Show a requester (error message) |
864 |
|
*/ |
865 |
|
|
866 |
< |
long int ShowRequester(char *a,char *b,char *) |
866 |
> |
long int ShowRequester(const char *a, const char *b, const char *) |
867 |
|
{ |
868 |
|
printf("%s: %s\n", a, b); |
869 |
|
return 1; |