Porting an RPG to Flash: Part II – Starting the data conversion

Last time, I finished by going through all the Etirites data files and considering how I could convert them to suitable formats for Flash to read. I’m itching to get started now. Let’s go write a graphics converter.

LSG to PNG conversion

First step: get libpng installed on my machine. (I’m using the MinGW compiler on Windows and writing the conversion utilities in C. A scripting language like Python might have been a better choice for some of them, but right now I’m more familiar with C so I can probably be just as productive with it). It depends on Zlib so compile and install that first. That was easy… everything seemed to just work.

Second step: find some example code for using libpng. I basically just want to be able to write an image in PNG format. Found some nice simple code on the web courtesy of Guillaume Cottenceau, and by modifying that I mange to write my first 32-bit PNG file. That was easy, too!

Now for the LSG loading. I seem to remember there were 2 slightly different versions of the LSG format – the later one could handle bigger graphics, more graphics, etc., but looking at the Etirites code it only seems to handle the first version so that’s all we’ll need to do. Though I might want to add v2 support later if I ever feel like converting one of my other old projects.

OK, that’s the LSG being loaded now – I can see a weird looking greyscale version of the first boss in the output PNG now! Fixing it up to use the Etirites palette, he appears in full colour. But as I suspected, very tiny looking.

Let’s scale him up, just doubling each pixel in both dimensions to begin with.

Eww! As I also suspected, far too pixellated. A quick search on Wikipedia for pixel art scaling algorithms and I’ve knocked together an EPX (AKA Scale2x or AdvMAME2x) scaler. It’s not the most advanced one but it is easy to code and seems to work quite well. Much better!

Now to make it able to handle multiple LSG frames and put them all into one PNG. That didn’t take long and now I have a converter that can convert all of the Etirites LSG files. I soon have a pile of them in PNG format. They look much nicer with the up-scaling as well… “Return of the Etirites… Now in HD!” ūüėÄ

Other graphics conversion

The Gimp can indeed open the TIFFs, but having seen what the up-scaling did to¬†the LSGs, I want to do it to the other graphics as well. Looks like I’ll need¬†to write another converter. Oh, and one for the font as well.

Those weren’t too hard to do. The map looks nice up-scaled. Not so sure about¬†the font or the swords, but they should be ok at least. So that’s all the¬†graphical data converted to Flash-friendly PNG format now. Not bad for a¬†day’s work.

Music conversion

Converting the music by playing the game in DosBox wasn’t as easy as I thought.¬†For a start, there’s no “sound test” or anything similar so getting all the¬†tunes would mean playing right to the end – even with the cheat mode that¬†would take time. Also, some of the tunes are quite long and don’t always play¬†to their full length in the game.

So what to do? There were several options…

  1. Find the original MIDI files. The tunes were originally created as MIDI before being converted to LSM.
  2. Hack the game source code to make it play any tunes we like. This would mean¬†setting up a DOS compiler in order to rebuild the game. It probably wouldn’t be too hard to get trusty old DJGPP installed again, but my custom structured assembler tool could be challenging to find and get working.
  3. Hack the game binary to play any tunes we like. This isn’t necessarily as¬†insane as it probably sounds… for example, if I could find the call that plays¬†the menu tune (which shouldn’t be too hard with access to the source code), I could probably get it to play any other tune on the menu by¬†changing one single byte.
  4. Write a quick and simple Windows LSM player program. Though given that I’ve¬†forgotten almost everything I used to know about MIDI programming, this¬†probably wouldn’t be a very quick or simple option.
  5. Write a reverse converter to convert the LSM files back to MIDI. Likely to be difficult as the LSM files are missing quite a bit of information that the MIDIs should have.

All of those apart from the first could be at least a little tricky, so naturally I was glad to find all the original MIDI files in a long-forgotten backed up directory on my external hard drive. Woo hoo! The tempos are all wrong but that should be easily fixed by playing with them in a MIDI studio.


Leave a Reply