#ifndef __COMMON_H
#define __COMMON_H

#define SCREEN_WD 320
#define SCREEN_HT 240
#define SCREEN_HT_FPAL (240+48) /* $B$3$N%5%$%:$G%U%l!<%`%P%C%U%!$r3NJ](B */

#define SCREEN_BPP 16

/* 3D stick threshold (absolute values) */
#define STICK_MIN 12
#define STICK_MAX 70

/*
 *		$B%9%?%C%/$J$I$NBg$-$5(B in bytes
 */
#define	BOOT_STACKSIZE		0x0200
#define	IDLE_STACKSIZE		0x0200
#define	MAIN_STACKSIZE		0x1000
#define	TMAN_STACKSIZE		0x0800
#define	AUDIO_STACKSIZE		0x1000

/* $B%9%l%C%I(B ID, pri */
#define TID_IDLE  1
#define TID_MAIN  2
#define TID_TMAN  3
#define TID_AUDIO 4
/* #define TID_DD    5 */
/* #define TID_GBPAK 5 */
/* #define TID_GBEMU 6 */

#define PRI_IDLE   10
#define PRI_MAIN   20
#define PRI_TMAN  100
#define PRI_AUDIO  50
/* #define PRI_DD     40 */
/* #define PRI_GBPAK  80 */
/* #define PRI_GBEMU  30 */

/*
 * 		$B%a%C%;!<%8%-%e!<$NBg$-$5(B
 */
#define	PI_MSGS_MAX 64
#define DMA_MSGS_MAX 1
#define PAD_MSGS_MAX 1
#define MAIN_TIMING_MSGS_MAX 1
#define AUDIO_TIMING_MSGS_MAX 1
/* #define GBPAK_MSGS_MAX MAXCONTROLLERS */
#define TASKMAN_MSGS_MAX 16
#define DMA_IO_MSGS_MAX 1

/* $B%a%C%;!<%8(B */
#define MSG_PAD             (('P'<<24)|('a'<<16)|('d'<<8)|(' '))
#define MSG_MAIN_GO         (('M'<<24)|('a'<<16)|('i'<<8)|('n'))
#define MSG_AUDIO_GO        (('A'<<24)|('u'<<16)|('d'<<8)|('i'))
#define MSG_RSPDONE         (('R'<<24)|('S'<<16)|('P'<<8)|('d'))
#define MSG_RETRACE         (('R'<<24)|('e'<<16)|('t'<<8)|('r'))
#define MSG_RDPDONE         (('R'<<24)|('D'<<16)|('P'<<8)|('d'))
#define MSG_PRENMI          (('p'<<24)|('N'<<16)|('M'<<8)|('I'))

/* RCP $B%?%9%/%(%s%H%j?t(B $B$H%?%9%/%M!<%`(B
 * MY_TASK_AUDIO $B$O(B $B@dBP(B 0 $BHVL\!#(B
 */
#define MY_TASK_MAX 10
#define MY_TASK_AUDIO 0
#define MY_TASK_RFC 1

/* Utilities */
#define BIT8(a,b,c,d,e,f,g,h) ((a<<7)|(b<<6)|(c<<5)|(d<<4)|(e<<3)|(f<<2)|(g<<1)|h)
#define ALIGN64B(x) (((u32)x+63)&0xffffffc0)
#define ALIGN16B(x) (((u32)x+15)&0xfffffff0)
#define ALIGN8B(x)   (((u32)x+7)&0xfffffff8)
#define ALIGN2B(x)   (((u32)x+1)&0xfffffffe)
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (1)
#endif
#ifndef CONT_Z
#define CONT_Z CONT_G
#endif
#define DBLBUF 2

/* ---------------------------------------------------------------- */
#ifdef _LANGUAGE_C
/* gbi.h, gu.h, sp.h($B%9%W%i%$%H(B) $B$OITMW!#(B */
#ifndef _GBI_H_
#define _GBI_H_
#endif
#ifndef _GU_H_
#define _GU_H_
#endif
#ifndef _SP_H_
#define _SP_H_
#endif
#include <ultra64.h>

/* $B%3%s%H%m!<%i(B $B%G!<%?(B */
typedef struct pad_object {
  u16 button, trig, padding_;
  s8 stick_x, stick_y;
} pad_object;

/* RSPTask $B$O(B POCKESTA/Kernel/Include/scheduler.h $B$N$b$N$r;H$&!#(B
 * audio library $B$G$O(B RSPTask $B$r;H$C$F$$$J$$$N$GF1L>9=B$BN$G$b(B
 * $B>WFM$r2sHr$G$-$F$$$k!#(B
 */
typedef struct RSPTask {
	OSMesg			mesgbuf[1];		/* message buffer for RCP done message		*/
	OSMesgQueue		mesgque;		/* message queue for RCP done message		*/
	u16			rspstat;		/* RSP task status							*/
	u16			rdpstat;		/* RDP task status							*/
	OSTask			ostask;			/* OS task record							*/
	struct RSPTask *next;			/* pointer to the next task					*/
} RSPTask;

typedef struct task_request_object {
#define MY_TASK_STATUS_DONE 0
#define MY_TASK_STATUS_REQUESTED 1
#define MY_TASK_STATUS_ALWAYS 2
/* #define MY_TASK_STATUS_YIELDED 3 */
  vu32 status; /* MY_TASK_STATUS_** */
  OSTask *taskp;
  vu32 rspdone; /* SP $B=hM}Cf$O(B $B=hM}3+;O;~$N(B osGetCount $BCM(B, $B=*$o$C$?$i(B osGetCount $B$N:9$,F~$k(B ($BK|$,0l(B 0 $B$K$J$k$+$b$7$l$J$$!#(Bstatus $B$,(B 0 $B$J$i(B rspdone $B$,Mh$F$$$k!#(B) */
  vu32 rdpdone; /* d0 $B$,(B 1 $B$J$i(B rdp $B=hM}Cf(B done $B$OMh$F$$$J$$!#(B*/
} task_request_object;

/* $B%7!<%1%s%94X?t(B */
typedef void *(*sq)(int i, void *);

#ifndef ulong
#define ulong u32
#endif
#ifndef ushort
#define ushort u16
#endif
#ifndef uchar
#define uchar u8
#endif
#include "extern.h"

#endif	/* _LANGUAGE_C */
/* ---------------------------------------------------------------- */
#endif /* __COMMON_H */
#ifndef PUBLIC
#define PUBLIC
#endif
#ifndef STATIC
#define STATIC static
#endif
