Petri Häkkinen Profile picture
Designer & programmer of Legend of Grimrock and Druidstone. Currently working on The Fall of the Black Mage (VIC-20) and Alan Wake 2.

May 11, 19 tweets

Reversing Bloodfest Part 2: The MYSTERY of *.IM Files! A thread🧵

Last time we cracked the main graphics and sound effects banks. Unfortunately these do not contain the fullscreen background images such as the glorious title and game over screens.

Most likely the screens are stored in these pesky *.IM files that we failed to decode last time:

I think the screens cannot be found by scanning memory dumps because they are very likely dynamically loaded and unpacked only when needed. A 320x256 image with 32 colors (5 bitplanes) is about 50 KB. It would simply have been too costly to keep them in memory all the time.

When I looked at the sample banks it looked like data files were encypted with something simple like XORring the bits. But is that really the case? Let's take a closer look...

We already know that *.IM files were compressed with Turbo Imploder 4.0. After unpacking here's how they look like. This is gfx/stargate.im. All other im files in gfx folder have a similar beginning.

The large amount of zeroes and the curious 12031990 in the beginning make me think this data is not scrambled.

Hmm... 12031990? 12th March 1990? That's too much of a coincidence!

I bet that number must mean something. It cannot be just some random scrambled bits. Especially since AMOS was created around that time... Let's look into the AMOS Professional manual once more and see if we can find any clues...

Bingo! It’s a magic number indicating a packed screen.

So we have a packed file inside a packed file! That's probably not very good for compression, but ehh...

Luckily the manual says it's created with SPACK instruction in AMOS and that it can be unpacked with UNPACK instruction. Let's try that next.

This must work right?

Result: a black screen. Bummer!

Hmm, the other graphics files had broken palettes. Maybe the zeroes in the unpacked IM file are supposed to be the palette but it has been zeroed out?

Let's try to override the palette with some random colors. Whoah! It's working!

I have a theory. Fading! AMOS simply uses the palette as is from the file. So if the palette was there, the image would appear fully faded in initially. The code must fade in the correct palette after unpacking. Which also means the palette is probably stored directly in the exe.

Typing "Palette $000,$EEF,$AAD,$227,$D95,$B73,$A62,$942,$831,$731,$621,$510,$400,$300,$200,$100,$CCC,$AAB,$99A,$779,$558,$447,$336,$225,..." brought back memories of taking turns with a childhood friend and typing in C64 programs from Mikrobitti magazine on a summer day.

That's it. The mystery of the IM files has been finally solved. Phew! But one thing remains... "12031990"?

There’s another file format described in the AMOS manual with a similar header. So it IS a date code! Francois Lionet is the author of AMOS. March 12th 1990 must be a very important date to him. (Or is it December 3rd 1990? The conventions differ across the world.)

There’s this interesting section about the history of AMOS in the book. Francois was in the French army in 1990 so maybe something important happened there? Or maybe he got married on that date? ”Baby Lionet” was born in 1992 which could support that theory.

Does anybody know? It would be very interesting to know, AMOS having had such an impact on my career and life.

And so we come to the end of the thread. Thanks for reading!

P.S. How did I get the palette for that stargate image? I forgot to mention earlier... I cheated a bit (again) and grabbed it using WinUAE by dumping the video registers.

Below's a reward to you for getting this far into the thread. RRRRAAGGH!! 👋

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling