User Tag List

Results 1 to 6 of 6

Thread: Working with and storing Floats

  1. #1
    Working with and storing Floats

    User Info Menu

    Working with and storing Floats

    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.

  2. #2
    Working with and storing Floats

    User Info Menu

    Re: Working with and storing Floats

    Nice tutorial it is good for beginers. The only thing i dont get is, 000e01e4 c541017c part of the code. Can you pm me alittle bit more of what it means?
    Other than that nice tut.

  3. #3
    Working with and storing Floats

    User Info Menu

    Re: Working with and storing Floats

    what kind of psp you have

  4. #4
    Working with and storing Floats Snake Champion, Asteroids Champion, Castle Crusher Champion, Johnny Race or Be Late Champion, Mission To Mars Champion

    User Info Menu

    Re: Working with and storing Floats

    Quote Originally Posted by ilose View Post
    Nice tutorial it is good for beginers. The only thing i dont get is, 000e01e4 c541017c part of the code. Can you pm me alittle bit more of what it means?
    Other than that nice tut.
    left= address right=data stored at said address

  5. #5
    Working with and storing Floats

    User Info Menu

    Re: Working with and storing Floats

    Quote Originally Posted by computermatt View Post
    left= address right=data stored at said address
    Right = Hex Value
    Every man for himself. You trust no one but yourself, if you want something done you do it your self don't rely on others. You watch your own back, you fight your own fights its you against the world.

    Quote Originally Posted by Some phag
    -.BUS.-'s mommy says to Cannon, "I love you,
    I love you, I love you"
    The Cannon on the bus says, "I love you, too"
    All through the town.

  6. #6
    Working with and storing Floats Snake Champion, Asteroids Champion, Castle Crusher Champion, Johnny Race or Be Late Champion, Mission To Mars Champion

    User Info Menu

    Re: Working with and storing Floats

    Quote Originally Posted by -.Z3U5.- View Post
    Right = Hex Value
    isn't that what I said

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •