I have long been fascinated with entering programs into computers by methods not involving a standard keyboard and monitor. This interest was peeked by my last article: Using the latest z80pack, version 1.17, to emulate an Altair 8800 or IMSAI 8080 using the new graphical FrontPanel. I have therefore chosen to design and write a program for the IMSAI 8080. In this article I will show you how I went about it, and how you could do the same. You may want to look at the afore mentioned article if you don’t own an IMSAI 8080 and don’t already have an emulator for it.
Having never programmed an IMSAI 8080 before, I needed to gather some information about it and the Intel 8080 CPU that it uses. I didn’t find much out there, but what I did is listed below.
- IMSAI 8080 User’s Manual (pdf)
- Intel 8080/Z80 Instruction Set and Comparison
- Intel 8080 Architecture information
- Intel 8080 Brief Explanation of the instructions
- Intel 8080 Instruction Set
Armed with the above information and the knowledge that the PROGRAMMED INPUT/OUTPUT on the Front Panel is available via port
0xFF, I could now proceed.
Specification of Program
The main consideration in choosing what program to create, is that it has to be small as I want to toggle it in via the front panel switches. I would also like to be able to control it via the PROGRAMMED INPUT switches. After some deliberation, I have decided to write a program to bounce a light back and forth on the PROGRAMMED OUTPUT. The speed of the light’s movement will be controlled by the PROGRAMMED INPUT, so that when set to 0x00 it will be fast and then get slower as the PROGRAMMED INPUT is increased to
0xFF. This may not be the most exciting program ever, but with all that switch flipping, I don’t want to attempt anything too ambitious.
Designing the Program
The program needs to be well designed before it is entered into the computer due to the difficulty of making changes once it has been entered. I am therefore going to use a form of Top-Down, Stepwise Refinement to ensure that the program is correct before entering.
High Level Pseudo Code
Refined Pseudo Code
I have chosen to store the position of the light as the value of the bit set in that position, so that I can then easily output it to the PROGRAMMED OUTPUT.
Testing the Design
Before I implement the design in Machine Code, I want to test that it is correct. This is particularly important due to the difficulty in toggling programs in to the IMSAI. To do this I want to look at several points in the code when they are presented with certain values. I will run through the design in the following table:
|?||?||direction = right||Start of program|
|right||?||position = 1|
|right||1||if( position == 128 || position == 1 )||true|
|right||1||direction = ~direction|
|left||1||if( direction == left )||true|
|left||2||: : :||Output and delay|
|left||2||if( position == 128 || position == 1 )||false|
|left||2||if( direction == left )||true|
|left||4||: : :||Output and delay|
|left||128||: : :||After a few iterations|
|left||128||if( position == 128 || position == 1 )||true|
|left||128||direction = ~direction|
|right||128||if( direction == left )||false|
|right||64||: : :||Output and delay|
I am happy that the design is correct from looking at this table. The first light to be turned on will be light 2, which is fine as the light is moving anyway. It is easy to alter this if you are so inclined. You can also use this method to check that the machine code implementation below is correct.
Implementing the Design in Machine Code
To make the implementation easier I am going to store the Direction and Position variables in registers. I will use the following process to convert the design into machine code:
- Write the program out in assembler using labels to record program locations.
- Put the hex equivalents to the assembler next to the appropriate lines, leaving unknown addresses marked with ????.
- Put the address of each line at the start of it.
- Go back and fill in the addresses marked with ????.
- Convert the hex into binary next to each line.
This gives me the following code:
Entering the program into the IMSAI 8080
The next bit is a little nerve racking and quite laborious. There are
0x40 bytes of code here, which is 512 bits. 512 ones and zeros that have to be entered exactly. 512 ones and zeros that if not entered correctly mean either re-entering the whole program again, or going back through them to check which were entered incorrectly. As well as this; if the program doesn’t work, is it because the program is wrong, or because I entered it in wrong? But now is not the time to worry, I have tested the program on paper, the design is sound, I need to grab the bull by the horns and enter this program.
To enter the program follow these instructions:
- Turn the machine on by moving the PWR ON / PWR OFF switch to PWR ON. This switch is located at the far-right of the unit.
- The machine is now at address 0. To input the first line of the program move the middle set of switches so that positions 3,2,1 are down. This corresponds to binary: 0000 1110 from Address 0 of the program.
- Press the DEPOSIT / DEPOSIT NEXT switch into the DEPOST position. This puts the data from the switches set above into memory at the current address, which is currently 0.
- Set the middle group of switches so that it corresponds to the binary in the next group of 8 bits of the program.
- Press the DEPOST / DEPOSIT NEXT switch into the DEPOSIT NEXT position. This increments the current address, and there it puts the data from the switches just set.
- Repeat lines 4 and 5 until the program has been entered.
The program can now be run by moving the RUN / STOP switch into the RUN position. You should now see the light bouncing back and forth in the PROGRAMMED OUTPUT at the top left of the unit. If you now move any of the PROGRAMMED INPUT switches, you will see that the light’s movement changes speed.
Debugging the Program
There are three main methods to help debug a program on the IMSAI:
- Step through the program_Do this by moving the _RUN / STOP switch into the STOP position. Now press the SINGLE STEP switch for each step you want to see. The current address will be displayed in the bottom middle lights, and it’s contents in the top middle lights. To run or step from a certain point, just examine that address first.
- Examine the contents of an address in memory_Do this by setting the left and middle group of switches to the address you want to examine, then move the _EXAMINE / EXAMINE NEXT switch into the EXAMINE position. You will now see it’s contents in the middle top group of lights. To see the contents of the next address just press EXAMINE NEXT.
- Change the contents of an address in memory_Do this by first examining the contents of the address using the _EXAMINE switch as above. Then set the middle group of switches to the data you want to put there, and press DEPOSIT. To continue entering data just set the middle switches to the next byte you want to enter and press DEPOSIT NEXT.
The program listing I have given works fine. However when I first wrote it, I had line 0x0028 read:
This made the program much too slow, and at first I didn’t think the program was working at all. Using the above debugging methods it was easy to step through the program and work out what was happening. I just changed the byte at
02, then examined address
0x0000, and pressed the RUN switch to run the program from
0x0000 (The start). I then felt waves of euphoria as my program worked correctly. I had done it with only one small hitch.
The Program Running on a Real IMSAI 8080
Since writing this article I have been contacted by Mike Loewen, who has a real IMSAI and has kindly allowed me to upload this footage of my program running on his machine. Mike has an interesting site about his Old Technology Collection which features his Restoration of an IMSAI 8080. I must say it was really good to see my program running on a real machine. If only I could lay my hands on one.
Now is the time to get really creative. To do this though, you need to really understand the machine, so the links at the start of the article should help you understand more about the machine and the Intel 8080 chip that powers it. If you remember the importance of designing and testing the program properly before you enter it, you should be fine. Good luck and have fun.