;TITLE 'Liberty FREEDOM 200 Terminal Setup program  -  W. Meyer -   6 Mar 84'
;
; Originally written in 1983 by W. Meyer to set up function keys on Falco
; TS-1 terminal.  Modified 14 Feb 84 by W. Meyer for use with the Liberty
; FREEDOM 200 terminal.  Note that CP/M function 6 is used to send the
; programming strings.  This is necessary due to the fact that the Liberty
; uses ^I as the address of one of its keys.	-- WM
;
; All rights reserved, including the right to offer this program commercially.
; Released into the public domain on 6 Mar 84 by W. Meyer for personal use and
; distribution.
;
CIN:	EQU	10
COUT:	EQU	9
CONBUF:	EQU	1000H
;
CR:	EQU	0DH
LF:	EQU	0AH
ESC:	EQU	1BH
DEL:	EQU	7FH
;
CNTLA:	EQU     'A'-'@'
CNTLB:  EQU     'B'-'@'
CNTLC:  EQU     'C'-'@'
CNTLD:  EQU     'D'-'@'
CNTLE:  EQU     'E'-'@'
CNTLF:  EQU     'F'-'@'
CNTLG:  EQU     'G'-'@'
CNTLH:  EQU     'H'-'@'
CNTLI:  EQU     'I'-'@'
CNTLJ:  EQU     'J'-'@'
CNTLK:  EQU     'K'-'@'
CNTLL:  EQU     'L'-'@'
CNTLM:  EQU     'M'-'@'
CNTLN:  EQU     'N'-'@'
CNTLO:  EQU     'O'-'@'
CNTLP:  EQU     'P'-'@'
CNTLQ:  EQU     'Q'-'@'
CNTLR:  EQU     'R'-'@'
CNTLS:  EQU     'S'-'@'
CNTLT:  EQU     'T'-'@'
CNTLU:  EQU     'U'-'@'
CNTLV:  EQU     'V'-'@'
CNTLW:  EQU     'W'-'@'
CNTLX:  EQU     'X'-'@'
CNTLY:	EQU	'Y'-'@'
CNTLZ:  EQU     'Z'-'@'
CNTLUAR:  EQU	'^'-'@'
;
EXIT:	EQU	0
BDOS:	EQU	5
;
	ORG	0100H
;
MAIN:
	CALL	CLRSCRN		; clear the screen
        CALL	DISPMENU        ; ..and display the menu
        CALL	GETRESP         ; ..then wait for operator choice
        JMP	DONE
;
CLRSCRN:
        LXI	D,CLRMSG        ; point to clear screen string
        MVI	C,9             ; ..and send it
        CALL	BDOS
        RET
;
DISPMENU:
        LXI	D,MENUMSG       ; point to menu string
        MVI	C,9             ; ..and send it
        CALL	BDOS
        RET
;
GETRESP:
        MVI	C,CIN           ; wait for response
	LXI	D,CONBUF
	MVI	A,01H		;plus cr
	STAX	D
        CALL	BDOS
	LDA	CONBUF+02H
        ANI	0FH             ; mask ascii offset
        JZ	DONE            ; zero means bail out
	CPI	A,01H		;mess 1
	JZ	MESSN1
	CPI	A,02H
	JZ	MESSN2
	CPI	A,03H
	JZ	MESSN3
DONE:
        LXI	D,CLRMSG        ; point to clear screen string
        MVI	C,9             ; ..and send it
        CALL	BDOS
	JMP	EXIT
;
MESSN1:	LXI	H,MSG1
	CALL	SNDMES
	JMP	DONE
;
;
MESSN2:	LXI	H,MSG2
	CALL	SNDMES
	JMP	DONE
;
;
MESSN3:	LXI	H,MSG3
	CALL	SNDMES
	JMP	DONE
;
;	
SNDMES:
	MOV	A,M	; get char
        CPI	'$'	; done?
        RZ       	; yes
        MOV	E,A     ; else send char
        MVI	C,6     ; using direct i/o
	PUSH	H
        CALL	BDOS
	POP	H
        INX	H       ; next char
        JMP	SNDMES
;
;
CLRMSG:
	DB	ESC,'*$'
