\ < Virtual terminal program.
\ Edit  line-modes  to reflect your serial line configuration.
\
\ line-modes    initializes the serial line.
\ connect       go into virtual terminal mode.
\
\ > Type  ESC CR   to get back to Forth.

only forth also definitions
\ needs modem  fload ??environment??\modem.fth before this

only forth also  modem also definitions decimal

2 constant connect#channel
0 constant disconnect?

: >modem  ( -- )
	false is disconnect?
	begin	key? if key m-emit then
		disconnect? ?exit
	again ;
: ascii-emit	( char -- )
	temp-single dup bl >= if emit exit then
	case	d# 00 of			endof	\ nothing
		d# 07 of	beep		endof	\ bell
		d# 08 of	1 backspaces	endof	\ bs
		d# 09 of	1 .tab		endof	\ tab
		d# 10 of	cr		endof	\ lf
		d# 11 of	??cr cr		endof	\ vt
		d# 12 of	erase-screen	endof	\ ff
		d# 13 of	at-xy? nip 0 swap at-xy endof	\ cr
		h# 11 of	beep		endof
		h# 18 of	delete-line	endof	\ can
		dup dark [char] @ + emit  light
	endcase ;
\ Listen to the modem and send the characters to the display
forth definitions
task: listener
: modem>	( -- )
	listener activate multi
	connect#channel use-channel
	begin m-key ascii-emit again ;
: line-modes	( -- )
	9600-baud 1-stop-bit 8-bits no-parity rts/cts set-line ;

defer log-in	' noop is log-in
: connect	( -- )
	single connect#channel m-open
	multi line-modes modem>
	log-in >modem
	listener sleep m-close ;
