; **************************************
; *        T H R I L L E R             *
; *       the card program             *
; **************************************
; The title program runs this one
; before every screen. It shows the
; card (night, screen, score, lives)
; and then runs the screen `next`
; names. It became a program of its
; own when the piece it plays as a
; game opens was 6K of digitized
; sound, too big to share memory with
; the front screen. That piece is now
; B3POKEY.ACT, 1.5K of settings for
; the sound chip, which would fit;
; the card stays a separate program.
;
; NOT WRITTEN: Run(), which has to
; load the next program from the disk.
;
; In this listing {inv}...{/inv} marks
; text typed in inverse video.

; the bytes the programs share
; wins: screens won so far this game
; (0: the game is just starting).
; lives, score: as they stand.
BYTE wins=$6F1,lives=$6F2,
  next=$6F6,   ; the screen to run
  bonus=$6FC   ; a life has been earned
CARD score=$6F3
; places in the Atari itself: the
; clock that ticks every TV frame and
; the attract-mode timer
BYTE rtclok=20,atract=77

; The piece that opens a game: the
; table b3pokey and the procedures
; that play it (B3Start, B3Tick,
; B3Stop). It has procedures in it,
; so it comes in after the
; declarations above.
INCLUDE "D:B3POKEY.ACT"

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

; ------ the card before each screen ------

; The card that opens a game (wins=0)
; plays B3POKEY.ACT, 3.2 seconds of
; music on the sound chip's four
; voices, once through; the button
; cuts it short. The cards
; between screens are silent: the
; screen just won has played its own
; piece.
PROC Card()
  BYTE i,night,n
  ; three screens make a night
  night=wins/3+1
  ; interrupts and players off.
  ; GRAPHICS 18 is big letters, 20
  ; across and 12 down, here in the
  ; Atari's own character set (756)
  ; and four colours.
  Poke(54286,64) Poke(53277,0)
  Graphics(18) Poke(756,224)
  Poke(708,$36) Poke(709,$0E)
  Poke(710,$C8) Poke(711,$1A)
  Position(6,0) PrintD(6,"THRILLER")
  Position(6,2) PrintD(6,"night ")
  PrintBD(6,night)
  Position(6,3) PrintD(6,"screen ")
  PrintBD(6,next)
  ; what the next screen asks of you
  IF next=1 THEN
    Position(3,5)
    PrintD(6,"{inv}SAVE YOUR GIRL{/inv}")
    Position(6,6)
    PrintD(6,"{inv}FROM THE{/inv}")
    Position(3,7)
    PrintD(6,"{inv}HAUNTED HOUSE!{/inv}")
  ELSEIF next=2 THEN
    Position(4,5)
    PrintD(6,"{inv}PROTECT YOUR{/inv}")
    Position(2,6)
    PrintD(6,"{inv}GIRLFRIEND FROM{/inv}")
    Position(3,7)
    PrintD(6,"{inv}GRISLY GHOULS!{/inv}")
  ELSE
    Position(1,5)
    PrintD(6,"{inv}FIND YOUR GIRL IN{/inv}")
    Position(1,6)
    PrintD(6,"{inv}THE MANSION BEFORE{/inv}")
    Position(6,7)
    PrintD(6,"{inv}THEY DO!{/inv}")
  FI
  Position(2,9) PrintD(6,"score ")
  PrintCD(6,score)
  Position(2,10) PrintD(6,"lives ")
  PrintBD(6,lives)
  IF bonus=1 THEN
    Position(4,11)
    PrintD(6,"BONUS LIFE!")
  FI
  ; A new game: play the piece. It is
  ; a table of 189 rows, one for each
  ; sixtieth of a second; B3Tick()
  ; pokes the next row into the sound
  ; registers and clears b3on after
  ; the last. n counts the frames:
  ; the button works after half a
  ; second.
  IF wins=0 THEN
    n=0
    B3Start()
    WHILE b3on<>0 DO
      Frame()
      B3Tick()
      n==+1
      IF n>30 AND Strig(0)=0 THEN
        EXIT FI
    OD
    B3Stop()
    SndRst()
    RETURN
  FI
  ; Between screens: wait two and a
  ; half seconds, or for the button
  ; once half a second has gone. On a
  ; bonus card the capital letters go
  ; from dim to bright, over and over.
  FOR i=0 TO 150 DO
    Frame()
    IF bonus=1 THEN
      Poke(708,$30+(i&14)) FI
    IF i>30 AND Strig(0)=0 THEN EXIT FI
  OD
  SndRst()
RETURN

; NOT WRITTEN. Load the program that
; `next` names (D:THRILL1.OBJ,
; D:THRILL2.OBJ or D:THRILL3.OBJ) and
; jump to its start. Under DOS 2.0S
; that is a binary load through CIO.
PROC Run()
RETURN

; Show the card, then run the screen
; (when Run is written).
PROC Main()
  Card()
  Run()
RETURN
