;  System Call Equates
ACTINT  EQU     $0E             ; ACTIVATE INTERRUPTS
BCDADD  EQU     $62             ; BCD ADD ROUTINE
BMUSIC  EQU     $12             ; START MUSIC PROCESSOR
CHRDIS  EQU     $32             ; DISPLAY A CHARACTER
COLSET  EQU     $18             ; COLOR SET
DISNUM  EQU     $36             ; DISPLAY NUMBERS
DECCTS  EQU     $10             ; DECREMENT COUNTERS
EMUSIC  EQU     $14             ; STOP MUSIC
EXIT    EQU     $02             ; END OF MULTIPLE CALLS
GETPAR  EQU     $4C             ; GET PARAMETER
INDEXW  EQU     $5A             ; TABLE MANAGER
INTPC   EQU     $00             ; START MULTIPLE CALLS
MSKTD   EQU     $7E             ; JOYSTICK DELTA MASKING
NEGT    EQU     $74             ; BCD TO DECIMAL CONVERT
QUIT    EQU     $78             ; GAME OVER ROUTINE
RANGED  EQU     $76             ; RANDOM NUMBER GENERATOR
RCALL   EQU     4               ; SUBROUTINE CALL
RECTAN  EQU     $1C             ; RECTANGLE WRITE
SETOUT  EQU     $16             ; SET SCREEN PARMS
STIMER  EQU     $C8             ; START TIMER PROCESSOR
STRDIS  EQU     $34             ; STRING DISPLAY
VECT    EQU     $3E             ; VECTORING ROUTINE
VWRITR  EQU     $1E             ; VECTOR WRITE
WRITP   EQU     $22             ; PATTERN WRITE
WRITR   EQU     $20             ; RELATIVE WRITE
;  RAM STORAGE EQUATES
VECT1   DEFL    $4E88
VECT2   DEFL    $4E9A
VECT3   DEFL    $4EAC
VECT4   DEFL    $4EBE
VECT5   DEFL    $4ED0
VECT6   DEFL    $4EE2
GSTACK  DEFL    $4F54
CONVRT  DEFL    $4F55
SCROLL  DEFL    $4F56
MUZRET  DEFL    $4F58           ; MUSIC RAM BLOCK
INSTAT  DEFL    $4F5E
SAVEBC  DEFL    $4F78
TCOUNT  DEFL    $4F77
CMF     DEFL    $4F76
OCTANI  DEFL    $4F75
OCT2    DEFL    $4F73
BONTOT  DEFL    $4F5F
OCT3    DEFL    $4F6B
LEVSCO  DEFL    $4F62
IYSAVE  DEFL    $4F65
ANISPD  DEFL    $4F67
OXSTAT  DEFL    $4F68
TIMER   DEFL    $4F69
OXCONT  DEFL    $4F6A
OCTPAT  DEFL    $4F71
SUBV1   DEFL    $4F6D
SUBV2   DEFL    $4F6F
DINDEX  DEFL    $4FFC
ANIMAT  DEFL    $4F82
CPP     DEFL    $4FF5
PIN     DEFL    $4FF6
DELTA   DEFL    $4F85
DIVER   DEFL    $4F87
VECLIM  DEFL    $4F83
VBMR    DEFL    $4FA3
VBSTAT  DEFL    VBMR+1
VBTIMB  DEFL    VBMR+2
VBDXL   DEFL    VBMR+3
VBDXH   DEFL    VBMR+4
VBXL    DEFL    VBMR+5
VBXH    DEFL    VBMR+6
VBXCK   DEFL    VBMR+7
VBDYL   DEFL    VBMR+8
VBDYH   DEFL    VBMR+9
VBYL    DEFL    VBMR+10
VBYH    DEFL    VBMR+11
VBYCK   DEFL    VBMR+12
BOMAG   DEFL    $4F89
BOSTAT  DEFL    BOMAG+1
BOTIME  DEFL    BOMAG+2
BODXL   DEFL    BOMAG+3
BODXH   DEFL    BOMAG+4
BOXL    DEFL    BOMAG+5
BOXH    DEFL    BOMAG+6
BOXCK   DEFL    BOMAG+7
BODYL   DEFL    BOMAG+8
BODYH   DEFL    BOMAG+9
BOYL    DEFL    BOMAG+10
BOYH    DEFL    BOMAG+11
BOYCK   DEFL    BOMAG+12
OMAG    DEFL    $4F96
OSTAT   DEFL    OMAG+1
OTIME   DEFL    OMAG+2
ODXL    DEFL    OMAG+3
OXH     DEFL    OMAG+6
OXCK    DEFL    OMAG+7
ODYL    DEFL    OMAG+8
OYH     DEFL    OMAG+11
OYCK    DEFL    OMAG+12
PBLOCK  DEFL    $4FBA
TTAB    DEFL    $4F7A           ; 4 TEMP. WORD ENTRIES
MSTACK  DEFL    $4FB8
NUMPLA  DEFL    $4FF3
NUMDIV  DEFL    $4FF4
MSCORE  DEFL    $2C54           ; WHERE THE MUSIC IS
VECTOR  DEFL    $4FFD
SWAP    DEFL    $4FF4
COUNT   DEFL    $4FFB
;  OTHER EQUATES (BYTE VALUES)
PLAY1   EQU     $4FBA
PLAY2   EQU     $4FBF
PLAY3   EQU     $4FC4
PLAY4   EQU     $4FC9
VOICES  EQU     $FC             ; 4 VOICE = 11111100B
DMAX    EQU     10
DCOUNT  EQU     1
SNDCLR  EQU     116
GREEN   EQU     204
BLUE    EQU     248
BLACK   EQU     0
OYSPD   EQU     10              ; THIS VARIES OCT Y SPEED
BDELT   EQU     $45
CLEAN   DEFL    $0F13           ; CLEAR TO END OF VECTOR AREA
FLOAT   DEFL    $0015           ; ANTI-GRAV FACTOR
DEADPT  DEFL    $3B00           ; DEAD DIVER PAT
OCTP3   DEFL    $3AB6
SCORE   DEFL    $3280
HOMER   DEFL    $3F31           ; OR $3F81
MDEAD   DEFL    $3F76           ; OR $3F6E
DING    DEFL    $3F89           ; OR $3F81
ORG     $2000                   ; START OF CARTRIDGE
        JP      $2003           ; AUTO START
        LD      HL,$4000
        LD      DE,$4001
        LD      BC,$0FFF
        LD      (HL),L
        LDIR
        IM      2
        LD      SP,GSTACK
        RST     $38
        DB      INTPC           ; START MULT SUBRTINES
        DB      COLSET+1
        DW      ZERO            ; SET SCREEN TO BLACK
        DB      SETOUT+1
        DB      190
        DB      26
        DB      0
        DB      RECTAN+1
        DB      0
        DB      87
        DB      160
        DB      8
        DB      $55
        DB      STRDIS+1
        DB      38
        DB      1
        DB      $4C
        DW      TREAS
        DB      STRDIS+1
        DB      92
        DB      16
        DB      $4C
        DW      COVE
        DB      BMUSIC+1
        DW      MSTACK
        DB      VOICES
        DW      MSCORE
        DB      EXIT            ; END MULT CALLS
        LD      A,$FF
        LD      ($4FEC),A
        LD      BC,PATTAB       ; TABLE OF PATTERS
        CALL    NEXPAT
        LD      DE,$286E
        LD      HL,$3000        ; FIRST DIVER PAT
        LD      (DIVER),HL
        LD      A,10
        LD      (ANISPD),A
        CALL    STADIV          ; START THE DIVER
        RST     $38
        DB      COLSET+1
        DW      TITCOL
        LD      HL, $0020       ; SET UP DIVER VECTOR
        LD      (DELTA),HL
        LD      A,9
        LD      (PIN),A
        LD      HL,TITLIM
        LD      (VECLIM),HL
        LD      A,170      ; INTERRUPT LINE NUMBER
        OUT     (15),A
        LD      A,3
        LD      (SCROLL),A
        LD      HL,TITIES
        LD      (SWAP),HL
        LD      A,8
        OUT     ($0E),A
        LD      HL,TIT1
        CALL    INTSET
DO      JR      DO
TIT1    LD      A,(SCROLL)
        ADD     A,8
        LD      (SCROLL),A
        LD      B,57
CYCLE   ADD     A,8
        OUT     (3),A
        OUT     (7),A
        OUT     (3),A
        OUT     (7),A
        OUT     (3),A
        OUT     (7),A
        OUT     (3),A
        OUT     (7),A
        DJNZ    CYCLE
        LD      A,BLACK
        OUT     (3),A
        OUT     (7),A
        CALL    $200
        LD      A,(VBXCK)
        BIT     3,A
        JR      Z,YCHEK
        LD      A,1
        LD      (VBXCK),A
        LD      A,(PIN)
        XOR     12
        LD      (PIN),A
        LD      HL,(SWAP)
        LD      DE,(VECLIM)
        LD      (SWAP),DE
        LD      (VECLIM),HL
YCHEK   LD      A,(VBYCK)
        BIT     3,A
        JR      Z,SET2
        LD      A,1
        LD      (VBYCK),A
        LD      A,(PIN)
        XOR     3
        LD      (PIN),A
SET2    LD      HL,TIT2
        LD      (VECTOR),HL
        LD      A,80
        OUT     (15),A
        EI
        RET
TIT2    CALL    DVRRTN
        LD      HL,TIT3
        LD      (VECTOR),HL
        LD      A,186
        OUT     (15),A
        EI
        RET
TIT3    LD      A,SNDCLR
        OUT     (0),A
        OUT     (4),A
        CALL    MUSIC
        IN      A,($10)
        AND     A
        JR      NZ,GSTART
        IN      A,($14)
        AND     A
        JR      NZ,GSTART
        IN      A,($15)
        AND     A
        JR      NZ,GSTART
        IN      A,($16)
        CP      3
        JP      M,W1
        AND     A
        JR      NZ,GSTART
W1      IN      A,($17)
        CP      3
        JP      M,W2
        AND     A
        JR      NZ,GSTART
W2      LD      HL,TIT1
        LD      (VECTOR),HL
        LD      A,0
        OUT     (15),A
        LD      B,255
WAITER  NOP
        DJNZ    WAITER
        LD      A,GREEN
        OUT     (0),A
        OUT     (4),A
        EI
        RET
GSTART  CALL    ERASE
        RST     $38
        DB      COLSET+1
        DW      PSCOL
        RST     $38
        DB      SETOUT+1
        DB      183
        DB      41
        DB      8
        LD      A,$FF
        LD      ($4FEC),A
        RST     $38
        DB      ACTINT
        LD      DE,LOGO
NOGOOD  RST     $38
        DB      GETPAR+1
        DW      PROMPT
        DB      1
        DW      NUMPLA
        LD      A,(NUMPLA)
        AND     A
        JR      Z,NOGOOD
        CP      5
        JP      P,NOGOOD
        LD      DE,LOGO2
        RST     $38
        DB      GETPAR+1
        DW      DPRMPT
        DB      1
        DW      NUMDIV
        LD      A,(NUMDIV)
        AND     A
        JR      NZ,OK
        INC     A
OK      LD      (NUMDIV),A
        CALL    ERASE
        LD      A,186
        OUT     (10),A
        LD      A,$EC
        OUT     (9),A
        LD      DE,$0004
        LD      A,(NUMPLA)
        LD      B,A
        LD      A,(NUMDIV)
        LD      HL,PBLOCK+3
INIT    LD      (HL),A
        INC     HL
        LD      (HL),1
        ADD     HL,DE
        DJNZ    INIT
ONE     LD      BC,$100
TWO     RST     $38
        DB      COLSET+1
        DW      BANDW
        LD      A,B
        LD      HL,PLATAB-2
        RST     $38
        DW      INDEXW
        PUSH    DE
        POP     IY
        LD      (IYSAVE),DE
        LD      A,15
        ADD     A,B
        LD      (CPP),A
        LD      HL,MUINT
        CALL    INTSET
        LD      A,(IY+3)
        AND     A
        JR      NZ,LIVING
        INC     C
        LD      A,4
        CP      C
        JP      Z,GAMEND
        JR      SKIPLA
LIVING  LD      (SAVEBC),BC
        LD      A,44
        OUT     (9),A
        RST     $38
        DB      STRDIS+1
        DB      $20
        DB      20
        DB      4
        DW      PLAYUP
        LD      A,$30
        OR      B
        LD      C,4
        LD      DE,$1459
        RST     $38
        DB      CHRDIS
        CALL    ADDERL
        CALL    SCODIS
        CALL    PULLED
        LD      HL,DUMMY
        CALL    INTSET
WAIT    JR      WAIT
CONTNU  DI
        POP     HL              ; THROW AWAY DUMMY RETURN VALUE
        CALL    ERASE
        RST     $38
        DB      COLSET+1
        DW      TOPCOL
        JR      PLOOP
RETURN  CALL    FPULL
DRET    LD      B,180
HALT1   HALT   
        DJNZ    HALT1
        LD      HL,MUINT
        CALL    INTSET
        CALL    ERASE
        LD      BC,(SAVEBC)
SKIPLA  INC     B
        LD      A,5
        CP      B
        JP      Z,ONE
        JP      TWO
PLOOP   LD      A,1
        LD      (INSTAT),A
        LD      HL,INT1
        CALL    INTSET
        RST     $38
        DB      RECTAN+1
        DB      0
        DB      0
        DB      160
        DB      10
        DB      $FF
        RST     $38
        DB      RECTAN+1
        DB      0
        DB      88
        DB      160
        DB      6
        DB      $55
        LD      BC,GPTAB
        CALL    NEXPAT
        RST     $38
        DB      WRITP+1
        DB      24
        DB      87
        DB      $10
        DW      $32E6
        LD      B,4
        PUSH    HL
        PUSH    AF
POP1    POP     AF
        POP     HL
REPEAT  RST     $38
        DB      RANGED+1
        DB      26
        LD      E,A
        LD      D,0
        LD      HL,$4C86
        ADD     HL,DE
        PUSH    HL
        LD      E,$50
        ADD     HL,DE
        PUSH    AF
        LD      A,(HL)
        AND     60
        CP      60
        JR      Z,POP1
        POP     AF
        SLA     A
        SLA     A
        ADD     A,24
        LD      E,A
        LD      D,82
        LD      HL,$3700        ; TREASURE PATTERN
        LD      A,$10
        RST     $38
        DB      WRITP
        LD      HL,TTAB-2
        LD      A,B
        RST     $38
        DB      INDEXW
        POP     DE
        LD      (HL),E
        INC     HL
        LD      (HL),D
        DJNZ    REPEAT
        LD      A,$20
        LD      (OMAG),A
        LD      (BOMAG),A
        LD      A,$80
        LD      (OSTAT),A
        LD      (BOSTAT),A
        LD      A,1
        LD      (BOXCK),A
        LD      A,3
        LD      (OXCK),A
        LD      (OYCK),A
        LD      HL,BDELT
        LD      (BODXL),HL
        RST     $38
        DB      RANGED+1
        DB      100
        ADD     A,30
        LD      (BOXH),A
        RST     $38
        DB      VWRITR+1
        DW      BOMAG
        DW      $3706           ; BOAT PATTERN
        XOR     A
        LD      (OMAG+4),A
        LD      (OMAG+5),A
        LD      (OMAG+9),A
        LD      (OMAG+10),A
        LD      (VBSTAT),A
        LD      (TCOUNT),A
        RST     $38
        DB      RANGED
        LD      (ODXL),A
        LD      A,OYSPD
        LD      (ODYL),A
        RST     $38
        DB      RANGED+1
        DB      60
        ADD     A,40
        LD      (OXH),A
        LD      A,66
        LD      (OYH),A
        RST     $38
        DB      VWRITR+1
        DW      OMAG
        DW      $3764           ; OCTOPUS PATTERN
        LD      HL,$3764
        LD      (OCTPAT),HL
        LD      HL,$3999
        LD      (OCT2),HL
        LD      HL,OCTP3
        LD      (OCT3),HL
        LD      A,5
        LD      (OCTANI),A
        LD      A,(IY+4)
        INC     A
        INC     A
        CP      7
        JP      M,LIMIT
        LD      A,6
LIMIT   LD      (CMF),A
        LD      A,$90           ; SETUP BEEP
        LD      (MUZRET),A
        LD      A,$B0
        LD      (MUZRET+2),A
        LD      A,$C9
        LD      (MUZRET+5),A
        LD      HL,SUBTAB
        LD      (SUBV1),HL
        LD      HL,SUBTB2
        LD      (SUBV2),HL
        LD      DE,BONTOT
        CALL    DESET
        XOR     A
        LD      (INSTAT),A
HOME    CALL    FIS
HEREIS  LD      A,100
        LD      (OXCONT),A
        LD      A,1
        LD      (INSTAT),A
        RST     $38
        DB      RECTAN+1
        DB      37
        DB      88
        DB      102
        DB      3
        DB      $FF
        RST     $38
        DB      RECTAN+1
        DB      38
        DB      89
        DB      100
        DB      1
        DB      0
        XOR     A
        LD      (INSTAT),A
        CALL    FPULL
HITIS   CALL    FISHW
        XOR     A
        LD      (OXSTAT),A
        LD      A,(CPP)         ; GET CURRENT PLAYER PORT
        LD      C,A
        IN      A,(C)
        BIT     4,A             ; IS TRIGGER PULLED?
        JR      Z,HITIS         ; NOPE, WAIT
        LD      A,(BOMAG)
        LD      E,A
        LD      A,(BOXH)
        BIT     6,E
        JR      Z,LOAD
        LD      E,A
        LD      A,138
        SUB     E
LOAD    LD      E,A
        LD      D,10            ; Y START POSITION
        LD      HL,GAMLIM
        LD      (VECLIM),HL     ; SET VECTOR LIMIT TABLE
        LD      HL,$3000
        LD      (DIVER),HL
        XOR     A
        LD      (ANIMAT),A
        CALL    STADIV          ; START DIVER
