Code Archaeology – How to revive a more than 30 year old game


When we opened the northern branch of CodeValue in Yokneam, Israel, about two years ago, we’ve decided to make a computer museum in our main meeting room. I took all of my old 8-bit computers, peripherals, programming books and other old devices that I collected since I was a little boy and used them to decorate the room. We have Commodore 128, Sinclair QL, Atari 2600, Amiga 3000, Olivetti PC1, Casio PB 1000, Windows XP Tablet, Windows 95 laptop and other machines as well as interesting artifacts such as punched cards, Magnetic-core memory. I also took all of my old computer magazines and books, so that anyone who is waiting for a meeting to start, can read about the first personal computers or learn 6502, x86, or Z80 assembler.


Among the computer magazines, I found an old folder from 1987. In 1987 I was an AFS student, I took part in a youth exchange program where I became an American teenager for six month. I was a family member of the lovely Counsel family in East Circle Drive, Whitefish Bay Wisconsin. I also joined the WFB High School and took the computer class. In this class we learned the 6502 assembly language and programmed the Apple IIe.


Since I was a Commodore fan boy, I already knew the 6502 assembly (My first computer at home was the Commodore VIC 20 where the only way to do something serious with 5KB machine was to use machine language). This was the first time that I had a real computer class and a very good teacher that helped me to polish my development skills. I very soon became the best student in the class, always getting A+ extra credits for all my projects. The folder that I found among my books and magazines contains all of my homework, many pages of long assembly code printed on a dot matrix printer.



One of the lists, contains the last project – the Annoying Snake game.


This code is about 1000 lines long. I thought – can I bring this game to life? can I use an Apple IIe emulator to run a code that I wrote more then 30 years ago when I was 17? I decided to give it a try.

First thing first, I took my phone and took a picture of each and every page of the code. On the one hand, it allowed me to magnify the text to find out whether it is ‘E’ or ‘F’ or other hard to read letters. On the other hand, sometimes I got a line that was cut to half between two consecutive pages and I needed to realize the opcode and data of that command.

The development and runtime environment

I started by searching for an apple II emulator, and found a very good one, the open source AppleWin. This emulator has some very good features, among them the ability to accelerate the speed of the machine – very important for fast macro assembly compilation (the ASM command). Another great feature is the built-in debugger that helped me find those location where I didn’t put the correct opcode or data.


The emulator has two disk drives emulator and it lets you switch between them, which makes it very easy to switch between the macro assembly disk and the data disk.

Although I didn’t use the Merlin macro assembly, I found this video very useful to set up my dev environment. It explains how to use the CiderPress program to work with disk images as well as how to start using the emulator.

The macro assembler

Once I had the environment set up, I needed to find the macro assembler program that I used in the WFB high school 30 years ago. I googled for Apple II and macro assembly and some of the macro assembly directives such as .HS and found the S-C Macro assembly. The problem is that this assembly is a bit different then the one I had in my original code. It lacks some of the macros and it uses some directive in a different way. It took me some time to understand how to migrate the code to use this dialect, the main changes are: The .HS directive takes the data without spaces or dots, for example instead of .HS 80.80.0D you write .HS 80800D. The opcode .AS for strings works the same however there is no .AT directive. Searching the web, I have found that the .AT is like the .AS, the only difference is that the last character in .AT has the most significant bit set to one to sign the end of string – like the modern ‘\0’ without wasting another byte. I also found that the .AS can do this trick by adding dash as a prefix for the string: .AS –”E” The S-C assembler could not take an ASCII or binary data (or there is a way that I couldn’t find), so I had to migrate commands such as ORA #%1000,0111 to ORA #$87 and CMP #’ ‘ to CMP #$A0, but this wasn’t so hard to migrate since the original code print included the resulting machine language code nearby the macro assembly text.

I should have spent more time browsing sites such as this one, to find a better match to the original assembly dialect, but I wanted to get started, so I decided to use the S-C assembler that I have found.

Entering the code:

Since the old printed pages where not easy to OCR, and since I had to migrate and translate many commands, I spent several hours typing, translating and migrating the code. I had found out that the S-C assembler cannot have line numbers above 9999, so I had to change the line numbers at the end of the code to overcome this limitation. After several hours I could assemble (compile) the code. It took me sometime to understand how to run a binary code (the BRUN command) and how to list the files on the disk (The CATALOG command), eventually it started, but very soon it stopped. I had to go over the source code again and verify that I got all correctly, I have found at least five places that I put the wrong opcode or data. I got into endless loops and invalid states, but the emulator built-in debugger was very helpful.

Bringing the game back to life

“Huston, we have a problem!” When I started this project I thought that the code list is all I need to revive the game. I found, however, that the game uses the BLOAD command to read files from the disk. Actually, there are two places that my original snake game uses the disk, to load and save the high score table and to load the 8 game rooms. For the high score, I read the code that saves a new high score and understood that it uses 160 bytes in from address 0x2000, where 14 bytes are used to hold the name, then a byte for the level and room number, and two bytes for the score. I wrote a very simple Basic program that creates an empty high score file:

10  FOR I = 0 TO 180 STEP 18

20  FOR X = 0 TO 13

30  POKE 8192 + X + I,255

40  NEXT X

45  POKE 8192 + I + 13,160

50  POKE 8192 + I + 14,255

60  POKE 8192 + I + 15,255

70  POKE 8192 + I + 16,0

80  POKE 8192 + I + 17,0

90  NEXT I

100  PRINT  CHR$ (4);”BSAVE HIGH SCORE,A8192,L180″

The other binary files are the room layout, a LO-RES binary file format that starts in address 1024, and spans another 1024 bytes. The problem is that the Apple graphics memory has holes. Reading some Apple II BASIC documents, I found out that I can create a lo-res graphics using commands such as GR to switch from text mode to graphic mode and COLOR, HLIN, VLIN and PLOT to do the graphics. I created a program in basic that generates rooms, for example:

… Room 8:

800  GOSUB 1100

810  GOSUB 1000

820  COLOR= 15

830  FOR I = 5 TO 33 STEP 8

840  HLIN 3,35 AT I

850  HLIN 3,35 AT I + 1

860  NEXT

870  FOR I = 7 TO 34 STEP 8

880  VLIN I,I + 3 AT I

882  VLIN I,I + 3 AT I + 1

884  NEXT

890  PRINT CHR$ (4)”BSAVE ROOM 8,A1024,L1024″

990  END


1010  COLOR= 15

1020  HLIN 0,39 AT 0

1030  HLIN 0,39 AT 39

1040  VLIN 0,39 AT 0

1050  VLIN 0,39 AT 39

1060  RETURN



1110  COLOR= 0

1120  FOR I = 0 TO 39

1130  HLIN 0,39 AT I

1140  NEXT

1150  RETURN

With 8 rooms and empty high score table, the game now runs:

To start the game, use: ]BRUN GAME



I prefer to change the keys and use the modern PC cursor keys. So press Y and follow the instructions.


The first room is an empty room with no obstacles:



Room 5 has more complex obstacle.

The name of the game: “The Annoying Snake” came from its annoying music, so you should set the sound in the emulator to hear it:


I have succeeded running the game on other apple II emulators:

Android, the a2ix emulator:

Web based (java script): appleIIjs:



I am very happy that I could bring back to life one of my oldest pieces of code.  I have two Amiga games from 1992 on the web:

However, I don’t have the ‘C’ language source code for these games.

I think that now I can say that I have more then 30 years of development experience!

You can find the source code and the binary here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

Up ↑

%d bloggers like this: