Plus/4 ROM-Listing
Suche
Index
FAQ
Kontakt
Zurück
;
;
;                           The Complete
;
;                          ROM dissasembly
;
;                                By 
;                            Mike Dailly 
;
;                 (c) Copyright 1998,1999,2000,2001
;                        All rights reserved 
;
;                          mike@dailly.org
;

;
; You will find MANY sections here unaccounted for,
; I would like some day to have a complete version, 
; just like the famous "The Complete Spectrum Rom Disassembly"
;
; Some information was obtained from Peter Gerrard's and Kevin Bergin's 
; book "The Complete COMMODORE 16 ROM Disassembly" available from
; Duckworth - ISBN 0 7156 2004 5
;

;
; Much of this will not compile due to the "extra" opcodes 
; that most assemblers will not recognise. where possible 
; I will include DB's or DW's
;

;
; Version
; -------
;  0.1					First public version. Small amount done just to show 
;						whats being done and how.
;
;
; Zero page variables
;

IOdirection         equ   $00         ; Chip IO directional register
IO                  equ   $01         ; Chip I/O, serial bus & tape control
					  ; Bit:	7 - Serial IN Bit
					  ;			6
					  ;			5
					  ;			4
					  ;			3
					  ;			2
					  ;			1 - Serial handshake (out)
					  ;			0 - Serial OUT line (HW inverted)

TokenSearch         equ   $02         ; Token value search
Renumber            equ   $03         ; renumber params ($03-$06)
EOLSearch           equ   $07         ; search char for end of line
QuoteScan           equ   $08         ; Scan quotes flag
TABsave             equ   $09         ; TAB column save
LoadVerify          equ   $0a         ; Load=0, Verify=1
InputBuffer         equ   $0b         ; Basic input buffer pointer/subscript no.
DIMflag             equ   $0c         ; Default DIM flag
VARflag             equ   $0d         ; Variable flag, $ff=string, $00=numeric.
NumericFlag         equ   $0e         ; Numeric flag: $80=integer, $00=float
FlagMisc            equ   $0f         ; Flag; DATA scan, LIST quote, memory.
flagFNx             equ   $10         ; Flag; Subscript - FNx                
flagInput			equ	  $11		  ; Flag; 0=Input; 152=Read; 64=Get
flagATN				equ	  $12		  ; Flag; ATN sign - comparison evaluation
flagPrompt			equ	  $13		  ; Flag; Current I/O prompt(1=prompt off)

BasicInt16			equ	  $14		  ; Basic stores integers here
BasicIntLo			equ	  $14		  ; LOW
BasicIntHi			equ	  $15		  ; HI

StringSP			equ   $16		  ; Temporary string stack
StringVector		equ	  $17		  ; Last temporary string vector
StringVectorLO		equ	  $17
StringVectorHI		equ   $18
StringStack			equ   $19		  ; Stack for temporary string vector

UtilArea			equ	  $22		  ; $22-$25 temp pointer area
Address             equ   $24         ; General Zero Page address usage.
AddressLo           equ   $24         
AddressHi           equ   $25         

LastBasicLineNo     equ   $3b         ; Previous BASIC line number
StackTop            equ   $7c         ; Top of run-time stack
Running             equ   $81         ; running a basic program? $80=yes
CurrLogFileNo		equ	  $ac		  ; Current logical file number
CurrSecAdd			equ   $ad		  ; Current Secondary address
CurrDev				equ	  $ae		  ; Current device number
CurrentROMBank      equ   $fb         ; this holds the current ROM selector

CrunchBasicTokenVec equ   $0304       ; Crunch BASIC Tokens link
CrunchVec           equ   $030C       ; Crunch HOOK vector
CHRGET				equ	  $0473		  ; get byte from basic ( incs LastBasicLineNo first )
CHRGOT				equ   $0479		  ; gets current byte from basic (doesn't inc LastBasicLineNo )
USRJump             equ   $500        ; USR program jump



        ORG   $8000

;
; $8000 - COLD start
;
L8000   JMP   L8019             

;
; $8000 - WARM start
;
L8003   JMP   L800A             

        db    $00   
        db    $43,$42,$4D             ; "cbm" ROM validation code

        JSR   LFFCC                   ; restore IO vector
        JSR   L8ADB                   ; half way through "CLR"
        STA   $13                     ; store current I/O prompt..
        JSR   LC7C9
        CLI    
L8016   JMP   L867E                   ; Error routine...


L8019   JSR   L8117                   ; Initialize vectors
        JSR   L802E                   ; Initialize BASIC
        JSR   L80C2                   ; print power on message "COMMODORE BASIC V3.5 ???? BYTES FREE"
        JSR   LFCF4                   ; "phoenix" routine. page in roms and check them

        LDX   #$FB
        TXS    
        BNE   L8016                   ; jump to error routine...

        dw    FixedFloat              ; $9871
        dw    FloatFixed              ; $9471

;
; $802E - Initialize BASIC
;
L802E   LDA   #$4C                    ; "JMP" opcode
        STA   $54                     ; store in JUMP vector for functions
        STA   $0500                   ; and in USR program jump

        LDA   #$1C                    ; point USR program jump to
        LDY   #$99                    ; "Illegal Quantity error"
        STA   $0501
        STY   $0502

        LDX   #$03                    ; Copy 4 bytes over for 2 vectors
L8041   LDA   $802A,x                 ; First is Float-Fixed ($9871)
        STA   $02F2,x                 ; next is Fixed-Float  ($9471)
        DEX    
        BPL   L8041

        LDX   #$32                    ; Copy down CHARGET and CHRGOT 
L804C   LDA   $8122,x                 ; routines. These are used for 
        STA   $0472,x                 ; fetching data under the system
        DEX                           ; ROM
        BNE   L804C

        STX   $68                     ; store 0 in Accum #1; hi-order (overflow)
        STX   $13                     ; current I/O prompt flag (1=off)
        STX   $18                     ; Last temp string vector
        STX   $02EB                   ; TRACE off (on=255)
        STX   $1000                   ; Start of BASIC RAM (lowres)
        TXA                           ; lda #$00

        LDX   #$03                    
L8064   STA   $72,x                   ; clear cassette buffer length
        STA   $02E5,x                 ; clear some graphics work area.
        DEX    
        BNE   L8064

        NOP                           ; how quaint...

        STX   $0503                   ; store 0 in... RND seed value (lowest)
        INX                           ; store 1 in....
        STX   $01FD                   ; work area..
        STX   $01FC
        LDX   $053B                   ; get character colour attribute.
        STX   $86                     ; and store in foreground colour.
        LDX   #$36                    
        STX   $85                     ; set Multicolour colour one to $36
        LDX   #$19
        STX   $16                     ; set temp string stack.
        LDX   #$01
        LDY   #$10
        STX   $2B                     ; set start of basic.
        STY   $2C
        LDX   #$05
        STX   $22                     ; util pointer area.
        LDA   #$D0
        STA   $02E4                   ; graphics work area.

        LDX   #$02
L8097   LDA   $0532,x                 ; copy start of memory pointer to
        STA   $36,x                   ; end of string storage
        STA   $32,x                   ; and end of arrays.
        DEX    
        BNE   L8097

		;
		; This copies the "GetUnderROM" section into a few places after CHRGET/CHRGOT.
		;
L80A1   LDY   #$00
L80A3   LDA   $8147,y                 ; copy get byte down into RAM
        STA   $04A5,x                 ; pages ROM out, gets byte from
        INX                           ; ($??),y restores ROM and returns.
        INY                           ; IRQ's are also disabled/enabled
        CPY   #$0B
        BCC   L80A3

        LDY   $22                     ; Starts at 5 and works down...
        LDA   $80BC,y                 ; $3b,$22,$24,$6f,$5f,$64
        STA   $049F,x
        DEC   $22
        BPL   L80A1
        RTS    

L08BC   db    $64,$5f,$6f,$24,$22,$3b

        ;
        ; Print power on message
        ;
L80C2   LDA   $2B                     
        LDY   $2C
        JSR   L8923
        JSR   PrintMessage

        ;
        ; Power on message
        ;
L80CD   db    $93,$0d,$20,$43,$4f,$4d,$4d,$4f     ; COMMODOR
        db    $44,$4f,$52,$45,$20,$42,$41,$53     ; E BASIC 
        db    $49,$43,$20,$56,$33,$2e,$35,$20     ; V3.5
        db    $00

L80E5   LDA   $37                     ; print "60671 bytes free"
        SEC                           ; (on a plus/4)
        SBC   $2B
        TAX    
        LDA   $38
        SBC   $2C
        JSR   LA45F
        JSR   PrintMessage

        db    $20,$42,$59,$54,$45,$53,$20,$46     ;  BYTES F
        db    $52,$45,$45,$0d,$00                 ; REE..
        
        jmp   $8a7b                               ; perform "NEW"

        ; Vectors for $300

        dw    $8686						; Error message link
        dw    $8712						; Warm start link
        dw    $8956						; Crunch Basic Tokens link
        dw    $8b6e						; Char. list link
        dw    $8bd6						; Char. dispatch
        dw    $9417						; Token evaluation
        dw    $896a						; Crunch hook vector
        dw    $8b88						; List hook vector
        dw    $8c8b						; Execute hook vector


        ;
        ; Init jump vectors from $300 to $311
        ;
InitVectors:
        LDX   #$11                    ; Copy vectors down from
L8119   LDA   $8105,x                 ; ROM into RAM at $300
        STA   $0300,x
        DEX    
        BPL   L8119
        RTS
    
        ;
        ; CHRGET/CHRGOT - This chunk of code is copied to RAM 
        ; and run from there. It is used to get data UNDER the 
        ; system ROM's for basic.
        ;
		; CHRGET ($0473)
L8123   INC   LastBasicLineNo         ; $3b			(goes to $0473 ) CHRGET
        BNE   L8129
        INC   LastBasicLineNo+1       ; $3c
		;
		; CHRGOT ($0479)
		;
L8129   SEI    
        STA   RAM_ON
        LDY   #$00
        LDA   (LastBasicLineNo),y     ; $3b
        STA   ROM_ON
        CLI    
        CMP   #$3A					  ; ":"		(colon)
        BCS   L8143					  ; if colon, exit
        CMP   #$20					  ; " "		(space)
        BEQ   L8123					  ; if space, get NEXT byte from basic
        SEC    
        SBC   #$30
        SEC    
        SBC   #$D0
L8143   RTS    

L0494   STA   $049C                   ; set location to get byte from.

		;
		; This section gets copied to $04A5
		;
GetUnderROM
        SEI                           ; IRQ's off
        STA   RAM_ON                  ; DISABLE ROM
        LDA   ($00),y                 ; get byte  ($00 is at location $49C)
        STA   ROM_ON                  ; enable ROM
        CLI                           ; IRQ's on again..
        RTS                           ; and return...
  
        db    $00,$00,$00

        ;
        ; Error message vectors
        ;
L8155   LDA   #$43
        BNE   L818B
L8159   LDA   #$4E
        BNE   L818B
L815D   LDA   #$14
        BNE   L818B
L8161   LDA   #$47
        BNE   L818B
L8165   LDA   #$4E
        BNE   L818B
L8169   LDA   #$5C
        BNE   L818B
L816D   LDA   #$5F
        BNE   L818B
L8171   LDA   #$3D
        BNE   L818B
L8175   LDA   #$57
        BNE   L818B
L8179   LDA   #$59
        BNE   L818B
L817D   LDA   #$62
        BNE   L818B
L8181   LDA   #$50
        BNE   L818B
L8185   LDA   #$6C
        BNE   L818B
L8189   LDA   #$5A
L818B   JMP   $0494

        ;
        ; Keywords. The end of each keyword has bit 7 set.
        ; So END is 'E','N','D'+$80
        ;
        ; DEFB    "EN",'D'+$80 
		;
        db   $45,$4E,$C4                          ; END
        db   $46,$4F,$D2                          ; FOR
        db   $4E,$45,$58,$D4                      ; NEXT
        db   $44,$41,$54,$C1                      ; DATA
        db   $49,$4E,$50,$55,$54,$A3              ; INPUT#
        db   $49,$4E,$50,$55,$D4                  ; INPUT
        db   $44,$49,$CD                          ; DIM
        db   $52,$45,$41,$C4                      ; READ
        db   $4C,$45,$D4						  ; LET
		db   $47,$4F,$54,$CF					  ; GOTO
		db	 $52,$55,$CE					      ; RUN
        db   $49,$C6							  ; IF
		db   $52,$45,$53,$54,$4F,$52,$C5          ; RESTORE
        db   $47,$4F,$53,$55,$C2                  ; GOSUB
        db   $52,$45,$54,$55,$52,$CE			  ; RETURN
		db   $52,$45,$CD						  ; REM
        db   $53,$54,$4F,$D0					  ; STOP
		db   $4F,$CE							  ; ON
		db   $57,$41,$49,$D4					  ; WAIT
        db   $4C,$4F,$41,$C4                      ; LOAD
        db   $53,$41,$56,$C5					  ; SAVE
		db   $56,$45,$52,$49,$46,$D9		      ; VERIFY
        db   $44,$45,$C6						  ; DEF
		db   $50,$4F,$4B,$C5					  ; POKE
        db   $50,$52,$49,$4E,$54,$A3			  ; PRINT#
		db	 $50,$52,$49,$4E,$D4				  ; PRINT
        db   $43,$4F,$4E,$D4					  ; CONT
        db   $4C,$49,$53,$D4					  ; LIST
		db	 $43,$4C,$D2						  ; CLR
        db   $43,$4D,$C4						  ; CMD
		db	 $53,$59,$D3						  ; SYS
		db	 $4F,$50,$45,$CE					  ;	OPEN
        db   $43,$4C,$4F,$53,$C5,$47,$45,$D4      ; CLOSEGET
        db   $4E,$45,$D7,$54,$41,$42,$A8,$54      ; NEWTAB(T
        db   $CF,$46,$CE,$53,$50,$43,$A8,$54      ; OFNSPC(T
        db   $48,$45,$CE,$4E,$4F,$D4,$53,$54      ; HENNOTST
        db   $45,$D0,$AB,$AD,$AA,$AF,$DE,$41      ; EP+-*/^A
        db   $4E,$C4,$4F,$D2,$BE,$BD,$BC,$53      ; NDOR?=<S
        db   $47,$CE,$49,$4E,$D4,$41,$42,$D3      ; GNINTABS
        db   $55,$53,$D2,$46,$52,$C5,$50,$4F      ; USRFREPO
        db   $D3,$53,$51,$D2,$52,$4E,$C4,$4C      ; SSQRRNDL
        db   $4F,$C7,$45,$58,$D0,$43,$4F,$D3      ; OGEXPCOS
        db   $53,$49,$CE,$54,$41,$CE,$41,$54      ; SINTANAT
        db   $CE,$50,$45,$45,$CB,$4C,$45,$CE      ; NPEEKLEN
        db   $53,$54,$52,$A4,$56,$41,$CC,$41      ; STR$VALA
        db   $53,$C3,$43,$48,$52,$A4,$4C,$45      ; SCCHR$LE
        db   $46,$54,$A4,$52,$49,$47,$48,$54      ; FT$RIGHT
        db   $A4,$4D,$49,$44,$A4,$47,$CF,$52      ; $MID$GOR
        db   $47,$D2,$52,$43,$4C,$D2,$52,$4C      ; GRRCLRRL
        db   $55,$CD,$4A,$4F,$D9,$52,$44,$4F      ; UMJOYRDO
        db   $D4,$44,$45,$C3,$48,$45,$58,$A4      ; TDECHEX$
        db   $45,$52,$52,$A4,$49,$4E,$53,$54      ; ERR$INST
        db   $D2,$45,$4C,$53,$C5,$52,$45,$53      ; RELSERES
        db   $55,$4D,$C5,$54,$52,$41,$D0,$54      ; UMETRAPT
        db   $52,$4F,$CE,$54,$52,$4F,$46,$C6      ; RONTROFF
        db   $53,$4F,$55,$4E,$C4,$56,$4F,$CC      ; SOUNDVOL
        db   $41,$55,$54,$CF,$50,$55,$44,$45      ; AUTOPUDE
        db   $C6,$47,$52,$41,$50,$48,$49,$C3      ; FGRAPHIC
        db   $50,$41,$49,$4E,$D4,$43,$48,$41      ; PAINTCHA
        db   $D2,$42,$4F,$D8,$43,$49,$52,$43      ; RBOXCIRC
        db   $4C,$C5,$47,$53,$48,$41,$50,$C5      ; LEGSHAPE
        db   $53,$53,$48,$41,$50,$C5,$44,$52      ; SSHAPEDR
        db   $41,$D7,$4C,$4F,$43,$41,$54,$C5      ; AWLOCATE
        db   $43,$4F,$4C,$4F,$D2,$53,$43,$4E      ; COLORSCN
        db   $43,$4C,$D2,$53,$43,$41,$4C,$C5      ; CLRSCALE
        db   $48,$45,$4C,$D0,$44,$CF,$4C,$4F      ; HELPDOLO
        db   $4F,$D0,$45,$58,$49,$D4,$44,$49      ; OPEXITDI
        db   $52,$45,$43,$54,$4F,$52,$D9,$44      ; RECTORYD
        db   $53,$41,$56,$C5,$44,$4C,$4F,$41      ; SAVEDLOA
        db   $C4,$48,$45,$41,$44,$45,$D2,$53      ; DHEADERS
        db   $43,$52,$41,$54,$43,$C8,$43,$4F      ; CRATCHCO
        db   $4C,$4C,$45,$43,$D4,$43,$4F,$50      ; LLECTCOP
        db   $D9,$52,$45,$4E,$41,$4D,$C5,$42      ; YRENAMEB
        db   $41,$43,$4B,$55,$D0,$44,$45,$4C      ; ACKUPDEL
        db   $45,$54,$C5,$52,$45,$4E,$55,$4D      ; ETERENUM
        db   $42,$45,$D2,$4B,$45,$D9,$4D,$4F      ; BERKEYMO
        db   $4E,$49,$54,$4F,$D2,$55,$53,$49      ; NITORUSI
        db   $4E,$C7,$55,$4E,$54,$49,$CC,$57      ; NGUNTILW
        db   $48,$49,$4C,$C5,$00                  ; HILE@

        ;
        ; Keyword Action vectors
        ;
        ; All these vectors are -1 from the actual 
        ; JUMP to address. these addresses are 
        ; PUSHED onto the stack and RTS'ed to.
        ;

L8383   dw    $8CD9, $ADC9, $9293, $8DAF
        dw    $90ED, $9107, $969A, $914E
        dw    $8E7B, $8D4C, $8BBB, $8DE0
        dw    $8C99, $8D2B, $8D82, $8E0A
        dw    $8CD7, $8E1A, $9E69, $A7F2
        dw    $A7DD, $A7EF, $9A9C, $9E11
        dw    $8FDF, $8FFF, $8D02, $8AFE
        dw    $8A97, $8FE5, $A7B4, $A84C
        dw    $A859, $90B7, $8A78, $8E0A
        dw    $B43F, $B42A, $B651, $B654
        dw    $B848, $B8BC, $B6CC, $B543
        dw    $C5C2, $B8D0, $B9D3, $BAE1
        dw    $C01D, $BD34, $BE28, $C4D8
        dw    $C50E, $C519, $C566, $C5B7
        dw    $B6E7, $B556, $B602, $B5AB
        dw    $C8BB, $C940, $C950, $C967
        dw    $C99B, $C9CB, $C9D9, $C9F3
        dw    $C9FF, $AE59, $AB8E, $B728
        dw    $FF51, $A2BE, $A358, $A2DD
        dw    $0500, $9A62, $9A7D, $A5E4
        dw    $A707, $A01E, $A660, $AA70
        dw    $AA77, $AAC0, $AB1A, $9DFA
        dw    $9D61, $9B66, $9D93, $9D70
        dw    $9CBB, $9CCF, $9D03, $9D15
        dw    $BF79, $BF85, $BF87, $BFC1
        dw    $BFFD, $9E1B, $B507, $B4BE
        dw    $9D79, $799E, $9E86, $7A7B
        dw    $7BA0, $A196, $ED7F, $50A5
        dw    $95FA, $F746, $7D95, $A626
        dw    $645A, $6494, $9627



        ;
        ; Error messages
        ;
        ; The end of each message has bit 7 set.
        ; db    "TOO MANY FILE FILE OPE",'N'+$80 
		;
L8471   db    $54,$4F,$4F,$20,$4D,$41,$4E,$59     ; TOO MANY FILE FILE OPEN
        db    $20,$46,$49,$4C,$45,$D3,$46,$49     ; 
        db    $4C,$45,$20,$4F,$50,$45,$CE

        db    $46,$49,$4C,$45,$20,$4E,$4F,$54     ; FILE NOT OPEN
        db    $20,$4F,$50,$45,$CE
		
		db    $46,$49,$4C,$45					  ; FILE
        db    $20,$4E,$4F,$54,$20,$46,$4F,$55     ;  NOT FOU
        db    $4E,$C4,$44,$45,$56,$49,$43,$45     ; N DEVICE
        db    $20,$4E,$4F,$54,$20,$50,$52,$45     ;  NOT PRE
        db    $53,$45,$4E,$D4,$4E,$4F,$54,$20     ; SEN NOT
        db    $49,$4E,$50,$55,$54,$20,$46,$49     ; INPUT FI
        db    $4C,$C5,$4E,$4F,$54,$20,$4F,$55     ; L NOT OU
        db    $54,$50,$55,$54,$20,$46,$49,$4C     ; TPUT FIL
        db    $C5,$4D,$49,$53,$53,$49,$4E,$47     ;  MISSING
        db    $20,$46,$49,$4C,$45,$20,$4E,$41     ;  FILE NA
        db    $4D,$C5,$49,$4C,$4C,$45,$47,$41     ; M ILLEGA
        db    $4C,$20,$44,$45,$56,$49,$43,$45     ; L DEVICE
        db    $20,$4E,$55,$4D,$42,$45,$D2,$4E     ;  NUMBE N
        db    $45,$58,$54,$20,$57,$49,$54,$48     ; EXT WITH
        db    $4F,$55,$54,$20,$46,$4F,$D2,$53     ; OUT FO S
        db    $59,$4E,$54,$41,$D8,$52,$45,$54     ; YNTA RET
        db    $55,$52,$4E,$20,$57,$49,$54,$48     ; URN WITH
        db    $4F,$55,$54,$20,$47,$4F,$53,$55     ; OUT GOSU
        db    $C2,$4F,$55,$54,$20,$4F,$46,$20     ;  OUT OF
        db    $44,$41,$54,$C1,$49,$4C,$4C,$45     ; DAT ILLE
        db    $47,$41,$4C,$20,$51,$55,$41,$4E     ; GAL QUAN
        db    $54,$49,$54,$D9,$4F,$56,$45,$52     ; TIT OVER
        db    $46,$4C,$4F,$D7,$4F,$55,$54,$20     ; FLO OUT
        db    $4F,$46,$20,$4D,$45,$4D,$4F,$52     ; OF MEMOR
        db    $D9,$55,$4E,$44,$45,$46,$27,$44     ;  UNDEF'D
        db    $20,$53,$54,$41,$54,$45,$4D,$45     ;  STATEME
        db    $4E,$D4,$42,$41,$44,$20,$53,$55     ; N BAD SU
        db    $42,$53,$43,$52,$49,$50,$D4,$52     ; BSCRIP R
        db    $45,$44,$49,$4D,$27,$44,$20,$41     ; EDIM'D A
        db    $52,$52,$41,$D9,$44,$49,$56,$49     ; RRA DIVI
        db    $53,$49,$4F,$4E,$20,$42,$59,$20     ; SION BY
        db    $5A,$45,$52,$CF,$49,$4C,$4C,$45     ; ZER ILLE
        db    $47,$41,$4C,$20,$44,$49,$52,$45     ; GAL DIRE
        db    $43,$D4,$54,$59,$50,$45,$20,$4D     ; C TYPE M
        db    $49,$53,$4D,$41,$54,$43,$C8,$53     ; ISMATC S
        db    $54,$52,$49,$4E,$47,$20,$54,$4F     ; TRING TO
        db    $4F,$20,$4C,$4F,$4E,$C7,$46,$49     ; O LON FI
        db    $4C,$45,$20,$44,$41,$54,$C1,$46     ; LE DAT F
        db    $4F,$52,$4D,$55,$4C,$41,$20,$54     ; ORMULA T
        db    $4F,$4F,$20,$43,$4F,$4D,$50,$4C     ; OO COMPL
        db    $45,$D8,$43,$41,$4E,$27,$54,$20     ; E CAN'T
        db    $43,$4F,$4E,$54,$49,$4E,$55,$C5     ; CONTINU
        db    $55,$4E,$44,$45,$46,$27,$44,$20     ; UNDEF'D
        db    $46,$55,$4E,$43,$54,$49,$4F,$CE     ; FUNCTIO
        db    $56,$45,$52,$49,$46,$D9,$4C,$4F     ; VERIF LO
        db    $41,$C4,$42,$52,$45,$41,$4B,$00     ; A BREAK@
        db    $A0,$43,$41,$4E,$27,$54,$20,$52     ;  CAN'T R
        db    $45,$53,$55,$4D,$C5,$4C,$4F,$4F     ; ESUM LOO
        db    $50,$20,$4E,$4F,$54,$20,$46,$4F     ; P NOT FO
        db    $55,$4E,$C4,$4C,$4F,$4F,$50,$20     ; UN LOOP
        db    $57,$49,$54,$48,$4F,$55,$54,$20     ; WITHOUT
        db    $44,$CF,$44,$49,$52,$45,$43,$54     ; D DIRECT
        db    $20,$4D,$4F,$44,$45,$20,$4F,$4E     ;  MODE ON
        db    $4C,$D9,$4E,$4F,$20,$47,$52,$41     ; L NO GRA
        db    $50,$48,$49,$43,$53,$20,$41,$52     ; PHICS AR
        db    $45,$C1,$42,$41,$44,$20,$44,$49     ; E BAD DI
        db    $53,$CB

 
        ; ********************************************
        ;
        ; Find start of error message #??
        ; Enter:    A           = Message number.
        ;
        ; Exit:     $24/$25     = Start address of message
        ;           Address
        ;
        ;           X           = -1
        ;           Y           = 0
        ;
        ; ********************************************

L8653   TAX                     ; store error message number in X
        LDY   #$00              ; We don't actually USE y, just 0 to access
        LDA   #$71              ; data. set START address of error message
        STA   AddressLo
        LDA   #$84
        STA   AddressHi

L865E   DEX                     ; -1 to start with....
        BMI   L867D             ; Found message?

L8661   LDA   (Address),y       ; Loop through message text
        PHA                     ; looking for an end of message marker
        INC   AddressLo         ; (BIT 7 being set). and inc message 
        BNE   L866A             ; start address ($24/$25) till we find it.
        INC   AddressHi
L866A   PLA                     ; now, check last character for end marker
        BPL   L8661             ; if <128 then NOT end of message...loop
        BMI   L865E             ; JUMP back to message counter...


L866F   JSR   PrintMessage      ; This is in fact called from below....


        db    $0d,$0a,$52,$45,$41,$44,$59,$2e     ; READY.
        db    $0d,$0a,$00

L867D   RTS                     ; FOUND message!


        ;
        ; No error... 
        ;
L867E   LDX   #$80              ; NO error.. just returns.
        db    $2c               ; make "BIT   $10A2" opcode instead of "LDX #$10"



        LDX   #$10              ; Error message 16 - 'out of memory'


        ; ********************************************
        ;
        ; Error routine. "X" holds error message number.
        ;
        ; ********************************************
L8683   JMP   ($0300)           ; Jump through Error message vector

        TXA                     ; get error number into
        BMI   L8703             ; >128? if so print message
        STX   $04EF             ; Store LAST error number (TRAP and error logs)

        BIT   Running           ; running a BASIC program? ($80=YES)   ($81)
        BPL   L86C5             ; if not, then immediate mode error.

        LDY   #$01
L8692   LDA   $0039,y           ; Store CURRENT basic line number
        STA   $04F0,y
        LDA   $025B,y           ; Store BASIC/DOS interface data.
        STA   $04F5,y
        DEY
        BPL   L8692             ; copy...

        CPX   #$11              ; error $11? 'undef'd statement'?
        BEQ   L86C5             ; if it is... then treat like  basic NOT running.

        LDY   $04F3             ; get line number HI?
        INY                     ; if $ff then no basic running.
        BEQ   L86C5
        DEY    
        STY   $15               ; store in INT high byte
        STY   $04F4
        LDY   $04F2             ; get line number LOW
        STY   $14               ; store in IN low byte for "error in line ????.."
        LDX   #$FF              ; flag as now NOT running
        STX   $04F3
        LDX   $04F7             ; get stack pointer for error trapping.
        TXS                     ; and SET...
        JSR   L8D69             ; perform GOTO
        JMP   L8BDC             ; perform RUN

L86C5   DEX    
        TXA    
        PHA    
        LDA   #$00
        STA   $83
        JSR   LC7C9
        PLA    
        JSR   L8653             ; Find the START address of error message
        JSR   LFFCC
        LDA   #$00
        STA   $13
        JSR   L903E
        JSR   L90B0
        LDY   #$00
L86E2   LDA   ($24),y
        PHA    
        AND   #$7F
        JSR   L90B2
        INY    
        PLA    
        BPL   L86E2
        JSR   L8AD8
        JSR   PrintMessage     ; LFF4F
        JSR   $5245
        HLT    
        LSE   $0052
L86FB   LDY   $3A
        INY    
        BEQ   L8703
        JSR   LA453
L8703   JSR   L866F            ; Print message

        ;
        ; Ready for Basic
        ;
        LDA   #$80
        JSR   LFF90
        LDA   #$00             ; set NOT running a basic program
        STA   Running
L870F   JMP   ($0302)
        LDX   #$FF
        STX   $3A
        JSR   L885A
        STX   LastBasicLineNo
        STY   LastBasicLineNo+1
        JSR   $0473
        TAX    
L8721   BEQ   L870F
        BCC   L872E
        JSR   L8953
        JSR   $0479
        JMP   L8BD9
L872E   JSR   L8E3E
        JSR   L8953
        STY   $0B
        JSR   L8A3D
        BCC   L8785
        LDY   #$01
        JSR   $04D1
        STA   $23
        LDA   $2D
        STA   $22
        LDA   $60
        STA   $25
        DEY    
        JSR   $04D1
        CLC    
        SBC   $5F
        EOR   #$FF
        CLC    
        ADC   $2D
        STA   $2D
        STA   $24
        LDA   $2E
        ADC   #$FF
        STA   $2E
        SBC   $60
        TAX    
        SEC    
        LDA   $5F
        SBC   $2D
        TAY    
        BCS   L876E
        INX    
        DEC   $25
L876E   CLC    
        ADC   $22
        BCC   L8776
        DEC   $23
        CLC    
L8776   JSR   $04B0
        STA   ($24),y
        INY    
        BNE   L8776
        INC   $23
        INC   $25
        DEX    
        BNE   L8776
L8785   JSR   L8A9A
        JSR   L8818
        LDY   #$00
        JSR   $04A5
        BEQ   L8721
        CLC    
        LDA   $2D
        LDY   $2E
        STA   $5A
        STY   $5B
        ADC   $0B
        BCC   L87A0
        INY    
L87A0   CLC    
        ADC   #$04
        BCC   L87A6
        INY    
L87A6   STA   $58
        STY   $59
        JSR   L88C0
        LDY   #$00
        LDA   #$01
        STA   ($5F),y
        INY    
        STA   ($5F),y
        INY    
        LDA   $14
        STA   ($5F),y
        LDA   $15
        INY    
        STA   ($5F),y
        INY    
        TYA    
        CLC    
        ADC   $5F
        STA   $5F
        BCC   L87CB
        INC   $60
L87CB   LDA   $31
        LDY   $32
        STA   $2D
        STY   $2E
        LDY   $0B
        DEY    
L87D6   JSR   $04A5
        STA   ($5F),y
        DEY    
        BPL   L87D6
        JSR   L8818
        JSR   L8A93
        LDA   $73
        ORA   $74
        BEQ   L8815
        LDA   $14
        CLC    
        ADC   $73
        STA   $63
        LDA   $15
        ADC   $74
        STA   $62
        LDX   #$90
        SEC    
        JSR   LA2CE
        JSR   LA46F
        LDX   #$00
L8802   LDA   $0101,x
        BEQ   L880D
        STA   $0527,x
        INX    
        BNE   L8802
L880D   LDA   #$1D
        STA   $0527,x
        INX    
        STX   $EF
L8815   JMP   L870F
L8818   LDA   $2B
        LDY   $2C
        STA   $22
        STY   $23
        CLC    
L8821   LDY   #$00
        JSR   $04B0
        BNE   L882E
        INY    
        JSR   $04B0
        BEQ   L8859
L882E   LDY   #$04
L8830   INY    
        JSR   $04B0
        BNE   L8830
        INY    
        TYA    
        ADC   $22
        TAX    
        LDY   #$00
        STA   ($22),y
        TYA    
        ADC   $23
        INY    
        STA   ($22),y
        STX   $22
        STA   $23
        BCC   L8821
L884B   CLC    
        LDA   $22
        LDY   $23
        ADC   #$02
        BCC   L8855
        INY    
L8855   STA   $2D
        STY   $2E
L8859   RTS    
L885A   LDX   #$00
L885C   JSR   LA791
        CMP   #$0D
        BEQ   L886E
        STA   $0200,x
        INX    
        CPX   #$59
        BCC   L885C
        JMP   LCC4C
L886E   JMP   L9031
L8871   JSR   LA760
L8874   LDA   $3D
        CMP   #$B0
        BNE   L8880
        LDA   $3E
        CMP   #$07
        BEQ   L88BD
L8880   LDY   #$00
        LDA   $02
        CMP   #$81
        BNE   L88A3
        CMP   ($3D),y
        BNE   L88BF
        LDY   #$02
        LDA   $4A
        CMP   #$FF
        BEQ   L88BF
        CMP   ($3D),y
        BNE   L889F
        DEY    
        LDA   $49
        CMP   ($3D),y
        BEQ   L88BF
L889F   LDX   #$12
        BNE   L88B1
L88A3   LDA   ($3D),y
        CMP   $02
        BEQ   L88BF
        LDX   #$12
        CMP   #$81
        BEQ   L88B1
        LDX   #$05
L88B1   TXA    
        CLC    
        ADC   $3D
        STA   $3D
        BCC   L8874
        INC   $3E
        BNE   L8874
L88BD   LDY   #$01
L88BF   RTS    
L88C0   JSR   L8923
        STA   $31
        STY   $32
        SEC    
        LDA   $5A
        SBC   $5F
        STA   $22
        TAY    
        LDA   $5B
        SBC   $60
        TAX    
        INX    
        TYA    
        BEQ   L88FD
        LDA   $5A
        SEC    
        SBC   $22
        STA   $5A
        BCS   L88E4
        DEC   $5B
        SEC    
L88E4   LDA   $58
        SBC   $22
        STA   $58
        BCS   L88F5
        DEC   $59
        BCC   L88F5
L88F0   JSR   L8189
        STA   ($58),y
L88F5   DEY    
        BNE   L88F0
        JSR   L8189
        STA   ($58),y
L88FD   DEC   $5B
        DEC   $59
        DEX    
        BNE   L88F5
        RTS    

        ;
        ; Check STACK depth
        ;
L8905   STY   $07F4
        SEC    
        LDA   StackTop
        SBC   $07F4
        STA   StackTop
        LDA   StackTop+1
        SBC   #$00
        STA   StackTop+1
        CMP   #$06
        BCC   L8950
        BNE   L8922
        LDA   StackTop
        CMP   #$EC
        BCC   L8950
L8922   RTS    

        ;
        ; Check memory space
        ;
L8923   CPY   $34
        BCC   L894F
        BNE   L892D
        CMP   $33
        BCC   L894F
L892D   PHA    
        LDX   #$09
        TYA    
L8931   PHA    
        LDA   $57,x
        DEX    
        BPL   L8931
        JSR   LA954
        LDX   #$F7
L893C   PLA    
        STA   $61,x
        INX    
        BMI   L893C
        PLA    
        TAY    
        PLA    
        CPY   $34
        BCC   L894F
        BNE   L8950
        CMP   $33
        BCS   L8950
L894F   RTS    
L8950   JMP   L8681

        ;
        ; Crunch tokens
        ;
L8953   JMP   (CrunchBasicTokenVec)   ; Jump through crunch token vector ($0304)
        LDA   LastBasicLineNo
        PHA    
        LDA   LastBasicLineNo+1
        PHA    
L895C   JSR   $0479
        JMP   L8965
L8962   JSR   $0473
L8965   BCC   L8962
        JMP   (CrunchVec)             ; Jump CRUNCH hook vector ($30c)

        BCC   L89D4
        CMP   #$00
        BEQ   L89C5
        CMP   #$3A
        BEQ   L8962
        CMP   #$3F
        BNE   L897C
        LDA   #$99
        BNE   L89AA
L897C   CMP   #$80
        BCC   L898B
        CMP   #$FF
        BEQ   L8962
        LDY   #$01
        JSR   L89EA
        BEQ   L895C
L898B   CMP   #$22
        BNE   L899C
L898F   JSR   $0473
        CMP   #$00
        BEQ   L89C5
        CMP   #$22
        BEQ   L8962
        BNE   L898F
L899C   JSR   L8A03
        BCC   L8962
        CPY   #$00
        BEQ   L89A8
        JSR   L89EA
L89A8   LDA   $0B
L89AA   LDY   #$00
        STA   (LastBasicLineNo),y
        CMP   #$8F
        BEQ   L89BF
        CMP   #$83
        BNE   L8962
        JSR   $0473
        JSR   L8DB0
        JMP   L895C
L89BF   JSR   $0473
        JSR   L8E0B
L89C5   LDX   LastBasicLineNo
        PLA    
        STA   LastBasicLineNo+1
        PLA    
        STA   LastBasicLineNo
        SEC    
        TXA    
        SBC   LastBasicLineNo
        TAY    
        INY    
        RTS    
L89D4   PHA    
        DEY    
        DEY    
        JSR   L89EA
        LDY   #$00
        LDA   #$FE
        STA   (LastBasicLineNo),y
        INY    
        PLA    
        STA   (LastBasicLineNo),y
        JSR   $0473
        JMP   L8962
L89EA   CLC    
        TYA    
        ADC   $3B
        STA   $22
        LDA   $3C
        ADC   #$00
        STA   $23
        LDY   #$00
L89F8   JSR   $04B0
        STA   ($3B),y
        INY    
        CMP   #$00
        BNE   L89F8
        RTS    
L8A03   LDA   #$81
        LDY   #$8E
        STA   $23
        STY   $22
        LDY   #$00
        STY   $0B
        DEY    
L8A10   INY    
L8A11   JSR   $04A5
        SEC    
        SBC   ($22),y
        BEQ   L8A10
        CMP   #$80
        BEQ   L8A38
L8A1D   LDA   ($22),y
        BMI   L8A24
        INY    
        BNE   L8A1D
L8A24   INY    
        INC   $0B
        CLC    
        TYA    
        ADC   $22
        STA   $22
        BCC   L8A31
        INC   $23
L8A31   CLC    
        LDY   #$00
        LDA   ($22),y
        BNE   L8A11
L8A38   ORA   $0B
        STA   $0B
        RTS    
L8A3D   LDA   $2B
        LDX   $2C
L8A41   LDY   #$01
        STA   $5F
        STX   $60
        JSR   $04D1
        BEQ   L8A77
        INY    
        INY    
        JSR   $04D1
        STA   $78
        LDA   $15
        CMP   $78
        BCC   L8A78
        BEQ   L8A5E
        DEY    
        BNE   L8A6C
L8A5E   DEY    
        JSR   $04D1
        STA   $78
        LDA   $14
        CMP   $78
        BCC   L8A78
        BEQ   L8A78
L8A6C   DEY    
        JSR   $04D1
        TAX    
        DEY    
        JSR   $04D1
        BCS   L8A41
L8A77   CLC    
L8A78   RTS    
        BNE   L8A78
        LDA   #$00
        TAY    
        STA   ($2B),y
        INY    
        STA   ($2B),y
        STA   $02EB
        LDA   $2B
        CLC    
        ADC   #$02
        STA   $2D
        LDA   $2C
        ADC   #$00
        STA   $2E
L8A93   JSR   L8AF1
        LDA   #$00

        ;
        ; Perform [CLR]
        ;
        BNE   L8AEC
L8A9A   JSR   LFFE7
        LDY   #$00
        STY   $79
        DEY    
        STY   $04F3
        STY   $04F0
        STY   $04F1
        STY   $04EF
        LDA   $37
        LDY   $38
        STA   $33
        STY   $34
        LDA   #$B0
        LDY   #$07
        STA   $7C
        STY   $7D
        LDA   $2D
        LDY   $2E
        STA   $2F
        STY   $30
        STA   $31
        STY   $32
        LDX   #$03
L8ACC   LDA   $8AED,x
        STA   $04E7,x
        DEX    
        BPL   L8ACC
L8AD5   JSR   L8CB1
L8AD8   LDX   #$19
        STX   $16
        PLA    
        TAY    
        PLA    
        LDX   #$FA
        TXS    
        PHA    
        TYA    
        PHA    
        LDA   #$00
        STA   $025C
        STA   $10
L8AEC   RTS    

        ;
        ; Back up text pointer
        ;
        JSR   $2E2C
        BIT   $18
        LDA   $2B
        ADC   #$FF
        STA   $3B
        LDA   $2C
        ADC   #$FF
        STA   $3C
        RTS    
        JSR   LAECA
L8B02   LDY   #$01
        JSR   $04D1
        BNE   L8B0F
        DEY    
        JSR   $04D1
        BEQ   L8B3D
L8B0F   JSR   L8CC0
        JSR   L903E
        LDY   #$02
        JSR   $04D1
        TAX    
        INY    
        JSR   $04D1
        CMP   $15
        BNE   L8B27
        CPX   $14
        BEQ   L8B29
L8B27   BCS   L8B3D
L8B29   JSR   L8B40
        LDY   #$00
        JSR   $04D1
        TAX    
        INY    
        JSR   $04D1
        STX   $5F
        STA   $60
        JMP   L8B02
L8B3D   JMP   L903E
L8B40   LDY   #$03
        STY   $49
        STY   $0F
        JSR   LA45F
        LDA   #$20
L8B4B   LDY   $49
        AND   #$7F
L8B4F   JSR   L90B2
        CMP   #$22
        BNE   L8B5C
        LDA   $0F
        EOR   #$FF
        STA   $0F
L8B5C   INY    
        BEQ   L8B3D
        BIT   $53
        BPL   L8B66
        JSR   LB70C
L8B66   JSR   $04D1
        BEQ   L8BBB
        JMP   ($0306)
        BPL   L8B4F
        CMP   #$FF
        BEQ   L8B4F
        BIT   $0F
        BMI   L8B4F
        CMP   #$FE
        BNE   L8B93
        INY    
        JSR   $04D1
        BEQ   L8B8E
        STY   $49
        SEC    
        JMP   ($030E)
        BCS   L8B4F
        LDY   #$00
        BEQ   L8BB2
L8B8E   DEY    
        LDA   #$FE
        BNE   L8B4F
L8B93   TAX    
        STY   $49
        LDY   #$81
        STY   $23
        LDY   #$8E
        STY   $22
        LDY   #$00
L8BA0   DEX    
        BPL   L8BB2
L8BA3   LDA   ($22),y
        PHA    
        INC   $22
        BNE   L8BAC
        INC   $23
L8BAC   PLA    
        BPL   L8BA3
        BMI   L8BA0
L8BB1   INY    
L8BB2   LDA   ($22),y
        BMI   L8B4B
        JSR   L90B2
        BNE   L8BB1
L8BBB   RTS    
        BNE   L8BC4
        JSR   L8D20
        JMP   L8A93
L8BC4   JSR   L8A9A
        JSR   $0479
        JSR   L8D4D
        JSR   L8D20
        JMP   L8BDC
L8BD3   JMP   ($0308)
        JSR   $0473
L8BD9   JSR   L8C25
L8BDC   JSR   L8CC0
        BIT   Running                 ; BASIC program running?
        BPL   L8BEA
        JSR   L8C1A
        TSX    
        STX   $04F7
L8BEA   LDY   #$00
        JSR   $04A5
        BEQ   L8BF4
        JMP   L8C93
L8BF4   BIT   Running                 ; BASIC program running?
        BPL   L8C17
        LDY   #$02
        JSR   $04A5
        BEQ   L8C17
        INY    
        JSR   $04A5
        STA   $39
        INY    
        JSR   $04A5
        STA   $3A
        TYA    
        CLC    
        ADC   $3B
        STA   $3B
        BCC   L8BD3
        INC   $3C
        BNE   L8BD3
L8C17   JMP   L867E
L8C1A   LDA   $3B
        LDY   $3C
        STA   $025B
        STY   $025C
L8C24   RTS    
L8C25   BEQ   L8C24
        BIT   $02EB
        BPL   L8C3F
        BIT   Running                 ; BASIC program running?
        BPL   L8C3F
        PHA    
        LDA   #$5B
        JSR   L90B2
        JSR   LA45B
        LDA   #$5D
        JSR   L90B2
        PLA    
L8C3F   CMP   #$FE
        BEQ   L8C82
        CMP   #$CB
        BEQ   L8C74
        CMP   #$CA
        BEQ   L8C6B
        CMP   #$FB
        BCS   L8C8D
        CMP   #$A3
        BCC   L8C59
        CMP   #$D5
        BCC   L8C8D
        SBC   #$32
L8C59   SEC    
        SBC   #$80
        BCC   L8C90
        ASL    
        TAY    
        LDA   $8384,y
        PHA    
        LDA   $8383,y
        PHA    
        JMP   $0473
L8C6B   LDA   #$B6
        PHA    
        LDA   #$5A
        PHA    
L8C71   JMP   $0473
L8C74   JSR   $0473
        CMP   #$A4
        BNE   L8C8D
        JSR   $0473
        JMP   L8D4D
        BRK    
L8C82   JSR   $0473
        BEQ   L8C8D
        SEC    
        JMP   ($0310)
        BCC   L8C71
L8C8D   JMP   L94A1
L8C90   JMP   L8E7C
L8C93   CMP   #$3A
        BNE   L8C8D
        JMP   L8BD3
        BEQ   L8CB1
        JSR   L9DE1
        STY   $14
        STA   $15
        JSR   L8A3D
        BCS   L8CAB
        JMP   L8D8F
L8CAB   LDA   $5F
        LDY   $60
        BCS   L8CB6
L8CB1   SEC    
        LDA   $2B
        LDY   $2C
L8CB6   SBC   #$01
        BCS   L8CBB
        DEY    
L8CBB   STA   $41
        STY   $42
L8CBF   RTS    

        ;
        ; Break
        ;
L8CC0   JSR   LFFE1
        BNE   L8CBF
        PHP    
        LDY   $04F3
        INY    
        BEQ   L8CD7
L8CCC   JSR   LFFE1
        BEQ   L8CCC
        PLP    
        LDX   #$1E
        JMP   L8683
L8CD7   PLP    
        
        ;
        ; Perform [STOP]
        ;
        BCS   L8CDB             

        ;
        ; Perform [END]
        ;
LEND    CLC                     
L8CDB   BNE   L8CBF
        BIT   Running                 ; BASIC program running?
        BPL   L8CEE
        JSR   L8C1A
        LDA   $39
        LDY   $3A
        STA   $0259
        STY   $025A
L8CEE   PLA    
        PLA    
        BCC   L8D00
        JSR   PrintMessage
        ORA   $420A
        HLT    
        EOR   $41
        ALR   #$00
        JMP   L86FB
L8D00   JMP   L867E
     
        ;
        ; Perform [CONT]
        ;
LCONT   BNE   L8CBF
        LDX   #$1A
        LDY   $025C
        BNE   L8D0F
        JMP   L8683
L8D0F   LDA   $025B
        STA   $3B
        STY   $3C
        LDA   $0259
        LDY   $025A
        STA   $39
        STY   $3A
L8D20   LDA   #$80                    ; Set now running program
        STA   Running                 
        ASL    
        STA   $73
        STA   $74
        JMP   LFF90

        ;
        ; Perform [GOSUB]
        ;
LGOSUB  LDY   #$05
        JSR   L8905
        DEY    
        LDA   $3C
        STA   (StackTop),y
        DEY    
        LDA   $3B
        STA   (StackTop),y
        DEY    
        LDA   $3A
        STA   (StackTop),y
        DEY    
        LDA   $39
        STA   (StackTop),y
        DEY    
        LDA   #$8D
        STA   (StackTop),y
        JSR   $0479

        ;
        ; Perform [GOTO]
        ;
LGOTO
L8D4D   JSR   L8E3E
        JSR   L8DC1
        SEC    
        LDA   $39
        SBC   $14
        LDA   $3A
        SBC   $15
        BCS   L8D69
        TYA    
        SEC    
        ADC   $3B
        LDX   $3C
        BCC   L8D6D
        INX    
        BCS   L8D6D
L8D69   LDA   $2B
        LDX   $2C
L8D6D   JSR   L8A41
        BCC   L8D8F
        LDA   $5F
        SBC   #$01
        STA   $3B
        LDA   $60
        SBC   #$00
        STA   $3C
        BIT   Running                 ; BASIC program running?
        BPL   L8D20
        RTS    

        ;
        ; Perform [RETURN]
        ;
LRETURN LDA   #$8D
        STA   $02
        JSR   L8871
        BEQ   L8D94
        LDX   #$0C
        BIT   $11A2
        JMP   L8683
L8D94   JSR   LA769
        LDY   #$05
        JSR   LA772
        DEY    
        LDA   ($3D),y
        STA   $3C
        DEY    
        LDA   ($3D),y
        STA   $3B
        DEY    
        LDA   ($3D),y
        JSR   LCD7F
        LDA   ($3D),y
        STA   $39

        ;
        ; Perform [DATA]
        ;
LDATA
L8DB0   JSR   L8DBE
L8DB3   TYA    
        CLC    
        ADC   $3B
        STA   $3B
        BCC   L8DBD
        INC   $3C
L8DBD   RTS    

        ;
        ; Scan for next statement
        ;
L8DBE   LDX   #$3A
        BIT   $00A2
        STX   $07
        LDY   #$00
        STY   $08
L8DC9   LDA   $08
        LDX   $07
        STA   $07
        STX   $08
L8DD1   JSR   $04A5
        BEQ   L8DBD
        CMP   $08
        BEQ   L8DBD
        INY    
        CMP   #$22
        BNE   L8DD1
        BEQ   L8DC9
        JSR   L932C
        JSR   $0479
        CMP   #$89
        BEQ   L8DF0
        LDA   #$A7
        JSR   L9493
L8DF0   LDA   $61
        BNE   L8E10
L8DF4   JSR   L8DB0
        LDY   #$00
        JSR   $04A5
        BEQ   L8E0B
        JSR   $0473
        CMP   #$D5
        BNE   L8DF4
        JSR   $0473
        JMP   L8E10
L8E0B   JSR   L8DC1
        BEQ   L8DB3
L8E10   JSR   $0479
        BCS   L8E18
        JMP   L8D4D
L8E18   JMP   L8C25
        JSR   L9D84
        PHA    
        CMP   #$8D
        BEQ   L8E2A
L8E23   CMP   #$89
        BEQ   L8E2A
        JMP   L94A1
L8E2A   DEC   $65
        BNE   L8E32
        PLA    
        JMP   L8C3F
L8E32   JSR   $0473
        JSR   L8E3E
        CMP   #$2C
        BEQ   L8E2A
        PLA    
L8E3D   RTS    
L8E3E   LDX   #$00
        STX   $08
        STX   $14
        STX   $15
L8E46   BCS   L8E3D
        INC   $08
        SBC   #$2F
        STA   $07
        LDA   $15
        STA   $22
        CMP   #$19
        BCS   L8E23
        LDA   $14
        ASL    
        ROL   $22
        ASL    
        ROL   $22
        ADC   $14
        STA   $14
        LDA   $22
        ADC   $15
        STA   $15
        ASL   $14
        ROL   $15
        LDA   $14
        ADC   $07
        STA   $14
        BCC   L8E76
        INC   $15
L8E76   JSR   $0473
        JMP   L8E46
L8E7C   JSR   L96A5
        STA   $49
        STY   $4A
        LDA   #$B2
        JSR   L9493
        LDA   $0E
        PHA    
        LDA   $0D
        PHA    
        JSR   L932C
        PLA    
        ROL    
        JSR   L931B
        BNE   L8EB0
        PLA    
L8E99   BPL   L8EAD
        JSR   LA2A0
        JSR   L9886
        LDY   #$00
        LDA   $64
        STA   ($49),y
        INY    
        LDA   $65
        STA   ($49),y
        RTS    
L8EAD   JMP   LA255
L8EB0   PLA    
L8EB1   LDY   $4A
        CPY   #$04
        BNE   L8F29
        JSR   L9C4E
        CMP   #$06
        BNE   L8EFC
        LDY   #$00
        STY   $61
        STY   $66
L8EC4   STY   $71
        JSR   L8EF4
        JSR   LA162
        INC   $71
        LDY   $71
        JSR   L8EF4
        JSR   LA291
        TAX    
        BEQ   L8EDE
        INX    
        TXA    
        JSR   LA16D
L8EDE   LDY   $71
        INY    
        CPY   #$06
        BNE   L8EC4
        JSR   LA162
        JSR   LA327
        LDX   $64
        LDY   $63
        LDA   $65
        JMP   LFFDB
L8EF4   JSR   $04B0
        JSR   $0485
        BCC   L8EFF
L8EFC   JMP   L991C             ; Illegal Quantity error
L8EFF   SBC   #$2F
        JMP   LA40A
L8F04   PLA    
        INY    
L8F06   CMP   $34
        BCC   L8F22
        BNE   L8F14
        DEY    
        JSR   $04DC
        CMP   $33
        BCC   L8F22
L8F14   LDY   $65
        CPY   $2E
        BCC   L8F22
        BNE   L8F40
        LDA   $64
        CMP   $2D
        BCS   L8F40
L8F22   LDA   $64
        LDY   $65
        JMP   L8F5E
L8F29   LDY   #$02
        JSR   $04DC
        CMP   $7B
        BNE   L8F06
        PHA    
        DEY    
        JSR   $04DC
        CMP   $7A
        BNE   L8F04
        LDA   $79
        BEQ   L8F04
        PLA    
L8F40   LDY   #$00
        JSR   $04DC
        JSR   L9B54
        LDA   $50
        LDY   $51
        STA   $6F
        STY   $70
        JSR   L9C1B
        LDA   $6F
        LDY   $70
        JSR   L9CAA
        LDA   #$61
        LDY   #$00
L8F5E   STA   $50
        STY   $51
        STA   $22
        STY   $23
        JSR   L9CAA
        JSR   L8F9C
        BCC   L8F79
        LDY   #$00
        LDA   $49
        STA   ($22),y
        INY    
        LDA   $4A
        STA   ($22),y
L8F79   LDA   $49
        STA   $22
        LDA   $4A
        STA   $23
        JSR   L8F9C
        BCC   L8F8F
        DEY    
        LDA   #$FF
        STA   ($22),y
        DEY    
        TXA    
        STA   ($22),y
L8F8F   LDY   #$02
L8F91   LDA   #$50
        JSR   $0494
        STA   ($49),y
        DEY    
        BPL   L8F91
        RTS    
L8F9C   LDY   #$00
        JSR   $04B0
        PHA    
        BEQ   L8FDD
        INY    
        JSR   $04B0
        TAX    
        INY    
        JSR   $04B0
        CMP   $38
        BCC   L8FB7
        BNE   L8FDD
        CPX   $37
        BCS   L8FDD
L8FB7   JSR   $04B0
        CMP   $34
        BCC   L8FDD
        BNE   L8FC4
        CPX   $33
        BCC   L8FDD
L8FC4   CMP   $7B
        BNE   L8FCC
        CPX   $7A
        BEQ   L8FDD
L8FCC   STX   $22
        STA   $23
        PLA    
        TAX    
        CLC    
        ADC   $22
        STA   $22
        BCC   L8FDB
        INC   $23
L8FDB   SEC    
        RTS    
L8FDD   PLA    
        CLC    
        RTS

        ; ********************************************
		;
		; perform "Print#" command
		;
        ; ********************************************

PerformPrintHash:
        JSR   L8FE6
        JMP   L90FE

        ; ********************************************
		;
		;	Perform "CMD" command
		;
        ; ********************************************
PerformCMD:
L8FE6   JSR   L9D84				; get BYTE paramater from basic stream 
        BEQ   L8FF0				; was CHRGOT answer a ":"? (or end of command)
        LDA   #$2C				; else Check for comma
        JSR   L9493				; if not found then "?SYNTAX ERROR"
L8FF0   PHP						; remember CHRGET answer
        STX   $13				; get current I/O prompt (1 = prompt off)
        JSR   LA797				; perform actual "CMD" via kernal
        PLP						; restore CHRGET returns...
        JMP   L9000				; Perform "PRINT" - prints to channel 

        ; ********************************************
		;
		;	Perform "PRINT" command
		;
        ; ********************************************
		
L8FFA   JSR   L908B				; Print from (y.a)
L8FFD   JSR   $0479				; call CHRGET/CHRGOT

PerformPrint:
L9000   BEQ   L903E
        CMP   #$FB
        BNE   L9009
        JMP   LAEF7
L9009   BEQ   L904E
        CMP   #$A3
        BEQ   L905F
        CMP   #$A6
        CLC    
        BEQ   L905F
        CMP   #$2C
        BEQ   L904F
        CMP   #$3B
        BEQ   L907A
        JSR   L932C
        BIT   $0D
        BMI   L8FFA
        JSR   LA46F
        JSR   L9B74
        JSR   L908B
        JSR   L90A6
        BNE   L8FFD
L9031   LDA   #$00
        STA   $0200,x
        LDX   #$FF
        LDY   #$01
        LDA   $13
        BNE   L904E
L903E   LDA   #$0D
        JSR   L90B2
        BIT   $13
        BPL   L904C
        LDA   #$0A
        JSR   L90B2
L904C   EOR   #$FF
L904E   RTS    
L904F   SEC    
        JSR   LFFF0
        TYA    
        SEC    
L9055   SBC   #$0A
        BCS   L9055
        EOR   #$FF
        ADC   #$01
        BNE   L9075
L905F   PHP    
        SEC    
        JSR   LFFF0
        STY   $09
        JSR   L9D81
        CMP   #$29
        BNE   L9080
        PLP    
        BCC   L9076
        TXA    
        SBC   $09
        BCC   L907A
L9075   TAX    
L9076   INX    
L9077   DEX    
        BNE   L9083
L907A   JSR   $0473
        JMP   L9009
L9080   JMP   L94A1
L9083   JSR   L90A6
        BNE   L9077
L9088   JSR   L9B74
L908B   JSR   L9C4E
        TAX    
        LDY   #$00
        INX    
L9092   DEX    
        BEQ   L904E
        JSR   $04B0
        JSR   L90B2
        INY    
        CMP   #$0D
        BNE   L9092
        JSR   L904C
        JMP   L9092
L90A6   LDA   $13
        BEQ   L90AD
L90AA   LDA   #$20
        BIT   $1DA9
        BIT   $3FA9
L90B2   JSR   LA78B
        AND   #$FF
        RTS    
        JSR   L9A86
        STA   $80
        CMP   #$23
        BEQ   L90CB
        CMP   #$F9
        BNE   L90DB
        JSR   $0473
        JMP   L90DB
L90CB   JSR   $0473
        JSR   L9D84
        LDA   #$2C
        JSR   L9493
        STX   $13
        JSR   LA7A6
L90DB   LDX   #$01
        LDY   #$02
        LDA   #$00
        STA   $0201
        LDA   #$40
        JSR   L9158
        LDX   $13
        BNE   L9100
        RTS    
        JSR   L9D84
        LDA   #$2C
        JSR   L9493
        STX   $13
        JSR   LA7A6
        JSR   L9117
L90FE   LDA   $13
L9100   JSR   LFFCC
        LDX   #$00
        STX   $13
        RTS    
        CMP   #$22
        BNE   L9117
        JSR   L944E
        LDA   #$3B
        JSR   L9493
        JSR   L908B
L9117   JSR   L9A86
        LDA   #$2C
        STA   $01FF
L911F   JSR   L9142
        LDA   $13
        BEQ   L9133
        JSR   LFFB7
        AND   #$02
        BEQ   L9133
        JSR   L90FE
        JMP   L8DB0
L9133   LDA   $0200
        BNE   L9156
        LDA   $13
        BNE   L911F
        JSR   L8DBE
        JMP   L8DB3
L9142   LDA   $13
        BNE   L914C
        JSR   L90B0
        JSR   L90AA
L914C   JMP   L885A
        LDX   $41
        LDY   $42
        LDA   #$98
        BIT   $00A9
L9158   STA   $11
        STX   $43
        STY   $44
L915E   JSR   L96A5
        STA   $49
        STY   $4A
        LDX   #$01
L9167   LDA   $3B,x
        STA   $4B,x
        LDA   $43,x
        STA   $3B,x
        DEX    
        BPL   L9167
        JSR   $0479
        BNE   L91A8
        BIT   $11
        BVC   L9195
        LDA   $80
        CMP   #$F9
        BNE   L9189
L9181   JSR   LA7AF
        TAX    
        BEQ   L9181
        BNE   L918C
L9189   JSR   LA7AF
L918C   STA   $0200
        LDX   #$FF
        LDY   #$01
        BNE   L91A4
L9195   BPL   L919A
        JMP   L9240
L919A   LDA   $13
        BNE   L91A1
        JSR   L90B0
L91A1   JSR   L9142
L91A4   STX   $3B
        STY   $3C
L91A8   JSR   $0473
        BIT   $0D
        BPL   L91E0
        BIT   $11
        BVC   L91BC
        INX    
        STX   $3B
        LDA   #$00
        STA   $07
        BEQ   L91C8
L91BC   STA   $07
        CMP   #$22
        BEQ   L91C9
        LDA   #$3A
        STA   $07
        LDA   #$2C
L91C8   CLC    
L91C9   STA   $08
        LDA   $3B
        LDY   $3C
        ADC   #$00
        BCC   L91D4
        INY    
L91D4   JSR   L9B7A
        JSR   L9DC6
        JSR   L8EB1
        JMP   L91E8
L91E0   JSR   LA37F
        LDA   $0E
        JSR   L8E99
L91E8   JSR   $0479
        BEQ   L9228
        CMP   #$2C
        BEQ   L9228
        LDA   $11
        BEQ   L91FF
        BMI   L91FB
        LDX   $13
        BNE   L9203
L91FB   LDX   #$16
        BNE   L9205
L91FF   LDA   $13
        BEQ   L9208
L9203   LDX   #$18
L9205   JMP   L8683
L9208   JSR   PrintMessage
        RLA   $4552,x
        SKB   $4F
        JSR   $5246
        LSE   $204D
        LSE   ($54),y
        EOR   ($52,x)
        SKB   $0D
        BRK    
        LDA   $025B
        LDY   $025C
        STA   $3B
        STY   $3C
        RTS    
L9228   LDX   #$01
L922A   LDA   $3B,x
        STA   $43,x
        LDA   $4B,x
        STA   $3B,x
        DEX    
        BPL   L922A
        JSR   $0479
        BEQ   L926A
        JSR   L9491
        JMP   L915E
L9240   JSR   L8DBE
        INY    
        TAX    
        BNE   L925C
        LDX   #$0D
        INY    
        JSR   $04A5
        BEQ   L92BB
        INY    
        JSR   $04A5
        STA   $3F
        INY    
        JSR   $04A5
        INY    
        STA   $40
L925C   JSR   L8DB3
        JSR   $0479
        TAX    
        CPX   #$83
        BNE   L9240
        JMP   L91A8
L926A   LDA   $43
        LDY   $44
        LDX   $11
        BPL   L9275
        JMP   L8CBB
L9275   LDY   #$00
        JSR   L8155
        BEQ   L9293
        LDA   $13
        BNE   L9293
        JSR   PrintMessage
        RLA   $5845,x
        SKB   $52
        EOR   ($20,x)
        EOR   #$47
        LSR   $524F
        EOR   $44
        ORA   $6000
        BNE   L92A9
        LDY   #$FF
        BNE   L92AE
L929A   LDY   #$12
        JSR   LA772
        JSR   $0479
        CMP   #$2C
        BNE   L9313
        JSR   $0473
L92A9   JSR   L96A5
        STA   $49
L92AE   STY   $4A
        LDY   #$81
        STY   $02
        JSR   L8871
        BEQ   L92BE
        LDX   #$0A
L92BB   JMP   L8683
L92BE   JSR   LA769
        LDA   $3D
        CLC    
        ADC   #$03
        LDY   $3E
        BCC   L92CB
        INY    
L92CB   JSR   LA21F
        LDY   #$08
        LDA   ($3D),y
        STA   $66
        LDY   #$01
        LDA   ($3D),y
        PHA    
        TAX    
        INY    
        LDA   ($3D),y
        PHA    
        TAY    
        TXA    
        JSR   L9E9B
        PLA    
        TAY    
        PLA    
        TAX    
        JSR   LA259
        LDA   $3D
        CLC    
        ADC   #$09
        LDY   $3E
        BCC   L92F4
        INY    
L92F4   JSR   LA2E0
        LDY   #$08
        SEC    
        SBC   ($3D),y
        BEQ   L929A
        LDY   #$11
        LDA   ($3D),y
        STA   $3B
        DEY    
        LDA   ($3D),y
        STA   $3C
        DEY    
        LDA   ($3D),y
        STA   $3A
        DEY    
        LDA   ($3D),y
        STA   $39
L9313   RTS    

		; *******************************************************
		;
		; Typechecking - numeric of string?
		;
		; *******************************************************
L9314   JSR   EvaluateExpression	; Evaluate expression(even if its a single number)
L9317   CLC							; force branch
        BCC   L931B
L931A   SEC    
L931B   BIT   VARflag				; check variable flag ($00 = numeric, $ff = string)		(VARflag = $0d)
        BMI   L9322					; if string then
        BCS   L9324					; display a type mismatch error on carry set

L9321   RTS    
L9322   BCS   L9321					

L9324   LDX   #$16					; display "?TYPE MISMATCH ERROR"
		db	  $2c					; makes "LDX #$19" into "BIT $19A2"
L9327   LDX   #$19					; displays "?FORMULA TOO COMPLEX ERROR"
        JMP   L8683


		; *******************************************************
		;
		; perform expresion evaluation on basic statement
		;
		; *******************************************************
EvaluateExpression
L932C   LDX   $3B
        BNE   L9332
        DEC   $3C
L9332   DEC   $3B
        LDX   #$00
        BIT   $48
        TXA    
        PHA    
        TSX    
        CPX   #$28
        BCC   L9327					; display "?FORMULA TOO COMPLEX ERROR"
        JSR   L9414
        LDA   #$00
        STA   $4D
L9346   JSR   $0479
L9349   SEC    
        SBC   #$B1
        BCC   L9365
        CMP   #$03
        BCS   L9365
        CMP   #$01
        ROL    
        EOR   #$01
        EOR   $4D
        CMP   $4D
        BCC   L93BE
        STA   $4D
        JSR   $0473
        JMP   L9349
L9365   LDX   $4D
        BNE   L9395
        BCS   L93E9
        ADC   #$07
        BCC   L93E9
        ADC   $0D
        BNE   L9376
        JMP   L9BDA
L9376   ADC   #$FF
        STA   $22
        ASL    
        ADC   $22
        TAY    
L937E   PLA    
        CMP   $8453,y
        BCS   L93EE
        JSR   L9317
L9387   PHA    
L9388   JSR   L93AE
        PLA    
        LDY   $4B
        BPL   L93A7
        TAX    
        BEQ   L93EC
        BNE   L93F7
L9395   LSR   $0D
        TXA    
        ROL    
        LDX   $3B
        BNE   L939F
        DEC   $3C
L939F   DEC   $3B
        LDY   #$1B
        STA   $4D
        BNE   L937E
L93A7   CMP   $8453,y
        BCS   L93F7
        BCC   L9387
L93AE   LDA   $8455,y
        PHA    
        LDA   $8454,y
        PHA    
        JSR   L93C1
        LDA   $4D
        JMP   L9337
L93BE   JMP   L94A1
L93C1   LDA   $66
        LDX   $8453,y
        TAY    
        CLC    
        PLA    
        ADC   #$01
        STA   $22
        PLA    
        ADC   #$00
        STA   $23
        TYA    
        PHA    
        JSR   LA2A0
        LDA   $65
        PHA    
        LDA   $64
        PHA    
        LDA   $63
        PHA    
        LDA   $62
        PHA    
        LDA   $61
        PHA    
        JMP   ($0022)
L93E9   LDY   #$FF
        PLA    
L93EC   BEQ   L9411
L93EE   CMP   #$64
        BEQ   L93F5
        JSR   L9317
L93F5   STY   $4B
L93F7   PLA    
        LSR    
        STA   $12
        PLA    
        STA   $69
        PLA    
        STA   $6A
        PLA    
        STA   $6B
        PLA    
        STA   $6C
        PLA    
        STA   $6D
        PLA    
        STA   $6E
        EOR   $66
        STA   $6F
L9411   LDA   $61
        RTS    
L9414   JMP   ($030A)
        LDA   #$00
        STA   $0D
L941B   JSR   $0473
        BCS   L9423
L9420   JMP   LA37F
L9423   JSR   L973A
        BCC   L942B
        JMP   L94AD
L942B   CMP   #$FF
        BNE   L943E
        LDA   #$39
        LDY   #$94
        JSR   LA221
        JMP   $0473
        SKB   $49
        ASO   $A1DA
L943E   CMP   #$2E
        BEQ   L9420
        CMP   #$AB
        BEQ   L94A6
        CMP   #$AA
        BEQ   L941B
        CMP   #$22
        BNE   L945D
L944E   LDA   $3B
        LDY   $3C
        ADC   #$00
        BCC   L9457
        INY    
L9457   JSR   L9B74
        JMP   L9DC6
L945D   CMP   #$A8
        BNE   L9477
        LDY   #$18
        BNE   L94A8
        JSR   L9886
        LDA   $65
        EOR   #$FF
        TAY    
        LDA   $64
        EOR   #$FF

        ; Float-Fixed
L9471   JSR   L9A92             ; Set NUMERIC flag, and clear mantissa.
        JMP   LA2C9             ; do Fixed-Float

L9477   CMP   #$A5
        BNE   L947E
        JMP   L9ADE
L947E   CMP   #$B4
        BCC   L9485
        JMP   L9599
L9485   JSR   L948E
        JSR   L932C


		; *******************************************************
		;
		; Check for "(" or ")" or "," - if not found display a
		; "?SYNTAX ERROR"
		;
		; *******************************************************
L948B   LDA   #$29				; Check for ")"
		db	  $2c				; mask "LDA #$28" with "BIT $28A9"
L948E	LDA   #$28				; check for "("
        db    $2c				; mask "LDA #$28" with "BIT $28A9"
L9491	LDA   #$2C				; check for ","


		; *******************************************************
		;
		; Check for character in basic stream 
		; IN:	A = char to check for
		; OUT:  If not found, display a syntax error
		;
		; *******************************************************
L9493   LDY   #$00
        STA   $78
        JSR   $04A5				; get current byte from basic
        CMP   $78				; compare with selected character
        BNE   L94A1				; if NOT the same, exit with "?SYNTAX ERROR"
        JMP   $0473				; move onto NEXT character
L94A1   LDX   #$0B				; display a "?SYNTAX ERROR"
        JMP   L8683				; call error routine.


L94A6   LDY   #$15
L94A8   PLA    
        PLA    
        JMP   L9388
L94AD   JSR   L96A5
        STA   $64
        STY   $65
        LDX   $45
        LDY   $46
        LDA   $0D
        BEQ   L9501
        LDA   #$00
        STA   $70
        CPX   #$54
        BNE   L94E8
        CPY   #$C9
        BNE   L953E
        LDA   $64
        CMP   #$A2
        BNE   L953E
        LDA   $65
        CMP   #$04
        BNE   L953E
        JSR   L9531
        STY   $5E
        DEY    
        STY   $71
        LDY   #$06
        STY   $5D
        LDY   #$24
        JSR   LA4FA
        JMP   L9B70
L94E8   CPX   #$44
        BNE   L953E
        CPY   #$D3
        BNE   L953E
        JSR   L94FA
        LDA   $7A
        LDY   $7B
        JMP   L9B74
L94FA   LDA   $79
        BNE   L953E
        JMP   LCCCF
L9501   BIT   $0E
        BPL   L9514
        LDY   #$00
        JSR   $04DC
        TAX    
        INY    
        JSR   $04DC
        TAY    
        TXA    
        JMP   L9471
L9514   LDA   $65
        CMP   #$04
        BNE   L9592
        LDA   $64
        CMP   #$A2
        BNE   L9592
        CPX   #$54
        BNE   L953F
        CPY   #$49
        BNE   L9592
        JSR   L9531
        TYA    
        LDX   #$A0
        JMP   LA2D4
L9531   JSR   LFFDE
        STX   $64
        STY   $63
        STA   $65
        LDY   #$00
        STY   $62
L953E   RTS    
L953F   CPX   #$53
        BNE   L954D
        CPY   #$54
        BNE   L9592
        JSR   LFFB7
        JMP   LA2C1
L954D   CPX   #$44
        BNE   L9577
        CPY   #$53
        BNE   L9592
        JSR   L94FA
        LDY   #$00
        LDA   #$7A
        JSR   $0494
        AND   #$0F
        ASL    
        STA   $0F
        ASL    
        ASL    
        ADC   $0F
        STA   $0F
        INY    
        LDA   #$7A
        JSR   $0494
        AND   #$0F
        ADC   $0F
        JMP   LA2C1
L9577   CPX   #$45
        BNE   L9592
        CPY   #$52
        BEQ   L958C
        CPY   #$4C
        BNE   L9592
        LDA   $04F1
        LDY   $04F0
        JMP   L9A76
L958C   LDA   $04EF
        JMP   LA2C1
L9592   LDA   $64
        LDY   $65
        JMP   LA21F
L9599   CMP   #$D5
        BCS   L95F5
        CMP   #$CB
        BCC   L95A3
        SBC   #$01
L95A3   PHA    
        TAX    
        JSR   $0473
        CPX   #$D3
        BEQ   L95B4
        CPX   #$CB
        BCS   L95D9
        CPX   #$C8
        BCC   L95D9
L95B4   JSR   L948E
        JSR   L932C
        JSR   L9491
        JSR   L931A
        PLA    
        CMP   #$D3
        BEQ   L95F2
        TAX    
        LDA   $65
        PHA    
        LDA   $64
        PHA    
        TXA    
        PHA    
        JSR   L9D84
        PLA    
        TAY    
        TXA    
        PHA    
        TYA    
        JMP   L95DD
L95D9   JSR   L9485
        PLA    
L95DD   SEC    
        SBC   #$B4
        ASL    
        TAY    
        LDA   $8416,y
        STA   $56
        LDA   $8415,y
        STA   $55
        JSR   $0054
        JMP   L9317
L95F2   JMP   LB386
L95F5   JMP   L94A1
        LDY   #$FF
        BIT   $00A0
        STY   $0B
        JSR   L9886
        LDA   $64
        EOR   $0B
        STA   $07
        LDA   $65
        EOR   $0B
        STA   $08
        JSR   LA281
        JSR   L9886
        LDA   $65
        EOR   $0B
        AND   $08
        EOR   $0B
        TAY    
        LDA   $64
        EOR   $0B
        AND   $07
        EOR   $0B
        JMP   L9471
        JSR   L931B
        BCS   L9640
        LDA   $6E
        ORA   #$7F
        AND   $6A
        STA   $6A
        LDA   #$69
        LDY   #$00
        JSR   LA2E0
        TAX    
        JMP   L9673
L9640   LDA   #$00
        STA   $0D
        DEC   $4D
        JSR   L9C4E
        STA   $61
        STX   $62
        STY   $63
        LDA   $6C
        LDY   $6D
        JSR   L9C52
        STX   $6C
        STY   $6D
        TAX    
        SEC    
        SBC   $61
        BEQ   L9668
        LDA   #$01
        BCC   L9668
        LDX   $61
        LDA   #$FF
L9668   STA   $66
        LDY   #$FF
        INX    
L966D   INY    
        DEX    
        BNE   L9678
        LDX   $66
L9673   BMI   L968C
        CLC    
        BCC   L968C
L9678   JSR   L8185
        PHA    
        JSR   L817D
        STA   $78
        PLA    
        CMP   $78
        BEQ   L966D
        LDX   #$FF
        BCS   L968C
        LDX   #$01
L968C   INX    
        TXA    
        ROL    
        AND   $12
        BEQ   L9695
        LDA   #$FF
L9695   JMP   LA2C1
L9698   JSR   L9491
        TAX    
        JSR   L96AA
        JSR   $0479
        BNE   L9698
        RTS    
L96A5   LDX   #$00
        JSR   $0479
L96AA   STX   $0C
L96AC   STA   $45
        JSR   $0479
        JSR   L973A
        BCS   L96B9
L96B6   JMP   L94A1
L96B9   LDX   #$00
        STX   $0D
        STX   $0E
        JSR   $0473
        BCC   L96C9
        JSR   L973A
        BCC   L96D4
L96C9   TAX    
L96CA   JSR   $0473
        BCC   L96CA
        JSR   L973A
        BCS   L96CA
L96D4   CMP   #$24
        BNE   L96DE
        LDA   #$FF
        STA   $0D
        BNE   L96EE
L96DE   CMP   #$25
        BNE   L96F5
        LDA   $10
        BNE   L96B6
        LDA   #$80
        STA   $0E
        ORA   $45
        STA   $45
L96EE   TXA    
        ORA   #$80
        TAX    
        JSR   $0473
L96F5   STX   $46
        SEC    
        ORA   $10
        SBC   #$28
        BNE   L9701
        JMP   L989B
L9701   LDY   #$00
        STY   $10
        LDA   $2D
        LDX   $2E
L9709   STX   $60
L970B   STA   $5F
        CPX   $30
        BNE   L9715
        CMP   $2F
        BEQ   L9744
L9715   JSR   $04D1
        STA   $78
        LDA   $45
        CMP   $78
        BNE   L9730
        INY    
        JSR   $04D1
        STA   $78
        LDA   $46
        CMP   $78
        BNE   L972F
        JMP   L984C
L972F   DEY    
L9730   CLC    
        LDA   $5F
        ADC   #$07
        BCC   L970B
        INX    
        BNE   L9709
L973A   CMP   #$41
        BCC   L9743
        SBC   #$5B
        SEC    
        SBC   #$A5
L9743   RTS    
L9744   PLA    
        PHA    
        CMP   #$AF
        BNE   L9774
L974A   LDA   #$A2
        LDY   #$04
        RTS    
L974F   CPY   #$C9
        BEQ   L974A
        CPY   #$49
        BNE   L9788
        BEQ   L9771
L9759   CPY   #$D3
        BEQ   L9771
        CPY   #$53
        BNE   L9788
        BEQ   L9771
L9763   CPY   #$54
        BNE   L9788
        BEQ   L9771
L9769   CPY   #$52
        BEQ   L9771
        CPY   #$4C
        BNE   L9788
L9771   JMP   L94A1
L9774   LDA   $45
        LDY   $46
        CMP   #$54
        BEQ   L974F
        CMP   #$53
        BEQ   L9763
        CMP   #$45
        BEQ   L9769
        CMP   #$44
        BEQ   L9759
L9788   LDA   $2F
        LDY   $30
        STA   $5F
        STY   $60
        LDA   $31
        LDY   $32
        STA   $5A
        STY   $5B
        CLC    
        ADC   #$07
        BCC   L979E
        INY    
L979E   STA   $58
        STY   $59
        JSR   L88C0
        LDA   $58
        LDY   $59
        INY    
        STA   $2F
        STY   $30
        STA   $58
        STY   $59
L97B2   LDA   $58
        LDX   $59
L97B6   CPX   $32
        BNE   L97C0
        CMP   $31
        BNE   L97C0
        BEQ   L9838
L97C0   STA   $22
        STX   $23
        LDY   #$00
        JSR   $04B0
        TAX    
        INY    
        JSR   $04B0
        PHP    
        INY    
        JSR   $04B0
        ADC   $58
        STA   $58
        INY    
        JSR   $04B0
        ADC   $59
        STA   $59
        PLP    
        BPL   L97B2
        TXA    
        BMI   L97B2
        INY    
        JSR   $04B0
        LDY   #$00
        ASL    
        ADC   #$05
L97EE   ADC   $22
        STA   $22
        BCC   L97F6
        INC   $23
L97F6   LDX   $23
        CPX   $59
        BNE   L9800
        CMP   $58
        BEQ   L97B6
L9800   LDY   #$00
        JSR   $04B0
        BEQ   L982B
        STA   $78
        INY    
        JSR   $04B0
        CLC    
        ADC   $78
        STA   $5A
        INY    
        JSR   $04B0
        ADC   #$00
        STA   $5B
        LDY   #$00
        JSR   L8189
        ADC   #$07
        STA   ($5A),y
        INY    
        JSR   L8189
        ADC   #$00
        STA   ($5A),y
L982B   LDA   #$03
        CLC    
        ADC   $22
        STA   $22
        BCC   L97F6
        INC   $23
        BNE   L97F6
L9838   LDY   #$00
        LDA   $45
        STA   ($5F),y
        INY    
        LDA   $46
        STA   ($5F),y
        LDA   #$00
L9845   INY    
        STA   ($5F),y
        CPY   #$06
        BNE   L9845
L984C   LDA   $5F
        CLC    
        ADC   #$02
        LDY   $60
        BCC   L9856
        INY    
L9856   STA   $47
        STY   $48
        RTS    
L985B   LDA   $0B
        ASL    
        ADC   #$05
        ADC   $5F
        LDY   $60
        BCC   L9867
        INY    
L9867   STA   $58
        STY   $59
        RTS   
       
        db    $90,$80           ; 32768
        db    $00,$00,$00

FixedFloat:
L9871   JSR   L9886             ; Fixed-Float
        LDA   $64               ; get top of mantissa
        LDY   $65
        RTS    

L9879   JSR   $0473
        JSR   L932C
L987F   JSR   L9317
        LDA   $66
        BMI   L9893
L9886   LDA   $61
        CMP   #$90
        BCC   L9898
        LDA   #$6C
        LDY   #$98
        JSR   LA2E0
L9893   BNE   L9898
        JMP   L991C             ; Illegal Quantity error
L9898   JMP   LA327
L989B   LDA   $0C
        ORA   $0E
        PHA    
        LDA   $0D
        PHA    
        LDY   #$00
L98A5   TYA    
        PHA    
        LDA   $46
        PHA    
        LDA   $45
        PHA    
        JSR   L9879
        PLA    
        STA   $45
        PLA    
        STA   $46
        PLA    
        TAY    
        TSX    
        LDA   $0102,x
        PHA    
        LDA   $0101,x
        PHA    
        LDA   $64
        STA   $0102,x
        LDA   $65
        STA   $0101,x
        INY    
        STY   $0B
        JSR   $0479
        LDY   $0B
        CMP   #$2C
        BEQ   L98A5
        JSR   L948B
        PLA    
        STA   $0D
        PLA    
        STA   $0E
        AND   #$7F
        STA   $0C
        LDX   $2F
        LDA   $30
L98E8   STX   $5F
        STA   $60
        CMP   $32
        BNE   L98F4
        CPX   $31
        BEQ   L993A
L98F4   LDY   #$00
        JSR   $04D1
        INY    
        CMP   $45
        BNE   L9909
        JSR   $04D1
        STA   $78
        LDA   $46
        CMP   $78
        BEQ   L9921
L9909   INY    
        JSR   $04D1
        CLC    
        ADC   $5F
        TAX    
        INY    
        JSR   $04D1
        ADC   $60
        BCC   L98E8

BadSubscript:             
L9919   LDX   #$12        ; Bad Subscript error

        db    $2c         ; makes LDX #$0e   into   BIT $0EA2    ($2c $a2 $0e)
        ldx   #$0E        ; Illegal Quantity error
L991E   JMP   L8683

L9921   LDX   #$13
        LDA   $0C
        BNE   L991E
        JSR   L985B
        LDY   #$04
        JSR   $04D1
        STA   $78
        LDA   $0B
        CMP   $78
        BNE   L9919
        JMP   L99C3
L993A   JSR   L985B
        JSR   L8923
        LDY   #$00
        STY   $72
        LDX   #$05
        LDA   $45
        STA   ($5F),y
        BPL   L994D
        DEX    
L994D   INY    
        LDA   $46
        STA   ($5F),y
        BPL   L9956
        DEX    
        DEX    
L9956   STX   $71
        LDA   $0B
        INY    
        INY    
        INY    
        STA   ($5F),y
L995F   LDX   #$0B
        LDA   #$00
        BIT   $0C
        BVC   L996F
        PLA    
        CLC    
        ADC   #$01
        TAX    
        PLA    
        ADC   #$00
L996F   INY    
        STA   ($5F),y
        INY    
        TXA    
        STA   ($5F),y
        JSR   L9A2F
        STX   $71
        STA   $72
        LDY   $22
        DEC   $0B
        BNE   L995F
        ADC   $59
        BCS   L99EE
        STA   $59
        TAY    
        TXA    
        ADC   $58
        BCC   L9992
        INY    
        BEQ   L99EE
L9992   JSR   L8923
        STA   $31
        STY   $32
        LDA   #$00
        INC   $72
        LDY   $71
        BEQ   L99A6
L99A1   DEY    
        STA   ($58),y
        BNE   L99A1
L99A6   DEC   $59
        DEC   $72
        BNE   L99A1
        INC   $59
        SEC    
        LDA   $31
        SBC   $5F
        LDY   #$02
        STA   ($5F),y
        LDA   $32
        INY    
        SBC   $60
        STA   ($5F),y
        LDA   $0C
        BNE   L9A2E
        INY    
L99C3   JSR   $04D1
        STA   $0B
        LDA   #$00
        STA   $71
L99CC   STA   $72
        INY    
        PLA    
        TAX    
        STA   $64
        JSR   $04D1
        STA   $78
        PLA    
        STA   $65
        CMP   $78
        BCC   L99F1
        BNE   L99EB
        INY    
        JSR   $04D1
        STA   $78
        CPX   $78
        BCC   L99F2
L99EB   JMP   L9919
L99EE   JMP   L8681
L99F1   INY    
L99F2   LDA   $72
        ORA   $71
        CLC    
        BEQ   L9A03
        JSR   L9A2F
        TXA    
        ADC   $64
        TAX    
        TYA    
        LDY   $22
L9A03   ADC   $65
        STX   $71
        DEC   $0B
        BNE   L99CC
        STA   $72
        LDX   #$05
        LDA   $45
        BPL   L9A14
        DEX    
L9A14   LDA   $46
        BPL   L9A1A
        DEX    
        DEX    
L9A1A   STX   $28
        LDA   #$00
        JSR   L9A3A
        TXA    
        ADC   $58
        STA   $47
        TYA    
        ADC   $59
        STA   $48
        TAY    
        LDA   $47
L9A2E   RTS    
L9A2F   STY   $22
        JSR   $04D1
        STA   $28
        DEY    
        JSR   $04D1
L9A3A   STA   $29
        LDA   #$10
        STA   $5D
        LDX   #$00
        LDY   #$00
L9A44   TXA    
        ASL    
        TAX    
        TYA    
        ROL    
        TAY    
        BCS   L99EE
        ASL   $71
        ROL   $72
        BCC   L9A5D
        CLC    
        TXA    
        ADC   $28
        TAX    
        TYA    
        ADC   $29
        TAY    
        BCS   L99EE
L9A5D   DEC   $5D
        BNE   L9A44
        RTS    
        LDA   $0D
        BEQ   L9A69
        JSR   L9C4E
L9A69   JSR   LA954
        SEC    
        LDA   $33
        SBC   $31
        TAY    
        LDA   $34
        SBC   $32
L9A76   JSR   L9A92
        SEC    
        JMP   LA2CE
        SEC    
        JSR   LFFF0
L9A81   LDA   #$00
        JMP   L9471
L9A86   BIT   Running                 ; BASIC program running?
        BMI   L9A2E
        LDX   #$15
        BIT   $1BA2
        JMP   L8683
L9A92   LDX   #$00
        STX   $0D
        STA   $62
        STY   $63
        LDX   #$90
        RTS    
        JSR   L9ACB
        JSR   L9A86
        JSR   L948E
        LDA   #$80
        STA   $10
        JSR   L96A5
        JSR   L9317
        JSR   L948B
        LDA   #$B2
        JSR   L9493
        PHA    
        LDA   $48
        PHA    
        LDA   $47
        PHA    
        LDA   $3C
        PHA    
        LDA   $3B
        PHA    
        JSR   L8DB0
        JMP   L9B3E
L9ACB   LDA   #$A5
        JSR   L9493
        ORA   #$80
        STA   $10
        JSR   L96AC
        STA   $4E
        STY   $4F
        JMP   L9317
L9ADE   JSR   L9ACB
        LDA   $4F
        PHA    
        LDA   $4E
        PHA    
        JSR   L9485
        JSR   L9317
        PLA    
        STA   $4E
        PLA    
        STA   $4F
        LDY   #$02
        JSR   L8159
        STA   $47
        TAX    
        INY    
        JSR   L8159
        BEQ   L9A8D
        STA   $48
        INY    
L9B04   JSR   L8161
        PHA    
        DEY    
        BPL   L9B04
        LDY   $48
        JSR   LA259
        LDA   $3C
        PHA    
        LDA   $3B
        PHA    
        JSR   L8159
        STA   $3B
        INY    
        JSR   L8159
        STA   $3C
        LDA   $48
        PHA    
        LDA   $47
        PHA    
        JSR   L9314
        PLA    
        STA   $4E
        PLA    
        STA   $4F
        JSR   $0479
        BEQ   L9B38
        JMP   L94A1
L9B38   PLA    
        STA   $3B
        PLA    
        STA   $3C
L9B3E   LDY   #$00
        PLA    
        STA   ($4E),y
        PLA    
        INY    
        STA   ($4E),y
        PLA    
        INY    
        STA   ($4E),y
        PLA    
        INY    
        STA   ($4E),y
        PLA    
        INY    
        STA   ($4E),y
        RTS    
L9B54   LDX   $64
        LDY   $65
        STX   $50
        STY   $51
L9B5C   JSR   LA906
        STX   $62
        STY   $63
        STA   $61
        RTS    
        JSR   L9317
        LDY   #$00
        JSR   LA471
        PLA    
        PLA    
L9B70   LDA   #$FF
        LDY   #$00
L9B74   LDX   #$22
        STX   $07
        STX   $08
L9B7A   STA   $6F
        STY   $70
        STA   $62
        STY   $63
        LDY   #$FF
L9B84   INY    
        JSR   $04C6
        BEQ   L9B96
        CMP   $07
        BEQ   L9B92
        CMP   $08
        BNE   L9B84
L9B92   CMP   #$22
        BEQ   L9B97
L9B96   CLC    
L9B97   STY   $61
        TYA    
        ADC   $6F
        STA   $71
        LDX   $70
        BCC   L9BA3
        INX    
L9BA3   STX   $72
        TYA    
        JSR   L9B54
        LDX   $6F
        LDY   $70
        JSR   L9C2C
L9BB0   LDX   $16
        CPX   #$22
        BNE   L9BBB
        LDX   #$19
        JMP   L8683
L9BBB   LDA   $61
        STA   DIRECTION,x
        LDA   $62
        STA   IO,x
        LDA   $63
        STA   $02,x
        LDY   #$00
        STX   $64
        STY   $65
        STY   $70
        DEY    
        STY   $0D
        STX   $17
        INX    
        INX    
        INX    
        STX   $16
        RTS    
L9BDA   LDA   $65
        PHA    
        LDA   $64
        PHA    
        JSR   L9414
        JSR   L931A
        PLA    
        STA   $6F
        PLA    
        STA   $70
        LDY   #$00
        JSR   $04C6
        STA   $78
        JSR   $04DC
        CLC    
        ADC   $78
        BCC   L9BFE
        JMP   LCC4C
L9BFE   JSR   L9B54
        JSR   L9C1B
        LDA   $50
        LDY   $51
        JSR   L9C52
        JSR   L9C30
        LDA   $6F
        LDY   $70
        JSR   L9C52
        JSR   L9BB0
        JMP   L9346
L9C1B   LDY   #$00
        JSR   $04C6
        PHA    
        INY    
        JSR   $04C6
        TAX    
        INY    
        JSR   $04C6
        TAY    
        PLA    
L9C2C   STX   $22
        STY   $23
L9C30   TAY    
        BEQ   L9C3E
        PHA    
L9C34   DEY    
        JSR   $04B0
        STA   ($35),y
        TYA    
        BNE   L9C34
        PLA    
L9C3E   CLC    
        ADC   $35
        STA   $35
        BCC   L9C47
        INC   $36
L9C47   RTS    
L9C48   JSR   L932C
L9C4B   JSR   L931A
L9C4E   LDA   $64
        LDY   $65
L9C52   STA   $22
        STY   $23
        JSR   L9CAA
        BNE   L9C94
        JSR   L8F9C
        BCC   L9C94
        DEY    
        LDA   #$FF
        STA   ($22),y
        DEY    
        TXA    
        STA   ($22),y
        PHA    
        EOR   #$FF
        SEC    
        ADC   $22
        LDY   $23
        BCS   L9C74
        DEY    
L9C74   STA   $22
        STY   $23
        TAX    
        PLA    
        CPY   $34
        BNE   L9CBA
        CPX   $33
        BNE   L9CBA
        PHA    
        SEC    
        ADC   $33
        STA   $33
        BCC   L9C8C
        INC   $34
L9C8C   INC   $33
        BNE   L9C92
        INC   $34
L9C92   PLA    
        RTS    
L9C94   LDY   #$00
        JSR   $04B0
        PHA    
        INY    
        JSR   $04B0
        TAX    
        INY    
        JSR   $04B0
        TAY    
        STX   $22
        STY   $23
        PLA    
        RTS    
L9CAA   CPY   $18
        BNE   L9CBA
        CMP   $17
        BNE   L9CBA
        STA   $16
        SBC   #$03
        STA   $17
        LDY   #$00
L9CBA   RTS    
        JSR   L9D87
        TXA    
        PHA    
        LDA   #$01
        JSR   L9B5C
        PLA    
        LDY   #$00
        STA   ($62),y
L9CCA   PLA    
        PLA    
        JMP   L9BB0
        JSR   L9D46
        PHA    
        JSR   L8181
        STA   $78
        PLA    
        CMP   $78
        TYA    
L9CDC   BCC   L9CE3
        JSR   L8181
        TAX    
        TYA    
L9CE3   PHA    
L9CE4   TXA    
L9CE5   PHA    
        JSR   L9B5C
        LDA   $50
        LDY   $51
        JSR   L9C52
        PLA    
        TAY    
        PLA    
        CLC    
        ADC   $22
        STA   $22
        BCC   L9CFC
        INC   $23
L9CFC   TYA    
        JSR   L9C30
        JMP   L9BB0
        JSR   L9D46
        PHA    
        JSR   L8181
        STA   $78
        PLA    
        CLC    
        SBC   $78
        EOR   #$FF
        JMP   L9CDC
        LDA   #$FF
        STA   $65
        JSR   $0479
        CMP   #$29
        BEQ   L9D26
        JSR   L9491
        JSR   L9D84
L9D26   JSR   L9D46
        BEQ   L9D7E
        DEX    
        TXA    
        PHA    
        LDX   #$00
        PHA    
        JSR   L8181
        STA   $78
        PLA    
        CLC    
        SBC   $78
        BCS   L9CE4
        EOR   #$FF
        CMP   $65
        BCC   L9CE5
        LDA   $65
        BCS   L9CE5
L9D46   JSR   L948B
        PLA    
        TAY    
        PLA    
        STA   $55
        PLA    
        PLA    
        PLA    
        TAX    
        PLA    
        STA   $50
        PLA    
        STA   $51
        LDA   $55
        PHA    
        TYA    
        PHA    
        LDY   #$00
        TXA    
        RTS    
        JSR   L9D67
        JMP   L9A81
L9D67   JSR   L9C4B
        LDX   #$00
        STX   $0D
        TAY    
        RTS    
        JSR   L9D67
        BEQ   L9D7B
        LDY   #$00
        JSR   $04B0
        TAY    
L9D7B   JMP   L9A81
L9D7E   JMP   L991C             ; Illegal Quantity error


        ; *********************************************
		;
		; input a byte paramater from basic 
		;
		; This gets the next paramater from basic, evaluates
		; and if >255 returns an error, else it returns
		; the value in "X"
		;
        ; *********************************************
GetByteParamFromBasic:
L9D81   JSR   $0473				; use CHRGET to fetch next paramater
L9D84   JSR   L9314				; evaluate and Check the type (int,float or string etc.)
L9D87   JSR   L987F				; perform Float-Fixed
        LDX   $64				; get Mantissa high (256-65535)
        BNE   L9D7E				; if paramater>255 display an illegal Quantity error
        LDX   $65				; get actual BYTE value from paramater.
        JMP   $0479				; use CHRGOT to get current basic byte. (return as well) - get ready for commas etc?


        ; *********************************************
		;
		; Perform "VAL" command
		;
        ; *********************************************
        JSR   L9D67
        BEQ   L9DCF
        LDX   $3B
        LDY   $3C
        STX   $71
        STY   $72
        LDX   $22
        STX   $3B
        CLC    
        ADC   $22
        STA   $24
        LDX   $23
        STX   $3C
        BCC   L9DB0
        INX    
L9DB0   STX   $25
        LDY   #$00
        JSR   $04BB
        PHA    
        TYA    
        STA   ($24),y
        JSR   $0479
        JSR   LA37F
        PLA    
        LDY   #$00
        STA   ($24),y
L9DC6   LDX   $71
        LDY   $72
        STX   $3B
        STY   $3C
        RTS    
L9DCF   JMP   L9F2B
L9DD2   JSR   L9314
        JSR   L9DE4
L9DD8   JSR   L9491
        JMP   L9D84
L9DDE   JSR   L9491
L9DE1   JSR   L9314
L9DE4   LDA   $66
        BMI   L9D7E
L9DE8   LDA   $61
        CMP   #$91
        BCS   L9D7E
        JSR   LA327
        LDA   $64
        LDY   $65
        STY   $14
        STA   $15
        RTS    
        LDA   $15
        PHA    
        LDA   $14
        PHA    
        JSR   L9DE4
        LDY   #$00
        JSR   L815D
        TAY    
        PLA    
        STA   $14
        PLA    
        STA   $15
        JMP   L9A81
        JSR   L9DD2
        TXA    
        LDY   #$00
        STA   ($14),y
        RTS    
        JSR   L9D67
        STA   $24
        LDY   #$00
        STY   $25
        STY   $71
        STY   $72
L9E28   CPY   $24
        BEQ   L9E60
        JSR   $04B0
        INY    
        CMP   #$20
        BEQ   L9E28
        INC   $25
        LDX   $25
        CPX   #$05
        BEQ   L9E67
        CMP   #$30
        BCC   L9E67
        CMP   #$3A
        BCC   L9E4E
        CMP   #$41
        BCC   L9E67
        CMP   #$47
        BCS   L9E67
        SBC   #$07
L9E4E   SBC   #$2F
        ASL    
        ASL    
        ASL    
        ASL    
        LDX   #$04
L9E56   ASL    
        ROL   $71
        ROL   $72
        DEX    
        BNE   L9E56
        BEQ   L9E28
L9E60   LDY   $71
        LDA   $72
        JMP   L9A76
L9E67   JMP   L991C             ; Illegal Quantity error
        JSR   L9DD2
        STX   $49
        LDX   #$00
        JSR   $0479
        BEQ   L9E79
        JSR   L9DD8
L9E79   STX   $4A
        LDY   #$00
L9E7D   JSR   L815D
        EOR   $4A
        AND   $49
        BEQ   L9E7D
L9E86   RTS    
L9E87   LDA   $66
        EOR   #$FF
        STA   $66
        EOR   $6E
        STA   $6F
        LDA   $61
        JMP   L9E9E
L9E96   JSR   L9FCD
        BCC   L9ED7
L9E9B   JSR   LA107
L9E9E   BNE   L9EA3
        JMP   LA281
L9EA3   LDX   $70
        STX   $56
        LDX   #$69
        LDA   $69
L9EAB   TAY    
        BEQ   L9E86
        SEC    
        SBC   $61
        BEQ   L9ED7
        BCC   L9EC7
        STY   $61
        LDY   $6E
        STY   $66
        EOR   #$FF
        ADC   #$00
        LDY   #$00
        STY   $56
        LDX   #$61
        BNE   L9ECB
L9EC7   LDY   #$00
        STY   $70
L9ECB   CMP   #$F9
        BMI   L9E96
        TAY    
        LDA   $70
        LSR   IO,x
        JSR   L9FE4
L9ED7   BIT   $6F
        BPL   L9F32
        LDY   #$61
        CPX   #$69
        BEQ   L9EE3
        LDY   #$69
L9EE3   SEC    
        EOR   #$FF
        ADC   $56
        STA   $70
        LDA   $0004,y
        SBC   $04,x
        STA   $65
        LDA   $0003,y
        SBC   $03,x
        STA   $64
        LDA   $0002,y
        SBC   $02,x
        STA   $63
        LDA   IO,y
        SBC   IO,x
        STA   $62
L9F06   BCS   L9F0B
        JSR   L9F7B
L9F0B   LDY   #$00
        TYA    
        CLC    
L9F0F   LDX   $62
        BNE   L9F5D
        LDX   $63
        STX   $62
        LDX   $64
        STX   $63
        LDX   $65
        STX   $64
        LDX   $70
        STX   $65
        STY   $70
        ADC   #$08
        CMP   #$20
        BNE   L9F0F
L9F2B   LDA   #$00
L9F2D   STA   $61
L9F2F   STA   $66
        RTS    
L9F32   ADC   $56
        STA   $70
        LDA   $65
        ADC   $6D
        STA   $65
        LDA   $64
        ADC   $6C
        STA   $64
        LDA   $63
        ADC   $6B
        STA   $63
        LDA   $62
        ADC   $6A
        STA   $62
        JMP   L9F6A
L9F51   ADC   #$01
        ASL   $70
        ROL   $65
        ROL   $64
        ROL   $63
        ROL   $62
L9F5D   BPL   L9F51
        SEC    
        SBC   $61
        BCS   L9F2B
        EOR   #$FF
        ADC   #$01
        STA   $61
L9F6A   BCC   L9F7A
L9F6C   INC   $61
        BEQ   L9FB2
        ROR   $62
        ROR   $63
        ROR   $64
        ROR   $65
        ROR   $70
L9F7A   RTS    
L9F7B   LDA   $66
        EOR   #$FF
        STA   $66
L9F81   LDA   $62
        EOR   #$FF
        STA   $62
        LDA   $63
        EOR   #$FF
        STA   $63
        LDA   $64
        EOR   #$FF
        STA   $64
        LDA   $65
        EOR   #$FF
        STA   $65
        LDA   $70
        EOR   #$FF
        STA   $70
        INC   $70
        BNE   L9FB1
L9FA3   INC   $65
        BNE   L9FB1
        INC   $64
        BNE   L9FB1
        INC   $63
        BNE   L9FB1
        INC   $62
L9FB1   RTS    
L9FB2   LDX   #$0F
        JMP   L8683
L9FB7   LDX   #$25
L9FB9   LDY   $04,x
        STY   $70
        LDY   $03,x
        STY   $04,x
        LDY   $02,x
        STY   $03,x
        LDY   IO,x
        STY   $02,x
        LDY   $68
        STY   IO,x
L9FCD   ADC   #$08
        BMI   L9FB9
        BEQ   L9FB9
        SBC   #$08
        TAY    
        LDA   $70
        BCS   L9FEE
L9FDA   ASL   IO,x
        BCC   L9FE0
        INC   IO,x
L9FE0   ROR   IO,x
        ROR   IO,x
L9FE4   ROR   $02,x
        ROR   $03,x
        ROR   $04,x
        ROR    
        INY    
        BNE   L9FDA
L9FEE   CLC    
        RTS    
        STA   (DIRECTION,x)
        BRK    
        BRK    
        BRK    
        ASO   ($7F,x)
        LSR   $CB56,x
        ADC   $1380,y
        ???   
        SKB   $76
        SEC    
        ???   
        ASL   $82,x
        SEC    
        TAX    
        RLA   $8020,y
        AND   $04,x
        INS   ($34),y
        STA   ($35,x)
        SKB   $F3
        SKB   $80
        SKB   DIRECTION
        BRK    
        BRK    
        SKB   $31
        HLT    
        ASO   $F8,x
LA01E   JSR   LA2B0
        BEQ   LA025
        BPL   LA028
LA025   JMP   L991C             ; Illegal Quantity error
LA028   LDA   $61
        SBC   #$7F
        PHA    
        LDA   #$80
        STA   $61
        LDA   #$0A
        LDY   #$A0
        JSR   LA066
        LDA   #$0F
        LDY   #$A0
        JSR   LA072
        LDA   #$F0
        LDY   #$9F
        JSR   LA06C
        LDA   #$F5
        LDY   #$9F
        JSR   LA6B3
        LDA   #$14
        LDY   #$A0
        JSR   LA066
        PLA    
        JSR   LA40A
        LDA   #$19
        LDY   #$A0
LA05C   JSR   LA0DC
        JMP   LA07B
LA062   LDA   #$A3
        LDY   #$A5
LA066   JSR   LA0DC
        JMP   L9E9E
LA06C   JSR   LA0DC
        JMP   L9E87
LA072   JSR   LA0DC
        JMP   LA197
LA078   JSR   LA107
LA07B   BNE   LA080
        JMP   LA0DB
LA080   JSR   LA137
        LDA   #$00
        STA   $26
        STA   $27
        STA   $28
        STA   $29
        LDA   $70
        JSR   LA0A9
        LDA   $65
        JSR   LA0A9
        LDA   $64
        JSR   LA0A9
        LDA   $63
        JSR   LA0A9
        LDA   $62
        JSR   LA0AE
        JMP   LA20C
LA0A9   BNE   LA0AE
        JMP   L9FB7
LA0AE   LSR    
        ORA   #$80
LA0B1   TAY    
        BCC   LA0CD
        CLC    
        LDA   $29
        ADC   $6D
        STA   $29
        LDA   $28
        ADC   $6C
        STA   $28
        LDA   $27
        ADC   $6B
        STA   $27
        LDA   $26
        ADC   $6A
        STA   $26
LA0CD   ROR   $26
        ROR   $27
        ROR   $28
        ROR   $29
        ROR   $70
        TYA    
        LSR    
        BNE   LA0B1
LA0DB   RTS    
LA0DC   STA   $22
        STY   $23
        LDY   #$04
        LDA   ($22),y
        STA   $6D
        DEY    
        LDA   ($22),y
        STA   $6C
        DEY    
        LDA   ($22),y
        STA   $6B
        DEY    
        LDA   ($22),y
        STA   $6E
        EOR   $66
        STA   $6F
        LDA   $6E
        ORA   #$80
        STA   $6A
        DEY    
        LDA   ($22),y
        STA   $69
        LDA   $61
        RTS    
LA107   STA   $22
        STY   $23
        LDY   #$04
        JSR   $04B0
        STA   $6D
        DEY    
        JSR   $04B0
        STA   $6C
        DEY    
        JSR   $04B0
        STA   $6B
        DEY    
        JSR   $04B0
        STA   $6E
        EOR   $66
        STA   $6F
        LDA   $6E
        ORA   #$80
        STA   $6A
        DEY    
        JSR   $04B0
        STA   $69
        LDA   $61
        RTS    
LA137   LDA   $69
LA139   BEQ   LA15A
        CLC    
        ADC   $61
        BCC   LA144
        BMI   LA15F
        CLC    
        BIT   $1410
        ADC   #$80
        STA   $61
        BNE   LA14F
        JMP   L9F2F
LA14F   LDA   $6F
        STA   $66
        RTS    
LA154   LDA   $66
        EOR   #$FF
        BMI   LA15F
LA15A   PLA    
        PLA    
        JMP   L9F2B
LA15F   JMP   L9FB2
LA162   JSR   LA291
        TAX    
        BEQ   LA178
        CLC    
        ADC   #$02
        BCS   LA15F
LA16D   LDX   #$00
        STX   $6F
        JSR   L9EAB
        INC   $61
        BEQ   LA15F
LA178   RTS    
        STY   $20
        BRK    
        BRK    
        BRK    
LA17E   LDX   #$14
        JMP   L8683
LA183   JSR   LA291
        LDA   #$79
        LDY   #$A1
        LDX   #$00
LA18C   STX   $6F
        JSR   LA221
        JMP   LA197
LA194   JSR   LA107
LA197   BEQ   LA17E
        JSR   LA2A0
        LDA   #$00
        SEC    
        SBC   $61
        STA   $61
        JSR   LA137
        INC   $61
        BEQ   LA15F
        LDX   #$FC
        LDA   #$01
LA1AE   LDY   $6A
        CPY   $62
        BNE   LA1C4
        LDY   $6B
        CPY   $63
        BNE   LA1C4
        LDY   $6C
        CPY   $64
        BNE   LA1C4
        LDY   $6D
        CPY   $65
LA1C4   PHP    
        ROL    
        BCC   LA1D1
        INX    
        STA   $29,x
        BEQ   LA1FF
        BPL   LA203
        LDA   #$01
LA1D1   PLP    
        BCS   LA1E2
LA1D4   ASL   $6D
        ROL   $6C
        ROL   $6B
        ROL   $6A
        BCS   LA1C4
        BMI   LA1AE
        BPL   LA1C4
LA1E2   TAY    
        LDA   $6D
        SBC   $65
        STA   $6D
        LDA   $6C
        SBC   $64
        STA   $6C
        LDA   $6B
        SBC   $63
        STA   $6B
        LDA   $6A
        SBC   $62
        STA   $6A
        TYA    
        JMP   LA1D4
LA1FF   LDA   #$40
        BNE   LA1D1
LA203   ASL    
        ASL    
        ASL    
        ASL    
        ASL    
        ASL    
        STA   $70
        PLP    
LA20C   LDA   $26
        STA   $62
        LDA   $27
        STA   $63
        LDA   $28
        STA   $64
        LDA   $29
        STA   $65
        JMP   L9F0B
LA21F   CLC    
        BIT   $38
        STA   $22
        STY   $23
        LDY   #$04
        JSR   LA320
        STA   $65
        DEY    
        JSR   LA320
        STA   $64
        DEY    
        JSR   LA320
        STA   $63
        DEY    
        JSR   LA320
        STA   $66
        ORA   #$80
        STA   $62
        DEY    
        JSR   LA320
        STA   $61
        STY   $70
        RTS    
LA24C   LDX   #$5C
        BIT   $57A2
        LDY   #$00
        BEQ   LA259
LA255   LDX   $49
        LDY   $4A
LA259   JSR   LA2A0
        STX   $22
        STY   $23
        LDY   #$04
        LDA   $65
        STA   ($22),y
        DEY    
        LDA   $64
        STA   ($22),y
        DEY    
        LDA   $63
        STA   ($22),y
        DEY    
        LDA   $66
        ORA   #$7F
        AND   $62
        STA   ($22),y
        DEY    
        LDA   $61
        STA   ($22),y
        STY   $70
        RTS    
LA281   LDA   $6E
LA283   STA   $66
        LDX   #$05
LA287   LDA   $68,x
        STA   $60,x
        DEX    
        BNE   LA287
        STX   $70
        RTS    
LA291   JSR   LA2A0
LA294   LDX   #$06
LA296   LDA   $60,x
        STA   $68,x
        DEX    
        BNE   LA296
        STX   $70
LA29F   RTS    
LA2A0   LDA   $61
        BEQ   LA29F
        ASL   $70
        BCC   LA29F
LA2A8   JSR   L9FA3
        BNE   LA29F
        JMP   L9F6C
LA2B0   LDA   $61
        BEQ   LA2BD
LA2B4   LDA   $66
LA2B6   ROL    
        LDA   #$FF
        BCS   LA2BD
        LDA   #$01
LA2BD   RTS    
        JSR   LA2B0
LA2C1   STA   $62
        LDA   #$00
        STA   $63
        LDX   #$88
LA2C9   LDA   $62
        EOR   #$FF
        ROL    
LA2CE   LDA   #$00
        STA   $65
        STA   $64
LA2D4   STX   $61
        STA   $70
        STA   $66
        JMP   L9F06
        LSR   $66
        RTS    
LA2E0   STA   $24
        STY   $25
        LDY   #$00
        LDA   ($24),y
        INY    
        TAX    
        BEQ   LA2B0
        LDA   ($24),y
        EOR   $66
        BMI   LA2B4
        CPX   $61
        BNE   LA317
        LDA   ($24),y
        ORA   #$80
        CMP   $62
        BNE   LA317
        INY    
        LDA   ($24),y
        CMP   $63
        BNE   LA317
        INY    
        LDA   ($24),y
        CMP   $64
        BNE   LA317
        INY    
        LDA   #$7F
        CMP   $70
        LDA   ($24),y
        SBC   $65
        BEQ   LA346
LA317   LDA   $66
        BCC   LA31D
        EOR   #$FF
LA31D   JMP   LA2B6
LA320   LDA   ($22),y
        BCS   LA346
        JMP   $04B0
LA327   LDA   $61
        BEQ   LA375
        SEC    
        SBC   #$A0
        BIT   $66
        BPL   LA33B
        TAX    
        LDA   #$FF
        STA   $68
        JSR   L9F81
        TXA    
LA33B   LDX   #$61
        CMP   #$F9
        BPL   LA347
        JSR   L9FCD
        STY   $68
LA346   RTS    
LA347   TAY    
        LDA   $66
        AND   #$80
        LSR   $62
        ORA   $62
        STA   $62
        JSR   L9FE4
        STY   $68
        RTS    
LA358   LDA   $61
        CMP   #$A0
        BCS   LA37E
        JSR   LA327
        STY   $70
        LDA   $66
        STY   $66
        EOR   #$80
        ROL    
        LDA   #$A0
        STA   $61
        LDA   $65
        STA   $07
        JMP   L9F06
LA375   STA   $62
        STA   $63
        STA   $64
        STA   $65
        TAY    
LA37E   RTS    
LA37F   LDY   #$00
        LDX   #$0A
LA383   STY   $5D,x
        DEX    
        BPL   LA383
        BCC   LA399
        CMP   #$2D
        BNE   LA392
        STX   $67
        BEQ   LA396
LA392   CMP   #$2B
        BNE   LA39B
LA396   JSR   $0473
LA399   BCC   LA3F6
LA39B   CMP   #$2E
        BEQ   LA3CD
        CMP   #$45
        BNE   LA3D3
        JSR   $0473
        BCC   LA3BF
        CMP   #$AB
        BEQ   LA3BA
        CMP   #$2D
        BEQ   LA3BA
        CMP   #$AA
        BEQ   LA3BC
        CMP   #$2B
        BEQ   LA3BC
        BNE   LA3C1
LA3BA   ROR   $60
LA3BC   JSR   $0473
LA3BF   BCC   LA41D
LA3C1   BIT   $60
        BPL   LA3D3
        LDA   #$00
        SEC    
        SBC   $5E
        JMP   LA3D5
LA3CD   ROR   $5F
        BIT   $5F
        BVC   LA396
LA3D3   LDA   $5E
LA3D5   SEC    
        SBC   $5D
        STA   $5E
        BEQ   LA3EE
        BPL   LA3E7
LA3DE   JSR   LA183
        INC   $5E
        BNE   LA3DE
        BEQ   LA3EE
LA3E7   JSR   LA162
        DEC   $5E
        BNE   LA3E7
LA3EE   LDA   $67
        BMI   LA3F3
        RTS    
LA3F3   JMP   LA627
LA3F6   PHA    
        BIT   $5F
        BPL   LA3FD
        INC   $5D
LA3FD   JSR   LA162
        PLA    
        SEC    
        SBC   #$30
        JSR   LA40A
        JMP   LA396
LA40A   PHA    
        JSR   LA291
        PLA    
        JSR   LA2C1
        LDA   $6E
        EOR   $66
        STA   $6F
        LDX   $61
        JMP   L9E9E
LA41D   LDA   $5E
        CMP   #$0A
        BCC   LA42C
        LDA   #$64
        BIT   $60
        BMI   LA43F
        JMP   L9FB2
LA42C   ASL    
        ASL    
        CLC    
        ADC   $5E
        ASL    
        CLC    
        LDY   #$00
        STA   $78
        JSR   $04A5
        ADC   $78
        SEC    
        SBC   #$30
LA43F   STA   $5E
        JMP   LA3BC
        ???   
        ASO   $9EFD,x
        ROR   $276B
        ORA   $6E9E,x
        ???   
LA453   JSR   PrintMessage
        JSR   $4E49
        JSR   LA500
        NOP    
        LDX   $39
LA45F   STA   $62
        STX   $63
        LDX   #$90
        SEC    
        JSR   LA2CE
        JSR   LA471
        JMP   L9088
LA46F   LDY   #$01
LA471   LDA   #$20
        BIT   $66
        BPL   LA479
        LDA   #$2D
LA479   STA   $00FF,y
        STA   $66
        STY   $71
        INY    
        LDA   #$30
        LDX   $61
        BNE   LA48A
        JMP   LA596
LA48A   LDA   #$00
        CPX   #$80
        BEQ   LA492
        BCS   LA49B
LA492   LDA   #$4E
        LDY   #$A4
        JSR   LA05C
        LDA   #$F7
LA49B   STA   $5D
LA49D   LDA   #$49
        LDY   #$A4
        JSR   LA2E0
        BEQ   LA4C4
        BPL   LA4BA
LA4A8   LDA   #$44
        LDY   #$A4
        JSR   LA2E0
        BEQ   LA4B3
        BPL   LA4C1
LA4B3   JSR   LA162
        DEC   $5D
        BNE   LA4A8
LA4BA   JSR   LA183
        INC   $5D
        BNE   LA49D
LA4C1   JSR   LA062
LA4C4   JSR   LA327
        LDX   #$01
        LDA   $5D
        CLC    
        ADC   #$0A
        BMI   LA4D9
        CMP   #$0B
        BCS   LA4DA
        ADC   #$FF
        TAX    
        LDA   #$02
LA4D9   SEC    
LA4DA   SBC   #$02
        STA   $5E
        STX   $5D
        TXA    
        BEQ   LA4E5
        BPL   LA4F8
LA4E5   LDY   $71
        LDA   #$2E
        INY    
        STA   $00FF,y
        TXA    
        BEQ   LA4F6
        LDA   #$30
        INY    
        STA   $00FF,y
LA4F6   STY   $71
LA4F8   LDY   #$00
LA4FA   LDX   #$80
LA4FC   LDA   $65
        CLC    
        ADC   $A5AB,y
        STA   $65
        LDA   $64
        ADC   $A5AA,y
        STA   $64
        LDA   $63
        ADC   $A5A9,y
        STA   $63
        LDA   $62
        ADC   $A5A8,y
        STA   $62
        INX    
        BCS   LA520
        BPL   LA4FC
        BMI   LA522
LA520   BMI   LA4FC
LA522   TXA    
        BCC   LA529
        EOR   #$FF
        ADC   #$0A
LA529   ADC   #$2F
        INY    
        INY    
        INY    
        INY    
        STY   $47
        LDY   $71
        INY    
        TAX    
        AND   #$7F
        STA   $00FF,y
        DEC   $5D
        BNE   LA544
        LDA   #$2E
        INY    
        STA   $00FF,y
LA544   STY   $71
        LDY   $47
        TXA    
        EOR   #$FF
        AND   #$80
        TAX    
        CPY   #$24
        BEQ   LA556
        CPY   #$3C
        BNE   LA4FC
LA556   LDY   $71
LA558   LDA   $00FF,y
        DEY    
        CMP   #$30
        BEQ   LA558
        CMP   #$2E
        BEQ   LA565
        INY    
LA565   LDA   #$2B
        LDX   $5E
        BEQ   LA599
        BPL   LA575
        LDA   #$00
        SEC    
        SBC   $5E
        TAX    
        LDA   #$2D
LA575   STA   $0101,y
        LDA   #$45
        STA   $0100,y
        TXA    
        LDX   #$2F
        SEC    
LA581   INX    
        SBC   #$0A
        BCS   LA581
        ADC   #$3A
        STA   $0103,y
        TXA    
        STA   $0102,y
        LDA   #$00
        STA   $0104,y
        BEQ   LA59E
LA596   STA   $00FF,y
LA599   LDA   #$00
        STA   $0100,y
LA59E   LDA   #$00
        LDY   #$01
        RTS    
        SKB   DIRECTION
        BRK    
        BRK    
        BRK    
        NOP    
        ASL    
        ASO   DIRECTION,x
        TYA    
        STX   $80,y
        INS   $BDF0,x
        CPY   #$00
        ORA   ($86,x)
        LDY   #$FF
        INS   $F0D8,x
        BRK    
        BRK    
        ASO   ($E8,x)
        INS   $FFFF,x
        SAY   DIRECTION,x
        BRK    
        ASL    
        INS   $FFFF,x
        INS   $DFFF,x
        ASL    
        SKB   DIRECTION
        ASO   ($4B,x)
        CPY   #$FF
        INS   $6073,x
        BRK    
        BRK    
        ASL   Voice2FreqHI
LA5DD   INS   $A8FD,x
        BRK    
        BRK    
        BRK    
        SKW   $9120
        LDX   #$A9
        LAX   ($A0,x)
        LDA   $20
        AND   ($A2,x)
        BEQ   LA660
        LDA   $69
        BNE   LA5F7
        JMP   L9F2D
LA5F7   LDX   #$4E
        LDY   #$00
        JSR   LA259
        LDA   $6E
        BPL   LA611
        JSR   LA358
        LDA   #$4E
        LDY   #$00
        JSR   LA2E0
        BNE   LA611
        TYA    
        LDY   $07
LA611   JSR   LA283
        TYA    
        PHA    
        JSR   LA01E
        LDA   #$4E
        LDY   #$00
        JSR   LA078
        JSR   LA660
        PLA    
        LSR    
        BCC   LA631
LA627   LDA   $61
        BEQ   LA631
        LDA   $66
        EOR   #$FF
        STA   $66
LA631   RTS    
        STA   ($38,x)
        TAX    
        RLA   $0729,y
        ADC   ($34),y
        CLI    
        ROL   $7456,x
        ASL   $7E,x
        LAX   ($1B),y
        RRA   $2F,x
        INC   $85E3
        NOP    
        ORA   $1C84,x
        ROL    
        SKW   $5963
        CLI    
        ASL    
        ROR   $FD75,x
        INS   $C6
        SKB   $31
        HLT    
        CLC    
        BPL   LA5DD
        BRK    
        BRK    
        BRK    
        BRK    
LA660   LDA   #$32
        LDY   #$A6
        JSR   LA05C
        LDA   $70
        ADC   #$50
        BCC   LA670
        JSR   LA2A8
LA670   STA   $56
        JSR   LA294
        LDA   $61
        CMP   #$88
        BCC   LA67E
LA67B   JSR   LA154
LA67E   JSR   LA358
        LDA   $07
        CLC    
        ADC   #$81
        BEQ   LA67B
        SEC    
        SBC   #$01
        PHA    
        LDX   #$05
LA68E   LDA   $69,x
        LDY   $61,x
        STA   $61,x
        STY   $69,x
        DEX    
        BPL   LA68E
        LDA   $56
        STA   $70
        JSR   L9E87
        JSR   LA627
        LDA   #$37
        LDY   #$A6
        JSR   LA6C9
        LDA   #$00
        STA   $6F
        PLA    
        JSR   LA139
        RTS    
LA6B3   STA   $71
        STY   $72
        JSR   LA24F
        LDA   #$57
        JSR   LA078
        JSR   LA6CD
        LDA   #$57
        LDY   #$00
        JMP   LA078
LA6C9   STA   $71
        STY   $72
LA6CD   JSR   LA24C
        LDA   ($71),y
        STA   $67
        LDY   $71
        INY    
        TYA    
        BNE   LA6DC
        INC   $72
LA6DC   STA   $71
        LDY   $72
LA6E0   JSR   LA05C
        LDA   $71
        LDY   $72
        CLC    
        ADC   #$05
        BCC   LA6ED
        INY    
LA6ED   STA   $71
        STY   $72
        JSR   LA066
        LDA   #$5C
        LDY   #$00
        DEC   $67
        BNE   LA6E0
        RTS    
        TYA    
        AND   $44,x
        NOP    
        BRK    
        PLA    
        PLP    
        LDA   ($46),y
        BRK    
        JSR   LA2B0
        BMI   LA73A
        BNE   LA725
        LDA   Timer1Low
        STA   $62
        LDA   Timer1High
        STA   $64
        LDA   Timer2Low
        STA   $63
        LDA   Timer2High
        STA   $65
        JMP   LA74A
LA725   LDA   #$03
        LDY   #$05
        JSR   LA221
        LDA   #$FD
        LDY   #$A6
        JSR   LA05C
        LDA   #$02
        LDY   #$A7
        JSR   LA066
LA73A   LDX   $65
        LDA   $62
        STA   $65
        STX   $62
        LDX   $63
        LDA   $64
        STA   $63
        STX   $64
LA74A   LDA   #$00
        STA   $66
        LDA   $61
        STA   $70
        LDA   #$80
        STA   $61
        JSR   L9F0B
        LDX   #$03
        LDY   #$05
LA75D   JMP   LA259
LA760   LDA   $7C
        STA   $3D
        LDA   $7D
        STA   $3E
        RTS    
LA769   LDA   $3D
        STA   $7C
        LDA   $3E
        STA   $7D
        RTS    
LA772   TYA    
        CLC    
        ADC   $7C
        STA   $7C
        BCC   LA77C
        INC   $7D
LA77C   RTS    
LA77D   TAX    
        BNE   LA782
        LDX   #$1E
LA782   JMP   L8683
LA785   JSR   LFFC0
        BCS   LA77D
        RTS    
LA78B   JSR   LFFD2
        BCS   LA77D
        RTS    
LA791   JSR   LFFCF
        BCS   LA77D
        RTS    

		;
		; CMD command jumps here for kernal processing
		;
LA797   PHA    
        JSR   LFFC9				; Set output vector (jumps through $031e ->$ED18)
        JSR   LA8F8
        TAX    
        PLA    
        BCC   LA7A5
        TXA    
        BCS   LA77D
LA7A5   RTS    
LA7A6   JSR   LFFC6
        JSR   LA8F8
        BCS   LA77D
        RTS    
LA7AF   JSR   LFFE4
        BCS   LA77D
        RTS    
        JSR   L9DE1
        LDA   #$A7
        PHA    
        LDA   #$CE
        PHA    
        LDA   $07F5
        PHA    
        LDA   $07F2
        LDX   $07F3
        LDY   $07F4
        PLP    
        JMP   ($0014)
        PHP    
        STA   $07F2
        STX   $07F3
        STY   $07F4
        PLA    
        STA   $07F5
        RTS    
        JSR   LA86B
LA7E1   LDX   $2D
        LDY   $2E
        LDA   #$2B
        JSR   LFFD8
        JSR   LA8F8
        BCS   LA77D
        RTS    
        LDA   #$01
        BIT   $00A9
        STA   $0A
        JSR   LA86B
LA7FA   LDA   $0A
        LDX   $2B
        LDY   $2C
        JSR   LFFD5
        PHP    
        JSR   LA8F8
        PLP    
        BCS   LA868
        LDA   $0A
        BEQ   LA824
        LDX   #$1C
        JSR   LFFB7
        AND   #$10
        BNE   LA82D
        BIT   Running                 ; BASIC program running?
        BMI   LA823
        JSR   PrintMessage
        ORA   $4B4F
        ORA   $6000
LA824   JSR   LFFB7
        AND   #$BF
        BEQ   LA830
        LDX   #$1D
LA82D   JMP   L8683
LA830   BIT   Running                 ; BASIC program running?
        BMI   LA844
        STX   $2D
        STY   $2E
        JSR   L866F
        JSR   L8818
        JSR   L8A93
        JMP   L870F
LA844   JSR   L8AF1
        JSR   L8818
        JMP   L8AD5
        JSR   LA8B0
        CLC    
        JSR   LA785
        JSR   LA8F8
        BCS   LA868
        RTS    
        JSR   LA8B0
        LDA   $49
        CLC    
        JSR   LFFC3
        JSR   LA8F8
        BCC   LA823
LA868   JMP   LA77D
LA86B   LDA   #$00
        JSR   LFFBD
        LDX   #$01
        LDY   #$00
        JSR   LFFBA
        JSR   LA89D
        JSR   LA8EE
        JSR   LA89D
        JSR   LA897
        LDY   #$00
        STX   $49
        JSR   LFFBA
        JSR   LA89D
        JSR   LA897
        TXA    
        TAY    
        LDX   $49
        JMP   LFFBA
LA897   JSR   LA8A5
        JMP   L9D84
LA89D   JSR   $0479
        BNE   LA8A4
        PLA    
        PLA    
LA8A4   RTS    
LA8A5   JSR   L9491
LA8A8   JSR   $0479
        BNE   LA8A4
        JMP   L94A1
LA8B0   LDA   #$00
        JSR   LFFBD
        JSR   LA8A8
        JSR   L9D84
        STX   $49
        TXA    
        LDX   #$01
        LDY   #$00
        JSR   LFFBA
        JSR   LA89D
        JSR   LA897
        STX   $4A
        LDY   #$00
        LDA   $49
        CPX   #$03
        BCC   LA8D6
        DEY    
LA8D6   JSR   LFFBA
        JSR   LA89D
        JSR   LA897
        TXA    
        TAY    
        LDX   $4A
        LDA   $49
        JSR   LFFBA
        JSR   LA89D
        JSR   LA8A5
LA8EE   JSR   L9C48
        LDX   $22
        LDY   $23
        JMP   LFFBD
LA8F8   PHP    
        PHA    
        LDA   $AE
        CMP   #$04
        BCC   LA903
        JSR   LCD57
LA903   PLA    
        PLP    
        RTS    
LA906   LSR   $0F
LA908   TAX    
        BEQ   LA943
        PHA    
        LDA   $33
        SEC    
        SBC   #$02
        LDY   $34
        BCS   LA916
        DEY    
LA916   STA   $22
        STY   $23
        TXA    
        EOR   #$FF
        SEC    
        ADC   $22
        BCS   LA923
        DEY    
LA923   CPY   $32
        BCC   LA944
        BNE   LA92D
        CMP   $31
        BCC   LA944
LA92D   STA   $35
        STY   $36
        LDY   #$01
        LDA   #$FF
        STA   ($22),y
        DEY    
        PLA    
        STA   ($22),y
        LDX   $35
        LDY   $36
        STX   $33
        STY   $34
LA943   RTS    
LA944   LDA   $0F
        BMI   LA951
        JSR   LA954
        SEC    
        ROR   $0F
        PLA    
        BNE   LA908
LA951   JMP   L8681
LA954   LDX   $16
LA956   CPX   #$19
        BEQ   LA96A
        JSR   LAA57
        BEQ   LA956
        TXA    
        LDY   #$00
        STA   ($5C),y
        TYA    
        INY    
        STA   ($5C),y
        BNE   LA956
LA96A   LDY   #$00
        STY   $58
        LDX   $37
        LDY   $38
        STX   $5F
        STX   $4E
        STX   $35
        STY   $60
        STY   $4F
        STY   $36
        TXA    
LA97F   JSR   LA9EA
        BNE   LA990
LA984   DEY    
        JSR   L8165
        JSR   LAA39
        SEC    
        ROR   $58
        BNE   LA97F
LA990   BIT   $58
        BPL   LA9D6
        LDX   #$00
        STX   $58
        LDA   #$02
LA99A   LDY   #$01
        JSR   L8165
        STA   ($5F),y
        DEY    
        JSR   L8165
        STA   ($5F),y
        JSR   $04B0
        TAX    
        JSR   LAA48
        STA   $35
        STY   $36
        TXA    
        JSR   LAA39
        TXA    
        TAY    
LA9B8   DEY    
        JSR   L8165
        STA   ($5F),y
        DEX    
        BNE   LA9B8
        LDY   #$02
LA9C3   LDA   $005E,y
        STA   ($22),y
        DEY    
        BNE   LA9C3
        LDA   $4E
        LDY   $4F
        JSR   LA9EA
        BEQ   LA984
        BNE   LA99A
LA9D6   LDY   #$00
        JSR   $04B0
        TAX    
        JSR   LAA48
        STA   $35
        STY   $36
        TXA    
        JSR   LAA39
        JMP   LA97F
LA9EA   CPY   $34
        BCC   LAA18
        BNE   LA9F6
        CMP   $33
        BEQ   LAA18
        BCC   LAA18
LA9F6   BIT   $58
        BMI   LA9FF
        LDA   #$02
        JSR   LAA48
LA9FF   LDA   #$02
        JSR   LAA39
        LDY   #$01
        JSR   L8165
        CMP   #$FF
        BNE   LAA0E
        RTS    
LAA0E   JSR   L8165
        STA   $0022,y
        DEY    
        BPL   LAA0E
        RTS    
LAA18   LDX   $16
LAA1A   CPX   #$19
        BEQ   LAA2E
        JSR   LAA57
        BEQ   LAA1A
        LDY   #$00
        STA   ($5C),y
        INY    
        LDA   #$FF
        STA   ($5C),y
        BNE   LAA1A
LAA2E   PLA    
        PLA    
        LDA   $35
        LDY   $36
        STA   $33
        STY   $34
        RTS    
LAA39   EOR   #$FF
        SEC    
        ADC   $4E
        LDY   $4F
        BCS   LAA43
        DEY    
LAA43   STA   $4E
        STY   $4F
        RTS    
LAA48   EOR   #$FF
        SEC    
        ADC   $5F
        LDY   $60
        BCS   LAA52
        DEY    
LAA52   STA   $5F
        STY   $60
        RTS    
LAA57   DEX    
        LDA   DIRECTION,x
        STA   $5D
        DEX    
        LDA   DIRECTION,x
        STA   $5C
        DEX    
        LDA   DIRECTION,x
        PHA    
        CLC    
        ADC   $5C
        STA   $5C
        BCC   LAA6E
        INC   $5D
LAA6E   PLA    
        RTS    
        LDA   #$EC
        LDY   #$AA
        JSR   LA066
LAA77   JSR   LA291
        LDA   #$F1
        LDY   #$AA
        LDX   $6E
        JSR   LA18C
        JSR   LA291
        JSR   LA358
        LDA   #$00
        STA   $6F
        JSR   L9E87
        LDA   #$F6
        LDY   #$AA
        JSR   LA06C
        LDA   $66
        PHA    
        BPL   LAAA9
        JSR   LA062
        LDA   $66
        BMI   LAAAC
        LDA   $12
        EOR   #$FF
        STA   $12
LAAA9   JSR   LA627
LAAAC   LDA   #$F6
        LDY   #$AA
        JSR   LA066
        PLA    
        BPL   LAAB9
        JSR   LA627
LAAB9   LDA   #$FB
        LDY   #$AA
        JMP   LA6B3
        JSR   LA24F
        LDA   #$00
        STA   $12
        JSR   LAA77
        LDX   #$4E
        LDY   #$00
        JSR   LA75D
        LDA   #$57
        LDY   #$00
        JSR   LA221
        LDA   #$00
        STA   $66
        LDA   $12
        JSR   LAAE8
        LDA   #$4E
        LDY   #$00
        JMP   LA194
LAAE8   PHA    
        JMP   LAAA9
        STA   ($49,x)
        ASO   $A2DA
        AXS   ($49,x)
        ASO   $A2DA
        RRA   DIRECTION,x
        BRK    
        BRK    
        ORA   $84
        INC   $1A
        AND   $861B
        PLP    
        ASO   $FB
        SED    
        AXS   $99
        PLA    
        SKB   IO
        AXS   $23
        AND   $DF,x
        SBC   ($86,x)
        LDA   $5D
        INS   $28
        AXS   ($49,x)
        ASO   $A2DA
        LDA   $66
        PHA    
        BPL   LAB22
        JSR   LA627
LAB22   LDA   $61
        PHA    
        CMP   #$81
        BCC   LAB30
        LDA   #$F0
        LDY   #$9F
        JSR   LA072
LAB30   LDA   #$4A
        LDY   #$AB
        JSR   LA6B3
        PLA    
        CMP   #$81
        BCC   LAB43
        LDA   #$EC
        LDY   #$AA
        JSR   LA06C
LAB43   PLA    
        BPL   LAB49
        JMP   LA627
LAB49   RTS    
        ???   
        ROR   $B3,x
        AXS   ($BD,x)
        DCM   ($79),y
        ???   
        LDX   $F5
        RRA   $FC83,y
        BCS   LAB6A
        SKW   $1F0C
        RRA   $CA
        SKW   $53DE
        SAX   #$C1
        ADC   $6414,x
        BVS   LABB5
        ADC   $EAB7,x
        EOR   ($7A),y
        ADC   $3063,x
        DEY    
        ROR   $927E,x
        SKB   $99
        NOP    
        ROR   $CC4C,x
        STA   ($C7),y
        RRA   $AAAA,x
        TAX    
        ASO   ($81),y
        BRK    
        BRK    
        BRK    
        BRK    
        SKB   $8A
        STA   $8CA7
        DEC   $D7,x
        CMP   $20,x
        DEC   $A9B6,x
        BRK    
        LDX   #$0A
        STX   $03
        STA   $04
        STX   $05
        STA   $06
        STA   $5A
        STA   $5B
        JSR   $0479
        BEQ   LAC0D
        JSR   L8E3E
        LDA   $08
        BEQ   LABB6
        LDA   $14
        LDX   $15
        STA   $03
        STX   $04
LABB6   JSR   $0479
        BEQ   LAC0D
        JSR   L9491
        JSR   L8E3E
        LDA   $08
        BEQ   LABD5
        LDA   $14
        LDX   $15
        STA   $05
        STX   $06
        BNE   LABD5
        TAX    
        BNE   LABD5
LABD2   JMP   L991C             ; Illegal Quantity error
LABD5   JSR   $0479
        BEQ   LAC0D
        JSR   L9491
        JSR   L8E3E
        LDA   $14
        LDX   $15
        STA   $5A
        STX   $5B
        JSR   L8A3D
        LDA   $5F
        LDX   $60
        STA   $58
        STX   $59
        LDA   $03
        LDX   $04
        STA   $14
        STX   $15
        JSR   L8A3D
        LDA   $60
        SEC    
        SBC   $59
        BCC   LABD2
        BNE   LAC0D
        LDA   $5F
        SBC   $58
        BCC   LABD2
LAC0D   JSR   L8AF1
LAC10   JSR   LAD86
        JSR   LAD86
        BNE   LAC55
        JSR   LAD59
LAC1B   JSR   LAD86
        JSR   LAD86
        BNE   LAC26
        JMP   LAEB3
LAC26   JSR   LAD86
        STA   $14
        INY    
        JSR   $04A5
        SEC    
        SBC   $5B
        BCC   LAC4D
        BNE   LAC3C
        LDA   $14
        SBC   $5A
        BCC   LAC4D
LAC3C   LDA   $62
        STA   ($3B),y
        DEY    
        LDA   $63
        STA   ($3B),y
        JSR   LAD86
        JSR   LAD73
        BEQ   LAC1B
LAC4D   JSR   LAD86
        JSR   LAD80
        BEQ   LAC1B
LAC55   JSR   LAD86
        JSR   LAD86
LAC5B   JSR   LAD86
LAC5E   CMP   #$22
        BNE   LAC6D
LAC62   JSR   LAD86
        BEQ   LAC10
        CMP   #$22
        BNE   LAC62
        BEQ   LAC5B
LAC6D   TAX    
        BEQ   LAC10
        BPL   LAC5B
        LDX   #$08
LAC74   CMP   $AB86,x
        BEQ   LAC89
        DEX    
        BNE   LAC74
        CMP   #$CB
        BNE   LAC5B
        JSR   $0473
        BEQ   LAC10
        CMP   #$A4
        BNE   LAC5B
LAC89   LDA   $3B
        STA   $0259
        LDA   $3C
        STA   $025A
        JSR   $0473
        BCS   LAC5E
        JSR   L8E3E
        JSR   LACEE
        LDA   $0259
        STA   $3B
        LDA   $025A
        STA   $3C
        LDY   #$00
        LDX   #$00
LACAC   LDA   $0101,x
        BEQ   LACCD
        PHA    
        JSR   $0473
        BCC   LACC5
        JSR   LAD42
        INC   $6C
        JSR   LADBB
        INC   $2D
        BNE   LACC5
        INC   $2E
LACC5   PLA    
        LDY   #$00
        STA   ($3B),y
        INX    
        BNE   LACAC
LACCD   JSR   $0473
        BCS   LACE7
LACD2   JSR   LAD42
        DEC   $6C
        JSR   LADA2
        LDA   $2D
        BNE   LACE0
        DEC   $2E
LACE0   DEC   $2D
        JSR   $0479
        BCC   LACD2
LACE7   CMP   #$2C
        BEQ   LAC89
        JMP   LAC5E
LACEE   JSR   LAD59
LACF1   JSR   LAD86
        BNE   LAD03
        JSR   LAD86
        BNE   LAD06
        LDA   #$FF
        STA   $62
        STA   $63
        BMI   LAD2D
LAD03   JSR   LAD86
LAD06   JSR   LAD86
        STA   $58
        CMP   $14
        BNE   LAD36
        JSR   LAD86
        STA   $59
        CMP   $15
        BNE   LAD3B
        SEC    
        SBC   $5B
        BCC   LAD25
        BNE   LAD2D
        LDA   $14
        SBC   $5A
        BCS   LAD2D
LAD25   LDA   $14
        STA   $63
        LDA   $15
        STA   $62
LAD2D   LDX   #$90
        SEC    
        JSR   LA2CE
        JMP   LA46F
LAD36   JSR   LAD86
        STA   $59
LAD3B   JSR   LAD64
        BEQ   LACF1
        CMP   $A5EA,y
        RLA   $2285,y
        LDA   $3C
        STA   $23
        LDA   $2D
        STA   $24
        LDA   $2E
        STA   $25
        LDY   #$00
        STY   $0B
        STY   $6C
        RTS    
LAD59   LDA   $03
        STA   $63
        LDA   $04
        STA   $62
        JMP   L8AF1
LAD64   LDA   $59
        SEC    
        SBC   $5B
        BCC   LAD80
        BNE   LAD73
        LDA   $58
        SBC   $5A
        BCC   LAD80
LAD73   LDA   $63
        CLC    
        ADC   $05
        STA   $63
        LDA   $62
        ADC   $06
        STA   $62
LAD80   JSR   LAD86
        BNE   LAD80
        RTS    
LAD86   LDY   #$00
        INC   $3B
        BNE   LAD8E
        INC   $3C
LAD8E   JMP   $04A5
LAD91   LDA   $22
        CMP   $24
        BNE   LAD9B
        LDA   $23
        CMP   $25
LAD9B   RTS    
LAD9C   INC   $22
        BNE   LADA2
        INC   $23
LADA2   LDY   $0B
        INY    
        JSR   $04B0
        LDY   $6C
        INY    
        STA   ($22),y
        JSR   LAD91
        BNE   LAD9C
        RTS    
LADB3   LDA   $24
        BNE   LADB9
        DEC   $25
LADB9   DEC   $24
LADBB   LDY   $0B
        JSR   $04BB
        LDY   $6C
        STA   ($24),y
        JSR   LAD91
        BNE   LADB3
        RTS    
        LDA   #$80
        STA   $10
        JSR   L8E7C
        LDA   #$81
        STA   $02
        JSR   L8871
        BEQ   LADE2
        LDY   #$12
        JSR   L8905
        JSR   LA760
LADE2   JSR   LA769
        JSR   L8DBE
        TYA    
        LDY   #$11
        CLC    
        ADC   $3B
        STA   ($7C),y
        LDA   $3C
        ADC   #$00
        DEY    
        STA   ($7C),y
        LDA   $3A
        DEY    
        STA   ($7C),y
        LDA   $39
        DEY    
        STA   ($7C),y
        LDA   #$A4
        JSR   L9493
        JSR   L9317
        JSR   L9314
        LDA   $66
        ORA   #$7F
        AND   $62
        STA   $62
        LDX   #$04
        LDY   #$0D
LAE18   LDA   $61,x
        STA   ($7C),y
        DEX    
        DEY    
        BPL   LAE18
        LDA   #$F0
        LDY   #$9F
        JSR   LA221
        JSR   $0479
        CMP   #$A9
        BNE   LAE34
        JSR   $0473
        JSR   L9314
LAE34   JSR   LA2B0
        PHA    
        JSR   LA2A0
        PLA    
        LDY   #$08
        LDX   #$05
LAE40   STA   ($7C),y
        LDA   $60,x
        DEY    
        DEX    
        BPL   LAE40
        LDA   $4A
        STA   ($7C),y
        LDA   $49
        DEY    
        STA   ($7C),y
        LDA   #$81
        DEY    
        STA   ($7C),y
        RTS    
LAE57   JMP   L94A1
        JSR   LB6DE
        JSR   $0479
        BEQ   LAE57
        JSR   LAECA
        LDA   $5F
        LDX   $60
        STA   $24
        STX   $25
        JSR   L8A3D
        BCC   LAE87
        LDY   #$01
        JSR   $04D1
        DEY    
        TAX    
        BNE   LAE80
        JSR   $04D1
        BEQ   LAE87
LAE80   JSR   $04D1
        STA   $5F
        STX   $60
LAE87   LDA   $24
        SEC    
        SBC   $5F
        TAX    
        LDA   $25
        SBC   $60
        TAY    
        BCS   LAEB3
        TXA    
        CLC    
        ADC   $2D
        STA   $2D
        TYA    
        ADC   $2E
        STA   $2E
        LDY   #$00
LAEA1   JSR   $04D1
        STA   ($24),y
        INY    
        BNE   LAEA1
        INC   $60
        INC   $25
        LDA   $2E
        CMP   $25
        BCS   LAEA1
LAEB3   JSR   L8818
        LDA   $22
        LDX   $23
        CLC    
        ADC   #$02
        STA   $2D
        BCC   LAEC2
        INX    
LAEC2   STX   $2E
        JSR   L8A93
        JMP   L867E
LAECA   BEQ   LAED2
        BCC   LAED2
        CMP   #$AB
        BNE   LAEF4
LAED2   JSR   L8E3E
        JSR   L8A3D
        JSR   $0479
        BEQ   LAEE9
        CMP   #$AB
        BNE   LAEF4
        JSR   $0473
        JSR   L8E3E
        BNE   LAEF4
LAEE9   LDA   $08
        BNE   LAEF3
        LDA   #$FF
        STA   $14
        STA   $15
LAEF3   RTS    
LAEF4   JMP   L94A1
LAEF7   LDX   #$FF
        STX   $02E0
        JSR   $0473
        JSR   L932C
        JSR   L931A
        LDA   $64
        PHA    
        LDA   $65
        PHA    
        LDY   #$02
LAF0D   JSR   $04DC
        DEY    
        STA   $003D,y
        BNE   LAF0D
        JSR   $04DC
        STA   $02DF
        TAY    
        BEQ   LAF2A
LAF1F   DEY    
        JSR   L8171
        CMP   #$23
        BEQ   LAF2D
        TYA    
        BNE   LAF1F
LAF2A   JMP   L94A1
LAF2D   LDA   #$3B
LAF2F   JSR   L9493
        STY   $76
        STY   $02CD
        JSR   L932C
        BIT   $0D
        BPL   LAF77
        JSR   LB170
        JSR   LB2B7
        LDX   $02D5
        BEQ   LAF5E
        LDX   #$00
        SEC    
        LDA   $02DB
        SBC   $77
        BCC   LAF5E
        LDX   #$3D
        CPX   $02D5
        BNE   LAF5D
        LSR    
        ADC   #$00
LAF5D   TAX    
LAF5E   LDY   #$00
LAF60   TXA    
        BEQ   LAF68
        DEX    
LAF64   LDA   #$20
        BNE   LAF70
LAF68   CPY   $77
        BCS   LAF64
        JSR   $04B0
        INY    
LAF70   JSR   LB2B0
        BNE   LAF60
        BEQ   LAF9B
LAF77   JSR   LA46F
        LDY   #$FF
LAF7C   INY    
        LDA   $0100,y
        BNE   LAF7C
        TYA    
        JSR   L9B5C
        LDY   #$00
LAF88   LDA   $0100,y
        BEQ   LAF92
        STA   ($62),y
        INY    
        BNE   LAF88
LAF92   JSR   L9BB0
        JSR   LB170
        JSR   LAFBB
LAF9B   JSR   $0479
        CMP   #$2C
        BEQ   LAF2F
        SEC    
        ROR   $76
        JSR   LB2B7
        PLA    
        TAY    
        PLA    
        JSR   L9C52
        JSR   $0479
        CMP   #$3B
        BEQ   LAFB8
        JMP   L903E
LAFB8   JMP   $0473
LAFBB   LDA   $04E7
        STA   $02DD
        LDA   #$FF
LAFC3   STA   $02DC
        JMP   LAFCB
LAFC9   STX   $82
LAFCB   CPY   $77
        BEQ   LB002
        LDA   $0100,y
        INY    
        CMP   #$20
        BEQ   LAFCB
        CMP   #$2D
        BEQ   LAFC3
        CMP   #$2E
        BEQ   LAFC9
        CMP   #$45
        BEQ   LAFF4
        STA   $0100,x
        STX   $02CE
        INX    
        BIT   $82
        BPL   LAFCB
        INC   $02D4
        JMP   LAFCB
LAFF4   LDA   $0100,y
        CMP   #$2D
        BNE   LAFFE
        ROR   $02D2
LAFFE   INY    
        STY   $02D3
LB002   LDA   $82
        BPL   LB008
        STX   $82
LB008   JSR   LB2B7
        LDA   $02D6
        CMP   #$FF
        BEQ   LB03B
        LDA   $02D9
        BEQ   LB056
        LDA   $02D3
        BNE   LB02E
        LDX   $02CE
        JSR   LB145
        DEC   $0102,x
        INX    
        STX   $02D3
        JSR   LB1CC
        BEQ   LB053
LB02E   LDY   $02D8
        BNE   LB04A
        LDY   $02DC
        BMI   LB04A
        LDA   $02D6
LB03B   BEQ   LB0A7
        DEC   $02D6
        BNE   LB047
        LDA   $02D7
        BEQ   LB0A7
LB047   INC   $02D1
LB04A   JSR   LB0BF
        JSR   LB18A
        JSR   LB0BF
LB053   JMP   LB1ED
LB056   LDY   $02D3
        BEQ   LB071
        STA   $77
        SEC    
        ROR   $02DA
        LDY   $82
        LDA   $02D2
        BPL   LB06E
        JSR   LB0F8
        JMP   LB07A
LB06E   JSR   LB0D9
LB071   LDY   $82
        BEQ   LB07A
        JSR   LB1D0
        BEQ   LB080
LB07A   JSR   LB18A
        JMP   LB083
LB080   DEC   $02D4
LB083   SEC    
        LDA   $02D6
        SBC   $02D4
        BCC   LB0A7
        STA   $02D1
        LDY   $02D8
        BNE   LB0AF
        LDY   $02DC
        BMI   LB0AF
        TAY    
        BEQ   LB0A7
        DEY    
        BNE   LB0B2
        LDA   $02D7
        ORA   $02D4
        BNE   LB053
LB0A7   LDA   #$2A
LB0A9   JSR   LB2B0
        BNE   LB0A9
        RTS    
LB0AF   TAY    
        BEQ   LB053
LB0B2   LDA   $02D4
        BNE   LB053
        DEC   $02D1
        INC   $76
        JMP   LB053
LB0BF   SEC    
        LDA   $02D6
        SBC   $02D4
        BEQ   LB101
        LDY   $82
        BCC   LB0E2
        STA   $77
LB0CE   CPY   $02CE
        BEQ   LB0D5
        BCS   LB0D6
LB0D5   INY    
LB0D6   INC   $02D4
LB0D9   JSR   LB10E
        DEC   $77
        BNE   LB0CE
        BEQ   LB0FF
LB0E2   EOR   #$FF
        ADC   #$01
        STA   $77
LB0E8   CPY   $02CD
        BEQ   LB0F4
        DEY    
        DEC   $02D4
        JMP   LB0F6
LB0F4   INC   $76
LB0F6   LDA   #$80
LB0F8   JSR   LB110
        DEC   $77
        BNE   LB0E8
LB0FF   STY   $82
LB101   RTS    
LB102   BNE   LB13D
        EOR   #$09
        STA   $0100,x
        DEX    
        CPX   $02D3
        RTS    
LB10E   LDA   #$00
LB110   LDX   $02D3
        INX    
        BIT   $02DA
        BMI   LB129
        EOR   $02D2
        BEQ   LB129
LB11E   JSR   LB153
        JSR   LB102
        BCS   LB11E
        JMP   L9FB2
LB129   LDA   $0100,x
        DEC   $0100,x
        CMP   #$30
        JSR   LB102
        BCS   LB129
        BIT   $02DA
        BPL   LB140
        STY   $82
LB13D   PLA    
        PLA    
        RTS    
LB140   LDA   $02D2
        EOR   #$80
LB145   STA   $02D2
        LDA   #$30
        STA   $0101,x
        LDA   #$31
        STA   $0102,x
        RTS    
LB153   LDA   $0100,x
        INC   $0100,x
        CMP   #$39
        RTS    
LB15C   CLC    
        INY    
        BEQ   LB165
        CPY   $02DF
        BCC   LB169
LB165   LDY   $76
        BNE   LB13D
LB169   JSR   L8171
        INC   $02DB
        RTS    
LB170   JSR   L9C4E
        STA   $77
        LDX   #$0A
        LDA   #$00
LB179   STA   $02D1,x
        DEX    
        BPL   LB179
        STX   $02D0
        STX   $82
        STX   $02CF
        TAX    
        TAY    
        RTS    
LB18A   CLC    
        LDA   $82
        ADC   $02D7
        BCS   LB1CB
        SEC    
        SBC   $76
        BCC   LB1CB
        CMP   $02CE
        BEQ   LB19E
        BCS   LB1CB
LB19E   CMP   $02CD
        BCC   LB1CB
        TAX    
        LDA   $0100,x
        CMP   #$35
        BCC   LB1CB
LB1AB   CPX   $02CD
        BEQ   LB1BA
        DEX    
        JSR   LB153
        STX   $02CE
        BEQ   LB1AB
        RTS    
LB1BA   LDA   #$31
        STA   $0100,x
        INX    
        STX   $82
        DEC   $76
        BPL   LB1CB
        INC   $76
        INC   $02D4
LB1CB   RTS    
LB1CC   LDY   $82
        BEQ   LB1E7
LB1D0   LDY   $02CD
LB1D3   LDA   $0100,y
        CMP   #$30
        RTS    
LB1D9   INC   $82
        JSR   LB10E
        INC   $02CD
        CPY   $02CE
        BEQ   LB1CB
        INY    
LB1E7   JSR   LB1D3
        BEQ   LB1D9
        RTS    
LB1ED   LDA   $02CF
        BMI   LB1F4
        INC   $76
LB1F4   LDX   $02CD
        DEX    
        LDY   $02DE
LB1FB   JSR   L8171
        INY    
        CMP   #$2C
        BNE   LB214
        BIT   $02D0
        BMI   LB20E
        LDA   $04E8
        JMP   LB276
LB20E   LDA   $02DD
        JMP   LB276
LB214   CMP   #$2E
        BNE   LB21E
        LDA   $04E9
        JMP   LB276
LB21E   CMP   #$2B
        BEQ   LB25D
        CMP   #$2D
        BEQ   LB258
        CMP   #$5E
        BNE   LB28D
        LDA   #$45
        JSR   LB2B0
        LDY   $02D3
        JSR   LB1D3
        BNE   LB23D
        INY    
        JSR   LB1D3
        BEQ   LB244
LB23D   LDA   #$2D
        BIT   $02D2
        BMI   LB246
LB244   LDA   #$2B
LB246   JSR   LB2B0
        LDX   $02D3
        LDA   $0100,x
        JSR   LB2B0
        LDY   $02E0
        JMP   LB26C
LB258   LDA   $02DC
        BMI   LB20E
LB25D   LDA   $02DC
        JMP   LB276
LB263   LDA   $76
        BNE   LB27C
        CPX   $02CE
        BEQ   LB271
LB26C   INX    
        LDA   $0100,x
        BIT   $30A9
LB273   LSR   $02D0
LB276   JSR   LB2B0
        BNE   LB1FB
        RTS    
LB27C   DEC   $76
        LDA   $02CF
        BMI   LB271
        SEC    
        ROR   $02CF
        LDA   $04EA
        JMP   LB273
LB28D   LDA   $02D1
        BEQ   LB263
        DEC   $02D1
LB295   BEQ   LB29A
        JMP   LB20E
LB29A   LDA   $02D8
        BMI   LB295
LB29F   JSR   L8171
        CMP   #$2C
        BNE   LB258
        LDA   $02DD
        JSR   LB2B0
        INY    
        JMP   LB29F
LB2B0   JSR   L90B2
        DEC   $02DB
        RTS    
LB2B7   LDY   $02E0
LB2BA   JSR   LB15C
        JSR   LB36C
        BNE   LB2D6
        STY   $02DE
        BCC   LB2E1
        TAX    
LB2C8   JSR   LB15C
        BCS   LB2D2
        JSR   LB374
        BEQ   LB2DC
LB2D2   LDY   $02DE
        TXA    
LB2D6   JSR   L90B2
        JMP   LB2BA
LB2DC   BCS   LB2C8
        LDY   $02DE
LB2E1   LDX   $76
        BNE   LB35F
        STX   $02DB
        DEY    
LB2E9   DEC   $02DB
LB2EC   JSR   LB15C
        BCS   LB365
        CMP   #$2C
        BEQ   LB2EC
        JSR   LB343
        BCC   LB2E9
        CMP   #$2E
        BNE   LB306
        INX    
        CPX   #$02
        BCC   LB2EC
LB303   JMP   L94A1
LB306   JSR   LB378
        BNE   LB316
        BCC   LB310
        STA   $02D5
LB310   INC   $02D6,x
        JMP   LB2EC
LB316   CMP   #$24
        BNE   LB329
        BIT   $02CF
        BPL   LB310
        CLC    
        ROR   $02CF
        DEC   $02D6
        JMP   LB310
LB329   CMP   #$5E
        BNE   LB343
        LDX   #$02
LB32F   JSR   LB15C
        BCS   LB303
        CMP   #$5E
        BNE   LB303
        DEX    
        BPL   LB32F
        INC   $02D9
        JSR   LB15C
        BCS   LB365
LB343   CMP   #$2B
        BNE   LB360
        LDA   $02DC
        BPL   LB351
        LDA   #$2B
        STA   $02DC
LB351   LDA   $02D8
        BNE   LB303
        ROR   $02D8
        STY   $02E0
        INC   $02DB
LB35F   RTS    
LB360   CMP   #$2D
        BEQ   LB351
        SEC    
LB365   STY   $02E0
        DEC   $02E0
        RTS    
LB36C   CMP   #$2B
        BEQ   LB385
        CMP   #$2D
        BEQ   LB385
LB374   CMP   #$2E
        BEQ   LB385
LB378   CMP   #$3D
        BEQ   LB385
        CMP   #$3E
        BEQ   LB385
        CMP   #$23
        BNE   LB385
        CLC    
LB385   RTS    
LB386   LDA   $64
        STA   $04EB
        LDA   $65
        STA   $04EC
        JSR   L932C
        JSR   L931A
        LDA   $64
        STA   $04ED
        LDA   $65
        STA   $04EE
        LDX   #$01
        STX   $65
        JSR   $0479
        CMP   #$29
        BEQ   LB3AE
        JSR   L9DD8
LB3AE   JSR   L948B
        LDX   $65
        BNE   LB3B8
        JMP   L991C             ; Illegal Quantity error
LB3B8   DEX    
        STX   $61
        LDX   #$03
LB3BD   LDA   $04EB,x
        STA   $57,x
        DEX    
        BPL   LB3BD
        LDY   #$02
LB3C7   JSR   L8175
        STA   $005B,y
        JSR   L8179
        STA   $005E,y
        DEY    
        BPL   LB3C7
        LDA   $5E
        BEQ   LB411
LB3DA   LDA   #$00
        STA   $62
        CLC    
        LDA   $5E
        ADC   $61
        BCS   LB411
        CMP   $5B
        BCC   LB3EB
        BNE   LB411
LB3EB   LDY   $62
        CPY   $5E
        BEQ   LB40C
        TYA    
        CLC    
        ADC   $61
        TAY    
        JSR   L8169
        STA   $78
        LDY   $62
        JSR   L816D
        CMP   $78
        BEQ   LB408
        INC   $61
        BNE   LB3DA
LB408   INC   $62
        BNE   LB3EB
LB40C   INC   $61
        LDA   $61
        BIT   $00A9
        PHA    
        LDA   $04ED
        LDY   $04EE
        JSR   L9C52
        LDA   $04EB
        LDY   $04EC
        JSR   L9C52
        PLA    
        TAY    
        JMP   L9A81
        JSR   L9A86
        JSR   $0479
        BEQ   LB43A
        JSR   L9DE1
        STY   $04F2
        BIT   $FFA9
        STA   $04F3
        RTS    
        JSR   L9A86
        LDX   $04F1
        INX    
        BEQ   LB4B9
        JSR   $0479
        BEQ   LB495
        BCC   LB48A
        CMP   #$82
        BNE   LB4B6
        JSR   LB495
        LDY   #$00
        JSR   $04A5
        BNE   LB484
        INY    
        JSR   $04A5
        BNE   LB46D
        INY    
        JSR   $04A5
        BNE   LB46D
        JMP   L867E
LB46D   LDY   #$03
        JSR   $04A5
        STA   $39
        INY    
        JSR   $04A5
        STA   $3A
        TYA    
        CLC    
        ADC   $3B
        STA   $3B
        BCC   LB484
        INC   $3C
LB484   JSR   $0473
        JMP   L8DB0
LB48A   JSR   L9DE1
        STA   $15
        JSR   LB4A4
        JMP   L8D69
LB495   LDX   #$01
LB497   LDA   $04F0,x
        STA   $39,x
        LDA   $04F5,x
        STA   $3B,x
        DEX    
        BPL   LB497
LB4A4   LDX   #$FF
        STX   $04EF
        STX   $04F0
        STX   $04F1
        LDX   $04F4
        STX   $04F3
        RTS    
LB4B6   JMP   L94A1
LB4B9   LDX   #$1F
        JMP   L8683
        JSR   L9D87
        DEX    
        TXA    
        CMP   #$24
        BCS   LB4FB
        JSR   L8653             ; Find the START address of error message.
        LDY   #$FF
        LDX   #$00
LB4CE   INX    
LB4CF   INY    
        LDA   ($24),y
        BMI   LB4DA
        CMP   #$20
        BCC   LB4CF
        BCS   LB4CE
LB4DA   TXA    
        JSR   L9B5C
        LDX   #$00
        LDY   #$FF
LB4E2   INY    
        LDA   ($24),y
        CMP   #$20
        BCC   LB4E2
        JSR   LB4FE
        PHA    
        AND   #$7F
        STA   ($62),y
        JSR   LB4FE
        INX    
        PLA    
        BPL   LB4E2
        JMP   L9CCA
LB4FB   JMP   L991C             ; Illegal Quantity error
LB4FE   PHA    
        TXA    
        PHA    
        TYA    
        TAX    
        PLA    
        TAY    
        PLA    
        RTS    
        JSR   L9317
        LDA   $14
        PHA    
        LDA   $15
        PHA    
        JSR   L9DE4
        LDA   #$04
        JSR   L9B5C
        LDY   #$00
        LDA   $15
        JSR   LB52D
        LDA   $14
        JSR   LB52D
        PLA    
        STA   $15
        PLA    
        STA   $14
        JMP   L9CCA
LB52D   PHA    
        LSR    
        LSR    
        LSR    
        LSR    
        JSR   LB536
        PLA    
LB536   AND   #$0F
        CMP   #$0A
        BCC   LB53E
        ADC   #$06
LB53E   ADC   #$30
        STA   ($62),y
        INY    
        RTS    
        JSR   L9C48
        TAY    
        DEY    
        CPY   #$04
        BCS   LB4FB
LB54D   JSR   $04B0
        STA   $04E7,y
        DEY    
        BPL   LB54D
        RTS    
LB557   LDY   #$01
LB559   LDA   $003B,y
        STA   $04F8,y
        LDA   $0039,y
        STA   $04FA,y
        DEY    
        BPL   LB559
        JSR   $0479
        BEQ   LB589
        CMP   #$FC
        BEQ   LB582
        CMP   #$FD
        BNE   LB5B4
        JSR   LB64C
        LDA   $61
        BNE   LB589
LB57C   JSR   $0479
        JMP   LB5BA
LB582   JSR   LB64C
        LDA   $61
        BNE   LB57C
LB589   LDY   #$05
        JSR   L8905
        DEY    
        LDA   $04F9
        STA   ($7C),y
        DEY    
        LDA   $04F8
        STA   ($7C),y
        DEY    
        LDA   $04FB
        STA   ($7C),y
        DEY    
        LDA   $04FA
        STA   ($7C),y
        DEY    
        LDA   #$EB
        STA   ($7C),y
        RTS    
        JSR   LB614
        JSR   $0479
        BEQ   LB5BA
LB5B4   JMP   L94A1
LB5B7   JSR   $0473
LB5BA   BEQ   LB5D9
        CMP   #$EC
        BEQ   LB600
        CMP   #$22
        BEQ   LB5CE
        CMP   #$EB
        BNE   LB5B7
        JSR   LB5B7
        JMP   LB57C
LB5CE   JSR   $0473
        BEQ   LB5D9
        CMP   #$22
        BNE   LB5CE
        BEQ   LB5B7
LB5D9   CMP   #$3A
        BEQ   LB5B7
        BIT   Running                 ; BASIC program running?
        BPL   LB625
        LDY   #$02
        JSR   $04A5
        BEQ   LB625
        INY    
        JSR   $04A5
        STA   $39
        INY    
        JSR   $04A5
        STA   $3A
        TYA    
        CLC    
        ADC   $3B
        STA   $3B
        BCC   LB5B7
        INC   $3C
        BNE   LB5B7
LB600   JMP   L8DB0
        BEQ   LB632
        CMP   #$FD
        BEQ   LB62D
        CMP   #$FC
        BNE   LB5B4
        JSR   LB64C
        LDA   $61
        BEQ   LB632
LB614   LDA   #$EB
        STA   $02
        JSR   L8871
        BNE   LB628
        JSR   LA769
        LDY   #$05
        JMP   LA772
LB625   LDX   #$20
        BIT   $21A2
        JMP   L8683
LB62D   JSR   LB64C
        BEQ   LB614
LB632   JSR   LB614
        DEY    
        LDA   ($3D),y
        STA   $3C
        DEY    
        LDA   ($3D),y
        STA   $3B
        DEY    
        LDA   ($3D),y
        JSR   LCD7F
        LDA   ($3D),y
        STA   $39
        JMP   LB557
LB64C   JSR   $0473
        JMP   L932C
        LDA   #$FF
        BIT   $00A9
        STA   $02EB
        RTS    
        JSR   L948E
        JSR   L96A5
        STA   $49
        STY   $4A
        JSR   L931A
        JSR   L9DD8
        DEX    
        STX   $77
        CMP   #$29
        BEQ   LB676
        JSR   L9DD8
        BIT   $FFA2
        STX   $78
        JSR   L948B
        LDA   #$B2
        JSR   L9493
        JSR   L932C
        JSR   L931A
        LDY   #$02
LB68A   LDA   #$49
        JSR   $0494
        STA   $005B,y
        JSR   $04DC
        STA   $005E,y
        DEY    
        BPL   LB68A
        SEC    
        LDA   $5F
        SBC   $77
        STA   $5F
        BCS   LB6A6
        DEC   $60
LB6A6   LDA   $78
        CMP   $5E
        BCC   LB6AE
        LDA   $5E
LB6AE   TAX    
        BEQ   LB6C7
        CLC    
        ADC   $77
        BCS   LB6CA
        CMP   $5B
        BCC   LB6BC
        BNE   LB6CA
LB6BC   LDY   $77
LB6BE   JSR   L816D
        STA   ($5C),y
        INY    
        DEX    
        BNE   LB6BE
LB6C7   JMP   L9C4E
LB6CA   JMP   L991C             ; Illegal Quantity error
        JSR   LB6DE
        JSR   L8E3E
        LDA   $14
        STA   $73
        LDA   $15
        STA   $74
        JMP   L867E
LB6DE   BIT   Running                 ; BASIC program running?
        BMI   LB6E3
        RTS    
LB6E3   LDX   #$22
        JMP   L8683
        LDX   $04EF
        INX    
        BEQ   LB709
        LDA   $04F0
        LDY   $04F1
        STA   $14
        STY   $15
        JSR   L8A3D
        BCC   LB709
        ROR   $53
        JSR   L903E
        LDX   $14
        LDA   $15
        JSR   L8B40
LB709   JMP   L903E
LB70C   LDX   $60
        TYA    
        CLC    
        ADC   $5F
        BCC   LB715
        INX    
LB715   CPX   $04F6
        BNE   LB728
        CMP   $04F5
        BCC   LB728
        BEQ   LB728
        LSR   $53
        LDA   #$82
        JMP   L90B2
LB728   RTS    
        BNE   LB7A7
        LDX   #$00
        LDY   #$00
LB72F   INX    
        LDA   $055E,x
        BEQ   LB788
        STA   $77
        STX   $76
        LDX   #$05
LB73B   LDA   $CD6E,x
        DEX    
        BNE   LB743
        ORA   $76
LB743   JSR   LFFD2
        TXA    
        BPL   LB73B
        LDX   #$07
LB74B   LDA   $0567,y
        INY    
        PHA    
        STX   $80
        LDX   #$04
LB754   CMP   $B839,x
        BEQ   LB78D
        DEX    
        BNE   LB754
        LDX   $80
        CPX   #$08
        BCC   LB769
        BNE   LB76E
        LDA   #$2B
        JSR   LFFD2
LB769   LDA   #$22
        JSR   LFFD2
LB76E   PLA    
        JSR   LFFD2
        LDX   #$09
LB774   DEC   $77
        BNE   LB74B
        CPX   #$09
        BCC   LB781
        LDA   #$22
        JSR   LFFD2
LB781   LDA   #$8D
        JSR   LFFD2
        LDX   $76
LB788   CPX   #$08
        BNE   LB72F
        RTS    
LB78D   LDX   $80
LB78F   LDA   $B830,x
        JSR   LFFD2
        DEX    
        CPX   #$03
        BCS   LB78F
        PLA    
        JSR   LCD74
        LDA   #$29
        JSR   LFFD2
        LDX   #$08
        BNE   LB774
LB7A7   JSR   L9D84
        DEX    
        CPX   #$08
        BCC   LB7B2
        JMP   L991C             ; Illegal Quantity error
LB7B2   STX   $76
        JSR   L9491
        JSR   L9C48
        JSR   LB7C2
        BCC   LB831
        JMP   L8681
LB7C2   STA   $77
        LDX   #$08
        JSR   LB83E
        STA   $02CD
        LDX   $76
        INX    
        JSR   LB83E
        STA   $02CE
        LDX   $76
        LDA   $77
        SEC    
        ORA   $055F,x
        BEQ   LB814
        BCC   LB7FE
        CLC    
        ADC   $02CD
        BCS   LB832
        CMP   #$81
        BCS   LB832
        TAX    
        LDY   $02CD
LB7EF   CPY   $02CE
        BEQ   LB814
        DEY    
        DEX    
        LDA   $0567,y
        STA   $0567,x
        BCS   LB7EF
LB7FE   ADC   $02CE
        TAX    
        LDY   $02CE
LB805   CPY   $02CD
        BCS   LB814
        LDA   $0567,y
        STA   $0567,x
        INY    
        INX    
        BCC   LB805
LB814   LDX   $76
        JSR   LB83E
        TAX    
        LDY   $76
        LDA   $77
        STA   $055F,y
        LDY   #$00
LB823   JSR   $04B0
        DEC   $77
        BMI   LB831
        STA   $0567,x
        INX    
        INY    
        BNE   LB823
LB831   CLC    
LB832   RTS    
        PLP    
        BIT   $52
        PHA    
        LSE   ($2B,x)
        HLT    
        ORA   $228D
        ASO   $00A9,y
        CLC    
LB841   DEX    
        BMI   LB832
        ADC   $055F,x
        BCC   LB841
        JSR   L9D84
        DEX    
        CPX   #$03
        BCS   LB8B5
        STX   $80
        JSR   L9DDE
        CMP   #$04
        BCS   LB8B5
        STY   $7E
        STA   $7F
        JSR   L9DDE
        LDX   $80
        CPX   #$02
        BNE   LB868
        DEX    
LB868   PHA    
        CPY   #$00
        BNE   LB874
        CMP   #$00
        BNE   LB874
        INY    
        BNE   LB883
LB874   TYA    
        PHA    
LB876   JSR   L8CC0
        LDA   $04FE,x
        ORA   $04FC,x
        BNE   LB876
        PLA    
        TAY    
LB883   TYA    
        EOR   #$FF
        CLC    
        ADC   #$01
        SEI    
        STA   $04FC,x
        PLA    
        EOR   #$FF
        ADC   #$00
        STA   $04FE,x
        LDA   $7E
        STA   Voice1FreqLo,x
        LDA   $B8B8,x
        TAX    
        LDA   Voice2FreqHI,x
        AND   #$FC
        ORA   $7F
        STA   Voice2FreqHI,x
        LDX   $80
        LDA   $B8BA,x
        ORA   SoundSelector
        STA   SoundSelector
        CLI    
        RTS    
LB8B5   JMP   L991C             ; Illegal Quantity error
        HLT    
        BRK    
        BPL   LB8DC
        RTI    
        JSR   L9D84
        CPX   #$09
        BCS   LB8B5
        STX   $80
        LDA   SoundSelector
        AND   #$F0
        ORA   $80
        STA   SoundSelector
        RTS    
        JSR   LC3B6
        LDX   #$04
        JSR   LC3D9
        JSR   LC37B
LB8DC   JSR   LC3A5
        CPX   #$02
        BCC   LB8E6
        JMP   L991C             ; Illegal Quantity error
LB8E6   TXA    
        LSR    
        ROR    
        STA   $8B
        BPL   LB8F1
        LDA   $84
        BEQ   LB8F8
LB8F1   JSR   LC1F3
        BCS   LB8F8
        BNE   LB8F9
LB8F8   RTS    
LB8F9   JSR   LA954
        LDA   $31
        STA   $22
        LDA   $32
        STA   $23
        SEC    
        LDA   $33
        SBC   #$03
        STA   $19
        LDA   $34
        SBC   #$00
        STA   $1A
LB911   LDX   #$00
        STX   $89
        STX   $8A
LB917   LDX   $02AF
        BNE   LB91F
        DEC   $02B0
LB91F   DEC   $02AF
        JSR   LC1F3
        BCS   LB929
        BNE   LB917
LB929   INC   $02AF
        BNE   LB931
        INC   $02B0
LB931   JSR   LC1C3
        LDX   $02AD
        BNE   LB93C
        DEC   $02AE
LB93C   DEC   $02AD
        LDA   $89
        JSR   LB99F
        STA   $89
        CLC    
        LDA   $02AD
        ADC   #$02
        STA   $02AD
        BCC   LB954
        INC   $02AE
LB954   LDA   $8A
        JSR   LB99F
        STA   $8A
        LDX   $02AD
        BNE   LB963
        DEC   $02AE
LB963   DEC   $02AD
        INC   $02AF
        BNE   LB96E
        INC   $02B0
LB96E   JSR   LC1F3
        BCS   LB975
        BNE   LB931
LB975   LDX   #$03
        LDY   #$00
        LDA   $23
        CMP   $32
        BNE   LB985
        LDA   $22
        CMP   $31
        BEQ   LB99C
LB985   LDA   $22
        BNE   LB98B
        DEC   $23
LB98B   DEC   $22
        JSR   $04B0
        STA   $02AD,x
        DEX    
        BPL   LB985
        JSR   L8CC0
        JMP   LB911
LB99C   JMP   LC37B
LB99F   PHA    
        JSR   LC1F3
        BCS   LB9D0
        BEQ   LB9D0
        PLA    
        BNE   LB9D3
        TAX    
        TAY    
        LDA   $23
        CMP   $1A
        BCC   LB9BD
        BNE   LB9BA
        LDA   $22
        CMP   $19
        BCC   LB9BD
LB9BA   JMP   L8681
LB9BD   LDA   $02AD,x
        STA   ($22),y
        INC   $22
        BNE   LB9C8
        INC   $23
LB9C8   INX    
        CPX   #$04
        BNE   LB9BD
        LDA   #$80
        RTS    
LB9D0   PLA    
        LDA   #$00
LB9D3   RTS    
        JSR   LC3B9
        JSR   L9DD8
        CPX   #$28
        BCS   LB9E8
        STX   $02DA
        JSR   L9DD8
        CPX   #$19
        BCC   LB9EB
LB9E8   JMP   L991C             ; Illegal Quantity error
LB9EB   STX   $02DB
        JSR   L9491
        JSR   L9C48
        STA   $02EA
        TYA    
        PHA    
        TXA    
        PHA    
        JSR   LC3A5
        TXA    
        ROR    
        ROR   $02B9
        PLA    
        STA   $22
        PLA    
        STA   $23
        LDA   $83
        BNE   LBA28
        LDX   $02DB
        LDY   $02DA
        CLC    
        JSR   LFFF0
        LDY   #$00
LBA19   CPY   $02EA
        BEQ   LBA27
        JSR   $04B0
        JSR   LFF4C
        INY    
        BNE   LBA19
LBA27   RTS    
LBA28   JSR   LC7BF
        LDA   $86
        PHA    
        LDA   $84
        PHA    
        BIT   $83
        BPL   LBA44
        PLA    
        BEQ   LBA4A
        LSR    
        BEQ   LBA4A
        LDX   $85
        BCC   LBA4C
        LDX   Colour1
        BCS   LBA4C
LBA44   LDX   Colour0
        PLA    
        BEQ   LBA4C
LBA4A   LDX   $86
LBA4C   STX   $86
        LDX   $02DB
        LDY   #$00
        STY   $02DC
LBA56   LDY   $02DC
        INC   $02DC
        JSR   $04B0
        DEC   $02EA
        BMI   LBA7B
        LDY   $02DA
        JSR   LBA7F
        INC   $02DA
        CPY   #$27
        BCC   LBA56
        LDY   #$00
        STY   $02DA
        INX    
        CPX   #$18
        BCC   LBA56
LBA7B   PLA    
        STA   $86
        RTS    
LBA7F   PHA    
        JSR   LC21A
        JSR   LC291
        LDA   #$00
        STA   $7E
        PLA    
        PHA    
        ASL    
        ROL   $7E
        ASL    
        ASL    
        ROL   $7E
        STA   $24
        LDA   $7E
        ADC   $02E4
        STA   $25
        TYA    
        PHA    
        LDY   #$07
LBAA0   LDA   $02B9
        ASL    
        LDA   ($24),y
        BCC   LBAAA
        EOR   #$FF
LBAAA   BIT   $83
        BPL   LBAD9
        AND   #$AA
        STA   $7E
        LDA   $84
        BNE   LBAC5
        LDA   $7E
        BCS   LBAC1
        LSR    
        EOR   $7E
        EOR   #$AA
        BNE   LBAD9
LBAC1   ORA   #$55
        BNE   LBAD9
LBAC5   CMP   #$02
        BNE   LBACD
        LDA   $7E
        BCS   LBAD9
LBACD   BCC   LBAD6
        LDA   $7E
        LSR    
        EOR   $7E
        BCC   LBAD9
LBAD6   LDA   $7E
        LSR    
LBAD9   STA   ($8C),y
        DEY    
        BPL   LBAA0
        PLA    
        TAY    
        PLA    
        RTS    
        JSR   LC3B6
        LDX   #$1F
        JSR   LC3F4
        LDX   #$2B
        JSR   LC3D9
        JSR   LC38F
        STY   $02D0
        STA   $02D1
        JSR   LC3A5
        CPX   #$02
        BCC   LBB02
        JMP   L991C             ; Illegal Quantity error
LBB02   STX   $02E8
        TXA    
        PHA    
        JSR   LBBB4
        PLA    
        BNE   LBB29
        BEQ   LBB12
LBB0F   JSR   LBC36
LBB12   JSR   LC0DA
        LDA   $02CA
        BNE   LBB0F
LBB1A   LDX   #$04
LBB1C   LDA   $02D7,x
        STA   $02AC,x
        DEX    
        BNE   LBB1C
        STX   $02E8
        RTS    
LBB29   LDX   #$00
        LDA   $02C5
        LSR    
        BCC   LBB33
        LDX   #$02
LBB33   LDA   $02DC,x
        STA   $02D6
        LDA   $02DD,x
        STA   $02D7
        LDA   #$00
        LDX   #$03
LBB43   STA   $02D2,x
        DEX    
        BPL   LBB43
LBB49   LDX   #$07
LBB4B   LDA   $02AD,x
        PHA    
        DEX    
        BPL   LBB4B
        JSR   LC0DA
        LDX   #$00
LBB57   PLA    
        STA   $02AD,x
        INX    
        CPX   #$08
        BNE   LBB57
LBB60   LDA   $02D6
        BNE   LBB6A
        DEC   $02D7
        BMI   LBB1A
LBB6A   DEC   $02D6
        LDX   #$25
        LDY   #$1B
        LDA   $02C5
        LSR    
        BCC   LBB79
        LDY   #$19
LBB79   LDA   #$00
LBB7B   LSR    
        PHA    
        JSR   LC2F6
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        PLA    
        BCC   LBB8C
        ORA   #$A0
LBB8C   INX    
        INX    
        LDY   #$19
        LSR   $02C5
        BCC   LBB97
        LDY   #$1B
LBB97   ROL   $02C5
        CPX   #$27
        BEQ   LBB7B
        LDX   #$06
        ASL    
        BEQ   LBB60
LBBA3   BCC   LBBAD
        INC   $02AD,x
        BNE   LBBAD
        INC   $02AE,x
LBBAD   ASL    
        DEX    
        DEX    
        BPL   LBBA3
        BMI   LBB49
LBBB4   LDY   #$23
        JSR   LBC56
        LDX   #$1F
        LDY   #$2B
LBBBD   TYA    
        PHA    
        JSR   LC322
        STA   $02B1,x
        STA   $02B5,x
        STA   $02BD,x
        TYA    
        STA   $02B2,x
        STA   $02B6,x
        STA   $02BE,x
        PLA    
        TAY    
        JSR   LC2F6
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        LDY   #$2D
        INX    
        INX    
        CPX   #$21
        BEQ   LBBBD
        LDA   #$90
        JSR   LBCD5
        LDA   $02C5
        AND   #$03
        STA   $02C5
        TAX    
        LDA   $BC18,x
        JSR   LBC36
        JSR   LC37B
        LDA   $02CA
        JSR   LBC36
        LDX   $02C5
        LDA   $BC18,x
        AND   #$F0
        STA   $02CB
        LDA   $BC1C,x
        STA   $02CA
        RTS    
        LDX   $41E4,y
        ASO   $1B41,y
        LDX   $46E4,y
        HLT    
        EOR   $44
        JSR   $0D42
        SKB   $45
        HLT    
        HLT    
        EOR   $5220,y
        ORA   $494D
        ALR   #$45
        JSR   $0D49
LBC36   JSR   LBD05
        LDX   #$04
LBC3B   LDA   $02AE,x
        ASL    
        ROR   $02AE,x
        ROR   $02AD,x
        BCC   LBC4F
        INC   $02AD,x
        BNE   LBC4F
        INC   $02AE,x
LBC4F   INX    
        INX    
        CPX   #$06
        BEQ   LBC3B
        RTS    
LBC56   JSR   LC318
LBC59   LDX   #$00
LBC5B   INX    
        SEC    
        SBC   #$5A
        BCS   LBC5B
        DEY    
        BPL   LBC5B
        STX   $02C5
        PHA    
        ADC   #$5A
        JSR   LBC76
        PLA    
        CLC    
        EOR   #$FF
        ADC   #$01
        DEC   $02C5
LBC76   LDX   #$FF
LBC78   INX    
        SEC    
        SBC   #$0A
        BCS   LBC78
        ADC   #$0A
        STA   $8E
        TXA    
        ASL    
        TAX    
        LDA   $C4B4,x
        LDY   $C4B3,x
LBC8B   CLC    
        DEC   $8E
        BMI   LBC9C
        ADC   $C4C8,x
        PHA    
        TYA    
        ADC   $C4C7,x
        TAY    
        PLA    
        BCC   LBC8B
LBC9C   PHA    
        LDX   #$00
        LDA   $02C5
        LSR    
        BCS   LBCA7
        LDX   #$02
LBCA7   PLA    
        STA   $02C6,x
        TYA    
        STA   $02C7,x
        RTS    
LBCB0   LDY   #$19
        BCC   LBCB6
        LDY   #$1B
LBCB6   LDA   $02C5
        ADC   #$02
        LSR    
        LSR    
        PHP    
        JSR   LC318
        CPY   #$FF
        BCC   LBCCC
        TXA    
        TAY    
        JSR   LC318
        BCS   LBCCF
LBCCC   JSR   LC337
LBCCF   PLP    
        BCS   LBCED
        JMP   LC327
LBCD5   STA   $02CA
        LDX   #$23
LBCDA   ASL   $02CA
        JSR   LBCB0
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        INX    
        INX    
        CPX   #$2B
        BCC   LBCDA
LBCED   RTS    
LBCEE   LDY   #$2B
LBCF0   JSR   LBC56
        LDX   #$07
LBCF5   LDA   $02DC,x
        STA   $02D0,x
        DEX    
        BPL   LBCF5
        LDA   #$50
        JSR   LBCD5
        LDA   #$10
LBD05   STA   $02CA
        LDY   #$1F
        LDX   #$23
LBD0C   ASL   $02CB
        ROL   $02CA
        JSR   LC2F4
        INX    
        INX    
        ASL   $02CB
        ROL   $02CA
        JSR   LC2F0
        PHA    
        TYA    
        PHA    
        LDY   #$21
        INX    
        INX    
        CPX   #$27
        BEQ   LBD0C
        LDX   #$03
LBD2D   PLA    
        STA   $02B1,x
        DEX    
        BPL   LBD2D
        RTS    
        JSR   LC7BF
        JSR   L9C48
        STA   $02CF
        STX   $24
        STY   $25
        LDX   #$04
        JSR   LC3D9
        JSR   LC3A5
        CPX   #$05
        BCC   LBD51
        JMP   L991C             ; Illegal Quantity error
LBD51   STX   $02D0
        LDX   #$03
        LDY   $02CF
        CPY   #$05
        BCS   LBD5E
        RTS    
LBD5E   DEY    
        JSR   $04BB
        STA   $02D5,x
        DEX    
        BPL   LBD5E
        STX   $02D1
        JSR   LC37B
        LDA   $02D5
        STA   $02D9
        LDA   $02D6
        STA   $02DA
LBD7A   LDA   #$08
        STA   $02E5
        INC   $02D1
        LDY   $02D1
        JSR   $04BB
        STA   $02D3
LBD8B   JSR   LC1F3
        STA   $02D2
        ASL   $02D3
        ROL    
        DEC   $02E5
        BIT   $83
        BPL   LBDA3
        ASL   $02D3
        ROL    
        DEC   $02E5
LBDA3   LDX   $02D0
        CPX   #$03
        BCC   LBDB6
        BEQ   LBDB1
        EOR   $02D2
        BCS   LBDC2
LBDB1   AND   $02D2
        BCS   LBDC2
LBDB6   CPX   #$01
        BCC   LBDC2
        BEQ   LBDC0
        ORA   $02D2
        BIT   $FF49
LBDC2   AND   #$03
        BIT   $83
        BMI   LBDCA
        AND   #$01
LBDCA   STA   $84
        JSR   LC1C3
        INC   $02AD
        BNE   LBDD7
        INC   $02AE
LBDD7   SEC    
        LDA   $02D9
        BIT   $83
        BPL   LBDE2
        SBC   #$02
        BIT   $01E9
        STA   $02D9
        LDA   $02DA
        SBC   #$00
        STA   $02DA
        BCS   LBE1E
        LDX   #$01
LBDF3   LDA   $02D5,x
        STA   $02D9,x
        LDA   $02B1,x
        STA   $02AD,x
        DEX    
        BPL   LBDF3
        INC   $02AF
        BNE   LBE0A
        INC   $02B0
LBE0A   SEC    
        LDA   $02D7
        SBC   #$01
        STA   $02D7
        LDA   $02D8
        SBC   #$00
        STA   $02D8
        BCS   LBE26
        RTS    
LBE1E   LDA   $02E5
        BEQ   LBE26
        JMP   LBD8B
LBE26   JMP   LBD7A
        JSR   LC7BF
        JSR   L96A5
        STA   $02DB
        STY   $02DC
        BIT   $0D
        BMI   LBE3C
        JMP   L9324
LBE3C   LDX   #$28
        JSR   LC3F4
        LDX   #$04
        JSR   LC3D9
        LDX   #$2A
        LDY   #$06
        LDA   #$02
        STA   $8E
LBE4E   JSR   LC322
        TAX    
        TYA    
        PHA    
        LDY   $8E
        JSR   LC382
        BCC   LBE67
        LDA   $02D5,y
        STA   $02AD,y
        LDA   $02D6,y
        STA   $02AE,y
LBE67   TXA    
        STA   $02D5,y
        STA   $02DE,y
        PLA    
        STA   $02D6,y
        STA   $02DF,y
        LDX   #$28
        LDY   #$04
        DEC   $8E
        DEC   $8E
        BEQ   LBE4E
        LDY   #$FF
        STY   $02D1
        LDA   $02AD
        STA   $02D9
        LDA   $02AE
        STA   $02DA
        TYA    
        JSR   L9B5C
LBE94   JSR   LC264
        LDA   ($8C),y
        BCC   LBEA9
        LDA   $02AD
        BIT   $83
        BPL   LBEA4
        SEC    
        ROL    
LBEA4   AND   #$07
        TAX    
        LDA   #$00
LBEA9   BIT   $83
        BPL   LBEAE
        DEX    
LBEAE   STX   $02DD
LBEB1   ASL    
        DEX    
        BPL   LBEB1
        ROR    
        STA   $8E
        LDA   #$08
        BIT   $83
        BPL   LBEBF
        LSR    
LBEBF   CLC    
        ADC   $02AD
        STA   $02AD
        BCC   LBECB
        INC   $02AE
LBECB   JSR   LC264
        LDA   #$00
        BCS   LBED4
        LDA   ($8C),y
LBED4   STA   $8F
        LDX   $02DD
LBED9   LSR    
        INX    
        CPX   #$08
        BNE   LBED9
        ORA   $8E
        INC   $02D1
        LDY   $02D1
        CPY   #$FC
        BCC   LBEEE
        JMP   LCC4C
LBEEE   STA   ($62),y
        LDX   $02DD
        LDA   $02D5
        SEC    
        BIT   $83
        BPL   LBEFE
        SBC   #$04
        BIT   $08E9
        STA   $02D5
        LDA   $8F
        BCS   LBEB1
        DEC   $02D6
        BPL   LBEB1
        LDX   $02D7
        BNE   LBF53
        DEC   $02D8
        BPL   LBF53
        BIT   $83
        BPL   LBF20
        ASL   $02DE
        ROL   $02DF
LBF20   LDX   #$00
LBF22   LDA   $02DE,x
        INY    
        STA   ($62),y
        INX    
        CPX   #$04
        BNE   LBF22
        INY    
        STY   $02DE
        LDA   $62
        STA   $02DF
        LDA   $63
        STA   $02E0
        LDA   #$DE
        STA   $64
        LDA   #$02
        STA   $65
        LDA   $02DB
        STA   $49
        LDA   $02DC
        STA   $4A
        JSR   L8F40
        JMP   LC37B
LBF53   DEC   $02D7
        INC   $02AF
        BNE   LBF5E
        INC   $02B0
LBF5E   LDA   $02D9
        STA   $02AD
        LDA   $02DA
        STA   $02AE
        LDA   $02DE
        STA   $02D5
        LDA   $02DF
        STA   $02D6
        JMP   LBE94
        LDA   $83
        CLC    
        ROL    
        ROL    
        ROL    
        ADC   #$00
        TAY    
        JMP   L9A81
        SEC    
        BIT   $18
        PHP    
        JSR   L9D87
        LDA   Colour4
        AND   #$7F
        CPX   #$04
        BEQ   LBFAE
        BCS   LBFBE
        LDA   Colour0
        AND   #$7F
        DEX    
        BMI   LBFAE
        LDA   $86
        DEX    
        BMI   LBFAE
        LDA   $85
        DEX    
        BMI   LBFAE
        LDA   Colour1
        AND   #$7F
LBFAE   PLP    
        BCS   LBFB6
        LSR    
        LSR    
        LSR    
        LSR    
        CLC    
LBFB6   ADC   #$00
        AND   #$0F
        TAY    
        JMP   L9A81
LBFBE   JMP   L991C             ; Illegal Quantity error
        JSR   L9D87
        DEX    
        CPX   #$02
        BCS   LBFBE
        LDA   $BFFB,x
        TAX    
        SEI    
LBFCE   STX   KeyboardLatch
        LDA   KeyboardLatch
        STX   KeyboardLatch
        CMP   KeyboardLatch
        BNE   LBFCE
        CLI    
        EOR   #$FF
        TAY    
        AND   #$0F
        TAX    
        LDA   $BFF0,x
        CPY   #$0F
        BCC   LBFEC
        ORA   #$80
LBFEC   TAY    
        JMP   L9A81
        BRK    
        ORA   ($05,x)
        BRK    
        ASO   $08
        ASL   DIRECTION
        ASO   ($02,x)
        SKB   $FA
        ORA   $8720,x
        STA   $02E0,x
        BCC   LC011
        BNE   LBFBE
        JSR   LC1F3
        TAY    
        BCC   LC00E
        LDY   #$00
LC00E   JMP   L9A81
LC011   TXA    
        ASL    
        TAX    
        LDA   $02AD,x
        TAY    
        LDA   $02AE,x
        JMP   L9471
        JSR   LC3B6
        LDX   #$1F
        JSR   LC3D9
        JSR   LC38F
        STY   $02D0
        STA   $02D1
        JSR   LC38F
        STY   $02D2
        STA   $02D3
        PHP    
        LDX   #$23
        JSR   LC2D3
        PLP    
        BCS   LC052
        LDA   $02D0
        STA   $02D2
        LDA   $02D1
        BIT   $83
        BPL   LC052
        ASL   $02D2
        ROL    
LC052   STA   $02D3
        JSR   LC38F
        STY   $02D8
        STA   $02D9
        JSR   LC38F
        STY   $02DA
        STA   $02DB
        JSR   LC38F
        STA   $80
        TYA    
        LDY   $80
        JSR   LBC59
        LDX   #$2D
        LDY   #$2B
        JSR   LC305
        BCC   LC089
        LDA   #$68
        LDY   #$01
        JSR   LC2F9
        STA   $02AD,x
        TYA    
        STA   $02AE,x
LC089   LDX   #$03
LC08B   LDA   $02D0,x
        STA   $02D4,x
        DEX    
        BPL   LC08B
        LDA   #$90
        JSR   LBCD5
        LDX   #$07
LC09B   LDA   $02D0,x
        STA   $02DC,x
        DEX    
        BPL   LC09B
        JSR   LBCEE
        JSR   LC37B
        LDX   #$02
        JSR   LC3A7
        STX   $E9
        CLC    
LC0B2   LDA   $E9
        BNE   LC0B9
        JMP   L991C             ; Illegal Quantity error
LC0B9   ADC   $02D8
        STA   $02D8
        BCC   LC0C4
        INC   $02D9
LC0C4   LDX   #$2D
        LDY   #$2B
        JSR   LC305
        BCS   LC0D5
        JSR   LBCEE
        JSR   LC0DA
        BCC   LC0B2
LC0D5   LDY   #$2D
        JSR   LBCF0
LC0DA   LDX   #$02
        LDY   #$06
LC0DE   LDA   #$00
        STA   $02B9,x
        STA   $02BA,x
        JSR   LC322
        BPL   LC0F3
        DEC   $02B9,x
        DEC   $02BA,x
        BNE   LC0FE
LC0F3   CMP   #$00
        BNE   LC0FB
        CPY   #$00
        BEQ   LC0FE
LC0FB   INC   $02B9,x
LC0FE   STA   $02B5,x
        ASL    
        STA   $02BD,x
        TYA    
        STA   $02B6,x
        ROL    
        STA   $02BE,x
        DEX    
        DEX    
        LDY   #$04
        CPX   #$00
        BEQ   LC0DE
        LDX   #$0A
        LDY   #$08
        JSR   LC305
        LDA   #$00
        ROL    
        ROL    
        STA   $02C3
        EOR   #$02
        STA   $02C4
        CLC    
        LDA   #$10
        ADC   $02C3
        TAY    
        PHA    
        EOR   #$02
        TAX    
        JSR   LC305
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        PLA    
        TAY    
        CLC    
        LDA   #$08
        ADC   $02C4
        TAX    
        JSR   LC305
        STA   $02C1
        STY   $02C2
LC14F   JSR   LC1A5
        LDY   $02C4
        SEC    
        LDA   $02B5,y
        SBC   #$01
        STA   $02B5,y
        BCS   LC16B
        LDA   $02B6,y
        SBC   #$00
        STA   $02B6,y
        BCS   LC16B
        RTS    
LC16B   LDX   $02C3
        LDA   $02C2
        BMI   LC179
        JSR   LC194
        LDX   $02C4
LC179   CLC    
        LDA   $02C1
        ADC   $02BD,x
        STA   $02C1
        LDA   $02C2
        ADC   $02BE,x
        STA   $02C2
        LDX   $02C4
        JSR   LC194
        BEQ   LC14F
LC194   LDY   #$02
        CLC    
LC197   LDA   $02AD,x
        ADC   $02B9,x
        STA   $02AD,x
        INX    
        DEY    
        BNE   LC197
        RTS    
LC1A5   LDA   $02E8
        ORA   $02E7
        BEQ   LC1C3
        INC   $02AD
        BNE   LC1B5
        INC   $02AE
LC1B5   JSR   LC1C3
        LDX   $02AD
        BNE   LC1C0
        DEC   $02AE
LC1C0   DEC   $02AD
LC1C3   JSR   LC2AD
        BCS   LC1EC
        JSR   LC21A
        JSR   LC269
        STA   $02E9
        LDA   ($8C),y
        ORA   $02E9
        BIT   $83
        BPL   LC1ED
        PHA    
        LDX   $84
        LDA   $02E9
        AND   $C4AF,x
        STA   $02E9
        PLA    
LC1E7   EOR   $02E9
LC1EA   STA   ($8C),y
LC1EC   RTS    
LC1ED   LDX   $84
        BNE   LC1EA
        BEQ   LC1E7
LC1F3   JSR   LC264
        BCS   LC219
        STA   $02E9
        LDA   ($8C),y
        AND   $02E9
LC200   ROL    
        DEX    
        BPL   LC200
        ROL    
        BIT   $8B
        BMI   LC20F
        AND   #$03
        CMP   $84
        CLC    
        RTS    
LC20F   CLC    
        AND   #$03
        BEQ   LC217
        LDX   #$00
        RTS    
LC217   LDX   #$FF
LC219   RTS    
LC21A   LDA   $D802,x
        STA   $8C
        LDA   $D81B,x
        AND   #$03
        PHA    
        ORA   #$1C
        STA   $8D
        JSR   LC238
        STA   ($8C),y
        PLA    
        ORA   #$18
        STA   $8D
        JSR   LC24E
        STA   ($8C),y
LC238   LDA   $86
        ASL    
        ASL    
        ASL    
        ASL    
        STA   $7E
        LDA   Colour0
        BIT   $83
        BPL   LC249
        LDA   $85
LC249   AND   #$0F
        ORA   $7E
        RTS    
LC24E   LDA   $86
        LSR    
        LSR    
        LSR    
        LSR    
        STA   $7E
        LDA   Colour0
        BIT   $83
        BPL   LC25F
        LDA   $85
LC25F   AND   #$F0
        ORA   $7E
        RTS    
LC264   JSR   LC2AD
        BCS   LC288
LC269   JSR   LC291
        LDA   $02AF
        AND   #$07
        TAY    
        LDA   $02AD
        BIT   $83
        PHP    
        BPL   LC27B
        ASL    
LC27B   AND   #$07
        TAX    
        LDA   $C289,x
        PLP    
        BPL   LC288
        INX    
        ORA   $C289,x
LC288   RTS    
        SKB   $40
        JSR   $0810
        SKB   $02
        ORA   ($98,x)
        CLC    
        ADC   $D802,x
        STA   $8C
        LDA   $D81B,x
        AND   #$03
        ADC   #$00
        ASL   $8C
        ROL    
        ASL   $8C
        ROL    
        ASL   $8C
        ROL    
        ORA   #$20
        STA   $8D
        RTS    
LC2AD   LDA   $02AE
        LSR    
        BNE   LC2D1
        LDA   $02AD
        ROR    
        LSR    
        BIT   $83
        BMI   LC2BD
        LSR    
LC2BD   TAY    
        CPY   #$28
        BCS   LC2D1
        LDA   $02B0
        BNE   LC2D1
        LDA   $02AF
        LSR    
        LSR    
        LSR    
        TAX    
        CMP   $88
        RTS    
LC2D1   SEC    
        RTS    
LC2D3   LDA   $02E6
        BEQ   LC2EF
        LDA   $87
        JSR   LC2DF
        LDA   $88
LC2DF   ASL    
        TAY    
        LDA   #$00
        JSR   LC337
        STA   $02AD,x
        TYA    
        INX    
        STA   $02AD,x
        INX    
LC2EF   RTS    
LC2F0   BCC   LC2F9
        BCS   LC308
LC2F4   BCS   LC305
LC2F6   JSR   LC318
LC2F9   CLC    
        ADC   $02AD,x
        PHA    
        TYA    
        ADC   $02AE,x
        TAY    
        PLA    
        RTS    
LC305   JSR   LC318
LC308   SEC    
        ORA   $02AD,x
        STA   $57
        TYA    
        ORA   $02AE,x
        TAY    
        PHP    
        LDA   $57
        PLP    
        RTS    
LC318   LDA   $02AD,y
        PHA    
        LDA   $02AE,y
        TAY    
        PLA    
        RTS    
LC322   JSR   LC305
LC325   BPL   LC336
LC327   PHP    
        CLC    
        EOR   #$FF
        ADC   #$01
        PHA    
        TYA    
        EOR   #$FF
        ADC   #$00
        TAY    
        PLA    
        PLP    
LC336   RTS    
LC337   STY   $8E
        STA   $8F
        LDA   $02AD,x
        LDY   $02AE,x
        PHP    
        JSR   LC325
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        LDA   #$00
        STA   $02EF
        LDY   #$10
LC353   LSR   $8E
        ROR   $8F
        BCC   LC368
        CLC    
        ADC   $02AD,x
        PHA    
        LDA   $02EF
        ADC   $02AE,x
        STA   $02EF
        PLA    
LC368   LSR   $02EF
        ROR    
        DEY    
        BNE   LC353
        ADC   #$00
        LDY   $02EF
        BCC   LC377
        INY    
LC377   PLP    
        JMP   LC325
LC37B   LDY   #$00
        JSR   LC382
        LDY   #$02
LC382   LDA   $02B1,y
        STA   $02AD,y
        LDA   $02B2,y
        STA   $02AE,y
        RTS    
LC38F   JSR   $0479
        BEQ   LC3A0
        JSR   L9491
        CMP   #$2C
        BEQ   LC3A0
        JSR   L9DE1
        SEC    
        RTS    
LC3A0   LDA   #$00
        TAY    
        CLC    
LC3A4   RTS    
LC3A5   LDX   #$00
LC3A7   JSR   $0479
        BEQ   LC3A4
        JSR   L9491
        CMP   #$2C
        BEQ   LC3A4
        JMP   L9D84
LC3B6   JSR   LC7BF
LC3B9   LDX   #$01
        JSR   $0479
LC3BE   BEQ   LC3D3
        CMP   #$2C
        BEQ   LC3D3
        JSR   L9D84
        CPX   #$04
        BCS   LC3D6
        CPX   #$02
        BIT   $83
        BMI   LC3D3
        BCS   LC3D6
LC3D3   STX   $84
        RTS    
LC3D6   JMP   L991C             ; Illegal Quantity error
LC3D9   JSR   $0479
        BEQ   LC3E5
        JSR   L9491
        CMP   #$2C
        BNE   LC3F7
LC3E5   LDY   #$00
LC3E7   LDA   $02AD,y
        STA   $02AD,x
        INX    
        INY    
        CPY   #$04
        BNE   LC3E7
        RTS    
LC3F4   JSR   L9491
LC3F7   STX   $02F0
        JSR   LC48F
        JSR   $0479
        CMP   #$2C
        BEQ   LC45A
        CMP   #$3B
        BEQ   LC40B
        JMP   L94A1
LC40B   JSR   $0473
        JSR   L9DE1
        STA   $80
        TYA    
        LDY   $80
        JSR   LBC59
        LDX   $02F0
        LDA   $02AD,x
        STA   $02AF,x
        LDA   $02AE,x
        STA   $02B0,x
        JSR   LC2D3
        LDA   #$0E
        STA   $02F1
        CLC    
        LDX   $02F0
LC434   JSR   LBCB0
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        LDY   #$00
        LSR   $02F1
        BCC   LC447
        LDY   #$02
LC447   JSR   LC2F4
        STA   $02AD,x
        TYA    
        STA   $02AE,x
        INX    
        INX    
        LSR   $02F1
        BNE   LC434
        CLC    
        RTS    
LC45A   JSR   $0473
        INC   $02F0
        INC   $02F0
        JSR   LC48F
        LDX   $02F0
        DEX    
        DEX    
        JSR   LC2D3
        LDY   #$02
        LDX   $02F0
        INX    
        INX    
LC475   DEX    
        DEX    
        LSR   $02F1
        BCC   LC486
        JSR   LC2F6
        STA   $02AD,x
        TYA    
        STA   $02AE,x
LC486   LDY   #$00
        CPX   $02F0
        BEQ   LC475
        CLC    
        RTS    
LC48F   JSR   $0479
        CMP   #$AA
        BEQ   LC49B
        CMP   #$AB
        BEQ   LC49B
        CLC    
LC49B   ROL   $02F1
        JSR   L9314
        JSR   L9DE8
        LDX   $02F0
        STA   $02AE,x
        TYA    
        STA   $02AD,x
        RTS    
        INS   $55AA,x
        BRK    
        BRK    
        BRK    
        BIT   $5771
        STA   $0080
        LDY   $8F
        CPY   $19
        CMP   $F0B2,x
        BCC   LC4C0
        SKW   $FFFF
        SKB   $72
        SKB   $50
        SKB   $0B
        ASO   ($A8,x)
        ASO   ($28,x)
        HLT    
        BCC   LC4D5
        INS   (IO,x)
        PLP    
        BRK    
        RRA   ($20,x)
        LAX   $20C7,y
        ADC   $F004,y
        HLT    
        LDX   #$01
        CMP   #$A4
        JSR   LC3BE
LC4E8   JSR   $0479
        CMP   #$2C
        BEQ   LC4F4
        CMP   #$A4
        BEQ   LC4F4
        RTS    
LC4F4   PHA    
        JSR   $0473
        LDX   #$04
        JSR   LC3F7
        PLA    
        BPL   LC506
        JSR   LC0DA
        JMP   LC4E8
LC506   JSR   LC37B
        JSR   LC1A5
        JMP   LC4E8
        JSR   LC7BF
        LDX   #$04
        JSR   LC3F7
        JMP   LC37B
        JSR   L9D84
        CPX   #$05
        BCS   LC564
        STX   $7E
        JSR   L9DD8
        DEX    
        CPX   #$10
        BCS   LC564
        STX   $7F
        LDX   #$07
        JSR   LC3A7
        CPX   #$08
        BCS   LC564
        TXA    
        ASL    
        ASL    
        ASL    
        ASL    
        ORA   $7F
        LDX   $7E
        CPX   #$01
        BEQ   LC54A
        BCS   LC551
        STA   Colour0
        BNE   LC563
LC54A   STA   $86
        STA   $053B
        BEQ   LC563
LC551   CPX   #$03
        BEQ   LC55B
        BCS   LC560
        STA   $85
        BNE   LC563
LC55B   STA   Colour1
        BEQ   LC563
LC560   STA   Colour4
LC563   RTS    
LC564   JMP   L991C             ; Illegal Quantity error
LC567   LDA   $83
        BNE   LC570
LC56B   LDA   #$93
        JMP   LFFD2
LC570   AND   #$40
        BEQ   LC57F
        JSR   LC56B
        LDX   #$14
        LDY   #$00
        CLC    
        JSR   LFFF0
LC57F   LDA   #$00
        LDY   #$20
        LDX   #$20
        JSR   LC5A7
        JSR   LC238
        LDY   #$1C
        LDX   #$04
        JSR   LC5A7
        JSR   LC24E
        LDY   #$18
        LDX   #$04
        JSR   LC5A7
        LDA   #$00
        LDX   #$03
LC5A0   STA   $02AD,x
        DEX    
        BPL   LC5A0
        RTS    
LC5A7   STY   $8D
        LDY   #$00
        STY   $8C
LC5AD   STA   ($8C),y
        DEY    
        BNE   LC5AD
        INC   $8D
        DEX    
        BNE   LC5AD
        RTS    
        JSR   L9D84
        CPX   #$02
        BCS   LC564
        STX   $02E6
        RTS    
        CMP   #$9C
        BNE   LC5D1
        JSR   LC738
        JSR   $0473
        LDA   #$00
        BEQ   LC5DB
LC5D1   JSR   L9D84
        CPX   #$05
        BCS   LC5ED
        LDA   $C637,x
LC5DB   CMP   $83
        BEQ   LC62A
        STA   $83
        TAX    
        BNE   LC5F0
        JSR   LC7C9
        LDA   #$28
        LDX   #$19
        BNE   LC626
LC5ED   JMP   L991C             ; Illegal Quantity error
LC5F0   JSR   LC63C
        LDA   TEDREG_06
        ORA   #$20
        STA   TEDREG_06
        LDA   TEDREG_07
        AND   #$EF
        BIT   $83
        BPL   LC606
        ORA   #$10
LC606   STA   TEDREG_07
        LDA   Voice1_BitMap
        AND   #$C3
        ORA   #$08
        STA   Voice1_BitMap
        LDA   ScreenAddress
        AND   #$03
        ORA   #$18
        STA   ScreenAddress
        LDA   #$28
        LDX   #$19
        BIT   $83
        BPL   LC626
        LSR    
LC626   STA   $87
        STX   $88
LC62A   JSR   LC3A5
        TXA    
        LSR    
        BNE   LC5ED
        BCC   LC636
        JMP   LC567
LC636   RTS    
        BRK    
        JSR   LA060
        CPX   #$A5
        ADC   $F0,x
        ORA   ($60,x)
        LDA   $38
        CMP   #$40
        BCS   LC67B
        JSR   LA954
        JSR   LC86B
        TXA    
        CLC    
        ADC   $31
        TYA    
        ADC   $32
        CMP   #$18
        BCS   LC678
        DEC   $75
        LDA   #$00
        STA   $22
        LDA   #$18
        STA   $23
        JSR   LC7F0
        LDA   $22
        STA   $33
        LDA   $23
        STA   $34
        LDA   #$00
        STA   $37
        LDA   #$18
        STA   $38
        JMP   LC825
LC678   JMP   L8681
LC67B   JSR   LA954
        LDY   $31
        STY   $5F
        LDA   $32
        CLC    
        ADC   #$30
        BCS   LC678
        STA   $60
        CMP   $34
        BCC   LC695
        BNE   LC678
        CPY   $33
        BCS   LC678
LC695   DEC   $75
        LDA   #$00
        STA   $4E
        LDA   #$30
        STA   $4F
        JSR   LC877
        LDA   $5F
        STA   $22
        LDA   $60
        STA   $23
        LDX   $31
        STX   $24
        LDA   $32
        STA   $25
        SEC    
        SBC   #$10
        TAY    
        JSR   LC7F8
        CLC    
        LDA   $32
        ADC   #$30
        STA   $32
        LDA   $30
        ADC   #$30
        STA   $30
        LDA   $2E
        ADC   #$30
        STA   $2E
        LDA   $2C
        ADC   #$30
        STA   $2C
        LDA   $42
        ADC   #$30
        STA   $42
LC6D8   JSR   L8818
        JSR   L884B
        BIT   Running                 ; BASIC program running?
        BPL   LC70F
        LDX   #$30
        BIT   $75
        BMI   LC6EA
        LDX   #$D0
LC6EA   TXA    
        CLC    
        ADC   $3C
        STA   $3C
        TXA    
        CLC    
        ADC   $025C
        STA   $025C
        TXA    
        CLC    
        ADC   $04F6
        STA   $04F6
        JSR   LA760
LC703   LDA   $3D
        CMP   #$B0
        BNE   LC710
        LDA   $3E
        CMP   #$07
        BNE   LC710
LC70F   RTS    
LC710   LDY   #$00
        LDA   ($3D),y
        CMP   #$81
        BNE   LC726
        LDY   #$02
        JSR   LC7AD
        LDY   #$10
        JSR   LC7AD
        LDA   #$12
        BNE   LC72D
LC726   LDY   #$04
        JSR   LC7AD
        LDA   #$05
LC72D   CLC    
        ADC   $3D
        STA   $3D
        BCC   LC703
        INC   $3E
        BNE   LC703
LC738   LDA   $75
        BNE   LC73D
        RTS    
LC73D   LDY   #$00
        STY   $75
        LDA   $38
        BMI   LC769
        JSR   LA954
        JSR   LC86B
        LDA   $0533
        STA   $22
        LDA   $0534
        STA   $23
        JSR   LC7F0
        LDX   #$01
LC75A   LDA   $0533,x
        STA   $37,x
        LDA   $22,x
        STA   $33,x
        DEX    
        BPL   LC75A
        JMP   LC825
LC769   LDY   #$00
        STY   $75
        STY   $22
        STY   $24
        LDA   #$10
        STA   $23
        LDA   #$40
        STA   $25
LC779   JSR   $04BB
        STA   ($22),y
        INY    
        BNE   LC779
        INC   $23
        INC   $25
        LDA   $32
        CMP   $25
        BCS   LC779
        LDA   $32
        SEC    
        SBC   #$30
        STA   $32
        LDA   $2C
        SBC   #$30
        STA   $2C
        LDA   $2E
        SBC   #$30
        STA   $2E
        LDA   $30
        SBC   #$30
        STA   $30
        LDA   $42
        SBC   #$30
        STA   $42
        JMP   LC6D8
LC7AD   LDA   ($3D),y
        BIT   $75
        BNE   LC7B9
        SEC    
        SBC   #$30
        STA   ($3D),y
        RTS    
LC7B9   CLC    
        ADC   #$30
        STA   ($3D),y
        RTS    
LC7BF   LDA   $75
        BEQ   LC7C4
        RTS    
LC7C4   LDX   #$23
        JMP   L8683
LC7C9   LDA   TEDREG_06
        AND   #$DF
        STA   TEDREG_06
        LDA   TEDREG_07
        AND   #$EF
        STA   TEDREG_07
        LDA   ScreenAddress
        AND   #$07
        ORA   #$08
        STA   ScreenAddress
        LDA   Voice1_BitMap
        ORA   #$04
        STA   Voice1_BitMap
        LDA   #$00
        STA   $83
        RTS    
LC7F0   LDA   $37
        STA   $24
        LDA   $38
        STA   $25
LC7F8   TXA    
        EOR   #$FF
        STA   $4E
        TYA    
        EOR   #$FF
        STA   $4F
        LDY   #$00
LC804   INC   $4E
        BNE   LC80C
        INC   $4F
        BEQ   LC824
LC80C   LDA   $22
        BNE   LC812
        DEC   $23
LC812   DEC   $22
        LDA   $24
        BNE   LC81A
        DEC   $25
LC81A   DEC   $24
        JSR   $04BB
        STA   ($22),y
        JMP   LC804
LC824   RTS    
LC825   LDA   $37
        LDY   $38
        STA   $22
        STY   $23
LC82D   SEC    
        LDA   $33
        SBC   $22
        LDA   $34
        SBC   $23
        BCS   LC824
        SEC    
        LDA   $22
        SBC   #$02
        STA   $22
        BCS   LC843
        DEC   $23
LC843   LDY   #$01
LC845   JSR   $04B0
        STA   $0024,y
        DEY    
        BPL   LC845
        INY    
        JSR   $04BB
        STA   $80
        LDA   $22
        SEC    
        SBC   $80
        STA   $22
        BCS   LC85F
        DEC   $23
LC85F   LDY   #$02
LC861   LDA   $0021,y
        STA   ($24),y
        DEY    
        BNE   LC861
        BEQ   LC82D
LC86B   SEC    
        LDA   $37
        SBC   $33
        TAX    
        LDA   $38
        SBC   $34
        TAY    
        RTS    
LC877   LDA   $37
        STA   $22
        LDA   $38
        STA   $23
LC87F   SEC    
        LDA   $33
        SBC   $22
        LDA   $34
        SBC   $23
        BCS   LC8BB
        SEC    
        LDA   $22
        SBC   #$02
        STA   $22
        BCS   LC895
        DEC   $23
LC895   CLC    
        LDY   #$00
LC898   JSR   $04B0
        STA   $0024,y
        ADC   $004E,y
        STA   ($22),y
        INY    
        CPY   #$01
        BNE   LC898
        DEY    
        JSR   $04BB
        STA   $80
        LDA   $22
        SEC    
        SBC   $80
        STA   $22
        BCS   LC87F
        DEC   $23
        BCC   LC87F
LC8BB   RTS    
        JSR   LCB1F
        AND   #$E6
        BNE   LC93E
        LDY   #$00
        JSR   LCA3F
        LDA   #$00
        LDX   $0277
        LDY   #$60
        JSR   LFFBA
        SEC    
        JSR   LFFC0
        BCC   LC8E1
        PHA    
        JSR   LC935
        PLA    
        TAX    
        JMP   L8683
LC8E1   LDX   #$00
        JSR   LFFC6
        LDY   #$03
LC8E8   STY   $02EC
LC8EB   JSR   LFFCF
        STA   $02ED
        JSR   LFFB7
        BNE   LC935
        JSR   LFFCF
        STA   $02EE
        JSR   LFFB7
        BNE   LC935
        DEC   $02EC
        BNE   LC8EB
        LDX   $02ED
        LDA   $02EE
        JSR   LA45F
        LDA   #$20
        JSR   LFFD2
LC914   JSR   LFFCF
        PHA    
        JSR   LFFB7
        BNE   LC934
        PLA    
        BEQ   LC926
        JSR   LFFD2
        JMP   LC914
LC926   LDA   #$0D
        JSR   LFFD2
        JSR   LFFE1
        BEQ   LC935
        LDY   #$02
        BNE   LC8E8
LC934   PLA    
LC935   JSR   LFFCC
        LDA   #$00
        CLC    
        JMP   LFFC3
LC93E   JMP   L94A1
        LDA   #$66
        JSR   LCB21
        JSR   LCCB5
        LDY   #$04
        JSR   LCA3F
        JMP   LA7E1
        LDA   #$E6
        JSR   LCB21
        JSR   LCCB5
        LDA   #$00
        STA   $0278
        STA   $0A
        LDY   #$05
        JSR   LCA3F
        JMP   LA7FA
        JSR   LCB1F
        JSR   LCCAF
        AND   #$11
        CMP   #$11
        BEQ   LC977
LC974   JMP   L94A1
LC977   JSR   LFFE7
        JSR   LCD2B
        BNE   LC996
        LDY   #$09
        JSR   LCA3F
        JSR   LCCCF
        BIT   Running                 ; BASIC program running?
        BMI   LC996
        LDY   #$00
        LDA   #$7A
        JSR   $0494
        CMP   #$32
        BCS   LC997
LC996   RTS    
LC997   LDX   #$24
        JMP   L8683
        JSR   LCB1F
        JSR   LCCAF
        JSR   LCD2B
        BNE   LC996
        LDY   #$0F
        JSR   LCA3F
        JSR   LCCCF
        BIT   Running                 ; BASIC program running?
        BMI   LC996
        LDA   #$0D
        JSR   LFFD2
        LDY   #$00
LC9BA   LDA   #$7A
        JSR   $0494
        BEQ   LC9C7
        JSR   LFFD2
        INY    
        BNE   LC9BA
LC9C7   LDA   #$0D
        JMP   LFFD2
        JSR   LCB1F
        AND   #$E7
        BNE   LC974
        JSR   LFFE7
        LDY   #$14
        BNE   LCA3F
        JSR   LCB1F
        AND   #$30
        CMP   #$30
        BNE   LC9E9
        LDA   $82
        AND   #$C7
        BEQ   LC9F0
LC9E9   LDA   $82
        JSR   LCCC0
        LDA   $82
LC9F0   LDY   #$17
        BNE   LCA3F
        LDA   #$E4
        JSR   LCB21
        JSR   LCCC6
        LDY   #$1E
        BNE   LCA3F
        LDA   #$C7
        JSR   LCB21
        AND   #$30
        CMP   #$30
        BEQ   LCA0E
        JMP   L94A1
LCA0E   JSR   LFFE7
        LDY   #$25
        JMP   LCA3F
LCA16   PHA    
        LDA   $025D
        LDX   #$7C
        LDY   #$02
        JSR   LFFBD
        LDA   $0276
        LDX   $0277
        LDY   $0278
        JSR   LFFBA
        PLA    
        BEQ   LCA3E
        LDX   $025D
        SEC    
        JSR   LFFC0
        LDA   $0276
        SEC    
        JMP   LFFC3
LCA3E   RTS    
LCA3F   JSR   LCD57
        LDX   #$00
        STX   $025D
LCA47   LDA   $CAF5,y
        BEQ   LCA16
        CMP   #$80
        BEQ   LCA16
        TAX    
        DEX    
        BEQ   LCA72
        DEX    
        BEQ   LCA78
        DEX    
        BEQ   LCA7E
        DEX    
        BEQ   LCA85
        DEX    
        BEQ   LCA8D
        DEX    
        BEQ   LCA97
        DEX    
        BEQ   LCAA5
        DEX    
        BEQ   LCAAF
        DEX    
        BEQ   LCAD2
LCA6C   JSR   LCAEB
LCA6F   INY    
        BNE   LCA47
LCA72   LDA   $82
        AND   #$10
        BEQ   LCA6F
LCA78   LDA   $026F
        JMP   LCA81
LCA7E   LDA   $0273
LCA81   ORA   #$30
        BNE   LCA6C
LCA85   LDA   #$40
        BIT   $82
        BMI   LCA6C
        BPL   LCA6F
LCA8D   LDA   $026E
        BEQ   LCA6F
        LDA   #$3A
        JSR   LCAEB
LCA97   TYA    
        PHA    
        LDA   $0270
        LDY   $0271
        LDX   $026E
        JMP   LCABA
LCAA5   LDA   $0272
        BEQ   LCA6F
        LDA   #$3A
        JSR   LCAEB
LCAAF   TYA    
        PHA    
        LDA   $0274
        LDY   $0275
        LDX   $0272
LCABA   STA   $22
        STY   $23
        STX   $80
        LDY   #$00
LCAC2   JSR   $04B0
        JSR   LCAEB
        INY    
        CPY   $80
        BNE   LCAC2
        PLA    
        TAY    
        JMP   LCA6F
LCAD2   LDA   $0279
        BEQ   LCA6F
        LDA   #$2C
        JSR   LCAEB
        LDA   $0279
        JSR   LCAEB
        LDA   $027A
        JSR   LCAEB
        JMP   LCA6F
LCAEB   LDX   $025D
        STA   $027C,x
        INC   $025D
        RTS    
        BIT   $07
        ORA   DIRECTION
        SKB   $02
        NOP    
        ASL   DIRECTION
        LSR   $3A02
        ASL   $09
        SKB   $53
        HLT    
        NOP    
        ASL   $80
        LSR   $02,x
        SKB   $43
        ASO   ($07,x)
        AND   $0502,x
        SKB   $52
        HLT    
        NOP    
        PHP    
        AND   $8006,x
        SKB   $03
        AND   $8002,x
LCB1F   LDA   #$00
LCB21   PHA    
        LDA   #$00
        STA   $82
        LDX   #$1E
LCB28   STA   $025E,x
        DEX    
        BNE   LCB28
        LDX   #$08
        STX   $0277
        LDX   #$6F
        STX   $0278
        LDX   #$00
        STX   $0276
        JSR   $0479
        BNE   LCB49
LCB42   PLA    
        JSR   LCCAA
        LDA   $82
        RTS    
LCB49   CMP   #$44
        BEQ   LCB6A
        CMP   #$91
        BEQ   LCB9F
        CMP   #$55
        BEQ   LCB64
        CMP   #$49
        BEQ   LCB83
        CMP   #$22
        BEQ   LCBA5
        CMP   #$28
        BEQ   LCBA5
LCB61   JMP   L94A1
LCB64   JSR   LCC58
        JMP   LCBCD
LCB6A   LDA   #$10
        JSR   LCCAA
        JSR   LCC97
        CPX   #$02
        BCS   LCB80
        STX   $026F
        STX   $0273
        LDA   #$10
        BNE   LCBCD
LCB80   JMP   LCC49
LCB83   LDA   $027B
        BNE   LCB61
        JSR   $0473
        STA   $0279
        JSR   $0473
        STA   $027A
        LDA   #$FF
        STA   $027B
        JSR   $0473
        JMP   LCBD1
LCB9F   JSR   LCC51
        JMP   LCBCD
LCBA5   LDA   #$01
        JSR   LCC69
        STA   $026E
        STA   $025D
        LDA   #$5E
        STA   $0270
        STA   $24
        LDA   #$02
        STA   $0271
        STA   $25
        LDY   #$00
LCBC0   JSR   $04B0
        STA   ($24),y
        INY    
        CPY   $025D
        BCC   LCBC0
        LDA   #$01
LCBCD   ORA   $82
        STA   $82
LCBD1   JSR   $0479
        BNE   LCBD9
LCBD6   JMP   LCB42
LCBD9   CMP   #$2C
        BNE   LCBE3
        JSR   $0473
        JMP   LCB49
LCBE3   CMP   #$91
        BEQ   LCB9F
        CMP   #$A4
        BNE   LCC46
LCBEB   JSR   $0473
        CMP   #$44
        BEQ   LCC02
        CMP   #$91
        BEQ   LCC15
        CMP   #$55
        BEQ   LCC1B
        CMP   #$22
        BEQ   LCC21
        CMP   #$28
        BEQ   LCC21
LCC02   LDA   #$20
        JSR   LCCAA
        JSR   LCC97
        CPX   #$02
        BCS   LCC49
        STX   $0273
        LDA   #$20
        BNE   LCC31
LCC15   JSR   LCC51
        JMP   LCC31
LCC1B   JSR   LCC58
        JMP   LCC31
LCC21   LDA   #$02
        JSR   LCC69
        STA   $0272
        STX   $0274
        STY   $0275
        LDA   #$02
LCC31   ORA   $82
        STA   $82
        JSR   $0479
        BEQ   LCBD6
        CMP   #$2C
        BEQ   LCBEB
        CMP   #$91
        BEQ   LCC15
        CMP   #$55
        BEQ   LCC1B
LCC46   LDX   #$0B
        BIT   $0EA2
        BIT   $17A2
        JMP   L8683
LCC51   JSR   $0473
        CMP   #$55
        BNE   LCC46
LCC58   JSR   LCC97
        CPX   #$20
        BCS   LCC49
        CPX   #$03
        BCC   LCC49
        STX   $0277
        LDA   #$08
        RTS    
LCC69   JSR   LCCAA
        JSR   L9C48
        TAX    
        BEQ   LCC49
        LDY   #$00
        JSR   $04B0
        CMP   #$40
        BNE   LCC8D
        LDA   #$80
        JSR   LCCAA
        LDA   $82
        ORA   #$80
        STA   $82
        DEX    
        INC   $22
        BNE   LCC8D
        INC   $23
LCC8D   TXA    
        CMP   #$11
        BCS   LCC4C
        LDX   $22
        LDY   $23
        RTS    
LCC97   JSR   $0473
        BEQ   LCC46
        BCC   LCCA7
        JSR   L948E
        JSR   L9D84
        JMP   L948B
LCCA7   JMP   L9D84
LCCAA   AND   $82
        BNE   LCC46
        RTS    
LCCAF   AND   #$E6
        BEQ   LCCB5
LCCB3   BNE   LCC46
LCCB5   LDA   $82
        AND   #$01
        CMP   #$01
        BNE   LCCB3
        LDA   $82
        RTS    
LCCC0   AND   #$C4
        BNE   LCCB3
        LDA   $82
LCCC6   AND   #$03
        CMP   #$03
        BNE   LCCB3
        LDA   $82
        RTS    
LCCCF   LDA   $79
        BNE   LCCE4
        LDA   #$28
        STA   $79
        JSR   LA906
        STX   $7A
        STY   $7B
        LDY   #$28
        JSR   LCDBA
        NOP    
LCCE4   LDX   $0277
        BNE   LCCEE
        LDX   #$08
        STX   $0277
LCCEE   LDA   #$00
        LDY   #$6F
        JSR   LFFBA
        LDA   #$00
        JSR   LFFBD
        JSR   LFFC0
        LDX   #$00
        JSR   LFFC6
        BCS   LCD1F
        LDY   #$FF
LCD06   INY    
        JSR   LFFCF
        CMP   #$0D
        BEQ   LCD12
        STA   ($7A),y
        BNE   LCD06
LCD12   LDA   #$00
        STA   ($7A),y
        JSR   LFFCC
        LDA   #$00
        SEC    
        JMP   LFFC3
LCD1F   PHA    
        JSR   LCD12
        JSR   LCD57
        PLA    
        TAX    
        JMP   L8683
LCD2B   BIT   Running                 ; BASIC program running?
        BMI   LCD54
        JSR   PrintMessage
        EOR   ($52,x)
        EOR   $20
        EOR   $554F,y
        JSR   $5553
        HLT    
        EOR   $3F
        BRK    
        JSR   LFFCC
        JSR   LFFCF
        PHA    
LCD47   CMP   #$0D
        BEQ   LCD50
        JSR   LFFCF
        BNE   LCD47
LCD50   PLA    
        CMP   #$59
        RTS    
LCD54   LDA   #$00
        RTS    
LCD57   TYA    
        PHA    
        LDA   $79
        BEQ   LCD67
        LDY   #$28
        TYA    
        STA   ($7A),y
        INY    
        LDA   #$FF
        STA   ($7A),y
LCD67   LDA   #$00
        STA   $79
        PLA    
        TAY    
        RTS    
        BIT   $2030
        EOR   $4B45,y
LCD74   TAX    
        TYA    
        PHA    
        LDA   #$00
        JSR   LA45F
        PLA    
        TAY    
        RTS    
LCD7F   STA   $3A
        DEY    
        TAX    
        INX    
        BNE   LCD88
        STX   Running                 ; Set
LCD88   RTS    
        CLD    
        ASO   $0C14,y
        ASO   $7B
        ORA   ($D7,x)
        CLD    
        ORA   ($07),y
        BPL   LCDB3
        RRA   $D817,y
        ASO   $10
        ORA   $1A
        NOP    
        ASL   $7B,x
        ASO   $1BD8,x
        BPL   LCDA7
        NOP    
        ASO   $7B,x
        ASO   ($47),y
        CLD    
        LDY   #$21
LCDAD   LDA   $CD89,y
        EOR   #$55
        JSR   LFFD2
        DEY    
        BPL   LCDAD
        RTS    
        BRK    
LCDBA   LDA   #$79
        STA   ($7A),y
        LDA   #$00
        INY    
        STA   ($7A),y
        RTS    
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
LCE00   TSX    
        LDA   $0104,x
        AND   #$10
        BNE   LCE0B
        JMP   ($0314)
LCE0B   JMP   ($0316)
        LDA   IRQ_STATUS
        AND   #$02
        BEQ   LCE18
        JSR   LCE60
LCE18   BIT   $07D8
        BPL   LCE2B
        LDA   $FD01
        STA   $07D4
        BPL   LCE2B
        JSR   LEA95
        JSR   LEA5B
LCE2B   JSR   LE3E4
        LDA   IRQ_STATUS
        AND   #$02
        BEQ   LCE5D
        STA   IRQ_STATUS
        BIT   RasterIRQcomp
        LDA   #$CC
        BVC   LCE5A
        JMP   ($0312)
        JSR   LCFBF
LCE45   JSR   LCECD
        LDA   $FB
        PHA    
        LDA   #$00
        STA   $FB
        PHP    
        CLI    
        JSR   LDB11
        PLP    
        PLA    
        STA   $FB
        LDA   #$A1
LCE5A   STA   RasterIRQcomp
LCE5D   JMP   LFCBE
LCE60   LDA   CurrRasterHI
        AND   #$01
        BNE   LCEA0
        LDA   CurrRasterLO
        CMP   #$A3
        BCS   LCE9C
        BIT   $83
        BVC   LCEC4
        LDA   #$08
        STA   ScreenAddress
        LDA   TEDREG_06
        AND   #$DF
        TAY    
        LDA   TEDREG_07
        AND   #$EF
        TAX    
        LDA   Voice1_BitMap
        ORA   $07FA
        PHA    
LCE8A   LDA   CurrRasterLO
        CMP   #$A3
        BCC   LCE8A
        PLA    
        STA   Voice1_BitMap
        STY   TEDREG_06
        STX   TEDREG_07
        RTS    
LCE9C   CMP   #$CC
        BCC   LCEC4
LCEA0   LDX   $83
        BEQ   LCEC4
        BPL   LCEAE
        LDA   TEDREG_07
        ORA   #$10
        STA   TEDREG_07
LCEAE   LDA   TEDREG_06
        ORA   #$20
        STA   TEDREG_06
        LDA   Voice1_BitMap
        AND   #$FB
        STA   Voice1_BitMap
        LDA   $07FB
        STA   ScreenAddress
LCEC4   RTS    
        NOP    
        NOP    
        NOP    
        NOP    
        NOP    
        NOP    
        NOP    
        NOP    
LCECD   LDX   #$01
LCECF   LDA   $04FC,x
        ORA   $04FE,x
        BEQ   LCEEA
        INC   $04FC,x
        BNE   LCEEA
        INC   $04FE,x
        BNE   LCEEA
        LDA   $CEEE,x
        AND   SoundSelector
        STA   SoundSelector
LCEEA   DEX    
        BPL   LCECF
        RTS    
        INS   $E69F
        LDA   $D0
        ASL   $E6
        LDY   $D0
        HLT    
        INC   $A3
        SEC    
        LDA   $A5
        SBC   #$01
        LDA   $A4
        SBC   #$1A
        LDA   $A3
        SBC   #$4F
        BCC   LCF11
        LDX   #$00
        STX   $A3
        STX   $A4
        STX   $A5
LCF11   LDA   #$7F
        JSR   LDB70
        STA   $EE
        LDA   #$7F
        JSR   LDB70
        CMP   $EE
        BNE   LCF11
        ORA   #$7F
        STA   $91
        RTS    
LCF26   SEI    
        LDA   $A5
        LDX   $A4
        LDY   $A3
LCF2D   SEI    
        STA   $A5
        STX   $A4
        STY   $A3
        CLI    
        RTS    
        ORA   $4F4D
        LSR   $5449
        LSE   $8D52
        ORA   $5242
        EOR   $41
LCF44   SAX   #$0D
        JSR   $2020
        BVC   LCF8E
        JSR   $5320
        HLT    
        JSR   $4341
        JSR   $5258
        JSR   $5259
        JSR   $5053
        ORA   $A03B
        EOR   ($A0,x)
        JSR   $5245
        HLT    
        LSE   $BDD2
        ROL   $CF,x
        PHP    
        AND   #$7F
        JSR   LFFD2
        INX    
        PLP    
        BPL   LCF66
        RTS    
LCF74   LDA   #$0D
        LDX   $98
        CPX   #$03
        BEQ   LCF82
        LDX   $99
        CPX   #$03
        BEQ   LCF85
LCF82   JSR   LDC49
LCF85   LDA   #$0D
        JMP   LD9B0
LCF8A   LDA   $0113,x
        BIT   $07F9
        BPL   LCF95
        LDA   $E143,x
LCF95   RTS    
LCF96   BIT   $07F8
        BMI   LCF9E
        LDA   ($A1),y
        RTS    
LCF9E   LDA   #$A1
        STA   $07DF
        JMP   $07D9
LCFA6   LDA   #$09
        STA   $FD20
        ORA   #$80
        STA   $FD20
        JMP   LFC1E
        PHP    
        SEI    
        STA   RAM_ON
        LDA   (DIRECTION),y
        STA   ROM_ON
        PLP    
        RTS    
LCFBF   LDA   $FD10
        AND   #$04
        BNE   LCFE1
        BIT   $07FC
        BMI   LCFD1
        LDA   IO
        AND   #$F7
        STA   IO
LCFD1   DEC   $07FD
        BPL   LCFDE
        LDA   #$04
        STA   $07FD
        JSR   LCEF0
LCFDE   JMP   LCEF0
LCFE1   STA   $07FC
        JSR   LE3B0
        JMP   LCFD1
LCFEA   INX    
        STX   $FEC4
        STX   $FEC0
        LDA   #$80
        STA   SoundSelector
        RTS    

        db    $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff       ; unused

        ;
        ; Character ROM goes here....
        ;
        DS    $800
        
LD800   ASL   $05
        BRK    
        PLP    
        BVC   LD87E
        LDY   #$C8
        BEQ   LD822
        RTI    
        PLA    
        BCC   LD7C6
LD80E   CPX   #$08
        BMI   LD86A
        SKB   $A8
        BNE   LD80E
        JSR   $7048
        TYA    
        CPY   #$0C
        SKW   $0C0C
        SKW   $0C0C
LD822   ORA   $0D0D
        ORA   $0D0D
        ASL   $0E0E
        ASL   $0E0E
        ASL   $0F0F
        ASO   $0F0F
LD834   LDX   #$28
        LDY   #$19
        RTS    
LD839   BCS   LD849
        STX   $CD
        STX   $C4
        STY   $CA
        STY   $C5
        JSR   LDE70
        JSR   LD8A8
LD849   LDX   $CD
        LDY   $CA
        RTS    
LD84E   LDA   #$0C
        STA   $053E
        LDA   #$03
        STA   $99
        LDA   #$00
        STA   $98
        STA   $0547
        STA   $83
        STA   $EF
        STA   $F0
        LDA   #$7A
        STA   $0545
        LDA   #$DB
        STA   $0546
        LDA   #$0A
        STA   $053F
        STA   $054A
        STA   $0542
        LDA   #$80
        STA   $0540
LD87E   LDA   #$10
        STA   $053B
        LDA   #$04
        STA   $0541
        JSR   LDE70
LD88B   JSR   LD89A
LD88E   JSR   LD8AA
        JSR   LDAF7
        CPX   $07E5
        INX    
        BCC   LD88E
LD89A   LDX   $07E6
        STX   $CD
        STX   $C4
LD8A1   LDY   $07E7
        STY   $CA
        STY   $C5
LD8A8   LDX   $CD
LD8AA   LDA   $D802,x
        STA   $C8
        LDA   $D81B,x
        STA   $C9
LD8B4   LDA   $C8
        STA   $EA
        LDA   $C9
        AND   #$03
        ORA   #$08
        STA   $EB
        RTS    
LD8C1   LDX   $055D
        BEQ   LD8D5
        LDY   $055E
        LDA   $0567,y
        DEC   $055D
        INC   $055E
        CLI    
        CLC    
        RTS    
LD8D5   LDY   $0527
        NOP    
LD8D9   LDA   $0528,x
        STA   $0527,x
        INX    
        CPX   $EF
        BNE   LD8D9
        DEC   $EF
        TYA    
        CLI    
        CLC    
        RTS    
LD8EA   JSR   LDC49
LD8ED   JSR   LD8B4
        LDY   $CA
        LDA   ($EA),y
        PHA    
        LDA   $053B
        STA   ($EA),y
        TYA    
        CLC    
        ADC   $C8
        STA   CursorLO
        LDA   $C9
        ADC   #$00
        SBC   #$0B
        STA   CursorHI
LD90A   LDA   $EF
        ORA   $055D
        BEQ   LD90A
        PLA    
        STA   ($EA),y
        LDA   #$FF
        STA   CursorHI
        STA   CursorLO
        JSR   LD8C1
        CMP   #$83
        BNE   LD933
        LDX   #$09
        SEI    
        STX   $EF
LD928   LDA   $E129,x
        STA   $0526,x
        DEX    
        BNE   LD928
LD931   BEQ   LD8ED
LD933   CMP   #$0D
        BNE   LD8EA
        STA   $C7
        JSR   LDF95
        STX   $0549
        JSR   LDF87
        LDA   #$00
        STA   $CB
        LDY   $07E7
        LDA   $C4
        BMI   LD960
        CMP   $CD
        BCC   LD960
        LDY   $C5
        CMP   $0549
        BNE   LD95C
        CPY   $C3
        BEQ   LD95E
LD95C   BCS   LD96F
LD95E   STA   $CD
LD960   STY   $CA
        JMP   LD977
LD965   TYA    
        PHA    
        TXA    
        PHA    
        LDA   $C7
        BEQ   LD931
        BPL   LD977
LD96F   LDA   #$00
        STA   $C7
        JMP   LCF74
        NOP    
LD977   JSR   LD8A8
        JSR   LDF2F
        STA   $CE
        AND   #$3F
        ASL   $CE
        BIT   $CE
        BPL   LD989
        ORA   #$80
LD989   BCC   LD98F
        LDX   $CB
        BNE   LD993
LD98F   BVS   LD993
        ORA   #$40
LD993   JSR   LD9BA
        LDY   $CD
        CPY   $0549
        BCC   LD9A7
        LDY   $CA
        CPY   $C3
        BCC   LD9A7
        ROR   $C7
        BMI   LD9AA
LD9A7   JSR   LDFBF
LD9AA   CMP   #$DE
        BNE   LD9B0
        LDA   #$FF
LD9B0   STA   $CE
        PLA    
        TAX    
        PLA    
        TAY    
        LDA   $CE
        CLC    
        RTS    
LD9BA   CMP   #$22
        BNE   LD9C6
        LDA   $CB
        EOR   #$01
        STA   $CB
        LDA   #$22
LD9C6   RTS    
        LDA   $CE
        STA   $07EB
        PLA    
        TAY    
        LDA   $CF
        BEQ   LD9D4
        LSR   $CB
LD9D4   PLA    
        TAX    
        PLA    
        CLC    
        RTS    
LD9D9   ORA   #$40
LD9DB   LDX   $C2
        BEQ   LD9E1
LD9DF   ORA   #$80
LD9E1   LDX   $CF
        BEQ   LD9E7
        DEC   $CF
LD9E7   BIT   $07EA
        BPL   LD9F5
        PHA    
        JSR   LDDCE
        LDX   #$00
        STX   $CF
        PLA    
LD9F5   JSR   LE001
LD9F8   CPY   $07E8
        BCC   LDA09
        LDX   $CD
        CPX   $07E5
        BCC   LDA09
        BIT   $07E9
        BMI   LDA20
LDA09   JSR   LD8A8
        JSR   LDFBF
        BCC   LDA20
        JSR   LDF39
        BCS   LDA1F
        SEC    
        BIT   $07E9
        BVS   LDA20
        JSR   LDA5E
LDA1F   CLC    
LDA20   RTS    
LDA21   LDX   $CD
        CPX   $07E5
        BCC   LDA38
        BIT   $07E9
        BPL   LDA34
        LDA   $07E6
        STA   $CD
        BCS   LDA3A
LDA34   JSR   LDA89
        CLC    
LDA38   INC   $CD
LDA3A   JMP   LD8A8
LDA3D   LDA   $D802,x
        STA   $A9
        STA   $C0
        LDA   $D81B,x
        STA   $C1
        AND   #$03
        ORA   #$08
        STA   $AA
LDA4F   LDA   ($C0),y
        STA   ($C8),y
        LDA   ($A9),y
        STA   ($EA),y
        CPY   $07E8
        INY    
        BCC   LDA4F
        RTS    
LDA5E   LDX   $C4
        BMI   LDA68
        CPX   $CD
        BCC   LDA68
        INC   $C4
LDA68   LDX   $07E5
LDA6B   JSR   LD8AA
        LDY   $07E7
        CPX   $CD
        BEQ   LDA83
        DEX    
        JSR   LDF3B
        INX    
        JSR   LDF48
        DEX    
        JSR   LDA3D
        BCS   LDA6B
LDA83   JSR   LDAF7
        JMP   LDF59
LDA89   LDX   $07E6
LDA8C   INX    
        JSR   LDF3B
        BCC   LDA9E
        CPX   $07E5
        BCC   LDA8C
        LDX   $07E6
        INX    
        JSR   LDF4A
LDA9E   DEC   $CD
        BIT   $C4
        BMI   LDAA6
        DEC   $C4
LDAA6   LDX   $07E6
        CPX   $FE
        BCS   LDAAF
        DEC   $FE
LDAAF   JSR   LDAC5
        LDX   $07E6
        JSR   LDF3B
        PHP    
        JSR   LDF4A
        PLP    
        BCC   LDAC4
        BIT   $07EC
        BMI   LDA89
LDAC4   RTS    
LDAC5   JSR   LD8AA
        LDY   $07E7
        CPX   $07E5
        BCS   LDADE
        INX    
        JSR   LDF3B
        DEX    
        JSR   LDF48
        INX    
        JSR   LDA3D
        BCS   LDAC5
LDADE   JSR   LDAF7
        LDA   #$7F
        JSR   LDB70
        CMP   #$DF
        BNE   LDAF3
        LDY   #$00
LDAEC   NOP    
        DEX    
        BNE   LDAEC
        DEY    
        BNE   LDAEC
LDAF3   RTS    
        NOP    
        NOP    
        NOP    
LDAF7   LDY   $07E7
        JSR   LDF4A
LDAFD   JSR   LD8AA
        DEY    
LDB01   INY    
        LDA   #$20
        STA   ($C8),y
        LDA   $053B
        STA   ($EA),y
        CPY   $07E8
        BNE   LDB01
        RTS    
LDB11   LDA   #$00
        STA   $0543
        LDY   #$40
        STY   $C6
        JSR   LDB70
        TAX    
        CPX   #$FF
        BNE   LDB25
        JMP   LDC01
LDB25   LDY   #$00
        LDA   #$26
        STA   $EC
        LDA   #$E0
        STA   $ED
        LDA   #$FE
LDB31   LDX   #$08
        PHA    
LDB34   PLA    
        PHA    
        JSR   LDB70
        STA   $EE
        PLA    
        PHA    
        JSR   LDB70
        CMP   $EE
        BNE   LDB34
LDB44   LSR    
        BCS   LDB5D
        PHA    
        LDA   ($EC),y
        CMP   #$05
        BCS   LDB5A
        CMP   #$03
        BEQ   LDB5A
        ORA   $0543
        STA   $0543
        BPL   LDB5C
LDB5A   STY   $C6
LDB5C   PLA    
LDB5D   INY    
        CPY   #$41
        BCS   LDB6A
        DEX    
        BNE   LDB44
        SEC    
        PLA    
        ROL    
        BNE   LDB31
LDB6A   PLA    
        LDA   $C6
        JMP   ($0545)
LDB70   STA   $FD30
        STA   KeyboardLatch
        LDA   KeyboardLatch
        RTS    
        LDA   $0543
        CMP   #$03
        BNE   LDB9A
        LDA   $0547
        BMI   LDBBA
        LDA   $0544
        BNE   LDBBA
        LDA   CharBase
        EOR   #$04
        STA   CharBase
        LDA   #$08
        STA   $0544
        BNE   LDBBA
LDB9A   ASL    
        CMP   #$08
        BCC   LDBAF
        LDA   #$06
        LDX   $07F7
        BNE   LDBAF
        LDX   $C6
        CPX   #$0D
        BNE   LDBAF
        STX   $F0
        RTS    
LDBAF   TAX    
        LDA   $E01E,x
        STA   $EC
        LDA   $E01F,x
        STA   $ED
LDBBA   LDY   $C6
        LDA   ($EC),y
        TAX    
        CPY   $07F6
        BEQ   LDBCB
        LDY   #$10
        STY   $0542
        BNE   LDC01
LDBCB   AND   #$7F
        BIT   $0540
        BMI   LDBE8
        BVS   LDC2B
        CMP   #$7F
        BEQ   LDC01
        CMP   #$14
        BEQ   LDBE8
        CMP   #$20
        BEQ   LDBE8
        CMP   #$1D
        BEQ   LDBE8
        CMP   #$11
        BNE   LDC2B
LDBE8   LDY   $0542
        BEQ   LDBF2
        DEC   $0542
        BNE   LDC2B
LDBF2   DEC   $0541
        BNE   LDC2B
        LDY   #$04
        STY   $0541
        LDY   $EF
        DEY    
        BPL   LDC2B
LDC01   NOP    
        NOP    
        LSR   $0544
        LDY   $C6
        STY   $07F6
        CPX   #$FF
        BEQ   LDC2B
        TXA    
        LDX   #$00
        STX   $F0
        LDX   #$07
LDC16   CMP   $DC41,x
        BEQ   LDC2C
        DEX    
        BPL   LDC16
        LDX   $EF
        CPX   $053F
        BCS   LDC2B
        STA   $0527,x
        INX    
        STX   $EF
LDC2B   RTS    
LDC2C   LDA   $055F,x
        STA   $055D
        LDA   #$00
LDC34   DEX    
        BMI   LDC3D
        CLC    
        ADC   $055F,x
        BCC   LDC34
LDC3D   STA   $055E
        RTS    
        STA   $89
        STX   $8A
        AXS   $8B
        DEY    
        STY   $CE85
        PHA    
        TXA    
        PHA    
        TYA    
        PHA    
LDC50   LDA   $F0
        BNE   LDC50
        STA   $C7
        LDA   #$D9
        PHA    
        LDA   #$C6
        PHA    
        LDY   $CA
        LDA   $CE
        CMP   #$0D
        BEQ   LDC8C
        CMP   #$8D
        BEQ   LDC8C
        LDX   $07EB
        CPX   #$1B
        BNE   LDC72
        JMP   LDE06
LDC72   TAX    
        BMI   LDC89
        CMP   #$20
        BCC   LDCA7
        CMP   #$60
        BCC   LDC81
        AND   #$DF
        BNE   LDC83
LDC81   AND   #$3F
LDC83   JSR   LD9BA
        JMP   LD9DB
LDC89   JMP   LDD47
LDC8C   JSR   LDF95
        INX    
        JSR   LDF4A
        LDY   $07E7
        STY   $CA
        JSR   LDA21
        LDA   #$00
        STA   $CF
        STA   $C2
        STA   $CB
        STA   $053C
        RTS    
LDCA7   CMP   #$1B
        BEQ   LDCF9
        LDX   $CF
        BEQ   LDCB2
LDCAF   JMP   LD9DF
LDCB2   CMP   #$14
        BNE   LDCB9
        JMP   LDD99
LDCB9   LDX   $CB
        BNE   LDCAF
        CMP   #$12
        BNE   LDCC3
        STA   $C2
LDCC3   CMP   #$13
        BNE   LDCD2
        CMP   $07EB
        BNE   LDCCF
        JSR   LDE70
LDCCF   JMP   LD89A
LDCD2   CMP   #$1D
        BEQ   LDCFA
        CMP   #$11
        BEQ   LDD00
        CMP   #$0E
        BEQ   LDD27
        CMP   #$08
        BEQ   LDD2E
        CMP   #$09
        BEQ   LDD35
LDCE6   LDX   #$0F
LDCE8   CMP   $E133,x
        BEQ   LDCF1
        DEX    
        BPL   LDCE8
        RTS    
LDCF1   PHA    
        JSR   LCF8A
        STA   $053B
        PLA    
LDCF9   RTS    
LDCFA   JSR   LDFBF
        BCS   LDD03
        RTS    
LDD00   JSR   LDA21
LDD03   JSR   LDF39
        BCS   LDD0B
        SEC    
        ROR   $C4
LDD0B   CLC    
LDD0C   RTS    
LDD0D   LDX   $07E6
        CPX   $CD
        BCS   LDD0C
LDD14   JSR   LDD03
        DEC   $CD
        JMP   LD8A8
LDD1C   JSR   LDFD4
        BCS   LDD0C
        BNE   LDD0B
        INC   $CD
        BNE   LDD14
LDD27   LDA   CharBase
        ORA   #$04
        BNE   LDD43
LDD2E   LDA   #$80
        ORA   $0547
        BMI   LDD3A
LDD35   LDA   #$7F
        AND   $0547
LDD3A   STA   $0547
        RTS    
LDD3E   LDA   CharBase
        AND   #$FB
LDD43   STA   CharBase
        RTS    
LDD47   AND   #$7F
        CMP   #$7F
        BNE   LDD4F
        LDA   #$5E
LDD4F   CMP   #$20
        BCC   LDD56
        JMP   LD9D9
LDD56   LDX   $CB
        BEQ   LDD5F
LDD5A   ORA   #$40
        JMP   LD9DF
LDD5F   CMP   #$14
        BEQ   LDDCE
        LDX   $CF
        BNE   LDD5A
        CMP   #$11
        BEQ   LDD0D
        CMP   #$12
        BNE   LDD73
        LDA   #$00
        STA   $C2
LDD73   CMP   #$1D
        BEQ   LDD1C
        CMP   #$13
        BNE   LDD7E
        JMP   LD88B
LDD7E   CMP   #$02
        BNE   LDD87
        LDA   #$80
        STA   $053C
LDD87   CMP   #$04
        BNE   LDD90
        LDA   #$00
        STA   $053C
LDD90   CMP   #$0E
        BEQ   LDD3E
        ORA   #$80
        JMP   LDCE6
LDD99   JSR   LDD1C
        JSR   LDFF6
        BCS   LDDB1
LDDA1   CPY   $07E8
        BCC   LDDBC
        LDX   $CD
        INX    
        JSR   LDF3B
        BCS   LDDBC
        JSR   LDFFF
LDDB1   LDA   $CC
        STA   $CA
        LDA   $FE
        STA   $CD
        JMP   LD8A8
LDDBC   JSR   LDFBF
        JSR   LDF2F
        JSR   LDFD4
        JSR   LE011
        JSR   LDFBF
        JMP   LDDA1
LDDCE   JSR   LDFF6
        JSR   LDF95
        CPX   $FE
        BNE   LDDDA
        CPY   $CC
LDDDA   BCC   LDDFD
        JSR   LD9F8
        BCS   LDE03
LDDE1   JSR   LDFD4
        JSR   LDF2F
        JSR   LDFBF
        JSR   LE011
        JSR   LDFD4
        LDX   $CD
        CPX   $FE
        BNE   LDDE1
        CPY   $CC
        BNE   LDDE1
        JSR   LDFFF
LDDFD   INC   $CF
        BNE   LDE03
        DEC   $CF
LDE03   JMP   LDDB1
LDE06   AND   #$7F
        SEC    
        SBC   #$41
        CMP   #$17
        BCS   LDE19
        ASL    
        TAX    
        LDA   $DE1B,x
        PHA    
        LDA   $DE1A,x
        PHA    
LDE19   RTS    
        PLP    
        DCM   $DE5F,x
        AND   $DF
        ???   
        CLC    
        DEC   $DE18,x
        CLC    
        DEC   $DE18,x
        TXA    
        DEC   $DF81,x
        STY   $DF,x
        SKW   $1FDF
        DCM   $D887,x
        TXS    
        SKW   $DEE0
        DEX    
        DEC   $DE47,x
        CLC    
        DEC   $DE5D,x
        CLC    
        DEC   $DEF5,x
        ASO   ($DF,x)
        JSR   LDE70
        JSR   LD88B
        LDA   #$01
        TAX    
        JSR   LDE7A
        LDA   #$17
        LDX   #$26
        JSR   LDE67
        JMP   LD89A
        CLC    
        BIT   $38
        LDX   $CA
        LDA   $CD
        BCC   LDE7A
LDE67   STA   $07E5
        STX   $07E8
        JMP   LDE80
LDE70   LDA   #$18
        LDX   #$27
        JSR   LDE67
        LDA   #$00
        TAX    
LDE7A   STA   $07E6
        STX   $07E7
LDE80   LDA   #$00
        LDX   #$04
LDE84   STA   $07ED,x
        DEX    
        BNE   LDE84
        RTS    
        JSR   LDA5E
        JSR   LD8A1
        INX    
        JSR   LDF3B
        PHP    
        JSR   LDF46
        PLP    
        BCS   LDE9F
        SEC    
        ROR   $C4
LDE9F   RTS    
        JSR   LDF87
        LDA   $07E6
        PHA    
        LDA   $CD
        STA   $07E6
        LDA   $07EC
        PHA    
        LDA   #$80
        STA   $07EC
        JSR   LDA9E
        PLA    
        STA   $07EC
        LDA   $07E6
        STA   $CD
        PLA    
        STA   $07E6
        SEC    
        ROR   $C4
        JMP   LD8A1
        JSR   LDFF6
LDECE   JSR   LDAFD
        INC   $CD
        JSR   LD8A8
        LDY   $07E7
        JSR   LDF39
        BCS   LDECE
LDEDE   JMP   LDDB1
        JSR   LDFF6
LDEE4   JSR   LDFFF
        CPY   $07E7
        BNE   LDEF1
        JSR   LDF39
        BCC   LDEDE
LDEF1   JSR   LDFD4
        BCC   LDEE4
        JSR   LDFF6
        TXA    
        PHA    
        JSR   LDA89
        PLA    
        STA   $FE
        JMP   LDEDE
        JSR   LDFF6
        JSR   LDF39
        BCS   LDF0F
        SEC    
        ROR   $C4
LDF0F   LDA   $07E6
        STA   $CD
        JSR   LDA5E
        JSR   LDF4A
        JMP   LDEDE
        LDA   #$00
        BIT   $80A9
        STA   $07E9
        RTS    
        LDA   #$00
        BIT   $FFA9
        STA   $07EA
        RTS    
LDF2F   LDY   $CA
        LDA   ($EA),y
        STA   $07ED
        LDA   ($C8),y
        RTS    
LDF39   LDX   $CD
LDF3B   JSR   LDF66
        AND   $07EE,x
        CMP   #$01
        JMP   LDF55
LDF46   LDX   $CD
LDF48   BCS   LDF59
LDF4A   JSR   LDF66
        EOR   #$FF
        AND   $07EE,x
LDF52   STA   $07EE,x
LDF55   LDX   $02E9
        RTS    
LDF59   BIT   $07E9
        BVS   LDF3B
        JSR   LDF66
        ORA   $07EE,x
        BNE   LDF52
LDF66   STX   $02E9
        TXA    
        AND   #$07
        TAX    
        LDA   $DF7A,x
        PHA    
        LDA   $02E9
        LSR    
        LSR    
        LSR    
        TAX    
        PLA    
        RTS    
        SKB   $40
        JSR   $0810
        SKB   $02
        ORA   ($AC,x)
        INS   $07
        STY   $CA
LDF87   JSR   LDF39
        BCC   LDF92
        DEC   $CD
        BPL   LDF87
        INC   $CD
LDF92   JMP   LD8A8
LDF95   INC   $CD
        JSR   LDF39
        BCS   LDF95
        DEC   $CD
        JSR   LD8A8
        LDY   $07E8
        STY   $CA
LDFA6   JSR   LDF2F
        CMP   #$20
        BNE   LDFBC
        CPY   $07E7
        BNE   LDFB7
        JSR   LDF39
        BCC   LDFBC
LDFB7   JSR   LDFD4
        BCC   LDFA6
LDFBC   STY   $C3
        RTS    
LDFBF   PHA    
        LDY   $CA
        CPY   $07E8
        BCC   LDFCF
        JSR   LDA21
        LDY   $07E7
        DEY    
        SEC    
LDFCF   INY    
        STY   $CA
        PLA    
        RTS    
LDFD4   LDY   $CA
        DEY    
        BMI   LDFDE
        CPY   $07E7
        BCS   LDFEF
LDFDE   LDY   $07E6
        CPY   $CD
        BCS   LDFF5
        DEC   $CD
        PHA    
        JSR   LD8A8
        PLA    
        LDY   $07E8
LDFEF   STY   $CA
        CPY   $07E8
        CLC    
LDFF5   RTS    
LDFF6   LDY   $CA
        STY   $CC
        LDX   $CD
        STX   $FE
        RTS    
LDFFF   LDA   #$20
LE001   LDY   $CA
        STA   ($C8),y
        JSR   LD8B4
        LDA   $053B
        ORA   $053C
        STA   ($EA),y
        RTS    
LE011   LDY   $CA
        STA   ($C8),y
        JSR   LD8B4
        LDA   $07ED
        STA   ($EA),y
        RTS    
        ROL   $E0
        RRA   $E0
        TAY    
        CPX   #$E9
        CPX   #$14
        ORA   $8C5C
        STA   $89
        STX   $40
        RLA   ($57),y
        EOR   ($34,x)
        NOP    
        LSE   ($45),y
        ORA   ($35,x)
        HLT    
        SKB   $36
        LSE   ($46,x)
        SKB   $58
        RLA   $59,x
        LSE   $38
        HLT    
        PHA    
        EOR   $56,x
        AND   $4A49,y
        BMI   LE098
        ALR   #$4F
        LSR   $5011
        JMP   $2E91
        NOP    
        AND   $9D2C
        ROL    
        RLA   $1B1D,y
        AND   $2F2B,x
LE05E   AND   ($13),y
        SKB   $32
        JSR   $5102
        ASO   ($FF,x)
        STY   $8D,x
        LDA   #$88
        TXA    
        AXS   $8B
        TSX    
        RLA   ($D7,x)
        CMP   ($24,x)
        NOP    
        DCM   ($C5),y
        ORA   ($25,x)
        HLT    
        CPY   $26
        DCM   ($C6,x)
        SKB   $D8
        RLA   $D9
        DCM   $28
        SKB   $C8
        CMP   $D6,x
        AND   #$C9
        DEX    
        LSR   $CBCD,x
        DCM   $11CE
        BNE   LE05E
        STA   ($3E),y
        LSE   $3CDD,y
        STA   $5DC0,x
        ORA   $5F1B,x
        DCM   $213F,y
        ???   
        LDY   #$02
        CMP   ($83),y
        INS   $8D94,x
        TAY    
        DEY    
        TXA    
        AXS   $8B
        LDY   $96
        LAX   ($B0),y
        AXS   $AD,y
        LDX   $01B1
        TYA    
        HLT    
        LDY   $BC99
        ???   
        TXS    
        LAX   $A5,x
        ???   
        LDY   $B8,x
        LDX   $A229,y
        LDA   $30,x
        LAX   $A1
        LDA   $11AA,y
        LAX   $91B6
        ROL   $DC5B,x
        SKW   $DF9D
        EOR   $1B1D,x
        DEC   $3FA6,x
        STA   ($93,x)
        SKB   $95
        LDY   #$02
        OAL   #$83
        INS   $FFFF,x
        SKW   $FFFF
        INS   $FFFF,x
        SKW   $0117
        ???   
        ORA   $FF
        SAY   $0412,x
        ???   
        SKB   $18
        ASO   $0719,x
        ???   
        ORA   $16,x
        HLT    
        ORA   #$0A
        HLT    
        ORA   $0F0B
        ASL   $10FF
        SKW   $84FF
        ASO   $82FF,y
        INS   $1DFF,x
        INS   $061B,x
        INS   $90FF,x
        INS   $05FF,x
        INS   $11FF,x
        INS   $44FF,x
        CPY   $2A22
        ORA   $5552
        LSR   $900D
        ORA   $1C
        ???   
        ???   
        ???   
        STA   $96,x
        AXS   $98,y
        STA   $9B9A,y
        BRK    
        ADC   ($32),y
        RRA   ($44,x)
        AND   $46,x
        RRA   $48,x
        AND   #$5A
        ???   
        ADC   $5F2E
LE153   ORA   #$40


		; *****************************************************
		;
		; Check for serial 
		; A = device to search for ( byte to send )
		;
		; *****************************************************
LE155   db    $2C				; mask "ORA #$20" with "BIT $2009"

LE156   ORA   #$20				; or in $20 to device...(make asci character)

LE158   PHA						; store device number
        BIT   $94				; get serial bus flags
        BPL   LE167				; not set?
        SEC						; set carry for rotating in
        ROR   $A6				; rotate serial bus usage byte (transfer byte?)
        JSR   LE181				; call "send to serial bus"
        LSR   $94				; shift serial bus flags
        LSR   $A6				; shift serial bus control

LE167   PLA						; get Device number back
        STA   $95				; store in buffered character for serial
        
		SEI    
        JSR   LE2C6				; serial clock on (and $01 with $fe)
        JSR   LE2BF				; set $02 in $01
        
		LDA   IO				
        ORA   #$04				; or $04 into $01 (IO control)
        STA   IO

LE177   SEI    
        JSR   LE2BF				; or  $01 with $02
        JSR   LE2C6				; and $01 with $fe
        JSR   LE2DC				; set timer to $400, and wait till it runs out.

LE181   SEI    
        JSR   LE2C6				; and $01 with $fe
        JSR   GetSerialIn		; Wait for line to settle, then clock serial bit into carry
        BCS   LE1E9				; if bit set, then timeout?
        JSR   LE2B8				; serial clock on ($01 and $FD)
        BIT   $A6
        BPL   LE19F

LE191   JSR   GetSerialIn		; wait for serial line to settle
        BCC   LE191				; if line just went LOW (bit was 0) then get again
LE196   LDA   IO				; wait for line to settle
        CMP   IO			
        BNE   LE196
        ASL						; get serial line into carry
        BCS   LE196				; if line HIGH then try again. (get order right?)

		;
		; Send actual byte across serial line
		;
LE19F   JSR   GetSerialIn		; wait for line to settle
        BCC   LE19F				; for for line HIGH
        JSR   LE2BF				; or  $01 with $02
        
		LDA   #$08				; send a whole byte
        STA   $AA

LE1AB   JSR   GetSerialIn
        BCC   LE1EE
        ROR   $95				; rotate byte to send (right to left sending)
        BCS   LE1B9				; bit set? then clock high
        JSR   LE2CD				; serial clock off ($01 OR $01) (set)
        BNE   LE1BC				; force branch (always BNE)

LE1B9   JSR   LE2C6				; $01 and $fe (clear bit 0)

LE1BC   JSR   Delay1ms			; delay 1 millisecond
        JSR   LE2B8				; $01 AND $fd (clear bit 1 - $02) set handshake
        JSR   Delay1ms			; delay 1 millisecond
        LDA   IO				; clear serial send
        AND   #$FE
        ORA   #$02				; clock handshake
        STA   IO				; store
        DEC   $AA				; minus 1 from bits to send counter
        BNE   LE1AB				; loop till all sent

        TXA						; Store "X" on stack
        PHA    

        LDX   #$78				; get timeout value
LE1D5   LDA   IO
        CMP   IO				
        BNE   LE1D5				; wait for serial IN to settle
        ASL						; get serial IN into carry
        BCC   LE1E5				; if CLEAR, then wait till ready (wait till set)
        DEX						; 1 off timeout
        BNE   LE1D5				; and keep going till timeout
        PLA    
        TAX    
        BCS   LE1EE
LE1E5   PLA						; if ready, then exit now
        TAX						; restore "X" from the stack
        CLI						; restore IRQ's
        RTS						; and exit

LE1E9   LDA   #$80				; exit with error
        JMP   LE1F0

LE1EE   LDA   #$03
LE1F0   JSR   LF41E
        CLI    
        CLC    
        BCC   LE242
LE1F7   STA   $95
        JSR   LE177
LE1FC   LDA   IO
        AND   #$FB
        STA   IO
        RTS    


LE203   STA   $95
        JSR   LE177
        BIT   $90
        BMI   LE242
LE20C   SEI    
        JSR   LE2CD
        JSR   LE1FC
        JSR   LE2B8
LE216   BIT   IO
        BVS   LE216
        CLI    
        RTS    
        INS   $9424,x
        BMI   LE226
        SEC    
        ROR   $94
        BNE   LE22B
LE226   PHA    
        JSR   LE181
        PLA    
LE22B   STA   $95
        CLC    
        RTS    
LE22F   SEI    
        JSR   LE2BF
        LDA   IO
        ORA   #$04
        STA   IO
        LDA   #$5F
        BNE   LE23F
LE23D   LDA   #$3F
LE23F   JSR   LE158
LE242   JSR   LE1FC
LE245   TXA    
        LDX   #$14
LE248   DEX    
        BNE   LE248
        TAX    
        JSR   LE2B8
        JMP   LE2C6
LE252   SEI    
        LDA   #$00
        STA   $AA
        JSR   LE2B8
        TXA    
        PHA    
LE25C   JSR   GetSerialIn
        BPL   LE25C
LE261   LDX   #$20
        JSR   LE2C6
LE266   LDA   IO
        CMP   IO
        BNE   LE266
        ASL    
        BPL   LE28E
        DEX    
        BNE   LE266
        LDA   $AA
        BEQ   LE27D
        PLA    
        TAX    
        LDA   #$02
        JMP   LE1F0
LE27D   JSR   LE2CD
        LDX   #$40
LE282   DEX    
        BNE   LE282
        LDA   #$40
        JSR   LF41E
        INC   $AA
        BNE   LE261
LE28E   LDX   #$08
LE290   LDA   IO
        ASL    
        BPL   LE290
        ROR   $A8
LE297   LDA   IO
        CMP   IO
        BNE   LE297
        ASL    
        BMI   LE297
        DEX    
        BNE   LE290
        STX   $AA
        PLA    
        TAX    
        JSR   LE2CD
        LDA   #$40
        BIT   $90
        BVC   LE2B3
        JSR   LE245
LE2B3   LDA   $A8
        CLI    
        CLC    
        RTS    
LE2B8   LDA   IO
        AND   #$FD
        STA   IO
        RTS    
LE2BF   LDA   IO
        ORA   #$02
        STA   IO
        RTS    
LE2C6   LDA   IO
        AND   #$FE
        STA   IO
        RTS    
LE2CD   LDA   IO
        ORA   #$01
        STA   IO
        RTS   
		
		; *************************************************
		;
		; Wait for serial line to settle, then shift
		; serial bit into carry (bit 7 is serial bit )
		;
		; *************************************************
GetSerialIn:
LE2D4   LDA   IO				; get current IO bits
        CMP   IO				; wait for line to settle
        BNE   LE2D4				
        ASL						; return bit found in carry
        RTS    


		; *************************************************
		;
		; Set timer to $400, and wait till it counts down
		;
		; *************************************************
LE2DC   JSR   LE2F8				; set timer to $400
        LDA   #$10				; wait for bit to be set in $ff09
LE2E1   BIT   IRQ_STATUS
        BEQ   LE2E1
        STA   IRQ_STATUS		; reset (clear) IRQ bit when done. (does NOT generate an interrupt)
        RTS						; and return

	
		; *************************************************
		;
		; Set timer to $4000, and wait till it counts down
		;
		; *************************************************
LE2EA   JSR   LE2FC				; set timer to $4000
        LDA   #$10				; wait till timer 1 sets bit $10
LE2EF   BIT   IRQ_STATUS		; in IRQ (wait till counted down)
        BEQ   LE2EF
        STA   IRQ_STATUS		; reset IRQ flag when done (does NOT generate an interrupt)
        RTS    


		; *************************************************
		;
		; Set timer 2 to $400
		;
		; *************************************************
LE2F8   LDA   #$04				; get HIGH byte of timer
        BNE   LE2FE				; force local branch

		; *************************************************
		;
		; Set timer 2 to $4000
		;
		; *************************************************
LE2FC   LDA   #$40
LE2FE   PHP						; store flags
        PHA						; store HIGH counter
        SEI						; make sure interrupts are OFF
        LDA   #$00				; always set LOW timer to zero
        STA   Timer2Low			; set value - timer is paused
        PLA						; get HIGH counter value back
        STA   Timer2High		; set it - also sets timer going
        LDA   #$10				; select timer 2 bit
        STA   IRQ_STATUS		; clear timer status
        PLP						; restore flags
        RTS						; and back


		; *************************************************
		;
		; Delay 1 millisecond
		; A is trashed
		;
		; *************************************************

Delay1ms:
LE311   TXA						; keep "X" safe
        LDX   #$05				; count from 5 down
LE314   DEX    
        BNE   LE314				; delay
        TAX						; restore X
        RTS    


LE319   SEC    
        BIT   $18
        LDA   $FD10
        AND   #$04
        BEQ   LE362
        PHP    
        JSR   LFBD8
        ORA   $5250
        EOR   $53
        LSE   ($20),y
        BVC   LE37C
        EOR   ($59,x)
        JSR   $2800
        BCC   LE344
        JSR   LFBD8
        ROL   $20
        HLT    
        EOR   $43
        LSE   $4452
        JSR   $2000
        CLD    
        INS   $4E4F,y
        JSR   $4154
        BVC   LE393
        BRK    
LE34F   JSR   LFBCB
        BCS   LE363
        LDA   $FD10
        AND   #$04
        BNE   LE34F
        JSR   LFBD8
        ORA   $4B4F
        BRK    
LE362   CLC    
LE363   RTS    
LE364   SEI
        LDA   TEDREG_06
        AND   #$EF
        STA   TEDREG_06
        LDA   IRQ_MASK
        AND   #$FD
        ORA   #$08
        STA   IRQ_MASK
        RTS
LE378   SEI
        LDA   TEDREG_06
LE37C   ORA   #$10
        STA   TEDREG_06
        LDA   IRQ_MASK
        AND   #$F7
        ORA   #$02
        STA   IRQ_MASK
        CLI    
        RTS    
LE38D   PHP    
        SEC    
        ROR   $07FC
        LDA   IO
        AND   #$F5
        STA   IO
        LDX   #$1E
LE39A   JSR   LE2EA
        DEX    
        BNE   LE39A
        PLP    
        RTS    
        LSE   ($31,x)
        AND   $3438,y
        LSE   ($4F,x)
        EOR   $4F4D
        SKB   $4F
        HLT    
        EOR   $A5
        ORA   ($09,x)
        PHP    
        STA   IO
        RTS    
LE3B7   LDY   #$00
        LDA   #$20
LE3BB   STA   ($B6),y
        INY    
        CPY   #$C0
        BNE   LE3BB
        RTS    
LE3C3   PHA    
        LDA   #$33
        STA   $B6
        LDA   #$03
        STA   $B7
        PLA    
        RTS    
LE3CE   JSR   LFBCB
        BCC   LE3E3
        JSR   LE3B0
        JSR   LE378
        LDX   $07BE
        TXS    
        LDA   #$00
        STA   $07BE
        SEC    
LE3E3   RTS    
LE3E4   LDA   IRQ_STATUS
        AND   IRQ_MASK
        AND   #$08
        BNE   LE3EF
        RTS    
LE3EF   STA   IRQ_STATUS
        SEI    
        LDA   #$90
        STA   Timer1Low
        LDA   #$33
        STA   Timer1High
        LDX   $07BF
        TXS    
        SEC    
        RTS    
LE403   LDA   #$A8
        STA   Timer1Low
        LDA   #$48
        STA   Timer1High
        LDA   #$08
        STA   IRQ_STATUS
        RTS    
LE413   SEC    
        BCS   LE417
LE416   CLC    
LE417   STY   $07CA
        STX   $07CB
        LDY   $07C8
        LDX   $07C9
        LDA   #$10
LE425   BIT   IRQ_STATUS
        BEQ   LE425
        STY   Timer2Low
        STX   Timer2High
        STA   IRQ_STATUS
        LDA   IO
        EOR   #$02
        STA   IO
        PHP    
        JSR   LE3CE
        PLP    
        LDY   $07CA
        LDX   $07CB
        BCS   LE416
        RTS    
LE447   LDA   #$4E
        STA   $07C8
        LDA   #$03
        STA   $07C9
        RTS    
LE452   LDA   #$D0
        STA   $07C8
        LDA   #$00
        STA   $07C9
        RTS    
LE45D   LDA   #$A4
        STA   $07C8
        LDA   #$01
        STA   $07C9
        RTS    
LE468   JSR   LE452
        JSR   LE413
        JSR   LE45D
        JMP   LE413
LE474   JSR   LE45D
        JSR   LE413
        JSR   LE452
        JMP   LE413
LE480   JSR   LE447
        JSR   LE413
        JSR   LE45D
        JMP   LE413
LE48C   STA   $A7
        LDA   #$01
        STA   $07B1
        JSR   LE480
        LDX   #$08
LE498   ROR   $A7
        BCS   LE4A5
        INC   $07B1
        JSR   LE468
        JMP   LE4A8
LE4A5   JSR   LE474
LE4A8   DEX    
        BNE   LE498
        ROR   $07B1
        BCS   LE4B6
        JSR   LE468
        JMP   LE4B9
LE4B6   JSR   LE474
LE4B9   RTS    
LE4BA   TSX    
        STX   $07BE
        LDA   IO
        ORA   #$02
        STA   IO
        JSR   LE452
        LDY   #$01
        STY   Timer2High
        LDA   #$10
        STA   IRQ_STATUS
        BIT   $F7
        BPL   LE4D9
        LDY   #$40
        LDX   #$FE
LE4D9   JSR   LE413
        DEX    
        BNE   LE4D9
        DEY    
        BNE   LE4D9
        LDY   #$09
LE4E4   TYA    
        ORA   $F7
        JSR   LE48C
        DEY    
        BNE   LE4E4
        LDA   $F8
        STA   $F5
        BEQ   LE4F6
        JSR   LE48C
LE4F6   LDY   #$00
        LDA   #$BA
        STA   $07DF
        JSR   $07D9
        PHA    
        EOR   $F5
        STA   $F5
        PLA    
        JSR   LE48C
        INC   $BA
        BNE   LE50F
        INC   $BB
LE50F   INC   $03F3
        BNE   LE4F6
        INC   $03F4
        BNE   LE4F6
        LDA   $F5
        JSR   LE48C
        JSR   LE45D
        JSR   LE413
        JSR   LE452
        LDY   #$01
        LDX   #$C2
LE52B   JSR   LE413
        DEX    
        BNE   LE52B
        DEY    
        BNE   LE52B
        RTS    
LE535   JSR   LE319
        JSR   LE364
        JSR   LE38D
        BCS   LE566
        LDA   #$80
        STA   $F7
LE544   LDA   $B6
        STA   $BA
        LDA   $B7
        STA   $BB
        LDA   #$41
        STA   $03F3
        LDA   #$FF
        STA   $03F4
        JSR   LE4BA
        BCS   LE566
        LDA   $F7
        BPL   LE565
        LDA   #$00
        STA   $F7
        BPL   LE544
LE565   CLC    
LE566   JSR   LE3B0
        JMP   LE378
LE56C   JSR   LE3C3
        JSR   LE3B7
        LDY   #$00
        LDA   $B2
        STA   ($B6),y
        INY    
        LDA   $B3
        STA   ($B6),y
        INY    
        LDA   $9D
        STA   ($B6),y
        INY    
        LDA   $9E
        STA   ($B6),y
        INY    
        STY   $07B3
        LDY   #$00
        STY   $07B2
LE590   LDY   $07B2
        CPY   $AB
        BEQ   LE5AD
        LDA   #$AF
        STA   $07DF
        JSR   $07D9
        LDY   $07B3
        STA   ($B6),y
        INC   $07B2
        INC   $07B3
        JMP   LE590
LE5AD   JMP   LE535
LE5B0   JSR   LE319
        JSR   LE364
        JSR   LE38D
        BCS   LE5EA
        LDA   #$80
        STA   $F7
LE5BF   LDA   $B2
        STA   $BA
        LDA   $B3
        STA   $BB
        CLC    
        LDA   $9D
        SBC   $B2
        EOR   #$FF
        STA   $03F3
        LDA   $9E
        SBC   $B3
        EOR   #$FF
        STA   $03F4
        JSR   LE4BA
        BCS   LE5EA
        LDA   $F7
        BPL   LE5E9
        LDA   #$00
        STA   $F7
        BPL   LE5BF
LE5E9   CLC    
LE5EA   JSR   LE3B0
        JMP   LE378
LE5F0   JSR   LE3B7
        LDA   #$05
        STA   $F8
        JMP   LE535
        RTI    
        BRK    
        SKB   $AE
        CLV    
        ASO   $AC
        LDA   $AD07,y
        ???   
        LDA   $07BA
        PHA    
        LDA   #$10
LE60D   BIT   IO
        BEQ   LE60D
LE611   BIT   IO
        BNE   LE611
        STX   Timer2Low
        STY   Timer2High
        PLA    
        STA   Timer3Low
        PLA    
        STA   Timer3High
        LDA   #$50
        STA   IRQ_STATUS
LE628   LDA   IO
        CMP   IO
        BNE   LE628
        AND   #$10
        BNE   LE603
        JSR   LE3CE
        LDA   #$10
LE637   BIT   IO
        BNE   LE682
        BIT   IRQ_STATUS
        BEQ   LE637
LE640   LDA   IO
        CMP   IO
        BNE   LE640
        AND   #$10
        BNE   LE682
        LDA   #$40
LE64C   BIT   IRQ_STATUS
        BEQ   LE64C
LE651   LDA   IO
        CMP   IO
        BNE   LE651
        AND   #$10
        BNE   LE687
        LDA   $07BC
        STA   Timer2Low
        LDA   $07BD
        STA   Timer2High
        LDA   #$10
        STA   IRQ_STATUS
        LDA   #$10
LE66E   BIT   IRQ_STATUS
        BEQ   LE66E
LE673   LDA   IO
        CMP   IO
        BNE   LE673
        AND   #$10
        BEQ   LE68C
        BIT   $E5FC
        BMI   LE68A
LE682   BIT   $E5FA
        BVS   LE68A
LE687   BIT   $E5FB
LE68A   CLC    
        RTS    
LE68C   SEC    
        RTS    
        RTI    
        BRK    
        SKB   $20
        ORA   $B0E5,x
        AND   $1270,x
        BPL   LE69C
        BMI   LE6C3
LE69C   JSR   LE5FD
        BCS   LE6D3
        BVS   LE6A5
        BVC   LE6D3
LE6A5   BIT   $E68F
        CLC    
        RTS    
        JSR   LE5FD
        BVS   LE6B3
        BPL   LE6BE
        BMI   LE6D3
LE6B3   JSR   LE5FD
        BCS   LE6D3
        BVS   LE6B3
        BPL   LE6D3
        BMI   LE6C3
LE6BE   BIT   $E68E
        CLC    
        RTS    
LE6C3   JSR   LE5FD
        BCS   LE6D3
        BVS   LE6D3
        BPL   LE6CE
        BMI   LE6D3
LE6CE   BIT   $E690
        CLC    
        RTS    
LE6D3   SEC    
        RTS    
LE6D5   TSX    
        STX   $07BF
        CLC    
        ROR   $07CC
        CLI    
LE6DE   JSR   LE691
        BCS   LE6DE
        BVS   LE6DE
        BPL   LE6DE
        JSR   LE403
        CLC    
        RTS    
LE6EC   BIT   $07CC
        BMI   LE742
        JSR   LE6D5
        BCS   LE742
LE6F6   LDA   #$01
        STA   $07B1
        LDX   #$08
        STX   $07B5
        SEC    
        ROR   $07CC
LE704   JSR   LE691
        BCS   LE742
        BVS   LE70F
        BPL   LE71C
        BMI   LE742
LE70F   CLC    
        ROR   $A7
        INC   $07B1
        DEC   $07B5
        BNE   LE704
        BEQ   LE724
LE71C   SEC    
        ROR   $A7
        DEC   $07B5
        BNE   LE704
LE724   JSR   LE691
        BCS   LE742
        BVS   LE72F
        BPL   LE738
        BMI   LE742
LE72F   LDA   $07B1
        AND   #$01
        BNE   LE742
        BEQ   LE73F
LE738   LDA   $07B1
        AND   #$01
        BEQ   LE742
LE73F   CLC    
        BCC   LE743
LE742   SEC    
LE743   SEI    
        PHP    
        CLC    
        ROR   $07CC
        PLP    
        RTS    
LE74B   TSX    
        STX   $07BE
        LDA   $93
        BEQ   LE756
        SEC    
        ROR   $93
		JSR   LE38D

		;
		; Load
		;
LE759   JSR   LE364					; Blank screen
        LDA   $07C0
        STA   $B6
        LDA   $07C1
        STA   $B7
        LDA   $07C2
        STA   $03F5
        LDA   $07C3
        STA   $03F6
        JSR   LE91D
        LDY   #$00
        STY   $07B6
        STY   $07B7
        STY   $F5
        STY   $B1
        STY   $F8
        LDA   #$B6
        STA   $07DF
        BIT   $07B0
        BPL   LE7A0
        JSR   LE6EC
        BCS   LE79D
        LDA   $A7
        STA   $F8
        EOR   $F5
        STA   $F5
        JMP   LE7A0
LE79D   SEC    
        ROR   $F8
LE7A0   JSR   LE6EC
        BCS   LE7BE
        LDY   #$00
        JSR   $07D9
        NOP    
        BIT   $93
        BMI   LE7B1
        LDA   $A7
LE7B1   CMP   $A7
        BNE   LE7BE
        STA   ($B6),y
        EOR   $F5
        STA   $F5
        JMP   LE7DC
LE7BE   LDY   $07B6
        CPY   #$1E
        BCS   LE7D7
        LDA   $B6
        STA   $0437,y
        LDA   $B7
        STA   $0455,y
        INC   $07B6
        INC   $B1
        JMP   LE7DC
LE7D7   LDA   #$FF
        STA   $07B6
LE7DC   INC   $B6
        BNE   LE7E2
        INC   $B7
LE7E2   INC   $03F5
        BNE   LE7A0
        INC   $03F6
        BNE   LE7A0
        LDA   $07B6
        STA   $07B7
        JSR   LE6EC
        LDA   $07B7
        BNE   LE800
        LDA   $A7
        CMP   $F5
        BNE   LE803
LE800   JMP   LE80A
LE803   LDA   $F7
        BMI   LE80A
        JMP   LE8B7
LE80A   LDA   $F7
        BMI   LE819
        LDA   $07B7
        BEQ   LE816
        JMP   LE8B7
LE816   JMP   LE8C7
LE819   LDA   #$00
        STA   $07B6
        STA   $F5
        LDA   $07C0
        STA   $B6
        LDA   $07C1
        STA   $B7
        LDA   $07C2
        STA   $03F5
        LDA   $07C3
        STA   $03F6
        JSR   LE91D
        BIT   $07B0
        BPL   LE853
        JSR   LE6EC
        BIT   $F8
        BPL   LE84D
        LDA   $A7
        STA   $F8
        BCC   LE84D
        ROR   $F8
LE84D   LDA   $F8
        EOR   $F5
        STA   $F5
LE853   JSR   LE6EC
        ROR   $07C4
        LDA   $A7
        EOR   $F5
        STA   $F5
        BIT   $07B7
        BMI   LE896
        LDY   $07B6
        CPY   $07B7
        BEQ   LE896
        LDA   $0437,y
        CMP   $B6
        BNE   LE896
        LDA   $0455,y
        CMP   $B7
        BNE   LE896
        INC   $07B6
        LDA   $07C4
        BMI   LE896
        LDY   #$00
        JSR   $07D9
        NOP    
        BIT   $93
        BMI   LE88E
        LDA   $A7
LE88E   CMP   $A7
        BNE   LE896
        DEC   $B1
        STA   ($B6),y
LE896   INC   $B6
        BNE   LE89C
        INC   $B7
LE89C   INC   $03F5
        BNE   LE853
        INC   $03F6
        BNE   LE853
        JSR   LE6EC
        LDA   #$00
        STA   $90
        LDA   $F8
        LDX   $B1
        BEQ   LE8C7
        BIT   $93
        BMI   LE8BF
LE8B7   LDA   #$60
        STA   $90
        SEC    
        JMP   LE8C8
LE8BF   LDA   #$10
        STA   $90
        SEC    
        JMP   LE8C8
LE8C7   CLC    
LE8C8   JSR   LE3B0
        JSR   LE378
        RTS    
        RLA   ($03),y
        EOR   ($FF,x)
LE8D3   LDY   #$03
LE8D5   LDA   $E8CF,y
        STA   $07C0,y
        DEY    
        BPL   LE8D5
        STY   $07B0
        LDA   $93
        PHA    
        INY    
        STY   $93
        STY   $0539
        JSR   LE74B
        PLA    
        STA   $93
        JMP   LE3C3

        ;
        ; init tape read
        ;
LE8F3   LDA   $B2
        STA   $07C0
        LDA   $B3
        STA   $07C1
        CLC    
        LDA   $9D
        SBC   $B2
        EOR   #$FF
        STA   $07C2
        LDA   $9E
        SBC   $B3
        EOR   #$FF
        STA   $07C3
        CLC    
        ROR   $07B0
        JMP   LE74B
		
LE917	db	  $02,$01,$02,$02,$0d,$02

		LDX   #$05							; Copy in timer values
		LDA   LE917,x
		STA   $07B8,x
        DEX    
        BPL   LE91F

LE928   LDA   #$0A
        STA   $07C5
LE92D   JSR   LE5FD
        BCS   LE928
        BVC   LE928
        DEC   $07C5
        BNE   LE92D
LE939   LDA   #$00
        STA   $BA
        STA   $BB
        LDY   #$10
LE941   LDX   #$00
        LDA   #$10
LE945   BIT   IO
        BEQ   LE945
LE949   BIT   IO
        BNE   LE949
LE94D   INX    
        BEQ   LE939
        BIT   IO
        BEQ   LE94D
LE954   INX    
        BEQ   LE939
        BIT   IO
        BNE   LE954
        TXA    
        CLC    
        ADC   $BA
        STA   $BA
        LDA   #$00
        ADC   $BB
        STA   $BB
        DEY    
        BNE   LE941
        LSR   $BB
        ROR   $BA
        LSR   $BB
        ROR   $BA
        LDA   $BA
        STA   $07B8
        ASL    
        STA   $07BA
        STA   $07BC
        LDA   $BB
        STA   $07B9
        ROL    
        STA   $07BB
        STA   $07BD
LE98A   JSR   LE5FD
        BCS   LE98A
        BVS   LE98A
        BPL   LE98A
        JSR   LE5FD
        BCS   LE98A
        BVS   LE98A
        BMI   LE98A
        CLC    
        ROR   $07CC
        JSR   LE403
        LDA   #$03
        STA   $07C6
        JSR   LE6F6
        BCC   LE9B0
        DEC   $07C6
LE9B0   JSR   LE6EC
        BCC   LE9BD
        DEC   $07C6
        BNE   LE9BD
        JMP   LE91D
LE9BD   LDA   $A7
        AND   #$0F
        CMP   #$01
        BNE   LE9B0
        LDA   $A7
        AND   #$80
        STA   $F7
        RTS    
LE9CC   JSR   LE8D3
        BCS   LEA1E
        LDA   $F8
        CMP   #$05
        BEQ   LEA1A
        CMP   #$01
        BEQ   LE9E3
        CMP   #$03
        BEQ   LE9E3
        CMP   #$04
        BNE   LE9CC
LE9E3   TAX    
        BIT   $9A
        BPL   LEA17
        JSR   LFBD8
        ORA   $4F46
        EOR   $4E,x
        SKB   $20
        BRK    
        LDY   #$04
LE9F5   LDA   ($B6),y
        JSR   LFFD2
        INY    
        CPY   #$15
        BNE   LE9F5
        LDX   #$FF
LEA01   JSR   LE2EA
        JSR   LE2EA
        DEX    
        BEQ   LEA17
        LDA   #$7F
        JSR   LDB70
        CMP   #$7F
        BEQ   LEA1E
        CMP   #$DF
        BNE   LEA01
LEA17   CLC    
        LDA   $F8
LEA1A   RTS    
        NOP    
        NOP    
        NOP    
LEA1E   LDA   #$00
        RTS    
LEA21   JSR   LE9CC
        BCS   LEA53
        CMP   #$05
        BEQ   LEA55
        LDY   #$FF
LEA2C   INY    
        CPY   $AB
        BEQ   LEA57
        LDA   #$AF
        STA   $07DF
        JSR   $07D9
        CMP   $0337,y
        BEQ   LEA2C
        LSR   $F8
        BCC   LEA21
        LDY   #$FF
        STY   $07C3
        DEY    
        STY   $07C2
        LDY   #$01
        JSR   LE8D5
        JMP   LEA21
LEA53   LDA   #$00
LEA55   SEC    
        RTS    
LEA57   CLC    
        LDA   $F8
        RTS    
LEA5B   LDA   $07D4
        AND   #$10
        BEQ   LEA94
        LDA   $FD10
        AND   #$02
        BEQ   LEA94
        LDX   #$00
        BIT   $07D0
        BPL   LEA79
        LDA   $07CF
        STX   $07D0
        JMP   LEA89
LEA79   BIT   $07CE
        BPL   LEA94
        BIT   $07D6
        BMI   LEA94
        LDA   $07CD
        STX   $07CE
LEA89   STA   $FD00
        LDA   $07D4
        AND   #$EF
        STA   $07D4
LEA94   RTS    
LEA95   LDA   $07D4
        AND   #$08
        BEQ   LEAF0
        LDA   $07D4
        AND   #$F7
        STA   $07D4
        LDA   $FD00
        BEQ   LEAC2
        STA   $07D5
        CMP   $FC
        BNE   LEAB7
        LDA   #$00
        STA   $07D6
        BEQ   LEAF0
LEAB7   CMP   $FD
        BNE   LEAC2
        LDA   #$FF
        STA   $07D6
        BNE   LEAF0
LEAC2   LDA   $07D3
        CMP   #$3F
        BEQ   LEAF0
        CMP   #$38
        BNE   LEADC
        LDA   $FD
        BEQ   LEADC
        STA   $07CF
        LDA   #$FF
        STA   $07D0
        STA   $07D7
LEADC   LDX   $07D1
        INX    
        TXA    
        AND   #$3F
        STA   $07D1
        TAX    
        LDA   $07D5
        STA   $03F7,x
        INC   $07D3
LEAF0   RTS    
LEAF1   LDA   $07D3
        BEQ   LEB2A
        PHP    
        SEI    
        LDX   $07D2
        INX    
        TXA    
        AND   #$3F
        STA   $07D2
        PLP    
        TAX    
        LDA   $03F7,x
        PHA    
        DEC   $07D3
        LDA   $07D3
        CMP   #$08
        BNE   LEB2B
        BIT   $07D7
        BPL   LEB2B
        LDA   $FC
        BEQ   LEB2B
        STA   $07CF
        SEC    
        ROR   $07D0
        LSR   $07D7
LEB25   BIT   $07D8
        BPL   LEB35
LEB2A   PHA    
LEB2B   LDA   $07D4
        AND   #$4F
        EOR   #$40
        STA   $90
        PLA    
LEB35   CLC    
        RTS    
LEB37   BIT   $07CE
        BMI   LEB37
        STA   $07CD
        SEC    
        ROR   $07CE
        JMP   LEB2A
LEB46   LDA   #$00
        LDX   #$0B
LEB4A   STA   $07CD,x
        DEX    
        BPL   LEB4A
        STA   $FD01
        STA   $FC
        STA   $FD
        RTS    
        ORA   $2F49
        LSE   $4520
        HLT    
        HLT    
        LSE   $2052
        LAX   ($0D,x)
        LSE   ($45),y
        EOR   ($52,x)
        LSE   ($48,x)
        EOR   #$4E
        LSE   $A0
        LSR   $4F
        HLT    
        LDY   #$0D
        BVC   LEBC8
        EOR   $53
        LSE   ($20),y
        BVC   LEBC8
        EOR   ($59,x)
        JSR   $4E4F
        JSR   $4154
        BVC   LEB4B
        BVC   LEBDA
        EOR   $53
        LSE   ($20),y
        HLT    
        EOR   $43
        LSE   $4452
        JSR   $2026
        BVC   LEBE3
        EOR   ($59,x)
        JSR   $4E4F
        JSR   $4154
        BVC   LEB66
        ORA   $4F4C
        EOR   ($44,x)
        EOR   #$4E
        DCM   $0D
        LSE   ($41),y
        LSR   $49,x
        LSR   $A047
        ORA   $4556
        HLT    
        EOR   #$46
        EOR   $4E49,y
        DCM   $0D
        LSR   $4F
        EOR   $4E,x
        SKB   $A0
        ORA   $4B4F
        STA   $9A24
LEBC8   BPL   LEBD7
LEBCA   LDA   $EB58,y
        PHP    
        AND   #$7F
        JSR   LFFD2
        INY    
        PLP    
        BPL   LEBCA
LEBD7   CLC    
        RTS    
        LDA   $98
        BNE   LEBF7
        LDA   $EF
        ORA   $055D
        BEQ   LEC22
        SEI    
        JMP   LD8C1
        LDA   $98
        BNE   LEBF7
        LDA   $CA
        STA   $C5
        LDA   $CD
        STA   $C4
        JMP   LD965
LEBF7   CMP   #$03
        BNE   LEC1A
        ORA   $C7
        STA   $C7
        LDA   $07E8
        STA   $C3
        JMP   LD965
LEC07   JSR   LFBBA
        CMP   #$01
        BNE   LEC14
        JSR   LEC24
        JMP   LFBC4
LEC14   JSR   LEAF1
        JMP   LFBC4
LEC1A   BCC   LEC07
        LDA   $90
        BEQ   LEC8B
        LDA   #$0D
LEC22   CLC    
        RTS    
LEC24   LDY   $0539
        CPY   #$BF
        BCC   LEC31
        JSR   LE8D3
        BCC   LEC24
        RTS    
LEC31   LDY   $0539
        LDA   ($B6),y
        PHA    
        INY    
        CPY   #$BF
        BCS   LEC45
        LDA   ($B6),y
        BNE   LEC45
        LDA   #$40
        JSR   LF41E
LEC45   INC   $0539
        PLA    
        CLC    
        RTS    
		;
		; Output
		;
LEC4B   PHA    
        LDA   $99
        CMP   #$03
        BNE   LEC56
        PLA    
        JMP   LDC49
LEC56   BCC   LEC5C
        PLA    
        JMP   LECDF
LEC5C   JSR   LFBB7
        CMP   #$01
        BNE   LEC84
        LDY   $0539
        CPY   #$BF
        BCC   LEC75
        JSR   LE535
        BCS   LEC7E
        LDA   #$02
        STA   $F8
        LDY   #$00
LEC75   PLA    
        STA   ($B6),y
        INY    
        STY   $0539
        BCC   LEC88
LEC7E   PLA    
        LDA   #$00
        JMP   LFBC4
LEC84   PLA    
        JSR   LEB37
LEC88   JMP   LFBC1
LEC8B   STX   $BA
        BIT   $F9
        BVS   LEC96
        LDX   $BA
        JMP   LE252
LEC96   LDA   $F9                      ; IEC flag
        AND   #$30                     ; clear LSB   
        TAX                            ; x-reg index for $fec0 or $fef0 ?   
        LDA   #$84                     ; $80: 1551 wake up $4: Job4=Computer receives
        STA   $FEC0,x                  ; PortA 
LECA0   LDA   $FEC2,x                  ; check for ???
        BMI   LECA0
        LDA   #$00                     
        STA   $FEC3,x                  ; PortA = 0: in 
        STA   $FEC2,x                  ; Data Valid = 0 
LECAD   LDA   $FEC2,x                   
        BPL   LECAD                    ; Wait for ???
        LDA   $FEC1,x
        AND   #$03
        CMP   #$03
        BNE   LECBD                    ; check Status-Bits   
        LDA   #$40                       
LECBD   JSR   LF41E                    ; and write new Status
        LDA   $FEC0,x                  ; get Byte  
        PHA                            ; and push to stack  
        LDA   #$40                     ;  Bit 6 Ack ???
        STA   $FEC2,x
LECC9   LDA   $FEC2,x                  ; Wait for ???
        BMI   LECC9
        LDA   #$FF
        STA   $FEC3,x                  ; DDRA to output 
        LDA   #$00
        STA   $FEC0,x                  ; PortA = $00    
        STA   $FEC2,x                  ; ???
        JMP   LEDD4                    ; finish (IEC) 
        NOP    
LECDF   BIT   $F9                      ; write flag IEC-Bus  
        BMI   LECE6
        JMP   LE21D                    ; ciout 
-------------------------------------------------------------
LECE6   PHA                            ;  
        STA   $05E8
        LDA   #$83
LECEC   STX   $BA
        PHA    
        LDA   $F9                      ; flag 
        AND   #$30
        TAX    
        PLA    
        STA   $FEC0,x                  ; write to PortA
LECF8   LDA   $FEC2,x                  ; wait for ???
        BMI   LECF8
        LDA   $05E8            
        STA   $FEC0,x                  ; write to PortA    
        LDA   #$00
        STA   $FEC2,x                  ; Data Valid = 0
LED08   LDA   $FEC2,x                  ; wait for ???
        BPL   LED08
        LDA   $FEC1,x                  ; read status-bits  
        AND   #$03
        JSR   LF41E                    ; 
        JMP   LEDDB

		;
		; Set INPUT device
		;
LED18   JSR   LEEE8
        BEQ   LED20
        JMP   LF279
LED20   JSR   LEEF8
        BEQ   LED36
        CMP   #$03
        BEQ   LED36
        BCS   LED3A
        CMP   #$02
        BNE   LED57
        JSR   LEB25
        BCS   LED39
        LDA   $AE
LED36   STA   $98
        CLC    
LED39   RTS    
LED3A   TAX    
        JSR   LEDFA
        BIT   $90
        BMI   LED54
        LDA   $AD
        BPL   LED4C
        JSR   LEE13
        JMP   LED4F
LED4C   JSR   LEE1A
LED4F   TXA    
        BIT   $90
        BPL   LED36
LED54   JMP   LF27F
LED57   LDX   $AD
        CPX   #$60
        BEQ   LED36
        JMP   LF282

		; *****************************************
		;
		; Set output device
		; 
		; 0 = Plus/4 keyboard
		; 1 = cassette
		; 2 = unused
		; 3 = Plus/4 screen
		; 4 = Printer
		; 8 = (usually) Disk
		; can also have more DISK devices...
		;
		; *****************************************
LED60   JSR   LEEE8					; get a free logical file slot
        BEQ   LED68					; found one? if so jump
        JMP   LF279					; display "?TOO MANY FILES ERROR" (10 files open MAX)

LED68   JSR   LEEF8					; set file values (sets CURRENT logical file number, secondary address and device)
        BNE   LED70					; of current device = keyboard, then display "?NOT OUTPUT FILE ERROR"
LED6D   JMP   LF285

LED70   CMP   #$03					; is output device the Plus/4 screen?
        BEQ   LED81					; if so, set screen
        BCS   LED85					; if 4 or more, then try and set them
        
		CMP   #$02					; else... must be tape, or ??????????? error?
        BNE   LEDA1					; if NOT unused, then MUST be tape... so jump to tape.
        
		JSR   LEB25					; try and set device, else display "?DEVICE NOT PRESENT ERROR"
        BCS   LED84					; if we can't, then exit...
        LDA   CurrDev				; get current output device
LED81   STA   $99					; SET current output device
        CLC							; exit
LED84   RTS    

		;
		; on device >=4 then usually serial device (printed or disk)
		;
LED85   TAX							; set device number
        JSR   LEE2C					; part of "TALK" - see if device is there?
        BIT   $90					; error?
        BMI   LED9E					; if so... 
        LDA   CurrSecAdd
        BPL   LED96
        JSR   LEE45
        BNE   LED99
LED96   JSR   LEE4D
LED99   TXA    
        BIT   $90
        BPL   LED81
LED9E   JMP   LF27F
LEDA1   LDX   $AD
        CPX   #$60
        BEQ   LED6D
        BNE   LED81

		; ***************************************************
		;
		; check for parallel DISK drive device connected.
		; preserve "A"
		;
		; ***************************************************
LEDA9   PHA					
        STX   $BA					; store device number
        LDX   #$30
        LDA   CurrDev
        CMP   #$08					; is current device a disk?
        BEQ   LEDBA
        CMP   #$09					; Disk Drive 2?
        BNE   LEDCF					; if NOT then try others...

        LDX   #$00					; check for parallel disk drive(s)
LEDBA   LDA   #$55					; using the DMA channel in the plus/4
        STA   $FEC0,x
        EOR   $FEC0,x
        BNE   LEDCF
        LDA   $FEC1,x
        AND   #$02
        BNE   LEDCF
        STX   $F9					; set DMA control mask
        CLC							; set parallel device found

		db    $24					; mask "SEC" with "BIT $38"

LEDCF	SEC							; set error, not a parallel device
	    LDX   $BA					; get device number and return.
        PLA    
        RTS    



		; ***************************************************
		;
		;
		;
		; ***************************************************
LEDD4   LDA   $FEC2,x
        BPL   LEDD4
        BMI   LEDE0
LEDDB   LDA   #$00
        STA   $FEC0,x
LEDE0   LDA   #$40
        STA   $FEC2,x
        LDX   $BA
        PLA    
        CLC    
        RTS    
LEDEA   STA   $FEF2
        STA   $FEC5
        STA   $FEC2
        DEX    
        STX   $FEC3
        JMP   LCFEA

LEDFA   JSR   LEDA9
        BCC   LEE02
        JMP   LE153
LEE02   PHA    
        LDA   #$40
        STA   $05E8
        LDA   $F9
        ORA   #$40
        STA   $F9
        LDA   #$81
        JMP   LECEC
LEE13   BIT   $F9
        BVS   LEE4C
        JMP   LE20C
LEE1A   BIT   $F9
        BVS   LEE21
        JMP   LE203
LEE21   PHA    
        NOP    
        NOP    
        STA   $05E8
        LDA   #$82
        JMP   LECEC

		;
		; Check for device attached 
		; A = device to search for
		;
LEE2C   JSR   LEDA9				; Check for parallel disk drives
        BCC   LEE34				; if found then skip serial check
        JMP   LE156				; check serial for device

LEE34   PHA    
        LDA   #$20
        STA   $05E8				; set in DMA work area
        LDA   $F9				; get dma control mask
        ORA   #$80				; or in $80
        STA   $F9				; store back
        LDA   #$81
        JMP   LECEC				;?????????????????????

LEE45   BIT   $F9
        BMI   LEE4C
        JMP   LE1FC
LEE4C   RTS    
LEE4D   BIT   $F9
        BMI   LEE54
        JMP   LE1F7
LEE54   PHA    
        STA   $05E8
        LDA   #$82
        JMP   LECEC
        ROR   $BA
        JSR   LEEED
        BEQ   LEE66
        CLC    
        RTS    
LEE66   JSR   LEEF8
        TXA    
        PHA    
        LDA   $AE
        BEQ   LEECA
        CMP   #$03
        BEQ   LEECA
        BCS   LEEB5
        CMP   #$02
        BNE   LEE81
        PHP    
        SEI    
        JSR   LEB46
        PLP    
        BEQ   LEECA
LEE81   LDA   $AD
        AND   #$0F
        BEQ   LEECA
        LDY   $0539
        CPY   #$BF
        BCC   LEE9C
        JSR   LE535
        BCS   LEEA5
        LDA   #$02
        STA   $F8
        LDY   #$00
        STY   $0539
LEE9C   LDA   #$00
        STA   ($B6),y
        JSR   LE535
        BCC   LEEA9
LEEA5   PLA    
        LDA   #$00
        RTS    
LEEA9   LDA   $AD
        CMP   #$62
        BNE   LEECA
        JSR   LE5F0
        JMP   LEECA
LEEB5   BIT   $BA
        BPL   LEEC7
        LDA   $AE
        CMP   #$08
        BCC   LEEC7
        LDA   $AD
        AND   #$0F
        CMP   #$0F
        BEQ   LEECA
LEEC7   JSR   LF211
LEECA   PLA    
        TAX    
        DEC   $97
        CPX   $97
        BEQ   LEEE6
        LDY   $97
        LDA   $0509,y
        STA   $0509,x
        LDA   $0513,y
        STA   $0513,x
        LDA   $051D,y
        STA   $051D,x
LEEE6   CLC    
        RTS    

		; *****************************************
		;
		; Open logical file
		; Find a free logical file handle and return.
		; X = -1 for error, not found.
		;
		; *****************************************
LEEE8   LDA   #$00					; clear I/O status word (ST)
        STA   $90					; ST
        TXA							; get channel number
LEEED   LDX   $97					; get number of open files ( index into file area )
LEEEF   DEX							; find a free slot...
        BMI   LEF07					; too many files?
        CMP   $0509,x				; check logical file number
        BNE   LEEEF					; find a free file slot
        RTS							; return with logical file number in "X"


LEEF8   LDA   $0509,x
        STA   $AC
        LDA   $051D,x
        STA   $AD
        LDA   $0513,x
        STA   $AE
LEF07   RTS    

        LDA   #$00
        STA   $97
        LDX   #$03
        CPX   $99
        BCS   LEF15
        JSR   LEF23
LEF15   CPX   $98
        BCS   LEF1C
        JSR   LEF3B
LEF1C   STX   $99
        LDA   #$00
        STA   $98
        RTS    
LEF23   BIT   $F9
        BMI   LEF2A
        JMP   LE23D
LEF2A   PHA    
        LDA   #$3F
        STA   $05E8
        LDA   $F9
        AND   #$7F
        STA   $F9
        LDA   #$81
        JMP   LECEC
LEF3B   BIT   $F9
        BVS   LEF42
        JMP   LE22F
LEF42   PHA    
        LDA   #$5F
        STA   $05E8
        LDA   $F9
        AND   #$BF
        STA   $F9
        LDA   #$81
        JMP   LECEC
        LDX   $AC
        JSR   LEEE8
        BNE   LEF5D
        JMP   LF276
LEF5D   LDX   $97
        CPX   #$0A
        BCC   LEF66
        JMP   LF273
LEF66   INC   $97
        LDA   $AC
        STA   $0509,x
        LDA   $AD
        ORA   #$60
        STA   $AD
        STA   $051D,x
        LDA   $AE
        STA   $0513,x
        BEQ   LEF86
        CMP   #$03
        BEQ   LEF86
        BCC   LEF88
        JSR   LF005
LEF86   CLC    
        RTS    
LEF88   CMP   #$02
        BNE   LEFB8
        JSR   LEB46
        TAX    
LEF90   INX    
        BEQ   LEF9E
        STX   $FD03
        CPX   $FD03
        BEQ   LEF90
        JMP   LF27F
LEF9E   SEC    
        ROR   $07D8
        LDA   #$AF
        STA   $07DF
        LDY   #$00
        JSR   $07D9
        STA   $FD03
        INY    
        JSR   $07D9
        STA   $FD02
        CLC    
        RTS    
LEFB8   LDA   $AD
        AND   #$0F
        BNE   LEFEA
        JSR   LE31B
        BCS   LEFE9
        JSR   LF160
        LDA   $AB
        BEQ   LEFD4
        JSR   LEA21
        BCC   LEFDF
        BEQ   LEFE9
LEFD1   JMP   LF27C
LEFD4   JSR   LE9CC
        BEQ   LEFE9
        BCS   LEFD1
        CMP   #$05
        BEQ   LEFD1
LEFDF   LDY   #$BF
        STY   $0539
        LDA   #$02
        STA   $F8
LEFE8   CLC    
LEFE9   RTS    
LEFEA   JSR   LE319
        BCS   LEFE9
        LDA   #$04
        STA   $F8
        JSR   LE56C
        BCS   LF004
        LDA   #$02
        STA   $F8
        LDY   #$00
        STY   $0539
        STY   $0537
LF004   RTS    
LF005   LDA   $AD
        BMI   LEFE8
        LDY   $AB
        BEQ   LEFE8
        LDA   #$00
        STA   $90
        LDA   $AE
        JSR   LEE2C
        BIT   $90
        BMI   LF025
        LDA   $AD
        ORA   #$F0
        JSR   LEE4D
        LDA   $90
        BPL   LF02A
LF025   PLA    
        PLA    
        JMP   LF27F
LF02A   LDA   $AB
        BEQ   LF040
        LDY   #$00
LF030   LDA   #$AF
        STA   $07DF
        JSR   $07D9
        JSR   LECDF
        INY    
        CPY   $AB
        BNE   LF030
LF040   JMP   LF223

;
; $F043 - Load program
;

LF043   STX   $B4                     ; Store load RAM base
        STY   $B5                     ; (lo,hi)
        JMP   ($032E)                 ; call user/kernal load routine

LF04A   STA   $93                     ; Kernal LOAD routine
        LDA   #$00                    ; store IO status word
        STA   $90
        LDA   $AE                     ; Check current device
        BNE   LF057                   ; if we HAVE one.. carry on
LF054   JMP   LF28B                   ; else print "I/O ERROR #9"

LF057   CMP   #$03                    ; Check for device "3"
        BEQ   LF054                   ; if so exit with error
        BCS   LF064                   ; if >3 carry on.
              
        CMP   #$02 					  ; Check for device "2"
        BEQ   LF054                   ; if so else exit with error
        JMP   LF0F0                   ; MUST be load from TAPE


;
; Load from serial
;

LF064   LDY   $AB
        BNE   LF06B
        JMP   LF288
LF06B   LDX   $AD
        JSR   LF160
        LDA   #$60
        STA   $AD
        JSR   LF005
        LDA   $AE
        JSR   LEDFA
        LDA   $AD
        JSR   LEE1A
        JSR   LEC8B
        STA   $9D
        LDA   $90
        LSR    
        LSR    
        BCS   LF0E8
        JSR   LEC8B
        STA   $9E
        TXA    
        BNE   LF09C
        LDA   $B4
        STA   $9D
        LDA   $B5
        STA   $9E
LF09C   JSR   LF189
LF09F   LDA   #$FD
        AND   $90
        STA   $90
        JSR   LFFE1
        BNE   LF0AD
        JMP   LF1FF
LF0AD   JSR   LEC8B
        TAX    
        LDA   $90
        LSR    
        LSR    
        BCS   LF09F
        TXA    
        LDY   $93
        BEQ   LF0D4
        LDY   #$00
        STA   $07C7
        LDA   #$9D
        STA   $07DF
        JSR   $07D9
        CMP   $07C7
        BEQ   LF0D6
        LDA   #$10
        JSR   LF41E
        BIT   $9D91
LF0D6   INC   $9D
        BNE   LF0DC
        INC   $9E
LF0DC   BIT   $90
        BVC   LF09F
        JSR   LEF3B
        JSR   LF211
        BCC   LF0EB
LF0E8   JMP   LF27C                   ; print "I/O ERROR #4"
LF0EB   LDX   $9D                     ; get END address of file, and return it
        LDY   $9E                     ; to the calling routine.
LF0EF   RTS    

;
; $F0F0 - Load from TAPE
;

LF0F0   JSR   LE31B                   ; print "PRESS PLAY ON TAPE"
        BCS   LF0EF                   ; if BREAK pressed.. exit
        JSR   LF160                   ; print "SEARCHING"
LF0F8   LDA   $AB                     ; get file name length
        BEQ   LF105                   ; if ZERO.. skip loading a "filename"
        JSR   LEA21                   ; Call "find a specific header"
        BCC   LF10C                   ; found it? yes.. carry on.
        BEQ   LF0EF                   ; break pressed?
        BCS   LF0E8                   ; another error? exit with error.

LF105   JSR   LE9CC                   ; Call "find ANY header"
        BEQ   LF0EF                   ; break pressed? exit.
        BCS   LF0E8                   ; another error? exit with error.

LF10C   LDA   $F8                     ; check to see if we FOUND the header 
        CMP   #$01                    ; if yes (A=1)
        BEQ   LF124                   ; jump down and LOAD it
        CMP   #$03                    ; if not the one we were looking for,
        BNE   LF0F8                   ; loop back and try again.

LF116   LDY   #$00                    ; Get load address from header
        LDA   ($B6),y                 ; first 2 bytes are SAVED start address
        STA   $B4                     ; next 2 are the END address,
        INY                           ; then we have the name
        LDA   ($B6),y                 ; This copies the LOAD address into the
        STA   $B5                     ; cassed buffer base address.
        JMP   LF128
LF124   LDA   $AD                     ; Is there a SECONDARY address?
        BNE   LF116                   ; if not, go back and get the base address

LF128   SEC                           ; This section simply subtracts the start
        LDY   #$02                    ; and end address to get the file length
        LDA   ($B6),y                 ; It then adds on the BASE of the file
        LDY   #$00                    ; cassette buffer (since the secondary
        SBC   ($B6),y                 ; address can move it), and stores it
        TAX                           ; in $9d-$9e
        LDY   #$03
        LDA   ($B6),y
        LDY   #$01
        SBC   ($B6),y
        TAY
        CLC
        TXA
        ADC   $B4
        STA   $9D
        TYA
        ADC   $B5                     ; $9d-$9e now hold the END address of 
        STA   $9E                     ; the file to be loaded.

        LDA   $B4                     ; copy the START address into a work
        STA   $B2                     ; copy ($b2-$b3)
        LDA   $B5
        STA   $B3
        JSR   LF189                   ; print "LOADING"
        JSR   LE8F3                   ; init tape read
        BCC   LF0EB                   ; sucessfull? if so.. return/

        LDA   #$1D                    ; check LOAD/VERIFY flag
        BIT   $93         
        BPL   LF0EF                   ; do we WANT to verify? if so return okay
        LDA   #$1C                    ; if it wasn't sucessful, return error.
        BNE   LF0EF

;
; $F160 - print "searching"
;

LF160   LDA   $9A                     ; check current mode
        BPL   LF188                   ; if in DIRECT mode ($80) return.
        LDY   #$0C                    ; print "searching"
        JSR   LEBCA
        LDA   $AB                     ; check for filename
        BEQ   LF188                   ; if we don't have one return.
        LDY   #$17                    ; else print " for"
        JSR   LEBCA

;
; $F172 Print filename
;
LF172   LDY   $AB                     ; do we HAVE a filename?
        BEQ   LF188                   ; if not... exit
        LDY   #$00                    ; else print filename
LF178   LDA   #$AF
        STA   $07DF
        JSR   $07D9
        JSR   LFFD2
        INY    
        CPY   $AB
        BNE   LF178
LF188   RTS    

;
; $F189 - Print "LOADING" or "VERIFYING"
;
LF189   LDY   #$49                    ; get message to print (loading)
        LDA   $93                     ; get loading/verifying flay 
        BEQ   LF191                   ; if loading (A=0) print that message
        LDY   #$59                    ; else print "VERIFYING" message
LF191   JMP   LEBC6

;
; $F194 - SAVE program
;
LF194   STX   $9D
        STY   $9E
        TAX    
        LDA   DIRECTION,x
        STA   $B2
        LDA   IO,x
        STA   $B3
        JMP   ($0330)                 ; call user/kernal SAVE routine

;
; $F1A4 - Kernal SAVE routine
;
LF1A4   LDA   $AE                     
        BNE   LF1AB
LF1A8   JMP   LF28B
LF1AB   CMP   #$03
        BEQ   LF1A8
        CMP   #$02
        BEQ   LF1A8
        BCC   LF234
        LDA   #$61
        STA   $AD
        LDY   $AB
        BNE   LF1C0
        JMP   LF288
LF1C0   JSR   LF005
        JSR   LF228
        LDA   $AE
        JSR   LEE2C
        LDA   $AD
        JSR   LEE4D
        LDY   #$00
        LDA   $B3
        STA   $9C
        LDA   $B2
        STA   $9B
        LDA   $9B
        JSR   LECDF
        LDA   $9C
        JSR   LECDF
LF1E4   SEC    
        LDA   $9B
        SBC   $9D
        LDA   $9C
        SBC   $9E
        BCS   LF20E
        LDA   #$9B
        STA   $07DF
        JSR   $07D9
        JSR   LECDF
        JSR   LFFE1
        BNE   LF206
LF1FF   JSR   LF211
        LDA   #$00
        SEC    
        RTS    
LF206   INC   $9B
        BNE   LF1E4
        INC   $9C
        BNE   LF1E4
LF20E   JSR   LEF23
LF211   BIT   $AD
        BMI   LF226
        LDA   $AE
        JSR   LEE2C
        LDA   $AD
        AND   #$EF
        ORA   #$E0
        JSR   LEE4D
LF223   JSR   LEF23
LF226   CLC    
        RTS    
LF228   LDA   $9A
        BPL   LF264
        LDY   #$51
        JSR   LEBCA
        JMP   LF172
LF234   JSR   LE319
        BCS   LF262
        JSR   LF228
        LDX   #$03
        LDA   $AD
        AND   #$01
        BNE   LF246
        LDX   #$01
LF246   STX   $F8
        JSR   LE56C
        BCS   LF262
        LDA   #$00
        STA   $F8
        JSR   LE5B0
        BCS   LF262
        LDA   $AD
        AND   #$02
        BEQ   LF261
        JSR   LE5F0
        BCS   LF262
LF261   CLC    
LF262   LDA   #$00
LF264   RTS    
        LDA   $91
        CMP   #$7F
        BNE   LF272
        PHP    
        JSR   LFFCC
        STA   $EF
        PLP    
LF272   RTS    
LF273   LDA   #$01
        BIT   $02A9
        BIT   $03A9
        BIT   $04A9
        BIT   $05A9
        BIT   $06A9
        BIT   $07A9
        BIT   $08A9
        BIT   $09A9
        PHA    
        JSR   LFFCC
        LDY   #$00
        BIT   $9A
        BVC   LF2A1
        JSR   LEBCA
        PLA    
        PHA    
        ORA   #$30
        JSR   LFFD2
LF2A1   PLA    
        SEC    
        RTS    
LF2A4   LDX   #$FF
        SEI    
        TXS    
        CLD    
        JSR   LCFA6
        JSR   LF30B
        JSR   LCF11
        PHP    
        BMI   LF2BC
        LDA   #$A5
        CMP   $0508
        BEQ   LF2BF
LF2BC   JSR   LF352
LF2BF   JSR   LF2CE
        JSR   LD84E
        PLP    
        BMI   LF2CB
        JMP   LF445
LF2CB   JMP   L8000
LF2CE   LDX   #$EB
        LDY   #$F2
        CLC    
        STX   $B8
        STY   $B9
        LDY   #$1F
LF2D9   LDA   $0312,y
        BCS   LF2E0
        LDA   ($B8),y
LF2E0   STA   $0312,y
        BCC   LF2E7
        STA   ($B8),y
LF2E7   DEY    
        BPL   LF2D9
        RTS    
        HLT    
        DEC   $CE0E
        JMP   $53F4
        INS   $EE5D
        CLC    
        SBC   $ED60
        SKW   $E8EF
        SBC   #$4B
        CPX   $F265
        CMP   $08EB,y
        INS   $F44C
        LSR    
        BEQ   LF2AE
        SBC   ($A9),y
        ASO   $0085
        LDA   #$08
        STA   IO
        LDX   #$FF
        STX   $FD10
        STX   $FEF3
        INX    
        STX   $FEF4
        STX   $FEF0
        LDA   #$40
        STA   $FEF5
        JSR   LEDEA
LF32A   LDA   $F338,x
        STA   Timer1Low,x
        INX    
        CPX   #$1A
        BNE   LF32A
        JMP   LEB46
        SBC   ($39),y
        BRK    
        BRK    
        BRK    
        BRK    
        ASO   $0008,y
        BRK    
        HLT    
        CPY   DIRECTION
        BRK    
        BRK    
        BRK    
        BRK    
        SKB   $D0
        PHP    
        ADC   ($5B),y
        ADC   $77,x
        ROR   $00A9
        TAY    
LF355   STA   $0002,y
        STA   $0200,y
        STA   $0300,y
        STA   $0400,y
        STA   $0700,y
        INY    
        BNE   LF355
        LDX   #$08
        STX   $9F
LF36B   LDA   $FFF5,x
        STA   $FFF5,x
        CMP   $3FF5,x
        BNE   LF377
        INY    
LF377   CMP   $7FF5,x
        BNE   LF37E
        DEC   $9F
LF37E   DEX    
        BNE   LF36B
        CPY   #$08
        BEQ   LF38C
        LDA   $9F
        BNE   LF391
        LDY   #$7F
        BIT   $3FA0
        LDX   #$F6
        BIT   $FDA0
        CLC    
        JSR   LF42F
        LDA   #$10
        STA   $0532
        LDX   #$3A
LF39E   LDA   $F3D1,x
        STA   $055E,x
        DEX    
        BNE   LF39E
        STX   $055D
        LDX   #$0B
LF3AC   LDA   $CFB3,x
        STA   $07D9,x
        DEX    
        BPL   LF3AC
        LDX   #$0F
LF3B7   LDA   $E143,x
        STA   $0113,x
        DEX    
        BPL   LF3B7
        LDA   #$A5
        STA   $0508
        LDA   #$04
        STA   $07FA
        LDA   #$18
        STA   $07FB
        RTS    
        NOP    
        NOP    
        ASO   $06
        ASL    
        ASO   $06
        SKB   $05
        ORA   $47
        HLT    
        EOR   ($50,x)
        PHA    
        EOR   #$43
        SKB   $4C
        LSE   $4441
        HLT    
        SKB   $49
        HLT    
        EOR   $43
        SKB   $4F
        HLT    
        EOR   $530D,y
        LSE   ($4E,x)
        LSE   ($4C,x)
        HLT    
        ORA   $5344
        EOR   ($56,x)
        EOR   $22
        HLT    
        EOR   $4E,x
        ORA   $494C
        LSE   ($54),y
        ORA   $4548
        JMP   $0D50
LF40C   STA   $AB
        STX   $AF
        STY   $B0
        RTS    
LF413   STA   $AC
        STX   $AE
        STY   $AD
        RTS    
LF41A   STA   $9A
LF41C   LDA   $90
LF41E   ORA   $90
        STA   $90
        RTS    
LF423   STA   $0535
        RTS    
LF427   BCC   LF42F
        LDX   $0533
        LDY   $0534
LF42F   STX   $0533
        STY   $0534
        RTS    
LF436   BCC   LF43E
        LDX   $0531
        LDY   $0532
LF43E   STX   $0531
        STY   $0532
        RTS    
LF445   LDX   #$00
        STX   $0554
        BEQ   LF458
        CLD    
        LDX   #$05
LF44F   PLA    
        STA   $0552,x
        DEX    
        BPL   LF44F
        LDX   #$09
LF458   STX   $07F4
        LDA   #$C0
        STA   $9A
        TSX    
        STX   $0558
        LDX   $07F4
        JSR   LCF66
        LDA   TEDREG_06
        ORA   #$10
        STA   TEDREG_06
        LDA   #$00
        STA   $A1
        STA   $A2
        CLI    
        LDX   #$0F
        JSR   LCF66
        LDA   $0552
        JSR   LFB10
        LDY   #$00
LF485   LDA   $0553,y
        JSR   LFB05
        INY    
        CPY   #$06
        BCC   LF485
        BCS   LF495
LF492   JSR   LFB0B
LF495   JSR   LFB3A
        LDX   #$00
        STX   $F3
LF49C   JSR   LFFCF
        STA   $0200,x
        INX    
        CMP   #$0D
        BNE   LF49C
        DEX    
        STX   $F4
LF4AA   JSR   LFB3F
        BEQ   LF495
        CMP   #$20
        BEQ   LF4AA
        LDX   #$0F
LF4B5   CMP   $F570,x
        BEQ   LF4BF
        DEX    
        BPL   LF4B5
        BMI   LF492
LF4BF   CPX   #$0D
        BCS   LF4D1
        TXA    
        ASL    
        TAX    
        LDA   $F581,x
        PHA    
        LDA   $F580,x
        PHA    
        JMP   LFAAD
LF4D1   STA   $055B
        JMP   LF66E
        BCS   LF4E1
        JSR   LFB5B
        JSR   LFAAD
        BCC   LF4E7
LF4E1   LDA   #$0B
        STA   $F1
        BNE   LF4F5
LF4E7   JSR   LFB64
        LSR    
        ROR   $F1
        LSR    
        ROR   $F1
        LSR    
        ROR   $F1
        STA   $F2
LF4F5   JSR   LFFE1
        BEQ   LF507
        JSR   LF59A
        LDA   #$08
        JSR   LFB96
        JSR   LFB72
        BCS   LF4F5
LF507   JMP   LF495
        BCS   LF507
        LDA   $F1
        LDY   $F2
        STA   $0553
        STY   $0552
        LDY   #$00
LF518   JSR   LFAAD
        BCS   LF507
        LDA   $F1
        STA   $0554,y
        INY    
        CPY   #$05
        BCC   LF518
        BCS   LF507
        BCS   LF53E
        JSR   LFB5B
        LDY   #$00
LF530   JSR   LFAAD
        BCS   LF53E
        LDA   $F1
        STA   ($A1),y
        INY    
        CPY   #$08
        BCC   LF530
LF53E   JSR   LFBD8
        ASO   $914F,y
        BRK    
        JSR   LF59A
        JMP   LF495
        BCS   LF557
        LDA   $F1
        STA   $0553
        LDA   $F2
        STA   $0552
LF557   LDX   $0558
        TXS    
        LDX   #$00
LF55D   LDA   $0552,x
        PHA    
        INX    
        CPX   #$03
        BNE   LF55D
        LDX   $0556
        LDY   $0557
        LDA   $0555
        RTI    
        CLI    
        EOR   $4752
        SKB   $43
        SKB   $41
        ROL   $4648
        ROL   $4C3B,x
        LSE   ($56),y
        HLT    
        SKB   $D6
        SKB   $77
        SKB   $4A
        SBC   $D0,x
        SBC   $CD,x
        SBC   $23,x
        INS   $1E,x
        SBC   $F91E,y
        ORA   $09F6
        INS   $28,x
        SBC   $09,x
        SBC   $20,x
        NOP    
        INS   $3EA9,y
        JSR   LFFD2
        JSR   LFAFB
        LDY   #$00
LF5A7   JSR   LCF96
        JSR   LFB05
        INY    
        CPY   #$08
        BCC   LF5A7
        JSR   LFBD8
        NOP    
        HLT    
        BRK    
        LDY   #$00
LF5BA   JSR   LCF96
        AND   #$7F
        CMP   #$20
        BCS   LF5C5
        LDA   #$2E
LF5C5   JSR   LFFD2
        INY    
        CPY   #$08
        BCC   LF5BA
        RTS    
        LDA   #$00
        BIT   $80A9
        STA   $BB
        JSR   LFBA0
        BCS   LF60A
        JSR   LFAAD
        BCS   LF60A
        JSR   LFB3A
        LDY   #$00
LF5E4   JSR   LCF96
        BIT   $BB
        BPL   LF5ED
        STA   ($F1),y
LF5ED   CMP   ($F1),y
        BEQ   LF5F9
        JSR   LFFE1
        BEQ   LF607
        JSR   LFAFB
LF5F9   INC   $F1
        BNE   LF5FF
        INC   $F2
LF5FF   JSR   LFB94
        JSR   LFB86
        BCS   LF5E4
LF607   JMP   LF495
LF60A   JMP   LF492
        NOP    
        JSR   LFBA0
        BCS   LF60A
        LDY   #$00
        JSR   LFB3F
        CMP   #$27
        BNE   LF62E
        JSR   LFB3F
LF61F   STA   $025D,y
        INY    
        JSR   LFB3F
        BEQ   LF643
        CPY   #$20
        BNE   LF61F
        BEQ   LF643
LF62E   STY   $055C
        JSR   LFAAB
LF634   LDA   $F1
        STA   $025D,y
        INY    
        JSR   LFAAD
        BCS   LF643
        CPY   #$20
        BNE   LF634
LF643   STY   $055B
        JSR   LFB3A
LF649   LDX   #$00
        LDY   #$00
LF64D   JSR   LCF96
        CMP   $025D,x
        BNE   LF664
        INY    
        INX    
        CPX   $055B
        BNE   LF64D
        JSR   LFFE1
        BEQ   LF607
        JSR   LFAFB
LF664   JSR   LFB94
        JSR   LFB86
        BCS   LF649
        BCC   LF607
LF66E   LDY   #$01
        STY   $AE
        STY   $AD
        DEY    
        STY   $AB
        STY   $90
        STY   $93
        LDA   #$02
        STA   $B0
        LDA   #$5D
        STA   $AF
LF683   JSR   LFB3F
        BEQ   LF6E6
        CMP   #$20
        BEQ   LF683
        CMP   #$22
        BNE   LF6A7
        LDX   $F3
LF692   CPX   $F4
        BCS   LF6E6
        LDA   $0200,x
        INX    
        CMP   #$22
        BEQ   LF6AB
        STA   ($AF),y
        INC   $AB
        INY    
        CPY   #$11
        BCC   LF692
LF6A7   JMP   LF492
        NOP    
LF6AB   STX   $F3
        JSR   LFB3F
        JSR   LFAAD
        BCS   LF6E6
        LDA   $F1
        BEQ   LF6A7
        CMP   #$03
        BEQ   LF6A7
        STA   $AE
        JSR   LFAAD
        BCS   LF6E6
        JSR   LFB5B
        JSR   LFAAD
        BCS   LF6A7
        JSR   LFB3A
        LDX   $F1
        LDY   $F2
        LDA   $055B
        CMP   #$53
        BNE   LF6A7
        LDA   #$00
        STA   $AD
        LDA   #$A1
        JSR   LFFD8
LF6E3   JMP   LF495
LF6E6   LDA   $055B
        CMP   #$56
        BEQ   LF6F3
        CMP   #$4C
        BNE   LF6A7
        LDA   #$00
LF6F3   JSR   LFFD5
        LDA   $90
        AND   #$10
        BEQ   LF6E3
        LDA   $055B
        CMP   #$4C
        BEQ   LF6A7
        LDX   #$2A
        JSR   LCF66
        BMI   LF6E3
        JSR   LFBA0
        BCS   LF6A7
        JSR   LFAAD
        BCS   LF6A7
        LDY   #$00
LF716   LDA   $F1
        STA   ($A1),y
        JSR   LFB94
        JSR   LFB86
        BCS   LF716
        BCC   LF6E3
        BCS   LF72E
        JSR   LFB5B
        JSR   LFAAD
        BCC   LF734
LF72E   LDA   #$14
        STA   $F1
        BNE   LF737
LF734   JSR   LFB64
LF737   JSR   LFB3A
        JSR   LFFE1
        BEQ   LF6E3
        JSR   LF752
        INC   $F6
        LDA   $F6
        JSR   LFB96
        LDA   $F6
        JSR   LFB74
        BCS   LF737
        BCC   LF6E3
LF752   LDA   #$2E
        JSR   LFFD2
        JSR   LFB08
LF75A   JSR   LFAFB
        JSR   LFB08
        LDY   #$00
        JSR   LCF96
        JSR   LF7D4
        PHA    
        LDX   $F6
        INX    
LF76C   DEX    
        BPL   LF77A
        JSR   LFBD8
        JSR   $2020
        BRK    
        JMP   LF780
        NOP    
LF77A   JSR   LCF96
        JSR   LFB05
LF780   INY    
        CPY   #$03
        BCC   LF76C
        PLA    
        LDX   #$03
        JSR   LF81B
        LDX   #$06
LF78D   CPX   #$03
        BNE   LF7A5
        LDY   $F6
        BEQ   LF7A5
LF795   LDA   $054B
        CMP   #$E8
        JSR   LCF96
        BCS   LF7BC
        JSR   LFB10
        DEY    
        BNE   LF795
LF7A5   ASL   $054B
        BCC   LF7B8
        LDA   $F88E,x
        JSR   LFFD2
        LDA   $F894,x
        BEQ   LF7B8
        JSR   LFFD2
LF7B8   DEX    
        BNE   LF78D
        RTS    
LF7BC   JSR   LF7C8
        CLC    
        ADC   #$01
        BNE   LF7C5
        INX    
LF7C5   JMP   LFAFF
LF7C8   LDX   $A2
        TAY    
        BPL   LF7CE
        DEX    
LF7CE   ADC   $A1
        BCC   LF7D3
        INX    
LF7D3   RTS    
LF7D4   TAY    
        LSR    
        BCC   LF7E3
        LSR    
        BCS   LF7F2
        CMP   #$22
        BEQ   LF7F2
        AND   #$07
        ORA   #$80
LF7E3   LSR    
        TAX    
        LDA   $F83D,x
        BCS   LF7EE
        LSR    
        LSR    
        LSR    
        LSR    
LF7EE   AND   #$0F
        BNE   LF7F6
LF7F2   LDY   #$80
        LDA   #$00
LF7F6   TAX    
LF7F7   LDA   $F881,x
        STA   $054B
        AND   #$03
        STA   $F6
        TYA    
        AND   #$8F
        TAX    
        TYA    
        LDY   #$03
        CPX   #$8A
        BEQ   LF817
LF80C   LSR    
        BCC   LF817
        LSR    
LF810   LSR    
        ORA   #$20
        DEY    
        BNE   LF810
        INY    
LF817   DEY    
        BNE   LF80C
        RTS    
LF81B   TAY    
        LDA   $F89B,y
        STA   $9F
        LDA   $F8DB,y
        STA   $A0
LF826   LDA   #$00
        LDY   #$05
LF82A   ASL   $A0
        ROL   $9F
        ROL    
        DEY    
        BNE   LF82A
        ADC   #$3F
        JSR   LFFD2
        DEX    
        BNE   LF826
        JMP   LFB08
        RTI    
        HLT    
        EOR   $03
        BNE   LF84B
        RTI    
        ORA   #$30
        HLT    
        EOR   $33
        BNE   LF853
LF84B   RTI    
        ORA   #$40
        HLT    
        EOR   $33
        BNE   LF85B
LF853   RTI    
        ORA   #$40
        HLT    
        EOR   $B3
        BNE   LF863
LF85B   RTI    
        ORA   #$00
        HLT    
        SKB   $33
        BNE   LF7EF
LF863   SKB   DIRECTION
        ORA   ($22),y
        SKB   $33
        BNE   LF7F7
        SKB   $9A
        BPL   LF891
        SKB   $33
        BNE   LF87B
        RTI    
        ORA   #$10
        HLT    
        SKB   $33
        BNE   LF883
LF87B   RTI    
        ORA   #$62
        ASO   ($78),y
        LDA   #$00
        AND   ($81,x)
        SKB   DIRECTION
        BRK    
        EOR   $914D,y
        HLT    
        STX   $4A
        STA   $9D
        BIT   $2C29
        RLA   ($28,x)
        BIT   $59
        BRK    
        CLI    
        BIT   $24
        BRK    
        SKW   $1C8A
        RLA   ($5D,x)
        XAA   #$1B
        LDA   ($9D,x)
        TXA    
        ORA   $9D23,x
        XAA   #$1D
        LDA   (DIRECTION,x)
        AND   #$19
        LDX   $A869
        ORA   $2423,y
        LSE   ($1B),y
        RLA   ($24,x)
        LSE   ($19),y
        LDA   (DIRECTION,x)
        NOP    
        LSE   $A55B,y
        ADC   #$24
        BIT   $AE
        LDX   $ADA8
        AND   #$00
        SKW   $1500
        SAY   $9C6D,x
        LDA   $69
        AND   #$53
        STY   $13
        SKB   $11
        LDA   $69
        RLA   ($A0,x)
        CLD    
        HLT    
        NOP    
        PHA    
        ROL   $62
        STY   $88,x
        SKB   $44
        INY    
        SKB   $68
        SKB   $E8
        STY   DIRECTION,x
        LDY   $08,x
        STY   $74
        LDY   $28,x
        ROR   $F474
        CPY   $724A
        HLT    
        LDY   $8A
        BRK    
        TAX    
        LDX   #$A2
        SKB   $74
        SKB   $72
        SKB   $68
        HLT    
        HLT    
        HLT    
        BRK    
        HLT    
        BRK    
        NOP    
        NOP    
        ROL   $26
        HLT    
        HLT    
        DEY    
        INY    
        CPY   $CA
        ROL   $48
        SKB   $44
        LDX   #$C8
        ORA   $2020
        JSR   $0390
        JMP   LF492
        JSR   LFB5B
LF927   LDX   #$00
        STX   $78
LF92B   JSR   LFB3F
        BNE   LF937
        CPX   #$00
        BNE   LF937
        JMP   LF495
LF937   CMP   #$20
        BEQ   LF927
        STA   $054C,x
        INX    
        CPX   #$03
        BNE   LF92B
LF943   DEX    
        BMI   LF958
        LDA   $054C,x
        SEC    
        SBC   #$3F
        LDY   #$05
LF94E   LSR    
        ROR   $78
        ROR   $77
        DEY    
        BNE   LF94E
        BEQ   LF943
LF958   LDX   #$02
LF95A   JSR   LFB3F
        BEQ   LF97D
        CMP   #$20
        BEQ   LF95A
        JSR   LFA7D
        BCS   LF976
        JSR   LFA8B
        LDY   $F1
        STY   $F2
        STA   $F1
        LDA   #$30
        STA   $77,x
        INX    
LF976   STA   $77,x
        INX    
        CPX   #$0A
        BCC   LF95A
LF97D   STX   $9F
        LDX   #$00
        STX   $054F
LF984   LDX   #$00
        STX   $0550
        LDA   $054F
        JSR   LF7D4
        LDX   $054B
        STX   $A0
        TAX    
        LDA   $F8DB,x
        JSR   LFA5E
        LDA   $F89B,x
        JSR   LFA5E
        LDX   #$06
LF9A3   CPX   #$03
        BNE   LF9BA
        LDY   $F6
        BEQ   LF9BA
LF9AB   LDA   $054B
        CMP   #$E8
        LDA   #$30
        BCS   LF9D2
        JSR   LFA5B
        DEY    
        BNE   LF9AB
LF9BA   ASL   $054B
        BCC   LF9CD
        LDA   $F88E,x
        JSR   LFA5E
        LDA   $F894,x
        BEQ   LF9CD
        JSR   LFA5E
LF9CD   DEX    
        BNE   LF9A3
        BEQ   LF9D8
LF9D2   JSR   LFA5B
        JSR   LFA5B
LF9D8   LDA   $9F
        CMP   $0550
        BEQ   LF9E2
        JMP   LFA6A
LF9E2   LDY   $F6
        BEQ   LFA1A
        LDA   $A0
        CMP   #$9D
        BNE   LFA12
        LDA   $F1
        SBC   $A1
        STA   $0551
        LDA   $F2
        SBC   $A2
        BCC   LFA02
        BNE   LFA72
        LDX   $0551
        BMI   LFA72
        BPL   LFA0B
LFA02   TAY    
        INY    
        BNE   LFA72
        LDX   $0551
        BPL   LFA72
LFA0B   DEX    
        DEX    
        TXA    
        LDY   $F6
        BNE   LFA15
LFA12   LDA   $00F0,y
LFA15   STA   ($A1),y
        DEY    
        BNE   LFA12
LFA1A   LDA   $054F
        STA   ($A1),y
        JSR   LFB35
        LDX   #$28
        JSR   LCF66
        JSR   LF75A
        INC   $F6
        LDA   $F6
        JSR   LFB96
        LDA   #$41
        STA   $0527
        LDA   #$20
        STA   $0528
        STA   $052D
        LDA   $A2
        JSR   LFB20
        STA   $0529
        STX   $052A
        LDA   $A1
        JSR   LFB20
        STA   $052B
        STX   $052C
        LDA   #$07
        STA   $EF
        JMP   LF495
LFA5B   JSR   LFA5E
LFA5E   STX   $07F3
        LDX   $0550
        CMP   $77,x
        BEQ   LFA75
        PLA    
        PLA    
LFA6A   INC   $054F
        BEQ   LFA72
        JMP   LF984
LFA72   JMP   LF492
LFA75   INX    
        STX   $0550
        LDX   $07F3
        RTS    
LFA7D   CMP   #$41
        BCC   LFA84
        CMP   #$47
        RTS    
LFA84   CMP   #$30
        BCC   LFA9E
        CMP   #$3A
        RTS    
LFA8B   JSR   LFAA0
        ASL    
        ASL    
        ASL    
        ASL    
        STA   $055C
        JSR   LFB3F
        JSR   LFAA0
        ORA   $055C
LFA9E   SEC    
        RTS    
LFAA0   CMP   #$3A
        PHP    
        AND   #$0F
        PLP    
        BCC   LFAAA
        ADC   #$08
LFAAA   RTS    
LFAAB   DEC   $F3
LFAAD   LDA   #$00
        STA   $F1
        STA   $F2
        STA   $07F4
LFAB6   JSR   LFB3F
        BEQ   LFAF5
        CMP   #$20
        BEQ   LFAB6
LFABF   CMP   #$20
        BEQ   LFAF1
        CMP   #$2C
        BEQ   LFAF1
        CMP   #$30
        BCC   LFAF6
        CMP   #$47
        BCS   LFAF6
        CMP   #$3A
        BCC   LFAD9
        CMP   #$41
        BCC   LFAF6
        SBC   #$08
LFAD9   SBC   #$2F
        ASL    
        ASL    
        ASL    
        ASL    
        LDX   #$04
LFAE1   ASL    
        ROL   $F1
        ROL   $F2
        DEX    
        BNE   LFAE1
        INC   $07F4
        JSR   LFB3F
        BNE   LFABF
LFAF1   LDA   $07F4
        CLC    
LFAF5   RTS    
LFAF6   PLA    
        PLA    
        JMP   LF492
LFAFB   LDA   $A1
        LDX   $A2
LFAFF   PHA    
        TXA    
        JSR   LFB10
        PLA    
LFB05   JSR   LFB10
LFB08   LDA   #$20
        BIT   $3FA9
        JMP   LFFD2
LFB10   STX   $07F3
        JSR   LFB20
        JSR   LFFD2
        TXA    
        LDX   $07F3
        JMP   LFFD2
LFB20   PHA    
        JSR   LFB2A
        TAX    
        PLA    
        LSR    
        LSR    
        LSR    
        LSR    
LFB2A   AND   #$0F
        CMP   #$0A
        BCC   LFB32
        ADC   #$06
LFB32   ADC   #$30
        RTS    
LFB35   LDA   #$91
        JSR   LFFD2
LFB3A   LDA   #$0D
        JMP   LFFD2
LFB3F   STX   $07F3
        LDX   $F3
        CPX   $F4
        BCS   LFB57
        LDA   $0200,x
        CMP   #$3A
        BEQ   LFB57
        INC   $F3
LFB51   PHP    
        LDX   $07F3
        PLP    
        RTS    
LFB57   LDA   #$00
        BEQ   LFB51
LFB5B   LDA   $F1
        STA   $A1
        LDA   $F2
        STA   $A2
        RTS    
LFB64   SEC    
        LDA   $F1
        SBC   $A1
        STA   $F1
        LDA   $F2
        SBC   $A2
        STA   $F2
        RTS    
LFB72   LDA   #$01
LFB74   STA   $07F3
        SEC    
        LDA   $F1
        SBC   $07F3
        STA   $F1
        LDA   $F2
        SBC   #$00
        STA   $F2
        RTS    
LFB86   SEC    
        LDA   $9F
        SBC   #$01
        STA   $9F
        LDA   $A0
        SBC   #$00
        STA   $A0
        RTS    
LFB94   LDA   #$01
LFB96   CLC    
        ADC   $A1
        STA   $A1
        BCC   LFB9F
        INC   $A2
LFB9F   RTS    
LFBA0   BCS   LFBB6
        JSR   LFB5B
        JSR   LFAAD
        BCS   LFBB6
        JSR   LFB64
        LDA   $F1
        STA   $9F
        LDA   $F2
        STA   $A0
        CLC    
LFBB6   RTS    
LFBB7   STA   $0110
LFBBA   STX   $0112
        STY   $0111
        RTS    
LFBC1   LDA   $0110
LFBC4   LDX   $0112
        LDY   $0111
        RTS    
LFBCB   STX   $FA
        JSR   LCF11
        LDX   $FA
        EOR   #$80
        ASL    
        LDA   #$00
        RTS    

        ; ********************************************
        ;
        ; Output a message.
        ;
        ; Message address-1 is on the stack.
        ; LDA #HI (address-1)
        ; PHA
        ; LDA #LO (address-1)
        ; PHA
        ; JMP PrintMessage
        ;
        ; ********************************************

LFBD8   PHA                           ; First store all registers
        TYA    
        PHA    
        TXA    
        PHA    
        TSX                           ; Next, get the base address from
        INX                           ; the stack
        INX    
        INX    
        INX
    
        LDA   $0100,x                 ; Get LOW byte
        STA   $BC
        INX    
        LDA   $0100,x                 ; and HIGH byte of message
        STA   $BD
        INC   $BC                     ; +1 to message address
        BNE   LFBF3
        INC   $BD

LFBF3   LDY   #$00                    ; Now print message...
LFBF5   LDA   ($BC),y                 ; get byte from message
        BEQ   LFBFF                   ; 0? End of message byte flag?
        JSR   LFFD2                   ; if not, output byte
        INY                           ; next char,
        BNE   LFBF5                   ; and loop...

LFBFF   TYA                           ; add on message length-1 (0 at the end)
        TSX                           
        INX    
        INX    
        INX    
        INX    

        CLC                           ; add it onto the actual STACK param
        ADC   $BC
        STA   $0100,x                 ; first low...
        LDA   #$00
        ADC   $BD                     ; then high...
        INX    
        STA   $0100,x

        PLA                           ; then restore registers and exit...
        TAX    
        PLA    
        TAY    
        PLA    
        RTS    


        ; *********************************************
        ;
        ; Get I/O base address (ACIA)
        ;
        ; *********************************************
LFC19   LDX   #$00
        LDY   #$FD
        RTS    




        ; *********************************************
        ;
        ; Check for ROM's.
        ; Here we search for the ROM sig (cbm) at $8007
        ;
        ; *********************************************
LFC1E   LDX   #$03
        STX   $96
        LDA   #$00
LFC24   STA   $05EC,x
        DEX    
        BPL   LFC24
LFC2A   LDX   $96
        LDA   $FC7B,x
        TAX    
        STA   $FDD0,x
        LDY   #$02
LFC35   LDA   $8007,y
        CMP   $FC56,y
        BNE   LFC51
        DEY    
        BPL   LFC35
        LDA   $8006
        LDX   $96
        STA   $05EC,x
        CMP   #$01
        BNE   LFC51
        STX   $FB
        JSR   L8000
LFC51   DEC   $96
        BPL   LFC2A
        RTS    

        db    $43,$42,$4d             ; ROM ID  "cbm"
        



        ; ********************************************
        ;
        ; Phoenix routine....
        ;
        ; ********************************************
LFC59   SEI
        LDX   #$03
        LDA   $05EC,X
        BEQ   LFC71
        TAX
        PHA    
        LDA   $FC7B,x
        TAX    
        STA   $FDD0,x
        STX   $FB
        JSR   L8000
        PLA    
        TAX    
LFC71   DEX    
        BNE   LFC5C
        STA   $FDD0
        STX   $FB
        CLI    
        RTS    



        ; ********************************************
        ;
        ; ROM paging index.
        ;
        ; Since the plus/4 can have 4 32k auto running
        ; ROM's only certain combinations can be paged in
        ;
        ; Well, this isn't really true, you only use
        ; this system if you want to AUTO run, otherwise
        ; you can make use of the 8 ROM slots however you
        ; want..
        ; 
        ; ********************************************
        db    $00,$05,$0a,$0f         ; ( basic, 3plus1, unused, unused )





        ; ********************************************
        ; 
        ; Long fetch routine
        ;
        ; ********************************************

        STA   $FDD0,X
        TAX
        LDA   ($BE),Y
        STA   $FDD0,X
        RTS



        ; ********************************************
        ;
        ; Long jump routine
        ;
        ; ********************************************

        PHA
        STX   $FB
        STA   $FDD0,x
        LDX   $05F3
        LDA   $05F4
        PHA    
        LDA   $05F2
        PLP    
        JSR   LFCB0
        STA   $05F2
        PHP    
        PLA    
        STA   $05F4
        STX   $05F3
        PLA    
        STA   $FB
        TAX    
        STA   $FDD0,x
        RTS    
LFCB0   JMP   ($05F0)

;
; $FCB3 - IRQ entry
;
LFCB3   PHA                           ; save
        TXA    
        PHA    
        TYA    
        PHA    
        
LFCB8   STA   $FDD0                   ; LONG IRQ entry. Select kernal ROM.
        JMP   LCE00                   ; process user/kernal IRQ

LFCBE   LDX   $FB                     ; return back to correct ROM
        STA   $FDD0,x                 ; ROM select

        PLA                           ; restore
        TAY    
        PLA    
        TAX    
        PLA    
        RTI                           ; exit

;
; $FCC9 - cartrage entry
;

LFCC9   LDX   $FB                     ; for cartrage
        STA   $FDD0,x
        JMP   ($02FE)

;
; $FCD1 - ROM banking routines
;
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        DB    $ff,$ff
LFCF1   JMP   LFCC9                   ; cart entry point
LFCF4   JMP   LFC59
        JMP   LFC7F
        JMP   LFC89
        JMP   LFCB8
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        INS   DIRECTION,x
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        SKB   DIRECTION
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        RTI    
        INS   $4000,x
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        XAA   #$C0
        NOP    
        TAX    
        RTI    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        TSX    
        SKW   $D21E
        RLA   $1BD2
        PHP    
        AND   $025C,x
        LDA   (DIRECTION,x)
        INY    
        BRK    
        BRK    
        BRK    
        BRK    
        SKB   $D0
        PHP    
        ADC   ($5B),y
        ADC   $77,x
        ROR   $6000
        INS   $002E,x
        SBC   DIRECTION
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        BRK    
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        JMP   LB7C2
LFF4C   JMP   LDC49
PrintMessage   
        JMP   LFBD8                   ; Output Messages (LFF4F)
        JMP   LF445
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        INS   $FFFF,x
        LSR   $4C85,x
        LSR   $4CD8
        ???   
        HLT    
        INS   ($4C),y
        DEC   $4CF2
        DCM   ($F2),y
LFF90   JMP   LF41A
        JMP   LEE4D
        JMP   LEE1A
        JMP   LF427
        JMP   LF436
        JMP   LDB11
        JMP   LF423
        JMP   LEC8B
        JMP   LECDF
        JMP   LEF3B
        JMP   LEF23
        JMP   LEE2C
        JMP   LEDFA
LFFB7   JMP   LF41C                   ; Get status
LFFBA   JMP   LF413                   ; set LFS
LFFBD   JMP   LF40C                   ; set NAME
LFFC0   JMP   ($0318)                 ; do OPEN file          ($EF53)
LFFC3   JMP   ($031A)                 ; do CLOSE file         ($EE5D)
LFFC6   JMP   ($031C)                 ; set INPUT vector      ($ED18)
LFFC9   JMP   ($031E)                 ; set OUTPUT vector     ($ED60)
LFFCC   JMP   ($0320)                 ; restore I/O vector    ($EF0C)
LFFCF   JMP   ($0322)                 ; Input                 ($EBE8)
LFFD2   JMP   ($0324)                 ; Output (print usually)($EC4B)
LFFD5   JMP   LF043                   ; Load a program
LFFD8   JMP   LF194                   ; Save a proram
LFFDB   JMP   LCF2D                   ; set TIME
LFFDE   JMP   LCF26                   ; get TIME
LFFE1   JMP   ($0326)                 ; test STOP             ($F265)
LFFE4   JMP   ($0328)                 ; GET                   ($EBD9)
LFFE7   JMP   ($032A)                 ; Abort I/O             ($EF08)
        JMP   LCEF0                   ; Kernal UDTIM
        JMP   LD834                   ; get screen size
LFFF0   JMP   LD839                   ; put/get row column
        JMP   LFC19                   ; Get I/O address

LFFF6   STA   ROM_ON                  ; set ROM "on"
        JMP   LF2A4                   ; POWER on vector (hidden in JUMP)
        DW    LFFF6                   ; RESET vector 
        DW    LFCB3                   ; IRQ vector

 

Letzte Änderung: 2020-09-20 19:37:30
Rubriken-Übersicht
 4 Besucher online 

Valid XHTML 1.0 Transitional Valid CSS!