• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

How does one store variables for injection codes?

Gun.Rugger

Smash Cadet
Joined
Jan 2, 2016
Messages
26
I am very new to ASM, but not new to programming. I am about to start writing a mod, and I think I have all the injection point memory addresses and most of the ASM code figured out. I have one major question.

How do I carve out space in memory safely to store variables?
I have 16 variables that need to be stored and referenced (4 for each player), and I need them to be at least 8 bits (they need to be a value of 0-99).
Ideally, I could find an area in memory that isn't used like 81xxxx00-81xxxxFF, so that I could do something like
Player 1:
81xxxx00
81xxxx01
81xxxx02
81xxxx03
Player 2:
81xxxx10
81xxxx11
81xxxx12
81xxxx13
etc.

A situation I would like to avoid if possible would be addresses that are scattered all about, but I could still make that work. It would just suck a bit.

Keep in mind that I would like this mod to be able to run on the wii, and am not sure if there are memory restrictions that will get in the way.

Thanks ahead of time! You are all very powerful wizards, and I hope to achieve a small portion of your power.
 

Gun.Rugger

Smash Cadet
Joined
Jan 2, 2016
Messages
26
Alternatively, I think it may be possible to do something like:

Player 1
80xxxxx0 00112233
Player 2
80xxxxx1 00112233
Player 3
80xxxxx2 00112233
Player 4
80xxxxx3 00112233

But I don't know how to read the 8 bit values from a 32 bit one.
 

Punkline

Dr. Frankenstack
Joined
May 15, 2015
Messages
423
A method I've always relied on is to include them with my code. You can access the data by bouncing off of a blrl instruction, creating a base address from the link register:
Code:
_injection_code:
bl _my_data
mflr r3
b _code_start
# r3 = address of _my_data label, after the blrl instruction

_my_data:
blrl
.long 0x00112233, 0x00112233, 0x00112233, 0x00112233

_code_start:
# put code that uses data here
-- the bl to _my_data will execute the blrl instruction; which will then immediately return with the address following it in the link register. By grabbing it with an mflr instruction, you can then access anything you place after the blrl -- allowing you to include variables (with default values) inline with your instructions.

Edit - Also, to load bytes instead of words; use lbz instead of lwz. Additionally, if you format the variables so that they're in a useful order, you can construct a loop that reads the variables iteratively with lbzx, or lbzux.
 
Last edited:
Top Bottom