; 
;		ASCXMT(4) REV. 2
;	BY KEITH PETERSEN, W8SDZ.  10/29/78.
; 
; THIS PROGRAM IS FOR TRANSMITTING ASCII
; THROUGH A BAUDOT MEDIUM USE A SPECIAL
; FORMAT OF FIGURES BLANK (X) - WHERE (X)
; IS A SPECIAL BAUDOT CHARACTER USED TO
; CONVEY THE ASCII EQUIVALENT CHARACTER TO THE
; RECEIVING END WHERE IT IS THEN CONVERTED BACK
; TO ASCII AGAIN.  LOWER CASE ALPHA CHARACTERS
; ARE TRANSMITTED VIA A 4TH CASE, LTRS BLANK (X).
;
; EQUATES
; 
LTRS:	EQU	1FH
FIGS:	EQU	1BH
CR:	EQU	48H
LF:	EQU	42H
STATUS:	EQU	0AH	;BAUDOT UART STATUS PORT
TBE:	EQU	80H	;UART TRANS. BUF. EMPTY FLAG
BTTY:	EQU	0BH	;BAUDOT UART DATA PORT
ALTMOD:	EQU	7DH	;ALTERNATE MODE KEY
BEGIN:	EQU	0FA00H	;MY ADDRESS FOR THIS PROGRAM
; 
;   	   PROGRAM STARTS HERE.
; CALL WITH ASCII CHARACTER IN ACCUMULATOR.
; 
	ORG	BEGIN	;PUT STARTING ADDRESS HERE
; 
START:	PUSH	PSW	;SAVE REGISTERS USED
	PUSH	B
	PUSH	H
; 
BAUDOT:	MVI	C,0	;SET UP COUNTER
	ANI	7FH	;STRIP PARITY BIT
	CPI	ALTMOD	;ALTERNATE MODE KEY?
	JNZ	BAUD2	;NO, IGNORE NEXT ROUTINE
	MVI	A,09H	;BAUDOT '$'
	JMP	BAUD3
; 
BAUD2:	CPI	7BH	;ABOVE L.C. 'Z' ?
	JNC	TTY0	;IF SO, IGNORE IT
	LXI	H,BTABLE ;POINT TO TABLE START
	ADD	L	;ADD CHARACTER VALUE
	MOV	L,A	;L POINTS TO BAUDOT CHAR.
	MOV	A,H	;GET H FOR CORRECTION
	ACI	0	;CORRECT IF NECESSARY
	MOV	H,A	;H IS NOW CORRECT
	MOV	A,M	;GET BAUDOT CHARACTER
	ORA	A	;IS IT A NON-PRINTING CHAR?
	JZ	TTY0	;IF SO IGNORE IT
	CPI	CR	;IS IT A CARRIAGE RETURN?
	JZ	TTYOUT-1 ;YES, HANDLE WITHOUT CASE TEST
	CPI	LF	;IS IT A LINE FEED?
	JNZ	BAUD3	;NO, IGNORE NEXT ROUTINE
	MVI	A,LTRS	
	PUSH	PSW	;SAVE IT ON STACK
	MVI	A,LF
	LXI	H,SCASE	;POINT TO PRESENT CASE REG.
	MVI	M,40H	;SET IT TO LOWER CASE
	JMP	TTYOUT-2 ;SEND LF AND LTRS
; 
BAUD3:	PUSH	PSW	;SAVE CHARACTER
	ANI	0C0H	;STRIP ALL BUT CASE BITS
	LXI	H,SCASE	;POINT TO PRESENT CASE REG.
	CMP	M	;SAME CASE AS PREVIOUS CHARACTER?
	JZ	TTYOUT	;YES NO CHANGE NECESSARY
	MOV	M,A	;UPDATE CASE REGISTER
	ORA	A
	JZ	TCASE
	CPI	80H
	JZ	UCASE
	CPI	0C0H
	JNZ	LCASE
; 
FCASE:	XRA	A	;GET A BAUDOT 'BLANK'
	PUSH	PSW	;SAVE IT ON THE STACK
	INR	C	;INCREMENT CHARACTER COUNT
