Skip to content

Character-Shift Parallax

Parallax by redrawing the font

The C64 scrolls one character screen, so its games faked a second layer by rolling the pixel definitions of a few background characters against the scroll. Achim's Codebase64 routine names Bounder, Parallax and Marauder; John Rowlands added it to Mayhem in Monsterland in an hour.

Late one night in December 1992, John Rowlands decided the levels of Mayhem in Monsterland needed parallax scrolling. He wrote in his diary for Commodore Format that he “spent an hour adding a piece of code that rolls the definition of a few characters in the opposite direction of the scroll (which gives the illusion of parallax)”. The result was a background pattern that moved at half the speed of the foreground.

An hour was enough because the trick changes very little. The VIC-II draws one screen of characters, and its fine-scroll registers move the whole of it at once, so it cannot slide a second layer past the first. What it can do is redraw a character. Every cell on screen that shows character 200 is drawn from the same eight bytes of the character set, so changing those eight bytes changes every copy at once. Roll them one pixel to the right while the screen scrolls one pixel to the left, and the pattern inside those cells stays still while everything else moves.

Fast facts

  • Mechanism: the background pattern is made of a few characters, often a 2×2 tile, whose 8-byte definitions are rotated one pixel against the scroll.
  • Effect: foreground and background move at different speeds without touching screen memory or colour RAM.
  • Cost: one pass over a 2×2 hires tile is 88 instructions, a few hundred cycles; a multicolour tile needs two passes.
  • Limit: only the cells built from the rolled characters move differently, and the pattern has to repeat every tile, because every copy of a character changes together.
  • Named uses: Bounder (Gremlin), Parallax and Marauder (Hewson) in Achim’s Codebase64 article; Mayhem in Monsterland in John Rowlands’s own diary.

How it works

Achim’s Codebase64 article works through a 2×2 tile of characters A and B on top, C and D underneath, with one routine for each direction. The left roll treats each pixel row of A and B as one 16-pixel row and rotates it, so the pixel that leaves the left edge of A comes back in at the right edge of B:

Assembly
; Roll a 2x2 hires tile one pixel left (after Achim, Codebase64).
; charA charB   are the tile's four character definitions,
; charC charD   8 bytes each, in the character set.
rollleft:
        ldx #$00
loop1:  lda charB,x          ; bit 7 of charB -> carry
        asl
        rol charA,x          ; carry -> bit 0 of charA, bit 7 of charA -> carry
        rol charB,x          ; carry -> bit 0 of charB
        lda charD,x          ; the same for the lower pair, C and D
        asl
        rol charC,x
        rol charD,x
        inx
        cpx #$08
        bne loop1
        rts

The right roll is the mirror image, using lsr and ror. The vertical rolls move each byte down or up one row and put the byte that falls off one end back at the other, carrying it between the upper and lower characters so the tile wraps cleanly.

The main program then calls the roll that runs against the scroll. Achim gives the two common uses:

  • A fixed background. Call the opposite roll every time the screen scrolls one pixel, so the pattern stays where it is while the scenery moves over it. His example is Marauder.
  • A slower background. Call the opposite roll every second frame, so the pattern drifts at half the scroll speed. His examples are Parallax and Bounder.

In multicolour mode each pixel is two bits wide, so a one-bit roll would turn colours into other colours. Achim’s note is that “in mc-mode these loops have to be called twice per frame”, moving the pattern one whole multicolour pixel.

The trick has a price beyond the cycles. Every cell that uses a rolled character changes, so anything else drawn with those characters would move with the background. The rolled characters can be used for the pattern and nothing else.

Mayhem in Monsterland

Mayhem in Monsterland already scrolled with VSP, the trick that moves the whole screen sideways, colours included. VSP made full-screen scrolling cheap, but it still moves one layer. Rowlands’s rolled characters added the second. The magazine’s caption called it “a trick the Boyz use a lot”, the Boyz being John and Steve Rowlands.

The same diary has a second kind of parallax, which is easy to confuse with the first. In Week Two the diary turns to the game’s Get Ready screen, which “scrolls along in six levels of parallax”. Steve Rowlands drew it as a “mini-parallax version of the levels” from “characters and sprites”. That screen, not the levels, has the six layers.

Why not a VIC-II trick?

VSP and its relatives change where the VIC-II starts drawing the screen. They make scrolling cheaper, but every one of them still moves the whole screen, so none of them gives a second layer. Cadaver, writing about scrolling games in all directions, set the VIC-II tricks aside as “usually too limiting for games, at least for scrolling in all directions”. Rolling characters works however the screen is moved, so it can sit on top of any of them.

Sources

  • Achim, “Simple parallax shifting”, Codebase64 (web): the four roll routines, multicolour mode, fixed and half-speed backgrounds, and Bounder, Parallax and Marauder. https://codebase64.net/doku.php?id=base:simple_parallax_shifting
  • John Rowlands and Steve Rowlands, “Let’s make a monster”, Mayhem in Monsterland development diary, Commodore Format issue 30, March 1993, p. 37: the hour’s work on rolling characters, half-speed background, the six-layer Get Ready screen and the caption.
  • Cadaver (Lasse Öörni), “Multidirectional scrolling and the ‘game world’” (Rant 4), Codebase64 (web): VIC-II scrolling tricks “usually too limiting for games”. https://codebase64.net/doku.php?id=base:rant4
  • Commodore, Commodore 64 Programmer’s Reference Guide (1983), pp. 128–129: the fine-scroll registers move the whole screen.
  • Zzap!64 issue 40, August 1988, pp. 26–27: review of Hewson’s Marauder.

See also

Checked. Verified against primary sources and signed off by a person.