Path: funic!news.funet.fi!sunic!ugle.unit.no!solan1.solan.unit.no!egeberg
From: egeberg@solan.unit.no (Christian Egeberg)
Newsgroups: comp.sys.handhelds
Subject: Chipper source & stuff
Keywords: Chipper, Chip-48, Games, S-Chip
Message-ID: <1991Jun6.150250.15059@ugle.unit.no>
Date: 6 Jun 91 15:02:50 GMT
Sender: news@ugle.unit.no
Reply-To: egeberg@solan.unit.no (Christian Egeberg)
Organization: Norwegian Institue of Technology
Lines: 1118

This is the Blinky V1.01 Chipper source
---------------------------------------------------------------------
;  Chip-48 Blinky (PacMan) by Christian Egeberg 7/11-'90 .. 11/11-'90

;  Register usage:
;  V0:  Temporary data, may change during any call
;  V1:  Temporary data, may change during any call
;  V2:  Temporary data, may change during most calls
;  V3:  Temporary data, may change during most calls
;  V4:  Temporary data, may change during some calls
;  V5:  Temporary data, may change during some calls
;  V6:  Pill and score counter
;  V7:  Life and sprite direction register
;  V8:  Blinky X screen coordinate
;  V9:  Blinky Y screen coordinate
;  VA:  Packlett X screen coordinate
;  VB:  Packlett Y screen coordinate
;  VC:  Heward X screen coordinate
;  VD:  Heward Y screen coordinate
;  VE:  Temporary constant and flag storage
;  VF:  Flag register

MASKNIBB    =     $1111
MASKBYTE    =     $11111111

DOWNKEY     =     #6
RIGHTKEY    =     #8
LEFTKEY     =     #7
UPKEY       =     #3
PRESSKEY    =     #F

PILLNUM     =     231
SUPERNUM    =     4

PILLTIME    =     5
SUPERTIME   =     255
CLSWAIT     =     64
EYEWAIT     =     3

PILLADD     =     1
SUPERADD    =     4
HWRDADD     =     25
PKLTADD     =     50
SCREENADD   =     100

MASKLIFE    =     $01000000
MASKHUNT    =     $10000000
MASKCODE    =     $11
DOWNCODE    =     $11
RIGHTCODE   =     $10
LEFTCODE    =     $01
UPCODE      =     $00

BLNKCODE    =     DOWNCODE
BLNKX       =     26
BLNKY       =     12
PKLTCODE    =     LEFTCODE
PKLTX       =     56
PKLTY       =     0
HWRDCODE    =     RIGHTCODE
HWRDX       =     2
HWRDY       =     26

GATELEFT    =     0
GATERIGHT   =     58

SCXPOS      =     17
SCYPOS      =     16
HIXPOS      =     17
HIYPOS      =     10
EYEX1       =     0
EYEX2       =     48
EYEY1       =     0
EYEY2       =     22

            CLS
            JP    START

COPYRIGHT:  DA    'Chr. Egeberg 11/11-''90'

START:      XOR   V0, V0
            XOR   V1, V1
            LD    I, SCORE
            LD    [I], V1
REINIT:     LD    V6, 0
            LD    V7, 0
            CALL  COPYMAZE
RESTART:    LD    VE, MASKLIFE
            AND   V7, VE
            LD    VE, HWRDCODE < 4 | PKLTCODE < 2 | BLNKCODE
            OR    V7, VE
            LD    V8, BLNKX
            LD    V9, BLNKY
            LD    VA, PKLTX
            LD    VB, PKLTY
            LD    VC, HWRDX
            LD    VD, HWRDY
            CLS
            CALL  DRAWMAZE
            CALL  DRAWBLNK
            LD    I, GHOST
            DRW   VA, VB, 4
            DRW   VC, VD, 4
GAMELOOP:   CALL  MOVEBLNK
            SE    VE, 0
            JP    ENCOUNTER
SPLITUP:    CALL  MOVEPKLT
            CALL  MOVEHWRD
            SE    V6, PILLADD * PILLNUM + SUPERADD * SUPERNUM
            JP    GAMELOOP
            LD    VE, V6
            CALL  ADDSCORE
            LD    VE, SCREENADD
            CALL  ADDSCORE
            JP    REINIT
ENCOUNTER:  LD    V0, DT
            SNE   V0, 0
            JP    GOTCHA
OOPSPKLT:   LD    V0, V8
            SHR   V0
            SHR   V0
            SHR   V0
            LD    V1, VA
            SHR   V1
            SHR   V1
            SHR   V1
            SE    V0, V1
            JP    OOPSHWRD
            LD    V0, V9
            SHR   V0
            SHR   V0
            SHR   V0
            LD    V1, VB
            SHR   V1
            SHR   V1
            SHR   V1
            SE    V0, V1
            JP    OOPSHWRD
            LD    I, GHOST
            DRW   VA, VB, 4
            LD    VA, PKLTX
            LD    VB, PKLTY
            DRW   VA, VB, 4
            LD    VE, ~( MASKCODE < 2) & MASKBYTE
            AND   V7, VE
            LD    VE, PKLTCODE < 2
            OR    V7, VE
            LD    VE, PKLTADD
            CALL  ADDSCORE
