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 (C) 1994-1997,2002-2004 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) < 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 |
|
// LEDs off |
102 |
|
for (int i=0; i<4; i++) |
103 |
|
led_state[i] = old_led_state[i] = LED_OFF; |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
+ |
/* |
498 |
+ |
* Open/close joystick drivers given old and new state of |
499 |
+ |
* joystick preferences |
500 |
+ |
*/ |
501 |
+ |
|
502 |
+ |
void C64::open_close_joystick(int port, int oldjoy, int newjoy) |
503 |
+ |
{ |
504 |
+ |
if (oldjoy != newjoy) { |
505 |
+ |
joy_minx[port] = joy_miny[port] = 32767; // Reset calibration |
506 |
+ |
joy_maxx[port] = joy_maxy[port] = -32768; |
507 |
+ |
if (newjoy) { |
508 |
+ |
joy[port] = SDL_JoystickOpen(newjoy - 1); |
509 |
+ |
if (joy[port] == NULL) |
510 |
+ |
fprintf(stderr, "Couldn't open joystick %d\n", port + 1); |
511 |
+ |
} else { |
512 |
+ |
if (joy[port]) { |
513 |
+ |
SDL_JoystickClose(joy[port]); |
514 |
+ |
joy[port] = NULL; |
515 |
+ |
} |
516 |
+ |
} |
517 |
+ |
} |
518 |
+ |
} |
519 |
+ |
|
520 |
+ |
void C64::open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2) |
521 |
+ |
{ |
522 |
+ |
open_close_joystick(0, oldjoy1, newjoy1); |
523 |
+ |
open_close_joystick(1, oldjoy2, newjoy2); |
524 |
+ |
} |
525 |
+ |
|
526 |
+ |
|
527 |
+ |
/* |
528 |
+ |
* Poll joystick port, return CIA mask |
529 |
+ |
*/ |
530 |
+ |
|
531 |
+ |
uint8 C64::poll_joystick(int port) |
532 |
+ |
{ |
533 |
+ |
uint8 j = 0xff; |
534 |
+ |
|
535 |
+ |
if (port == 0 && (joy[0] || joy[1])) |
536 |
+ |
SDL_JoystickUpdate(); |
537 |
+ |
|
538 |
+ |
if (joy[port]) { |
539 |
+ |
int x = SDL_JoystickGetAxis(joy[port], 0), y = SDL_JoystickGetAxis(joy[port], 1); |
540 |
+ |
|
541 |
+ |
if (x > joy_maxx[port]) |
542 |
+ |
joy_maxx[port] = x; |
543 |
+ |
if (x < joy_minx[port]) |
544 |
+ |
joy_minx[port] = x; |
545 |
+ |
if (y > joy_maxy[port]) |
546 |
+ |
joy_maxy[port] = y; |
547 |
+ |
if (y < joy_miny[port]) |
548 |
+ |
joy_miny[port] = y; |
549 |
+ |
|
550 |
+ |
if (joy_maxx[port] - joy_minx[port] < 100 || joy_maxy[port] - joy_miny[port] < 100) |
551 |
+ |
return 0xff; |
552 |
+ |
|
553 |
+ |
if (x < (joy_minx[port] + (joy_maxx[port]-joy_minx[port])/3)) |
554 |
+ |
j &= 0xfb; // Left |
555 |
+ |
else if (x > (joy_minx[port] + 2*(joy_maxx[port]-joy_minx[port])/3)) |
556 |
+ |
j &= 0xf7; // Right |
557 |
+ |
|
558 |
+ |
if (y < (joy_miny[port] + (joy_maxy[port]-joy_miny[port])/3)) |
559 |
+ |
j &= 0xfe; // Up |
560 |
+ |
else if (y > (joy_miny[port] + 2*(joy_maxy[port]-joy_miny[port])/3)) |
561 |
+ |
j &= 0xfd; // Down |
562 |
+ |
|
563 |
+ |
if (SDL_JoystickGetButton(joy[port], 0)) |
564 |
+ |
j &= 0xef; // Button |
565 |
+ |
} |
566 |
+ |
|
567 |
+ |
return j; |
568 |
+ |
} |
569 |
+ |
|
570 |
+ |
|
571 |
|
/* |
572 |
|
* Allocate C64 colors |
573 |
|
*/ |