Skip to content

Commit 4fed0c0

Browse files
committed
decompile touchcontrol (98%)
1 parent e9789bf commit 4fed0c0

File tree

11 files changed

+261
-43
lines changed

11 files changed

+261
-43
lines changed

config/eur/arm9/delinks.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ src/Main/Main.cpp:
1313
src/Main/System/SysNew.cpp:
1414
.text start:0x02011e10 end:0x0201200c
1515

16+
src/Main/Player/TouchControl.cpp:
17+
.text start:0x02014124 end:0x020144a0
18+
1619
src/Main/System/OverlayManager.cpp:
1720
.text start:0x020147fc end:0x02014944
1821

config/eur/arm9/symbols.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -685,15 +685,15 @@ _ZN18UnkStruct_02049b8013func_02013ee8Eii kind:function(arm,size=0x98) addr:0x02
685685
func_02013f80 kind:function(arm,size=0x6c) addr:0x02013f80
686686
func_02013fec kind:function(arm,size=0xc) addr:0x02013fec
687687
func_02013ff8 kind:function(arm,size=0x12c) addr:0x02013ff8
688-
func_02014124 kind:function(arm,size=0xb8) addr:0x02014124
688+
_ZN12TouchControl11UpdateStateEP10TouchStateP15TouchStateFlags kind:function(arm,size=0xb8) addr:0x02014124
689689
_ZN12TouchControlC1Ev kind:function(thumb,size=0x3c) addr:0x020141dc
690-
func_02014218 kind:function(arm,size=0x18) addr:0x02014218
691-
func_02014230 kind:function(arm,size=0x12c) addr:0x02014230
692-
func_0201435c kind:function(arm,size=0x44) addr:0x0201435c
693-
func_020143a0 kind:function(arm,size=0x50) addr:0x020143a0
694-
func_020143f0 kind:function(arm,size=0x24) addr:0x020143f0
695-
func_02014414 kind:function(arm,size=0x64) addr:0x02014414
696-
_ZN12TouchControl13func_02014478EP18UnkStruct_02049b4ci kind:function(arm,size=0x28) addr:0x02014478
690+
_ZN12TouchControl13IncreaseSpeedEt kind:function(arm,size=0x18) addr:0x02014218
691+
_ZN12TouchControl11UpdateFlagsEt kind:function(arm,size=0x12c) addr:0x02014230
692+
_ZN12TouchControl20UpdateWithStateFlagsEP15TouchStateFlagst kind:function(arm,size=0x44) addr:0x0201435c
693+
_ZN12TouchControl6UpdateEP10TouchStatet kind:function(arm,size=0x50) addr:0x020143a0
694+
_ZN12TouchControl13func_020143f0Ev kind:function(arm,size=0x24) addr:0x020143f0
695+
_ZN12TouchControl13func_02014414Etb kind:function(arm,size=0x64) addr:0x02014414
696+
_ZN12TouchControl13func_02014478EP10TouchStatet kind:function(arm,size=0x28) addr:0x02014478
697697
func_020144a0 kind:function(thumb,size=0x10) addr:0x020144a0
698698
func_020144b0 kind:function(thumb,size=0x1c) addr:0x020144b0
699699
func_020144cc kind:function(thumb,size=0x6c) addr:0x020144cc
@@ -1801,7 +1801,7 @@ func_0202e864 kind:function(arm,size=0x94) addr:0x0202e864
18011801
func_0202e8f8 kind:function(arm,size=0xf0) addr:0x0202e8f8
18021802
func_0202e9e8 kind:function(arm,size=0x9c) addr:0x0202e9e8
18031803
func_0202ea84 kind:function(arm,size=0x4c) addr:0x0202ea84
1804-
func_0202ead0 kind:function(arm,size=0x1c) addr:0x0202ead0
1804+
TP_GetTouchStateFlags kind:function(arm,size=0x1c) addr:0x0202ead0
18051805
func_0202eaec kind:function(arm,size=0x1ec) addr:0x0202eaec
18061806
func_0202ecd8 kind:function(arm,size=0x11c) addr:0x0202ecd8
18071807
func_0202edf4 kind:function(arm,size=0x18) addr:0x0202edf4

