;  "The Incredible Wizard"
;  For Bally Arcade/Astrocade
;
;                THE INCREDIBLE WIZARD #2017
;
;    Created by Tom McHugh, Scot Norris, and Julie Malan.
;     With creative consultation and in conjunction with
;                   Action Graphics, Inc.
;                Produced by Astrocade, Inc.
;
;          Licensed from Bally/Midway Mfg. Co. and 
;   based on the original (c) "Wizard of Wor" game done by
;           Dave Nutting Associates (A Bally Co.)
;  Cassette documentation by Scot Norris and Dave Armstrong
;          Copyright Action Graphics, Inc. 2/22/82
;
; 
;  Disassembly Started November 2, 2011 by AJT
;
;  This program can be assembled usign ZMAC.  Make sure that HVGLIB.H
;  is in the same directory and then type:
;      zmac -i -m -o wizwor.bin -x wizwor.lst wizwor.asm
;
;
;  Version History:
;    .03 (Sept. 8, 2012) - *** OUTDATED!!! ***
;                          Disassembly version .04 (July 26, 2013) has
;                          been released.  This version is OUTDATED, but
;                          is available for reference or comparison purposes.                          
;                        - Continued finding code.
;    .02 (Nov. 16, 2011) - Second Preliminary version.  First
;                          version added to BallyAlley.com.
;    .01 (Nov. 10, 2011) - First Distributed version.
;                          Distributed ONLY via email.



        INCLUDE "HVGLIB.H"      ; Home Video Game Library

SCRTCH  EQU     $4E38           ; First byte of Scratchpad on Line $91
                                ; This leaves 11 lines available for scratchpad
                                ; or 40 bytes per line x 11 = 440 + 16 = 456 Bytes

LIVES1  EQU     $4F36           ; Number of Lives for Player 1
LIVES2  EQU     $4F37           ; Number of Lives for Player 2           
GAMDIF  EQU     $4F3C           ; Game Difficulty Level
COUNT1  EQU     $4FD5           ; Countdown Timer for Player 1 to Exit Safe Area
COUNT2  EQU     $4FD6           ; Countdown Timer for Player 2 to Exit Safe Area
NUMPLA  EQU     $4FF3           ; Number of Players                                
 

        ORG     FIRSTC

        DB      'U'             ; Sentinal for Menu Start

;  First Menu Item node
        DW      MENUST          ; ... Next Menu Node
        DW      L2084           ; ... Choice 1 Text is "THE WIZARD"
        DW      L2019           ; ... Start of "The Incredible Wizard" 

;  Reset Vector Jumps - Used with RST Instruction
        JP      L3216           ; Reset VECTor #1 /  8 / $08
        JP      L322D           ; Reset VECTor #2 / 16 / $10
        JP      L33E8           ; Reset VECTor #3 / 24 / $18
        JP      L2883           ; Reset VECTor #4 / 32 / $20
        JP      L3234           ; Reset VECTor #5 / 40 / $28
        JP      L323A           ; Reset VECTor #6 / 48 / $30

;  Start of "The Incredible Wizard" Program 
        
;  Initialize Scratch RAM $4F00-$4FAF to zero.  $4F00 is the first byte
;  of line 96 (of 0-101) to the 16'th byte of line 100. 
L2019:  SYSSUK  FILL            ;  UPI FILL memory with data
        DW      $4F00           ;  ... Memory Address = 20224
        DW      $00B0           ;  ... Byte Count = 176
        DB      $00             ;  ... Data = 0

;  Game Difficulty Level Menu

;  Display Game Difficulty Level Menu
;  The menu looks like this:
;
;      THE WIZARD
;    1 - EASY
;    2 - MEDIUM
;    3 - HARD
;
        SYSSUK  MENU            ;  UPI display a MENU
        DW      L2084           ;  ... Title Address "THE WIZARD"
        DW      L2065           ;  ... Menu Linked List

;  Game difficulty level selection is in A.    

L2026:  LD      A,$80           ;  Setup for "EASY" Game Difficulty Level 
        JR      L202C
L202A:  LD      A,$40           ;  Setup for "HARD" Game Difficulty Level
L202C:  LD      ($4F3C),A       ;  

;  Get the Number of Players
;  Number of players must be 1 or 2.  The player's input is checked
;  to make sure that it is valid.  If it isn't 1 or 2, then the
;  player will be asked again until valid input is given.

L202F:  SYSSUK  GETPAR          ;  UPI GET game PARameter from 
        DW      L2077           ;  ... Prompt Address "# OF PLAYERS"
        DB      $01             ;  ... Digits = 1
        DW      $4FF3           ;  ... Parameter Address of Number of Players  

        LD      A,($4FF3)       ; Load A with Number of Players   
        DEC     A                
        CP      $02
        JP      NC,L202F        ; Number of players <> 2, then get again 
        
;  Screen and Interrupt Initialization

;  Vertical Blank
;  First byte of Scratchpad starts on line 91 (of 0-101)
;  This leaves 11 lines available for scratchpad, or:
;     40 bytes per line x 11 = 440 + 16 = 456 Bytes
;  First scratchpad byte available is $4E38 
        
        SYSSUK  SETOUT          ;  UPI SET some OUTput ports
        DB      $B6             ;  ... VERBL*2 = 182
        DB      $2C             ;  ... HORCB/4 = 44
        DB      $08             ;  ... INMOD = 8

        SYSSUK  COLSET          ;  UPI COLors SET
        DW      L208F           ;  ... Table Address = $208F

        DI      

;  Set-up Interrupt Vector for $2094
        LD      A,$94
        OUT     (INFBK),A       ; Port $D, write INterrupt FeedBacK
        LD      A,$20
        LD      I,A             ; High byte of Interrupt Vector

        JP      L22A1

;  Game Difficulty Level Text
L2054:  DB      "EASY",$00
L2059:  DB      "MEDIUM",$00
L2060:  DB      "HARD",$00
        
;  Game Difficulty Level Linked List  
L2065:  DW      L206B           ; Link to Choice 2
        DW      L2054           ; Address of Choice 1 Menu Text, "EASY"
        DW      L2026           ; Jump here if Choice 1 is selected

L206B   DW      L2071           ; Link to Choice 3
        DW      L2059           ; Address of Choice 2 Menu Text, "MEDIUM"
        DW      L202F           ; Jump here if Choice 2 is selected

L2071:  DW      $0000           ; Last Link in Linked List
        DW      L2060           ; Address of Choice 3 Menu Text, "HARD"
        DW      L202A           ; Jump here if Choice 3 is selected

;  Text      
L2077:  DB      "# OF PLAYERS",$00
L2084:  DB      "THE WIZARD",$00

;  Color Table
L208F:  DB      $63             ; color 3 Left = Red 
        DB      $7D             ; color 2 Left = Yellow 
        DB      $F4             ; color 1 Left = Blue 
        DB      $00             ; color 0 Left = Black 
        
        DB      $00

;  Screen INTerrupt VECtor
L2094:  DW      L2096           

;  Interrupt Routine        
L2096:  PUSH    AF
        PUSH    BC
        PUSH    DE
        PUSH    HL
        PUSH    IX
        PUSH    IY
        EX      AF,AF'
        PUSH    AF
        EXX     
        PUSH    BC
        PUSH    DE
        PUSH    HL
        CALL    L20B7
        POP     HL
        POP     DE
        POP     BC
        EXX     
        POP     AF
        EX      AF,AF'
        POP     IY
        POP     IX
        POP     HL
        POP     DE
        POP     BC
        POP     AF
        EI      
        RET   


L20B7:  LD      A,($4F26)
        RLA     
        JR      NC,L2106
        LD      A,($4FEB)
        RRA     
        JR      C,L20E5
        LD      IX,$4E38
        CALL    L211A
        LD      IX,$4E6C
        CALL    L2120
        LD      IX,$4E8B
        CALL    L2120
        LD      IX,$4EAA
        CALL    L2120
        CALL    L2134
        JP      L2106
L20E5:  LD      HL,$4F3C
        SET     3,(HL)
        LD      IX,$4E52
        CALL    L211A
        LD      IX,$4EC9
        CALL    L2120
        LD      IX,$4EE8
        CALL    L2120
        LD      IX,$4F07
        CALL    L2120
L2106:  CALL    STIMER         
        CALL    L3ED5
        LD      HL,$4F31
        LD      A,(HL)
        AND     A
        RET     Z

        DEC     (HL)
        RET     NZ

        LD      HL,$4FDE
        SET     5,(HL)
        RET     


L211A:  CALL    L2160
        JP      L2123
L2120:  CALL    L21B6
L2123:  CALL    L35C3
        BIT     6,(IX+$00)
        RET     Z

        LD      A,(IX+$03)
        AND     A
        RET     Z

        DEC     (IX+$03)
        RET     
        

L2134:  LD      HL,$4E86
        CALL    L2155
        LD      HL,$4EA5
        CALL    L2155
        LD      HL,$4EC4
        CALL    L2155
        LD      HL,$4EE3
        CALL    L2155
        LD      HL,$4F02
        CALL    L2155
        LD      HL,$4F21
L2155:  LD      B,$03
L2157:  LD      A,(HL)
        AND     A
        JR      Z,L215C
        DEC     (HL)
L215C:  INC     HL
        DJNZ    L2157
        RET


L2160:  CALL    L21F9
        RET     Z

        LD      B,$0B
        CALL    L2208
        LD      L,(IX+$16)
        LD      E,(IX+$17)
        BIT     2,(IX+$07)
        LD      IY,$4E38
        JR      Z,L217D
        LD      IY,$4E52
L217D:  CALL    L21D9
        CALL    L2196
        LD      IY,$4E6C
        LD      B,$06
L2189:  PUSH    BC
        CALL    L21D9
        LD      BC,$001F
        ADD     IY,BC
        POP     BC
        DJNZ    L2189
        RET     


L2196:  BIT     7,(IY+$15)
        RET     Z

        LD      A,(IX+$16)
        SUB     (IY+$16)
        ADD     A,$04
        CP      $09
        RET     NC

        LD      A,(IX+$17)
        SUB     (IY+$17)
        ADD     A,$04
        CP      $09
        RET     NC

        SET     5,(IY+$15)
        RET     

L21B6:  CALL    L21F9
        RET     Z

        LD      A,($4F2E)
        CP      $02
        LD      B,$0D
        JR      NZ,L21C5
        LD      B,$0B
L21C5:  CALL    L2208
        LD      L,(IX+$16)
        LD      E,(IX+$17)
        LD      IY,$4E38
        CALL    L21D9
        LD      IY,$4E52
L21D9:  LD      A,(IY+$00)
        AND     $C9
        CP      $80
        RET     NZ

        LD      A,(IY+$08)
        SUB     L
        ADD     A,$17
        CP      H
        RET     NC

        LD      A,(IY+$09)
        SUB     E
        ADD     A,$09
        CP      D
        RET     NC

        PUSH    HL
        PUSH    DE
        CALL    L3263
        POP     DE
        POP     HL
        RET     


L21F9:  PUSH    IX
        POP     HL
        LD      BC,$0015
        ADD     HL,BC
        PUSH    HL
        CALL    L2212
        POP     HL
        BIT     6,(HL)
        RET     


L2208:  BIT     1,(HL)
        LD      (HL),$00
L220C:  LD      H,B
        LD      D,$08
        RET     NZ

        EX      DE,HL
        RET      


L2212:  BIT     7,(HL)
        RET     Z

        LD      C,(HL)
        LD      A,C
        AND     $0C
        OUT     (XPAND),A       ; eXPANDer pixel definition port
        BIT     5,(HL)
        JR      NZ,L2260
        PUSH    HL
        CALL    L2262
        POP     HL
        PUSH    HL
        INC     HL
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        BIT     4,C
        LD      A,$04
        JR      Z,L2230
        RRCA    
L2230:  BIT     0,C
        JR      NZ,L2236
        NEG     
L2236:  BIT     1,C
        JR      Z,L223E
        ADD     A,E
        LD      E,A
        JR      L2240
L223E:  ADD     A,D
        LD      D,A
L2240:  LD      (HL),D
        DEC     HL
        LD      (HL),E
        INC     HL
        LD      A,E
        AND     $03
        LD      B,A
        CALL    L3201
        LD      A,B
        RRCA    
        RRCA    
        OR      D
        LD      D,A
        INC     HL
        LD      (HL),E
        INC     HL
        LD      (HL),D
        IN      A,($08)
        CALL    L226B
        POP     HL
        IN      A,($08)
        AND     A
        RET     Z

        SET     6,(HL)
L2260:  RES     7,(HL)
L2262:  INC     HL
        INC     HL
        INC     HL
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        LD      A,D
        OR      E
        RET     Z

L226B:  LD      A,D
        RLCA    
        RLCA    
        AND     $03
        OR      $28
        OUT     (MAGIC),A       ; write MAGIC register
        EX      DE,HL
        LD      A,H
        AND     $0F
        LD      H,A
        BIT     4,C
        JR      NZ,L228B
        BIT     1,C
        JR      NZ,L2285
        LD      B,$04
        JR      L2291
L2285:  LD      (HL),$FF
        INC     HL
        LD      (HL),$00
        RET     

L228B:  BIT     1,C
        JR      NZ,L229B
        LD      B,$06
L2291:  LD      DE,$0028
        LD      A,$88
L2296:  LD      (HL),A
        ADD     HL,DE
        DJNZ    L2296
        RET     

L229B:  LD      (HL),$FC
        INC     HL
        LD      (HL),$FC
        RET


L22A1:  SYSTEM  INTPC           ;  UPI INTerPret with Context create
;
        DO      RCALL           ;  UPI Real CALL asm language subroutine
        DW      L3D32           ;  ... Real Address = 15666
;
;  Check if there are two players.  If there are, initialize Number of Lives 
;  for player 2 to 7 lives. 
        DO      RCALL           ;  UPI Real CALL asm language subroutine
        DW      L22DA           ;  ... Real Address = 8922
;
;  Initialize Number of Lives for player 1 to 7 lives 
        DO      SETB            ;  UPI SET Byte
        DB      $07             ;  ... Data = 7
        DW      LIVES1          ;  Number of Lives for Player 1
;
        DO      RCALL           ;  UPI Real CALL asm language subroutine
        DW      L23A9           ;  ... Real Address = 9129
;
        DONT    XINTC           ;  UPI eXit INTerpreter with Context
;
        LD      HL,$4F3C
        RES     3,(HL)
        CALL    L3079

        SYSSUK  SENTRY          ;  UPI SENse TRansition
        DW      L22D6           ;  ... Keymask Address = 8918
;
        SYSSUK  DOIT            ;  UPI DOIT table, branch to translation handler
        DW      L2308           ;  ... Table Address = 8968
;
        SYSSUK  SENTRY          ;  UPI SENse TRansition
        DW      L22D6           ;  ... Keymask Address = 8918
;
        SYSSUK  DOIT            ;  UPI DOIT table, branch to translation handler
        DW      L2308           ;  ... Table Address = 8968
;
L22C9:  EI      
        LD      A,($4F3C)
        BIT     3,A
        JR      NZ,$22B1
        CALL    L2AF5
        JR      L22C9

;  Keypad Mask Table
L22D6:  DB      $00
        DB      $00
        DB      $00
        DB      $00

;  If there are two players, then initialize Number of Lives 
;  for player 2 to 7 lives. 
L22DA:  LD      A,($4FF3)       ; Number of Players
        DEC     A               ;                
        RET     Z               ; If only only player, then RET, else... 
        LD      A,$07           ;   ... Set Number of Players to 7 
        LD      (LIVES2),A      ;   ... Load Number of Lives for Player 1
        RET     

;  SENTRY RETURN Code SCT6 Handler
;  Counter-Timer 6 has counted down
L22E5:  LD      A,$01
        LD      ($4FDB),A
        CALL    L2F8A
        CALL    L2B30
        CALL    L33F4
        LD      HL,LIVES1
        LD      A,(HL)
        INC     HL
        OR      (HL)
        RET     NZ

        LD      A,($4E38)
        LD      HL,$4E52
        OR      (HL)
        RET     M

        LD      HL,$4FDE
        SET     4,(HL)
        RET     


;  DOIT table
L2308:  DB      $55             ; RCALL - $15 (SJ0), Joy 1 for player 1 changed
        DW      L2386           ; Handler Address

        DB      $57             ; RCALL - $17 (SJ1), Joy 2 for player 2 changed  
        DW      L238B           ; Handler Address

        DB      $54             ; RCALL - $14 (ST0), Trigger 1 for player 1 changed
        DW      L32CB           ; Handler Address

        DB      $56             ; RCALL - $16 (ST1), Trigger 2 for player 2 changed
        DW      L32D1           ; Handler Address

        DB      $51             ; RCALL - $11 (SSEC), SEConds timer has counted down 
        DW      L2342           ; Handler Address

        DB      $41             ; RCALL - $01 (SCT0), Counter-Timer 0 has counted down 
        DW      L2370           ; Handler Address

        DB      $42             ; RCALL - $02 (SCT1), Counter-Timer 1 has counted down
        DW      L237B           ; Handler Address

        DB      $43             ; RCALL - $03 (SCT2), Counter-Timer 2 has counted down
        DW      L337D           ; Handler Address

        DB      $44             ; RCALL - $04 (SCT3), Counter-Timer 3 has counted down
        DW      L34A1           ; Handler Address

        DB      $45             ; RCALL - $05 (SCT4), Counter-Timer 4 has counted down
        DW      L2409           ; Handler Address

        DB      $46             ; RCALL - $06 (SCT5), Counter-Timer 5 has counted down
        DW      L23C0           ; Handler Address

        DB      $47             ; RCALL - $07 (SCT6), Counter-Timer 6 has counted down
        DW      L22E5           ; Handler Address

        DB      $48             ; RCALL - $08 (SCT7), Counter-Timer 7 has counted down
        DW      L239A           ; Handler Address

        DB      $89             ; MCALL - $09 (SF0), Sentry, Flag bit 0 has changed
        DW      L245C           ; Handler Address

        DB      $4A             ; RCALL - $0A (SF1), Sentry, Flag bit 1 has changed
        DW      L324C           ; Handler Address

        DB      $4B             ; RCALL - $0B (SF2), Sentry, Flag bit 2 has changed
        DW      L3241           ; Handler Address

        DB      $4C             ; RCALL - $0C (SF3), Sentry, Flag bit 3 has changed
        DW      L23B2           ; Handler Address

        DB      $4D             ; RCALL - $0D (SF4), Sentry, Flag bit 4 has changed
        DW      L23D9           ; Handler Address

        DB      $4E             ; RCALL - $0E (SF5), Sentry, Flag bit 5 has changed
        DW      L3475           ; Handler Address

        DB      $C0             ; End of DOIT Table


;  SENTRY RETURN Code SSEC Handler
;  SEConds timer has counted down
L2342:  LD      A,($4F26)
        BIT     3,A
        JR      Z,L234D
        SYSSUK  DECCTS           ;  UPI DECrement CT'S under 
        DB      $FC              ;  ... Counters = 252
;
        RET     


L234D:  SYSSUK  DECCTS           ;  UPI DECrement CT'S under 
        DB      $FF              ;  ... Counters = 255
;
        LD      A,(COUNT1)
        AND     A
        CALL    NZ,L2366
        LD      A,(COUNT2)
        AND     A
        RET     Z

        DI      

; Display Countdown Timer for Player 2 to Exit Safe Area
        SYSSUK  DISNUM           ;  UPI DISplay NUMber
        DB      $7C              ;  ... X = 124
        DB      $4A              ;  ... Y = 74
        DB      $04              ;  ... Options = 4
        DB      $01              ;  ... Extended = 1
        DW      COUNT2           ;  ... Countdown Timer for Player 2
;                                       to Exit Safe Area
;
        RET     


; Display Countdown Timer for Player 1 to Exit Safe Area  
L2366:  DI      
        SYSSUK  DISNUM           ;  UPI DISplay NUMber
        DB      $1E              ;  ... X = 30
        DB      $4A              ;  ... Y = 74
        DB      $08              ;  ... Options = 8
        DB      $01              ;  ... Extended = 1
        DW      COUNT1           ;  ... Countdown Timer for Player 1
;                                       to Exit Safe Area
;
        RET     


;  SENTRY RETURN Code SCT0 Handler
;  Counter-Timer 0 has counted down
L2370:  LD      HL,$4E38
        BIT     0,(HL)
        JP      Z,L3005
        SET     1,(HL)
        RET     

;  SENTRY RETURN Code SCT1 Handler
;  Counter-Timer 1 has counted down
L237B:  LD      HL,$4E52
        BIT     0,(HL)
        JP      Z,L2FFA
        SET     1,(HL)
        RET      


;  SENTRY RETURN Code SJ0 Handler
;                Code SJ1 Handler              
;  Joystick 1 for player 1 has changed and/or
;  Joystick 2 for player 2 has changed
L2386:  LD      HL,$4E39        ; Joystick 1 handler
        JR      L238E
L238B:  LD      HL,$4E53        ; Joystick 2 handler
L238E:  LD      A,(HL)
        AND     $F0
        OR      B
        LD      (HL),A
        DEC     HL
        BIT     0,(HL)
        RET     Z

        SET     1,(HL)
        RET

;  SENTRY RETURN Code SCT7 Handler
;  Counter-Timer 7 has counted down
L239A:  LD      HL,$4E4D
        LD      A,($4E67)
        OR      (HL)
        JR      Z,L23A9
        LD      A,$01
        LD      ($4FDC),A
        RET     


L23A9:  CALL    L23F8
        LD      A,$01
        LD      ($4FDE),A
        RET     


;  SENTRY RETURN Code SF3 Handler
;  Sentry, Flag bit 3 has changed
L23B2:  CALL    L23D0           ; Display "ESCAPED" Message
        LD      HL,$4F26
        SET     3,(HL)
        LD      A,$02
        LD      ($4FDA),A
        RET     


;  SENTRY RETURN Code SCT5 Handler
;  Counter-Timer 5 has counted down
L23C0:  CALL    L23D0           ; Display "ESCAPED" Message
        CALL    L34B8          
        RES     3,(HL)
L23C8:  LD      HL,$4FDE
        SET     1,(HL)
        SET     2,(HL)
        RET     


; Display "ESCAPED" centered near bottom of screen 
L23D0:  DI      
        SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $1B              ;  ... X = 27
        DB      $4A              ;  ... Y = 74
        DB      $6C              ;  ... Options: 2x, XOR Write, Red on Black
        DW      L23F0            ;  ... String Address of "ESCAPED"
        ;
        RET     


;  SENTRY RETURN Code SF4 Handler
;  Sentry, Flag bit 4 has changed
;
;  Display "GAME OVER" then perform System Reset via the On-Board
;  ROM's QUIT function.  This resets the machine and displays the main
;  menu again. 
L23D9:  DI      
        SYSSUK  STRDIS                  ;  UPI STRing DISplay
        DB      $30                     ;  ... X = 48
        DB      $18                     ;  ... Y = 24
        DB      $48                     ;  ... Options = 72
        DW      L23FF                   ;  ... String "GAME OVER"
        ;
        EI      
        SYSSUK  SETB                    ;  UPI SET Byte
        DB      $80                     ;  ... Data = 128
        DW      $4F40                   ;  ... Memory Address = 20288
        ;
        SYSSUK  PAWS                    ;  UPI PAUSE
        DB      $01                     ;  ... Interrupts = 1
        ;
        CALL    L23F8
        DI      
        SYSTEM  QUIT                    ;  UPI QUIT cassette execution


L23F0:  DB      "ESCAPED",$00

L23F8:  LD      A,($4F42)
        RLA     
        JR      NC,L23F8
        RET     
        
L23FF:  DB      "GAME" 
        DB      $06             ; Six spaces      
        DB      "OVER",$00  


;  SENTRY RETURN Code SCT4 Handler
;  Counter-Timer 4 has counted down
L2409:  DI      
        LD      HL,$4F26
        LD      A,(HL)
        XOR     $01
        LD      (HL),A
        RRA     
        LD      C,$0C
        JR      C,L242A
        LD      A,($4F2E)
        AND     A
        LD      A,$02
        JR      NZ,L2420
        LD      A,$0A
L2420:  LD      ($4FD9),A
        LD      HL,$4F42
        SET     4,(HL)
        LD      C,$00            ; ... Options: 1x, Standard Write, Black on Black
L242A:  LD      A,$5F            ; ... ASCII Character to Display (Left Arrow) 
        LD      DE,$1A04         ; ... X,Y Coordinates
        SYSTEM  CHRDIS           ;  UPI CHaRacter DISplay
        
        LD      A,$61            ; ... ASCII Character to Display (Right Arrow)
        LD      DE,$1A94         ; ... X,Y Coordinates
        SYSTEM  CHRDIS           ;  UPI CHaRacter DISplay
        
        LD      A,$04
        OUT     (XPAND),A        ; eXPANDer pixel definition port
        LD      A,$28
        OUT     (MAGIC),A        ; write MAGIC register
        LD      DE,$0028
        LD      A,$22
        LD      HL,$03C3
        CALL    L244F
        RLCA    
        LD      HL,$03E4
L244F:  CALL    L2455
        CALL    L2455
L2455:  ADD     HL,DE
        LD      (HL),A
        ADD     HL,DE
        LD      (HL),A
        ADD     HL,DE
        ADD     HL,DE
        RET     


;  SENTRY RETURN Code SF0 Handler
;  Flag bit 0 has changed

;  I'm not sure if the MCALL and the RCALL are disassembled correctly
;  as I had to do a lot of this part by hand.
L245C:  DO      MCALL           ; UPI Call Interprter Subroutine
        DW      L24C3           ; Address of routine to call
        ;
        DO      RCALL           ; UPI Real CALL asm language subroutine
        DW      L2E15           ; Address of routine to call
        ;
        DO      SETB            ;  UPI SET Byte
        DB      $01             ;  ... Data = 1
        DW      $4F40           ;  ... Memory Address = 20288
        ;
        DO      STRDIS          ;  UPI STRing DISplay
        DB      $2B             ;  ... X = 43
        DB      $0B             ;  ... Y = 11
        DB      $94             ;  ... Options = 148
        DW      L2510           ;  ... String Address of "GET"
        ;
        DO      STRDIS          ;  UPI STRing DISplay
        DB      $0A             ;  ... X = 10
        DB      $36             ;  ... Y = 54
        DB      $98             ;  ... Options = 152
        DW      L2514           ;  ... String Address of "READY"
        ;
        DONT    XINTC           ;  UPI eXit INTerpreter with Context

        LD      C,$60
        CALL    L2E8B
        SYSSUK  MCALL            ;  UPI Macro CALL interpreter subroutine
        DW      L24C3            ;  ... Macro Address = 9411
        ;
        SYSSUK  SETB             ;  UPI SET Byte
        DB      $02              ;  ... Data = 2
        DW      $4F40            ;  ... Memory Address = 20288
        ;
        SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $20              ;  ... X = 32
        DB      $18              ;  ... Y = 24
        DB      $D4              ;  ... Options = 212
        DW      L251A            ;  ... String Address of "GO"
        ;
        LD      C,$34
        CALL    L2E8B
        SYSTEM  INTPC            ;  UPI INTerPret with Context create
        ;
        DO      MCALL            ;  UPI Macro CALL interpreter subroutine
        DW      L24C3            ;  ... Macro Address = 9411
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L251D            ;  ... Real Address = 9501
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L2757            ;  ... Real Address = 10071
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L2EFE            ;  ... Real Address = 12030
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L29E1            ;  ... Real Address = 10721
        ;
        DO      SETB             ;  UPI SET Byte
        DB      $0F              ;  ... Data = 15
        DW      $4FD7            ;  ... Memory Address = 20439
        ;
        DO      SETB             ;  UPI SET Byte
        DB      $02              ;  ... Data = 2
        DW      $4FDB            ;  ... Memory Address = 20443
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L24F9            ;  ... Real Address = 9465
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L24E0            ;  ... Real Address = 9440
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L24ED            ;  ... Real Address = 9453
        ;
        DO      CHRDIS           ;  UPI CHaRacter DISplay
        DB      $20              ;  ... X = 32
        DB      $54              ;  ... Y = 84
        DB      $08              ;  ... Options = 8
        DB      $30              ;  ... Character = 48
        ;
        DO      SETB             ;  UPI SET Byte
        DB      $01              ;  ... Data = 1
        DW      $4FD9            ;  ... Memory Address = 20441
        ;
        DO      SETB             ;  UPI SET Byte
        DB      $01              ;  ... Data = 1
        DW      $4F27            ;  ... Memory Address = 20263
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L24CD            ;  ... Real Address = 9421
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L23C8            ;  ... Real Address = 9160
        ;
        DONT    MRET             ;  UPI Macro RETurn from interpreter subroutine


L24C3:  DO      FILL             ;  UPI FILL memory with data
        DW      NORMEM           ;  ... Memory Address = 16384
        DW      $0F32            ;  ... Byte Count = 3890
        DB      $00              ;  ... Data = 0
        ;
        DO      RCALL            ;  UPI Real CALL asm language subroutine
        DW      L3D32            ;  ... Real Address = 15666
        ;
        DONT    MRET             ;  UPI Macro RETurn from interpreter subroutine


L24CD:  LD      HL,$4F3C
        LD      A,(HL)
        RES     0,(HL)
        RES     1,(HL)
        RRCA    
        RRCA    
        RRCA    
        AND     $60
        OR      $80
        LD      ($4F26),A
        RET     


L24E0:  LD      IX,FNTSML
        SYSSUK  DISNUM                  ;  UPI DISplay NUMber
        DB      $6E                     ;  ... X = 110
        DB      $4E                     ;  ... Y = 78
        DB      $0C                     ;  ... Options = 12
        DB      $C2                     ;  ... Extended = 194
        DW      $4f33                   ;  ... Number Address = 20275
        ;
        RET     


L24ED:  LD      A,($4FF3)
        DEC     A
        RET     Z

        SYSSUK  CHRDIS                  ;  UPI CHaRacter DISplay
        DB      $98                     ;  ... X = 152
        DB      $54                     ;  ... Y = 84
        DB      $04                     ;  ... Options = 4
        DB      $30                     ;  ... Character = 48
        ;
        RET     


L24F9:  LD      A,($4F3C)
        BIT     6,A
        JR      NZ,L2507
        LD      A,($4F32)
        CP      $07
        JR      C,L2509
L2507:  LD      A,$06
L2509:  SUB     $07
        CPL     
        LD      ($4F2C),A
        RET     


L2510:  DB      "GET",$00 
L2514:  DB      "READY",$00
L251A:  DB      "GO",$00


L251D:  LD      A,($4F32)
        LD      C,A
        CP      $09
        JR      C,L253C
        AND     $03
        JR      NZ,L252C
        INC     A
        JR      $254E
L252C:  SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $09              ;  ... Cutoff = 9
        ;
        CALL    L2562
        JR      NZ,L252C
        LD      A,(HL)
        OR      D
        LD      (HL),A
        LD      A,E
        ADD     A,$0F
        JR      L254E
L253C:  AND     $03
        JR      Z,L254E
L2540:  SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $0D              ;  ... Cutoff = 13
        ;
        CALL    L2562
        JR      NZ,L2540
        LD      A,(HL)
        OR      D
        LD      (HL),A
        LD      A,E
        ADD     A,$02            ;  Displacement
L254E:  SYSSUK  INDEXW           ;  UPI INDEX Word by A
        DW      L2577            ;  ... Base Address = 9591
        ;
        EX      DE,HL           
        LD      ($4F28),HL
        LD      A,C
        AND     $07
        SUB     $07
        RET     NZ
        
        LD      H,A
        LD      L,A
        LD      ($4F34),HL
        RET     


L2562:  LD      E,A
        LD      HL,$4F34
        INC     A
        CP      $09
        JR      C,L256E
        SUB     $08
        INC     HL
L256E:  LD      B,A
        XOR     A
        SCF     
L2571:  RLA     
        DJNZ    L2571
        LD      D,A
        AND     (HL)
        RET     

;  Base Address of Table for INDEXW
;
;  I'm not sure how many tables are in this table, or what the entries
;  represent, but following the code using the debugger, I know that
;  the addresses run through AT LEAST entry $0D  

L2577:  DW      $25A7           ; Entry $00
        DW      $26A3           ; Entry $01
        DW      $25B9           ; Entry $02
        DW      $25CB           ; Entry $03
        DW      $25DD           ; Entry $04
        DW      $25EF           ; Entry $05
        DW      $2601           ; Entry $06
        DW      $2613           ; Entry $07
        DW      $2625           ; Entry $08
        DW      $2637           ; Entry $09
        DW      $2649           ; Entry $0A
        DW      $265B           ; Entry $0B
        DW      $266D           ; Entry $0C
        DW      $267F           ; Entry $0D

        DB      $91
        DB      $26
        DB      $B5
        DB      $26
        DB      $C7
        DB      $26
        DB      $D9
        DB      $26
        DB      $EB
        DB      $26
        DB      $FD
        DB      $26
        DB      $0F
        DB      $27
        DB      $21
        DB      $27
        DB      $33
        DB      $27
        DB      $45
        DB      $27
        DB      $AC
        DB      $EE
        DB      $CE
        DB      $BC
        DB      $5B
        DB      $EF
        DB      $BC
        DB      $EF
        DB      $FF
        DB      $B6
        DB      $9F
        DB      $DD
        DB      $3B
        DB      $EF
        DB      $EC
        DB      $95
        DB      $95
        DB      $9C
        DB      $AC
        DB      $EE
        DB      $CE
        DB      $3A
        DB      $D7
        DB      $AD
        DB      $97
        DB      $AF
        DB      $FC
        DB      $AD
        DB      $73
        DB      $9E
        DB      $BC
        DB      $7B
        DB      $ED
        DB      $9C
        DB      $D5
        DB      $9C
        DB      $AC
        DB      $6A
        DB      $CE
        DB      $BC
        DB      $D7
        DB      $AD
        DB      $9E
        DB      $EF
        DB      $FE
        DB      $A5
        DB      $33
        DB      $33
        DB      $BC
        DB      $F7
        DB      $9F
        DB      $9C
        DB      $59
        DB      $CD
        DB      $AC
        DB      $6A
        DB      $CE
        DB      $3A
        DB      $DF
        DB      $CF
        DB      $97
        DB      $AF
        DB      $63
        DB      $AD
        DB      $73
        DB      $33
        DB      $BC
        DB      $F5
        DB      $BF
        DB      $9C
        DB      $DC
        DB      $51
        DB      $AC
        DB      $C6
        DB      $AE
        DB      $3A
        DB      $CD
        DB      $73
        DB      $97
        DB      $AE
        DB      $DF
        DB      $A7
        DB      $3B
        DB      $CD
        DB      $3B
        DB      $FF
        DB      $CE
        DB      $9D
        DB      $59
        DB      $CD
        DB      $AC
        DB      $6A
        DB      $CE
        DB      $BC
        DB      $DF
        DB      $63
        DB      $9E
        DB      $C7
        DB      $BF
        DB      $AD
        DB      $6B
        DB      $53
        DB      $BC
        DB      $7B
        DB      $ED
        DB      $9C
        DB      $D5
        DB      $9C
        DB      $A6
        DB      $AC
        DB      $EC
        DB      $3B
        DB      $5A
        DB      $FC
        DB      $9F
        DB      $E7
        DB      $BC
        DB      $A7
        DB      $33
        DB      $BE
        DB      $33
        DB      $BF
        DB      $53
        DB      $9D
        DB      $59
        DB      $CD
        DB      $AE
        DB      $EE
        DB      $EE
        DB      $33
        DB      $33
        DB      $33
        DB      $9F
        DB      $79
        DB      $73
        DB      $A7
        DB      $9E
        DB      $FF
        DB      $3B
        DB      $6B
        DB      $53
        DB      $95
        DB      $9D
        DB      $CD
        DB      $AC
        DB      $CE
        DB      $EC
        DB      $BC
        DB      $E5
        DB      $BC
        DB      $9E
        DB      $7A
        DB      $DE
        DB      $A5
        DB      $B7
        DB      $AF
        DB      $3A
        DB      $5B
        DB      $73
        DB      $9D
        DB      $C5
        DB      $9D
        DB      $AC
        DB      $6A
        DB      $CE
        DB      $BC
        DB      $FF
        DB      $EF
        DB      $9E
        DB      $53
        DB      $33
        DB      $A5
        DB      $A7
        DB      $BF
        DB      $BC
        DB      $5B
        DB      $73
        DB      $9C
        DB      $C5
        DB      $9D
        DB      $AC
        DB      $6A
        DB      $EC
        DB      $BC
        DB      $73
        DB      $9E
        DB      $96
        DB      $BF
        DB      $ED
        DB      $AD
        DB      $53
        DB      $BC
        DB      $BC
        DB      $EF
        DB      $FC
        DB      $9C
        DB      $D5
        DB      $9C
        DB      $A6
        DB      $AC
        DB      $EC
        DB      $3B
        DB      $FC
        DB      $FC
        DB      $97
        DB      $B6
        DB      $9E
        DB      $A7
        DB      $97
        DB      $AD
        DB      $3B
        DB      $EF
        DB      $DE
        DB      $9D
        DB      $59
        DB      $CD
        DB      $AC
        DB      $6A
        DB      $CE
        DB      $3A
        DB      $FD
        DB      $CF
        DB      $B5
        DB      $BC
        DB      $63
        DB      $BC
        DB      $7A
        DB      $DF
        DB      $3A
        DB      $DF
        DB      $63
        DB      $9D
        DB      $C5
        DB      $9D
        DB      $A6
        DB      $AC
        DB      $EC
        DB      $39
        DB      $7A
        DB      $DE
        DB      $9C
        DB      $79
        DB      $63
        DB      $AE
        DB      $DC
        DB      $73
        DB      $3B
        DB      $EE
        DB      $FD
        DB      $95
        DB      $95
        DB      $9C
        DB      $AE
        DB      $EE
        DB      $EE
        DB      $BF
        DB      $FF
        DB      $FF
        DB      $BF
        DB      $FF
        DB      $FF
        DB      $BF
        DB      $FF
        DB      $FF
        DB      $BF
        DB      $FF
        DB      $FF
        DB      $9D
        DB      $DD
        DB      $DD
        DB      $AE
        DB      $CE
        DB      $EE
        DB      $B7
        DB      $AD
        DB      $53
        DB      $B5
        DB      $3A
        DB      $EF
        DB      $BE
        DB      $D5
        DB      $BF
        DB      $B7
        DB      $AE
        DB      $FF
        DB      $9D
        DB      $DD
        DB      $DD
        DB      $AE
        DB      $EE
        DB      $CE
        DB      $BF
        DB      $F5
        DB      $AF
        DB      $BF
        DB      $DE
        DB      $FF
        DB      $B5
        DB      $AF
        DB      $53
        DB      $BE
        DB      $F5
        DB      $AF
        DB      $9D
        DB      $DC
        DB      $DD
        DB      $AE
        DB      $EE
        DB      $EE
        DB      $3B
        DB      $73
        DB      $BF
        DB      $33
        DB      $B7
        DB      $33
        DB      $B7
        DB      $3B
        DB      $73
        DB      $BF
        DB      $73
        DB      $BF
        DB      $9D
        DB      $DD
        DB      $DD
        DB      $AE
        DB      $EE
        DB      $EE
        DB      $39
        DB      $F5
        DB      $BF
        DB      $B6
        DB      $BE
        DB      $73
        DB      $BD
        DB      $79
        DB      $73
        DB      $3A
        DB      $F6
        DB      $BF
        DB      $9D
        DB      $DD
        DB      $DD
        DB      $AE
        DB      $EE
        DB      $CE
        DB      $39
        DB      $F5
        DB      $AF
        DB      $BE
        DB      $DE
        DB      $FF
        DB      $BF
        DB      $6B
        DB      $DF
        DB      $BF
        DB      $F5
        DB      $AF
        DB      $9D
        DB      $DC
        DB      $DD
        DB      $AE
        DB      $EE
        DB      $CE
        DB      $B5
        DB      $9F
        DB      $63
        DB      $B6
        DB      $A5
        DB      $9F
        DB      $39
        DB      $F6
        DB      $AF
        DB      $B6
        DB      $BF
        DB      $FF
        DB      $9D
        DB      $DD
        DB      $DD
        DB      $AC
        DB      $EE
        DB      $EE
        DB      $B6
        DB      $9F
        DB      $53
        DB      $BF
        DB      $E7
        DB      $AF
        DB      $BF
        DB      $5B
        DB      $DF
        DB      $B5
        DB      $AF
        DB      $63
        DB      $9C
        DB      $DD
        DB      $DD
        DB      $AC
        DB      $EE
        DB      $CE
        DB      $B6
        DB      $9F
        DB      $ED
        DB      $BF
        DB      $ED
        DB      $FE
        DB      $BF
        DB      $F6
        DB      $9F
        DB      $B7
        DB      $BF
        DB      $63
        DB      $9D
        DB      $DD
        DB      $DD
        DB      $AC
        DB      $EE
        DB      $EC
        DB      $BE
        DB      $D7
        DB      $BC
        DB      $3B
        DB      $ED
        DB      $FE
        DB      $3B
        DB      $DE
        DB      $FD
        DB      $BD
        DB      $E7
        DB      $BC
        DB      $9C
        DB      $DD
        DB      $DC

L2757:  DI      
        LD      A,$10
        OUT     (MAGIC),A       ; write MAGIC register
        LD      HL,$0003
        EXX     
        LD      D,$00
L2762:  LD      E,$00
L2764:  PUSH    DE
        CALL    L27B8      
        CALL    L27EE      
        CALL    L2801      
        CALL    L280C      
        CALL    L281E
        EXX     
        INC     HL
        INC     HL
        INC     HL
        EXX     
        POP     DE
        LD      A,E
        ADD     A,$0C
        LD      E,A
        CP      $79
        JR      C,L2764
        EXX     
        LD      DE,$01BF
        ADD     HL,DE
        EXX     
        LD      A,D
        ADD     A,$0C
        LD      D,A
        CP      $3D
        JR      C,L2762
        SYSTEM  INTPC           ;  UPI INTerPret with Context create
        ;
        DO      RECTAN          ;  UPI paint a RECTANgle
        DB      $0E             ;  ... X = 14
        DB      $48             ;  ... Y = 72
        DB      $0C             ;  ... Width = 12
        DB      $0C             ;  ... Height = 12
        DB      $FF             ;  ... Color = 255
        ;
        DO      RECTAN          ;  UPI paint a RECTANgle
        DB      $0F             ;  ... X = 15
        DB      $48             ;  ... Y = 72
        DB      $0A             ;  ... Width = 10
        DB      $0B             ;  ... Height = 11
        DB      $00             ;  ... Color = 0
        ;
        DO      RECTAN          ;  UPI paint a RECTANgle
        DB      $86             ;  ... X = 134
        DB      $48             ;  ... Y = 72
        DB      $0C             ;  ... Width = 12
        DB      $0C             ;  ... Height = 12
        DB      $FF             ;  ... Color = 255
        ;
        DO      RECTAN          ;  UPI paint a RECTANgle
        DB      $87             ;  ... X = 135
        DB      $48             ;  ... Y = 72
        DB      $0A             ;  ... Width = 10
        DB      $0B             ;  ... Height = 11
        DB      $00             ;  ... Color = 0
        ;
        DO      RECTAN          ;  UPI paint a RECTANgle
        DB      $36             ;  ... X = 54
        DB      $47             ;  ... Y = 71
        DB      $32             ;  ... Width = 50
        DB      $14             ;  ... Height = 20
        DB      $55             ;  ... Color = 85
        ;
        DO      RECTAN          ;  UPI paint a RECTANgle
        DB      $37             ;  ... X = 55
        DB      $48             ;  ... Y = 72
        DB      $30             ;  ... Width = 48
        DB      $12             ;  ... Height = 18
        DB      $00             ;  ... Color = 0
        ;
        DONT    XINTC           ;  UPI eXit INTerpreter with Context
        ;
        RET


L27B8:  LD      A,D
        RST     $08             ;  User ReStarT #1 of 6
        LD      A,C
        ADD     A,C
        ADD     A,C
        LD      D,A
        LD      A,E
        RST     $08             ;  User ReStarT #1 of 6
        LD      A,C
        LD      C,$00
        CP      $06
        JR      C,L27CB
        INC     C
        SUB     $0B
        CPL     
L27CB:  SRL     A
        JR      C,L27D1
        SET     1,C
L27D1:  ADD     A,D
        LD      E,A
        LD      D,$00
        LD      HL,($4F28)
        ADD     HL,DE
        LD      A,(HL)
        BIT     1,C
        JR      Z,L27E2
        RRCA    
        RRCA    
        RRCA    
        RRCA    
L27E2:  BIT     0,C
        LD      C,A
        RET     Z

        AND     $0C
        RET     PE
        
        LD      A,C
        XOR     $0C
        LD      C,A
        RET     


L27EE:  BIT     0,C
        RET     NZ

        EXX     
        PUSH    HL
L27F3:  LD      (HL),$0F
        INC     HL
        LD      (HL),$FF
        INC     HL
        LD      (HL),$FF
        INC     HL
        LD      (HL),$F0
L27FE:  POP     HL
        EXX     
        RET     


L2801:  BIT     1,C
        RET     NZ

        EXX     
        PUSH    HL
        LD      DE,$01B8
        ADD     HL,DE
        JR      L27F3
L280C:  BIT     2,C
        RET     NZ

        EXX     
        PUSH    HL
        LD      A,$0C
L2813:  LD      B,$0C
        LD      DE,$0028
L2818:  LD      (HL),A
        ADD     HL,DE
        DJNZ    L2818
        JR      L27FE
L281E:  BIT     3,C
        RET     NZ

        EXX     
        PUSH    HL
        INC     HL
        INC     HL
        INC     HL
        LD      A,$30
        JR      L2813
L282A:  LD      (IX+$01),B
        BIT     0,(IX+$00)
        RET     NZ

        EXX     
        LD      A,C
        AND     A
        RET     Z

        EXX     
L2837:  LD      A,(IX+$07)
L283A:  ADD     A,$40
        CP      $C0
        JR      NC,L283A
        AND     $FC
        OR      C
        LD      (IX+$07),A
L2846:  LD      A,(IX+$07)
L2849:  RES     5,(IX+$00)
L284D:  RST     $30              ;  User ReStarT #6 of 6
        LD      BC,$000A
        JP      L295A
L2854:  BIT     7,(IX+$0A)
        RET     NZ

        BIT     5,(IX+$00)
        RET     Z

        JR      L2846
L2860:  LD      A,(IX+$00)
        AND     $C0
        CP      $80
        RET     NZ

        BIT     7,(IX+$0A)
        RET     NZ

        CALL    L2A5A
        LD      C,$00
        EXX     
        LD      A,(IX+$01)
        AND     $0F
        LD      B,A
        LD      (IX+$01),A
        RST     $20              ;  User ReStarT #4 of 6
        JR      NZ,L282A
        RST     $20              ;  User ReStarT #4 of 6
        JR      NZ,L282A
        RET      


; Reset VECTor #4 / 32 / $20
L2883:  CALL    L288A
        LD      A,B
        AND     $F0
        RET     
 

L288A:  RST     $30             ;  User restart #6 of 6
        BIT     4,(IX+$00)
        JR      Z,L28FF
        RES     4,(IX+$00)
        LD      A,D
        RST     $08             ;  User restart #1 of 6
        RET     NZ
        
        BIT     2,B
        JR      Z,$28AF
        LD      A,$0B
        ADD     A,E
        LD      E,A
        CALL    L2EF2
        RET     NZ
        
        LD      C,$02
        SET     6,B
        CALL    L293D
        SBC     HL,DE
        JR      $28BE
        BIT     3,B
        RET     Z
        
        CALL    L2EE8
        RET     NZ
        
        LD      C,$03
        SET     7,B
        CALL    L293D
        ADD     HL,DE
        LD      A,H
        CP      $F0
        JR      C,$28C7
        LD      A,$78
        JR      $28CC
        CP      $79
        JR      C,$28F2
        XOR     A
        EX      AF,AF'
        CALL    L2409
        EX      AF,AF'
        LD      H,A
        LD      L,$00
        BIT     2,(IX+$00)
        JR      Z,$28F2
        LD      D,A
        LD      A,($4F2E)
        DEC     A
        LD      A,D
        JR      NZ,$28F2
        LD      HL,$4F42
        SET     5,(HL)
L28E7:  CALL    L34D1
        LD      HL,$4FDE
        SET     3,(HL)
        JP      L3445
        CP      (IX+$04)
        CALL    NZ,L2956
        LD      (IX+$03),L
        LD      (IX+$04),H
        RET     


;  JR to here.  Follow code.
L28FF:  SET     4,(IX+$00)
        LD      A,E
        RST     $08                     ;  USER RESTART #1 OF 6
        RET     NZ

        BIT     0,B
        JR      Z,L291D
        LD      A,$0B
        ADD     A,D
        LD      D,A
        CALL    L2ED6
        RET     NZ

        LD      C,$00
        SET     4,B
        CALL    L2945
        SBC     HL,DE
        JR      L292C
L291D:  BIT     1,B
        RET     Z

        CALL    L2EDE
        RET     NZ

        LD      C,$01
        SET     5,B
        CALL    L2945
        ADD     HL,DE
L292C:  LD      A,H
        CP      $3D
        RET     NC

        CP      (IX+$06)
        CALL    NZ,L2956
        LD      (IX+$05),L
        LD      (IX+$06),H
        RET     


L293D:  LD      E,(IX+$03)
        LD      D,(IX+$04)
        JR      L294B
L2945:  LD      E,(IX+$05)
        LD      D,(IX+$06)
L294B:  LD      L,(IX+$02)
        LD      H,$00
        ADD     HL,HL
        ADD     HL,HL
        ADD     HL,HL
        ADD     HL,HL
        EX      DE,HL
        RET     


L2956:  EXX     
        INC     C
        EXX     
        RET     


L295A:  PUSH    IX
        POP     HL
        ADD     HL,BC
        PUSH    HL
        BIT     4,(HL)
        JR      NZ,L2966
        LD      C,$05
        ADD     HL,BC
L2966:  INC     HL
        PUSH    AF
        INC     D
        INC     D
        LD      A,E
        ADD     A,$10
        LD      E,A
        POP     AF
        PUSH    HL
        BIT     2,(IX+$00)
        LD      HL,$3646
        JR      NZ,L297C
        LD      HL,$3696
L297C:  BIT     6,(IX+$00)
        JR      Z,L2985
        LD      HL,$363E
L2985:  PUSH    AF
        PUSH    AF
        RLCA    
        RLCA    
        AND     $03
        LD      C,A
        POP     AF
        AND     $1E
        RLA     
        OR      C
        LD      C,A
        POP     AF
        ADD     HL,BC
        ADD     HL,BC
        EX      (SP),HL
        INC     A
        BIT     1,A
        LD      C,$00
        JR      Z,L29BE
        BIT     0,A
        PUSH    AF
        JR      NZ,L29B7
        BIT     2,(IX+$00)
        JR      Z,L29AF
        DEC     A
        AND     $1C
        CP      $0C
        JR      Z,L29BD
L29AF:  LD      A,$07
        LD      C,$80
        ADD     A,D
        LD      D,A
        JR      L29BD
L29B7:  LD      C,$40
        LD      A,$07
        ADD     A,E
        LD      E,A
L29BD:  POP     AF
L29BE:  INC     A
        AND     $03
        LD      A,E
        JR      NZ,L29C5
        CPL     
L29C5:  AND     $03
        OR      C
        OR      $20
        LD      (HL),A
        CALL    L3201
        INC     HL
        LD      (HL),E
        INC     HL
        LD      (HL),D
        EX      (SP),HL
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        POP     HL
        INC     HL
        LD      (HL),E
        INC     HL
        LD      (HL),D
        POP     HL
        SET     5,(HL)
        SET     7,(HL)
        RET


L29E1:  LD      A,($4F32)
        CP      $09
        JR      C,L29EA
        LD      A,$08
L29EA:  SYSSUK  INDEXB           ;  UPI INDEX Byte by A
        DW      L2A51            ;  ... Base Address = 10833
        ;
        LD      C,A
        LD      B,$06
L29F1:  PUSH    BC
        LD      A,B
        RST     $18              ;  User ReStarT #3 of 6
        CALL    L29FB
        POP     BC
        DJNZ    L29F1
        RET     


L29FB:  SYSSUK  INDEXW           ;  UPI INDEX Word by A
        DW      $2A44            ;  ... Base Address = 10820
        ;
        RRA     
        JR      C,L2A06
        SET     3,(IX+$0A)
L2A06:  SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $03              ;  ... Cutoff = 3
        ;
        CALL    L2A3C
        LD      E,A
        INC     HL
        SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $02              ;  ... Cutoff = 2
        ;
        CALL    L2A3C
        LD      D,A
        INC     C
        LD      A,C
        CP      $10
        JR      C,L2A1D
        AND     $F0
L2A1D:  LD      C,A
        XOR     A
L2A1F:  LD      B,$A4
L2A21:  PUSH    IX
        POP     HL
        PUSH    HL
        INC     HL
        LD      (HL),$00
        INC     HL
        LD      (HL),C
        LD      C,$00
        INC     HL
        LD      (HL),C
        INC     HL
        LD      (HL),E
        INC     HL
        LD      (HL),C
        INC     HL
        LD      (HL),D
        INC     HL
        LD      (HL),A
        INC     HL
        LD      (HL),$A0
        POP     HL
        LD      (HL),B
        RET     


L2A3C:  LD      B,A
        INC     B
        LD      A,$F4
L2A40:  ADD     A,$0C
        DJNZ    L2A40
        ADD     A,(HL)
        RET     
 

        DB      $0C
        DB      $00
        DB      $30
        DB      $00
        DB      $54
        DB      $00
        DB      $0C
        DB      $18
        DB      $30
        DB      $18
        DB      $54

;  Table for INDEXB
L2A51:  DB      $18
        DB      $00
        DB      $01
        DB      $02
        DB      $03
        DB      $04
        DB      $05
        DB      $06
        DB      $07


L2A5A:  BIT     3,(IX+$0A)
        LD      HL,$4E38
        LD      DE,$4E52
        JR      Z,L2A67
        EX      DE,HL
L2A67:  LD      A,(IX+$01)
        AND     $F0
        JR      Z,L2A88
        LD      A,(IX+$1A)
        AND     A
        RET     NZ

        LD      A,($4F2E)
        DEC     A
        JR      Z,L2AA6
        LD      A,(HL)
        AND     $C1
        CP      $80
        JR      Z,L2ABE
        EX      DE,HL
        LD      A,(HL)
        AND     $C1
        CP      $80
        JR      Z,L2ABE
L2A88:  LD      A,(IX+$06)
        CP      $18
        LD      C,$02
        JR      C,L2A93
        LD      C,$01
L2A93:  LD      A,R
        BIT     4,A
        LD      B,$01
        JR      Z,L2A9C
        LD      B,C
L2A9C:  BIT     2,A
        LD      A,$04
        JR      Z,L2AA4
        LD      A,$08
L2AA4:  JR      L2AD8
L2AA6:  LD      A,(IX+$06)
        CP      $0C
        LD      B,$02
        JR      C,L2AB1
        LD      B,$01
L2AB1:  LD      A,($4F26)
        BIT     2,A
        LD      A,$04
        JR      NZ,L2AD8
        LD      A,$08
        JR      L2AD8
L2ABE:  LD      BC,$0004
        ADD     HL,BC
        LD      A,(HL)
        SUB     (IX+$04)
        LD      B,$08
        JR      NC,L2ACC
        LD      B,$04
L2ACC:  INC     HL
        INC     HL
        LD      A,(HL)
        SUB     (IX+$06)
        LD      A,$02
        JR      NC,L2AD8
        LD      A,$01
L2AD8:  OR      B
        LD      (IX+$01),A
        LD      B,$7F
        LD      A,(IX+$02)
        RRA     
        RRA     
        RRA     
        RRA     
        AND     $0F
        JR      Z,L2AEE
L2AE9:  SRL     B
        RRA     
        JR      NC,L2AE9
L2AEE:  LD      A,R
        AND     B
        LD      (IX+$1A),A
        RET


L2AF5   LD      A,($4F27)
        AND     A
        RET     Z

        PUSH    IY
        LD      HL,$4F2B
        CALL    L2B55
        CALL    L2C4C
        CALL    L2B69
        CALL    L2860
        CALL    L2B9E
        CALL    L2854
        LD      IY,$4E38
        CALL    L2C68
        CALL    L3015
        CALL    L2D76
        LD      IY,$4E52
        CALL    L2C68
        CALL    L3015
        CALL    L2D76
        POP     IY
        JP      L31AC


L2B30:  CALL    L2B38
        BIT     0,(IX+$0A)
        RET     NZ

L2B38:  LD      HL,$4F2A
        CALL    L2B55
        RES     0,(IX+$0A)
        PUSH    IY
        LD      IY,$4E38
        CALL    L2C6C
        LD      IY,$4E52
        CALL    L2C6C
        POP     IY
        RET     
        
        
L2B55:  INC     (HL)
        LD      A,(HL)
        CP      $06
        JR      C,L2B5D
        LD      (HL),$00
L2B5D:  LD      B,A
        RST     $18              ;  User ReStarT #3 of 6
        BIT     7,(IX+$00)
        RET     NZ

        LD      A,(HL)
        AND     A
        JR      NZ,L2B55
        RET     

L2B69:  BIT     3,(IX+$00)
        RET     Z

        SET     5,(IX+$15)
        LD      A,$06
        CALL    L2B8E
        LD      A,($4F2E)
        AND     A
        LD      HL,$4F42
        JR      Z,L2B8B
        DEC     A
        JR      Z,L2B88
        DEC     HL
        DEC     HL
        SET     3,(HL)
        RET     


L2B88:  SET     0,(HL)
        RET

L2B8B:  SET     1,(HL)
        RET     


L2B8E:  SET     6,(IX+$00)
        RES     3,(IX+$00)
        LD      (IX+$03),$01
        LD      (IX+$05),A
        RET     


L2B9E:  BIT     6,(IX+$00)
        RET     Z

        BIT     7,(IX+$0A)
        RET     NZ

        LD      A,(IX+$03)
        AND     A
        RET     NZ

        LD      (IX+$03),$04
        DEC     (IX+$05)
        JR      Z,L2BC3
        LD      A,(IX+$07)
        ADD     A,$40
        LD      (IX+$07),A
        AND     $C0
        JP      L2849


L2BC3:  BIT     2,(IX+$00)
        CALL    L34D1
        RET     Z

        LD      A,(IX+$07)
        AND     $1C
        CP      $08
        RET     NC

        AND     A
        JR      NZ,L2BDB
        LD      HL,$4F2C
        DEC     (HL)
        RET     P

L2BDB:  LD      HL,$4F41
        BIT     2,A
        JR      Z,L2BE6
        SET     3,(HL)
        JR      L2BE8
L2BE6:  SET     4,(HL)
L2BE8:  LD      C,(IX+$02)
        LD      A,(IX+$07)
        ADD     A,$04
L2BF0:  AND     $3C
        EX      AF,AF'
L2BF3:  LD      A,$07
        CALL    L2C41
        ADD     A,$18
        LD      E,A
        LD      A,($4E3C)
        SUB     E
        ADD     A,$12
        CP      $24
        JR      C,L2BF3
        LD      A,($4E56)
        SUB     E
        ADD     A,$12
        CP      $24
        JR      C,L2BF3
        LD      A,($4F2E)
        DEC     A
        JR      NZ,L2C1F
        LD      A,E
        CP      $3D
        JR      C,L2C1F
        LD      HL,$4F26
        SET     2,(HL)
L2C1F:  LD      A,$06
        CALL    L2C41
        LD      D,A
        LD      A,($4E3E)
        SUB     D
        ADD     A,$06
        CP      $0C
        JR      C,L2C1F
        LD      A,($4E58)
        SUB     D
        ADD     A,$06
        CP      $0C
        JR      C,L2C1F
        EX      AF,AF'
        LD      (IX+$1B),$2D
        JP      L2A1F
L2C41:  SYSTEM  RANGED           ;  UPI RANGED random number
        ;
        INC     A
        LD      B,A
        LD      A,$F4
L2C47:  ADD     A,$0C
        DJNZ    L2C47
        RET     


L2C4C:  RST     $30                     ;  User ReStarT #6 of 6
        LD      HL,COUNT1
        LD      A,E
        CP      $3C
        JR      C,L2C56
        INC     HL
L2C56:  LD      A,(HL)
        AND     A
        JR      NZ,L2C5F
        RES     2,(IX+$0A)
        RET     


L2C5F:  SET     2,(IX+$0A)
L2C63:  RES     0,(IX+$00)
        RET     


L2C68:  LD      B,$81
        JR      L2C6E
L2C6C:  LD      B,$80
L2C6E:  BIT     2,(IX+$0A)
        RET     NZ

        LD      A,(IX+$00)
        AND     $C1
        CP      B
        RET     NZ

        LD      A,(IY+$00)
        AND     $C1
        CP      $80
        RET     NZ

        RST     $28              ;  User ReStarT #5 of 6
        LD      A,D
        SUB     H
        ADD     A,$0B
        CP      $16
        JR      NC,L2C9F
        CALL    L2D24
        JR      Z,L2CBC
        CALL    L2D11
        JR      Z,L2CBC
        CALL    L2D18
        JR      Z,L2CBC
        CALL    L2D1B
        JR      Z,L2CBC
L2C9F:  RST     $28              ;  User ReStarT #5 of 6
        LD      A,E
        SUB     L
        ADD     A,$0B
        CP      $16
        JR      NC,L2CED
        CALL    L2D4F
        JR      Z,L2CBC
        CALL    L2D3C
        JR      Z,L2CBC
        CALL    L2D43
        JR      Z,L2CBC
        CALL    L2D46
        JR      NZ,L2CED
L2CBC:  LD      A,R
        RRA     
        JR      NC,L2CCA
        LD      A,(IX+$01)
        AND     $0F
        LD      (IX+$01),A
        RET     


L2CCA:  LD      (IX+$1B),$1E
        SET     1,(IX+$0A)
        BIT     0,(IX+$00)
        RET     Z

        CALL    L2C63
        LD      A,(IX+$07)
        AND     $1C
        RET     Z

        LD      HL,$4F41
        SUB     $04
        JR      NZ,L2CEA
        SET     4,(HL)
        RET     


L2CEA:  SET     3,(HL)
        RET     

L2CED:  RES     1,(IX+$00)
        RES     1,(IX+$0A)
        LD      A,(IX+$1B)
        AND     A
        RET     NZ

        LD      A,($4F32)
        DEC     A
        RET     Z

        LD      A,(IX+$07)
        AND     $1C
        RET     Z

        CP      $0C
        RET     NC

        SET     0,(IX+$00)
        SET     7,(IX+$0A)
        RET     


L2D11:  RST     $28              ;  User ReStarT #5 of 6
        LD      A,H
        ADD     A,$07
        LD      H,A
        JR      L2D24
L2D18:  RST     $28              ;  User ReStarT #5 of 6
        JR      $2D20
L2D1B:  RST     $28              ;  User ReStarT #5 of 6
        LD      A,H
        ADD     A,$07
        LD      H,A
        LD      A,D
        ADD     A,$07
        LD      D,A
L2D24:  LD      A,D
        LD      B,H
        CALL    L2D6C
        RET     NZ

        LD      A,E
        CP      L
        JR      C,L2D2F
L2D2E:  EX      DE,HL
L2D2F:  LD      A,L
        LD      B,E
        RST     $10              ;  User ReStarT #2 of 6
        RET     Z

        LD      B,A
        CALL    L2EE8
        LD      DE,$0003
        JR      $2D65
L2D3C:  RST     $28              ;  User ReStarT #5 of 6
        LD      A,L
        ADD     A,$07
        LD      L,A
        JR      L2D4F
L2D43:  RST     $28              ;  User ReStarT #5 of 6
        JR      $2D4B
L2D46:  RST     $28              ;  User ReStarT #5 of 6
        LD      A,L
        ADD     A,$07
        LD      L,A
        LD      A,E
        ADD     A,$07
        LD      E,A
L2D4F:  LD      A,E
        LD      B,L
        CALL    L2D6C
        RET     NZ

        LD      A,D
        CP      H
        JR      C,L2D5A
L2D59:  EX      DE,HL
L2D5A:  LD      A,H
        LD      B,D
        RST     $10              ;  User ReStarT #2 of 6
        RET     Z

        LD      B,A
        CALL    L2EDE
        LD      DE,$01E0
        LD      A,(HL)
        AND     C
        RET     NZ

        ADD     HL,DE
        DJNZ    $2D65
        RET     


L2D6C:  SET     0,(IX+$0A)
        PUSH    DE
        PUSH    HL
        RST     $10                     ;  USER RESTART #2 OF 6
        POP     HL
        POP     DE
        RET     

L2D76:  LD      A,($4F3C)
        RLA     
        RET     C

        LD      A,(IX+$00)
        AND     $C1
        CP      $80
        RET     NZ

        BIT     1,(IX+$0A)
        RET     Z

        LD      A,(IX+$02)
        CP      $20
        RET     NC

        BIT     7,(IX+$15)
        RET     NZ

        LD      A,(IX+$1C)
        AND     A
        RET     NZ

        LD      A,(IY+$00)
        AND     $C1
        CP      $80
        RET     NZ

        RST     $28                     ;  USER RESTART #5 OF 6
        LD      A,(IX+$07)
        AND     $03
        JR      Z,L2DD6
        DEC     A
        JR      Z,L2DE4
        DEC     A
        JR      Z,L2DBC
        LD      A,D
        CP      H
        RET     NZ

        LD      A,E
        CP      L
        RET     NC

        CALL    L2D2F
        RET     NZ

        LD      A,$18
        JR      L2DC8
L2DBC:  LD      A,D
        CP      H
        RET     NZ

        LD      A,E
        CP      L
        RET     C

        CALL    L2D2E
        RET     NZ

        LD      A,$0B
L2DC8:  ADD     A,(IX+$04)
        AND     $FE
        LD      E,A
        LD      A,(IX+$06)
        ADD     A,$06
        LD      D,A
        JR      L2DFC
L2DD6:  LD      A,E
        CP      L
        RET     NZ

        LD      A,D
        CP      H
        RET     C

        CALL    L2D59
        RET     NZ

        LD      A,$FD
        JR      L2DF0
L2DE4:  LD      A,E
        CP      L
        RET     NZ

        LD      A,D
        CP      H
        RET     NC

        CALL    L2D5A
        RET     NZ

        LD      A,$0A
L2DF0:  ADD     A,(IX+$06)
        AND     $FE
        LD      D,A
        LD      A,(IX+$04)
        ADD     A,$14
        LD      E,A
L2DFC:  BIT     1,(IX+$00)
        JR      NZ,L2E0B
        SET     1,(IX+$00)
        LD      (IX+$1C),$0F
        RET     

L2E0B:  LD      HL,$4F42
        SET     3,(HL)
        LD      H,$90
        JP      L3304


L2E15:  LD      B,$00
        LD      HL,$4F33
        LD      A,(HL)
        INC     A
        DAA     
        LD      (HL),A
        DEC     HL
        INC     (HL)
        LD      A,(HL)
        CP      $08
        JR      NZ,L2E26
        INC     (HL)
L2E26:  AND     $03
        CALL    Z,L2E5F
        LD      A,($4F3C)
        AND     $03
        JR      Z,L2E52
        CALL    L2E7A
        SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $2C              ;  ... X = 44
        DB      $30              ;  ... Y = 48
        DB      $04              ;  ... Options = 4
        DW      L2EAD            ;  ... String Address =of "ALL SCORES"
        ;
        SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $26              ;  ... X = 38
        DB      $40              ;  ... Y = 64
        DB      $48              ;  ... Options = 72
        DW      L2EB8            ;  ... String Address of "DOUBLE"
        ;
        LD      A,($4F3C)
        AND     $03
        JP      PO,L2E52
        SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $0E              ;  ... X = 14
        DB      $40              ;  ... Y = 64
        DB      $48              ;  ... Options = 72
        DW      L2EBF            ;  ... String Address of "QUADRUPLE"
        ;
L2E52:  LD      A,B
        AND     A
        RET     Z

        LD      C,$78
        CALL    L2E8B
        SYSSUK  MCALL            ;  UPI Macro CALL interpreter subroutine
        DW      L24C3            ;  ... Macro Address = 9411
        ;
        RET     


L2E5F:  LD      HL,LIVES1
        INC     (HL)
        CALL    L2F2E
        LD      A,($4FF3)
        DEC     A
        JR      Z,L2E73
        LD      HL,LIVES2
        INC     (HL)
        CALL    L2F33
L2E73:  SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $24              ;  ... X = 36
        DB      $20              ;  ... Y = 32
        DB      $0C              ;  ... Options = 12
        DW      L2EC9            ;  ... String Address of "EXTRA PLAYER"
        ;
L2E7A:  LD      A,B
        INC     B
        AND     A
        RET     NZ
        
        LD      HL,$4F40
        SET     2,(HL)
        SYSSUK  STRDIS           ;  UPI STRing DISplay
        DB      $2E              ;  ... X = 46
        DB      $00              ;  ... Y = 0
        DB      $48              ;  ... Options = 72
        DW      L2EA7            ;  ... String Address of "BONUS"
        ;
        RET


L2E8B:  SYSSUK  PAWS            ;  UPI PAUSE
        DB      $02             ;  ... Interrupts = 2
        ;
        LD      HL,LIVES1
        LD      A,(HL)
        AND     A
        JR      Z,L2E98
        IN      A,($10)
        LD      B,A
L2E98:  INC     HL
        LD      A,(HL)
        AND     A
        JR      Z,L2E9F
        IN      A,($11)
L2E9F:  OR      B
        BIT     4,A
        RET     NZ
        
        DEC     C
        JR      NZ,L2E8B
        RET     


L2EA7:  DB      "BONUS",$00
L2EAD:  DB      "ALL SCORES",$00
L2EB8:  DB      "DOUBLE",$00
L2EBF:  DB      "QUADRUPLE",$00
L2EC9:  DB      "EXTRA PLAYER",$00

L2ED6:  CALL    L31F9
        LD      HL,$4000
        JR      L2EE4
L2EDE:  CALL    L31F9
        LD      HL,$41B8
L2EE4:  LD      C,$01
        JR      L2EFA
L2EE8:  CALL    L31F9
        LD      HL,$402B
        LD      C,$10
        JR      L2EFA
L2EF2:  CALL    L31F9
        LD      HL,$4028
        LD      C,$04
L2EFA:  ADD     HL,DE
        LD      A,(HL)
        AND     C
        RET     


L2EFE:   LD      A,(LIVES1)
         AND     A
         JR      Z,L2F11
         CP      $08
         JR      C,L2F0A
         LD      A,$07
L2F0A:   LD      B,A
         LD      HL,$2F3A
         CALL    L2F20  
L2F11:   LD      A,(LIVES2)
         AND     A
         RET     Z

         CP      $08
         JR      C,L2F1C
         LD      A,$07
L2F1C:   LD      B,A
         LD      HL,$2F5D
L2F20:   PUSH    BC
         PUSH    HL
         CALL    L35F4
         POP     HL
         LD      BC,$0005
         ADD     HL,BC
         POP     BC 
         DJNZ    L2F20
         RET     


;  After the Worluk is killed, the program jumps here. 
L2F2E:  LD      HL,$2F80
        JR      $2F36
L2F33:  LD      HL,$2F85
        DI      
        JP      L35F4


        DB      $20
        DB      $94
        DB      $0B
        DB      $D6
        DB      $36
        DB      $20
        DB      $91
        DB      $0B
        DB      $D6
        DB      $36
        DB      $20
        DB      $B1
        DB      $09
        DB      $D6
        DB      $36
        DB      $20
        DB      $D1
        DB      $07
        DB      $D6
        DB      $36
        DB      $20
        DB      $F1
        DB      $05
        DB      $D6
        DB      $36
        DB      $20
        DB      $81
        DB      $02
        DB      $D6
        DB      $36
        DB      $20
        DB      $51
        DB      $00
        DB      $D6
        DB      $36
        DB      $60
        DB      $B3
        DB      $0B
        DB      $E6
        DB      $36
        DB      $60
        DB      $B6
        DB      $0B
        DB      $E6
        DB      $36
        DB      $60
        DB      $D6
        DB      $09
        DB      $E6
        DB      $36
        DB      $60
        DB      $F6
        DB      $07
        DB      $E6
        DB      $36
        DB      $60
        DB      $16
        DB      $06
        DB      $E6
        DB      $36
        DB      $60
        DB      $A6
        DB      $02
        DB      $E6
        DB      $36
        DB      $60
        DB      $76
        DB      $00
        DB      $E6
        DB      $36
        DB      $20
        DB      $DC
        DB      $04
        DB      $D6
        DB      $36
        DB      $60
        DB      $FC
        DB      $04
        DB      $E6
        DB      $36

L2F8A:  LD      A,($4F27)
        AND     A
        RET     Z

        LD      A,($4F26)
        BIT     4,A
        RET     NZ

        LD      IX,$4E38
        LD      D,$07
        LD      HL,$4FE4
        CALL    L2FAA
        LD      IX,$4E52
        LD      D,$02
        LD      HL,$4FE5
L2FAA:  BIT     7,(IX+$00)
        RET     NZ

        BIT     7,(IX+$0A)
        RET     NZ

        LD      (HL),$00
        BIT     0,D
        JR      Z,L2FCE
        LD      A,(LIVES1)
        AND     A
        RET     Z

        LD      E,$00
        LD      B,$04
        CALL    L2FE9
        LD      (COUNT1),A
        XOR     A
L2FCA:  LD      E,$0F
        JR      L2FE0
L2FCE:  LD      A,(LIVES2)
        AND     A
        RET     Z

        LD      E,$78
        LD      B,$08
        CALL    L2FE9
        LD      (COUNT2),A
;  Draw 1x10 line above player's "Safe Area"        
        XOR     A               ; Color Mask to Write Rectangle with
L2FDE:  LD      E,$87           ; X Coordinate for UL Corner 
L2FE0:  LD      D,$47           ; Y Coordinate for UL Corner
        LD      BC,$010A        ; X,Y Size in Pixels (1,10)
        DI      
        SYSTEM  RECTAN          ;  UPI paint a RECTANgle
        ;
        RET     


L2FE9:  RES     2,(IX+$0A)
        LD      A,D
        LD      B,$81
        LD      C,$10
        LD      D,$48
        CALL    L2A21
        LD      A,$0A
        RET     


L2FFA:  LD      A,$FF
        CALL    L2FDE
        LD      C,$08
        LD      E,$7C
        JR      $300E
L3005:  LD      A,$FF
        CALL    L2FCA
;  Place a Black Space in the Countdown Timer area for Player 1, when the
;  Player 1 leaves the Safe Area at the beginning of each turn.  
        LD      C,$04           ; ... Options: 1x, Standard Write, Blue on Black                                       
        LD      E,30            ; ... X Coordinate
        LD      D,74            ; ... Y Coordinate
        LD      A,$20           ; ... ASCII Character to Display (Space)
        SYSTEM  CHRDIS          ;  UPI CHaRacter DISplay
;
        RET     


;  CALL to here.  Follow Code. 
L3015:  DB      $FD
        DB      $7E
        DB      $00
        DB      $E6
        DB      $C1
        DB      $FE
        DB      $80
        DB      $C0
        DB      $DD
        DB      $7E
        DB      $00
        DB      $E6
        DB      $C9
        DB      $FE
        DB      $80
        DB      $C0
        DB      $FD
        DB      $7E
        DB      $04
        DB      $DD
        DB      $96
        DB      $04
        DB      $4F
        DB      $C6
        DB      $06
        DB      $FE
        DB      $0C
        DB      $D0
        DB      $FD
        DB      $7E
        DB      $06
        DB      $DD
        DB      $96
        DB      $06
        DB      $47
        DB      $C6
        DB      $06
        DB      $FE
        DB      $0C
        DB      $D0
        DB      $EF
        DB      $DD
        DB      $CB
        DB      $07
        DB      $4E
        DB      $20
        DB      $30
        DB      $7D
        DB      $BB
        DB      $78
        DB      $20
        DB      $0B
        DB      $17
        DB      $DD
        DB      $CB
        DB      $07
        DB      $46
        DB      $20
        DB      $01
        DB      $3F
        DB      $D2
        DB      $63
        DB      $32
        DB      $FD
        DB      $CB
        DB      $07
        DB      $46
        DB      $3E
        DB      $08
        DB      $28
        DB      $01
        DB      $AF
        DB      $FD
        DB      $CB
        DB      $07
        DB      $4E
        DB      $28
        DB      $07
        DB      $85
        DB      $CF
        DB      $FD
        DB      $77
        DB      $04
        DB      $18
        DB      $05
        DB      $84
        DB      $CF
        DB      $FD
        DB      $77
        DB      $06
        DB      $FD
        DB      $CB
        DB      $00
        DB      $EE
        DB      $C9
        DB      $7C
        DB      $BA
        DB      $79
        DB      $18
        DB      $CE

L3079:  LD      IX,$4E38
        CALL    L3084
        LD      IX,$4E52
L3084:  BIT     5,(IX+$00)
        JR      NZ,L308F
        LD      A,($4F27)
        AND     A
        RET     Z

L308F:  BIT     7,(IX+$0A)
        RET     NZ

        CALL    L30C4
        CALL    L312E          
        CALL    L2B9E         
        BIT     3,(IX+$00)
        RET     Z

        LD      A,$10
        CALL    L2B8E       
        LD      A,($4F2E)
        CP      $02
        JR      NZ,L30B3
        LD      HL,$4F26
        SET     4,(HL)
L30B3:  BIT     2,(IX+$07)
        LD      HL,LIVES1
        JR      NZ,L30BD
        INC     HL
L30BD:  DEC     (HL)
        LD      HL,$4F41
        SET     0,(HL)
        RET 
        
        
L30C4:  BIT     1,(IX+$00)
        RET     Z

        LD      A,(IX+$06)
        SUB     $04
        LD      (IX+$06),A
        CP      $44
        PUSH    AF
        CALL    Z,L30E0
        POP     AF
        CP      $3C
        CALL    Z,L30F3
        JP      L2846
L30E0:  LD      HL,$4F41
        SET     6,(HL)
        BIT     2,(IX+$07)
        LD      HL,$2F3A
        JR      NZ,L30F1
        LD      HL,$2F5D
L30F1:  JR      L312A
L30F3:  RES     0,(IX+$00)
        RES     1,(IX+$00)
        BIT     2,(IX+$07)
        LD      HL,COUNT1
        JR      NZ,L3107
        LD      HL,COUNT2
L3107:  LD      (HL),$01
        LD      A,(LIVES1)
        LD      HL,$2F3A
        JR      NZ,L3117
        LD      A,(LIVES2)
        LD      HL,$2F5D
L3117:  DEC     A
        RET     Z

        PUSH    AF
        PUSH    HL
        CALL    L312A
        POP     HL
        POP     AF
        CP      $07
        RET     NC

        LD      B,A
        LD      DE,$0005
L3127:  ADD     HL,DE
        DJNZ    L3127
L312A:  DI      
        JP      L35F4
L312E:  LD      A,(IX+$00)
        AND     $CB
        CP      $80
        RET     NZ

        LD      A,(IX+$01)
        AND     $0F
        LD      B,A
        RST     $20              ;  User ReStarT #4 of 6
        JR      NZ,L318B
        RST     $20              ;  User ReStarT #4 of 6
        JR      NZ,L318B
        BIT     2,(IX+$0A)
        JR      NZ,L3183
        BIT     5,(IX+$00)
        JP      NZ,L2846
        LD      A,B
        AND     A
        RET     PE

        CP      $04
        JR      NC,L316A
        LD      A,(IX+$04)
        ADD     A,$0C
L315B:  SUB     $0C
        RET     Z

        JR      NC,L315B
        CP      $FA
        LD      B,$04
        JR      C,L3168
        LD      B,$08
L3168:  JR      L317C
L316A:  LD      A,(IX+$06)
        ADD     A,$0C
L316F:  SUB     $0C
        RET     Z

        JR      NC,L316F
        CP      $FA
        LD      B,$01
        JR      C,L317C
        LD      B,$02
L317C:  RST     $20              ;  User ReStarT #4 of 6
        JR      NZ,L318E
        RST     $20              ;  User ReStarT #4 of 6
        JR      NZ,L318E
        RET     
        
        
L3183:  LD      A,(IX+$07)
        AND     $03
        LD      C,A
        JR      L3195
L318B:  LD      (IX+$01),B
L318E:  BIT     2,(IX+$0A)
        JP      Z,L2837
L3195:  LD      A,(IX+$07)
        AND     $04
        OR      $08
        LD      B,A
        LD      A,(IX+$0A)
        INC     (IX+$0A)
        RRCA    
        RRCA    
        AND     $C0
        OR      B
        OR      C
        JP      L284D

L31AC:  BIT     7,(IX+$1D)
        JR      Z,L31BF
        LD      H,(IX+$1D)
        LD      L,(IX+$1E)
        XOR     A
        LD      (IX+$1D),A
        RES     7,H
        LD      (HL),A
L31BF:  LD      A,(IX+$00)
        AND     $C0
        CP      $80
        RET     NZ

        LD      HL,$4AFD
        LD      DE,$0078
        LD      A,(IX+$06)
        ADD     A,$05
L31D2:  ADD     HL,DE
        SUB     $0C
        JR      NC,L31D2
        LD      A,(IX+$04)
        ADD     A,$05
L31DC:  INC     HL
        SUB     $0C
        JR      NC,L31DC
        LD      A,(IX+$07)
        AND     $1C
        ADD     A,$04
        CP      $10
        RET     NC

        LD      B,A
        RRCA    
        RRCA    
        OR      B
        LD      (HL),A
        SET     7,H
        LD      (IX+$1D),H
        LD      (IX+$1E),L
        RET


L31F9:  LD      A,D
        RST     $08             ;  USER RESTART #1 OF 6
        LD      D,A
        LD      A,E
        RST     $08             ;  USER RESTART #1 OF 6
        ADD     A,$0E
        LD      E,A
L3201:  PUSH    HL
        SRL     E
        SRL     E
        LD      H,$00
        LD      L,D
        LD      D,H
        ADD     HL,HL
        ADD     HL,HL
        ADD     HL,HL
        PUSH    HL
        ADD     HL,HL
        ADD     HL,HL
        ADD     HL,DE
        POP     DE
        ADD     HL,DE
        EX      DE,HL
        POP     HL
        RET     


;  Reset VECTor #1 /  8 / $08 
L3216:  LD      HL,$3221
        LD      C,$0B
L321B:  DEC     C
        INC     HL
        CP      (HL)
        JR      C,L321B
        LD      A,(HL)
        RET     

        DB      $78
        DB      $6C
        DB      $60
        DB      $54
        DB      $48
        DB      $3C
        DB      $30
        DB      $24
        DB      $18
        DB      $0C
        DB      $00

;  Reset VECTor #2 / 16 / $10
L322D:  RST     $08              ;  User ReStarT #1 of 6
        LD      A,B
        LD      B,C
        RST     $08              ;  User ReStarT #1 of 6
        LD      A,B
        SUB     C
        RET     

; Reset VECTor #5 / 40 / $28
L3234:  LD      L,(IY+$04)
        LD      H,(IY+$06)
L323A:  LD      E,(IX+$04)      ; Reset VECTor #6 / 48 / $30
        LD      D,(IX+$06)
        RET     

; 
;  SENTRY RETURN Code SF2 Handler
;  Sentry, Flag bit 2 has changed
L3241:  LD      HL,$4F39
        LD      BC,$8408
        LD      DE,$5400
        JR      L3255

;  SENTRY RETURN Code SF1 Handler
;  Sentry, Flag bit 1 has changed
L324C:  LD      HL,$4F3B
        LD      BC,$8404
        LD      DE,$5478
L3255:  LD      A,($4F26)
        BIT     3,A
        RET     NZ

        LD      A,(HL)
        DEC     HL
        OR      (HL)
        RET     Z

        DI      
        SYSTEM  DISNUM                  ;  UPI DISplay NUMber
        ;
        RET     


L3263:  SET     3,(IY+$00)
        BIT     2,(IX+$00)
        RET     NZ

        BIT     2,(IY+$00)
        LD      B,$05
        JR      Z,L3295
        LD      A,(IY+$07)
        RRA     
        RRA     
        AND     $07
        LD      B,A
        INC     B
        CP      $03
        JR      C,L3295
        LD      HL,$4F3C
        JR      NZ,L328C
        SET     0,(HL)
        LD      B,$10
        JR      L3295
L328C:  SET     1,(HL)
        LD      B,$20
        LD      HL,$4F2E
        SET     3,(HL)
L3295:  LD      A,($4F26)
        LD      C,A
        BIT     6,C
        LD      A,B
        JR      Z,L32A0
        ADD     A,A
        DAA     
L32A0:  BIT     5,C
        JR      Z,L32A6
        ADD     A,A
        DAA     
L32A6:  BIT     2,(IX+$07)
        LD      DE,$4F38
        LD      B,$00
        JR      NZ,L32B4
        INC     DE
        INC     DE
        INC     B
L32B4:  LD      HL,$4FDE
        DEC     B
        JR      NZ,L32BE
        SET     1,(HL)
        JR      L32C0
L32BE:  SET     2,(HL)
L32C0:  EX      DE,HL
        ADD     A,(HL)
        DAA     
        LD      (HL),A
        INC     HL
        LD      A,$00
        ADC     A,(HL)
        DAA     
        LD      (HL),A
        RET


;  SENTRY RETURN Code ST0 Handler
;                Code ST1 Handler 
;  Trigger 1 for player 1 changed and/or
;  Trigger 2 for player 2 changed
L32CB:  LD      IX,$4E38        ; Trigger 1 for Player 1 Changed
        JR      L32D5
L32D1:  LD      IX,$4E52        ; Trigger 2 for Player 2 Changed
L32D5:  BIT     4,B
        RET     Z

        LD      A,($4F27)
        AND     A
        RET     Z

        LD      A,(IX+$00)
        AND     $C1
        CP      $80
        RET     NZ

        BIT     7,(IX+$15)
        RET     NZ

        CALL    L332C
        RET     NC

        RES     3,(IX+$0A)
        SET     2,(IX+$0A)
        SET     5,(IX+$00)
        INC     (IX+$0A)
        LD      HL,$4F41
        SET     2,(HL)
        LD      H,$80
L3304:  LD      A,(IX+$07)
        AND     $1C
        ADD     A,$04
        CP      $10
        JR      C,L3311
        LD      A,$0C
L3311:  OR      H
        LD      H,A
L3313:  LD      BC,$0015
        LD      A,(IX+$07)
        AND     $03
        OR      H
        PUSH    IX
        POP     HL
        ADD     HL,BC
        PUSH    HL
        INC     HL
        LD      (HL),E
        INC     HL
        LD      (HL),D
        INC     HL
        LD      (HL),B
        INC     HL
        LD      (HL),B
        POP     HL
        LD      (HL),A
        RET     



L332C:  RST     $30             ;  USER RESTART #6 OF 6
        LD      A,(IX+$07)
        BIT     1,A
        RRA     
        JR      Z,L3359
        JR      NC,L3341
        INC     E
        INC     E
        CALL    L2EE8
        RET     NZ

        LD      A,$19
        JR      L334B
L3341:  LD      A,E
        ADD     A,$08
        LD      E,A
        CALL    L2EF2
        RET     NZ

        LD      A,$0E
L334B:  ADD     A,(IX+$04)
        AND     $FC
        LD      E,A
        LD      A,(IX+$06)
        ADD     A,$05
        LD      D,A
        SCF     
        RET


L3359:  JR      NC,L3366
        INC     D
        INC     D
        INC     D
        CALL    L2EDE
        RET     NZ

        LD      A,$0B
        JR      L336F
L3366:  LD      A,D
        ADD     A,$08
        LD      D,A
        CALL    L2ED6
        RET     NZ

        XOR     A
L336F:  ADD     A,(IX+$06)
        AND     $FC
        LD      D,A
        LD      A,(IX+$04)
        ADD     A,$13
        LD      E,A
        SCF     
        RET     


L337D:  LD      A,($4F32)
        LD      A,$04
        LD      HL,$4F3C
        BIT     6,(HL)
        JR      Z,L338B
        LD      A,$02
L338B:  LD      ($4FD7),A
        LD      B,$06
L3390:  PUSH    BC
        RST     $18              ;  User ReStarT #3 of 6
        CALL    L3399
        POP     BC
        DJNZ    L3390
        RET     


L3399:  LD      A,(IX+$00)
        AND     $C0
        CP      $80
        RET     NZ

        LD      HL,$4F3C
        LD      A,(IX+$07)
        RRA     
        RRA     
        AND     $07
        CP      $03
        JR      C,L33B6
        RET     NZ

        BIT     7,(HL)
        JR      NZ,L33BB
        JR      L33BA
L33B6:  BIT     7,(HL)
        JR      NZ,L33BB
L33BA:  INC     A
L33BB:  SYSSUK  INDEXB          ;  UPI INDEX Byte by A
        DW      L33E3           ;  ... Base Address = 13283
        ;
        LD      A,(IX+$02)
        ADD     A,A
        CP      (HL)
        RET     NC

        CP      $10
        JR      C,L33CB
        AND     $F0
L33CB:  LD      (IX+$02),A
        CP      $20
        RET     C

        LD      B,$FE
        JR      Z,L33D7
        LD      B,$FC
L33D7:  RST     $30              ;  User ReStarT #6 of 6
        LD      A,E
        AND     B
        LD      (IX+$04),A
        LD      A,D
        AND     B
        LD      (IX+$06),A
        RET     

;  Base Address of Table for INDEXB
L33E3:  DB      $09
        DB      $11
        DB      $11
        DB      $21
        DB      $41

;  Reset VECTor #3 / 24 / $18
L33E8:  LD      IX,$4E4D
        LD      DE,$001F
        ADD     IX,DE
        DJNZ    $33EF
        RET     


L33F4:  LD      A,($4F27)
        AND     A
        RET     Z

        LD      B,$06
L33FB:  PUSH    BC
        RST     $18              ;  User ReStarT #3 of 6
        POP     BC
        BIT     7,(IX+$00)
        RET     NZ

        DJNZ    L33FB
        LD      A,($4F26)
        BIT     1,A
        RET     NZ

        LD      A,($4E38)
        LD      HL,$4E52
        OR      (HL)
        BIT     6,A
        RET     NZ

        LD      HL,$4F2E
        LD      A,(HL)
        INC     (HL)
        AND     A
        JR      Z,L3459
        DEC     A
        JR      NZ,L344B
        LD      A,($4F32)
        DEC     A
        JR      Z,L344B
        LD      B,$40
        SRL     A
        JR      Z,L3434
        LD      B,$80
        SRL     A
        JR      Z,L3434
        LD      B,$C0
L3434:  SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $00              ;  ... Cutoff = 0
        ;
        CP      B
        JR      NC,L344B
        LD      HL,$0403
        LD      ($4F2F),HL
L3440:  LD      A,$01
        LD      ($4FD8),A


L3445:  LD      HL,$4F26
        SET     1,(HL)
        RET     


L344B:  LD      HL,$4F26
        SET     3,(HL)
        XOR     A
        LD      ($4F27),A
        INC     A
        LD      ($4FDC),A
        RET     


L3459:  LD      HL,$4F41
        SET     1,(HL)
        LD      BC,$0C00
        LD      A,$04
        LD      ($4FD7),A
        LD      A,$0C
        CALL    L2BF0
        CALL    L3440
        LD      A,C
        CP      $3D
        RET     C

        SET     2,(HL)
        RET     


;  SENTRY RETURN Code SF5 Handler
;  Sentry, Flag bit 5 has changed
L3475:  LD      IX,$4E6C
        LD      A,(IX+$00)
        AND     $C0
        CP      $80
        RET     NZ

        LD      HL,$4F31
        BIT     7,(IX+$15)
        JR      Z,L3491
        LD      (HL),$02
        SET     5,(IX+$15)
        RET     

L3491:  LD      (HL),$14
        CALL    L332C
        RET     NC

        LD      HL,$4F40
        SET     5,(HL)
        LD      H,$8C
        JP      L3313


;  SENTRY RETURN Code SCT3 Handler
;  Counter-Timer 3 has counted down
L34A1:   LD      HL,$4F2E
         LD      A,(HL)
         AND     A
         RET     Z

         DEC     A
         JR      NZ,L34DA
         LD      A,($4F3C)
         BIT     6,A
         LD      A,$20
         JR      NZ,L34B5
         LD      A,$10
L34B5:   LD      ($4E6E),A
L34B8:   LD      HL,$4F26
         RES     1,(HL)
         RET     


L34BE:  LD      HL,$4F40
        SET     6,(HL)
        JP      L28E7
L34C6:  SET     2,(HL)
        LD      A,$01
        LD      ($4FD8),A
        RES     5,(IX+$0A)
L34D1:  SET     7,(IX+$0A)
        LD      (IX+$00),$00
        RET     
     

L34DA:  LD      IX,$4E6C
        BIT     2,(HL)
        JR      Z,L34C6
        RES     2,(HL)
        BIT     3,(HL)
        JR      NZ,L34B8
        LD      A,($4F26)
        BIT     4,A
        JR      NZ,L34BE
        LD      A,($4F32)
        CP      $05
        LD      A,$03
        JR      NC,L34F9
        INC     A
L34F9:  LD      ($4FD8),A
        LD      HL,$4E38
        LD      DE,$4E52
        SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $00              ;  ... Cutoff = 0
        ;
        BIT     3,A
        JR      Z,L350A
        EX      DE,HL
L350A:  LD      A,(HL)
        AND     $C1
        CP      $80
        JR      Z,L351C
        EX      DE,HL
        LD      A,(HL)
        AND     $C1
        CP      $80
        LD      DE,$003C
        JR      NZ,L3591
L351C:  PUSH    HL
        POP     IX
        LD      HL,$4F2F
        PUSH    HL
        CALL    L35BC
        LD      C,A
        INC     HL
        CALL    L35BC
        LD      B,A
        EXX     
        LD      A,(IX+$06)
        ADD     A,$06
        RST     $08              ;  User ReStarT #1 of 6
        EX      AF,AF'
        LD      A,(IX+$04)
        ADD     A,$06
        RST     $08              ;  User ReStarT #1 of 6
        EXX     
        LD      E,A
        EX      AF,AF'
        LD      D,A
        POP     HL
L353F:  SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $00              ;  ... Cutoff = 0
        ;
        RRA     
        JR      NC,L356E
        RRA     
        LD      A,(IX+$07)
        AND     $03
        CP      $03
        CALL    Z,L3565
        LD      A,E
        ADD     A,B
        JR      L355D
        AND     $03
        CP      $02
        CALL    Z,L3565
        LD      A,E
        SUB     B
L355D:  CP      $79
        JR      NC,L353F
        LD      E,A
        INC     HL
        JR      L358B
L3565:  SYSSUK  RANGED           ;  UPI RANGED random number
        DB      $00              ;  ... Cutoff = 0
        ;
        AND     $03
        RET     Z

        POP     AF
        JR      L353F
L356E:  RRA     
        LD      A,(IX+$07)
        JR      NC,L357F
        AND     $03
        CP      $01
        CALL    Z,L3565
        LD      A,D
        ADD     A,C
        JR      L3586
L357F:  AND     $03
        CALL    Z,L3565
        LD      A,D
        SUB     C
L3586:  CP      $3D
        JR      NC,L353F
        LD      D,A
L358B:  LD      A,(HL)
        CP      $02
        JR      C,L3591
        DEC     (HL)
L3591:  LD      HL,$4F40
        SET     4,(HL)
        LD      HL,$4FDE
        SET     5,(HL)
        LD      A,($4F3C)
        RLA     
        LD      C,$10
        JR      C,L35A5
        LD      C,$20
L35A5:  BIT     2,(IX+$07)
        LD      IX,$4E6C
        RES     3,(IX+$0A)
        JR      NZ,L35B7
        SET     3,(IX+$0A)
L35B7:  LD      A,$10
        JP      L2A1F
L35BC:  LD      B,(HL)
        XOR     A
L35BE:  ADD     A,$0C
        DJNZ    L35BE
        RET


L35C3:  PUSH    IX
        POP     HL
        LD      BC,$000A
        ADD     HL,BC
        BIT     7,(HL)
        RET     Z

        RES     7,(HL)
        PUSH    HL
        BIT     6,(HL)
        RES     6,(HL)
        CALL    NZ,L35EB
        POP     HL
        BIT     5,(HL)
        RET     Z

        LD      A,(IX+$06)
        DEC     HL
        LD      (HL),A
        LD      A,(IX+$04)
        DEC     HL
        LD      (HL),A
        INC     HL
        INC     HL
        LD      A,(HL)
        XOR     $70
        LD      (HL),A
L35EB:  BIT     4,(HL)
        LD      DE,$0005
        JR      Z,L35F3
        ADD     HL,DE
L35F3:  INC     HL
L35F4:  LD      A,(HL)
        OUT     (MAGIC),A       ; write MAGIC register
        LD      BC,$FFD6
        BIT     7,A
        JR      NZ,L3608
        LD      BC,$002A
        BIT     6,A
        JR      NZ,L3608
        LD      BC,$0026
L3608:  INC     HL
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        PUSH    DE
        INC     HL
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        POP     HL
        BIT     6,A
        LD      A,$08
        JR      NZ,L3629
L3618:  EX      AF,AF'
        LD      A,(DE)
        INC     DE
        LD      (HL),A
        INC     HL
        LD      A,(DE)
        INC     DE
        LD      (HL),A
        INC     HL
        LD      (HL),$00
        ADD     HL,BC
        EX      AF,AF'
        DEC     A
        JR      NZ,L3618
        RET     


L3629:  EX      AF,AF'
        LD      A,(DE)
        INC     DE
        LD      (HL),A
        DEC     HL
        LD      A,(DE)
        INC     DE
        LD      (HL),A
        DEC     HL
        LD      (HL),$00
        ADD     HL,BC
        EX      AF,AF'
        DEC     A
        JR      NZ,L3629
        RET     


L363A:  DB      $43
        DB      $CD
        DB      $BB
        DB      $86
        DB      $C6
        DB      $39
        DB      $D6
        DB      $39
        DB      $E6
        DB      $39
        DB      $F6
        DB      $39
        DB      $F6
        DB      $36
        DB      $06
        DB      $37
        DB      $16
        DB      $37
        DB      $00
        DB      $00
        DB      $26
        DB      $37
        DB      $36
        DB      $37
        DB      $46
        DB      $37
        DB      $00
        DB      $00
        DB      $56
        DB      $37
        DB      $66
        DB      $37
        DB      $76
        DB      $37
        DB      $00
        DB      $00
        DB      $86
        DB      $37
        DB      $96
        DB      $37
        DB      $A6
        DB      $37
        DB      $00
        DB      $00
        DB      $B6
        DB      $37
        DB      $C6
        DB      $37
        DB      $D6
        DB      $37
        DB      $00
        DB      $00
        DB      $E6
        DB      $37
        DB      $F6
        DB      $37
        DB      $06
        DB      $38
        DB      $00
        DB      $00
        DB      $16
        DB      $38
        DB      $26
        DB      $38
        DB      $36
        DB      $38
        DB      $00
        DB      $00
        DB      $16
        DB      $38
        DB      $26
        DB      $38
        DB      $36
        DB      $38
        DB      $00
        DB      $00
        DB      $46
        DB      $38
        DB      $56
        DB      $38
        DB      $66
        DB      $38
        DB      $00
        DB      $00
        DB      $76
        DB      $38
        DB      $86
        DB      $38
        DB      $96
        DB      $38
        DB      $00
        DB      $00
        DB      $A6
        DB      $38
        DB      $B6
        DB      $38
        DB      $C6
        DB      $38
        DB      $00
        DB      $00
        DB      $E6
        DB      $36
        DB      $D6
        DB      $38
        DB      $E6
        DB      $38
        DB      $00
        DB      $00
        DB      $F6
        DB      $38
        DB      $06
        DB      $39
        DB      $16
        DB      $39
        DB      $00
        DB      $00
        DB      $D6
        DB      $36
        DB      $26
        DB      $39
        DB      $36
        DB      $39
        DB      $00
        DB      $00
        DB      $00
        DB      $00
        DB      $46
        DB      $39
        DB      $56
        DB      $39
        DB      $46
        DB      $39
        DB      $00
        DB      $00
        DB      $66
        DB      $39
        DB      $76
        DB      $39
        DB      $66
        DB      $39
        DB      $00
        DB      $00
        DB      $86
        DB      $39
        DB      $96
        DB      $39
        DB      $86
        DB      $39
        DB      $00
        DB      $00
        DB      $A6
        DB      $39
        DB      $B6
        DB      $39
        DB      $A6
        DB      $39

;  Yellow Worrior (Standing Position)
        DB      $3A,$00           ; . 3 2 2 . . . .
        DB      $21,$00           ; . 2 . 1 . . . .
        DB      $4A,$00           ; 1 . 2 2 . . . .
        DB      $B8,$08           ; 2 3 2 . . . 2 .
        DB      $BF,$FF           ; 2 3 3 3 3 3 3 3
        DB      $28,$08           ; . 2 2 . . . 2 .
        DB      $82,$00           ; 2 . . 2 . . . .
        DB      $50,$50           ; 1 1 . . 1 1 . .

;  Blue Worrior (Standing Position)
        DB      $35,$00           ; . 3 1 1 . . . . 
        DB      $13,$00           ; . 1 . 3 . . . . 
        DB      $C5,$00           ; 3 . 1 1 . . . . 
        DB      $74,$08           ; 1 3 1 . . . 2 . 
        DB      $7F,$FF           ; 1 3 3 3 3 3 3 3 
        DB      $14,$08           ; . 1 1 . . . 2 . 
        DB      $41,$00           ; 1 . . 1 . . . . 
        DB      $F0,$F0           ; 3 3 . . 3 3 . . 

       
L36F6:  DB      $00
        DB      $03
        DB      $14
        DB      $5C
        DB      $14
        DB      $10
        DB      $75
        DB      $50
        DB      $75
        DB      $50
        DB      $54
        DB      $D0
        DB      $43
        DB      $17
        DB      $1C
        DB      $03
        DB      $00
        DB      $03
        DB      $14
        DB      $5C
        DB      $14
        DB      $10
        DB      $75
        DB      $50
        DB      $75
        DB      $50
        DB      $54
        DB      $D0
        DB      $43
        DB      $5C
        DB      $4C
        DB      $03
        DB      $0C
        DB      $03
        DB      $1D
        DB      $17
        DB      $1D
        DB      $10
        DB      $75
        DB      $50
        DB      $45
        DB      $50
        DB      $54
        DB      $D0
        DB      $43
        DB      $5C
        DB      $4C
        DB      $03
        DB      $15
        DB      $40
        DB      $47
        DB      $D4
        DB      $C5
        DB      $54
        DB      $31
        DB      $40
        DB      $0D
        DB      $44
        DB      $15
        DB      $54
        DB      $10
        DB      $0C
        DB      $F0
        DB      $03

; Burwor, Blue (Not Sticking Out Tongue)
        DB      $55,$40           ; 1 1 1 1 1 . . . 
        DB      $07,$D4           ; . . 1 3 3 1 1 . 
        DB      $C5,$54           ; 3 . 1 1 1 1 1 . 
        DB      $31,$40           ; . 3 . 1 1 . . . 
        DB      $1D,$44           ; . 1 3 1 1 . 1 . 
        DB      $15,$54           ; . 1 1 1 1 1 1 . 
        DB      $30,$0C           ; . 3 . . . . 3 . 
        DB      $C0,$03           ; 3 . . . . . . 3 


; Burwor, Blue  (Sticking Out Tongue)
        DB      $55,$40           ; 1 1 1 1 1 . . .
        DB      $04,$D4           ; . . 1 . 3 1 1 . 
        DB      $C5,$7F           ; 3 . 1 1 1 3 3 3 
        DB      $31,$54           ; . 3 . 1 1 1 1 . 
        DB      $1D,$40           ; . 1 3 1 1 . . . 
        DB      $15,$54           ; . 1 1 1 1 1 1 . 
        DB      $30,$04           ; . 3 . . . . 1 . 
        DB      $C0,$0F           ; 3 . . . . . 3 3 

        DB      $0A
        DB      $00
        DB      $26
        DB      $20
        DB      $A2
        DB      $80
        DB      $2A
        DB      $A3
        DB      $0A
        DB      $A8
        DB      $02
        DB      $A3
        DB      $30
        DB      $A8
        DB      $3A
        DB      $80
        DB      $0A
        DB      $00
        DB      $26
        DB      $20
        DB      $A2
        DB      $80
        DB      $2A
        DB      $A3
        DB      $0A
        DB      $A8
        DB      $02
        DB      $A0
        DB      $C0
        DB      $A8
        DB      $EA
        DB      $03
        DB      $0A
        DB      $80
        DB      $22
        DB      $80
        DB      $A6
        DB      $80
        DB      $2A
        DB      $A0
        DB      $0A
        DB      $A8
        DB      $02
        DB      $A3
        DB      $20
        DB      $A8
        DB      $CA
        DB      $80

; Garwor, Yellow (Mouth Open and Tail Low) 
        DB      $00,$20           ; . . . . . 2 . . 
        DB      $F0,$A8           ; 3 3 . . 2 2 2 . 
        DB      $82,$86           ; 2 . . 2 2 . 1 2 
        DB      $8A,$AA           ; 2 . 2 2 2 2 2 2 
        DB      $AA,$A0           ; 2 2 2 2 2 2 . . 
        DB      $2A,$88           ; . 2 2 2 2 . 2 . 
        DB      $22,$00           ; . 2 . 2 . . . . 
        DB      $0C,$C0           ; . . 3 . 3 . . . 

; Garwor, Yellow (Mouth Open and Tail High)
        DB      $F0,$20           ; 3 3 . . . 2 . . 
        DB      $80,$A8           ; 2 . . . 2 2 2 . 
        DB      $82,$86           ; 2 . . 2 2 . 1 2 
        DB      $8A,$AA           ; 2 . 2 2 2 2 2 2 
        DB      $2A,$A0           ; . 2 2 2 2 2 . . 
        DB      $2A,$88           ; . 2 2 2 2 . 2 . 
        DB      $22,$00           ; . 2 . 2 . . . . 
        DB      $C0,$C0           ; 3 . . . 3 . . . 

; Garwor, Yellow (Mouth Open)
        DB      $C0,$20           ; 3 . . . . 2 . . 
        DB      $20,$A8           ; . 2 . . 2 2 2 . 
        DB      $82,$92           ; 2 . . 2 2 1 . 2 
        DB      $8A,$AA           ; 2 . 2 2 2 2 2 2 
        DB      $AA,$AA           ; 2 2 2 2 2 2 2 2 
        DB      $2A,$80           ; . 2 2 2 2 . . . 
        DB      $22,$00           ; . 2 . 2 . . . . 
        DB      $0C,$00           ; . . 3 . . . . . 

        DB      $0F
        DB      $30
        DB      $3F
        DB      $30
        DB      $F7
        DB      $31
        DB      $3F
        DB      $FC
        DB      $0F
        DB      $F1
        DB      $03
        DB      $FC
        DB      $C0
        DB      $F1
        DB      $3F
        DB      $0C
        DB      $0F
        DB      $C0
        DB      $3F
        DB      $C0
        DB      $F3
        DB      $C0
        DB      $3F
        DB      $FD
        DB      $0F
        DB      $F0
        DB      $03
        DB      $FD
        DB      $30
        DB      $F0
        DB      $CF
        DB      $0D
        DB      $0F
        DB      $30
        DB      $3F
        DB      $30
        DB      $F7
        DB      $30
        DB      $3F
        DB      $FC
        DB      $0F
        DB      $F1
        DB      $C3
        DB      $FC
        DB      $30
        DB      $F1
        DB      $0F
        DB      $0C
        DB      $30
        DB      $30
        DB      $C0
        DB      $FC
        DB      $C3
        DB      $DF
        DB      $CF
        DB      $FF
        DB      $3F
        DB      $C0
        DB      $3F
        DB      $FF
        DB      $CC
        DB      $C0
        DB      $11
        DB      $10

;  Thorwor, Red, Facing Right (Mouth Close/3 Blue Feet)
        DB      $C0,$30           ; 3 . . . . 3 . .  
        DB      $30,$FC           ; . 3 . . 3 3 3 . 
        DB      $C3,$CF           ; 3 . . 3 3 . 3 3 
        DB      $CF,$FF           ; 3 . 3 3 3 3 3 3 
        DB      $3F,$FF           ; . 3 3 3 3 3 3 3 
        DB      $3F,$C0           ; . 3 3 3 3 . . . 
        DB      $CC,$C0           ; 3 . 3 . 3 . . . 
        DB      $44,$40           ; 1 . 1 . 1 . . . 

