How do I byteswap a SNES rom?
Moderators: B00daW, Moderators
Forum rules
1. NO BLATANT PIRACY. This includes reproducing homebrew less than 10 years old, with the exception of free software.
2. No advertising your reproductions, with the exception of free software.
3. Be nice. See RFC 1855 if you aren't sure what this means.
1. NO BLATANT PIRACY. This includes reproducing homebrew less than 10 years old, with the exception of free software.
2. No advertising your reproductions, with the exception of free software.
3. Be nice. See RFC 1855 if you aren't sure what this means.
-
- Posts: 19
- Joined: Sun Jun 14, 2009 6:35 am
How do I byteswap a SNES rom?
Hi,
I am trying to make a repro of a romhack to play on real hardware. I found the FeRAM project on github. The only thing I am struggling with is that it states the rom needs to be byteswapped. What does that mean? How is it done? I am thankful for all points in the right direction.
Thanks!
Nidhoegger
I am trying to make a repro of a romhack to play on real hardware. I found the FeRAM project on github. The only thing I am struggling with is that it states the rom needs to be byteswapped. What does that mean? How is it done? I am thankful for all points in the right direction.
Thanks!
Nidhoegger
Re: How do I byteswap a SNES rom?
Whether the ROM needs to be byteswapped depends on your programmer.
16-bit ROMs can be assumed to need to be programmed little-endian or big-endian, and the programmer just needs to agree with whatever's using the 'PROM afterwards.
Your programmer should have this functionality built-in. Otherwise, almost any hex editor will also be usable.
16-bit ROMs can be assumed to need to be programmed little-endian or big-endian, and the programmer just needs to agree with whatever's using the 'PROM afterwards.
Your programmer should have this functionality built-in. Otherwise, almost any hex editor will also be usable.
- jeffythedragonslayer
- Posts: 344
- Joined: Thu Dec 09, 2021 12:29 pm
Re: How do I byteswap a SNES rom?
This example visualizes how byteswapping switches adjacent characters around:
https://www.reddit.com/r/emulation/comm ... lained_for
Oh and FYI, we do have a dedicated SNES section on this forum.
https://www.reddit.com/r/emulation/comm ... lained_for
Oh and FYI, we do have a dedicated SNES section on this forum.
Re: How do I byteswap a SNES rom?
This repro subforum is for SNES, as well.
-
- Posts: 19
- Joined: Sun Jun 14, 2009 6:35 am
Re: How do I byteswap a SNES rom?
When trying to post in the SNES Section is explicitly redirects me to here for questions about repros. Thank you for the Link, ill have a look at it.jeffythedragonslayer wrote: ↑Sat Mar 04, 2023 2:04 am This example visualizes how byteswapping switches adjacent characters around:
https://www.reddit.com/r/emulation/comm ... lained_for
Oh and FYI, we do have a dedicated SNES section on this forum.
EDIT: No Idea if something is wrong with my Browser, but I only see a blank space where I guess the visualizationshould be...
Re: How do I byteswap a SNES rom?
WHAT DOES BYTE SWAPPING MEAN?
The following diagram shows the hex values in a sample 6-byte file before and after byte swapping it:
MAYBE JUST TRY BOTH WAYS
If the ROM programming process is quick and reprogramming a ROM is not harmful, then maybe you can just try both ways: program the ROM with the original file and if that doesn't work try byte swapping the file then reprogramming the ROM with that. One way should work. See the bottom of this post for a way to byte swap the file on a Windows computer.
If reprogramming the ROM is not feasible or you want to understand when byte swapping the file is required, read the next section.
IS BYTE SWAPPING REQUIRED?
To learn what little-endian and big-endian mean, look at the Wikipedia article Endianness, especially the example diagram. The example in the article is 32 bits (like hex 0A0B0C0D), but the cases in this thread will be 16 bits (like hex 0A0B).
A. What endianness the ROM programmer is expecting the file to be in, and
B. What endianness the SNES FeRAM Cart is using to the present the physical 16-bit ROM as an 8-bit ROM to the CPU.
For A, Presumably the ROM programmer used to write the 16-bit ROM will have some documentation that indicates if it reads from files using little-endian or big-endian ordering. Nidhoegger, if you can't tell what file endianness your ROM programmer needs, I guess you can tell us your ROM programmer's brand and model and we can search online for more information.
But for B, can anyone tell if the SNES FeRAM Cart "converts" the physical 16-bit ROM into a virtual 8-bit ROM using little-ending or big-endian ordering?
As lidnariq says, if the ROM programmer has an option to choose the endianness of the file, then that can be used instead of byte swapping the file. Just choose whichever endianness the circuit is using.
If the ROM programmer requires one kind of endianness but the circuit expects the other type of endianness, then you should byte swap the file before the ROM programmer reads it.
Take a look at the following images for the four possible correct cases.
Legend for the images:
(1) the file: (a) without byte swapping, (b) after byte swapping.
(2) the ROM programmer interprets the file: (a) in little-endian order, (b) in big-endian order.
(3) the physical ROM.
(4) the circuit presents the physical ROM's values: (a) in little-endian order, (b) in big-endian order.
(5) what the CPU sees.
HOW TO BYTE SWAP A FILE
Here's a way to byte swap a file on a Windows computer:
1. Download the file binutils-2.32-1-mingw32-bin.tar.xz
2. Use 7-zip to open the file, find the objcopy.exe file inside and extract it.
3. In a Command Prompt, enter the the following command:
objcopy -I binary -O binary --reverse-bytes=2 inputfile.bin outputfile.bin
where inputfile.bin is the original file and outputfile.bin will be the byte-swapped file.
Lidnariq also suggests almost any hex editor can do this byte swapping. But in my experience with two hex editors on Windows (XVI32 and HxD), they don't have byte swapping functions. And for a past project I remember searching for a hex editor that could swap the endianness of a file but didn't find one. However, I was only focused on finding tools for Windows and my search was very quick.
Lidnariq (or anyone else), can you suggest any specific hex editors (or any other tools) that can byte swap a file?
The following diagram shows the hex values in a sample 6-byte file before and after byte swapping it:
Code: Select all
Before: 0A 0B 0C 0D 0E 0F
× × ×
After: 0B 0A 0D 0C 0F 0E
MAYBE JUST TRY BOTH WAYS
If the ROM programming process is quick and reprogramming a ROM is not harmful, then maybe you can just try both ways: program the ROM with the original file and if that doesn't work try byte swapping the file then reprogramming the ROM with that. One way should work. See the bottom of this post for a way to byte swap the file on a Windows computer.
If reprogramming the ROM is not feasible or you want to understand when byte swapping the file is required, read the next section.
IS BYTE SWAPPING REQUIRED?
To learn what little-endian and big-endian mean, look at the Wikipedia article Endianness, especially the example diagram. The example in the article is 32 bits (like hex 0A0B0C0D), but the cases in this thread will be 16 bits (like hex 0A0B).
More specifically, we can tell if byte swapping the file is needed once we know both of the following things:
A. What endianness the ROM programmer is expecting the file to be in, and
B. What endianness the SNES FeRAM Cart is using to the present the physical 16-bit ROM as an 8-bit ROM to the CPU.
For A, Presumably the ROM programmer used to write the 16-bit ROM will have some documentation that indicates if it reads from files using little-endian or big-endian ordering. Nidhoegger, if you can't tell what file endianness your ROM programmer needs, I guess you can tell us your ROM programmer's brand and model and we can search online for more information.
But for B, can anyone tell if the SNES FeRAM Cart "converts" the physical 16-bit ROM into a virtual 8-bit ROM using little-ending or big-endian ordering?
As lidnariq says, if the ROM programmer has an option to choose the endianness of the file, then that can be used instead of byte swapping the file. Just choose whichever endianness the circuit is using.
If the ROM programmer requires one kind of endianness but the circuit expects the other type of endianness, then you should byte swap the file before the ROM programmer reads it.
Take a look at the following images for the four possible correct cases.
Legend for the images:
(1) the file: (a) without byte swapping, (b) after byte swapping.
(2) the ROM programmer interprets the file: (a) in little-endian order, (b) in big-endian order.
(3) the physical ROM.
(4) the circuit presents the physical ROM's values: (a) in little-endian order, (b) in big-endian order.
(5) what the CPU sees.
HOW TO BYTE SWAP A FILE
Here's a way to byte swap a file on a Windows computer:
1. Download the file binutils-2.32-1-mingw32-bin.tar.xz
2. Use 7-zip to open the file, find the objcopy.exe file inside and extract it.
3. In a Command Prompt, enter the the following command:
objcopy -I binary -O binary --reverse-bytes=2 inputfile.bin outputfile.bin
where inputfile.bin is the original file and outputfile.bin will be the byte-swapped file.
Lidnariq also suggests almost any hex editor can do this byte swapping. But in my experience with two hex editors on Windows (XVI32 and HxD), they don't have byte swapping functions. And for a past project I remember searching for a hex editor that could swap the endianness of a file but didn't find one. However, I was only focused on finding tools for Windows and my search was very quick.
Lidnariq (or anyone else), can you suggest any specific hex editors (or any other tools) that can byte swap a file?
Re: How do I byteswap a SNES rom?
Winhex is a good one and it does byte swap (and other swaps too) easily.Lidnariq also suggests almost any hex editor can do this byte swapping. But in my experience with two hex editors on Windows (XVI32 and HxD), they don't have byte swapping functions. And for a past project I remember searching for a hex editor that could swap the endianness of a file but didn't find one.
I’m unclear why you need/want byte swap to begin with? I’ve NEVER had to byteswap anything for a repo. If we were talking about Genesis carts, then yes, byte swapping makes sense for a repo to run on OEM carts.
Re: How do I byteswap a SNES rom?
This particular cart (the SNES FeRAM Cart) is built with a 16-bit ROM -- that is, each address in the ROM chip outputs 16 data bits -- but the SNES expects 8 data bits, and files on computers also store values in byte units. As you probably know, any time you have to break down a multi-byte value into individual bytes, there's two ways you can order the bytes. If the writing process orders the bytes one way and the reading process orders the bytes the other way, you'll need to compensate somehow, such as byte swapping the source file before using it to burn the ROM.
If the cart was built on a ROM that outputs 8 data bits, then the processes would be based on bytes all the way through and no byte ordering differences could happen.
Re: How do I byteswap a SNES rom?
If I understand correctly, this cart when it was being designed, the authors pinned the rom such that a “non-native” programming of the rom would be needed? Basically a mistake but easily corrected by byteswapping. I have never used that cart pcb before so I didn’t realize its issue. We make our own carts so I never looked into this one.Bavi_H wrote: ↑Sat Mar 04, 2023 10:25 pmThis particular cart (the SNES FeRAM Cart) is built with a 16-bit ROM -- that is, each address in the ROM chip outputs 16 data bits -- but the SNES expects 8 data bits, and files on computers also store values in byte units. As you probably know, any time you have to break down a multi-byte value into individual bytes, there's two ways you can order the bytes. If the writing process orders the bytes one way and the reading process orders the bytes the other way, you'll need to compensate somehow, such as byte swapping the source file before using it to burn the ROM.
If the cart was built on a ROM that outputs 8 data bits, then the processes would be based on bytes all the way through and no byte ordering differences could happen.