OOPSHWRD:   LD    V0, V8
            SHR   V0
            SHR   V0
            SHR   V0
            LD    V1, VC
            SHR   V1
            SHR   V1
            SHR   V1
            SE    V0, V1
            JP    SPLITUP
            LD    V0, V9
            SHR   V0
            SHR   V0
            SHR   V0
            LD    V1, VD
            SHR   V1
            SHR   V1
            SHR   V1
            SE    V0, V1
            JP    SPLITUP
            LD    I, GHOST
            DRW   VC, VD, 4
            LD    VC, HWRDX
            LD    VD, HWRDY
            DRW   VC, VD, 4
            LD    VE, ~( MASKCODE < 4) & MASKBYTE
            AND   V7, VE
            LD    VE, HWRDCODE < 4
            OR    V7, VE
            LD    VE, HWRDADD
            CALL  ADDSCORE
            JP    SPLITUP
GOTCHA:     LD    V0, CLSWAIT
            CALL  WAITKEY
            LD    VE, MASKLIFE
            XOR   V7, VE
            LD    V0, V7
            AND   V0, VE
            SE    V0, 0
            JP    RESTART
            LD    VE, V6
            CALL  ADDSCORE
            CALL  NEWHIGH
            CLS
            LD    V6, HIXPOS
            LD    V7, HIYPOS
            LD    I, HIGHSCORE
            CALL  PRINTDEC
            LD    V6, SCXPOS
            LD    V7, SCYPOS
            LD    I, SCORE
            CALL  PRINTDEC
            LD    V4, EYEX1
            LD    V5, EYEX1 + 8
            LD    V6, EYEY1
            LD    V7, PRESSKEY
EYEX1LOOP:  LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            LD    V0, EYEWAIT
            CALL  WAITKEY
            SE    VE, 0
            JP    EYEPRESS
            LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            ADD   V4, 2
            ADD   V5, 2
            SE    V4, EYEX2
            JP    EYEX1LOOP
EYEY1LOOP:  LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            LD    V0, EYEWAIT
            CALL  WAITKEY
            SE    VE, 0
            JP    EYEPRESS
            LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            ADD   V6, 2
            SE    V6, EYEY2
            JP    EYEY1LOOP
EYEX2LOOP:  LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            LD    V0, EYEWAIT
            CALL  WAITKEY
            SE    VE, 0
            JP    EYEPRESS
            LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            ADD   V4, -2 & MASKBYTE
            ADD   V5, -2 & MASKBYTE
            SE    V4, EYEX1
            JP    EYEX2LOOP
EYEY2LOOP:  LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            LD    V0, EYEWAIT
            CALL  WAITKEY
            SE    VE, 0
            JP    EYEPRESS
            LD    I, EYELEFT
            DRW   V4, V6, 9
            LD    I, EYERIGHT
            DRW   V5, V6, 9
            ADD   V6, -2 & MASKBYTE
            SE    V6, EYEY1
            JP    EYEY2LOOP
            JP    EYEX1LOOP
EYEPRESS:   LD    I, EYERIGHT
            DRW   V5, V6, 9
            LD    I, EYEBLINK
            DRW   V5, V6, 9
            JP    START

;  MOVEBLNK
;  ->:  Nothing
;  <-:  VE:  Collision flag
;  <>:  V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, VE, VF, I

MOVEBLNK:   LD    V3, V7
            LD    VE, MASKCODE
            AND   V3, VE
            LD    V4, V8
            LD    V5, V9
            LD    VE, DOWNKEY
            SKNP  VE
            JP    BLNKDOWN
            LD    VE, UPKEY
            SKNP  VE
            JP    BLNKUP
            LD    VE, RIGHTKEY
            SKNP  VE
            JP    BLNKRIGHT
            LD    VE, LEFTKEY
            SKNP  VE
            JP    BLNKLEFT
NOKEY:      SNE   V3, DOWNCODE
            ADD   V5, 2
            SNE   V3, UPCODE
            ADD   V5, -2 & MASKBYTE
            SNE   V3, RIGHTCODE
            ADD   V4, 2
            SNE   V3, LEFTCODE
            ADD   V4, -2 & MASKBYTE
            LD    V0, V4
            LD    V1, V5
            CALL  SPRITMAZE
            LD    V2, V0
            LD    VE, GRAPHEDGE
            AND   V0, VE
