Compucolor.org – Virtual Media

Listing of file='SENDER.MAC;01' on disk='vmedia/taylor_5-sector.ccvf'

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;	MORSE CODE SENDER
;
	TITLE	SENDER
;

	PUBLIC	ABORT,CI,DISCTL
	PUBLIC	FCSSP

	EXTRN	DECOUT
	EXTRN	JMPVEC,CO,OSTR,SAVE
	EXTRN	FILVEC,EMESS,PFSPC,RESET,OPEN
	EXTRN	CLSEQO,RWSEQI,INSEQO
	EXTRN	GTBYT,PTBYT,ADHLA
	EXTRN	CPYRGT
	EXTRN	CLRMAC,DEFMAC,EXPMAC,GETMAC,PRTMAC,PUTMAC
	EXTRN	READ
	EXTRN	SEND,DOTTIM,CHSPD
	EXTRN	SETFIL


;	SYSTEM ADDRESSES


EXTBUF	EQU	81D6H		;BUFFER FOR EXTERN. OUTPUT

INPCRT	EQU	81C5H		;JUMP VECTOR NUMBER 31
KBDFL	EQU	81DFH		;HOLDS NUMBER OF JUMP VECTOR
READY	EQU	81FFH		;KEYBOARD READY FLAG
KBCHA	EQU	81FEH		;KEYBOARD CHARACTER BUFFER
VCRAD	EQU	81CBH		;VISIBLE CURSOR ADDRESS
VHLAD	EQU	81D2H		;VISIBLE CURSOR HL

;	OFFSETS IN FILE PARAMETER BLOCK

FOPT	EQU	0
FATR	EQU	1
FNAM	EQU	2
FTYP	EQU	8
FVER	EQU	11
FSBK	EQU	12
FSIZ	EQU	14
FLBC	EQU	16
FLAD	EQU	17
FSAD	EQU	19
FSPR	EQU	21
FDBK	EQU	22
FDEN	EQU	23
FAUX	EQU	24
FHAN	EQU	26
FFCN	EQU	28
FDRV	EQU	29
FBLK	EQU	30
FBUF	EQU	32
FXBC	EQU	34
FPTR	EQU	36

;	SPECIAL CONTROL CHARACTERS

CR	EQU	13
LF	EQU	10
FF	EQU	12
TAB	EQU	9
ESC	EQU	27

BUFLEN	EQU	64
MACLEN	EQU	64
NUMMAC	EQU	10

CYN	EQU	6
GRN	EQU	2
RED	EQU	1

;
;..............................................................
;
;	START OF PROGRAM
;

SENDER:	DI
	LXI	H,0		;SAVE FCS STACK POINTER
	DAD	SP
	SHLD	FCSSP
	LXI	SP,STACK	;SETUP PROGRAM STACK
	MVI	A,31		;SET UP VECTOR
	STA	KBDFL		;TO INPCRT
	MVI	A,0C3H		;LITERALLY JMP
	STA	INPCRT
	LXI	H,CHRINT	;INPCRT:   JMP	CHRINT
	SHLD	INPCRT+1

	CALL	JMPVEC		;SETUP JUMPS FOR CONSOLE I/O
	CALL	FILVEC		;SETUP JUMPS FOR FILE I/O

RESTRT:	LXI	H,MSG00		;PRINT STARTUP MESSAGE
	CALL	OSTR
	CALL	CPYRGT

	XRA	A
	STA	LINFLG		;SETUP AS CHARACTER MODE
	STA	WRDFLG
	STA	FILFLG		;   AND INPUT FROM KEYBOARD
	STA	ABORT
	MVI	A,0FFH
	STA	CHRFLG
	CALL	CLRMAC
	LXI	H,HLPMSG	;PRINT HELPFUL INFO
	CALL	OSTR

BCKGND:	LXI	H,INBUF		;POINT TO BUFFER COUNTER
	MVI	M,0		;CLEAR IT
	LXI	H,TMPBUF
	MVI	M,0
	INX	H
	SHLD	BUFPTR
	LHLD	VHLAD		;SETUP CURSOR ADDRESS FOR
	SHLD	SHLAD		;   SENDING ROUTINE
	EI

BKG10:	LDA	ABORT
	ORA	A
	JZ	BKG15
	XRA	A
	STA	ABORT
	JMP	BCKGND
BKG15:	CALL	CI		;GET NEXT CHARACTER
	ANI	127
	PUSH	PSW
	LDA	CHRFLG		;CHR MODE ?
	ORA	A
	JNZ	BKG17
	POP	PSW
	PUSH	PSW
	CPI	127		;NO, CHECK FOR DELETE
	JNZ	STORE
	LXI	H,TMPBUF
	DCR	M
	JP	DECPTR
	MVI	M,0
	JMP	NXTCHR
DECPTR:	LHLD	BUFPTR
	DCX	H
	SHLD	BUFPTR
	CALL	DISPLY
	JMP	NXTCHR
STORE:	LHLD	BUFPTR
	MOV	M,A
	INX	H
	SHLD	BUFPTR		;SAVE BUFFER POINTER
	LXI	H,TMPBUF
	INR	M
	CPI	33		;CONTROL CHR OR SPACE ?
	JC	TSTSPC
NXTCHR:	POP	PSW
	JMP	BKG10
TSTSPC:	CPI	' '
	JNZ	TXBUF
	LDA	LINFLG
	ORA	A
	JNZ	NXTCHR
TXBUF:	LXI	H,TMPBUF
	MOV	B,M
	INX	H
	DCR	B
	JZ	TXFIN
TXLOOP:	PUSH	B
	PUSH	H
	MOV	A,M
	CALL	DISPLY
	CALL	SEND
	POP	H
	INX	H
	POP	B
	LDA	ABORT
	ORA	A
	JZ	TXLP10
	XRA	A
	STA	ABORT
	POP	PSW
	JMP	BCKGND
TXLP10:	DCR	B
	JNZ	TXLOOP
TXFIN:	LXI	H,TMPBUF
	MVI	M,0
	INX	H
	SHLD	BUFPTR

BKG17:	POP	PSW
	CPI	32		;SEE IF CONTROL CHR
	JC	CNTRL
BKG20:	CALL	DISPLY		;DISPLAY CHR AND SEND AS MORSE
BKG30:	CALL	SEND
	JMP	BKG10

;	HANDLE CONTROL CHARACTERS

CNTRL:	MOV	C,A
	MVI	B,0
	LXI	H,CTLTBL	;INDEX INTO JUMP TABLE
	DAD	B
	DAD	B
	MOV	E,M
	INX	H
	MOV	D,M
	LXI	H,BCKGND	;   SETUP RETURN ADDRESS
	PUSH	H
	XCHG
	PCHL			;   AND JUMP!!!

CTLTBL:	DW	FREE,FREE		;@,A	0,1
	DW	FREE,CHRMOD		;B,C	2,3
	DW	DEFMAC,EXIT		;D,E	4,5
	DW	FILE,GETMAC		;F,G	6,7
	DW	HELP,FREE		;H,I	8,9
	DW	LINFED,BCKGND		;J,K	10,11
	DW	LINMOD,CARRET		;L,M	12,13
	DW	FREE,FREE		;N,O	14,15
	DW	PUTMAC,QUERY		;P,Q	16,17
	DW	RESTRT,SPEED		;R,S	18,19
	DW	FREE,FREE		;T,U	20,21
	DW	FREE,WRDMOD		;V,W	22,23
	DW	EXPMAC,FREE		;X,Y	24,25
	DW	DEL ,EXIT		;Z,ESC	26,27
	DW	FREE,FREE		;\,]	28,29
	DW	FREE,FREE		;^,_	30,31

FREE:	CALL	DISCTL
	JMP	BKG10


;
;	DISPLAY THE CHARACTER BEING SENT
;

DISPLY:	PUSH	PSW
	MVI	A,CYN		;SET COLOR AS CYAN
DISP10:	LHLD	SHLAD
	INX	H
	MOV	M,A
	INX	H
	CALL	WRAP
	SHLD	SHLAD
	POP	PSW
	RET

;	ALTERNATE ENTRY POINT FOR CONTROL CHARACTER DISPLAY

DISCTL:	PUSH	PSW
	MVI	A,RED		;CONTROL CHRS ARE RED
	JMP	DISP10

SHLAD:	DS	2

WRAP:	MOV	A,H		;WRAP AROUND ON SCREEN ADDR
	CPI	80H		;   IF NECESSARY
	RC
	MVI	H,70H
	RET

;.............................................................
;
;	CONTROL-C - CHARACTER MODE COMMAND (DEFAULT)
;

CHRMOD:	CALL	DISCTL
	STA	CHRFLG
	XRA	A
	STA	LINFLG
	STA	WRDFLG
	RET

CHRFLG:	DB	0

;.............................................................
;
;	CONTROL-E - EXIT COMMAND
;

EXIT:	MVI	A,13
	STA	KBDFL
	MVI	B,0
	LHLD	FCSSP
	SPHL
	RET

;.............................................................
;
;	CONTROL-F - SEND DATA FILE
;

FILE:	CALL	DISCTL
	LXI	B,TXTTYP	;DEFAULT FILE TYPE IS 'TXT'
	LXI	D,IBUF
	LXI	H,FPB
	XRA	A		;SET OPEN CODE FOR OLD FILE
	CALL	SETFIL
	MVI	A,0FFH
	STA	FILFLG
	RET

;	MAIN SENDING LOOP FOR DATA FILE

FILE10:	LXI	H,FPB		;GET NEXT CHARACTER FROM FILE
	CALL	GTBYT
	PUSH	PSW
	JC	LOOPE1
	CPI	26		;MIGHT BE SCROLL
	JZ	LOOPE1
	CALL	CO		;PRINT CHR
;
;	SEE IF SENDING IS TO BE SUSPENDED
;
ABTEST:	EI
	LDA	READY		;SEE IF BREAK
	CPI	50H
	JZ	ABTEST		;HANG UNTIL ANOTHER IS STRUCK
	CPI	80H
	JNZ	DONE
	XRA	A
	STA	READY
	LDA	KBCHA
	CPI	ESC		;ESCAPE CAUSES PROGRAM ABORT
	JZ	FIN
DONE:	POP	PSW
	RET
FIN:	POP	PSW
	XRA	A
	STA	FILFLG
	POP	H
	JMP	BCKGND

;
;	EXIT MAIN LOOP
;

LOOPE1:	JZ	EOF		;AT END OF FILE - CLOSE OUTPUT
	LXI	H,ERRMSG
	CALL	OSTR
	JMP	FIN

EOF:	RET

;.............................................................
;
;	CONTROL-H - HELP COMMAND
;

HELP:	CALL	DISCTL
	LXI	H,HLPMSG
	CALL	OSTR
	RET

;..............................................................
;
;	CONTROL-J - LINEFEED
;

LINFED:	PUSH	PSW
	LHLD	SHLAD
	LXI	D,128
	DAD	D
	CALL	WRAP
	SHLD	SHLAD
	POP	PSW
	POP	H		;THROW AWAY RETURN ADDRESS
	JMP	BKG30

;..............................................................
;
;	CONTROL-L - LINE MODE
;

LINMOD:	CALL	DISCTL
	STA	LINFLG
	XRA	A
	STA	CHRFLG
	STA	WRDFLG
	RET

LINFLG:	DB	0

;..............................................................
;
;	CONTROL-M - CARRIAGE RETURN
;

CARRET:	PUSH	PSW
	LHLD	SHLAD
	MOV	A,L
	ORA	A
	JM	CARR10
	MVI	L,0
	JMP	CARR20
CARR10:	MVI	L,128
CARR20:	SHLD	SHLAD
	POP	PSW
	POP	H		;THROW AWAY RETURN ADDRESS
	JMP	BKG30

;..............................................................
;
;	CONTROL-Q - QUERY COMMAND
;

QUERY:	CALL	DISCTL
	LXI	H,SPDMSG
	CALL	OSTR
	LXI	H,HIDIG
	LDA	WPM
	CALL	DECOUT
	LXI	H,HIDIG
	CALL	OSTR
	MVI	B,NUMMAC
	XRA	A
QRY10:	PUSH	B
	PUSH	PSW
	CALL	PRTMAC
	POP	PSW
	INR	A
	POP	B
	DCR	B
	JNZ	QRY10
	RET

;..............................................................
;
;	CONTROL-S - SET SPEED
;

SPEED:	CALL	DISCTL
SPD10:	CALL	CI
	CPI	'0'
	JC	SPD10
	CPI	'9'+1
	JNC	SPD10
	SUI	'0'
	LXI	H,SPDTAB
	MOV	C,A
	MVI	B,0
	DAD	B
	DAD	B
	MOV	A,M
	STA	DOTTIM
	INX	H
	MOV	A,M
	STA	WPM
	RET

WPM:	DB	15
SPDTAB:	DB	60,5
	DB	30,10
	DB	20,15
	DB	15,20
	DB	12,25
	DB	10,30
	DB	6,50
	DB	4,75
	DB	3,100
	DB	2,150

;..............................................................
;
;	CONTROL-W - WORD MODE
;

WRDMOD:	CALL	DISCTL
	STA	WRDFLG
	XRA	A
	STA	CHRFLG
	STA	LINFLG
	RET

WRDFLG:	DB	0

;..............................................................
;
;	CONTROL-Z - DELETE CHARACTER
;

DEL:	MVI	A,127
	POP	H		;THROW AWAY RETURN ADDRESS
	JMP	BKG20

;..............................................................
;
;	KEYBOARD INTERRUPT ROUTINE
;
;	CHRINT IS CALLED WHENEVER A KEY IS STRUCK.
;	THE JUMP IS FROM INPCRT.

CHRINT:	CALL	SAVE	;CONTEXT SAVE
	LXI	H,INBUF
	MOV	A,E
	CPI	26
	JZ	CHIN10
	CPI	127
	JNZ	CHIN20
CHIN10:	MOV	A,M
	ORA	A
	JZ	CHIN30
	DCR	M
	MVI	A,26
	CALL	CO
	RET
CHIN20:	CPI	CR
	JZ	CHIN25
	CPI	LF
	JNZ	CHIN30
CHIN25:	INR	M
	INR	M
	MOV	A,M
	CALL	ADHLA
	MVI	M,LF
	DCX	H
	MVI	A,CR
	MOV	M,A
	CALL	CO
	MVI	A,LF
	CALL	CO
	RET

CHIN30:	MVI	A,BUFLEN	;LENGTH OF BUFFER
	CMP	M	;SEE IF BUFFER IS FULL
	RC		;IF IT IS IGNORE CHARACTER
	INR	M	;INCREMENT COUNTER
	MOV	A,M	;PUT COUNT IN A
	CALL	ADHLA	;ADD COUNTER TO BEGINNING OF BUFFER
	MOV	A,E	;CHARACTER IS IN E
	CPI	ESC	;SEE IF ESCAPE HAS BEEN HIT
	JZ	BREAK	;USER WANTS TO EXIT
	ANI	127	;MAKE SURE ITS ASCII
	CPI	26
	JNZ	CHIN35
	MVI	A,127
CHIN35:	MOV	M,A	;STORE IT
	CPI	32
	JNC	CHIN40	;ECHO CONTROL CHRS AS LETTERS
	ADI	40H
CHIN40:	CALL	CO	;ECHO IT
	RET		;INTERRUPTS REENABLED ON THE WAY BACK
;
;	BREAK ALLOWS THE USER TO BRANCH TO A LOCATION WHEN THE
;	ESCAPE KEY IS STRUCK.  IN THIS CASE THE LOCATION IS
;	CALLED BCKGND
;

BREAK:	MVI	A,0FFH
	STA	ABORT
	RET

INBUF:	DS	BUFLEN+4	;STORAGE AREA FOR TYPE AHEAD

;
;..............................................................
;
;	CI READS AND ECHOS ONE CHARACTER FROM THE KEYBOARD
;

CI:	LDA	FILFLG
	ORA	A
	JZ	CI10
	CALL	FILE10
	RET
CI10:	PUSH	H	;SAVE H
	LXI	H,INBUF
CI20:	MOV	A,M	;READ COUNTER
	ANA	A	;SEE IF ZERO
	JZ	CI20	;LOOK AND WAIT IF ZERO
	DI		;HOLD OFF INTERRUPTS WHILE PROCESSING
	PUSH	D	;SAVE D
	DCR	M	;REDUCE BUFFER COUNTER
	MOV	D,M
	INX	H	;POINT TO CHARACTER
	MOV	A,M	;READ IT
	PUSH	PSW	;STACK IT
