;ECHO
;Special echo processing is performed here.
;DEL will backspace and erase the previous character.
;^U will erase the entire line by backspacing and erasing.
;DELs are handled by the old backspace-and-erase game.
;Special handling must be performed if we are deleting a <TAB>.
;D6 contains the character being deleted.
RUBOUT: CMPB D6,#'I-'@ ;was it a tab?
BEQ RBTB ; yes
;DEL was of a printable character - queue up the backspace sequence
KRTG: MOV #3,D3 ;set character count
LEA A6,ERUB ;set buffer address
MOV A6,D1 ; into d1
TRMBFQ ;queue the backspace sequence
RTN
ERUB: BYTE 10,40,10,0
;DEL was of a <TAB> - calculate how big the <TAB> was and backup over it.
RBTB: CLR D3 ;preclear D3
MOVW T.POB(A5),D3 ;set beginning position count
MOV T.ICC(A5),D2 ;set input character count
MOV T.IBF(A5),A6 ;set input buffer base
KRTS: DEC D2 ;done with scan?
BMI KRTQ ; yes
MOVB (A6)+,D1 ;scan forward calculating position
CMPB D1,#11 ;<TAB>
BEQ KRTT
CMPB D1,#15 ;<CR>
BEQ KRTC
CMPB D1,#33 ;<ESC>
BEQ KRTI
CMPB D1,#40 ;control character
BLO KRTS
CMPB D1,#172
BHI KRTS
KRTI: INC D3 ;increment position for one character
BR KRTS
KRTT: ADD #10,D3 ;adjust position for <TAB>
AND #^C7,D3
BR KRTS
KRTC: CLR D3 ;clear position for <CR>
BR KRTS
KRTQ: COM D3 ;calculate necessary backspaces
AND #7,D3
INC D3
MOV #10,D1 ;set immediate backspace character
TRMBFQ ;queue the backspaces
ECHX: RTN
;Echo a control-U by erasing the entire line.
CTRLU: TST D6 ;no action if nothing to erase
BEQ CTUX
CLR D3 ;preclear D3
MOVW T.POO(A5),D3 ;calculate backspace number to erase the line
SUBW T.POB(A5),D3
BEQ ECHX
CMP D3,T.ILS(A5) ;insure not greater than terminal width
BLOS CLUA
MOV T.ILS(A5),D3
CLUA: MOV #10,D1 ;queue up backspaces
TRMBFQ
ASL D1,#2 ;queue up spaces
TRMBFQ
MOV #10,D1 ;queue up backspaces
TRMBFQ
CTUX: RTN
;INP
;Input character processing subroutine.
;Return a negative flag to indicate possible multi-byte key codes.
;Detect a negative flag which indicates the multi-byte processing return.
INP: AND #177,D1 ;strip char to 7 bits
LCC #0
RTN
PAGE
;CRT
;Special crt control processing.
;D1 contains the control code for X,Y positioning or special commands.
;If D1 is positive we have screen positioning (row in hi byte, col in lo).
;If D1 is negative we have the special command in the low byte.
CRT: TSTW D1 ;is it cursor position?
BMI CRTS ; no
;Special commands - D1 contains the command code in the low byte
CRTS: AND #377,D1 ;strip the high byte
BNE CRTU ; and branch unless clear screen
TTYI ;special case for clear screen
BYTE LI,28.,0
EVEN
;output some <NUL>s after screen-oriented functions
CRTZ: MOV #45.,D0
CLR D1
10$: TTY
SOB D0,10$
RTN
;Command processing per director tables
CRTU: PUSH A2 ;save A2
ASL D1 ; times 2 (word offset).
CMP D1,#CRCB-CRCA ;check for valid code
BHI CRTX ; and bypass if bad
LEA A2,CRCA-2 ;index the table
ADD D1,A2 ;add command code
MOVW @A2,D1 ;pick up data field offset
ADD D1,A2 ;make absolute data address
TTYL @A2 ;print the data field
CMPB @A2,#36 ;sleep if home command
BEQ CRTXZ
CMPB 1(A2),#100 ;sleep if erase command
BHI CRTXZ
CRTX: POP A2 ;restore A2
RTN
CRTXZ: POP A2 ;restore A2
BR CRTZ ; and go output nulls
;Byte offset and data tables follow for all commands
CRCA: WORD C1-.,C2-.,C3-.,C4-.,C5-.,C6-.,C7-.,C8-.
WORD C9-.,C10-.,C11-.,C12-.,C13-.,C14-.,C15-.,C16-.
CRCB:
PAGE
DEFINE CRT CODE1,CODE2,CODE3
IF NB,CODE1,BYTE CODE1
IF NB,CODE2,BYTE CODE2
IF NB,CODE3,BYTE CODE3
BYTE 0
ENDM
C0: CRT ;clear screen
C1: CRT LI,22 ;cursor home
C2: CRT CR ;cursor return
C3: CRT LI,14 ;cursor up
C4: CRT LF ;cursor down
C5: CRT BS ;cursor left
C6: CRT 20 ;cursor right
C7: CRT LI,25 ;lock keyboard
C8: CRT LI,6 ;unlock keyboard
C9: CRT LI,17 ;erase to end of line
C10: CRT LI,'W-'@ ;erase to end of screen (background only)
C11: CRT LI,31 ;low intensity
C12: CRT LI,37 ;high intensity
C13: CRT LI,37 ;enable prot. fields
C14: CRT LI,31 ;disable prot. fields
C15: CRT LI,19. ;delete line
C16: CRT LI,26. ;insert line
EVEN