DONEKEY:    SE    V0, 0
            JP    STOPBLNK
            LD    VE, GRAPHSPEC
            LD    V0, V2
            AND   V2, VE
            SNE   V2, PL
            JP    EATPILL
            SNE   V2, SP
            JP    EATSUPER
            SNE   V2, GW
            JP    GATEWAY
DONEEAT:    CALL  DRAWBLNK
            LD    VE, ~MASKCODE & MASKBYTE
            AND   V7, VE
            OR    V7, V3
            LD    V8, V4
            LD    V9, V5
            JP    DRAWBLNK
BLNKDOWN:   LD    V0, V4
            LD    V1, V5
            ADD   V1, 2
            CALL  SPRITMAZE
            LD    V2, V0
            LD    VE, GRAPHEDGE
            AND   V0, VE
            SE    V0, 0
            JP    NOKEY
            LD    V3, DOWNCODE
            ADD   V5, 2
            JP    DONEKEY
BLNKUP:     LD    V0, V4
            LD    V1, V5
            ADD   V1, -2 & MASKBYTE
            CALL  SPRITMAZE
            LD    V2, V0
            LD    VE, GRAPHEDGE
            AND   V0, VE
            SE    V0, 0
            JP    NOKEY
            LD    V3, UPCODE
            ADD   V5, -2 & MASKBYTE
            JP    DONEKEY
BLNKRIGHT:  LD    V0, V4
            LD    V1, V5
            ADD   V0, 2
            CALL  SPRITMAZE
            LD    V2, V0
            LD    VE, GRAPHEDGE
            AND   V0, VE
            SE    V0, 0
            JP    NOKEY
            LD    V3, RIGHTCODE
            ADD   V4, 2
            JP    DONEKEY
BLNKLEFT:   LD    V0, V4
            LD    V1, V5
            ADD   V0, -2 & MASKBYTE
            CALL  SPRITMAZE
            LD    V2, V0
            LD    VE, GRAPHEDGE
            AND   V0, VE
            SE    V0, 0
            JP    NOKEY
            LD    V3, LEFTCODE
            ADD   V4, -2 & MASKBYTE
            JP    DONEKEY
STOPBLNK:   CALL  DRAWBLNK
            DRW   V8, V9, 4
            LD    VE, VF
            RET
EATPILL:    LD    VE, ~MASKNIBB & MASKBYTE
            AND   V0, VE
            OR    V0, V3
            LD    [I], V0
            LD    I, PILL
            DRW   V4, V5, 4
            ADD   V6, PILLADD
            LD    V1, PILLTIME
            LD    V0, DT
            SNE   V0, 0
            LD    ST, V1
            JP    DONEEAT
EATSUPER:   LD    VE, ~MASKNIBB & MASKBYTE
            AND   V0, VE
            OR    V0, V3
            LD    [I], V0
            LD    I, SUPER
            DRW   V4, V5, 4
            ADD   V6, SUPERADD
            LD    V0, VA
            LD    V1, VB
            CALL  SPRITMAZE
            LD    VE, ~MASKNIBB & MASKBYTE
            AND   V0, VE
            SE    V0, 0
            JP    SKIPPKLT
            LD    VE, MASKCODE < 2
            XOR   V7, VE
SKIPPKLT:   LD    V0, VC
            LD    V1, VD
            CALL  SPRITMAZE
            LD    VE, ~MASKNIBB & MASKBYTE
            AND   V0, VE
            SE    V0, 0
            JP    SKIPHWRD
            LD    VE, MASKCODE < 4
            XOR   V7, VE
SKIPHWRD:   LD    V0, SUPERTIME
            LD    ST, V0
            LD    DT, V0
            JP    DONEEAT
GATEWAY:    SNE   V3, LEFTCODE
            LD    V4, GATERIGHT
            SNE   V3, RIGHTCODE
            LD    V4, GATELEFT
            JP    DONEEAT

;  MOVEPKLT
;  ->:  Nothing
;  <-:  Nothing
;  <>:  V0, V1, V2, V7, VA, VB, VE, VF, I

MOVEPKLT:   LD    V2, V7
            LD    VE, MASKCODE < 2
            AND   V2, VE
            LD    V0, VA
            LD    V1, VB
            CALL  SPRITMAZE
            LD    I, GHOST
            LD    VE, ~MASKNIBB & MASKBYTE
            AND   V0, VE
            SE    V0, 0
            JP    RANDPKLT
TURNPKLT:   DRW   VA, VB, 4
            SNE   V2, DOWNCODE < 2
            ADD   VB, 2
            SNE   V2, UPCODE < 2
            ADD   VB, -2 & MASKBYTE
            SNE   V2, RIGHTCODE < 2
            ADD   VA, 2
            SNE   V2, LEFTCODE < 2
            ADD   VA, -2 & MASKBYTE
            DRW   VA, VB, 4
            RET