TWATCH  CALL    MOVDIV
        LD      A,(VBSTAT)
        CP      1
        JP      Z,DRET
        LD      B,4
DITTO   LD      A,B
        LD      HL,TTAB-2
        RST     $38
        DB      INDEXW
        XOR     A
        SUB     E
        JR      Z,GONE
        LD      A,(DE)
        AND     A
        JR      NZ,GOTIT
GONE    DJNZ    DITTO
        JR      TWATCH
GOTIT   XOR     A
        LD      (HL),A
        LD      A,E
        SLA     A
        SLA     A
        LD      E,A
        LD      D,82
        LD      HL,$3700
        LD      A,1
        LD      (INSTAT),A
        LD      A,$20
        RST     $38
        DB      WRITP
        LD      DE,DING
        CALL    DOBEEP
        XOR     A
        LD      (INSTAT),A
BWATCH  CALL    MOVDIV
        LD      A,(VBSTAT)
        CP      $FF
        JP      Z,BWATCH
        CP      1
        JP      Z,DRET
        LD      A,(BOMAG)
        BIT     6,A
        LD      A,(BOXH)
        JR      Z,NBFLOP
        LD      L,A
        LD      A,128
        SUB     L
NBFLOP  SRL     A
        SRL     A
        LD      L,A
        LD      H,0
        LD      DE,$4190
        ADD     HL,DE
        LD      B,8
NOHOME  LD      A,(HL)
        AND     A
        JR      NZ,BACK
        INC     HL
        DJNZ    NOHOME
        JR      BWATCH
BACK    XOR     A
        LD      (OXSTAT),A
        LD      (VBSTAT),A
        LD      HL,(DIVER)
        LD      A,(VBYH)
        LD      D,A
        LD      A,(VBXH)
        LD      E,A
        LD      A,1
        LD      (INSTAT),A
        LD      A,(VBMR)
        RST     $38
        DB      WRITR
        XOR     A
        LD      (INSTAT),A
        LD      DE,HOMER
        CALL    DOBEEP
        LD      HL,LEVSCO       ; ADD TREASURE
        PUSH    IY
        POP     DE
        LD      B,3
        RST     $38
        DB      BCDADD
        CALL    ADDERO
        LD      A,(TCOUNT)
        INC     A
        LD      (TCOUNT),A
        CP      4
        JR      Z,EOB
        LD      B,180
HALT2   HALT
        PUSH    BC
        CALL    FISHW
        POP     BC
        DJNZ    HALT2
        JP      HEREIS
EOB     INC     (IY+4)        
        CALL    ENDADD
        JP      RETURN          ; ADD SCORES, BONUS,...
MOVDIV  LD      A,(CPP)
        LD      C,A
        LD      A,2
        LD      (ANISPD),A
        IN      A,(C)
        LD      HL,$100
        LD      (DELTA),HL
        BIT     4,A
        JR      Z,CONT
        LD      HL,(DELTA)
        ADD     HL,HL
        LD      (DELTA),HL
        PUSH    AF
        LD      A,1
        LD      (ANISPD),A
        POP     AF
CONT    AND     $F              ; MASK OFF TRIGGER
        LD      (PIN),A         ; SAVE PLAYER INPUT
FISHW   LD      A,(CMF)
        LD      B,A
FISHER  LD      A,B
        DEC     A
        LD      HL,FISHVT
        RST     $38
        DB      INDEXW
        PUSH    DE
        POP     IX
        BIT     7,(IX+1)
        CALL    Z,SAFISH
        DJNZ    FISHER
        RET
FIS     LD      A,(CMF)
        LD      B,A
X1      LD      A,B
        DEC     A
        LD      HL,FISHVT
        RST     $38
        DB      INDEXW
        PUSH    DE
        POP     IX
        RST     $38
        DB      RANGED+1
        DB      80
        LD      (IX+6),A
        CALL    FIRST
        DJNZ    X1
        RET
SAFISH  LD      (IX+6),0
FIRST   LD      A,4             ; DETERMINE # OF FISH PATS
        ADD     A,(IY+4)
        CP      NUMFIS
        JP      M,NOLOAD
        LD      A,NUMFIS
NOLOAD  RST     $38
        DB      RANGED
        LD      HL,FISHIN
        RST     $38
        DB      INDEXW
        LD      A,(DE)
        LD      (IX+13),A
        INC     DE
        LD      A,(DE)
        LD      (IX+14),A
        INC     DE
        LD      A,(DE)
        LD      (IX+15),A
        INC     DE
        LD      A,(DE)
        LD      (IX+16),A
        INC     DE
        LD      A,(DE)
        LD      (IX+4),A
        XOR     A
        RST     $38
        DB      RANGED
        BIT     7,A
        JR      Z,NOMAGF
        LD      (IX+0),$60
        JR      MAGF
NOMAGF  LD      (IX+0),$20
MAGF    LD      (IX+5),0
        LD      (IX+9),0
        LD      (IX+10),0
        LD      A,225
        RST     $38
        DB      RANGED
        ADD     A,30
        LD      (IX+3),A
        LD      A,225
        RST     $38
        DB      RANGED
        ADD     A,30
        LD      (IX+8),A
        LD      A,30
        RST     $38
        DB      RANGED
        ADD     A,25
        LD      (IX+11),A
        LD      (IX+7),1
        LD      (IX+12),3
        LD      (IX+17),2
        LD      A,1
        LD      (INSTAT),A
        LD      H,(IX+14)
        LD      L,(IX+13)
        RST     $38
        DB      VWRITR
        LD      (IX+1),$80
        XOR     A
        LD      (INSTAT),A
        RET
INT1    EX      AF,AF'
        OUT     (9),A
        EXX
        CALL    $200
        LD      A,140
        OUT     (15),A
        LD      HL,INT2
        LD      (VECTOR),HL
        LD      A,(OXSTAT)
        AND     A
        JR      Z,TTSKIP
        LD      A,(CPP)
        LD      C,A
        IN      A,(C)
        LD      B,A
        BIT     4,B
        JR      Z,B2
        LD      B,3
        JR      TREPT
