(back to project list)

Disassembly of Elite for the Apple II

Elite is a first-person spaceship simulator, featuring trading and combat. Initially published in 1984 for the BBC Micro, it was ported to multiple systems, and spawned a number of sequels. The Apple II version was published by Firebird, and is copyright 1985 by David Braben and Ian Bell.

This disassembly is based on the 4am crack. The files are essentially standard DOS 3.3 format, but parts are descrambled at load time, making direct examination of the disk files ineffective. See Generating the Binary for an explanation of how the project binary was created.

The disassembly is not fully commented. Much of the code and data in Elite is common across the various 6502 ports. While the graphics and sound code is Apple II-specific, the math routines, text tokenization, trading system, galaxy definition, and 3D meshes are nearly identical to the BBC Micro and C64 versions. While I have gone through all of the Apple II-specific code and some of the common code, the majority of the common code has not been commented. (I may get around to it eventually; for now, I've left notes with pointers to equivalent locations identified in the BBC and C64 sources. These have been included in the HTML listing.)

Related resources:

Huge thanks go to Ian Bell for posting the original BBC Micro sources, Paul Brink for commenting them, Kroc Camen for Elite Harmless, and Christian Pinder for Elite:TNK.

Software trivia: Elite has no self-modifying code, except for what appears to be a bug fix patch for an incorrect branch in the joystick code. This is very unusual for a game.


How to Play

Scans of the original manual can be found online, as can a colorful HTML version.

Apple II Controls

title screen

The controls are many, and non-obvious. My "Gold Edition" came with a C64 manual and an Apple II control sheet (which I can't find). I've had trouble finding the Apple II controls elsewhere, so here's a complete list.

The game will initially be in keyboard-only mode, which is very confusing for players who expect the joystick to be the default input device. Enter the sequence = K - to switch to joystick mode. Throw in a U after the K to enable lower-case output on the text screen.

While docked at a station:

Flight control keys:

Flight joystick controls (initially disabled; enable from pause mode):

Short-range / galaxy map:

Bear in mind that energy bombs, escape pods, docking computers, and intergalactic hyperdrives are optional equipment that are not installed on your initial ship. See the full manual for more information.

While in pause mode:

When you toggle a setting in pause mode you will hear a short chirp. The chirp is doubled when the mode is returned to its default state, so if you listen closely you can tell what state it's in.


Apple II Implementation Notes

The Apple II version uses the text and hi-res screens. The text screens are used for information screens, like ship status and planet characteristics, as well as the trading interface. On other systems the information may be displayed in the cockpit interface, inside the viewscreen area, so the usable part of the text screen is generally limited to an area of the same size.

Only one hi-res page is used. The screen is treated as black and white, with the middle 256 (of 280) pixels used horizontally. Limiting to 256 allows the X coordinates to be stored in a single byte. The Apple II's method of displaying color means that vertical lines will have a bit of a green/purple shimmer.

Lines are drawn with a read-XOR-write sequence. XOR (exclusive-or) flips the state of each drawn pixel, so plotting a pixel on a black background results in a white pixel, while plotting on a white background results in a black pixel. If you draw two white lines that cross each other (like an 'X'), the middle pixel will be black. This approach allows you to erase a line by drawing it twice, and means that it doesn't matter in what order you draw and erase overlapping lines.

When animating a moving 3D shape, the obvious approach is to draw it, then erase it, then draw it again in its new position, and so on. Drawing lines is a fairly expensive operation, so doing this without page-flipping would result in a fair bit of flicker: the time required to erase all of the lines would be a substantial fraction of the screen refresh time, so the computer would display nothing but black for that cycle.

Because the lines are XORed, there's an alternative: instead of erasing all lines and then drawing all lines, we can erase a single line and draw it in its new position before moving on to the next. This way, you'll occasionally see a piece of a line missing, but at any given time most of the shape is still present. By working this way, Elite is able to avoid excessive flickering without having to give up 8KB for the second hi-res page.


Copyright 2020 by Andy McFadden