In addition to using much self-modifying code, the early PDP-1 pioneers also conceived of JIT compilers. When I was working on
RIPOFF for the PDP-1 I learned that there are five distinct spaceship shapes in Spacewar!. The "outlines" for each was stored as data points, which were used at runtime to generate highly efficient code for displaying the ships on the screen. Here is a sample of some generated code from my game. The Spacewar! code generated the opcodes directly into memory once when a ship was initialized. A few notes.
- The starting coordinate for the shape is loaded into the AC and IO registers in "screen" format. The X and Y positions are stored in the upper 10 bits of the registers as values between -511..512.
- Each block of code after that applies an accumulative offset to that initial point.
- The offsets are also in screen format and are pre-calculated based on the rotation of the shape.
- swap is a macro that switches the values in the AC and IO registers.
- disp is a macro to display a point on the screen; it expects X to be in AC and Y to be in IO.
This code is very efficient mainly because X and Y remain in the two (and only) PDP-1 registers without ever needing to be saved off to memory.
dtk, dap rox
lac \px / Starting point.
lio \py
/ Sprite code.
/ y=2, x=2
swap
sub \cn2
add \sm2
swap
add \sn2
add \cm2
disp
/ y=4, x=0
swap
sub \cn4
swap
add \sn4
disp
/ y=4, x=0
swap
sub \cn4
swap
add \sn4
disp
/ y=2, x=8
swap
sub \cn2
add \sm8
swap
add \sn2
add \cm8
disp
/ y=0, x=4
swap
add \sm4
swap
add \cm4
disp
/ y=0, x=-8
swap
sub \sm8
swap
sub \cm8
disp
/ y=2, x=-4
swap
sub \cn2
sub \sm4
swap
add \sn2
sub \cm4
disp
/ y=2, x=4
swap
sub \cn2
add \sm4
swap
add \sn2
add \cm4
disp
/ ...etc.
Mike