config/jp/arm9/delinks.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ src/Main/Main.cpp:
1313
src/Main/System/SysNew.cpp:
1414
.text start:0x02011e10 end:0x0201200c
1515

16+
src/Main/Player/TouchControl.cpp:
17+
.text start:0x02014128 end:0x020144a4
18+
1619
src/Main/System/OverlayManager.cpp:
1720
.text start:0x02014800 end:0x02014948
1821

config/jp/arm9/symbols.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -685,15 +685,15 @@ _ZN18UnkStruct_02049b8013func_02013ee8Eii kind:function(arm,size=0x98) addr:0x02
685685
func_02013f84 kind:function(arm,size=0x6c) addr:0x02013f84
686686
func_02013ff0 kind:function(arm,size=0xc) addr:0x02013ff0
687687
func_02013ffc kind:function(arm,size=0x12c) addr:0x02013ffc
688-
func_02014128 kind:function(arm,size=0xb8) addr:0x02014128
688+
_ZN12TouchControl11UpdateStateEP10TouchStateP15TouchStateFlags kind:function(arm,size=0xb8) addr:0x02014128
689689
_ZN12TouchControlC1Ev kind:function(thumb,size=0x3c) addr:0x020141e0
690-
func_0201421c kind:function(arm,size=0x18) addr:0x0201421c
691-
func_02014234 kind:function(arm,size=0x12c) addr:0x02014234
692-
func_02014360 kind:function(arm,size=0x44) addr:0x02014360
693-
func_020143a4 kind:function(arm,size=0x50) addr:0x020143a4
694-
func_020143f4 kind:function(arm,size=0x24) addr:0x020143f4
695-
func_02014418 kind:function(arm,size=0x64) addr:0x02014418
696-
_ZN12TouchControl13func_02014478EP18UnkStruct_02049b4ci kind:function(arm,size=0x28) addr:0x0201447c
690+
_ZN12TouchControl13IncreaseSpeedEt kind:function(arm,size=0x18) addr:0x0201421c
691+
_ZN12TouchControl11UpdateFlagsEt kind:function(arm,size=0x12c) addr:0x02014234
692+
_ZN12TouchControl20UpdateWithStateFlagsEP15TouchStateFlagst kind:function(arm,size=0x44) addr:0x02014360
693+
_ZN12TouchControl6UpdateEP10TouchStatet kind:function(arm,size=0x50) addr:0x020143a4
694+
_ZN12TouchControl13func_020143f0Ev kind:function(arm,size=0x24) addr:0x020143f4
695+
_ZN12TouchControl13func_02014414Etb kind:function(arm,size=0x64) addr:0x02014418
696+
_ZN12TouchControl13func_02014478EP10TouchStatet kind:function(arm,size=0x28) addr:0x0201447c
697697
func_020144a0 kind:function(thumb,size=0x10) addr:0x020144a4
698698
func_020144b4 kind:function(thumb,size=0x1c) addr:0x020144b4
699699
func_020144d0 kind:function(thumb,size=0x6c) addr:0x020144d0
@@ -1822,7 +1822,7 @@ func_0202e864 kind:function(arm,size=0x94) addr:0x0202fd94
18221822
func_0202e8f8 kind:function(arm,size=0xf0) addr:0x0202fe28
18231823
func_0202ff18 kind:function(arm,size=0x9c) addr:0x0202ff18
18241824
func_0202ffb4 kind:function(arm,size=0x4c) addr:0x0202ffb4
1825-
func_02030000 kind:function(arm,size=0x1c) addr:0x02030000
1825+
TP_GetTouchStateFlags kind:function(arm,size=0x1c) addr:0x02030000
18261826
func_0203001c kind:function(arm,size=0x1ec) addr:0x0203001c
18271827
func_02030208 kind:function(arm,size=0x11c) addr:0x02030208
18281828
func_02030324 kind:function(arm,size=0x18) addr:0x02030324