CI30:	DCR	D	;SHIFT COUNTER
	JM	CI40	;WHEN DONE
	INX	H	;CHARACTER TO BE SHIFTED
	MOV	A,M
	DCX	H	;POINT TO NEW HOME
	MOV	M,A	;NEW HOME
	INX	H
	JMP	CI30	;LOOP UNTIL DONE
CI40:	EI		;ENABLE INTERRUPTS
	POP	PSW	;THE CHARACTER
	POP	D
	POP	H
	RET

;..............................................................
;
;	MESSAGES
;
MSG00:	DB	29,6,2,12,'COMPUCOLOR ',6,3,'II ',21
	DB	'MORSE CODE SENDER ',6,6,'V9.80',13,10,239

HLPMSG:	DB	13,10,6,2,'THE FOLLOWING ARE VALID COMMANDS.'
	DB	' HOLD DOWN THE',13,10
	DB	6,6,'CONTROL ',6,2,'KEY AND HIT THE KEY'
	DB	' FOR THE REQUIRED FUNCTION.',13,10
	DB	6,1,'A ',6,2,'NOT USED     '
	DB	6,1,'B ',6,2,'NOT USED     '
	DB	6,1,'C ',6,2,'CHR MODE     '
	DB	6,1,'D ',6,2,'DEFINE MACRO ',13,10
	DB	6,1,'E ',6,2,'EXIT TO FCS  '
	DB	6,1,'F ',6,2,'FILE INPUT   '
	DB	6,1,'G ',6,2,'GET MACROS   '
	DB	6,1,'H ',6,2,'THIS HELP MSG',13,10
	DB	6,1,'I ',6,2,'TAB          '
	DB	6,1,'J ',6,2,'LINEFEED     '
	DB	6,1,'K ',6,2,'KILL LINE    '
	DB	6,1,'L ',6,2,'LINE MODE    ',13,10
	DB	6,1,'M ',6,2,'CARRIAGE RET '
	DB	6,1,'N ',6,2,'NOT USED     '
	DB	6,1,'O ',6,2,'NOT USED     '
	DB	6,1,'P ',6,2,'PUT MACROS',13,10
	DB	6,1,'Q ',6,2,'QUERY STATUS '
	DB	6,1,'R ',6,2,'RESTART      '
	DB	6,1,'S ',6,2,'SPEED (0-9)  '
	DB	6,1,'T ',6,2,'NOT USED     ',13,10
	DB	6,1,'U ',6,2,'NOT USED     '
	DB	6,1,'V ',6,2,'NOT USED     '
	DB	6,1,'W ',6,2,'WORD MODE    '
	DB	6,1,'X ',6,2,'EXPAND MACRO ',13,10
	DB	6,1,'Y ',6,2,'NOT USED     '
	DB	6,1,'Z ',6,2,'DELETE       ',13,10,10
	DB	6,1,'        ESC ',6,2,'STOPS SENDING '
	DB	'IMMEDIATELY',13,10,10
	DB	'  MACROS ARE NUMBERED ',6,1,'0-9',6,2,'.'
	DB	' (A NUMBER MUST FOLLOW ^D AND ^X.)',13,10
	DB	'  THERE ARE TEN SPEEDS AVAILABLE,'
	DB	'ALSO NUMBERED 0-9:',13,10,6,1
	DB	'        5,10,15,20,25,30,50,75,100,150 '
	DB	6,2,'WPM.',13,10,239

SPDMSG:	DB	13,10,6,3,'SPEED = ',6,2,239
HIDIG:	DB	'   '
	DB	' WPM',13,10,239
ERRMSG:	DB	17,'*** HARDWARE ERROR ***',13,10,239

TXTTYP:	DB	'TXT'		;DEFAULT FILE TYPE FOR READING

;..............................................................
;
;	DATA AREAS
;

FILFLG:	DB	0	;FLAG SET IF INPUT FROM FILE
ABORT:	DB	0	;FLAG SET IF SENDING TO BE ABORTED

	DB	0FFH
BUFFER:	DS	BUFLEN	;CONSOLE INPUT BUFFER
	DB	0FFH

BUFPTR:	DS	2
TMPBUF:	DS	BUFLEN+4

IBUF:	DS	1024	;FILE INPUT BUFFER

	DS	150	;STACK AREA
STACK:	DS	2

FCSSP:	DS	2	;FCS STACK POINTER
FPB:	DS	38	;INPUT FPB

	END	SENDER