;Compile with RAM variables only


E000 0F         ???
E001 DC         ???		;Carry-over from BASIC ROM @$C000
E002 A5 61      	LDA FC1EXP
E004 C9 88      	CMP #$88
E006 90 03      	BCC $E00B
E008 20 D4 DA   	JSR MLDVEX
E00B 20 CC DC   	JSR INT
E00E A5 07      	LDA CHARAC
E010 18         	CLC
E011 69 81      	ADC #$81
E013 F0 F3      	BEQ $E00B
E015 38         	SEC
E016 E9 01      	SBC #$01
E018 48         	PHA
E019 A2 05      	LDX #$05
E01B B5 69      	LDA FC2EXP,X
E01D B4 61      	LDY FC1EXP,X
E01F 95 61      	STA FC1EXP,X
E021 94 69      	STY FC2EXP,X
E023 CA         	DEX
E024 10 F5      	BPL $E01B
E026 A5 56      	LDA JMPER+2
E028 85 70      	STA FC1ROU
E02A 20 53 D8   	JSR $D853
E02D 20 B4 DF   	JSR NEGOP
E030 A9 C4      	LDA FIXUP1	;#$C4
E032 A0 DF      	LDY FIXUP1+1	;#$DF table of some constants
E034 20 56 E0   	JSR POLYIN
E037 A9 00      	LDA #$00
E039 85 6F      	STA ARISGN
E03B 68         	PLA
E03C 20 B9 DA   	JSR $DAB9
E03F 60         	RTS

;====================================================================
; POLYX - Function Series Evaluation
;
POLYX
E040 85 71      	STA CSBFLN
E042 84 72      	STY CSBFLN+1
E044 20 CA DB   	JSR $DBCA
E047 A9 57      	LDA #$57
E049 20 28 DA   	JSR FMULT
E04C 20 5A E0   	JSR POLYX1
E04F A9 57      	LDA #$57
E051 A0 00      	LDY #$00
E053 4C 28 DA   	JMP FMULT

POLYIN
E056 85 71      	STA CSBFLN
E058 84 72      	STY CSBFLN+1

POLYX1
E05A 20 C7 DB   	JSR MOV2F
E05D B1 71      	LDA (CSBFLN),Y
E05F 85 67      	STA SEVALP
E061 A4 71      	LDY CSBFLN
E063 C8         	INY
E064 98         	TYA
E065 D0 02      	BNE POLYSK1
E067 E6 72      	INC CSBFLN+1

POLYSK1
E069 85 71      	STA CSBFLN
E06B A4 72      	LDY CSBFLN+1

POLYLP
E06D 20 28 DA   	JSR FMULT
E070 A5 71      	LDA CSBFLN
E072 A4 72      	LDY CSBFLN+1
E074 18         	CLC
E075 69 05      	ADC #$05
E077 90 01      	BCC POLYSK2
E079 C8         	INY

POLYSK2
E07A 85 71      	STA CSBFLN
E07C 84 72      	STY CSBFLN+1
E07E 20 67 D8   	JSR FADD
E081 A9 5C      	LDA #$5C
E083 A0 00      	LDY #$00
E085 C6 67      	DEC SEVALP
E087 D0 E4      	BNE POLYLP
E089 60         	RTS

;====================================================================
; RMULC - Constant Manipulation: RND Data
;
RMULC
E08A .db $98, $35, $44, $7A, $00, $68, $28, $B1, $46, $00

;====================================================================
; RND - Perform RND function
;
RND
E094 20 2B DC   	JSR SIGN
E097 30 37      	BMI RNDCAL
E099 D0 20      	BNE RANDDT
E09B 20 00 E5   	JSR IOBASE

E09E 86 22      	STX UTLPTR
E0A0 84 23      	STY UTLPTR+1
E0A2 A0 04      	LDY #$04
E0A4 B1 22      	LDA (UTLPTR),Y
E0A6 85 62      	STA FC1M1
E0A8 C8         	INY
E0A9 B1 22      	LDA (UTLPTR),Y
E0AB 85 64      	STA FC1M3
E0AD A0 08      	LDY #$08
E0AF B1 22      	LDA (UTLPTR),Y
E0B1 85 63      	STA FC1M2
E0B3 C8         	INY
E0B4 B1 22      	LDA (UTLPTR),Y
E0B6 85 65      	STA FC1M4
E0B8 4C E0 E0   	JMP RNDEXIT

RANDDT
E0BB A9 BB      	LDA #$BB
E0BD A0 00      	LDY #$00
E0BF 20 A2 DB   	JSR MOVFM

E0C2 A9 8A      	LDA FIXUP1+2	;#$8A randomize data LSB
E0C4 A0 E0      	LDY FIXUP1+3	;#$E0	;randomize data MSB
E0C6 20 28 DA   	JSR FMULT	;multiply

E0C9 A9 BF      	LDA FIXUP1+4	;#$BF
E0CB A0 E0      	LDY FIXUP1+5	;#$E0
E0CD 20 67 D8   	JSR FADD	;ADD at E0BF

RNDCAL
E0D0 A6 65      	LDX FC1M4
E0D2 A5 62      	LDA FC1M1
E0D4 85 65      	STA FC1M4
E0D6 86 62      	STX FC1M1
E0D8 A6 63      	LDX FC1M2
E0DA A5 64      	LDA FC1M3
E0DC 85 63      	STA FC1M2
E0DE 86 64      	STX FC1M3

RNDEXIT
E0E0 A9 00      	LDA #$00
E0E2 85 66      	STA FC1SGN
E0E4 A5 61      	LDA FC1EXP
E0E6 85 70      	STA FC1ROU
E0E8 A9 80      	LDA #$80
E0EA 85 61      	STA FC1EXP
E0EC 20 D7 D8   	JSR $D8D7
E0EF A2 BB      	LDX #$BB
E0F1 A0 00      	LDY #$00

RNEXIT
E0F3 4C D4 DB   	JMP $DBD4


;====================================================================
; BIOERR - Handle I/O Error in BASIC
;
BIOERR
E0F6 C9 F0     	CMP #$F0
E0F8 D0 07      	BNE BERSK
E0FA 84 38      	STY MEMSIZ+1
E0FC 86 37      	STX MEMSIZ
E0FE 4C 63 C6   	JMP $C663

BERSK
E101 AA         	TAX
E102 D0 02      	BNE BERREX
E104 A2 1E      	LDX #$1E

BERREX
E106 4C 37 C4   	JMP ERROR

;====================================================================
; BCHOUT - Output character
;
BCHOUT
E109 	JSR (CHOTVP)		;CHROUT
E10C B0 E8	BCS BIOERR
E10E 60         	RTS

;====================================================================
; BCHIN - Input a character
;
BCHIN
E10F 	JSR (CHINVP)		;CHRIN
E112 B0 E2      	BCS BIOERR
E114 60         	RTS

;====================================================================
; BCKOUT - Setup for output
;
BCKOUT
E115 	JSR (CKOTVP)		;CHKOUT
E118 B0 DC      	BCS BIOERR
E11A 60         	RTS

;====================================================================
; BCKIN - Setup for input
;
BCKIN
E11B 	JSR (CKINVP)		;CHKIN
E11E B0 D6     	BCS BIOERR
E120 60         	RTS

;====================================================================
; BGETIN - Get one character
;
BGETIN
E121 	JSR (GTINVP)		;GETIN
E124 B0 D0      	BCS BIOERR
E126 60         	RTS

;====================================================================
; SYS - Perform SYS
;
SYS
E127 20 8A CD   	JSR FRMNUM	;confirm result
E12A 20 F7 D7   	JSR GETADR	;convert FAC1 to integer (line) number

E12D A9 E1      	LDA FIXUP1+7	;#$E1
E12F 48         	PHA
E130 A9 43      	LDA FIXUP1+6	;#$43
E132 48         	PHA	;push address $E143 (breakpoint)
E133 AD 0F 03   	LDA R6502P
E136 48        	PHA		;save processor flags
E137 AD 0C 03   	LDA R6502A
E13A AE 0D 03   	LDX R6502X
E13D AC 0E 03   	LDY R6502Y
E140 28         	PLP		;restore flags
E141 6C 14 00   	JMP (INTRVL)		;jump to routine

E144 08         	PHP		;on return, restore regs
E145 8D 0C 03   	STA R6502A
E148 BE 0D 03  	STX R6502X
E14B 8C 0E 03   	STY R6502Y
E14E 68        	PLA
E14F 8D 0F 03   	STA R6502P
E152 60         	RTS

;====================================================================
; SAVET - Perform SAVE
;
SAVET
E153 20 D1 E1   	JSR SLPARA
E156 A6 2D      	LDX VARTAB
E158 A4 2E      	LDY VARTAB+1
E15A A9 2B      	LDA #$2B
E15C 20 75 F6   	JSR ISAVE
E15F B0 95      	BCS BIOERR
E161 60         	RTS

;====================================================================
; VERFYT - Perform Verify/Load
;
VERFYT
E162 A9 01      	LDA #$01		;1=verify
E164 	.db $2C		;results in BIT $00A9 skip
VERFYL
E165 A9 00      	LDA #$00		;0=load
E167 85 0A      	STA VERCK
E169 20 D1 E1   	JSR SLPARA

E16C A5 0A      	LDA VERCK
E16E A6 2B      	LDX TXTTAB
E170 A4 2C      	LDY TXTTAB+1
E172 20 42 F5   	JSR ILOAD

E175 B0 57      	BCS CLSEXT
E177 A5 0A      	LDA VERCK
E179 F0 1A      	BEQ VERLD

E17B A2 1C      	LDX #$1C
E17D 20 57 FE   	JSR IRDST
E180 29 10      	AND #$10
E182 F0 03      	BEQ SKPRDY

E184 4C 37 C4   	JMP ERROR

SKPRDY
E187 A5 7A      	LDA TXTPTR
E189 C9 02      	CMP #$02
E18B F0 07      	BEQ VERIFX

E18D A9 64      	LDA #$64
E18F A0 C3      	LDY #$C3
E191 4C 1E CB   	JMP STROUT	;string at $C364

VERIFX
E194 60         	RTS

VERLD
E195 20 57 FE   	JSR IRDST
E198 29 EF      	AND #$BF
E19A F0 05      	BEQ VERSK1

E19C A2 1D      	LDX #$1D
E19E 4C 17 C4   	JMP ERROR

VERSK1
E1A1 A5 7B      	LDA TXTPTR+1
E1A3 C9 02      	CMP #$02
E1A5 D0 0E      	BNE VERSK2

E1A7 86 2D      	STX VARTAB
E1A9 84 2E      	STY VARTAB+1 
E1AB A9 76      	LDA #$16
E1AD A0 C3      	LDY #$C3
E1AF 20 1E CB   	JSR STROUT		;string at $C316
E1B2 4C 2A C5   	JMP $C52A

VERSK2
E1B5 20 BE C6   	JSR STXPT
E1B8 4C 76 E4   	JMP BASSLN

;====================================================================
; OPENT - Perform OPEN
;
OPENT
E1BB 10 16 E2   	JSR OCPARA
E1BE 	JSR (OPENVP)		;OPEN
E1C1 B0 0B      	BCS CLSEXT
E1C3 60         	RTS

;====================================================================
; CLOSET - Perform CLOSE
;
CLOSET
E1C4 20 16 E2   	JSR OCPARA
E1C7 A5 49      	LDA FORPNT
E1C9 	JSR (CLOSVP)		;CLOSE
E1CC 90 C6      	BCC VERIFX
CLSEXT
E1CE 4C F6 E0   	JMP BIOERR

;====================================================================
; SLPARA - Get LOAD/SAVE parameters
;
SLPARA
E1D1 A9 00      	LDA #$00
E1D3 20 BD FF   	JSR SETNAM
E1D6 A2 01      	LDX #$01
E1D8 A0 00      	LDY #$00
E1DA 20 50 FE   	JSR SETLFS
E1DD 20 03 E2   	JSR DEFLT
E1E0 20 54 E2   	JSR OPCSK2
E1E3 20 03 E2   	JSR DEFLT
E1E6 20 FD E1   	JSR COMBYT
E1E9 A0 00      	LDY #$00
E1EB 86 49      	STX FORPNT
E1ED 20 50 FE   	JSR SETLFS
E1F0 20 03 E2   	JSR DEFLT
E1F3 20 FD E1   	JSR COMBYT
E1F6 8A         	TXA
E1F7 A8         	TAY
E1F8 A6 49      	LDX FORPNT
E1FA 4C 50 FE   	JMP SETLFS

;====================================================================
; COMBYT - Get next one-byte parameter
;
COMBYT
E1FD 20 0B E2   	JSR COMMA
E200 4C 9E D7   	JMP GETBYT

;====================================================================
; DEFLT - Check default parameters
;
DEFLT
E203 20 79 00   	JSR CHRGOT
E206 D0 02      	BNE DEFLEX
E208 68         	PLA
E209 68         	PLA
DEFLEX
E20A 60         	RTS

;====================================================================
; COMMA - Check for comma
;
COMMA
E20B 20 FD CE   	JSR CHKCOM
E20E 20 79 00   	JSR CHRGOT
E211 D0 F7      	BNE DEFLEX
E213 4C 08 CF   	JMP SNERR

;====================================================================
; OCPARA - Get OPEN/CLOSE parameters
;
OCPARA
E216 A9 00      	LDA #$00
E218 20 49 FE   	JSR ISETNM
E21B 20 0E E2   	JSR COMMA+3
E21E 20 9E D7   	JSR GETBYT
E221 86 49      	STX FORPNT
E223 8A         	TXA
E224 A2 01      	LDA #$01
E226 A0 00      	LDY #$00
E228 20 50 FE   	JSR SETLFS
E22B 20 03 E2   	JSR DEFLT
E22E 20 FD E1   	JSR COMBYT
E231 86 4A      	STX FORPNT+1
E233 A0 00      	LDY #$00
E235 A5 49      	LDA FORPNT
E237 E0 03      	CPX #$03
E239 90 01      	BCC OPCSK1

E23B 88         	DEY
OCPSK1
E23C 20 50 FE   	JSR SETLFS
E23F 20 03 E2   	JSR DEFLT
E242 20 FD E1   	JSR COMBYT
E245 8A         	TXA
E246 A8         	TAY
E247 A6 4A      	LDX FORPNT+1
E249 A5 49      	LDA FORPNT
E24B 20 50 FE   	JSR SETLFS
E24E 20 03 E2   	JSR DEFLT
E251 20 0B E2   	JSR COMMA

OCPSK2
E254 20 9E CD   	JSR FRMEVL
E257 20 A3 D6   	JSR FRESTR
E25A A6 22      	LDX UTLPTR
E25C A4 23      	LDY UTLPTR+1
E25E 4C 49 FE   	JMP ISETNM

;====================================================================
; COS - Perform COS function
;
COS
E261 A9 DD      	LDA FIXUP1+12	;#$DD
E263 A0 E2      	LDY FIXUP1+13	;#$E2 PI2 table
E265 20 67 D8   	JSR FADD

;====================================================================
; SIN - Perform SIN function
;
SIN
E268 20 0C DC   	JSR MOVAF
E26B A9 E2      	LDA FIXUP1+14	;#$E2
E26D A0 E2      	LDY FIXUP1+15	;#$E2 PI*2 table
E26F A6 6E      	LDX FC2SGN
E271 20 07 DB   	JSR FDIV
E274 20 0C DC   	JSR MOVAF
E277 20 CC DC   	JSR INT
E27A A9 00      	LDA #$00
E27C 85 6F      	STA ARISGN
E27E 20 53 D8   	JSR $D853
E281 A9 E7      	LDA FIXUP1+16	;#$E7
E283 A0 E2      	LDY FIXUP1+17	;#$E2
E285 20 50 D8   	JSR FSUB	;const 1/4
E288 A5 66      	LDA FC1SGN
E28A 48         	PHA
E28B 10 0D      	BPL SINCON1
E28D 20 49 D8   	JSR FADDH
E290 A5 66      	LDA FC1SGN
E292 30 09     	BMI SINCON1A

E294 A5 12      	LDA TANSGN
E296 49 FF      	EOR #$FF
E298 85 12      	STA TANSGN

SINCON1
E29A 20 B4 DF   	JSR NEGOP

SINCON1A
E29D A9 E7      	LDA FIXUP1+16	;#$E7
E29F A0 E2      	LDY FIXUP1+17	;#$E2
E2A1 20 67  D8  	JSR FADD	;const 1/4
E2A4 68         	PLA
E2A5 10 03      	BPL SINCON2
E2A7 20 B4  DF  	JSR NEGOP

SINCON2
E2AA A9 EC      	LDA FIXUP1+18	; #$EC
E2AC A0 E2      	LDY FIXUP1+19	;#$E2	;counter
E2AE 4C 40 E0   	JMP POLYX

;====================================================================
; TAN - Perform TAN function
;
TAN
E2B1 20 CA DB   	JSR $DBCA
E2B4 A9 00      	LDA #$00
E2B6 85 12      	STA TANSGN
E2B8 20 68 E2   	JSR SIN
E2BB A2 4E      	LDX #$4E
E2BD A0 00      	LDY #$00
E2BF 20 F3 E0   	JSR RNEXIT
E2C2 A9 57      	LDA #$57
E2C4 A0 00      	LDY #$00
E2C6 20 A2 DB   	JSR MOVFM
E2C9 A9 00      	LDA #$00
E2CB 85 66      	STA FC1SGN
E2CD A5 12      	LDA TANSGN
E2CF 20 D9 E2   	JSR TAN2
E2D2 A9 4E      	LDA #$4E
E2D4 A0 00      	LDY #$00
E2D6 4C 0F DB   	JMP FDIVT

TAN2
E2D9 48         	PHA
E2DA 4C 9A E2   	JMP SINCON1

;
;Data: Trigonometry Constants $E2DD-E30A
PI2		;PI/2
E2DD .db $81, $49, $0F, $DA, $A2 

PI22		;PI*2
E2E2 .db $83, $49, $0F, $DA, $A2

PI14		;1/4
E2E7 .db $7F, $00, $00, $00, $00 

RNCTR		;counter
E2EC .db $05

TRIG14		;-14.3813907
E2ED .db $84, $E6, $1A, $2D, $1B 

TRIG42		;42.0077971
E2F2 .db $86, $28, $07, $FB, $F8

TRIG76		;-76.7041703
E2F7 .db $87, $99, $68, $89, $01

TRIG81		;81.6052237
E2FC .db $87, $23, $35, $DF, $E1

TRIG41		;-41.3417021
E301 .db, $86, $A5, $5D, $E7, $28

TRIG6		;6.28318531
E306 .db $83, $49, $0F, $DA, $A2


;====================================================================
; ATN - Perform ATN function
;
ATN
E30B A5 66      	LDA FC1SGN
E30D 48         	PHA
E30E 10 03      	BPL ATNSK1
E310 20 B4 DF   	JSR NEGOP

ATNSK1
E313 A5 61      	LDA FC1EXP
E315 48         	PHA
E316 C9 21      	CMP #$81
E318 90 07      	BCC ATNSK2

E31A A9 BC      	LDA #$BC
E31C A0 D9      	LDY #$D9	;FONE - table of floating point constants
E31E 20 0F DB   	JSR FDIVT

ATNSK2
E321 A9 3B      	LDA FIXUP1+22	;#$3B
E323 A0 E3      	LDY FIXUP1+23	;$$E3 ATNCON - table of ATN constants
E325 20 40 E0  	JSR POLYX

E328 68        	PLA
E329 C9 81      	CMP #$81
E32B 90 07      	BCC ATNSK3
E32D A9 DD     	LDA FIXUP1+12	;#$DD
E32F A0 E2      	LDY FIXUP1+13	;#$E2	;const PI/2
E331 20 50 D8   	JSR FSUB

ATNSK3
E334 68         	PLA
E335 10 03      	BPL ATNEXT
E337 4C B4 DF   	JMP NEGOP

ATNEXT
E33A 60         	RTS

;
;  ATN Constants $E33B-E377
;
ATNCON
E33B .db $0B, $76, $B3, $83, $BD, $D3, $79, $1E
E343 .db $F4, $A6, $F5, $7B, $83, $FC, $B0, $10
E34B .db $7C, $0C, $1F, $67, $CA, $7C, $DE, $53
E353 .db $CB, $C1, $7D, $14, $64, $70, $4C, $7D
E35B .db $B7, $EA, $51, $7A, $7D, $63, $30, $88
E363 .db $7E, $7E, $92, $44, $99, $3A, $7E, $4C 
E36B .db $CC, $91, $C7, $7F, $AA, $AA, $AA, $13
E373 .db $81, $00, $00, $00, $00,

;====================================================================
; INIT - BASIC cold start
;
INIT
E378 20 5B E4   	JSR INITV

INITNV
E37B 20 A4 E3   	JSR INITCZ
E37E 20 04 E4   	JSR INITMS
E381 A2 FB      	LDX #$FB
E383 9A         	TXS
E384 4C 74 C4   	JMP READY	;jump to BASIC

;====================================================================
; INITAT - CHRGET for zero-page
;
INITAT
E387 E6 7A      	INC TXTPTR
E389 D0 02      	BNE ININCR
E38B E6 7B      	INC TXTPTR+1

ININCR
E38D AD 60 EA   	LDA MOVLOOP-2
E390 C9 3A      	CMP #':'	;$3A
E392 B0 0A      	BCS INIEXT

E394 C9 20      	CMP #' '	;$20 {space}
E396 F0 EF      	BEQ INITAT

E398 38         	SEC
E399 E9 30      	SBC #$30
E39B 38         	SEC
E39C E9 D0      	SBC #$D0

INIEXT
E39E 60         	RTS

;====================================================================
; RNDSED - RND seed value
;
RNDSED
E39F .db $80, $4F, $C7, $52, $58

;====================================================================
; INITCZ - Initialize BASIC RAM
;
INITCZ
E3A4 A9 4C      	LDA #$4C
E3A6 85 54      	STA JMPER
E3A8 85 00      	STA USRPOK
E3AA A9 48      	LDA #$48
E3AC A0 D2      	LDY #$D2
E3AE 85 01      	STA USRVEC	;USER vector to $D248
E3B0 84 02      	STY USRVEC+1

E3B2 A9 91      	LDA #$91
E3B4 A0 D3      	LDY #$D3
E3B6 85 05      	STA ADRAY2
E3B8 84 06      	STY ADRAY2+1	;$D391

E3BA A9 AA      	LDA #$AA
E3BC A0 D1      	LDY #$D1
E3BE 85 03      	STA ADRAY1
E3C0 84 04      	STY ADRAY1+1	;$D1AA

E3C2 A2 1C      	LDX #$1C

CHGLOP
E3C4 ED 87 E3   	LDA INITAT,X	;copy CHRGET
E3C7 95 73      	STA CHRGET,X
E3C9 CA         	DEX
E3CA 10 F8      	BPL CHGLOP

E3CC A9 03      	LDA #$03
E3CE 85 53      	STA JMPER-1	:$53
E3D0 A9 00      	LDA #$00
E3D2 85 68      	STA FC1OVF
E3D4 85 13      	STA IOPMPT
E3D6 85 18      	STA LASTPT+1
E3D8 A2 01      	LDX #$01
E3DA BE FD 01   	STX BUF-3	;$01FD
E3DD BE FC 01   	STX BUF-4	;$01FC
E3E0 A2 19      	LDX #$19
E3E2 86 16      	STX TEMPPT
E3E4 38         	SEC
E3E5 20 82 FE   	JSR IMEMBT
E3E8 86 2B      	STX TXTTAB
E3EA 84 2C      	STY TXTTAB+1
E3EC 38         	SEC
E3ED 20 73 FE   	JSR IMEMTP
E3F0 86 37      	STX MEMSIZ
E3F2 84 38      	STY MEMSIZ+1
E3F4 86 33      	STX FRETOP
E3F6 84 34      	STY FRETOP+1
E3F8 A0 00      	LDY #$00
E3FA 98         	TYA
E3FB 91 2B      	STA (TXTTAB),Y
E3FD E6 2B      	INC TXTTAB
E3FF D0 02      	BNE CZEXIT

E401 E6 2C      	INC TXTTAB+1

CZEXIT
E403 60         	RTS


;====================================================================
; INITMS - Print power-up message
;
INITMS
E404 A5 2B      	LDA TXTTAB
E406 A4 2C      	LDY TXTTAB+1
E408 20 08 C4   	JSR REASON	; Check for memory overlap?
E40B A9 36      	LDA FIXUP1+30	;#$36	WORDS text
E40D A0 E4      	LDY FIXUP1+31	;#$E4
E40F 20 1E CB   	JSR STROUT

E412 A5 37      	LDA MEMSIZ
E414 38         	SEC
E415 E5 2B      	SBC TXTTAB
E417 AA         	TAX
E418 A5 38      	LDA MEMSIZ+1
E41A E5 2C      	SBC TXTTAB+1
E41C 20 CD DD   	JSR $DDCD	; External entry into INPRT 
E41F A9 29     	LDA FIXUP1+32	;#$29	FREMES text
E421 A0 E4      	LDY FIXUP1+33	;#$E4
E423 20 1E CB   	JSR STROUT
E426 4C 44 C6   	JMP $C644	; External entry into SCRTCH

FREMES
E429 .db ' BYTES FREE', $0D, $00

WORDS
E436 .db $93, '**** CBM BASIC V2 ****', $0D, $00

;====================================================================
; BVTRS - Basic vector table
;
BVTRS
E44F .dw ERROR		;$C43A
E451 .dw MAIN		;$C483
E453 .dw CRNCH		;$C57C
E455 .dw QPLOP		;$C71A
E457 .dw GONE		;$C7E4
E459 .dw EVAL		;$CE86

;====================================================================
; INITV - Initialize vectors
;
INITV
E45B A2 0B      	LDX #$0B	;move 12 bytes

TVLOOP
E45D BD 4F E4   	LDA BVTRS,X	;load from BASIC vector table
E460 9D 00 03   	STA ERRVPT,X	;save to $0300
E463 CA         	DEX
E464 10 F7      	BPL TVLOOP
E466 60         	RTS

;====================================================================
; BASSFT - BASIC warm start
;
BASSFT
E467 	JSR (CLCHVP)	;CLRCH
E46A A9 00      	LDA #$00
E46C 85 13      	STA IOPMPT
E46E 20 7A C6   	JSR $C67A	;External entry into CLEAR
E471 58         	CLI
E472 4C 74 C4   	JMP READY

E475 .db $41

BASSLN
E476 20 33 C5	JSR LNKPRG
E479 4C 77 C6   	JMP $C677	;external entry into CLEAR


;====================================================================
; FIXUP1 - Absolute location fixup area #1
;
FIXUP1	.org $E47C
	.dw $DFC4	;e47c
	.dw RMULC	;7e
	.dw RANDDT+4	;80
	.dw SYS+28	;82
	.dw $C364	;84
	.dw $C316	;86
	.dw PI2	;88
	.dw PI22	;8a
	.dw PI14	;8c
	.dw RNCTR	;8e
	.dw $D9BC	;90
	.dw ATNCON	;92
	.dw $D248	;94
	.dw $D391	;96
	.dw $D1AA	;98
	.dw WORDS	;9a
	.dw FREMES	;9c
	.dw CLKWAIT+1	;9e
;ends at $ef9f


;====================================================================
; SOUT1 - Serial output "1" (inverted logic)
;
SOUT1
E4A0 AD 2C 91   	LDA D2PCR
E4A3 29 DF      	AND #%11011111	;$DF CB2
E4A5 8D 2C 91   	STA D2PCR
E4AB 60         	RTS

;====================================================================
; SOUT0- Serial output "0" (inverted logic)
;
SOUT0
E4A9 AD 2C 91   	LDA D2PCR
E4AC 09 20      	ORA #%00100000	;$20
E4AE 8D 2C 91   	STA D2PCR
E4B1 60         	RTS

;====================================================================
; SDCLK - Get SERDATA/SCLK in
;
SDCLK
E4B2 AD 1F 91   	LDA D1ORAH
E4B5 CD 1F 91   	CMP D1ORAH
E4B8 D0 F8      	BNE SDCLK

E4BA 4A         	LSR
E4BB 60         	RTS

;====================================================================
; SSADR - Get SECADR patch for LOAD/VERIFY
;
SSADR
E4BC A6 B9      	LDX SECADR
E4BE 4C 47 F6   	JMP SRCHMS

;====================================================================
; SLDPCH - Relocated patch for serial LOAD/VERIFY
;
SLDPCH
E4C1 8A         	TXA
E4C2 D0 08      	BNE SLDEXIT

E4C4 A5 C3      	LDA MEMUSS
E4C6 85 AE      	STA EAL
E4C8 A5 C4      	LDA MEMUSS+1
E4CA 85 AF      	STA EAL+1

SLDEXIT
E4CC 4C 6A F6   	JMP LOADMS

;====================================================================
; TPWPCH - Tape write patch for CLOSE
;
TPWPCH
E4CF 20 E3 F8   	JSR TPWRIT
E4D2 90 03      	BCC TPWCHEX
E4D4 68         	PLA
E4D5 A9 00      	LDA #$00

TPWCHEX
E4D7 4C 9E F3   	JMP ICLSE1	;External entry into ICLOSE

;====================================================================
; FIXUP2 - Absolute location fixup area #2
;
FIXUP2	.org E4DA
	.dw KRNLSV	;e4da
	.dw $FFFF	;dc
	.dw $FFFF	;de
	.dw $FFFF	;e0
	.dw $FFFF	;e2
	.dw $FFFF	;e4
	.dw $FFFF	;e6
	.dw $FFFF	;e8
	.dw $FFFF	;ea
	.dw $FFFF	;ec
	.dw $FFFF	;ee
	.dw $FFFF	;f0
	.dw $FFFF	;f2
	.dw $FFFF	;f4
	.dw $FFFF	;f6
	.dw $FFFF	;f8
	.dw $FFFF	;fa
	.dw $FFFF	;fc
	.dw $FFFF	;fe

;ends at $e4ff

;====================================================================
; IOBASE - Return I/O base address
;
IOBASE
E500 A2 10      	LDX #$10
E502 A0 91      	LDY #$91
E504 60         	RTS

;====================================================================
; ISCREN - Return screen organization
;
ISCREN
E505 A2 16      	LDX #$16        
E507 A0 17      	LDY #$17
E509 60         	RTS

;====================================================================
; IPLOT - Read/set cursor position
;
IPLOT
E50A B0 07      	BCS READPL	;carry set to read
E50C 86 D6      	STX CURROW
E50E 84 D3      	STY CSRIDX
E510 20 87 E5   	JSR SCNPTR

READPL
E513 A6 D6      	LDX CURROW
E515 A4 D3      	LDY CSRIDX
E517 60         	RTS

;====================================================================
; CINT1 - Initialize I/O
;
CINT1
E518 20 BE E5   	JSR IODEF1
E51B AD 88 02   	LDA HIPAGE
E51E 29 FD      	AND #%11111101	;$FD
E520 0A         	ASL
E521 0A         	ASL
E522 09 80      	ORA #%10110000	;$B0
E524 8D 05 90   	STA VRSTRT
E527 AD 88 02   	LDA HIPAGE
E52A 29 02      	AND #%00000010	;$02
E52C F0 08      	BEQ $E536

E52E A9 80      	LDA #$B0
E530 0D 02 90  	ORA VRCOLS
E533 8D 02 90   	STA VRCOLS
E536 A9 00      	LDA #$00
E538 8D 91 02   	STA SHMODE
E53B 85 CF      	STA BLNON

E53D A9 DC      	LDA FIXUP1+34	;#$DC
E53F 8D 8F 02   	STA FCEVAL
E542 A9 EE      	LDA FIXUP1+35	;#$EE
E544 8D 90 02   	STA FCEVAL+1	;FCEVAL=$EEDC???

E547 A9 0A      	LDA #$0A
E549 8D 89 02   	STA KBMAXL
E54C 8D 8C 02   	STA KRPTDL
E54F A9 06      	LDA #$06
E551 8D 86 02   	STA CLCODE
E554 A9 04      	LDA #$04
E556 8D 8E 02   	STA LSSHFT
E559 A9 0C      	LDA #$0C
E55B 85 CD      	STA BLNCT
E55D 85 CC      	STA BLNSW
;
; Clear screen
;
CLRSCN
E55F AD 88 02   	LDA HIPAGE
E562 09 80      	ORA #%10000000	;$80
E564 A8        	TAY
E565 A9 00      	LDA #$00
E567 AA         	TAX

CLRLP1
E568 94 D9      	STY SLLTBL,X
E56A 18         	CLC
E56B 69 16      	ADC #$16
E56D 90 01      	BCC CLRSC1
E56F C8         	INY

CLRSC1
E570 E8         	INX
E571 E0 18      	CPX #$18
E573 D0 F3      	BNE CLRLP1

E575 A9 FF      	LDA #$FF
E577 95 D9      	STA SLLTBL,X
E579 A2 16      	LDX #$16

CLRLP2
E57B 20 8D EA   	JSR CLRLIN
E57E CA         	DEX
E57F 10 FA      	BPL CLRLP2
;
; "Home" cursor
;
HOME
E581 A0 00      	LDY #$00
E583 84 D3      	STY CSRIDX
E585 84 D6      	STY CURROW
;
; Set screen pointers
;
SCNPTR
E587 A6 D6      	LDX CURROW
E589 A5 D3      	LDA CSRIDX

SCNPLP
E58B B4 D9      	LDY SLLTBL,X
E58D 30 08      	BMI SCNPT1
E58F 18         	CLC
E590 69 16      	ADC #$16
E592 85 D3      	STA CSRIDX
E594 CA         	DEX
E595 10 F4      	BPL SCNPLP

SCNPT1
E597 B5 D9      	LDA SLLTBL,X
E599 29 03      	AND #$03
E59B 0D 88 02   	ORA HIPAGE
E59E 85 D2      	STA LINPTR+1
E5A0 BD FD ED   	LDA LBSCAD,X
E5A3 85 D1      	STA LINPTR
E5A5 A9 15      	LDA #$15
E5A7 E8         	INX

SCNLP1
E5A8 B4 D9      	LDY SLLTBL,X
E5AA 30 06      	BMI SCNEXIT
E5AC 18         	CLC
E5AD 69 16      	ADC #$16
E5AF E8         	INX
E5B0 10 F6      	BPL SCNLP1

SCNEXIT
E5B2 85 D5      	STA LINLEN
E5B4 60         	RTS

;====================================================================
; PANIC - Set I/O defaults (unused entry point)
;
PANIC
E5B5 20 BB E5   	JSR IODEF1
E5B8 4C 81 E5   	JMP HOME
;
; Real PANIC entry
;
IODEF1
E5BB A9 03      	LDA #$03
E5BD 85 9A      	STA OUTDEV
E5BF A9 00      	LDA #$00
E5C1 85 99      	STA INDEV
;
; Initialize 6561 VIC
;
E5C3 A2 10      	LDX #$10


V6561I
E5C5 BD E3 ED   	LDA VICSUP-1,X	;$ede3
E5C8 9D FF 8F   	STA $8FFF,X
E5CB CA         	DEX
E5CC D0 F7      	BNE V6561I
E5CE 60         	RTS

;====================================================================
; LP2 - Get character from keyboard buffer
;
LP2
E5CF AC 77 02   	LDY KBUFFR
E5D2 A2 00      	LDX #$00

LP2LOOP
E5D4 BD 78 02   	LDA KBUFFR+1,X
E5D7 9D 77 02   	STA KBUFFR,X
E5DA E8         	INX
E5DB E4 C6      	CPX KEYCNT
E5DD D0 F5      	BNE LP2LOOP
E5DF C6 C6      	DEC KEYCNT
E5E1 98         	TYA
E5E2 58         	CLI
E5E3 18         	CLC
E5E4 60         	RTS

;====================================================================
; INKEY - Input from keyboard
;
INKEY
E5E5 20 42 E7   	JSR OUTSCR

KEYLP1
E5E8 A5 C6      	LDA KEYCNT
E5EA 85 CC      	STA BLNSW
E5EC 8D 92 02   	STA SCRLFL
E5EF F0 F7      	BEQ KEYLP1

E5F1 78         	SEI
E5F2 A5 CF      	LDA BLNON
E5F4 F0 0C      	BEQ INKEY1

E5F6 A5 CE      	LDA GDBLN
E5F8 AE 87 02   	LDX CSRCLR
E5FB A0 00      	LDY #$00
E5FD 84 CF      	STY BLNON
E5FF 20 A1 EA   	JSR PRNSCR

INKEY1
E602 20 CF E5   	JSR LP2
E605 C9 83      	CMP #$83
E607 D0 10      	BNE INKEY2

E609 A2 09      	LDX #$09
E60B 78         	SEI
E60C 86 C6      	STX KEYCNT

KEYLP2
E60E BD F3 ED   	LDA RUNSHF-1,X
E611 9D 76 02   	STA KBUFFR-1,X
E614 CA         	DEX
E615 D0 F7      	BNE KEYLP2
E617 F0 CF      	BEQ KEYLP1

INKEY2
E619 C9 0D      	CMP #$0D
E61B D0 C8      	BNE INKEY

E61D A4 D5      	LDY LINLEN
E61F 84 D0      	STY INSRC

KEYLP3
E621 B1 D1      	LDA (LINPTR),Y
E623 C9 20      	CMP #$20
E625 D0 03      	BNE INKEY3

E627 88         	DEY
E628 D0 F7      	BNE KEYLP3

INKEY3
E62A C8         	INY
E62B 84 C8      	STY EOLPTR
E62D A0 00      	LDY #$00
E62F 8C 92 02   	STY SCRLFL
E632 84 D3      	STY CSRIDX
E634 84 D4      	STY CSRMOD
E636 A5 C9      	LDA ICRROW
E638 30 1D      	BMI INSCR1

E63A A6 D6      	LDX CURROW
E63C 20 19 E7   	JSR CSRMIN+4	;$E719
E63F E4 C9      	CPX ICRROW
E641 D0 14      	BNE INSCR1	;$E657
E643 D0 12      	BNE INSCR1

E645 A5 CA      	LDA ICRCOL
E647 85 D3      	STA CSRIDX
E649 C5 C8      	CMP EOLPTR
E64B 90 0A      	BCC INSCR1
E64D B0 42      	BCS INSCR4A

;====================================================================
; INSCR - Input from screen/keyboard until <RET>
;
INSCR
E64F 98         	TYA
E650 48         	PHA
E651 8A         	TXA
E652 48         	PHA
E653 A5 D0      	LDA INSRC
E655 F0 91      	BEQ KEYLP1

INSCR1
E657 A4 D3      	LDY CSRIDX
E659 B1 D1      	LDA (LINPTR),Y

E65B .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea	;patch area??
E663 .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
E66B .db $ea, $ea, $ea, $ea, $ea, $ea, $ea

E672 85 D7      	STA LASTKY
E674 29 3F      	AND #%00111111	;$3F
E676 06 D7      	ASL LASTKY
E678 24 D7      	BIT LASTKY
E67A 10 02      	BPL INSCR2

E67C 09 80      	ORA #%10110000	;$B0

INSCR2
E67E 90 04      	BCC INSCR3

E680 A6 D4      	LDX CSRMOD
E682 D0 04      	BNE INSCR4

INSCR3
E684 70 02      	BVS INSCR4

E686 09 40      	ORA #%01000000	;$40

INSCR4
E688 E6 D3      	INC CSRIDX
E68A 20 BB E6   	JSR QUOTET
E68D C4 C8      	CPY EOLPTR
E68F D0 17      	BNE INSCR7

INSCR4A
E691 A9 00      	LDA #$00
E693 85 D0      	STA INSRC
E695 A9 0D      	LDA #$0D
E697 A6 99      	LDX INDEV
E699 E0 03      	CPX #$03
E69B F0 06      	BEQ INSCR5

E69D A6 9A      	LDX OUTDEV
E69F E0 03      	CPX #$03	;output to screen?
E6A1 F0 03      	BEQ INSCR6

INSCR5
E6A3 20 42 E7   	JSR OUTSCR

INSCR6
E6A6 A9 0D      	LDA #$0D

INSCR7
E6A8 85 D7      	STA LASTKY
E6AA 68         	PLA
E6AB AA         	TAX
E6AC 68         	PLA
E6AD A8         	TAY
E6AE A5 D7      	LDA LASTKY
E6B0 C9 DE      	CMP #$DE	;which key??
E6B2 D0 02      	BNE INSCREX

E6B4 A9 FF      	LDA #$FF	;load return code

INSCREX
E6B6 18         	CLC
E6B7 60         	RTS

;====================================================================
; QUOTET - Quotes test
;
QUOTET
E6BB C9 22      	CMP '"'	;#$22
E6BA D0 08      	BNE QUOTEX

E6BC A5 D4      	LDA CSRMOD
E6BE 49 01      	EOR #%00000001	;$01
E6C0 85 D4      	STA CSRMOD
E6C2 A9 22      	LDA '"'	;#$22

QUOTEX
E6C4 60         	RTS

;====================================================================
; CMD4 cmd- Setup screen print
;
CMD4
E6C5 09 40      	ORA #%01000000	;$40
E6C7 A6 C7      	LDX RVS
E6C9 F0 02      	BEQ CMD41	;$e6cd

E6CB 09 80      	ORA #%10110000	;$B0 or 80

CMD41
E6CD A6 D8      	LDX INSRTO
E6CF F0 02      	BEQ CMD42	;$e6d3

E6D1 C6 D8     	DEC INSRTO

CMD42
E6D3 AE 86 02   	LDX CLCODE
E6D6 20 A1 EA   	JSR PRNSCR
E6D9 20 EA E6   	JSR CSRPLS

CMD42A
E6DC 68        	PLA
E6DD A8         	TAY
E6DE A5 D8      	LDA INSRTO
E6E0 F0 02      	BEQ CMD4SK	;$E6E4

E6E2 46 D4      	LSR CSRMOD

CMD4SK
E6E4 68         	PLA
E6E5 AA         	TAX
E6E6 68         	PLA
E6E7 18         	CLC
E6E8 58         	CLI
E6E9 60         	RTS

;====================================================================
; CSLPLS - Advance cursor
;
CSRPLS
E6EA 20 FA E8   	JSR CKLNPL
E6ED E6 D3     	INC CSRIDX
E6EF A5 D5      	LDA LINLEN
E6F1 C5 D3      	CMP CSRIDX
E6F3 B0 37      	BCS CSREXIT	;$E72C

E6F5 C9 57      	CMP #$57
E6F7 F0 2A      	BEQ CSRDEC	;$E723

E6F9 AD 92 02   	LDA SCRLFL
E6FC F0 03      	BEQ CSRPSK	;$E701
E6FE 4C F0 E9   	JMP INSSLOP	;$E9F0

CSRPSK
E701 A6 D6      	LDX CURROW
E703 E0 17      	CPX #$17
E705 90 07      	BCC CSRSK2	;$E70E

E707 20 75 E9   	JSR SCRLSC
E70A C6 D6      	DEC CURROW
E70C A6 D6      	LDX CURROW

CSRSK2
E70E 16 D9      	ASL SLLTBL,X
E710 56 D9      	LSR SLLTBL,X
E712 4C 5B ED   	JMP GRTX2

;====================================================================
; CSRMIN - Retreat cursor ($E719??)
;
CSRMIN
E715 69 16      	ADC #$16	;add 22d (screen line length)
E717 85 D5      	STA LINLEN

CSRMLP
E719 B5 D9      	LDA SLLTBL,X
E71B 30 03      	BMI CSRMIN1	;$E720
E71D CA         	DEX
E71E D0 F9      	BNE CSRMLP	;$E719

CSRMIN1
E720 4C 7E EA   	JMP LINSTR

CSRDEC
E723 C6 D6      	DEC CURROW
E725 20 C3 E8   	JSR NEWLIN
E728 A9 00      	LDA #$00
E72A 85 D3      	STA CSRIDX

CSREXIT
E72C 60         	RTS

;====================================================================
; CSRUP - Move cursor up
;
CSRUP
E72D A6 D6      	LDX CURROW
E72F D0 06      	BNE CSRUP1	;$E737
E731 86 D3      	STX CSRIDX
E733 68         	PLA
E734 68         	PLA
E735 D0 A5      	BNE CMD42A	;$E6DC

CSRUP1
E737 CA         	DEX
E738 86 D6      	STX CURROW
E73A 20 87 E5   	JSR SCNPTR
E73D A4 D5      	LDY LINLEN
E73F 84 D3      	STY CSRIDX
E741 60         	RTS

;====================================================================
; OUTSCR - Output to screen
;
OUTSCR
E742 48         	PHA
E743 85 D7      	STA LASTKY
E745 8A         	TXA
E746 48         	PHA
E747 98         	TYA
E748 48         	PHA
E749 A9 00      	LDA #$00
E74B 85 D0      	STA INSRC
E74D A4 D3      	LDY CSRIDX
E74F A5 D7      	LDA LASTKY
E751 10 03      	BPL NOSHCH	;$E756
E753 4C 00 E8   	JMP SHCHRS
;
; Output unshifted characters
;
NOSHCH
E756 C9 0D      	CMP #$0D
E758 D0 03      	BNE NOTCR	;$E75D

E75A 4C D8 E8   	JMP CR

NOTCR
E75D C9 20      	CMP #' '	;$20
E75F 90 10     	 BCC CTRLCODE	;$E771

E761 C9 60      	CMP #$60	;last standard ASCII
E763 90 04      	BCC ALPHA	;$E769

E765 29 DF      	AND #%11011111	;$DF
E767 D0 02      	BNE ALPHA1	;$E76B

ALPHA
E769 29 3F      	AND #$3F

ALPHA1	
E76B 20 BB E6   	JSR QUOTET
E76E 4C C7 E6   	JMP CMD4+2	;$E6C7

CTRLCODE
E771 A6 D8      	LDX INSRTO
E773 F0 03      	BEQ NOINSERT	;$E778
E775 4C CB E6   	JMP CMD41-2	;$E6CB

NOINSERT
E778 C9 14      	CMP #$14	;{delete}
E77A D0 2E      	BNE NOTDEL	;$E7AA

E77C 98         	TYA
E77D D0 06      	BNE DEL	;$E785

E77F 20 2D E7   	JSR CSRUP	;$E72D
E782 4C 9F E7   	JMP NOSHCH1	;$E79F

DEL
E785 20 E8 E8   	JSR CKLNMI	;$E8E8
E788 88         	DEY
E789 84 D3      	STY CSRIDX
E78B 20 B2 EA   	JSR BLINK

NOSHLP1
E78E C8         	INY
E78F B1 D1      	LDA (LINPTR),Y
E791 88         	DEY
E792 91 D1      	STA (LINPTR),Y
E794 C8         	INY
E795 E1 F3      	LDA (COLRPT),Y
E797 88         	DEY
E798 91 F3      	STA (COLRPT),Y
E79A C8         	INY
E79B C4 D5      	CPY LINLEN
E79D D0 EF      	BNE NOSHLP1	;$E78E

NOSHCH1
E79F A9 20      	LDA #$20
E7A1 91 D1      	STA (LINPTR),Y
E7A3 AD 86 02  	LDA CLCODE
E7A6 91 F3      	STA (COLRPT),Y
E7A8 10 4D      	BPL $E7F7

NOTDEL
E7AA A6 D4      	LDX CSRMOD		
E7AC F0 03      	BEQ NOTDEL1	;$E7B1
E7AE 4C CE E6   	JMP CMD41-2	;$E6CB

NOTDEL1
E7B1 C9 12      	CMP #$12	;{RVS}
E7B3 D0 02      	BNE NOTRVS	;$E7B7

E7B5 85 C7      	STA RVS

NOTRVS
E7B7 C9 13      	CMP #$13	;{HOME}
E7B9 D0 03      	BNE NOTHOME	;$E7BE

E7BB 20 81 E5   	JSR HOME

NOTHOME
E7BE C9 1D      	CMP #$1D	;{RIGHT}
E7C0 D0 17      	BNE NOTRT	;$E7D9

E7C2 C8         	INY	;right
E7C3 20 FA E8   	JSR CKLNPL
E7C6 84 D3      	STY CSRIDX
E7C8 88         	DEY
E7C9 C4 D5      	CPY LINLEN
E7CB 90 09      	BCC CSRRTEX	;$E7D6

E7CD C6 D6      	DEC CURROW
E7CF 20 C3 E8   	JSR NEWLIN
E7D2 A0 00      	LDY #$00
E7D4 84 D3      	STY CSRIDX

CSRRTEX
E7D6 4C DC E6   	JMP CMD42A	;$E6DC

NOTRT	
E7D9 C9 11      	CMP #$11	;{DOWN}
E7DB D0 1D      	BNE NOTDOWN	;$E7FA

E7DD 18         	CLC	;down
E7DE 98         	TYA
E7DF 69 16      	ADC #$16
E7E1 A8         	TAY
E7E2 E6 D6      	INC CURROW
E7E4 C5 D5      	CMP LINLEN
E7E6 90 EC      	BCC CSRRTEX-2	;$E7D4
E7E8 F0 EA      	BEQ CSRRTEX-2	;$E7D4

E7EA C6 D6      	DEC CURROW

NOTRTLP
E7EC E9 16      	SBC #$16
E7EE 90 04      	BCC NOTRT1	;$E7F4

E7F0 85 D3      	STA CSRIDX
E7F2 D0 F8      	BNE NOTRTLP	;$E7EC

NOTRT1
E7F4 20 C3 E8   	JSR NEWLIN
E7F7 4C DC E6   	JMP CMD42A

NOTDOWN
E7FA 20 12 E9   	JSR STCLRC	;$E912
E7FD 4C 21 ED   	JMP GRTXTF	;$ED21
;
; Output shifted characters
;
SHCHRS
E800 .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
E808 .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
E810 .db $ea, $ea, $ea, $ea, $ea

E815 29 7F      	AND #%01111111	;$7F
E817 C9 7F      	CMP #%01111111	;$7F
E819 D0 02      	BNE $+2	;$E81D

E81B A9 5E      	LDA #$5E

E81D .db $ea, $ea, $ea, $ea, $ea, $ea

E823 C9 20      	CMP #$20	;{space}
E825 90 03      	BCC $+3	;$E82A
E827 4C C5 E6   	JMP CMD4	;$E6C5

E82A C9 0D      	CMP #$0D	;{return}
E82C D0 03      	BNE $+3	;$E831
E82E 4C D8 E8   	JMP CR

E831 A6 D4      	LDX CSRMOD
E833 D0 3F      	BNE SCHR2	;$E874

E835 C9 14      	CMP #$14	;{text}
E837 D0 37      	BNE SCHR1	;$E870

E839 A4 D5      	LDY LINLEN
E83B B1 D1      	LDA (LINPTR),Y
E83D C9 20      	CMP #$20
E83F D0 04      	BNE $+4	;$E845

E841 C4 D3      	CPY CSRIDX
E843 D0 07      	BNE $+7	;$E84C

E845 C0 57      	CPY #$57	
E847 F0 24      	BEQ SCHR1-3	;$E86D

E849 20 EE E9   	JSR INSSPC	;$E9EE
E84C A4 D5      	LDY LINLEN
E84E 20 B2 EA   	JSR BLINK

SHCHLOOP
E851 88         	DEY
E852 B1 D1      	LDA (LINPTR),Y
E854 C8         	INY
E855 91 D1      	STA (LINPTR),Y
E857 88         	DEY
E858 B1 F3      	LDA (COLRPT),Y
E85A C8         	INY
E85B 91 F3      	STA (COLRPT),Y
E85D 88         	DEY
E85E C4 D3      	CPY CSRIDX
E860 D0 EF      	BNE SCHCHLOOP	;$E851

E862 A9 20      	LDA #$20
E864 91 D1      	STA (LINPTR),Y
E866 AD 86 02   	LDA CLCODE
E869 91 F3      	STA (COLRPT),Y
E86B E6 D8      	INC INSRTO
E86D 4C DC E6   	JMP CMD42A

SCHR1
E870 A6 D8      	LDX INSRTO
E872 F0 05      	BEQ $+5	;$E879

SCHR2
E874 09 40      	ORA #%01000000	;$40
E876 4C CB E6   	JMP CMD4+6	;$E6CB

E879 C9 11      	CMP #$11	;{down}
E87B D0 16      	BNE SCHR3	;$E893

E87D A6 D6      	LDX CURROW
E87F F0 37      	BEQ SHCHEXIT-3	;$E8B8

E881 C6 D6      	DEC CURROW
E883 A5 D3      	LDA CSRIDX
E885 38         	SEC
E886 E9 16      	SBC #$16
E888 90 04      	BCC $+4	;$E88E

E88A 85 D3      	STA CSRIDX
E88C 10 2A      	BPL SHCHEXIT-3	;$E8B8
E88E 20 87 E5   	JSR SCNPTR
E891 D0 25      	BNE SHCHEXIT-3	;$E8B8

SCHR3
E893 C9 12      	CMP #$12	;{RVS}
E895 D0 04      	BNE $+4	;$E89B

E897 A9 00      	LDA #$00
E899 85 C7      	STA RVS
E89B C9 1D      	CMP #$1D	;{right}
E89D D0 12      	BNE SHCH4	;$E8B1

E89F 98         	TYA
E8A0 F0 09      	BEQ $+9	;$E8AB
E8A2 20 E8 E8   	JSR CKLNMI	;$E8E8
E8A5 88         	DEY
E8A6 84 D3      	STY CSRIDX
E8A8 4C DC E6   	JMP CMD42A

E8AB 20 2D E7   	JSR CSRUP	;$E72D
E8AE 4C DC E6   	JMP CMD42A

SHCH4
E8B1 C9 13      	CMP #$13	;{home}
E8B3 D0 06      	BNE SHCHEXIT	;$E8BB

E8B5 20 5F E5   	JSR CLRSCN	;$E55F
E8B8 4C DC E6   	JMP CMD42A

SHCHEXIT
E8BB 09 80      	ORA #%10000000	;$80
E8BD 20 12 E9   	JSR STCLRC	;$E912
E8C0 4C 30 ED   	JMP G1	;$ED30

;====================================================================
; NEWLIN - Goto next line
;
NEWLIN
E8C3 46 C9      	LSR ICRROW
E8C5 A6 D6      	LDX CURROW

NWLNLP
E8C7 E8         	INX
E8CB E0 17      	CPX #$17
E8CA D0 03      	BNE NEWLIN1	;$E8CF
E8CC 20 75 E9   	JSR SCRLSC

NEWLIN1
E8CF B5 D9      	LDA SLLTBL,X
E8D1 10 F4      	BPL NWLNLP	;$E8C7
E8D3 86 D6      	STX CURROW
E8D5 4C 87 E5   	JMP SCNPTR

;====================================================================
; CR - Output <RET>
;
CR
E8D8 A2 00      	LDX #$00
E8DA 86 D8      	STX INSRTO
E8DC 86 C7      	STX RVS
E8DE 86 D4      	STX CSRMOD
E8E0 86 D3      	STX CSRIDX
E8E2 20 C3 E8   	JSR NEWLIN
E8E5 4C DC E6   	JMP CMD42A	;$E6DC

;====================================================================
; CKLNMI - Check line decrement
;
CKLNMI
E8E8 A2 04      	LDX #$04
E8EA A9 00      	LDA #$00

CKLNLP
E8EC C5 D3      	CMP CSRIDX
E8EE F0 07      	BEQ CKLND1	;$E8F7
E8F0 18         	CLC
E8F1 69 16      	ADC #$16
E8F3 CA         	DEX
E8F4 D0 F6      	BNE CKLNLP	;$E8EC
E8F6 60         	RTS

CKLND1
E8F7 C6 D6      	DEC CURROW
E8F9 60         	RTS

;====================================================================
; CKLNPL - Check for line increment
;
CKLNPL
E8FA A2 04      	LDX #$04
E8FC A9 15      	LDA #$15

CKLNINL
E8FE C5 D3      	CMP CSRIDX
E900 F0 07      	BEQ CKLNIN	;$E909
E902 18         	CLC
E903 69 16      	ADC #$16
E905 CA         	DEX
E906 D0 F6      	BNE CKLNINL	;$E8FE
E908 60        	RTS

CKLNIN
E909 A6 D6      	LDX CURROW
E90B E0 17      	CPX #$17
E90D F0 02      	BEQ CKLNEX	;$E911
E90F E6 D6      	INC CURROW

CKNLEX
E911 60         	RTS

;====================================================================
; STCLRC - Set color code
;
STCLRC
E912 A2 07      	LDX #$07

STCLRL
E914 DD 21 E9   	CMP COLRTB,X
E917 F0 04      	BEQ SETCLR	;$E91D
E919 CA         	DEX
E91A 10 F8      	BPL STCLRL	;$E914
E91C 60         	RTS

SETCLR
E91D BE 86 02   	STX CLCODE
E920 60         	RTS

;  Table: Color code
COLRTB
E921 90 05 1C 9F 9C 1E 1F 9E


;  Table: ScreenCode <==> ASCII
XLATB1
E929 EF A1 DF A6 E1 B1 E2 B2
E931 E3 B3 E4 B4 E5 B5 E6 B6
E939 E7 B7 E8 B8 E9 B9 FA BA
E941 FB BB FC BC EC BD FE BE
E949 84 BF F7 C0 F8 DB F9 DD
E951 EA DE 5E E0 5B E1 5D E2
E959 40 B0 61 B1 78 DB 79 DD
E961 66 B6 77 C0 70 F0 71 F1
E969 72 F2 73 F3 74 F4 75 F5
E971 76 F6 7D FD

;====================================================================
; SCRLSC - Scroll screen Evaluation
;
SCRLSC
E975 A5 AC      	LDA SAL
E977 48	PHA
E978 A5 AD      	LDA SAL+1
E97A 48	PHA
E97B A5 AE      	LDA EAL
E97D 48	PHA
E97E A5 AF      	LDA EAL+1
E980 48         	PHA

SCLPUSH
E981 A2 FF      	LDX #$FF
E983 C6 D6      	DEC CURROW
E985 C6 C9      	DEC ICRROW
E987 C6 F2      	DEC SCROWM

SCRLP1
E989 E8         	INX
E98A 20 7E EA   	JSR LINSTR
E98D E0 16      	CPX #$16
E98F B0 0C      	BCS $+12	;$E99D

E991 BD FE ED   	LDA LBSCAD+1,X	;$EDFE,X
E994 85 AC      	STA SAL
E996 B5 DA      	LDA SLLTBL+1,X
E998 20 56 EA   	JSR MOVELN
E99B 30 EC      	BMI SCRLP1	;$E989

E99D 20 8D EA   	JSR CLRLIN
E9A0 A2 00      	LDX #$00

SCRLP2
E9A2 B5 D9      	LDA SLLTBL,X
E9A4 29 7F      	AND #%01111111	;$7F
E9A6 B4 DA      	LDY SLLTBL+1,X
E9AB 10 02      	BPL $+2	;E9AC

E9AA 09 80      	ORA #%10000000	;$B0 or 80
E9AC 95 D9      	STA SLLTBL,X
E9AE E8         	INX
E9AF E0 16      	CPX #$16
E9B1 D0 EF      	BNE SCRLP2	;$E9A2

E9B3 A5 EF      	LDA SLLTBL+32	;$EF
E9B5 09 80      	ORA #%10000000	;$B0 or 80
E9B7 85 EF      	STA SLLTBL+32	;$EF
E9B9 A5 D9      	LDA SLLTBL
E9BB 10 C4      	BPL SCLPUSH	;$E981

E9BD E6 D6      	INC CURROW
E9BF E6 F2      	INC SCROWM
E9C1 A9 FB      	LDA #$FB
E9C3 8D 20 91   	STA D2ORB
E9C6 AD 21 91   	LDA D2ORA
E9C9 C9 FE      	CMP #$FE
E9CB 08         	PHP
E9CC A9 F7      	LDA #$F7
E9CE 8D 20 91   	STA  D2ORB
E9D1 28         	PLP
E9D2 D0 0B      	BNE $+11	;$E9DF

E9D4 A0 00      	LDY #$00
E9D6 EA         	NOP
E9D7 CA         	DEX
E9D8 D0 FC      	BNE $-2	;E9D6

E9DA 88         	DEY
E9DB D0 F9      	BNE $-5	;E9D6 

E9DD 84 C6      	STY KEYCNT
E9DF A6 D6      	LDX CURROW 
E9E1 68         	PLA
E9E2 85 AF      	STA EAL+1
E9E4 68         	PLA
E9E5 85 AE      	STA EAL
E9E7 68         	PLA
E9E8 85 AD      	STA SAL+1
E9EA 68         	PLA
E9EB 85 AC      	STA SAL
E9ED 60         	RTS


;====================================================================
; INSSPC - Open a space on the screen
;
INSSPC
E9EE A6 D6      	LDX CURROW

INSSLOP
E9F0 E8         	INX
E9F1 B5 D9      	LDA SLLTBL,X
E9F3 10 FB      	BPL INSSLOP	; $E9F0

E9F5 86 F2      	STX SCROWM
E9F7 E0 16      	CPX #$16
E9F9 F0 0D      	BEQ INSSPC1	;$EA08
E9FB 90 0B      	BCC INSSPC1

E9FD 20 75 E9   	JSR SCRLSC
EA00 A6 F2      	LDX SCROWM
EA02 CA         	DEX
EA03 C6 D6      	DEC CURROW
EA05 4C 0E E7   	JMP CSRSK2	;$E70E

INSSPC1
EA08 A5 AC      	LDA SAL
EA0A 48         	PHA
EA0B A5 AD      	LDA SAL+1
EA0D 48         	PHA
EA0E A5 AE      	LDA EAL
EA10 48         	PHA
EA11 A5 AF      	LDA EAL+1
EA13 48         	PHA
EA14 A2 17      	LDX #$17

INSSLP2
EA16 CA         	DEX
EA17 20 7E EA   	JSR LINSTR
EA1A E4 F2      	CPX SCROWM
EA1C 90 0E      	BCC INSSPC2	;$EA2C
EA1E F0 0C      	BEQ INSSPC2	;$EA2C

EA20 BD FC ED   	LDA LBSCAD-1,X	;$EDFC
EA23 85 AC      	STA EAL
EA25 B5 D8      	LDA INSRTO,X
EA27 20 56 EA   	JSR MOVELN
EA2A 30 EA      	BMI INSSLP2	;$EA16

INSSPC2
EA2C 20 8D EA   	JSR CLRLIN
EA2F A2 15      	LDX #$15

INSSLP3
EA31 E4 F2      	CPX SCROWM
EA33 90 0F      	BCC INSEXIT	;$EA44

EA35 B5 DA      	LDA SLLTBL+1,X 
EA37 29 7F      	AND #%01111111	;$7F
EA39 B4 D9      	LDY SLLTBL,X
EA3B 10 02      	BPL INSSPC3	;$EA3F
EA3D 09 80      	ORA #%10000000	;$80

INSSPC3
EA3F 95 DA      	STA SLLTBL+1,X
EA41 CA         	DEX
EA42 D0 ED      	BNE INSSLP3	;$EA31

INSEXIT
EA44 A6 F2      	LDX SCROWM
EA46 20 0E E7   	JSR CSRSK2
EA49 68         	PLA
EA4A 85 AF      	STA EAL+1
EA4C 68         	PLA
EA4D 85 AE      	STA EAL
EA4F 68         	PLA
EA50 85 AD      	STA SAL+1
EA52 68         	PLA
EA53 85 AC      	STA SAL
EA55 60         	RTS

;====================================================================
; MOVELN - Move a screen line
;
MOVELN
EA56 29 03      	AND #%00000011	;$03
EA58 0D 88 02   	ORA HIPAGE
EA5B 85 AD      	STA SAL+1
EA5D 20 6E EA   	JSR COPYCL
EA60 A0 15      	LDY #$15

MOVLOOP
EA62 B1 AC      	LDA (SAL),Y
EA64 91 D1      	STA (LINPTR),Y
EA66 B1 AE      	LDA (EAL),Y
EA68 91 F3      	STA (COLRPT),Y
EA6A 88         	DEY
EA6B 10 F5      	BPL MOVLOOP	;$EA62
EA6D 60         	RTS

;====================================================================
; COPYCL - Synchronize color transfer
;
COPYCL
EA6E 20 B2 EA   	JSR BLINK
EA71 A5 AC      	LDA SAL
EA73 85 AE      	STA EAL
EA75 A5 AD      	LDA SAL+1
EA77 29 03      	AND #%00000011	;$03
EA79 09 94      	ORA #%10010100	;$94
EA7B 85 AF      	STA EAL+1
EA7D 60         	RTS

;====================================================================
; LINSTR - Set start of line
;
LINSTR
EA7E BD FD ED   	LDA LBSCAD,X	;$EDFD
EA81 85 D1      	STA LINPTR
EA83 B5 D9      	LDA SLLTBL,X
EA85 29 03      	AND #%00000011	;$03
EA87 0D 88 02   	ORA HIPAGE
EA8A 85 D2      	STA LINPTR+1
EA8C 60         	RTS

;====================================================================
; CLRLIN - Clear screen line
;
CLRLIN
EA8D A0 15      	LDY #$15
EA8F 20 7E EA   	JSR LINSTR
EA92 20 B2 EA   	JSR BLINK

CLEARLP
EA95 A9 20      	LDA #' '	;$20
EA97 91 D1      	STA (LINPTR),Y
EA99 A9 01      	LDA #$01
EA9B 91 F3      	STA (COLRPT),Y
EA9D 88         	DEY
EA9E 10 F5      	BPL CLEARLP	;$EA95
EAA0 60         	RTS

;====================================================================
; PRNSCR - Print to screen
;
PRNSCR
EAA1 A8         	TAY
EAA2 A9 02      	LDA #$02
EAA4 85 CD      	STA BLNCT
EAA6 20 B2 EA   	JSR BLINK
EAA9 98         	TYA

PRNSCR1
EAAA A4 D3      	LDY CSRIDX
EAAC 91 D1      	STA (LINPTR),Y
EAAE 8A         	TXA
EAAF 91 F3      	STA (COLRPT),Y
EAB1 60         	RTS

;====================================================================
; BLINK - Blink cursor
;
BLINK
EAB2 A5 D1      	LDA LINPTR
EAB4 85 F3      	STA COLRPT
EAB6 A5 D2      	LDA LINPTR+1
EAB8 29 03      	AND #%00000011	;$03
EABA 09 94      	ORA #%10010100	;$94
EABC 85 F4      	STA COLRPT+1
EABE 60         	RTS

;====================================================================
; IRQVEC - IRQ Vector
;
IRQVEC
EABF 	JSR IUDTIM	;update clock F734
EAC2 A5 CC      	LDA BLNSW
EAC4 D0 29      	BNE IRQVEC2	;$EAEF

EAC6 C6 CD      	DEC BLNCT	;decrement blink count
EAC8 D0 25      	BNE IRQVEC2	;$EAEF

EACA A9 14      	LDA #$14
EACC 85 CD      	STA BLNCT
EACE A4 D3      	LDY CSRIDX
EAD0 46 CF      	LSR BLNON
EAD2 AE 87 02   	LDX CSRCLR
EAD5 B1 D1      	LDA (LINPTR),Y
EAD7 B0 11      	BCS IRQVEC1	;$EAEA

EAD9 E6 CF      	INC BLNON
EADB 85 CE      	STA GDBLN
EADD 20 B2 EA   	JSR BLINK
EAE0 B1 F3      	LDA (COLRPT),Y
EAE2 8D 87 02   	STA CSRCLR
EAE5 AE 86 02   	LDX CLCODE
EAE8 A5 CE      	LDA GDBLN

IRQVEC1
EAEA 49 60      	EOR #%11000000	;$B0 or 60
EAEC 20 AA EA   	JSR PRNSCR1

IRQVEC2
EAEF AD 1F 91   	LDA D1ORAH
EAF2 29 40      	AND #%01000000	;$40
EAF4 F0 0B      	BEQ IRQVEC3	;$EB01

EAF6 A0 00      	LDY #$00
EAF8 84 C0      	STY CAS1
EAFA AD 1C 91   	LDA D1PCR
EAFD 09 02      	ORA #%00000010	;$02
EAFF D0 09      	BNE IRQVEC4	;$EB0A

IRQVEC3
EB01 A5 C0      	LDA CAS1
EB03 D0 0D      	BNE IRQVEC5	;$EB12

EB05 AD 1C 91   	LDA D1PCR
EB08 29 FD      	AND #%11111101	;$FD

IRQVEC4
EB0A 2C 1E 91   	BIT D1IER
EB0D 70 03      	BVS IRQVEC5	;$EB12

EB0F 8D 1C 91   	STA D1PCR

IRQVEC5
EB12 20 1E EB   	JSR ISCNKY	;Eb1E
EB15 2C 24 91   	BIT D2TM1L	;9124
EB18 68         	PLA
EB19 A8         	TAY
EB1A 68         	PLA
EB1B AA         	TAX
EB1C 68         	PLA
EB1D 40         	RTI

;====================================================================
; ISCNKY - Scan keyboard
;
ISCNKY
EB1E A9 00      	LDA #$00
EB20 8D 8D 02   	STA SHFTFL
EB23 A0 40      	LDY #$40
EB25 84 CB      	STY KEYDN
EB27 8D 20 91   	STA D2ORB
EB2A AE 21 91   	LDX D2ORA
EB2D E0 FF      	CPX #$FF
EB2F F0 5E      	BEQ PROCK1A	;$EB8F

EB31 A9 FE      	LDA #$FE
EB33 8D 20 91   	STA D2ORB
EB36 A0 00      	LDY #$00
EB38 A9 5E      	LDA #$5E
EB3A 85 F5      	STA KEYTAB
EB3C A9 EC      	LDA #$EC
EB3E 85 F6      	STA KEYTAB+1

ISCKLP1
EB40 A2 08      	LDX #$0B
EB42 AD 21 91   	LDA D2ORA
EB45 CD 21 91   	CMP D2ORA
EB48 D0 F6      	BNE ISCKLP1	;$EB40

ISCKLP2
EB4A 4A         	LSR
EB4B B0 16      	BCS ISCNK1+3	;$EB63

EB4D 48         	PHA
EB4E B1 F5      	LDA (KEYTAB),Y
EB50 C9 05      	CMP #$05
EB52 B0 0C      	BCS ISCNK1	;$EB60

EB54 C9 03      	CMP #$03
EB56 F0 08      	BEQ ISCNK1	;$EB60

EB58 0D 8D 02   	ORA SHFTFL
EB5B 8D 8D 02   	STA SHFTFL
EB5E 10 02      	BPL ISCNK1+2	;$EB62

ISCNK1
EB60 84 CB      	STY KEYDN
EB62 68         	PLA
EB63 C8         	INY
EB64 C0 41      	CPY #$41
EB66 B0 09      	BCS ISCNEXIT	;$EB71

EB68 CA         	DEX
EB69 D0 DF      	BNE ISCKLP2	;$EB4A

EB6B 38         	SEC
EB6C 2E 20 91   	ROL D2ORB
EB6F D0 CF      	BNE ISCKLP1	;$EB40

ISCNEXIT
EB71 6C 8F 02   	JMP (FCEVAL)
;
; Process key image 
;
PROCKY
EB74 A4 CB      	LDY KEYDN
EB76 B1 F5      	LDA (KEYTAB),Y
EB78 AA         	TAX
EB79 C4 C5      	CPY CURKEY
EB7B F0 07      	BEQ PROCK1	;$EB84

EB7D A0 10      	LDY #$10
EB7F 8C 8C 02   	STY KRPTDL
EB82 D0 36      	BNE PROCK4	;$EBBA

PROCK1
EB84 29 7F      	AND #%01111111	;$7F
EB86 2C 8A 02   	BIT KEYRPT
EB89 30 16      	BMI PROCK2	;$EBA1
EB8B 70 49      	BVS PROCK5	;$EBD6

EB8D C9 7F      	CMP #$7F

PROCK1A
EB8F F0 29      	BEQ PROCK4	;$EBBA

EB91 C9 14      	CMP #$14
EB93 F0 0C      	BEQ PROCK2	;$EBA1

EB95 C9 20      	CMP #$20
EB97 F0 08      	BEQ PROCK2	;$EBA1

EB99 C9 1D      	CMP #$1D
EB9B F0 04      	BEQ PROCK2	;$EBA1

EB9D C9 11      	CMP #$11
EB9F D0 35      	BNE PROCK5	;$EBD6

PROCK2
EBA1 AC 8C 02   	LDY KRPTDL
EBA4 F0 05      	BEQ PROCK3	;$EBAB

EBA6 CE 8C 02   	DEC KRPTDL
EBA9 D0 2B      	BNE PROCK5	;$EBD6

PROCK3
EBAB CE 8E 02   	DEC LSSHFT
EBAE D0 26      	BNE PROCK5	;$EBD6

EBB0 A0 04      	LDY #$04
EBB2 8C 8B 02   	STY KRPTSP
EBB5 A4 C6      	LDY KEYCNT
EBB7 88         	DEY
EBB8 10 1C     	BPL PROCK5	;$EBD6

PROCK4
EBBA A4 CB      	LDY KEYDN
EBBC 84 C5      	STY CURKEY
EBBE AC 8D 02   	LDY SHFTFL
EBC1 8C 8E 02   	STY LSSHFT
EBC4 E0 FF      	CPX #$FF
EBC6 F0 0E      	BEQ PROCK5	;$EBD6

EBC8 8A         	TXA
EBC9 A6 C6      	LDX KEYCNT
EBCB EC 89 02   	CPX KBMAXL
EBCE B0 06      	BCS PROCK5	;$EBD6

EBD0 9D 77 02   	STA KBUFFR,X
EBD3 E8         	INX
EBD4 86 C6      	STX KEYCNT

PROCK5
EBD6 A9 F7      	LDA #$F7
EBD8 8D 20 91   	STA D2ORB
EBDB 60         	RTS


;
; Unknown function (no apparent access)
;
EBDC AD 8D 02   	LDA SHFTFL
EBDF C9 03      	CMP #$03
EBE1 D0 2C      	BNE PROCK6	;$EC0F

EBE3 CD 8E 02   	CMP LSSHFT
EBE6 F0 EE      	BEQ PROCK5	;$EBD6

EBE8 AD 91 02   	LDA SHMODE
EBEB 30 56      	BMI PROCKEX	;$EC43

EBED .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
EBF5 .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
EBFD .db $ea, $ea, $ea

EC00 AD 05 90   	LDA VRSTRT
EC03 49 02      	EOR #$02
EC05 8D 05 90   	STA VRSTRT

EC08 .db $ea, $ea, $ea, $ea

PROCK6
EC0C 4C 43 EC   	JMP PROCKEX	;$EC43
EC0F 0A         	ASL
EC10 C9 08      	CMP #$0B
EC12 90 04      	BCC $+4	;$EC1B
EC14 A9 06      	LDA #$06

EC16 .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
EC1E .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
EC26 .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
EC2E .db $ea, $ea, $ea, $ea, $ea, $ea, $ea, $ea
EC36 .db $ea, $ea

EC38 AA         	TAX
EC39 BD 46 EC   	LDA KDECOD,X
EC3C 85 F5      	STA KEYTAB
EC3E BD 47 EC   	LDA KDECOD+1,X
EC41 85 F6      	STA KEYTAB+1

PROCKEX
EC43 4C 74 EB   	JMP PROCKY

;====================================================================
; KDECOD - Pointers to keyboard decode tables
;
KDECOD
EC46 .dw KDECD1		;$5E, $EC Unshifted
EC48 .dw KDECD2		;$9F, $EC Shifted
EC4A .dw KDECD3		;$E0, $EC Commodore
EC4C .dw KDECD5		;$A3, $ED Control
EC4E .dw KDECD1		;$EC5E Unshifted
EC50 .dw KDECD2		;$EC9F Shifted
EC52 .dw KDECD4		;$69, $ED Decode
EC54 .dw KDECD5		;$EDA3 Control
EC56 .dw GRTXTF		;$21, $ED Graphics/text control
EC58 .dw KDECD4		;$ED69 Decode
EC5A .dw KDECD4		;$ED69 Decode
EC5C .dw KDECD5		;$EDA3 Control
;
;Unshifted
;
KDECD1
EC5E 31 33 35 37 39 2B
EC64 5C 14 5F 57 52 59 49 50
EC6C 2A 0D 04 41 44 47 4A 4C
EC74 3B 1D 03 01 58 56 4E 2C
EC7C 2F 11 20 5A 43 42 4D 2E
EC84 01 85 02 53 46 4B 4B 3A
EC8C 3D 86 51 45 54 55 4F 40
EC94 5E 87 32 34 36 38 30 2D
EC9C 13 88 FF
;
;shifted
;
KDECD2
EC9F 21 23 25 27 29
ECA4 DB A9 94 5F D7 D2 D9 C9
ECAC D0 C0 8D 04 C1 C4 C7 CA
ECB4 CC 5D 9D 83 01 D8 D6 CE
ECBC 3C 3F 91 A0 DA C3 C2 CD
ECC4 3E 01 89 02 D3 C6 C8 CB
ECCC 5B 3D 8A D1 C5 D4 D5 CF
ECD4 BA DE 8B 22 24 26 28 30
ECDC DD 93 8C FF 
;
;Commodore
;
KDECD3
ECE0 21 23 25 27
ECE4 29 A6 A8 94 5F B3 B2 B7
ECEC A2 AF DF 8D 04 B0 AC A5
ECF4 B5 B6 5D 9D 83 01 BD BE
ECFC AA 3C 3F 91 A0 AD BC BF
ED04 A7 3E 01 89 02 AE BB B4
ED0C A1 5B 3D 8A AB B1 A3 B8
ED14 B9 A4 DE 8B 22 24 26 28
ED1C 30 DC 93 8C FF
;
;Graphics/tect control code
;@$ed21
GRTXTF
	cmp #$0e
	bne $+9	;G1	;+09

	lda #$02
	ora VRSTRT
	sta VRSTRT
	jmp CMD42A

G1		;$ED30
	cmp #$be
	bne G2

	lda #$fd
	and VRSTRT
	sta VRSTRT
	jmp CMD42A

G2		;$ED3F
	cmp #$08
	bne G3
	lda #$80
	ora SHMODE
	sta SHMODE
	bmi $-16	;$-ef

G3		;$ED4D
	cmp #$09
	bne $+235	;EE3D		;$+eb

	lda #$7f
	and SHMODE
	sta SHMODE
	bpl $+225	;ed6b		;$+e1

	inx
	lda SLLTBL,x
	ora #$80
	sta SLLTBL,x
	dex
	lda LINLEN
	clc
	jmp CSRMIN	;$e715

;ED21 C9 0E D0
;ED24 0B A9 02 0D 05 90 8D 05
;ED2C 90 4C DC E6 C9 BE D0 0B
;ED34 A9 FD 2D 05 90 8D 05 90
;ED3C 4C DC E6 C9 08 D0 0A A9
;ED44 80 0D 91 02 8D 91 02 30
;ED4C EF C9 09 D0 EB A9 7F 2D
;ED54 91 02 8D 91 02 10 E1 E8
;ED5C B5 D9 09 80 95 D9 CA A5
;ED64 D5 18 4C 15 E7 
;
;Keyboard decoding table - Shifted
;
KDECD4
ED69 FF FF FF
ED6C FF FF FF FF FF FF 04 FF
ED74 FF FF FF FF E2 9D 83 01
ED7C FF FF FF FF FF 91 A0 FF
ED84 FF FF FF EE 01 89 02 FF
ED8C FF FF FF E1 FD 8A FF FF
ED94 FF FF FF B0 E0 BE F2 F4
ED9C F6 FF F0 ED 93 8C FF 
;
;Keyboard decoding table - control
;
KDECD5
EDA3 90
EDA4 1C 9C 1F 12 FF FF FF 06
EDAC FF 12 FF FF FF FF FF FF
EDB4 FF FF FF FF FF FF FF FF
EDBC FF FF FF FF FF FF FF FF
EDC4 FF FF FF FF FF FF FF FF
EDCC FF FF FF FF FF FF FF FF
EDD4 FF FF FF FF FF FF FF FF
EDDC FF FF 05 9F 1E 9E 92 FF
;
;VIC chip setup table
;
VICSUP
EDE4 .db $05, $19, $16, $2E, $00, $C0, $00, $00
EDEC .db $00, $00, $00, $00, $00, $00, $00, $1B
;
;Shift-run equivalent
;
RUNSHF
EDF4 .db $4C, $4F, $41, $44, $0D, $52, $55, $4E
EDFC .db $0D 
;
;Low-byte screen address
;
LBSCAD
EDFD .db $00, $16, $2C, $42, $58, $6E, $84
EE04 .db $9A, $B0, $C6, $DC, $F2, $08, $1E, $34
EE0C .db $4A, $60, $76, $8C, $A2, $BB, $CE, $E4


;====================================================================
; ITALK - Send TALK command on serial bus (internal)
;
ITALK
EE14 09 40      	ORA #%01000000	;$40

;====================================================================
; ILISTN - Send LISTEN command on serial bus (internal)
;
ILISTN
EE16 09 20      	ORA #%00100000	;$20
EE19 20 60 F1   	JSR SBIDLE	;test IER for bus idle
EE1C 48         	PHA
EE1D 24 94      	BIT C3PO
EE1F 10 0A      	BPL LISN1	;$EE2B

EE21 38         	SEC
EE22 66 A3      	ROR SBITCF
EE24 20 49 EE   	JSR OTDSBU
EE27 46 94      	LSR C3PO
EE29 46 A3      	LSR SBITCF

LISN1
EE2B 68         	PLA
EE2C 85 95      	STA BSOUT
EE2E 20 A0 E4   	JSR SOUT1	;send DATA=1
EE31 C9 3F      	CMP #%00111111	;$3F
EE33 D0 03      	BNE LISN2	;$EE38

EE35 20 84 EF   	JSR SCLK1	;tsend SCLK=1

LISN2
EE38 AD 1F 91   	LDA D1ORAH
EE3B 09 80      	ORA #%10110000	;$B0
EE3D 8D 1F 91   	STA D1ORAH

ILISTEX
EE40 20 8D EF   	JSR SCLK0	;send SCLK=0
EE43 20 A0 E4   	JSR SOUT1	;send DATA=1
EE46 20 96 EF   	JSR DELAY	;wait


;====================================================================
; OTDSBU- Send data on serial bus
;
OTDSBU
EE49 78         	SEI
EE4A 20 A0 E4   	JSR SOUT1
EE4D 20 B2 E4   	JSR SDCLK
EE50 4A         	LSR
EE51 B0 61      	BCS FLGERR

EE53 20 84 EF   	JSR SCLK1
EE56 24 A3      	BIT SBITCF
EE58 10 0C      	BPL OTDLP3	;$EE66

OTDLP1
EE5A 20 B2 E4   	JSR SDCLK
EE5D 4A         	LSR
EE5E 90 FA      	BCC OTDLP1	;$EE5A

OTDLP2
EE60 20 B2 E4   	JSR SDCLK
EE63 4A         	LSR
EE64 B0 FA      	BCS OTDLP2	;$EE60

OTDLP3
EE66 20 B2 E4   	JSR SDCLK
EE69 4A         	LSR
EE6A 90 FA      	BCC OTDLP3	;$EE66

EE6C 20 8D EF   	JSR SCLK0
EE6F A9 08      	LDA #$08
EE71 85 A5      	STA CNTDN

OTDLP4
EE73 AD 1F 91   	LDA D1ORAH
EE76 CD 1F 91   	CMP D1ORAH
EE79 D0 F8      	BNE OTDLP4	;$EE73

EE7B 4A         	LSR
EE7C 4A         	LSR
EE7D 90 38      	BCC FLGER03	;$EEB7

EE7F 66 95      	ROR BSOUT
EE81 B0 05      	BCS OTDSB1	;$EE8B

EE83 20 A9 E4   	JSR SOUT0
EE86 D0 03      	BNE OTDSB1	;$EE8B

EE88 20 A0  E4  	JSR SOUT1

OTDSB1
EE8B 20 84  EF  	JSR SCLK1

EE8E .db $EA, $EA, $EA, $EA

EE92 AD 2C 91   	LDA D2PCR
EE95 29 DF      	AND #%11011111	;$DF
EE97 09 02      	ORA #%00000010	;$02
EE99 8D 2C 91   	STA D2PCR
EE9C C6 A5      	DEC CNTDN
EE9E D0 D3      	BNE OTDLP4	;$EE73

EEA0 A9 04      	LDA #$04
EEA2 8D 29 91   	STA D2TM2H

OTDLP5
EEA5 AD 2D 91   	LDA D2IFR
EEA8 29 20      	AND #%00100000	;$20
EEAA D0 0B      	BNE FLGER03	;$EEB7

EEAC 20 B2 E4   	JSR SDCLK
EEAF 4A         	LSR
EEB0 B0 F3      	BCS OTDLP5	;$EEA5
EEB2 58         	CLI
EEB3 60         	RTS

;====================================================================
; FLGERR - Flag errors
;
FLGERR
EEB4 A9 80      	LDA #$80	; Error $80 - device not present
EEB6 2C	.db $2C

FLGER03
EEB7 A9 03   	LDA #$03	; Error $03 - write timeout
EEB9 20 6A FE   	JSR ISETMS1	;$FE6A External entry into ISETMS
EEBC 58         	CLI
EEBD 18         	CLC
EEBE 90 49      	BCC IUNLSN+5	;$EF09


;====================================================================
; ISECND - Send LISTEN secondary address (internal)
;
ISECND
EEC0 85 95      	STA BSOUT
EEC2 20 40 EE   	JSR ILISTEX	;$EE40 external entry into ILISTN
		;CLK=0, DATA=1, pause
;
; CLRATN - Clear the ATN line
;
CLRATN
EEC5 AD 1F 91   	LDA D1ORAH	; release ATN
EEC8 29 7F      	AND #%01111111	;$7F
EECA 8D 1F 91   	STA D1ORAH
EECD 60         	RTS

;====================================================================
; ITKSA - Sent TALK secondary address (internal)
;
ITKSA
EECE 65 95      	STA BSOUT     
EED0 20 40 EE   	JSR ILISTEX	;$EE40 external entry into ILISTN
		;CLK=0, DATA=1, pause
;
; Wait for CLK
;
CLKWAIT
EED3 78         	SEI
EED4 20 A9 E4   	JSR SOUT0
EED7 20 C5 EE   	JSR CLRATN
EEDA 20 84 EF   	JSR SCLK1

CLKWAIT
EEDD 20 B2 E4   	JSR SDCLK
EEE0 B0 FB      	BCS CLKWAIT	;$EEDD
EEE2 58         	CLI
EEE3 60         	RTS


;====================================================================
; ICIOUT - Send serial deferred (internal)
;
ICIOUT
EEE4 24 94      	BIT C3PO       
EEE6 30 05      	BMI ICIOUT1	;$EEED
EEE8 38         	SEC
EEE9 66 94      	ROR C3PO
EEEB D0 05      	BNE ICIOUT2	;$EEF2

ICIOUT1
EEED 48         	PHA
EEEE 20 49 EE   	JSR OTDSBU
EEF1 68         	PLA

ICIOUT2
EEF2 85 95      	STA BSOUT
EEF4 18         	CLC
EEF5 60         	RTS


;====================================================================
; IUNTLK - Send UNTALK on serial bus (internal)
;
IUNTLK
EEF6 20 8D EF   	JSR SCLK0
EEF7 AD 1F 91   	LDA D1ORAH
EEF9 AD 1F 91   	LDA D1ORAH
EEFC 09 80      	ORA #%10110000	;$B0
EEFE 8D 1F 91   	STA D1ORAH

EF01 A9 5F      	LDA #$5F	;entry 1
EF03 2C 	.db $2C	;really BIT $3FA9 to skip EF04

;====================================================================
; IUNLSN - Send UNLISTEN on serial bus (internal)
;
IUNLSN
EF04 A9 3F      	LDA #$3F	;entry 2
EF06 20 1C EE   	JSR ILISTN+5	;$EE1C skip serial idle test
EF09 20 C5 EE   	JSR CLRATN
EF0C 8A         	TXA
EF0D A2 0B      	LDX #$0B

IUNLP1
EF0F CA         	DEX
EF10 D0 FD      	BNE IUNLP1	;$EF0F
EF12 AA         	TAX
EF13 20 84 EF   	JSR SCLK1
EF16 4C A0 E4   	JMP SOUT1

;====================================================================
; IACPTR - Receive from serial bus (internal)
;
IACPTR
EF19 78         	SEI           
EF1A A9 00      	LDA #$00
EF1C 85 A5      	STA CNTDN
EF1E 20 84 EF   	JSR SCLK1

IACPLP1
EF21 20 B2 E4   	JSR SDCLK
EF24 90 FB      	BCC IACPLP1	;$EF21

EF26 20 A0 E4   	JSR SOUT1

IACPTR1
EF29 A9 01      	LDA #$01
EF2B 8D 29 91   	STA D2TM2H

IACPLP2
EF2E AD 2D 91   	LDA D2IFR
EF31 29 20      	AND #%00100000	;$20
EF33 D0 07      	BNE IACPTR2	;$EF3C

EF35 20 B2 E4   	JSR SDCLK
EF38 B0 F4      	BCS IACPLP2	;$EF2E
EF3A 90 18      	BCC IACPTR3A	;$EF54

IACPTR2
EF3C A5 A5      	LDA CNTDN
EF3E F0 05      	BEQ IACPTR3	;$EF45

EF40 A9 02      	LDA #$02	;set eerror code to 2
EF42 4C B9 EE   	JMP FLGER03+2	;$EEB9 

IACPTR3
EF45 20 A9 E4   	JSR SOUT0
EF48 20 0C EF   	JSR IUNLSN+8	;$EF0C
EF4B A9 40      	LDA #$40
EF4D 20 6A FE   	JSR ISETMS+4	;$FE6A
EF50 E6 A5      	INC CNTDN
EF52 D0 D5      	BNE IACPTR1	;$EF29

IACPTR3A
EF54 A9 08      	LDA #$0B

IACPLP3
EF56 85 A5      	STA CNTDN

IACPLP4
EF58 AD 1F 91   	LDA D1ORAH
EF5B CD 1F 91   	CMP D1ORAH
EF5E D0 F8      	BNE IACPLP3	;$EF56

EF60 4A         	LSR
EF61 90 F5      	BCC IACPLP4	;$EF58

EF63 4A         	LSR
EF64 66 A4      	ROR CYCLE

IACPLP5
EF66 AD 1F 91   	LDA D1ORAH
EF69 CD 1F 91   	CMP D1ORAH
EF6C D0 F8      	BNE IACPLP5	;$EF66

EF6E 4A         	LSR
EF6F B0 F5      	BCS IACPLP5	;$EF66

EF71 C6 A5      	DEC CNTDN
EF73 D0 E3      	BNE IACPLP4	;$EF58

EF75 20 A9 E4   	JSR SOUT0
EF78 A5 90      	LDA CSTAT
EF7A F0 03      	BEQ IACPEX	;$EF7F

EF7C 20 0C EF   	JSR IUNLSN+8

IACPEX
EF7F A5 A4      	LDA CYCLE
EF81 58         	CLI
EF82 18         	CLC
EF83 60         	RTS


;====================================================================
; SCLK1 - Set Serial CLK "1" (inverted logic)
;
SCLK1
EF84 AD 2C 91   	LDA D2PCR
EF87 29 FD      	AND #%11111101	;$FD
EF89 8D 2C 91   	STA D2PCR
EF8C 60         	RTS


;====================================================================
; SCLK0 - Set Serial CLK "0"
;
SCLK0
EF8D AD 2C 91   	LDA D2PCR
EF90 09 02      	ORA #%00000010	;$02
EF92 8D 2C 91   	STA D2PCR
EF95 60         	RTS

;====================================================================
; DELAY - Delay 1ms
;
DELAY
EF96 A9 04      	LDA #$04
EF98 8D 29 91   	STA D2TM2H

DLYLOOP
EF9B AD 2D 91   	LDA D2IFR
EF9E 29 20      	AND #%00100000	;$20
EFA0 F0 F9      	BEQ DLYLOOP	;$EF9B
EFA2 60         	RTS


;====================================================================
; SSEND - RS-232 Send
;
SSEND
EFA3 A5 B4      	LDA BITTS
EFA5 F0 47      	BEQ SSNDN
EFA7 30 3F      	BMI SSEND1	;$EFE8

EFA9 46 B6      	LSR RODATA
EFAB A2 00      	LDX #$00
EFAD 90 01      	BCC SSEND2	;$EFB0

EFAF CA         	DEX

SSEND2
EFB0 8A         	TXA
EFB1 45 BD      	EOR ROPRTY
EFB3 85 BD      	STA ROPRTY
EFB5 C6 B4      	DEC BITTS
EFB7 F0 06      	BEQ SSEND3	;$EFBF

SSEND2A
EFB9 8A         	TXA
EFBA 29 20      	AND #%00100000	;$20
EFBC 85 B5      	STA NXTBIT
EFBE 60         	RTS

SSEND3
EFBF A9 20      	LDA #$20
EFC1 2C 94 02   	BIT M51CDR
EFC4 F0 14      	BEQ SSEND5	;$EFDA
EFC6 30 1C      	BMI SSEND7	;$EFE4
EFC8 70 14      	BVS SSEND6	;$EFDE

EFCA A5 BD      	LDA ROPRTY
EFCC D0 01      	BNE SSEND4A	;$EFCF

SSEND4
EFCE CA         	DEX

SSEND4A
EFCF C6 B4      	DEC BITTS
EFD1 AD 93 02   	LDA M51CTR
EFD4 10 E3      	BPL SSEND2A	;$EFB9

EFD6 C6 B4      	DEC BITTS
EFD8 D0 DF      	BNE SSEND2A	;$EFB9

SSEND5
EFDA E6 B4      	INC BITTS
EFDC D0 F0      	BNE SSEND4	;$EFCE

SSEND6
EFDE A5 BD      	LDA ROPRTY
EFE0 F0 ED      	BEQ SSEND4A	;$EFCF
EFE2 D0 EA      	BNE SSEND4	;$EFCE

SSEND7
EFE4 70 E9      	BVS SSEND4A	;$EFCF
EFE6 50 E6      	BVC SSEND4	;$EFCE

SSEND1
EFE8 E6 B4      	INC BITTS
EFEA A2 FF      	LDX #$FF
EFEC D0 CB      	BNE SSEND2A	;$EFB9


;====================================================================
; SSNDN - Send new RS-232 byte
;
SSNDN
EFEE AD 94 02  	LDA M51CDR
EFF1 4A         	LSR
EFF2 90 07      	BCC SSNDN1	;$EFFB

EFF4 2C 20 91   	BIT D2ORB
EFF7 10 1D      	BPL DSRERR
EFF9 50 1E      	BVC CTSERR

SSNDN1
EFFB A9 00      	LDA #$00
EFFD 85 BD      	STA ROPRTY
EFFF 85 B5      	STA NXTBIT
F001 AE 98 02   	LDX BITNUM
F004 86 B4      	STX BITTS
F006 AC 9D 02   	LDY RODBS
F009 CC 9E 02   	CPY RODBE
F00C F0 13      	BEQ DISTIM

F00E B1 F9      	LDA (ROBUF),Y
F010 85 B6      	STA RODATA
F012 EE 9D 02   	INC RODBS
F015 60         	RTS

;====================================================================
; DSRERR - "No DSR"/"CTS" errors
;
DSRERR
F016 A9 40	LDA #$40	; no DSR
F018 2C   	.db $2C	;bit $10a9
;
; CTSERR - CTS Error
;
CTSERR
F019 A9 10	LDA #$10	; no CTS
F01B 0D 97 02   	ORA RSSTAT
F01E 8D 97 02   	STA RSSTAT
;
; DISTIM - Disable timer
;
DISTIM
F021 A9 40      	LDA #$40	; disable timer
F023 8D 1E 91   	STA D1IER
F026 60         	RTS


;====================================================================
; BITCNT - Compute bit count
;
BITCNT
F027 A2 09     	LDX #$09
F029 A9 20      	LDA #$20
F02B 2C 93 02   	BIT M51CTR
F02E F0 01      	BEQ $+1	;$F031

F030 CA         	DEX
F031 50 02      	BVC BITEXIT	;$F035
F033 CA         	DEX
F034 CA         	DEX

BITEXIT
F035 60         	RTS


;====================================================================
; SERRX - RS-232 Receive
;
SERRX
F036 A6 A9      	LDX RINONE
F038 D0 2E      	BNE PROCSB

F03A C6 A8      	DEC TPRWRE
F03C F0 31      	BEQ PROCSB1	;$F06F
F03E 30 0D      	BMI SERRX1	;$F04D

F040 A5 A7      	LDA INBIT
F042 45 AB      	EOR RIPRTY
F044 85 AB      	STA RIPRTY
F046 46 A7      	LSR INBIT
F048 66 AA      	ROR RIDATA

SERRXEX
F04A 60         	RTS

F04B C6 A8      	DEC TPRWRE

SERRX1
F04D A5 A7      	LDA INBIT
F04F F0 62      	BEQ PRSBEX	;$F0B3
F051 AD 93 02   	LDA M51CTR
F054 0A         	ASL
F055 A9 01      	LDA #$01
F057 65 A8      	ADC TPRWRE
F059 D0 EF      	BNE SERRXEX	;$F04A
;
; RXSET - Setup to receive
;
RXSET
F05B A9 90      	LDA #$90
F05D 8D 1E 91   	STA D1IER
F060 85 A9      	STA RINONE
F062 A9 20      	LDA #$20
F064 8D 1E 91   	STA D1IER
F067 60         	RTS


;====================================================================
; PROCSB - Process RS-232 byte
;
PROCSB
F068 A5 A7      	LDA INBIT
F06A D0 EF      	BNE RXSET
F06C 85 A9      	STA RINONE
F06E 60         	RTS

F06F AC 9B 02   	LDY RIDBE
F072 C8         	INY
F073 CC 9C 02   	CPY RIDBSR
F076 F0 2A      	BEQ SBE04	;$F0A2

F078 8C 9B 02   	STY RIDBE
F07B 88         	DEY
F07C A5 AA      	LDA RIDATA
F07E AE 98 02   	LDX BITNUM

PRSBLP1
F081 E0 09      	CPX #$09
F083 F0 04      	BEQ PROCSB2	;$F089

F085 4A         	LSR
F086 E8         	INX
F087 D0 F8      	BNE PRSBLP1	;$F081

PROCSB2
F089 91 F7      	STA (RIBUF),Y
F08B A9 20      	LDA #$20
F08D 2C 94 02   	BIT M51CDR
F090 F0 B9      	BEQ SERRX1-2	;$F04B
F092 30 B6      	BMI SERRX1-3	;$F04A RTS

F094 A5 A7      	LDA INBIT
F096 45 AB      	EOR RIPRTY
F098 F0 03      	BEQ $+3	;$F09D
F09A 70 AE      	BVS SERRX1-3	;$F04A

F09C 2C 	.db $2C
F09D 50 AB   	BVC SINPEX2	;BIT $A850 = BVC+A8

SBE01
F09F A9 01      	LDA #$01
F0A1 2C 	.db $2C

SBE04
F0A2 A9 04   	LDA #$04	;BIT $04A9
F0A4 2C	.db $2C

SBE80
F0A5 A9 80   	LDA #$80	;BIT $80A9
F0A7 2C 	.db $2C

SBE02
F0A8 A9 02   	LDA #$02	;BIT $02A9
F0AA 0D 97 02   	ORA RSSTAT
F0AD 8D 97 02   	STA RSSTAT
F0B0 4C 5B F0   	JMP RXSET