include/Game/GameModeManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include "Player/TouchControl.hpp"
44
#include "System/SysNew.hpp"
55
#include "Unknown/UnkStruct_02049b18.hpp"
6-
#include "Unknown/UnkStruct_02049b4c.hpp"
76
#include "nitro/button.h"
87
#include "nitro/math.h"
8+
#include "nitro/touch.h"
99
#include "types.h"
1010

1111
class GameModeManagerBase;

include/Player/TouchControl.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

3-
#include "Unknown/UnkStruct_02049b4c.hpp"
43
#include "nitro/math.h"
4+
#include "nitro/touch.h"
55
#include "types.h"
66

77
typedef u16 TouchFlags;
88
enum TouchFlag_ {
9+
TouchFlag_None = 0x0000,
910
TouchFlag_TouchedNow = 0x0001,
1011
TouchFlag_UntouchedNow = 0x0002,
1112
TouchFlag_Repeat = 0x0004,
@@ -18,20 +19,26 @@ class TouchControl {
1819
/* 00 */ u16 mSpeed;
1920
/* 02 */ u16 mTimeBetweenTouches; // gets set to mTimeSinceTouch when touching the screen
2021
/* 04 */ u16 mTimeSinceTouch; // increases by mSpeed every frame
21-
/* 06 */ unk16 mRepeatStart;
22-
/* 08 */ unk16 mRepeatLoop;
22+
/* 06 */ u16 mRepeatStart;
23+
/* 08 */ u16 mRepeatLoop;
2324
// mRepeatTimer starts at mRepeatStart, decreases by mSpeed while touching the screen.
2425
// if equal to 0, mRepeatTimer gets set to mRepeatLoop and the Repeat flag is set
25-
/* 0A */ unk16 mRepeatTimer;
26-
/* 0C */ bool mTouch;
27-
/* 10 */ Vec2s mTouchPos;
28-
/* 14 */ bool mTouchPrev;
29-
/* 16 */ Vec2s mTouchPosPrev;
26+
/* 0A */ u16 mRepeatTimer;
27+
/* 0C */ TouchState mState;
28+
/* 12 */ TouchState mPrevState;
3029
/* 18 */ Vec2s mTouchPosLast;
3130
/* 1C */ Vec2s mTouchPosStart;
3231
/* 20 */ TouchFlags mFlags;
3332
/* 22 */
3433

3534
TouchControl();
36-
void func_02014478(UnkStruct_02049b4c *param1, unk32 param2);
35+
void IncreaseSpeed(u16 increase);
36+
void UpdateFlags(u16 speed);
37+
void UpdateWithStateFlags(TouchStateFlags *state, u16 speed);
38+
void Update(TouchState *state, u16 speed);
39+
void func_02014414(u16 speedIncrease, bool shouldIncrease);
40+
void func_02014478(TouchState *state, u16 speed);
41+
42+
static bool func_020143f0();
43+
static void UpdateState(TouchState *state, TouchStateFlags *stateFlags);
3744
};

include/Unknown/UnkStruct_02049b4c.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

include/nitro/touch.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
3+
#include "global.h"
4+
#include "nitro/math.h"
5+
#include "types.h"
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
typedef struct TouchStateFlags {
12+
/* 00 */ Vec2us touchPos;
13+
/* 04 */ u16 touch;
14+
/* 06 */ u16 flags;
15+
} TouchStateFlags; // size = 0x08
16+
17+
typedef struct TouchState {
18+
/* 00 */ bool touch;
19+
/* 01 */ bool unk_01;
20+
/* 02 */ Vec2s touchPos;
21+
} TouchState; // size = 0x06
22+
23+
typedef struct TouchStateU {
24+
/* 00 */ bool touch;
25+
/* 01 */ bool unk_01;
26+
/* 02 */ Vec2us touchPos;
27+
} TouchStateU; // size = 0x06
28+
29+
void WaitForTouchUpdate(u16 param1);
30+
bool TP_GetTouchStateFlags(TouchStateFlags *pState);
31+
32+
static inline void TP_CopyState(TouchState *from, TouchState *to) {
33+
to->touch = from->touch;
34+
to->unk_01 = from->unk_01;
35+
to->touchPos = from->touchPos;
36+
}
37+
38+
extern TouchState data_02049b4c;
39+
40+
#ifdef __cplusplus
41+
}
42+
#endif

