Thomas Fach-Pedersen
@madmoose

Digging through the Dune executable I came across the functions and definitions that make up the results screen.

Dune supports interpolated strings, where variables are substituted in based on escape codes, but here the strings are loaded in and the default values are simply overwritten in memory.

The bottom frieze isn't correct for the results screen but it does show off the cute little date and time indicator… 🙂

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

Cryo's Dune displays its text in variable-width fonts with justified text layout. It has two fonts for latin scripts and two for Fremen.

When you choose the Fremen language, Dune just uses the French localization with this custom font 🙂

The fonts are in the resources DNCHAR and DNCHAR2. Each store a table of 256 glyph widths, followed by 128 8x9 glyphs and 128 8x7 glyphs.

(Font extraction has been added to dune-extract)

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

There's probably no line in any game – indeed, any written media – more deep, powerful, or weighty than the first in-game spoken line from Cryo's Dune:

"I am the Duke Leto Atreides, your father."

The lip sync system isn't hooked up properly yet, but here's all the lip sync frames for your enjoyment.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

The first two sietches now appear to render perfectly.

Bug fixes were needed for the sprite rendering (y-flip was broken…), sprite scaling (don't confuse width, output pitch and input pitch…), the gradient renderer (remember to add gradient y-delta after every line…), and the random number generator that fuzzes the gradient value (remember the RNG state across lines…)

Also two more rooms from the palace, because they're nice!

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

I made a quick utility in Rust to extract resources and sprites from Dune's DUNE.DAT: github.com/madmoose/dune-extra

The sprites are exported to png with alpha transparency.

I got tired of hacking my engine every time I wanted to inspect something more closely…

Not all the sprite sheets have a palette so some of them will export in grayscale. Also, there's no way to tell if a resource is a sprite sheet. I'll probably include a list.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

Here's a visualization of the non-moving parts of Leto's face.

The placement of the face sprites are defined in the last block of the sprite sheet file, in this case LETO.HSQ.

The data defines a number of facial expressions (each a list of sprites-id, x, and y), and a number of facial expression sequences.

I’m still working out how exactly these interact, but the first list appears to be all the static parts.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

It took a while but I finally found where Dune draws the talking heads. This is 9 sprites put together.

The game builds a list of the sprites (still working on how), and if I copy the list from my emulator, “Duke Leto, your father” show's up.

I spent a long time on how the game reads the lip sync data that's in the .voc-files, but Dune completely ignores that when audio is not enabled – and my emulator doesn't have audio yet…

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

"The planet is Arrakis, also known as… Dune."

I reverse engineered the globe rendering code a good while ago, and finally decided to integrate it into the engine.

There's a couple of lookup tables, some pre-calculation, and a bit of 16.16 fixed point math. Luckily reverse engineering it doesn't mean you have to understand how it works!

This video also highlights the need for a rescaler from the non-square pixels of 320x200.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

I've worked out which part of the code fetches lip sync data for the character animations, but the character rendering appears to reach into the UI code so I thought I'd work a bit on that code to get some clarity.

Here's the palace throne room with the ui frieze at the bottom. The interface layout is stored as a list of icon IDs and positions in the executable.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

The palace rooms from the intro now render pixel-perfectly, aside from the main characters.

The ready room uses only sprites, but Lady Jessica's and Duke Leto's rooms use polygons and line drawing. The gradient-filled polygons incorporate a random number generator to provide some dithering, and the line drawing code supports stippling.

The attached video shows the rooms being drawn piece by piece.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

The first three rooms of the palace now render almost perfectly. There's some off-by-one errors in the polygon rendering code which I'll have to chase down, and there's still an unimplemented line drawing command.

Dune can draw gradient-filled polygons with a bit of noise added to the color, which these rooms don't really show off. Once the code's complete I'll have to validate it byte-for-byte with the original.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

I had a busy day full of activities that were not reverse engineering related so I decided to complete a tiny task I'd put off, and I implemented subtitles for the Princess Irulan video.

The list of frames on which to show and hide subtitles are hardcoded in the executable.

The available languages are American English, British English, French, German, Italian, Spanish, and Fremen – which is French with a custom alphabet.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

Here’s what the ready room looks like a) when you fail to subtract 1 from the sprite id, and b) when you fail to apply the flip flag from the room definition.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

After the desert flyover segment we go into the Palace ready room with a nice transition. It consists of 24 sprites, half of them flipped horizontally.

The rooms are drawn with sprites, gradient-filled polygons and simple lines. They can also define positions where characters can be placed.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

I was going to say that my body is ready but it is, in fact, quite ill-prepared.

#brettdomino #brettdominotrio

Thomas Fach-Pedersen
@madmoose

Now with a cool pixely transition between the sky segment and the desert flyover segment:

(Many of the segments in the intro start with a transition from a black screen, which makes for a non-enticing video preview image… the video is neat when you play it, I promise!)

Thomas Fach-Pedersen
@madmoose

The next section of the Dune intro is this lovely desert flyover.

The previous videos were played by simply calling the draw-next-frame-if-available function in a loop, but in the spirit of TMTOWTDI this one uses the callback function list I mentioned previously.

The video also has a flag in the resource list that causes it be drawn to the screen 24 lines down.

Next section uses room drawing. I should do transitions soon…

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

This short scene with some lovely palette-only animation consists of a fade-in and two palette transitions.

The palette transitions are driven from a list of callbacks that are run at regular intervals. Dune appears to allow up to 20 functions in the list, but the function to add to the list is only referenced 18 places in the whole game and I doubt much more than two are ever running at the same time.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

Finally we get to the first non-video segment of the Dune intro.

This image is constructed of 6 sprites, stored in a 4bpp run-length encoding. Every pixel in the sprites stores a value from 0 to 15 and the caller of the sprite drawing function can then specify a palette offset that the value is added to. Calling it with a palette offset of 255 is how you tell it that you want 8bpp decoding instead of 4bpp.

Dune has a lot of interesting palette-based animation.

Thomas Fach-Pedersen
@madmoose

The various segments of the intro are defined in a list in the executable, and every segment is defined by two functions, one to loads the fade-in image, and one to play the video or animation.

Oddly, this flying Dune logo part is actually defined as three segments. Segment 1 loads the video and displays the first image, but the play function is an empty function. Segment 2 has an empty load function and then plays 86 frames of the video. The last segment then plays the rest of the video.

Thomas Fach-Pedersen
@madmoose

The next part of the intro is a clip from intro of the 1984 Dune movie featuring Virginia Madsen as Princess Irulan.

The game includes 10 or so clips from the movie, and to save some space they're compressed at 1/4 resolution, drawn on screen with horizontal and vertical black bars. Strangely you have to dig through the in-game book to find the other videos.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

For the “Virgin Games Presents” screen, some of the frames are encoded using an 8bpp run-length encoding.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

The intro to Cryo Interactive's Dune from 1992 is very long, at least in the cd version, and consists of a number of videos and animated screens.

The first video in the intro shows the logo of the game's publisher, Virgin. In this video every frame is individually compressed with Cryo's HSQ compressor.

#dosgaming #retrogaming #reverseengineering #dune #CryoInteractive

Thomas Fach-Pedersen
@madmoose

I decoded the first in-game frame from the demo of ReadySoft's "Brain Dead 13" FMV game from 1995.

ReadySoft is best known for Dragon's Lair and Space Ace.

The game runs in 320x200, but in planar made with a frame pitch of 328 pixels (or 82 in plane-pitch…), which isn't fun to wrap your head around, but on the other hand they were nice enough to release the demo with debug symbols!

#dosgaming #retrogaming #reverseengineering