;  Thorwor, Red, Facing Right (Mouth Open/2 Blue Feet)
        DB      $0C,$30           ; . . 3 . . 3 . . 
        DB      $30,$FC           ; . 3 . . 3 3 3 . 
        DB      $C3,$DF           ; 3 . . 3 3 1 3 3 
        DB      $CF,$FF           ; 3 . 3 3 3 3 3 3 
        DB      $3F,$C0           ; . 3 3 3 3 . . . 
        DB      $3F,$FF           ; . 3 3 3 3 3 3 3 
        DB      $CC,$C0           ; 3 . 3 . 3 . . . 
        DB      $11,$00           ; . 1 . 1 . . . . 

;  Worluk, Blue with Yellow Wings (Wings All the Way Up)
        DB      $8C,$32           ; 2 . 3 . . 3 . 2 
        DB      $A1,$4A           ; 2 2 . 1 1 . 2 2 
        DB      $A8,$2A           ; 2 2 2 . . 2 2 2 
        DB      $17,$D4           ; . 1 1 3 3 1 1 . 
        DB      $49,$61           ; 1 . 2 1 1 2 . 1 
        DB      $05,$50           ; . . 1 1 1 1 . . 
        DB      $11,$44           ; . 1 . 1 1 . 1 . 
        DB      $C0,$03           ; 3 . . . . . . 3 

;  Worluk, Blue with Yellow Wings (Wings Half-Way Up)
        DB      $0C,$30           ; . . 3 . . 3 . . 
        DB      $81,$42           ; 2 . . 1 1 . . 2 
        DB      $A8,$2A           ; 2 2 2 . . 2 2 2 
        DB      $17,$D4           ; . 1 1 3 3 1 1 . 
        DB      $69,$69           ; 1 2 2 1 1 2 2 1 
        DB      $05,$50           ; . . 1 1 1 1 . . 
        DB      $11,$44           ; . 1 . 1 1 . 1 . 
        DB      $C0,$03           ; 3 . . . . . . 3 

;  Worluk, Blue with Yellow Wings (Wings Down)
        DB      $0C,$30           ; . . 3 . . 3 . . 
        DB      $01,$40           ; . . . 1 1 . . . 
        DB      $08,$20           ; . . 2 . . 2 . . 
        DB      $17,$D4           ; . 1 1 3 3 1 1 . 
        DB      $69,$69           ; 1 2 2 1 1 2 2 1 
        DB      $85,$52           ; 2 . 1 1 1 1 . 2 
        DB      $11,$44           ; . 1 . 1 1 . 1 . 
        DB      $C0,$03           ; 3 . . . . . . 3 

        DB      $00
        DB      $C1
        DB      $01
        DB      $05
        DB      $75
        DB      $15
        DB      $55
        DB      $55
        DB      $45
        DB      $50
        DB      $01
        DB      $00
        DB      $00
        DB      $40
        DB      $00
        DB      $C0
        DB      $00
        DB      $C0
        DB      $00
        DB      $41
        DB      $01
        DB      $05
        DB      $75
        DB      $D5
        DB      $55
        DB      $54
        DB      $45
        DB      $50
        DB      $01
        DB      $00
        DB      $00
        DB      $00
        DB      $03
        DB      $00
        DB      $01
        DB      $C1
        DB      $01
        DB      $45
        DB      $74
        DB      $55
        DB      $55
        DB      $55
        DB      $45
        DB      $50
        DB      $00
        DB      $00
        DB      $00
        DB      $00
        DB      $01
        DB      $50
        DB      $00
        DB      $70
        DB      $01
        DB      $50
        DB      $05
        DB      $54
        DB      $D1
        DB      $43
        DB      $01
        DB      $50
        DB      $00
        DB      $54
        DB      $00
        DB      $55
        DB      $05
        DB      $40
        DB      $01
        DB      $C0
        DB      $05
        DB      $40
        DB      $15
        DB      $50
        DB      $05
        DB      $C7
        DB      $05
        DB      $40
        DB      $01
        DB      $50
        DB      $00
        DB      $54
        DB      $05
        DB      $40
        DB      $01
        DB      $C0
        DB      $05
        DB      $40
        DB      $05
        DB      $17
        DB      $05
        DB      $5C
        DB      $05
        DB      $40
        DB      $01
        DB      $50
        DB      $01
        DB      $54
        DB      $00
        DB      $C0
        DB      $02
        DB      $E0
        DB      $00
        DB      $C3
        DB      $00
        DB      $C3
        DB      $74
        DB      $C4
        DB      $45
        DB      $D0
        DB      $D3
        DB      $D3
        DB      $0D
        DB      $47
        DB      $00
        DB      $C0
        DB      $02
        DB      $E0
        DB      $00
        DB      $C0
        DB      $00
        DB      $C0
        DB      $74
        DB      $C3
        DB      $45
        DB      $D7
        DB      $D3
        DB      $D3
        DB      $0D
        DB      $47
        DB      $00
        DB      $C0
        DB      $02
        DB      $E0
        DB      $00
        DB      $C0
        DB      $00
        DB      $C0
        DB      $74
        DB      $C3
        DB      $45
        DB      $D7
        DB      $D3
        DB      $D7
        DB      $0D
        DB      $40
        DB      $35
        DB      $00
        DB      $13
        DB      $00
        DB      $C5
        DB      $00
        DB      $74
        DB      $08
        DB      $7F
        DB      $FF
        DB      $14
        DB      $08
        DB      $44
        DB      $00
        DB      $FF
        DB      $00
        DB      $35
        DB      $00
        DB      $13
        DB      $00
        DB      $C5
        DB      $00
        DB      $74
        DB      $08
        DB      $7F
        DB      $FF
        DB      $14
        DB      $08
        DB      $14
        DB      $00
        DB      $3F
        DB      $00
        DB      $00
        DB      $C0
        DB      $02
        DB      $E0
        DB      $00
        DB      $C1
        DB      $00
        DB      $C1
        DB      $98
        DB      $C8
        DB      $8A
        DB      $E0
        DB      $E3
        DB      $E1
        DB      $06
        DB      $89
        DB      $00
        DB      $C0
        DB      $02
        DB      $E0
        DB      $00
        DB      $C0
        DB      $00
        DB      $C0
        DB      $98
        DB      $C1
        DB      $8A
        DB      $E9
        DB      $E3
        DB      $E1
        DB      $06
        DB      $89
        DB      $00
        DB      $C0
        DB      $02
        DB      $E0
        DB      $00
        DB      $C0
        DB      $00
        DB      $C0
        DB      $98
        DB      $C1
        DB      $8A
        DB      $E9
        DB      $E3
        DB      $E9
        DB      $06
        DB      $80

;  Yellow Worrior (Walking 1)
        DB      $3A,$00           ; . 3 2 2 . . . . 
        DB      $21,$00           ; . 2 . 1 . . . . 
        DB      $4A,$00           ; 1 . 2 2 . . . . 
        DB      $B8,$08           ; 2 3 2 . . . 2 . 
        DB      $BF,$FF           ; 2 3 3 3 3 3 3 3 
        DB      $28,$08           ; . 2 2 . . . 2 . 
        DB      $88,$00           ; 2 . 2 . . . . . 
        DB      $55,$00           ; 1 1 1 1 . . . . 

;  Yellow Worrior (Walking 2)        
        DB      $3A,$00           ; . 3 2 2 . . . . 
        DB      $21,$00           ; . 2 . 1 . . . . 
        DB      $4A,$00           ; 1 . 2 2 . . . . 
        DB      $B8,$08           ; 2 3 2 . . . 2 . 
        DB      $BF,$FF           ; 2 3 3 3 3 3 3 3 
        DB      $28,$08           ; . 2 2 . . . 2 . 
        DB      $28,$00           ; . 2 2 . . . . . 
        DB      $15,$00           ; . 1 1 1 . . . . 

        DB      $2E
        DB      $C0
        DB      $8F
        DB      $20
        DB      $33
        DB      $00
        DB      $03
        DB      $0C
        DB      $00
        DB      $CC
        DB      $75
        DB      $D0
        DB      $47
        DB      $D3
        DB      $D9
        DB      $47
        DB      $0C
        DB      $E0
        DB      $2F
        DB      $B0
        DB      $8B
        DB      $80
        DB      $30
        DB      $F0
        DB      $00
        DB      $F0
        DB      $75
        DB      $D0
        DB      $47
        DB      $D3
        DB      $DA
        DB      $47
        DB      $54
        DB      $38
        DB      $4C
        DB      $02
        DB      $94
        DB      $0F
        DB      $74
        DB      $FE
        DB      $7F
        DB      $0B
        DB      $14
        DB      $02
        DB      $43
        DB      $C0
        DB      $F0
        DB      $00
        DB      $D4
        DB      $E0
        DB      $4C
        DB      $38
        DB      $94
        DB      $23
        DB      $B4
        DB      $3C
        DB      $7F
        DB      $CB
        DB      $17
        DB      $CE
        DB      $40
        DB      $00
        DB      $F0
        DB      $00
        DB      $2E
        DB      $E0
        DB      $8F
        DB      $80
        DB      $03
        DB      $80
        DB      $03
        DB      $04
        DB      $00
        DB      $C4
        DB      $9A
        DB      $E0
        DB      $8B
        DB      $E1
        DB      $EE
        DB      $89
        DB      $0C
        DB      $E0
        DB      $2F
        DB      $80
        DB      $8B
        DB      $C0
        DB      $30
        DB      $D0
        DB      $00
        DB      $D0
        DB      $9A
        DB      $C0
        DB      $8B
        DB      $E1
        DB      $E6
        DB      $89
        DB      $E8
        DB      $38
        DB      $84
        DB      $02
        DB      $E8
        DB      $0F
        DB      $B8
        DB      $FE
        DB      $BF
        DB      $0B
        DB      $28
        DB      $02
        DB      $81
        DB      $40
        DB      $50
        DB      $00

;  Yellow Worrior (Firing Position)
        DB      $E8,$E0           ; 3 2 2 . 3 2 . . 
        DB      $84,$C8           ; 2 . 1 . 3 . 2 . 
        DB      $68,$23           ; 1 2 2 . . 2 . 3 
        DB      $B8,$3C           ; 2 3 2 . . 3 3 . 
        DB      $BF,$CB           ; 2 3 3 3 3 . 2 3 
        DB      $29,$42           ; . 2 2 1 1 . . 2 
        DB      $80,$00           ; 2 . . . . . . . 
        DB      $50,$00           ; 1 1 . . . . . . 

; Explosion 1
        DB      $00,$00           ; . . . . . . . . 
        DB      $0E,$00           ; . . 3 2 . . . . 
        DB      $1F,$70           ; . 1 3 3 1 3 . . 
        DB      $3F,$C0           ; . 3 3 3 3 . . . 
        DB      $0F,$D0           ; . . 3 3 3 1 . . 
        DB      $2F,$F0           ; . 2 3 3 3 3 . . 
        DB      $0D,$0C           ; . . 3 1 . . 3 . 
        DB      $00,$00           ; . . . . . . . . 

; Explosion 2
        DB      $C8,$0C           ; 3 . 2 . . . 3 . 
        DB      $2E,$20           ; . 2 3 2 . 2 . . 
        DB      $11,$8E           ; . 1 . 1 2 . 3 2 
        DB      $BF,$F8           ; 2 3 3 3 3 3 2 . 
        DB      $0F,$D0           ; . . 3 3 3 1 . . 
        DB      $B7,$F8           ; 2 3 1 3 3 3 2 . 
        DB      $2D,$8C           ; . 2 3 1 2 . 3 . 
        DB      $20,$C2           ; . 2 . . 3 . . 2 

;  Explosion 3
        DB      $48,$04           ; 1 . 2 . . . 1 . 
        DB      $36,$20           ; . 3 1 2 . 2 . . 
        DB      $11,$8E           ; . 1 . 1 2 . 3 2 
        DB      $B3,$C4           ; 2 3 . 3 3 . 1 . 
        DB      $07,$30           ; . . 1 3 . 3 . . 
        DB      $73,$D8           ; 1 3 . 3 3 1 2 . 
        DB      $2C,$8C           ; . 2 3 . 2 . 3 . 
        DB      $10,$C2           ; . 1 . . 3 . . 2  


        DB      $C4
        DB      $0C
        DB      $22
        DB      $10
        DB      $00
        DB      $C1
        DB      $42
        DB      $30
        DB      $0C
        DB      $42
        DB      $83
        DB      $04
        DB      $04
        DB      $08
        DB      $30
        DB      $43
        DB      $03
        DB      $10
        DB      $10
        DB      $04
        DB      $F9
        DB      $FF
        DB      $A0
        DB      $10
        DB      $08
        DB      $01
        DB      $02
        DB      $02
        DB      $13
        DB      $29
        DB      $12
        DB      $34
        DB      $11
        DB      $3E
        DB      $14
        DB      $81
        DB      $16
        DB      $DD
        DB      $15
        DB      $0E
        DB      $01
        DB      $B4
        DB      $09
        DB      $00
        DB      $10
        DB      $20
        DB      $15
        DB      $1B
        DB      $16
        DB      $AA
        DB      $00
        DB      $03
        DB      $04
        DB      $F9
        DB      $FF
        DB      $20
        DB      $04
        DB      $FE
        DB      $23
        DB      $02
        DB      $01
        DB      $05
        DB      $F9
        DB      $FF
        DB      $02
        DB      $13
        DB      $13
        DB      $12
        DB      $0D
        DB      $11
        DB      $0B
        DB      $02
        DB      $22
        DB      $3A
        DB      $04
        DB      $F9
        DB      $FF
        DB      $20
        DB      $02
        DB      $FE
        DB      $23
        DB      $01
        DB      $01
        DB      $05
        DB      $F9
        DB      $FF
        DB      $03
        DB      $13
        DB      $0A
        DB      $12
        DB      $08
        DB      $11
        DB      $06
        DB      $02
        DB      $22
        DB      $3A
        DB      $13
        DB      $2C
        DB      $12
        DB      $14
        DB      $11
        DB      $0F
        DB      $10
        DB      $10
        DB      $05
        DB      $F9
        DB      $FF
        DB      $02
        DB      $04
        DB      $F9
        DB      $FF
        DB      $A0
        DB      $10
        DB      $04
        DB      $21
        DB      $01
        DB      $01
        DB      $17
        DB      $10
        DB      $04
        DB      $EB
        DB      $FF
        DB      $70
        DB      $10
        DB      $04
        DB      $03
        DB      $01
        DB      $01
        DB      $05
        DB      $EB
        DB      $FF
        DB      $01
        DB      $16
        DB      $88
        DB      $15
        DB      $18
        DB      $00
        DB      $03
        DB      $10
        DB      $18
        DB      $04
        DB      $F9
        DB      $FF
        DB      $18
        DB      $02
        DB      $FE
        DB      $21
        DB      $01
        DB      $01
        DB      $13
        DB      $27
        DB      $12
        DB      $46
        DB      $11
        DB      $7E
        DB      $05
        DB      $F9
        DB      $FF
        DB      $01
        DB      $16
        DB      $77
        DB      $15
        DB      $17
        DB      $17
        DB      $0A
        DB      $04
        DB      $EB
        DB      $FF
        DB      $0A
        DB      $02
        DB      $FE
        DB      $03
        DB      $01
        DB      $01
        DB      $05
        DB      $EB
        DB      $FF
        DB      $01
        DB      $00
        DB      $04
        DB      $F9
        DB      $FF
        DB      $80
        DB      $02
        DB      $02
        DB      $23
        DB      $01
        DB      $01
        DB      $05
        DB      $F9
        DB      $FF
        DB      $01
        DB      $00
        DB      $03
        DB      $10
        DB      $06
        DB      $04
        DB      $F9
        DB      $FF
        DB      $72
        DB      $06
        DB      $05
        DB      $21
        DB      $01
        DB      $01
        DB      $17
        DB      $22
        DB      $04
        DB      $EB
        DB      $FF
        DB      $64
        DB      $05
        DB      $03
        DB      $21
        DB      $01
        DB      $01
        DB      $05
        DB      $EB
        DB      $FF
        DB      $04
        DB      $13
        DB      $11
        DB      $12
        DB      $17
        DB      $11
        DB      $1F
        DB      $16
        DB      $9A
        DB      $15
        DB      $1A
        DB      $00
        DB      $05
        DB      $F9
        DB      $FF
        DB      $01
        DB      $06
        DB      $F9
        DB      $FF
        DB      $01
        DB      $00
        DB      $03
        DB      $01
        DB      $02
        DB      $13
        DB      $2A
        DB      $12
        DB      $18
        DB      $11
        DB      $06
        DB      $10
        DB      $30
        DB      $04
        DB      $F9
        DB      $FF
        DB      $30
        DB      $20
        DB      $FC
        DB      $01
        DB      $01
        DB      $01
        DB      $17
        DB      $00
        DB      $04
        DB      $EB
        DB      $FF
        DB      $20
        DB      $00
        DB      $02
        DB      $21
        DB      $04
        DB      $04
        DB      $05
        DB      $EB
        DB      $FF
        DB      $06
        DB      $16
        DB      $FF
        DB      $15
        DB      $1F
        DB      $00
        DB      $03
        DB      $10
        DB      $20
        DB      $13
        DB      $13
        DB      $12
        DB      $12
        DB      $11
        DB      $10
        DB      $17
        DB      $10
        DB      $16
        DB      $67
        DB      $15
        DB      $17
        DB      $04
        DB      $F9
        DB      $FF
        DB      $18
        DB      $20
        DB      $F8
        DB      $01
        DB      $02
        DB      $02
        DB      $01
        DB      $28
        DB      $03
        DB      $10
        DB      $28
        DB      $17
        DB      $84
        DB      $04
        DB      $EB
        DB      $FF
        DB      $84
        DB      $0A
        DB      $FF
        DB      $03
        DB      $01
        DB      $01
        DB      $16
        DB      $CC
        DB      $15
        DB      $0C
        DB      $14
        DB      $83
        DB      $13
        DB      $22
        DB      $12
        DB      $1D
        DB      $11
        DB      $10
        DB      $04
        DB      $F2
        DB      $FF
        DB      $8C
        DB      $83
        DB      $01
        DB      $23
        DB      $08
        DB      $08
        DB      $05
        DB      $F2
        DB      $FF
        DB      $01
        DB      $00
        DB      $15
        DB      $1C
        DB      $01
        DB      $20
        DB      $03
        DB      $10
        DB      $20
        DB      $04
        DB      $F9
        DB      $FF
        DB      $20
        DB      $0C
        DB      $FF
        DB      $03
        DB      $01
        DB      $01
        DB      $16
        DB      $55
        DB      $15
        DB      $06
        DB      $13
        DB      $54
        DB      $12
        DB      $6A
        DB      $11
        DB      $FD
        DB      $01
        DB      $14
        DB      $03
        DB      $10
        DB      $30
        DB      $14
        DB      $81
        DB      $16
        DB      $FC
        DB      $15
        DB      $0E
        DB      $13
        DB      $2C
        DB      $12
        DB      $4F
        DB      $11
        DB      $37
        DB      $01
        DB      $68
        DB      $03
        DB      $10
        DB      $10
        DB      $14
        DB      $85
        DB      $16
        DB      $87
        DB      $15
        DB      $08
        DB      $13
        DB      $46
        DB      $12
        DB      $2C
        DB      $11
        DB      $FD
        DB      $04
        DB      $F9
        DB      $FF
        DB      $30
        DB      $10
        DB      $02
        DB      $21
        DB      $05
        DB      $05
        DB      $05
        DB      $F9
        DB      $FF
        DB      $04
        DB      $00
        DB      $03
        DB      $10
        DB      $30
        DB      $16
        DB      $FE
        DB      $15
        DB      $0F
        DB      $14
        DB      $81
        DB      $13
        DB      $3E
        DB      $12
        DB      $A8
        DB      $11
        DB      $6A
        DB      $01
        DB      $42
        DB      $13
        DB      $37
        DB      $12
        DB      $85
        DB      $11
        DB      $5E
        DB      $01
        DB      $16
        DB      $13
        DB      $35
        DB      $12
        DB      $7E
        DB      $11
        DB      $54
        DB      $01
        DB      $34
        DB      $13
        DB      $3E
        DB      $12
        DB      $A8
        DB      $11
        DB      $6A
        DB      $01
        DB      $34
        DB      $03
        DB      $10
        DB      $30
        DB      $16
        DB      $EF
        DB      $15
        DB      $0F
        DB      $14
        DB      $81
        DB      $13
        DB      $70
        DB      $12
        DB      $3E
        DB      $11
        DB      $A8
        DB      $01
        DB      $60
        DB      $13
        DB      $70
        DB      $12
        DB      $42
        DB      $11
        DB      $A8
        DB      $01
        DB      $58
        DB      $02
        DB      $9B
        DB      $3B
        DB      $10
        DB      $14
        DB      $14
        DB      $48
        DB      $04
        DB      $F9
        DB      $FF
        DB      $14
        DB      $08
        DB      $FF
        DB      $23
        DB      $02
        DB      $03
        DB      $15
        DB      $28
        DB      $17
        DB      $20
        DB      $04
        DB      $EB
        DB      $FF
        DB      $54
        DB      $20
        DB      $04
        DB      $03
        DB      $02
        DB      $03
        DB      $05
        DB      $F9
        DB      $FF
        DB      $01
        DB      $16
        DB      $88
        DB      $13
        DB      $FD
        DB      $12
        DB      $FE
        DB      $11
        DB      $FF
        DB      $00
        DB      $01
        DB      $06
        DB      $03
        DB      $13
        DB      $E0
        DB      $12
        DB      $C8
        DB      $11
        DB      $B6
        DB      $10
        DB      $14
        DB      $14
        DB      $48
        DB      $16
        DB      $88
        DB      $15
        DB      $28
        DB      $17
        DB      $20
        DB      $01
        DB      $20
        DB      $02
        DB      $DF
        DB      $3B
        DB      $04
        DB      $EB
        DB      $FF
        DB      $80
        DB      $00
        DB      $FE
        DB      $01
        DB      $01
        DB      $01
        DB      $17
        DB      $80
        DB      $10
        DB      $40
        DB      $13
        DB      $68
        DB      $12
        DB      $44
        DB      $11
        DB      $21
        DB      $15
        DB      $1F
        DB      $16
        DB      $EE
        DB      $01
        DB      $40
        DB      $15
        DB      $2F
        DB      $05
        DB      $F9
        DB      $FF
        DB      $02
        DB      $04
        DB      $F9
        DB      $FF
        DB      $80
        DB      $02
        DB      $FF
        DB      $21
        DB      $01
        DB      $01
        DB      $14
        DB      $80
        DB      $04
        DB      $F2
        DB      $FF
        DB      $BF
        DB      $80
        DB      $01
        DB      $01
        DB      $02
        DB      $02
        DB      $00
        DB      $03
        DB      $10
        DB      $14
        DB      $14
        DB      $88
        DB      $13
        DB      $37
        DB      $12
        DB      $85
        DB      $11
        DB      $8D
        DB      $17
        DB      $00
        DB      $16
        DB      $AA
        DB      $15
        DB      $2A
        DB      $01
        DB      $28
        DB      $09
        DB      $14
        DB      $00
        DB      $04
        DB      $F9
        DB      $FF
        DB      $5C
        DB      $14
        DB      $06
        DB      $01
        DB      $04
        DB      $04
        DB      $17
        DB      $28
        DB      $00
        DB      $13
        DB      $A8
        DB      $12
        DB      $1A
        DB      $11
        DB      $7E
        DB      $16
        DB      $DD
        DB      $15
        DB      $2D
        DB      $10
        DB      $1E
        DB      $17
        DB      $18
        DB      $14
        DB      $01
        DB      $05
        DB      $F2
        DB      $FF
        DB      $05
        DB      $04
        DB      $F2
        DB      $FF
        DB      $1C
        DB      $01
        DB      $03
        DB      $23
        DB      $02
        DB      $02
        DB      $00
        DB      $05
        DB      $F2
        DB      $FF
        DB      $01
        DB      $14
        DB      $1C
        DB      $04
        DB      $F2
        DB      $FF
        DB      $1C
        DB      $01
        DB      $FD
        DB      $23
        DB      $07
        DB      $07
        DB      $00
        DB      $03

