1987 · Electronic Arts

Skate or Die!

This minisite was contributed by unorig, air. It’s currently claimed by unorig who is editing it to reach a Gold tier standard.

From LOAD"EA",8,1 to the title screen: a loader that decrypts itself in layers, checks the disk with the drive's own code, and leaves a disk server running in the drive for the rest of the game.

01 · The file

One sector that runs itself

The disk's directory lists a single program, EA, said to be two blocks long. The file is one sector: 254 bytes that load into the processor's stack page, from $0102. Nothing calls them. When the KERNAL's LOAD returns, it pulls its return address off the stack, and the file has filled that part of the stack with the bytes $01 $00, so the return lands on $0101, the byte before the file.

That byte is left over from the start-up screen. BASIC prints 38911 BASIC BYTES FREE by building the number in the stack page, and the "8" it leaves at $0101 is $38, the 6502's SEC instruction. The processor sets the carry and runs on into the file. The code then reads seventeen sectors of track 1 into memory at $0334, fills the stack page with $01 to erase itself, and jumps into what it loaded.

02 · Decryption

Each layer scrambles the one before

The seventeen sectors are encrypted. A first pass undoes a running XOR over nearly 2,500 bytes. The code it reveals copies the KERNAL ROM into the RAM beneath it ($0389), resets the machine if a cartridge answers at $8000, and points the NMI and RESET vectors at an RTI, so the RESTORE key does nothing.

Then come four layers. A routine at $0340 XORs the rest of the loader with the low byte of the address it was called from, and it is called four times, from four places ($03BF is the first). Each call reveals the code after it and scrambles the code that has just run, so at no moment is the whole loader in memory in the clear. Between layers, three checksums test that the erasing fill happened and that nobody has patched the code; a failure jumps into garbage.

The screen the loader shows while it works: 49 characters of the EA logo at $C800, placed on the screen at $C000, drawn from the bytes still in memory when the title starts. The background steps from blue towards grey with each page that arrives from the disk.

03 · The disk check

A track that a copier cannot write

Track 2 of the disk holds no sectors at all. The track holds one sync mark, a run of filler bytes, then 512 pairs of the bytes $CC $AD followed by twelve particular bytes. The loader unpacks a 182-byte program, sends it to the drive one byte at a time, and runs it there. The drive program moves the head to track 2, changes the speed at which it reads bits, and looks for that exact pattern, three tries at most. The loader then asks the drive for the result and for a byte of the program itself, to be sure the program was not replaced. If either answer is wrong, it fills its own memory with $FF and resets the machine.

The check is the last thing the encrypted loader does before it changes the drive for good. The loader resets the drive, has it read four sectors of track 1, and jumps into them. That is EA's disk server: it stays in the drive's memory for the whole game and answers three-byte commands, a command, a track, and a sector, sent over the serial lines. The C64 never holds a copy of it.

04 · The hand-over

Wiping the loader behind it

The loader's own receive routine XORs every byte with $A5 and turns the background up a shade with each page, which is the stepping colour behind the logo. The loader reads six sectors of track 3 to $2000, copies a wiper to $EF00, and the wiper clears the encrypted loader from memory before it returns into the new code.

That code, stage 3 ($2000), is 52 bytes. Stage 3 copies the resident disk loader up to $F230, where it stays for the rest of the game, loads file 0, the title, and jumps to it. Every later load in the game goes through that resident loader and the server in the drive (The town).

05 · The title

A picture that moves only its colours

The title program unpacks its picture first ($4160), so it is on screen while the samples for the music load behind it. The picture is a multicolour bitmap, packed on the disk with a simple run-length scheme ($4338): a byte below 128 is followed by that many plus one literal bytes, a byte of 128 or more by one byte to repeat.

The title picture drawn from the title's memory: the bitmap at $A000, the screen colours at $8800, and the colour-RAM copy at $8400, as $41CD shows them.

Nothing on the screen moves; only colours change. Each frame the raster interrupt ($4093) plays the music, then uses a frame counter to step four colour effects: ELECTRONIC ARTS flips between white and yellow every 32 frames, white and greys roll down the three credit lines, a highlight sweeps across the EA logo, and the words SKATE, OR, and DIE! swap their colour with their shadow one after another ($423E, $42BC), 16 frames apart.

06 · Leaving the title

The shop starts on an interrupt

The title waits for fire on either joystick ($4022); the space bar works too, because the keyboard row it sits on is the one left selected. On fire, the music stops, the shop is loaded to $0880, and the NMI vector is pointed at $0880. The title then restarts the timer that drove the samples and spins in a loop. The next tick of that timer raises an NMI, and the NMI is how the shop starts.

The title leaves a 0 at $FDFF. The shop reads it, and anything but $55 makes it load the event manager that runs the town and the events. Rob Hubbard's music, with its sampled guitars played through the volume register, is on Music and sound.