ASM code help

Started by goemon_guy, July 22, 2011, 07:50:59 PM

Previous topic - Next topic

dcx2

Yes, but you would lose the pointer that you put into r16.

Remember the basic format.  lhz rD,d(rA)  rD is the destination register; it will hold the value that is read from memory.  rA is a pointer register; it will hold the base address to the value.  d is the displacement operand, it will say how far forward or backward the value is from rA's address.

EDIT:

review this post.  http://wiird.l0nk.org/forum/index.php/topic,5249.0.html

Deathwolf

Yes, then we need to write the pointer again to another register. Everything is clear now. Thanks
lolz

goemon_guy

#17
Say I wanted to add a subtraction after the addi, using a different button activator, then. How would I do that. The question is basically where to put the subi, because I can't seem to figure out where it should go. o.o

I tried this;

stwu r1,-80(r1)
stmw r14,8(r1)

lis r14,-32677
ori r14,r14,27576

lis r16,-32724
ori r16,r16,44758

lwz r16,0(r16)
lwz r15,0(r14)

cmpwi r16,2064
bne- 0x0C
addi r15,r15,1

cmpwi r16, 0x410
bne- 0x0C
subi r15,r15,1


cmpwi r15,772
bne- 0x08
li r15,0

stw r15,0(r14)
lha r8,18(r30)
lmw r14,8(r1)
addi r1,r1,80
subi r1,r1,80

But it doesn't seem to allow the value to decrease.
-Currently hacking the following game(s):
...
Request a code via PM, if you wish.

Deathwolf

the last subi is outside of the stack frame which doesn't work anymore.

stwu r1,-80(r1)
stmw r14,8(r1)
lis r14,-32677
ori r14,r14,27576
lis r16,-32724
ori r16,r16,44758
lwz r16,0(r16)
lwz r15,0(r14)
cmpwi r16,2064
bne- 0x0C
addi r15,r15,1
cmpwi r16, 0x410
bne- 0x0C
subi r15,r15,1
cmpwi r15,772
bne- 0x08
li r15,0
stw r15,0(r14)
lha r8,18(r30)
subi r1,r1,80 <-- inside the stack frame
lmw r14,8(r1)
addi r1,r1,80
lolz

goemon_guy

I moved the subi r1,r1,80 and it froze the game :S. I then moved it under the lmw, and it froze upon entering the status screen.
-Currently hacking the following game(s):
...
Request a code via PM, if you wish.

Deathwolf

Oh, ok then sorry for this. dcx2 could help you with this.

btw why are you going to subtract 80 from r1? r1 is for the stack frame!
lolz

goemon_guy

Haha, I dunno what I was trying to do there!

Either way, I removed it and the code worked just fine.

Thanks again!
-Currently hacking the following game(s):
...
Request a code via PM, if you wish.

dcx2

#22
Yeah, r1 is the stack pointer, don't touch it unless you know what you're doing.  Removing the subi r1 should make your code work as expected.

BTW, when making your roller roll backwards, make sure you don't roll-under.  That is, assuming 0 is the "first" legit value, then when your subi result is less than 0, you will want to replace it with 771.

EDIT:

btw, you can prefix lines with # to make them a comment.  i.e.

lis r16,-32724      # load r16 with button activator address
ori r16,r16,44758

Note that when you paste the assembly into ASMWiiRD, you should maximize the window.  ASMWiiRD uses word-wrap for its textbox, and so a comment that is long will wrap to a new line, and the assembler will try to treat the new line as a command instead of a comment.

goemon_guy

That's actually useful to know, as I forgot to add that into the code.

And it seems like I'm going to have to use the F6 codetype for the code, as the address for the ASM does in fact change upon switching discs.

And it also seems like I changed something in the code, and my subi no longer subtracts from it. XD
-Currently hacking the following game(s):
...
Request a code via PM, if you wish.

dcx2

#24
Do you mean the F2 code type?

F6 searches for a unique pattern of Z values and if it finds it, puts the address of those Z values into the po.  If the ASM actually moves to a completely different address, this is what you'll need.  You will also need to make sure that the F6 code runs after the ASM is loaded, and you may need a way to re-trigger the F6 code.

F2 uses an XOR checksum to make sure that a C2 patch is being applied to the correct ASM.  If the ASM is just sometimes there, sometimes not, but always at the same address, then this is what you want.

EDIT:

This is why your subi doesn't work.  It's a prime example of why you should use branch labels!!

cmpwi r16,2064
bne- 0x0C           # this should be bne- 0x08
addi r15,r15,1

cmpwi r16, 0x410
bne- 0x0C           # this should ALSO be bne- 0x08
subi r15,r15,1

goemon_guy

#25
Quote from: dcx2 on July 22, 2011, 11:28:43 PM
This is why your subi doesn't work.  It's a prime example of why you should use branch labels!!

Alright, alright, I'll use them from now on :P

The ASM completely changes its location when you change the disc to the 2nd.

Fortunately, it's always in the same place, (Disc 1 is always in the same spot, and Disc 2 is in a different spot, but, it too is constant.)
-Currently hacking the following game(s):
...
Request a code via PM, if you wish.