; 
LCASE:	MVI	A,LTRS
	JMP	TTYOUT-2
; 
TCASE:	XRA	A	;GET A BAUDOT 'BLANK'
	PUSH	PSW	;SAVE IT ON THE STACK
	INR	C	;INCREMENT CHARACTER COUNT
; 
UCASE:	MVI	A,FIGS
	INR	C	;INCREMENT CHARACTER COUNT
	PUSH	PSW	;SAVE IT ON THE STACK
; 
TTYOUT:	IN	STATUS	;BAUDOT UART STATUS
	ANI	TBE	;TRANS. BUFFER EMPTY?
	JZ	TTYOUT	;IF NOT, LOOP AND WAIT
	POP	PSW	;GET CHARACTER
; 
; OMIT NEXT THREE LINES IF NO LIGHTS.
; 
	CMA		;INVERT FOR LIGHTS
	OUT	0FFH	;PUT ON FRONT PANEL LIGHTS
	CMA		;INVERT BACK TO NORMAL
;
; OMIT ABOVE THREE LINES IF NO LIGHTS.
; 
	ORI	0E0H	;MAKE UPPER 3 BITS MARKING
	OUT	BTTY	;SEND TO BAUDOT UART PORT
	DCR	C	;MORE TO SEND?
	JP	TTYOUT	;YES, CONTINUE SENDING
; 
TTY0:	POP	H	;RESTORE REGISTERS
	POP	B
	POP	PSW
	RET		;RETURN TO CALLING PROGRAM
; 
BTABLE:	DB	5FH,17H,13H	;NUL SOH STX
	DB	1,0,0AH		;ETX EOT ENQ
	DB	0,85H,10H	;ACK BEL BS
	DB	15H,42H,0C2H	;HT  LF  VT
	DB	2,48H,0		;FF  CR  SO
	DB	7,0,0		;SI  DLE DC1
	DB	0,0,0		;DC2 DC3 DC4
	DB	0,6,0		;NAK SYN ETB
	DB	18H,0,16H	;CAN EM  SUB
	DB	0EH,0,0		;ESC FS  GS
	DB	0,0,44H		;RS  US  SPACE
	DB	8DH,91H,94H	;!   "   #
	DB	89H,0BH,9AH	;$   PCT &
	DB	8BH,8FH,92H	;'   (   )
	DB	14H,1AH,8CH	;AS  PL  ,
	DB	83H,9CH,9DH	;-   .   /
	DB	96H,97H,93H	;0   1   2
	DB	81H,8AH,90H	;3   4   5
	DB	95H,87H,86H	;6   7   8
	DB	98H,8EH,9EH	;9   :   ;
	DB	0FH,0DH,12H	;LT  EQ  GT
	DB	99H,5,43H	;?   AT  A
	DB	59H,4EH,49H	;B   C   D
	DB	41H,4DH,5AH	;E   F   G
	DB	54H,46H,4BH	;H   I   J
	DB	4FH,52H,5CH	;K   L   M
	DB	4CH,58H,56H	;N   O   P
	DB	57H,4AH,45H	;Q   R   S
	DB	50H,47H,5EH	;T   U   V
	DB	53H,5DH,55H	;W   X   Y
	DB	51H,11H,1DH	;Z   LB  LS
	DB	1CH,19H,3	;RB  UA  LA
; 
; THESE ARE THE LOWER CASE ALPHA CHARACTERS
; 
	DB	0,0C3H,0D9H	;'   A   B
	DB	0CEH,0C9H,0C1H	;C   D   E
	DB	0CDH,0DAH,0D4H	;F   G   H
	DB	0C6H,0CBH,0CFH	;I   J   K
	DB	0D2H,0DCH,0CCH	;L   M   N
	DB	0D8H,0D6H,0D7H	;O   P   Q
	DB	0CAH,0C5H,0D0H	;R   S   T
	DB	0C7H,0DEH,0D3H	;U   V   W
	DB	0DDH,0D5H,0D1H	;X   Y   Z
; 
; TEMPORARY STORAGE AREA
; 
SCASE:	DB	40H	;PRESENT CASE REGISTER
; 
	END
  
