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.3 by cebix, 2003-07-14T13:59:02Z vs.
Revision 1.4 by cebix, 2004-01-10T15:07:14Z

# 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          }
# 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