diff --git a/config/GMPE01_00/symbols.txt b/config/GMPE01_00/symbols.txt index 243a1ba0..8886b70d 100644 --- a/config/GMPE01_00/symbols.txt +++ b/config/GMPE01_00/symbols.txt @@ -49,8 +49,8 @@ HuSysVWaitGet = .text:0x80005A24; // type:function size:0xC rand8 = .text:0x80005A30; // type:function size:0x2C HuPadInit = .text:0x80005A5C; // type:function size:0xF0 HuPadRead = .text:0x80005B4C; // type:function size:0x168 -PadReadVSync = .text:0x80005CB4; // type:function size:0x440 -PadADConv = .text:0x800060F4; // type:function size:0x234 +PadReadVSync = .text:0x80005CB4; // type:function size:0x440 scope:local +PadADConv = .text:0x800060F4; // type:function size:0x234 scope:local HuPadRumbleSet = .text:0x80006328; // type:function size:0x54 HuPadRumbleStop = .text:0x8000637C; // type:function size:0x70 HuPadRumbleAllStop = .text:0x800063EC; // type:function size:0x70 @@ -4687,7 +4687,7 @@ lbl_8011EBB8 = .rodata:0x8011EBB8; // type:object size:0x88 lbl_8011EC40 = .rodata:0x8011EC40; // type:object size:0x88 data:byte lbl_8011ECC8 = .rodata:0x8011ECC8; // type:object size:0x100 lbl_8011EDE0 = .data:0x8011EDE0; // type:object size:0x10 data:string -chanTbl = .data:0x8011EDF0; // type:object size:0x10 +chanTbl = .data:0x8011EDF0; // type:object size:0x10 scope:local correctDiskID = .data:0x8011EE00; // type:object size:0x124 scope:local jumptable_8011EF24 = .data:0x8011EF24; // type:object size:0x34 scope:local lbl_8011EF58 = .data:0x8011EF58; // type:object size:0x11 data:string @@ -5384,8 +5384,8 @@ lbl_801405E0 = .data:0x801405E0; // type:object size:0x19E0 lbl_80141FC0 = .data:0x80141FC0; // type:object size:0x10 lbl_80141FD0 = .data:0x80141FD0; // type:object size:0x20 lbl_80141FF0 = .data:0x80141FF0; // type:object size:0x800 -padStatErrOld = .bss:0x80142800; // type:object size:0x10 -rumbleData = .bss:0x80142810; // type:object size:0x30 +padStatErrOld = .bss:0x80142800; // type:object size:0x10 scope:local +rumbleData = .bss:0x80142810; // type:object size:0x20 scope:local ReadDataStat = .bss:0x80142840; // type:object size:0x2E00 scope:local align:32 data:4byte TextBuffer = .bss:0x80145640; // type:object size:0x400 rmodeobj = .bss:0x80145A40; // type:object size:0x40 scope:local @@ -5941,7 +5941,7 @@ lbl_801D39E8 = .sdata:0x801D39E8; // type:object size:0x8 lbl_801D39F0 = .sdata:0x801D39F0; // type:object size:0x8 data:2byte lbl_801D39F8 = .sdata:0x801D39F8; // type:object size:0x1 data:byte lbl_801D3A00 = .sbss:0x801D3A00; // type:object size:0x4 data:4byte -lbl_801D3A04 = .sbss:0x801D3A04; // type:object size:0x4 data:4byte +HuDvdErrWait = .sbss:0x801D3A04; // type:object size:0x4 data:4byte lbl_801D3A08 = .sbss:0x801D3A08; // type:object size:0x4 lbl_801D3A0C = .sbss:0x801D3A0C; // type:object size:0x4 lbl_801D3A10 = .sbss:0x801D3A10; // type:object size:0x4 @@ -5976,8 +5976,8 @@ _PadSubStkX = .sbss:0x801D3A80; // type:object size:0x4 scope:local _PadStkY = .sbss:0x801D3A84; // type:object size:0x4 scope:local _PadStkX = .sbss:0x801D3A88; // type:object size:0x4 scope:local _PadRepCnt = .sbss:0x801D3A8C; // type:object size:0x8 scope:local -_PadBtnDown = .sbss:0x801D3A94; // type:object size:0x8 scope:local -_PadBtn = .sbss:0x801D3A9C; // type:object size:0x8 scope:local +_PadBtnDown = .sbss:0x801D3A94; // type:object size:0x8 +_PadBtn = .sbss:0x801D3A9C; // type:object size:0x8 HuPadErr = .sbss:0x801D3AA4; // type:object size:0x4 HuPadDStkRep = .sbss:0x801D3AA8; // type:object size:0x4 HuPadDStk = .sbss:0x801D3AAC; // type:object size:0x4 @@ -6143,8 +6143,8 @@ Snd3DSpeedOffset = .sbss:0x801D3D24; // type:object size:0x4 data:float Snd3DStartDisOffset = .sbss:0x801D3D28; // type:object size:0x4 data:float Snd3DFrontSurDisOffset = .sbss:0x801D3D2C; // type:object size:0x4 data:float Snd3DBackSurDisOffset = .sbss:0x801D3D30; // type:object size:0x4 data:float -HuAuxBVol = .sbss:0x801D3D34; // type:object size:0x1 data:byte scope:local -HuAuxAVol = .sbss:0x801D3D35; // type:object size:0x1 data:byte scope:local +HuAuxBVol = .sbss:0x801D3D34; // type:object size:0x1 scope:local data:byte +HuAuxAVol = .sbss:0x801D3D35; // type:object size:0x1 scope:local data:byte auxBNoBak = .sbss:0x801D3D38; // type:object size:0x4 scope:local data:4byte auxANoBak = .sbss:0x801D3D3C; // type:object size:0x4 scope:local data:4byte sndGroupBak = .sbss:0x801D3D40; // type:object size:0x2 scope:local data:2byte @@ -6261,7 +6261,7 @@ lbl_801D3F04 = .sbss:0x801D3F04; // type:object size:0x4 data:4byte lbl_801D3F08 = .sbss:0x801D3F08; // type:object size:0x4 data:4byte lbl_801D3F0C = .sbss:0x801D3F0C; // type:object size:0x4 data:4byte lbl_801D3F10 = .sbss:0x801D3F10; // type:object size:0x4 data:4byte -boardRandSeed = .sbss:0x801D3F14; // type:object size:0x4 scope:local data:4byte +boardRandSeed = .sbss:0x801D3F14; // type:object size:0x4 data:4byte lbl_801D3F18 = .sbss:0x801D3F18; // type:object size:0x8 data:4byte lbl_801D3F20 = .sbss:0x801D3F20; // type:object size:0x4 data:4byte lbl_801D3F24 = .sbss:0x801D3F24; // type:object size:0x4 data:4byte diff --git a/configure.py b/configure.py index 78b8f9bc..dc27b4f1 100644 --- a/configure.py +++ b/configure.py @@ -232,7 +232,7 @@ config.libs = [ "host": False, "objects": [ Object(NonMatching, "game/main.c"), - Object(NonMatching, "game/pad.c"), + Object(Matching, "game/pad.c"), Object(Matching, "game/dvd.c"), Object(NonMatching, "game/data.c"), Object(Matching, "game/decode.c"), diff --git a/include/functions.h b/include/functions.h index 49770b6a..ba2d1180 100644 --- a/include/functions.h +++ b/include/functions.h @@ -38,8 +38,6 @@ void HuWinMesSpeedSet(s16, s16); void HuWinMesMaxSizeGet(s16, f32*, ...); s16 HuWinCreate(float x, float y, s16 w, s16 h, s16 frame); -void HuPadRumbleAllStop(void); - void HuAudFXListnerKill(void); void HuAudDllSndGrpSet(u16 ovl); void HuAudVoiceInit(s16 ovl); diff --git a/include/game/msm.h b/include/game/msm.h index f08be89a..826c4f80 100644 --- a/include/game/msm.h +++ b/include/game/msm.h @@ -35,6 +35,7 @@ typedef struct { /* 0x0C */ float backSurDis; } UnkMsmStruct_02; // Size (min: 0x10, max: 0x1C) +void msmSysRegularProc(void); void msmSysSetOutputMode(s32 arg0); void msmSysSetAux(s32 arg0, s32 arg1); s32 msmSysGetSampSize(s32 arg0); diff --git a/include/game/pad.h b/include/game/pad.h new file mode 100644 index 00000000..a771d2c2 --- /dev/null +++ b/include/game/pad.h @@ -0,0 +1,35 @@ +#ifndef _GAME_PAD_H +#define _GAME_PAD_H + +#include "dolphin.h" + +#define PAD_BUTTON_DIR (PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_UP | PAD_BUTTON_DOWN) + +#define PAD_BUTTON_TRIGGER_L 0x4000 +#define PAD_BUTTON_TRIGGER_R 0x2000 + +extern u16 HuPadBtn[4]; +extern u16 HuPadBtnDown[4]; +extern u16 HuPadBtnRep[4]; +extern s8 HuPadStkX[4]; +extern s8 HuPadStkY[4]; +extern s8 HuPadSubStkX[4]; +extern s8 HuPadSubStkY[4]; +extern u8 HuPadTrigL[4]; +extern u8 HuPadTrigR[4]; +extern u8 HuPadDStk[4]; +extern u8 HuPadDStkRep[4]; +extern s8 HuPadErr[4]; +extern u16 _PadBtn[4]; +extern u16 _PadBtnDown[4]; +extern u32 VCounter; + +void HuPadInit(void); +void HuPadRead(void); +void HuPadRumbleSet(s16 pad, s16 duration, s16 off, s16 on); +void HuPadRumbleStop(s16 pad); +void HuPadRumbleAllStop(void); +s16 HuPadStatGet(s16 pad); +u32 HuPadRumbleGet(void); + +#endif \ No newline at end of file diff --git a/include/variables.h b/include/variables.h index 9dbeef8b..4bd9c0ca 100644 --- a/include/variables.h +++ b/include/variables.h @@ -4,9 +4,6 @@ #include "dolphin.h" #include "common_structs.h" -extern u16 HuPadBtnDown[4]; -extern u8 HuPadDStk[4]; - extern WipeState wipeData; extern PlayerConfig GWPlayerCfg[4]; diff --git a/src/REL/subchrselDll/subchrselDll.c b/src/REL/subchrselDll/subchrselDll.c index aa5c4c37..e945bf6f 100644 --- a/src/REL/subchrselDll/subchrselDll.c +++ b/src/REL/subchrselDll/subchrselDll.c @@ -1,7 +1,7 @@ #include "common.h" #include "game/object.h" #include "game/printfunc.h" -#include "dolphin/pad.h" +#include "game/pad.h" #include "math.h" diff --git a/src/REL/w10Dll/w10Dll4.c b/src/REL/w10Dll/w10Dll4.c index bcd62892..180ca388 100644 --- a/src/REL/w10Dll/w10Dll4.c +++ b/src/REL/w10Dll/w10Dll4.c @@ -1,8 +1,7 @@ #include "REL/w10Dll.h" +#include "game/pad.h" #include "game/data.h" -s16 HuPadStatGet(s16 i); //TODO: Move to some other header file since gamework.c relies on an implicit declaration of it - char lbl_1_data_98[] = "@@@@@@@@@@@@@@ Tutorial Exit @@@@@@@@@@@@@@\n\000"; w10DllUnk03 lbl_1_data_C6[11] = { @@ -145,7 +144,7 @@ void fn_1_1984(void) { if (contPortIndex == -1) { continue; } - if (HuPadStatGet(contPortIndex) == 0 && HuPadBtnDown[contPortIndex] & 0x1000) { + if (HuPadStatGet(contPortIndex) == 0 && HuPadBtnDown[contPortIndex] & PAD_BUTTON_START) { break; } } diff --git a/src/game/objmain.c b/src/game/objmain.c index ab6f414d..6935918b 100644 --- a/src/game/objmain.c +++ b/src/game/objmain.c @@ -1,6 +1,7 @@ #include "common.h" #include "game/printfunc.h" #include "game/object.h" +#include "game/pad.h" #define OM_OVL_HIS_MAX 16 #define OM_MAX_GROUPS 10 diff --git a/src/game/pad.c b/src/game/pad.c new file mode 100644 index 00000000..38b3e0c1 --- /dev/null +++ b/src/game/pad.c @@ -0,0 +1,258 @@ +#include "common.h" +#include "dolphin.h" +#include "game/msm.h" +#include "game/pad.h" + + +typedef struct pad_rumble { + s16 duration; + s16 off; + s16 on; + s16 time; +} PadRumble; + +static void PadReadVSync(u32 retraceCount); +static void PadADConv(s16 pad, PADStatus *status); + +static int padStatErrOld[4]; +static PadRumble rumbleData[4]; + +u16 HuPadBtn[4]; +u16 HuPadBtnDown[4]; +u16 HuPadBtnRep[4]; +s8 HuPadStkX[4]; +s8 HuPadStkY[4]; +s8 HuPadSubStkX[4]; +s8 HuPadSubStkY[4]; +u8 HuPadTrigL[4]; +u8 HuPadTrigR[4]; +u8 HuPadDStk[4]; +u8 HuPadDStkRep[4]; +s8 HuPadErr[4]; +u16 _PadBtn[4]; +u16 _PadBtnDown[4]; +static u16 _PadRepCnt[4]; +static s8 _PadStkX[4]; +static s8 _PadStkY[4]; +static s8 _PadSubStkX[4]; +static s8 _PadSubStkY[4]; +static u8 _PadTrigL[4]; +static u8 _PadTrigR[4]; +static u8 _PadDStk[4]; +static u8 _PadDStkRep[4]; +static u8 _PadDStkRepCnt[4]; +static u8 _PadDStkRepOld[4]; +static s8 _PadErr[4]; +static u32 RumbleBit; +u32 VCounter; + +static u32 chanTbl[4] = { PAD_CHAN0_BIT, PAD_CHAN1_BIT, PAD_CHAN2_BIT, PAD_CHAN3_BIT }; + +extern int HuDvdErrWait; + +void HuPadInit(void) +{ + int i; + BOOL int_level; + PADSetSpec(PAD_SPEC_5); + PADInit(); + SISetSamplingRate(0); + int_level = OSDisableInterrupts(); + VISetPostRetraceCallback(PadReadVSync); + OSRestoreInterrupts(int_level); + for(i=0; i<4; i++) { + padStatErrOld[i] = PAD_ERR_NOT_READY; + } + VIWaitForRetrace(); + VIWaitForRetrace(); + HuPadRead(); + for(i=0; i<4; i++) { + if(_PadErr[i] == PAD_ERR_NONE) { + PADControlMotor(i, PAD_MOTOR_STOP_HARD); + } + rumbleData[i].duration = 0; + _PadRepCnt[i] = 0; + } +} + +void HuPadRead(void) +{ + s16 i; + for(i=0; i<4; i++) { + HuPadBtn[i] = _PadBtn[i] & ~(PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_UP | PAD_BUTTON_DOWN); + HuPadBtnDown[i] = _PadBtnDown[i] & ~(PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT | PAD_BUTTON_UP | PAD_BUTTON_DOWN); + HuPadStkX[i] = _PadStkX[i]; + HuPadStkY[i] = _PadStkY[i]; + HuPadSubStkX[i] = _PadSubStkX[i]; + HuPadSubStkY[i] = _PadSubStkY[i]; + HuPadTrigL[i] = _PadTrigL[i]; + HuPadTrigR[i] = _PadTrigR[i]; + HuPadDStk[i] = _PadDStk[i]; + HuPadDStkRep[i] = _PadDStkRep[i]; + HuPadErr[i] = _PadErr[i]; + _PadBtnDown[i] = 0; + } +} + +static void PadReadVSync(u32 retraceCount) +{ + u32 chan; + s16 i; + PADStatus status[4]; + if(!HuDvdErrWait) { + RumbleBit = PADRead(status); + PADClamp(status); + chan = 0; + for(i=0; i<4; i++) { + PADStatus *curr_status = &status[i]; + PadRumble *rumble = &rumbleData[i]; + if(padStatErrOld[i] && curr_status->err == PAD_ERR_NONE) { + PADControlMotor(i, PAD_MOTOR_STOP_HARD); + rumble->duration = 0; + } + padStatErrOld[i] = curr_status->err; + if(curr_status->err != PAD_ERR_NONE) { + _PadErr[i] = curr_status->err; + if(curr_status->err != PAD_ERR_TRANSFER && curr_status->err != PAD_ERR_NOT_READY) { + chan |= chanTbl[i]; + } + _PadBtnDown[i] = _PadBtn[i] = _PadStkX[i] = _PadStkY[i] = _PadSubStkX[i] = _PadSubStkY[i] = _PadTrigL[i] = _PadTrigR[i] = _PadDStkRep[i] = _PadDStk[i] = HuPadBtnRep[i] = 0; + } else { + u16 button = curr_status->button; + if(curr_status->triggerL & 0xC0) { + button |= PAD_BUTTON_TRIGGER_L; + } + if(curr_status->triggerR & 0xC0) { + button |= PAD_BUTTON_TRIGGER_R; + } + if(button && _PadBtn[i] == button) { + if(_PadRepCnt[i] > 20) { + HuPadBtnRep[i] = button; + } else { + HuPadBtnRep[i] = 0; + _PadRepCnt[i]++; + } + } else { + _PadRepCnt[i] = 0; + HuPadBtnRep[i] = button; + } + PadADConv(i, curr_status); + _PadBtnDown[i] |= PADButtonDown(_PadBtn[i], button); + _PadBtn[i] = button; + _PadStkX[i] = curr_status->stickX; + _PadStkY[i] = curr_status->stickY; + _PadSubStkX[i] = curr_status->substickX; + _PadSubStkY[i] = curr_status->substickY; + _PadTrigL[i] = curr_status->triggerL; + _PadTrigR[i] = curr_status->triggerR; + _PadErr[i] = curr_status->err; + if(rumble->duration) { + s16 time = rumble->time%(rumble->off+rumble->on); + if(time == 0) { + PADControlMotor(i, PAD_MOTOR_RUMBLE); + } else { + if(time == rumble->off) { + PADControlMotor(i, PAD_MOTOR_STOP); + } + } + rumble->time++; + if(rumble->time > rumble->duration) { + PADControlMotor(i, PAD_MOTOR_STOP_HARD); + rumble->duration = 0; + } + } + } + } + if(chan) { + PADReset(chan); + } + } + msmSysRegularProc(); + VCounter++; +} + +static void PadADConv(s16 pad, PADStatus *status) +{ + s16 stickX, stickY; + s16 spA, sp8; + spA = 0; + sp8 = 0; + stickX = abs(status->stickX); + stickY = abs(status->stickY); + _PadDStk[pad] = 0; + if(stickY > 20) { + if(status->stickY > 0) { + _PadDStk[pad] |= PAD_BUTTON_UP; + } else { + _PadDStk[pad] |= PAD_BUTTON_DOWN; + } + } + if(stickX > 30) { + if(status->stickX < 0) { + _PadDStk[pad] |= PAD_BUTTON_LEFT; + } else { + _PadDStk[pad] |= PAD_BUTTON_RIGHT; + } + } + if(stickX+stickY < 20) { + _PadDStkRepOld[pad] =0; + } + if(_PadDStkRepCnt[pad]) { + _PadDStkRepCnt[pad]--; + if(stickX+stickY < 20) { + _PadDStkRepCnt[pad] = 0; + } + _PadDStkRep[pad] = 0; + } else { + _PadDStkRep[pad] = _PadDStk[pad]; + if(_PadDStkRep[pad]) { + if(_PadDStkRepOld[pad] == _PadDStkRep[pad]) { + _PadDStkRepCnt[pad] = 2; + } else { + _PadDStkRepCnt[pad] = 20; + } + _PadDStkRepOld[pad] = _PadDStkRep[pad]; + } + } +} + +void HuPadRumbleSet(s16 pad, s16 duration, s16 off, s16 on) +{ + PadRumble *rumble = &rumbleData[pad]; + if(_PadErr[pad] == PAD_ERR_NONE) { + rumble->duration = duration; + rumble->off = off; + rumble->on = on; + rumble->time = 0; + } +} + +void HuPadRumbleStop(s16 pad) +{ + PadRumble *rumble = &rumbleData[pad]; + if(_PadErr[pad] == PAD_ERR_NONE) { + rumble->duration = 0; + PADControlMotor(pad, PAD_MOTOR_STOP_HARD); + } +} + +void HuPadRumbleAllStop(void) +{ + int i; + for(i=0; i<4; i++) { + rumbleData[i].duration = 0; + if(_PadErr[i] == PAD_ERR_NONE) { + PADControlMotor(i, PAD_MOTOR_STOP_HARD); + } + } +} + +s16 HuPadStatGet(s16 pad) +{ + return _PadErr[pad]; +} + +u32 HuPadRumbleGet(void) +{ + return RumbleBit; +} \ No newline at end of file diff --git a/src/game/window.c b/src/game/window.c index 46b8776e..ee65b823 100644 --- a/src/game/window.c +++ b/src/game/window.c @@ -6,6 +6,7 @@ #include "game/dvd.h" #include "game/memory.h" #include "game/process.h" +#include "game/pad.h" #include "math.h" #include "stdarg.h" @@ -45,10 +46,6 @@ void HuAR_ARAMtoMRAM(void*); void mtxTransCat(Mtx, float, float, float); void *MessData_MesPtrGet(void*, u32); - -extern u16 HuPadBtn[4]; -extern u8 HuPadDStkRep[4]; - WindowData ATTRIBUTE_ALIGN(32) winData[32]; u32 winKey[4]; keyBufData winComKeyBuf[256]; @@ -1092,11 +1089,11 @@ static void HuWinChoice(WindowData *window) { if (window->choice != choice_next) { window->choice = choice_next; HuAudFXPlay(0); - } else if (key & (window->key_auto | 0x100)) { + } else if (key & (window->key_auto | PAD_BUTTON_A)) { HuAudFXPlay(2); window->key_down = key; window->stat = 0; - } else if ((key & 0x200) && !(window->attr & 0x10)) { + } else if ((key & PAD_BUTTON_B) && !(window->attr & 0x10)) { HuAudFXPlay(3); window->key_down = key; window->choice = -1;