Original Supertris

Saturday, February 23, 2013

Starting to Parse

I have developed the Lightspeed Pascal binary source code parser to the point where it can parse the source file with the constants, types, and global variables in it. Basically it turns this:

00000000  c6 07 00 00 00 12 07 47  6c 6f 62 61 6c 73 98 01  |.......Globals..|
00000010  94 01 c8 03 00 00 00 00  94 01 9e 01 7e 04 05 53  |............~..S|
00000020  6f 75 6e 64 7c 01 7e 04  05 4e 6f 69 73 65 98 01  |ound|.~..Noise..|
00000030  94 01 a2 01 94 01 92 16  00 01 26 7b 20 6e 75 6d  |..........&{ num|
00000040  62 65 72 73 20 6f 66 20  73 6f 75 6e 64 73 20 6d  |bers of sounds m|
00000050  69 6e 75 73 20 31 2c 20  67 6f 74 20 69 74 3f 20  |inus 1, got it? |
00000060  7d 08 cc 07 0a 47 6f 6f  64 53 6f 75 6e 64 73 08  |}....GoodSounds.|
00000070  7a 03 03 00 00 0c 98 01  cc 06 09 42 61 64 53 6f  |z..........BadSo|
00000080  75 6e 64 73 7a 03 03 00  00 0f 98 01 cc 07 0b 43  |undsz..........C|
00000090  6c 65 61 72 53 6f 75 6e  64 73 7a 03 03 00 00 07  |learSoundsz.....|
000000a0  98 01 cc 07 0b 4c 65 76  65 6c 53 6f 75 6e 64 73  |.....LevelSounds|
000000b0  7a 03 03 00 00 05 98 01  94 01 92 08 00 01 0b 7b  |z..............{|
000000c0  20 6d 65 6e 75 20 49 44  73 7d cc 05 07 41 70 70  | menu IDs}...App|
000000d0  6c 65 49 44 7a 03 03 00  00 01 98 01 cc 06 09 41  |leIDz..........A|
000000e0  62 6f 75 74 49 74 65 6d  7a 03 03 00 00 01 98 01  |boutItemz.......|
000000f0  94 01 cc 05 06 46 69 6c  65 49 44 08 7a 03 03 00  |.....FileID.z...|
00000100  00 02 98 01 cc 06 08 51  75 69 74 49 74 65 6d 08  |.......QuitItem.|
00000110  7a 03 03 00 00 01 98 01  94 01 cc 05 06 45 64 69  |z............Edi|
00000120  74 49 44 08 7a 03 03 00  00 03 98 01 cc 06 08 55  |tID.z..........U|
00000130  6e 64 6f 49 74 65 6d 08  7a 03 03 00 00 01 98 01  |ndoItem.z.......|
00000140  cc 05 07 43 75 74 49 74  65 6d 7a 03 03 00 00 03  |...CutItemz.....|

into this:

unit Globals;

interface

uses Sound, Noise;

const

{ numbers of sounds minus 1, got it? }
GoodSounds = 12;
BadSounds = 15;
ClearSounds = 7;
LevelSounds = 5;

{ menu IDs}

AppleID = 1;
AboutItem = 1;

FileID = 2;

QuitItem = 1;

EditID = 3;

UndoItem = 1;
CutItem = 3;

So far this is just declarations and comments. Real code will follow.

Sunday, February 17, 2013

The Sleeper Re-Awakens

So that last post was a false alarm. I'm not sure what I was up to in the summer of 2006, but we had a second child in 2007 and now I am finally starting to have enough spare time to resume work on this project. Thanks everyone for your comments and patience.

I have good news and bad news. The good news is that I have actually been working on this project for a few weeks now, albeit slowly. The fact that the code has been leading the blog is probably a good thing. The bad news is that an extraordinary amount of bit rot has set in over the past two decades and it will take some effort to get the project off the ground. Here's what I have so far.

I created a github project for this, where you can look at the source code, etc. I decided to go with HTML5 as a platform so it will be largely platform independent. I hope it can work on most browsers, smartphones, and tablets. We'll see. Audio could be a challenge. But if they could do Angry Birds in HTML5, surely I can make Supertris work, too. There is a little bit of code there now that I wrote in the summer of 2011, just to get my feet wet with JavaScript and HTML5 game coding. It's not much now (you can't even clear rows), but it does demonstrate a game loop, screen updates, and keyboard control.

Anyway, rather than write something from scratch now, I want to be true to the original design of the game and use as much of its logic and algorithms as I can. Thus, my plan is to basically translate the original Pascal source into JavaScript and go from there. I'm not sure whether I want to manually translate the source or write something to do it automatically. That decision will be made once I can actually read the source. Read on:

While I have been diligent about migrating the original Lightspeed Pascal source code from stacks of 3.5" floppies to big hard disks to NAS devices (I'm on my second NAS, now), I never actually looked at the source itself until recently. Um, it's stored as binary files, not text. One of the nice features of Lightspeed Pascal's IDE was its automatic code formatting (boldface and indentation, mostly), which was pretty advanced for Reagan-era software, I understand. I guess it stored the source in a semi-parsed binary format to facilitate this. I recall an option when saving source code to save it in text or their proprietary format. I tried both and they looked the same on-screen, so I used their binary format for all but one of the source code files. D'Oh!

Thus my first task is to reverse engineer their format and generate readable Pascal output. I an writing a Python script to do this right now. It seems mostly straightforward, though there are a few byte code sequences that I do not yet understand. And it appears that they are using multiple bytes to encode syntactic elements where one would do. There must be a reason for this, but I have yet to determine what it is. Stay tuned....