; **************************************
; *        T H R I L L E R             *
; *       the title program            *
; **************************************
; Designed in 1984 by Dale Lutz, on a
; sheet of paper. Written in 2026 by
; Dale and Claude, in Action!, for a
; 48K Atari 800 and one joystick.
;
; The game is five programs on one
; disk: this one, the card program
; (THRILLERC.ACT) and the three
; screens (THRILLER1, 2 and 3.ACT).
; This one shows the front screen,
; with the three screens side by side
; as they were on the 1984 sketch.
; The joystick picks one, the button
; starts it. When a screen is won it
; comes back here, and this program
; runs the card program, which shows
; a card and runs the next one:
; 1, 2, 3, then 1 again, a night later
; and harder. Every third screen won
; earns a life. It keeps the score,
; the lives and the high score in a
; few bytes of page 6.
;
; NOT WRITTEN: Run(), which has to
; load the next program from the disk.
;
; In this listing {inv}...{/inv} marks
; text typed in inverse video.
;
; HOW THIS PROGRAM WORKS
; PROC Main looks at the shared bytes
; to see why it was run: for the first
; time, after a screen was won, or
; after a game ended. It shows the
; verses and the front screen as
; needed, sets the bytes for the next
; program and runs it.
; The front screen and the verses each
; have a display list of their own
; (the table that tells the Atari what
; kind of line to draw at each place
; down the screen), built at $640. The
; moving figures are players
; (sprites).
; There is no ordinary main loop. PROC
; Loop plays the digitized music, and
; sixty times a second it calls Tick
; (front screen) or Roll (verses) to
; do everything else.

; TITLE has the characters (tset) and
; the three pictures (panels), SHAPES
; him and her (hero, girl), SHAPES1
; the werewolf (wolf), LAUGH the laugh.
; L1POKEY, the front screen's music,
; has procedures in it, so it comes
; in after the declarations below.
INCLUDE "D:TITLE.ACT"
INCLUDE "D:SHAPES.ACT"
INCLUDE "D:SHAPES1.ACT"
INCLUDE "D:LAUGH.ACT"

; DLIST: where our display list is
; built, in page 6. FUR, SKIN: the two
; colours player 1 takes (the wolf's
; fur, his skin). MAGIC: the mark that
; says the shared bytes have been set
; up.
DEFINE DLIST="$640",FUR="$18",
  SKIN="$28",MAGIC="$54"

; the bytes the five programs share
; chain: 1 while a game is going on.
; wins: screens won this game. result:
; 1 the screen just run was won.
; score, hi, last: this game's score,
; the high score, and the last game's
; score.
BYTE chain=$6F0,wins=$6F1,lives=$6F2,
  result=$6F5,
  next=$6F6,   ; the screen to run
  magic=$6FB,  ; MAGIC once hi is set
  bonus=$6FC   ; a life has been earned
CARD score=$6F3,
  hi=$6F7,last=$6F9

; places in the Atari itself: the
; clock that ticks every TV frame, the
; attract-mode timer, the top of
; memory, the START, SELECT and OPTION
; keys, two volume registers, and the
; left-to-right positions of the four
; players and the four missiles
BYTE rtclok=20,atract=77,ramtop=106,
  consol=53279,
  audc1=$D201,audc2=$D203,
  hposp0=$D000,hposp1=$D001,
  hposp2=$D002,hposp3=$D003,
  hposm0=$D004,hposm1=$D005,
  hposm2=$D006,hposm3=$D007
; scrn, pmb, chb: the addresses of
; screen memory, player-missile memory
; and our character set (idle is not
; used). sel: the panel picked, 0 to
; 2. frm: counts frames. held: the
; stick has not been let go since it
; last stepped.
CARD scrn,pmb,chb,idle
BYTE sel,frm,held
; the moonwalker under the panels:
; where he is (the second interrupt
; reads it), which way he glides,
; and how long his spin has to run
BYTE mwx=$6E0,mwd,mwt
; where the figure in the panel is
; (the first interrupt reads it)
BYTE pnx=$6E1
; go: the button has been pressed.
; blip: how long the picking sound
; has left
; armed: the button and the keys
; have been let go since the screen
; came up. scene: 0 the front screen,
; 1 the verses. bnote: the pitch of
; the picking sound.
BYTE go,blip,armed,scene,bnote
; the verses: nl lines so far, row
; the line in the top slot, sub how
; far it has crept toward the next
; gf: counts the graveyard ghouls'
; steps
BYTE nl,row,sub,gf
; crawl: the verses, 40 bytes a line.
; The three ghouls in the graveyard:
; gcol the column each is in, gdir
; which way it is going, glo and ghi
; the two ends of its beat.
BYTE ARRAY crawl(2160),gcol(3),
  gdir(3),glo=[1 12 29],ghi=[7 16 36]

; his eleven poses again, facing left
; (made by PROC Init)
BYTE ARRAY herol(858)

; Two display list interrupts, one
; after the other down the screen.
; The first, on the line above the
; panels, makes playfield 0 green and
; playfield 2 brown for the pictures,
; and puts players 0 to 2 where the
; figure in the chosen panel is (pnx).
; The second, on the panels' last
; line, makes playfield 2 black again
; for the words underneath, and moves
; the same three players across to
; where the moonwalker is (mwx), with
; his skin colour in player 1. They
; are copied to $600 and $621.
;  PHA; LDA #$C6; STA WSYNC;
;  STA COLPF0; LDA #$24; STA COLPF2;
;  LDA pnx; STA HPOSP0; STA HPOSP1;
;  STA HPOSP2; LDA #$21; STA VDSLST;
;  PLA; RTI
;  PHA; LDA #0; STA WSYNC; STA COLPF2;
;  STA VDSLST; LDA mwx; STA HPOSP0;
;  STA HPOSP1; STA HPOSP2; LDA #$28;
;  STA COLPM1; PLA; RTI
; (VDSLST holds the address of the
; routine the next interrupt will run.
; Each of the two puts the other's low
; byte there, $21 or 0, so they take
; turns down the screen.)
BYTE ARRAY dlicode=[
  $48 $A9 $C6 $8D $0A $D4 $8D $16 $D0
  $A9 $24 $8D $18 $D0 $AD $E1 $06
  $8D $00 $D0 $8D $01 $D0 $8D $02 $D0
  $A9 $21 $8D $00 $02 $68 $40
  $48 $A9 $00 $8D $0A $D4 $8D $18 $D0
  $8D $00 $02 $AD $E0 $06 $8D $00 $D0
  $8D $01 $D0 $8D $02 $D0 $A9 $28
  $8D $13 $D0 $68 $40]

; The front screen's music: the table
; l1pokey and the three procedures
; that play it (L1Start, L1Tick,
; L1Stop). See "the loop", below.
INCLUDE "D:L1POKEY.ACT"

; wait for the next TV frame
PROC Frame()
  BYTE f
  f=rtclok
  DO UNTIL rtclok<>f OD
  atract=0 frm==+1
RETURN

; a mirror image of n bytes of shapes
; (each byte is a row of eight dots,
; so its bits are put in the opposite
; order)
PROC Flip(BYTE POINTER src,dst CARD n)
  CARD i
  BYTE b,m,k
  FOR i=0 TO n-1 DO
    b=src(i) m=0
    FOR k=0 TO 7 DO
      m==LSH 1
      IF (b&1)=1 THEN m==+1 FI
      b==RSH 1
    OD
    dst(i)=m
  OD
RETURN

; Done once. Take 4K at the top of
; memory for the players and our
; characters, copy the two interrupts
; to page 6, and make his left-facing
; shapes.
PROC Init()
  ; 16 pages down: players at pmb,
  ; characters 2K further up
  ramtop==-16
  Graphics(0)
  pmb=ramtop*256 chb=pmb+2048
  Zero(pmb,2048)
  ; the Atari's own letters (in ROM at
  ; 57344), then ours over them from
  ; character 65 on (520 = 65*8)
  MoveBlock(chb,57344,1024)
  MoveBlock(chb+520,tset,400)
  ; the two interrupt routines, 64
  ; bytes, to $600
  MoveBlock($600,dlicode,64)
  ; 858 bytes: eleven poses of 78
  Flip(hero,herol,858)
RETURN

; Interrupts off, players and missiles
; off and moved off the screen. Used
; when a scene ends.
PROC PmOff()
  Poke(54286,64) Poke(53277,0)
  hposp0=0 hposp1=0 hposp2=0 hposp3=0
  hposm0=0 hposm1=0 hposm2=0 hposm3=0
RETURN

; ---------- the front screen ----------

; our own display list: the name in
; big letters, two lines of words,
; nine lines of pictures (ANTIC mode
; 4), eleven more lines of words
; Also turns the players on and sets
; the colours. The interrupts are
; turned on later, in PROC Front.
PROC Display()
  BYTE i
  Graphics(0)
  Poke(752,1) Poke(82,0)
  scrn=PeekC(88)
  ; three lots of 8 blank TV lines
  Poke(DLIST,$70) Poke(DLIST+1,$70)
  Poke(DLIST+2,$70)
  ; row 0 in mode 7 (big letters). $40
  ; means the address of the line's
  ; data follows: here, screen memory.
  Poke(DLIST+3,$47) PokeC(DLIST+4,scrn)
  ; rows 1 to 3 in mode 2 (ordinary
  ; text). $80 on row 3 calls the
  ; first interrupt, ready for the
  ; pictures.
  Poke(DLIST+6,$42)
  PokeC(DLIST+7,scrn+40)
  Poke(DLIST+9,2)
  Poke(DLIST+10,$82)
  ; rows 4 to 12, the pictures, in
  ; mode 4 (four-colour characters).
  ; The last calls the second
  ; interrupt.
  FOR i=11 TO 18 DO Poke(DLIST+i,4) OD
  Poke(DLIST+19,$84)
  ; rows 13 to 23 in mode 2
  FOR i=20 TO 30 DO Poke(DLIST+i,2) OD
  ; $41: wait for the next frame and
  ; start the list again. Then tell
  ; the Atari where the list is.
  Poke(DLIST+31,$41)
  PokeC(DLIST+32,DLIST)
  PokeC(560,DLIST)
  ; our character set (756). Players:
  ; where their memory is (54279),
  ; switch them on (53277), players in
  ; front and missiles as a fifth
  ; player (623), one-line players
  ; (559).
  Poke(756,chb RSH 8)
  Poke(54279,ramtop)
  Poke(53277,3)
  Poke(623,49)
  Poke(559,62)
  ; colours: 704-707 the players,
  ; 708-711 the playfield, 712 the
  ; background
  Poke(704,$34) Poke(705,SKIN)
  Poke(706,$02) Poke(707,$86)
  Poke(708,$36) Poke(709,$0C)
  Poke(710,0) Poke(711,$28)
  Poke(712,0)
RETURN

; words under panel k, centred
; (Panel k starts at column 1+k*13 and
; is 12 wide. s(0) is the number of
; letters in s.)
PROC Centre(BYTE k,y BYTE ARRAY s)
  Position(1+k*13+((12-s(0)) RSH 1),y)
  Print(s)
RETURN

; all the words on the front screen,
; with the two scores
PROC Words()
  Position(6,0) Print("THRILLER")
  Position(11,1)
  Print("NOW PLAY THE GAME!")
  Centre(0,13,"SAVE YOUR")
  Centre(0,14,"GIRL AS YOU")
  Centre(0,15,"ARE A")
  Centre(0,16,"WEREWOLF!")
  Centre(1,13,"PROTECT YOUR")
  Centre(1,14,"GIRLFRIEND")
  Centre(1,15,"FROM GRISLY")
  Centre(1,16,"GHOULS!")
  Centre(2,13,"FIND YOUR")
  Centre(2,14,"GIRL IN THE")
  Centre(2,15,"MANSION")
  Position(25,16)
  Print("BEFORE THEY DO!")
  ; lines 17 to 19 are his stage
  Position(2,20)
  Print("JOYSTICK: PICK A SCREEN  ")
  Print("BUTTON: PLAY")
  Position(5,21) Print("HIGH SCORE ")
  PrintC(hi)
  Position(25,21) Print("LAST ")
  PrintC(last)
  Position(9,22)
  Print("OPTION: A TALE IN VERSE")
  Position(9,23)
  Print("{inv}GET YOUR THRILL TODAY!{/inv}")
RETURN

; The three pictures. Each is 12
; characters wide and 9 high, 108
; bytes, and is copied a row at a time
; to rows 4 to 12 of the screen (40
; bytes to a row).
PROC Panels()
  BYTE k,y
  FOR k=0 TO 2 DO
    FOR y=0 TO 8 DO
      MoveBlock(scrn+(4+y)*40+1+k*13,
        panels+k*108+y*12,12)
    OD
  OD
RETURN

; the chosen screen's name in inverse,
; and its frame in the bright colour
PROC Mark(BYTE k,on)
  BYTE x,y,c
  BYTE POINTER p
  ; p: the top left cell of panel k
  ; (161 = row 4, column 1)
  p=scrn+161+k*13
  ; its name on row 3. 49 is the digit
  ; 1; 128 more makes a character
  ; inverse.
  Position(3+k*13,3)
  IF on=1 THEN Print("{inv}SCREEN {/inv}")
  ELSE Print("SCREEN ") FI
  Put(49+k+on*128)
  ; the cells round the edge of the
  ; panel: 128 more gives the bright
  ; colour, 128 less the plain one
  FOR y=0 TO 8 DO
    FOR x=0 TO 11 DO
      IF y=0 OR y=8 OR x=0 OR x=11 THEN
        c=p(x)&127
        p(x)=c+on*128
      FI
    OD
    p==+40
  OD
RETURN

; the chosen panel comes to life: the
; players are him (or the wolf) and her
PROC Live()
  BYTE POINTER s
  BYTE x,gx,x0,t
  ; x0: just inside the left edge of
  ; the chosen panel, in player
  ; coordinates. t counts 0 to 15, a
  ; step every four frames; x goes
  ; from 0 up to 7 and back.
  x0=56+sel*52 t=(frm RSH 2)&15
  IF t<8 THEN x=t ELSE x=15-t FI
  IF sel=0 THEN  ; the wolf runs after her
    Poke(705,FUR)
    s=wolf+((frm RSH 2)&1)*78
    x=x0+x gx=x0+26
  ELSEIF sel=1 THEN ; he dances
    Poke(705,SKIN)
    s=hero+156+((frm RSH 3)&1)*78
    x=x0+12 gx=x0+2
  ELSE           ; he searches, to and
    Poke(705,SKIN) ; fro; she is hidden
    x=x0+4+x*2 gx=0
    IF t<8 THEN
      s=hero+((frm RSH 3)&1)*78
    ELSE
      s=herol+((frm RSH 3)&1)*78
    FI
  FI
  ; His shape: 26 bytes each for
  ; players 0, 1 and 2 (their memory
  ; is at +1024, +1280 and +1536),
  ; starting 110 TV lines down. pnx
  ; tells the first interrupt where to
  ; put them across.
  MoveBlock(pmb+1024+110,s,26)
  MoveBlock(pmb+1280+110,s+26,26)
  MoveBlock(pmb+1536+110,s+52,26)
  pnx=x
  ; Her: two poses of 52 bytes, 26 for
  ; player 3 (+1792) and 26 for the
  ; missiles (+768). In the middle
  ; panel she stands still.
  s=girl+((frm RSH 2)&1)*52
  IF sel=1 THEN s=girl FI
  MoveBlock(pmb+1792+110,s,26)
  MoveBlock(pmb+768+110,s+26,26)
  ; position 0 is off the screen:
  ; hidden
  hposp3=gx
  IF gx=0 THEN
    hposm3=0 hposm2=0 hposm1=0 hposm0=0
  ELSE
    hposm3=gx hposm2=gx+2
    hposm1=gx+4 hposm0=gx+6
  FI
RETURN

; While the front screen waits he
; moonwalks to and fro under the
; panels: facing one way and gliding
; the other, with a spin at each end.
PROC Moon()
  BYTE POINTER s
  ; mwt>0: he is spinning, one pose
  ; held for 24 frames
  IF mwt>0 THEN
    mwt==-1 s=hero+468
  ELSE
    ; gliding: four poses in turn,
    ; facing right (hero) while he
    ; goes left and left (herol) while
    ; he goes right. He moves every
    ; second frame, and turns at 60
    ; and at 188.
    IF mwd=0 THEN s=hero ELSE s=herol FI
    s==+546+((frm RSH 3)&3)*78
    IF (frm&1)=0 THEN
      IF mwd=0 THEN
        mwx==-1
        IF mwx<60 THEN mwd=1 mwt=24 FI
      ELSE
        mwx==+1
        IF mwx>188 THEN mwd=0 mwt=24 FI
      FI
    FI
  FI
  ; his shape goes 176 TV lines down;
  ; the second interrupt puts him at
  ; mwx
  MoveBlock(pmb+1024+176,s,26)
  MoveBlock(pmb+1280+176,s+26,26)
  MoveBlock(pmb+1536+176,s+52,26)
RETURN

; ---------------- the loop ----------------
; The front screen plays L1POKEY.ACT:
; two bars of music on all four of
; POKEY's voices (bass, lead, and two
; for the drum), round and round for
; as long as it is up. The tune is a
; table of 243 rows, one for each
; sixtieth of a second, and each row
; is the eight bytes to put in the
; sound registers for that moment.
; PROC Loop (further down, which the
; verses share) waits for each new
; frame, has L1Tick() poke the next
; row, and then calls Tick() for the
; joystick and the moving figures.
; The music takes all four voices, so
; the note that sounds when you pick
; a screen borrows the fourth from
; the drum for a tenth of a second.
; L1Start() sets the sound clock to
; its slow rate (AUDCTL=1), which is
; why that note is poked straight in
; rather than made with Sound(), which
; would set the clock back.

; The front screen's sixtieth of a
; second: move the figures, then read
; the joystick, the button and the
; keys.
PROC Tick()
  BYTE s
  ; Frame() has already counted this
  ; frame in frm
  Live() Moon()
  ; the name glows
  Poke(708,$32+((frm RSH 3)&3)*2)
  ; the picking sound stops when its
  ; time is up
  IF blip>0 THEN
    blip==-1
    ; while it lasts, the note takes
    ; voice 4 back from the drum that
    ; L1Tick() has just put there
    IF blip>0 THEN
      Poke(53766,bnote) Poke(53767,$A8)
    FI
  FI
  s=Stick(0)
  ; SELECT steps along, too
  IF consol=5 THEN s=7 FI
  ; held makes one push of the stick
  ; one step. 7 is right, 11 is left;
  ; the choice goes round from 2 to 0.
  IF s=15 THEN held=0
  ELSEIF held=0 THEN
    held=1
    IF s=7 OR s=11 THEN
      ; take the mark off the old
      ; panel, mark the new one, sound
      ; a note
      Mark(sel,0)
      IF s=7 THEN
        sel==+1
        IF sel=3 THEN sel=0 FI
      ELSEIF sel=0 THEN sel=2
      ELSE sel==-1 FI
      Mark(sel,1)
      ; 14, 12 or 9: about the notes
      ; C, D and G with the slow clock
      bnote=14-sel*2-(sel RSH 1)
      Poke(53766,bnote) Poke(53767,$A8)
      blip=6
    FI
  FI
  ; Nothing counts until the button
  ; and the keys have all been let go
  ; once (armed). Then the button or
  ; START sets go to 1, OPTION to 2.
  IF armed=0 THEN
    IF Strig(0)=1 AND consol=7 THEN
      armed=1 FI
  ELSEIF Strig(0)=0 OR consol=6 THEN
    go=1
  ELSEIF consol=3 THEN go=2 ; OPTION
  FI
RETURN

; ---------------- the verses ----------------
; Shown when a game ends, and from the
; front screen with OPTION: verses of
; our own that climb the screen and
; shrink as they go, as if the page
; were leaning away.
; Each line of words is 40 bytes: ten
; blanks, twenty letters, ten blanks.
; The screen is eight slots, sixteen
; TV lines each, every one with its
; own address in the display list:
;  top 3   mode 2 (small letters, the
;          whole 40 bytes) and 8 blank
;  next 3  mode 6 (wide letters, the
;          middle 20) and 8 blank
;  last 2  mode 7 (wide and tall)
; A line of words steps up a slot at
; a time and so gets smaller. Between
; steps the whole stack creeps up a
; TV line at a time: three blank-line
; instructions above it shrink (18
; lines down to 3) and three under it
; grow by the same, so the graveyard
; at the bottom stays where it is.
; Under the verses: four lines of
; mode 4 with a fence, two stones and
; three ghouls shuffling; he
; moonwalks through them and she
; stands by. The front screen's two
; interrupts do the colours and put
; the players in place.
; NOT TRIED ON AN 800: if crawl()
; lies across a 4K line of memory,
; one line of words will show wrong.

; three blank-line instructions that
; add up to t TV lines (3 to 18)
; (The instruction for n blank lines,
; 1 to 8, is (n-1)*16: LSH 4 does the
; multiplying.)
PROC Pad(CARD at BYTE t)
  BYTE a,b
  a=t/3 b=(t-a)/2
  Poke(at,(a-1) LSH 4)
  Poke(at+1,(b-1) LSH 4)
  Poke(at+2,(t-a-b-1) LSH 4)
