/*
 * $Id: controller.h,v 1.1 2003/02/07 18:15:44 wheeler Exp $
 *
 * コントローラの処理
 *
 * $Log: controller.h,v $
 * Revision 1.1  2003/02/07 18:15:44  wheeler
 * Fox's version of libultra and friends.
 *
 * Revision 1.8  1996/12/02  05:34:48  hayakawa
 * pad_tの２重定義対策
 *
 * Revision 1.7  1996/10/20  09:09:52  hayakawa
 * _LANGUAGE_C_PLUS_PLUS を __cplusplus に変更
 *
 * Revision 1.6  1996/10/14  02:15:01  hayakawa
 * ヘッダ修正
 *
 *
 */

#ifndef __CONTROLLER_H_
#define __CONTROLLER_H_

#include "ultra64.h"

#define CONT_ABCDEF		(CONT_A|CONT_B|CONT_C|CONT_D|CONT_E|CONT_F)
#define CONT_LR			(CONT_L|CONT_R)
#define CONT_CROSS		(CONT_UP|CONT_DOWN|CONT_LEFT|CONT_RIGHT)
#define CONT_ABCDEFGLRS		(CONT_ABCDEF|CONT_G|CONT_LR|CONT_START)
#define CONT_ABCDEFGLRSX	(CONT_ABCDEFGLRS|CONT_CROSS)

#ifndef __PAD_T_
#define __PAD_T_
typedef struct pad_s {
    OSContPad	now;
    OSContPad	before;
    OSContPad	on;
    OSContPad	off;
} pad_t;
#endif /* __PAD_T_ */

typedef struct global_s {
    int		pad_enable;
    int		pad_count;
    u8		pad_pattern;
    OSContStatus pad_status[MAXCONTROLLERS];
    pad_t 	pad[MAXCONTROLLERS];
} global_t;

extern global_t global;
extern int default_pad_no;
extern int debug_pad_no;

/*
 * マクロ版コントローラチェック
 * 機能は、関数版と同じ
 */
#define ControllerCheck( pad1, now1, on1, mask1 )	\
(						\
    ((mask1) == 0) ? (				\
	(((on1) == 0 || (((pad1)->on.button & (on1)) == (on1))) && \
	 ((now1) == 0 || (((pad1)->now.button & (now1)) == (now1)))) \
    ) : (					\
	(((on1) == 0 || (((pad1)->on.button & (mask1)) == (on1))) && \
	 ((now1) == 0 || (((pad1)->now.button & (mask1)) == ((now1)|(on1))))) \
    )						\
)

#ifdef __cplusplus
extern "C" {
#endif

void InitController(void);
void ReadController(void);

int controllerCheck(
    pad_t *pad,			/* 現在のパッドステータス */
    u16 now,			/* 〜を押しながら */
    u16 on,			/* 〜を押す */
    u16 mask			/* マスクビット */
);
void ReadController_thread(void);
void InitController_thread( void );

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif
