Hi,
I made a roller in ASM using a one shot button activator.
But unfortunately, it always adds/subs 2 from the value each press and not 1.
What could I do to fix it? Please help.
Here´s the assembly:
lhz r31, 2 (r28) # original instruction
lis r12, 0x8053
lhz r12, 0x56DA (r12) # one shot BA
cmpwi r12, 0x1000 # is minus pressed?
bne- _END
subi r31, r31, 1 # sub 1 from the value
sth r31,2(r28)
_END:
cmpwi r12, 0x10 # is plus pressed?
bne- _END2
addi r31, r31, 1 # add one to the value
sth r31,2(r28)
_END2:
lis r12, 0x8053
lhz r12, 0x56DA (r12)
cmpwi r12, 0x1000
bne- _END # TEST FIRST ACTIVATOR
subi r31, r31, 1
sth r31,2(r28)
b _END2
_END:
cmpwi r12, 0x10
bne- _END2 # TEST SECOND ACTIVATOR
addi r31, r31, 1 # add one to the value
sth r31,2(r28)
_END2:
lhz r31, 2 (r28)
You just added a "branch" instruction...
Yes which branchs to the original instruction. You can ask dcx2 too but this code is correct.
Quote from: Deathwolf on August 02, 2011, 10:00:48 PM
Yes which branchs to the original instruction. You can ask dcx2 too but this code is correct.
It works, but I asked *why* the code adds 2 to the value instead of one.
Another address, but same coding added 5 to the value. And a third one really just added 1 each time...
Set multiple XBP on the hook address. Count how many frames go by. My guess is that you get two XBP's per frame. That would be why it counts by 2.
The other hook that counts by 5 probably runs 5 times per frame.
a way to fix this is to add a counter to the ASM .. i did this with the ones i made for MH3 ..
what u would want to do is something like this
when your branch for activation is pressed (By Button Activation)
it would then go into a Counter Asm section
were it would Store a value somewere in free ram (normaly where your ASM is being placed)
and it would add to it every time that code is On ..
so Example
if your code is active every 2 frames put the counter to 2 and then let it branch to Add Value to your address ..
This is a bullet-proof way to do one-shots in ASM, no matter how many times a BP executes per frame.
Use the bl trick to make room for some data. This will hold the "previous buttons".
Compare the "current buttons" to the "previous buttons" using xor. When you get a 1 in the right bit, compare that bit to the current state of the buttons to determine whether it was just pressed (current button = 1) or just released (current button = 0) When the xor bit is 1 and the current bit is 1, execute your hack.
Before the code is done, store the current buttons to the data area, because on the next round they will be the previous buttons.
Quote from: dcx2 on August 03, 2011, 12:45:46 AM
Set multiple XBP on the hook address. Count how many frames go by. My guess is that you get two XBP's per frame. That would be why it counts by 2.
if my one shot ba is works once per frame and using the following hook adds 0A to the value at the same time, it should be 10 times a frame.
I also tried to execute the hook and it seems so :(
Quote from: Skiller on August 04, 2011, 12:32:40 AM
if your code is active every 2 frames put the counter to 2 and then let it branch to Add Value to your address ..
How do I write that counter? I don´t have a clue atm...
I´ll try to provide a starting point then.
Hook: 803DB0E0 (executes 10 times a frame)
stwu r1,-16(r1) # stack frame
stw r11,8(r1) # stack frame
lhz r31,0(r28) # original instruction
lis r12, 0x8053
lhz r12, 0x56DA(r12) # load one shot BA
cmpwi r12, 0x4000 # do we press C?
bne- _NOTPRESSED1 # if not, branch...
addi r31,r31,1 # add 1 to value
>> counter?<<
cmpwi r31,494 # did we surpass 493? (= highest possible value)
blt- _CONTINUE1 # if less ...
li r31, 0 # reset back to 0
_CONTINUE1: # continue to store
sth r31,0(r28) # update value
_NOTPRESSED1: # not pressing C gets us here
cmpwi r12, 0x2000 # do we press Z?
bne- _NOTPRESSED2 # if not, exit code
subi r31,r31,1 # sub 1 from r31
>> counter?<<
cmpwi r31,0 # did we get down to zero?
bgt- _CONTINUE2 # if greater than 0...
li r31,493 # reset to max. value
_CONTINUE2: # continue
sth r31,0(r28) # update value
_NOTPRESSED2: # exit
lwz r11,8(r1) # end stack frame
addi r1,r1,16 # end stack frame