	MACLIB	Z80
OFFSET	EQU	4000H	;beyond bank zero.
BANK8	EQU	80H
KEYSTRT	EQU	2155H	;where function key table starts in bank 8.
	PUBLIC	KEYCPM,KEYWRD
KEYCPM:	LXI	H,HEAD
	LXI	D,OFFSET
	LXI	B,FEATHER
	LDIR
	CALL	XARROW
	RET
KEYWRD:	LXI	H,HEAD	;the front of my arrow
	LXI	D,OFFSET ;the target
	LXI	B,FEATHER ;length of arrow
	LDIR		    ;twang
	LXI	H,ALTBLE	;start of wordstar key table
	LXI	D,402Dh		;position of table to be moved
	LXI	B,0AH		;number of characters in table
	LDIR
	CALL	XARROW
	RET
ALTBLE:	EQU	$
	DB	01H,05H			;cpm ^e  up
	DB	01H,04H			;cpm ^d  right
	DB	01H,18H			;cpm ^x  down
	DB	01H,13H			;cpm ^s  left
	DB	0,0
MOVCDE:	CALL	XARROW
	RET
HEAD	EQU	$
XARROW:	EQU	$+OFFSET-HEAD
	DI
	IN	0
	STA	SVBANK
	ORI	BANK8
	OUT	0		;switch to bank8
	LXI	H,2155H		;put key address in register hl
	MVI	C,11		;maximum number of function key definitions
	XRA	A		;set register a to zero
	MOV	D,A		;move zero to register d
XLOOP:	EQU	$+OFFSET-HEAD	;this loops 11 times.
	MOV	E,M		;puts value pointed to by hl into register e
				;this is length of key definition
	CMP	E		;compares e register to zeroed a register
	RZ			;return if zero.
	DCR	C		;decrement register c
	DB	28H,04H		;jrz xmove
	DAD	D		;add de to hl
				;hl will point to the next function key
				;definition length.
	INX	H		;increment hl
	DB	18H,0F6H	;jr xloop
XMOVE:	EQU	$+OFFSET-HEAD
	XCHG			;this swaps the contents of hl with de
				;de now points the key area to receive the
				;new keytable.
	LXI	H,CPTABLE
	LXI	B,10		;length of cptable
	LDIR			;move new definitions
	LDA	SVBANK
	OUT	0		;back to bank1
	EI
	RET
	DB	0,0
CPTABLE: EQU	$+OFFSET-HEAD
	DB	01H,0BH			;cpm ^k  up
	DB	01H,0CH			;cpm ^l  right
	DB	01H,0AH			;cpm ^j  down
	DB	01H,08H			;cpm ^h  left
	DB	0,0
SVBANK:	EQU	$+OFFSET-HEAD
	DB	0,0
CODEND	EQU	$
FEATHER	EQU	CODEND-HEAD
	END