RETURN

; point the eight slots at their lines
; (by putting an address in each
; slot's instruction in the display
; list)
PROC Slots()
  BYTE j
  CARD p
  ; the three small slots show a whole
  ; 40 bytes each
  p=crawl+row*40
  FOR j=0 TO 2 DO
    PokeC(DLIST+6+j*4,p) p==+40
  OD
  ; the five wide ones show the middle
  ; 20: 10 bytes further in
  p==+10
  FOR j=0 TO 2 DO
    PokeC(DLIST+18+j*4,p) p==+40
  OD
  PokeC(DLIST+30,p)
  PokeC(DLIST+33,p+40)
RETURN

; one more line of words, centred
; (into crawl, at line nl. Taking 32
; from a letter's code gives the
; number the screen uses for it.)
PROC Line(BYTE ARRAY s)
  BYTE i
  BYTE POINTER p
  p=crawl+nl*40+9+((20-s(0)) RSH 1)
  FOR i=1 TO s(0) DO
    p(i)=s(i)-32
  OD
  nl==+1
RETURN

; a blank line between verses
PROC Gap()
  nl==+1
RETURN

; the three ghouls: a step, and every
; second step a move along
PROC Shuffle()
  BYTE k,y,c
  CARD p
  ; every second step each ghoul goes
  ; one column along, and turns at the
  ; end of its beat
  gf==+1
  FOR k=0 TO 2 DO
    IF (gf&1)=0 THEN
      IF gdir(k)=0 THEN
        gcol(k)==+1
        IF gcol(k)=ghi(k) THEN
          gdir(k)=1 FI
      ELSE
        gcol(k)==-1
        IF gcol(k)=glo(k) THEN
          gdir(k)=0 FI
      FI
    FI
    ; its two poses are characters 89
    ; to 94 and 109 to 114, two wide
    ; and three high
    c=89
    IF (gf&1)=1 THEN c=109 FI
    ; rows 1 to 3 of the graveyard:
    ; wipe its beat, then draw it
    FOR y=0 TO 2 DO
      p=scrn+40+y*40
      Zero(p+glo(k),ghi(k)-glo(k)+2)
      Poke(p+gcol(k),c+y*2)
      Poke(p+gcol(k)+1,c+y*2+1)
    OD
  OD
RETURN

; the verses' sixtieth of a second
PROC Roll()
  BYTE POINTER s
  ; Frame() has already counted this
  ; frame in frm
  ; he moonwalks; both interrupts put
  ; him at mwx
  Moon() pnx=mwx
  ; she changes pose every 16 frames
  s=girl+((frm RSH 4)&1)*52
  MoveBlock(pmb+1792+176,s,26)
  MoveBlock(pmb+768+176,s+26,26)
  ; the ghouls step every 32 frames
  IF (frm&31)=0 THEN Shuffle() FI
  ; Every second frame the stack
  ; creeps up one TV line. After 16 of
  ; those each line of words moves up
  ; a slot. When the last line has had
  ; its turn in the top slot, stop.
  IF (frm&1)=0 THEN
    sub==+1
    IF sub=16 THEN
      sub=0 row==+1
      IF row>=nl THEN go=1 RETURN FI
      Slots()
    FI
    ; the blank lines above shrink and
    ; those below grow
    Pad(DLIST+2,18-sub)
    Pad(DLIST+35,3+sub)
  FI
  ; once the button and the keys have
  ; been let go, either ends the
  ; verses
  IF armed=0 THEN
    IF Strig(0)=1 AND consol=7 THEN
      armed=1 FI
  ELSEIF Strig(0)=0 OR consol<>7 THEN
    go=1
  FI
RETURN

