#ifndef __JOYPAD_H
#define __JOYPAD_H


#include "types.h"
#include "hw.h"

/* Joypad Definitions */
#define	K_ANY	0xFFFC		// All switches, ignore pwr & sgn
#define	K_BTNS	0x303C		// All buttons; no d-pads, pwr or sgn
#define	K_PADS	0xCFC0		// All d-pads
#define	K_LPAD	0x0F00		// Left d-pad only
#define	K_RPAD	0xC0C0		// Right d-pad only
#define	K_PWR	0x0001		// Battery status
#define	K_SGN	0x0002		// Signature; 1 = Standard Pad
#define	K_A	0x0004		// A Button
#define	K_B	0x0008		// B Button
#define	K_RT	0x0010		// R Trigger
#define	K_LT	0x0020		// L Trigger
#define	K_RU	0x0040		// Right Pad, Up
#define	K_RR	0x0080		// Right Pad, Right
#define	K_LR	0x0100		// Left Pad,  Right
#define	K_LL	0x0200		// Left Pad,  Left
#define	K_LD	0x0400		// Left Pad,  Down
#define	K_LU	0x0800		// Left Pad,  Up
#define	K_STA	0x1000		// Start Button
#define	K_SEL	0x2000		// Select Button
#define	K_RL	0x4000		// Right Pad, Left
#define	K_RD	0x8000		// Right Pad, Down

/* Reads the joypad, returns the 16 button bits */
u16 vbReadPad()
{
	HW_REGS[SCR] = 0x84;
	while(HW_REGS[SCR] & 2);
	return (HW_REGS[SDHR] << 8) | HW_REGS[SDLR];
}


#endif