B2      LD      B,1
TREPT   LD      A,(TIMER)
        DEC     A
        LD      (TIMER),A
        JR      NZ,TSKIP
        LD      A,20            ; OXYGEN TIMER
        LD      (TIMER),A
        LD      A,(OXCONT)
        DEC     A
        LD      (OXCONT),A
        JR      NZ,TSKIP
        XOR     A
        LD      (OXSTAT),A
        LD      DE,MDEAD
        CALL    DOBEEP
        LD      A,$FF
        LD      (VBSTAT),A
        JR      TTSKIP
TSKIP   DJNZ    TREPT
TTSKIP  LD      DE,$598A
        LD      A,(INSTAT)
        AND     A
        JR      NZ,PSAFE
        LD      A,(OXCONT)
        LD      C,A
        LD      A,100
        SUB     C
        LD      C,A
        LD      B,A
        LD      A,E
        SUB     B
        LD      E,A
        LD      A,$AA
        LD      B,1
        RST     $38
        DB      RECTAN
PSAFE   EXX
        LD      A,$C0
        EX      AF,AF'
        EI
        RET
DUMMY   EXX
        EX      AF,AF'
        CALL    $200
        CALL    MUSIC
        LD      A,(CPP)
        LD      C,A
        IN      A,(C)
        BIT     4,A
        JP      NZ,CONTNU
        EX      AF,AF'
        EXX
        EI
        RET
MUINT   EXX
        EX      AF,AF'
        CALL    $200
        CALL    MUSIC
        EX      AF,AF'
        EXX
        EI
        RET
INT2    EX      AF,AF'
        OUT     (9),A
        EXX
        PUSH    IX
        PUSH    IY
        LD      A,(INSTAT)
        AND     A
        JR      NZ,MAGIC
        LD      IY,(IYSAVE)
        LD      A,(COUNT)
        INC     A
        CP      6
        JR      NZ,STORE
        XOR     A
STORE   LD      (COUNT),A
        LD      HL,(SUBV1)
        LD      E,A
        LD      D,0
        SLA     E
        RL      D
        ADD     HL,DE
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        LD      HL,MAGIC
        PUSH    HL
        EX      DE,HL
        JP      (HL)
MAGIC   LD      A,19
        OUT     (15),A
        LD      HL,INT1
        LD      (VECTOR),HL
        POP     IY
        POP     IX
        EXX
        XOR     A
        EX      AF,AF'
        EI
        RET
STADIV  LD      A,E
        LD      (VBXH),A
        LD      A,D
        LD      (VBYH),A
        XOR     A
        LD      (VBXL),A
        LD      (VBYL),A
        INC     A
        LD      (VBXCK),A
        LD      (VBYCK),A
        LD      A,$80
        LD      (VBSTAT),A
        LD      A,1
        LD      (INSTAT),A
        LD      A,$20
        LD      (VBMR),A
        LD      HL,(DIVER)
        RST     $38
        DB      WRITR
        XOR     A                                     
        LD      (INSTAT),A
        LD      A,1
        LD      (OXSTAT),A
        LD      A,25
        LD      (TIMER),A
        LD      A,(ANISPD)
        CP      10
        RET     Z
        LD      A,1
        LD      (INSTAT),A
        RST     $38
        DB      RECTAN+1
        DB      37
        DB      88
        DB      102
        DB      3
        DB      $FF
        RST     $38
        DB      RECTAN+1
        DB      38
        DB      89
        DB      100
        DB      1
        DB      0
        XOR     A
        LD      (INSTAT),A
        RET
ATTOP   LD      A,1
        LD      (VBSTAT),A
        DEC     (IY+3)
        RET
DDRTN   LD      HL,DEADPT       ; DEAD DIVER PATTERN
        LD      (DIVER),HL
        LD      HL,GAMLIM
        LD      DE,0
        LD      (VBDXL),DE
        LD      DE,$FF00
        LD      (VBDYL),DE
        LD      A,1
        LD      (VBTIMB),A
        RST     $38
        DB      VECT
        LD      HL,(DIVER)
        RST     $38
        DB      VWRITR
        LD      A,(VBYCK)
        BIT     3,A
        JR      NZ,ATTOP                             
        RET
DVRRTN  LD      A,(VBSTAT)
        CP      1
        RET     Z
        BIT     7,A
        RET     Z
        LD      HL,(DIVER)
        LD      IX,VBMR         ; DIVER VECTOR
        RST     $38
        DB      VWRITR
        LD      A,(VBSTAT)
        CP      $FF
        JR      Z,DDRTN
        LD      A,(PIN)
        AND     A
        JP      Z,MOVED
        LD      A,(ANISPD)
        LD      B,A
        LD      A,(ANIMAT)
        INC     A
        CP      B
        LD      (ANIMAT),A
        JP      M,MOVED
        XOR     A
        LD      (ANIMAT),A
        LD      A,(DINDEX)
        INC     A
        CP      DMAX
        LD      (DINDEX),A
        JP      M,NDPATT
        XOR     A
        LD      (DINDEX),A
NDPATT  LD      HL,DPTAB
        RST     $38
        DB      INDEXW
        LD      (DIVER),DE
MOVED   LD      A,(PIN)
        LD      B,A
        LD      A,(VBMR)
        BIT     2,B
        JR      NZ,LEFT
        BIT     3,B
        JR      NZ,RIGHT
        JR      SKIP
LEFT    BIT     6,A
        JR      NZ,SKIP
        LD      A,$60
        JR      FLIP
RIGHT   BIT     6,A
        JR      Z,SKIP
        LD      A,$20
FLIP    LD      (VBMR),A
        LD      A,(VBXH)
        LD      E,A
        LD      A,135
        SUB     E
        LD      (VBXH),A
