//* pad.c - Joypad controller interface routines //* System library headers #include //* Application headers #include "pad.h" #include "screens.h" //* Status buffer pointers for pads 1 and 2 static volatile u_char *bb0, *bb1; //*------------------------------------------------------------------------------------------ //* PadInit - Get pad buffers (initialize pointers to the 2 buffers) //*------------------------------------------------------------------------------------- void PadInit (void) { GetPadBuf(&bb0, &bb1); } //*------------------------------------------------------------------------------------------ //* ReadPadStat - Read and return status of controller in port 1 only //*------------------------------------------------------------------------------------- u_long ReadPadStat(void) { register int ct, lx, ly; register u_long result; //* Test for no controller or an unsupported controller in port 1 if (*bb0 || ((ct=*(bb0+1)>>4)!=CONTROLLER_ANALOG && ct!=CONTROLLER_DIGITAL)) { //* Turn sound off (in case loops are playing) SsSetMute(SS_MUTE_ON); //* Overlay controller error screen once ControlErrorScreen(); //* Pause while no controller or an unsupported controller is detected in port 1 while (*bb0 || ((ct=*(bb0+1)>>4)!=CONTROLLER_ANALOG && ct!=CONTROLLER_DIGITAL)) VSync(0); //* Turn sound back on SsSetMute(SS_MUTE_OFF); } //* Get common controller button status from port 1 only //* Note: complement result (~) so 1=pressed & 0=released result = ~(*(bb0+3) | *(bb0+2)<<8); if (ct == CONTROLLER_ANALOG) { //* Analog controller being used... lx = *(bb0+6); //* Get left stick horizontal value ly = *(bb0+7); //* Get left stick vertical value if (lx <= ANALOG_LOW_TRIGGER) { result |= PAD1_LEFT; //* Simulate LEFT d-pad button press } else if (lx >= ANALOG_HIGH_TRIGGER) { result |= PAD1_RIGHT; //* Simulate RIGHT d-pad button press } if (ly <= ANALOG_LOW_TRIGGER) { result |= PAD1_UP; //* Simulate UP d-pad button press } else if (ly >= ANALOG_HIGH_TRIGGER) { result |= PAD1_DOWN; //* Simulate DOWN d-pad button press } } return result; }