Extra Adresses in ASM

Started by doomkaiber001, December 01, 2010, 07:54:40 PM

Previous topic - Next topic

doomkaiber001

I know BASIC Asm; I can change values like in ammo or money, or Health. Just about. But I prefer making these codes 'longer', they're more spread out and easier to read:

Address: 802BEF10

lis r5, 0x802B
ori r5, r5, 0xEF10
lwz r29, 0(r5)
cmpwi r29, 200
ble LowAmmo
bgt HighAmmo
LowAmmo:
addi r29, r29, 100
cmpwi r29, 200
ble LowAmmo
b End
HighAmmo:
subi r29, r29, 100
cmpwi r29, 200
bgt HighAmmo
End:
stw r29, 0(r5)

I originally made this code to test to see if I understood Labels, which is why what it does is kinda stupid.

dcx2

Huh, not too bad...that looks like a C0 code, except that I wouldn't use r29.  In general, avoid using registers above r12, because they are non-volatile.  However, you can use a stack frame to preserve their contents if you really want to use them.

Part of the problem is that registers in the code handler can change depending on the version.  So, you should really create a stack frame before using *any* registers (volatile or not), push them onto the stack, do your work, pop the registers back off the stack, and remove the stack frame.

However, if you know you're using a recent-ish version of Gecko OS, and you don't mind not being able to work on all versions, then you can use a few registers that are known safe for certain versions.  I know this list works for 1.9.3.1

from http://wiird.l0nk.org/forum/index.php/topic,5622.msg48854.html#msg48854

r0 safe
r1 Stack pointer
r2 Table of Contents (TOC) pointer

r3 safe
r4 not safe
r5 safe
r6 ba
r7 gr addresses
r8 code execution status

r9 safe
r10 safe
r11 safe
r12 safe

r13 not safe (reserved)
r14 not safe
r15 code line address
r16 po

r17-31 unknown

doomkaiber001

Ok, use any of the registers written in blue in your post.

I thought that was a C2 code, I haven't put it through the compiler yet though. I'm starting to look for addresses in games which allow you to make 'easy' codes. I'm not having much luck though...

dcx2

That list is ONLY for C0 codes and ONLY for certain versions of the code handler.  It is NOT for C2 codes, and if you're writing a real code that you want to distribute you should make something that works for all versions, because that list is different for some other builds of Gecko OS.

C2 code register safety is governed by an ENTIRELY different set of rules, because your code will run "in the game" instead of "in the code handler".

http://wiird.l0nk.org/forum/index.php/topic,6555.msg55745.html#msg55745

Also, C2 codes replace (or "hook") an instruction in the game with a branch to your ASM code, which has a corresponding branch back from the code to the address you hooked.  Typically, the instruction replaced will be placed at the end of the code.

doomkaiber001

Ok. Now onto making simple codes, and learning about more complex codes.

Thank you dcx2, you have helped me so much today! :)

doomkaiber001

#20
Ok, so if I wanted this code to work for all versions of Gecko, I'd do this (if it wasn't a C0 codetype);

stwu r1, -80(r1)
stmw r14, 8(r1)
lis r15, 0x802B
ori r15, r15, 0xEF10
lwz r29, 0(r5)
...
End:
stw r29, 0(r15)
lmw r14, 8(r1)
addi r1, r1, 80

doomkaiber001

Ok... I put it through the compiler and got this code;

CD382E75 00000008
3CA08B38 60A52E75
80650000 2C0300C8
40810008 41810014
38630064 2C0300C8
4081FFF8 48000010
3863FF9C 2C0300C8
4080FFF8 90650000
60000000 00000000

Whats a CD codetype?

dcx2

Uh...it's not a codetype.

It would be a switch (CC code type), with the first address bit set...but the CC code type doesn't use address bits.

doomkaiber001

Trust myself to go and make a code like that!