PRSBEX
F0B3 A5 AA      	LDA RIDATA
F0B5 D0 F1      	BNE SBE02	;$F0A8
F0B7 F0 EC      	BEQ SBE80	;$F0A5
F0B9 4C 96 F7   	JMP IOERMS9	;$F796


;====================================================================
; SSUBBT - Submit to RS-232
;
SSUBBT
F0BC 85 9A      	STA OUTDEV
F0BE AD 94 02   	LDA M51CDR
F0C1 4A         	LSR
F0C2 90 27      	BCC SSRETC	;$F0EB return OK

F0C4 A9 02      	LDA #$02
F0C6 2C 10 91   	BIT D1OUTB
F0C9 10 1D      	BPL SSRETE	;$F0E8 return DSR error
F0CB D0 1E      	BNE SSRETC	;$F0EB

SSLOOP1
F0CD AD 1E 91   	LDA D1IER
F0D0 29 30      	AND #%00110000	;$30
F0D2 D0 F9      	BNE SSLOOP1	;$F0CD

SSLOOP2
F0D4 2C 10 91   	BIT D1OUTB
F0D7 70 FB      	BVS SSLOOP2	;$F0D4

F0D9 AD 10 91   	LDA D1OUTB
F0DC 09 02      	ORA #$02
F0DE 8D 10 91   	STA D1OUTB

SSLOOP3
F0E1 2C 10 91   	BIT D1OUTB
F0E4 70 05      	BVS SSRETC	;$F0EB
F0E6 30 F9      	BMI SSLOOP3	;$F0E1

SSRETE
F0E8 20 16 F0   	JSR DSRERR	;set DSR error

SSRETC
F0EB 18         	CLC
F0EC 60         	RTS


;====================================================================
; SSENDB - Send to RS-232 buffer
;
SSENDB
F0ED AC 9E 02   	LDY RODBE
F0F0 C8         	INY
F0F1 CC 9D 02   	CPY RODBS
F0F4 F0 F7      	BEQ SSENDB

F0F6 8C 9E 02   	STY RODBE
F0F9 88         	DEY
F0FA 91 F9      	STA (ROBUF),Y
F0FC 2C 1E 91   	BIT D1IER
F0FF 50 01      	BVC SNDB1	;$F102

F101 60        	RTS

SNDB1
F102 AD 99 02   	LDA BAUDOF
F105 8D 14 91   	STA D1TM1L
F108 AD 9A 02   	LDA BAUDOF+1
F10B 8D 15 91   	STA D1TM1L+1
F10E A9 C0      	LDA #%11000000	;$C0
F110 8D 1E 91   	STA D1IER
F113 4C EE EF   	JMP SSNDN


;====================================================================
; SERINP - Input from RS-232
;
SERINP
F116 85 99      	STA INDEV
F118 AD 94 02   	LDA M51CDR
F11B 4A         	LSR
F11C 90 28      	BCC SINPEX2	;$F146

F11E 29 08      	AND #%00001000	;$08
F120 F0 24      	BEQ SINPEX2	;$F146

F122 A9 02      	LDA #$02
F124 2C 10 91   	BIT D1OUTB
F127 10 BF      	BPL SSRETE	;$F0E8 DSR error
F129 F0 19      	BEQ SINRETC	;$F144

SINPLP1
F12B 2C 1E 91   	BIT D1IER
F12E 70 FB      	BVS SINPLP1	;$F12B

F130 AD 10 91   	LDA D1OUTB
F133 29 FD      	AND #%11111101	;$FD
F135 8D 10 91   	STA D1OUTB

SINLP2
F138 AD 10 91   	LDA D1OUTB
F13B 29 04      	AND #%00000100	;$04
F13D F0 F9      	BEQ SINLP2	;$F138

SINPEX1
F13F A9 90      	LDA #%10010000	;$90
F141 8D 1E 91   	STA D1IER

SINRETC
F144 18         	CLC
F145 60         	RTS

SINPEX2
F146 AD 1E 91   	LDA D1IER
F149 29 30      	AND #%00110000	;$30
F14B F0 F2      	BEQ SINPEX1	;$F13F
F14D 18         	CLC
F14E 60         	RTS


;====================================================================
; SERGET - Get from RS-232
;
SERGET
F14F AC 9C 02   	LDY RIDBSR
F152 CC 9B 02   	CPY RIDBE
F155 F0 06      	BEQ SERGET1	;$F15D

F157 E1 F7      	LDA (RIBUF),Y
F159 EE 9C 02   	INC RIDBSR
F15C 60         	RTS

SERGET1
F15D A9 00      	LDA #$00
F15F 60         	RTS


;====================================================================
; SBIDLE - Serial bus idle
;
SBIDLE
F160 48         	PHA
F161 AD 1E 91   	LDA D1IER
F164 F0 0C      	BEQ SBIDLEX	;$F172

SBIDLLP
F166 AD 1E 91   	LDA D1IER
F169 29 60      	AND #$60
F16B D0 F9      	BNE SBIDLLP	;$F166

F16D A9 10      	LDA #$10
F16F 8D 1E 91   	STA D1IER

SBIDLEX
F172 68         	PLA
F173 60         	RTS


;====================================================================
; KIOMSG - KERNEL I/O messages
;
KIOMSG
F174 .db $0D, 'I/O ERROR', $0D, $0D		;00h

F180 .db $0D, 'SEARCHING FOR '		;0Ch

F18F .db $0D, 'PRESS PLAY ON TAPE'		;1Bh

F1A2 .db 'PRESS RECORD & PLAY ON TAPE'	;2Eh

F1BD .db $0D, 'LOADING'		;49h

F1C5 .db $0D, 'SAVING '		;51h

F1CD .db $0D, 'VERIFYING'		;59h

F1D7 .db $0D, 'FOUND '		;63h

F1DE .db $0D, 'OK <CR>'		;6Ah


;====================================================================
; DIRMSG - Print message to screen if Direct
;
DIRMSG
F1E2 24 9D      	BIT $9D
F1E4 10 0D      	BPL MSGEXIT	;$F1F3
;
; MSG - Print message
;
MSG
F1E6 B9 74 F1   	LDA KIOMSG,Y	; Y = message#
F1E9 08         	PHP
F1EA 29 7F      	AND #%01111111	;$7F clear character shift
F1EC 	JSR (CHOTVP)	;CHROUT
F1EF C8         	INY
F1F0 28         	PLP
F1F1 10 F3      	BPL MSG

MSGEXIT
F1F3 18         	CLC
F1F4 60         	RTS


;====================================================================
; IGETIN - Get a byte (internal)
;
IGETIN
F1F5 A5 99      	LDA INDEV      
F1F7 D0 08      	BNE IGET232	;$F201
F1F9 A5 C6      	LDA KEYCNT
F1FB F0 6D      	BEQ GTSCEXC	;$F26A
F1FD 78         	SEI
F1FE 4C CF E5   	JMP LP2

IGET232
F201 C9 02      	CMP #$02	;input from RS-232?
F203 D0 18      	BNE CHINSCRN	;$F21D

IGETIN1
F205 84 97      	STY REGSAV
F207 20 4F F1   	JSR SERGET
F20A A4 97      	LDY REGSAV
F20C 18         	CLC
F20D 60         	RTS


;====================================================================
; ICHRIN - Input a byte (internal)
;
ICHRIN
F20E A5 99      	LDA INDEV
F210 D0 0B      	BNE CHINSCRN	;$F21D not 0, must not be keyboard

F212 A5 D3      	LDA CSRIDX
F214 85 CA      	STA ICRCOL
F216 A5 D6      	LDA CURROW
F218 85 C9      	STA ICRROW
F21A 4C 4F E6   	JMP INSCR	;$E64F

CHINSCRN
F21D C9 03      	CMP #$03	;screen?
F21F D0 09      	BNE ICHRIN1	;$F22A

F221 85 D0      	STA INSRC
F223 A5 D5      	LDA LINLEN
F225 85 C8      	STA EOLPTR
F227 4C 4F E6   	JMP INSCR	;$E64F

ICHRIN1
F22A B0 38      	BCS GTTSCH1	;$F264

F22C C9 02      	CMP #$02	;RS-232?
F22E F0 3F      	BEQ GTTSCH2	;$F26F

F230 86 97      	STX REGSAV
F232 20 50 F2   	JSR GTTSCH
F235 B0 16      	BCS ICHREXIT	;$F24D

F237 48         	PHA
F238 20 50 F2   	JSR GTTSCH
F23B B0 0D      	BCS ICHRIN3	;$F24A
F23D D0 05      	BNE ICHRIN2	;$F244
F23F A9 40      	LDA #$40
F241 20 6A FE   	JSR ISETMS+4	;$FE6A

ICHRIN2
F244 C6 A6      	DEC BUFPNT
F246 A6 97      	LDX REGSAV
F248 68         	PLA
F249 60         	RTS

ICHRIN3
F24A AA         	TAX
F24B 68         	PLA
F24C 8A         	TXA

ICHREXIT
F24D A6 97      	LDX REGSAV
F24F 60         	RTS


;====================================================================
; GTTSCH - Get input from tape/serial/RS-232
;
GTTSCH
F250 20 8A F8   	JSR INCTPT
F253 D0 0B      	BNE GTTSCEX	;$F260
F255 20 C0 F8   	JSR TPREAD
F258 B0 11      	BCS GTSCEXC+1	;$F26B
F25A A9 00      	LDA #$00
F25C 85 A6      	STA BUFPNT
F25E F0 F0      	BEQ GTTSCH	;$F250

GTTSCEX
F260 B1 B2      	LDA (CBSTPT),Y
F262 18         	CLC
F263 60         	RTS

GTTSCH1
F264 A5 90      	LDA CSTAT
F266 F0 04      	BEQ GTTSCH2	;$F26C
F268 A9 0D      	LDA #$0D

GTSCEXC
F26A 18         	CLC
F26B 60         	RTS

GTTSCH2
F26C 4C 19 EF   	JMP ACPTR

GTSCHLP
F26F 20 05 F2   	JSR IGETIN1
F272 B0 05      	BCS GTSCEX2	;$F279
F274 C9 00      	CMP #$00
F276 F0 F7      	BEQ GTSCHLP	;$F26F

F278 18         	CLC

GTSCEX2
F279 60         	RTS


;====================================================================
; ICHROT - Output one character (internal)
;
ICHROT
F27A 48        	PHA
F27B A5 9A      	LDA OUTDEV
F27D C9 03      	CMP #$03	;screen?
F27F D0 04      	BNE ONOTSCR	;$F285 no, skip

F281 68         	PLA
F282 4C 42 E7   	JMP OUTSCR	;send to screen

ONOTSCR
F285 90 04      	BCC OTIEEE	;$F28B serial - RS232 or IEEE?

F287 68         	PLA
F288 4C E4 EE   	JMP ICIOUT	;send to IEEE

OTIEEE
F28B C9 02      	CMP #$02
F28D F0 2A      	BEQ OTRS232	;$F2B9 send to RS232

F28F 68         	PLA	;must be tape
F290 85 9E      	STA TPTR1
F292 48         	PHA
F293 8A         	TXA
F294 48         	PHA
F295 98         	TYA
F296 48         	PHA
F297 20 8A F8   	JSR INCTPT	;increment tape pointer
F29A D0 0E      	BNE CHROT1	;$F2AA

F29C 20 E3 F8   	JSR TPWRIT	;write char
F29F B0 0E      	BCS CHROT2	;$F2AF

F2A1 A9 02      	LDA #$02
F2A3 A0 00      	LDY #$00
F2A5 91 B2      	STA (CBSTPT),Y
F2A7 C8         	INY
F2A8 84 A6      	STY BUFPNT

CHROT1
F2AA A5 9E      	LDA TPTR1
F2AC 91 B2      	STA (CBSTPT),Y
F2AE 18         	CLC
F2AF 68         	PLA

CHROT2
F2B0 A8         	TAY
F2B1 68         	PLA
F2B2 AA         	TAX
F2B3 68         	PLA
F2B4 90 02      	BCC CHRRET	;$F2B8
F2B6 A9 00      	LDA #$00

CHRRET
F2B8 60         	RTS

OTRS232
F2B9 68         	PLA
F2BA 86 97      	STX REGSAV
F2BC 84 9E      	STY TPTR1
F2BE 20 ED F0   	JSR SSENDB
F2C1 A6 97     	LDX REGSAV
F2C3 A4 9E      	LDY TPTR1
F2C5 18         	CLC
F2C6 60         	RTS

;====================================================================
; ICHKIN - Set input device (internal)
;
ICHKIN
F2C7 20 CF F3   	JSR FIND
F2CA F0 03      	BEQ ICHKI1	;$F2CF
F2CC 4C 84 F7   	JMP IOERMS3	;$F784

ICHKI1
F2CF 20 DF F3   	JSR FLATRB
F2D2 A5 BA      	LDA CHANNL
F2D4 F0 16      	BEQ ICHKI2	;$F2EC

F2D6 C9 03      	CMP #$03	;SCREEN?
F2D8 F0 12      	BEQ ICHKI2	;$F2EC
F2DA B0 14      	BCS ICHKI3	;$F2F0 IEEE?

F2DC C9 02      	CMP #$02	;RS232?
F2DE D0 03      	BNE $+3	;$F2E3
F2E0 4C 16 F1   	JMP SERINP	;go to serial input

F2E3 A6 B9      	LDX SECADR
F2E5 E0 60      	CPX #$60
F2E7 F0 03      	BEQ ICHKI2	;$F2EC
F2E9 4C 8D F7   	JMP IOERMS6	;$F78D

ICHKI2
F2EC 85 99      	STA INDEV
F2EE 18         	CLC
F2EF 60         	RTS

ICHKI3		;handle IEEE
F2F0 AA         	TAX
F2F1 20 14 EE   	JSR TALK
F2F4 A5 B9      	LDA SECADR
F2F6 10 06      	BPL ICHKI4	;$F2FE
F2F8 20 D3 EE   	JSR CLKWAIT
F2FB 4C 01 F3   	JMP ICHKI4+3	;$F301

ICHKI4
F2FE 20 CE EE   	JSR TKSA
F301 8A         	TXA
F302 24 90      	BIT CSTAT
F304 10 E6      	BPL ICHKI2	;$F2EC
F306 4C 8A F7   	JMP IOERMS5	;$F78A


;====================================================================
; ICHKOT - Set output device (internal)
;
ICHKOT
F309 20 CF F3  	JSR FIND
F30C F0 03     	BEQ $+3	;$F311
F30E 4C 84 F7  	JMP IOERMS3	;$F784 Press play

F311 20 DF F3  	JSR FLATRB
F314 A5 BA     	LDA CHANNL
F316 D0 03     	BNE $+3	;$F31B

ICHKER7
F318 4C 90 F7  	JMP IOERMS7	;$F790 dev0=kbd Verify

F31B C9 03     	CMP #$03	;screen?
F31D F0 0F     	BEQ ICHKO1	;$F32E
F31F B0 11     	BCS ICHKO2	;$F332 IEEE

F321 C9 02     	CMP #$02	;RS232?
F323 D0 03     	BNE $+3	;$F328
F325 4C BC F0  	JMP SSUBBT

F328 A6 B9     	LDX SECADR	;devs 0, 1
F32A E0 60     	CPX #$60
F32C F0 EA     	BEQ ICHKER7	;$F318 tape verify

ICHKO1		;screen
F32E 85 9A     	STA OUTDEV	
F330 18        	CLC
F331 60        	RTS

ICHKO2		;IEEE
F332 AA        	TAX	
F333 20 17 EE  	JSR LISTEN
F336 A5 B9     	LDA SECADR
F338 10 05     	BPL $+5	;$F33F

F33A 20 C5 EE  	JSR CLRATN
F33D D0 03     	BNE $+3	;$F342

F33F 20 C0 EE  	JSR ISECND
F342 8A        	TXA
F343 24 90     	BIT CSTAT
F345 10 E7     	BPL ICHKO1	;$F32E

F347 4C 8A F7  	JMP IOERMS5	;$F78A Loading


;====================================================================
; ICLOSE - Close file (internal)
;
ICLOSE
F34A 20 D4 F3  	JSR $F3D4
F34D F0 02     	BEQ $+2	;$F351
F34F 18        	CLC
F350 60        	RTS

ICLSE
F351 20 DF F3  	JSR FLATRB
F354 8A        	TXA
F355 48        	PHA
F356 A5 BA     	LDA CHANNL
F358 F0 57     	BEQ $F3B1

F35A C9 03     	CMP #$03	;screen
F35C F0 53     	BEQ ICLSE4	;$F3B1
F35E B0 4E     	BCS ICLSE3	;$F3AE

F360 C9 02     	CMP #$02	;RS232
F362 D0 29     	BNE ICLSE1	;$F38D

F364 68        	PLA
F365 20 B2 F3  	JSR ICLSE4+1	;$F3B2
F368 A9 7D     	LDA #%011111101	;$7D
F36A 8D 1E 91  	STA D1IER
F36D A9 06     	LDA #%00000110	;$06
F36F 8D 10 91  	STA D1OUTB
F372 A9 EE     	LDA #11101110	;$EE
F374 8D 1C 91  	STA D1PCR
F377 20 75 FE  	JSR IMEMTP+2	;$FE75
F37A A5 F8     	LDA RIBUF+1
F37C F0 01     	BEQ $+1	;$F37F

F37E C8        	INY
F37F A5 FA     	LDA ROBUF+1
F381 F0 01     	BEQ $+1	;$F384

F383 C8        	INY
F384 A9 60     	LDA #$00
F386 65 F8     	STA RIBUF+1
F388 85 FA     	STA ROBUF+1
F38A 4C 3C F5  	JMP $F53C

ICLSE1
F38D A5 B9     	LDA SECADR
F38F 29 0F     	AND #%00001111	;$0F
F391 F0 1E     	BEQ ICLSE4	;$F3B1

F393 20 4D F8  	JSR GETBFA	;$F84D
F396 A9 00     	LDA #$00
F398 20 90 F2  	JSR OTIEEE+4	;$F290 skips channel check
F39B 4C CF E4  	JMP TPWPCH	;$E4CF

ICLSE1
F39E B0 2E     	BCS ICLSEEX	;$F3CE
F3A0 A5 B9     	LDA SECADR
F3A2 C9 62     	CMP #$62
F3A4 D0 0B     	BNE ICLSE4	;$F3B1
F3A6 A9 05     	LDA #$05
F3A8 20 E7 F7  	JSR WRTPHD
F3AB 4C B1 F3  	JMP ICLSE4	;$F3B1

F3AE 20 DA F6  	JSR $F6DA

ICLSE4
F3B1 68        	PLA
F3B2 AA        	TAX
F3B3 C6 98     	DEC COPNFL
F3B5 E4 98     	CPX COPNFL
F3B7 F0 14     	BEQ $F3CD
F3B9 A4 98     	LDY COPNFL
F3BB B9 59 02  	LDA FILTBL,Y
F3BE 9D 59 02  	STA FILTBL,X
F3C1 B9 63 02  	LDA DEVTBL,Y
F3C4 9D 63 02  	STA DEVTBL,X
F3C7 B9 6D 02  	LDA SECTAB,Y
F3CA 9D 6D 02  	STA SECTAB,X
F3CD 16        	CLC

ICLSEEX
F3CE 60        	RTS


;====================================================================
; FIND - Find file
;
FIND
F3CF A9 00     	LDA #$00
F3D1 85 90     	STA CSTAT
F3D3 8A        	TXA
F3D4 A6 98     	LDX COPNFL

FINDLOOP
F3D6 CA        	DEX
F3D7 30 15     	BMI FLATRBX	;$F3EE

F3D9 DD 59  02 	CMP FILTBL,X
F3DC 60 F8     	BNE FINDLOOP	;$F3D6

F3DE 60        	RTS

;====================================================================
; FLATRB - Set file values
;
FLATRB
F3DF BD 59 02	LDA FILTBL,X
F3E2 85 B8	STA LOGFIL
F3E4 BD 63 02	LDA DEVTBL,X
F3E7 85 BA	STA CHANNL
F3E9 BD 6D 02	LDA SECTAB,X
F3EC 85 B9	STA SECADR

FLATRBX
F3EE 60	RTS
;====================================================================
; ICLALL - Abort all files (internal)
;
ICLALL
F3EF A9 00     	LDA #$00
F3F1 85 98     	STA COPNFL

;====================================================================
; ICLRCH - Restore default I/O (internal)
;
ICLRCH
F3F3 A2 03     	LDX #$03
F3F5 E4 9A     	CPX OUTDEV	;is output device <=3
F3F7 B0 03     	BCS $+3	;$F3FC yes, continue 
 
F3F9 20 04 EF  	JSR IUNLSN	;send unlisten command

F3FC E4 99     	CPX INDEV	;is input device <=3
F3FE B0 03     	BCS $+3	;$F403 yes, continue

F400 20 F6 EE  	JSR IUNTLK	;send untalk

F403 86 9A     	STX OUTDEV
F405 A9 00     	LDA #$00
F407 85 99     	STA INDEV
F409 60        	RTS


;====================================================================
; IOPEN - Open file (internal)
;
IOPEN
F40A A6 B8     	LDX LOGFIL
F40C D0 03     	BNE $+3	;F411 <>0 not "save"
F40E 4C 8D F7  	JMP IOERMS6	;$F78D saving

F411 20 CF F3  	JSR FIND
F414 D0 03     	BNE $+3	;F419
F416 4C 81 F7  	JMP IOERMS2	;$F781 searching for

F419 A6 98     	LDX COPNFL
F41B E0 0A     	CPX #$0A	;10 files open?
F41D 90 03     	BCC $+3	;F422
F41F 4C 7E F7  	JMP IOERMS	;I/O error

F422 E6 98     	INC COPNFL
F424 A5 B8     	LDA LOGFIL
F426 9D 59 02  	STA FILTBL,X
F429 A5 B9     	LDA SECADR
F42B 09 60     	ORA #%01100000	;$60
F42D 85 B9     	STA SECADR
F42F 9D 6D 02  	STA SECTAB,X
F432 A5 BA     	LDA CHANNL
F434 9D 63 02  	STA DEVTBL,X
F437 F0 5A     	BEQ IOPENRC	;$F493 return clear

F439 C9 03     	CMP #$03	;screen?
F43B F0 56     	BEQ IOPENRC	;$F493
F43D 90 05     	BCC $+5	;F444

F43F 20 95 F4  	JSR SENDSA	;send secondary
F442 90 4F     	BCC IOPENRC	;$F493 return clear

F444 C9 02     	CMP #$02	;RS232?
F446 D0 03     	BNE $+3	;F44B not RS232
F448 4C C7 F4  	JMP SEROPN

F44B 20 4D F8  	JSR GETBFA	;not screen or RS232
F44E B0 03     	BCS $+3	;F453
F450 4C 96 F7  	JMP IOERMS9	;$F796 OK

F453 A5 B9     	LDA SECADR
F455 29 0F     	AND #$0F
F457 D0 1F     	BNE IOPEN2	;$F478

F459 20 94 F8  	JSR PLAYMS
F45C B0 36     	BCS IOPENRC+1	;$F494 return CY=1

F45E 20 47 F6  	JSR SRCHMS	;searching
F461 A5 B7     	LDA FNMLEN
F463 F0 0A     	BEQ IOPEN1	;F46F	name found

F465 20 67 F8  	JSR LOCSPH
F468 90 18     	BCC IOPEN3	;$F482
F46A F0 28     	BEQ IOPENRC+1	;$F494 return CY=1

IOPENA
F46C 4C 87 F7  	JMP SETTIME

IOPEN1
F46F 20 AF F7  	JSR LOCTPH
F472 F0 20     	BEQ IOPENRC+1	;$F494
F474 90 0C     	BCC IOPEN3	;$F482
F476 B0 F4     	BCS IOPENA	;$F46C

IOPEN2
F478 20 B7 F8  	JSR RECDMS
F47B B0 17     	BCS IOPENRC+1	;$F494 return CY=1

F47D A9 04     	LDA #$04
F47F 20 E7 F7  	JSR WRTPHD

IOPEN3
F482 A9 BF     	LDA #$BF
F484 A4 B9     	LDY SECADR
F486 C0 60     	CPY #$60
F488 F0 07     	BEQ IOPENRC-2	;$F491

F48A A0 00     	LDY #$00
F48C A9 02     	LDA #$02
F48E 91 B2     	STA (CBSTPT),Y
F490 98        	TYA
F491 65 A6     	STA BUFPNT

IOPENRC
F493 18        	CLC
F494 60        	RTS


;====================================================================
; SENDSA - Send secondary address
;
SENDSA
F495 A5 B9     	LDA SECADR
F497 30 2C     	BMI SNDSARC	;$F4C5

F499 A4 B7     	LDY FNMLEN
F49B F0 28     	BEQ SNDSARC	;$F4C5

F49D A5 BA     	LDA CHANNL
F49F 20 17 EE  	JSR LISTEN
F4A2 A5 B9     	LDA SECADR
F4A4 09 F0     	ORA #%11110000	;$F0
F4A6 20 C0 EE  	JSR ISECND	;$EEC0
F4A9 A5 90     	LDA CSTAT
F4AB 10 05     	BPL SENDSA1	;$F4B2

F4AD 68        	PLA
F4AE 68        	PLA
F4AF 4C 8A F7  	JMP IOERMS1	;$F78A

SENDSA1
F4B2 A5 B7     	LDA FNMLEN
F4B4 F0 0C     	BEQ SNDSARU	;$F4C2

F4B6 A0 00     	LDY #$00

SENDSALP
F4B8 B1 BB     	LDA (FNPTR),Y	;send chrout to filename
F4BA 20 E4 EE  	JSR ICIOUT
F4BD C8        	INY
F4BE C4 B7     	CPY FNMLEN
F4C0 D0 F6     	BNE SEMDSALP	;$F4B8

SNDSARU
F4C2 20 04 EF  	JSR IUNLSN

SNDSARC
F4C5 18        	CLC
F4C6 60        	RTS


;====================================================================
; SEROPN - Open RS-232
;
SEROPN
F4C7 A9 06     	LDA #%00000110	;$06
F4C9 8D 12 91  	STA D1DDRA
F4CC 8D 10 91  	STA D1OUTB
F4CF A9 EE     	LDA #%11101110	;$EE
F4D1 8D 1C 91  	STA D1PCR
F4D4 A0 00     	LDY #$00
F4D6 8C 97 02  	STY RSSTAT

SEROPLP
F4D9 C4 B7     	CPY FNMLEN
F4DB F0 0A     	BEQ SEROPN1	;$F4E7

F4DD B1 BB     	LDA (FNPTR),Y
F4DF 99 93 02  	STA M51CTR,Y
F4E2 C8        	INY
F4E3 C0 04     	CPY #$04
F4E5 D0 F2     	BNE SEROPLP	;$F4D9

SEROPN1
F4E7 20 27 F0  	JSR BITCNT
F4EA 8E 98 02  	STX BITNUM
F4ED AD 93 02  	LDA M51CTR
F4F0 29 0F     	AND #%00001111	;$0F
F4F2 D0 00     	BNE $+0	;F4F4

F4F4 0A        	ASL
F4F5 AA        	TAX
F4F6 BD 5A FF  	LDA R232TB-2,X	;$FF5A,X
F4F9 0A        	ASL
F4FA A8        	TAY
F4FB BD 5B FF  	LDA R232TB-1,X	;$FF5B,X
F4FE 2A        	ROL
F4FF 48        	PHA
F500 9B        	TYA
F501 69 C8     	ADC #$C8
F503 8D 99 02  	STA BAUDOF
F506 68        	PLA
F507 69 00     	ADC #$00
F509 8D 9A 02  	STA BAUDOF+1
F50C AD 94 02  	LDA M51CDR
F50F 4A        	LSR
F510 90 09     	BCC SEROPN2	;$F51B

F512 AD 20 91  	LDA D2ORB
F515 0A        	ASL
F516 B0 03     	BCS SEROPN2	;$F51B
F518 4C 16 F0  	JMP DSRERR

SEROPN2
F51B AD 9B 02  	LDA RIDBE
F51E 8D 9C 02  	STA RIDBSR
F521 AD 9E 02  	LDA RODBE
F524 8D 9D 02  	STA RODBS
F527 20 75 FE  	JSR IMEMTP+2	;$FE75

F52A A5 F8     	LDA RIBUF+1
F52C D0 05     	BNE SEROPN3	;$F533

F52E 88        	DEY
F52F 84 F8     	STY RIBUF+1
F531 86 F7     	STX RIBUF

SEROPN3
F533 A5 FA     	LDA ROBUF+1
F535 D0 05     	BNE $F53C
F537 88        	DEY
F538 84 FA     	STY ROBUF+1
F53A 86 F9     	STX ROBUF
F53C 38        	SEC
F53D A9 F0     	LDA #$F0
F53F 4C 7B FE  	JMP STOTOP	;$FE7B


;====================================================================
; ILOAD - Load RAM from device (internal)
;
ILOAD
F542 86 C3     	STX MEMUSS	;save load location
F544 84 C4     	STY MEMUSS+1
F546 6C 30 03  	JMP (CLOADV)


;====================================================================
; LNKLOD - Load RAM (indirect from $0330)
;
LNKLOD
F549 85 93     	STA IOFLG2
F54B A9 00     	LDA #$00
F54D 85 90     	STA CSTAT
F54F A5 BA     	LDA CHANNL
F551 D0 03     	BNE $+3	;$F556

LNKLDEX
F553 4C 96 F7  	JMP IOERMS9	;$F796 "OK"

F556 C9 03     	CMP #$03	;screen?
F558 F0 F9     	BEQ LNKLDEX	;$F553
F55A 90 6E     	BCC TAPLOA	;<3, must be tape
;
; SERLOA - Load file from serial bus
;
SERLOA
F55C A4 B7     	LDY FNMLEN
F55E D0 03     	BNE $+3	;F563
F560 4C 93 F7  	JMP IOERMS8	;$F793 found

F563 20 BC E4  	JSR SSADR	;$E4BC
F566 A9 60     	LDA #$60
F568 85 B9     	STA SECADR
F56A 20 95 F4  	JSR SENDSA
F56D A5 BA     	LDA CHANNL
F56F 20 14 EE  	JSR TALK
F572 A5 B9     	LDA SECADR
F574 20 CE EE  	JSR TKSA
F577 20 19 EF  	JSR IACPTR
F57A 85 AE     	STA EAL
F57C A5 90     	LDA CSTAT
F57E 4A        	LSR
F57F 4A        	LSR
F580 B0 45     	BCS SERLDEX	;$F5C7

F582 20 19 EF  	JSR IACPTR
F585 85 AF     	STA EAL+1
F587 20 C1 E4  	JSR SLDPCH	;$E4C1

SERLDLP
F58A A9 FD     	LDA #$FD
F58C 25 90     	AND CSTAT
F58E 85 90     	STA CSTAT
F590 	JSR (STOPVP)	;STOP
F593 D0 03     	BNE $+3	;F598
F595 4C CE F6  	JMP SAVEXIT	;$F6CE

F598 20 19 EF  	JSR IACPTR
F59B AA        	TAX
F59C A5 90     	LDA CSTAT
F59E 4A        	LSR
F59F 4A        	LSR
F5A0 B0 E8     	BCS SERLDLP	;$F58A

F5A2 8A        	TXA
F5A3 A4 93     	LDY IOFLG2
F5A5 F0 0C     	BEQ SERLD1	;$F5B3

F5A7 A0 00     	LDY #$00
F5A9 D1 AE     	CMP (EAL),Y
F5AB F0 08     	BEQ SERLD2	;$F5B5

F5AD A9 10     	LDA #$10
F5AF 20 6A FE  	JSR ISETMS1	;$FE6A
F5B2 2C 	.db $2C	;bit $ae91

SERLD1
F5B3 91 AE  	STA (EAL),Y

SERLD2
F5B5 E6 AE     	INC EAL
F5B7 D0 02     	BNE $+2	;$F5BB

F5B9 E6 AF     	INC EAL+1
F5BB 24 90     	BIT CSTAT
F5BD 50 CB     	BVC SERLDLP	;$F58A

F5BF 20 F6 EE  	JSR IUNTLK
F5C2 20 DA F6  	JSR $F6DA
F5C5 90 7A     	BCC TPLOAEX	;$F641

SERLDEX
F5C7 4C 87 F7  	JMP IOERMS4	;$F787 play & rec



;====================================================================
; TAPLOA - Load file from tape
;
TAPLOA
F5CA C9 02     	CMP #$02
F5CC D0 03     	BNE $+3	;F5D1
F5CE 4C B9 F0  	JMP IOERMS9	;$F0B9

F5D1 20 4D F8  	JSR GETBFA
F5D4 B0 03     	BCS $+3	;F5D9
F5D6 4C 96 F7  	JMP IOERMS9	;$F796

F5D9 20 94 F8  	JSR PLAYMS
F5DC B0 68     	BCS TPLORTS

F5DE 20 47 F6  	JSR SRCHMS

TAPLOALP
F5E1 A5 B7     	LDA FNMLEN
F5E3 F0 09     	BEQ TAPLOA1	;$F5EE

F5E5 20 67 F8  	JSR LOCSPH
F5E8 90 0B     	BCC TAPLOA2	;$F5F5
F5EA F0 5A     	BEQ TPLORTS
F5EC B0 D9     	BCS SERLDEX	;$F5C7

TAPLOA1
F5EE 20 AF F7  	JSR LOCTPH
F5F1 F0 53     	BEQ TPLORTS
F5F3 B0 D2     	BCS SERLDEX	;$F5C7

TAPLOA2
F5F5 A5 90     	LDA CSTAT
F5F7 29 10     	AND #%00010000	;$10
F5F9 38        	SEC
F5FA D0 4A     	BNE TPLORTS

F5FC E0 01     	CPX #$01
F5FE F0 11     	BEQ TAPLOA3	;$F611

F600 E0 03     	CPX #$03

TAPLOA2A
F602 D0 DD     	BNE TAPLOALP	;$F5E1
 
TALPOALP2
F604 A0 01     	LDY #$01
F606 B1 B2     	LDA (CBSTPT),Y
F608 85 C3     	STA MEMUSS
F60A C8        	INY
F60B B1 B2     	LDA (CBSTPT),Y
F60D 85 C4     	STA MEMUSS+1
F60F B0 04     	BCS TAPLOA4	;$F615

TAPLOA3
F611 A5 B9     	LDA SECADR
F613 D0 EF     	BNE TAPLOALP2	;F604

TAPLOA4
F615 A0 03     	LDY #$03
F617 B1 B2     	LDA (CBSTPT),Y
F619 A0 01     	LDY #$01
F61B F1 B2     	SBC (CBSTPT),Y
F61D AA        	TAX
F61E A0 04     	LDY #$04
F620 B1 B2     	LDA (CBSTPT),Y
F622 A0 02     	LDY #$02
F624 F1 B2     	SBC (CBSTPT),Y
F626 A8        	TAY
F627 18        	CLC
F628 8A        	TXA
F629 65 C3     	ADC MEMUSS
F62B 85 AE     	STA EAL
F62D 98        	TYA
F62E 65 C4     	ADC MEMUSS+1
F630 85 AF     	STA EAL+1
F632 A5 C3     	LDA MEMUSS
F634 85 C1     	STA STAL
F636 A5 C4     	LDA MEMUSS+1
F638 85 C2     	STA STAL+1
F63A 20 6A F6  	JSR LOADMS
F63D 20 C9 F8  	JSR TPREAD1	;$F8C9
F640 24 	.db$24	;BIT LASTPT+1

TPLOAEX
F641 18	CLC
F642 A6 AE     	LDX EAL
F644 A4 AF     	LDY EAL+1

TPLORTS
F646 60        	RTS



;====================================================================
; SRCHMS - Print "Searching"
;
SRCHMS
F647 A5 9D     	LDA CMDMOD
F649 10 1E     	BPL SRCHEX	;$F669


F64B A0 0C     	LDY #$0C	;"Searching for"
F64D 20 E6 F1  	JSR MSG
F650 A5 B7     	LDA FNMLEN
F652 F0 15     	BEQ SRCHEX	;$F669
F654 A0 17     	LDY #$17	;point to "FOR" in "Searching For"
F656 20 E6 F1  	JSR MSG
;
; FLNMMS - Print filename
;
FLNMMS
F659 A4 B7     	LDY FNMLEN
F65B F0 0C     	BEQ SRCHEX	;$F669
F65D A0 00     	LDY #$00

FLNMLP
F65F B1 BB     	LDA (FNPTR),Y
F661 	JSR (CHOTVP)	;CHROUT
F664 C8        	INY
F665 C4 B7     	CPY FNMLEN
F667 D0 F6     	BNE FLNMLP	;$F65F

SRCHEX
F669 60        	RTS


;====================================================================
; LOADMS - Print "Loading" or "Verifying"
;
LOADMS
F66A A0 49     	LDY #$49	;"Loading"
F66C A5 93     	LDA IOFLG2
F66E F0 02     	BEQ DOMESG	;$F672

F670 A0 59     	LDY #$59	;"Verifying"

DOMESG
F672 4C E2 F1  	JMP DIRMSG


;====================================================================
; ISAVE - Save RAM to device
;
ISAVE
F675 86 AE     	STX EAL
F677 84 AF     	STY EAL+1
F679 AA        	TAX
F67A B5 00     	LDA USRPOK,X
F67C 85 C1     	STA STAL
F67E B5 01     	LDA USRVEC,X
F680 85 C2     	STA STAL+1
F682 6C 32 03  	JMP (CSAVEV)


;====================================================================
; LNKSAV - Link to SAVE (indirect from $0302)
;
LNKSAV
F685 A5 BA     	LDA CHANNL	;Get current device
F687 D0 03     	BNE $+3	;F68C Not 0, continue
F689 4C 96 F7  	JMP IOERMS9	;$F796 OK 

F68C C9 03     	CMP #$03	;Device 3 (printer 3-5)
F68E F0 F9     	BEQ $-5	;$F689
F690 90 5F     	BCC TAPESV
;
; SERSAV - Save to serial bus
;
SERSAV
F692 A9 61     	LDA #$61
F694 85 B9     	STA SECADR
F696 A4 B7     	LDY FNMLEN
F698 D0 03     	BNE $+3	;$F69D
F69A 4C 93 F7  	JMP IOERMS8	;$F793 found

F69D 20 95 F4  	JSR SENDSA
F6A0 20 28 F7  	JSR SAVEMS
F6A3 A5 BA     	LDA CHANNL
F6A5 20 17 EE  	JSR LISTEN
F6A8 A5 B9     	LDA SECADR
F6AA 20 C0 EE  	JSR ISECND
F6AD A0 00     	LDY #$00
F6AF 20 D2 FB  	JSR RSTTPP
F6B2 A5 AC     	LDA SAL
F6B4 20 E4 EE  	JSR ICIOUT
F6B7 A5 AD     	LDA SAL+1
F6B9 20 E4 EE  	JSR ICIOUT

SERSAVLP
F6BC 20 11 FD  	JSR CKWRPT
F6BF B0 16     	BCS SERSAV1	;$F6D7

F6C1 B1 AC     	LDA (SAL),Y
F6C3 20 E4 EE  	JSR ICIOUT
F6C6 	JSR (STOPVP)	;STOP
F6C9 DE 07     	BNE TAPLOA2A	;$F602

F6CB 20 DA F6  	JSR SERSAV1A	;$F6DA
F6CE A9 00     	LDA #$00
F6D0 38       	SEC
F6D1 60        	RTS

F6D2 20 1B FD  	JSR INCRDP	;$FD1B
F6D5 D0 E5     	BNE SERSAVLP	;$F6BC

SERSAV1
F6D7 20 04 EF  	JSR IUNLSN

SERSAV1A
F6DA 24 B9     	BIT SECADR
F6DC 3E 11     	BMI SERSAVRC	;$F6EF

F6DE A5 BA     	LDA CHANNL
F6E0 20 17 EE  	JSR LISTEN
F6E3 A5 B9     	LDA SECADR
F6E5 29 EF     	AND #%11101111	;$EF
F6E7 09 E0     	ORA #%11100000	;$E0
F6E9 20 C0 EE  	JSR ISECND
F6EC 20 04 EF  	JSR IUNLSN

SERSAVRC
F6EF 18        	CLC
F6F0 60        	RTS


;====================================================================
; TAPESV - Save to tape
;
TAPESV
F6F1 C9 02     	CMP #$02
F6F3 D0 03     	BNE $+3	;$F6F8
F6F5 4C 96 F7  	JMP IOERMS9	;was $F0B9 

F6F8 20 4D F8  	JSR GETBFA
F6FB 90 BC     	BCC $-6	;LNKSAV+4 $F689 JMP IOERMS9

F6FD 20 B7 F8  	JSR RECDMS
F700 B0 25     	BCS TPSVRET	;$F727 RTS

F702 20 28 F7  	JSR SAVEMS	;print "saving" message
F705 A2 03     	LDX #$03
F707 A5 B9     	LDA SECADR
F709 29 01     	AND #%00000001	;$01
F70B D0 02     	BNE $+2	;$F70F

F70D A2 01     	LDX #$01
F70F 8A        	TXA
F710 20 E7 F7  	JSR WRTPHD
F713 B0 12     	BCS TPSVRET	;$F727

F715 20 E6 F8  	JSR TPWRIT+3	;$F8E6
F718 B0 0D     	BCS TPSVRET	;$F727

F71A A5 B9     	LDA SECADR
F71C 29 02     	AND #%00000010	;$02
F71E F0 06     	BEQ TPSVRET-1	;$F726 exit with CLC

F720 A9 05     	LDA #$05
F722 20 E7 F7  	JSR WRTPHD
F725 24 	.db $24	; BIT $18
F726 18     	CLC	

TPSVRET
F727 60        	RTS


;====================================================================
; SAVEMS - Print "Saving"
;
SAVEMS
F728 A5 9D     	LDA CMDMOD
F72A 10 FB     	BPL TPSVRET	;$F727

F72C A0 51     	LDY #$51	'Saving"
F72E 20 E6 F1  	JSR MSG
F731 4C 59 F6  	JMP FLNMMS	;print filename


;====================================================================
; IUDTIM - Update RTC (internal)
;
IUDTIM
F734 A2 00     	LDX #$00
F736 E6 A2     	INC CTIMR+2
F738 D0 06     	BNE UDTIM1	;$F740

F73A E6 A1     	INC CTIMR+1
F73C D0 02     	BNE UDTIM1	;$F740

F73E E6 A0     	INC CTIMR

UDTIM1
F740 38        	SEC
F741 A5 A2     	LDA CTIMR+2
F743 E9 01     	SBC #$01
F745 A5 A1     	LDA CTIMR+1
F747 E9 1A     	SBC #$1A
F749 A5 A0     	LDA CTIMR
F74B E9 4F     	SEC #$4F
F74D 90 06     	BCC UDTIM2	;$F755

F74F 86 A0     	STX CTIMR
F751 86 A1     	STX CTIMR+1
F753 86 A2     	STX CTIMR+2


UDTIM2
F755 AD 2F 91  	LDA D2OUTA
F758 CD 2F 91  	CMP D2OUTA
F75B D0 FB     	BNE UDTIM2	;$F755

F75D 85 91     	STA STKEY
F75F 60        	RTS


;====================================================================
; IRDTIM - Read RTC (internal)
;
IRDTIM
F760 78        	SEI
F761 A5 A2     	LDA CTIMR+2
F763 A6 A1     	LDX CTIMR+1
F765 A4 A0     	LDY CTIMR


;====================================================================
; ISETTM - Set RTC (internal)
;
ISETTM
F767 78        	SEI 
F768 85 A2     	STA CTIMR+2
F76A 86 A1     	STX CTIMR+1
F76C 84 A0     	STY CTIMR
F76E 58        	CLI
F76F 60        	RTS


;====================================================================
; ISTOP - Check STOP key
;
ISTOP
F770 A5 91     	LDA STKEY
F772 C9 FE     	CMP #%11111110	;$FE
F774 D0 07     	BNE ISTOPEX	;$F77D

F776 08        	PHP
F777 	JSR (CLCHVP)	;CLRCH
F77A 85 C6     	STA KEYCNT
F77C 28        	PLP

ISTOPEX
F77D 60        	RTS


;====================================================================
;IOERMS - I/O Error Message Table register load
;         All use the BIT $xxA9 trick to skip unused entries
;
IOERMS1
F77E A9 01     	LDA #$01	;I/O Error
F780 .db $2C

IOERMS2
F781 A9 02  	LDA #$02	;Searching for
F783 .db $2C 

IOERMS3
F784 A9 03  	LDA #$03	;Press Play on Tape
F786 .db $2C 

IOERMS4
F787 A9 04  	LDA #$04	;Press Record & Play on Tape
F789 .db $2C 

IOERMS5
F78A A9 05  	LDA #$05	;Loading
F78C .db $2C 

IOERMS6
F78D A9 06  	LDA #$06	;Saving
F78F .db $2C 

IOERMS7
F790 A9 07  	LDA #$07	;Verifying
F792 .db $2C 

IOERMS8
F793 A9 08  	LDA #$08	;Found
F795 .db $2C 

IOERMS9
F796 A9 09  	LDA #$09	;OK

F798 48        	PHA
F799 	JSR (CLCHVP)	;CLRCH
F79C A0 00     	LDY #$00
F79E 24 9D     	BIT CMDMOD
F7A0 50 0A     	BVC IOERMSEX	;$F7AC

F7A2 20 E6 F1  	JSR MSG	;Error 0-I/O Error
F7A5 68        	PLA
F7A6 48        	PHA
F7A7 09 30     	ORA #%00110000	;$30
F7A9 	JSR (CHOTVP)	;CHROUT

IOERMSEX
F7AC 68        	PLA
F7AD 38        	SEC
F7AE 60        	RTS


;====================================================================
; LOCTPH - Find any tape header
;
LOCTPH
F7AF A5 93     	LDA IOFLG2
F7B1 48        	PHA
F7B2 20 C0 F8  	JSR TPREAD
F7B5 68        	PLA
F7B6 85 93     	STA IOFLG2
F7B8 B0 2C     	BCS $F7E6

F7BA A0 00     	LDY #$00
F7BC B1 B2     	LDA (CBSTPT),Y
F7BE C9 05     	CMP #$05
F7C0 F0 24     	BEQ LOCTPEX	;$F7E6

F7C2 C9 01     	CMP #$01
F7C4 F0 08     	BEQ LOCTP1	;$F7CE

F7C6 C9 03     	CMP #$03
F7C8 F0 04     	BEQ LOCTP1	;$F7CE

F7CA C9 04     	CMP #$04
F7CC D0 E1     	BNE LOCTPH

LOCTP1
F7CE AA        	TAX
F7CF 24 9D     	BIT CMDMOD
F7D1 10 11     	BPL LOCTPEX-2	;$F7E4 return CLC

F7D3 A0 63     	LDY #$63	;"Found"
F7D5 20 E6 F1  	JSR MSG
F7D8 A0 05     	LDY #$05

LOCLOOP
F7DA B1 B2     	LDA (CBSTPT),Y
F7DC 	JSR (CHOTVP)	;CHROUT
F7DF C8        	INY
F7E0 C0 15     	CPY #$15
F7E2 D0 F6     	BNE LOCLOOP	;$F7DA
F7E4 18        	CLC
F7E5 88        	DEY

LOCTPEX
F7E6 60        	RTS



;====================================================================
; WRTPHD - Write tape header
;
WRTPHD
F7E7 85 9E     	STA TPTR1
F7E9 20 4D F8  	JSR GETBFA
F7EC 90 5E     	BCC WRTPEX	;$F84C

F7EE A5 C2     	LDA STAL+1
F7F0 48        	PHA
F7F1 A5 C1     	LDA STAL
F7F3 48        	PHA
F7F4 A5 AF     	LDA EAL+1
F7F6 48        	PHA
F7F7 A5 AE     	LDA EAL
F7F9 48        	PHA
F7FA A0 BF     	LDY #$BF
F7FC A9 20     	LDA #$20

WRTPLP1
F7FE 91 B2     	STA (CBSTPT),Y
F800 88        	DEY
F801 D0 FB     	BNE WRTPLP1	;$F7FE

F803 A5 9E     	LDA TPTR1
F805 91 B2     	STA (CBSTPT),Y
F807 C8        	INY
F808 A5 C1     	LDA STAL
F80A 91 B2     	STA (CBSTPT),Y
F80C C8        	INY
F80D A5 C2     	LDA STAL+1
F80F 91 B2     	STA (CBSTPT),Y
F811 C8        	INY
F812 A5 AE     	LDA EAL
F814 91 B2     	STA (CBSTPT),Y
F816 C8        	INY
F817 A5 AF     	LDA EAL+1
F819 91 B2     	STA (CBSTPT),Y
F81B C8        	INY
F81C 84 9F     	STY TPTR2
F81E A0 00     	LDY #$00
F820 84 9E     	STY TPTR1

WRTPLP2
F822 A4 9E     	LDY TPTR1
F824 C4 B7     	CPY FNMLEN
F826 F0 0C     	BEQ WRTPH1	;$F834

F828 B1 BB     	LDA (FNPTR),Y
F82A A4 9F     	LDY TPTR2
F82C 91 B2     	STA (CBSTPT),Y
F82E E6 9E     	INC TPTR1
F830 E6 9F     	INC TPTR2
F832 D0 EE     	BNE WRTPLP2	;$F822

WRTPH1
F834 20 54 FB  	JSR SETBST
F837 A9 69     	LDA #$69
F839 85 AB     	STA RIPRTY
F83B 20 EA F8  	JSR $F8EA
F63E A8        	TAY
F83F 68        	PLA
F840 85 AE     	STA EAL
F842 68        	PLA
F843 85 AF     	STA EAL+1
F845 68        	PLA
F646 85 C1     	STA STAL
F848 68        	PLA
F849 85 C2     	STA STAL+1
F84B 98        	TYA

WRTPEX
F84C 60        	RTS


