
start ldx #int
 STX $f3c8
 lda #3
 sta line
 lda #%00010101
 lda #%10010101
 sta line polled tx int rx
 lda #suspec suspend character
 sta suspend
 ldx #startq
 stx inp
 stx outp set up line que
 clr count
 clr fcs
 lda #xon
 sta lastf
 clr monito
 clr tmode
 clr pnum
 clr pdlen
 clr ptype
 clr size
 clr chksum
 clr fld
 clr rstat
 clr ebqmod
 clr datind
 clr chebo
 clr kerchr
 clr delay
 lda #dmaxtr
 sta maxtry
 lda #debq
 sta rebq
 sta sebq
 lda #dpadln
 sta rpad
 sta spad
 lda #dpadch
 sta rpadch
 sta spadch
 lda #deol
 sta reol
 sta seol
 lda #dpakln
 sta rpsiz
 sta spsiz
 lda #dtime
 sta rtime
 sta stime
 lda #dquote
 sta rquote
 sta squote
 cli
 jmp main

 FCB $74,$35,$7A,$29,$6C,$8B,$77,$32,$68,$8C,$79,$36,$70,$30,$71,$8D
main equ * main loop and despatcher
 ldy #$3000
 sty point
 ldx #prompt
 jsr pstr issue welcome prompt
 ldx #menu1
 jsr pstr find out what user wants to do
 lda cons+1
 lda cons+1 clean i/f
 jsr cinput
 jsr coutch echo reply
 cmpa #'0
 lbeq term term emulation to line
 cmpa #'2
 lbeq send file transfer (kermit)
 cmpa #'1
 lbeq flexex return to flex
 cmpa #'3
 lbeq receve receive a file (kermit)
 cmpa #'4
 lbeq close
 cmpa #'5
 beq monon
 cmpa #'6
 beq monoff
 bra main

monon sta monito
mmsg ldx #mdone
 jsr pstr
 bra main

monoff clr monito
 bra mmsg

*************************************************
*terminal emulation******************************

term equ *
 ldx #escstr tell user how tp break out
 jsr pstr
terml jsr cinchk any console i/p
 beq lhand no
 bit b #$10 test for <break>
 bne berr yes
 jsr cinput read data
 cmpa suspend
 lbeq main    exit at user request

sendl jsr loutch send it to line
 bra lhand

berr lda cons+1 set line i/f to space
 sei
 lda #%11110101
 sta line
 ldx #$ffff
wait dex
 INX
 DEX
 bne wait
 lda #%10110101 restore i/f
 sta line
 cli

lhand equ *
 jsr coutck ok to tx?
 beq terml no
 tst count que empty?
 beq terml yes
 jsr unque
 jsr coutch send it
 bra terml

************************************
flexex lda #$03   return to flex
 sta line reset i/f causing ints
 jmp $cd03 and warmstart to flex
*********************************

************************************
*line handler and other subrs.

qures equ *
 sei
 pshs x
 ldx #startq
 stx inp
 stx outp
 clr count
 puls x
 cli
 rts

cinchk equ *
 pshs a see if data from console
 ldb cons
 bitb #1
 puls a,pc

cinput bsr cinchk
 beq cinput no rxd
 lda cons+1
 anda #$7f
 rts

loutck pshs a see if line ok to tx
 lda line
 bit a #2
 puls a,pc

telppc equ *
loutch bsr loutck
 beq loutch o/p to line
 sta line+1
 rts

pstr lda #$0d
 jsr couts
 lda #$0a
 jsr couts
pstrs lda 0,x+ send string to console
 cmpa #eom
 beq pstre end of message
 jsr couts send char
 bra pstrs
pstre rts

getplc equ *
 ldy #$ffff abort i/p timeout timer
getplt cmpy #$0000
*beq toexit timeout occured
 leay -1,y keep timing
 tst count
 bne unque got data
 jsr cinchk
 beq getplt no console rx
 jsr cinput get data
 cmpa suspend
 bne getplt not abort
toexit leas 2,s equiv to an rts
 jmp rpkfls handle console abort back in kermit
unque equ * count must be checked as non 0 before entry
 sei
 pshs b,x
 ldx outp
 lda 0,x+ read char from line buffer
 cmpx #end
 bne un1
 ldx #startq
un1 stx outp
 dec count
 ldb count
 cli
 cmpb #xlo
 bne unx
 ldb #xon  send xon if reqd
 cmpb lastf last code sent?
 beq unx was an xon !
 stb lastf
 stb fcs set up for tx of an xon
 ldb #%10110101
 stb line set tx int on
unx puls b,x,pc

couts jsr coutck
 beq couts
 bra coutch

coutch equ *
 sta cons+1 send data to console
cexit rts

coutcr jsr coutck
 beq coutcr
 bsr coutch o/p data
 cmpa #cr
 bne cexit
 pshs a
 lda #lf if cr then crlf
coutlf jsr coutck
 beq coutlf
 jsr coutch
 puls a get back cr !
 rts


coutck equ * see if can send to console
 pshs a
 lda cons
 bita #2
 puls a,pc


