News: 11 March 2016 - Forum Rules

Author Topic: How does one decompress graphics?  (Read 788 times)

Googie

  • Hero Member
  • *****
  • Posts: 1120
  • Keepin' ROM Hacking gangsta since 2003, baby!
    • View Profile
    • My work in progress ROM Hacking site
How does one decompress graphics?
« on: January 27, 2022, 09:26:23 am »
What's up, fellas.

A friend of mine is interested in making a full translation of the NES game Last Armageddon, I looked through the game and the graphics are compressed. So I wanna know how does one goes about decompressing the graphics in an NES game in order to make a translation?

Any tips would be helpful, it'll be cool to see this game translated, thanks fellas.  :D   

FAST6191

  • Hero Member
  • *****
  • Posts: 3526
    • View Profile
Re: How does one decompress graphics?
« Reply #1 on: January 27, 2022, 10:21:08 am »
How did you come to the conclusion things were compressed?

NES compression tends to be rather custom -- there is no BIOS or SDK that provided devs with easy options.
The NES is also rather slow and without much computing power, along with needing games to happen in real time, so you are in this case somewhat lucky.

The most common style of compression on the NES is probably going to be RLE, a primitive format but useful. If there is a repeated section, a run if you will, of characters then it will note the length of them (000000000 becomes some variation on the theme of 0x9).

You do also have tile reuse, dual tile encoding and other more game aware/game level methods to consider in this. These are comparatively more common on the NES than they might be on later systems.

Do also make sure to check nobody has looked at the game in question before, or maybe games from the same developer (coders like to reuse code they know works after all).

https://ece.uwaterloo.ca/~ece611/LempelZiv.pdf is what I usually point people at for higher level compressions seen on later systems but the principles still stand, and you will get some proto LZ (RLE is arguably a special case of it) and Huffman (basically substitute this value for this one from a table, the table being picked to represent the best choices for a substitution in that given case).

With knowledge of the compression formats, usually grabbing the decompressed version from RAM and comparing it to the data in the ROM you can figure out the format (there are only so many ways to say* substitute this value with this value or go here and grab this much data from elsewhere and paste it in here). It gets far easier if you know assembly though as you can watch everything it does in the process of getting it from the ROM to something decompressed in RAM, and relate it back to the higher level concepts from the document above but it is not essential for all of it, some of it will demand it though as it can get way too esoteric for even skilled hackers that have worked in it all before or have odd conditional actions where for some values it behaves oddly.

*most custom compression, including dev added something new for the next game they made, problems then amounting to "what is the flag to say "no compression in the next ? bytes" and "what is the split between where to go to read and how much to read", maybe with a slight tweak in window length for the sliding window stuff (pointers get large to the point of troubling your compression when you have to address a 4 gigabyte file to find a piece of matching data, if you restrict your decompression to within ?? bytes of the current location then pointers get smaller and compression ratios might well be better at the cost of potential in some exotic cases). Change any one of those and your trusting dumb decompression routine will fail when it dutifully tries to decode things as it was taught to but you can describe the changes in a sentence usually so code is easily enough changed.

Jorpho

  • Hero Member
  • *****
  • Posts: 5232
  • The cat screams with the voice of a man.
    • View Profile
Re: How does one decompress graphics?
« Reply #2 on: January 27, 2022, 10:25:48 am »
This signature is an illusion and is a trap devised by Satan. Go ahead dauntlessly! Make rapid progres!

Cyneprepou4uk

  • Hero Member
  • *****
  • Posts: 880
  • I am the baldest romhacker
    • View Profile
Re: How does one decompress graphics?
« Reply #3 on: January 27, 2022, 11:53:33 am »
Font graphics for this game is 1BPP.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7412
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: How does one decompress graphics?
« Reply #4 on: January 27, 2022, 12:00:59 pm »
So I wanna know how does one goes about decompressing the graphics in an NES game in order to make a translation?

Generally by learning 6502 ASM to read the game's code.
If it's not a popular game someone has already documented.

RLE was kind of common on NES.
LZSS was very common on SNES.
But still, you have to read the code to find the details of its implementation.
"My watch says 30 chickens" Google, 2018