ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Display_SDL.h
(Generate patch)

Comparing Frodo4/Src/Display_SDL.h (file contents):
Revision 1.1 by cebix, 2003-07-01T17:32:13Z vs.
Revision 1.7 by cebix, 2005-06-27T19:55:48Z

# Line 2 | Line 2
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 (C) 1994-1997,2002-2005 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
# Line 37 | Line 37 | static C64Display *c64_disp;
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,
# Line 73 | Line 76 | enum {
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  
# Line 95 | Line 94 | C64Display::C64Display(C64 *the_c64) : T
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;
# Line 102 | Line 105 | C64Display::C64Display(C64 *the_c64) : T
105          // Start timer for LED error blinking
106          c64_disp = this;
107          pulse_sa.sa_handler = (void (*)(int))pulse_handler;
108 <        pulse_sa.sa_flags = 0;
108 >        pulse_sa.sa_flags = SA_RESTART;
109          sigemptyset(&pulse_sa.sa_mask);
110          sigaction(SIGALRM, &pulse_sa, NULL);
111          pulse_tv.it_interval.tv_sec = 0;
# Line 491 | Line 494 | bool C64Display::NumLock(void)
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   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines