News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

LoROM to PC conversion

Started by Munchy, March 28, 2019, 06:42:19 PM

Previous topic - Next topic

Munchy

Hiya,

Since I'm writing something that uses stored pointer addresses, I needed to have a way of programmatically converting LOROM to PCaddress.  I found a function on a Super Mario board, but it evaluates exactly $400000  too high:

here it is in unicode (lo, hi, bank are uInt16 and header is bool)

        ((lo & 255) +
        (256 * (hi & 255)) +
        (32768 * bank) -
        ((header) ? 0 : 512) -
        32256)


obviously I simply strap on `-0x400000` to get the desired result; but, in case this method messes me around later on, I was just curious as to what - if anything is missing in this math to throw it out?

Smiley

(32768 * bank) -
The first rom bank is 0x80, not zero, so you need to subtract 0x80 from the bank before multiplying by 0x8000.

Munchy

Quote from: SMILEuser96 on March 28, 2019, 09:40:08 PM
(32768 * bank) -
The first rom bank is 0x80, not zero, so you need to subtract 0x80 from the bank before multiplying by 0x8000.

awesome! Yep, much tidier :) thanks Smiley!