SKIP    LD      A,(VBMR)                                   
        LD      C,A
        LD      HL,(DELTA)
        LD      DE,(DELTA)
        RST     $38
        DB      MSKTD
        LD      (VBDXL),DE
        LD      DE,FLOAT
        CCF
        SBC     HL,DE
        LD      (VBDYL),HL
        LD      A,1
        LD      (VBTIMB),A      ; LOAD TIME BASE
        LD      HL,(VECLIM)
        RST     $38
        DB      VECT
        IN      A,(8)           ; CLEAR INTERCEPT
        LD      HL,(DIVER)
        RST     $38
        DB      VWRITR
        IN      A,(8)           ; CHECK INTERCEPT
        AND     A
        JR      Z,NDEAD
        JP      NDEAD   ; TEST !!!!!!!!!!!!!!!!!!
        LD      DE,$3F6E
        CALL    DOBEEP
        LD      A,$FF
        LD      (VBSTAT),A
        XOR     A
        LD      (OXSTAT),A
NDEAD   RET
BOMOV   RST     $38
        DB      VWRITR+1
        DW      BOMAG
        DW      $3706           ; BOAT PATTERN
        LD      A,(BOXCK)
        BIT     3,A
        JR      Z,MBO
        LD      A,1
        LD      (BOXCK),A
        LD      A,(BOMAG)
        XOR     $40
        LD      (BOMAG),A
        LD      A,(BOXH)
        LD      E,A
        LD      A,124
        SUB     E
        LD      (BOXH),A
MBO     LD      A,1
        LD      (BOTIME),A
        RST     $38
        DB      VECT+1
        DW      BOMAG
        DW      BOLIM
        RST     $38
        DB      VWRITR+1
        DW      BOMAG
        DW      $3706           ; BOAT PATTERN
        RET
OCT     LD      IX,OMAG
        LD      HL,(OCTPAT)
        RST     $38
        DB      VWRITR
        XOR     A
        RST     $38
        DB      RANGED
        LD      (ODXL),A
        LD      A,1
        LD      (OTIME),A
        RST     $38
        DB      VECT+1
        DW      OMAG
        DW      OLIM
        LD      HL,OCTANI
        DEC     (HL)
        JR      NZ,OCTSKP
        LD      (HL),3
        LD      HL,(OCT3)
        LD      DE,(OCT2)
        LD      (OCT3),DE
        LD      DE,(OCTPAT)
        LD      (OCT2),DE
        LD      (OCTPAT),HL
OCTSKP  LD      HL,(OCTPAT)
        RST     $38
        DB      VWRITR
        LD      HL,(SUBV1)
        LD      DE,(SUBV2)
        LD      (SUBV1),DE
        LD      (SUBV2),HL
        RET
NEXPAT  LD      A,(BC)
        LD      E,A
        INC     BC
        LD      A,(BC)
        LD      D,A
        INC     BC
        LD      A,(BC)
        LD      L,A
        INC     BC
        LD      A,(BC)
        LD      H,A
        INC     BC
        LD      A,$FF
        CP      E
        JR      Z,OUT1
        LD      A,$10
        RST     $38
        DB      WRITP
        JR      NEXPAT
OUT1    RET
ERASE   LD      BC,CLEAN
UERASE  LD      HL,$4000
        LD      DE,$4001
        LD      (HL),L
        LDIR
        RET
AFISH   BIT     7,(IX+1)
        RET     Z
        LD      H,(IX+14)
        LD      L,(IX+13)
        RST     $38
        DB      VWRITR
        LD      HL,FISLIM
        LD      (IX+2),1
        RST     $38
        DB      VECT
        BIT     3,(IX+7)
        JR      Z,ANIM
        LD      (IX+1),0
        RET
ANIM    DEC     (IX+17)
        JR      NZ,NOSWAP
        LD      (IX+17),2
        LD      E,(IX+13)
        LD      D,(IX+14)
        LD      L,(IX+15)
        LD      H,(IX+16)
        LD      (IX+13),L
        LD      (IX+14),H
        LD      (IX+15),E
        LD      (IX+16),D
NOSWAP  LD      H,(IX+14)                
        LD      L,(IX+13)
        RST     $38
        DB      VWRITR
        RET
FISH1   LD      IX,VECT1
        JR      PHONE
FISH2   LD      IX,VECT2
        JR      PHONE
FISH3   LD      IX,VECT3
        JR      PHONE
FISH4   LD      IX,VECT4
        JR      PHONE
FISH5   LD      IX,VECT5
        JR      PHONE
FISH6   LD      IX,VECT6
PHONE   CALL    AFISH
        EI
        RET
INTSET  DI
        LD      (VECTOR),HL
        LD      HL,VECTOR
        LD      A,H
        LD      I,A
        LD      A,L
        OUT     (13),A
        EI
        RET
GAMEND  LD      HL,MUINT
        CALL    INTSET
        LD      A,44
        OUT     (9),A
        DI
        RST     $38
        DB      STRDIS+1
        DB      $20
        DB      20
        DB      4
        DW      GAMOVR
        LD      L,0
        LD      (IYSAVE),HL                                                                                                               
        CALL    SCODIS
        EI
RESET   IN      A,($10)
        BIT     4,A
        JR      Z,RESET
        RST     0
FPULL   CALL    FISHW
PULLED  LD      A,(CPP)
        LD      C,A
        IN      A,(C)
        BIT     4,A
        JR      NZ,PULLED
        RET
SCODIS  RST     $38
        DB      STRDIS+1
        DB      $20
        DB      $27
        DB      12
        DW      SCODIV
        RST     $38
        DB      WRITR+1
        DB      86
        DB      $27
        DB      $20
        DW      $3000           ; DIVER PAT
        LD      A,(IYSAVE)
        AND     A
        JR      NZ,NOEND
        LD      HL,$3D76
        JR      CHEST
NOEND   LD      A,(IY+4)
        DEC     A
        CP      NUMFIS-3
        JP      M,MAXED
        LD      A,NUMFIS-1
MAXED   LD      HL,FISHIN
        RST     $38
        DB      INDEXW
        LD      A,(DE)
        LD      L,A
        INC     DE
        LD      A,(DE)
        LD      H,A
CHEST   LD      A,$20
        LD      DE,$207E
        RST     $38
        DB      WRITR
        XOR     A
