In this example I am gonna use a Piece from my live color changing code for socom 2.
Why are using floating points better then using decimal?
Well when you deal with decimal, anything over 7fff got negative. That is a bad thing with you work with floats because the don't work like that. When you usually add a decimal on a float once you get too high you will tend to freeze. So in this case you would use a floating point to store your math correctly and avoid freezing.
Here is a breakdown of the mips used.
lui - Load upper intermediate, uses t0 - t9 registers
lwc1 - load word from floating point, store in $f registers but can be placed in t register
swc1 - Storeword from floating point, stores from $f register
Ok so here is our basic code to add red (now the address are a little off because this is a giant code)
Code:
000e017c 3c000010 (lui zero, $0010)
000e0194 3c08004c (lui t0, $004c)
000e019c 3c0a000e (lui t2, $000e)
000e01e0 c5008590 (lwc1 $f0, $8590(t0))
000e01e4 c541017c (lwc1 $f1, $017c(t2))
000e01e8 46000880 (add.s $f2, $f1, $f0)
000e01ec e5028590 (swc1 $f2, $8590(t0))
I am going to break this down by address and explain what is going on in the code.
000e017c 3c000010
This line controls how much we will add to our color. In this case we will be adding 0010.
Since we are doing this as a float and not a decimal we will need to use LUI and since we are just using this for nothing but a number to add by we do now need to put this into a register, rather we put zero, then the ammount:
lui zero, $0010.
000e0194 3c08004c
This line is loading the upper 4 to our address for blue. The address for blue is
004b858c and the reason we are loading 004c and not 004b is because the lower 4, 858c is above 7ffff, in which case we just add 1 to the upper 4 making it 004c. We stick this into register t0 for later use when we goto load the rest of the line in the routine.
000e019c 3c0a000e
This line loads the upper 4 to the line that we are using to increment. Work just like what I explained above.
000e01e0 c5008590
This line loads the rest of 004b858c but loads it into a floating point. Meaning this works just like loadword(lw) only instead of using a t register we will be using $f in this case I used $f0. So we load 858c into $f0 and store it into t0, meaning we loaded our line for blue, 004b858c (004c858c if you want to go by the routine).
000e01e4 c541017c
This line loads the lower 4 to the line that we are using as the increment. 000e017c remember that? This works just the same as the one I described above. We are taking 017c putting it into register $f1 and storing it into t2.
Resulting in 000e017c being loaded into memory.
000e01e8 46000880
This line adds 2 floating points and stores them into a new register.
The register you are storing the result into always comes first.
so in this case add.s $f2, $f1, $f0. Not a whole lot that can be explained here because it works just like the add command on in this case it's just adding floats.
000e01ec e5028590
This line takes what we put in $f2 (the result from the addition of $f1 and $f0) and stores it into t0. This is storing into t0 because if you remember we the line for blue is in t0. So in this case everytime you run this routine blue will add +0010.
Bookmarks