Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
1 user currently in Rom Hacking: hukka | 2 guests
Acmlm's Board - I2 Archive - Rom Hacking - ram to rom adressing | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
elixirnova

Red Paratroopa
Level: 22

Posts: 40/177
EXP: 56507
For next: 1843

Since: 04-05-04
From: Midgar

Since last post: 1 day
Last activity: 1 day
Posted on 09-09-04 07:48 AM Link | Quote
Hey i remember finding a guide a long time ago on how to convert an snes ram adress such as ones found in zsnes to what they'd be in a rom like when it calls to lda $0fff
and such i remember you have to subtract the 200byte header and somthing about reversing the byte such as 1AF0 = F01A anyone have a guide or can tell me about how to correctly do it?
the rom im using it on is a lo-rom but hi-rom conversion method would be helpful too


(edited by elixirnova on 09-08-04 11:06 PM)
jonwil

Goomba
Level: 9

Posts: 14/25
EXP: 2989
For next: 173

Since: 04-09-04

Since last post: 85 days
Last activity: 81 days
Posted on 09-09-04 11:58 AM Link | Quote
look for a program called Lunar Address at fusoya.cg-games.net
That program can convert addresses for you.
MathOnNapkins

Math n' Hacks
Level: 67

Posts: 418/2189
EXP: 2495887
For next: 96985

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 09-10-04 02:00 AM Link | Quote
Some terminology:

Given a long cpu address $1F5046 we must split it up into two parts:

1F | 5046

The first number, #1F is called the bank. The portion on the right is called the absolute part of the address.

If you are looking at the address in a hex editor, then yes the bytes are written in reverse order.

For example: AD 05 F6 is machine code for LDA $F605

Ex 2: AF 00 90 06. This corresponds to LDA $069000.

First of all, just delete the 200 byte rom header. Removing it affects nothing, and subtracting #200 all the time gets tedious.

$069000 is a CPU address, so to convert that to a rom address, you look at the bank number. In this case, it is #06. Here's how I do it. If the bank number is even, as in this case, the corresponding digits in the rom address will be half of that. So the rom address at this point looks like $03????. Since the bank is even, we have to subtract #8000 from the absolute portion of the address (#9000). Thus we get #9000-#8000 = #1000 = #????. The finalized rom address is therefore $031000.

On the other hand, say we have an odd bank. Ex. 3: BF 05 A5 1B

This corresponds to LDA $1BA505, X. The (, X) part is not important for this explanation.

To find the highest two digits for the rom address we still divide the bank (#1B) by two, except we discard the remainder. So #1B/2 = #D remainder 1 -> #D b/c we discard the remainder. What that 1 really represents is #8000 bytes but don't worry too much about that at this point. To simplify things, I just remember not to subtract those #8000 bytes in the case that the bank is odd. Therefore, we just write the rom address as $0DA505.

Summary: even bank - halve the bank and take that as your highest two digits. subtract #8000 bytes from the absolute address.
odd bank - halve the bank and discard the remainder. Don't subtract #8000 from the absolute address.

You can get programs that will do this for you but when I'm working I don't have time to plug numbers into a program so I've gotten good at calculating them mentally. To derive a cpu address from a rom address is very similar.

Suppose we are given $030000 as a rom address. Look at the absolute portion, #0000. It is less than #8000, so we need to double the "bank" (not really a bank but the top two digits) and get #6. Then add #8000 to the absolute address. Result: $068000.

If we are given $038700 as a rom address, then we need to realize that this came from an odd bank (the last rom address obviously came from an even bank). In case you haven't caught on yet, note that the the absolute portion is at least #8000. That tells us it came from an odd bank. Thus, we need to double the bank to get #6 but we need to add back that remainder of 1 that was thrown away in calculating a rom address. So the bank will actually be #7. Since this came from an odd-banked cpu address, #8000 was never subtracted from it, so we again leave the absolute portion alone. Result: $078700.

While this may seem complicated, that is the extent of the Lo-Rom addressing scheme in terms of conversion.

Most of the confusion over Lo-Rom addressing is the fact that its banks are #8000 bytes long. Technically they are 64K long, but code is only mapped into half of that. The lower #8000 bytes are used as memory. However, the SNES doesn't have enough memory to fill up all those banks, the lower #8000 bytes of each bank are actually identical to the values of the lower #8000 bytes of bank $7E, which is a full bank in the sense that it is a full 64K instead of the 32K banks. $7F is the same way, and these make up the 128K of memory that the snes has. Lastly, $70 is a special bank where you can write to the save game memory (SRAM). Most people have heard this called battery backup. Other than $7E, $7F, and $70, there are no other special banks to read and write memory in. Everything else is read only (i.e. code).

Finally going back to the actual content of your question, if you write LDA $0FFF you should generally assume that this means load A from $7E0FFF. There are times when the Data Bank register is changed to $7F or $70 and in those cases the same instruction would correspond to $7F0FFF or $700FFF.

I'm not very swift. You'd laugh if you knew how long it took me to figure all this out.


(edited by MathOnNapkins on 09-09-04 05:08 PM)
(edited by MathOnNapkins on 09-09-04 05:10 PM)
FuSoYa
Defender of Relm
Level: 26

Posts: 121/255
EXP: 99529
For next: 2746

Since: 03-15-04
From: Moon

Since last post: 7 days
Last activity: 7 hours
Posted on 09-10-04 08:24 AM Link | Quote
Originally posted by MathOnNapkins
However, the SNES doesn't have enough memory to fill up all those banks, the lower #8000 bytes of each bank are actually identical to the values of the lower #8000 bytes of bank $7E,


Actually, it's just the first 0x2000 bytes that mirrors RAM from bank 7E. The rest of that area is used for hardware registers and sometimes SRAM.
MathOnNapkins

Math n' Hacks
Level: 67

Posts: 423/2189
EXP: 2495887
For next: 96985

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 09-10-04 08:45 AM Link | Quote
Go Fu.

Yeah I knew that the area around $2000 and above was hardware, and there are memory maps out there if you google it, but I wasn't too sure about the usage of those since I never had to mess with those regions.

That is, other than the hardware registers that handle DMA, HDMA, and other screen settings, I don't remember the memory mapping for the higher regions.


(edited by MathOnNapkins on 09-10-04 12:10 AM)
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Rom Hacking - ram to rom adressing | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.017 seconds.