; set the verses up. over=1: a game
; has just ended
PROC Verses(BYTE over)
  BYTE i
  ; a plain screen; clear the players
  ; and the verses
  Graphics(0)
  Poke(752,1) Poke(82,0)
  scrn=PeekC(88)
  Zero(pmb,2048)
  Zero(crawl,2160)
  ; the first eight lines stay blank,
  ; so the words come in at the bottom
  ; slot
  nl=8
  IF over=1 THEN Line("GAME OVER")
  ELSE Line("THRILLER") FI
  Gap()
  Line("THE MOON CLIMBS HIGH")
  Line("ABOVE THE TREES")
  Line("AND SOMETHING HOWLS")
  Line("UPON THE BREEZE")
  Gap()
  Line("THE GRAVEYARD GATE")
  Line("SWINGS OPEN WIDE")
  Line("THE GHOULS BELOW")
  Line("WON'T STAY INSIDE")
  Gap()
  Line("THEY SHUFFLE OUT")
  Line("ON CREAKING FEET")
  Line("THEY CANNOT HELP IT")
  Line("IT'S THE BEAT")
  Gap()
  Line("UP ON THE HILL")
  Line("A MANSION WAITS")
  Line("TWELVE ROOMS OF DARK")
  Line("BEHIND ITS GATES")
  Gap()
  Line("SHE CALLS FOR YOU")
  Line("THE LAMP BURNS LOW")
  Line("A CLOCK STRIKES ONE")
  Line("THE GHOULS ALL KNOW")
  Gap()
  Line("YOU RAN, YOU DANCED")
  Line("YOU FOUGHT ALL NIGHT")
  Line("BUT NO ONE LASTS")
  Line("TILL MORNING LIGHT")
  Gap()
  Line("SO REST A WHILE")
  Line("BENEATH THE STONE")
  Line("THEN TRY AGAIN")
  Line("YOU'RE NOT ALONE")
  Gap()
  Line("GET YOUR THRILL")
  Line("TODAY!")
  ; The display list. Two lots of 8
  ; blank lines, then (further down)
  ; the top pad at +2.
  row=0 sub=0
  Poke(DLIST,$70) Poke(DLIST+1,$70)
  ; three mode 2 slots from +5 and
  ; three mode 6 slots from +17. Each
  ; is an instruction with $40 (an
  ; address follows: Slots fills it
  ; in), two bytes of address, and 8
  ; blank lines.
  FOR i=0 TO 2 DO
    Poke(DLIST+5+i*4,$42)
    Poke(DLIST+8+i*4,$70)
    Poke(DLIST+17+i*4,$46)
    Poke(DLIST+20+i*4,$70)
  OD
  ; two mode 7 slots. $C7 is $47 with
  ; $80: the first interrupt, for the
  ; graveyard's colours.
  Poke(DLIST+29,$47) Poke(DLIST+32,$C7)
  ; the pads above and below the
  ; stack, and the slots' addresses
  Pad(DLIST+2,18) Pad(DLIST+35,3)
  Slots()
  ; four lines of mode 4 for the
  ; graveyard, which is the start of
  ; screen memory; the second
  ; interrupt on the last; then back
  ; to the top
  Poke(DLIST+38,$44)
  PokeC(DLIST+39,scrn)
  Poke(DLIST+41,4) Poke(DLIST+42,4)
  Poke(DLIST+43,$84)
  Poke(DLIST+44,$41)
  PokeC(DLIST+45,DLIST)
  ; the graveyard
  ; a fence along row 0, two stones
  ; two cells square on rows 2 and 3,
  ; and the ghouls
  FOR i=0 TO 39 DO Poke(scrn+i,88) OD
  Poke(scrn+89,80) Poke(scrn+90,81)
  Poke(scrn+129,82) Poke(scrn+130,83)
  Poke(scrn+106,80) Poke(scrn+107,81)
  Poke(scrn+146,82) Poke(scrn+147,83)
  FOR i=0 TO 2 DO
    gcol(i)=glo(i)+i gdir(i)=0
  OD
  gf=0 Shuffle()
  ; she stands at 130 across; he
  ; starts at the right
  hposp3=130 hposm3=130 hposm2=132
  hposm1=134 hposm0=136
  mwx=188 mwd=0 mwt=0 pnx=mwx
  ; use our list, our characters, the
  ; players and the colours, as PROC
  ; Display does
  PokeC(560,DLIST)
  Poke(756,chb RSH 8)
  Poke(54279,ramtop)
  Poke(53277,3)
  Poke(623,49)
  Poke(559,62)
  Poke(704,$34) Poke(705,SKIN)
  Poke(706,$02) Poke(707,$86)
  Poke(708,$1C) Poke(709,$0A)
  Poke(710,0) Poke(711,$28)
  Poke(712,0)
  ; wait for the next frame, then
  ; point the interrupt at $600 and
  ; switch it on
  armed=0 go=0 scene=1
  Frame()
  PokeC(512,$600) Poke(54286,192)
