Skip to content

Commit

Permalink
Matches in sysdolphin/controller (#1444)
Browse files Browse the repository at this point in the history
* Match HSD_PadFlushQueue

* Match PadRenewCopyStatus

* Change PadZeroQueue to RenewGameStatus and match
  • Loading branch information
PsiLupan authored Sep 6, 2024
1 parent 714d1ab commit 8cad9f0
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 30 deletions.
2 changes: 1 addition & 1 deletion asm/melee/lb/lbcardgame.s
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
/* 800199FC 000165DC 48 00 00 35 */ bl lb_80019A30
/* 80019A00 000165E0 2C 03 00 00 */ cmpwi r3, 0x0
/* 80019A04 000165E4 41 82 00 08 */ beq .L_80019A0C
/* 80019A08 000165E8 48 35 E1 4D */ bl HSD_PadZeroQueue
/* 80019A08 000165E8 48 35 E1 4D */ bl HSD_PadRenewGameStatus
.L_80019A0C:
/* 80019A0C 000165EC 38 60 00 00 */ li r3, 0x0
/* 80019A10 000165F0 48 00 00 21 */ bl lb_80019A30
Expand Down
16 changes: 10 additions & 6 deletions asm/sysdolphin/baselib/controller.s
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@
/* 000011B4 000011F4 4E 80 00 20 */ blr
.endfn HSD_PadRenewCopyStatus

.fn HSD_PadZeroQueue, global
.fn HSD_PadRenewGameStatus, global
/* 000011B8 000011F8 3C 60 00 00 */ lis r3, HSD_PadLibData@ha
/* 000011BC 000011FC C0 00 00 00 */ lfs f0, HSD_Controller_804DE5B0@sda21(r0)
/* 000011C0 00001200 38 63 00 00 */ addi r3, r3, HSD_PadLibData@l
Expand Down Expand Up @@ -1343,7 +1343,7 @@
/* 00001340 00001380 38 A5 00 44 */ addi r5, r5, 0x44
/* 00001344 00001384 42 00 FE 90 */ bdnz .L_000011D4
/* 00001348 00001388 4E 80 00 20 */ blr
.endfn HSD_PadZeroQueue
.endfn HSD_PadRenewGameStatus

.fn HSD_PadRenewStatus, global
/* 0000134C 0000138C 7C 08 02 A6 */ mflr r0
Expand All @@ -1353,7 +1353,7 @@
/* 0000135C 0000139C 48 00 00 01 */ bl HSD_PadRenewRawStatus
/* 00001360 000013A0 48 00 00 01 */ bl HSD_PadRenewMasterStatus
/* 00001364 000013A4 48 00 00 01 */ bl HSD_PadRenewCopyStatus
/* 00001368 000013A8 48 00 00 01 */ bl HSD_PadZeroQueue
/* 00001368 000013A8 48 00 00 01 */ bl HSD_PadRenewGameStatus
/* 0000136C 000013AC 80 01 00 0C */ lwz r0, 0xc(r1)
/* 00001370 000013B0 38 21 00 08 */ addi r1, r1, 0x8
/* 00001374 000013B4 7C 08 03 A6 */ mtlr r0
Expand Down Expand Up @@ -1669,9 +1669,13 @@
.skip 0x110
.endobj HSD_PadCopyStatus

.obj HSD_PadRumbleData, global
.skip 0x114
.endobj HSD_PadRumbleData
.obj HSD_PadGameStatus, global
.skip 0x110
.endobj HSD_PadGameStatus

.obj pad, local
.skip 0x4
.endobj pad

# 0x00000000 - 0x00000070
.section .sdata2, "a"
Expand Down
4 changes: 2 additions & 2 deletions config/GALE01/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19453,7 +19453,7 @@ HSD_PadADConvertCheck1 = .text:0x803771D4; // type:function size:0x27C scope:glo
HSD_PadCrossDir = .text:0x80377450; // type:function size:0xBC scope:global
HSD_PadRenewMasterStatus = .text:0x8037750C; // type:function size:0x4B4 scope:global
HSD_PadRenewCopyStatus = .text:0x803779C0; // type:function size:0x194 scope:global
HSD_PadZeroQueue = .text:0x80377B54; // type:function size:0x194 scope:global
HSD_PadRenewGameStatus = .text:0x80377B54; // type:function size:0x194 scope:global
HSD_PadRenewStatus = .text:0x80377CE8; // type:function size:0x30 scope:global
HSD_PadReset = .text:0x80377D18; // type:function size:0x80 scope:global
HSD_PadInit = .text:0x80377D98; // type:function size:0x2F8 scope:global
Expand Down Expand Up @@ -25163,7 +25163,7 @@ HSD_VIData = .bss:0x804C1D80; // type:object size:0x1F4 scope:global data:4byte
HSD_PadLibData = .bss:0x804C1F78; // type:object size:0x34 scope:global data:byte
HSD_PadMasterStatus = .bss:0x804C1FAC; // type:object size:0x110 scope:global data:4byte
HSD_PadCopyStatus = .bss:0x804C20BC; // type:object size:0x110 scope:global data:4byte
HSD_PadRumbleData = .bss:0x804C21CC; // type:object size:0x114 scope:global data:4byte
HSD_PadGameStatus = .bss:0x804C21CC; // type:object size:0x110 scope:global data:4byte
HSD_Rumble_804C22E0 = .bss:0x804C22E0; // type:object size:0x30 scope:global data:4byte
...bss.0 = .bss:0x804C22E0; // type:label scope:local
HSD_Mtx_804C2310 = .bss:0x804C2310; // type:object size:0x2C scope:global
Expand Down
16 changes: 7 additions & 9 deletions src/melee/ft/fighter.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ extern ftData* gFtDataList[FTKIND_MAX];
extern MotionState ftData_MotionStateList[ftCo_MS_Count];
extern MotionState* ftData_CharacterStateTables[FTKIND_MAX];

extern HSD_PadStatus HSD_PadRumbleData[4];

extern StageInfo stage_info; // from asm/melee/gm_1A36.s

// ==== fighter.c variables ====
Expand Down Expand Up @@ -1816,20 +1814,20 @@ void Fighter_Spaghetti_8006AD10(Fighter_GObj* gobj)

} else {
SET_STICKS(fp->input.lstick.x, fp->input.lstick.y,
HSD_PadRumbleData[fp->x618_player_id].nml_stickX,
HSD_PadRumbleData[fp->x618_player_id].nml_stickY);
HSD_PadGameStatus[fp->x618_player_id].nml_stickX,
HSD_PadGameStatus[fp->x618_player_id].nml_stickY);
if (g_debugLevel < 3 && gm_8016B41C() == 0) {
SET_STICKS(
fp->input.cstick.x, fp->input.cstick.y,
HSD_PadRumbleData[fp->x618_player_id].nml_subStickX,
HSD_PadRumbleData[fp->x618_player_id].nml_subStickY);
HSD_PadGameStatus[fp->x618_player_id].nml_subStickX,
HSD_PadGameStatus[fp->x618_player_id].nml_subStickY);
} else {
fp->input.cstick.x = 0;
fp->input.cstick.y = 0;
}

