diff --git a/src/research/controller-input.ld b/src/research/controller-input.ld new file mode 100644 index 0000000..811391b --- /dev/null +++ b/src/research/controller-input.ld @@ -0,0 +1,3 @@ +$$ = 0; +$C2$.call.PADRead = 0x80011bf4; +$C2$.main = 0x800ed2b4; diff --git a/src/research/controller-input.s b/src/research/controller-input.s new file mode 100644 index 0000000..3bf6897 --- /dev/null +++ b/src/research/controller-input.s @@ -0,0 +1,108 @@ +/* + 9000_0000 [1] status + 9400_0000 dst +*/ +.set aStatus, 0 +.set status.preparing, 0 +.set status.ready, 1 +.set status.running, 2 +.set status.done, 3 + +.macro .call addr + lis r12, \addr@h + ori r12, r12, \addr@l + mtlr r12 + blrl +.endm + +.call.PADRead: +## check enabled + lis r12, 0x9000 + lbz r0, aStatus(r12) + cmplwi r0, status.running + lis r12, pad.PADRead@h + ori r12, r12, pad.PADRead@l + mtlr r12 + bnelrl+ + +.set rRet, 31 +.set rInput, 30 +.set rDst, 29 +.set rMario, 28 +.set rGamePad, 27 +.set rPadStatus, 26 +# r23-r31 is restored in orignal code + +.main: +## check whether to run + lis r12, 0x9000 + lbz r11, aStatus(r12) + cmplwi r11, status.ready + bne+ .main.done +## init +### backup return value + mr rRet, r3 +### set status + li r11, status.running + stb r11, aStatus(r12) +### init variables + li rInput, 0 + lis rDst, 0x9400 + lwz rMario, gpMarioOriginal$r13(r13) + lwz rGamePad, 0x4FC(rMario) + lis rPadStatus, mPadStatus@ha + la rPadStatus, mPadStatus@l(rPadStatus) +.main.loop: +## set input + sth rInput, 2(rPadStatus) +## calculate +### JUTGamePad.read() + mr r3, rGamePad + .call JUTGamePad.read +### TMarioGamePad::updateMeaning() + mr r3, rGamePad + .call TMarioGamePad.updateMeaning +### TMario.checkController() + mr r3, rMario + .call TMario.checkController +## record +### input (size=2) + sthu rInput, -2(rDst) +### PadStatus.MStick (size=2) + lhz r0, 2(rPadStatus) + sthu r0, -2(rDst) +### JUTGamePad::CStick (size=0x10) + addi r4, rGamePad, 0x48 # &gamepad.MStick + li r5, 0x10 + sub rDst, rDst, r5 + mr r3, rDst + .call memcpy +### controllerWork->MStickInt (size=4) + lwz r11, 0x108(rMario) + lwz r0, 0(r11) + stwu r0, -4(rDst) +### controllerWork->MStickFloat (size=12) + addi r4, r11, 0x10 + li r5, 12 + sub rDst, rDst, r5 + mr r3, rDst + .call memcpy +## baseAcc, accDir (size=8) + lwz r0, 0x8C(rMario) + stwu r0, -4(rDst) + lwz r0, 0x90(rMario) + stwu r0, -4(rDst) +.main.loop.next: + addi rInput, rInput, 1 + rlwinm. r0, rInput, 0, 0x0, 0xF + beq+ .main.loop +.main.epilogue: +## set done + lis r12, 0x9000 + li r0, status.done + stb r0, aStatus(r12) +## restore return value + mr r3, rRet +.main.done: +## orig + lmw r23, 0x16C(r1)