diff --git a/config/RSPE01_01/splits.txt b/config/RSPE01_01/splits.txt index cf8095dcc..9d551c0d2 100644 --- a/config/RSPE01_01/splits.txt +++ b/config/RSPE01_01/splits.txt @@ -3217,7 +3217,7 @@ Pack/RPKernel/RPSysAppMiiManager.cpp: .text start:0x801A6360 end:0x801A6424 .data start:0x803B9E90 end:0x803B9EA0 -Pack/RPKernel/RPSysControllerSyncMgr.cpp: +Pack/RPKernel/RPSysPairingMgr.cpp: .text start:0x801A6424 end:0x801A6554 .sbss start:0x804BF5B0 end:0x804BF5B8 diff --git a/config/RSPE01_01/symbols.txt b/config/RSPE01_01/symbols.txt index fd3869081..1c230d2e4 100644 --- a/config/RSPE01_01/symbols.txt +++ b/config/RSPE01_01/symbols.txt @@ -7508,48 +7508,48 @@ fn_8019B034 = .text:0x8019B034; // type:function size:0x8C fn_8019B0C0 = .text:0x8019B0C0; // type:function size:0x58 fn_8019B118 = .text:0x8019B118; // type:function size:0x4C fn_8019B164 = .text:0x8019B164; // type:function size:0xB0 -fn_8019B214 = .text:0x8019B214; // type:function size:0x80 -fn_8019B294 = .text:0x8019B294; // type:function size:0x60 -fn_8019B2F4 = .text:0x8019B2F4; // type:function size:0xB4 -fn_8019B3A8 = .text:0x8019B3A8; // type:function size:0x174 -fn_8019B51C = .text:0x8019B51C; // type:function size:0x24 -fn_8019B540 = .text:0x8019B540; // type:function size:0x24 -fn_8019B564 = .text:0x8019B564; // type:function size:0x24 -fn_8019B588 = .text:0x8019B588; // type:function size:0x24 +requestCoreInfoAsync__19RPSysCoreControllerFv = .text:0x8019B214; // type:function size:0x80 +getInfoCallback__19RPSysCoreControllerFll = .text:0x8019B294; // type:function size:0x60 +popKPADParamStackAll__19RPSysCoreControllerFv = .text:0x8019B2F4; // type:function size:0xB4 +pushKPADParamStackAll__19RPSysCoreControllerFv = .text:0x8019B3A8; // type:function size:0x174 +setAccParam__19RPSysCoreControllerFff = .text:0x8019B51C; // type:function size:0x24 +setDistParam__19RPSysCoreControllerFff = .text:0x8019B540; // type:function size:0x24 +setHoriParam__19RPSysCoreControllerFff = .text:0x8019B564; // type:function size:0x24 +setPosParam__19RPSysCoreControllerFff = .text:0x8019B588; // type:function size:0x24 isPrevDpdCtrlEnable__19RPSysCoreControllerFv = .text:0x8019B5AC; // type:function size:0x20 -fn_8019B5CC = .text:0x8019B5CC; // type:function size:0x54 -fn_8019B620 = .text:0x8019B620; // type:function size:0x70 -fn_8019B690 = .text:0x8019B690; // type:function size:0x68 -fn_8019B6F8 = .text:0x8019B6F8; // type:function size:0x38 -fn_8019B730 = .text:0x8019B730; // type:function size:0x8 -fn_8019B738 = .text:0x8019B738; // type:function size:0x8 -fn_8019B740 = .text:0x8019B740; // type:function size:0x54 -fn_8019B794 = .text:0x8019B794; // type:function size:0x48 +popDpdCtrlStackAll__19RPSysCoreControllerFv = .text:0x8019B5CC; // type:function size:0x54 +pushDpdCtrlStackAll__19RPSysCoreControllerFb = .text:0x8019B620; // type:function size:0x70 +disableDpdCtrlAll__19RPSysCoreControllerFv = .text:0x8019B690; // type:function size:0x68 +set__19RPSysCoreControllerFlRC16RPSysCoreAddress = .text:0x8019B6F8; // type:function size:0x38 +disableConnection__19RPSysCoreControllerFv = .text:0x8019B730; // type:function size:0x8 +enableConnection__19RPSysCoreControllerFv = .text:0x8019B738; // type:function size:0x8 +isCoreBaseDevice__19RPSysCoreControllerCFv = .text:0x8019B740; // type:function size:0x54 +rumble__19RPSysCoreControllerFQ219RPSysCoreController14ERumblePattern = .text:0x8019B794; // type:function size:0x48 stopMotorAll__19RPSysCoreControllerFv = .text:0x8019B7DC; // type:function size:0x44 -fn_8019B820 = .text:0x8019B820; // type:function size:0x4 -fn_8019B824 = .text:0x8019B824; // type:function size:0x38 -fn_8019B85C = .text:0x8019B85C; // type:function size:0x28C -fn_8019BAE8 = .text:0x8019BAE8; // type:function size:0x18 -fn_8019BB00 = .text:0x8019BB00; // type:function size:0x14 -fn_8019BB14 = .text:0x8019BB14; // type:function size:0x5C -fn_8019BB70 = .text:0x8019BB70; // type:function size:0x310 -fn_8019BE80 = .text:0x8019BE80; // type:function size:0x200 -fn_8019C080 = .text:0x8019C080; // type:function size:0x8 -fn_8019C088 = .text:0x8019C088; // type:function size:0x8 -fn_8019C090 = .text:0x8019C090; // type:function size:0x68 -fn_8019C0F8 = .text:0x8019C0F8; // type:function size:0xB4 -fn_8019C1AC = .text:0x8019C1AC; // type:function size:0x7C -fn_8019C228 = .text:0x8019C228; // type:function size:0x34 -fn_8019C25C = .text:0x8019C25C; // type:function size:0x98 -fn_8019C2F4 = .text:0x8019C2F4; // type:function size:0x80 -fn_8019C374 = .text:0x8019C374; // type:function size:0x8 -fn_8019C37C = .text:0x8019C37C; // type:function size:0x8 -fn_8019C384 = .text:0x8019C384; // type:function size:0x110 -fn_8019C494 = .text:0x8019C494; // type:function size:0x20 -fn_8019C4B4 = .text:0x8019C4B4; // type:function size:0x20 -fn_8019C4D4 = .text:0x8019C4D4; // type:function size:0x24C -fn_8019C720 = .text:0x8019C720; // type:function size:0x24 -fn_8019C744 = .text:0x8019C744; // type:function size:0x8 +shutdownSystem__19RPSysCoreControllerFb = .text:0x8019B820; // type:function size:0x4 +becomeMainController__19RPSysCoreControllerFv = .text:0x8019B824; // type:function size:0x38 +beginFrame__19RPSysCoreControllerFP9PADStatus = .text:0x8019B85C; // type:function size:0x28C +getExCoreStatus__19RPSysCoreControllerFii = .text:0x8019BAE8; // type:function size:0x18 +setExAccParam__19RPSysCoreControllerFiff = .text:0x8019BB00; // type:function size:0x14 +__dt__19RPSysCoreControllerFv = .text:0x8019BB14; // type:function size:0x5C +__ct__19RPSysCoreControllerFUl = .text:0x8019BB70; // type:function size:0x310 +initScene__19RPSysCoreControllerFv = .text:0x8019BE80; // type:function size:0x200 +forceSensorBarPowerOn__19RPSysCoreControllerFv = .text:0x8019C080; // type:function size:0x8 +sceneReset__19RPSysCoreControllerFv = .text:0x8019C088; // type:function size:0x8 +applySetting__19RPSysCoreControllerFv = .text:0x8019C090; // type:function size:0x68 +initialize__19RPSysCoreControllerFv = .text:0x8019C0F8; // type:function size:0xB4 +createCoreController__19RPSysCoreControllerFv = .text:0x8019C1AC; // type:function size:0x7C +isLowBattery__13RPSysCoreInfoCFv = .text:0x8019C228; // type:function size:0x34 +isEqual__16RPSysCoreAddressCFRC16RPSysCoreAddress = .text:0x8019C25C; // type:function size:0x98 +isValid__16RPSysCoreAddressCFv = .text:0x8019C2F4; // type:function size:0x80 +get__16RPSysCoreAddressCFi = .text:0x8019C374; // type:function size:0x8 +set__16RPSysCoreAddressFPCUc = .text:0x8019C37C; // type:function size:0x8 +read__16RPSysCoreAddressFl = .text:0x8019C384; // type:function size:0x110 +reset__16RPSysCoreAddressFv = .text:0x8019C494; // type:function size:0x20 +__ct__16RPSysCoreAddressFv = .text:0x8019C4B4; // type:function size:0x20 +calc__Q219RPSysCoreController8ExStatusFPQ23EGG10CoreStatusl = .text:0x8019C4D4; // type:function size:0x24C +__sinit_\RPSysController_cpp = .text:0x8019C720; // type:function size:0x24 scope:local +@2300@__dt__19RPSysCoreControllerFv = .text:0x8019C744; // type:function size:0x8 scope:weak Construct__16RPSysKokeshiIconFv = .text:0x8019C74C; // type:function size:0x2F0 ModifyBgColor__16RPSysKokeshiIconFRC20RPSysKokeshiLocationUsUs9_GXTexFmt13RFLIconBGType8_GXColor = .text:0x8019CA3C; // type:function size:0x1A4 MakeEdge__16RPSysKokeshiIconFv = .text:0x8019CBE0; // type:function size:0xB14 @@ -7705,19 +7705,19 @@ __ct__19RPSysKokeshiCtrlMgrFP29IRPSysKokeshiCtrlDataCallbackPQ23EGG4HeapUl = .te __dt__Q219RPSysKokeshiCtrlMgr11T__DisposerFv = .text:0x801A62F0; // type:function size:0x70 scope:weak __dt__18RPSysAppMiiManagerFv = .text:0x801A6360; // type:function size:0x40 __ct__18RPSysAppMiiManagerFUsPQ23EGG4Heap = .text:0x801A63A0; // type:function size:0x84 -calc__22RPSysControllerSyncMgrFv = .text:0x801A6424; // type:function size:0xB0 -__ct__22RPSysControllerSyncMgrFv = .text:0x801A64D4; // type:function size:0x44 -simpleSyncCallBack__22RPSysControllerSyncMgrFll = .text:0x801A6518; // type:function size:0x3C -fn_801A6554 = .text:0x801A6554; // type:function size:0x10 -fn_801A6564 = .text:0x801A6564; // type:function size:0x10 -fn_801A6574 = .text:0x801A6574; // type:function size:0x4 -fn_801A6578 = .text:0x801A6578; // type:function size:0x52C -fn_801A6AA4 = .text:0x801A6AA4; // type:function size:0x1E8 -fn_801A6C8C = .text:0x801A6C8C; // type:function size:0xC8 -fn_801A6D54 = .text:0x801A6D54; // type:function size:0xC8 -fn_801A6E1C = .text:0x801A6E1C; // type:function size:0x64 -fn_801A6E80 = .text:0x801A6E80; // type:function size:0x28 -fn_801A6EA8 = .text:0x801A6EA8; // type:function size:0x58 +calc__15RPSysPairingMgrFv = .text:0x801A6424; // type:function size:0xB0 +__ct__15RPSysPairingMgrFv = .text:0x801A64D4; // type:function size:0x44 +simpleSyncCallback__15RPSysPairingMgrFll = .text:0x801A6518; // type:function size:0x3C +disableConnection__22RPSysCoreControllerMgrCFv = .text:0x801A6554; // type:function size:0x10 +enableConnection__22RPSysCoreControllerMgrCFv = .text:0x801A6564; // type:function size:0x10 +endFrame__22RPSysCoreControllerMgrFv = .text:0x801A6574; // type:function size:0x4 +beginFrame__22RPSysCoreControllerMgrFv = .text:0x801A6578; // type:function size:0x52C +sceneReset__22RPSysCoreControllerMgrFv = .text:0x801A6AA4; // type:function size:0x1E8 +findController__22RPSysCoreControllerMgrCFl = .text:0x801A6C8C; // type:function size:0xC8 +create__22RPSysCoreControllerMgrFv = .text:0x801A6D54; // type:function size:0xC8 +controlDpdCallback__22RPSysCoreControllerMgrFll = .text:0x801A6E1C; // type:function size:0x64 +clearDeviceCallback__22RPSysCoreControllerMgrFl = .text:0x801A6E80; // type:function size:0x28 +connectCallback__22RPSysCoreControllerMgrFRCQ23EGG24CoreControllerConnectArg = .text:0x801A6EA8; // type:function size:0x58 openLib__17RPSysNWC24ManagerFv = .text:0x801A6F00; // type:function size:0x68 commitMail__17RPSysNWC24ManagerFPCwPCwUsPC11RPSysAvatariP16__va_list_struct = .text:0x801A6F68; // type:function size:0x5C8 __dt__17RPSysNWC24ManagerFv = .text:0x801A7530; // type:function size:0x40 @@ -15107,9 +15107,9 @@ PLAYER_COLORS__11RPSysLayout = .rodata:0x80382D60; // type:object size:0x10 lbl_80382D70 = .rodata:0x80382D70; // type:object size:0x5 data:string @stringBase0 = .rodata:0x80382D78; // type:object size:0x1 scope:local data:string_table lbl_80382D80 = .rodata:0x80382D80; // type:object size:0x118 -lbl_80382E98 = .rodata:0x80382E98; // type:object size:0x10 align:4 data:float -lbl_80382EA8 = .rodata:0x80382EA8; // type:object size:0x10 align:4 data:float -lbl_80382EB8 = .rodata:0x80382EB8; // type:object size:0x20 +DEFAULT_EX_THRESHOLD__19RPSysCoreController = .rodata:0x80382E98; // type:object size:0x10 align:4 data:float +DEFAULT_EX_RATE__19RPSysCoreController = .rodata:0x80382EA8; // type:object size:0x10 align:4 data:float +@stringBase0 = .rodata:0x80382EB8; // type:object size:0x19 scope:local data:string_table lbl_80382ED8 = .rodata:0x80382ED8; // type:object size:0x9 data:string lbl_80382EE1 = .rodata:0x80382EE1; // type:object size:0x9 data:string lbl_80382EF0 = .rodata:0x80382EF0; // type:object size:0x20 data:4byte @@ -18607,7 +18607,7 @@ __vt__9RPSysFile = .data:0x803B9BF8; // type:object size:0xC __vt__11RPSysAvatar = .data:0x803B9C08; // type:object size:0x14 lbl_803B9C20 = .data:0x803B9C20; // type:object size:0x10 lbl_803B9C30 = .data:0x803B9C30; // type:object size:0x18 -lbl_803B9C48 = .data:0x803B9C48; // type:object size:0x38 +__vt__19RPSysCoreController = .data:0x803B9C48; // type:object size:0x38 __vt__16RPSysKokeshiIcon = .data:0x803B9C80; // type:object size:0x18 __vt__19RPSysKokeshiGenInfo = .data:0x803B9C98; // type:object size:0xC __vt__20RPSysKokeshiLocation = .data:0x803B9CA8; // type:object size:0xC @@ -20450,7 +20450,7 @@ lbl_804BDBA8 = .sdata:0x804BDBA8; // type:object size:0x4 data:4byte lbl_804BDBAC = .sdata:0x804BDBAC; // type:object size:0x4 data:4byte lbl_804BDBB0 = .sdata:0x804BDBB0; // type:object size:0x8 data:4byte lbl_804BDBB8 = .sdata:0x804BDBB8; // type:object size:0x8 -lbl_804BDBC0 = .sdata:0x804BDBC0; // type:object size:0x8 align:4 data:float +sSensorHeight__19RPSysCoreController = .sdata:0x804BDBC0; // type:object size:0x4 align:4 data:float LIGHT_TEXTURE_FILE_NAMES__16RPSysKokeshiIcon = .sdata:0x804BDBC8; // type:object size:0x8 lbl_804BDBD0 = .sdata:0x804BDBD0; // type:object size:0x8 lbl_804BDBD8 = .sdata:0x804BDBD8; // type:object size:0x8 @@ -21872,38 +21872,30 @@ lbl_804BF518 = .sbss:0x804BF518; // type:object size:0x8 data:4byte lbl_804BF520 = .sbss:0x804BF520; // type:object size:0x8 data:4byte spInstance__24RPSysHostIOSocketManager = .sbss:0x804BF528; // type:object size:0x4 data:4byte spInstance__15RP_DEBUG_STUB_0 = .sbss:0x804BF530; // type:object size:0x4 data:4byte -spInstance__15RPSysTextWriter = .sbss:0x804BF538; // type:object size:0x8 data:4byte +spInstance__15RPSysTextWriter = .sbss:0x804BF538; // type:object size:0x4 data:4byte spInstance__19RPSysKokeshiManager = .sbss:0x804BF540; // type:object size:0x8 data:4byte lbl_804BF548 = .sbss:0x804BF548; // type:object size:0x8 data:4byte lbl_804BF550 = .sbss:0x804BF550; // type:object size:0x8 spTextBuffer__19RPSysWideTextWriter = .sbss:0x804BF558; // type:object size:0x4 data:4byte lbl_804BF560 = .sbss:0x804BF560; // type:object size:0x8 data:4byte spInstance__17RPSysTagProcessor = .sbss:0x804BF568; // type:object size:0x8 data:4byte -lbl_804BF570 = .sbss:0x804BF570; // type:object size:0x2 data:2byte -gap_11_804BF572_sbss = .sbss:0x804BF572; // type:object size:0x2 scope:global -lbl_804BF574 = .sbss:0x804BF574; // type:object size:0x4 data:4byte -lbl_804BF578 = .sbss:0x804BF578; // type:object size:0x1 data:byte -lbl_804BF579 = .sbss:0x804BF579; // type:object size:0x1 data:byte -lbl_804BF57A = .sbss:0x804BF57A; // type:object size:0x1 data:byte -lbl_804BF57B = .sbss:0x804BF57B; // type:object size:0x1 data:byte -lbl_804BF57C = .sbss:0x804BF57C; // type:object size:0x1 data:byte -lbl_804BF57D = .sbss:0x804BF57D; // type:object size:0x1 data:byte -lbl_804BF57E = .sbss:0x804BF57E; // type:object size:0x1 data:byte -gap_11_804BF57F_sbss = .sbss:0x804BF57F; // type:object size:0x1 scope:global -lbl_804BF580 = .sbss:0x804BF580; // type:object size:0x8 data:byte -lbl_804BF588 = .sbss:0x804BF588; // type:object size:0x8 data:4byte +sNextPlayerNo__19RPSysCoreController = .sbss:0x804BF570; // type:object size:0x2 data:2byte +spMainController__19RPSysCoreController = .sbss:0x804BF574; // type:object size:0x4 data:4byte +sMainAddress__19RPSysCoreController = .sbss:0x804BF578; // type:object size:0x6 data:byte +sDisconnectOccurred__19RPSysCoreController = .sbss:0x804BF57E; // type:object size:0x1 data:byte +sAddrWork__16RPSysCoreAddress = .sbss:0x804BF580; // type:object size:0x6 data:byte +lbl_804BF588 = .sbss:0x804BF588; // type:object size:0x8 align:4 data:4byte lbl_804BF590 = .sbss:0x804BF590; // type:object size:0x8 align:4 data:float lbl_804BF598 = .sbss:0x804BF598; // type:object size:0x8 data:4byte lbl_804BF5A0 = .sbss:0x804BF5A0; // type:object size:0x8 data:4byte spInstance__16RPSysHomeMenuMgr = .sbss:0x804BF5A8; // type:object size:0x4 data:4byte lbl_804BF5AC = .sbss:0x804BF5AC; // type:object size:0x4 data:4byte -sIsSyncing__22RPSysControllerSyncMgr = .sbss:0x804BF5B0; // type:object size:0x1 data:byte -lbl_804BF5B8 = .sbss:0x804BF5B8; // type:object size:0x2 data:2byte -lbl_804BF5BA = .sbss:0x804BF5BA; // type:object size:0x2 data:2byte -lbl_804BF5BC = .sbss:0x804BF5BC; // type:object size:0x2 data:2byte -lbl_804BF5BE = .sbss:0x804BF5BE; // type:object size:0x1 data:byte -gap_11_804BF5BF_sbss = .sbss:0x804BF5BF; // type:object size:0x1 scope:global -lbl_804BF5C0 = .sbss:0x804BF5C0; // type:object size:0x8 data:4byte +sIsBusy__15RPSysPairingMgr = .sbss:0x804BF5B0; // type:object size:0x1 data:byte +sConnectionFlag__22RPSysCoreControllerMgr = .sbss:0x804BF5B8; // type:object size:0x2 data:2byte +sPrevConnectionFlag__22RPSysCoreControllerMgr = .sbss:0x804BF5BA; // type:object size:0x2 data:2byte +sDpdCtrlEnableFlag__22RPSysCoreControllerMgr = .sbss:0x804BF5BC; // type:object size:0x2 data:2byte +sClearDeviceFlag__22RPSysCoreControllerMgr = .sbss:0x804BF5BE; // type:object size:0x1 data:byte +spInstance__22RPSysCoreControllerMgr = .sbss:0x804BF5C0; // type:object size:0x4 data:4byte @GUARD@cameraData$16612 = .sbss:0x804BF5C8; // type:object size:0x1 scope:local data:byte spAllocator__10RPGrpModel = .sbss:0x804BF5D0; // type:object size:0x4 data:4byte spEntryHead__10RPGrpModel = .sbss:0x804BF5D4; // type:object size:0x4 data:4byte @@ -23474,10 +23466,10 @@ lbl_804C1578 = .sdata2:0x804C1578; // type:object size:0x1 data:byte lbl_804C1579 = .sdata2:0x804C1579; // type:object size:0x1 data:byte lbl_804C157A = .sdata2:0x804C157A; // type:object size:0x1 data:byte lbl_804C157B = .sdata2:0x804C157B; // type:object size:0x5 data:byte -lbl_804C1580 = .sdata2:0x804C1580; // type:object size:0x4 align:4 data:float -lbl_804C1584 = .sdata2:0x804C1584; // type:object size:0x4 align:4 data:float -lbl_804C1588 = .sdata2:0x804C1588; // type:object size:0x8 align:8 data:double -lbl_804C1590 = .sdata2:0x804C1590; // type:object size:0x4 align:4 data:float +@21953 = .sdata2:0x804C1580; // type:object size:0x4 scope:local align:4 data:float +@21954 = .sdata2:0x804C1584; // type:object size:0x4 scope:local align:4 data:float +@21960 = .sdata2:0x804C1588; // type:object size:0x8 scope:local align:8 data:double +@21986 = .sdata2:0x804C1590; // type:object size:0x4 scope:local align:4 data:float gap_12_804C1594_sdata2 = .sdata2:0x804C1594; // type:object size:0x4 scope:global lbl_804C1598 = .sdata2:0x804C1598; // type:object size:0x8 align:8 data:double lbl_804C15A0 = .sdata2:0x804C15A0; // type:object size:0x1 data:byte @@ -23542,15 +23534,15 @@ lbl_804C16B8 = .sdata2:0x804C16B8; // type:object size:0x4 align:4 data:float gap_12_804C16BC_sdata2 = .sdata2:0x804C16BC; // type:object size:0x4 scope:global lbl_804C16C0 = .sdata2:0x804C16C0; // type:object size:0x8 align:8 data:double lbl_804C16C8 = .sdata2:0x804C16C8; // type:object size:0x8 align:8 data:double -lbl_804C16D0 = .sdata2:0x804C16D0; // type:object size:0x4 align:4 data:float -lbl_804C16D4 = .sdata2:0x804C16D4; // type:object size:0x4 align:4 data:float -lbl_804C16D8 = .sdata2:0x804C16D8; // type:object size:0x4 align:4 data:float -lbl_804C16DC = .sdata2:0x804C16DC; // type:object size:0x4 align:4 data:float -lbl_804C16E0 = .sdata2:0x804C16E0; // type:object size:0x4 align:4 data:float -lbl_804C16E4 = .sdata2:0x804C16E4; // type:object size:0x4 align:4 data:float -lbl_804C16E8 = .sdata2:0x804C16E8; // type:object size:0x4 align:4 data:float -lbl_804C16EC = .sdata2:0x804C16EC; // type:object size:0x4 align:4 data:float -lbl_804C16F0 = .sdata2:0x804C16F0; // type:object size:0x8 align:4 data:float +@22137 = .sdata2:0x804C16D0; // type:object size:0x4 scope:local align:4 data:float +@22138 = .sdata2:0x804C16D4; // type:object size:0x4 scope:local align:4 data:float +@22316 = .sdata2:0x804C16D8; // type:object size:0x4 scope:local align:4 data:float +@22317 = .sdata2:0x804C16DC; // type:object size:0x4 scope:local align:4 data:float +@22318 = .sdata2:0x804C16E0; // type:object size:0x4 scope:local align:4 data:float +@22432 = .sdata2:0x804C16E4; // type:object size:0x4 scope:local align:4 data:float +@22433 = .sdata2:0x804C16E8; // type:object size:0x4 scope:local align:4 data:float +@22442 = .sdata2:0x804C16EC; // type:object size:0x4 scope:local align:4 data:float +@22443 = .sdata2:0x804C16F0; // type:object size:0x4 scope:local align:4 data:float lbl_804C16F8 = .sdata2:0x804C16F8; // type:object size:0x1 data:byte lbl_804C16F9 = .sdata2:0x804C16F9; // type:object size:0x1 data:byte lbl_804C16FA = .sdata2:0x804C16FA; // type:object size:0x1 data:byte diff --git a/configure.py b/configure.py index 05e26fc55..6a143faf1 100755 --- a/configure.py +++ b/configure.py @@ -1172,7 +1172,7 @@ def MatchingFor(*versions): Object(NonMatching, "Pack/RPKernel/RPSysTutorialWinMgr.cpp"), Object(Matching, "Pack/RPKernel/RPSysLytPicture.cpp"), Object(NonMatching, "Pack/RPKernel/RPSysTagProcessor.cpp"), - Object(NonMatching, "Pack/RPKernel/RPSysController.cpp"), + Object(Matching, "Pack/RPKernel/RPSysController.cpp"), Object(NonMatching, "Pack/RPKernel/RPSysKokeshiIcon.cpp"), Object(Matching, "Pack/RPKernel/RPSysKokeshiGenInfo.cpp"), Object(Matching, "Pack/RPKernel/RPSysKokeshiLocation.cpp"), @@ -1193,7 +1193,7 @@ def MatchingFor(*versions): Object(Matching, "Pack/RPKernel/RPSysKokeshiCtrlDataMgr.cpp"), Object(Matching, "Pack/RPKernel/RPSysKokeshiCtrlMgr.cpp"), Object(NonMatching, "Pack/RPKernel/RPSysAppMiiManager.cpp"), - Object(Matching, "Pack/RPKernel/RPSysControllerSyncMgr.cpp"), + Object(Matching, "Pack/RPKernel/RPSysPairingMgr.cpp"), Object(NonMatching, "Pack/RPKernel/RPSysControllerMgr.cpp"), Object(NonMatching, "Pack/RPKernel/RPSysNWC24Manager.cpp"), Object(NonMatching, "Pack/RPKernel/RPSysParticleManager.cpp"), diff --git a/include/Pack/RPAudio/RPSndAudioMgr.h b/include/Pack/RPAudio/RPSndAudioMgr.h index f8c1128d2..32e903028 100644 --- a/include/Pack/RPAudio/RPSndAudioMgr.h +++ b/include/Pack/RPAudio/RPSndAudioMgr.h @@ -459,6 +459,13 @@ class RPSndAudioMgr : public EGG::ExpAudioMgr { return mPlayerNum; } + /** + * @brief Accesses the static sound archive manager + */ + RPSndStaticMgr& getStaticMgr() { + return mStaticMgr; + } + private: /** * @brief Audio manager flags diff --git a/include/Pack/RPAudio/RPSndObject.h b/include/Pack/RPAudio/RPSndObject.h index 1372a6026..8350933f7 100644 --- a/include/Pack/RPAudio/RPSndObject.h +++ b/include/Pack/RPAudio/RPSndObject.h @@ -11,8 +11,6 @@ #include #include -#include - //! @addtogroup rp_audio //! @{ @@ -201,7 +199,7 @@ class TRPSndObject : public TRPSndAudio3DActor, }; //! Shorthand for default specialization -typedef TRPSndObject RPSndObject; +typedef TRPSndObject RPSndObject; /****************************************************************************** * diff --git a/include/Pack/RPKernel.h b/include/Pack/RPKernel.h index 1e5ff85fd..9912de53d 100644 --- a/include/Pack/RPKernel.h +++ b/include/Pack/RPKernel.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Pack/RPKernel/RPSysController.h b/include/Pack/RPKernel/RPSysController.h index 25e6fa54d..6d6d73deb 100644 --- a/include/Pack/RPKernel/RPSysController.h +++ b/include/Pack/RPKernel/RPSysController.h @@ -2,76 +2,642 @@ #define RP_KERNEL_CONTROLLER_H #include +#include + #include +#include #include //! @addtogroup rp_kernel //! @{ +/** + * @brief Helper macro to access core controllers + */ +#define RP_GET_CORE_CTRL(N) \ + static_cast( \ + EGG_GET_INSTANCE(EGG::CoreControllerMgr)->getNthController(N)) + /****************************************************************************** * * RPSysCoreAddress * ******************************************************************************/ + +/** + * @brief Wii Remote controller MAC address + */ class RPSysCoreAddress { public: + /** + * @brief Constructor + */ RPSysCoreAddress(); + /** + * @brief Clears the controller address + */ void reset(); - bool get(s32 chan); + + /** + * @brief Attempts to read the address of the specified controller + * + * @param chan Controller remote channel + * @return Success + */ + bool read(s32 chan); + + /** + * @brief Sets the value of this controller address + * + * @param pData New controller address + */ void set(const u8* pData); + /** + * @brief Gets the specified digit of this address + * + * @param idx Digit index + */ + u8 get(int idx) const; + + /** + * @brief Tests whether this controller address is valid + */ bool isValid() const; - u8 operator[](int i) const; - bool operator==(const RPSysCoreAddress& rOther) const; + /** + * @brief Tests whether two controller addresses are equivalent + * + * @param rOther Other controller address + */ + bool isEqual(const RPSysCoreAddress& rOther) const; + +private: + //! Number of read attempts before giving up + static const int RETRY_NUM = 1000; private: + //! Controller address work buffer + static u8 sAddrWork[WPAD_ADDR_LEN]; + //! Remote address u8 mData[WPAD_ADDR_LEN]; // at 0x0 }; /****************************************************************************** * - * RPSysCoreController + * RPSysCoreInfo * ******************************************************************************/ -class RPSysCoreController : public EGG::CoreController { + +/** + * @brief Wii Remote controller information + */ +class RPSysCoreInfo : public WPADInfo { + // Controller manages the flags + friend class RPSysCoreController; + public: - bool isPrevDpdCtrlEnable(); + /** + * @brief Constructor + */ + RPSysCoreInfo(); - static void stopMotorAll(); + /** + * @brief Clears the controller information + */ + void reset(); - const RPSysCoreAddress& getAddress() const { - return mAddress; - } + /** + * @brief Tests whether the controller battery level is low + */ + bool isLowBattery() const; private: - char unk8FC[0x2BA8 - 0x8FC]; - RPSysCoreAddress mAddress; // at 0x2BA8 + /** + * @brief Information flags + */ + enum { + EFlag_GetInfoSuccess = 1 << 0, //!< WPADGetInfoAsync succeeded + EFlag_GetInfoFail = 1 << 1, //!< WPADGetInfoAsync failed + }; + +private: + //! Information flags + u16 mFlags; // at 0x0 }; /****************************************************************************** * - * RPSysCoreControllerMgr + * RPSysCoreController * ******************************************************************************/ -class RPSysCoreControllerMgr { + +/** + * @brief Wii Remote controller state + */ +class RPSysCoreController : public EGG::CoreController, + public IRPSysHostIOSocket { + // Manager accesses internal state + friend class RPSysCoreControllerMgr; + public: - static u32 isDpdCtrlEnable(s32 chan) { - return sDpdCtrlEnableFlag & (1 << chan); - } + /** + * @brief Rumble pattern + */ + enum ERumblePattern { + ERumblePattern_Cursor, //!< Cursor action + ERumblePattern_Connect, //!< Controller connected + ERumblePattern_2, + ERumblePattern_Change, //!< Active player change + }; + + /** + * @brief KPAD parameter stack + */ + class ParamStack { + public: + /** + * @brief Constructor + */ + ParamStack(); + + /** + * @brief Clears the parameter stack + */ + void reset(); + + /** + * @brief Sets the initial parameters + * + * @param playRadius DPD play radius + * @param sensitivity DPD sensitivity + */ + void configure(f32 playRadius, f32 sensitivity); + + /** + * @brief Sets the current parameters + * + * @param playRadius DPD play radius + * @param sensitivity DPD sensitivity + */ + void set(f32 playRadius, f32 sensitivity); + + /** + * @brief Pushes the current parameter set onto the stack + */ + void push(); + + /** + * @brief Pops the top parameter set from the stack + */ + void pop(); + + /** + * @brief Gets the current play radius parameter + */ + f32 getPlayRadius() const { + return mPlayRadiusStack[mSize]; + } + + /** + * @brief Gets the current sensitivity parameter + */ + f32 getSensitivity() const { + return mSensitivityStack[mSize]; + } + + private: + //! Stack capacity + static const int CAPACITY = 8; + + private: + //! Stack size + s16 mSize; // at 0x0 + + //! Initial play radius parameter + f32 mInitialPlayRadius; // at 0x4 + //! Initial sensitivity parameter + f32 mInitialSensitivity; // at 0x8 + + //! Play radius parameter stack + f32 mPlayRadiusStack[CAPACITY]; // at 0xC + //! Sensitivity parameter stack + f32 mSensitivityStack[CAPACITY]; // at 0x2C + }; + + /** + * @brief CoreStatus extension + */ + class ExStatus { + public: + /** + * @brief Constructor + */ + ExStatus(); + + /** + * @brief Sets the current parameters + * + * @param threshold Acceleration smoothing threshold + * @param rate Acceleration smoothing rate + */ + void set(f32 threshold, f32 rate); + + /** + * @brief Gets the specified core status + * + * @param idx Core status index + */ + EGG::CoreStatus* getCoreStatus(int idx) { + return &status[idx]; + } + + /** + * @brief Updates the controller input state + * + * @param pStatusArray Controller sample set + * @param count Number of controler samples + */ + void calc(EGG::CoreStatus* pStatusArray, s32 count); + + private: + //! Smoothing threshold + f32 mPassThreshold; // at 0x0 + //! Smoothing rate + f32 mPassRate; // at 0x4 + + //! Input samples + EGG::CoreStatus status[KPAD_MAX_SAMPLES]; // at 0x8 + }; + +public: + /** + * @brief Initializes the controller system + */ + static void initialize(); + + /** + * @brief Tests whether the sensor bar is positioned above the TV + */ + static bool isSensorBarTop(); + + /** + * @brief Applies global controller settings + */ + static void applySetting(); + + /** + * @brief Prepares the controller system for a scene reset + */ + static void sceneReset(); + + /** + * @brief Forcibly turns on the sensor bar + */ + static void forceSensorBarPowerOn(); + + /** + * @brief Prepares the controller system for a new scene + */ + static void initScene(); + + /** + * @brief Constructor + * + * @param id Unique ID + */ + RPSysCoreController(u32 id); + + /** + * @brief Destructor + */ + virtual ~RPSysCoreController() override; // at 0x14 + + /** + * @brief Sets the KPAD position parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ + virtual void setPosParam(f32 playRadius, + f32 sensitivity) override; // at 0x8 + + /** + * @brief Sets the KPAD horizon parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ + virtual void setHoriParam(f32 playRadius, + f32 sensitivity) override; // at 0xC - static RPSysCoreController* getNthController(int index) { - EGG::CoreController* pController = - EGG_GET_INSTANCE(EGG::CoreControllerMgr)->getNthController(index); + /** + * @brief Sets the KPAD distance parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ + virtual void setDistParam(f32 playRadius, + f32 sensitivity) override; // at 0x10 - return static_cast(pController); + /** + * @brief Sets the KPAD acceleration parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ + virtual void setAccParam(f32 playRadius, + f32 sensitivity) override; // at 0x14 + + /** + * @brief Performs processing at the beginning of the frame + * + * @param pStatus GameCube controller status (for debugging?) + */ + virtual void beginFrame(PADStatus* pStatus = NULL) override; // at 0x18 + + /** + * @brief Sets the parameters for the specified extended status + * + * @param idx Extended status index + * @param threshold Smoothing threshold + * @param rate Smoothing rate + */ + void setExAccParam(int idx, f32 threshold, f32 rate); + + /** + * @brief Accesses the specified core status + * + * @param idx Extended status index + * @param sample Core status sample index + */ + EGG::CoreStatus* getExCoreStatus(int idx, int sample); + + /** + * @brief Shuts down the controller system + * + * @param forIpl Whether the program is exiting to the IPL + */ + static void shutdownSystem(bool forIpl); + + /** + * @brief Turns off the rumble motor in all controllers + */ + static void stopMotorAll(); + + /** + * @brief Starts the specified rumble pattern + * + * @param pattern Rumble pattern + */ + void rumble(ERumblePattern pattern); + + /** + * @brief Tests whether this controller's base device (no extension) is a + * Wii Remote controller + */ + bool isCoreBaseDevice() const; + + /** + * @brief Enables pairing of controllers + */ + static void enableConnection(); + + /** + * @brief Disables pairing of controllers + */ + static void disableConnection(); + + /** + * @brief Toggles whether DPD control is enabled + * + * @param enable Whether to enable DPD control + */ + void enableDpdCtrl(bool enable); + + /** + * @brief Disables DPD control for all controllers + */ + static void disableDpdCtrlAll(); + + /** + * @brief Resets the state of the DPD control stack + */ + void resetDpdCtrlStack(); + + /** + * @brief Pushes a new value to the DPD control stack + * + * @param enable Whether to enable DPD control + */ + void pushDpdCtrlStack(bool enable); + + /** + * @brief Pushes a new value to the DPD control stack for all controllers + * + * @param enable Whether to enable DPD control + */ + static void pushDpdCtrlStackAll(bool enable); + + /** + * @brief Pops the top value from the DPD control stack + */ + void popDpdCtrlStack(); + + /** + * @brief Pops the top value from the DPD control stack for all controllers + */ + static void popDpdCtrlStackAll(); + + /** + * @brief Tests whether DPD control was enabled at the previous stack level + */ + bool isPrevDpdCtrlEnable(); + + /** + * @brief Pushes the current KPAD parameter set onto the stack for all + * controllers + */ + static void pushKPADParamStackAll(); + + /** + * @brief Pops the top KPAD parameter set from the stack for all controllers + */ + static void popKPADParamStackAll(); + + /** + * @brief Attempts to read the controller information + * + * @return Success + */ + bool requestCoreInfoAsync(); + + /** + * @brief Accesses this controller's MAC address + */ + RPSysCoreAddress& getAddress() { + return mAddress; + } + /** + * @brief Accesses this controller's MAC address (const-view) + */ + const RPSysCoreAddress& getAddress() const { + return mAddress; } private: - static u32 sDpdCtrlEnableFlag; + /** + * @brief Controller event + */ + enum EEvent { + EEvent_None, //!< Nothing happened + EEvent_Connect, //!< Connected this frame + EEvent_Disconnect, //!< Disconnected this frame + }; + + /** + * @brief Extended status ID + */ + enum EExStatus { + EExStatus_0, + EExStatus_1, + EExStatus_2, + EExStatus_3, + + EExStatus_Max, + }; + + /** + * @brief Vertical Y acceleration type + */ + enum EAccVYType { + EAccVYType_None, //!< DPD is invalid + EAccVYType_Low, //!< Below average acceleration + EAccVYType_High, //!< Above average acceleration + }; + + //! DPD control stack size + static const int DPD_STACK_CAPACITY = 8; + + //! Number of samples to use for the vertical Y acceleration average + static const u32 ACC_VY_AVG_SAMPLES = 100; + + //! Buttons considered for cursor auto-repeat + static const u32 CURSOR_BUTTONS = + EGG::cCORE_BUTTON_UP | EGG::cCORE_BUTTON_DOWN | // + EGG::cCORE_BUTTON_LEFT | EGG::cCORE_BUTTON_RIGHT | // + EGG::cCORE_FSSTICK_UP | EGG::cCORE_FSSTICK_DOWN | // + EGG::cCORE_FSSTICK_LEFT | EGG::cCORE_FSSTICK_RIGHT; + + //! Cursor auto-repeat delay, in frames + static const u32 CURSOR_REPEAT_DELAY = 40; + //! Cursor auto-repeat rate, in frames + static const u32 CURSOR_REPEAT_RATE = 5; + +private: + /** + * @brief Creates a new controller object + */ + static EGG::CoreController* createCoreController(); + + /** + * @brief Becomes the main (Player 1) controller + */ + void becomeMainController(); + + /** + * @brief Assigns a new WPAD channel and address to this controller + * + * @param chan New WPAD channel + * @param rAddress New controller address + */ + void set(s32 chan, const RPSysCoreAddress& rAddress); + + /** + * @brief Updates the vertical Y acceleration statistics + */ + DECOMP_INLINE void updateAccVYMinMax(); + + /** + * @brief WPADGetInfoAsync callback + * + * @param chan Remote channel + * @param result WPAD library result + */ + static void getInfoCallback(s32 chan, s32 result); + +private: + //! Default threshold parameters for each extended status + static const f32 DEFAULT_EX_THRESHOLD[EExStatus_Max]; + //! Default rate parameters for each extended status + static const f32 DEFAULT_EX_RATE[EExStatus_Max]; + + //! Next player index + static s16 sNextPlayerNo; + + //! Player 1's controller + static RPSysCoreController* spMainController; + //! Player 1's controller address + static RPSysCoreAddress sMainAddress; + + //! Whether a controller has disconnected in this scene + static bool sDisconnectOccurred; + + //! Sensor bar height level + static f32 sSensorHeight; + + //! Last result from WPADProbe + s32 mWPADProbeResult; // at 0x900 + //! Controller event + EEvent mEvent; // at 0x904 + //! Assigned player ID + u32 mPlayerNo; // at 0x908 + + //! Held cursor buttons + u32 mCursorHold; // at 0x90C + //! How long the cursor buttons have been held + u32 mCursorHoldTime; // at 0x910 + //! Cursor buttons held during the previous frame + u32 mPrevCursorHold; // at 0x914 + //! Controller buttons to consider for cursor auto-repeat + u32 mCursorButtons; // at 0x918 + //! Delay for cursor auto-repeat + u32 mCursorRepeatDelay; // at 0x91C + //! Rate for cursor auto-repeat + u32 mCursorRepeatRate; // at 0x920 + + //! Vertical Y acceleration analysis result + EAccVYType mAccVYType; // at 0x924 + //! Minimum vertical Y acceleration + f32 mAccVYMin; // at 0x928 + //! Maximum vertical Y acceleration + f32 mAccVYMax; // at 0x92C + //! Number of vertical Y samples taken for averaging + u16 mAccVYSamples; // at 0x930 + + //! DPD control stack size + s16 mDpdCtrlStackSize; // at 0x932 + //! DPD control stack space + bool mDpdCtrlStack[DPD_STACK_CAPACITY]; // at 0x934 + + //! KPAD position parameter stack + ParamStack mPosParamStack; // at 0x93C + //! KPAD horizon parameter stack + ParamStack mHoriParamStack; // at 0x988 + //! KPAD distance parameter stack + ParamStack mDistParamStack; // at 0x9D4 + //! KPAD acceleration parameter stack + ParamStack mAccParamStack; // at 0xA20 + + //! Controller information + RPSysCoreInfo mCoreInfo; // at 0xA6C + //! Extended controller status + ExStatus mExStatus[EExStatus_Max]; // at 0xA88 + //! MAC address + RPSysCoreAddress mAddress; // at 0x2BA8 }; //! @} diff --git a/include/Pack/RPKernel/RPSysControllerMgr.h b/include/Pack/RPKernel/RPSysControllerMgr.h new file mode 100644 index 000000000..0b5fb65a7 --- /dev/null +++ b/include/Pack/RPKernel/RPSysControllerMgr.h @@ -0,0 +1,128 @@ +#ifndef RP_KERNEL_CONTROLLER_MGR_H +#define RP_KERNEL_CONTROLLER_MGR_H +#include + +#include + +#include + +//! @addtogroup rp_kernel +//! @{ + +// Forward declarations +class RPSysCoreController; +class RPSysPairingMgr; + +/** + * @brief Wii Remote controller manager + */ +class RPSysCoreControllerMgr : public EGG::CoreControllerMgr { + RP_SINGLETON_DECL(RPSysCoreControllerMgr); + +public: + /** + * @brief Initializes the controller manager singleton + */ + static void create(); + + /** + * @brief Performs processing at the beginning of the frame + */ + virtual void beginFrame() override; // at 0x8 + + /** + * @brief Performs processing at the end of the frame + */ + virtual void endFrame() override; // at 0xC + + /** + * @brief Accesses the controller using the specified channel + * + * @param chan Remote channel + */ + RPSysCoreController* findController(s32 chan) const; + + /** + * @brief Prepares the controller system for a scene reset + */ + void sceneReset(); + + /** + * @brief Enables pairing of controllers + */ + void enableConnection() const; + + /** + * @brief Disables pairing of controllers + */ + void disableConnection() const; + + /** + * @brief Tests whether DPD control is enabled for the specified remote + * channel + * + * @param chan Remote channel + */ + static bool isDpdCtrlEnable(s32 chan) { + return sDpdCtrlEnableFlag & (1 << chan); + } + +private: + /** + * @brief Controller search type + */ + enum ESearchType { + ESearchType_Address, //!< Find controllers by their address + ESearchType_Channel, //!< Find controllers by their remote channel + }; + + //! Required work memory size + static const u32 MIN_WORK_SIZE = 0x100000; + +private: + /** + * @brief Controller connect callback + * + * @param rArg Callback argument + */ + static void connectCallback(const EGG::CoreControllerConnectArg& rArg); + + /** + * @brief WPAD clear device callback + * + * @param result WPAD sync result + */ + static void clearDeviceCallback(s32 result); + + /** + * @brief WPAD DPD control callback + * + * @param chan Remote channel + * @param result WPAD DPD command + */ + static void controlDpdCallback(s32 chan, s32 result); + +private: + //! Bitfield of controllers currently connected + static u16 sConnectionFlag; + //! Bitfield of controllers connected during the previous frame + static u16 sPrevConnectionFlag; + + //! Bitfield of controllers with DPD control enabled + static u16 sDpdCtrlEnableFlag; + + //! Whether WPADClearDevice has completed + static bool sClearDeviceFlag; + + char unk30[0x60 - 0x30]; + + //! Controller search type + ESearchType mSearchType; // at 0x60 + + //! Controller pairing manager + RPSysPairingMgr* mpPairingMgr; // at 0x64 +}; + +//! @} + +#endif diff --git a/include/Pack/RPKernel/RPSysControllerSyncMgr.h b/include/Pack/RPKernel/RPSysControllerSyncMgr.h deleted file mode 100644 index e0a112fb8..000000000 --- a/include/Pack/RPKernel/RPSysControllerSyncMgr.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef RP_KERNEL_CONTROLLER_SYNC_MGR_H -#define RP_KERNEL_CONTROLLER_SYNC_MGR_H -#include - -//! @addtogroup rp_kernel -//! @{ - -/** - * @brief Controller synchronization manager - */ -class RPSysControllerSyncMgr { -public: - /** - * @brief Constructor - */ - RPSysControllerSyncMgr(); - - /** - * @brief Updates the sync state - */ - void calc(); - - /** - * @brief Sets whether syncing is enabled - * - * @param enabled Whether to enable syncing - */ - void setEnabled(bool enabled) { - mIsEnabled = enabled; - } - -private: - /** - * @brief Synchronization state - */ - enum ESyncState { - ESyncState_Start, //! Begin sync search - ESyncState_Stop, //!< End sync search - ESyncState_Wait, //!< Wait for results - }; - -private: - /** - * @brief WPAD simple sync callback - * - * @param result WPAD sync result - * @param num Number of synced controllers - */ - static void simpleSyncCallBack(s32 result, s32 num); - -private: - //! Whether the simple sync is currently ongoing - static bool sIsSyncing; - - //! Current sync state - ESyncState mSyncState; // at 0x0 - //! Whether syncing is enabled - bool mIsEnabled; // at 0x4 -}; - -//! @} - -#endif diff --git a/include/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.h b/include/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.h index 6fe29dfc7..d6eb816c9 100644 --- a/include/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.h +++ b/include/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.h @@ -28,7 +28,7 @@ class RPSysKokeshiCtrlDataMgr { //! Linked-list node NW4R_UT_LIST_LINK_DECL(); // at 0x0 //! Resource file descriptor - u16 rd; // at 0x8 + RPGrpHandle handle; // at 0x8 }; /** @@ -122,9 +122,9 @@ class RPSysKokeshiCtrlDataMgr { /** * @brief Appends a new file to the file resource list * - * @param rd File resource descriptor + * @param handle Resource handle */ - void appendFile(u16 rd); + void appendFile(RPGrpHandle handle); /** * @brief Appends a new model to the model resource list diff --git a/include/Pack/RPKernel/RPSysKokeshiCtrlMgr.h b/include/Pack/RPKernel/RPSysKokeshiCtrlMgr.h index d70db794f..196ba1082 100644 --- a/include/Pack/RPKernel/RPSysKokeshiCtrlMgr.h +++ b/include/Pack/RPKernel/RPSysKokeshiCtrlMgr.h @@ -104,9 +104,9 @@ class RPSysKokeshiCtrlMgr { * @brief Appends a new file to the file resource list * * @param chan WPAD channel of the data manager - * @param rd File resource descriptor + * @param handle Resource handle */ - void appendFile(s32 chan, u16 rd); + void appendFile(s32 chan, RPGrpHandle handle); /** * @brief Appends a new model to the model resource list diff --git a/include/Pack/RPKernel/RPSysPairingMgr.h b/include/Pack/RPKernel/RPSysPairingMgr.h new file mode 100644 index 000000000..7231711c7 --- /dev/null +++ b/include/Pack/RPKernel/RPSysPairingMgr.h @@ -0,0 +1,63 @@ +#ifndef RP_KERNEL_PAIRING_MGR_H +#define RP_KERNEL_PAIRING_MGR_H +#include + +//! @addtogroup rp_kernel +//! @{ + +/** + * @brief Controller pairing manager + */ +class RPSysPairingMgr { +public: + /** + * @brief Constructor + */ + RPSysPairingMgr(); + + /** + * @brief Updates the pairing state + */ + void calc(); + + /** + * @brief Sets whether pairing is enabled + * + * @param enabled Whether to enable pairing + */ + void setEnabled(bool enabled) { + mIsEnabled = enabled; + } + +private: + /** + * @brief Pairing state + */ + enum EPairingState { + EPairingState_Start, //! Begin sync search + EPairingState_Stop, //!< End sync search + EPairingState_Wait, //!< Wait for results + }; + +private: + /** + * @brief WPAD simple sync callback + * + * @param result WPAD sync result + * @param num Number of synced controllers + */ + static void simpleSyncCallback(s32 result, s32 num); + +private: + //! Whether pairing is ongoing + static bool sIsBusy; + + //! Current pairing state + EPairingState mPairingState; // at 0x0 + //! Whether pairing is enabled + bool mIsEnabled; // at 0x4 +}; + +//! @} + +#endif diff --git a/include/Pack/types_pack.h b/include/Pack/types_pack.h index 5063534a8..89a36115b 100644 --- a/include/Pack/types_pack.h +++ b/include/Pack/types_pack.h @@ -14,18 +14,27 @@ typedef u16 RPTime16; */ typedef u32 RPTime32; -/** - * @brief Maximum number of connected remotes - */ +//! Maximum number of connected remotes #define RP_MAX_CONTROLLERS 4 -/** - * @brief Maximum number of players - */ +//! Maximum number of players in Wii Sports +#define RP_SPORTS_MAX_PLAYERS 4 +//! Maximum number of players in Wii Play +#define RP_PARTY_MAX_PLAYERS 2 +//! Maximum number of players in Wii Fit +#define RP_HEALTH_MAX_PLAYERS 2 +//! Maximum number of players in Wii Music +#define RP_MUSIC_MAX_PLAYERS 2 + +//! Maximum number of players in the current pack #if defined(PACK_SPORTS) -#define RP_MAX_PLAYERS 4 +#define RP_MAX_PLAYERS RP_SPORTS_MAX_PLAYERS #elif defined(PACK_PARTY) -#define RP_MAX_PLAYERS 2 +#define RP_MAX_PLAYERS RP_PARTY_MAX_PLAYERS +#elif defined(PACK_HEALTH) +#define RP_MAX_PLAYERS RP_HEALTH_MAX_PLAYERS +#elif defined(PACK_MUSIC) +#define RP_MAX_PLAYERS RP_MUSIC_MAX_PLAYERS #endif /** diff --git a/include/egg/core/eggController.h b/include/egg/core/eggController.h index 6c26e24bc..ea59fde2c 100644 --- a/include/egg/core/eggController.h +++ b/include/egg/core/eggController.h @@ -3,7 +3,6 @@ #include #include - #include #include @@ -122,10 +121,10 @@ class CoreStatus : public KPADStatus { } bool isCore() const { - return getDevType() == WPAD_DEV_CORE || isFreestyle(); + return getDevType() == cDEV_CORE || isFreestyle(); } bool isFreestyle() const { - return getDevType() == WPAD_DEV_FREESTYLE; + return getDevType() == cDEV_FREESTYLE; } s8 getDPDValidFlag() const { @@ -222,17 +221,18 @@ class CoreController { void startMotor(); void stopMotor(); - void createRumbleMgr(u8 overlap_num); - void startPatternRumble(const char* pPattern, int frame, bool force); - void startPowerFrameRumble(f32 power, int frame, bool force); + void createRumbleMgr(u8 overlap_num = 1); + void startPatternRumble(const char* pPattern, int frame, + bool force = false); + void startPowerFrameRumble(f32 power, int frame, bool force = false); void stopRumbleMgr(); CoreStatus* getCoreStatus(int index); CoreStatus* getCoreStatus() { - return getCoreStatus(0); + return &mCoreStatus[0]; } -private: +protected: enum StableAxis { STABLE_AXIS_X, STABLE_AXIS_Y, @@ -249,10 +249,10 @@ class CoreController { STABLE_FLAG_XYZ = STABLE_FLAG_X | STABLE_FLAG_Y | STABLE_FLAG_Z }; -private: +protected: void calc_posture_matrix(Matrix34f& rPostureMtx, bool checkStable); -private: +protected: s32 mChannelID; // at 0x4 u32 mFSStickHold; // at 0x8 @@ -309,12 +309,21 @@ class CoreControllerMgr { CoreController* getNthController(int index); -private: + static void setCoreControllerFactory(CoreControllerFactory pFactory) { + sCoreControllerFactory = pFactory; + } + + static void setConnectCallback(CoreControllerConnectCallback pCallback) { + sConnectCallback = pCallback; + } + +protected: CoreControllerMgr(); +protected: static void connectCallback(s32 chan, s32 result); -private: +protected: TBuffer mControllers; // at 0x14 CoreControllerExtensionCallback* mExtensionCallback; // at 0x20 TBuffer mDevTypes; // at 0x24 diff --git a/include/egg/core/eggSingleton.h b/include/egg/core/eggSingleton.h index 52a0debdc..a298a8090 100644 --- a/include/egg/core/eggSingleton.h +++ b/include/egg/core/eggSingleton.h @@ -3,9 +3,9 @@ #include #include - #include + /** * @brief Declares functions and data for a disposable singleton class */ @@ -26,7 +26,7 @@ public: \ return sInstance; \ } \ \ -private: \ +protected: \ static T* sInstance; /** diff --git a/include/revolution/KPAD/KPAD.h b/include/revolution/KPAD/KPAD.h index 283c42ec4..e99e35c12 100644 --- a/include/revolution/KPAD/KPAD.h +++ b/include/revolution/KPAD/KPAD.h @@ -3,12 +3,26 @@ #include #include +#include + #ifdef __cplusplus extern "C" { #endif #define KPAD_MAX_SAMPLES 16 +typedef WPADCallback KPADCallback; + +typedef enum { + KPAD_CHAN0 = WPAD_CHAN0, + KPAD_CHAN1 = WPAD_CHAN1, + KPAD_CHAN2 = WPAD_CHAN2, + KPAD_CHAN3 = WPAD_CHAN3, + + KPAD_MAX_CONTROLLERS = WPAD_MAX_CONTROLLERS, + KPAD_CHAN_INVALID = WPAD_CHAN_INVALID +} KPADChannel; + typedef union KPADEXStatus { struct { Vec2 stick; // at 0x0 @@ -52,17 +66,24 @@ typedef struct KPADStatus { KPADEXStatus ex_status; // at 0x60 } KPADStatus; -void KPADSetBtnRepeat(s32 chan, f32, f32); +void KPADSetBtnRepeat(s32 chan, f32 delay_sec, f32 pulse_sec); void KPADSetPosParam(s32 chan, f32 playRadius, f32 sensitivity); void KPADSetHoriParam(s32 chan, f32 playRadius, f32 sensitivity); void KPADSetDistParam(s32 chan, f32 playRadius, f32 sensitivity); void KPADSetAccParam(s32 chan, f32 playRadius, f32 sensitivity); +void KPADSetSensorHeight(s32 chan, f32 level); + s32 KPADRead(s32 chan, KPADStatus* pSamples, s32 numSamples); void KPADInit(void); +void KPADSetControlDpdCallback(s32 chan, KPADCallback cb); + +void KPADDisableDPD(s32 chan); +void KPADEnableDPD(s32 chan); + #ifdef __cplusplus } #endif diff --git a/src/Pack/RPAudio/RPSndAudioMgr.cpp b/src/Pack/RPAudio/RPSndAudioMgr.cpp index bcb5f53c7..bbc722659 100644 --- a/src/Pack/RPAudio/RPSndAudioMgr.cpp +++ b/src/Pack/RPAudio/RPSndAudioMgr.cpp @@ -305,7 +305,7 @@ void RPSndAudioMgr::calc() { } } - SimpleAudioMgr::calc(); + EGG::SimpleAudioMgr::calc(); } RP_GET_INSTANCE(RPSndSpeakerMgr)->calc(); @@ -659,11 +659,8 @@ void RPSndAudioMgr::startPauseSe(const char* pNameRemote, const char* pNameTV, mPauseSePlayerFlag = 1 << player; mPauseSeChan = chan; + mPauseSePrevDpdEnable = RP_GET_CORE_CTRL(player)->isPrevDpdCtrlEnable(); - RPSysCoreController* pController = - RPSysCoreControllerMgr::getNthController(player); - - mPauseSePrevDpdEnable = pController->isPrevDpdCtrlEnable(); DAT_804bf648 = 0; } diff --git a/src/Pack/RPAudio/RPSndHomeMenuArcMgr.cpp b/src/Pack/RPAudio/RPSndHomeMenuArcMgr.cpp index 8e1a84cf9..1a55a87e7 100644 --- a/src/Pack/RPAudio/RPSndHomeMenuArcMgr.cpp +++ b/src/Pack/RPAudio/RPSndHomeMenuArcMgr.cpp @@ -32,5 +32,5 @@ void RPSndHomeMenuArcMgr::calc() { return; } - ArcPlayer::calc(); + EGG::ArcPlayer::calc(); } diff --git a/src/Pack/RPAudio/RPSndStaticMgr.cpp b/src/Pack/RPAudio/RPSndStaticMgr.cpp index b5c3cfe0d..00ecdd6b0 100644 --- a/src/Pack/RPAudio/RPSndStaticMgr.cpp +++ b/src/Pack/RPAudio/RPSndStaticMgr.cpp @@ -63,7 +63,7 @@ void RPSndStaticMgr::calc() { rTask.valid = false; } - ArcPlayer::calc(); + EGG::ArcPlayer::calc(); } /** diff --git a/src/Pack/RPKernel/RPSysController.cpp b/src/Pack/RPKernel/RPSysController.cpp new file mode 100644 index 000000000..f1689240f --- /dev/null +++ b/src/Pack/RPKernel/RPSysController.cpp @@ -0,0 +1,941 @@ +#include + +#include + +#include +#include + +#include +#include + +//! Sensor height when the bar is above the TV +#define SENSOR_HEIGHT_TOP 0.15f +//! Sensor height when the bar is below the TV +#define SENSOR_HEIGHT_BOTTOM -0.35f + +//! KPAD button repeat delay frequency +#define KPAD_DELAY_FREQ 1.5f +//! KPAD button repeat pulse frequency +#define KPAD_PULSE_FREQ 12.0f + +/** + * @brief Default threshold parameters for each extended status + */ +const f32 RPSysCoreController::DEFAULT_EX_THRESHOLD[EExStatus_Max] = { + 0.01f, // EExStatus_0 + 0.1f, // EExStatus_1 + 0.1f, // EExStatus_2 + 0.1f, // EExStatus_3 +}; + +/** + * @brief Default rate parameters for each extended status + */ +const f32 RPSysCoreController::DEFAULT_EX_RATE[EExStatus_Max] = { + 0.1f, // EExStatus_0 + 0.015f, // EExStatus_1 + 0.05f, // EExStatus_2 + 0.02f, // EExStatus_3 +}; + +/** + * @brief Next player index + */ +s16 RPSysCoreController::sNextPlayerNo = 0; + +/** + * @brief Player 1's controller + */ +RPSysCoreController* RPSysCoreController::spMainController = NULL; + +/** + * @brief Player 1's controller address + */ +RPSysCoreAddress RPSysCoreController::sMainAddress; + +/** + * @brief Whether a controller has disconnected in this scene + */ +bool RPSysCoreController::sDisconnectOccurred = false; + +/** + * @brief Sensor bar height level + */ +f32 RPSysCoreController::sSensorHeight = SENSOR_HEIGHT_TOP; + +/****************************************************************************** + * + * ParamStack + * + ******************************************************************************/ + +/** + * @brief Constructor + */ +RPSysCoreController::ParamStack::ParamStack() + : mSize(0), mInitialPlayRadius(0.0f), mInitialSensitivity(0.0f) { + + for (int i = 0; i < CAPACITY; i++) { + mPlayRadiusStack[i] = 0.0f; + mSensitivityStack[i] = 0.0f; + } +} + +/** + * @brief Clears the parameter stack + */ +void RPSysCoreController::ParamStack::reset() { + mSize = 0; + + for (int i = 0; i < CAPACITY; i++) { + mPlayRadiusStack[i] = 0.0f; + mSensitivityStack[i] = 0.0f; + } + + mPlayRadiusStack[0] = mInitialPlayRadius; + mSensitivityStack[0] = mInitialSensitivity; +} + +/** + * @brief Sets the initial parameters + * + * @param playRadius DPD play radius + * @param sensitivity DPD sensitivity + */ +void RPSysCoreController::ParamStack::configure(f32 playRadius, + f32 sensitivity) { + mInitialPlayRadius = playRadius; + mInitialSensitivity = sensitivity; +} + +/** + * @brief Sets the current parameters + * + * @param playRadius DPD play radius + * @param sensitivity DPD sensitivity + */ +void RPSysCoreController::ParamStack::set(f32 playRadius, f32 sensitivity) { + mPlayRadiusStack[mSize] = playRadius; + mSensitivityStack[mSize] = sensitivity; +} + +/** + * @brief Pushes the current parameter set onto the stack + */ +void RPSysCoreController::ParamStack::push() { + ++mSize; + + if (mSize >= 0 && mSize < CAPACITY) { + mPlayRadiusStack[mSize] = mInitialPlayRadius; + mSensitivityStack[mSize] = mInitialSensitivity; + } +} + +/** + * @brief Pops the top parameter set from the stack + */ +void RPSysCoreController::ParamStack::pop() { + if (mSize > 0) { + mSize--; + } +} + +/****************************************************************************** + * + * ExStatus + * + ******************************************************************************/ + +/** + * @brief Performs smoothing on an acceleration component + * + * @param pValue Value to modify + * @param target Smoothing target + * @param threshold Smoothing threshold + * @param rate Smoothing rate + */ +static void CalcAcc(f32* pValue, f32 target, f32 threshold, f32 rate) { + f32 t; + f32 delta = target - *pValue; + + if (delta < 0.0f) { + t = -delta; + } else { + t = delta; + } + + if (t >= threshold) { + t = 1.0f; + } else { + t /= threshold; + t *= t; + t *= t; + } + + t *= rate; + *pValue += t * delta; +} + +/** + * @brief Constructor + */ +RPSysCoreController::ExStatus::ExStatus() + : mPassThreshold(0.0f), mPassRate(1.0f) { + + std::memset(status, 0, sizeof(status)); +} + +/** + * @brief Sets the current parameters + * + * @param threshold Acceleration smoothing threshold + * @param rate Acceleration smoothing rate + */ +void RPSysCoreController::ExStatus::set(f32 threshold, f32 rate) { + mPassThreshold = threshold; + mPassRate = rate; +} + +/** + * @brief Updates the controller input state + * + * @param pStatusArray Controller sample set + * @param count Number of controler samples + */ +void RPSysCoreController::ExStatus::calc(EGG::CoreStatus* pStatusArray, + s32 count) { + Vec prev = status[0].acc; + + for (s32 i = count - 1; i >= 0; i--) { + EGG::CoreStatus* pOut = &status[i]; + Vec acc = prev; + + CalcAcc(&acc.x, pStatusArray[i].acc.x, mPassThreshold, mPassRate); + CalcAcc(&acc.y, pStatusArray[i].acc.y, mPassThreshold, mPassRate); + CalcAcc(&acc.z, pStatusArray[i].acc.z, mPassThreshold, mPassRate); + pOut->acc = acc; + + pOut->acc_value = + std::sqrtf(acc.x * acc.x + acc.y * acc.y + acc.z * acc.z); + + prev.x -= acc.x; + prev.y -= acc.y; + prev.z -= acc.z; + + pOut->acc_speed = + std::sqrtf(prev.x * prev.x + prev.y * prev.y + prev.z * prev.z); + + prev = acc; + } +} + +/****************************************************************************** + * + * RPSysCoreAddress + * + ******************************************************************************/ + +/** + * @brief Controller address work buffer + */ +u8 RPSysCoreAddress::sAddrWork[WPAD_ADDR_LEN] = {}; + +/** + * @brief Constructor + */ +RPSysCoreAddress::RPSysCoreAddress() { + reset(); +} + +/** + * @brief Clears the controller address + */ +void RPSysCoreAddress::reset() { + for (int i = 0; i < WPAD_ADDR_LEN; i++) { + mData[i] = 0; + } +} + +/** + * @brief Attempts to read the address of the specified controller + * + * @param chan Controller remote channel + * @return Success + */ +bool RPSysCoreAddress::read(s32 chan) { + int attempts = 0; + bool success = false; + + do { + WPADGetAddress(chan, sAddrWork); + attempts++; + success = false; + + for (int j = 0; j < WPAD_ADDR_LEN; j++) { + mData[j] = sAddrWork[j]; + } + + for (int j = 0; j < WPAD_ADDR_LEN; j++) { + if (mData[j] != 0) { + success = true; + break; + } + } + } while (!success && attempts < RETRY_NUM); + + return success; +} + +/** + * @brief Sets the value of this controller address + * + * @param pData New controller address + */ +void RPSysCoreAddress::set(const u8* pData) { + std::memcpy(mData, pData, sizeof(mData)); +} + +/** + * @brief Gets the specified digit of this address + * + * @param idx Digit index + */ +u8 RPSysCoreAddress::get(int idx) const { + return mData[idx]; +} + +/** + * @brief Tests whether this controller address is valid + */ +bool RPSysCoreAddress::isValid() const { + bool valid = false; + + for (int i = 0; i < WPAD_ADDR_LEN; i++) { + if (mData[i] != 0) { + valid = true; + break; + } + } + + return valid; +} + +/** + * @brief Tests whether two controller addresses are equivalent + * + * @param rOther Other controller address + */ +bool RPSysCoreAddress::isEqual(const RPSysCoreAddress& rOther) const { + bool same = true; + + for (int i = 0; i < WPAD_ADDR_LEN; i++) { + if (mData[i] != rOther.mData[i]) { + same = false; + break; + } + } + + return same; +} + +/****************************************************************************** + * + * RPSysCoreInfo + * + ******************************************************************************/ + +/** + * @brief Constructor + */ +RPSysCoreInfo::RPSysCoreInfo() { + reset(); +} + +/** + * @brief Clears the controller information + */ +void RPSysCoreInfo::reset() { + std::memset(this, 0, sizeof(*this)); + mFlags = 0; // double clear :p +} + +/** + * @brief Tests whether the controller battery level is low + */ +bool RPSysCoreInfo::isLowBattery() const { + bool isLow = false; + + if (mFlags & EFlag_GetInfoSuccess) { + switch (battery) { + case 0: + case 1: { + isLow = true; + break; + + default: { + break; + } + } + } + } + + return isLow; +} + +/****************************************************************************** + * + * RPSysCoreController + * + ******************************************************************************/ + +/** + * @brief Creates a new controller object + */ +EGG::CoreController* RPSysCoreController::createCoreController() { + RPSysCoreController* pController = new RPSysCoreController(sNextPlayerNo++); + + if (spMainController == NULL) { + pController->becomeMainController(); + } + + return pController; +} + +/** + * @brief Initializes the controller system + */ +void RPSysCoreController::initialize() { + RPSysCoreControllerMgr::setCoreControllerFactory(createCoreController); + RPSysCoreControllerMgr::create(); + + f32 delay = 1.0f / KPAD_DELAY_FREQ; + f32 pulse = 1.0f / KPAD_PULSE_FREQ; + + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + KPADSetSensorHeight(i, sSensorHeight); + KPADSetBtnRepeat(i, delay, pulse); + } + + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->createRumbleMgr(); + } + + sDisconnectOccurred = false; +} + +/** + * @brief Tests whether the sensor bar is positioned above the TV + */ +bool RPSysCoreController::isSensorBarTop() { + return WPADGetSensorBarPosition() == WPAD_SENSOR_BAR_TOP; +} + +/** + * @brief Applies global controller settings + */ +void RPSysCoreController::applySetting() { + if (isSensorBarTop()) { + sSensorHeight = SENSOR_HEIGHT_TOP; + } else { + sSensorHeight = SENSOR_HEIGHT_BOTTOM; + } + + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + KPADSetSensorHeight(i, sSensorHeight); + } +} + +/** + * @brief Prepares the controller system for a scene reset + */ +void RPSysCoreController::sceneReset() { + RP_GET_INSTANCE(RPSysCoreControllerMgr)->sceneReset(); +} + +/** + * @brief Forcibly turns on the sensor bar + */ +void RPSysCoreController::forceSensorBarPowerOn() { + WPADSetSensorBarPower(TRUE); +} + +/** + * @brief Prepares the controller system for a new scene + */ +void RPSysCoreController::initScene() { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->mPosParamStack.reset(); + RP_GET_CORE_CTRL(i)->mHoriParamStack.reset(); + RP_GET_CORE_CTRL(i)->mDistParamStack.reset(); + RP_GET_CORE_CTRL(i)->mAccParamStack.reset(); + RP_GET_CORE_CTRL(i)->resetDpdCtrlStack(); + } + + forceSensorBarPowerOn(); + sDisconnectOccurred = false; +} + +/** + * @brief Constructor + * + * @param playerNo Player ID + */ +RPSysCoreController::RPSysCoreController(u32 playerNo) { + mWPADProbeResult = WPAD_ERR_NO_CONTROLLER; + mEvent = EEvent_None; + mPlayerNo = playerNo; + + mCursorHold = 0; + mCursorHoldTime = 0; + mPrevCursorHold = 0; + mCursorButtons = CURSOR_BUTTONS; + mCursorRepeatDelay = CURSOR_REPEAT_DELAY; + mCursorRepeatRate = CURSOR_REPEAT_RATE; + + mAccVYType = EAccVYType_None; + mAccVYMin = 0.0f; + mAccVYMax = 0.0f; + mAccVYSamples = 0; + + resetDpdCtrlStack(); + + mPosParamStack.configure(0.06f, 1.0f); + mHoriParamStack.configure(0.0f, 1.0f); + mDistParamStack.configure(0.0f, 1.0f); + mAccParamStack.configure(0.0f, 1.0f); + + for (int i = 0; i < EExStatus_Max; i++) { + setExAccParam(i, DEFAULT_EX_THRESHOLD[i], DEFAULT_EX_RATE[i]); + } +} + +/** + * @brief Destructor + */ +RPSysCoreController::~RPSysCoreController() {} + +/** + * @brief Sets the parameters for the specified extended status + * + * @param idx Extended status index + * @param threshold Smoothing threshold + * @param rate Smoothing rate + */ +void RPSysCoreController::setExAccParam(int idx, f32 threshold, f32 rate) { + mExStatus[idx].set(threshold, rate); +} + +/** + * @brief Accesses the specified core status + * + * @param idx Extended status index + * @param sample Core status sample index + */ +EGG::CoreStatus* RPSysCoreController::getExCoreStatus(int idx, int sample) { + return mExStatus[idx].getCoreStatus(sample); +} + +/** + * @brief Performs processing at the beginning of the frame + * + * @param pStatus GameCube controller status (for debugging?) + */ +void RPSysCoreController::beginFrame(PADStatus* pStatus) { + s32 devType; + mWPADProbeResult = WPADProbe(mChannelID, &devType); + + if (mDpdCtrlStack[mDpdCtrlStackSize]) { + KPADEnableDPD(mChannelID); + } else { + KPADDisableDPD(mChannelID); + } + + KPADSetPosParam(mChannelID, // + mPosParamStack.getPlayRadius(), + mPosParamStack.getSensitivity()); + + KPADSetHoriParam(mChannelID, // + mHoriParamStack.getPlayRadius(), + mHoriParamStack.getSensitivity()); + + KPADSetDistParam(mChannelID, // + mDistParamStack.getPlayRadius(), + mDistParamStack.getSensitivity()); + + KPADSetAccParam(mChannelID, // + mAccParamStack.getPlayRadius(), + mAccParamStack.getSensitivity()); + + EGG::CoreController::beginFrame(pStatus); + + if (mWPADProbeResult == WPAD_ERR_NO_CONTROLLER) { + getCoreStatus()->hold = 0; + getCoreStatus()->trig = 0; + getCoreStatus()->release = 0; + } + + mCursorHold = 0; + u32 nowHold = mCursorButtons & getCoreStatus()->hold; + + if (nowHold == 0) { + mPrevCursorHold = 0; + mCursorHoldTime = 0; + } else { + u32 prevHold = mPrevCursorHold; + + if (prevHold == nowHold) { + u32 time = ++mCursorHoldTime; + + if (time == mCursorRepeatDelay || + (time > mCursorRepeatDelay && + (time - mCursorRepeatDelay) % mCursorRepeatRate == 0)) { + + mCursorHold = nowHold; + } + } else { + mPrevCursorHold = nowHold; + mCursorHoldTime = 0; + + mCursorHold = nowHold & (0xFFFFFFFF ^ prevHold); + } + } + + for (int i = 0; i < EExStatus_Max; i++) { + mExStatus[i].calc(mCoreStatus, mKPADReadLength); + } + + updateAccVYMinMax(); +} + +/** + * @brief Becomes the main (Player 1) controller + */ +void RPSysCoreController::becomeMainController() { + spMainController = this; + sMainAddress = mAddress; +} + +/** + * @brief Shuts down the controller system + * + * @param forIpl Whether the program is exiting to the IPL + */ +void RPSysCoreController::shutdownSystem(bool /* forIpl */) {} + +/** + * @brief Turns off the rumble motor in all controllers + */ +void RPSysCoreController::stopMotorAll() { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->stopMotor(); + } +} + +/** + * @brief Starts the specified rumble pattern + * + * @param pattern Rumble pattern + */ +void RPSysCoreController::rumble(ERumblePattern pattern) { + switch (pattern) { + case ERumblePattern_Cursor: { + startPatternRumble("****--------", sizeof("****--------") - 1); + break; + } + + case ERumblePattern_Connect: + case ERumblePattern_2: + case ERumblePattern_Change: { + startPatternRumble("***-***---*", sizeof("***-***---*") - 1); + break; + } + + default: { + break; + } + } +} + +/** + * @brief Tests whether this controller's base device (no extension) is a + * Wii Remote controller + */ +bool RPSysCoreController::isCoreBaseDevice() const { + bool isCore = false; + + if (mWPADProbeResult != WPAD_ERR_NO_CONTROLLER) { + switch (getDevType()) { + case EGG::cDEV_CORE: + case EGG::cDEV_FREESTYLE: + case EGG::cDEV_CLASSIC: + case EGG::cDEV_FUTURE: + case EGG::cDEV_NOT_SUPPORTED: + case EGG::cDEV_UNKNOWN: { + isCore = true; + break; + } + + case EGG::cDEV_NOT_FOUND: + case EGG::cDEV_NULL: + default: { + break; + } + } + } + + return isCore; +} + +/** + * @brief Enables pairing of controllers + */ +void RPSysCoreController::enableConnection() { + RP_GET_INSTANCE(RPSysCoreControllerMgr)->enableConnection(); +} + +/** + * @brief Disables pairing of controllers + */ +void RPSysCoreController::disableConnection() { + RP_GET_INSTANCE(RPSysCoreControllerMgr)->disableConnection(); +} + +/** + * @brief Assigns a new WPAD channel and address to this controller + * + * @param chan New WPAD channel + * @param rAddress New controller address + */ +void RPSysCoreController::set(s32 chan, const RPSysCoreAddress& rAddress) { + mChannelID = chan; + mAddress = rAddress; +} + +/** + * @brief Toggles whether DPD control is enabled + * + * @param enable Whether to enable DPD control + */ +void RPSysCoreController::enableDpdCtrl(bool enable) { + if (mDpdCtrlStackSize >= 0 && mDpdCtrlStackSize < DPD_STACK_CAPACITY) { + mDpdCtrlStack[mDpdCtrlStackSize] = enable; + } +} + +/** + * @brief Disables DPD control for all controllers + */ +void RPSysCoreController::disableDpdCtrlAll() { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->enableDpdCtrl(false); + } +} + +/** + * @brief Resets the state of the DPD control stack + */ +void RPSysCoreController::resetDpdCtrlStack() { + mDpdCtrlStackSize = 0; + + for (int i = 0; i < DPD_STACK_CAPACITY; i++) { + mDpdCtrlStack[i] = true; + } +} + +/** + * @brief Pushes a new value to the DPD control stack + * + * @param enable Whether to enable DPD control + */ +void RPSysCoreController::pushDpdCtrlStack(bool enable) { + ++mDpdCtrlStackSize; + + if (mDpdCtrlStackSize >= 0 && mDpdCtrlStackSize < DPD_STACK_CAPACITY) { + mDpdCtrlStack[mDpdCtrlStackSize] = enable; + } +} + +/** + * @brief Pushes a new value to the DPD control stack for all controllers + * + * @param enable Whether to enable DPD control + */ +void RPSysCoreController::pushDpdCtrlStackAll(bool enable) { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->pushDpdCtrlStack(enable); + } +} + +/** + * @brief Pops the top value from the DPD control stack + */ +void RPSysCoreController::popDpdCtrlStack() { + if (mDpdCtrlStackSize > 0) { + mDpdCtrlStackSize--; + } +} + +/** + * @brief Pops the top value from the DPD control stack for all controllers + */ +void RPSysCoreController::popDpdCtrlStackAll() { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->popDpdCtrlStack(); + } +} + +/** + * @brief Tests whether DPD control was enabled at the previous stack level + */ +bool RPSysCoreController::isPrevDpdCtrlEnable() { + s16 prev = mDpdCtrlStackSize - 1; + + if (prev < 0) { + prev = 0; + } + + return mDpdCtrlStack[prev]; +} + +/** + * @brief Sets the KPAD position parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ +void RPSysCoreController::setPosParam(f32 playRadius, f32 sensitivity) { + mPosParamStack.set(playRadius, sensitivity); +} + +/** + * @brief Sets the KPAD horizon parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ +void RPSysCoreController::setHoriParam(f32 playRadius, f32 sensitivity) { + mHoriParamStack.set(playRadius, sensitivity); +} + +/** + * @brief Sets the KPAD distance parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ +void RPSysCoreController::setDistParam(f32 playRadius, f32 sensitivity) { + mDistParamStack.set(playRadius, sensitivity); +} + +/** + * @brief Sets the KPAD acceleration parameters + * + * @param playRadius Play radius parameter + * @param sensitivity Sensitivity parameter + */ +void RPSysCoreController::setAccParam(f32 playRadius, f32 sensitivity) { + mAccParamStack.set(playRadius, sensitivity); +} + +/** + * @brief Pushes the current KPAD parameter set onto the stack for all + * controllers + */ +void RPSysCoreController::pushKPADParamStackAll() { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->mPosParamStack.push(); + RP_GET_CORE_CTRL(i)->mHoriParamStack.push(); + RP_GET_CORE_CTRL(i)->mDistParamStack.push(); + RP_GET_CORE_CTRL(i)->mAccParamStack.push(); + } +} + +/** + * @brief Pops the top KPAD parameter set from the stack for all controllers + */ +void RPSysCoreController::popKPADParamStackAll() { + for (int i = 0; i < RP_MAX_CONTROLLERS; i++) { + RP_GET_CORE_CTRL(i)->mPosParamStack.pop(); + RP_GET_CORE_CTRL(i)->mHoriParamStack.pop(); + RP_GET_CORE_CTRL(i)->mDistParamStack.pop(); + RP_GET_CORE_CTRL(i)->mAccParamStack.pop(); + } +} + +/** + * @brief Updates the vertical Y acceleration statistics + */ +void RPSysCoreController::updateAccVYMinMax() { + // TODO(kiwi) What is this flag value? + if (getCoreStatus()->getDPDValidFlag() == 2) { + if (mAccVYSamples < ACC_VY_AVG_SAMPLES) { + mAccVYSamples++; + } + + mAccVYMin += (getCoreStatus()->acc_vertical.y - mAccVYMin) * 0.05f; + mAccVYMax += (getCoreStatus()->acc_vertical.y - mAccVYMax) * 0.05f; + } else { + mAccVYSamples = 0; + } + + if (mAccVYSamples >= ACC_VY_AVG_SAMPLES) { + if (getCoreStatus()->acc_vertical.y < mAccVYMin) { + mAccVYMin = getCoreStatus()->acc_vertical.y; + } + + if (getCoreStatus()->acc_vertical.y > mAccVYMax) { + mAccVYMax = getCoreStatus()->acc_vertical.y; + } + } + + // TODO(kiwi) What is this flag value? + if (getCoreStatus()->getDPDValidFlag() == 0) { + if (getCoreStatus()->acc_vertical.y > (mAccVYMin + mAccVYMax) * 0.5f) { + mAccVYType = EAccVYType_High; + } else { + mAccVYType = EAccVYType_Low; + } + } else { + mAccVYType = EAccVYType_None; + } +} + +/** + * @brief WPADGetInfoAsync callback + * + * @param chan Remote channel + * @param result WPAD library result + */ +void RPSysCoreController::getInfoCallback(s32 chan, s32 result) { + RPSysCoreController* p = + RP_GET_INSTANCE(RPSysCoreControllerMgr)->findController(chan); + + if (p == NULL) { + return; + } + + if (result == WPAD_ERR_OK) { + p->mCoreInfo.mFlags |= RPSysCoreInfo::EFlag_GetInfoSuccess; + } + + p->mCoreInfo.mFlags |= RPSysCoreInfo::EFlag_GetInfoFail; +} + +/** + * @brief Attempts to read the controller information + * + * @return Success + */ +bool RPSysCoreController::requestCoreInfoAsync() { + bool success = false; + mCoreInfo.reset(); + + s32 result = WPADGetInfoAsync(mChannelID, &mCoreInfo, getInfoCallback); + if (result == WPAD_ERR_OK) { + success = true; + } else { + mCoreInfo.mFlags |= RPSysCoreInfo::EFlag_GetInfoFail; + } + + return success; +} diff --git a/src/Pack/RPKernel/RPSysControllerMgr.cpp b/src/Pack/RPKernel/RPSysControllerMgr.cpp new file mode 100644 index 000000000..4f1df3624 --- /dev/null +++ b/src/Pack/RPKernel/RPSysControllerMgr.cpp @@ -0,0 +1,364 @@ +#include +#include +#include +#include +#include + +#include + +#include +#include + +/** + * @brief Bitfield of controllers currently connected + */ +u16 RPSysCoreControllerMgr::sConnectionFlag = 0; + +/** + * @brief Bitfield of controllers connected during the previous frame + */ +u16 RPSysCoreControllerMgr::sPrevConnectionFlag = 0; + +/** + * @brief Bitfield of controllers with DPD control enabled + */ +u16 RPSysCoreControllerMgr::sDpdCtrlEnableFlag = 0; + +/** + * @brief Whether WPADClearDevice has completed + */ +bool RPSysCoreControllerMgr::sClearDeviceFlag = false; + +RP_SINGLETON_IMPL(RPSysCoreControllerMgr); + +/** + * @brief Constructor + */ +RPSysCoreControllerMgr::RPSysCoreControllerMgr() + : mSearchType(ESearchType_Channel) { + + mpPairingMgr = new RPSysPairingMgr(); +} + +/** + * @brief Controller connect callback + * + * @param rArg Callback argument + */ +void RPSysCoreControllerMgr::connectCallback( + const EGG::CoreControllerConnectArg& rArg) { + + switch (rArg.result) { + case WPAD_ERR_OK: { + sConnectionFlag |= 1 << rArg.chan; + RPSndSpeakerMgr::setSpeakerOnCallback(rArg.chan, rArg.result); + break; + } + + case WPAD_ERR_NO_CONTROLLER: { + sConnectionFlag &= ~(1 << rArg.chan); + RPSndSpeakerMgr::setSpeakerOffCallback(rArg.chan, rArg.result); + break; + } + } +} + +/** + * @brief WPAD clear device callback + * + * @param result WPAD sync result + */ +void RPSysCoreControllerMgr::clearDeviceCallback(s32 result) { + switch (result) { + case WPAD_SYNC_WAITING: { + WPADStartClearDevice(); + break; + } + + case WPAD_SYNC_DONE: { + sClearDeviceFlag = true; + break; + } + + case WPAD_SYNC_BUSY: + default: { + break; + } + } +} + +/** + * @brief WPAD DPD control callback + * + * @param chan Remote channel + * @param result WPAD DPD command + */ +void RPSysCoreControllerMgr::controlDpdCallback(s32 chan, s32 result) { + switch (result) { + case WPAD_DPD_BASIC: { + if (WPADIsDpdEnabled(chan)) { + sDpdCtrlEnableFlag |= 1 << chan; + } else { + sDpdCtrlEnableFlag &= ~(1 << chan); + } + break; + } + + case WPAD_DPD_DISABLE: + default: { + break; + } + } +} + +/** + * @brief Initializes the controller manager singleton + */ +void RPSysCoreControllerMgr::create() { + u32 workSize = WPADGetWorkMemorySize(); + if (workSize <= MIN_WORK_SIZE) { + workSize = MIN_WORK_SIZE; + } + + sWPADWorkSize = workSize; + + // Override the EGG manager + RPSysCoreControllerMgr* p = new RPSysCoreControllerMgr(); + EGG::CoreControllerMgr::sInstance = p; + spInstance = p; + + WPADSetClearDeviceCallback(clearDeviceCallback); + setConnectCallback(connectCallback); + + for (s32 i = 0; i < RP_MAX_CONTROLLERS; i++) { + KPADSetControlDpdCallback(i, controlDpdCallback); + } +} + +/** + * @brief Accesses the controller using the specified channel + * + * @param chan Remote channel + */ +RPSysCoreController* RPSysCoreControllerMgr::findController(s32 chan) const { + RPSysCoreController* pFound = NULL; + + for (int i = 0; i < mControllers.getSize(); i++) { + RPSysCoreController* pIt = + static_cast(mControllers.get(i)); + + if (pIt->getChannelID() == chan) { + pFound = pIt; + break; + } + } + + return pFound; +} + +/** + * @brief Prepares the controller system for a scene reset + */ +void RPSysCoreControllerMgr::sceneReset() { + u16 connected = sConnectionFlag; + + for (int i = 0; i < mControllers.getSize(); i++) { + RPSysCoreController* pIt = + static_cast(mControllers.get(i)); + + if (connected & 1 << pIt->getChannelID()) { + continue; + } + + pIt->getAddress().reset(); + + // Find the next connected controller in the order + RPSysCoreController* pTarget = NULL; + for (int j = i + 1; j < mControllers.getSize(); j++) { + RPSysCoreController* pIt = + static_cast(mControllers.get(j)); + + if (connected & 1 << pIt->getChannelID()) { + pTarget = pIt; + break; + } + } + + // Swap the data, moving all connected controllers towards the front + if (pTarget != NULL) { + s32 fromChan = pIt->getChannelID(); + RPSysCoreAddress fromAddr = pIt->getAddress(); + + s32 toChan = pTarget->getChannelID(); + RPSysCoreAddress toAddr = pTarget->getAddress(); + + pIt->set(toChan, toAddr); + pTarget->set(fromChan, fromAddr); + } + } +} + +/** + * @brief Performs processing at the beginning of the frame + */ +void RPSysCoreControllerMgr::beginFrame() { + u16 connected = sConnectionFlag; + u16 prevConnected = sPrevConnectionFlag; + + // Newly connected controllers + u16 connectOn = connected & (connected ^ prevConnected); + // Newly disconnected controllers + u16 connectOff = prevConnected & (connected ^ prevConnected); + + sPrevConnectionFlag = connected; + + if (sClearDeviceFlag) { + sClearDeviceFlag = false; + } + + for (int i = 0; i < mControllers.getSize(); i++) { + RPSysCoreController* pIt = + static_cast(mControllers.get(i)); + + pIt->mEvent = RPSysCoreController::EEvent_None; + } + + s32 chan = 0; + + do { + if (connectOn & 1 << chan) { + RPSysCoreAddress addr; + addr.read(chan); + + if (addr.isValid()) { + RPSysCoreController* pConnected; + + // Try to find the controller that belongs to this connection + switch (mSearchType) { + case ESearchType_Channel: { + pConnected = findController(chan); + break; + } + + default: /* ESearchType_Address */ { + int players = mControllers.getSize(); + + if (RP_GET_INSTANCE(RPSysProjectLocal) != NULL) { + switch (RP_GET_INSTANCE(RPSysProjectLocal)->getPack()) { + case RPSysSceneCreator::EPackID_PartyPack: { + players = RP_PARTY_MAX_PLAYERS; + break; + } + + default: { + break; + } + } + } + + pConnected = NULL; + + for (int i = 0; i < players; i++) { + if (i >= mControllers.getSize()) { + continue; // ??? + } + + RPSysCoreController* pIt = + static_cast( + mControllers.get(i)); + + if (pIt->getAddress().isEqual(addr)) { + pConnected = pIt; + break; + } + } + break; + } + } + + // Take the first available controller instead + if (pConnected == NULL) { + pConnected = NULL; // ??? + + for (int i = 0; i < mControllers.getSize(); i++) { + RPSysCoreController* pIt = + static_cast( + mControllers.get(i)); + + if ((connectOn & 1 << pIt->getChannelID()) || + !(prevConnected & 1 << pIt->getChannelID())) { + + pConnected = pIt; + break; + } + } + } + + // Swap the controller assignment + if (pConnected != NULL) { + RPSysCoreController* pChanOwner = findController(chan); + + if (pChanOwner != pConnected) { + RPSysCoreAddress foundAddr = pConnected->getAddress(); + pChanOwner->set(pConnected->getChannelID(), foundAddr); + } + + pConnected->set(chan, addr); + + if (pConnected->mPlayerNo == 0) { + pConnected->becomeMainController(); + } + + pConnected->rumble( + RPSysCoreController::ERumblePattern_Connect); + + RP_GET_INSTANCE(RPSndAudioMgr) + ->getStaticMgr() + .startSe(rp_STATIC_CONNECT_01_CTSP, + pConnected->mPlayerNo); + + pConnected->mEvent = RPSysCoreController::EEvent_Connect; + } + } + + RPSysCoreController::forceSensorBarPowerOn(); + } + + if (connectOff & 1 << chan) { + RPSysCoreController* pDisconnected = findController(chan); + pDisconnected->mEvent = RPSysCoreController::EEvent_Disconnect; + + RPSysCoreController::sDisconnectOccurred = true; + } + + } while (++chan < RP_MAX_CONTROLLERS); + + EGG::CoreControllerMgr::beginFrame(); + mpPairingMgr->calc(); + + // Old data becomes invalid when controller configuration changes + if (connectOff & (1 << RP_MAX_CONTROLLERS) - 1) { + RP_GET_INSTANCE(RPSysPlayerMgr)->resetOldData(); + } +} + +/** + * @brief Performs processing at the end of the frame + */ +void RPSysCoreControllerMgr::endFrame() { + EGG::CoreControllerMgr::endFrame(); +} + +/** + * @brief Enables pairing of controllers + */ +void RPSysCoreControllerMgr::enableConnection() const { + mpPairingMgr->setEnabled(true); +} + +/** + * @brief Disables pairing of controllers + */ +void RPSysCoreControllerMgr::disableConnection() const { + mpPairingMgr->setEnabled(false); +} diff --git a/src/Pack/RPKernel/RPSysControllerSyncMgr.cpp b/src/Pack/RPKernel/RPSysControllerSyncMgr.cpp deleted file mode 100644 index 609f639ff..000000000 --- a/src/Pack/RPKernel/RPSysControllerSyncMgr.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include - -#include - -/** - * @brief Whether the simple sync is currently ongoing - */ -bool RPSysControllerSyncMgr::sIsSyncing = false; - -/** - * @brief WPAD simple sync callback - * - * @param result WPAD sync result - * @param num Number of synced controllers - */ -void RPSysControllerSyncMgr::simpleSyncCallBack(s32 result, s32 /* num*/) { - switch (result) { - case WPAD_SYNC_WAITING: { - break; - } - - case WPAD_SYNC_BUSY: { - sIsSyncing = false; - break; - } - - case WPAD_SYNC_DONE: { - sIsSyncing = false; - break; - } - - default: { - break; - } - } -} - -/** - * @brief Constructor - */ -RPSysControllerSyncMgr::RPSysControllerSyncMgr() - : mSyncState(ESyncState_Start), mIsEnabled(false) { - - WPADSetSimpleSyncCallback(simpleSyncCallBack); -} - -/** - * @brief Updates the sync state - */ -void RPSysControllerSyncMgr::calc() { - switch (mSyncState) { - case ESyncState_Start: { - if (!mIsEnabled) { - break; - } - - if (WPADStartSimpleSync()) { - mSyncState = ESyncState_Stop; - sIsSyncing = true; - } - break; - } - - case ESyncState_Stop: { - if (mIsEnabled) { - break; - } - - if (WPADStopSimpleSync()) { - mSyncState = ESyncState_Wait; - } - break; - } - - case ESyncState_Wait: { - if (!sIsSyncing) { - mSyncState = ESyncState_Start; - } - break; - } - } -} diff --git a/src/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.cpp b/src/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.cpp index 945bebe9e..26012574e 100644 --- a/src/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.cpp +++ b/src/Pack/RPKernel/RPSysKokeshiCtrlDataMgr.cpp @@ -117,11 +117,11 @@ void RPSysKokeshiCtrlDataMgr::createResource() { /** * @brief Appends a new file to the file resource list * - * @param rd File resource descriptor + * @param handle Resource handle */ -void RPSysKokeshiCtrlDataMgr::appendFile(u16 rd) { +void RPSysKokeshiCtrlDataMgr::appendFile(RPGrpHandle handle) { FileResource* pResFile = new (mpHeap) FileResource(); - pResFile->rd = rd; + pResFile->handle = handle; nw4r::ut::List_Append(&mResourceList, pResFile); } @@ -185,7 +185,7 @@ void RPSysKokeshiCtrlDataMgr::resetData() { RPGrpModelResManager* pResManager = RPGrpModelResManager::GetCurrent(); NW4R_UT_LIST_FOREACH_SAFE (FileResource, it, mResourceList, { - pResManager->Terminate(it->rd); + pResManager->Terminate(it->handle); nw4r::ut::List_Remove(&mResourceList, it); }) diff --git a/src/Pack/RPKernel/RPSysKokeshiCtrlMgr.cpp b/src/Pack/RPKernel/RPSysKokeshiCtrlMgr.cpp index e3849d4c5..70b8fecc8 100644 --- a/src/Pack/RPKernel/RPSysKokeshiCtrlMgr.cpp +++ b/src/Pack/RPKernel/RPSysKokeshiCtrlMgr.cpp @@ -88,10 +88,10 @@ EGG::Heap* RPSysKokeshiCtrlMgr::getResourceHeap(s32 chan) { * @brief Appends a new file to the file resource list * * @param chan WPAD channel of the data manager - * @param rd File resource descriptor + * @param handle Resource handle */ -void RPSysKokeshiCtrlMgr::appendFile(s32 chan, u16 rd) { - mpDataMgrs[chan]->appendFile(rd); +void RPSysKokeshiCtrlMgr::appendFile(s32 chan, RPGrpHandle handle) { + mpDataMgrs[chan]->appendFile(handle); } /** diff --git a/src/Pack/RPKernel/RPSysPairingMgr.cpp b/src/Pack/RPKernel/RPSysPairingMgr.cpp new file mode 100644 index 000000000..b1a61d125 --- /dev/null +++ b/src/Pack/RPKernel/RPSysPairingMgr.cpp @@ -0,0 +1,82 @@ +#include + +#include + +/** + * @brief Whether pairing is ongoing + */ +bool RPSysPairingMgr::sIsBusy = false; + +/** + * @brief WPAD simple sync callback + * + * @param result WPAD sync result + * @param num Number of synced controllers + */ +void RPSysPairingMgr::simpleSyncCallback(s32 result, s32 /* num*/) { + switch (result) { + case WPAD_SYNC_WAITING: { + break; + } + + case WPAD_SYNC_BUSY: { + sIsBusy = false; + break; + } + + case WPAD_SYNC_DONE: { + sIsBusy = false; + break; + } + + default: { + break; + } + } +} + +/** + * @brief Constructor + */ +RPSysPairingMgr::RPSysPairingMgr() + : mPairingState(EPairingState_Start), mIsEnabled(false) { + + WPADSetSimpleSyncCallback(simpleSyncCallback); +} + +/** + * @brief Updates the pairing state + */ +void RPSysPairingMgr::calc() { + switch (mPairingState) { + case EPairingState_Start: { + if (!mIsEnabled) { + break; + } + + if (WPADStartSimpleSync()) { + mPairingState = EPairingState_Stop; + sIsBusy = true; + } + break; + } + + case EPairingState_Stop: { + if (mIsEnabled) { + break; + } + + if (WPADStopSimpleSync()) { + mPairingState = EPairingState_Wait; + } + break; + } + + case EPairingState_Wait: { + if (!sIsBusy) { + mPairingState = EPairingState_Start; + } + break; + } + } +} diff --git a/src/Pack/RPSystem/RPSysPlayerMgr.cpp b/src/Pack/RPSystem/RPSysPlayerMgr.cpp index 04355834c..a573bf071 100644 --- a/src/Pack/RPSystem/RPSysPlayerMgr.cpp +++ b/src/Pack/RPSystem/RPSysPlayerMgr.cpp @@ -186,10 +186,9 @@ bool RPSysPlayerMgr::isValidOldData() { continue; } - RPSysCoreController* pController = - RPSysCoreControllerMgr::getNthController(player); + if (RP_GET_CORE_CTRL(player)->getAddress().isEqual( + mpOldData[j].address)) { - if (pController->getAddress() == mpOldData[j].address) { found++; mpOldData[i] = RPSysPlayerOldData(mpOldData[j]); break; @@ -278,11 +277,7 @@ void RPSysPlayerMgr::calcOldData() { mpOldData[i + absIdx].dataSource = mpPlayers[i].getDataSource(); mpOldData[i + absIdx].index = mpPlayers[i].getIndex(); mpOldData[i + absIdx].createID = mpPlayers[i].getCreateID(); - - RPSysCoreController* pController = - RPSysCoreControllerMgr::getNthController(i); - - mpOldData[i + absIdx].address = pController->getAddress(); + mpOldData[i + absIdx].address = RP_GET_CORE_CTRL(i)->getAddress(); } } } @@ -385,7 +380,7 @@ void RPSysPlayerMgr::saveOldData() { u8 addr[WPAD_ADDR_LEN]; for (int k = 0; k < WPAD_ADDR_LEN; k++) { - addr[k] = mpOldData[currIdx].address[k]; + addr[k] = mpOldData[currIdx].address.get(k); } #if defined(PACK_SPORTS) diff --git a/src/egg/core/eggController.cpp b/src/egg/core/eggController.cpp index 289b87a84..62f6e55b6 100644 --- a/src/egg/core/eggController.cpp +++ b/src/egg/core/eggController.cpp @@ -74,7 +74,8 @@ void CoreController::sceneReset() { mStableAccel.set(0.0, 0.0, 0.0); mStableFlags = 0; - mStableTimer[0] = mStableTimer[1] = mStableTimer[2] = 0; + mStableTimer[STABLE_AXIS_X] = mStableTimer[STABLE_AXIS_Y] = + mStableTimer[STABLE_AXIS_Z] = 0; mSimpleRumblePattern = 0; mSimpleRumbleFrame = 0; @@ -230,7 +231,7 @@ void CoreController::beginFrame(PADStatus* pStatus) { calc_posture_matrix(mPostureMtx, true); if (mEnableSimpleRumble) { - if (mSimpleRumblePattern & (1 << mSimpleRumbleIndex)) { + if (mSimpleRumblePattern & 1 << mSimpleRumbleIndex) { startMotor(); } else { stopMotor();