add to a memory location

Started by strakn, January 31, 2011, 05:42:45 PM

Previous topic - Next topic

strakn

i know from looking at the code type doc how to write to a mem address but how can you add to the current value?

Panda On Smack

you could use the gecko registers to do some simple calculations. I do this for FIFA and adding 1 to my score on a button press etc

You could also write an ASM code to increment the value

What is your current code?

strakn

no code yet i was just looking for a way to add to a value instead of simply writing your own value. i would also like to use a button activator to add one to a value instead of say just setting it at 99 as in like number of lives or whatever.

dcx2

Use an 82 code type to read the value into a Gecko Register

Use an 86 code type to add something to the value in the Gecko Register

Use an 84 code type to write the Gecko Register back to memory.

Patedj

excuse me dcx2, sir?  O0
does this register it to the wii gecko(os) or through the gecko(usb) into the computers temp?
[spoiler]I think it goes through the gecko(usb) and into my computer. That's why I'm making an effort to cleaning up my ASM. [/spoiler].
You can pm me, I've got time for your troubles.

-LeetGamer-

If you mean increase the value at an address then try this:

lis r0 [Upper 16bits of address]
lwz r1 [Lower 16bits of address](r0)
addi r1 r1 [Value to increase by]
stw r1 [Lower 16bits of address](r0)

Not too sure on the syntax and whatnot of PPC, but you should get the idea. I'm just loading the value at the address, increasing it with addi, then storing the new value back to the address.

If you didn't mean increasing then let me know.

dcx2

#6
Patedj - It's not a USB Gecko thing at all.  "Gecko Registers" are just some memory reserved by the code handler for use with code types.  There are several code types in the code type doc that use the values in Gecko Registers.  Those code types typically start with the number 8.

Gecko Registers are for doing some operations without ASM.  For instance, this is a Mario Size Roller for SMG2 that allows you to make Mario bigger or smaller based on the button presses.  When Mario's size is > 1, it changes his size by 1.  When Mario's size is < 1, it changes his size by 0.1.

It is almost entirely written with regular Gecko code types to store a "current size" float in a Gecko Register.  A C2 hook at the end reads the "current size" from the Gecko Register and writes it to the appropriate place in memory.  Note that it uses Gecko Register 0xA, which is the four bytes at address 80001830.  If you look at those bytes in Memory Viewer with auto-update while the code is running, you'll see the size value changing in real time.

Mario Size Roller [dcx2]
4E00000C 00000000 # these next four lines do a 1-shot button activator
28750A02 00004002 # button activator for "increase"
CC000000 00000001
14000000 00000003
26001830 41A00000 # if less than 20
24001830 3F733333 # if greater than 0.95
8690000A 3F800000 # add 1
E2100000 00000000 # else
8690000A 3DCCCCCD # add 0.1
E0000000 80008000 # end all

4E00000C 00000000 # 1 shot again
28750A02 00004001 # button activator for decrease
CC000000 00000001
14000000 00000003
24001830 3E19999A # if greater than 0.15
24001830 3F866666 # if greater than 1.05
8690000A BF800000 # sub 1
E2100000 00000000 # else
8690000A BDCCCCCD # sub 0.1
E0000000 80008000 # end all

4E00000C 00000000
28750A02 00004800 # button activator to force size to 1.0
CC000000 00000000 # note: this 1-shot runs by default the first time to make sure Gecko Register 0xA is pre-loaded with 1.0
14000000 00000003
8000000A 3F800000 # write 1.0
E0000000 80008000

C23C0D14 00000004 # hook which copies the size from the Gecko Register to the address where Mario's size is located
3D808000 818C1830
919E002C 919E0030
919E0034 C03E002C
60000000 00000000

strakn

Here is my code but it doesnt work.  Can anyone see what the problem is

28200EE0 00008000 # home button to activate
8220000A 80A1C80C # load value into grA
8609000A 448A0000 # add floating point value of 1000 to grA
8420000A 80A1C80C # write new grA value back to mem
E0000000 80008000

when I try the code it changes the current value from 500 to extremly high or negative random numbers (+/-1164567)

-LeetGamer-

Quote from: strakn on February 02, 2011, 01:29:15 AM
Here is my code but it doesnt work.  Can anyone see what the problem is

28200EE0 00008000 # home button to activate
8220000A 80A1C80C # load value into grA
8609000A 448A0000 # add floating point value of 1000 to grA
8420000A 80A1C80C # write new grA value back to mem
E0000000 80008000

when I try the code it changes the current value from 500 to extremly high or negative random numbers (+/-1164567)

Maybe it isn't a float value.

dcx2

#9
The Gecko ops that work with floats assume that *all* the data is a float.  You can't add float 1000.0 to an integer 500.  You would need to cast one to the other to do so.

Also, for your 86 code type, you specified Y = 9, which is not a valid value.  http://www.geckocodes.org/index.php?arsenal=1#86

My Size Roller example was perhaps a bit more complicated than necessary.  Now that you've provided a code, I think you want to do this.

28200EE0 00008000 # home button to activate
8220000A 80A1C80C # load value into grA
8600000A 000003E8 # add integer 1000 to grA
8420000A 80A1C80C # write new grA value back to mem
E0000000 80008000

EDIT: we can do a little bit better...

28200EE0 00008000 # home button to activate
8000000A 80A1C80C # grA = 80A1C80C
8601000A 000003E8 # [ grA ] = [ grA ] + 0x3E8
E0000000 80008000 # terminate the activator

You will also probably see it increase as long as you're pressing the activator, instead of just once.  Add 4 to the activator address to make it only fire once per press.

Patedj

Thankyou. I'm glad that it's the code handler. This means that I can also work on my gecko registers  O0
You can pm me, I've got time for your troubles.

strakn

Quote from: dcx2 on February 02, 2011, 01:51:24 AM

You will also probably see it increase as long as you're pressing the activator, instead of just once.  Add 4 to the activator address to make it only fire once per press.

yes this is whats happening i cant press the button quick enough to only add 1000, by activator address do you mean 2800EE00 I tried changing that to 2800EE04 but that didnt work.

dcx2

If you don't use the "real" button activator, that can happen.  Your address doesn't look like a real button activator, which usually ends in 2, 6, A, or E...not 0.

In any event, you can use this trick to make it 1-shot.

4E00000C 00000000 # these next four lines do a 1-shot button activator
28200EE0 00008000 # button activator = home key
CC000000 00000001
14000000 00000003
8000000A 80A1C80C # grA = 80A1C80C
8601000A 000003E8 # [ grA ] = [ grA ] + 0x3E8
E0000000 80008000 # terminate the activator

strakn

#13
Thanks that worked perfectly.

Now I have decided for learning purpose to make this code using only ASM, including the button activator.
This is my first attempt at using ASM so it took me a while to read up on the instructions and whatnot.

The code is working however, same problem it is not doing a one shot ( I thought I read somewhere that ASM would solve the one shot problem, must have been mistaken there.)

Anyway here is the code, Is there some way to implement a one shot code directly in the ASM, again this is just a learning example I know it is probably easier to just use regualar gecko codes.

lis r12,0x8020        # r12 = button activator
ori r12,r12,0x0EE0  #       adress
lhz r12,0(r12)        # r12 = controller value
cmplwi r12,0x8000  # compare if controller value is 0x8000
bne- 0x0018         # skip to end if not equal
lis r12,0x80A1       # r12 = address where
ori r12,r12,0xC80C  #       money is stored
lwz r11,0(r12)        # load money value in r11
addi r11,r11,1000    # add 1000 to money value
stw r11,0(r12)       # store new money value back to 0x80A1C80C
blr

dcx2

It'd be best if you could find a button activator that had the edge bits after it.  That's how I usually did one shot.

Otherwise, you'll have to keep a copy of the previous button activator, and XOR them together.  The XOR will set a bit when they're different; this is the "edge".  When you detect an edge, check the current activator; if it's a 1, then they just pressed the button.  At the end, you'll want to update the "previous button activator" with the current one, so that way it's ready for the next frame.

Oh, btw, I found a much easier way to do the one shot thing.

28200EE0 00008000 # button activator = home key
A8000000 00000001 # if counter == 1
8000000A 80A1C80C # grA = 80A1C80C
8601000A 000003E8 # [ grA ] = [ grA ] + 0x3E8
E0000000 80008000 # terminate the activator and counter