11-21-2021, 05:51 PM
(11-21-2021, 05:42 PM)Vega Wrote: @ha and @l are tools in an ASM compiler to help with applying values of statements, variables, and macros to various instructionsok i fix this in my code and doesn't work
.set InputManager_s_instance, 0x809bd70c
lis r3, InputManager_s_instance@ha
lwz r3, InputManager_s_instance@l (r3)
With the address of 0x809bd70c. If you split it in 'half' and try to execute the following instructions...
lis r3, 0x809B
lwz r3, 0xD70C (r3)
The compiler will reject it. The 0xD70C is not within the proper 16-bit signed range.
What @ha will do is adjust the value during compilation to comply with the 16-bit signed range. Thus the instructions end up like this...
lis r3, 0x809C #809B + 1
lwz r3, 0xFFFFD70C (r3) #Sign extend 0xD70C to comply with range
Now this will compile and load the r3 value from the correct spot originally specified in r3.
When using any instructions that treat its values as signed you wanna use @ha and @l. If you are using instructions that treat its values as logical you would instead use @h and @l.
@ha = Upper Half (+1 if necessary)
@h = Upper Half
@l = Lower Half (will be sign extended if used with @ha only when its necessary)
the code:
import dolphin_memory_engine as dolphin_memory
dolphin_memory.hook()
def lwz(a,b):
i = hex(a+b)[2:]
i = i[-8:]
i = int(i,16)
return dolphin_memory.read_word(i)
def stw(a,b,c):
dolphin_memory.write_word(a+b,c)
def lhz(a,b):
v = hex(lwz(a, b))[2:]
return int(v[:4],16)
def ori(a,b):
a = hex(a)[2:]
b= hex(b)[2:]
return int(a[:-len(b)]+b,16)
def sth(a,b,c):
dolphin_memory.write_word(a+b,c)
def press_a():
r3 = 0x809c0000
r3 = lwz(r3, 0xFFFFD70C)
r3 = lwz(r3, 0x8)
r4 = lhz(r3, 0x20)
r4 = ori(r4,0x1)
r4 = lhz(r3, 0x20)
print(hex(r3))
press_a()