The Great Flight Simulator Hack of 1982
The word "Hack"
It is very unfortunate that the usage of the word "hack" has drifted
away from its original meaning of something spontaneous, elegant and a
technical feat (see The NewHacker's
Dictionary; the Hacker's Anti
Defamation League, and Eric S. Raymond's how to
become a hacker page). Its present usage (which I and many people
oppose) seems to be what I would now call a "cracker", i.e. one who
maliciosly violates the integrity or spirit of someone elses work or
system, to achieve ends of no value to humanity. Hacking, as I define
it, is a wholesome and positive way to spend time, and one of the most
enjoyable that I know. Cracking, as in breaking copy protection
schemes, breaking into computer networks to steal or modify
information, virus writing and the like are clearly unwholesome and
negative practices, and I don't condone them.
I have given up trying to correct people about the usage of
"hacker" vs "cracker". The word "hacker" is just too entrenched in the
media these days. So I'm on the lookout for an alternative... please
email me if you know of one.
Warning
Some of this article is necessarily rather technical in nature. But
don't let that stop you from reading it, and absorbing some of the feel
for what I did, and how I felt when I was doing it.
Background
The era
The Z80 was king of the microcomputer world. Cassette tape was still
alive and well, and the Tandy TRS- 80 Model I was a popular platform
despite its woeful graphics. Each character cell of its 64 by 16 screen
could be turned into 6 black and white graphics cells, yielding a
resolution of 128 by 48. Glenn
Wallace coined a great name for these: brixels! Bruce Artwick had
just written Flight Simulator 1, so I purchased FS1 for Tandy on a
cassette.
My equipment
I had a 4MHz Z80 S100 homebrew computer with a pair of full height
5.25" floppy drives running CP/M 1.4. I had picked up a DecWriter
terminal cheap, and hacked a 600 baud serial interface to it, and a
parallel keyboard interface so I could use the good keyboard on it for
the computer. (DecWriters normally run at only 300 baud, and at 600 it
was comparable in speed with the cheap dot matrix printers at the time,
but it took 15" paper and was indestructable). My cassette interface
was versatile enough to read Tandy tapes with special software and a
bit of luck.
Asteroids
This was also the golden age (for me) of arcade games: the programs
were small enough to disassemble in a few weeks, although it was hard
work. Conversions were the thing then: put a hot new game on hardware
that was already paid for, and give it a new lease of life. It was not
just a matter of copying EPROMS and blowing new color lookup PROMs:
they deliberately had different architecture. One of my few successful
conversions I called "Froglet": it was the Frogger game on Scrambler
hardware.
While most arcade games were moving to color graphics with
sprites, a few games like Asteroids were persisting with vector
graphics. I mean literally vector graphics: a line was drawn by rapidly
moving the beam to the start of the line, turning on the beam current,
deflecting it slowly to the end of the line, turning off the beam, and
radidly moving to the start of the next line. Although a normal TV
picture tube was used, it had special analogue current drive to the
yokes that worked off 12 bit A/Ds. The TTL circuitry on the deflection
side was a miracle of engineering: it drew in a 4K by 3K space at 6
mega pixels per second, using a finite state machine implemented in TTL
gates! 7497 binary rate multiplier chips did the actual line
interpolation. The 6502 processor (one of the cheapest and simplest)
just had to maintain a list of vector instructions in a special vector
ram. There were vector instrucions like moveto, drawto, set brightness,
jump, and jump to subroutine! (That is, jump to a vector
subroutine: draw a saucer, for example, using moves and draws, and
return to the calling vector code. Not 6502 code; there was separate
RAM and ROM for that!) There were vector subroutines that drew
asteroids, saucers, and digits in a vector ROM. (The finite state
machine had its own "program counter" and handled all this). The vector
opcodes I "disassembled" by hand, using just a dump of the control PROM
and the circuit diagram. The endpoints of the lines were restricted to
10 bits, so it had a resolution of 1024 x 768 but an accuracy (well,
smoothness) of 4096 x 3072.
Software
My main tool was a public domain program by Ward Christensen (of Xmodem
fame) called Resource that Ron Harris and I hacked for Z80 opcodes (real
Zilog mnemonics, not those horrid TDL ones). The great thing about
Resource was that it produced assembler source, and you could edit the
output and reassemble it with modifications. We added quite a bit of
functionality to this program, and soon became quite adept at
disassembling 8080 and Z80 programs, and even converting games for
Tandy graphics to run on our Memory Mapped Graphics cards. (All video
adapters are memory mapped these days, but back then it was special).
I also had a public domain disassembler that was table driven,
and came with tables for the 6800 microprocessor. I entered 6502
opcodes, and did a few mods of my own, and so had a 6502 disassembler
with which to disassemble the Asteroids control ROM.
The hack
Hardware
I had my own cocktail asteroids game, but sold the cabinet to my video
game pimp. It looked impressive: bare picture tube, about three power
transformers, the analogue "brick" ICs that drove the yokes, and the 12
bit A/D chips standing proud in special sockets with all that expensive
looking printing on them. The joystick (an industrial strength digital
job, basically 4 switches) I interfaced to my Z80. I had one of those
S100 breadboards, which I filled with some custom goodies. You can see
the card on my nostalgia page.
One of the goodies was a hardware FIFO chip: 9 bits wide by 40
characters deep. I used this to send commands from the Z80 to the 6502
without making either wait unnecessarily. It fed a simple parallel port
to connect the Z80 to the 6502 (using the asteroids joystick input port
as an 8 bit parallel port). Another goody was the hardware multiplier:
just a pair of 74LS384s.. Each multiplied an 8 bit number by n bits
SERIALly, but I clocked them at 20Mhz, so my 4MHz Z80 could not read
the numbers faster than this pair of chips could multiply them. 16 x n
bits was ideal for me - mostly I wanted to multiply two unsigned 16 bit
integers to yield a 16 bit result - FS1 was only interested in the most
significant half of the result.
Software
I disassembled Bruce Artwick's Flight Simulator (FS1) for Tandy. This
was some job, as I had little interest in the detailed flight
equations, and it was (for its time) quite a large program. But Bruce
had done a fine job, with two nicely isolated multiply routines that I
adapted to my hardware, and a nice set of parameters that scaled the
resolution of the graphics back end. I simply changed a pair of words
from 128 and 48 to 1024 and 768, and suddenly the program was producing
a list of vectors with a resolution suitable for sending to the
Asteroids! I tossed out the Tandy line drawing routines, and instead
generated vector lists for Asteroids.
The hardest part was burning a bootstrap EPROM for Asteroids
that would load a small 6502 program into program memory and run that.
I can remember burning many eproms that tried to do better than just
crash. I think I used the Z80 assembler with macros for common 6502
instructions, and tested the result by disassembling it. Finally, one
of the test programs displayed the full screen test pattern (built into
the vector ROM). I was so pleased that I left it in the bootstrap
program, so I knew the 6502 was alive. Debugging was very hard - I
remember using the digits in the vector ROM to display hex numbers as a
kind of crude "printf" facility. And of course to modify the program I
would edit the "source" on the Z80, assemble it, disassemble it to
check it, burn a new EPROM, try it. When the bootstrap was working I
could edit, assemble, disassemble, reboot the 6502, send the file, and
pray that it worked. When things were really advanced, the program read
into the 6502 by the bootstrap would wait for a complete vector list
and display it; wait for another vector list (in the other half of
memory) and display when that was complete.
Results
When it finally came together, it was wonderful. Flight Simulator
running in 1024 by 768 resolution, smooth as silk, sharp as a pin.
Probably Bruce himself had not seen his program in as high a resolution
as this. I modified the WW2 scenery to make a kind of Star Wars channel
with a few kinks. (In those days, of course, there was no such dream as
a scenery editor - I figured out the new co-ordinates on paper, and
reassembled the whole FS1 program).
The sad part is that after it was running only a few weeks, I
decided that it was too awkward physically, what with the bare picture
tube, EHT leads, all those power transformers, all the cables and such,
and such limited space in the hacker room. But of course the fun part of
a project like this is hacking it together and getting it going;
actually using it is almost like documenting a program. Only a handful
of people on this earth ever saw this marvel. But I still have fond
memories of that monstrocity - probably my greatest hack.
"The New Hacker's Dictionary",
Raymond E S, MIT Press. ISBN: 0-262-18145-2 (hc), 0-262-68069-6 (pbk).
A humorous, very readable, well illustrated book of technical terms and
their history, with great stories attached to many. Also nostalgia for
we older hackers.
See also the newsgroup alt.hackers
.
Mike's Home Page.
Last modified: 20 Jan 2000: 'How to become a hacker'
link