;
MENUMSG:
       	DB	'Freedom 200 Function Key Setup Program -- WM   6 Mar 84'
        DB      CR,LF,LF
        DB      '  1)   Standard CP/M Utility Keys',CR,LF
        DB      '  2)   Standard Wordstar Functions',CR,LF
        DB      '  3)   Enhanced Electric Blackboard Functions',CR,LF
        DB      '  4)   ',CR,LF
        DB      '  5)   ',CR,LF
        DB      '  6)   ',CR,LF
        DB      '  7)   ',CR,LF
        DB      '  8)   ',CR,LF
        DB      '  9)   ',CR,LF
        DB      '  0)   Exit this program with no terminal change.',CR,LF
        DB      CR,LF
        DB      CR,LF
        DB      '       Please make your selection now:  $'
;
;
MSG1:	; CPM
	DB	ESC,'*'
        DB      ESC,'|11','A:',CR,CNTLY ; FN 1
	DB	ESC,'|21','B:',CR,CNTLY ; FN 2
	DB	ESC,'|31','C:',CR,CNTLY ; FN 3
	DB	ESC,'|41','D:',CR,CNTLY ; FN 4
	DB	ESC,'|<1','DFDRV A:',CR,CNTLY ; FN 1 SHIFTED
	DB	ESC,'|=1','DFDRV B:',CR,CNTLY ; FN 2 SHIFTED
	DB	ESC,'|>1','DFDRV C:',CR,CNTLY ; FN 3 SHIFTED
	DB	ESC,'|?1','DFDRV D:',CR,CNTLY ; FN 4 SHIFTED
	DB	ESC,'|:1','A:SYSLOAD A:BNKICPM',CR,CNTLY ; FN 10
	DB	ESC,'|;1',CNTLY		; INS MODE
        DB	ESC,'|',0,'1',CNTLY	; INS CHAR
        DB	ESC,'|',1,'1',CNTLY	; DEL CHAR
        DB	ESC,'|',2,'1',CNTLY	; INS LINE
        DB	ESC,'|',3,'1',CNTLY	; DEL LINE
        DB	ESC,'|',4,'1',CNTLY	; ERA EOL
        DB	ESC,'|',5,'1',CNTLY	; ERA EOP
        DB	ESC,'|',6,'1',CNTLY	; SEND
        DB	ESC,'|',7,'1',CNTLY	; PRINT
        DB	ESC,'|',8,'1',CNTLY	; SCROLL UP
        DB	ESC,'|',9,'1',CNTLY	; SCROLL DOWN
        DB	ESC,'|',10,'1',CNTLA,CNTLY ; WORD LEFT
        DB	ESC,'|',11,'1',CNTLF,CNTLY ; WORD RIGHT
	DB	ESC,'|',CNTLN,'1',CNTLK,CNTLY   ; CURSOR UP
        DB	ESC,'|',CNTLO,'1',CNTLV,CNTLY   ; CURSOR DOWN
        DB	ESC,'| 1',CNTLH,CNTLY		; CURSOR LEFT
        DB	ESC,'|!1',CNTLL,CNTLY		; CURSOR RIGHT
        DB	ESC,'|',CNTLL,'1',CNTLUAR,CNTLY	; CURSOR HOME
	DB	'$'      