RANDPKLT:   RND   V1, ~MASKNIBB & MASKBYTE
            AND   V0, V1
            SE    V0, 0
            JP    SETPKLT
PKLTERR:    LD    VE, MASKCODE < 2
            XOR   V7, VE
            XOR   V2, VE
            JP    TURNPKLT
SETPKLT:    DRW   VA, VB, 4
PKLTL:      SHL   V0
            SNE   VF, 0
            JP    PKLTD
            LD    V2, LEFTCODE < 2
            ADD   VA, -2 & MASKBYTE
            JP    PKLTSET
PKLTD:      SHL   V0
            SNE   VF, 0
            JP    PKLTR
            LD    V2, DOWNCODE < 2
            ADD   VB, 2
            JP    PKLTSET
PKLTR:      SHL   V0
            SNE   VF, 0
            JP    PKLTU
            LD    V2, RIGHTCODE < 2
            ADD   VA, 2
            JP    PKLTSET
PKLTU:      SHL   V0
            SNE   VF, 0
            JP    PKLTERR
            LD    V2, UPCODE < 2
            ADD   VB, -2 & MASKBYTE
PKLTSET:    DRW   VA, VB, 4
            LD    VE, ~( MASKCODE < 2) & MASKBYTE
            AND   V7, VE
            OR    V7, V2
            RET

;  MOVEHWRD
;  ->:  Nothing
;  <-:  Nothing
;  <>:  V0, V1, V2, V3, V7, VC, VD, VE, VF, I

MOVEHWRD:   LD    V2, V7
            LD    V3, V7
            LD    VE, MASKCODE < 4
            AND   V2, VE
            LD    V0, VC
            LD    V1, VD
            CALL  SPRITMAZE
            LD    I, GHOST
            LD    VE, ~MASKNIBB & MASKBYTE
            AND   V0, VE
            SE    V0, 0
            JP    LOOKHWRD
TURNHWRD:   DRW   VC, VD, 4
            SNE   V2, DOWNCODE < 4
            ADD   VD, 2
            SNE   V2, UPCODE < 4
            ADD   VD, -2 & MASKBYTE
            SNE   V2, RIGHTCODE < 4
            ADD   VC, 2
            SNE   V2, LEFTCODE < 4
            ADD   VC, -2 & MASKBYTE
            DRW   VC, VD, 4
            RET
LOOKHWRD:   LD    VE, MASKHUNT
            LD    V1, DT
            SE    V1, 0
            JP    RANDHWRD
            LD    V1, V0
            SHL   V3
            SNE   VF, 0
            JP    HORISHWRD
VERTHWRD:   LD    V3, V9
            SUB   V3, VD
            SNE   VF, 0
            JP    HWRDLU
            SE    V3, 0
            JP    HWRDLD
            XOR   V7, VE
            LD    V3, V8
            SUB   V3, VC
            SNE   VF, 0
            JP    HWRDLL
            SE    V3, 0
            JP    HWRDLR
            XOR   V7, VE
            JP    RANDHWRD
HORISHWRD:  LD    V3, V8
            SUB   V3, VC
            SNE   VF, 0
            JP    HWRDLL
            SE    V3, 0
            JP    HWRDLR
            XOR   V7, VE
            LD    V3, V9
            SUB   V3, VD
            SNE   VF, 0
            JP    HWRDLU
            SE    V3, 0
            JP    HWRDLD
            XOR   V7, VE
            JP    RANDHWRD
HWRDLD:     LD    V3, MD
            AND   V1, V3
            SNE   V1, 0
            JP    RANDHWRD
            DRW   VC, VD, 4
            ADD   VD, 2
            DRW   VC, VD, 4
            XOR   V7, VE
            LD    VE, ~( MASKCODE < 4) & MASKBYTE
            AND   V7, VE
            LD    V2, DOWNCODE < 4
            OR    V7, V2
            RET
HWRDLU:     LD    V3, MU
            AND   V1, V3
            SNE   V1, 0
            JP    RANDHWRD
            DRW   VC, VD, 4
            ADD   VD, -2 & MASKBYTE
            DRW   VC, VD, 4
            XOR   V7, VE
            LD    VE, ~( MASKCODE < 4) & MASKBYTE
            AND   V7, VE
            LD    V2, UPCODE < 4
            OR    V7, V2
            RET
HWRDLR:     LD    V3, MR
            AND   V1, V3
            SNE   V1, 0
            JP    RANDHWRD
            DRW   VC, VD, 4
            ADD   VC, 2
            DRW   VC, VD, 4
            XOR   V7, VE
            LD    VE, ~( MASKCODE < 4) & MASKBYTE
            AND   V7, VE
            LD    V2, RIGHTCODE < 4
            OR    V7, V2
            RET
HWRDLL:     LD    V3, ML
            AND   V1, V3
            SNE   V1, 0
            JP    RANDHWRD
            DRW   VC, VD, 4
            ADD   VC, -2 & MASKBYTE
            DRW   VC, VD, 4
            XOR   V7, VE
            LD    VE, ~( MASKCODE < 4) & MASKBYTE
            AND   V7, VE
            LD    V2, LEFTCODE < 4
            OR    V7, V2
            RET
RANDHWRD:   RND   V1, ~MASKNIBB & MASKBYTE
            AND   V0, V1
            SE    V0, 0
            JP    SETHWRD
HWRDERR:    XOR   V7, VE
            LD    VE, MASKCODE < 4
            XOR   V7, VE
            XOR   V2, VE
            JP    TURNHWRD
SETHWRD:    DRW   VC, VD, 4
HWRDRL:     SHL   V0
            SNE   VF, 0
            JP    HWRDRD
            LD    V2, LEFTCODE < 4 | MASKHUNT
            ADD   VC, -2 & MASKBYTE
            JP    HWRDSET
HWRDRD:     SHL   V0
            SNE   VF, 0
            JP    HWRDRR
            LD    V2, DOWNCODE < 4
            ADD   VD, 2
            JP    HWRDSET
HWRDRR:     SHL   V0
            SNE   VF, 0
            JP    HWRDRU
            LD    V2, RIGHTCODE < 4 | MASKHUNT
            ADD   VC, 2
            JP    HWRDSET
HWRDRU:     SHL   V0
            SNE   VF, 0
            JP    HWRDERR
            LD    V2, UPCODE < 4
            ADD   VD, -2 & MASKBYTE
HWRDSET:    DRW   VC, VD, 4
            LD    VE, ~( MASKCODE < 4 | MASKHUNT) & MASKBYTE
            AND   V7, VE
            OR    V7, V2
            RET

;  DRAWBLNK
;  ->  V7:  Sprite direction register
;  ->  V8:  Blinky X screen coordinate
;  ->  V9:  Blinky Y screen coordinate
;  <-  VE:  Collision flag
;  <-  I:  Blinky sprite pointer
;  <>  V0, VE, VF, I

DRAWBLNK:   LD    V0, V7
            LD    VE, 3
            AND   V0, VE
            SHL   V0
            SHL   V0
            LD    I, SPRITES
            ADD   I, V0
            DRW   V8, V9, 4
            LD    VE, VF
            RET

;  COPYMAZE
;  ->  Nothing
;  <-  Nothing
;  <>  V0, V1, V2, V3, VE, VF, I

COPYMAZE:   LD    VE, 0
COPYLOOP:   LD    I, MAZE
            ADD   I, VE
            ADD   I, VE
            ADD   I, VE
            ADD   I, VE
            LD    V3, [I]
            LD    I, BUFFER
            ADD   I, VE
            ADD   I, VE
            ADD   I, VE
            ADD   I, VE
            LD    [I], V3
            ADD   VE, 1
            SE    VE, MAZEEND - MAZE \ 4
            JP    COPYLOOP
            RET

;  DRAWMAZE
;  ->  Nothing
;  <-  Nothing
;  <>  V0, V1, V2, V3, VE, VF, I

DRAWMAZE:   XOR   V2, V2
            XOR   V3, V3
            LD    VE, 15
DRAWLOOP:   LD    V0, V2
            LD    V1, V3
            CALL  GRAPHMAZE
            AND   V0, VE
            SHL   V0
            LD    I, GRAPHS
            ADD   I, V0
            DRW   V2, V3, 2
            ADD   V2, 2
            SE    V2, 64
            JP    DRAWLOOP
            XOR   V2, V2
            ADD   V3, 2
            SNE   V3, 32
            RET
            JP    DRAWLOOP

;  SPRITMAZE,  GRAPHMAZE
;  ->  V0:  X coordinate
;  ->  V1:  Y coordinate
;  <-  V0:  Maze data byte
;  <-  I:  Maze data pointer
;  <>  V0, V1, VF, I

SPRITMAZE:  ADD   V0, 2
            ADD   V1, 2
GRAPHMAZE:  SHR   V0
            SHR   V1
            SHL   V1
            SHL   V1
            SHL   V1
            SHL   V1
            LD    I, BUFFER
            ADD   I, V1
            ADD   I, V1
            ADD   I, V0
            LD    V0, [I]
            RET

;  PRINTDEC
;  ->  V6:  Print X coordinate
;  ->  V7:  Print Y coordinate
;  ->  I:  16 bit value pointer
;  <-  Nothing
;  <>  V0, V1, V2, V3, V4, V5, V6, V7, VE, VF, I

PRINTDEC:   LD    V1, [I]
            LD    VE, 1
            XOR   V4, V4
            LD    V2, V0
            LD    V3, V1
LOOPTENG:   LD    V5, 10000 % 256
            SUB   V3, V5
            SNE   VF, 0
            SUB   V2, VE
            SNE   VF, 0
            JP    SKIPTENG
            LD    V5, 10000 \ 256
            SUB   V2, V5
            SNE   VF, 0
            JP    SKIPTENG
            LD    V0, V2
            LD    V1, V3
            ADD   V4, VE
            JP    LOOPTENG
SKIPTENG:   LD    F, V4
            DRW   V6, V7, 5
            ADD   V6, 6
            XOR   V4, V4
            LD    V2, V0
            LD    V3, V1
LOOPTHOUS:  LD    V5, 1000 % 256
            SUB   V3, V5
            SNE   VF, 0
            SUB   V2, VE
            SNE   VF, 0
            JP    SKIPTHOUS
            LD    V5, 1000 \ 256
            SUB   V2, V5
            SNE   VF, 0
            JP    SKIPTHOUS
            LD    V0, V2
            LD    V1, V3
            ADD   V4, VE
            JP    LOOPTHOUS
SKIPTHOUS:  LD    F, V4
            DRW   V6, V7, 5
            ADD   V6, 6
            XOR   V4, V4
            LD    V2, V0
            LD    V3, V1
LOOPHUNDR:  LD    V5, 100
            SUB   V3, V5
            SNE   VF, 0
            SUB   V2, VE
            SNE   VF, 0
            JP    SKIPHUNDR
            LD    V0, V2
            LD    V1, V3
            ADD   V4, VE
            JP    LOOPHUNDR
SKIPHUNDR:  LD    F, V4
            DRW   V6, V7, 5
            ADD   V6, 6
            XOR   V4, V4
            LD    V2, V0
            LD    V3, V1
LOOPTEN:    LD    V5, 10
            SUB   V3, V5
            SNE   VF, 0
            JP    SKIPTEN
            LD    V1, V3
            ADD   V4, VE
            JP    LOOPTEN
SKIPTEN:    LD    F, V4
            DRW   V6, V7, 5
            ADD   V6, 6
            LD    F, V1
            DRW   V6, V7, 5
            RET

;  ADDSCORE
;  ->  VE:  Score count to add
;  <-  Nothing
;  <>  V0, V1, VE, VF, I

ADDSCORE:   LD    I, SCORE
            LD    V1, [I]
            ADD   V1, VE
            SE    VF, 0
            ADD   V0, 1
            LD    I, SCORE
            LD    [I], V1
            RET

;  NEWHIGH
;  ->  Nothing
;  <-  Nothing
;  <>  V0, V1, V2, V3, VE, VF, I

NEWHIGH:    LD    I, SCORE
            LD    V3, [I]
            LD    VE, V0
            SUB   VE, V2
            SNE   VF, 0
            RET
            SE    VE, 0
            JP    STOREHIGH
            LD    VE, V1
            SUB   VE, V3
            SNE   VF, 0
            RET
STOREHIGH:  LD    I, HIGHSCORE
            LD    [I], V1
            RET

;  WAITKEY
;  ->  V0:  Waitcount
;  <-  VE:  Keypressed
;  <>  V0, V1, V2, V3, VE, VF

WAITKEY:    XOR   VE, VE
            LD    V2, PRESSKEY
            LD    V3, -1 & MASKBYTE
            LD    V1, 16
LOOPKEY:    SKNP  V2
            JP    HITKEY
            ADD   V1, V3
            SE    V1, 0
            JP    LOOPKEY
            LD    V1, 16
            ADD   V0, V3
            SE    V0, 0
            JP    LOOPKEY
            RET
HITKEY:     LD    VE, 1
            RET

SCORE       DW    0
HIGHSCORE:  DW    0

SPRITES     =     ?

UP:         DB    $00000000, $01010000, $01110000, $00100000

LEFT:       DB    $00000000, $01100000, $00110000, $01100000

RIGHT:      DB    $00000000, $00110000, $01100000, $00110000

DOWN:       DB    $00000000, $00100000, $01110000, $01010000

GHOST:      DB    $00000000, $00100000, $01110000, $01110000

PILL:       DB    $00000000, $00000000, $00100000, $00000000

SUPER:      DB    $00000000, $00000000, $00000000, $00000000

GRAPHS      =     ?

;  $0000  Trail up
;  $0001  Trail left
;  $0010  Trail right
;  $0011  Trail down
;  $0100  Empty space
;  $0101  Ordinary pill
;  $0110  Super pill
;  $0111  Gateway
;  $1000  Horisontal egde
;  $1001  Invisible horisontal edge
;  $1010  Vertical edge
;  $1011  Invisible vertical edge
;  $1100  Upper left corner
;  $1101  Upper right corner
;  $1110  Lower left corner
;  $1111  Lower right corner

GRAPHEDGE   =     $1000
GRAPHSPEC   =     $0111
ES          =     $0100
PL          =     $0101
SP          =     $0110
GW          =     $0111
LR          =     $1000
ILR         =     $1001
UD          =     $1010
IUD         =     $1011
UL          =     $1100
UR          =     $1101
DL          =     $1110
DR          =     $1111
MU          =     $00010000
MR          =     $00100000
MUR         =     $00110000
MD          =     $01000000
MDU         =     $01010000
MDR         =     $01100000
MDUR        =     $01110000
ML          =     $10000000
MUL         =     $10010000
MRL         =     $10100000
MURL        =     $10110000
MDL         =     $11000000
MDUL        =     $11010000
MDRL        =     $11100000
MDURL       =     $11110000

            DB    $00000000, $00000000

            DB    $00000000, $00000000

            DB    $00000000, $00000000

            DB    $00000000, $00000000

EMPTY:      DB    $00000000, $00000000

PILLGR:     DB    $10000000, $00000000

SUPERGR:    DB    $00000000, $00000000

GATEGR:     DB    $00000000, $00000000

HORIS:      DB    $11000000, $00000000

INVHORIS:   DB    $00000000, $00000000

VERT:       DB    $10000000, $10000000

INVVERT:    DB    $00000000, $00000000

UPLEFT:     DB    $11000000, $10000000

UPRIGHT:    DB    $10000000, $10000000

DOWNLEFT:   DB    $11000000, $00000000

DOWNRIGHT:  DB    $10000000, $00000000

MAZE        =     ?

;  ##################################################################
;  #------------------------------- ------------------------------- #
;  #|                             | |                         O   | #
;  #| ? . . . . ? . . ? . . . . ? | | ? . . . . ? . . ? . . .OOO? | #
;  #|                             | |                        OOO  | #
;  #| . ------- . --- . ------- . --- . ------- . --- . ------- . | #
;  #|   |         | |         |         |         | |         |   | #
;  #| . | ? x . ? | | ? . . ? | ? . . ? | ? . . ? | | ? . x ? | . | #
;  #|   |         | |         |         |         | |         |   | #
;  #| . | . --------------- . ----------- . --------------- . | . | #
;  #|                 |                         |                 | #
;  #| ? . ? . . . . ? | ? . ? . ? . . ? . ? . ? | ? . . . . ? . ? | #
;  #|                 |                         |                 | #
;  #| . ----------- . | . ----- . --- . ----- . | . ----------- . | #
;  #|   |         |       |     O           |       |         |   | #
;  #| . | ? . . ? | ? ? ? | ? .O?O. . ? . ? | ? ? ? | ? . . ? | . | #
;  #              |       |    O O          |       |               #
;  #+ ? . ? --- . --- . --- . ----------- . --- . --- . --- ? . ? + #
;  #                          |         |                           #
;  #| . | ? . . ? . . ? . . ? ----- ----- ? . . ? . . ? . . ? | . | #
;  #|   |                         | |                         |   | #
;  #| . ------- . --------- ? . ? | | ? . ? --------- . ------- . | #
;  #|         |   |       |       | |       |       |   |         | #
;  #| ? . . ? | . ------------- . --- . ------------- . | ? . . ? | #
;  #|         |                                         |         | #
;  #| . --- x | ? . . . . ? . . ? . . ? . . ? . . . . ? | x --- . | #
;  #|   | |   |                                         |   | |   | #
;  #| . --- . ----------- . --- . --- . --- . ----------- . --- . | #
;  #|   O                   | |         | |                       | #
;  #| ?OOO. ? . . . . . . ? | | ? . . ? | | ? . . . . . . ? . . ? | #
;  #|  OOO                  | |         | |                       | #
;  #------------------------- ----------- ------------------------- #
;  #                                                                #
;  ##################################################################

            DB    UL, LR, LR, LR, LR, LR, LR, LR
            DB    LR, LR, LR, LR, LR, LR, LR, UR
            DB    UL, LR, LR, LR, LR, LR, LR, LR
            DB    LR, LR, LR, LR, LR, LR, LR, UR

            DB    UD, MDR | PL, PL, PL, PL, PL, MDRL | PL, PL
            DB    PL, MDRL | PL, PL, PL, PL, PL, MDL | PL, UD
            DB    UD, MDR | PL, PL, PL, PL, PL, MDRL | PL, PL
            DB    PL, MDRL | PL, PL, PL, PL, PL, MDL | PL, UD

            DB    UD, PL, UL, LR, LR, DR, PL, UL
            DB    UR, PL, LR, LR, LR, UR, PL, DL
            DB    DR, PL, UL, LR, LR, DR, PL, UL
            DB    UR, PL, LR, LR, LR, UR, PL, UD

            DB    UD, PL, UD, MDR | PL, SP, PL, MUL | PL, UD
            DB    UD, MUR | PL, PL, PL, MDL | PL, UD, MUR | PL, PL
            DB    PL, MUL | PL, UD, MDR | PL, PL, PL, MUL | PL, UD
            DB    UD, MUR | PL, PL, SP, MDL | PL, UD, PL, UD

            DB    UD, PL, DR, PL, LR, LR, LR, LR
            DB    LR, UL, LR, DR, PL, LR, LR, LR
            DB    LR, LR, DR, PL, LR, LR, UL, LR
            DB    LR, LR, LR, DR, PL, DR, PL, UD

            DB    UD, MDUR | PL, PL, MURL | PL, PL, PL, PL, PL
            DB    MDL | PL, UD, MDR | PL, PL, MURL | PL, PL, MDRL | PL, PL
            DB    PL, MDRL | PL, PL, MURL | PL, PL, MDL | PL, UD, MDR | PL
            DB    PL, PL, PL, PL, MURL | PL, PL, MDUL | PL, UD

            DB    UD, PL, UL, LR, LR, LR, LR, UR
            DB    PL, DR, PL, UL, LR, DR, PL, LR
            DB    DR, PL, LR, LR, UR, PL, DR, PL
            DB    UL, LR, LR, LR, LR, UR, PL, UD

            DB    DR, PL, DR, MDR | PL, PL, PL, MDL | PL, UD
            DB    MUR | PL, MDRL | PL, MUL | PL, UD, MDR | PL, PL, MURL, PL
            DB    PL, MURL | PL, PL, MDL | PL,
            DB    UD, MUR | PL, MDRL | PL, MUL | PL
            DB    UD, MDR | PL, PL, PL, MDL | PL, DR, PL, DR

            DB    GW, MDUR | ES, PL, MDUL | PL, LR, DR, PL, DL
            DB    DR, PL, LR, DR, PL, UL, LR, LR
            DB    LR, LR, UR, PL, LR, DR, PL, LR
            DB    DR, PL, LR, DR, MDUR | PL, PL, MDUL | ES, GW

            DB    UD, PL, UD, MUR | PL, PL, PL, MDURL | PL, PL
            DB    PL, MURL | PL, PL, PL, MDUL | PL, LR, LR, UR
            DB    UL, LR, DR, MDUR | PL, PL, PL, MURL | PL, PL
            DB    PL, MDURL | PL, PL, PL, MUL | PL, UD, PL, UD

            DB    UD, PL, LR, LR, LR, UR, PL, UL
            DB    LR, LR, LR, UR, MUR | PL, PL, MDL | PL, UD
            DB    UD, MDR | PL, PL, MUL | PL, UL, LR, LR, LR
            DB    UR, PL, UL, LR, LR, DR, PL, UD

            DB    UD, MDUR | PL, PL, PL, MDL | PL, UD, PL, LR
            DB    LR, LR, LR, LR, LR, DR, PL, LR
            DB    DR, PL, LR, LR, LR, LR, LR, LR
            DB    DR, PL, UD, MDR | PL, PL, PL, MDUL | PL, UD

            DB    UD, PL, UL, UR, SP, UD, MUR | PL, PL
            DB    PL, PL, PL, MDRL | PL, PL, PL, MDURL | PL, PL
            DB    PL, MDURL | PL, PL, PL, MDRL | PL, PL, PL, PL
            DB    PL, MUL | PL, UD, SP, UL, UR, PL, UD

            DB    UD, PL, LR, DR, PL, LR, LR, LR
            DB    LR, LR, DR, PL, UL, UR, PL, LR
            DB    DR, PL, UL, UR, PL, LR, LR, LR
            DB    LR, LR, DR, PL, LR, DR, PL, UD

            DB    UD, MUR | PL, PL, PL, MURL | PL, PL, PL, PL
            DB    PL, PL, PL, MUL | PL, UD, UD, MUR | PL, PL
            DB    PL, MUL | PL, UD, UD, MUR | PL, PL, PL, PL
            DB    PL, PL, PL, MURL | PL, PL, PL, MUL | PL, UD

            DB    LR, LR, LR, LR, LR, LR, LR, LR
            DB    LR, LR, LR, LR, DR, LR, LR, LR
            DB    LR, LR, DR, LR, LR, LR, LR, LR
            DB    LR, LR, LR, LR, LR, LR, LR, DR

MAZEEND     =     ?

EYES        =     ?

EYELEFT:    DB    $00111100, $01000010
            DB    $10011001, $10011001
            DB    $01000010, $00111100
            DB    $00000001, $00010000
            DB    $00001111

EYERIGHT:   DB    $01111000, $10000100
            DB    $00110010, $00110010
            DB    $10000100, $01111000
            DB    $00000000, $00010000
            DB    $11100000

EYEBLINK:   DB    $01111000, $11111100
            DB    $11111110, $11111110
            DB    $10000100, $01111000
            DB    $00000000, $00010000
            DB    $11100000

BUFFER      =     ?
