News: 11 March 2016 - Forum Rules

Author Topic: Castlevania: Symphony of the Night (PS1) - compressed graphics  (Read 3270 times)


  • Jr. Member
  • **
  • Posts: 5
    • View Profile

I'm a hungarian fan-translator and I began my work on this title. Little did I know that according to a certain "Zone files technical documentation" written by Nyxojaele, the game uses compressed graphics for some of its visuals. I can do HEX editing and tile editing... basically stuff that involves low-level skills, but I can't make any sense of the documented method to get these graphics decompressed. And even then, there's the problem of injecting these graphics back to the game. The document states:

"Some graphics encountered are compressed to save space. This compression is not super-complex,
and it vaguely resembles RLE compression. Compressed graphics are stored linearly- that means
to decompress them, all you need to do is read in some compressed values, then output the
appropriate decompressed values. Rinse, repeat. After encountering the "end of graphic" value,
the entire array of decompressed values will be the actual graphic as it should be for loading
into VRAM.

The first 8 bytes are called "common values"- each byte being it's own value. These are values
that show up frequently in the compressed graphic, and later on will be referred to by index.
After the common values, all other values are stored as nybbles (2 values per byte, 4 bits
each)- these values should be read in the following manner:

 1) Read 1 value. This is the opcode- it represents what sort of compression exists for the
    coming value(s), or what action to take (such as the end of compression marker)
 2) Depending on the opcode, there may be parameter values following the opcode. Read these
    values as well.
 3) Calculate what the output values should be and add them to the output array.
 4) If the opcode was NOT the end of compression marker, go back to step 1, starting at the
    position immediately following the parameters, if any, in the compressed data.

The opcodes and parameters are as follows:
    Opcode    What to do with it
    0x0       Read 2 more values. Bitshift the first value left by 4, then add it to the 2nd
              value, and finally add 19 to that value. Append that many 0's (zeroes) to the
              decompressed array.
    0x1       Read 1 more value. Append that value to the decompressed array.
    0x2       Read 1 more value. Append that value twice to the decompressed array.
    0x3       Read 1 more value. Append that value to the decompressed array. Read and Append
              another value.
    0x4       Read 1 more value. Append that value to the decompressed array. Read and Append
              another value. Read and Append a 3rd value.
    0x5       Read 1 more value- This is your desired value. Read another value- This is your
              loop value. Append the desired value to the decompressed array, loop times.
    0x6       Read 1 more value. Append that many 0's (zeroes) to the decompressed array.
    0x7-0xE   Subtract 7 from the opcode and use that as an index into the common values array-
              From that value, the first 4bits are your loop value, and the last 4 bits are
              your desired value. Append your desired value to de decompressed array, loop
    0xF       Finish. This signals that decompression is done, and no more opcodes should be
              read from the compressed data."

I assume this needs some assembly knowledge, which I don't have (yet).

Any kind of guidance or help is appreciated. Right now, I know that some fonts are missing, namely the font that's used during the intro sequence (after prologue) and the fonts/graphics used for the "Level Up", "Heart Up" messages (also the "Final Stage: Bloodlines" and other fonts that are used for the zones' names.)

As far as I can tell, I extracted everything that's stored as RAW.

Thanks in advance.

- Feri


  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: Castlevania: Symphony of the Night (PS1) - compressed graphics
« Reply #1 on: July 20, 2019, 06:28:51 pm »
Given those instructions, you shouldn't need any assembly knowledge. If you know any kind of programming language, you can write a function to decompress those graphics, just by translating those instructions into code.

Simplest thing to do in general terms is open the file in binary read mode, and go through it byte-by-byte. Read the first 8 bytes (after the header if it has one), and store them in an array/list/whatever, depending on the language you're using, so it can be indexed when the proper instruction is read (the 0x07-0x0e instruction). Once you've done that, read each byte in order, and split it into nibbles (half-bytes).

nibble1 = byte >> 4
nibble2 = byte & 0x0f

You then want to have some kind of switch or if/else if control flow structure with a case for each of the opcodes. You'll test the first nibble against the cases to get into the logic for the matching opcode, then you'll execute that logic, reading additional bytes as necessary. The instructions are pretty straightforward for each opcode, and can easily be translated into code. As you read real 4-bit values (not opcodes or parameters), append them to a bit array. Loop through the file until you hit the end decompression opcode, at which point you have a decompressed file in your bit array, which you'll write to a new file.
« Last Edit: July 20, 2019, 09:27:39 pm by theflyingzamboni »
ROM wasn't hacked in a day.


  • Jr. Member
  • **
  • Posts: 8
    • View Profile
Re: Castlevania: Symphony of the Night (PS1) - compressed graphics
« Reply #2 on: September 20, 2019, 03:12:58 pm »
Are you translating the japanese or english version of the game? I have a tool to decomp and rebuild the japanese compression, but i don't tested in usa version, you only need to put the programmer name in credits.


  • Jr. Member
  • **
  • Posts: 3
    • View Profile
Re: Castlevania: Symphony of the Night (PS1) - compressed graphics
« Reply #3 on: January 08, 2020, 11:40:13 am »

Is it possible to have the tool to decompress please?
I'm translating the game as well.