Converting to/from SNES addresses

Share and discuss all facets of DKC ROM hacking...

Converting to/from SNES addresses

Postby rainbowsprinklez » October 18th, 2022, 4:36 am

Hey guys! Are you sick of getting SNES addresses when you just want to know what to change in hex? I mean, a Gnawty in DKC1's init script is at b5b413. How does THAT help me?

Actually, a lot. It's actually very easy to convert, and you can even convert in your head!
Consider this table.
Code: Select all
0 1 2 3
4 5 6 7
8 9 a b
c d e f

When converting from SNES, we only have to worry about the first digit. So our address b5b413. We only look at b in the table and choose the same column in the first row (so 3). So b5b413 converts to 351413. The jungle theme tilemaps are at d90000 in dkc1. This converts to 190000!

And that's all there is to it! So if somebody gives you a SNES address, you can quickly convert!
Veteran Venturer
Bananas received 110
Posts: 604
Joined: 2016

Re: Converting to/from SNES addresses

Postby VideoViking » October 18th, 2022, 4:56 am

So if I'm reading this correctly, when dealing with the alphabetic portion of the HEX code, they will always translate to the top row, ergo:

0 = c
1 = d
2 = a and e
3 = b and f

In the HEX format, "a" represents 10 going all the way up to "f", or 15. The number 16 simply rolls back to 0.

Can this work outside of the SNES ecosystem? For example, Sega, Playstation, XBOX, Windows even?
Treasure Hunter
Bananas received 41
Posts: 329
Joined: 2009

Re: Converting to/from SNES addresses

Postby rainbowsprinklez » October 18th, 2022, 7:53 am

VideoViking wrote:So if I'm reading this correctly, when dealing with the alphabetic portion of the HEX code, they will always translate to the top row, ergo:

0 = c
1 = d
2 = a and e
3 = b and f

Yes. Also note 8 and 9 converts to 0 and 1.

VideoViking wrote:In the HEX format, "a" represents 10 going all the way up to "f", or 15. The number 16 simply rolls back to 0.


Yes, but irrelevant here.

VideoViking wrote:Can this work outside of the SNES ecosystem? For example, Sega, Playstation, XBOX, Windows even?


I'm not sure how higher systems work. But, this works on SNES because the addressing for the SNES deals with the higher bits turned on or off. Look at the windows calc -> programmer mode. if you type in b you can see the top bit is turned on. Turning this off results in 3. f has a similar thing. If you turn the top two bits off, you get 3

Image
Veteran Venturer
Bananas received 110
Posts: 604
Joined: 2016

Re: Converting to/from SNES addresses

Postby WesternTanager794 » October 18th, 2022, 7:58 am

Thanks for the guide! Nice explanations! :parry:
Sage of Discovery
Bananas received 128
Posts: 2393
Joined: 2022

Re: Converting to/from SNES addresses

Postby Cyclone » November 18th, 2022, 12:13 pm

Hi, I got an snes address of CEF88E. How do I convert it to a PC address that my HEX editor will understand? I would like to convert it using windows calculator.
Expedition Leader
Bananas received 559
Posts: 1257
Joined: 2008

Re: Converting to/from SNES addresses

Postby Mattrizzle » November 18th, 2022, 1:29 pm

The quickest way is to use the XOR (exclusive OR) bitwise operation.

In Windows calculator, bitwise operations are in the dropdown labeled "Bitwise" just above the keypad. Simply type your address, click the "Bitwise" dropdown, select XOR, type in the value to the right of XOR above, and hit Enter (or click the equals sign on the keypad).

If the upper nybble of the bank byte is between 8 and B, XOR $800000.
If the upper nybble of the bank byte is between C and F, XOR $C00000.

The XOR bitwise operation essentially works as a toggle. Bits in both operands which match will be cleared (0), while bits in both operands which do not match will be set (1).

In your case,
Spoiler!
the upper nybble of the bank byte of CEF88E is between C and F.
CEF88E XOR C00000 = 0EF88E


You can XOR the same value to convert back into a SNES HiROM address:
Spoiler!
0EF88E XOR C00000 = CEF88E
Veteran Venturer
Bananas received 222
Posts: 559
Joined: 2008

Re: Converting to/from SNES addresses

Postby rainbowsprinklez » November 18th, 2022, 2:48 pm

Mattrizzle wrote:The quickest way...


Neat trick! I didn't immediately think of that! But I disagree with your claim of that being the quickest way... My way allows you to quickly do in your head, by remembering C is in the same column as 0. Ehh guess they both do the exact same thing anyways! :)
Veteran Venturer
Bananas received 110
Posts: 604
Joined: 2016

Re: Converting to/from SNES addresses

Postby Cyclone » November 18th, 2022, 3:36 pm

Mattrizzle wrote:If the upper nybble of the bank byte is between 8 and B, XOR $800000.
If the upper nybble of the bank byte is between C and F, XOR $C00000.


Thanks Mattrizzle. Can't you just minus 0x800000? That's what I was doing and it was working fine till now. I guess it was because the address was greater then 0x800000?
Expedition Leader
Bananas received 559
Posts: 1257
Joined: 2008

Re: Converting to/from SNES addresses

Postby WesternTanager794 » November 18th, 2022, 3:54 pm

Interesting! Both ways work great! :parry:
Sage of Discovery
Bananas received 128
Posts: 2393
Joined: 2022



Return to ROM Hacking

Who is online

Users browsing this forum: No registered users and 7 guests