Giter Club home page Giter Club logo

final-fantasy-msx2-de-compressor's Introduction

Final Fantasy MSX2: (De)Compressor Tool

About

This is a decompression and compression tool for .PIC files in Final Fantasy for the MSX2.

Technical

The compression for this game has is fairly odd. The scheme has write and fill behaviors, which is theoretically simple enough. When the algorithm first starts, it checks the first two bytes. If they're equal then is writes them to the decompression buffer YY times; YY being the value of the next byte. If the bytes are not equal, it just writes the first byte and the moves on to the next byte. The algorithm continues this process until it's done. Here's a breakdown of how this works:

  • XX XX YY = Fill
  • XX = Write byte

Conceptually, this algorithm is already quite flawed. Most algorithms have a byte that identifies what type of action the algorithm should take (if it's a fill or a write). I'm also oversimplifying the process for brevity sake.

There's other factors to keep in mind, such as the header. The header for the .PIC files is 0x30 bytes long: the last 0x20 is palette data, and the first 0x10 bytes I have not fully reverse engineered. Key values are the length and width size. In the decompression buffer, if the width is filled, then the remaining pixels are padded out. As for length, I couldn't figure out how it worked. As a result, when dumping data, a length size attribute must be specified.

While my explanation sounds reasonable enough, the implementation is a different story. To get the compression and decompression working, I had to essentially write C# code that looks and functions like assembly code to match the game's original Z80 assembly language code. There's a few edge cases that forced me to do so that don't make apparent sense. Once I got the something that worked, I ran away as fast as I could.

Usage

See below for terminal usage information.

Dumping

"FF MSX GFX.exe" "Dump" "%AddressOffset%" "%InputPathBaseGfxCompressed%" "%OutputPathBaseGfxUncompressed%"
  • AddressOffset: Specify where in the binary file the .PIC file starts. If you're working off an extracted image set this to "0x00"
  • InputPathBaseGfxCompressed: Path of the compressed image / binary file
  • OutputPathBaseGfxUncompressed: Where to write the uncompressed data. The file must already exist as this is where the header data is retrieved from.

Writing

"FF MSX GFX.exe" "Write" "%OutputPathGfxCompressed%" "%InputPathBaseGfxCompressed%"
  • OutputPathGfxCompressed: The file path where compressed date will be output to
  • InputPathBaseGfxCompressed: This in the path of the original .PIC file. It is needed for the header information.

Special thanks

  • TWE#3544

final-fantasy-msx2-de-compressor's People

Contributors

adboomlodestar avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.