From a4b2b79f0d45fafb43a9aa038180b545ab625a2a Mon Sep 17 00:00:00 2001 From: gamemasterplc Date: Sat, 23 Dec 2023 11:17:15 -0600 Subject: [PATCH] Start decompiling pad.c --- config/GMPE01_00/symbols.txt | 12 +-- configure.py | 2 +- include/game/msm.h | 1 + src/game/pad.c | 152 +++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 src/game/pad.c diff --git a/config/GMPE01_00/symbols.txt b/config/GMPE01_00/symbols.txt index 4127bef0..6fed8996 100644 --- a/config/GMPE01_00/symbols.txt +++ b/config/GMPE01_00/symbols.txt @@ -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 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/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/src/game/pad.c b/src/game/pad.c new file mode 100644 index 00000000..2bd9f508 --- /dev/null +++ b/src/game/pad.c @@ -0,0 +1,152 @@ +#include "common.h" +#include "dolphin.h" +#include "game/msm.h" + +typedef struct pad_rumble { + s16 duration; + s16 stop; + s16 rumble; + s16 time; +} padRumble; + +void HuPadRead(void); +static void PadReadVSync(u32 retraceCount); +static void PadADConv(s16 pad, PADStatus *status); + +static int padStatErrOld[4]; +static padRumble rumbleData[4]; + +u16 HuPadBtnRep[4]; +u16 _PadBtnDown[4]; +u16 _PadBtn[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; + +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) +{ + +} + +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 |= 0x4000; + } + if(curr_status->triggerR & 0xC0) { + button |= 0x2000; + } + 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->stop+rumble->rumble); + if(time == 0) { + PADControlMotor(i, PAD_MOTOR_RUMBLE); + } else { + if(time == rumble->stop) { + 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 player, PADStatus *status) +{ + + +} \ No newline at end of file