Slot 2 Mapping Flat Code in $00000 - $05db9 [1] RAM Code

Self-modifying line interrupt handler

The interrupt handle looks like this:

    push af    ; Protect register
    in a,($bf) ; Satisfy interrupt
    or a       ; Check if line or frame interrupt
    jp p,$de80 ; Jump to RAM code for line interrupt
    jp $016f   ; Jump to ROM code for frame interrupt

This is about as fast as you can dispatch a line interrupt; the only faster thing would be to always dispatch it, even for VBlanks.

The code at $de80 is copied there from $07f0 by some code at $00cc. Once in RAM, it looks like this:

    in a,($7e)         ; Check line number
    add a,a            ; Double it. This will make numbers below $80 alias to those above it; the game uses line interrupts from line $7f to $bf.
    ld ($de87),a       ; Self-modify the following instruction to index the ath byte in a buffer at $c800.
    ld  a,($c800)      ; The previous line modifies the middle byte of this opcode: the LSB of the address.
    out ($bf),a        ; Set the HScroll to that value
    ld a,$88
    out ($bf),a
    pop af             ; Clean up and return

This is a bit faster than performing a lookup via a register.

The game sets an HScroll on every line from $7f (or higher, when moving the horizon) to $bf. During the VBlank, it sets the line interrupt register to the start line number (as stored at ROM address $c191), then polls waiting for line $b7. One that is hit (in the following frame), it sets the line interrupt register to zero, causing the next line interrupt to happen at the desired line, then on every line after that. It spends a lot of its time in the line counter polling.

Tile decompression during gameplay

The game loads a large quantity of tiles while the game is running - notably, at the start, it only has tiles for a straight road as it is using a lot of space for the START banner, so it loads the necessary tiles over the course of several seconds while on the initial straight. These seem to be decompressed incrementally, updating a small amount of data during each VBlank.

Return to top