NEXNUM  LD      HL,PLATAB
        RST     $38
        DB      INDEXW
        EX      DE,HL
        PUSH    AF
        LD      D,A
        SLA     D
        SLA     D
        SLA     D
        LD      A,48
        ADD     A,D
        LD      D,A
        POP     AF
        LD      E,$20
        LD      BC,$8608
        RST     $38
        DB      DISNUM
        LD      E,99
        LD      B,1
        INC     HL
        INC     HL
        INC     HL
        RST     $38
        DB      DISNUM
        LD      E,120
        INC     HL
        PUSH    AF
        LD      A,(HL)
        AND     $F0
        LD      B,A
        LD      A,(HL)
        DEC     A
        AND     $F0
        CP      B
        JR      Z,SAME
        LD      A,(HL)
        ADD     A,6
        LD      (HL),A
SAME    LD      A,(HL)
        LD      HL,CONVRT
        ADD     A,0
        DAA
        LD      (HL),A
        POP     AF
        LD      B,$82
        RST     $38
        DB      DISNUM
        LD      C,12
        PUSH    AF
        LD      E,20
        ADD     A,$31
        RST     $38
        DB      CHRDIS
        LD      A,(NUMPLA)
        LD      B,A
        POP     AF
        INC     A
        CP      B
        JP      NZ,NEXNUM
        RET
ADDERL  LD      B,(IY+4)
        LD      DE,LEVSCO
        CALL    DESET
        LD      HL,HUND
ADD1    PUSH    BC
        LD      B,3
        RST     $38
        DB      BCDADD
        POP     BC
        DJNZ    ADD1
        RET
ADDERO  LD      A,(OXCONT)
        LD      B,A
        LD      DE,BONTOT
        LD      HL,ONEP
ADD2    PUSH    BC
        LD      B,3
        RST     $38
        DB      BCDADD
        POP     BC
        DJNZ    ADD2
        RET
ENDADD  PUSH    IY
        POP     DE
        LD      HL,BONTOT
        LD      B,3
        RST     $38
        DB      BCDADD
        RET
DESET   XOR     A
        LD      (DE),A
        INC     DE
        LD      (DE),A
        INC     DE
        LD      (DE),A
        DEC     DE
        DEC     DE
        RET
DOBEEP  DI
        PUSH    DE
        LD      A,($4FD4)       ; VOICES
        LD      (MUZRET+1),A
        LD      HL,($4FD2)      ; VOLUMES
        LD      (MUZRET+3),HL
        LD      DE,($4FCE)      ; MUZPC
        LD      HL,($4FD0)      ; MUZSP
        DEC     HL
        LD      (HL),D
        DEC     HL
        LD      (HL),E
        POP     DE
        LD      ($4FCE),DE
        LD      ($4FD0),HL
        EI
        RET
MUSIC   IN      A,($17)
        BIT     1,A
        JR      Z,STARTM
        RST     $38
        DB      BMUSIC+1
        DW      MSTACK
        DB      VOICES
        DW      NULL
        RET
STARTM  IN      A,($16)
        BIT     1,A
        RET     Z
        RST     $38
        DB      BMUSIC+1
        DW      MSTACK
        DB      VOICES
        DW      MSCORE
        RET
;  ROM DATA TABLES
NULL    DB      $E1             ; NULL MUSIC
        DB      1
        JP      NULL
ZERO    DB      0
        DB      0
        DB      0
        DB      0
        DB      0
        DB      0
        DB      0
        DB      0
TOPCOL  DB      248
        DB      247
        DB      119
        DB      GREEN
        DB      248
        DB      119
        DB      247
        DB      GREEN
MIDCOL  DB      248
        DB      119
        DB      247
        DB      GREEN
        DB      248
        DB      119
        DB      247
        DB      GREEN
BOTCOL  DB      0
        DB      150
        DB      SNDCLR
        DB      GREEN
        DB      0
        DB      150
        DB      SNDCLR
        DB      GREEN
TITCOL  DB      248
        DB      154
        DB      116
        DB      163
        DB      248
        DB      119
        DB      116
        DB      163
PSCOL   DB      248
        DB      0
        DB      247
        DB      163
        DB      248
        DB      0
        DB      247
        DB      163
BANDW   DB      119     
        DB      0
        DB      7
        DB      242
        DB      7
        DB      7
        DB      7
        DB      0
PLATAB  DW      PLAY1
        DW      PLAY2
        DW      PLAY3
        DW      PLAY4
FISHVT  DW      VECT1
        DW      VECT2
        DW      VECT3
        DW      VECT4
        DW      VECT5
        DW      VECT6
NUMFIS  EQU     19
FISHIN  DW      F1
        DW      F2
        DW      F3
        DW      F4
        DW      F5
        DW      F6
        DW      F7
        DW      F8
        DW      F9
        DW      F10
        DW      F11
        DW      F12
        DW      F13
        DW      F14
        DW      F15
        DW      F16
        DW      F17
        DW      F18
        DW      F19
F1      DW      $37AE           ; SHARK
        DW      $3BF4
        DB      2
F2      DW      $3200           ; BLACK FISHIE
        DW      $3200
        DB      3
F3      DW      $3200           ; BLACK/BLUE BLINK
        DW      $3EBF
        DB      2
F4      DW      $3210           ; BLUE ANIM
        DW      $3EBF
        DB      2
F5      DW      $3210           ; BLINK FISHIE
        DW      $3EAF
        DB      2
F6      DW      $3210           ; YELLOW ANIM
        DW      $3EAF
        DB      2
F7      DW      $31C4           ; BARRACUDA
        DW      $31D4
        DB      4
F8      DW      $31E4           ; GOLDFISH
        DW      $31F2
        DB      3
F9      DW      $3E9B           ; SNARK
        DW      $3EA5
        DB      3
F10     DW      $3E4D           ; TURTLE
        DW      $3E74
        DB      1
F11     DW      $3DDC           ; SEAHORSE
        DW      $3E13
        DB      3
F12     DW      $3C5B           ; SAILFISK
        DW      $3CBA
        DB      2
F13     DW      $3A6E           ; NOSE FISH
        DW      $3A92
        DB      1