;
MSG2:   ; WORDSTAR
	DB	ESC,'*'
        DB      ESC,'|11',CNTLK,CNTLB,CNTLY ; FN 1	mark begin
	DB	ESC,'|21',CNTLK,CNTLK,CNTLY ; FN 2      mark end
	DB	ESC,'|31',CNTLK,CNTLH,CNTLY ; FN 3      hide marks
	DB	ESC,'|41',CNTLY ; FN 4
	DB	ESC,'|51',CNTLY         ; FN 5
	DB	ESC,'|61',CNTLQ,CNTLC,CNTLY ; FN 6      home bottom
	DB	ESC,'|71',CNTLY         ; FN 7
	DB	ESC,'|81',CNTLY         ; FN 8
	DB	ESC,'|91',CNTLR,CNTLY   ; FN 9          page up
	DB	ESC,'|:1',CNTLC,CNTLY   ; FN 10         page down
	DB	ESC,'|;1',CNTLV,CNTLY	; INS MODE      insert on/off
        DB	ESC,'|',0,'1',CNTLY	; INS CHAR
        DB	ESC,'|',1,'1',CNTLY	; DEL CHAR
        DB	ESC,'|',2,'1',CNTLY	; INS LINE
        DB	ESC,'|',3,'1',CNTLY	; DEL LINE
        DB	ESC,'|',4,'1',CNTLY	; ERA EOL
        DB	ESC,'|',5,'1',CNTLY	; ERA EOP
        DB	ESC,'|',6,'1',CNTLY	; SEND
        DB	ESC,'|',7,'1',CNTLY	; PRINT
        DB	ESC,'|',8,'1',CNTLW,CNTLY ; SCROLL UP
        DB	ESC,'|',9,'1',CNTLZ,CNTLY ; SCROLL DOWN
        DB	ESC,'|',10,'1',CNTLA,CNTLY ; WORD LEFT
        DB	ESC,'|',11,'1',CNTLF,CNTLY ; WORD RIGHT
	DB	ESC,'|',CNTLN,'1',CNTLE,CNTLY   ; CURSOR UP
        DB	ESC,'|',CNTLO,'1',CNTLX,CNTLY   ; CURSOR DOWN
        DB	ESC,'| 1',CNTLS,CNTLY		; CURSOR LEFT
        DB	ESC,'|!1',CNTLD,CNTLY		; CURSOR RIGHT
        DB	ESC,'|',CNTLL,'1',CNTLQ,CNTLR,CNTLY	; CURSOR HOME
	DB	ESC,'|',CNTLG,'1',CNTLK,CNTLX,CNTLY ; PRINT
	DB	'$'      
;
MSG3:	; EB
	DB	ESC,'*'
        DB      ESC,'|11',ESC,'IMB',CNTLY ; FN 1        mark begin
	DB	ESC,'|21',ESC,'IME',CNTLY ; FN 2        mark end
	DB	ESC,'|31',ESC,'DM',CNTLY  ; FN 3        delete marks
	DB	ESC,'|41',CNTLY           ; FN 4
	DB	ESC,'|51',CNTLY           ; FN 5
	DB	ESC,'|61',CNTLB,CNTLY     ; FN 6  home bottom
	DB	ESC,'|71',ESC,'SM',CNTLY  ; FN 7        set margin
	DB	ESC,'|81',ESC,'XK',CNTLY  ; FN 8        execute keystrokes
	DB	ESC,'|91',ESC,CNTLK,CNTLY ; FN 9        page up
	DB	ESC,'|:1',ESC,CNTLV,CNTLY ; FN 10       page down
        DB	ESC,'|B1',ESC,'RM',CNTLY  ; FN 7 SHIFTED  reset margin
	DB	ESC,'|;1',ESC,'RC',CNTLY  ; INS MODE    replace chars
        DB	ESC,'|',0,'1',ESC,'IC',CNTLY ; INS CHAR insert chars
        DB	ESC,'|',1,'1',ESC,'DC',CNTLY ; DEL CHAR delete chars
        DB	ESC,'|',2,'1',ESC,'IL',CNTLY ; INS LINE insert line
        DB	ESC,'|',3,'1',ESC,'DL',CNTLY ; DEL LINE delete line
        DB	ESC,'|',4,'1',ESC,'RL',CNTLY ; ERA EOL  replace lines
        DB	ESC,'|',5,'1',ESC,'B',CNTLV,ESC,DEL,CNTLK,CNTLY	; ERA EOP erase eol
        DB	ESC,'|',6,'1',CNTLY	  ; SEND
        DB	ESC,'|',8,'1',ESC,CNTLK,CNTLY	; SCROLL UP
        DB	ESC,'|',9,'1',ESC,CNTLV,CNTLY	; SCROLL DOWN
        DB	ESC,'|',10,'1',ESC,CNTLH,CNTLY	; WORD LEFT
        DB	ESC,'|',11,'1',ESC,CNTLL,CNTLY	; WORD RIGHT
	DB	ESC,'|',CNTLN,'1',CNTLK,CNTLY   ; CURSOR UP
        DB	ESC,'|',CNTLO,'1',CNTLV,CNTLY   ; CURSOR DOWN
        DB	ESC,'| 1',CNTLH,CNTLY		; CURSOR LEFT
        DB	ESC,'|!1',CNTLL,CNTLY		; CURSOR RIGHT
        DB	ESC,'|',CNTLL,'1',CNTLUAR,CNTLY	; CURSOR HOME
	DB	ESC,'|',CNTLG,'1',ESC,'EXS',CNTLY ; PRINT save file
	DB	'$'      
