Thanks! I converted it to JavaScript (removed the type declarations and prepend "function" before the function declarations) to play around with it, and it works great both ways. I also did some research, and played around with Lunar Address, and found that HiROM addressing is actually much less complicated than LoROM:
LoROM -> ROM data occupies only the upper half of banks 00 to 6F. Banks 70-7F are reserved by the SNES, banks 80-EF are mirrors of banks 00-6F, and banks F0-FF take on where banks 00-6f left off.
HiROM -> ROM data occupies banks C0-FF fully and completely. This means all you have to worry about when doing conversion is offsetting the PC address "bank" (or highest byte) by C0. The rest of the address stays the same.
So in C syntax style...
Code
int snespchirom(unsigned int addrlo, unsigned int addrhi, unsigned int bank, bool header)
{
return (addrlo&255)+(256*(addrhi&255))+(65536*((bank&255)-192))+((header)?512:0);
}
int pcsneslohirom(int addr, bool header)
{
return (addr&255);
}
int pcsneshihirom(int addr, bool header)
{
return ((addr-((header)?512:0))/256)&255;
}
int pcsnesbankhirom(int addr, bool header)
{
return (((addr-((header)?512:0))/65536)&255)+192;
}
I used your code as a base, so I hope you don't mind.
These functions work for HiROM. I guess I may as well post again once I make functions for ExHiROM and ExLoROM, so if anyone else is hunting for data and stumbles across this thread, they will find what they need.
Your layout has been removed.