tempf1 = HSD_PadRumbleData[fp->x618_player_id].nml_analogR;
tempf0 = HSD_PadRumbleData[fp->x618_player_id].nml_analogL;
tempf1 = HSD_PadGameStatus[fp->x618_player_id].nml_analogR;
tempf0 = HSD_PadGameStatus[fp->x618_player_id].nml_analogL;

fp->input.x650 = (tempf0 > tempf1) ? tempf0 : tempf1;
}
Expand Down Expand Up @@ -1858,7 +1856,7 @@ void Fighter_Spaghetti_8006AD10(Fighter_GObj* gobj)
fp->input.held_inputs = ftCo_800A198C(fp);
} else {
fp->input.held_inputs =
HSD_PadRumbleData[fp->x618_player_id].button;
HSD_PadGameStatus[fp->x618_player_id].button;
}

if (gm_8016B0FC()) {
Expand Down
187 changes: 177 additions & 10 deletions src/sysdolphin/baselib/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
PadLibData HSD_PadLibData;
HSD_PadStatus HSD_PadMasterStatus[4];
HSD_PadStatus HSD_PadCopyStatus[4];
HSD_PadStatus HSD_PadGameStatus[4];

u8 HSD_PadGetRawQueueCount(void)
{
Expand All @@ -32,17 +33,49 @@ s32 HSD_PadGetResetSwitch(void)
return (p->reset_switch != 0) ? true : false;
}

static void HSD_PadRawQueueShift(u32 qnum, u8* qpos)
static void HSD_PadRawQueueShift(u8 qnum, u8* qptr)
{
*qpos = (*qpos + 1) - ((*qpos + 1) / qnum) * qnum;
*qptr = (*qptr + 1) % qnum;
}

static void HSD_PadRawMerge(PADStatus* src1, PADStatus* src2, PADStatus* dst)
{
dst[0].button = src1[0].button | src2[0].button;
dst[1].button = src1[1].button | src2[1].button;
dst[2].button = src1[2].button | src2[2].button;
dst[3].button = src1[3].button | src2[3].button;
int i;
for (i = 0; i < 4; i++) {
dst[i].button = src1[i].button | src2[i].button;
}
}

void HSD_PadFlushQueue(HSD_FlushType ftype)
{
PadLibData* p;
PADStatus* qdst;
PADStatus* qread;
bool intr;

p = &HSD_PadLibData;
intr = OSDisableInterrupts();
switch (ftype) {
case HSD_PAD_FLUSH_QUEUE_MERGE:
for (; p->qcount > 1; p->qcount -= 1) {
qread = &p->queue->stat[p->qread * 4];
HSD_PadRawQueueShift(p->qnum, &p->qread);
qdst = &p->queue->stat[p->qread * 4];
HSD_PadRawMerge(qread, qdst, qdst);
}
break;
case HSD_PAD_FLUSH_QUEUE_THROWAWAY:
p->qread = p->qwrite;
p->qcount = 0;
break;
case HSD_PAD_FLUSH_QUEUE_LEAVE1:
if (p->qcount > 1) {
p->qread = p->qwrite != 0 ? p->qwrite - 1 : p->qnum - 1;
p->qcount = 1;
}
break;
}
OSRestoreInterrupts(intr);
}

void HSD_PadClampCheck1(u8* val, u8 shift, u8 min, u8 max)
Expand Down Expand Up @@ -108,20 +141,154 @@ void HSD_PadRenewMasterStatus(void)

void HSD_PadRenewCopyStatus(void)
{
NOT_IMPLEMENTED;
int iVar1;
HSD_PadStatus* mp;
HSD_PadStatus* cp;
PadLibData* p;

int i;

p = &HSD_PadLibData;
for (i = 0; i < 4; i++) {
mp = &HSD_PadMasterStatus[i];
cp = &HSD_PadCopyStatus[i];

cp->last_button = cp->button;
cp->err = mp->err;
if (cp->err == 0) {
cp->button = mp->button;
cp->stickX = mp->stickX;
cp->stickY = mp->stickY;
cp->subStickX = mp->subStickX;
cp->subStickY = mp->subStickY;
cp->analogL = mp->analogL;
cp->analogR = mp->analogR;
cp->analogA = mp->analogA;
cp->analogB = mp->analogB;
cp->nml_stickX = mp->nml_stickX;
cp->nml_stickY = mp->nml_stickY;
cp->nml_subStickX = mp->nml_subStickX;
cp->nml_subStickY = mp->nml_subStickY;
cp->nml_analogL = mp->nml_analogL;
cp->nml_analogR = mp->nml_analogR;
cp->nml_analogA = mp->nml_analogA;
cp->nml_analogB = mp->nml_analogB;
} else {
cp->button = 0;
cp->subStickY = 0;
cp->subStickX = 0;
cp->stickY = 0;
cp->stickX = 0;
cp->analogB = 0;
cp->analogA = 0;
cp->analogR = 0;
cp->analogL = 0;
cp->nml_subStickY = 0.0;
cp->nml_subStickX = 0.0;
cp->nml_stickY = 0.0;
cp->nml_stickX = 0.0;
cp->nml_analogB = 0.0;
cp->nml_analogA = 0.0;
cp->nml_analogR = 0.0;
cp->nml_analogL = 0.0;
}
cp->trigger = cp->button & (cp->last_button ^ cp->button);
cp->release = cp->last_button & (cp->last_button ^ cp->button);
if (cp->last_button ^ cp->button) {
cp->repeat = cp->trigger;
cp->repeat_count = p->repeat_start;
} else {
iVar1 = cp->repeat_count - 1;
cp->repeat_count = iVar1;
if (iVar1 != 0) {
cp->repeat = 0;
} else {
cp->repeat = cp->button;
cp->repeat_count = p->repeat_interval;
}
}
};
return;
}

void HSD_PadZeroQueue(void)
void HSD_PadRenewGameStatus(void)
{
NOT_IMPLEMENTED;
int iVar1;
HSD_PadStatus* mp;
HSD_PadStatus* gs;
PadLibData* p;

int i;

p = &HSD_PadLibData;
for (i = 0; i < 4; i++) {
mp = &HSD_PadMasterStatus[i];
gs = &HSD_PadGameStatus[i];

gs->last_button = gs->button;
gs->err = mp->err;
if (gs->err == 0) {
gs->button = mp->button;
gs->stickX = mp->stickX;
gs->stickY = mp->stickY;
gs->subStickX = mp->subStickX;
gs->subStickY = mp->subStickY;
gs->analogL = mp->analogL;
gs->analogR = mp->analogR;
gs->analogA = mp->analogA;
gs->analogB = mp->analogB;
gs->nml_stickX = mp->nml_stickX;
gs->nml_stickY = mp->nml_stickY;
gs->nml_subStickX = mp->nml_subStickX;
gs->nml_subStickY = mp->nml_subStickY;
gs->nml_analogL = mp->nml_analogL;
gs->nml_analogR = mp->nml_analogR;
gs->nml_analogA = mp->nml_analogA;
gs->nml_analogB = mp->nml_analogB;
} else {
gs->button = 0;
gs->subStickY = 0;
gs->subStickX = 0;
gs->stickY = 0;
gs->stickX = 0;
gs->analogB = 0;
gs->analogA = 0;
gs->analogR = 0;
gs->analogL = 0;
gs->nml_subStickY = 0.0;
gs->nml_subStickX = 0.0;
gs->nml_stickY = 0.0;
gs->nml_stickX = 0.0;
gs->nml_analogB = 0.0;
gs->nml_analogA = 0.0;
gs->nml_analogR = 0.0;
gs->nml_analogL = 0.0;
}
gs->trigger = gs->button & (gs->last_button ^ gs->button);
gs->release = gs->last_button & (gs->last_button ^ gs->button);
if (gs->last_button ^ gs->button) {
gs->repeat = gs->trigger;
gs->repeat_count = p->repeat_start;
} else {
iVar1 = gs->repeat_count - 1;
gs->repeat_count = iVar1;
if (iVar1 != 0) {
gs->repeat = 0;
} else {
gs->repeat = gs->button;
gs->repeat_count = p->repeat_interval;
}
}
};
return;
}

void HSD_PadRenewStatus(void)
{
HSD_PadRenewRawStatus(0);
HSD_PadRenewMasterStatus();
HSD_PadRenewCopyStatus();
HSD_PadZeroQueue();
HSD_PadRenewGameStatus();
}

void HSD_PadReset(void)
Expand Down
4 changes: 2 additions & 2 deletions src/sysdolphin/baselib/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ struct HSD_PadStatus {
f32 nml_analogA;
f32 nml_analogB;
u8 cross_dir;
u8 support_rumble;
s8 err;
};

Expand Down Expand Up @@ -84,13 +83,14 @@ struct PadLibData {
};

extern HSD_PadStatus HSD_PadMasterStatus[4];
extern HSD_PadStatus HSD_PadGameStatus[4];

void HSD_PadFlushQueue(HSD_FlushType);
u8 HSD_PadGetRawQueueCount(void);
s32 HSD_PadGetResetSwitch(void);
void HSD_PadRenewRawStatus(int);
void HSD_PadRenewMasterStatus(void);
void HSD_PadZeroQueue(void);
void HSD_PadRenewGameStatus(void);
void HSD_PadRenewStatus(void);
void HSD_PadReset(void);
void HSD_PadInit(s32, u8*, s32, HSD_PadRumbleListData*);
Expand Down

0 comments on commit 8cad9f0

Please sign in to comment.