RETURN

; play the music until go is set:
; each frame, the next row of the
; tune, then Tick() or Roll()
PROC Loop()
  L1Start()
  DO
    Frame()
    L1Tick()
    IF scene=0 THEN Tick()
    ELSE Roll() FI
  UNTIL go>0 OD
  L1Stop()
RETURN

; the laugh, once, fading over its
; last quarter (as the screens play
; it when a life is lost): ft is the
; 16 levels at 1/8 to 8/8 of full
; strength, shrunk toward the middle
; level 8
PROC Laugh()
  CARD i,c,fs,st
  BYTE b,v,d,k,o
  BYTE ARRAY ft(128)
  FOR k=1 TO 8 DO
    FOR v=0 TO 15 DO
      IF v<8 THEN d=8-((8-v)*k+4)/8
      ELSE d=8+((v-8)*k+4)/8 FI
      ft((k-1)*16+v)=$10%d
    OD
  OD
  fs=LAUGHLEN/28
  o=112 c=fs-1 st=LAUGHLEN-fs*7
  FOR i=0 TO LAUGHLEN-1 DO
    b=laugh(i)
    v=ft(o+(b RSH 4)) audc1=v audc2=v
    FOR d=1 TO 9 DO OD
    v=ft(o+(b&15)) audc1=v audc2=v
    FOR d=1 TO 9 DO OD
    IF i>=st THEN
      c==+1
      IF c=fs THEN
        c=0
        IF o>0 THEN o==-16 FI
      FI
    FI
  OD
  audc1=0 audc2=0
RETURN

; The verses, start to finish. If
; they run to the end (the last words
; have gone off the top) the laugh
; plays over the graveyard before the
; front screen comes back; the button
; skips both.
; (Called by Main with over=1 after a
; game, and with over=0 for OPTION.)
PROC Story(BYTE over)
  Verses(over)
  Loop()
  SndRst()
  IF row>=nl THEN Laugh() FI
  PmOff()
  Zero(pmb,2048)
RETURN

; The front screen, start to finish.
; It comes back with go=1 (play: next
; is the screen picked) or go=2
; (OPTION: show the verses).
PROC Front()
  Display() Words() Panels()
  ; start with the next screen picked
  sel=next-1
  IF sel>2 THEN sel=0 FI
  Mark(0,0) Mark(1,0) Mark(2,0)
  Mark(sel,1)
  ; held=1: a stick already pushed
  ; does not count
  held=1 go=0 blip=0 armed=0 scene=0
  mwx=188 mwd=0 mwt=0
  ; wait for the next frame, then
  ; point the interrupt at $600 and
  ; switch it on
  Frame()
  PokeC(512,$600) Poke(54286,192)
  ; the music, until something is
  ; chosen
  Loop()
  next=sel+1
  SndRst() PmOff()
RETURN

; NOT WRITTEN. Load the card program
; (D:THRILLC.OBJ) and jump to its
; start; it shows the card and loads
; the screen `next` names. Under DOS
; 2.0S that is a binary load through
; CIO.
PROC Run()
RETURN

; Run at power-on, and again each time
; a screen ends. chain and result say
; which.
PROC Main()
  Init()
  ; the first run since power-on?
  IF magic<>MAGIC THEN
    magic=MAGIC hi=0 last=0
    chain=0 next=1
  FI
  bonus=0
  IF chain=1 AND result=1 THEN
    ; a screen was won: the next one
    next==+1
    IF next=4 THEN next=1 FI
    ; three in a row: a bonus life
    IF wins MOD 3=0 AND lives<5 THEN
      lives==+1 bonus=1
    FI
  ELSE
    IF chain=1 THEN ; a game just ended
      ; keep the scores, show the
      ; verses
      last=score
      IF score>hi THEN hi=score FI
      Story(1)
    FI
    chain=0
    ; OPTION on the front screen shows
    ; the verses, then it comes back
    DO
      Front()
      IF go=1 THEN EXIT FI
      Story(0)
    OD
    ; a new game
    chain=1 wins=0 lives=3 score=0
  FI
  ; run the card program (when Run is
  ; written)
  result=0
  Run()
RETURN
