Thriller · the program listingsScreen 3: the mansion

About the listingsTitle programCard programThe woodsThe graveyardThe mansionPictures, tunes and sounds

Twelve dark rooms joined by doors, a lamp that lights a little of one, her voice, the ghoul pack, lightning, and lightning in a bottle. The longest of the five.

Never compiled. These listings were written as the design of the game, in Action!, within what a 48K Atari 800 of 1984 could do. They have not been through the Action! cartridge or run on an Atari. What plays on the game page is a line-for-line translation into JavaScript, made by hand, PROC for PROC. Expect small mistakes a compiler would have caught, and note the parts marked NOT WRITTEN: loading one program from another off the disk.

THRILLER3.ACT · 1984 lines · the file itself

Its 61 PROCs and FUNCs, in the order they appear:

1; **************************************2; *  T H R I L L E R    -   screen 3   *3; *   "Find your girl in the mansion   *4; *         before they do!"           *5; **************************************6; Designed in 1984 by Dale Lutz, on a7; sheet of paper. Written in 2026 by8; Dale and Claude, in Action!, for a9; 48K Atari 800 and one joystick.10;11; She is hiding somewhere in a dark12; mansion of twelve rooms, and the13; ghouls are in there looking for her.14; Your lamp lights only a little way15; around you. Every few seconds she16; calls for help: the louder the call17; (the VOICE meter shows it), the fewer18; doors there are between you and her.19; The button makes you call to her and20; she answers at once, but the ghouls21; hear it too and come on faster.22; GHOULS shows how many rooms they are23; from her. Get to her first. A ghoul24; in your way will grab you and hold25; you up: keep clear of the eyes.26;27; In this listing {inv}...{/inv} marks28; text typed in inverse video.29;30; HOW THIS PROGRAM WORKS31; The mansion is twelve rooms, four32; across and three down, numbered 0 to33; 11. Two small arrays say which rooms34; have a door in their east wall (de)35; and in their south wall (ds). PROC36; Maze knocks the doors through at37; random. PROC Dist then counts, for38; every room, how many doors it is39; from her room. Her calls, the40; glowing doorway and the ghouls'41; march all go by that count.42; Only the room he is in is drawn.43; PROC BuildRoom draws it, fully lit,44; in an array called room. The screen45; itself starts black inside the46; walls, and PROC Lamp copies from47; room to the screen just the cells48; near him.49; He and she are players (sprites).50; The ghouls are characters, like the51; walls and the furniture.52; Sixty times a second the loop in53; PROC Main moves him, the lamp, the54; lightning, the ghouls in his room,55; her voice, the ghoul pack (which56; goes from room to room toward her on57; a timer) and the music.58; You win the round by touching her.59; You lose a life if the pack reaches60; her room first, or if ghouls grab61; you too many times.6263; the other files: SHAPES3 has the64; characters for the room and the65; ghouls, SHAPES has the shapes of him66; and her, MUSIC3 the tune, LAUGH the67; digitized laugh. (HAPPOKEY, the68; piece that greets a win, comes in69; further down.)70INCLUDE "D:SHAPES3.ACT" ; mset71INCLUDE "D:SHAPES.ACT"  ; hero,girl72INCLUDE "D:MUSIC3.ACT"  ; bass,lead,drum73INCLUDE "D:LAUGH.ACT"   ; laugh,LAUGHLEN7475; MAXG: the most ghouls there can be76; on the screen. WALL to EYES: the77; numbers of characters in our own78; character set. SCALL to SDOWN:79; numbers for the sound effects (see80; PROC Effect).81DEFINE MAXG="4",     ; ghouls in a room82  WALL="65",BASE="66",FLOOR="67",83  PORT="238",        ; 110, in inverse84  CLOCK="114",85  GLOW="248",        ; 120, in inverse86  EYES="213",        ; 85, in inverse87  SCALL="1",SGRAB="2",SGROAN="3",88  SDOOR="4",STHUN="5",89  SFIND="6",SDOWN="7" ; sound effects9091; the bytes the five programs share92; (the title program, the card93; program and the three screens).94; They are in page 6,95; which DOS leaves alone between loads.96; chain: 0 this screen was run by97;   itself, 1 the title program ran it98; wins: screens won so far this game99; result: 1 the screen was won, 0 the100;   game is over101BYTE chain=$6F0,wins=$6F1,lives=$6F2,102  result=$6F5103CARD score=$6F3104; ease: tries lost on this visit to105; the screen. Each one makes the106; next try a little easier.107BYTE ease108109; places in the Atari itself: the110; clock that ticks every TV frame, the111; attract-mode timer, the top of112; memory, the START, SELECT and OPTION113; keys, two volume registers, and the114; left-to-right positions of the four115; players and the four missiles116BYTE rtclok=20,atract=77,ramtop=106,117  consol=53279,118  audc1=$D201,audc2=$D203,119  hposp0=$D000,hposp1=$D001,120  hposp2=$D002,hposp3=$D003,121  hposm0=$D004,hposm1=$D005,122  hposm2=$D006,hposm3=$D007123; scrn: the address of screen memory.124; pmb: of player-missile memory. chb:125; of our character set. ptm: frames126; until the ghoul pack moves a room.127; ptime: frames between its moves.128; pace, slack: see PROC NewLevel.129CARD scrn,pmb,chb,130  ptm,ptime, ; the ghouls' next move131  pace,slack132133; him, her, and the house134; hp: the grabs he can still take135; before one costs a life (hpm to136; start with: 3 on night 1, 2 on137; night 2, then 1). caught: a grab138; has just used the last of them, and139; cg is the ghoul that did it.140BYTE hp,hpm,caught,cg141; hx,hy: where he is, in player142; coordinates (hx across, hy his top143; TV line). hdir: 0 facing right, 1144; facing left. hstep: counts the145; frames he has walked, to pick his146; pose. stun: frames a ghoul still147; holds him. hfree: frames in which no148; ghoul can grab him.149BYTE hx,hy,hdir,hstep,stun,hfree,150  hcx,hcy,  ; the cell he stands in151  lcx,lcy,  ; where the lamp was drawn152  lx,ly,    ; where she is hiding153  hroom,groom,proom, ; his room, hers,154            ; and the ghouls'155  ; level: the night, from 1. found:156  ; he has reached her. taken: the157  ; ghouls have reached her room. frm:158  ; counts frames.159  level,found,taken,frm,160  gl,     ; the doorway that glows161  bot,    ; bottles he is carrying162  lit,    ; frames of their light left163  bk1,bk2, ; the furniture that hides164          ; a bottle165  ; vlev: how loud her last call was166  ; (0 to 8). vtm: frames to her next167  ; call. vcool: frames until the168  ; button works again. gdel: frames169  ; between a ghoul's steps.170  vlev,vtm,vcool,gdel,171  flash   ; frames of lightning left172CARD ftm  ; frames to the next flash173174; the music and the sound effects175; mpos: the step of the tune (0 to176; 127). mtm: frames left in this step.177; tempo: frames in a step. bnote,bvol,178; lnote,lvol, enote,evol: the note and179; volume of the bass, the lead and the180; lead's echo. dtyp,dvol,dpit: the181; drum. sfx: the sound effect playing182; (0 none). sfxt: frames it has left.183BYTE mpos,mtm,tempo,bnote,bvol,184  lnote,lvol,enote,evol,185  dtyp,dvol,dpit,sfx,sfxt186187; The mansion: four rooms across and188; three down, numbered 0 to 11.189BYTE ARRAY de(12), ; a door to the east?190  ds(12),          ; to the south?191  ; seen: 1 he has been in this room,192  ; 2 its clock has chimed too (PROC193  ; Maze borrows it while it makes the194  ; doors)195  seen(12),196  dist(12),        ; doors from her room197  rgh(12),         ; ghouls living here198  ; three pieces for each room: ft the199  ; kind (0 table, 1 bookcase, 2200  ; armchair, 3 clock, 255 none),201  ; fx,fy its column and row202  ft(36),fx(36),fy(36), ; the furniture203  ff(36)   ; has he found it yet?204205; the ghouls in this room: state (1206; walking, 2 dazed), column and row,207; a timer, which step, which way208BYTE ARRAY gst(MAXG),gx(MAXG),209  gy(MAXG),gtm(MAXG),gfr(MAXG),210  gdir(MAXG)211212BYTE ARRAY room(880), ; this room, lit213  herol(156),         ; him, facing left214; how far the lamp reaches to each215; side, on each of its nine rows216  lw=[2 4 5 5 5 5 5 4 2],217  ; fan: not used in this program218  fan=[121 96 81 60 81 60 47 40]219220; The piece that greets a win: the221; table happokey and the procedures222; that play it (HpStart, HpTick,223; HpStop). It has procedures in it,224; so it comes in after the225; declarations above.226INCLUDE "D:HAPPOKEY.ACT"227228; The display list interrupt. It runs229; under the room and gives the two230; text lines their own colours:231;  PHA; LDA #$34; STA WSYNC; STA COLPF2232;  LDA #$0E; STA COLPF1; PLA; RTI233; (In a text line COLPF2 is the colour234; behind the letters and COLPF1 their235; brightness. Storing to WSYNC waits236; for the end of the TV line, so the237; change does not show part way238; across.)239PROC Dli=*()240[$48 $A9 $34 $8D $0A $D4 $8D $18 $D0241 $A9 $0E $8D $17 $D0 $68 $40]242243; wait for the next sixtieth of a second244PROC Frame()245  BYTE f246  f=rtclok247  DO UNTIL rtclok<>f OD248  atract=0 frm==+1249RETURN250251; start sound effect t, to last n252; frames. PROC Effect plays it, a253; frame at a time.254PROC Sfx(BYTE t,n)255  sfx=t sfxt=n256RETURN257258; mirror n bytes of player shape259; (each byte is a row of eight dots,260; so its bits are put in the opposite261; order)262PROC Flip(BYTE ARRAY src,dst CARD n)263  CARD i264  BYTE b,m,k265  FOR i=0 TO n-1 DO266    b=src(i) m=0267    FOR k=0 TO 7 DO268      m=m LSH 1269      IF (b&1)=1 THEN m==+1 FI270      b=b RSH 1271    OD272    dst(i)=m273  OD274RETURN275276; a character row with its four277; two-bit pixels in the other order278BYTE FUNC Rev2(BYTE b)279RETURN (((b&3) LSH 6)%((b&12) LSH 2)280       %((b&48) RSH 2)%(b RSH 6))281282; mirror a ghoul (two characters wide,283; three high) into six more characters284; Row r of the ghoul is 16 bytes, two285; characters of 8, which is why286; p=r*16. The left and right287; characters change places as well.288PROC FlipG(BYTE ARRAY src,dst)289  BYTE r,k290  CARD p291  FOR r=0 TO 2 DO292    p=r*16293    FOR k=0 TO 7 DO294      dst(p+k)=Rev2(src(p+8+k))295      dst(p+8+k)=Rev2(src(p+k))296    OD297  OD298RETURN299300; done once: memory and shapes301PROC Init()302  ; lower the top of memory by 16303  ; pages (4K) and keep what is above304  ; it for ourselves305  ramtop==-16  ; 2K of players and 1K306  Graphics(0)  ; of characters up top307  ; players at pmb, characters 2K308  ; (2048 bytes) further up309  pmb=ramtop*256 chb=pmb+2048310  Zero(pmb,2048)311  ; Start with a copy of the Atari's312  ; own letters (in ROM at 57344). A313  ; character is 8 bytes, so 520 =314  ; 65*8 and 880 = 110*8: our pictures315  ; go in as characters 65 to 97 and316  ; 110 to 122.317  MoveBlock(chb,57344,1024)318  MoveBlock(chb+520,mset,264)319  MoveBlock(chb+880,mset+264,104)320  ; the ghoul's two steps are321  ; characters 86-91 and 92-97 (688 =322  ; 86*8). Mirror them into 98-103 and323  ; 104-109.324  FlipG(chb+688,chb+784) ; walking left325  FlipG(chb+736,chb+832)326  ; and him: 156 bytes is his two327  ; walking poses, 78 bytes each328  Flip(hero,herol,156)329RETURN330331; the game screen, as in screen 2:332; GRAPHICS 0 with its first 22 lines333; changed to ANTIC mode 4334PROC Screen()335  CARD dl336  BYTE i337  Graphics(0)338  ; no cursor, left margin 0339  Poke(752,1) Poke(82,0)340  ; scrn: where screen memory is. dl:341  ; where the display list is, the342  ; table that tells the Atari what343  ; kind of line to draw at each place344  ; down the screen.345  scrn=PeekC(88) dl=PeekC(560)346  ; Byte 3 of the list is the first347  ; text line ($40 = its address348  ; follows, in bytes 4 and 5). Bytes349  ; 6 to 26 are the next 21 lines.350  ; Make all 22 mode 4 (four-colour351  ; characters). $80 on the last one352  ; calls Dli. The two lines after it353  ; stay as text.354  Poke(dl+3,$44)355  FOR i=6 TO 25 DO Poke(dl+i,4) OD356  Poke(dl+26,$84)    ; ...and the DLI357  ; use our character set358  Poke(756,chb RSH 8)359  ; players and missiles: where their360  ; memory is, switch them on361  Poke(54279,ramtop) ; PMBASE362  Poke(53277,3)      ; GRACTL363  Poke(623,49)       ; players in front,364                     ; missiles = 5th,365                     ; P0 over P1 = both366                     ; colours ORed: his367                     ; white socks368  Poke(559,62)       ; one-line players369  ; colours: 704-707 the four players,370  ; 708-711 the playfield, 712 the371  ; background372  Poke(704,$34) ; his red suit373  Poke(705,$28) ; his skin374  Poke(706,$02) ; his hair and shoes375  Poke(707,$86) ; her dress376  Poke(708,$C6) ; ghoul flesh, books377  Poke(709,$06) ; the walls378  Poke(710,$24) ; wood, ghoul rags379  Poke(711,$26) ; her skin;380                ; eyes in the dark381  Poke(712,0)382  ; tell the Atari where Dli is, and383  ; switch display list interrupts on384  PokeC(512,Dli) Poke(54286,192)385RETURN386387; ---------- the two text lines ----------388389; Show a message at the right of the390; first text line (22 columns, wiped391; first).392PROC Msg(BYTE ARRAY s)393  Position(17,22)394  Print("                      ")395  Position(17,22) Print(s)396RETURN397398; the score, on the second text line399PROC ShowScore()400  Position(7,23) PrintC(score)401RETURN402403; how loud her last call was404PROC ShowVoice()405  BYTE i406  ; eight cells: a solid block for407  ; each step of loudness, a dot for408  ; the rest409  Position(7,22)410  FOR i=1 TO 8 DO411    IF i<=vlev THEN Put(160)412    ELSE Put('.) FI413  OD414RETURN415416; how many rooms the ghouls are from her417PROC ShowPack()418  Position(21,23)419  PrintB(dist(proom)) Put(32)420RETURN421422; the bottles he carries (character423; 121 is a bottle)424PROC ShowBot()425  BYTE i426  Position(15,22)427  FOR i=1 TO 2 DO428    IF i<=bot THEN Put(121)429    ELSE Put(32) FI430  OD431RETURN432433; his strength, just left of the434; lives (character 122 is a spark)435PROC ShowHp()436  BYTE i437  ; hpm cells, ending just before438  ; column 34: the hp he has left are439  ; the sparks at the right440  Position(34-hpm,23)441  FOR i=1 TO hpm DO442    IF i>hpm-hp THEN Put(122)443    ELSE Put(32) FI444  OD445RETURN446447; Both text lines, drawn afresh at the448; start of a round: the labels, the449; night, a heart for each life450; (character 0), and all the meters.451PROC ShowAll()452  BYTE i453  Position(1,22) Print("VOICE")454  Position(1,23) Print("SCORE")455  Position(14,23) Print("GHOULS")456  Position(24,23) Print("NIGHT ")457  PrintB(level) Print("   ")458  Position(34,23) Print("     ")459  Position(34,23)460  FOR i=1 TO lives DO Put(0) OD461  ShowScore() ShowVoice() ShowPack()462  ShowBot() ShowHp()463RETURN464465; -------------- the mansion --------------466467; is there a room that way at all?468; (0 north, 1 east, 2 south, 3 west)469; r&3 is the room's column (0 to 3).470; Rooms 0-3 are the top row, 8-11 the471; bottom.472BYTE FUNC Valid(BYTE r,d)473  IF d=0 AND r>3 THEN RETURN (1) FI474  IF d=1 AND (r&3)<3 THEN RETURN (1) FI475  IF d=2 AND r<8 THEN RETURN (1) FI476  IF d=3 AND (r&3)>0 THEN RETURN (1) FI477RETURN (0)478479; the number of the room next door in480; direction d: 4 less north, 1 more481; east, 4 more south, 1 less west482BYTE FUNC Nbr(BYTE r,d)483  IF d=0 THEN RETURN (r-4) FI484  IF d=1 THEN RETURN (r+1) FI485  IF d=2 THEN RETURN (r+4) FI486RETURN (r-1)487488; Is there a door in wall d of room r?489; Only east and south doors are490; stored, so a door north is the south491; door of the room above (r-4), and a492; door west is the east door of the493; room to the left (r-1).494BYTE FUNC HasDoor(BYTE r,d)495  IF Valid(r,d)=0 THEN RETURN (0) FI496  IF d=0 THEN RETURN (ds(r-4)) FI497  IF d=1 THEN RETURN (de(r)) FI498  IF d=2 THEN RETURN (ds(r)) FI499RETURN (de(r-1))500501; A new set of doors. Wander from room502; to room at random, knocking a door503; through whenever the next room has504; not been visited, until all have:505; then every room can be reached.506PROC Maze()507  BYTE cur,nb,d,n,i508  ; no doors, no room visited509  FOR i=0 TO 11 DO510    de(i)=0 ds(i)=0 seen(i)=0511  OD512  ; start anywhere. n counts the rooms513  ; visited.514  cur=Rand(12) seen(cur)=1 n=1515  WHILE n<12 DO516    ; pick a direction. If there is a517    ; room that way, go there, and if518    ; it is new, open the door between519    ; the two520    d=Rand(4)521    IF Valid(cur,d)=1 THEN522      nb=Nbr(cur,d)523      IF seen(nb)=0 THEN524        seen(nb)=1 n==+1525        IF d=0 THEN ds(nb)=1526        ELSEIF d=1 THEN de(cur)=1527        ELSEIF d=2 THEN ds(cur)=1528        ELSE de(nb)=1 FI529      FI530      cur=nb531    FI532  OD533  ; up to three more east doors and534  ; three more south doors, so there535  ; is often more than one way round536  FOR i=1 TO 3 DO    ; and a few more537    cur=Rand(12)538    IF (cur&3)<3 THEN de(cur)=1 FI539    ds(Rand(8))=1540  OD541RETURN542543; how many doors is each room from hers?544; (Called once a round, after Maze and545; after her room is chosen.)546PROC Dist()547  BYTE r,d,k,nb548  ; 255 = not known yet. Her own room549  ; is 0.550  FOR r=0 TO 11 DO dist(r)=255 OD551  dist(groom)=0552  ; Twelve passes over every room and553  ; every door. A room with a door to554  ; a nearer room becomes that room's555  ; count plus 1. (The first test556  ; stops a room that is still at 255557  ; being used: 255+1 would not fit in558  ; a byte.)559  FOR k=1 TO 12 DO560    FOR r=0 TO 11 DO561      FOR d=0 TO 3 DO562        IF HasDoor(r,d)=1 THEN563          nb=Nbr(r,d)564          IF dist(nb)<dist(r)565             AND dist(nb)+1<dist(r)566          THEN dist(r)=dist(nb)+1 FI567        FI568      OD569    OD570  OD571RETURN572573; Three pieces of furniture a room,574; each in its own corner, clear of the575; doors and of the way between them.576; Also says how many ghouls live in577; each room, and hides the two578; bottles. Called once a round.579PROC Furnish()580  BYTE r,i,q,k581  FOR r=0 TO 11 DO582    ; q: the corner for the first583    ; piece; the next two pieces take584    ; the next two corners585    q=Rand(4)586    FOR i=0 TO 2 DO587      k=r*3+i588      ; k: this piece's place in the589      ; lists. A kind at random, not590      ; yet found.591      ft(k)=Rand(4) ff(k)=0592      ; bit 0 of q: left or right593      ; side. Bit 1: top or bottom.594      IF (q&1)=0 THEN fx(k)=3+Rand(9)595      ELSE fx(k)=25+Rand(8) FI596      IF (q&2)=0 THEN fy(k)=4+Rand(3)597      ELSE fy(k)=15+Rand(3) FI598      q=(q+1)&3599    OD600    ; ghouls living here: 0 or 1, one601    ; more after night 4, another602    ; after night 7603    rgh(r)=Rand(2)604    IF level>4 THEN rgh(r)==+1 FI605    IF level>7 THEN rgh(r)==+1 FI606  OD607  ; (the two pieces that hide a bottle608  ; are picked in Round, once it is609  ; known which pieces stay)610RETURN611612; which doorway leads toward her?613; Sets gl to its direction (0 to 3),614; or 255 if no door leads nearer.615PROC Way()616  BYTE i617  gl=255618  FOR i=0 TO 3 DO619    IF HasDoor(hroom,i)=1 THEN620      IF dist(Nbr(hroom,i))<dist(hroom)621      THEN gl=i FI622    FI623  OD624RETURN625626; make doorway gl glow627; (in the array room; GLOW is a bright628; doorway character)629PROC GlowDoor()630  BYTE y631  CARD p632  ; a west or east doorway is rows 10633  ; to 13 of column 0 or column 39634  FOR y=10 TO 13 DO635    p=y*40636    IF gl=3 THEN room(p)=GLOW FI637    IF gl=1 THEN room(p+39)=GLOW FI638  OD639  ; a north doorway is columns 18 to640  ; 21 of the top three rows641  IF gl=0 THEN SetBlock(room+18,4,GLOW)642    SetBlock(room+58,4,GLOW)643    SetBlock(room+98,4,GLOW)644  FI645  ; a south doorway is the same646  ; columns of row 21 (858 = 21*40+18)647  IF gl=2 THEN648    SetBlock(room+858,4,GLOW) FI649RETURN650651; draw room hroom into the array room,652; as it would look with the lights on653; room is 22 rows of 40 cells, one654; byte each, so cell x,y is655; room(y*40+x).656PROC BuildRoom()657  BYTE y,i,k,t658  CARD p659  ; rows 0 and 1 wall, row 2 the foot660  ; of the wall, row 21 the bottom661  ; wall662  Zero(room,880)663  SetBlock(room,80,WALL)664  SetBlock(room+80,40,BASE)665  SetBlock(room+840,40,WALL)666  ; rows 3 to 20: a wall cell at each667  ; side, floor between668  FOR y=3 TO 20 DO669    p=y*40670    room(p)=WALL room(p+39)=WALL671    SetBlock(room+p+1,38,FLOOR)672  OD673  ; two portraits on the wall674  FOR i=0 TO 1 DO675    p=6+i*26676    room(p)=PORT room(p+1)=PORT+1677    room(p+40)=PORT+2678    room(p+41)=PORT+3679  OD680  ; cut the doorways: 0 is an empty681  ; cell682  IF HasDoor(hroom,0)=1 THEN683    Zero(room+18,4) Zero(room+58,4)684    Zero(room+98,4)685  FI686  IF HasDoor(hroom,2)=1 THEN687    Zero(room+858,4) FI688  FOR y=10 TO 13 DO689    p=y*40690    IF HasDoor(hroom,3)=1 THEN691      room(p)=0 FI692    IF HasDoor(hroom,1)=1 THEN693      room(p+39)=0 FI694  OD695  ; the doorway toward her, if it is696  ; to glow697  GlowDoor()698  ; this room's three pieces of699  ; furniture. p is the address of the700  ; piece's top left cell; +1 is the701  ; cell to its right, +40 the cell702  ; below.703  FOR i=0 TO 2 DO704    k=hroom*3+i t=ft(k)705    p=room+fy(k)*40+fx(k)706    IF t=0 THEN        ; a table707      Poke(p,69) Poke(p+1,70)708      Poke(p+2,71) Poke(p+40,72)709      Poke(p+41,73) Poke(p+42,74)710    ELSEIF t=1 THEN    ; a bookcase711      Poke(p,75) Poke(p+1,76)712      Poke(p+40,77) Poke(p+41,78)713      Poke(p+80,79) Poke(p+81,80)714    ELSEIF t=2 THEN    ; an armchair715      Poke(p,81) Poke(p+1,82)716      Poke(p+40,83) Poke(p+41,84)717    ELSEIF t=3 THEN    ; a clock718      Poke(p,CLOCK) Poke(p+1,CLOCK+1)719      Poke(p+40,CLOCK+2)720      Poke(p+41,CLOCK+3)721      Poke(p+80,CLOCK+4)722      Poke(p+81,CLOCK+5)723    FI724  OD725RETURN726727; Is character c something he and the728; ghouls cannot walk through? Walls729; and furniture are (characters 65 to730; 84, all but the floor), and so are731; the clocks. Empty doorways are not.732BYTE FUNC Solid(BYTE c)733  IF c>=WALL AND c<=84 AND c<>FLOOR734  THEN RETURN (1) FI735  IF c>=CLOCK AND c<=CLOCK+5 THEN736    RETURN (1) FI737RETURN (0)738739; what is on the floor under his feet,740; if he stood at x,y?741; x,y are player coordinates. A cell742; is 4 across and 8 down, and the743; room's top left corner is at 48,32.744; Taking off 44 and 9, not 48 and 32,745; gives the cell 4 to the right of x746; and 23 lines below y: the middle of747; his feet, as he is 8 wide and 26748; tall.749BYTE FUNC At(BYTE x,y)750  CARD p751  p=((y-9) RSH 3)*40+((x-44) RSH 2)752RETURN (room(p))753754; --------------- the lamp ---------------755;756; lcx,lcy: the cell at the middle of757; the lamplight, which reaches four758; rows up and four down. lcx=255 means759; no lamplight is drawn.760761; is the cell in column x, row y762; inside the lamplight?763BYTE FUNC InLight(BYTE x,y)764  BYTE d,w765  ; a bottle lights the whole room766  IF lit>0 THEN RETURN (1) FI767  ; d: which of the lamp's nine rows768  ; this is (0 to 8). For a row above769  ; the light the byte goes below 0770  ; and wraps round to a big number,771  ; so one test does for both.772  d=y+4-lcy773  IF d>8 THEN RETURN (0) FI774  w=lw(d)775  ; within w columns of the middle?776  IF x+w>=lcx AND lcx+w>=x THEN777    RETURN (1) FI778RETURN (0)779780; put out the light where the lamp was781; (y is the row plus 4 here, so 7 to782; 24 means rows 3 to 20, the ones783; inside the walls. Columns 1 to 38 of784; each row are blanked.)785PROC Dark()786  BYTE d,y787  FOR d=0 TO 8 DO788    y=lcy+d789    IF y>=7 AND y<=24 THEN790      y==-4 Zero(scrn+y*40+1,38)791    FI792  OD793RETURN794795; show the room where the lamp is now796; (by copying the lit cells from the797; array room to the screen)798PROC Light()799  BYTE d,y,w,x0,x1800  CARD p801  FOR d=0 TO 8 DO802    y=lcy+d803    IF y>=7 AND y<=24 THEN804      y==-4 w=lw(d)805      ; x0 to x1: the lit columns of806      ; this row, kept inside the807      ; walls808      IF lcx>w THEN x0=lcx-w809      ELSE x0=1 FI810      x1=lcx+w811      IF x1>38 THEN x1=38 FI812      IF x1>=x0 THEN813        p=y*40+x0814        MoveBlock(scrn+p,room+p,x1-x0+1)815      FI816    FI817  OD818RETURN819820; Draw ghoul i: whatever part of it is821; in the lamplight. If its head is in822; the dark, all he sees is its eyes.823PROC DrawG(BYTE i)824  BYTE c,r,k,x,y825  ; c: its first character. 86 if it826  ; faces right, 98 if left, and 6827  ; more for its other step.828  IF gdir(i)=0 THEN c=86829  ELSE c=98 FI830  c==+gfr(i)*6831  x=gx(i) y=gy(i)832  ; neither of its two top cells is833  ; lit: draw the eyes834  IF InLight(x,y)=0835     AND InLight(x+1,y)=0836  THEN Poke(scrn+y*40+x,EYES) FI837  ; its six cells, the lit ones only838  FOR r=0 TO 2 DO839    FOR k=0 TO 1 DO840      IF InLight(x+k,y+r)=1 THEN841        Poke(scrn+(y+r)*40+x+k,c)842      FI843      c==+1844    OD845  OD846RETURN847848; put back what was under ghoul i849PROC EraseG(BYTE i)850  BYTE r,k851  CARD p852  FOR r=0 TO 2 DO853    FOR k=0 TO 1 DO854      p=(gy(i)+r)*40+gx(i)+k855      IF InLight(gx(i)+k,gy(i)+r)=1856      THEN Poke(scrn+p,room(p))857      ELSE Poke(scrn+p,0) FI858    OD859  OD860RETURN861862; she can only be seen in the lamplight863; She is player 3 and the four864; missiles, side by side. Position 0865; is off the screen, which hides her.866PROC ShowGirl()867  BYTE x868  x=0869  IF hroom=groom THEN870    ; her cell, worked out as his is871    ; in PROC Lamp872    IF InLight((lx-44) RSH 2,873               (ly-19) RSH 3)=1874    THEN x=lx FI875  FI876  hposp3=x hposm3=x hposm2=x+2877  hposm1=x+4 hposm0=x+6878RETURN879880; move the lamplight when he has moved881; to another cell882; Called every frame. Also where883; points are scored for finding884; furniture.885PROC Lamp()886  BYTE i,k887  ; the cell at his middle: 4 across888  ; and 13 lines down from hx,hy (the889  ; room starts at 48,32)890  hcx=(hx-44) RSH 2 hcy=(hy-19) RSH 3891  ; lightning or a bottle is lighting892  ; the whole room: leave it893  IF flash>0 OR lit>0 THEN RETURN FI894  ; still in the same cell: no change895  IF hcx=lcx AND hcy=lcy THEN RETURN FI896  IF lcx<255 THEN Dark() FI897  lcx=hcx lcy=hcy898  Light()899  ; the ghouls, as the light now falls900  ; on them901  FOR i=0 TO MAXG-1 DO902    IF gst(i)>0 THEN DrawG(i) FI903  OD904  ShowGirl()905  ; the lamp falls on a piece of906  ; furniture for the first time:907  ; a chime, and 25 points908  FOR i=0 TO 2 DO909    k=hroom*3+i910    IF ff(k)=0 AND911       InLight(fx(k)+1,fy(k)+1)=1912    THEN913      ff(k)=1 score==+25 ShowScore()914      Sfx(SFIND,12)915      ; a bottle was hidden here? He916      ; can carry two.917      IF k=bk1 OR k=bk2 THEN918        IF bot<2 THEN bot==+1 FI919        ShowBot() Sfx(SFIND,24)920        Msg("LIGHTNING IN A BOTTLE!")921      ELSEIF ft(k)=0 THEN922        Msg("A TABLE! +25")923      ELSEIF ft(k)=1 THEN924        Msg("OLD BOOKS! +25")925      ELSEIF ft(k)=2 THEN926        Msg("AN ARMCHAIR! +25")927      ELSE928        Msg("A CLOCK! TICK... +25")929      FI930    FI931  OD932RETURN933934; Now and then lightning shows the935; whole room for a moment: her, if she936; is here, and where the ghouls stand.937PROC Storm()938  BYTE y,i939  ; not while a bottle is burning940  IF lit>0 THEN RETURN FI941  ; a flash is on: count it down. The942  ; background is white for its first943  ; three frames; after nine the room944  ; goes dark and lcx=255 makes Lamp945  ; draw the lamplight again.946  IF flash>0 THEN947    flash==-1948    IF flash=6 THEN Poke(712,0) FI949    IF flash=0 THEN  ; dark again950      FOR y=3 TO 20 DO951        Zero(scrn+y*40+1,38)952      OD953      lcx=255954    FI955    RETURN956  FI957  ; no flash: count down to the next958  ftm==-1959  IF ftm>0 THEN RETURN FI960  ; Flash! The next will come in 4 to961  ; 8 seconds. Background white. Rows962  ; 3 to 20 of the room (720 cells,963  ; starting at cell 120) are all964  ; shown.965  ftm=250+Rand(250)966  flash=9 Poke(712,$0E)967  MoveBlock(scrn+120,room+120,720)968  ; a pair of eyes where each ghoul's969  ; head is970  FOR i=0 TO MAXG-1 DO971    IF gst(i)>0 THEN972      Poke(scrn+gy(i)*40+gx(i),EYES)973    FI974  OD975  ; and her, if this is her room976  IF hroom=groom THEN977    hposp3=lx hposm3=lx hposm2=lx+2978    hposm1=lx+4 hposm0=lx+6979  FI980  Sfx(STHUN,40)981  Msg("LIGHTNING!")982RETURN983984; --------------- the ghouls ---------------985986; could ghoul i stand at nx,ny?987BYTE FUNC Free(BYTE i,nx,ny)988  BYTE j989  CARD p990  ; inside the walls?991  IF nx<1 OR nx>37 OR ny<3 OR ny>18992  THEN RETURN (0) FI993  ; the two cells under its bottom row994  ; must not be solid995  p=(ny+2)*40+nx     ; its feet996  IF Solid(room(p))=1997     OR Solid(room(p+1))=1998  THEN RETURN (0) FI999  ; and it must not overlap another1000  ; ghoul (each is 2 cells wide and 31001  ; high)1002  FOR j=0 TO MAXG-1 DO1003    IF j<>i AND gst(j)>0 THEN1004      IF nx+2>gx(j) AND gx(j)+2>nx1005         AND ny+3>gy(j) AND gy(j)+3>ny1006      THEN RETURN (0) FI1007    FI1008  OD1009RETURN (1)10101011; is x,y a fair way from him? A ghoul1012; never rises within reach.1013BYTE FUNC Far(BYTE x,y)1014  BYTE ty,dx,dy1015  ; ty: the row of his head. dx,dy:1016  ; columns and rows between x,y and1017  ; him.1018  ty=(hy-32) RSH 31019  IF x<hcx THEN dx=hcx-x ELSE dx=x-hcx FI1020  IF y<ty THEN dy=ty-y ELSE dy=y-ty FI1021  IF dx>8 OR dy>6 THEN RETURN (1) FI1022RETURN (0)10231024; n more ghouls, on the far side of1025; the room from him. Called when he1026; comes into a room, and when the pack1027; arrives in the room he is in.1028PROC SpawnG(BYTE n)1029  BYTE k,i,t,x,y1030  FOR k=1 TO n DO1031    ; find a ghoul that is not in use1032    ; (state 0); if all four are, give1033    ; up1034    i=01035    WHILE i<MAXG AND gst(i)>0 DO1036      i==+1 OD1037    IF i=MAXG THEN RETURN FI1038    ; up to eight tries at a place in1039    ; the half of the room he is not1040    ; in1041    FOR t=1 TO 8 DO1042      IF hcx<20 THEN x=22+Rand(14)1043      ELSE x=3+Rand(14) FI1044      y=4+Rand(13)1045      IF Free(i,x,y)=1 AND Far(x,y)=11046      THEN1047        ; a walking ghoul, facing him,1048        ; that waits half a second or1049        ; more before it moves1050        gx(i)=x gy(i)=y gfr(i)=01051        gst(i)=1 gtm(i)=30+Rand(30)1052        IF x>hcx THEN gdir(i)=11053        ELSE gdir(i)=0 FI1054        DrawG(i)1055        EXIT1056      FI1057    OD1058  OD1059RETURN10601061; one shambling step toward him1062PROC StepG(BYTE i)1063  BYTE x,y,nx,ny,tx,ty,dx,dy,j1064  x=gx(i) y=gy(i) nx=x ny=y1065  ; tx,ty: where it is heading, the1066  ; cell of his head (a column to the1067  ; left, as a ghoul is two wide).1068  ; dx,dy: how far it is from there.1069  IF hcx>0 THEN tx=hcx-1 ELSE tx=0 FI1070  ty=(hy-32) RSH 31071  IF x<tx THEN dx=tx-x ELSE dx=x-tx FI1072  IF y<ty THEN dy=ty-y ELSE dy=y-ty FI1073  ; one time in six, a step in any1074  ; direction1075  IF Rand(6)=0 THEN  ; a lurch off course1076    j=Rand(4)1077    IF j=0 THEN nx=x+11078    ELSEIF j=1 THEN nx=x-11079    ELSEIF j=2 THEN ny=y+11080    ELSE ny=y-1 FI1081  ; otherwise a step along whichever1082  ; is further, across or up and down1083  ELSEIF dx>dy THEN1084    IF x<tx THEN nx=x+1 ELSE nx=x-1 FI1085  ELSEIF dy>0 THEN1086    IF y<ty THEN ny=y+1 ELSE ny=y-1 FI1087  FI1088  ; blocked? Then a step the other way1089  ; of the two, if that gets it1090  ; nearer.1091  IF Free(i,nx,ny)=0 THEN1092    nx=x ny=y        ; try the other way1093    IF dx>dy THEN1094      IF y<ty THEN ny=y+11095      ELSEIF y>ty THEN ny=y-1 FI1096    ELSE1097      IF x<tx THEN nx=x+11098      ELSEIF x>tx THEN nx=x-1 FI1099    FI1100  FI1101  ; face the way it is going1102  IF nx>x THEN gdir(i)=01103  ELSEIF nx<x THEN gdir(i)=1 FI1104  ; rub it out, move it if it can go1105  ; there, change to its other step,1106  ; draw it again1107  EraseG(i)1108  IF Free(i,nx,ny)=1 THEN1109    gx(i)=nx gy(i)=ny1110  FI1111  gfr(i)==!11112  DrawG(i)1113  ; frames until its next step1114  gtm(i)=gdel+Rand(6)1115RETURN11161117; A ghoul has grabbed him, and he has1118; a bottle: it bursts. For four1119; seconds the whole room is lit and1120; every ghoul in it is dazed.1121PROC Burst()1122  BYTE i1123  ; 240 frames is four seconds.1124  ; Background white, rows 3 to 20 of1125  ; the room all shown.1126  bot==-1 ShowBot()1127  lit=240 flash=0 Poke(712,$0E)1128  MoveBlock(scrn+120,room+120,720)1129  ; state 2 is dazed, for 255 frames1130  FOR i=0 TO MAXG-1 DO1131    IF gst(i)>0 THEN1132      gst(i)=2 gtm(i)=255 DrawG(i)1133    FI1134  OD1135  ShowGirl()1136  Sfx(STHUN,40)1137  Msg("THE BOTTLE BURSTS!")1138RETURN11391140; the bottle's light runs down: it1141; flickers for the last second, then1142; the room is dark again1143PROC Glare()1144  BYTE y1145  IF lit=0 THEN RETURN FI1146  lit==-11147  ; white for the first four frames1148  ; only1149  IF lit=236 THEN Poke(712,0) FI1150  ; under 48 frames left: the1151  ; background flickers1152  IF lit<48 THEN1153    IF (lit&8)=8 THEN Poke(712,2)1154    ELSE Poke(712,0) FI1155  FI1156  ; out: blank the room. lcx=255 makes1157  ; Lamp draw the lamplight again.1158  IF lit=0 THEN1159    FOR y=3 TO 20 DO1160      Zero(scrn+y*40+1,38)1161    OD1162    lcx=255 ShowGirl()1163  FI1164RETURN11651166; every ghoul, every frame1167; (moves them, and sees whether one is1168; touching him)1169PROC Ghouls()1170  BYTE i,px,py1171  FOR i=0 TO MAXG-1 DO1172    IF gst(i)>0 THEN1173      ; its timer runs down. At 0 a1174      ; dazed ghoul wakes, and a1175      ; walking one takes a step.1176      IF gtm(i)>0 THEN gtm(i)==-11177      ELSEIF gst(i)=2 THEN1178        gst(i)=1 gtm(i)=gdel1179      ELSE StepG(i) FI1180      ; px,py: its top left corner in1181      ; player coordinates (a cell is1182      ; 4 by 8, the room starts at1183      ; 48,32). Is it touching him?1184      ; Not counted while hfree is1185      ; running.1186      px=48+gx(i)*4 py=32+gy(i)*81187      IF hfree=01188         AND hx+6>px AND px+6>hx1189         AND hy+22>py AND py+22>hy1190      THEN1191        ; a walking ghoul (state 1)1192        IF gst(i)=1 THEN1193          IF bot>0 THEN Burst()1194          ELSE       ; it has hold of him1195            ; he is held for 451196            ; frames, and cannot be1197            ; grabbed for 110. The1198            ; ghoul is dazed for 90.1199            ; He has one grab fewer1200            ; left; at none, PROC1201            ; Caught takes a life.1202            stun=45 hfree=1101203            gst(i)=2 gtm(i)=901204            Sfx(SGRAB,10)1205            hp==-1 ShowHp()1206            IF hp=0 THEN caught=1 cg=i1207            ELSE1208              Msg("A GHOUL GRABS YOU!")1209            FI1210          FI1211        ELSEIF lit>0 THEN1212          ; dazed, in the bottle's1213          ; light: touch it and it goes1214          ; back underground for good1215          ; 50 points for it, and one1216          ; ghoul fewer lives in this1217          ; room1218          EraseG(i) gst(i)=01219          IF rgh(hroom)>0 THEN1220            rgh(hroom)==-1 FI1221          score==+50 ShowScore()1222          Sfx(SDOWN,20)1223          Msg("BACK UNDERGROUND! +50")1224        FI1225      FI1226    FI1227  OD1228RETURN12291230; ------------------ him ------------------12311232; he has just come into room hroom1233; Draws the room dark, and puts the1234; ghouls and (if it is her room) her1235; into it.1236PROC Enter()1237  BYTE y,i1238  CARD p1239  ; On the first night, the first time1240  ; he comes into a room the doorway1241  ; that leads toward her glows. After1242  ; that night he has to bump into a1243  ; clock to see it (PROC Bump).1244  gl=255 lit=01245  IF seen(hroom)=0 THEN1246    seen(hroom)=11247    IF level=1 THEN Way() FI1248  FI1249  ; draw the room into the array.1250  ; Clear the missiles and all four1251  ; players (1280 bytes from +768 to1252  ; the end of player memory).1253  BuildRoom()1254  Zero(pmb+768,1280)1255  ; on the screen: the top three rows1256  ; (120 cells) and the bottom row as1257  ; they are1258  MoveBlock(scrn,room,120)1259  MoveBlock(scrn+840,room+840,40)1260  FOR y=3 TO 20 DO   ; only the walls1261    p=y*401262    Zero(scrn+p,40)1263    Poke(scrn+p,room(p))1264    Poke(scrn+p+39,room(p+39))1265  OD1266  ; no ghouls yet, his cell, no1267  ; lamplight drawn, no lightning1268  FOR i=0 TO MAXG-1 DO gst(i)=0 OD1269  hcx=(hx-44) RSH 2 hcy=(hy-19) RSH 31270  lcx=255 flash=0 Poke(712,0)1271  ; the ghouls who live here, and two1272  ; more if the pack is in this room1273  SpawnG(rgh(hroom))1274  IF hroom=proom THEN SpawnG(2) FI1275  ; Her room: put her shape into1276  ; player memory. 26 bytes for player1277  ; 3 (at +1792) and 26 for the1278  ; missiles (at +768), each starting1279  ; ly TV lines down.1280  IF hroom=groom THEN1281    MoveBlock(pmb+1792+ly,girl,26)1282    MoveBlock(pmb+768+ly,girl+26,26)1283  FI1284  Sfx(SDOOR,8)1285  ; she hears the door, and calls1286  IF vtm>20 THEN vtm=20 FI1287RETURN12881289; Draw him, every frame. A pose is 781290; bytes: 26 rows for each of players1291; 0, 1 and 2, which lie one on top of1292; another to give him his colours.1293PROC DrawHero()1294  CARD s1295  BYTE x1296  ; hstep picks one of his two walking1297  ; poses, changing every eight frames1298  ; he walks1299  IF hdir=0 THEN1300    s=hero+((hstep RSH 3)&1)*781301  ELSE1302    s=herol+((hstep RSH 3)&1)*781303  FI1304  ; With one-line players each player1305  ; has 256 bytes of memory, one for1306  ; every TV line down the screen:1307  ; player 0 at +1024, player 1 at1308  ; +1280, player 2 at +1536. Starting1309  ; at +hy puts him hy lines down.1310  MoveBlock(pmb+1024+hy,s,26)1311  MoveBlock(pmb+1280+hy,s+26,26)1312  MoveBlock(pmb+1536+hy,s+52,26)1313  ; while a ghoul holds him he1314  ; flickers: position 0 is off the1315  ; screen1316  x=hx1317  IF (stun&2)=2 THEN x=0 FI ; held1318  hposp0=x hposp1=x hposp2=x1319RETURN13201321; He has walked into something. If it1322; is a clock, it chimes, and (after1323; the first night) the doorway toward1324; her glows: once for each room.1325PROC Bump(BYTE c)1326  BYTE y1327  CARD p1328  ; not a clock: nothing happens1329  IF c<CLOCK OR c>CLOCK+5 THEN1330    RETURN FI1331  ; not on night 1, only once in each1332  ; room (seen goes to 2), and not in1333  ; her room1334  IF level=1 OR seen(hroom)<>11335     OR hroom=groom THEN RETURN FI1336  seen(hroom)=21337  Way() GlowDoor()1338  ; show the top and bottom rows and1339  ; the side doorways again, where the1340  ; glow may now be1341  MoveBlock(scrn,room,120)1342  MoveBlock(scrn+840,room+840,40)1343  FOR y=10 TO 13 DO1344    p=y*401345    Poke(scrn+p,room(p))1346    Poke(scrn+p+39,room(p+39))1347  OD1348  Sfx(SFIND,24)1349  Msg("THE CLOCK CHIMES...")1350RETURN13511352; Move him, once a frame. The stick1353; reads 15 at rest, and one bit goes1354; to 0 for each way it is pushed: 11355; up, 2 down, 4 left, 8 right. He goes1356; 1 across or 2 up or down in a frame,1357; if what is there is not solid. Then1358; see if he has gone through a1359; doorway.1360PROC Hero()1361  BYTE s,c1362  ; hfree: the time he cannot be1363  ; grabbed runs down. stun: held by a1364  ; ghoul, he cannot move.1365  IF hfree>0 THEN hfree==-1 FI1366  IF stun>0 THEN stun==-11367  ELSE1368    s=Stick(0)1369    ; stick pushed: on with his walk1370    IF s<>15 THEN hstep==+1 FI1371    ; right: look at the cell 4 ahead1372    IF (s&8)=0 THEN1373      hdir=01374      c=At(hx+4,hy)1375      IF Solid(c)=0 THEN hx==+11376      ELSE Bump(c) FI1377    FI1378    ; left1379    IF (s&4)=0 THEN1380      hdir=11381      c=At(hx-4,hy)1382      IF Solid(c)=0 THEN hx==-11383      ELSE Bump(c) FI1384    FI1385    ; up1386    IF (s&1)=0 THEN1387      c=At(hx,hy-2)1388      IF Solid(c)=0 THEN hy==-21389      ELSE Bump(c) FI1390    FI1391    ; down1392    IF (s&2)=0 THEN1393      c=At(hx,hy+2)1394      IF Solid(c)=0 THEN hy==+21395      ELSE Bump(c) FI1396    FI1397    ; through a door?1398    ; Walls are solid, so he can only1399    ; get this far out in a doorway.1400    ; West is the room 1 less, east 11401    ; more, north 4 less, south 41402    ; more. He comes in at the1403    ; opposite side.1404    IF hx<=47 THEN1405      hroom==-1 hx=194 Enter()1406    ELSEIF hx>=197 THEN1407      hroom==+1 hx=50 Enter()1408    ELSEIF hy<=32 THEN1409      hroom==-4 hy=166 Enter()1410    ELSEIF hy>=178 THEN1411      hroom==+4 hy=36 Enter()1412    FI1413  FI1414  DrawHero()1415RETURN14161417; has he reached her?1418; (within 7 across and 14 down of her,1419; in her room). found=1 ends the1420; round: see PROC Main.1421PROC Meet()1422  IF hroom=groom1423     AND hx+7>lx AND lx+7>hx1424     AND hy+14>ly AND ly+14>hy1425  THEN found=1 FI1426RETURN14271428; She calls every few seconds, and at1429; once if he calls first (the button).1430; But then the ghouls hear him too.1431PROC Voice()1432  BYTE d1433  ; both timers run down1434  IF vcool>0 THEN vcool==-1 FI1435  IF vtm>0 THEN vtm==-1 FI1436  ; time for her call, or the button1437  ; is down and has had its second of1438  ; rest1439  IF vtm=0 OR (Strig(0)=0 AND vcool=0)1440  THEN1441    ; vtm>0 means it was his call. The1442    ; pack's next move comes 90 frames1443    ; (a second and a half) sooner.1444    IF vtm>0 THEN1445      IF ptm>90 THEN ptm==-901446      ELSE ptm=1 FI1447    FI1448    ; her next call in 200 frames; the1449    ; button rests for 601450    vtm=200 vcool=601451    ; d: doors between him and her.1452    ; The meter shows 8 in her room1453    ; and one less for each door, but1454    ; never less than 1.1455    d=dist(hroom)1456    IF d<7 THEN vlev=8-d1457    ELSE vlev=1 FI1458    ShowVoice() Sfx(SCALL,24)1459    IF d=0 THEN1460      Msg("SHE IS IN THIS ROOM!")1461    ELSE1462      Msg("SHE CALLS: HELP ME!")1463    FI1464  FI1465RETURN14661467; the ghouls go one room nearer to her1468; Called every frame, but it only acts1469; when its timer ptm runs out.1470PROC Pack()1471  BYTE d,nb1472  ptm==-11473  IF ptm>0 THEN RETURN FI1474  ptm=ptime1475  ; take the first door that leads to1476  ; a room nearer to her1477  FOR d=0 TO 3 DO1478    IF HasDoor(proom,d)=1 THEN1479      nb=Nbr(proom,d)1480      IF dist(nb)<dist(proom) THEN1481        proom=nb1482        EXIT1483      FI1484    FI1485  OD1486  ShowPack() Sfx(SGROAN,30)1487  ; In her room: the round is lost. In1488  ; his room: two of them appear.1489  IF proom=groom THEN taken=11490  ELSEIF proom=hroom THEN1491    SpawnG(2)1492    Msg("THE GHOULS ARE HERE!")1493  ELSE1494    Msg("THEY ARE CLOSER NOW...")1495  FI1496RETURN14971498; ------------- sound -------------14991500; One frame of the sound effect that1501; is playing, on voice 3. sfxt counts1502; down the frames it has left, and1503; most effects use it to slide the1504; pitch or the loudness.1505PROC Effect()1506  sfxt==-11507  IF sfx=SCALL THEN   ; "he-elp!"1508    IF sfxt>12 THEN1509      Sound(3,40,10,vlev+4)1510    ELSE Sound(3,50,10,vlev+4) FI1511  ELSEIF sfx=SGRAB THEN ; a thump1512    Sound(3,250-sfxt*12,10,10)1513  ELSEIF sfx=SGROAN THEN ; a groan1514    Sound(3,225-sfxt,12,8)1515  ELSEIF sfx=SDOWN THEN ; underground1516    Sound(3,220-sfxt*8,10,8)1517  ELSEIF sfx=SFIND THEN ; a find1518    IF sfxt>6 THEN Sound(3,60,10,8)1519    ELSE Sound(3,40,10,8) FI1520  ELSEIF sfx=STHUN THEN ; thunder1521    Sound(3,200+Rand(50),8,sfxt RSH 2)1522  ELSE                ; a door1523    Sound(3,100+sfxt*4,10,4)1524  FI1525  IF sfxt=0 THEN sfx=0 FI1526RETURN15271528; the band, called once a frame: bass1529; on voice 0, lead on 1, its echo on 2,1530; a heartbeat or a sound effect on 31531PROC Music()1532  BYTE b,l,e,d1533  ; in the middle of a step: let the1534  ; bass and the lead die away a1535  ; little1536  IF mtm>0 THEN1537    mtm==-11538    IF bvol>3 THEN bvol==-1 FI1539    IF lvol>4 AND (mtm&1)=0 THEN1540      lvol==-1 FI1541  ELSE1542    ; The next step of the tune. In1543    ; the tables 0 is silence, 1 lets1544    ; the note ring on, and anything1545    ; else is a new note. The echo is1546    ; the lead from three steps back.1547    ; The drum table is 16 steps, used1548    ; over and over.1549    mtm=tempo-11550    b=bass(mpos) l=lead(mpos)1551    e=lead((mpos-3)&127)1552    d=drum(mpos&15)1553    IF b=0 THEN bvol=01554    ELSEIF b>1 THEN bnote=b bvol=8 FI1555    IF l=0 THEN lvol=01556    ELSEIF l>1 THEN lnote=l lvol=7 FI1557    IF e=0 THEN evol=01558    ELSEIF e>1 THEN enote=e evol=3 FI1559    IF d=1 THEN dtyp=1 dvol=12 dpit=1001560    ELSEIF d=2 THEN dtyp=2 dvol=91561    ELSEIF d=3 THEN dtyp=3 dvol=4 FI1562    ; the tune is 128 steps long1563    mpos=(mpos+1)&1271564  FI1565  ; set the three voices1566  Sound(0,bnote,12,bvol)1567  Sound(1,lnote,10,lvol)1568  Sound(2,enote,10,evol)1569  ; voice 3: a sound effect if one is1570  ; playing, else the drum1571  IF sfx>0 THEN Effect()1572  ELSEIF dvol>0 THEN1573    IF dtyp=1 THEN    ; kick1574      Sound(3,dpit,10,dvol)1575      dpit==+45 dvol==-41576    ELSEIF dtyp=2 THEN ; snare1577      Sound(3,14,8,dvol) dvol==-31578    ELSE              ; hat1579      Sound(3,1,8,dvol) dvol=01580    FI1581  ELSE Sound(3,0,0,0) FI1582RETURN15831584; start the tune from the top, with1585; every voice silent and no sound1586; effect1587PROC MusicOn()1588  mpos=0 mtm=0 bvol=0 lvol=0 evol=01589  dvol=0 sfx=01590RETURN15911592; The digitized laugh: see screen 2.1593; Each byte of laugh holds two samples1594; of four bits. A sample is played by1595; putting $10 + its level into the two1596; volume registers; the empty FOR1597; loops wait between samples. Nothing1598; else can happen meanwhile. Called1599; when a life is lost.1600PROC Laugh(BYTE n)1601  CARD i,c,fs,st1602  BYTE b,v,d,k,o,p1603  BYTE ARRAY ft(128)1604  ; ft: the 16 levels at 1/8 to 8/81605  ; of full strength, 16 to a row,1606  ; shrunk toward the middle level 81607  FOR k=1 TO 8 DO1608    FOR v=0 TO 15 DO1609      IF v<8 THEN d=8-((8-v)*k+4)/81610      ELSE d=8+((v-8)*k+4)/8 FI1611      ft((k-1)*16+v)=$10%d1612    OD1613  OD1614  ; n=1: once, fading over its last1615  ; quarter. n=2: once at full strength1616  ; (row 112), then again, fading all1617  ; the way through. st is where the1618  ; fade starts; it drops a row every1619  ; fs bytes.1620  IF n=1 THEN fs=LAUGHLEN/281621  ELSE fs=LAUGHLEN/7 FI1622  ; o: the row of ft in use (112 is1623  ; full strength)1624  o=1121625  FOR p=1 TO n DO1626    st=LAUGHLEN c=fs-11627    IF p=n THEN st=LAUGHLEN-fs*7 FI1628    FOR i=0 TO LAUGHLEN-1 DO1629      ; the high half of the byte,1630      ; then the low half1631      b=laugh(i)1632      v=ft(o+(b RSH 4)) audc1=v audc2=v1633      FOR d=1 TO 9 DO OD1634      v=ft(o+(b&15)) audc1=v audc2=v1635      FOR d=1 TO 9 DO OD1636      ; fading: a row quieter every fs1637      ; bytes1638      IF i>=st THEN1639        c==+11640        IF c=fs THEN1641          c=01642          IF o>0 THEN o==-16 FI1643        FI1644      FI1645    OD1646  OD1647  audc1=0 audc2=01648RETURN16491650; ------------- the game -------------16511652; how hard is this level?1653; Sets the numbers that depend on the1654; night (level), and on ease.1655PROC NewLevel()1656  ; gdel: frames between a ghoul's1657  ; steps, 15 on night 1 down to 81658  IF level<8 THEN gdel=16-level1659  ELSE gdel=8 FI1660  ; the grabs he can take1661  IF level<3 THEN hpm=4-level1662  ELSE hpm=1 FI1663  ; frames the ghouls allow for each1664  ; door between you and her: it goes1665  ; on shrinking, night after night1666  pace=150+2400/(level+2)1667  ; and 150 more for each try already1668  ; lost here1669  pace==+ease*1501670  ; slack: frames added to the pack's1671  ; whole march (see PROC Round)1672  IF level<6 THEN slack=1200-level*1501673  ELSE slack=300 FI1674  ; the tune goes faster after night 31675  tempo=101676  IF level>3 THEN tempo=9 FI1677RETURN16781679; a new mansion, and everybody in it1680; Called at the start of every try.1681PROC Round()1682  BYTE i,r1683  ; doors, her room, the count of1684  ; doors from it, furniture1685  Maze() groom=Rand(12)1686  Dist() Furnish()1687  FOR i=0 TO 11 DO seen(i)=0 OD1688  ; the ghouls start as far from her1689  ; as they can be1690  proom=01691  FOR i=1 TO 11 DO1692    IF dist(i)>dist(proom) THEN1693      proom=i FI1694  OD1695  ; and he starts a good way off too1696  hroom=proom1697  ; forty tries at a room more than1698  ; two doors from her1699  FOR i=1 TO 40 DO1700    r=Rand(12)1701    IF dist(r)>2 AND r<>proom THEN1702      hroom=r1703      EXIT1704    FI1705  OD1706  ; no luck: any room but hers and the1707  ; ghouls'1708  IF hroom=proom THEN1709    FOR r=0 TO 11 DO1710      IF dist(r)>0 AND r<>proom THEN1711        hroom=r FI1712    OD1713  FI1714  ; ptime: frames between the pack's1715  ; moves. Their whole march takes as1716  ; long as he is allowed (pace for1717  ; each door he has to go through)1718  ; and slack frames more: about 171719  ; seconds on night 1, less on later1720  ; nights.1721  ptime=(dist(hroom)*pace+slack)1722        /dist(proom)1723  ptm=ptime1724  ; she hides in one of the four1725  ; corners of her room (lx,ly are1726  ; player coordinates)1727  IF Rand(2)=0 THEN lx=641728  ELSE lx=180 FI1729  IF Rand(2)=0 THEN ly=441730  ELSE ly=150 FI1731  ; nothing stands in her corner of1732  ; her room, so he can always reach1733  ; her1734  FOR i=0 TO 2 DO1735    r=groom*3+i1736    IF (fx(r)<20 AND lx<124)1737       OR (fx(r)>19 AND lx>123)1738    THEN1739      IF (fy(r)<10 AND ly<100)1740         OR (fy(r)>9 AND ly>99)1741      THEN ft(r)=255 ff(r)=1 FI1742    FI1743  OD1744  ; two pieces hide lightning in a1745  ; bottle: two different ones, and1746  ; neither a piece just taken away,1747  ; so every mansion has two to find1748  DO1749    bk1=Rand(36)1750  UNTIL ft(bk1)<>255 OD1751  DO1752    bk2=Rand(36)1753  UNTIL ft(bk2)<>255 AND bk2<>bk1 OD1754  ; he starts in the middle of his1755  ; room, with nothing in hand and1756  ; full strength1757  hx=124 hy=104 hdir=0 hstep=01758  stun=0 hfree=0 found=0 taken=01759  bot=0 lit=0 hp=hpm caught=01760  ; her first call comes after a1761  ; second, the first lightning after1762  ; 2.5 to 41763  vtm=60 vcool=0 vlev=01764  flash=0 ftm=150+Rand(100)1765  ; draw the text lines and the room1766  ShowAll() Enter()1767  Msg("FIND HER! LISTEN...")1768  MusicOn()1769RETURN17701771; he has found her: the lights come on1772PROC Found()1773  SndRst()1774  ; show the whole room, and her1775  MoveBlock(scrn,room,880)1776  hposp3=lx hposm3=lx hposm2=lx+21777  hposm1=lx+4 hposm0=lx+61778  ; she holds out her arms to him1779  IF hx>=lx THEN1780    MoveBlock(pmb+1792+ly,girl+156,26)1781    MoveBlock(pmb+768+ly,girl+182,26)1782  FI1783  Msg("YOU FOUND HER! SAFE!")1784  ; HAPPOKEY.ACT, 3.2 seconds of music1785  ; on the sound chip's four voices,1786  ; once through: a table of 193 rows,1787  ; one for each sixtieth of a second.1788  ; HpTick() pokes the next row into1789  ; the sound registers and clears1790  ; hpon after the last.1791  ; Nothing moves meanwhile.1792  HpStart()1793  WHILE hpon<>0 DO1794    Frame()1795    HpTick()1796  OD1797  SndRst()1798  ; points for finding her: 200, and1799  ; 100 more for every room the ghouls1800  ; still had to go1801  score==+200+dist(proom)*1001802  ShowScore()1803RETURN18041805; the ghouls got to her room first1806PROC Taken()1807  BYTE i1808  SndRst()1809  Msg("THEY FOUND HER FIRST!")1810  ; a falling note, then the laugh1811  FOR i=0 TO 40 DO1812    Frame()1813    Sound(0,230-i,12,8)1814  OD1815  SndRst()1816  ; twice for his last life1817  IF lives=1 THEN Laugh(2)1818  ELSE Laugh(1) FI1819  ; a life goes, and its heart is1820  ; rubbed out1821  lives==-11822  Position(34+lives,23) Put(32)1823RETURN18241825; a grab too many: it costs a life.1826; If he has one left he gets up where1827; he fell, in the same mansion; that1828; ghoul has gone back underground,1829; and for a while nothing can grab1830; him. The pack loses no time by it.1831PROC Caught()1832  BYTE i1833  SndRst()1834  Msg("THE GHOULS GOT YOU!")1835  ; a falling note, then the laugh1836  FOR i=0 TO 40 DO1837    Frame()1838    Sound(0,230-i,12,8)1839  OD1840  SndRst()1841  IF lives=1 THEN Laugh(2)1842  ELSE Laugh(1) FI1843  ; a life goes, and its heart is1844  ; rubbed out1845  lives==-11846  Position(34+lives,23) Put(32)1847  caught=01848  IF lives=0 THEN RETURN FI1849  ; the ghoul that got him is taken1850  ; away, he has all his grabs back,1851  ; and for 150 frames nothing can1852  ; grab him1853  EraseG(cg) gst(cg)=01854  IF rgh(hroom)>0 THEN1855    rgh(hroom)==-1 FI1856  hp=hpm ShowHp()1857  stun=0 hfree=1501858  Msg("UP YOU GET! FIND HER!")1859RETURN18601861; Back to the title program, which1862; shows the card for the next screen1863; and loads it. (The loading is not1864; written: under DOS 2.0S it is a1865; binary load of D:THRILLER.OBJ and a1866; jump to its start.)1867PROC Next()1868  SndRst()1869  ; interrupt off, players and1870  ; missiles off and moved off the1871  ; screen1872  Poke(54286,64) Poke(53277,0)1873  hposp0=0 hposp1=0 hposp2=0 hposp3=01874  hposm0=0 hposm1=0 hposm2=0 hposm3=01875RETURN18761877; No lives left. Run by the title1878; program: show GAME OVER for three1879; seconds, set result to 0 and go1880; back. Run by itself: wait for START.1881PROC GameOver()1882  BYTE i1883  IF chain=1 THEN1884    Msg("GAME OVER")1885    FOR i=0 TO 180 DO Frame() OD1886    result=0 Next()1887  ELSE1888    Msg("GAME OVER: PRESS START")1889    DO Frame() UNTIL consol=6 OD1890  FI1891RETURN18921893; This screen's own title page, in big1894; letters (GRAPHICS 18), with the1895; tune. Only shown when the screen is1896; run by itself. Waits for START.1897PROC Title()1898  ; interrupt and players off1899  Poke(54286,64) Poke(53277,0)1900  hposp0=0 hposp1=0 hposp2=0 hposp3=01901  hposm0=0 hposm1=0 hposm2=0 hposm3=01902  ; the Atari's own letters (756), and1903  ; four colours1904  Graphics(18) Poke(756,224)1905  Poke(708,$36) Poke(709,$0E)1906  Poke(710,$C8) Poke(711,$1A)1907  Position(6,1) PrintD(6,"THRILLER")1908  Position(4,3)1909  PrintD(6,"screen three")1910  Position(1,5)1911  PrintD(6,"FIND YOUR GIRL IN")1912  Position(1,6)1913  PrintD(6,"THE MANSION BEFORE")1914  Position(6,7)1915  PrintD(6,"THEY DO!")1916  Position(4,9) PrintD(6,"press start")1917  Position(0,11)1918  PrintD(6,"designed 1984 d.lutz")1919  MusicOn() tempo=101920  DO1921    Frame() Music()1922    IF (frm&3)=0 THEN ; the title drips1923      Poke(708,$32+Rand(4)*2) FI1924  UNTIL consol=6 OD1925  SndRst()1926RETURN19271928; The whole program. The outer loop is1929; one game, the middle loop one try at1930; a mansion, the inner loop one TV1931; frame.1932PROC Main()1933  Init()1934  DO1935    ; run by itself: title page, new1936    ; game1937    IF chain=0 THEN1938      Title() score=0 lives=3 wins=01939    FI1940    Screen() ease=01941    DO1942      ; three screens won make a night1943      level=wins/3+1 NewLevel()1944      Round()1945      DO1946        ; one frame: him, his lamp,1947        ; lightning, the bottle's1948        ; light, the ghouls in this1949        ; room, a life lost to them,1950        ; her voice, the ghoul pack,1951        ; has he reached her, the1952        ; music1953        Frame()1954        Hero() Lamp() Storm() Glare()1955        Ghouls()1956        IF caught=1 THEN Caught() FI1957        Voice() Pack() Meet() Music()1958      UNTIL found=1 OR taken=11959            OR lives=0 OD1960      IF found=1 THEN1961        Found()1962        ; in the full game: count the1963        ; win, set result to 1 and go1964        ; back to the title program1965        IF chain=1 THEN1966          wins==+1 result=1 Next()1967          RETURN1968        FI1969        ; by itself: add 3 wins, which1970        ; makes the next try a night1971        ; later1972        wins==+3 ease=01973      ELSEIF taken=1 THEN1974        ; the ghouls won: a new1975        ; mansion, a little easier1976        ; (ease is 2 at most)1977        Taken()1978        IF ease<2 THEN ease==+1 FI1979      FI1980    UNTIL lives=0 OD1981    GameOver()1982    IF chain=1 THEN RETURN FI1983  OD1984RETURN