L3CA3:  PUSH    IY
        POP     HL
        LD      B,A
        ADD     HL,DE
        DEC     (HL)
        JP      NZ,L3D2E
        INC     HL
        LD      A,(HL)
        DEC     HL
        LD      (HL),A
        INC     HL
        INC     HL
        BIT     0,(HL)
        RET     Z

        LD      C,(HL)
        INC     HL
        BIT     2,C
        JR      NZ,L3D1C
        BIT     3,C
        JR      Z,L3CF8
        INC     HL
        INC     HL
        INC     HL
        XOR     A
        CP      (HL)
        JR      Z,L3CDF
        DEC     (HL)
        JR      NZ,L3CDF
        RES     0,C
        LD      DE,$0006
        OR      A
        SBC     HL,DE
        LD      (HL),$00
        BIT     5,C
        JR      Z,L3CDB
        LD      (IY+$0D),$01
L3CDB:  INC     HL
        INC     HL
        LD      (HL),C
        RET     


L3CDF:  DEC     HL
        DEC     HL
        DEC     HL
        RES     3,C
        BIT     1,C
        JR      NZ,L3CED
        XOR     A
        SUB     (HL)
        LD      (HL),A
        JR      L3CF8
L3CED:  DEC     HL
        LD      (HL),C
        BIT     4,C
        INC     HL
        INC     HL
        JR      Z,L3CF6
        INC     HL
L3CF6:  LD      B,(HL)
        RET     


L3CF8:  LD      A,B
        ADD     A,(HL)
        LD      B,A
        INC     HL
        CP      (HL)
        JR      NC,L3D05
        SET     4,C
        SET     3,C
        JR      L3D16
L3D05:  JR      NZ,L3D0D
        SET     4,C
        SET     3,C
        JR      L3D16
L3D0D:  INC     HL
        CP      (HL)
        JR      C,L3D15
        RES     4,C
        SET     3,C
L3D15:  DEC     HL
L3D16:  DEC     HL
        DEC     HL
        LD      (HL),C
        RET


        DB      $18
        DB      $0F


L3D1C:  INC     HL
        PUSH    HL
        LD      A,(HL)
        INC     HL
        SUB     (HL)
        NEG     
        LD      E,A
        LD      D,$00
        LD      A,R
        POP     HL
        ADD     A,(HL)
        LD      B,A
        JP      L3D31
L3D2E:  INC     HL
        INC     HL
        LD      C,(HL)
L3D31:  RET     


;  Following the code...
;    1)  $4F59 = $3A06  ($3A06 holds $0310)
;    2)  $4F5B = $00
;    3)  COL3L = $63 (Red)
L3D32:  EXX     
        LD      HL,$3A06
        LD      ($4F59),HL      
        LD      HL,$4F5B
        LD      (HL),$00         
L3D3E:  LD      A,$63           ; $63 is the color red
        OUT     (COL3L),A       ; COLor 3 Left = $63 (Color Red)
        LD      A,$F5           ; F5 is the color Light Blue
        OUT     (COL1L),A       ; COLor 1 Left = $F5 (Light Blue) 
        LD      HL,$4F42
        SET     7,(HL)          ; Set Most Significant Bit of $4F42
        INC     HL              ; Set HL to $4F43
        XOR     A               ; Change A to $00
        LD      (HL),A          ; $4F43 = 0
        OUT     (COL0L),A       ; write COLor 0 Left = $00 (Black)
        INC     A               ; A = $01
        LD      HL,$4F66        ;
        LD      (HL),A          ; $4F66 = $01
        LD      HL,($4F59)      ; HL = $3A06
        PUSH    HL              ; Put $3A06 on stack
        LD      HL,$4F44        
        LD      BC,$0021
        LD      (HL),$00        ; $4F44 = $00
        LD      E,L             ; E = $44
        LD      D,H             ; D = $4F
        INC     DE              ; DE = $4F45
        LDIR                        
        LD      HL,$4F59
        LD      BC,$0818
        OTIR    
        POP     HL
        LD      ($4F59),HL
        EXX     
        RET     


L3D74:  EXX     
        JR      L3D3E
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        EX      DE,HL
        XOR     A
        RET     


L3D7D:  LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$10
        LD      HL,$000A
        JR      L3D8F
        LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$17
        LD      HL,$0003
L3D8F:  LD      DE,$4F59
        OUT     (C),A
        ADD     HL,DE
        LD      (HL),A
        EXX     
        XOR     A
        RET     


L3D99:  LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$16
        LD      HL,$0004
        JR      L3D8F
        LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$15
        LD      HL,$0005
        JR      L3D8F
        LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$14
        LD      HL,$0006
        JR      L3D8F
        LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$11
        LD      HL,$0009
        JR      L3D8F
        LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$12
        LD      HL,$0008
        JR      L3D8F
        LD      A,(HL)
        INC     HL
        EXX     
        LD      C,$13
        LD      HL,$0007
        JR      L3D8F
        LD      (IY+$02),$01
        RET     


L3DDA:  LD      (IY+$02),$00
        LD      A,($4F42)
        SET     7,A
        LD      ($4F42),A
        XOR     A
        RET     


L3DE8:  INC     A
        RET     


L3DEA:  LD      A,(HL)
        INC     HL
        LD      (IY+$0B),A
        INC     A
        RET     


L3DF1:  LD      E,(HL)
        INC     HL
        LD      D,(HL)
        INC     HL
        PUSH    HL
        PUSH    IY
        POP     HL
        ADD     HL,DE
        LD      DE,$0005
        ADD     HL,DE
        LD      A,$06
        POP     DE
L3E01:  EX      DE,HL
        LD      B,(HL)
        INC     HL
        EX      DE,HL
        LD      (HL),B
        DEC     HL
        DEC     A
        JR      NZ,L3E01
        EX      DE,HL
        RET     


L3E0C:  LD      E,(HL)
        INC     HL
        LD      D,(HL)
        INC     HL
        LD      A,(HL)
        INC     HL
        PUSH    HL
        PUSH    IY
        POP     HL
        ADD     HL,DE
        LD      DE,$0006
        ADD     HL,DE
        LD      (HL),A
        POP     HL
        XOR     A
        RET     

; Next byte loaded into HL
L3E1F:  DB      $E8
        DB      $3D
        DB      $EA
        DB      $3D
        DB      $77
        DB      $3D
        DB      $74
        DB      $3D
        DB      $F1
        DB      $3D
        DB      $0C
        DB      $3E
        DB      $E8
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $DA
        DB      $3D
        DB      $D5
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $E8
        DB      $3D
        DB      $7D
        DB      $3D
        DB      $B7
        DB      $3D
        DB      $C1
        DB      $3D
        DB      $CB
        DB      $3D
        DB      $AD
        DB      $3D
        DB      $A3
        DB      $3D
        DB      $99
        DB      $3D
        DB      $87
        DB      $3D
        
        
L3E4F:  LD      A,D
        CP      (IY+$02)
        JR      C,L3E63
        EXX     
        CALL    L3D3E
        LD      (IY+$0D),$01
        LD      (IY+$02),D
        LD      ($4F59),HL
L3E63:  LD      HL,$4F42
        RES     7,(HL)
        RET


L3E69:  LD      HL,$4F41
        LD      A,(HL)
        OR      A
        JR      Z,L3E9E
        LD      (HL),$00
        RRA     
        LD      D,$02
        LD      HL,$3B29
        JR      C,L3E4F
        RRA     
        LD      D,$01
        LD      HL,$3A07
        JR      C,L3E4F
        LD      D,$00
        RRA     
        LD      HL,$3A80
        JR      C,L3E4F
        RRA     
        LD      HL,$3A40
        JR      C,L3E4F
        RRA     
        LD      HL,$3A2A
        JR      C,L3E4F
        RRA     
        RRA     
        LD      HL,$3B55
        JR      C,L3E4F
        RRA     
L3E9E:  RET     


L3E9F:  LD      HL,$4F42
        LD      A,(HL)
        CP      $80
        JR      Z,L3ED4
        LD      (HL),$00
        RRA     
        LD      D,$01
        LD      HL,$3C1E
        JP      C,L3E4F
        RRA     
        LD      D,$00
        LD      HL,$3B0F
        JP      C,L3E4F
        RRA     
        RRA     
        LD      HL,$3A56
        JP      C,L3E4F
        RRA     
        LD      HL,$3BDF
        JP      C,L3E4F
        RRA     
        LD      D,$01
        LD      HL,$3C09
        JP      C,L3E4F
        RRA     
L3ED4:  RET


L3ED5:  LD      IY,$4F59
        LD      HL,$3F36
        PUSH    HL
        LD      HL,$4F40
        LD      A,(HL)       
        LD      (HL),$00
        OR      A
        JR      Z,L3F30
        LD      D,$00
        RRA     
        LD      HL,$3B9B
        JP      C,L3E4F
        RRA     
        LD      HL,$3B6D
        JP      C,L3E4F
        RRA     
        LD      HL,$3B7E
        JP      C,L3E4F
        LD      D,$02
        RRA     
        JR      NC,L3F0E
        LD      HL,$3AE7
        CALL    L3E4F
        LD      HL,$4F43
        LD      (HL),$01
        RET


L3F0E:  RRA     
        LD      HL,$3C53
        JP      C,L3E4F
        RRA     
        LD      D,$00
        LD      HL,$3AB8
        JP      C,L3E4F
        RRA     
        LD      D,$02
        LD      HL,$3C74
        JP      C,L3E4F
        RRA     
        LD      D,$03
        LD      HL,$3BC4
        JP      C,L3E4F


L3F30:  CALL    L3E69
        JP      L3E9F
        LD      A,($4F66)
        OR      A
        JR      Z,L3F5F
        LD      HL,($4F59)
L3F3F:  LD      A,(HL)
        INC     HL
        EXX     
        LD      HL,$3F55
        PUSH    HL
        LD      HL,$3E1F
        RLCA    
        LD      E,A
        LD      D,$00
        ADD     HL,DE
        LD      E,(HL)
        INC     HL
        LD      D,(HL)
        PUSH    DE
        EXX     
        XOR     A
        RET


; Next address loaded into HL
L3F55:  DB      $B7
        DB      $28
        DB      $E7
        DB      $22
        DB      $59
        DB      $4F
        DB      $FD
        DB      $36
        DB      $0D
        DB      $00


L3F5F:  XOR     A
        CP      (IY+$0D)
        JR      NZ,L3FB5
        CP      (IY+$0C)
        JR      NZ,L3FB5
        INC     (IY+$0C)
        CP      (IY+$0B)
        JR      Z,L3F7B
        DEC     (IY+$0B)
        JR      NZ,L3F7B
        LD      (IY+$0D),$01
L3F7B:  CP      (IY-$15)
        JR      Z,L3F8D
        LD      A,($4F5C)
        LD      DE,$FFEB
        CALL    L3CA3
        LD      (IY+$03),B
        XOR     A
L3F8D:  CP      (IY-$07)
        JR      Z,L3F9F
        LD      A,($4F63)
        LD      DE,$FFF9
        CALL    L3CA3
        LD      (IY+$0A),B
        XOR     A
L3F9F:  CP      (IY-$0E)
        JR      Z,L3FB1
        LD      A,($4F5F)
        LD      DE,$FFF2
        CALL    L3CA3
        LD      (IY+$06),B
        XOR     A
L3FB1:  XOR     A
        LD      ($4F65),A
L3FB5:  LD      BC,$0818
        LD      HL,$4F5C
        OTIR    
        XOR     A
        LD      HL,$4F43
        CP      (HL)
        JR      Z,L3FE0
        DEC     (HL)
        JR      NZ,L3FD9
        SYSTEM  RANGED          ;  UPI Ranged Random Number
        ;
        LD      B,A
        AND     $0F
        ADD     A,$04
        LD      (HL),A
        LD      A,B
        OR      $03
        BIT     7,A
        JR      NZ,L3FD7
        XOR     A
L3FD7:  OUT     (COL0L),A       ; write COLor 0 Left
L3FD9:  LD      A,(HL)
        AND     $07
        OUT     (COL3L),A       ; write COLor 3 Left
        OUT     (COL1L),A       ; write COLor 1 Left
L3FE0:  RET     

        DB      "(C)ASTROVISION",$00
        DB      "THE WIZARD",$00

        DB      $03
        DB      $12
        DB      $82
        DB      $FF
        DB      $FF

; End of "The Incredible Wizard"