src/019_MainSelect/FileSelectManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ARM void FileSelectManager::vfunc_24() {
5555
this->func_0201875c();
5656
this->func_02018908();
5757

58-
if (!this->mTouchControl.mTouch) {
58+
if (!this->mTouchControl.mState.touch) {
5959
this->mUnk_148 = -1;
6060
}
6161

src/Main/Player/TouchControl.cpp

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#include "Player/TouchControl.hpp"
2+
#include "Unknown/UnkMemFuncs.h"
3+
4+
// non-matching
5+
ARM void TouchControl::UpdateState(TouchState *state, TouchStateFlags *stateFlags) {
6+
if (stateFlags->touch == 1) {
7+
if (stateFlags->flags == 0) {
8+
Vec2us pos;
9+
pos.y = stateFlags->touchPos.y;
10+
pos.x = stateFlags->touchPos.x;
11+
12+
state->touch = true;
13+
state->touchPos.x = pos.x;
14+
state->touchPos.y = pos.y;
15+
} else {
16+
if ((stateFlags->flags & 1) == 0) {
17+
state->touchPos.x = stateFlags->touchPos.x;
18+
}
19+
20+
if ((stateFlags->flags & 2) == 0) {
21+
state->touchPos.y = stateFlags->touchPos.y;
22+
}
23+
24+
if (state->touchPos.x >= 0 && state->touchPos.x < 0x100 && state->touchPos.y >= 0 && state->touchPos.y < 0xC0) {
25+
state->touch = true;
26+
} else {
27+
state->touch = false;
28+
state->unk_01 = false;
29+
state->touchPos.x = -1;
30+
state->touchPos.y = -1;
31+
}
32+
}
33+
} else {
34+
state->touch = false;
35+
state->unk_01 = false;
36+
state->touchPos.x = -1;
37+
state->touchPos.y = -1;
38+
}
39+
}
40+
41+
THUMB TouchControl::TouchControl() {
42+
this->mSpeed = 1;
43+
this->mTimeBetweenTouches = -1;
44+
this->mTimeSinceTouch = -1;
45+
this->mRepeatStart = 20;
46+
this->mRepeatLoop = 6;
47+
this->mTouchPosLast.x = 128;
48+
this->mRepeatTimer = 0;
49+
50+
this->mState.touch = false;
51+
this->mState.unk_01 = false;
52+
this->mState.touchPos.x = -1;
53+
this->mState.touchPos.y = -1;
54+
55+
this->mPrevState.touch = false;
56+
this->mPrevState.unk_01 = false;
57+
this->mPrevState.touchPos.x = -1;
58+
this->mPrevState.touchPos.y = -1;
59+
60+
this->mTouchPosLast.y = 96;
61+
this->mTouchPosStart.x = -1;
62+
this->mTouchPosStart.y = -1;
63+
this->mFlags = TouchFlag_None;
64+
}
65+
66+
ARM void TouchControl::IncreaseSpeed(u16 increase) {
67+
this->mFlags = TouchFlag_None;
68+
this->mSpeed += increase;
69+
}
70+
71+
// non-matching
72+
ARM void TouchControl::UpdateFlags(u16 speed) {
73+
this->mFlags = TouchFlag_None;
74+
75+
if (this->mPrevState.unk_01 == false && this->mState.unk_01 == false) {
76+
if (this->mPrevState.touch == false && this->mState.touch == true) {
77+
this->mFlags |= TouchFlag_TouchedNow;
78+
}
79+
80+
if (this->mPrevState.touch == true && this->mState.touch == false) {
81+
this->mFlags |= TouchFlag_UntouchedNow;
82+
}
83+
}
84+
85+
if (this->mSpeed < speed) {
86+
this->mSpeed = speed;
87+
}
88+
89+
switch (!(this->mFlags & TouchFlag_TouchedNow)) {
90+
default:
91+
this->mFlags |= TouchFlag_Repeat;
92+
this->mRepeatTimer = this->mRepeatStart;
93+
break;
94+
case 0:
95+
if (this->mState.touch != false && this->mRepeatTimer != 0) {
96+
if (this->mRepeatTimer - this->mSpeed > 0) {
97+
this->mRepeatTimer -= this->mSpeed;
98+
} else {
99+
this->mFlags |= TouchFlag_Repeat;
100+
this->mRepeatTimer = this->mRepeatLoop;
101+
}
102+
}
103+
break;
104+
}
105+
106+
if (this->mTimeSinceTouch + this->mSpeed < 0xFFFF) {
107+
this->mTimeSinceTouch += this->mSpeed;
108+
} else {
109+
this->mTimeSinceTouch = -1;
110+
}
111+
112+
if (this->mFlags & TouchFlag_TouchedNow) {
113+
this->mTimeBetweenTouches = this->mTimeSinceTouch;
114+
this->mTimeSinceTouch = 0;
115+
this->mTouchPosStart.x = this->mState.touchPos.x;
116+
this->mTouchPosStart.y = this->mState.touchPos.y;
117+
}
118+
119+
this->mSpeed = speed;
120+
121+
if (this->mState.touch) {
122+
this->mTouchPosLast.x = this->mState.touchPos.x;
123+
this->mTouchPosLast.y = this->mState.touchPos.y;
124+
}
125+
}
126+
127+
ARM void TouchControl::UpdateWithStateFlags(TouchStateFlags *state, u16 speed) {
128+
*(TouchStateU *) &this->mPrevState = *(TouchStateU *) &this->mState;
129+
this->UpdateState(&this->mState, state);
130+
this->UpdateFlags(speed);
131+
}
132+
133+
ARM void TouchControl::Update(TouchState *state, u16 speed) {
134+
TouchStateU curState = *(TouchStateU *) &this->mState;
135+
TouchStateU newState = *(TouchStateU *) &*state;
136+
137+
this->mPrevState.touch = curState.touch;
138+
139+
this->mPrevState.touch = curState.touch;
140+
this->mPrevState.unk_01 = curState.unk_01;
141+
this->mPrevState.touchPos.x = curState.touchPos.x;
142+
this->mPrevState.touchPos.y = curState.touchPos.y;
143+
144+
this->mState.touch = newState.touch;
145+
this->mState.unk_01 = newState.unk_01;
146+
this->mState.touchPos.x = newState.touchPos.x;
147+
this->mState.touchPos.y = newState.touchPos.y;
148+
149+
this->UpdateFlags(speed);
150+
}
151+
152+
ARM bool TouchControl::func_020143f0() {
153+
return ((*((u16 *) 0x027FFFA8) & 0x8000) >> 15) == 1;
154+
}
155+
156+
ARM void TouchControl::func_02014414(u16 speedIncrease, bool shouldIncrease) {
157+
TouchStateFlags touchState;
158+
159+
if (shouldIncrease) {
160+
this->IncreaseSpeed(speedIncrease);
161+
return;
162+
}
163+
164+
if (TouchControl::func_020143f0()) {
165+
Fill16(0, (u16 *) &touchState, sizeof(TouchStateFlags));
166+
} else {
167+
TP_GetTouchStateFlags(&touchState);
168+
}
169+
170+
this->UpdateWithStateFlags(&touchState, speedIncrease);
171+
}
172+
173+
ARM void TouchControl::func_02014478(TouchState *state, u16 speed) {
174+
TouchControl::func_020143f0();
175+
this->Update(state, speed);
176+
}

0 commit comments

Comments
 (0)