2 |
|
* Display_SDL.h - C64 graphics display, emulator window handling, |
3 |
|
* SDL specific stuff |
4 |
|
* |
5 |
< |
* Frodo (C) 1994-1997,2002 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 |
37 |
|
static struct sigaction pulse_sa; |
38 |
|
static itimerval pulse_tv; |
39 |
|
|
40 |
+ |
// SDL joysticks |
41 |
+ |
static SDL_Joystick *joy[2] = {NULL, NULL}; |
42 |
+ |
|
43 |
|
// Colors for speedometer/drive LEDs |
44 |
|
enum { |
45 |
|
black = 0, |
76 |
|
int init_graphics(void) |
77 |
|
{ |
78 |
|
// Init SDL |
79 |
< |
if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
79 |
> |
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) { |
80 |
|
fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError()); |
81 |
|
return 0; |
82 |
|
} |
83 |
|
|
81 |
– |
// Open window |
82 |
– |
SDL_WM_SetCaption(VERSION_STRING, "Frodo"); |
83 |
– |
screen = SDL_SetVideoMode(DISPLAY_X, DISPLAY_Y + 17, 8, SDL_DOUBLEBUF); |
84 |
– |
|
84 |
|
return 1; |
85 |
|
} |
86 |
|
|
94 |
|
quit_requested = false; |
95 |
|
speedometer_string[0] = 0; |
96 |
|
|
97 |
+ |
// Open window |
98 |
+ |
SDL_WM_SetCaption(VERSION_STRING, "Frodo"); |
99 |
+ |
screen = SDL_SetVideoMode(DISPLAY_X, DISPLAY_Y + 17, 8, SDL_DOUBLEBUF | (ThePrefs.DisplayType == DISPTYPE_SCREEN ? SDL_FULLSCREEN : 0)); |
100 |
+ |
|
101 |
+ |
// Hide mouse pointer in fullscreen mode |
102 |
+ |
if (ThePrefs.DisplayType == DISPTYPE_SCREEN) |
103 |
+ |
SDL_ShowCursor(0); |
104 |
+ |
|
105 |
|
// LEDs off |
106 |
|
for (int i=0; i<4; i++) |
107 |
|
led_state[i] = old_led_state[i] = LED_OFF; |
109 |
|
// Start timer for LED error blinking |
110 |
|
c64_disp = this; |
111 |
|
pulse_sa.sa_handler = (void (*)(int))pulse_handler; |
112 |
< |
pulse_sa.sa_flags = 0; |
112 |
> |
pulse_sa.sa_flags = SA_RESTART; |
113 |
|
sigemptyset(&pulse_sa.sa_mask); |
114 |
|
sigaction(SIGALRM, &pulse_sa, NULL); |
115 |
|
pulse_tv.it_interval.tv_sec = 0; |
126 |
|
|
127 |
|
C64Display::~C64Display() |
128 |
|
{ |
129 |
+ |
pulse_tv.it_interval.tv_sec = 0; |
130 |
+ |
pulse_tv.it_interval.tv_usec = 0; |
131 |
+ |
pulse_tv.it_value.tv_sec = 0; |
132 |
+ |
pulse_tv.it_value.tv_usec = 0; |
133 |
+ |
setitimer(ITIMER_REAL, &pulse_tv, NULL); |
134 |
+ |
|
135 |
|
SDL_Quit(); |
136 |
+ |
|
137 |
+ |
c64_disp = NULL; |
138 |
|
} |
139 |
|
|
140 |
|
|
441 |
|
switch (event.key.keysym.sym) { |
442 |
|
|
443 |
|
case SDLK_F9: // F9: Invoke SAM |
444 |
< |
SAM(TheC64); |
444 |
> |
if (ThePrefs.DisplayType == DISPTYPE_WINDOW) // don't invoke in fullscreen mode |
445 |
> |
SAM(TheC64); |
446 |
|
break; |
447 |
|
|
448 |
< |
case SDLK_F10: // F10: Quit |
449 |
< |
quit_requested = true; |
448 |
> |
case SDLK_F10: // F10: Prefs/Quit |
449 |
> |
TheC64->Pause(); |
450 |
> |
if (ThePrefs.DisplayType == DISPTYPE_SCREEN) { // exit fullscreen mode |
451 |
> |
SDL_WM_ToggleFullScreen(screen); |
452 |
> |
SDL_ShowCursor(1); |
453 |
> |
} |
454 |
> |
|
455 |
> |
if (!TheApp->RunPrefsEditor()) { |
456 |
> |
quit_requested = true; |
457 |
> |
} |
458 |
> |
|
459 |
> |
if (ThePrefs.DisplayType == DISPTYPE_SCREEN) { // enter fullscreen mode |
460 |
> |
SDL_ShowCursor(0); |
461 |
> |
SDL_WM_ToggleFullScreen(screen); |
462 |
> |
} |
463 |
> |
|
464 |
> |
TheC64->Resume(); |
465 |
|
break; |
466 |
|
|
467 |
|
case SDLK_F11: // F11: NMI (Restore) |
523 |
|
|
524 |
|
|
525 |
|
/* |
526 |
+ |
* Open/close joystick drivers given old and new state of |
527 |
+ |
* joystick preferences |
528 |
+ |
*/ |
529 |
+ |
|
530 |
+ |
void C64::open_close_joystick(int port, int oldjoy, int newjoy) |
531 |
+ |
{ |
532 |
+ |
if (oldjoy != newjoy) { |
533 |
+ |
joy_minx[port] = joy_miny[port] = 32767; // Reset calibration |
534 |
+ |
joy_maxx[port] = joy_maxy[port] = -32768; |
535 |
+ |
if (newjoy) { |
536 |
+ |
joy[port] = SDL_JoystickOpen(newjoy - 1); |
537 |
+ |
if (joy[port] == NULL) |
538 |
+ |
fprintf(stderr, "Couldn't open joystick %d\n", port + 1); |
539 |
+ |
} else { |
540 |
+ |
if (joy[port]) { |
541 |
+ |
SDL_JoystickClose(joy[port]); |
542 |
+ |
joy[port] = NULL; |
543 |
+ |
} |
544 |
+ |
} |
545 |
+ |
} |
546 |
+ |
} |
547 |
+ |
|
548 |
+ |
void C64::open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2) |
549 |
+ |
{ |
550 |
+ |
open_close_joystick(0, oldjoy1, newjoy1); |
551 |
+ |
open_close_joystick(1, oldjoy2, newjoy2); |
552 |
+ |
} |
553 |
+ |
|
554 |
+ |
|
555 |
+ |
/* |
556 |
+ |
* Poll joystick port, return CIA mask |
557 |
+ |
*/ |
558 |
+ |
|
559 |
+ |
uint8 C64::poll_joystick(int port) |
560 |
+ |
{ |
561 |
+ |
uint8 j = 0xff; |
562 |
+ |
|
563 |
+ |
if (port == 0 && (joy[0] || joy[1])) |
564 |
+ |
SDL_JoystickUpdate(); |
565 |
+ |
|
566 |
+ |
if (joy[port]) { |
567 |
+ |
int x = SDL_JoystickGetAxis(joy[port], 0), y = SDL_JoystickGetAxis(joy[port], 1); |
568 |
+ |
|
569 |
+ |
if (x > joy_maxx[port]) |
570 |
+ |
joy_maxx[port] = x; |
571 |
+ |
if (x < joy_minx[port]) |
572 |
+ |
joy_minx[port] = x; |
573 |
+ |
if (y > joy_maxy[port]) |
574 |
+ |
joy_maxy[port] = y; |
575 |
+ |
if (y < joy_miny[port]) |
576 |
+ |
joy_miny[port] = y; |
577 |
+ |
|
578 |
+ |
if (joy_maxx[port] - joy_minx[port] < 100 || joy_maxy[port] - joy_miny[port] < 100) |
579 |
+ |
return 0xff; |
580 |
+ |
|
581 |
+ |
if (x < (joy_minx[port] + (joy_maxx[port]-joy_minx[port])/3)) |
582 |
+ |
j &= 0xfb; // Left |
583 |
+ |
else if (x > (joy_minx[port] + 2*(joy_maxx[port]-joy_minx[port])/3)) |
584 |
+ |
j &= 0xf7; // Right |
585 |
+ |
|
586 |
+ |
if (y < (joy_miny[port] + (joy_maxy[port]-joy_miny[port])/3)) |
587 |
+ |
j &= 0xfe; // Up |
588 |
+ |
else if (y > (joy_miny[port] + 2*(joy_maxy[port]-joy_miny[port])/3)) |
589 |
+ |
j &= 0xfd; // Down |
590 |
+ |
|
591 |
+ |
if (SDL_JoystickGetButton(joy[port], 0)) |
592 |
+ |
j &= 0xef; // Button |
593 |
+ |
} |
594 |
+ |
|
595 |
+ |
return j; |
596 |
+ |
} |
597 |
+ |
|
598 |
+ |
|
599 |
+ |
/* |
600 |
|
* Allocate C64 colors |
601 |
|
*/ |
602 |
|
|
626 |
|
* Show a requester (error message) |
627 |
|
*/ |
628 |
|
|
629 |
< |
long int ShowRequester(char *a,char *b,char *) |
629 |
> |
long int ShowRequester(const char *a, const char *b, const char *) |
630 |
|
{ |
631 |
|
printf("%s: %s\n", a, b); |
632 |
|
return 1; |