;====================================================================
; GETBFA - Get buffer address
;
GETBFA
F84D A6 B2     	LDX CBSTPT
F84F A4 B3     	LDY CBSTPT+1
F851 C0 02     	CPY #$02
F853 60        	RTS


;====================================================================
; SETBST - Set buffer start/end pointers
;
SETBST
F854 20 4D F8  	JSR GETBFA
F857 8A        	TXA
F858 85 C1     	STA STAL
F85A 18        	CLC
F85B 69 C0     	ADC #$C0
F85D 85 AE     	STA EAL
F85F 98        	TYA
FB60 85 C2     	STA STAL+1
F862 69 00     	ADC #$00
F864 85 AF     	STA EAL+1
F866 60        	RTS


;====================================================================
; LOCSPH- Find specific tape header
;
LOCSPH
F867 20 AF F7  	JSR LOCTPH
F86A B0 1D     	BCS LCSPEXC+1	;$F889 return

F86C A0 05     	LDY #$05
F86E 84 9F     	STY TPTR2
F870 A0 00     	LDY #$00
F872 64 9E     	STY TPTR1

LCSPHLP
F874 C4 B7     	CPY FNMLEN
F876 F0 10     	BEQ LCSPEXC	;$F888 return CLC

F878 B1 BB     	LDA (FNPTR),Y
F87A A4 9F     	LDY TPTR2
F87C D1 B2     	CMP (CBSTPT),Y
F87E D0 E7     	BNE LOCSPH

F8B0 E6 9E     	INC TPTR1
F882 E6 9F     	INC TPTR2
F884 A4 9E     	LDY TPTR1
F886 D0 EC     	BNE LCSPHLP	;$F874

LCSPEXC
F888 18        	CLC
F889 60        	RTS


;====================================================================
; INCTPT - Bump tape pointer
;
INCTPT
F88A 20 4D F8  	JSR GETBFA
F88D E6 A6     	INC BUFPNT
F88F A4 A6     	LDY BUFPNT
F891 C0 C0     	CPY #$C0
F893 60        	RTS


;====================================================================
; PLAYMS - Print "Press Play on Tape"
;
PLAYMS
F894 20 AB F8  	JSR TPSTAT
F897 F0 1C     	BEQ TPSTEX	;$F8B5 exit

F899 A0 1B     	LDY #$1B	;"Press Play..."
F89B 20 E6 F1  	JSR MSG

WTPLAY
F89E 20 4B F9  	JSR TPSTOP
F8A1 20 AB F8  	JSR TPSTAT
F8A4 D0 F8     	BNE WTPLAY	;$F89E wait for PLAY switch

F8A6 A0 6A     	LDY #$6A	;"OK"
F8A8 4C E6 F1  	JMP MSG


;====================================================================
; TPSTAT - Check tape status
;
TPSTAT
F8AB A9 40     	LDA #%01000000	;$40
F8AD 2C 1F 91  	BIT D1ORAH	;switch sense
F8B0 D0 03     	BNE TPSTEX	;$F8B5
F8B2 2C 1F 91  	BIT D1ORAH

TPSTEX
F8B5 18        	CLC
F8B6 60        	RTS


;====================================================================
; RECDMS - Print "Press Record on Tape"
;
RECDMS
F8B7 20 AB F8  	JSR TPSTAT
F8BA F0 F9     	BEQ TPSTEX	;$F8B5

F8BC A0 2E     	LDY #$2E	;"Press Play & Record"
F8BE D0 DB     	BNE WTPLAY-3	;$F89B JSR MSG


;====================================================================
; TPREAD - Initiate tape read
;
TPREAD
F8C0 A9 00     	LDA #$00
F8C2 85 90     	STA CSTAT
F8C4 85 93     	STA IOFLG2

TPREAD1
F8C6 20 54 F8  	JSR SETBST
F8C9 20 94 F8  	JSR PLAYMS
F8CC B0 1F     	BCS TPCODE-2	;$F8ED

F8CE 78        	SEI
F8CF A9 00     	LDA #$00
F8D1 85 AA     	STA RIDATA
F8D3 85 B4     	STA BITTS
F8D5 85 B0     	STA TPCON
F8D7 85 9E     	STA TPTR1
F8D9 85 9F     	STA TPTR2
F8DB 85 9C     	STA BYTINF
F8DD A9 82     	LDA #$82
F8DF A2 0E     	LDX #$0E
F8E1 D0 11     	BNE TPCODE1	;$F8F4

;====================================================================
; TPWRIT - Initiate tape write
;
TPWRIT
F8E3 20 54 F8  	JSR SETBST
F8E6 A9 14     	LDA #$14
F8EB 85 AB     	STA RIPRTY
F8EA 20 B7 F8  	JSR RECDMS
F8ED B0 68     	BCS TPSTEX1	;$F957
;
; TPCODE - Common tape code
;
TPCODE
F8EF 78        	SEI
F8F0 A9 A0     	LDA #%10100000	;$A0
F8F2 A2 08     	LDX #%00001000	;$08

TPCODE1
F8F4 A0 7F     	LDY #%01111111	;$7F
F8F6 8C 2E 91  	STY D2IER
F8F9 8D 2E 91  	STA D2IER
F8FC 20 60 F1  	JSR SBIDLE
F8FF AD 14 03  	LDA IRQVP	;save current IRQ Vector
F902 8D 9F 02  	STA TAPIRQ
F905 AD 15 03  	LDA IRQVP+1
F908 8D A0 02  	STA TAPIRQ+1
F90B 20 FB FC  	JSR STOIRQ1	;$FCFB .X=8 set tape IRQ vectors
F90E A9 02     	LDA #$02
F910 85 BE     	STA FSBLK
F912 20 DB FB  	JSR NCHAR
F915 AD 1C 91  	LDA D1PCR
F918 29 FD     	AND #%11111101	;$FD
F91A 09 0C     	ORA #%00001100	;$0C
F91C 8D 1C 91  	STA D1PCR
F91F 85 C0     	STA CAS1
F921 A2 FF     	LDX #$FF	;setup loop
F923 A0 FF     	LDY #$FF

TPCDLP1
F925 88        	DEY
F926 D0 FD     	BNE TPCDLP1	;$F925

F928 CA        	DEX
F929 D0 F8     	BNE TPCDLP1-2	;$F923 outside loop
F92B 8D 29 91  	STA D2TM2H
F92E 58        	CLI

TPCDLP2
F92F AD A0 02  	LDA TAPIRQ+1
F932 CD 15 03  	CMP IRQVP+1
F935 18        	CLC
F936 F0 1F     	BEQ TPSTEX-5	;$F957

F938 20 4B F9  	JSR TPSTOP
F93B AD 2D 91  	LDA D2IFR
F93E 29 40     	AND #%01000000	;$40
F940 F0 ED     	BEQ TPCDLP2	;$F92F

F942 AD 14 91  	LDA D1TM1L
F945 20 34 F7  	JSR IUDTIM
F948 4C 2F F9  	JMP TPCDLP2	;$F92F




;====================================================================
; TPSTOP - Check tape stop
;
TPSTOP
F94B 	JSR (STOPVP)	;STOP
F94E 18        	CLC
F94F D0 0B     	BNE TPSTEX	;$F95C

F951 20 CF FC  	JSR RESIRQ
F954 38        	SEC
F955 68        	PLA
F956 68        	PLA

TPSPEX1
F957 A9 00     	LDA #$00
F959 8D A0 02  	STA TAPIRQ+1

TPSTEX
F95C 60        	RTS


;====================================================================
; SETRDT - Set read timing
;
SETRDT
F95D 86 B1     	STX TPCON+1
F95F A5 B0     	LDA TPCON
F961 0A        	ASL
F962 0A        	ASL
F963 18        	CLC
F964 65 B0     	ADC TPCON
F966 18        	CLC
F967 65 B1     	ADC TPCON+1
F969 85 B1     	STA TPCON+1
F96B A9 00     	LDA #$00
F96D 24 B0     	BIT TPCON
F96F 30 01     	BMI RDTSK1	;$F972

F971 2A        	ROL
F972 06 B1     	ASL TPCON+1

RDTSK1
F974 2A        	ROL
F975 06 B1     	ASL TPCON+1
F977 2A        	ROL
F978 AA        	TAX

RDTLP1
F979 AD 28 91  	LDA D2TM2L
F97C C9 15     	CMP #$15
F97E 90 F9     	BCC RDTLP1	;$F979

F980 65 B1     	ADC TPCON+1
F982 8D 24 91  	STA D2TM1L
F985 8A        	TXA
F986 6D 29 91  	ADC D2TM2H
F989 8D 25 91  	STA D2TM1L+1
F98C 58        	CLI
F98D 60        	RTS


;====================================================================
; RDTPBT - Read tape bits
;
RDTPBT
F98E AE 29 91  	LDX D2TM2H
F991 A0 FF     	LDY #$FF
F993 98        	TYA
F994 ED 28 91  	SBC D2TM2L
F997 EC 29 91  	CPX D2TM2H
F99A D0 F2     	BNE RDTPBT

F99C 86 B1     	STX TPCON+1
F99E AA        	TAX
F99F 8C 28 91  	STY D2TM2L
F9A2 8C 29 91  	STY D2TM2H
F9A5 98        	TYA
F9A6 E5 B1     	SBC TPCON+1
F9A8 86 B1     	STX TPCON+1
F9AA 4A        	LSR
F9AB 66 B1     	ROR TPCON+1
F9AD 4A        	LSR
F9AE 66 B1     	ROR TPCON+1
F9B0 A5 B0     	LDA TPCON
F9B2 18        	CLC
F9B3 69 3C     	ADC #$3C
F9B5 2C 21 91  	BIT D2ORA
F9B8 C5 B1     	CMP TPCON+1
F9BA B0 4A     	BCS RDTP4	;$FA06

F9BC A6 9C     	LDX BYTINF
F9BE F0 03     	BEQ $+3	;F9C3
F9C0 4C AD FA  	JMP STORTC	;save tape IRQs

F9C3 A6 A3     	LDX SBITCF
F9C5 30 1B     	BMI RDTP1	;$F9E2

F9C7 A2 00     	LDX #$00
F9C9 69 30     	ADC #$30
F9CB 65 B0     	ADC TPCON
F9CD C5 B1     	CMP TPCON+1
F9CF B0 1C     	BCS RDTP2	;$F9ED

F9D1 E8        	INX
F9D2 69 26     	ADC #$26
F9D4 65 B0     	ADC TPCON
F9D6 C5 B1     	CMP TPCON+1
F9D8 B0 17     	BCS RDTP3	;$F9F1

F9DA 69 2C     	ADC #$2C
F9DC 65 B0     	ADC TPCON
F9DE C5 B1     	CMP TPCON+1
F9E0 90 03     	BCC RDTPLP1	;$F9E5

RDTP1
F9E2 4C 60 FA  	JMP RDTP6A	;$FA60

RDTPLP1
F9E5 A5 B4     	LDA BITTS
F9E7 F0 1D     	BEQ RDTP4	;$FA06

F9E9 85 AB     	STA RIPRTY
F9EB D0 19     	BNE RDTP4	;$FA06

RDTP2
F9ED E6 A9     	INC RINONE
F9EF B0 02     	BCS RDTP3A	;$F9F3

RDTP3
F9F1 C6 A9     	DEC RINONE

RDTP3A
F9F3 38        	SEC
F9F4 E9 13     	SBC #$13
F9F6 E5 B1     	SBC TPCON+1
F9FB 65 92     	ADC SVXT
F9FA 85 92     	STA SVXT
F9FC A5 A4     	LDA CYCLE
F9FE 49 01     	EOR #$01
FA00 85 A4     	STA CYCLE
FA02 F0 21     	BEQ RDTP3C	;$FA25

FA04 86 D7     	STX LASTKY
FA06 A5 B4     	LDA BITTS
FA08 F0 18     	BEQ RDTPEX1	;$FA22

FA0A 2C 2D 91  	BIT D2IFR
FA0D 50 13     	BVC RDTPEX1	;$FA22

FA0F A9 00     	LDA #$00
FA11 85 A4     	STA CYCLE
FA13 A5 A3     	LDA SBITCF
FA15 10 30     	BPL RDTP6	;$FA47
FA17 30 C9     	BMI RDTP1	;$F9E2

RDTP3B
FA19 A2 A6     	LDX #$A6
FA1B 20 5D F9  	JSR SETRDT
FA1E A5 9B     	LDA TPRTY
FA20 D0 C3     	BNE RDTPLP1	;$F9E5

RDTPEX1
FA22 4C 56 FF  	JMP EOI

RDTP3C
FA25 A5 92     	LDA SVXT
FA27 F0 07     	BEQ RDTP5A	;$FA30
FA29 30 03     	BMI RDTP5	;$FA2E

FA2B C6 B0     	DEC TPCON
FA2D 2C 	.db $2C	;bit $b0e6

RDTP5
FA2E E6 B0  	INC TPCON1

RDTP5A	
FA30 A9 00     	LDA #$00
FA32 85 92     	STA SVXT
FA34 E4 D7     	CPX LASTKY
FA36 D0 0F     	BNE RDTP6	;$FA47

FA38 8A        	TXA
FA39 D0 AA     	BNE RDTPLP1	;$F9E5

FA3B A5 A9     	LDA RINONE
FA3D 30 C7     	BMI RDTP4	;$FA06

FA3F C9 10     	CMP #$10
FA41 90 C3     	BCC RDTP4	;$FA06

FA43 85 96     	STA EOTFLG
FA45 B0 BF     	BCS RDTP4	;$FA06

RDTP6
FA47 8A        	TXA
FA48 45 9B     	EOR TPRTY
FA4A 85 9B     	STA TPRTY
FA4C A5 B4     	LDA BITTS
FA4E F0 D2     	BEQ RDTPEX1	;$FA22

FA50 C6 A3     	DEC SBITCF
FA52 30 C5     	BMI RDTP3B	;$FA19

FA54 46 D7     	LSR LASTKY
FA56 66 BF     	ROR MYCH
FA58 A2 DA     	LDX #$DA
FA5A 20 5D F9  	JSR SETRDT
FA5D 4C 56 FF  	JMP EOI

RDTP6A
FA60 A5 96     	LDA EOTFLG
FA62 F0 04     	BEQ RDTP7	;$FA68

FA64 A5 B4     	LDA BITTS
FA66 F0 04     	BEQ RDTP8	;$FA6C

RDTP7
FA68 A5 A3     	LDA SBITCF
FA6A 10 85     	BPL RDTP3	;$F9F1

RDTP8
FA6C 46 B1     	LSR TPCON+1
FA6E A9 93     	LDA #$93
FA70 38        	SEC
FA71 E5 B1     	SBC TPCON+1
FA73 65 B0     	ADC TPCON
FA75 0A        	ASL
FA76 AA        	TAX
FA77 20 5D F9  	JSR SETRDT
FA7A E6 9C     	INC BYTINF
FA7C A5 B4     	LDA BITTS
FA7E D0 11     	BNE RDTP9	;$FA91

FA80 A5 96     	LDA EOTFLG
FA82 F0 26     	BEQ RDTPEX2	;$FAAA

FA84 85 A8     	STA TPRWRE
FA86 A9 00     	LDA #$00
FA88 85 96     	STA EOTFLG
FA8A A9 C0     	LDA #%11000000	;$C0
FA8C 8D 2E 91  	STA D2IER
FA8F 85 B4     	STA BITTS

RDTP9
FA91 A5 96     	LDA EOTFLG
FA93 85 B5     	STA NXTBIT
FA95 F0 09     	BEQ RDTP10	;$FAA0

FA97 A9 00     	LDA #$00
FA99 85 B4     	STA BITTS
FA9B A9 40     	LDA #%01000000	;$40
FA9D 8D 2E 91  	STA D2IER

RDTP10
FAA0 A5 BF     	LDA MYCH
FAA2 85 BD     	STA ROPRTY
FAA4 A5 A8     	LDA TPRWRE
FAA6 05 A9     	ORA RINONE
FAA8 85 B6     	STA RODATA

RDTPEX2
FAAA 4C 56 FF  	JMP EOI


;====================================================================
; STORTC - Store tape characters
;
STORTC
FAAD 20 DE FB  	JSR NCHAR
FAB0 85 9C     	STA BYTINF
FAB2 A2 DA     	LDX #$DA
FAB4 20 5D F9  	JSR SETRDT
FAB7 A5 BE     	LDA FSBLK
FAB9 F0 02     	BEQ $+2	;FABD

FABB 85 A7     	STA INBIT
FABD A9 0F     	LDA #$0F
FABF 24 AA     	BIT RIDATA
FAC1 10 17     	BPL $FADA

FAC3 A5 B5     	LDA NXTBIT
FAC5 D0 0C     	BNE $FAD3

FAC7 A6 BE     	LDX FSBLK
FAC9 CA        	DEX
FACA D0 0B     	BNE STOCHEX1	;$FAD7

FACC A9 08     	LDA #$08
FACE 20 6A FE  	JSR $FE6A
FAD1 D0 04     	BNE STOCHEX1

FAD3 A9 00     	LDA #$00
FAD5 85 AA     	STA RIDATA

STOCHEX1
FAD7 4C 56 FF  	JMP EOI

FADA 70 31     	BVS $FB0D
FADC D0 18     	BNE $FAF6

FADE A5 B5     	LDA NXTBIT
FAE0 D0 F5     	BNE STOCHEX1

FAE2 A5 B6     	LDA RODATA
FAE4 D0 F1     	BNE STOCHEX1

FAE6 A5 A7     	LDA INBIT
FAE8 4A        	LSR
FAE9 A5 BD     	LDA ROPRTY
FAEB 30 03     	BMI $FAF0
FAED 93 18     	BCC $FB07

FAEF 18        	CLC
FAF0 B0 15     	BCS $FB07
FAF2 29 0F     	AND #%00001111	;$0F
FAF4 85 AA     	STA RIDATA
FAF6 C6 AA     	DEC RIDATA
FAF8 D0 DD     	BNE STOCHEX1

FAFA A9 40     	LDA #$40
FAFC 85 AA     	STA RIDATA
FAFE 20 D2 FB  	JSR RSTTPP
FB01 A9 00     	LDA #$00
FB03 65 AB     	STA RIPRTY
FB05 F0 D0     	BEQ STOCHEX1

FB07 A9 80     	LDA #$80
FB09 85 AA     	STA RIDATA
FB0B D0 CA     	BNE STOCHEX1

FB0D A5 B5     	LDA NXTBIT
FB0F F0 0A     	BEQ $FB1B

FB11 A9 04     	LDA #$04
FB13 20 6A FE  	JSR $FE6A
FB16 A9 00     	LDA #$00
FB18 4C 97 FB  	JMP $FB97

FB1B 20 11 FD  	JSR CKWRPT
FB1E 90 03     	BCC $FB23
FB20 4C 95 FB  	JMP $FB95

FB23 A6 A7     	LDX INBIT
FB25 CA        	DEX
FB26 F0 2D     	BEQ $FB55

FB28 A5 93     	LDA IOFLG2
FB2A F0 0C     	BEQ $FB38

FB2C A0 00     	LDY #$00
FB2E A5 BD     	LDA ROPRTY
FB30 D1 AC     	CMP (SAL),Y
FB32 F0 04     	BEQ $FB38

FB34 A9 01     	LDA #$01
FB36 85 B6     	STA RODATA
FB38 A5 B6     	LDA RODATA
FB3A F0 4B     	BEQ $FB87

FB3C A2 3D     	LDX #$3D
FB3E E4 9E     	CPX TPTR1
FB40 90 3E     	BCC $FB80

FB42 A6 9E     	LDX TPTR1
FB44 A5 AD     	LDA SAL+1
FB46 9D 01 01  	STA FBUFFR+1,X
FB49 A5 AC     	LDA SAL
FB4B 9D 00 01  	STA FBUFFR,X
FB4E E8        	INX
FB4F E8        	INX
FB50 86 9E     	STX TPTR1
FB52 4C 87 FB  	JMP $FB87

FB55 A6 9F     	LDX TPTR2
FB57 E4 9E     	CPX TPTR1
FB59 F0 35     	BEQ $FB90

FB5B A5 AC     	LDA SAL
FB5D DD 00 01  	CMP FBUFFR,X
FB60 D0 2E     	BNE $FB90

FB62 A5 AD     	LDA SAL+1
FB64 DD 01 01  	CMP FBUFFR+1,X
FE67 D0 27     	BNE $FB90

FB69 E6 9F     	INC TPTR2
FB6B E6 9F     	INC TPTR2
FB6D A5 93     	LDA IOFLG2
FB6F F0 0B     	BEQ $FB7C

FB71 A5 BD     	LDA ROPRTY
FB73 A0 00     	LDY #$00
FB75 D1 AC     	CMP (SAL),Y
FB77 F0 17     	BEQ $FB90

FB79 C8        	INY
FB7A 84 B6     	STY RODATA
FB7C A5 B6     	LDA RODATA
FB7E F0 07     	BEQ $FB87

FB80 A9 10     	LDA #$10
FB82 20 6A FE  	JSR $FE6A
FB85 D0 09     	BNE $FB90

FB87 A5 93     	LDA IOFLG2
FB89 D0 05     	BNE $FB90

FB8B A8        	TAY
FB8C A5 BD     	LDA ROPRTY
FB8E 91 AC     	STA (SAL),Y
FB90 20 1B FD  	JSR INCRDP
FB93 D0 3A     	BNE $FBCF

FB95 A9 80     	LDA #$80


FB97 65 AA     	STA RIDATA
FB99 A6 BE     	LDX FSBLK
FB9B CA        	DEX
FB9C 30 02     	BMI $FBA0

FB9E 86 BE     	STX FSBLK
FBA0 C6 A7     	DEC INBIT
FBA2 F0 08     	BEQ $FBAC

FBA4 A5 9E     	LDA TPTR1
FBA6 D0 27     	BNE $FBCF

FBA8 85 BE     	STA FSBLK
FBAA F0 23     	BEQ $FBCF

FEAC 20 CF FC  	JSR RESIRQ
FBAF 20 D2 FB  	JSR RSTTPP
FBB2 A0 00     	LDY #$00
FBB4 84 AB     	STY RIPRTY
FBB6 E1 AC     	LDA (SAL),Y
FBB8 45 AB    	EOR RIPRTY
FBBA 85 AB     	STA RIPRTY
FBBC 20 1B FD  	JSR INCRDP
FBBF 20 11 FD  	JSR CKWRPT
FBC2 90 F2     	BCC $FBB6

FBC4 A5 AB     	LDA RIPRTY
FBC6 45 BD     	EOR ROPRTY
FBC8 F0 05     	BEQ $FBCF

FBCA A9 20     	LDA #$20
FBCC 20 6A FE  	JSR ISETMS1	;$FE6A
FBCF 4C 56 FF  	JMP EOI


;====================================================================
; RSTTPP - Reset tape pointer
;
RSTTPP
FBD2 A5 C2     	LDA STAL+1
FBD4 85 AD     	STA SAL+1
FBD6 A5 C1     	LDA STAL
FBD8 85 AC     	STA SAL
FBDA 60        	RTS


;====================================================================
; NCHAR - New character setup
;
NCHAR
FBDB A9 08     	LDA #$08
FBDD 85 A3     	STA SBITCF
FBDF A9 00     	LDA #$00
FBE1 85 A4     	STA  CYCLE
FBE3 85 AB     	STA RIPRTY
FBE5 85 9B     	STA TPRTY
FBE7 65 A9     	STA RINONE
FBE9 60        	RTS


;====================================================================
; TONE - Send tone to tape
;
TONE
FBEA A5 BD     	LDA ROPRTY
FBEC 4A        	LSR	;determine tone length
FBED A9 60     	LDA #$60	;set short tone timing
FBEF 90 02     	BCC TONE1	;$FBF3 C=clear, 0

TONEA
FBF1 A9 B0     	LDA #$B0	;set long tone timine

TONE1
FBF3 A2 00     	LDX #$00
FBF5 8D 28 91  	STA D2TM2L
FBF8 8E 29 91  	STX D2TM2H
FBFB AD 20 91  	LDA D2ORB
FBFE 49 0B     	EOR #%00001000	;$08
FC00 8D 20 91  	STA D2ORB
FC03 29 08     	AND #%00001011	;$0B
FC05 60        	RTS


;====================================================================
; TWRDTA - Write data to tape
;
TWRDTA
FC06 38        	SEC
FC07 66 AD     	ROR SAL+1
FC09 30 3C     	BMI TWRDEX1

FC0B A5 A8     	LDA TPRWRE
FC0D D0 12     	BNE TWRD1	;$FC21

FC0F A9 10     	LDA #$10
FC11 A2 01     	LDX #$01
FC13 20 F5 FB  	JSR TONE1+2	;$FBF5
FC16 D0 2F     	BNE TWRDEX1

FC18 E6 A8     	INC TPRWRE
FC1A A5 AD     	LDA SAL+1
FC1C 10 29     	BPL TWRDEX1
FC1E 4C 95 FC  	JMP WRLEDR

TWRD1
FC21 A5 A9     	LDA RINONE
FC23 D0 09     	BNE TWRD2+1	;$FC2B

FC25 20 F1 FB  	JSR TONEA	;$FBF1
FC28 D0 1D     	BNE TWRDEX1

TWRD2
FC2A E6 A9     	INC RINONE	;LDA #$D0
FC2C D0 19     	BNE TWRDEX1	;ORA Y

FC2E 20 EA FB  	JSR TONE
FC31 D0 14     	BNE TWRDEX1

FC33 A5 A4     	LDA CYCLE
FC35 49 01     	EOR #$01
FC37 85 A4     	STA CYCLE
FC39 F0 0F     	BEQ TWRD3	;$FC4A

FC3B A5 BD     	LDA ROPRTY
FC3D 49 09     	EOR #$01
FC3F 85 BD     	STA ROPRTY
FC41 29 01     	AND #$01
FC43 45 9B     	EOR TPRTY
FC45 85 9B     	STA TPRTY

TWRDEX1
FC47 4C 56 FF  	JMP EOI

TWRD3
FC4A 46 BD     	LSR ROPRTY
FC4C C6 A3     	DEC SBITCF
FC4E A5 A3     	LDA SBITCF
FC50 F0 3A     	BEQ TWRD6	;$FC8C
FC52 10 F3     	BPL TWRDEX1

FC54 20 DB FB  	JSR NCHAR
FC57 58        	CLI
FC58 A5 A5     	LDA CNTDN
FC5A F0 12     	BEQ TWRD4	;$FC6E

FC5C A2 00     	LDX #$00
FC5E 86 D7     	STX LASTKY
FC60 C6 A5     	DEC CNTDN
FC62 A6 BE     	LDX FSBLK
FC64 E0 02     	CPX #$02
FC66 D0 02     	BNE $+2	;FC6A

FC68 09 80     	ORA #%10000000	;$80
FC6A 85 BD     	STA ROPRTY	;$BD
FC6C D0 D9     	BNE TWRDEX1

TWRD4
FC6E 20 11 FD  	JSR CKWRPT
FC71 90 0A     	BCC TWRD5	;$FC7D
FC73 D0 91     	BNE TWRDTA

FC75 E6 AD     	INC SAL+1
FC77 A5 D7     	LDA LASTKY
FC79 85 BD     	STA ROPRTY
FC7B B0 CA     	BCS TWRDEX1

TWRD5
FC7D A0 00     	LDY #$00
FC7F B1 AC     	LDA (SAL),Y
FC81 85 BD     	STA ROPRTY
FC83 45 D7     	EOR LASTKY
FC85 85 D7     	STA LASTKY
FC87 20 1B FD  	JSR INCRDP
FCBA D0 BB     	BNE TWRDEX1

TWRD6
FC8C A5 9B     	LDA TPRTY
FCBE 49 01     	EOR #$01
FC90 85 BD     	STA ROPRTY

TPEOI
FC92 4C 56 FF  	JMP EOI


;====================================================================
; WRLEDR - Write tape leader
;
WRLEDR
FC95 C6 BE     	DEC FSBLK
FC97 D0 03     	BNE WRLDR1	;$FC9C

FC99 20 08 FD  	JSR NOMOTR

WRLDR1
FC9C A9 50     	LDA #$50
FC9E 85 A7     	STA INBIT
FCA0 A2 08     	LDX #$08
FCA2 78        	SEI
FCA3 20 FB FC  	JSR STOIRQ1	;$FCFB tape IRQs
FCA6 D0 EA     	BNE TPEOI	;$FC92

FCA8 A9 78     	LDA #$78
FCAA 20 F3 FB  	JSR TONE1	;$FBF3
FCAD D0 E3     	BNE TPEOI	;$FC92

FCAF C6 A7     	DEC INBIT
FCB1 D0 DF     	BNE TPEOI	;$FC92

FCB3 20 DB FB  	JSR NCHAR
FCB6 C6 AB     	DEC RIPRTY
FCB8 10 D8     	BPL TPEOI	;$FC92

FCBA A2 0A     	LDX #$0A
FCBC 20 FB FC  	JSR STOIRQ1	;$FCFB
FCBF 58        	CLI
FCC0 E6 AB     	INC RIPRTY
FCC2 A5 BE     	LDA FSBLK
FCC4 F0 30     	BEQ STOIRQ	;$FCF6

FCC6 20 D2 FB  	JSR RSTTPP
FCC9 A2 09     	LDX #$09
FCCB 86 A5     	STX CNTDN
FCCD D0 85     	BNE $FC54
;
; RESIRQ - Restore normal IRQ
;
RESIRQ
FCCF 08        	PHP
FCD0 78        	SEI
FCD1 20 08 FD  	JSR NOMOTR
FCD4 A9 7F     	LDA #%01111111	;$7F
FCD6 8D 2E 91  	STA D2IER
FCD9 A9 F7     	LDA #%01111111	;$F7
FCDB 8D 20 91  	STA D2ORB
FCDE A9 40     	LDA #%01000000	;$40
FCE0 8D 2B 91  	STA D2ACR
FCE3 20 39 FE  	JSR ENABTM
FCE6 AD A0 02  	LDA TAPIRQ+1
FCE9 F0 09     	BEQ RSIRQEX	;$FCF4

FCEB 8D 15 03  	STA IRQVP+1
FCEE AD 9F 02  	LDA TAPIRQ
FCF1 8D 14 03  	STA IRQVP

RSIRQEX
FCF4 28        	PLP
FCF5 60        	RTS


;====================================================================
; STOIRQ - Set IRQ vector
;
STOIRQ
FCF6 20 CF FC  	JSR RESIRQ
FCF9 F0 97     	BEQ TPEOI	;$FC92
STOIRQ1
FCFB BD E9 FD  	LDA RATS3,X	;$FDE9,X	;TPVECS
FCFE 8D 14 03  	STA IRQVP
FD01 BD EA FD  	LDA RATS3+1,X	;$FDEA,X
FD04 8D 15 03  	STA IRQVP+1
FD07 60        	RTS


;====================================================================
; NOMOTR - Kill tape motor
;
NOMOTR
FD08 AD 1C 91  	LDA D1PCR
FD0B 09 0E     	ORA #%00001110	;$0E
FD0D 8D 1C 91  	STA D1PCR
FD10 60        	RTS


;====================================================================
; CKWRPT - Check read/write pointer
;
CKWRPT
FD11 38        	SEC
FD12 A5  AC    	LDA SAL
FD14 E5  AE    	SBC EAL
FD16 A5  AD    	LDA SAL+1
FD18 E5  AF    	SBC EAL+1
FD1A 60        	RTS


;====================================================================
; INCRDP - Bump read/write pointer
;
INCRDP
FD1B E6  AC    	INC SAL
FD1D D0  02    	BNE INCRSK	;$FD21

FD1F E6  AD    	INC SAL+1

INCRSK
FD21 60        	RTS


;####################################################################
; Power-on RESET entry
;####################################################################
RESET
FD22 A2 FF     	LDX #$FF
FD24 78        	SEI
FD25 9A        	TXS
FD26 D8        	CLD
FD27 20 3F FD  	JSR SCNROM
FD2A D0 03     	BNE SKIPA0	;$FD2F

FD2C 6C 00 A0  	JMP (A0BASE)

SKIPA0
FD2F 20 8D FD  	JSR RAMTAS
FD32 20 52 FD  	JSR RESTOR
FD35 20 F9 FD  	JSR IOINIT
FD38 20 18 E5  	JSR CINT1
FD3B 58        	CLI
FD3C 6C 00 C0  	JMP (BASICRB)


;====================================================================
; SCNROM - Scan ROM areas for Autostart ROM signature
;
SCNROM
FD3F A2 05     	LDX #$05

SCNLOOP
FD41 BD 4C FD  	LDA SCANEX,X	;$FD4C,X
FD44 DD 03 A0  	CMP $A003,X
FD47 D0 03     	BNE SCANEX	;$FD4C

FD49 CA        	DEX
FD4A D0 F5     	BNE SCNLOOP	;$FD41

SCANEX
FD4C 60        	RTS
;
; ROMSIG - Autostart ROM signature
;
ROMSIG
FD4D .db 'A0', $C3, $C2, $CD		;"A0CBM"


;====================================================================
; IRESTR - Restore KERNEL vectors (internal)
;
IRESTR
FD52 A2  6D    	LDX FIXUP2	;#$6D
FD54 A0  FD    	LDY FIXUP2+1	;#$FD $FD6D KERNEL vecs
FD56 18        	CLC
;
; IVECTR - Change vectors for user
;
IVECTR
FD57 86 C3     	STX MEMUSS
FD59 84 C4    	STY MEMUSS+1
FD5B A0 1F     	LDY #$1F

VECLOOP
FD5D B9 14 03  	LDA IRQVP,Y
FD60 B0 02     	BCS VECSK	;$FD64

FD62 B1 C3     	LDA (MEMUSS),Y

VECSK
FD64 91 C3     	STA (MEMUSS),Y
FD66 99 14 03  	STA IRQVP,Y
FD69 88        	DEY
FD6A 10 F1     	BPL VECLOOP	;$FD5D
FD6C 60        	RTS

;
;KERNEL Vectors
;
KNRLSV
FD6D .dw $EABF, $FED2, $FEAD, $F40A
FD75 .dw $F34A, $F2C7, $F309, $F3F3
FD7D .dw $F20E, $F27A, $F770, $F1F5 
FD85 .dw $F3EF, $FED2, $F549, $F685


;====================================================================
; RAMTAS - Initialize system contents
;
RAMTAS
FD8D A9 00     	LDA #$00
FD8F AA        	TAX
FD90 95 00     	STA USRPOK,X
FD92 9D 00 02  	STA BUF,X
FD95 9D 00 03  	STA ERRVPT,X
FD98 E8        	INX
FD99 D0 F5     	BNE $FD90

FD9B A2 3C     	LDX #$3C
FD9D A0 03     	LDY #$03
FD9F 86 B2     	STX CBSTPT
FDA1 64 B3     	STY CBSTPT+1
FDA3 85 C1     	STA STAL
FDA5 85 97     	STA REGSAV
FDA7 8D 81 02  	STA OSSTAR
FDAA A8        	TAY
FDAB A9 04     	LDA #$04
FDAD 85 C2     	STA STAL+1

RAMTASLP1
FDAF E6 C1     	INC STAL
FDB1 D0 02     	BNE RAMTAS1	;$FDB5

FDB3 E6 C2     	INC STAL+1

RAMTAS1
FDB5 20 91 FE  	JSR MEMTST
FDB8 A5 97     	LDA REGSAV
FDBA F0 22     	BEQ RAMTAS3	;$FDDE
FDBC B0 F1     	BCS RAMTASLP1	;$FDAF

FDBE A4 C2     	LDY STAL+1
FDC0 A6 C1     	LDX STAL
FDC2 C0 20     	CPY #$20
FDC4 90 25     	BCC RATS3+2	;$FDEB

FDC6 C0 21     	CPY #$21
FDC8 B0 08     	BCS RAMTAS2	;$FDD2

FDCA A0 1E     	LDY #$1E
FDCC 8C 88 02  	STY HIPAGE

RAMTAS1A
FDCF 4C 7B FE  	JMP STOTOP	;$FE7B

RAMTAS2
FDD2 A9 12     	LDA #$12
FDD4 8D 82 02  	STA OSSTAR+1
FDD7 A9 10     	LDA #$10
FDD9 8D 88 02  	STA HIPAGE
FDDC D0 F1     	BNE RAMTAS1A	;$FDCF

RAMTAS3
FDDE 90 CF     	BCC RAMTASLP1	;$FDAF

FDE0 A5 C2     	LDA STAL+1
FDE2 8D 82 02  	STA OSSTAR+1
FDE5 85 97     	STA REGSAV
FDE7 C9 11     	CMP #$11

RATS3
FDE9 90 C4     	BCC RAMTASLP1	;$FDAF

I6561LP
FDEB 20 C3 E5  	JSR V6561I-2	;$E5C3
FDEE 4C EB FD  	JMP I6561LP	;$FDEB


;====================================================================
; TAPEVC - Tape IRQ vectors
;
TAPEVC
FDF1 .dw $FCA8, $FC0B, $EABF, $F98E


;====================================================================
; IOINIT - Initialize I/O
;
IOINIT
FDF9 A9 7F     	LDA #$7F
FDFB 8D 1E 91  	STA D1IER
FDFE 8D 2E 91  	STA D2IER
FE01 A9 40     	LDA #$40
FE03 8D 2B 91  	STA D2ACR
FE06 A9 40     	LDA #$40
FE08 8D 1B 91  	STA D1ACR
FE0B A9 FE     	LDA #$FE
FE0D 8D 1C 91  	STA D1PCR
FE10 A9 DE     	LDA #$DE
FE12 8D 2C 91  	STA D2PCR
FE15 A2 00     	LDX #$00
FE17 8E 12 91  	STX $911
FE1A A2 FF     	LDX #$FF
FE1C 8E 22 91  	STX D2DDRB
FE1F A2 00     	LDX #$00
FE21 8E 23 91  	STX D2DDRA
FE24 A2 80     	LDX #$80
FE26 8E 13 91  	STX D1DDRB
FE29 A2 00     	LDX #$00
FE2B 8E 1F 91  	STX D1ORAH
FE2E 20 84 EF  	JSR SCLK1
FE31 A9 82     	LDA #$82
FE33 8D 1E 91  	STA D1IER
FE36 20 8D EF  	JSR SCLK0
;
; ENABTM - Enable timer
;
ENABTM
FE39 A9 C0     	LDA #$C0
FE3B 8D 2E 91  	STA D2IER
FE3E A9 89     	LDA #$89
FE40 8D 24 91  	STA D2TM1L
FE43 A9 42     	LDA #$42
FE45 8D 25 91  	STA D2TM1L+1
FE48 60        	RTS


;====================================================================
; ISETNM - Set filename (internal)
;
ISETNM
FE49 85 B7     	STA FNMLEN
FE4B 86 BB     	STX FNPTR
FE4D 84 BC     	STY FNPTR+1
FE4F 60        	RTS


;====================================================================
; ISETLF - Set logical file parameters (internal)
;
ISETLF
FE50 85 88     	STA $88
FE52 86 BA     	STX CHANNL
FE54 84 B9     	STY SECADR
FE56 60        	RTS


;====================================================================
; IRDST - Get I/O status word (internal)
;
IRDST
FE57 A5 BA     	LDA CHANNL
FE59 C9 02     	CMP #$02
FE5B D0 0B     	BNE ISETMS+2	;$FE68

FE5D AD 97 02  	LDA RSSTAT
FE60 A9 00     	LDA #$00
FE62 8D 97 02  	STA RSSTAT
FE65 60        	RTS
	

;====================================================================
; ISETMS - Control OS messages (internal)
;
ISETMS
FE66 85 9D     	STA CMDMOD
FE68 A5 90     	LDA CSTAT

ISETMS1
FE6A 05 90     	ORA CSTAT
FE6C 85 90     	STA CSTAT
FE6E 60        	RTS


;====================================================================
; ISETTO - Set IEEE timeout (internal)
;
ISETTO
FE6F 8D 85 02  	STA STIMOT
FE72 60        	RTS


;====================================================================
; IMEMTP - Set/read top of memory (internal)
;
IMEMTP
FE73 90 06     	BCC STOTOP	;$FE7B
FE75 AE 83 02  	LDX OSTOP
FE78 AC 84 02  	LDY OSTOP+1

STOTOP
FE7B 8E 83 02  	STX OSTOP
FE7E 8C 84 02  	STY OSTOP+1
FE81 60        	RTS


;====================================================================
; IMEMBT - Set/read bottom of memory  (internal)
;
IMEMBT
FE82 90 06     	BCC STOBOT	;$FE8A
FE84 AE 81 02  	LDX OSSTAR
FE87 AC 82 02  	LDY OSSTAR+1

STOBOT
FE8A 8E 81 02  	STX OSSTAR
FE8D 8C 82 02  	STY OSSTAR+1
FE90 60        	RTS


;====================================================================
; MEMTST - Test memory
;
MEMTST
FE91 B1 C1     	LDA (STAL),Y
FE93 AA        	TAX
FE94 A9 55     	LDA #%01010101	;$55
FE96 91 C1     	STA (STAL),Y
FE98 D1 C1     	CMP (STAL),Y
FE9A D0 08     	BNE MEMTS1	;$FEA4

FE9C 6A        	ROR
FE9D 91 C1     	STA (STAL),Y
FE9F D1 C1     	CMP (STAL),Y
FEA1 D0 01     	BNE MEMTS1	;$FEA4
FEA3 A9 	.db $A9	;LDA #$18

MEMTS1
FEA4 18     	CLC	 
FEA5 8A        	TXA
FEA6 91 C1     	STA (STAL)
FEA8 60        	RTS


;====================================================================
; NMI - NMI transfer entry
;====================================================================
NMI
FEA9 78        	SEI
FEAA 6C 18 03  	JMP (NMIVP)	;$FEAD


;====================================================================
; LNKNMI - Link to NMI code
;
LNKNMI
FEAD 48        	PHA
FEAE 8A        	TXA
FEAF 48        	PHA
FEB0 98        	TYA
FEB1 48        	PHA
FEB2 AD 1D 91  	LDA D1IFR
FEB5 10 48     	BPL WARM2-3	;$FEFF EOI

FEB7 2D 1E 91  	AND D1IER
FEBA AA        	TAX
FEBB 29 02     	AND #%00000010	;$02
FEBD F0 1F     	BEQ WARM1	;$FEDE

FEBF 20 3F FD  	JSR SCNROM
FEC2 D0 03     	BNE LNKNMI1	;$FEC7 skip A0 init

FEC4 6C 02 A0  	JMP (A0BASE+2)

LNKNMI1
FEC7 2C 11 91  	BIT D1OUTA
FECA 20 34 F7  	JSR IUDTIM
FECD 	JSR (STOPVP)	;STOP
FED0 D0 2B     	BNE WARM2-3	;$FEFF EOI

;====================================================================
; WARMST - Default USER vector
;
WARMST
FED2 20 52 FD  	JSR RESTOR
FED5 20 F9 FD  	JSR IOINIT
FED8 20 18 E5  	JSR CINT1
FEDB 6C 02 C0  	JMP (BASICRB+2)

WARM1
FEDE AD 1E 91  	LDA D1IER
FEE1 09 80     	ORA #%10000000	;$80
FEE3 48        	PHA
FEE4 A9 7F     	LDA #%01111111	;$7F
FEE6 8D 1E 91  	STA D1IER
FEE9 8A        	TXA
FEEA 29 40     	AND #$40
FEEC F0 14     	BEQ WARM2	;$FF02

FEEE A9 CE     	LDA #%11001110	;$CE
FEF0 05 B5     	ORA NXTBIT
FEF2 8D 1C 91  	STA D1PCR
FEF5 AD 14 91  	LDA D1TM1L
FEF8 68        	PLA
FEF9 8D 1E 91  	STA D1IER
FEFC 20 A3 EF  	JSR SSEND
FEFF 4C 56 FF  	JMP EOI

WARM2
FF02 8A        	TXA	;serial NMI
FF03 29 20     	AND #%00100000	;$20
FF05 F0 25     	BEQ WARM3	;$FF2C

FF07 AD 10 91  	LDA D1OUTB
FF0A 29 01     	AND #%00000001	;$01
FF0C 85 A7     	STA INBIT
FF0E AD 18 91  	LDA D1TM2L
FF11 E9 16     	SBC #$16
FF13 6D 99 02  	ADC BAUDOF
FF16 8D 18 91  	STA D1TM2L
FF19 AD 19 91  	LDA D1TM2L+1
FF1C 6D 9A 02  	ADC BAUDOF+1
FF1F 8D 19 91  	STA D1TM2L+1
FF22 68        	PLA
FF23 8D 1E 91  	STA D1IER
FF26 20 36 F0  	JSR SERRX
FF29 4C 56 FF  	JMP EOI

WARM3
FF2C 8A        	TXA
FF2D 29 10     	AND #%00010000	;$10
FF2F F0 25     	BEQ EOI

FF31 AD 93 02  	LDA M51CTR
FF34 29 0F     	AND #%00001111	;$0F
FF36 D0 00     	BNE $+1	;$FF38
FF38 0A        	ASL
FF39 AA        	TAX
FF3A BD 5A FF  	LDA R232TB-2,X	;$FF5A,X
FF3D 8D 18 91  	STA D1TM2L
FF40 BD 5B FF  	LDA R232TB-1,X	;$FF5B,X
FF43 8D 19 91  	STA D1TM2L+1
FF46 AD 10 91  	LDA D1OUTB
FF49 68        	PLA
FF4A 09 20     	ORA #$20
FF4C 29 EF     	AND #$EF
FF4E 8D 1E 91  	STA D1IER
FF51 AE 98 02  	LDX BITNUM
FF54 86 A8     	STX TPRWRE
;
; EOI - End of Interrupt external entry point
;
EOI
FF56 68        	PLA
FF57 A8        	TAY
FF58 68        	PLA
FF59 AA        	TAX
FF5A 68        	PLA
FF5B 40        	RTI


;====================================================================
; 232TBL - Baud rate tables
;
R232TB
FF5C .db $92, $27, $40, $1A, $C6, $11, $74, $0E
FF64 .db $EE, $0C, $45, $06, $F1, $02, $46, $01
FF6C .db $B8, $00, $71, $00, $2A, $00

;====================================================================
; IRQ - IRQ transfer point
;====================================================================
IRQ
FF72 46        	PHA
FF73 8A        	TXA
FF74 48        	PHA
FF75 98        	TYA
FF76 48        	PHA
FF77 BA        	TSX
FF78 BD 04 01  	LDA FBUFFR+4,X	;$0104,X
FF7B 29 10     	AND #%00010000	;$10	breakpoint or IRQ
FF7D F0 03     	BEQ BRKSKIP	;$FF82

FF7F 6C 16 03  	JMP (BRKVP)

BRKSKIP
FF82 6C 14 03  	JMP (IRQVP)
 
FF85 .dw $FFFF
FF87 .dw $FFFF		; padding


;====================================================================
; - Vector table
;
FF8A 4C 52 FD  JMP IRESTR		;$FD52 RESTOR
FF8D 4C 57 FD  JMP IVECTR		;$FD57 VECTOR
FF90 4C 66 FE  JMP ISETMS		;$FE66 SETMSG
FF93 4C C0 EE  JMP ISECND		;$EEC0 SECND
FF96 4C CE EE  JMP ITKSA		;$EECE
FF99 4C 73 FE  JMP IMEMTP		;$FE73
FF9C 4C 82 FE  JMP IMEMBT		;$FE82
FF9F 4C 1E EB  JMP ISCNKY		;$EB1E
FFA2 4C 6F FE  JMP ISETTO		;$FE6F SETTMO
FFA5 4C 19 EF  JMP IACPTR		;$EF19 ACPTR
FFA8 4C E4 EE  JMP ICIOUT		;$EEE4
FFAB 4C F6 EE  JMP IUNTLK		;$EEF6
FFAE 4C 04 EF  JMP IUNLSN		;$EF04
FFB1 4C 16 EE  JMP ILISTN		;$EE16 
FFB4 4C 14 EE  JMP ITALK		;$EE14
FFB7 4C 57 FE  JMP IRDST		;$FE57 READST
FFBA 4C 50 FE  JMP ISETLF		;$FE50 SETLFS
FFBD 4C 49 FE  JMP ISETNM		;$FE49
FFC0 6C 1A 03  JMP (OPENVP)		;$F40A OPEN
FFC3 6C 1C 03  JMP (CLOSVP)		;$F34A CLOSE
FFC6 6C 1E 03  JMP (CKINVP)		;$F2C7 CHKIN
FFC9 6C 20 03  JMP (CKOTVP)		;$F309 CHKOUT
FFCC 6C 22 03  JMP (CLCHVP)		;$F3F3 CLRCH
FFCF 6C 24 03  JMP (CHINVP)		;$F20E CHRIN
FFD2 6C 26 03  JMP (CHOTVP)		;$F27A CHROUT
FFD5 4C 42 F5  JMP ILOAD		;$F542
FFD8 4C 75 F6  JMP ISAVE		;$F675
FFDB 4C 67 F7  JMP ISETTM		;$F767 SETTIM
FFDE 4C 60 F7  JMP IRDTIM		;$F760
FFE1 6C 28 03  JMP (STOPVP)		;$F770 STOP
FFE4 6C 2A 03  JMP (GTINVP)		;$F1F5 GETIN
FFE7 6C 2C 03  JMP (CLALVP)		;$F3EF CLALL
FFEA 4C 34 F7  JMP IUDTIM		;$F734
FFED 4C 05 E5  JMP ISCREN		;$E505
FFF0 4C 0A E5  JMP IPLOT		;$E50A
FFF3 4C 00 E5  JMP IOBASE		;$E500
;
;Unused vectors
;
FFF6 .dw $FFFF
FFF8 .dw $FFFF


;====================================================================
; - Power-on Vectors
;
FFFA .dw NMI		;$FEA9
FFFC .dw RESET		;$FD22
FFFE .dw IRQ		;$FF72
VIC-20 Kernel ROM	Page 6
03/13/97 2:23 PM





