1983 · Cosmi

Aztec Challenge

This minisite was contributed by air, Nico-van-der-Zijden. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/c64/aztec-challenge with me to Gold.

The whole game, ported to JavaScript routine by routine and run on its own bytes at the C64's pace, from Cosmi's logo to the seventh level and round again.

01 · Play

Play Aztec Challenge with the keyboard

The arrow keys are the joystick in port 2, and Z or Enter is its fire button. F1 starts a game for one player and F3 a game for two, who take turns; pressed during one of the menu's previews, the key waits in the C64's keyboard buffer and the game starts when the preview ends, a few seconds later. On the scorecard, fire starts the level. Left alone, the menu shows the levels played by the game itself.

KeysOn the C64Does
Tap a key in this table to press it in the game.
F1F1on the menu or its previews: a game for one player
F3F3on the menu or its previews: a game for two players
EscRUN/STOPon the scorecard, the Stairs, the Temple and the Vermin: back to Cosmi's logo
← → ↑ ↓the joystick in port 2run, jump, duck, climb, swim and hop, as each level reads it
Z or Enterfirestart the level from the scorecard; on the Stairs, step right; in the Piranha, alone, dive

The game as the port runs it, from $1000, where the tape hands over. The game reads the menu's keys through the KERNAL's GETIN and RUN/STOP through its STOP routine, and the port runs the same four KERNAL routines on its own memory, with the keyboard scan of the KERNAL's interrupt, which every interrupt of the game ends in: a key goes into the buffer when it goes down, and GETIN takes it out.

02 · The port

Every routine of the game, written again in JavaScript

Nothing on this page emulates a 6502. The game is written out in JavaScript, one function for each routine of the listing, in eight files under reference/: one for the engine (Cosmi's logo, the menu and its previews, the scorecard, the end of a level, and the music's interrupt) and one for each of the seven levels. The port runs on the game's own 64 KB, loaded from the bytes the Source code tab shows, and every variable stays where the game keeps it: the lives lost at $02, the level at $03, the stage reached in it at $45, and Hopaztec's trapped tiles from $5C28.

Some of what the game reads cannot be worked out from memory. Its random numbers come from the low byte of CIA 1's timer, which counts down 16,422 cycles between interrupts, and from voice 3 of the SID, set to noise. Its hits come from the video chip's sprite collisions. On the page the timer is counted from the page's own clock, the noise is the SID's 23-bit shift register stepped as the voice runs, and the collisions are the site's model of the video chip, which works them out pixel by pixel as the clock moves. The Stairs also read CIA 2's timer, for the third block's X, but that timer never runs, so the read gives 255 on the C64 and here alike.

The page keeps the C64's pace by keeping its clock. The game times itself with delay loops, and the port counts the cycles of each one as it reaches it; the rest of the game's work costs the cycles it costs on the C64. Every 16,422 cycles the clock runs the music's interrupt. The Stairs and the Vermin wait for the raster, and there the clock runs to the line. The page and the game draw different random numbers, so the same input plays out differently on each.

The screen is drawn by the site's model of the video chip from the port's memory, with each write to the chip at the line and cycle where the clock stood. The menu and the scorecard are written in the C64's own letters, which the video chip reads from the character ROM, so this page carries the part of it they show: the first 2 KB of the character ROM (901225-01, $D000-$D7FF), the upper case and graphics set and its reversed copy. The sound is the port's writes to the SID, in twelfths of a frame, played through the site's model of the SID.