MEM2 question

Started by Sharkbyte, February 05, 2010, 07:08:53 PM

Previous topic - Next topic

Sharkbyte

I am trying to make my first code that use uses mem2. the address is 91BFE784, the value is 00000000. what would I write the ba to? I tried 04 and it doesn't work. anything else freezes the console and I have to start over.

wiiztec

would be

42000000 90000000
05BFE784 00000000
If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

Thomas83Lin

yep just dont forgot to use a terminator sense you just changed the ba

E0000000 80008000

dcx2

#3
I got a bit confused when I read this, so I'm going to make a comment about it.

04 code types use the remaining 3 bytes for the address.  To change the upper byte you must use the BA (or PO).  Normally the BA is 0x80000000, so the first byte of any 04 code type's address is usually 0x80.  But in this case, you want the first byte to be 0x91.  You COULD do it this way...

42000000 91000000
04BFE784 00000000
E0000000 80008000
(fail!  can't set ba like this, only the upper 7 bits of ba are used)

This works fine, and you still need to use the terminator at the end to make sure the BA goes back to 0x80000000 so you don't screw the next code up.

But look carefully at wiiztec's code.

42000000 90000000
05BFE784 00000000
E0000000 80008000

The 05 code type adds a "1" to the upper byte of the address in the BA.  That's why the two codes are identical.

The 05 code type is most useful when writing to an 0x81______ address.  Normally, if you set the BA to 0x81000000, you would have to use a terminator to put it back to normal.  However, if your address begins with 0x81, then you can use the 05 code type without changing the BA.  This means you don't need a terminator anymore.

Unfortunately, you have to change the BA anyway because you're in mem2 so we still need a terminator despite using an 05 code.

Romaap

#4
The ba has to be set to a multiplication of 0x02000000.
The codetype document says:
"Each time the ba is added to a code address, the code handler do : address = address + (ba & 0xFE000000)"

So if you set it to 0x91000000 it would actually be set to 0x90000000.
0x91000000 & 0xFE000000 = 0x90000000

dcx2

Quote from: Romaap on February 17, 2010, 06:10:05 PM
The ba has to be set to a multiplication of 0x2000000.
The codetype document says:
"Each time the ba is added to a code address, the code handler do : address = address + (ba & 0xFE000000)"

So if you set it to 0x91000000 it would actually be set to 0x90000000.
0x91000000 & 0xFE000000 = 0x90000000
Aah, I almost misunderstood you, because I didn't count the 0's.  0x02000000.

I did not know the restriction on ba, thanks.  The po does not have this restriction, yes?  I don't see anything listed in the code type docs.

Romaap

Quote from: dcx2 on February 17, 2010, 06:20:37 PM
Quote from: Romaap on February 17, 2010, 06:10:05 PM
The ba has to be set to a multiplication of 0x2000000.
The codetype document says:
"Each time the ba is added to a code address, the code handler do : address = address + (ba & 0xFE000000)"

So if you set it to 0x91000000 it would actually be set to 0x90000000.
0x91000000 & 0xFE000000 = 0x90000000
Aah, I almost misunderstood you, because I didn't count the 0's.  0x02000000.

I did not know the restriction on ba, thanks.  The po does not have this restriction, yes?  I don't see anything listed in the code type docs.
The po can be practically everything, you could even set it to the address you want to write to and use  10000000 XXXXXXXX.