F14     DW      $3972           ; CLAIM
        DW      $3980
        DW      2
F15     DW      $3B2C           ; SWORD FISH
        DW      $3B90
        DB      2
F16     DW      $390E           ; PARTY SUB
        DW      $39E3
        DB      1
F17     DW      $3D12           ; SQUID
        DW      $3280
        DB      2
F18     DW      $3A47           ; CRAB
        DW      $3A57
        DB      3
F19     DW      $3764           ; OCT
        DW      $3AB6
        DB      3
HUND    DB      0
ONEP    DB      1
        DB      0
        DB      0
PLAYUP  DB      'PLAYER   UP'
        DB      0
TREAS   DB      'TREASURE'
        DB      0
COVE    DB      'COVE'
        DB      0                                                                                                                                                                            
LOGO    DB      '   (C) 1983         SPECTRE SYSTEMS  '
        DB      0
LOGO2   DB      'BY BRETT BILBREY    FOR SPECTRECADE  '
        DB      0
PROMPT  DB      'NUMBER OF     PLAYERS'
        DB      0
DPRMPT  DB      'NUMBER OF     DIVERS'
        DB      0
SCODIV  DB      'SCORE'
        DB      0
GAMOVR  DB      'SORRY CHARLIE..'
        DB      0
TITLIM  DB      100
        DB      130
        DB      30
        DB      45
GAMLIM  DB      0
        DB      130
        DB      10
        DB      74
BOLIM   DB      0
        DB      124
TITIES  DB      0
        DB      30
        DB      30
        DB      45
OLIM    DB      20
        DB      120
        DB      64
        DB      66
FISLIM  DB      0
        DB      125
        DB      12
        DB      55
SUBTAB  DW      DVRRTN
        DW      BOMOV
        DW      OCT
        DW      FISH1
        DW      FISH2
        DW      FISH3
SUBTB2  DW      DVRRTN
        DW      BOMOV
        DW      OCT
        DW      FISH4
        DW      FISH5
        DW      FISH6
DPTAB   DW      $3000
        DW      $302E
        DW      $305C
        DW      $308A
        DW      $30B8
        DW      $30E6
        DW      $310E
        DW      $313C
        DW      $3164
        DW      $3192
PATTAB  DB      17
        DB      30
        DW      $3BF6           ; TITLE SHARK
        DB      72
        DB      84
        DW      $3DAE           ; ANCHOR
        DB      105
        DB      74
        DW      $3D78           ; CHEST
        DB      0
        DB      70
        DW      $3212
        DB      10
        DB      10
        DW      $3212
        DB      121
        DB      70
        DW      $3212
        DB      111
        DB      66
        DW      $3202
        DB      77
        DB      64
        DW      $3212
        DB      154
        DB      47
        DW      $3212
        DB      67
        DB      55
        DW      $3202
        DB      87
        DB      36
        DW      $3212
        DB      25
        DB      15
        DW      $3212
        DB      60
        DB      40
        DW      $3910           ; SUB
        DB      100
        DB      90
        DW      $3700           ; TREASURE
        DB      33
        DB      89
        DW      $3700           ; TREASURE
        DB      44
        DB      87
        DW      $3700           ; TREASURE
        DB      0
        DB      43
        DW      $3300           ; START OF SHIP
        DB      4
        DB      79
        DW      $332A
        DB      8
        DB      38
        DW      $3330
        DB      16
        DB      40
        DW      $3396
        DB      51
        DB      23
        DW      $3428
        DB      55
        DB      27
        DW      $342F
        DB      59
        DB      31
        DW      $3436
        DB      63
        DB      23
        DW      $3441
        DB      68
        DB      40
        DW      $3465
        DB      60
        DB      40
        DW      $346C
        DB      72
        DB      44
        DW      $3480
        DB      76
        DB      48
        DW      $3487
        DB      80
        DB      52
        DW      $348E
        DB      48
        DB      56
        DW      $3495
        DB      60
        DB      59
        DW      $349A
        DB      68
        DB      64
        DW      $34D2
        DB      76
        DB      69
        DW      $3500
        DB      84
        DB      72
        DW      $351C
        DB      92
        DB      64
        DW      $3538
        DB      96
        DB      59
        DW      $354F
        DB      100
        DB      61
        DW      $3560
        DB      28
        DB      43
        DW      $3567
        DB      36
        DB      45
        DW      $35B9
        DB      52
        DB      40
        DW      $360D
        DB      44
        DB      47
        DW      $3669
        DB      133
        DB      69
        DW      $3766           ; TOCPUS
GPTAB   DB      0
        DB      81
        DW      $3825           ; START OF GROUND
        DB      15
        DB      86
        DW      $383C
        DB      25
        DB      81
        DW      $3886
        DB      49
        DB      84
        DW      $38A1
        DB      70
        DB      81
        DW      $38A9
        DB      121
        DB      82
        DW      $38E2
        DB      147
        DB      81
        DW      $38F8
        DB      $FF             ; END OF PATTERN TABLE
PEND    DEFL    $
        END        
 

"Treasure Cove" By Brett Bilbrey
--------------------------------

This is NOT the finished version of "Treasure Cove."  This source code is 
based on the preliminary version that was provided by Brett in April of 2009.
All hand-written notes and changes from the printout have been ignored.  

-- Version (.02) - March 3, 2010
   - First release.  Assembles fine using Zmac.
   - This version does NOT run.
   - When run under MESS .135, it "locks up."  When the debugger is used, the
     game is getting "stuck" in the WRITP routine in the system ROM.  The
     problem has been traced back to when the cartridge calls the WRITP
     routine from $27DE.  The game never returns from this call.
   - Richard Degler suggests, "Sounds like the Stack area is getting clobbered
     by the WRITPattern - there is no bounds checking so if it draws too far
     down it just can't find its way back."  

-- Version (.01) - March 1, 2010
   - Source typed in by Adam Trionfo
   - Typed-in from January 22 - March 1, 2010 
   - Assembles without errors.
   - A few changes to the source had to be made:
        - Lines 386 and 387: The label HALT was changed to HALT1
        - Lines 426 and 442: The label POP changed to POP1