Here's an example of what I'm talking about:
CodeDesigner v2.0 Source:
Code:
/*
CodeDesigner v2.0 Source
ReadPad() Example with isHolding check
Created by: Gtlcpimp
*/
address $000bfff0 // The _readPad configuration memory block
hexcode $00100000 // Controller input address
nop // isHolding boolean address
nop // Padding to keep everything inline for ps2dis debugging
nop // Padding to keep everything inline for ps2dis debugging
address $000c0000 // Change to wherever you want
// Or just append the _readPad function to your code
_readPad:
// No need to preserve registers since we are only using v0 and v1
lui v1, $000c
lw v1, $fff0(v1) // Load controller input address from config section
lh v1, $0000(v1)
addiu v0, zero, -1
bne v1, v0, 7 // Check for no controller input
nop
lui v0, $000c
sb zero, $fff4(v0) // Write pad button is not holding (isHolding = false)
daddu v0, zero, zero
daddu v1, zero, zero
goto _readPadQuit
bne v1, a0, 3
nop
goto _readPadHold
daddu v0, zero, zero
goto _readPadQuit
_readPadHold:
lui v0, $000c
lb v1, $fff4(v0) // Load boolean isHolding
bne v1, zero, 7 // See if we already are holding
nop
addiu v1, zero, 1
sb v1, $fff4(v0) // Write pad button is holding (isHolding = true)
addiu v0, zero, 1 // Return true on button press check
daddu v1, zero, zero // Return false on already holding
goto _readPadQuit
addiu v0, zero, 1
addiu v1, zero, 1
_readPadQuit:
jr ra
nop
Hexadecimal RAW Output:
Code:
200BFFF0 00100000
200BFFF4 00000000
200BFFF8 00000000
200BFFFC 00000000
200C0000 3C03000C
200C0004 8C63FFF0
200C0008 84630000
200C000C 2402FFFF
200C0010 14620007
200C0014 00000000
200C0018 3C02000C
200C001C A040FFF4
200C0020 0000102D
200C0024 0000182D
200C0028 10000014
200C002C 00000000
200C0030 14640003
200C0034 00000000
200C0038 10000004
200C003C 00000000
200C0040 0000102D
200C0044 1000000D
200C0048 00000000
200C004C 3C02000C
200C0050 8043FFF4
200C0054 14600007
200C0058 00000000
200C005C 24030001
200C0060 A043FFF4
200C0064 24020001
200C0068 0000182D
200C006C 10000003
200C0070 00000000
200C0074 24020001
200C0078 24030001
200C007C 03E00008
200C0080 00000000
Just change the controller input address in the configuration to whatever you want it to be.
You call it with the controller button you want to know if it is being pressed or not in register a0.
It will return the value '1' in register v0 if the button is being pressed, '0' if it is not.
It will return the value '1' in register v1 if you are already holding the button, '0' if you are pressing it as a new button.
It clears the isHolding when you call it and it reads NOINPUT (0xFFFF). Keep in mind it's just an example, you can implement it in your code if you wish, but it could definitely be made better. (kinda just rushed through it in a hurry)