;********************************************************
;*    This program allows the Lobo Max-80 F3 and F4 keys
;*    to be reprogrammed to anything the user likes.
;*
;*          Ver 1.0 -- Tom Marazita 8/14/83
;********************************************************


;
;General equates
;
BDOS	EQU	0005		;BDOS VECTOR
CONIN	EQU	01H		;CONSOLE INPUT FUNCTION
DCONIN	EQU	06H		;DIRECT CONSOLE INPUT FUNCTION
CONOUT	EQU	02H		;CONSOLE OUT FUNCTION
F3	EQU	0DC6EH		;ADDRESS OF F3'S CHARACTER IN BIOS
F4	EQU	0DC6FH		;ADDRESS OF F4'S CHARACTER IN BIOS
CR	EQU	0DH		;A CARRIAGE RETURN...
LF	EQU	0AH		;...AND A LINE FEED
;
;Program starts here, naturally.
;
	ORG	100H		;YES,ANOTHER PROGRAM THAT STARTS AT 100H

START	LXI	D,SIGNON	;POINT TO SIGN ON MESSAGE
	CALL	PUTMSG		;SAY HELLO TO USER...
	MVI	C,CONIN
	CALL	BDOS		;GET KEY CHOICE FROM USER
	CPI	'1'		;IS IT KEY CHOICE 1?
	JZ	ONE
	CPI	'2'		;OR CHOICE TWO?
	JZ	TWO
	LXI	D,BADKEY	;NEITHER, PRINT BADKEY MESSAGE AND EXIT
	CALL	PUTMSG
	RET			;RETURN TO CPM

ONE	LXI	H,F3		;POINT TO F3 ADDRESS
	JMP	SKIP2		;SKIP OVER KEY TWO STUFF
TWO	LXI	H,F4		;POINT TO F4 ADDRESS

SKIP2	SHLD	SAVEKEY		;SAVE IT FOR LATER, 'CAUSE BDOS MIGHT EAT IT.
	LXI	D,QMSG		;POINT TO QUERY MESSAGE
	CALL	PUTMSG
WAIT	MVI	C,DCONIN	;GET NEW CHAR FROM USER
	MVI	E,0FFH		;FF MEANS GET A CHAR.
	CALL	BDOS
	ORA	A
	JZ	WAIT		;IF ZERO, THEN NO CHAR YET
	LHLD	SAVEKEY		;RESTORE KEY ADDRESS
	MOV	M,A		;OTHERWISE, STORE CHAR AT KEY ADDRESS
	CALL	ECHO		;ECHO KEY TO CONSOLE
	LXI	D,EMSG		;PRINT ENDING MSG
	CALL	PUTMSG
	RET			;RETURN TO CPM
;
;Call this with a char in A and it will be printed.
;
ECHO	STA	SAVECHR		;SAVE IT FOR LATER
	CPI	20H		;IF A CTRL CHAR, PRINT '^CHAR'
	CC	CTRLCHR		;YES, A WAS LESS THAN 20 SO ITS A CTRL CHAR
	LDA	SAVECHR		;GET NEW CHAR INTO E FOR BDOS
	MOV	E,A
	MVI	C,CONOUT	;ECHO NEW CHAR TO USER
	CALL	BDOS
	RET

CTRLCHR	ADI	'@'		;FOLD TO PRINTABLE CHAR
	STA	SAVECHR		;SAVE NEW CHAR FOR LATER PRINTING
	MVI	E,'^'		;PRINT THIS NEAT THING TO SHOW IT IS CTRL
	MVI	C,CONOUT
	CALL	BDOS
	RET	
;
;Enter here with DE pointing to a string to be printed
;
PUTMSG	MVI	C,9		;BDOS FUNCTION TO PRINT A STRING TO CON:
	CALL	BDOS		;PRINT THE STRING
	RET
;
;Nothing but messages and storage past this point.
;
SIGNON	DB	'Which function key is it your desire to change:'
	DB	CR,LF,LF
	DB	'        (1) F3     or     (2) F4'
	DB	CR,LF,LF,'Hit 1 or 2, Oh soft one... $'
QMSG	DB	CR,LF,'Now, hit the key corresponding to the new value: $'
EMSG	DB	CR,LF,LF,'The key has been reprogrammed, soft one.$'
BADKEY	DB	CR,LF,LF,'Illegal choice, program terminated.$'
SAVEKEY	DS	2
SAVECHR	DS	1
	END
