archanox/RGBDS2CIL

View on GitHub
Assembly/mrdo.asm

Summary

Maintainability
Test Coverage
****************************************************************************
*                                       *
*        MR DO! (C) 1990 SPECIAL FX SOFTWARE LIMITED           *
*                                       *
*                   BY WESLEY KNACKERS                   *
*                                       *
*                START DATE 28/06/90                   *
*                 LAST DATE 05/09/90                   *
*                                       *
****************************************************************************

MRDOSPEED    EQU    128+64+32
EATSPEED    EQU    128+32
BALLSPEED    EQU    2
BRDLEN        EQU    9        ;SCORE BOARD LENGTH

STACK        EQU    $CFFF
OBJSET        EQU    $8000        ;$1000
BGSET        EQU    OBJSET+$1000    ;$800
DISPSCREEN    EQU    $9800        ;$400
STATSCREEN    EQU    $9C00        ;$400
BACKSCREEN    EQU    $C800        ;$400
BYTESCREEN    EQU    $CC00        ;$100
WORKRAM        EQU    $C000
OAMRAM        EQU    $FE00
INTRAM        EQU    $FF80
BLITS        EQU    INTRAM
OBJDATA        EQU    OAMRAM

PORT        EQU    $FF00
SB        EQU    $FF01
SC        EQU    $FF02
DIV        EQU    $FF04
TIMA        EQU    $FF05
TMA        EQU    $FF06
TAC        EQU    $FF07
LCDC        EQU    $FF40
STAT        EQU    $FF41
SCY        EQU    $FF42
SCX        EQU    $FF43
LY        EQU    $FF44
LYC        EQU    $FF45
DMA        EQU    $FF46
BGP        EQU    $FF47
OBP0        EQU    $FF48
OBP1        EQU    $FF49
WY        EQU    $FF4A
WX        EQU    $FF4B
IF        EQU    $FF0F
IE        EQU    $FFFF

APLEN        EQU    5
APNUM        EQU    10        ;APPLE TOTAL
CDTOTAL        EQU    5+1*4        ;CHR DUMP TOTAL
CHRNUM        EQU    3        ;CHR SP TOTAL
DINONUM        EQU    4
GHSTNUM        EQU    3
BADNUM        EQU    DINONUM+GHSTNUM+1
SPNUM        EQU    BADNUM+CHRNUM    ;SPRITE TOTAL

TYP        EQU    0        ;SPRITE VARS
YNO        EQU    1
XNO        EQU    2
GNO        EQU    3
FLG        EQU    4
ADL        EQU    5
YSD        EQU    6
XSD        EQU    7
EVAR        EQU    XSD+1

P0        EQU    %00000000    ;OBJ FLAGS
P1        EQU    %00010000
R        EQU    %00000000
L        EQU    %00100000
U        EQU    %01000000
D        EQU    %00000000
PRI        EQU    %10000000

;OBJ CHARACTER DATA...

EBG        EQU    $7C
PNTG        EQU    $F5    ;1
BALL1G        EQU    $F6    ;1
BALL2G        EQU    $F7    ;1
FIVEG        EQU    $F8    ;2
EXTRAG        EQU    $FA    ;5

BIGMRDO        EQU    00*4
BIGDINO        EQU    09*4
BIGEXTRA    EQU    18*4

LETTERHI    EQU    EXTRAG*$10+OBJSET

EXPHS0        EQU    EBG+00*$10+OBJSET+08
EXPHS1        EQU    EBG+04*$10+OBJSET+10
EXPHS2        EQU    EBG+08*$10+OBJSET+06

MRDO        EQU    $00    ;MRDO (4)
MONSTG        EQU    $18    ;APPLE MONSTER (4)
EATERG        EQU    $28    ;WALL EATER (4)
GHOSTG        EQU    $38    ;GHOST (3)
EBONSG        EQU    $3E    ;EXTRA MONSTER (3)

WL        EQU    $00    ;BG CHR GROUPS
CH        EQU    $10
ED        EQU    $14
CN        EQU    $1C
DT        EQU    $20
WT        EQU    $24    ;WHITE CHR!
FD        EQU    $25
AP0        EQU    $5C
AP1        EQU    AP0+4
AP2        EQU    AP1+4
AP3        EQU    AP2+4
AP4        EQU    AP3+4
AP5        EQU    AP4+4
AP6        EQU    AP5+4
WLE        EQU    ED-1

TMRDO        EQU    1    ;BADDIE TYPES
TOUTBALL    EQU    2
TINBALL        EQU    3
TCBALL        EQU    4
TTBALL        EQU    5
TDINO        EQU    6
TDINOE        EQU    7
TDINOP        EQU    8
TGHOST        EQU    9
TGHOSTE        EQU    10
TPOINTS        EQU    11
TEXDANCE    EQU    12
TEXUP        EQU    13
TEXWALK        EQU    14
TEXEXIT        EQU    15
TEXEAT        EQU    16

TAPPW        EQU    1    ;APPLE TYPES
TAPPJ        EQU    2
TAPPF        EQU    3
TAPPS        EQU    4

****************************************************************************
;RAM VARIABLES...

        ORG    WORKRAM+$1000
GAMEOBJ        DEFS    $A0,0    ;DUMMY OBJDATA

VARS
SPEEDFLAG    DEFB    0
TOGGLE        DEFB    0
MRDOANI        DEFB    0
ANIOFF3        DEFB    0
ANIOFF4        DEFB    0
BLOBSINE
NEWSCY        DEFB    0
BLOBY
NEWSCX        DEFB    0
BLOBX
SCYT        DEFB    0
BLOBXSD
SCXT        DEFB    0
SUBMENU        DEFB    0
LEVEL        DEFB    0
MENUY
MAP        DEFB    0
SCRLCOUNT
CATCHDEL    DEFB    0
LOGOSTATE
CHERRYDEL    DEFB    0
LOGTIME
CHERRYBON    DEFB    0
CONTOG
CHERRYTOT    DEFB    0
SPEED        DEFB    0
SPEEDO        DEFB    0
SPDCOW        DEFB    0
LETLOW        DEFW    0
LETCOW        DEFB    0
EXTRALETTER    DEFB    0
EXTRATOT    DEFB    0
FREEZE        DEFB    0
GHOSTOTAL    DEFB    0
FRAMES        DEFB    0
TALLOFF        DEFB    0
DUMPTOT        DEFB    0
APPLEAND    DEFB    0
KEYPRESS    DEFB    0
CONTROL        DEFB    0
MUD        DEFB    0
SPLAT        DEFB    0
GODELAY        DEFB    0
VEND
RND1        DEFB    $20
RND2        DEFB    $AA
RND3        DEFB    $55
REALSCORE    DEFB    "000000"    ;ACTUAL SCORE
SCORE        DEFB    "000000",0,0,0    ;LEVELS SCORE,TIME,ENDOBJ
        DEFB    "000000",0,0,0
        DEFB    "000000",0,0,0
TOTAL        DEFB    "000000",0,0    ;RUNNING TOTAL,TIME
TIMER        EQU    SCORE+6
TIMERTOTAL    EQU    TOTAL+6

;***************************************************************************

        ORG    WORKRAM+$1100

STATUSOBJ    DEFS    $A0,0
CHRDUMP        DEFS    3*CDTOTAL,0        ;ADLO,ADHI,CHR

;***************************************************************************

        ORG    WORKRAM+$1200

SPRITES ;        TYP,YNO,XNO,GNO
;            FLG,ADL,YSD,XSD

MRDOSP        DEFB    TMRDO,0,0,MRDO
        DEFB    0,00*16,0,0

DINOSP        DEFB    TDINO,$70,$58,MONSTG
        DEFB    0,01*16,0,0
        DEFB    TDINO,$70,$58,MONSTG
        DEFB    0,02*16,0,0
        DEFB    TDINO,$70,$58,MONSTG
        DEFB    2,03*16,0,0
        DEFB    TDINO,$70,$58,MONSTG
        DEFB    2,04*16,0,0

GHSTSP        DEFB    TGHOST,8*13,8*12+2,GHOSTG
        DEFB    1,05*16,0,0
        DEFB    TGHOST,8*13,8*14+4,GHOSTG
        DEFB    3,06*16,0,0
        DEFB    TGHOST,8*13,8*16+6,GHOSTG
        DEFB    3,07*16,0,0

EXBONSP        DEFB    TEXDANCE,8*13,8*10+0,EBONSG
        DEFB    1,08*16,0,0

MRBALLSP    DEFB    TCBALL,0,0,BALL1G
        DEFB    0,09*16,0,0
MRSBALLSP    DEFB    0,0,0,BALL2G
        DEFB    0,09*16+4,0,0
SCORSP        DEFB    0,0,0,0
        DEFB    0,09*16+8,0,0

APPLESP        DEFS    APLEN*APNUM,0    ;TYP,YNO,XNO,GNO,FLG

EXTRATAB    DEFB    4,8*09-4,EXTRAG+0,P1 ;Y,X,GNO,FLG
        DEFB    2,8*10-4,EXTRAG+1,P1
        DEFB    0,8*11-4,EXTRAG+2,P1
        DEFB    2,8*12-4,EXTRAG+3,P1
        DEFB    4,8*13-4,EXTRAG+4,P1

        DEFS    $5A,0        ;*** FREE RAM ***

;         SCORE(6)/NAME(3)/SCENE(1)/TIME(2)

HIGHTAB        DEFB    "001700JOF",7,0,7
        DEFB    "001600CHZ",6,0,6
        DEFB    "001500KEG",5,0,5
        DEFB    "001400ELM",4,0,4
        DEFB    "001300MYK",3,0,3
        DEFB    "001200IVN",2,0,2
        DEFB    "001100PAM",1,0,1
HIGHTABEND    DEFB    "001000GAZ",0,0,0
HIGHBUFF    DEFB    "FROBUSH HERE"

;***************************************************************************
;CARTRIDGE REGISTRATION DATA

        ORG    $100
        NOP                ;NULL BYTE    
        JP    START            ;GAME START ADDR
        HEX    CEED6666CC0D000B    ;NINTENDO CHRDATA
        HEX    03730083000C000C
        HEX    0008111F8889000E
        HEX    DCCC6EE6DDDDD999
        HEX    BBBB67636E0EECCC
        HEX    DDDC999FBBB9333E
        DEFB    "MRDO!           "    ;GAME TITLE
        DEFB    0,0,0            ;UNUSED
        DEFB    0            ;CARTRIDGE TYPE (ROM ONLY)
        DEFB    0            ;ROM SIZE    (256K)
        DEFB    0            ;RAM SIZE    (NONE)
        DEFW    0            ;MAKER CODE
        DEFB    0            ;VERSION NUMBER
        DEFB    0            ;COMPLEMENT CHECK
        DEFW    0            ;CHECK SUM

;***************************************************************************
;TABLES...
        ORG    $200

BADTAB        DEFW    NOBAD        ;00
        DEFW    NOBAD        ;01 PLAYER 1
        DEFW    OUTBALL        ;02
        DEFW    INBALL        ;03
        DEFW    CARRYBALL    ;04
        DEFW    THROWBALL    ;05
        DEFW    DINO        ;06
        DEFW    DINOEAT        ;07
        DEFW    DINOPUSH    ;08
        DEFW    GHOST        ;09
        DEFW    GHOSTEAT    ;10
        DEFW    POINTS        ;11
        DEFW    EXDANCE        ;12 EXTRA
        DEFW    EXUP        ;13
        DEFW    EXWALK        ;14
        DEFW    EXEXIT        ;15
        DEFW    EXEAT        ;16

HITBALLTAB    DEFW    DUFKILL        ;00
        DEFW    MRDOCATCH    ;01
        DEFW    DUFKILL        ;02
        DEFW    DUFKILL        ;03
        DEFW    DUFKILL        ;04
        DEFW    DUFKILL        ;05
        DEFW    DINODIE        ;06
        DEFW    DINODIE        ;07
        DEFW    DINODIE        ;08
        DEFW    GHOSTDIE    ;09
        DEFW    GHOSTDIE    ;10
        DEFW    DUFKILL        ;11
        DEFW    DUFKILL        ;12 EXTRA
        DEFW    DUFKILL        ;13
        DEFW    EXDIE        ;14
        DEFW    EXDIE        ;15
        DEFW    EXDIE        ;16

APPLETAB    DEFW    NOAPPLE        ;00
        DEFW    APPLEWAIT    ;01
        DEFW    APPLEJIG    ;02
        DEFW    APPLEFALL    ;03
        DEFW    APPLESPLIT    ;04

VECTAB        DEFB    +0,-1,+1,+0,+0,+1,-1,+0
VECTAB2        DEFB    +0,-2,+2,+0,+0,+2,-2,+0

VALIDLR        DEFB    +0,+2,+4,+0    ;+1 FOR KEY DECODE
VALIDUD        DEFB    +0,+1,+3,+0

BALLOFF        DEFB    +0,-8,+8,+0,+0,+8,-8,+0
BALLXY        DEFB    -1,+0,-1,-1,+1,-1,-1,+1
BALLVEC        DEFB    +BALLSPEED,-BALLSPEED,+BALLSPEED,+BALLSPEED
        DEFB    -BALLSPEED,+BALLSPEED,-BALLSPEED,-BALLSPEED

BALLCPS        DEFB    ED+4,ED+5,ED+6,ED+7,CN+1,DT+2    ;UP,RG
        DEFB    ED+0,ED+1,ED+6,ED+7,CN+3,DT+0    ;DW,RG
        DEFB    ED+0,ED+1,ED+2,ED+3,CN+2,DT+1    ;DW,LT
        DEFB    ED+4,ED+5,ED+2,ED+3,CN+0,DT+3    ;UP,LT

BALLBOU        DEFB    1,1,3,3,2,1+128
        DEFB    0,0,2,2,3,2+128
        DEFB    3,3,1,1,0,3+128
        DEFB    2,2,0,0,1,0+128

MRDOTAB        DEFB    $00,$06,$0C,$12    ;U/R/D/R

CHEWJP        DEFW    CHEWUP        ;00
        DEFW    CHEWRT        ;01
        DEFW    CHEWDW        ;02
        DEFW    CHEWLT        ;03

EATJP        DEFW    EATWALL        ;00
        DEFW    EATUNNEL    ;01
        DEFW    EATCHERRY    ;02
        DEFW    EATAPPLE    ;03
        DEFW    EATFOOD        ;04

BITAB        DEFB    %0001,%0010,%0100,%1000
VECTOBIT    DEFB    %1000,%0001,%0100,%0010
BITTOVEC    DEFB    0,1,3,0,2,0,0,0,0

****************************************************************************
;SPRITE CHARACTER TABLES...((CHR,FLG)*4)(TOPL,TOPR,BOTR,BOTL)

        ORG    $300

CHRTABLE    DEFB    $06,U,$07,U,$05,U,$04,U        ;00 MRDO U
        DEFB    $0E,U,$0F,U,$0D,U,$0C,U        ;01
        DEFB    $16,U,$17,U,$15,U,$14,U        ;02
        DEFB    $1E,U,$1F,U,$1D,U,$1C,U        ;03
        DEFB    $26,U,$27,U,$25,U,$24,U        ;04
        DEFB    $2E,U,$2F,U,$2D,U,$2C,U        ;05
        DEFB    $00,R,$01,R,$03,R,$02,R        ;06 MRDO R
        DEFB    $08,R,$09,R,$0B,R,$0A,R        ;07
        DEFB    $10,R,$11,R,$13,R,$12,R        ;08
        DEFB    $18,R,$19,R,$1B,R,$1A,R        ;09
        DEFB    $20,R,$21,R,$23,R,$22,R        ;0A
        DEFB    $28,R,$29,R,$2B,R,$2A,R        ;0B
        DEFB    $05,D+L,$04,D+L,$06,D+L,$07,D+L    ;0C MRDO D
        DEFB    $0D,D+L,$0C,D+L,$0E,D+L,$0F,D+L    ;0D
        DEFB    $15,D+L,$14,D+L,$16,D+L,$17,D+L    ;0E
        DEFB    $1D,D+L,$1C,D+L,$1E,D+L,$1F,D+L    ;0F
        DEFB    $25,D+L,$24,D+L,$26,D+L,$27,D+L    ;10
        DEFB    $2D,D+L,$2C,D+L,$2E,D+L,$2F,D+L    ;11
        DEFB    $01,L,$00,L,$02,L,$03,L        ;12 MRDO L
        DEFB    $09,L,$08,L,$0A,L,$0B,L        ;13
        DEFB    $11,L,$10,L,$12,L,$13,L        ;14
        DEFB    $19,L,$18,L,$1A,L,$1B,L        ;15
        DEFB    $21,L,$20,L,$22,L,$23,L        ;16
        DEFB    $29,L,$28,L,$2A,L,$2B,L        ;17

        DEFB    $42,U,$43,U,$41,U,$40,U        ;18 DINO U
        DEFB    $4A,U,$4B,U,$49,U,$48,U        ;19
        DEFB    $52,U,$53,U,$51,U,$50,U        ;1A
        DEFB    $5A,U,$5B,U,$59,U,$58,U        ;1B
        DEFB    $3C,R,$3D,R,$3F,R,$3E,R        ;1C DINO R
        DEFB    $44,R,$45,R,$47,R,$46,R        ;1D
        DEFB    $4C,R,$4D,R,$4F,R,$4E,R        ;1E
        DEFB    $54,R,$55,R,$57,R,$56,R        ;1F
        DEFB    $40,D,$41,D,$43,D,$42,D        ;20 DINO D
        DEFB    $48,D,$49,D,$4B,D,$4A,D        ;21
        DEFB    $50,D,$51,D,$53,D,$52,D        ;22
        DEFB    $58,D,$59,D,$5B,D,$5A,D        ;23
        DEFB    $3D,L,$3C,L,$3E,L,$3F,L        ;24 DINO L
        DEFB    $45,L,$44,L,$46,L,$47,L        ;25
        DEFB    $4D,L,$4C,L,$4E,L,$4F,L        ;26
        DEFB    $55,L,$54,L,$56,L,$57,L        ;27

        DEFB    $62,U,$63,U,$61,U,$60,U        ;28 DINOX U
        DEFB    $6A,U,$6B,U,$69,U,$68,U        ;29
        DEFB    $72,U,$73,U,$71,U,$70,U        ;2A
        DEFB    $7A,U,$7B,U,$79,U,$78,U        ;2B
        DEFB    $5C,R,$5D,R,$5F,R,$5E,R        ;2C DINOX R
        DEFB    $64,R,$65,R,$67,R,$66,R        ;2D
        DEFB    $6C,R,$6D,R,$6F,R,$6E,R        ;2E
        DEFB    $74,R,$75,R,$77,R,$76,R        ;2F
        DEFB    $60,D,$61,D,$63,D,$62,D        ;30 DINOX D
        DEFB    $68,D,$69,D,$6B,D,$6A,D        ;31
        DEFB    $70,D,$71,D,$73,D,$72,D        ;32
        DEFB    $78,D,$79,D,$7B,D,$7A,D        ;33
        DEFB    $5D,L,$5C,L,$5E,L,$5F,L        ;34 DINOX L
        DEFB    $65,L,$64,L,$66,L,$67,L        ;35
        DEFB    $6D,L,$6C,L,$6E,L,$6F,L        ;36
        DEFB    $75,L,$74,L,$76,L,$77,L        ;37

        DEFB    $30,R,$31,R,$33,R,$32,R        ;38 GHOST R
        DEFB    $34,R,$35,R,$37,R,$36,R        ;39
        DEFB    $38,R,$39,R,$3B,R,$3A,R        ;3A

        DEFB    $31,L,$30,L,$32,L,$33,L        ;3B GHOST L
        DEFB    $35,L,$34,L,$36,L,$37,L        ;3C
        DEFB    $39,L,$38,L,$3A,L,$3B,L        ;3D

        DEFB    $7C,R,$7E,R,$7F,R,$7D,R        ;3E EBONUSS LR    
        DEFB    $80,R,$82,R,$83,R,$81,R        ;3F
        DEFB    $84,R,$86,R,$87,R,$85,R        ;40

****************************************************************************

        ORG    $600

BLOCKS         DEFB    ED+2,ED+6,ED+3,ED+7    ;00 U  TUNNELS
        DEFB    ED+4,ED+5,ED+0,ED+1    ;01 R
         DEFB    ED+2,ED+6,ED+3,ED+7    ;02 D
        DEFB    ED+4,ED+5,ED+0,ED+1    ;03 L
CORNERS        DEFB    CN+0,CN+1,ED+3,ED+7    ;04 U  ENDS
        DEFB    ED+4,CN+1,ED+0,CN+3    ;05 R
        DEFB    ED+2,ED+6,CN+2,CN+3    ;06 D
        DEFB    CN+0,ED+5,CN+2,ED+1    ;07 L
        DEFB    CN+0,ED+5,ED+3,DT+0    ;08 TL CORNERS
        DEFB    ED+4,CN+1,DT+1,ED+7    ;09 TR
        DEFB    DT+3,ED+6,ED+0,CN+3    ;0A BR
        DEFB    ED+2,DT+2,CN+2,ED+1    ;0B BL
        DEFB    ED+4,ED+5,DT+1,DT+0    ;0C T  WALLS
        DEFB    DT+3,ED+6,DT+1,ED+7    ;0D R
        DEFB    DT+3,DT+2,ED+0,ED+1    ;0E B
        DEFB    ED+2,DT+2,ED+3,DT+0    ;0F L
CHERRY        DEFB    CH+0,CH+1,CH+2,CH+3    ;10
FOOD        DEFB    FD+0,FD+1,FD+2,FD+3    ;11
APPLE        DEFB    AP0,AP0+1,AP0+2,AP0+3    ;12
        DEFB    DT+3,DT+2,DT+1,DT+0    ;13 MIDDLE!

;EAT TABLES...

UTL        DEFB    CN+0,CN+0,CN+0,CN+0    ;WALLS/CHERRY
        DEFB    DT+1,DT+1,ED+2,ED+3    ;EDGES
        DEFB    ED+4,ED+5,ED+6,ED+7
        DEFB    CN+0,DT+3,ED+3,DT+1    ;CORNERS
        DEFB    WT,DT+1,WT,DT+3    ;DOTS
        DEFB    WT
UTR        DEFB    CN+1,CN+1,CN+1,CN+1    ;WALLS/CHERRY
        DEFB    DT+0,DT+0,ED+2,ED+3    ;EDGES
        DEFB    ED+4,ED+5,ED+6,ED+7
        DEFB    DT+2,CN+1,DT+0,ED+7    ;CORNERS
        DEFB    DT+0,WT,DT+2,WT    ;DOTS
        DEFB    WT
UBL        DEFB    ED+2,ED+3,ED+2,ED+3    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,ED+2,ED+3    ;EDGES
        DEFB    DT+3,DT+3,"0","1"
        DEFB    ED+2,ED+3,CN+2,CN+3    ;CORNERS
        DEFB    WT,DT+1,WT,DT+3    ;DOTS
        DEFB    WT
UBR        DEFB    ED+6,ED+7,ED+6,ED+7    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,"2","3"    ;EDGES
        DEFB    DT+2,DT+2,ED+6,ED+7
        DEFB    ED+6,ED+7,CN+2,CN+3    ;CORNERS
        DEFB    DT+0,WT,DT+2,WT    ;DOTS
        DEFB    WT

MULTIE        ADD    A,E    ;FOR CIRCLE
        ADD    A,E
        ADD    A,E
        ADD    A,E
        RET

MULTID        ADD    A,D
        ADD    A,D
        ADD    A,D
        ADD    A,D
        RET

HEXTAB        DEFB    "0123456789ABCDEF"

OBJSWAP        DEFB    8*16,9*16,9*16+4,9*16+8    
        DEFB    9*16,8*16,8*16+4,8*16+8    

LEVTAB        DEFW    SCENE1,SCENE2,SCENE3,SCENE4,SCENE5
        DEFW    SCENE6,SCENE7,SCENE8,SCENE9,SCENE10

STATNUM        DEFW    STATSCREEN+32+0,REALSCORE+0
        DEFW    STATSCREEN+32+1,REALSCORE+1
        DEFW    STATSCREEN+32+2,REALSCORE+2
        DEFW    STATSCREEN+32+3,REALSCORE+3
        DEFW    STATSCREEN+32+4,REALSCORE+4
        DEFW    STATSCREEN+32+5,REALSCORE+5
        DEFW    STATSCREEN+32+0,REALSCORE+0    ;SPARE
        DEFW    STATSCREEN+32+0,REALSCORE+0    ;

        ORG    $700

LTL        DEFB    CN+0,CN+0,CN+0,CN+0    ;WALLS/CHERRY
        DEFB    "4","5",ED+2,ED+3    ;EDGES
        DEFB    ED+4,ED+5,DT+2,DT+2 
        DEFB    CN+0,ED+5,DT+3,DT+2    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT
LTR        DEFB    ED+4,ED+5,ED+4,ED+5    ;WALLS/CHERRY
        DEFB    "6","7",DT+3,DT+3    ;EDGES
        DEFB    ED+4,ED+5,ED+6,ED+7
        DEFB    ED+4,CN+1,"A","B"    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT
LBL        DEFB    CN+2,CN+2,CN+2,CN+2    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,ED+2,ED+3    ;EDGES
        DEFB    "C","D",DT+0,DT+0
        DEFB    DT+1,DT+0,CN+2,ED+1    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT
LBR        DEFB    ED+0,ED+1,ED+0,ED+1    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,DT+1,DT+1    ;EDGES
        DEFB    "E","F",ED+6,ED+7
        DEFB    "G","H",ED+0,CN+3    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT

RTL        DEFB    ED+4,ED+5,ED+4,ED+5    ;WALLS/CHERRY
        DEFB    "I","J",ED+2,ED+3    ;EDGES
        DEFB    ED+4,ED+5,DT+2,DT+2
        DEFB    CN+0,ED+5,"K","L"    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT
RTR        DEFB    CN+1,CN+1,CN+1,CN+1    ;WALLS/CHERRY
        DEFB    "M","N",DT+3,DT+3    ;EDGES
        DEFB    ED+4,ED+5,ED+6,ED+7
        DEFB    ED+4,CN+1,DT+3,DT+2    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT
RBL        DEFB    ED+0,ED+1,ED+0,ED+1    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,ED+2,ED+3    ;EDGES
        DEFB    "O","P",DT+0,DT+0
        DEFB    "Q","R",CN+2,ED+1    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT
RBR        DEFB    CN+3,CN+3,CN+3,CN+3    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,DT+1,DT+1    ;EDGES
        DEFB    "S","T",ED+6,ED+7
        DEFB    DT+1,DT+0,ED+0,CN+3    ;CORNERS
        DEFB    DT+0,DT+1,DT+2,DT+3    ;DOTS
        DEFB    WT

CTAB        DEFB    $00,$00,$01,$01,$01,$02,$02,$03
        DEFB    $03,$03,$04,$04,$04,$05,$05,$05
        DEFB    $06,$06,$06,$07,$07,$07,$08,$08
        DEFB    $08,$09,$09,$09,$09,$0A,$0A,$0A
        DEFB    $0B,$0B,$0B,$0B,$0C,$0C,$0C,$0C
        DEFB    $0C,$0D,$0D,$0D,$0D,$0D,$0E,$0E
        DEFB    $0E,$0E,$0E,$0E,$0E,$0E,$0F,$0F
        DEFB    $0F,$0F,$0F,$0F,$0F,$0F,$0F,$0F

QUADX        DEFB    $00
QUADY        DEFB    $00,$FF,$FF
QUADTAB        DEFB    $00,$3F,$00,$3F

        ORG    $800

DTL        DEFB    ED+2,ED+3,ED+2,ED+3    ;WALLS/CHERRY
        DEFB    DT+1,DT+1,ED+2,ED+3    ;EDGES
        DEFB    ED+4,ED+5,ED+6,ED+7
        DEFB    CN+0,CN+0,ED+2,ED+3    ;CORNERS
        DEFB    WT,DT+1,WT,DT+3    ;DOTS
        DEFB    WT
DTR        DEFB    ED+6,ED+7,ED+6,ED+7    ;WALLS/CHERRY
        DEFB    DT+0,DT+0,ED+2,ED+3    ;EDGES
        DEFB    ED+4,ED+5,ED+6,ED+7
        DEFB    CN+1,CN+1,ED+6,ED+7    ;CORNERS
        DEFB    DT+0,WT,DT+2,WT    ;DOTS
        DEFB    WT
DBL        DEFB    CN+2,CN+2,CN+2,CN+2    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,ED+2,ED+3    ;EDGES
        DEFB    DT+3,DT+3,ED+6,ED+7
        DEFB    CN+2,DT+3,CN+2,DT+1    ;CORNERS
        DEFB    WT,DT+1,WT,DT+3    ;DOTS
        DEFB    WT
DBR        DEFB    CN+3,CN+3,CN+3,CN+3    ;WALLS/CHERRY
        DEFB    ED+0,ED+1,ED+2,ED+3    ;EDGES
        DEFB    DT+2,DT+2,ED+6,ED+7
        DEFB    DT+2,CN+3,DT+0,CN+3    ;CORNERS
        DEFB    DT+0,WT,DT+2,WT    ;DOTS
        DEFB    WT

LAFALL        DEFB    DT+1,DT+1,ED+2,ED+3    ;EDGES
        DEFB    DT+3,DT+3,WT,WT
        DEFB    ED+2,DT+3,ED+3,DT+1    ;CORNERS
        DEFB    WT,DT+1,WT,DT+3        ;DOTS
        DEFB    WT
        DEFB    FD+0,FD+1,FD+2,FD+3    ;FOOD

RAFALL        DEFB    DT+0,DT+0,WT,WT        ;EDGES
        DEFB    DT+2,DT+2,ED+6,ED+7
        DEFB    DT+2,ED+6,DT+0,ED+7    ;CORNERS
        DEFB    DT+0,WT,DT+2,WT        ;DOTS
        DEFB    WT
        DEFB    FD+0,FD+1,FD+2,FD+3    ;FOOD

SUBMENUTAB    DEFW    OPTIONS        ;00
        DEFW    UPMENU        ;01
        DEFW    SKILEVEL    ;02
        DEFW    UPMENU        ;03
        DEFW    SOUNDOPT    ;04
        DEFW    DWMENU        ;05

LOGOTAB        DEFW    LOGOON        ;00
        DEFW    RASTARS        ;01
        DEFW    STARFALL    ;02
        DEFW    BARREL        ;03

FACEADTAB    DEFW    $16*$20+STATSCREEN+$05
        DEFB    $00,$04
        DEFW    $16*$20+STATSCREEN+$09
        DEFB    $08,$0C
        DEFW    $16*$20+STATSCREEN+$0D
        DEFB    $10,$14

WAVETAB        DEFB    +02,+04,+06,+06,+07,+07,+08,+08
        DEFB    +08,+08,+07,+07,+06,+04,+02,+00
        DEFB    -02,-04,-06,-06,-07,-07,-08,-08
        DEFB    -08,-08,-07,-07,-06,-04,-02,-00

PULSETAB    DEFB    %00110100,%01110100
        DEFB    %10110100,%11110100
        DEFB    %11110100,%11110100
        DEFB    %10110100,%01110100

FADETAB        DEFB    %11100100,%11100100
        DEFB    %11100100,%11100100
        DEFB    %11100100,%11100100
        DEFB    %11100100,%11100100
        DEFB    %10100100,%10010100
        DEFB    %10010100,%10010100
        DEFB    %01010000,%01010000
        DEFB    %01010000,%01000000

WELLTAB        DEFW    EMOVE        ;0
        DEFW    ALLWAIT        ;1
        DEFW    ALLMOVE        ;2
        DEFW    ALLWAIT        ;3
        DEFW    DODIMOVE    ;4

SETBIGTAB    DEFB    BIGMRDO,8*15,8*$16+1    ;OBJ OFFSET,Y,X
        DEFB    BIGDINO,8*15,8*$1D
        DEFB    BIGEXTRA,8*15,8*$16

****************************************************************************

DMATRANS    DI
        LD    (DMA),A
        LD    A,40
DMAL        DEC    A
        JR    NZ,DMAL
        EI
        RET

SYSETUP        CALL    WAITBLANK
        DI
        XOR    A
        LD    (LCDC),A    ;LCD CONTROLLER OFF

        LD    HL,VARS
        LD    B,VEND-VARS
RESETV        LD    (HLI),A
        DEC    B
        JR    NZ,RESETV

        LD    (IF),A
        INC    A
        LD    (IE),A

        LD    HL,DMATRANS    ;SETUP DMA TRANS ROUTINE
        LD    DE,INTRAM
        LD    B,SYSETUP-DMATRANS
TOINTRAM    LD    A,(HLI)
        LD    (DE),A
        INC    E
        DEC    B
        JR    NZ,TOINTRAM
        CALL    CLEARDISP
        CALL    CLEARSTAT
        EI
        RET

;***************************************************************************

GAMESETUP    XOR    A
        LD    (MAP),A
        LD    (LEVEL),A
        LD    HL,REALSCORE    ;RESET SCORE
        LD    A,"0"
        LD    (HLI),A
        LD    (HLI),A
        LD    (HLI),A
        LD    (HLI),A
        LD    (HLI),A
        LD    (HL),A
        LD    B,4        ;AND LEVEL SCORES/TIMERS
        CALL    RESETBOARD
        LD    A,%11        ;APPLE Y SPEED
        LD    (APPLEAND),A
        JP    SETEXTRA

;***************************************************************************

LEVELSETUP    CALL    CLEARSTAT
        CALL    RESETOBJ    ;CLEAR REAL OBJ
        CALL    STATUS        ;DRAW STATUS LINE

;COPY CHRS/SPRITES TO OBJSET...

        CALL    CLEARSET
        LD    HL,CPNT        ;WILL CHANGE
        LD    DE,PNTG*$10+OBJSET
        LD    BC,$10
        CALL    SHUNT
        LD    HL,CMRDO
        LD    A,(CONTROL)
        OR    A
        JR    Z,ISMISTER
        LD    HL,CMRSDO
ISMISTER    LD    DE,OBJSET
        LD    BC,$300
        CALL    SHUNT
        LD    HL,GAMESETAB
        CALL    CREATESET

        XOR    A
        LD    (WY),A
        LD    (SPEEDO),A
        LD    (SPDCOW),A
        LD    (FREEZE),A
        LD    (FRAMES),A
        LD    (DUMPTOT),A
        LD    (KEYPRESS),A
        LD    (CHERRYTOT),A
        LD    (CHERRYDEL),A

        LD    B,BADNUM    ;RESET BADDIES
        LD    HL,DINOSP
        LD    DE,EVAR
RESETSP        LD    (HL),A
        ADD    HL,DE
        DEC    B
        JR    NZ,RESETSP
        LD    (HL),TCBALL    ;RESET MRDO BALL
        ADD    HL,DE
        LD    (HL),A        ;RESET MRSDO BALL
        ADD    HL,DE
        LD    (HL),A        ;RESET PNTS

        LD    B,APNUM        ;RESET APPLES
        LD    HL,APPLESP
        LD    DE,APLEN-1
SETAPPLES    LD    (HLI),A
        LD    (HL),A
        ADD    HL,DE
        DEC    B
        JR    NZ,SETAPPLES

        LD    A,8        ;EXTRA MONSTER & SCORE
        LD    (LETCOW),A
        LD    A,<LETTERHI+$50    ;" "
        LD    (LETLOW),A
        LD    B,16
RESETEX        PUSH    BC
        CALL    PRSCORE
        CALL    FLAGS
        POP    BC
        DEC    B
        JR    NZ,RESETEX

        LD    A,60
        LD    (GODELAY),A
        LD    A,MRDOSPEED
        LD    (SPEED),A
        LD    A,$07
        LD    (WX),A
        LD    (CHERRYBON),A
        INC    A
        LD    (SCX),A
        LD    (NEWSCX),A
        LD    A,$50
        LD    (SCY),A
        LD    (NEWSCY),A

        LD    A,%11100000    ;OBJ PAL0 WITH MASK
        LD    (OBP0),A
        LD    A,%11100100    ;OBJ PAL1
        LD    (OBP1),A
        LD    (MUD),A        ;BG PAL STORE

        LD    HL,EXBONSP
        LD    (HL),TEXDANCE    ;TYP
        INC    L
        LD    (HL),8-1    ;YNO
        INC    L
        LD    (HL),8*8    ;XNO
        INC    L
        LD    (HL),EBONSG    ;GNO
        INC    L
        LD    (HL),1        ;FLG

        LD    HL,EXTRATAB+2    ;SETUP EXTRA TOTAL
        LD    B,5
        LD    A,EXTRAG
SETET        LD    (HLI),A
        INC    L
        INC    L
        INC    L
        INC    A
        DEC    B
        JR    NZ,SETET
        JP    DRAWMAP        ;DRAW CURRENT MAP

;***************************************************************************

        ENT
START        LD    SP,STACK
        CALL    SYSETUP
        CALL    MENU
        CALL    GAMESETUP
LEVELOOP    CALL    LEVELSETUP

MAINLOOP    CALL    SPLITSCREEN    ;DO STATUS AND CHR DUMPS
        CALL    KEYS
        CALL    DECODE        ;WORK MR DO!
        CALL    MRDOCHEW    ;EAT BACKGROUND
        CALL    BRINGON        ;TEMP BADDIE INIT
        CALL    BADDIES        ;WORK BADDIES
        CALL    COLLISIONS    ;XY CHECKS
        CALL    APPLEPIE    ;WORK APPLES
         CALL    DUMPOBJ        ;PLACE SPRITES INTO DUMMY OBJDATA
        CALL    STATSP        ;WORK STATUS LINE SPRITES
        CALL    CLOCK
        CALL    RAND
        CALL    FLAGS

    ;    LD    A,%11000010    ;TIME LEFT TEST
    ;    LD    (LCDC),A

        LD    A,(KEYPRESS)
        BIT    3,A        ;'START' TO PAUSE
        JP    NZ,PAUSEGAME
        BIT    2,A        ;'SELECT' TO SKIP LEVEL
        JR    NZ,EXITLEVEL
        LD    A,(EXTRATOT)
        OR    A
        JR    Z,EXTRALIFE
        LD    A,(CHERRYTOT)    ;EATEN ALL CHERRIES?
        OR    A
        JR    NZ,MAINLOOP

        CALL    WINHOW

;---------------------------------------------------------------------------

EXITLEVEL    CALL    WAITBLANK
        XOR    A
        LD    (LCDC),A

        LD    A,(TALLOFF)    ;NEXT SCORE BOARD INDEX
        ADD    A,BRDLEN
        LD    (TALLOFF),A
        LD    A,(MAP)        ;INCREASE MAP
        INC    A
        CP    10
        JR    NZ,NOMAPR
        CALL    SHOWAVERAGES
        XOR    A
        LD    (TALLOFF),A
NOMAPR        LD    (MAP),A
        CP    3
        CALL    Z,SHOWRESULTS
        CP    6
        CALL    Z,SHOWRESULTS
        CP    9
        CALL    Z,SHOWRESULTS

        LD    A,(LEVEL)    ;INCREASE LEVEL DIGIT
        INC    A
        CP    99
        JR    NZ,NOLEVR
        LD    A,$FF
NOLEVR        LD    (LEVEL),A
        JP    LEVELOOP

WAITISH        CALL    WAITBLANK    ;SLOW DOWN
        LD    A,100
        JP    WAITSYNC

WINHOW        LD    H,A        ;STORE HOW LEVEL WAS WON
        LD    A,(TALLOFF)
        ADD    A,<SCORE+8
        LD    L,A
        LD    A,H
        LD    H,>SCORE
        LD    (HL),A
        RET

;***************************************************************************

EXTRALIFE    ;DO FANCY BITS...

        LD    A,2
        CALL    WINHOW
        CALL    SETEXTRA
        JR    EXITLEVEL

SETEXTRA    LD    A,5
        LD    (EXTRATOT),A
        LD    HL,EXTRATAB+2
        LD    B,A
        LD    A,EXTRAG
RESETET        LD    (HLI),A
        LD    (HL),P1
        INC    A
        INC    L
        INC    L
        INC    L
        DEC    B
        JR    NZ,RESETET
        RET

;***************************************************************************

PAUSEGAME    CALL    WAITBLANK
        LD    A,>STATUSOBJ
        CALL    BLITS
        LD    A,%10100100    ;OBJ PAL1
        LD    (OBP1),A
        LD    A,%11100011    ;STATUS ON
        LD    (LCDC),A
        CALL    WAITNOK

NOSTRT        CALL    WAITBLANK
        CALL    KEYS
        BIT    3,A        ;'START'
        JR    Z,NOSTRT
        CALL    WAITNOK        
        JP    MAINLOOP

WAITNOK        CALL    KEYS
        OR    A
        JR    NZ,WAITNOK
        RET

;***************************************************************************

SPLITSCREEN    CALL    WAITBLANK
        LD    A,>STATUSOBJ
        CALL    BLITS
        LD    A,%10100100    ;OBJ PAL1
        LD    (OBP1),A
        LD    A,%11100011    ;STATUS ON
        LD    (LCDC),A

        CALL    PRSCORE
        CALL    CHRDUMPER
        CALL    PRAPPLES

        LD    A,(NEWSCX)    ;UPDATE SCROLL OFFSETS
        LD    (SCX),A
        LD    A,(NEWSCY)
        LD    (SCY),A
        LD    A,(MUD)        ;BG  PAL
        LD    (BGP),A

        LD    A,16        ;WAIT FOR END OF WINDOW
        CALL    WAITSYNC
        LD    A,>GAMEOBJ    ;DMA DUMMY OBJDATA
        CALL    BLITS
        LD    A,%11000011    ;STATUS OFF
        LD    (LCDC),A
        LD    A,%11100100    ;OBJ PAL1
        LD    (OBP1),A
        RET

;***************************************************************************
;PRINT THE APPLES...

PRAPPLES    LD    HL,APPLESP
        LD    BC,APNUM*256+32-1
PRALOOP        INC    L
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO
        INC    L
        SRL    D
        RRA
        SRL    D
        RRA
        SRL    D
        RRA
        AND    %11100000
        ADD    A,E
        LD    E,A
        LD    A,D
        ADD    A,>DISPSCREEN
        LD    D,A
        LD    A,(HL)        ;GNO

        LD    (DE),A
        INC    E
        INC    A
        LD    (DE),A
        LD    A,E
        ADD    A,C
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A

        LD    A,(HLI)
        ADD    A,2
        LD    (DE),A
        INC    E
        INC    A
        LD    (DE),A
        INC    L
        DEC    B
        JR    NZ,PRALOOP
        RET

;***************************************************************************
;WORK THE APPLES...

APPLEPIE    XOR    A
        LD    (SPLAT),A    ;RESET @DONE ONCE@ FLAG
        LD    A,APNUM
        LD    HL,APPLESP
APLOOP        PUSH    AF
        CALL    WORKAPPLE
        INC    L
        LD    (HL),D        ;YNO
        INC    L
        LD    (HL),E        ;XNO
        INC    L
        LD    (HL),C        ;GNO
        INC    L
        LD    (HL),B        ;FLG
        INC    L
        POP    AF
        DEC    A
        JR    NZ,APLOOP
        RET

WORKAPPLE    PUSH    HL
        LD    A,(HLI)        ;TYP
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO
        INC    L
        LD    C,(HL)        ;GNO
        INC    L
        LD    B,(HL)        ;FLG
        ADD    A,A
        ADD    A,<APPLETAB
        LD    L,A
        LD    H,>APPLETAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        JP    (HL)

;---------------------------------------------------------------------------
;THE APPLE BITS... (MUST POP HL(TYP) BEFORE EXITING)

NOAPPLE        LD    E,0
        LD    D,E
NOLFALL        POP    HL
        RET

GOSPLIT        POP    HL
        LD    (HL),TAPPS
        LD    C,AP2
        LD    B,40        ;DELAY
        RET

APPLEWAIT    LD    A,D        ;HIT BOTTOM?
        CP    $1A
        JR    Z,GOSPLIT
        LD    L,E
        LD    H,D
        INC    H
        INC    H
        CALL    GETMAPLO

        LD    A,(HLI)        ;TEST LEFT CHR
        CP    CH+4
        JR    C,NOLFALL
        LD    A,(HL)        ;TEST RIGHT CHR
        POP    HL
        CP    CH+4
        JR    C,NORFALL
        INC    (HL)        ;AND WOBBLE
        LD    B,60        ;FOR 1 SECOND
NORFALL        RET

APPLEJIG    LD    A,(SPEEDFLAG)
        AND    %100
        ADD    A,AP0
        LD    C,A
        POP    HL
        DEC    B
        RET    NZ
        INC    (HL)        ;GO FALL!
        LD    B,0        ;FALL COUNTER
        RET

APPLEFALL    LD    A,(APPLEAND)    ;SLOW DOWN A BIT
        LD    L,A
        LD    A,(SPEEDFLAG)    ;DIFFICULTY LEVEL
        AND    L
        JR    NZ,HLOUT

        PUSH    DE
        CALL    GETMAPLODE    ;DE=BACKSCREEN

        LD    A,(DUMPTOT)
        LD    L,A
        ADD    A,2
        LD    (DUMPTOT),A
        LD    A,L
        ADD    A,A
        ADD    A,L
        ADD    A,<CHRDUMP
        LD    L,A
        LD    H,>CHRDUMP    ;HL=CHR DUMP

        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L

        LD    A,B
        CP    3        ;PAST CRITICAL POINT? (2CHRS)
        JR    C,REPBACK

        PUSH    BC
        LD    A,(DE)        ;IF SO THEN CHANGE THE MAP!
        CP    ED
        JR    C,LEEV0
        ADD    A,<LAFALL-ED
        LD    C,A
        LD    B,>LAFALL
        LD    A,(BC)
        LD    (DE),A
LEEV0        LD    (HLI),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        CP    ED
        JR    C,LEEV1
        ADD    A,<RAFALL-ED
        LD    C,A
        LD    B,>RAFALL
        LD    A,(BC)
        LD    (DE),A
LEEV1        LD    (HL),A
        POP    BC

FLOUT        LD    HL,96-1
        ADD    HL,DE
        POP    DE
        INC    D        ;DOWN 1 CHR
        INC    B        ;CHR COUNT
        LD    A,(HLI)
        CP    CH+4
        JR    C,STOPAFALL
        LD    A,(HL)
        CP    CH+4
        JR    C,STOPAFALL
HLOUT        POP    HL
        RET

REPBACK        LD    A,(DE)        ;JUST REPLACE BACKGROUND
        LD    (HLI),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        LD    (HL),A
        JR    FLOUT

STOPAFALL    LD    A,B        ;PAST CRITICAL POINT
        CP    3
        JP    NC,GOSPLIT
        POP    HL
        LD    (HL),TAPPW
        RET

APPLESPLIT    LD    A,B
        AND    %111
        LD    A,C
        JR    NZ,NOASPL
        CP    AP6
        JR    Z,NOASPL
        ADD    A,$4
NOASPL        LD    C,A
        
        DEC    B
        JR    NZ,HLOUT
        INC    B
        LD    A,(SPLAT)    ;DON'T SPLIT MORE THAN 1 APPLE
        OR    A
        JR    NZ,HLOUT    ;AT A TIME!

        CALL    GETMAPLODE    ;DE=BACKSCREEN

        LD    A,(DUMPTOT)
        LD    L,A
        ADD    A,4
        LD    (DUMPTOT),A
        LD    (SPLAT),A    ;SET 'DONE ONCE' FLAG!
        LD    A,L
        ADD    A,A
        ADD    A,L
        ADD    A,<CHRDUMP
        LD    L,A
        LD    H,>CHRDUMP    ;HL=CHR DUMP

        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        CP    ED
        JR    C,LEEV2
        ADD    A,<LAFALL-ED
        LD    C,A
        LD    B,>LAFALL
        LD    A,(BC)
        LD    (DE),A
LEEV2        LD    (HLI),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        CP    ED
        JR    C,LEEV3
        ADD    A,<RAFALL-ED
        LD    C,A
        LD    B,>RAFALL
        LD    A,(BC)
        LD    (DE),A
LEEV3        LD    (HLI),A

        LD    A,E
        ADD    A,32-1
        LD    (HLI),A
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A

        LD    (HLI),A
        LD    A,(DE)
        LD    (HLI),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        LD    (HL),A

        POP    HL
        LD    E,0
        LD    D,E        ;MAKE Y=0
        LD    (HL),E        ;TYP OFF
        RET

****************************************************************************
;TEMP BRING ON ROUTINES...

BRINGON        CALL    GETDINO
        RET    NZ
        LD    (HL),TDINO    ;TYP
        INC    L
        LD    (HL),$78    ;YNO
        INC    L
        LD    (HL),$58    ;XNO
        INC    L
        LD    (HL),MONSTG    ;GNO
        INC    L
        LD    A,(HL)
        LD    (HL),2        ;FLG
        RET

GETDINO        LD    HL,DINOSP
        LD    BC,DINONUM*256+EVAR
GETSP        LD    A,(HL)        ;TYP
        OR    A
        RET    Z
        LD    A,L
        ADD    A,C
        LD    L,A
        DEC    B
        JR    NZ,GETSP
        DEC    B
        RET

GETAPPLE    LD    HL,APPLESP
        LD    BC,APNUM*256+APLEN
GETAP        LD    A,(HL)        ;TYP
        OR    A
        RET    Z
        LD    A,L
        ADD    A,C
        LD    L,A
        DEC    B
        JR    NZ,GETAP
        DEC    B
        RET

;***************************************************************************
;WORK ANIMATION VARS AND FLAGS...

FLAGS        LD    A,(SPEEDFLAG)
        INC    A
        LD    (SPEEDFLAG),A
        LD    C,A
        AND    1
        LD    (TOGGLE),A
        LD    A,C
        AND    %11000
        SRL    A
        SRL    A
        SRL    A
        LD    (ANIOFF4),A
        LD    A,C
        AND    7
        RET    NZ
        LD    A,(ANIOFF3)
        ADD    A,%01
        CP    %11
        JR    NZ,NOT3
        XOR    A
NOT3        LD    (ANIOFF3),A
        RET

****************************************************************************
;THE XY COLLISION ROUTINES...

COLLISIONS
        LD    HL,MRBALLSP

;BALL TO ALL 2*2 SPRITES...

BALLCP        LD    A,(HL)        ;TYP
        CP    TTBALL        ;BALL MOVING?
        RET    NZ
        PUSH    HL        ;HL=BALL VARS
        INC    L
        LD    A,(HLI)        ;YNO
        SUB    8
        LD    D,A
        LD    A,(HL)        ;XNO
        SUB    8
        LD    E,A

        LD    HL,MRDOSP+YNO
        LD    B,BADNUM+1

BALLCPL        LD    C,L

        LD    A,(HLI)        ;YNO
        SUB    D
        CP    16
        JR    NC,NBALLCP
        LD    A,(HL)        ;XNO
        SUB    E
        CP    16
        JR    NC,NBALLCP

        DEC    L
        DEC    L
        LD    E,L        ;DE=BADDIE VARS
        LD    D,H
        LD    A,(HL)        ;TYP
        ADD    A,A
        ADD    A,<HITBALLTAB
        LD    L,A
        LD    H,>HITBALLTAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        JP    (HL)        ;NO MORE CHECKS NEEDED

NBALLCP        LD    A,C
        ADD    A,EVAR
        LD    L,A
        DEC    B
        JR    NZ,BALLCPL
        POP    HL
        RET

;--------------------------------------------------------------------------
;BALL TO 2 BY 2 DEATH ROUTINES...
;(SP)=BALL VARS DE=BAD VARS

MRDOCATCH    POP    HL
        LD    A,(CATCHDEL)
        OR    A
        RET    NZ
        LD    (HL),TCBALL    ;CATCHBALL
        RET

;---------------------------------------------------------------------------

GHOSTDIE    LD    A,(GHOSTOTAL)
        DEC    A
        LD    (GHOSTOTAL),A
        JR    NZ,NOTLASTG
        LD    (FREEZE),A
        LD    A,%11100100    ;RESET BACKGROUND PALETTE
        LD    (MUD),A
NOTLASTG    LD    L,E
        LD    H,D
        LD    (HL),0        ;TYP
        INC    L
        LD    D,(HL)
        INC    L
        LD    E,(HL)
        CALL    GOAPPLE
        JP    BALLSCORE

;---------------------------------------------------------------------------
;RESET EXMON/CHANGE PAL/RESET LETTER/SETUP APPLES/KILL GHOSTS/UNFREEZE...

EXDIE        LD    A,(EXTRATOT)
        DEC    A
        LD    (EXTRATOT),A
        LD    A,(EXTRALETTER)
        LD    C,A
        SUB    EXTRAG
        ADD    A,A
        ADD    A,A
        ADD    A,<EXTRATAB+2
        LD    L,A
        LD    H,>EXTRATAB
        LD    (HL),C        ;RESTORE CHR
        INC    L
        LD    (HL),P0        ;CHANGE PALETTE

        XOR    A
        LD    (FREEZE),A
        LD    A,<LETTERHI+$50    ;" "
        LD    (LETLOW),A
        LD    A,8        ;CLEAR CENTRE OF EMON
        LD    (LETCOW),A
        LD    A,%11100100    ;RESET BACKGROUND PALETTE
        LD    (MUD),A

        PUSH    DE
        LD    HL,GHSTSP    ;KILL THE GHOSTS...
        CALL    GAPPLE
        LD    HL,1*EVAR+GHSTSP
        CALL    GAPPLE
        LD    HL,2*EVAR+GHSTSP
        CALL    GAPPLE

        POP    HL
        LD    (HL),TEXDANCE    ;TYP
        INC    L
        LD    D,(HL)
        LD    (HL),8-1    ;YNO
        INC    L
        LD    E,(HL)
        LD    (HL),8*8    ;XNO
        INC    L
        LD    (HL),EBONSG    ;GNO
        INC    L
        LD    (HL),1        ;FLG
        CALL    GOAPPLE
        JR    BALLSCORE

GAPPLE        LD    A,(HL)        ;TYP
        OR    A
        RET    Z
        LD    (HL),0
        INC    L
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO

;---------------------------------------------------------------------------

GOAPPLE        CALL    GETAPPLE    ;SETUP APPLE
        RET    NZ        ;NONE LEFT
        LD    (HL),TAPPW    ;TYP
        INC    L
        LD    A,D
        SRL    A
        SRL    A
        SRL    A
        DEC    A
        LD    (HLI),A        ;YNO
        LD    A,E
        SRL    A
        SRL    A
        SRL    A
        DEC    A
        LD    (HLI),A        ;XNO
        LD    (HL),AP0    ;GNO
        INC    L
        LD    (HL),0        ;FLG
        RET

;---------------------------------------------------------------------------

DINODIE

;---------------------------------------------------------------------------

GOBALLBANG    LD    L,E
        LD    H,D
        LD    (HL),0        ;BADDIE OFF
        INC    L
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO

;---------------------------------------------------------------------------
;SETUP BONUS SCORE DISPLAY...
;DE=XY

BALLSCORE    LD    HL,SCORSP
        LD    (HL),TPOINTS    ;TYP
        INC    L
        LD    A,D
        ADD    A,4
        LD    (HLI),A        ;YNO
        LD    (HL),E        ;XNO
        INC    L
        LD    (HL),FIVEG    ;GNO 500 PTS
        INC    L
        LD    (HL),64        ;FLG 60TH DELAY

;---------------------------------------------------------------------------
;SETUP BALL SPIN OUT...

        POP    HL
        LD    (HL),TOUTBALL    ;TYP
        INC    L
        LD    A,(HLI)        ;YNO
        LD    E,(HL)        ;XNO
        INC    L
        INC    L
        LD    (HL),0        ;FLG RADIUS
        INC    L
        INC    L
        LD    (HLI),A        ;TEMP Y
        LD    (HL),E        ;TEMP X
        LD    HL,$0503    ;500 PTS
        JP    SCOREADD

DUFKILL        POP    HL
        RET

;***************************************************************************
;WORK MR DO...

EATCHERRY    INC    C        ;IN SEQUENCE?
        DEC    C
        JR    Z,NOCHSEQU
        LD    A,(CHERRYBON)
        DEC    A
        LD    (CHERRYBON),A
        JR    NZ,RESCHSEQU

        LD    HL,SCORSP
        LD    (HL),TPOINTS    ;TYP
        INC    L
        LD    A,D
        ADD    A,4
        LD    (HLI),A        ;YNO
        LD    (HL),E        ;XNO
        INC    L
        LD    (HL),FIVEG    ;GNO 500 PTS
        INC    L
        LD    (HL),64        ;FLG 50TH DELAY
        LD    HL,$0503    ;500 PTS BONUS
        CALL    SCOREADD

NOCHSEQU    LD    A,7        ;RESET CHERRY SEQU
        LD    (CHERRYBON),A
RESCHSEQU    LD    A,42        ;RESET TIME LIMIT
        LD    (CHERRYDEL),A
        LD    A,(CHERRYTOT)
        DEC    A
        LD    (CHERRYTOT),A
        LD    HL,$0504    ;50 PTS PER CHERRY
        CALL    SCOREADD

EATWALL        LD    A,EATSPEED    ;SLOW DELAY
        LD    (SPEED),A
        LD    A,32
        LD    (SPDCOW),A
        RET

EATAPPLE    RET

EATUNNEL    RET

;---------------------------------------------------------------------------
;1000 PTS/CHANGE BACKGROUND PALETTE/GO EXTRA/GO GHOSTS...

EATFOOD        LD    HL,SCORSP
        LD    (HL),TPOINTS    ;TYP
        INC    L
        LD    A,D
        ADD    A,4
        LD    (HLI),A        ;YNO
        LD    (HL),E        ;XNO
        INC    L
        LD    (HL),PNTG    ;GNO 1000 PTS
        INC    L
        LD    (HL),64*2    ;FLG 60TH DELAY
        LD    HL,$0102    ;1000 PTS PER FOOD ITEM
        CALL    SCOREADD

        LD    A,%11101000
        LD    (MUD),A        ;CHANGE BACKGROUND COLOURS
        LD    (FREEZE),A    ;AND FREEZE

        PUSH    DE
        LD    HL,EXBONSP
        LD    A,(HL)        ;TYP
        CP    TEXWALK        ;ON SCREEN?
        JR    NC,ISOUT

;PICK THE NEXT EXTRA CHR...

        LD    DE,EXTRATAB+3
GETLET        LD    A,(DE)
        CP    P1        ;IF P0 THEN FREE
        JR    Z,GOTLET
        LD    A,E
        ADD    A,4
        LD    E,A
        JR    GETLET        ;WILL ALWAYS GET ONE!

GOTLET        DEC    E
        LD    A,(DE)        ;STORE CURRENT CHR
        LD    (EXTRALETTER),A
        SUB    EXTRAG
        SWAP    A
        ADD    A,<LETTERHI
        LD    (LETLOW),A
        LD    A,$FF
        LD    (DE),A        ;CHANGE TO SPACE CHR
        LD    A,8        ;START THE CHANGE
        LD    (LETCOW),A

        LD    C,2        ;FLG
        LD    DE,$0058    ;YX
        LD    (HL),TEXWALK    ;TYP
        INC    L
        LD    (HL),D        ;YNO
        INC    L
        LD    (HL),E        ;XNO
        INC    L
        INC    L
        LD    (HL),C        ;FLG
        JR    PUTGHST

ISOUT        INC    L
        LD    D,(HL)
        INC    L
        LD    E,(HL)
        INC    L
        INC    L
        LD    C,(HL)
        
PUTGHST        LD    HL,GHSTSP
        LD    A,GHSTNUM
        LD    (GHOSTOTAL),A
        LD    B,A
SETGHST        LD    (HL),TGHOST    ;TYP
        INC    L
        LD    (HL),D        ;YNO
        INC    L
        LD    (HL),E        ;XNO
        INC    L
        LD    (HL),GHOSTG    ;GNO
        INC    L
        LD    (HL),C        ;FLG
        LD    A,EVAR-FLG
        ADD    A,L
        LD    L,A
        DEC    B
        JR    NZ,SETGHST
        POP    DE
        RET

;---------------------------------------------------------------------------

DECODE        LD    A,(GODELAY)    ;INITAIL DELAY
        OR    A
        JR    Z,NOGODEL
        DEC    A
        LD    (GODELAY),A
        RET

NOGODEL        LD    A,(CHERRYDEL)    ;DECREASE BONUS TIME LIMIT
        OR    A
        JR    Z,NODECBON
        DEC    A
        LD    (CHERRYDEL),A
NODECBON    LD    C,A

        LD    A,(MRDOSP+XNO)
        LD    E,A
        LD    A,(MRDOSP+YNO)
        LD    D,A
        ADD    A,8
        AND    15
        JR    NZ,DECODER
        LD    A,E
        ADD    A,8
        AND    15
        JR    NZ,DECODER

        LD    L,E
        LD    H,D
        CALL    GETBYTEHI
        LD    A,(HL)        ;GET CONTROL BYTE
        LD    (HL),1        ;SET TUNNEL BYTE
        ADD    A,A
        ADD    A,<EATJP
        LD    L,A
        LD    H,>EATJP
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        CALL    JPHL        ;WORK EAT ROUTINE

;---------------------------------------------------------------------------

DECODER        LD    A,(SPEED)
        OR    A
        JR    Z,NOSLOW
        LD    C,A
        LD    A,(SPDCOW)
        DEC    A
        LD    (SPDCOW),A
        JR    NZ,ISSLOW

        LD    A,MRDOSPEED
        LD    (SPEED),A

ISSLOW        LD    A,(SPEEDO)
        ADD    A,C
        LD    (SPEEDO),A
        RET    NC

NOSLOW        LD    A,(MRDOSP+FLG)    ;LAST MOVE
        LD    B,A
        LD    A,(KEYPRESS)    ;GET KEYPAD
        SWAP    A
        AND    %1111
        JP    Z,INVALID    ;NOT WALKING
        LD    C,A

        AND    %0011        ;GET L/R
        ADD    A,<VALIDLR
        LD    L,A
        LD    H,>VALIDLR

        LD    A,D        ;ON Y BOUNRY?
        ADD    A,8
        AND    15
        JR    NZ,INVALIDX    ;MISS OUT IF NOT

        LD    A,(HL)        ;GET DIRECTION+1!
        SUB    1
        JR    C,INVALIDX    ;INCORRECT MOVE
        CP    B        ;SAME AS LAST MOVE?
        JR    NZ,NEWMOVE

INVALIDX    LD    A,E        ;ON X BOUNRY?
        ADD    A,8
        AND    15
        JR    NZ,INVALIDY    ;MISS OUT IF NOT

        LD    A,C    
        AND    %1100        ;GET U/D
        SRL    A
        SRL    A
        ADD    A,<VALIDUD
        LD    L,A
        LD    A,(HL)        ;GET DIRECTION+1!
        SUB    1
        JR    C,INVALIDY    ;INCORRECT MOVE
        CP    B        ;SAME AS LAST MOVE?
        JR    NZ,NEWMOVE

INVALIDY    LD    A,B        ;USE LAST MOVE
NEWMOVE        LD    B,A
        
;---------------------------------------------------------------------------
;ANIMATE MR DO...

        ADD    A,<MRDOTAB
        LD    L,A
        LD    A,(MRDOANI)
        INC    A
        CP    6*2
        JR    NZ,NOWRAP
        XOR    A
NOWRAP        LD    (MRDOANI),A
        SRL    A
        ADD    A,(HL)
        LD    (MRDOSP+GNO),A

;-----------------------------------------------------------------------------
;MOVE MR DO...

        LD    A,B
        ADD    A,A
        ADD    A,<VECTAB
        LD    L,A
    
        LD    A,(HLI)
        ADD    A,E
        SUB    8
        CP    8*$16+1
        JR    NC,NOSCROLL
        ADD    A,8
        LD    E,A        
        LD    (MRDOSP+XNO),A
        SUB    8*10
        JR    C,NOSCROLL
        CP    8*4+1
        JR    NC,NOSCROLL
        LD    (NEWSCX),A

NOSCROLL    LD    A,(HL)
        ADD    A,D
        SUB    8+16
        CP    8*$18+1
        JR    NC,INVALID
        ADD    A,8+16
        LD    D,A
        LD    (MRDOSP+YNO),A
        SUB    8*10
        JR    C,INVALID
        CP    8*10+1
        JR    NC,INVALID
        LD    (NEWSCY),A

;-----------------------------------------------------------------------------

INVALID        LD    A,B        
        LD    (MRDOSP+FLG),A

;THROW THE BALL...

        LD    A,(KEYPRESS)    ;A/B
        AND    %10        ;%11
        RET    Z

DOBALL        LD    A,B
        ADD    A,A
        ADD    A,<BALLOFF
        LD    L,A
        LD    H,>BALLOFF    ;PLACE BALL
        LD    A,(HLI)
        ADD    A,E
        OR    4
        LD    E,A
        LD    A,(HL)
        ADD    A,D
        OR    4
        LD    D,A

        LD    HL,MRBALLSP
        LD    A,(HL)
        CP    TCBALL        ;DO WE HOLD THE BALL?
        RET    NZ
        LD    (HL),TTBALL    ;THROW BALL
        INC    L
        LD    (HL),D        ;YNO
        INC    L
        LD    (HL),E        ;XNO
        INC    L
        INC    L
        LD    (HL),B        ;VECTOR

        LD    A,32        ;DELAY TO AVOID REGRAB
        LD    (CATCHDEL),A
        RET

;*****************************************************************************
;WORK THE BADDIES...

BADDIES        LD    B,SPNUM
        LD    HL,DINOSP
BADLOOP        PUSH    BC
        LD    A,(HLI)        ;TYP
        PUSH    HL
        CALL    WORKBADDIE
        POP    HL
        LD    (HL),D        ;YNO
        INC    L
        LD    (HL),E        ;XNO
        INC    L
        LD    (HL),C        ;GNO
        INC    L
        LD    (HL),B        ;FLG
        LD    A,L
        ADD    A,EVAR-FLG
        LD    L,A
        LD    A,(RND1)
        XOR    E
        RRCA
        RRCA
        RRCA
        XOR    D
        LD    (RND1),A
        POP    BC
        DEC    B
        JR    NZ,BADLOOP
        RET

WORKBADDIE    LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO
        INC    L
        LD    C,(HL)        ;GNO
        INC    L
        LD    B,(HL)        ;FLG
        INC    L
        INC    L
        PUSH    HL        ;MISC VARS DATA
        ADD    A,A
        LD    L,A
        LD    H,>BADTAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
JPHL        JP    (HL)

NOBAD        POP    HL
        LD    E,-16
        LD    D,E
        RET

;---------------------------------------------------------------------------
;CIRCLE ROUTINE...
;A=RADIUS (0TO$FF) RETS DE=XY

CIRCLE        PUSH    BC
        LD    C,A
        AND    %11000000    ;QUADRANT
        RLCA
        RLCA
        LD    B,A
        ADD    A,<QUADTAB
        LD    L,A
        LD    H,>QUADTAB
        LD    A,C        ;ANGLE
        XOR    (HL)
        AND    %00111111
        LD    C,A
        ADD    A,<CTAB
        LD    L,A        ;INDEX
        LD    E,(HL)        ;X VALUE
        LD    A,<CTAB+$3F
        SUB    C
        LD    L,A
        LD    D,(HL)        ;Y VALUE
        LD    A,B
        ADD    A,<QUADX
        LD    L,A
        LD    A,E
        XOR    (HL)
        LD    E,A
        LD    A,B
        ADD    A,<QUADY
        LD    L,A
        LD    A,D
        XOR    (HL)
        LD    D,A
        POP    BC
        RET

;-----------------------------------------------------------------------------
;MOVE BADDIE USING VECTOR FLAG (0TO3)...

MOVEBADF    LD    A,(FREEZE)    ;KEEP STILL IF FROZZEN
        OR    A
        RET    NZ
MOVEBAD        LD    A,B
        ADD    A,A
        ADD    A,<VECTAB
        LD    L,A
        LD    H,>VECTAB
        LD    A,(HLI)
        ADD    A,E
        LD    E,A
        LD    A,(HL)
        ADD    A,D
        LD    D,A
        RET

;---------------------------------------------------------------------------
;FIND ANY POSSIBLE EXITS AT EACH JUNCTION...
;DE=XY RETS A=%UDLR BITS

FINDEXITS    PUSH    DE
        LD    L,E
        DEC    L
        LD    H,D
        DEC    H
        CALL    GETMAPHI
        LD    DE,$0100

        LD    A,(HLI)    ;TOP CHR...
        CP    DT+1
        JR    Z,ISUP
        CP    DT+3
        JR    Z,ISUP
        OR    D
        CP    ED+3
        JR    NZ,NOUP
ISUP        SET    3,E
NOUP        LD    A,(HL)    ;R CHR...
        OR    D
        CP    DT+3
        JR    Z,ISRT
        CP    ED+5
        JR    NZ,NORT
ISRT        SET    0,E
NORT        LD    A,L
        ADD    A,32
        LD    L,A
        ADC    A,H
        SUB    L
        LD    H,A
        LD    A,(HLD)    ;BOT CHR...
        CP    DT+0
        JR    Z,ISDW
        CP    DT+2
        JR    Z,ISDW
        OR    D
        CP    ED+7
        JR    NZ,NODW
ISDW        SET    2,E
NODW        LD    A,(HL)    ;L CHR...
        OR    D
        CP    DT+1
        JR    Z,ISLF
        CP    ED+1
        JR    NZ,NOLF
ISLF        SET    1,E
NOLF        LD    A,E
        POP    DE
        RET

;---------------------------------------------------------------------------
;THIS IS THE INTELLIGENCE ROUTINE AND
;SHOULD BE DIFFERENT FOR EACH BADDIE TYPE...

WORKEXITS    PUSH    DE
        LD    D,L
        LD    E,A        ;TEMP EXITS

;DO WE HAVE TO CHANGE DIRECTION?

        LD    A,B        ;GET OLD DIR
        ADD    A,<VECTOBIT
        LD    L,A
        LD    H,>VECTOBIT
        LD    A,(HL)
        AND    E        ;IS DIR AN OPTION
        JR    Z,CHANGEDIR    ;IF NOT THEN CHANGE

        LD    A,(RND2)    ;RND MOVE
        AND    7
        JR    NZ,DINODE

CHANGEDIR    LD    A,(RND1)
        ADD    A,D
        SRL    A
        SRL    A
        SRL    A
FINDEX        LD    D,A
        AND    3
        ADD    A,<BITAB
        LD    L,A
        LD    A,(HL)
        AND    E
        JR    NZ,GOEXIT
        LD    A,D        ;WILL DO MAX 4 TIMES ONLY!
        INC    A
        JR    FINDEX
        
GOEXIT        LD    A,(HL)
        ADD    A,<BITTOVEC
        LD    L,A
        LD    B,(HL)        ;NEW DIRECTION
DINODE        POP    DE
        RET

;---------------------------------------------------------------------------
;THE DINO MONSTER ROUTINES...

DINO        LD    A,E
        OR    D
        AND    7
        JR    NZ,DINOMOVE    ;ON BOUNDRY?
        CALL    FINDEXITS
        OR    A
        JR    Z,DINOMOVE
        POP    HL
        PUSH    HL
        CALL    WORKEXITS
DINOMOVE    CALL    MOVEBADF    ;MOVE AND ANIMATE
        LD    A,B
        ADD    A,A
        ADD    A,A
        LD    C,A
        LD    A,(ANIOFF4)
        ADD    A,MONSTG
        ADD    A,C
        LD    C,A
        POP    HL
        RET

DINOEAT        POP    HL
        RET

DINOPUSH    POP    HL
        RET

;-----------------------------------------------------------------------------
;THE EXTRA BONUS MONSTER...

EXDANCE        LD    A,(SPEEDFLAG)
        AND    %11
        JR    NZ,EXOUT

        LD    A,E        ;BOUNCE OFF EDGES
        SUB    8*8
        LD    L,A
        CP    4*8
        JR    C,NOEXFL
        LD    A,B
        XOR    2
        LD    B,A

NOEXFL        LD    A,E        ;ON A BOUNDRY?
        AND    7
        JR    NZ,EXMOVE
        LD    A,(RND1)    ;PICK A LETTER?
        AND    7
        JR    NZ,EXMOVE

        LD    A,L        ;INDEX THE EXTRATAB
        ADD    A,4
        SRL    A
        AND    %11100
        ADD    A,<EXTRATAB+3
        LD    L,A
        LD    H,>EXTRATAB

        LD    A,(HLD)        ;PAL0=FREE
        CP    P0        ;PAL1=GONE
        JR    Z,EXMOVE
        LD    A,(HL)        ;STORE CURRENT CHR
        LD    (EXTRALETTER),A
        LD    (HL),$FF    ;CHANGE TO SPACE CHR
        SUB    EXTRAG
        SWAP    A
        ADD    A,<LETTERHI
        LD    (LETLOW),A
        LD    A,8        ;START THE CHANGE
        LD    (LETCOW),A
        POP    HL
UPTYPE        LD    A,L
        SUB    YSD
        LD    L,A
        INC    (HL)        ;NEXT TYP
        RET    

EXUP        POP    HL
        DEC    D        ;MOVE UP
        LD    A,D
        CP    -16
        RET    NZ
        LD    E,$0B*8        ;AND ATTACK
        LD    B,2
        JR    UPTYPE

EXEXIT
EXEAT        POP    HL
        RET

EXWALK        LD    A,E
        OR    D
        AND    7
        JR    NZ,EXMOVE    ;ON BOUNDRY?
        CALL    FINDEXITS
        OR    A
        JR    Z,EXMOVE
        POP    HL
        PUSH    HL
        CALL    WORKEXITS

EXMOVE        CALL    MOVEBAD
        LD    A,(ANIOFF3)
        ADD    A,EBONSG
        LD    C,A
EXOUT        POP    HL
        RET

;---------------------------------------------------------------------------
;THE GHOST ROUTINES...

GHOST        LD    A,E
        OR    D
        AND    7
        JR    NZ,GHOSTMOVE        ;ON BOUNDRY?
        CALL    FINDEXITS
        OR    A
        JR    Z,GHOSTMOVE
        POP    HL
        PUSH    HL
        CALL    WORKEXITS 
GHOSTMOVE    CALL    MOVEBAD
        LD    C,GHOSTG
        LD    A,B
        SRL    A
        JR    Z,GHOSTR
        LD    C,GHOSTG+3
GHOSTR        LD    A,(ANIOFF3)
        ADD    A,C
        LD    C,A
        POP    HL
        RET

GHOSTEAT    POP    HL
        RET

;-----------------------------------------------------------------------------
;THE BALL ROUTINES...

CARRYBALL    LD    HL,MRDOSP+YNO
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO
        INC    L
        LD    A,(HLI)        ;GNO
        PUSH    AF
        LD    A,(HL)        ;FLG
        ADD    A,A
        ADD    A,<BALLOFF
        LD    L,A
        LD    H,>BALLOFF    ;PLACE BALL
        LD    A,(HLI)
        ADD    A,E
        LD    E,A
        LD    A,(HL)
        ADD    A,D
        LD    D,A

        POP    AF        ;ANIMATE BALL
        AND    3
        ADD    A,A
        ADD    A,<BALLXY
        LD    L,A
        LD    A,(HLI)
        ADD    A,E
        LD    E,A
        LD    A,(HL)
        ADD    A,D
        LD    D,A        
        POP    HL
        RET

;-----------------------------------------------------------------------------

THROWBALL    LD    A,(CATCHDEL)    ;DELAY FOR REGRAB
        OR    A
        JR    Z,CDEL0
        DEC    A
        LD    (CATCHDEL),A

CDEL0        LD    A,E
        ADD    A,4
        AND    7
        JR    Z,ISCHN
        LD    A,D
        ADD    A,4
        AND    7
        JR    NZ,NOCHN

ISCHN        LD    L,E
        LD    H,D
        CALL    GETMAPHI        ;HL=SCRN3 ADDR

        LD    A,(HL)        ;GET CHR
        CP    CH+4        ;WALL OR CHERRY?
        JR    NC,NOCHWL
        LD    A,B        ;THEN ALWAYS FLIP DIRECTION
        XOR    2
        LD    B,A
        JR    NOCHN

NOCHWL        PUSH    DE
        LD    E,A

        LD    A,B        ;GET LAST DIRECTION
        ADD    A,A
        LD    L,A
        ADD    A,A
        ADD    A,L
        ADD    A,<BALLCPS
        LD    L,A
        LD    H,>BALLCPS

        LD    D,6        ;TOTAL NUMBER OF CHRS TO CHECK
BCHECK        LD    A,(HLI)        ;HAVE WE HIT A VALID CHR?
        CP    E
        JR    NZ,NOBHIT    ;IF NOT THEN CARRY ON MOVING

        LD    A,BALLBOU-BALLCPS-1
        ADD    A,L
        LD    L,A        ;INDEX BOUNCE VECTORS
        LD    A,(HL)        ;GET NEW BOUNCE DIRECTION
        BIT    7,A        ;BIT OF RND?
        JR    Z,NRNDB

        LD    B,A
        LD    A,(RND3)    ;STOPS BEING TRAPPED!
        AND    2
        ADD    A,128
        XOR    B

NRNDB        LD    B,A        
        JR    BHITC

NOBHIT        DEC    D
        JR    NZ,BCHECK

BHITC        POP    DE
NOCHN        LD    A,B        ;MOVE THE BALL
        ADD    A,A
        ADD    A,<BALLVEC
        LD    L,A
        LD    H,>BALLVEC
        LD    A,(HLI)
        ADD    A,E
        LD    E,A
        LD    A,(HL)
        ADD    A,D
        LD    D,A
        POP    HL
        RET

;---------------------------------------------------------------------------
;BALL CIRCLE ROUTINES...

OUTBALL        LD    A,B        ;GET COUNTER
        CP    %01000000
        JR    Z,GOINBALL
        AND    %00001111    ;GET RADIUS
        SWAP    A
        CALL    CIRCLE
        LD    A,B
        CPL
        AND    %00110000
        SWAP    A        ;GET MATHS INDEX
        ADD    A,<MULTIE
        LD    L,A
        LD    H,>MULTIE
        XOR    A
        CALL    JPHL        ;X MULTI
        LD    E,A
        LD    A,MULTID-MULTIE
        ADD    A,L
        LD    L,A
        XOR    A
        CALL    JPHL        ;Y MULTI
        POP    HL
        ADD    A,(HL)        ;CENT Y
        LD    D,A
        INC    L
        LD    A,(HL)        ;CENT X
        ADD    A,E
        LD    E,A
        INC    B
        RET

GOINBALL    POP    HL
        LD    (HL),32        ;60TH DELAY (WILL CHANGE)
        LD    A,L
        SUB    YSD
        LD    L,A
        LD    (HL),TINBALL    ;TYP
        RET

INBALL        POP    HL
        LD    A,(HL)
        OR    A
        JR    Z,INBALL0
        DEC    (HL)
        LD    E,-16
        LD    D,E
        RET

INBALL0        DEC    B
        JR    NZ,INBALL1
        LD    A,L
        SUB    YSD
        LD    L,A
        LD    (HL),TCBALL    ;TYP
        RET

INBALL1        PUSH    HL
        LD    A,B        ;GET COUNTER
        AND    %00001111    ;GET RADIUS
        SWAP    A
        CALL    CIRCLE
        LD    A,B
        CPL
        AND    %00110000
        SWAP    A        ;GET MATHS INDEX
        ADD    A,<MULTIE
        LD    L,A
        LD    H,>MULTIE
        LD    A,(MRDOSP+XNO)
        CALL    JPHL        ;X MULTI
        LD    E,A
        LD    A,MULTID-MULTIE
        ADD    A,L
        LD    L,A
        LD    A,(MRDOSP+YNO)
        CALL    JPHL        ;Y MULTI
        LD    D,A
        POP    HL
        RET

;---------------------------------------------------------------------------
;BONUS SCORE DISPLAY ROUTINES...

POINTS        POP    HL
        DEC    B        ;DECREASE COUNTER
        RET    NZ
        LD    A,L
        LD      B,L
        SUB    YSD
        LD    L,A
        LD    (HL),0        ;BADDIE OFF
        LD    L,B
        RET

;***************************************************************************
;SETUP SPRITES...

DUMPOBJ        LD    A,(NEWSCX)    ;INVERT SCROLL OFFSETS
        CPL
        INC    A
        LD    (SCXT),A
        LD    A,(NEWSCY)
        CPL
        ADD    A,9
        LD    (SCYT),A

;-----------------------------------------------------------------------------

        LD    HL,SPRITES+ADL    ;SWAP 8 OBJ POINTERS
        LD    DE,EVAR
        LD    A,(SPEEDFLAG)
        LD    C,A
        SWAP    A
        LD    B,8
MPLEX        AND    %01110000
        LD    (HL),A
        ADD    A,16
        ADD    HL,DE
        DEC    B
        JR    NZ,MPLEX

        LD    A,C        ;AND MIXUP THE REST
        AND    1
        ADD    A,A
        ADD    A,A
        ADD    A,<OBJSWAP
        LD    C,A
        LD    B,>OBJSWAP
        LD    A,(BC)
        INC    C
        LD    (HL),A
        ADD    HL,DE
        LD    A,(BC)
        INC    C
        LD    (HL),A
        ADD    HL,DE
        LD    A,(BC)
        INC    C
        LD    (HL),A
        ADD    HL,DE
        LD    A,(BC)
        LD    (HL),A

;-----------------------------------------------------------------------------
;DO 2*2 CHAR SPRITES...

        LD    HL,SPRITES
        LD    A,BADNUM+1    ;TOTAL+MRDO
DUMPL        PUSH    AF
        CALL    DUMP2BY2
        POP    AF
        DEC    A
        JR    NZ,DUMPL

;-----------------------------------------------------------------------------
;DO 1*1 SPRITES... (BALLS)

        CALL    DUMP1BY1
        CALL    DUMP1BY1

;-----------------------------------------------------------------------------
;DO 2*1 SPRITES... (POINTS)

        LD    A,(SPEEDFLAG)
        ADD    A,A
        AND    P1
        LD    C,A        ;PALETTE CONTROL FLASH

DUMP2BY1    INC    L        ;IGNORE TYP
        LD    A,(SCYT)
        ADD    A,(HL)
        LD    E,A        ;YNO
        INC    L
        LD    A,(SCXT)
        ADD    A,(HL)        ;XNO
        LD    D,A
        INC    L
        LD    A,(HLI)        ;GNO
        INC    L        ;FLAG
        LD    L,(HL)        ;OBJ ADDR L
        LD    H,>GAMEOBJ

        LD    (HL),E        ;YNO
        INC    L
        LD    (HL),D        ;XNO
        INC    L
        LD    (HLI),A        ;GNO
        LD    (HL),C        ;FLAG
        INC    L
        LD    A,D
        ADD    A,8
        LD    D,A
        LD    (HL),E        ;YNO
        INC    L
        LD    (HL),D        ;XNO
        INC    L
        LD    (HL),$F9    ;GNO (00)
        INC    L
        LD    (HL),C        ;FLAG
        RET

DUMP1BY1    INC    L        ;IGNORE TYP
        LD    A,(SCYT)
        ADD    A,(HL)
        ADD    A,4
        LD    E,A        ;YNO
        INC    L
        LD    A,(SCXT)
        ADD    A,(HL)        ;XNO
        ADD    A,4
        INC    L
        LD    D,(HL)        ;GNO
        INC    L
        INC    L
        PUSH    HL
        LD    L,(HL)        ;OBJ ADDR L
        LD    H,>GAMEOBJ
        LD    (HL),E        ;YNO
        INC    L
        LD    (HLI),A        ;XNO
        LD    (HL),D        ;GNO
        INC    L
        LD    (HL),0        ;FLAG
        POP    HL
        LD    A,L
        ADD    A,EVAR-ADL
        LD    L,A
        RET

DUMP2BY2    INC    L        ;IGNORE TYP
        LD    A,(SCYT)
        ADD    A,(HL)
        LD    E,A        ;YNO
        INC    L
        LD    A,(SCXT)
        ADD    A,(HL)        ;XNO
        LD    D,A
        INC    L
        LD    A,(HLI)        ;GNO
        INC    L        ;FLAG
        PUSH    HL
        LD    L,(HL)        ;OBJ ADDR L
        LD    H,>GAMEOBJ

;A=2BY2 CHRNUM E=YNO D=XNO HL=OBJDATA

DUMP2BY2S    LD    C,A        ;GET CHRTABLE DATA...
        SLA    C
        RLA
        SLA    C
        RLA
        SLA    C
        RLA
        AND    %111
        ADD    A,>CHRTABLE
        LD    B,A

        LD    (HL),E        ;YNO
        INC    L
        LD    (HL),D        ;XNO
        INC    L
        LD    A,(BC)
        LD    (HLI),A        ;GNO
        INC    C
        LD    A,(BC)
        LD    (HLI),A        ;FLAG
        INC    C
        LD    A,D
        ADD    A,8
        LD    D,A
        LD    (HL),E        ;YNO
        INC    L
        LD    (HLI),A        ;XNO
        LD    A,(BC)
        LD    (HLI),A        ;GNO
        INC    C
        LD    A,(BC)
        LD    (HLI),A        ;FLAG
        INC    C
        LD    A,E
        ADD    A,8
        LD    E,A
        LD    (HLI),A        ;YNO
        LD    (HL),D        ;XNO
        INC    L
        LD    A,(BC)
        LD    (HLI),A        ;GNO
        INC    C
        LD    A,(BC)
        LD    (HLI),A        ;FLAG
        INC    C
        LD    A,D
        SUB    8
        LD    (HL),E        ;YNO
        INC    L
        LD    (HLI),A        ;XNO
        LD    A,(BC)
        LD    (HLI),A        ;GNO
        INC    C
        LD    A,(BC)
        LD    (HL),A        ;FLAG

        POP    HL
        LD    A,L
        ADD    A,EVAR-ADL
        LD    L,A
        RET

;**************************************************************************
;CHEW THE BACKGROUND UP...

MRDOCHEW    LD    A,(MRDOSP+XNO)
        LD    C,A
        SUB    4
        LD    E,A
        LD    A,(MRDOSP+YNO)
        SUB    4
        LD    D,A
        ADD    A,4        ;ON A CHR BOUNDRY?
        OR    C
        AND    7
        RET    NZ

        LD    A,(MRDOSP+FLG)
        LD    B,A

;B=FLG (0/3) DE=COORDS...

GOCHEW        LD    A,(DUMPTOT)    ;INDEX CHR DUMP TABLE
        LD    C,A
        ADD    A,A
        ADD    A,C
        ADD    A,<CHRDUMP
        LD    L,A
        LD    H,>CHRDUMP
        LD    A,C
        ADD    A,4
        LD    (DUMPTOT),A

CHEWS        PUSH    HL

        SRL    D
        SRL    D
        SRL    D
        SRL    D
        RR    E
        SRL    D
        RR    E
        SRL    D
        RR    E
        LD    A,D
        ADD    A,>BACKSCREEN
        LD    D,A        ;DE=BACKSCREEN ADDR
        LD    A,B
        ADD    A,A
        ADD    A,<CHEWJP
        LD    L,A
        LD    H,>CHEWJP
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        JP    (HL)

;---------------------------------------------------------------------------

CHEWUP        POP    HL
        LD    B,>UTL
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHU0
        XOR    A
CHU0        ADD    A,<UTL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E

        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHU1
        XOR    A
CHU1        ADD    A,<UTR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        LD    A,E
        ADD    A,32-1
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A

        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHU2
        XOR    A
CHU2        ADD    A,<UBL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E

        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHU3
        XOR    A
CHU3        ADD    A,<UBR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        RET

;---------------------------------------------------------------------------

CHEWRT        POP    HL
        LD    B,>RTL
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHR0
        XOR    A
CHR0        ADD    A,<RTL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHR1
        XOR    A
CHR1        ADD    A,<RTR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        LD    A,E
        ADD    A,32-1
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHR2
        XOR    A
CHR2        ADD    A,<RBL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHR3
        XOR    A
CHR3        ADD    A,<RBR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        RET

;---------------------------------------------------------------------------

CHEWDW        POP    HL
        LD    B,>DTL
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHD0
        XOR    A
CHD0        ADD    A,<DTL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHD1
        XOR    A
CHD1        ADD    A,<DTR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        LD    A,E
        ADD    A,32-1
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHD2
        XOR    A
CHD2        ADD    A,<DBL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHD3
        XOR    A
CHD3        ADD    A,<DBR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        RET

;---------------------------------------------------------------------------

CHEWLT        POP    HL
        LD    B,>LTL
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHL0
        AND    3
        XOR    A
CHL0        ADD    A,<LTL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHL1
        XOR    A
CHL1        ADD    A,<LTR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        LD    A,E
        ADD    A,32-1
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHL2
        XOR    A
CHL2        ADD    A,<LBL
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        INC    E
        LD    (HL),E
        INC    L
        LD    (HL),D
        INC    L
        LD    A,(DE)
        SUB    CH
        JR    NC,CHL3
        XOR    A
CHL3        ADD    A,<LBR
        LD    C,A
        LD    A,(BC)
        LD    (HLI),A
        LD    (DE),A
        RET

;***************************************************************************
;DUMP DOWN CHRS ON FLYBACK...

CHRDUMPER    LD    A,(DUMPTOT)    ;ANY CHRS TO DUMP?
        OR    A
        RET    Z
        LD    B,A
        XOR    A
        LD    (DUMPTOT),A
        LD    HL,CHRDUMP
        LD    C,>DISPSCREEN^>BACKSCREEN
CDUMP        LD    E,(HL)
        INC    L
        LD    A,(HLI)
        XOR    C
        LD    D,A
        LD    A,(HLI)
        LD    (DE),A
        DEC    B
        JR    NZ,CDUMP
        RET

;***************************************************************************
;PRINT ONE CHR EVERY LOOP...

PRSCORE        LD    A,(LETCOW)
        OR    A
        JP    NZ,COPYLETTER

        LD    A,(SPEEDFLAG)
        AND    7
        ADD    A,A
        ADD    A,A
        ADD    A,<STATNUM
        LD    L,A
        LD    H,>STATNUM
        LD    E,(HL)
        INC    L
        LD    D,(HL)        ;DE=SCRN
        INC    L
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A        ;HL=CHR PNTR
        LD    A,(HL)
        LD    (DE),A
        RET

;L=UNIT OFFSET (0TO6) H=CHR TO ADD (0TO9)...

SCOREADD    PUSH    DE
        LD    A,L        ;ADD TO MAIN SCORE
        ADD    A,<REALSCORE
        LD    L,A
        LD    E,A
        LD    D,H
        LD    A,D
        LD    H,>REALSCORE
        CALL    UPSCORE        ;AND TO LEVEL SCORE
        LD    A,(TALLOFF)
        ADD    A,6
        ADD    A,E
        LD    L,A
        LD    A,D
        POP    DE

UPSCORE        ADD    A,(HL)
        CP    "9"+1
        JR    C,NOSCRP
        SUB    10
        LD    (HLD),A
        LD    A,1
        JR    UPSCORE
NOSCRP        LD    (HL),A
        RET

CLOCK        LD    A,(FRAMES)
        INC    A
        LD    (FRAMES),A
        CP    60
        RET    NZ
        XOR    A
        LD    (FRAMES),A
        LD    A,(TALLOFF)
        ADD    A,<TIMER
        LD    L,A
        LD    H,>TIMER
        CALL    UPCLOCK
        LD    L,<TIMERTOTAL
UPCLOCK        INC    (HL)
        RET    NZ
        INC    L
        INC    (HL)
        RET

;***************************************************************************
;DRAW THE STATUS LINE...

STATUS        LD    HL,STATLINE
        LD    DE,STATSCREEN
        CALL    PRINTSHAPE
    ;    LD    HL,PAUSETEXT
    ;    CALL    PRINTEXT

        CALL    CHECKHIGH
        CALL    PRHIGHSCORES        ;JOFFA

        LD    HL,STATSCREEN+18
        LD    A,(LEVEL)
        INC    A
        JP    PRDECDIGITS

;***************************************************************************
;WORK STATUS LINE SPRITES...

STATSP        LD    HL,STATUSOBJ    ;OBJ VARS
        LD    DE,EXTRATAB
        LD    A,(SPEEDFLAG)
        SRL    A
        SRL    A
        LD    C,A
        LD    A,(WY)
        ADD    A,16+1        ;Y OFFSET
        LD    B,A
        LD    A,5

PUTSSP        PUSH    AF
        LD    A,(DE)
        ADD    A,C
        AND    3
        ADD    A,B
        LD    (HLI),A        ;YNO
        INC    E
        LD    A,(DE)
        LD    (HLI),A        ;XNO
        INC    E
        LD    A,(DE)
        LD    (HLI),A        ;GNO
        INC    E
        LD    A,(DE)
        LD    (HLI),A        ;FLG
        INC    E
        POP    AF
        DEC    A
        JR    NZ,PUTSSP

        PUSH    HL
        LD    HL,EXBONSP
        LD    C,(HL)        ;TYP
        INC    L
        LD    A,(HLI)        ;YNO
        ADD    A,8
        LD    E,A

        LD    A,C        ;STOPS STUPID BUG!
        CP    TEXWALK
        JR    C,ONSTAT
        LD    E,-16

ONSTAT        LD    D,(HL)        ;XNO
        INC    L
        LD    A,(HL)        ;GNO
        POP    HL
         PUSH    HL        ;KEEP HERE!
        JP    DUMP2BY2S

;*****************************************************************************
;DRAW THE BACKGROUND SCREEN...

DRAWMAP        LD    HL,DISPSCREEN
        LD    BC,32*32
FILLMAP        PUSH    BC        ;FILL MAP WITH GRAVEL!
        PUSH    HL
        CALL    RAND
        POP    HL
        POP    BC
        LD    A,(RND2)
        SWAP    A
        AND    $F
        LD    (HLI),A
        DEC    BC
        LD    A,B
        OR    C
        JR    NZ,FILLMAP

        LD    HL,BYTESCREEN    ;CLEAR BYTE SCREEN
FILLBYTE    LD    (HLI),A
        DEC    B
        JR    NZ,FILLBYTE

        LD    A,(MAP)
        ADD    A,A
        ADD    A,<LEVTAB
        LD    L,A
        LD    H,>LEVTAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A

        LD    DE,MRDOSP+YNO
        LD    A,(HLI)        ;MRDO Y
        LD    (DE),A
        INC    E
        LD    A,(HLI)        ;MRDO X
        LD    (DE),A
        INC    E
        LD    A,$06        ;GRAPHIC
        LD    (DE),A
        INC    E
        LD    A,$01        ;DIRECTION
        LD    (DE),A
        LD    A,TCBALL    ;CARRY BALL
        LD    (MRBALLSP+TYP),A

        LD    D,(HL)        ;TUNNEL Y,X
        INC    HL
        LD    E,(HL)
        INC    HL
        CALL    DOTUNNEL    ;DRAW TUNNEL
        CALL    ENDTUNNEL    ;DRAW END AND CHERRIES
        PUSH    HL
        CALL    COPYMAP        ;COPY MAP WITHOUT APPLES/FOOD
        POP    HL
        CALL    PUTAPPLES    ;DRAW APPLES

PUTFOOD        LD    D,(HL)
        INC    HL
        LD    E,(HL)
        INC    HL
        LD    A,(HL)
        PUSH    AF
        PUSH    DE
        LD    C,<FOOD
        LD    A,4
        CALL    DRAWBLOCK
        POP    HL
        CALL    GETMAPLO
        POP    AF
        ADD    A,A
        ADD    A,A
        LD    C,A
        PUSH    AF
        PUSH    AF
        PUSH    AF
        JR    DRWBLOCK

;---------------------------------------------------------------------------

;PLACE ITEM 'A' ONTO BYTE MAP SCREEN...

DRAWBLOCK    PUSH    HL
        PUSH    AF
        LD    L,E
        LD    H,D
        CALL    GETBYTELO
        POP    AF
        LD    (HL),A
        PUSH    BC
        PUSH    DE
        LD    L,E
        LD    H,D
        CALL    LOWAD        ;HL=SCRN  ADDR

DRWBLOCK    LD    B,>BLOCKS    ;BC=BLOCK ADDR
        LD    A,(BC)
        LD    (HLI),A
        INC    C
        LD    A,(BC)
        LD    (HLI),A
        INC    C
        LD    A,L
        ADD    A,32-2
        LD    L,A
        ADC    A,H
        SUB    L
        LD    H,A
        LD    A,(BC)
        LD    (HLI),A
        INC    C
        LD    A,(BC)
        LD    (HL),A
        POP    DE
        POP    BC
        POP    HL
        RET

;---------------------------------------------------------------------------

DOTUNNEL    LD    A,(HLI)        ;START BLOCK NUMBER
        CP    -1
        RET    Z
        ADD    A,A
        ADD    A,A
        LD    C,A
        LD    A,1
        CALL    DRAWBLOCK    ;DRAW START BLOCK

        LD    A,(HLI)        ;DIRECTION 0TO4
        ADD    A,A
        LD    B,A
        ADD    A,A
        LD    C,A        ;C=BLOCK ADDR LOW
        LD    A,<VECTAB2
        ADD    A,B
        LD    B,A        ;B=VECTOR TABLE ADDR LOW
        LD    A,(HLI)        ;GET LENGTH

        PUSH    HL
        LD    H,>VECTAB2
DRAWREP        PUSH    AF
        LD    L,B
        LD    A,(HLI)        ;MOVE TO NEXT POS
        ADD    A,E
        LD    E,A
        LD    A,(HL)
        ADD    A,D
        LD    D,A
        LD    A,1
        CALL    DRAWBLOCK    ;DRAW REPEAT BLOCK
        POP    AF
        DEC    A
        JR    NZ,DRAWREP
        POP    HL
        JR    DOTUNNEL

ENDTUNNEL    LD    A,(HLI)        ;END BLOCK NUMBER
        ADD    A,A
        ADD    A,A
        LD    C,A
        LD    A,1
        CALL    DRAWBLOCK

PUTCHERRY    LD    A,(HLI)
        CP    -1
        RET    Z
        LD    D,A
        LD    E,(HL)
        INC    HL
        LD    C,<CHERRY
        LD    A,2
        CALL    DRAWBLOCK
        INC    E
        INC    E
        LD    A,2
        CALL    DRAWBLOCK
        INC    D
        INC    D
        LD    A,2
        CALL    DRAWBLOCK
        DEC    E
        DEC    E
        LD    A,2                                                                              
        CALL    DRAWBLOCK
        LD    A,(CHERRYTOT)
        ADD    A,4
        LD    (CHERRYTOT),A
        JR    PUTCHERRY

PUTAPPLES    LD    BC,APPLESP

PUTAPPLE    LD    A,(HLI)
        CP    -1
        RET    Z

        LD    D,A
        LD    A,TAPPW        ;APPLE WAIT
        LD    (BC),A        ;TYP
        INC    C
        LD    A,D
        LD    (BC),A        ;YNO
        INC    C
        LD    A,(HLI)
        LD    E,A
        LD    (BC),A        ;XNO
        INC    C
        PUSH    BC
        LD    C,<APPLE
        LD    A,3
        CALL    DRAWBLOCK
        POP    BC
        LD    A,AP0
        LD    (BC),A        ;GNO
        INC    C
        XOR    A
        LD    (BC),A        ;FLG
        INC    C
        JR    PUTAPPLE

;***************************************************************************

COPYMAP        LD    HL,DISPSCREEN
        LD    DE,BACKSCREEN
        LD    BC,32*32
COPYM        LD    A,(HLI)
        LD    (DE),A
        INC    DE
        DEC    BC
        LD    A,B
        OR    C
        JR    NZ,COPYM
        RET

****************************************************************************
;COPY A CHR INTO THE EXTRA BONUS SPRITES...
;LETCOW=8 LETLOW=<CHR TO COPY (TAKES 8 FRAMES)
 
COPYLETTER    LD    B,A
        DEC    A
        LD    (LETCOW),A
        LD    A,8
        SUB    B
        ADD    A,A
        LD    B,A        ;POINTER
        LD    A,(LETLOW)
        LD    E,A
        LD    D,>LETTERHI    ;DE=LETTER GRAPHIC
        ADD    A,2
        LD    (LETLOW),A

        LD    A,B        ;PLACE INTO ALL 3 GRAPHICS...
        ADD    A,<EXPHS0
        LD    L,A
        LD    H,>EXPHS0
        CALL    PUTLINE
        LD    A,B
        ADD    A,<EXPHS1
        LD    L,A
        LD    H,>EXPHS1
        CALL    PUTLINE
        LD    A,B
        ADD    A,<EXPHS2
        LD    L,A
        LD    H,>EXPHS2

PUTLINE        LD    A,(DE)        ;DO LEFT SIDE
        AND    %11110000
        SWAP    A
        LD    C,A
        LD    A,(HL)
        AND    %11110000
        OR    C
        LD    (HLI),A
        INC    E
        LD    A,(DE)
        AND    %11110000
        SWAP    A
        LD    C,A
        LD    A,(HL)
        AND    %11110000
        OR    C
        LD    (HL),A
        LD    A,L
        ADD    A,32
        LD    L,A
        ADC    A,H
        SUB    L
        LD    H,A
        LD    A,(DE)        ;DO RIGHT SIDE
        AND    %00001111
        SWAP    A
        LD    C,A
        LD    A,(HL)
        AND    %00001111
        OR    C
        LD    (HLD),A
        DEC    E
        LD    A,(DE)
        AND    %00001111
        SWAP    A
        LD    C,A
        LD    A,(HL)
        AND    %00001111
        OR    C
        LD    (HL),A
        RET

;***************************************************************************

KEYS        LD    A,$20        ;READ CURSOR PAD
        LD    (PORT),A
        LD    A,(PORT) 
        LD    A,(PORT) 
        CPL
        AND    %1111
        SWAP    A
        LD    C,A
        LD    A,$10
        LD    (PORT),A
        LD    A,(PORT)
        LD    A,(PORT)
        LD    A,(PORT)
        LD    A,(PORT)
        LD    A,(PORT)
        LD    A,(PORT)
        CPL
        AND    %1111
        ADD    A,C
        LD    C,A
        LD    (KEYPRESS),A
        LD    A,$30
        LD    (PORT),A
        LD    A,C
        RET

;*****************************************************************************
;SCREEN ADDR ROUTINES...

PIXAD        SRL    H
        SRL    H
        SRL    H
        SRL    H
        RR    L
        SRL    H
        RR    L
        SRL    H
        RR    L
        LD    A,H
        ADD    A,>DISPSCREEN
        LD    H,A
        RET

GETMAPHI    SRL    H
        SRL    H
        SRL    H
        SRL    H
        RR    L
        SRL    H
        RR    L
        SRL    H
        RR    L
        LD    A,H
        ADD    A,>BACKSCREEN
        LD    H,A
        RET

GETMAPLODE    SRL    D
        RRA
        SRL    D
        RRA
        SRL    D
        RRA
        AND    %11100000
        ADD    A,E
        LD    E,A
        LD    A,D
        ADD    A,>BACKSCREEN
        LD    D,A
        RET

GETMAPLO    SRL    H
        RRA
        SRL    H
        RRA
        SRL    H
        RRA
        AND    %11100000
        ADD    A,L
        LD    L,A
        LD    A,H
        ADD    A,>BACKSCREEN
        LD    H,A
        RET

GETBYTEHI    LD    A,L
        SWAP    A
        AND    %00001111
        LD    L,A
        LD    A,H
        AND    %11110000
        ADD    A,L
        LD    L,A
        LD    H,>BYTESCREEN
        RET

GETBYTELO    LD    A,H
        SRL    A
        SWAP    A
        SRL    L
        ADD    A,L
        LD    L,A
        LD    H,>BYTESCREEN
        RET

LOWAD        SRL    H
        RRA
        SRL    H
        RRA
        SRL    H
        RRA
        AND    %11100000
        ADD    A,L
        LD    L,A
        LD    A,H
        ADD    A,>DISPSCREEN
        LD    H,A
        RET

;*****************************************************************************

WAITBLANK    LD    A,144
WAITSYNC    LD    (LYC),A
WAITSC        LD    A,(STAT)
        BIT    2,A
        JR    Z,WAITSC
        RET

;*****************************************************************************

RESETOBJ    LD    HL,OBJDATA
        CALL    RESETOB
        LD    HL,GAMEOBJ
        CALL    RESETOB
        LD    HL,STATUSOBJ
RESETOB        LD    B,40
        LD    A,8*31
RESETO        LD    (HLI),A
        LD    (HLI),A
        LD    (HL),0
        INC    L
        LD    (HL),0
        INC    L
        DEC    B
        JR    NZ,RESETO
        RET

;*****************************************************************************

RAND        LD    HL,RND1
        LD    A,(HLI)
        LD    E,A
        LD    A,(HLI)
        LD    D,A
        LD    A,(DIV)
        XOR    (HL)
        XOR    E
        XOR    D
        RLCA
        RLCA
        RLCA
        SRL    E
        SRL    D
        LD    (HL),D
        DEC    L
        LD    (HL),E
        DEC    L
        LD    (HL),A
        RET

;***************************************************************************
;TEXT ROUTINES...

;HL=STRING

PRINTEXT    LD    A,(HLI)        ;LENGTH
        OR    A
        RET    Z
        LD    B,A
        LD    E,(HL)        ;DE=SCRN ADDR
        INC    HL
        LD    D,(HL)
        INC    HL
TEXTL        LD    A,(HLI)        ;0=EXIT
        LD    (DE),A
        INC    E
        DEC    B
        JR    NZ,TEXTL
        JR    PRINTEXT

;HL=DATA DE=SCRN ADDR

PRINTSHAPE    LD    C,(HL)        ;XSIZE
        INC    HL
        LD    B,(HL)        ;YSIZE
        INC    HL
YROWS        PUSH    BC
        PUSH    DE
XROWS        LD    A,(HLI)
        LD    (DE),A
        INC    E
        DEC    C
        JR    NZ,XROWS
        POP    DE
        POP    BC
        LD    A,E
        ADD    A,$20
        LD    E,A
        ADC    A,D
        SUB    E
        LD    D,A
        DEC    B
        JR    NZ,YROWS
        RET

;***************************************************************************

;DIVIDE HL/BC (BC MUST BE NEGATIVE!) RETS BC=RESULT HL=REMAINDER

DIVIDE        PUSH    DE
        LD    DE,-1
DIVE        INC    DE
        ADD    HL,BC
        JR    C,DIVE
        LD    C,E
        LD    B,D
        POP    DE
        RET

;***************************************************************************

CREATESET    LD    E,(HL)        ;DE=DEST
        INC    HL
        LD    A,(HLI)
        LD    D,A
        OR    E
        RET    Z
        LD    C,(HL)        ;BC=LEN
        INC    HL
        LD    B,(HL)
        INC    HL
        LD    A,(HLI)
        PUSH    HL
        LD    H,(HL)
        LD    L,A
        CALL    SHUNT
        POP    HL
        INC    HL
        JR    CREATESET

CLEARSET    LD    HL,OBJSET
        LD    DE,OBJSET+1
        LD    BC,$1800-1
        LD    (HL),0
SHUNT        LD    A,(HLI)
        LD    (DE),A
        INC    DE
        DEC    BC
        LD    A,B
        OR    C
        JR    NZ,SHUNT
        RET

;***************************************************************************

;VARIABLE DISPLAY ROUTINES...

DISPBIN        LD    HL,STATSCREEN+32
        LD    B,8
DOBIN        LD    (HL),"0"
        RLCA
        JR    NC,ISNONE
        LD    (HL),"1"
ISNONE        INC    L
        DEC    B
        JR    NZ,DOBIN
        RET

;*****************************************************************************

CLEARSTAT    LD    HL,STATSCREEN
        JR    CLEARS

CLEARDISP    LD    HL,DISPSCREEN

CLEARS        LD    BC,32*32
CLR        LD    (HL),$FF
        INC    HL
        DEC    BC
        LD    A,B
        OR    C
        JR    NZ,CLR
        RET

;*****************************************************************************

HEXBYTE        LD    HL,STATSCREEN+$20+19
        JR    PRHEX

HEXWORD        LD    A,H
        PUSH    AF
        LD    A,L
        LD    HL,STATSCREEN+$20+19
        CALL    PRHEX
        POP    AF

PRHEX        LD    C,A
        AND    $F
        ADD    A,<HEXTAB
        LD    E,A
        LD    D,>HEXTAB
        LD    A,(DE)
        LD    (HLD),A
        LD    A,C
        SWAP    A
        AND    $F
        ADD    A,<HEXTAB
        LD    E,A
        LD    A,(DE)
        LD    (HLD),A
        RET

PRDEC        LD    HL,STATSCREEN
        LD    C,100
        CALL    PRDEC0
PRDECDIGITS    LD    C,10
        CALL    PRDEC0
        ADD    A,"0"
        LD    (HL),A
        RET

PRDEC0        LD    B,"0"-1
PRDEC1        INC    B
        SUB    C
        JR    NC,PRDEC1
        ADD    A,C
        LD    (HL),B
        INC    L
        RET

;*****************************************************************************
;SET TABLES...

GAMESETAB    DEFW    "0"*$10+BGSET,$2C0,CASCII    ;ASCII CHR
        DEFW    BGSET,$290,CGRND0        ;BACKGROUND CHR
        DEFW    AP0*$10+BGSET,$1C0,CAPPLES    ;APPLE CHR
        DEFW    BALL1G*$10+OBJSET,$90,CBALLS    ;BALLS/500/EXTRA OBJ
        DEFW    OBJSET+$300,$6A0,CBADS        ;BADDIE OBJ
        DEFW    0

MENUSETAB    DEFW    "0"*$10+BGSET,$2C0,CASCII    ;ASCII CHR
        DEFW    OBJSET,$1A0,CSTAR        ;STAR/HAND OBJ
        DEFW    OBJSET+$300,$40,CBLOB        ;BLOB OBJ
        DEFW    BGSET+$000,$1C0,CHEADS        ;HEAD CHR
        DEFW    BGSET+$5C0,$180,CICONS        ;ICON CHR
        DEFW    OBJSET+$800,$730,CLOGO        ;LOGO CHR
        DEFW    0

BOARDTAB    DEFW    BGSET,$120,CBIGAPPLES        ;BIGAPPLE CHR
        DEFW    OBJSET,$6C0,CBIGMRDO        ;BIG MRDO ETC OBJ
        DEFW    OBJSET+$6C0,$140,CFINI        ;END LEVEL OBJ
        DEFW    0

MENUTEXT    DEFB    5
        DEFW    $0B*$20+STATSCREEN+$08
        DEFB    "CLONE",5
        DEFW    $0D*$20+STATSCREEN+$08
        DEFB    "TWINS",5
        DEFW    $0F*$20+STATSCREEN+$08
        DEFB    "REMIX",12
        DEFW    $13*$20+STATSCREEN+$04
        DEFB    "SKILL OPTION",12
        DEFW    $1B*$20+STATSCREEN+$04
        DEFB    "AUDIO OPTION",16

        DEFW    $1E*$20+STATSCREEN+$02
        HEX    5C5D5E5FFFFF64656667FFFF6C6D6E6F10
        DEFW    $1F*$20+STATSCREEN+$02
        HEX    60616263FFFF68696A6BFFFF7071727300

STATLINE    DEFB    20,03
        HEX    FF53434F52455BFFFFFFFFFFFF5B4D4150FFFFFF
        HEX    FFFFFFFFFFFF5BFFFFFFFFFFFF5B3C3C3CFFFFFF
        HEX    3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E3E

BIGAPPLE1    DEFB    03,03
        HEX    000102030405060708
BIGAPPLE2    DEFB    03,03
        HEX    090A0B0C0D0E0F1011

PAUSETEXT    DEFB    6
        DEFW    $20*9+STATSCREEN+7
        DEFB    "PAUSED",0

RESTEXT        DEFB    10
        DEFW    09*$20+DISPSCREEN+5
        DEFB    "VERY",$FF,"GOOD:",0

AVRTEXT        DEFB    5
        DEFW    05*$20+DISPSCREEN+0
        DEFB    "TOTAL",7
        DEFW    07*$20+DISPSCREEN+0
        DEFB    "AVERAGE",10
        DEFW    12*$20+DISPSCREEN+5
        DEFB    "WONDERFUL:",0

SCENE1        HEX    D8580208        ;MRDO Y,X,TUNNEL Y,X
        DEFB    $07,1,05,$09,2,01    ;BLOCK,DIR,LEN
        DEFB    $0B,1,01,$09,2,01
        DEFB    $0B,1,01,$09,2,08
        DEFB    $0A,3,01,$08,2,01
        DEFB    $0A,3,01,$08,2,01
        DEFB    $0A,3,09,$0B,0,02
        DEFB    $08,1,02,$09,2,02
        DEFB    $0E,1,03,$0E,0,12,-1,$0C     ;END,BLOCK
        HEX    02000600060C0610        ;C
        HEX    08060C06120012040E101210FF
        HEX    020406080C040A100814120EFF    ;A
        HEX    0E0A00                ;F

SCENE2        HEX    D8580800
        DEFB    $06,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,07
        DEFB    $09,2,01,$0B,1,01
        DEFB    $09,2,01,$0B,1,01
        DEFB    $09,2,04,$0A,3,01
        DEFB    $08,2,01,$0A,3,05
        DEFB    $0F,2,01,$0A,3,02
        DEFB    $08,2,01,$0A,3,02
        DEFB    $08,2,01,$0A,3,01
        DEFB    $08,2,02,$0B,1,11,-1,$05
        HEX    0604060808100C10        ;C
        HEX    0C001000121416141408140CFF
        HEX    0406080E08140A020A0E120CFF    ;A
        HEX    0E0A04                ;F

SCENE3        HEX    D8580800
        DEFB    $06,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,07
        DEFB    $09,2,01,$0B,1,01
        DEFB    $09,2,01,$0B,1,01
        DEFB    $09,2,04,$0A,3,01
        DEFB    $08,2,01,$00,3,06
        DEFB    $07,1,01,$0E,1,05
        DEFB    $0D,2,01,$0B,1,01
        DEFB    $09,2,03,$0A,3,01
        DEFB    $08,2,01,$0A,3,09
        DEFB    $0B,0,01,$09,3,01
        DEFB    $0B,0,01,-1,$04
        HEX    0806080A08100C10        ;C
        HEX    0A000E0012061606140E1412FF
        HEX    0606060C08020C08120C1212FF    ;A
        HEX    0E0A04                ;F

SCENE4        HEX    D8581A0A
        DEFB    $07,1,04,$0A,0,12
        DEFB    $09,3,05,$08,2,03
        DEFB    $0A,3,01,$08,2,02
        DEFB    $0A,3,01,$08,2,02
        DEFB    $0F,1,03,$0A,3,03
        DEFB    $0F,2,01,$0A,3,02
        DEFB    $08,2,02,$0B,1,09
        DEFB    $13,1,02,-1,$05
        HEX    040004040A000E00        ;C
        HEX    0A0E0E0E06140A1418021806FF
        HEX    0202060A08100C0C0E141208FF    ;A
        HEX    0E0A04                ;F

SCENE5        HEX    D8580216
        DEFB    $05,3,11,$08,2,05
        DEFB    $0B,1,04,$0C,1,01
        DEFB    $0C,2,01,$00,3,01
        DEFB    $0F,2,01,$0B,1,01
        DEFB    $0E,1,01,$0A,0,01
        DEFB    $0D,0,01,$0C,1,04
        DEFB    $09,2,01,$0B,1,01
        DEFB    $09,2,05,$0A,3,01
        DEFB    $08,2,01,$0A,3,09
        DEFB    $0B,0,01,$09,3,01
        DEFB    $0B,0,01,-1,$04
        HEX    0604060808100814        ;C
        HEX    100214021408140C10121412FF
        HEX    0602060C080C04140E101006FF    ;A
        HEX    0E0A13                ;F

SCENE6        HEX    D8580216
        DEFB    $05,3,09,$08,2,01
        DEFB    $0A,3,01,$08,2,01
        DEFB    $0A,3,01,$08,2,09
        DEFB    $0B,1,01,$09,2,01
        DEFB    $0B,1,09,$0A,0,01
        DEFB    $08,1,01,$0A,0,03
        DEFB    $09,3,01,$0B,0,01
        DEFB    $09,3,05,$0E,3,05
        DEFB    -1,$0F
        HEX    08040C04080A080E        ;C
        HEX    08140C1414021406160C1610FF
        HEX    0606040E061208121202140CFF    ;A
        HEX    0E0A04                ;F

SCENE7        HEX    D8581A0A
        DEFB    $06,0,05,$0F,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,01,$08,1,01
        DEFB    $0A,0,02,$09,3,11
        DEFB    $08,2,01,-1,$06
        HEX    06020A020808080C        ;C
        HEX    12001204120E160E0C141014FF
        HEX    04040408060810060E10040EFF    ;A
        HEX    0E0A04                ;F

SCENE8        HEX    D8580212
        DEFB    $09,3,07,$08,2,01
        DEFB    $0A,3,01,$08,2,01
        DEFB    $0A,3,01,$08,2,03
        DEFB    $0B,1,01,$09,2,01
        DEFB    $0B,1,01,$09,2,02
        DEFB    $0A,3,02,$08,2,03
        DEFB    $0B,1,01,$09,2,01
        DEFB    $0B,1,09,$0A,0,01
        DEFB    $08,1,01,$0A,0,03
        DEFB    $09,3,02,$0B,0,01
        DEFB    $01,3,07,$0F,1,03
        DEFB    $0E,1,04,$0D,0,01
        DEFB    $08,1,01,$0A,0,01
        DEFB    $08,1,01,$0A,0,03
        DEFB    $09,3,01,$0B,0,01
        DEFB    $09,3,01,-1,$0B
        HEX    06040A04060A0A0A        ;C
        HEX    06100A1014021406160C1610FF
        HEX    0802060804100A0E12081412FF    ;A
        HEX    0E0A04                ;F

SCENE9        HEX    D8581A00
        DEFB    $07,1,09,$0A,0,01
        DEFB    $08,1,01,$0A,0,01
        DEFB    $08,1,01,$0A,0,08
        DEFB    $09,3,01,$0B,0,01
        DEFB    $09,3,01,$0B,0,01
        DEFB    $09,3,07,$08,2,01
        DEFB    $0A,3,01,$08,2,01
        DEFB    $0A,3,01,$08,2,04
        DEFB    $0B,1,01,$09,2,01
        DEFB    $0B,1,04,$0E,1,06,-1,$0D
        HEX    08040C04060A060E        ;C
        HEX    0C0E0C1212001600140C1410FF
        HEX    04080608060406120A101208FF    ;A
        HEX    0E0A04                ;F

SCENE10        HEX    D8580402
        DEFB    $08,2,01,$0A,3,01
        DEFB    $08,2,08,$0B,1,01
        DEFB    $09,2,01,$0B,1,01
        DEFB    $09,2,01,$0B,1,07
        DEFB    $0A,0,02,$09,3,01
        DEFB    $0B,0,01,$09,3,01
        DEFB    $0B,0,01,$09,3,02
        DEFB    $0B,0,04,$09,3,01
        DEFB    $0B,0,01,$09,3,01
        DEFB    $0B,0,01,$09,3,01
        DEFB    $0B,0,01,$0D,0,01
        DEFB    $08,1,07,$09,2,01
        DEFB    $0B,1,01,$09,2,01
        DEFB    $0B,1,01,$09,2,08
        DEFB    $0A,3,01,$08,2,01,$0A,3,01,-1,$0F
        HEX    0C020C06080C0810        ;C
        HEX    0E121212120212061608160CFF
        HEX    040C04100A0410060E10140CFF    ;A
        HEX    0E0A00                ;F

;***************************************************************************

LOGO        DEFB    18,08
        HEX    808182838485868788898A86868686868B8C
        HEX    8D8E8F9091929394959697989999999A9B8C
        HEX    9C9D9E9FA0A1A2A3A4A5A6A7A8A9A9AAABAC
        HEX    ADAEAFB0B1B2B3B4B5B6B7B8B9BAA9BBBCBD
        HEX    BEBFC0C1C2C3C4C5B5B6C6C7C8C9CACBCCCD
        HEX    CECFA9A9A9A9A9D0B5D1D2D3D4D5D6D7D8D9
        HEX    DADBDCDCDCDCDDDEDFF2E0E1E2E3E4E5E68C
        HEX    8C8C8C8C8C8CE7E8E9EAEBECEDEEEFF0F18C

CLOGO        HEX    00000000000000000100030107030E07
        HEX    03030F0F1C1F333CACF0E8F050E0D3E3
        HEX    E0E0F8F81CFCE61E1B070B070503E5E3
        HEX    03030F0F1C1F333CEC70E8F0D0E0D1E1
        HEX    F0F0FCFC0EFEF30F0D0305030201F2F1
        HEX    0000000000000000FFD5FFFFC0FFF0E0
        HEX    0000000000000000FF55FFFF00FF0000
        HEX    0000000000000303FF57FCFF1BFC7438
        HEX    00001F1FFFFFE0FF1FE0E00000000000
        HEX    0000C0C0FCFC3FFFC33F3C0303000000
        HEX    0000000000008080FFF5FFFF3CFFCF3E
        HEX    0000000000000000F850FCF80EFC071E
        HEX    00000000000000000000000000000000
        HEX    0D0F0D070F0F0F070F0F0E070E0F0E0F
        HEX    A7C7A7C74F8F4F8F4F8F9F1F9F1F9F1F
        HEX    F2F1F2F1FAF9F9F8FCFCFCFCFEFE7E7E
        HEX    A3C3A3C3A7C7478787070F0F0F0F1F1F
        HEX    F9F8FDFCFDFCFCFCFEFEFEFEFEFEBFBF
        HEX    7FFF7FEA7FF7BF7FB87F573828101000
        HEX    FFFFFFAAFFD5FFEF7FFFB87F47383800
        HEX    F4F8E8F0E9F1D3E3A3C3438383030101
        HEX    1F1FFFFFFFFFFFFFFFFFFFFFFFFFFFFF
        HEX    C0C0FCFCFFFFFFFFFFFFFFFFFFFFFFFF
        HEX    330F0D030201C1C0E0E0F0F0F8F8FCFC
        HEX    FFFFFFAAFFD57FEABF755F3A2F1D2F1E
        HEX    FFFFFFAAFF55FFAAFF55FFAAFF55FFAA
        HEX    FFFFFFAAF654FBAAFD55F9A8FD55FEAA
        HEX    C3CFE3A673577336F357F3B6F357F3B6
        HEX    0D0E0D0E1D1E1A1C1A1C1A1C1A1C3438
        HEX    3F3F3F3F3F3F7E7E7E7E7E7E7E7EFCFC
        HEX    7E7E7F7F3F3F3F3F1F1F1F1F0F0F0F0F
        HEX    1F1F1F1F3F3FBFBFBFBFFEFEFEFEFEFE
        HEX    BFBFBFBF1F1F1F1F1F1F0F0F0F0F0F0F
        HEX    03030707878787878787C7C7C7C7C7C7
        HEX    8080C7C7DFDFFFFFFFFFF3F3E1E1C0C0
        HEX    0000E0E0F0F0F8F8F8F8F8F8F0F00000
        HEX    7F7F1F1F1F1F1F1F1F1F1F1F1F1F1F1F
        HEX    FFFFFFFFF3F3E1E1E0E0E0E0E0E0E0E0
        HEX    FEFEFFFFFFFFFFFFFFFF7F7F7F7F3F3F
        HEX    170F170E0B078B878583C5C3C2C1E2E1
        HEX    FF55FFAAFF55FFAAFFD5FFAAFFD5FFEA
        HEX    FF55FFAAFF55FFAAFF55FFAAFF55FFAA
        HEX    FF55FFAAFF55FFAAFF55FFABFE57FDAE
        HEX    FF57DFBFBE7FF1FECEF030C0C0000101
        HEX    C0E0F8F83CFCCE3E360E170E0B070B87
        HEX    34383438697169716971D3E3D3E3D9E1
        HEX    FCFCFCFCF9F8F9F8FAF9F2F1F5F3E5E3
        HEX    4707A74753E36BF3F5F9F5F9FADCFABC
        HEX    FCFCFCFCFCFCF9F8F9F8FAF9F2F10503
        HEX    07074707A74753E353E3E9F1E9F1F4B8
        HEX    E7E7E7E7E7E7F7F7F7F7FFFFFFFFF3F3
        HEX    C0C0C0C0C0C0C0C0C0C0C3C3C7C7A787
        HEX    00000000000000000000C0C0E0E0E0E0
        HEX    1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F1F
        HEX    E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0
        HEX    3F3F1F1F1F1F1F1F0F0F0F0F0F0F0F0F
        HEX    E2E1E1E0F1F0F1F0F1F0F1F0F2F1F2F1
        HEX    FFD57FEA7FF57FEA7FF57FEFFFFFE0FF
        HEX    FF55FFAAFF55FFAAFF55FFFAFFFD0FFF
        HEX    FA5CF4B8F478E8F0E870D0E0D0E0D0E0
        HEX    07070F0F1F1F3F3F3F3F7F7F7E7EFEFE
        HEX    8B878B878B870B87160E160E160E160E
        HEX    E6F8797E1E1F0F0F0D0F0D0E0C060C0E
        HEX    0B07FB0707FFFFFEFFFDFFAAFFD5FFAA
        HEX    FD5EFDAEFE57FFABFF55FFAAFF55FFAA
        HEX    0703FA0707FFFFFEFFFDFFAAFF55FFAA
        HEX    F478FBBCFC5FFFAFFF57FFAAFF55FFAA
        HEX    1C00E31C1CFFFFFFFFF7FFAAFF55FFAA
        HEX    5727AF7373FCFCFFFFDFFFABFF55FFAA
        HEX    E0E0C0C0F0000CF0F2FCFAFCFD5EFDAE
        HEX    0F0F0F0F0F0F0F0F0F0F0F0F0F0F1F1F
        HEX    F1F0F0F0F0F0F0F0F0F0F0F0F1F1F3F3
        HEX    1FE0E00000000F0F3F3FFFFFFFFFFFFF
        HEX    F10F0E010100F0F0FCFCFFFFFFFFFFFF
        HEX    FFD57FEBBF755F3B2F1F170F8B87CBC7
        HEX    A0C0A1C1A1C1A3C34383438347874787
        HEX    FCFEFCFCFCFCF8F8F0F8F0F0E0E0C1C0
        HEX    2C1C2C1C2C1C58385838B878B07070F0
        HEX    0C060C0E0C060C0E0C060C0E0C060C0E
        HEX    FFD5FFAAFFD5FFAAFFD5FFAAFFD5FFAA
        HEX    FD5EFDAEFD5EFDAEFD5EFDAEFA5CF4B8
        HEX    E0E0E0E0E0E0E0E0E0E0E0E0F1F1FFFF
        HEX    1F1F1F1F3F3F3F3F7F7FFFFFFFFFFFFF
        HEX    E3E3E7E7E7E7CFCFCFCF8F8F8F8F0F0F
        HEX    FFFFFCFFFCF8F8F0E0F0E0F0E0F0F8F0
        HEX    FFFF3FFF3F1F1F0F070F070F070F1F0F
        HEX    CBC7E6E3E6E3F6F3F6F3F1F2F2F0F0F0
        HEX    478783078A0480008000010002010503
        HEX    8180020105031B07661F9F7F7BFEFBF7
        HEX    60E0E0E0C0C080800000000000000000
        HEX    0C060C0E0C060C0F0E07070303010100
        HEX    FFD5FFAA7F553F3F008000FFFFFFFFAA
        HEX    FF55FFAAFF55FFFF000000FFFFFFFFAA
        HEX    FF55FFAAFF55FFFF070303FFFFFFFFAB
        HEX    E870D0E0A1C14383438343834383A1C1
        HEX    1F1F7F7FFFFFFFFFFFFFFFFFFFFFFFFF
        HEX    FFFFFEFEFCFCF8F8F0F0E1E0C2C10503
        HEX    0707070703030303C10120C0D0E0ECF0
        HEX    FCF8FCFFFFFFFFFFFFFFFFFF3F3F0F0F
        HEX    3F1F3FFFFFFFFFFFFFFFFFFFFCFCF0F0
        HEX    E0E0E0E0C8C8CCCD878F0F0F3F3FFEFF
        HEX    0B07170E7F6DEFDFAEDCAE9FD7CFEBE7
        HEX    F3F6F3B7E366C3CF071E0EFCFCF8F850
        HEX    01010000000000000000000000000000
        HEX    A0C0D8E06678393E1E1F0F0F03030000
        HEX    FFFF1F1F0000E0001FE0E0FFFFFF3F3F
        HEX    FCFCC0C001003E01C13F3FFFFEFEE0C0
        HEX    0B07370FCE3E3CFCF0F0C0C000000000
        HEX    B3BC1C1F0F0F07070101000000000000
        HEX    0000E0001FE0E0FFFFFF3F3F00000000
        HEX    04000B04F40F0FFFFFFFF8FC00000000
        HEX    060EEC0614E6EDF0AAB13639111F0F1F
        HEX    152365038E7170FFFFFFEFFFC0C0C080
        HEX    00008080C0C0C0C0C0C0808000000000
        HEX    FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

CSTAR        HEX    00000000000000000000000000000000
        HEX    00001000281038102810100000000000
        HEX    10002810543854385438281010000000
        HEX    100038106C38D66C6C38381010000000
        HEX    6C10D638BA7C7CFEBA7CD6386C100000
        HEX    100028105438BA7C5438281010000000
        HEX    00001000281054382810100000000000
        HEX    00000000100028101000000000000000

CHAND        HEX    0000000007001F0738186830D665A7C2
        HEX    00000000C000F7E07F17381C38183B1C
        HEX    000000000000BC00FEBC4F4E0505B74D
        HEX    AECF96CFA3CFCC63D360E830F040A0C0
        HEX    4C3F9F5F10D8F0F433F4B87F5F3FB070
        HEX    4FFEFEF878603020B06030E0E0C080C0
        HEX    B1C8A5D8527D283F0F07000000000000
        HEX    60E867E870FF3FFFF8F0000000000000
        HEX    604060C0E0C0C0800000000000000000

        HEX    000000001E1C33233B776F47DF8ADF8E
        HEX    3C3C6666A6E61F9BCFC7BF2E1E042E1C
        HEX    000038384444E6A69E9A5EC67E0EFC1C
        HEX    8EC747E3486838703420746052605260
        HEX    2C185D38030093019201A403A403A403
        HEX    523CDE30AE70BEE67DCD7DD567F375E3
        HEX    50605060506050602830293016190F0F
        HEX    09071703810200000000FE00F0FFFF0F
        HEX    FDB3EDC3CF0F130E271CCE381CF0F8E0

CBLOB        HEX    07071E1F3C3F32336161696C656DE3E3
        HEX    E0E0B8787CBC4CCC86869636A6B6C7C7
        HEX    F7F6DDFEECFFF6FFEBFFF4FF7E7F1F1F
        HEX    ED6F7B3DE7396BF5C5FB0BF79EEEF8F8

CICONS        HEX    0F001F0F38187337EF6FDF5FDE5EEF6F
        HEX    DF00FFDF70708F87DFCFFDFFF8F9FDF8
        HEX    BC00FEBCE7E61B1BBDBDFBFBF1F1E4F6
        HEX    000000003800FC38EE6CDFD6BBBA7B7A
        HEX    6F2F773733173B1B190B1C0C0F070700
        HEX    FFFD9F3F8F8FD090DFDF3F31F1E0E000
        HEX    EEEEFEFFFFFFF7F76B6B9C9CFFF7F700
        HEX    77F6EEECDCD8D8D0B8B07060E0C0C000
        HEX    00000000637F63736273637F66736E77
        HEX    00003078F0FF90F8101810FF30187038
        HEX    0000010101FF0101416161FF43714763
        HEX    0000008080FE10DA109A00FE109A109A
        HEX    667F6E776670607F60706070607F0000
        HEX    30FF7038310000FF0100000000FF0000
        HEX    43FFC763C3E0C0FFC0E0C00000FF0000
        HEX    00FE109A101A00FE101A101A00FE0000
        HEX    4160637167734E664D6DCB6BCBEBEDE5
        HEX    EF00FFEF3838D7D7EFEFFDFDB8B8F8F8
        HEX    B800FCB84F4CB7B5F7F7E6E6E0E0EDED
        HEX    04040406C404ECCC302CD0D0D4D6D6D7
        HEX    CDE5C602161213191311313001300000
        HEX    FDFDDFFFEFCF61612D6D9E9EFFF3F300
        HEX    DDDDFBFBFFFFDEDEAEAE7171FFDEDF00
        HEX    B6A764466446CC86DC8E9E1E1C0E0C00

CHEADS        HEX    3E3E73736161656573732F3E7F615F7C
        HEX    7C7CE6E6C2C2D252E6E6BA7AC3438D0D
        HEX    5FFE5FEF6FF7377B1B3C7F678181FF7F
        HEX    DD1DFDFDFFF9FFF3FE06FEFA8181FFFE
        HEX    00003E3E73736565656573733F3E3739
        HEX    00007C7CE6E6D252D252E4E6BC7CCC44
        HEX    2F702F711F331F191F1C7F678181FF7F
        HEX    C682E2C2E4E4C8C89C1CFEFA8181FFFE
        HEX    1E1F3333292B212333331E1E26322C60
        HEX    F8FC9C9E4C4E0C0E9C9EF8FC98BC0C1E
        HEX    7F477F4F7E5D5F782F307F5F8181FF7F
        HEX    068FC6CFE6EFEC7E987CFEE68181FFFE
        HEX    1F3F39793272307039791F3F1B3D3778
        HEX    78F8CCCC94D484C4CCCC7878C44C8406
        HEX    6EF16FF367FF377E193E7F678181FF7F
        HEX    F2E2F2F27ABAFA1EF40CFEFA8181FFFE
        HEX    3F7F7FF17FFC7FE74FF87F773F6F3F6F
        HEX    3EFEFFC7FF9FFFF3171BEFEBF6F6F4F6
        HEX    7FEF7FEF7EEF7DEE3F6E5E768F9BFF7F
        HEX    F6F6F6F6F676F63676346A2E3111FFFE
        HEX    3E7E7FE37FF97FCF77CF6F783F773F6F
        HEX    3E7E7FE37FCFFFF96FF1171BEEEEF4F6
        HEX    7EDF7CDF7FDE7FEF3F707F5F8181FF7F
        HEX    7AFA3AFAFA7AF6F60E0CFEFA8181FFFE
        HEX    00000002000800200002002400000048
        HEX    00000005000000110040000400480000
        HEX    000000A0001000440020000200100002
        HEX    00000040000800800024001000020010

****************************************************************************

CBIGMRDO    HEX    00007070E8E9F9FB73773C3F101F101F
        HEX    1F3F63EF8EFE1FF73EEE2FE760C06BC6
        HEX    8080E0E050302818BCBC7A727E7A3E3E
        HEX    0C0F0707000001010101010303030707
        HEX    AFE7F7F3FBFCF7EFFBC7FDE3FDF2FFF8
        HEX    8C1CFCFCFE3EEBEBD5CDC5C5C76DFBFE
        HEX    07070F0F1F1F3C3C7B7BFFFFFFFF7F7F
        HEX    FFFFCFCF1E1E1F1F8F8F4747C1C18080
        HEX    C0C080800000E0E0D0D0F0F0E0E00000
        HEX    0000000000000001393975777E7F3E3F
        HEX    00001F3F63EF8EFE1FF73EEE2FE760C0
        HEX    00008080E0E050302818BCBC7A727E7A
        HEX    080F0C0F070700000101010101011D1C
        HEX    6BC6AFE7F7F3FBFCF7EFFBC7FDE3FDF2
        HEX    3E3E8C1CFCFCFE3EEBEBD5CDC5C5C76D
        HEX    3F3F7F7F7B7B78787C7C747438380000
        HEX    FFF8DFFF1E1E1C1C3C3C7F7F7F7F3F3F
        HEX    FBFE808000000000C0C0A0A0E0E0C0C0
        HEX    0000000000000000000000010307040F
        HEX    000000001F3F236F4EFE9FF73EEE2FE7
        HEX    000000008080E0E05030A818BCBC7A72
        HEX    081F0C1F0E0F1D1D1F1F0F0F01010101
        HEX    60C06BC6AFE7F7F3FBFCF7EFFBC7FDE3
        HEX    7E7A3E3E8C1CFCFCFE3EEBEBD5CDC5C5
        HEX    00000101030307070707030303030101
        HEX    FDF2FFF8FFFFFFFFFEFEFDFDFFFFFEFE
        HEX    C76DFBFE000000000000000000000000
        HEX    000000000000000101033A3F74777C7F
        HEX    00001F3F236F4EFE9FF73EEE2FE760C0
        HEX    00008080E0E050302818BCBC7A727E7A
        HEX    383F213F1E1E00000101010101010000
        HEX    6BC6AFE7F7F3FBFCF7EFFBC7FDE3FDF2
        HEX    3E3E8C1CFCFCFE3EEBEBD5CDC5C5C76D
        HEX    000000000101030307070F0F0F0F0707
        HEX    FFF8FFFFFFFFC7C7BBBBF5F5FCFCF8F8
        HEX    FBFEE0E0C0C0E0E0A0A0C0C000000000
        HEX    00000000010103031F1F3F3F0E0F0607
        HEX    3F3FEAF1B6C06FC67FAF7D8DB7EFCB07
        HEX    0000C0C0A0605030A818E8D8E8D890B0
        HEX    3E3F1F1F0F0F07073E3F1E1F0F0F0607
        HEX    A0C050E02F8F5F9FD808A08070A0A080
        HEX    5030A060F0F0F8F85838281828185030
        HEX    3F3F1E1F0F0F0C0E181F181F1C1F0F0F
        HEX    6080C00081C0E7E7BC3C2FCB01FFFFFF
        HEX    5030A06040C0DCDCF2F2FEEE84FCF8F8
        HEX    000000000101030306073E3F7E7F1D1F
        HEX    00007E7ED5E36D80DE8CFF5EFB1B6FDF
        HEX    00000000808040C0A0605030D0B0D0B0
        HEX    0D0E7D7F3E3F1E1F0E0F7D7E3D3F1E1F
        HEX    970F4080A1C05F1FBF3FB0104000E040
        HEX    2060A06040C0E0E0F0F0B07050305030
        HEX    0D0F7E7F3F3F1F1F0307030303030101
        HEX    4000C000F1789CDC17E705F980FFFFFF
        HEX    A060A06040C0F0F09898F87830F0F0F0
        HEX    00000000010103031F1F3F3F0E0F0607
        HEX    3F3FEAF1B6C06FC67FAF7D8DB7EFCB07
        HEX    0000C0C0A0605030A818E8D8E8D890B0
        HEX    3E3F1F1F0F0F07073E3F1E1F0F0F0607
        HEX    A0C050E02F8F5F9FD808A08070A0A080
        HEX    5030A060F0F0F8F85838281828185030
        HEX    3F3F1E1F0F0F07070D0F0C0F0E0F0707
        HEX    6080C0005E9FF3BBE2FCE0FFF0FFFFFF
        HEX    5030A06040C09C9CF2F2BE2E04FCFCFC
        HEX    000000000101030306073E3F7E7F1D1F
        HEX    00007E7ED5E36D80DE8CFF5EFB1B6FDF
        HEX    00000000808040C0A0605030D0B0D0B0
        HEX    0D0E7D7F3E3F1E1F0E0F7D7E3D3F1E1F
        HEX    970F4080A1C05F1FBF3FB0104000E040
        HEX    2060A06040C0E0E0F0F0B07050305030
        HEX    0D0F7E7F3F3E1F1F0707070707070303
        HEX    4000C000F1F89CDC17E705F980FFFFFF
        HEX    A060A06040C0E0E09090F07020E0E0E0
        HEX    000000001F1F383F717FE3FFF3FF7B7F
        HEX    00000000C3C337F7EFFF9FB70E1F1E0E
        HEX    00000000F0F808FCC4EE22B6321E341E
        HEX    3F3F1D1F0F0E0F0E0707070703030303
        HEX    2E2E9F97FFFFE362EF6EE764EFEEE3E2
        HEX    B89C7038E0F0E020C060C04080C08080
        HEX    0F0F1D1D6E6ED6D6F5F5FBFBFFFF7F7F
        HEX    FFFFFFC1FEE37C7E8181C3C3C3C38181
        HEX    C0C0E0E076766D6DAFAFDFDFFFFFFEFE
        HEX    00001F1F383F717FE3FFF3FF7B7F3F3F
        HEX    0000C3C337F7EFFF9FB70E1F1E0E2E2E
        HEX    0000F0F808FCC4EE22B6321E341EB89C
        HEX    1D1F0F0E0F0E070707070B0B6F6FDFDF
        HEX    9F97FFFFE362EF6EE764EFEEE3E2FFFF
        HEX    7038E0F0E020C060C04080C080808080
        HEX    EDEDECECF6F67F7F3F3F1E1E00000000
        HEX    FFC1FEE37C7E00000101030303030101
        HEX    C0C0E0E076766D6DAFAFDFDFFFFFFEFE
        HEX    0000000000001F1F383F717FE3FFF3FF
        HEX    000000000000C3C337F7EFFF9FB70E1F
        HEX    000000000000F0F808FCC4EE22B6321E
        HEX    7B7F3F3F1D1F0F0E0F0E070707070303
        HEX    1E0E2E2E9F97FFFFE362EF6EE764EFEE
        HEX    341EB89C7038E0F0E020C060C04080C0
        HEX    0F0F1F1F6D6DD6D6F5F5FBFBFFFF7F7F
        HEX    E3E2FFFFFFC1FEE37D7F8383C3C38181
        HEX    C0C0E0E0F6F66D6DAFAFDFDFFFFFFEFE
        HEX    00000F1F103F237F447D4C782C781D39
        HEX    0000C3C3ECEFF7FFF9ED70F878707474
        HEX    0000F8F81CFC8EDEC7EFCFFFDEFEFCFC
        HEX    0E1C070F070403060302010301010101
        HEX    F9E9FFFFC746DF5ECF4CDF5FC747FFFF
        HEX    B8F8F070F070E0E0E0E0D0D0F6F6FBFB
        HEX    030307076E6ED6D6F5F5FBFBFFFF7F7F
        HEX    FF837FC73E7E00008080C0C0C0C08080
        HEX    B7B737376F6FFEFEFCFC787800000000

CBIGAPPLES    HEX    00000000000007071F1F3F3F7E7F7D7F
        HEX    001C1C3C30702767ECFFE7FCBEF01CE0
        HEX    000000000000808060E010F04838E41C
        HEX    FCFFF8FFFCFFFAFFFCFFFEFFFDFFFEFF
        HEX    28D05CA03AC05DA02FD01FE02FD015EA
        HEX    2C1C443C2E1E661EE61ECE3EDE3E8E7E
        HEX    7F7F7E7F3F3F3F3F1F1F0F0F03030000
        HEX    02FD80FF48FFD5FFFFFFFFFFFFFFFFFF
        HEX    5EFEACFC7CFCF8F8F8F8F0F0C0C00000
        HEX    00000000000003030F0F1E1F3D3F7C7F
        HEX    000E0E1E18389BBBF6FFA2FF05F82AD0
        HEX    000000000000C0C030F0887844BC641C
        HEX    787FFCFFFAFFFCFFFEFFFDFFFEFF7F7F
        HEX    5CA038C05CA02AD01DE02FD01FE02FD0
        HEX    B20E261E532F271F730FE71FCB3FD73F
        HEX    7E7F3F3F3F3F1F1F0F0F070701010000
        HEX    95EA02FDA0FFC8FFF5FFFFFFFFFFFFFF
        HEX    8F7F5EFEAEFE7CFCFCFCF8F8F0F0C0C0

CFINI        HEX    00000000010102030203050605060D07 ;CHERRY
        HEX    000000C040E0D060A83028302830EC78
        HEX    1C0E341C3638333C183F2C1F170F0000
        HEX    E6F44262D6624AF662FEFEFC34780000
        HEX    00000F00170F3B1D773BEF71EF70B778 ;DINO
        HEX    0000F800FCF8BECC7F96BFCAFDF6FE04
        HEX    5B3CB779F7787B3C3F1F1D0F1F0F1F0F
        HEX    FDFEFBC6F60CFE0CFCF8F88070E0B8F0
        HEX    00003C007F3EE767DF5FEB6CDB7DDB6C ;EMON
        HEX    00007C00FEFCE7A6F3F2A766FFFE7BC6
        HEX    DB6DDB6D6B3C6F3F37181F0F370E5F3E
        HEX    FBC6FBF6D63CF6FCEC18F8F0EC70FA7C
        HEX    0000110123034507090F101F203F407F ;DIAM
        HEX    00008080C8406420B210D888CC8466C2
        HEX    FFFF7F7F3F3F1F1F4F0F270713030101
        HEX    D3FDFEC2FC84F888F190E220C4408080

****************************************************************************

CMRDO        HEX    23007723DE75C97FE37E763D3F1D3F14
        HEX    E000F0E078F0FC88FE5C77BAEB9E7EFC
        HEX    7F27FF4FDF79753BEF7FF778FA747A3C
        HEX    EE1CFFF2FBF6FEFCFEFCEFFAFF7E7E3C
        HEX    7600FF76FBFDEFFCD7BE3FD3F71B3F1F
        HEX    1C003E1CF33EE6FCCC78E6FCF71ADB6E
        HEX    7F3EFF7EFFFEDEFFFFF9FBDDFF666600
        HEX    5BEEFF96FFA6BEF4DCF8B8D0F0606000
        HEX    030027037E25D97FC37EE67D7F3D3F14
        HEX    E000F0E078F0FC88FE5C77BAEB9E7EFC
        HEX    7B27F74FCF7C7A3D3F1F7F375F3C3D00
        HEX    EC18FEF4F6FCFCF8E8F0DCF8FEF4FEFC
        HEX    06006F06BB6DFB7CFD5EF67F7F33F73B
        HEX    38007C38E67CCCF8CC78E6FCF71ADB6E
        HEX    FFFEFFFEDFFEEEFFFBADEFC6C6000000
        HEX    5BEEFF96FFA6BEF4DCF8B8D0F0606000
        HEX    0000030007031E05391F633EC67DDF7D
        HEX    0000E000F0E078F0FC88FE5C77BAEB9E
        HEX    7F343B177B27773E3D1E170F130F0B07
        HEX    7EFCEC18FCF8F87078E070E0F8D0F8F0
        HEX    00000D001F0D7F1B977839FFEFFEFFE6
        HEX    C000E0C030E098F098F0CCF8EE34B6DC
        HEX    CEF5FFFDFFBDFDCFDF07070101000000
        HEX    B6DCFE2CFE4C7CE8B8F070A0E0C0C000
        HEX    0000030007030E05190F331E663DDF7D
        HEX    0000E000F0E078F0FC88FE5C77BAEB9E
        HEX    DF747B373F13331F3E1F2D1F2F1F2F1F
        HEX    7EFCEC18FCF8F830B870FCE8F870F0C0
        HEX    01000301FE031FFFF7F8F5FBDFFEEFFE
        HEX    8000C08060C0B0E098F0CCF8EE34B6DC
        HEX    FEA5EFF5FF7DFD5F7F27270101000000
        HEX    B6DCFE2CFE4C7CE8B8F070A0E0C0C000
        HEX    030007033E05693FD37EC67DDF7D7F34
        HEX    E000F0E078F0FC88FE5C77BAEB9E7EFC
        HEX    3B177B27773E2D1E5F3F553EBA7DBF7F
        HEX    EC18FCF8D4787AF4F4F8D860E0008000
        HEX    C00036C0CFF6F7FDDBFCBCFFD7BFBFD3
        HEX    7000F8708CF8D4F8CC78E6FCF71ADB6E
        HEX    F71A7F3E5B3E3E1F2B17170808000000
        HEX    5BEEFF96FFA6BEF4DCF8B8D0F0606000
        HEX    030027037E25D97FC37EE67D7F3D3F14
        HEX    E000F0E078F0FC88FE5C77BAEB9E7EFC
        HEX    7B27FF4FCF7C7A3D6F3FFB7CB77A5F3E
        HEX    EC18FEF4FAFCEEFC7DFAFE7CAC707000
        HEX    6600BF667BFDEBFCBFFED6BFFFD3F71B
        HEX    38007C38E67CCCF8CC78E6FCF71ADB6E
        HEX    6F1EBF7EFF7EB67F7F3D7B2E2E101000
        HEX    5BEEFF96FFA6BEF4DCF8B8D0F0606000

CMRSDO        HEX    21007221DD63A37F7F3F3E1F1F0F3E1F
        HEX    F800F4F8BEFCDFE67F82FE24FF82FF1A
        HEX    653FCE7FFF73BF77CC7FF75BFF4C7C38
        HEX    7F85FFF927FEFEFC3FEADFE2EF765E3C
        HEX    7E00F77EED9FECBFDEF3FF5B6E3F6D3F
        HEX    0C00160CBB1EF6B8F4F8F4F8FAFC5DFE
        HEX    6A3FEB7E5FFEBBCEFB9EFFCDFF747703
        HEX    EF5EFB0EF72EFF86FD86FE2CFCD8D800
        HEX    010022017D23E37FFF7F7E3F2F1F3E1F
        HEX    F800F4F8BEFCDFE67F82FE24FF82FF1A
        HEX    653FC67FEF797F3B7E2F7F273F181800
        HEX    7E84FFFA27FAFEFC3CE8DEECDF62FF7E
        HEX    06003F067D3FF84FFC5F7F337E3B6D3F
        HEX    18003C18FE3CB4F8F4F8F4F8FAFC5DFE
        HEX    EA3FEBFE9FFEFB8EFBBEFFA9EFC6C600
        HEX    EF5EFB0EF72EFF86FD86FE2CFCD8D800
        HEX    0000010002010D03330F7F3FFE7FEF5F
        HEX    0000F800F4F8BEFCDFE67F82FE24FF82
        HEX    721F673F773C3F1D1E0B1F080F070701
        HEX    FF1A7E84FAFCBEF4FCD8F8B07C88FCF8
        HEX    000007000F063D0F783FFE4FFF53EEDB
        HEX    C000E0C0F06070E0E8F0E8F0F4F8BAFC
        HEX    BDFEF79CFFACFFBDFFD5DB0E0F010100
        HEX    DEBCF61CEE5CFE0CFA0CFC58F8B0B000
        HEX    00000100020105031B07271F7E3F7F3F
        HEX    0000F800F4F8BEFCDFE67F82FE24FF82
        HEX    FA5F731F3B1E1F0E170F0C070D060F07
        HEX    FF1ABEC4FC78F4F8F478F810B0E0F0E0
        HEX    0100030107001F07ED1FF8FF9FFFDEB3
        HEX    0000C000E0C0D0E0D0E0E8F0F4F8BAFC
        HEX    FFCABDDEFFDCFF3D271D1F0203010100
        HEX    DEBCF61CEE5CFE0CFA0CFC58F8B0B000
        HEX    010002014503FB47EF7FFE7F7F3F2E1F
        HEX    F800F4F8BEFCDFE67F82FE24FF82FF1A
        HEX    351F633F673C3F1D1F0F351B37183F1F
        HEX    7E84FEFCBEF4FAFCDEA4FCC8F8B0F080
        HEX    00000600EF06F9EF98FFFD9FDEB3FFBB
        HEX    38007C38F87068F0F8F0F4F8FAFC5DFE
        HEX    FEFFFB2EEF5EFF4E7F2A371F1F000000
        HEX    EF5EFB0EF72EFF86FD86FE2CFCD8D800
        HEX    21007221FD43E37FFF7F7E3F2F1F3E1F
        HEX    F800F4F8BEFCDFE67F82FE24FF82FF1A
        HEX    653FC77FEF795E3B6C3FDF6FFF627F3E
        HEX    7E847FFAA7FAFFFE7FD2DEE4FC383800
        HEX    6600FF66D5FFE89FFCBFFFB3EEFBE73F
        HEX    1C003E1CFF3AB6F8F4F8F4F8FAFC5DFE
        HEX    6C3F7B3EDF6EFB5EFB4E7F293F1E1E00
        HEX    EF5EFB0EF72EFF86FD86FE2CFCD8D800

CBADS        HEX    3E007F3EFD63FF45FF41FD63FF7FB77E
        HEX    FC007EFCFBC6FF8AFF820DF6F60CFEF4
        HEX    5F3D2F1D2F1E5F3FB77FA66F6E1D1D00
        HEX    1EF40FFAFFFAFF06FEFC66FCECD8D800
        HEX    1F003F1F7E317F22FF60FF71BF7FBB7F
        HEX    0000FC00FEFCFBC6FF8AFF82FDC6FEFC
        HEX    5F3E5F3D5F3D5F3E7F3FE77FF66F660E
        HEX    FE0CFEF40FFAFFFAFF06FDFE66FC66EC
        HEX    00000F00170F2F185F305F31BF78FF7F
        HEX    00008000FC807EFCFB46FF423FCAFBC6
        HEX    BB7F5F3E5F3F5F3F7F3F733F73373317
        HEX    FFFEFFFCFF02FDFEFEFCFEFC33FE3376
        HEX    0000000000000F00170F3B1D773BEF71
        HEX    000000000000F800FCF8BECC7F96BFCA
        HEX    EF70B7797B3DF778BB7CB77FF37F7D3F
        HEX    FDF6FEFCFDFEFFF2FE04FCF8F880E0C0
        HEX    7B00CD7BFFFFFEFF95FEABF47FE0FFE6
        HEX    8000C080E0C070E0A870D830F850F8F0
        HEX    FFEFFFAFFF2F7F2F7F263F171A0D0D00
        HEX    B8F058B0F810F850F8B0F060E0C0C000
        HEX    00000F00170F3B1D773BEF71EF70B778
        HEX    0000F800FCF8BECC7F96BFCAFEF4FEF8
        HEX    5B3DB779F7787B3C3F1F1B0707000000
        HEX    D5FEAFFAFFF2FE04FCF858E0E0000000
        HEX    06000D061E0F3F1F391F56397F307F33
        HEX    E00070E0F8F09CF86A9CF60CFE14FE3C
        HEX    5F377D375E373D173E131F090E070700
        HEX    EEFCD6ECFEC4FED4FEACFC58F8303000
        HEX    0F00170F3B1D773BEF71AF7057393B1F
        HEX    F800FCF8BECC7F96BFCAFEF4FCF85EF0
        HEX    773BF67BF7797B3C3F1F1B0707010100
        HEX    050EAFFAFFF2FE047CF8B4F8B8F0F000
        HEX    06000F061F0F3F1F381F57387F33FD77
        HEX    30005830BC78CEFCB5CE7B86FF8AFFDE
        HEX    EE769C76FE76FC765E333F090E070700
        HEX    77FEEBF67FE2FFEAFF56FE2CBC181800
        HEX    00000F00170F3B1D773BEF71EF70B778
        HEX    0000F800FCF8BECC7F96BFCAFFF4FEF8
        HEX    5B3DB779F7787B3C3F1F1D0F1F0F1F0F
        HEX    D5FEAFFAFFF2FE04FCF8F88070E0B8F0
        HEX    06000D061E0FFF1FF9FFF6F9DFF0FFF3
        HEX    E00070E0F8F09CF86A9CF60CFE14FE3C
        HEX    BFF77DD7FED7FD97BE131F090E070700
        HEX    EEFCD6ECFEC4FED4FEACFC58F8307000
        HEX    000007001F077E19ED7366395F3BEB75
        HEX    0000C000E0C0F0A0F8D0FC487E98FDEE
        HEX    5D3AEB74543BFB7CBE7FEF7FFF63BF73
        HEX    FF1AFFE2FF0EB77EFB166FF2F240F8F0
        HEX    FA006FFAFAFFDDBFFB3DF53AFAF5EBF4
        HEX    9000F890B8F04CF8DC687E84EE54D6FC
        HEX    DFA2F7EAFFAADFB9B70D2F1C7F3F3F00
        HEX    BEDCFEB4FC88F850F0E0E08040808000
        HEX    07001F077E19ED7366395F3BEB755D3A
        HEX    C000E0C0F0A0F8D0FC487E98FDEEFF1A
        HEX    EB74543BFB7C7F3F7F379E677F0D1F0F
        HEX    FFE2FF0EB77EFB96EFF2F200C080E0C0
        HEX    25005F255D3FFE1FFDCEFAFDFDBADDFA
        HEX    4800FC485CF8A6FCEEB4BF4277AAEB7E
        HEX    FFD9FB95BF152F1C1B06170E3F1F1F00
        HEX    DF6EFF5AFE44FCA8F8F0F040A0C0C000
        HEX    1F077E19ED7366395F3BEB755D3AEB74
        HEX    E0C0F0A0F8D0FC487E98FDEEFF1AFFE2
        HEX    543BFB7C7F3F3F1F2F1F3F1D7F3A7F3F
        HEX    FF0EB77EFB96EF72F280A0C0E0404080
        HEX    0200C702FEC7EFFFFEFFFDBEFEDDFEBD
        HEX    A400FEA4AEFC53FEF75A5FA1BB55F53F
        HEX    7FB4DD6A7F0A170E0D030B071F0F0F00
        HEX    EFB7FFADFFA2FE54FC78F820D0E0E000
        HEX    07001F077E19ED7366395F3BEB755D3A
        HEX    C800FCC8FEBCFFD6FE537FA7FFC9FD48
        HEX    EB74543BFB7C7F3F3E1F7B3CEE70BF7E
        HEX    F890F830FC50FE94FEECFA7C7C303000
        HEX    C5006FC5FDEFBEFFFDBEDABDFD9AAD1A
        HEX    4800FC485CF8A6FCEEB4BF4277AAEB7E
        HEX    3F197F34FF72FF6F7F305C3838000000
        HEX    DF6EFFDAFE24FE1CFFC6FE2C7C38E870
        HEX    00001F003F1F6F30DF6FDF6FDF6FDF6F
        HEX    DF6FDF6FDF6FDF6F6F303F1F370E5F3E
        HEX    0000F800FCF8F60CFBF6FBF6FBF6FBF6
        HEX    FBF6FBF6FBF6FBF6F60CFCF8EC70FA7C
        HEX    000000003F007F1FEF30DF6FDF6FDF6F
        HEX    DF6FDF6FDF6FDF6FDF6F6F307F5F3F3C
        HEX    00000000FC00FEF8F70CFBF6FBF6FBF6
        HEX    FBF6FBF6FBF6FBF6FBF6F60CFFFAFE3C
        HEX    1F003F1F6F30DF6FDF6FDF6FDF6FDF6F
        HEX    DF6FDF6FDF6FEFB0FFFFFF787C303800
        HEX    F800FCF8F70CFBF6FBF6FBF6FBF6FBF6
        HEX    FBF6FBF6FBF6F70DFFFFFF1E3E0C1C00
        HEX    FB778EFDE7FFF93EF67F9FFFAFDFF57F
        HEX    F8F06CF8EE9CF75ABEFFFBFF37FFDEFF
        HEX    00000000000000003F00423FBF7F7FFF
        HEX    0000000000000000FC0042FCFDFEFEFF
        HEX    3F0F7D3BFE73EF77FF737F385F3F7F3F
        HEX    FCF07E9CFF2E7F9AFDF6FE0CFCF878E0
        HEX    FF1FE7B8CEF1BF73D7E9BB74D7E87FFF
        HEX    F0E0F810FCC87FB8FAEFFF1DFFE7FFFE
        HEX    BF7F5FE0B7DFB7DDB4CFDFE07FFFBF7E
        HEX    FDFEFA07EDFBDDB3FDFBFB07FEFFFD7E
        HEX    00003E005D3EBA67FD43FD4BBA675D3E
        HEX    00007C00BA7C5DE6BFC2BFD25DE6BA7C
        HEX    6F34DF63DF6FDF7FDF6F6F376739331C
        HEX    F62CFBC6FBF6FBFEFBF6F6ECE69CCC38
        HEX    3E005D3EBA67FD4BFD43BA677F3E361B
        HEX    7C00BA7C5DE6BFD2BFC25DE6FE7C6CD8
        HEX    371857386F316F376F3357383718331C
        HEX    EC18EA1CF68CF6ECF6CCEA9CEC18CC38

****************************************************************************

CPNT        HEX    3F00773FFB6CFF4BBF6BBF6BFB44BF7F

****************************************************************************

CBALLS        HEX    7E00DB3CAD76F77EFF7EBD7EDB3C7E00
        HEX    7600DF34B77ABB7EBF7EDF3C6E183C00
C500        HEX    1F003E1F7F317F37753B2F1D7D335E3F
        HEX    FE00FFFE6D93FF6DFF6DFF6D6D93FFFE
CEXTRA        HEX    FFFEBBC6BFDEB7CCBFDCBFDFBDC3FFFF
        HEX    FFE7DBBDA4DBBD66BD66A4DBDBBDFFE7
        HEX    FFFFFF8189F7EFF7EF34EF34EF34FF3C
        HEX    FFFEBBC7BDDBBDDBBFC6B7DABBDDFFFF
        HEX    FF7EDFE3BBDDA3DDBFC1BBDDBBDDFFFF

****************************************************************************

CGRND0        HEX    59228E5103AC0186814243349748F805
        HEX    F9022A44F3088053E011914AC825FF00
        HEX    FF00A34C9122E001E0059126E7187E81
        HEX    F70013ACE112C021C122E011A116E409
        HEX    FF00CC22A1128A41804000A08441C132
        HEX    3E81F904E314C8237E813F807805E710
        HEX    E409FE014F209649038427081384FC01
        HEX    F904640A1384400303848548E310FE01
        HEX    EF008240800AC13C805C803EC1086380
        HEX    5D82E7006116E308C11C812C401AE300
        HEX    FF00D5208310815841BC8114A348EA05
        HEX    F30C47908364811AC3388150E502DF20
        HEX    CF20FF00FF003388FF00CF20F9049F40
        HEX    3F80F00ADF20F7009944F9042790DC02
        HEX    FF009348FF00CF20FC02BF00F904E611
        HEX    FF00F3089F40FF00FA01E710FF007904
        HEX    3C42E804F905324BF20BE516E516CD27
        HEX    1C210FD044E9D364A93229322932EC79
        HEX    9C4E349C36B833BC18BF2C9F974FC020
        HEX    E6F44262D6624AF662FEFEFC34790182
        HEX    000000000000000010004E4EB1FF0EF1
        HEX    0000000000000000001082006D6D92FF
        HEX    80A040C0A060A06040C0809040C040C0
        HEX    A06040C0A060A06040C080A040C09040
        HEX    54AFABFB545020000000000000000000
        HEX    C0FF373F0A4800000000000000000000
        HEX    020305060506020B0506020305060203
        HEX    010902030203050605060203020B0101
        HEX    DB00F7087807D72FE818D032A060A060
        HEX    FA00FF005F809AE06F7016180B2C0B0C
        HEX    D030E81AA818542CFB07FC03F708DB00
        HEX    051605060B4C1718EDF21BE0F308BF00
        HEX    00000000000000040000012102030203
        HEX    00000000000000100000808848C060E0
        HEX    0506020B010100020000000000000000
        HEX    20E0C8C0001040000000000000000000
        HEX    00000000000000000000000000000000
        HEX    A040C00883238406054E0E1F337FDFE0
        HEX    0100081C307AC6F6EA4EF2DAE6B2CA66
        HEX    BFF08FBD828FC082B1C2CEF3333F0E0F
        HEX    94CE289C5038A27041E483C001920900

****************************************************************************

CASCII        HEX    7E7EE7C3DB99BDA5BDA5DB99E7C37E7E
        HEX    3C3C6474446464742434667642627E7E
        HEX    7C7CC6C693BBF3FB46669EDF8181FFFF
        HEX    FEFE87C3F3F94563727683C185C3FFFE
        HEX    E0E0BCBCBCB4B7B78181F781F7F71C3C
        HEX    FFFF83C19EDF86C2737973F9A5C37E7E
        HEX    7E7EE7C3CE9E81839D9DDD9DE3C37E7E
        HEX    FFFFC381FBF9091B163212362C643C7C
        HEX    FF7E81C39999C34299999999A5C3FF7E
        HEX    7E7FA3C1D999D999B9C17D791D091F0F
        HEX    183C3424342434243424183C34243C18
        HEX    1C383464346414342C68183000000000
        HEX    776699DB9989D391A5C3DB66663C3C18
        HEX    00003E3E77636F4D41416E4F73613E3F
        HEX    FFFFFFFF000000000000000000000000
        HEX    FF7EA5C3DB9979F31A130C1E1A120C1E
        HEX    181838287F4FCF8183C14F6F28381818
        HEX    7E7EE7C3DB99999981819999DB99FFFF
        HEX    FEFEC583DB99DA87D99BDB99C583FEFE
        HEX    FE7EE2C6DC9EB8B0B8B0DE9FE1C3FF7F
        HEX    FEFE878393B9B9ADB9AD93B98783FEFE
        HEX    FEFEC682DE9ECC84DC9CDF9FC381FFFF
        HEX    7F7F63416F4F66426E4E684868487878
        HEX    FF7E81C3B999BE9EB991BD9981C3FF7E
        HEX    FFE7DD99DD99C181C181DD99DD99FFE7
        HEX    FFFF818181E76666666681E78181FFFF
        HEX    FFFF8181E78177E776E4AC84948CFCF8
        HEX    E6FEBB99B7928E848E84B392B999E7FE
        HEX    F8F0B098B098B098BE9F9F818181FEFF
        HEX    FFE799BD8199818181A5BDA5FDBDE7E7
        HEX    EFEFBD999D898D85B581B991BD99F7F7
        HEX    7E7EA5C3DB9999999999DB99A5C37E7E
        HEX    FEFEC583DB99DB99C583DE9ED090F0F0
        HEX    7E7EA5C3DB99999D9D9F9393A9D97E7F
        HEX    FEFEC7839B999B998E8696929B99FFFF
        HEX    7F7EE7C3CF9FA7C2F3F9737987C3FFFE
        HEX    FFFF8181C381E7EF6E246E246E247E3C
        HEX    FFFFBD99BD99BD9999BDC39966C33C7E
        HEX    E7FFBD99BD9981DB5AC342666624183C
        HEX    E7FFBD99BD99A5A581C3DB42425A7E7E
        HEX    FFE799BD00DB4266426600DB99BDFFE7
        HEX    E7E7DBBD009981C3C366662424243C3C
        HEX    7EFF8381B9916372C6668DCDC1817EFF
        HEX    18181818181818181818181818181818

****************************************************************************

CAPPLES        HEX    9F21FE02BD0D3353E12FCF5F9DBF9ABF
        HEX    F3C47F308C892774D36A99C50D858D05
        HEX    BEBFBABF9DBFDE5FEF2FF5133848FF07
        HEX    CD05758D29DD1AFAF7F4CFE81710FEE1
        HEX    9F20FF0FB010A36DCF5F9CBFBBBFBFBF
        HEX    F3C43F20DCD18F88C7B493EA99C50D85
        HEX    BABF9DBFDE5FEF2FF317F80B3C44FF03
        HEX    8D058D05D58D2DDD9BFAF7F40F08FEF1
        HEX    11014A02BD0D3313612FCF5F9DBF9ABF
        HEX    E3C0753088892474D26A99C50D858D05
        HEX    BEBFBABF9DBF5E5F2F2FD553B8F80FF7
        HEX    CD05758D29DD1AFAF5F4CCE81D1DF2FF
        HEX    10004A02B5053313410FCA5A9C9E1A3E
        HEX    E3C0652088892070922A90C40D850800
        HEX    AEAF808490B21E1E2525CD4BB0F80BF3
        HEX    4C04150D281C1A7AB1B0CCE80D0DB2BF
        HEX    11014800B40432524100C04802028088
        HEX    63405510000104540000000401010040
        HEX    0000B091808018002C20CF48B3FC09F1
        HEX    000001010808020201108C086D6D92FF
        HEX    10004900B40020404000800000400000
        HEX    23004500000110000000000022000000
        HEX    10000400000000001000CE4EB1FF0EF1
        HEX    0000040000000000011084006D6D92FF
        HEX    10004800B00020004000800000000000
        HEX    23000500000100000000000000000000
        HEX    00000000000000001000CE4EB1FF0EF1
        HEX    0000000000000000011084006D6D92FF

;***************************************************************************

MENU        CALL    CLEARDISP
        CALL    CLEARSTAT
        CALL    CLEARSET
        LD    HL,MENUSETAB
        CALL    CREATESET

        LD    HL,LOGO
        LD    DE,$20+DISPSCREEN+1
        CALL    PRINTSHAPE
        LD    HL,MENUTEXT
        CALL    PRINTEXT

        LD    HL,BYTESCREEN    ;SETUP SCX LOGO POSITIONS
        LD    B,66/2
        LD    A,20*8
SLOGO        LD    (HLI),A
        CPL
        LD    (HLI),A
        CPL
        INC    A
        DEC    B
        JR    NZ,SLOGO

         XOR    A
        LD    HL,STATUSOBJ
        LD    B,$28*4        ;RESET STATUS OBJS
RESETST        LD    (HLI),A
        DEC    B
        JR    NZ,RESETST

        LD    (MENUY),A
        LD    (SUBMENU),A
        LD    (BLOBSINE),A
        LD    (KEYPRESS),A
        LD    (LOGOSTATE),A
        LD    A,50*4
        LD    (LOGTIME),A
        LD    A,%11100100
        LD    (OBP0),A
        LD    A,%01101100
        LD    (OBP1),A
        LD    (CONTOG),A
        LD    A,8*8
        LD    (BLOBY),A
        
LOGOLOOP    CALL    WAITBLANK
        LD    A,>STATUSOBJ
        CALL    BLITS
        CALL    LOGOPULSE
        CALL    WORKMENU
        CALL    MENUOBJ
        CALL    FLAGS
        CALL    RAND
        CALL    KEYS
        JR    LOGOLOOP

;***************************************************************************
;SUB MENU ROUTINES...

WORKMENU    LD    A,(SUBMENU)
        ADD    A,A
        ADD    A,<SUBMENUTAB
        LD    L,A
        LD    H,>SUBMENUTAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        CALL    JPHL        ;DO OPTION MENU
        LD    A,(LOGTIME)    ;CHANGE TITLE EFFECTS
        DEC    A
        LD    (LOGTIME),A
        RET    NZ
        LD    A,(LOGOSTATE)
        INC    A
        AND    3
        LD    (LOGOSTATE),A
        RET

;---------------------------------------------------------------------------

EXITMENU    POP    AF
        POP    AF        ;RET ADDR
        CALL    WAITBLANK
        XOR    A
        LD    (LCDC),A
        JP    WAITNOK

OPTIONS        LD    HL,STATUSOBJ
        LD    A,(CONTOG)
        LD    C,A
        LD    A,(KEYPRESS)
        BIT    3,A        ;'START'
        JR    Z,NOGAME
        LD    A,(CONTROL)
        CP    2
        JR    NZ,EXITMENU
        INC    L
        LD    (HL),$0D    ;XNO
        INC    L
        LD    (HL),$11    ;GNO
NEXTUP        LD    A,8*8
        LD    (SCRLCOUNT),A
NEXTMENU    LD    A,(SUBMENU)
        INC    A
        LD    (SUBMENU),A
        RET

NOGAME        AND    %11110100    ;CUR/SELECT
        LD    A,(CONTROL)
        JR    Z,NEWSEL
        LD    C,0
        JR    NOSEL
NEWSEL        INC    C
        DEC    C
        JR    NZ,NOSEL
        INC    A
        LD    C,A
        CP    3
        JR    NZ,SELWRP
        XOR    A
SELWRP        LD    (CONTROL),A

NOSEL        SWAP    A
        ADD    A,100
        LD    (HLI),A        ;YNO
        LD    (HL),$2C    ;XNO
        INC    L
        LD    (HL),$08    ;GNO
        LD    A,C
        LD    (CONTOG),A
        RET

;---------------------------------------------------------------------------

UPMENU        LD    A,(MENUY)    ;MENU MOVES UP
        INC    A
        LD    (MENUY),A
        LD    C,A
        LD    A,(SCRLCOUNT)
        DEC    A
        LD    (SCRLCOUNT),A
        JR    Z,NEXTMENU
HANDYMAN    LD    A,C
        CPL
        AND    %00011111
        ADD    A,8*12
        LD    (STATUSOBJ),A
        LD    A,C
        SRL    A
        AND    15
        ADD    A,<WAVETAB
        LD    L,A
        LD    H,>WAVETAB
        LD    A,(HL)
        ADD    A,$0D-4
        LD    (STATUSOBJ+1),A
        RET

SKILEVEL

SOUNDOPT    LD    A,(KEYPRESS)
        BIT    3,A        ;'START'
        JR    NZ,NEXTUP
        RET

DWMENU        LD    A,(MENUY)    ;MENU MOVES DOWN
        SUB    2
        LD    (MENUY),A
        LD    C,A
        LD    A,(SCRLCOUNT)
        DEC    A
        LD    (SCRLCOUNT),A
        JR    NZ,HANDYMAN
        LD    (SUBMENU),A
        RET

;***************************************************************************
;THE LOGO SPECIAL FX...

LOGOPULSE    LD    A,%11000011    ;DISPSCREEN
        LD    (LCDC),A
        XOR    A
        LD    (SCY),A
        LD    A,(RND1)
        LD    C,A
        AND    %11
        CALL    NZ,ANIHEAD

        LD    A,(SPEEDFLAG)
        SRL    A
        SRL    A
        SRL    A
        AND    1
        ADD    A,$18
        LD    HL,$16*$20+STATSCREEN+$0C
        LD    (HLI),A
        INC    L
        INC    L
        ADD    A,2
        LD    (HL),A

        LD    A,(LOGOSTATE)
        ADD    A,A
        ADD    A,<LOGOTAB
        LD    L,A
        LD    H,>LOGOTAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        CALL    JPHL

        LD    A,$48
        CALL    WAITSYNC

        XOR    A
        LD    (BGP),A
        LD    (SCX),A
        LD    A,(MENUY)    ;CURRENT Y POS
        LD    (SCY),A
        LD    A,%11001011    ;STATSCREEN
        LD    (LCDC),A

        LD    E,<FADETAB-1
        LD    H,>FADETAB
        LD    BC,$1049
FADE        LD    A,C
        INC    C
        CALL    WAITSYNC
        LD    A,B
        ADD    A,E
        LD    L,A
        LD    A,(HL)
        LD    (BGP),A
        DEC    B
        JR    NZ,FADE
        RET

;---------------------------------------------------------------------------

LOGOON        LD    A,%11100100
        LD    (BGP),A
        LD    HL,BYTESCREEN    ;TEMP VARS
        LD    BC,$4207
LOGON        LD    A,C
        INC    C
        CALL    WAITSYNC
        LD    A,(HL)
        LD    (SCX),A
        OR    A
        JR    Z,NOMOV
        INC    A
        BIT    0,B
        JR    Z,NOMOV
        SUB    2
NOMOV        LD    (HLI),A
        DEC    B
        JR    NZ,LOGON
        RET

;---------------------------------------------------------------------------

BARREL        LD    A,(SPEEDFLAG)
        AND    31
        LD    D,A
        LD    E,<WAVETAB
        LD    H,>WAVETAB
        LD    BC,$4207
BARON
        INC    D
        LD    A,D
        AND    31
        ADD    A,E
        LD    L,A
        LD    A,C
        INC    C
        CALL    WAITSYNC
        LD    A,(HL)
        LD    (SCX),A

        DEC    B
        JR    NZ,BARON
        RET

;---------------------------------------------------------------------------

RASTARS        LD    A,(SPEEDFLAG)
        SRL    A
        SRL    A
        LD    D,A
        LD    E,<PULSETAB
        LD    H,>PULSETAB
        LD    BC,$4207
RASTAR        LD    A,C
        INC    C
        CALL    WAITSYNC
        INC    D
        LD    A,D
        AND    7
        ADD    A,E
        LD    L,A
        LD    A,(HL)
        LD    (BGP),A
        DEC    B
        JR    NZ,RASTAR
        RET

;---------------------------------------------------------------------------

STARFALL    LD    A,66
        CALL    WAITSYNC
        LD    A,(SPEEDFLAG)    ;SETUP A STAR...
        AND    %1111
        ADD    A,A
        ADD    A,A
        ADD    A,4*9+2
        LD    L,A
        LD    H,>STATUSOBJ
        LD    A,(HL)
        OR    A
        RET    NZ
        LD    (HL),$8        ;GNO/TIME
        INC    L
        LD    A,(HL)
        XOR    P1
        LD    (HLD),A
        DEC    L
        LD    A,(RND1)
        AND    127
        ADD    A,16+8
        LD    (HLD),A        ;XNO
        LD    A,(RND2)
        AND    63
        ADD    A,16+4
        LD    (HL),A        ;YNO
        RET

;***************************************************************************
;ANIMATE CHRMAPPED SCREEN...

ANIHEAD        ADD    A,A        ;ANIMATE SKILL FACES
        ADD    A,A
        ADD    A,<FACEADTAB-4
        LD    L,A
        LD    H,>FACEADTAB
        LD    E,(HL)
        INC    L
        LD    D,(HL)
        INC    L
        LD    A,C
        SRL    A
        SRL    A
        AND    %1
        ADD    A,L
        LD    L,A
        LD    A,(HL)
        LD    (DE),A
        INC    E
        INC    A
        LD    (DE),A
        INC    A
        LD    HL,32-1
        ADD    HL,DE
        LD    (HLI),A
        INC    A
        LD    (HL),A
        RET

;***************************************************************************
;WORK THE MENU SPRITES...

MENUOBJ        LD    HL,STATUSOBJ
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO
        INC    L
        LD    C,(HL)
        DEC    L
        DEC    L
        CALL    DUMP3BY3    ;DO HAND

        LD    BC,$1000
        LD    A,(SPEEDFLAG)
        AND    %11
        JR    NZ,WORKSTAR
        INC    C
WORKSTAR    LD    A,B
        AND    3
        ADD    A,(HL)
        LD    (HLI),A        ;FALLING STAR
        INC    L
        LD    A,(HL)        ;DECREASE GNO
        OR    A
        JR    Z,STAROFF
        SUB    C
STAROFF        LD    (HLI),A
        INC    L
        DEC    B
        JR    NZ,WORKSTAR

;WORK THE LITTLE BLOB THING!...

        PUSH    HL
        LD    A,(TOGGLE)
        LD    C,A
        LD    A,(BLOBSINE)
        ADD    A,C
        LD    C,A
        LD    A,(BLOBY)
        ADD    A,C
        LD    (BLOBY),A
        LD    E,A
        CP    17*8+4
        LD    A,C
        JR    C,NOBOW
        LD    A,(RND1)
        AND    7
        SUB    4
        LD    (BLOBXSD),A
        LD    A,(RND2)
        AND    7
        SUB    8
NOBOW        LD    (BLOBSINE),A

        LD    A,(BLOBXSD)
        LD    D,A
        LD    A,(BLOBX)
        ADD    A,D
        LD    (BLOBX),A
        LD    D,A
        LD    A,GHOSTG
        JP    DUMP2BY2S        

;---------------------------------------------------------------------------

DUMP3BY3    LD    (HL),D        ;YNO
        INC    L
        LD    A,E
        LD    (HLI),A        ;XNO
        LD    (HL),C        ;GNO
        INC    C
        INC    L
        LD    (HL),0        ;FLG
        INC    L
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    C
        INC    L
        LD    (HL),0
        INC    L
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    C
        INC    L
        LD    (HL),0
        INC    L

        LD    A,D
        ADD    A,8
        LD    D,A
        LD    (HLI),A        ;YNO
        LD    A,E
        LD    (HLI),A        ;XNO
        LD    (HL),C        ;GNO
        INC    C
        INC    L
        LD    (HL),0        ;FLG
        INC    L
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    C
        INC    L
        LD    (HL),0
        INC    L
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    C
        INC    L
        LD    (HL),0
        INC    L

        LD    A,D
        ADD    A,8
        LD    D,A
        LD    (HLI),A        ;YNO
        LD    A,E
        LD    (HLI),A        ;XNO
        LD    (HL),C        ;GNO
        INC    C
        INC    L
        LD    (HL),0        ;FLG
        INC    L
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    C
        INC    L
        LD    (HL),0
        INC    L
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    C
        INC    L
        LD    (HL),0
        INC    L
        RET

;***************************************************************************
;***************************************************************************
;HERE'S A LATE RESULT...
;DISPLAY+RESET LAST 3 LEVEL SCORES&TIMES/ADD TO RUNNING TOTAL...

SHOWRESULTS    LD    A,(LEVEL)
        DEC    A
        CALL    BOARDLINED    ;PRINT SCORE BOARD
        CALL    BOARDLINE
        CALL    BOARDLINE
        CALL    TOTOTAL        ;ADD TO TOTAL...
        LD    HL,RESTEXT
        CALL    PRINTEXT
        LD    HL,BOARDTAB    ;CHANGE GRAPHIC SET
        CALL    CREATESET

        XOR    A
        LD    (SCXT),A    ;SCRNX
        LD    (SUBMENU),A    ;MODE

;SETUP 'BIG' SPRITES...

        LD    B,3
        LD    HL,SETBIGTAB    ;BIG SPRITES
        LD    D,>STATUSOBJ
SETBIG        LD    E,(HL)        ;OFFSET
        INC    HL
        LD    A,(HLI)        ;YNO
        LD    (DE),A
        INC    E
        LD    A,(HLI)        ;XNO
        LD    (DE),A
        INC    E
        INC    E
        XOR    A
        LD    (DE),A
        DEC    B
        JR    NZ,SETBIG

;SETUP 'FINISHED' SPRITES...

        LD    HL,27*4+STATUSOBJ    ;FINISH SPRITES
        LD    DE,$1C90
        LD    A,(0*BRDLEN+SCORE+8)
        CALL    DUMPENDOBJ
        LD    D,$2C
        LD    A,(1*BRDLEN+SCORE+8)
        CALL    DUMPENDOBJ
        LD    D,$3C
        LD    A,(2*BRDLEN+SCORE+8)
        CALL    DUMPENDOBJ

        LD    B,3
        CALL    RESETBOARD    ;RESET LAST 3

RESLOOP        CALL    WAITBLANK
        LD    A,>STATUSOBJ
        CALL    BLITS
        LD    HL,BIGAPPLE1
        XOR    A        ;NO SCROLL UP TOP
        LD    (SCX),A
        LD    A,(SPEEDFLAG)    ;ANIMATE APPLE
        AND    %100
        JR    Z,APLM
        LD    HL,BIGAPPLE2
APLM        LD    DE,$20*13+STATSCREEN+$18
        CALL    PRINTSHAPE
        LD    A,%11000011
        LD    (LCDC),A
        LD    A,%11100100
        LD    (BGP),A
        LD    A,8*08        ;SPLIT SCREENS
        CALL    WAITSYNC
        LD    A,(SPEEDFLAG)
        SRL    A
        AND    7
        ADD    A,<PULSETAB
        LD    L,A
        LD    H,>PULSETAB
        LD    A,(HL)
        AND    %11000000
        LD    L,A
        SRL    A
        SRL    A
        OR    L
        SRL    A
        SRL    A
        OR    L    
        LD    (BGP),A
        LD    A,8*10
        CALL    WAITSYNC
        LD    A,%11001011
        LD    (LCDC),A
        LD    A,%11100100
        LD    (BGP),A
        CALL    WORKWELL
        CALL    DUMPBIG
        CALL    FLAGS
        JR    RESLOOP

;---------------------------------------------------------------------------

WORKWELL    LD    A,(SUBMENU)
        ADD    A,A
        ADD    A,<WELLTAB
        LD    L,A
        LD    H,>WELLTAB
        LD    A,(HLI)
        LD    H,(HL)
        LD    L,A
        CALL    JPHL
        LD    A,(SCXT)
        LD    (SCX),A
        RET

EMOVE        LD    A,(STATUSOBJ+BIGEXTRA+1)
        INC    A
        LD    (STATUSOBJ+BIGEXTRA+1),A
        CP    10*8-4
        RET    NZ
UPWELLY        LD    A,60*3
        LD    (SCRLCOUNT),A
UPWELL        LD    A,(SUBMENU)
        INC    A
        LD    (SUBMENU),A
        RET

ALLWAIT        LD    A,(SCRLCOUNT)
        DEC    A
        LD    (SCRLCOUNT),A
        JR    Z,UPWELL
        RET

ALLMOVE        LD    A,(STATUSOBJ+BIGEXTRA+1)
        INC    A
        LD    (STATUSOBJ+BIGEXTRA+1),A
DODIMOVE    LD    A,(SCXT)
        DEC    A
        LD    (SCXT),A
        LD    A,(STATUSOBJ+BIGDINO+1)
        INC    A
        LD    (STATUSOBJ+BIGDINO+1),A
        LD    A,(STATUSOBJ+BIGMRDO+1)
        INC    A
        LD    (STATUSOBJ+BIGMRDO+1),A
        CP    8*6
        JR    Z,UPWELLY    ;IN MIDDLE?
        CP    8*21
        RET    NZ        ;OFF EDGE?
        POP    AF        ;THEN EXIT
        POP    AF
        CALL    WAITBLANK
        XOR    A
        LD    (LCDC),A
        RET

;---------------------------------------------------------------------------

DUMPBIG        LD    HL,STATUSOBJ
        LD    A,(SPEEDFLAG)
        SRL    A
        SRL    A
        SRL    A
        AND    %11
        LD    C,A
        ADD    A,A
        ADD    A,A
        ADD    A,A
        ADD    A,C
        LD    B,3
DUMPBG        LD    C,A
        LD    D,(HL)        ;YNO
        INC    L
        LD    E,(HL)        ;XNO
        DEC    L
        CALL    DUMP3BY3
        LD    A,C
        ADD    A,$24-9
        DEC    B
        JR    NZ,DUMPBG
        RET

;***************************************************************************
;DISPLAY+RESET LAST LEVEL SCORE&TIME/ADD TO RUNNING TOTAL/SHOW AVERAGE...

SHOWAVERAGES    LD    A,(LEVEL)
        INC    A
        CALL    BOARDLINED
        CALL    TOTOTAL        ;ADD  TO TOTAL...

        LD    DE,TOTAL
        LD    HL,5*$20+DISPSCREEN+8
        PUSH    DE
        CALL    DUMPDIGIT  
        POP    DE
        LD    HL,7*$20+DISPSCREEN+8
        LD    (HL),"0"
        INC    L
        LD    C,5
PUTAVER        LD    A,(DE)
        LD    (HLI),A
        INC    E
        DEC    C
        JR    NZ,PUTAVER
        INC    E

        INC    L        ;AVERAGE TIME...
        PUSH    HL
        LD    A,(DE)
        LD    L,A
        INC    E
        LD    A,(DE)
        LD    H,A        ;TOTAL TIME
        INC    E
        LD    A,(DE)        ;END OBJ
        LD    D,A
        LD    BC,-10
        CALL    DIVIDE
        LD    L,C
        LD    H,B
        LD    BC,-60
        CALL    DIVIDE
        LD    A,C
        LD    BC,60
        ADD    HL,BC
        LD    E,L
        POP    HL
        CALL    PRDECDIGITS    ;PRINT MINUTES
        INC    L
        LD    (HL),";"
        INC    L
        LD    A,E
        CALL    PRDECDIGITS    ;PRINT SECONDS
        LD    A,D
        LD    HL,STATUSOBJ    ;FINISH SPRITE
        LD    DE,$1C90
        CALL    DUMPENDOBJ

        LD    B,4
        CALL    RESETBOARD    ;RESET LAST 4
        LD    HL,AVRTEXT
        CALL    PRINTEXT
        LD    HL,BOARDTAB    ;CHANGE GRAPHIC SET
        CALL    CREATESET

        LD    A,%11000011
        LD    (LCDC),A
AVELOOP        CALL    WAITBLANK
        LD    A,>STATUSOBJ
        CALL    BLITS
        CALL    KEYS
        AND    %1000
        JR    Z,AVELOOP
        CALL    WAITBLANK
        XOR    A
        LD    (LCDC),A
        JP    START

;---------------------------------------------------------------------------

RESETBOARD    LD    HL,SCORE    ;RESET LAST 3 LEVELS
        LD    A,"0"
RESETB        LD    (HLI),A        ;RESET SCORE DIGITS
        LD    (HLI),A
        LD    (HLI),A
        LD    (HLI),A
        LD    (HLI),A
        LD    (HLI),A
        LD    (HL),0        ;RESET TIMER
        INC    L
        LD    (HL),0
        INC    L
        LD    (HL),0        ;RESET END OBJ
        INC    L
        DEC    B
        JR    NZ,RESETB
        RET        

BOARDLINED    LD    E,A
        XOR    A
        LD    (SCX),A
        LD    (SCY),A
        LD    (TALLOFF),A
        LD    A,%11100100
        LD    (OBP0),A
        CALL    CLEARDISP
        CALL    CLEARSTAT
        CALL    RESETOBJ
        LD    A,E
        LD    DE,SCORE    ;PLACE LEVEL SCORE
        LD    HL,2*$20+DISPSCREEN+1

BOARDLINE    PUSH    AF        ;WAVE NUMBER
        CALL    PRDECDIGITS
        INC    L
        INC    L
        CALL    DUMPDIGIT
        LD    A,$40-14
        ADD    A,L
        LD    L,A
        POP    AF
        INC    A
        RET

DUMPDIGIT    LD    C,6
PUTSCORE    LD    A,(DE)
        LD    (HLI),A
        INC    E
        DEC    C
        JR    NZ,PUTSCORE
        INC    L
        PUSH    HL
        LD    A,(DE)
        LD    L,A
        INC    E
        LD    A,(DE)
        LD    H,A
        INC    E
        LD    BC,-60
        CALL    DIVIDE
        LD    A,C
        LD    BC,60
        ADD    HL,BC
        LD    D,L
        POP    HL
        CALL    PRDECDIGITS    ;PRINT MINUTES
        INC    L
        LD    (HL),";"
        INC    L
        INC    E        ;IGNORE END OBJ
        LD    A,D
        LD    D,>SCORE
        JP    PRDECDIGITS

;ADD LEVEL SCORE TO RUNNING TOTAL...

TOTOTAL        LD    DE,SCORE
        LD    B,3
UPTOTAL        LD    HL,TOTAL
        LD    C,6
DIGITADD    LD    A,(DE)
        SUB    "0"
        CALL    UPSCORE
        INC    L
        INC    E
        DEC    C
        JR    NZ,DIGITADD
        INC    E        ;IGNORE TIMER
        INC    E
        INC    E        ;IGNORE END OBJ
        DEC    B
        JR    NZ,UPTOTAL
        RET

DUMPENDOBJ    ADD    A,A
        ADD    A,A
        ADD    A,$6C
        LD    C,A

DUMP2BY2SEQU    LD    (HL),D
        INC    L
        LD    A,E
        LD    (HLI),A
        LD    (HL),C
        INC    L
        LD    (HL),0
        INC    L
        INC    C
        LD    (HL),D
        INC    L
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    L
        LD    (HL),0
        INC    L
        INC    C
        LD    A,D
        ADD    A,8
        LD    (HLI),A
        LD    (HL),E
        INC    L
        LD    (HL),C
        INC    L
        LD    (HL),0
        INC    L
        INC    C
        LD    (HLI),A
        LD    A,E
        ADD    A,8
        LD    (HLI),A
        LD    (HL),C
        INC    L
        LD    (HL),0
        INC    L
        RET

;***************************************************************************
;HIGHSCORES...

ENTRIES        EQU    8
DIGTOT        EQU    6
INITOT        EQU    3
VARTOT        EQU    3
LINELEN        EQU    DIGTOT+INITOT+VARTOT
RANKCHR        EQU    0

CHECKHIGH    LD    DE,HIGHTAB
        LD    B,ENTRIES
CHECKLINE    PUSH    DE
        LD    HL,REALSCORE
        LD    C,DIGTOT
CHECKCHR    LD    A,(DE)
        CP    (HL)        ;HIGH-SCORE
        JR    C,ISBIG
        JR    NZ,NEXTLINE
        INC    E
        INC    L
        DEC    C
        JR    NZ,CHECKCHR
NEXTLINE    POP    DE
        LD    A,E
        ADD    A,LINELEN
        LD    E,A
        DEC    B
        JR    NZ,CHECKLINE
        RET

ISBIG        POP    DE

;SHUNT TABLE AND ENTER SCORE

        LD    HL,HIGHTABEND+LINELEN-1
        LD    DE,HIGHBUFF+LINELEN-1
SHUNTALL    LD    C,LINELEN
SHUNTLINE    LD    A,(HLD)
        LD    (DE),A
        DEC    E
        DEC    C
        JR    NZ,SHUNTLINE
        DEC    B
        JR    NZ,SHUNTALL
        INC    HL
        LD    DE,REALSCORE

        LD    B,DIGTOT    ;PLACE SCORE
PUTDIG        LD    A,(DE)
        LD    (HLI),A        
        INC    E
        DEC    B
        JR    NZ,PUTDIG

        LD    A,-1        ;WIPE NAME
        LD    (HLI),A    
        LD    (HLI),A
        LD    (HLI),A

        LD    A,(LEVEL)    ;PLACE LEVEL
        INC    A
        LD    (HLI),A
        LD    A,(TIMERTOTAL)    ;AND TIME
        LD    (HLI),A
        LD    A,(TIMERTOTAL+1)
        LD    (HL),A
        RET

PRHIGHSCORES
        LD    HL,$20*4+STATSCREEN
        LD    DE,HIGHTAB
        LD    A,ENTRIES

PRHIGHS        PUSH    AF
        ADD    A,RANKCHR
        LD    (HLI),A        ;PRINT RANK
        LD    C,6
        CALL    PRHGH        ;PRINT SCORE
        INC    L
        LD    C,3
        CALL    PRHGH        ;PRINT NAME
        INC    L
        LD    A,(DE)
        INC    E
        CALL    PRDECDIGITS    ;PRINT SCENE
        INC    L
        INC    L

        LD    A,(DE)
        INC    E
        PUSH    DE
        PUSH    HL
        LD    L,A
        LD    A,(DE)
        INC    E
        LD    H,A
        LD    BC,-60
        CALL    DIVIDE
        LD    A,C
        LD    BC,+60
        ADD    HL,BC
        LD    D,L
        POP    HL

        CALL    PRDECDIGITS    ;PRINT MINUTES
        INC    L
        LD    (HL),";"
        INC    L
        LD    A,D
        LD    D,>HIGHTAB
        CALL    PRDECDIGITS    ;PRINT SECONDS

        LD    DE,$20-19
        ADD    HL,DE
        POP    DE
        INC    E
        POP    AF
        DEC    A
        JR    NZ,PRHIGHS
        RET

PRHGH        LD    A,(DE)        ;PRINT SCORE/NAME
        LD    (HLI),A
        INC    E
        DEC    C
        JR    NZ,PRHGH
        RET

;***************************************************************************

        END

;***************************************************************************