home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / gbe / joypad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-12  |  2.9 KB  |  116 lines

  1. /*
  2.  *  gbe - gameboy emulator
  3.  *  Copyright (C) 1999  Chuck Mason, Steven Fuller
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18.  *
  19.  *
  20.  *  Chuck Mason <chuckjr@sinclair.net>
  21.  *  Steven Fuller <relnev@atdot.org>
  22.  */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. #include "joypad.h"
  27. #include "cpu.h"
  28. #include "jlib.h"
  29.  
  30. /* its gotta go somewhere */
  31.  
  32. unsigned char current_joypad = 0x00;
  33.      /* Joypad goes as follows:    why? because testing proves so! (look at mem.c -> $ff00) 
  34.           START.SELECT.B.A.DOWN.UP.LEFT.RIGHT
  35.      */
  36.      
  37.  
  38. void handler_keypress(void *, void *);
  39. void handler_keyrelease(void *, void *);
  40.  
  41. void joypad_init()
  42. {
  43.      if(use_joystick < 4) {
  44.           if(jlib_open(use_joystick) == 0) {
  45.                printf("Unable to open joystick, using keyboard instead.\n");
  46.                use_joystick = 5;
  47.           }
  48.           
  49.      }
  50. }
  51.  
  52. void joypad_update()
  53. {
  54.      if(use_joystick != 5) {
  55.           jlib_update(use_joystick);
  56.           joystick_read();
  57.      }  
  58. }
  59.  
  60. void joystick_read()
  61. {
  62.      if(jlib_check(use_joystick, JOYSTICK_UP))
  63.           current_joypad |= 0x04;
  64.      else
  65.           current_joypad &= ~0x04;
  66.      
  67.      if(jlib_check(use_joystick, JOYSTICK_DOWN))
  68.           current_joypad |= 0x08;
  69.      else
  70.           current_joypad &= ~0x08;
  71.      
  72.      if(jlib_check(use_joystick, JOYSTICK_LEFT))
  73.           current_joypad |= 0x02;
  74.      else
  75.           current_joypad &= ~0x02;
  76.      
  77.      if(jlib_check(use_joystick, JOYSTICK_RIGHT))
  78.           current_joypad |= 0x01;
  79.      else
  80.           current_joypad &= ~0x01;
  81.      
  82.      if(jlib_check(use_joystick, JOYSTICK_BUTTON(0)))
  83.           current_joypad |= 0x10;
  84.      else
  85.           current_joypad &= ~0x10;
  86.      
  87.      if(jlib_check(use_joystick, JOYSTICK_BUTTON(2)))
  88.           current_joypad |= 0x20;
  89.      else
  90.           current_joypad &= ~0x20;
  91.      
  92.      if(jlib_check(use_joystick, JOYSTICK_BUTTON(5)))
  93.           current_joypad |= 0x80;
  94.      else
  95.           current_joypad &= ~0x80;
  96.  
  97.      if(jlib_check(use_joystick, JOYSTICK_BUTTON(4)))
  98.           current_joypad |= 0x40;
  99.      else
  100.           current_joypad &= ~0x40;
  101. }
  102.  
  103. void joypad_press(int code)
  104. {
  105.      if(code == GBE_O_ESCAPE)
  106.           gameboy_proc->running = 0;
  107.      else
  108.           current_joypad |= code;
  109. }
  110.  
  111. void joypad_release(int code)
  112. {
  113.      if(code <= 0xFF)
  114.           current_joypad &= ~code;
  115. }
  116.