home *** CD-ROM | disk | FTP | other *** search
- /*
- * gbe - gameboy emulator
- * Copyright (C) 1999 Chuck Mason, Steven Fuller
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *
- * Chuck Mason <chuckjr@sinclair.net>
- * Steven Fuller <relnev@atdot.org>
- */
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "joypad.h"
- #include "cpu.h"
- #include "jlib.h"
-
- /* its gotta go somewhere */
-
- unsigned char current_joypad = 0x00;
- /* Joypad goes as follows: why? because testing proves so! (look at mem.c -> $ff00)
- START.SELECT.B.A.DOWN.UP.LEFT.RIGHT
- */
-
-
- void handler_keypress(void *, void *);
- void handler_keyrelease(void *, void *);
-
- void joypad_init()
- {
- if(use_joystick < 4) {
- if(jlib_open(use_joystick) == 0) {
- printf("Unable to open joystick, using keyboard instead.\n");
- use_joystick = 5;
- }
-
- }
- }
-
- void joypad_update()
- {
- if(use_joystick != 5) {
- jlib_update(use_joystick);
- joystick_read();
- }
- }
-
- void joystick_read()
- {
- if(jlib_check(use_joystick, JOYSTICK_UP))
- current_joypad |= 0x04;
- else
- current_joypad &= ~0x04;
-
- if(jlib_check(use_joystick, JOYSTICK_DOWN))
- current_joypad |= 0x08;
- else
- current_joypad &= ~0x08;
-
- if(jlib_check(use_joystick, JOYSTICK_LEFT))
- current_joypad |= 0x02;
- else
- current_joypad &= ~0x02;
-
- if(jlib_check(use_joystick, JOYSTICK_RIGHT))
- current_joypad |= 0x01;
- else
- current_joypad &= ~0x01;
-
- if(jlib_check(use_joystick, JOYSTICK_BUTTON(0)))
- current_joypad |= 0x10;
- else
- current_joypad &= ~0x10;
-
- if(jlib_check(use_joystick, JOYSTICK_BUTTON(2)))
- current_joypad |= 0x20;
- else
- current_joypad &= ~0x20;
-
- if(jlib_check(use_joystick, JOYSTICK_BUTTON(5)))
- current_joypad |= 0x80;
- else
- current_joypad &= ~0x80;
-
- if(jlib_check(use_joystick, JOYSTICK_BUTTON(4)))
- current_joypad |= 0x40;
- else
- current_joypad &= ~0x40;
- }
-
- void joypad_press(int code)
- {
- if(code == GBE_O_ESCAPE)
- gameboy_proc->running = 0;
- else
- current_joypad |= code;
- }
-
- void joypad_release(int code)
- {
- if(code <= 0xFF)
- current_joypad &= ~code;
- }
-