;
;===========================================
;
;	ASCII TO BAUDOT TO ASCII PROGRAM
;	WITH BUFFER TO DISK AND DISK TO BUFFER
;	ROUTINES TAKEN FROM 'LINK.ASM' BY L.E.HUGHS
;
;	RANDY SUESS 12/20/78
;============================================
;
;08/12/79 MODIFICATIONS BY JIM MILLS WB9KFP TO ALLOW
;OPERATION USING PMMI MM-103 DIRECT-CONNECT MODEM
;
;
;            CTRL-R    SEND TEXT FILE FROM DISK TO CYBER
;            CTRL-Y    ENABLE TEXT-FILE-LOADER (INTO MEMORY)
;            CTRL-Q    DISABLE TEXT FILE LOADER, WRITE MEMORY TO DISK
 
;         BDOS ENTRY POINT AND FUNCTION CODES
 
 BDOS     EQU    0005H
 OFFC     EQU    15             ;OPEN FILE
 CFFC     EQU    16             ;CLOSE FILE
 DFFC     EQU    19             ;DELETE FILE
 RRFC     EQU    20             ;READ RECORD
 WRFC     EQU    21             ;WRITE RECORD
 MFFC     EQU    22             ;MAKE FILE
 
;         DEFAULT FCB AND FIELD DEFINITIONS
 
 FCB      EQU    5CH
 FN       EQU    1              ;FILE NAME FIEH
LETH:	EQU	3CH	;LESS-THAN SIGN
CNTB:	EQU	02H	;CONTROL B
STAR:	EQU	2AH	;ASTERISK
CNTI:	EQU	09H	;CONTROL I
CNTZ:	EQU	1AH	;CONTROL Z
CNTA:	EQU	01H	;CONTROL A
CNTX:	EQU	18H	;CONTROL X
UARW:	EQU	5EH	;UP-ARROW
PLUS:	EQU	2BH	;PLUS SIGN
RESL:	EQU	5CH	;REVERSE SLANT
LBKT:	EQU	5BH	;LEFT BRACKET
RBKT:	EQU	5DH	;RIGHT BRACKET
ESCP:	EQU	1BH	;ESCAPE KEY
ALMD:	EQU	7DH	;ALTERNATE MODE KEY
BEGIN:	EQU	0FB00H	;MY ADDRESS FOR THIS PROGRAM
; 
; PROGRAM STARTS HERE
; 
	ORG	BEGIN	;PUT DESIRED ADDRESS HERE
; 
ASCRCV:	PUSH	H	;SAVE HL REGISTERS
	LHLD	CASAVE	;GET PRESENT CASE
; 
START:	IN	BTTY	;GET BAUDOT CHARACTER
	ANI	1FH	;BAUDOT CHARACTERS ONLY
	CPI	FIGS
	JZ	UCASE
	CPI	LTRS
	JZ	LCASE
	ORA	A	;BAUDOT 'BLANK' ?
	JZ	TCASE
	CPI	SPACE
	JNZ	START1
	LXI	H,LTABLE ;SPACE GIVES LOWER CASE
; 
START1:	SHLD	CASAVE	;SAVE PRESENT CASE
	ADD	L	;ADD CHAR. TO TABLE ADRS.
	MOV	L,A	;L POINTS TO ASCII CHAR.
	MOV	A,H	;GET H FOR CORRECTION
	ACI	0	;SEE IF CORRECTION NEEDED
	MOV	H,A	;H IS CORRECT NOW
	XRA	A	;PUT ZERO IN A REG.
	STA	FLAG	;CLEAR LTRS-FIGS LAST FLAG
	MOV	A,M	;GET ASCII EQUIVALENT
	POP	H	;RESTORE HL REGISTERS
	ORA	A	;IS IT PRINTABLE?
	RNZ		;YES, VALID CHAR. RETURN
	CMA		;MAKE 0FFH 'IGNORE FLAG'
	RET		;RETURN TO CALLING PROGRAM
; 
LCASE:	LXI	H,LTABLE ;LOWER CASE TABLE ADDRESS
	JMP	SETFLG	;SET LTRS LAST FLAG, EXIT
; 
UCASE:	LXI	H,UTABLE ;UPPER CASE TABLE ADDRESS
	JMP	SETFLG	;SET FIGS LAST FLAG, EXIT
; 
TCASE:	LDA	FLAG	;GET SHIFT REMINDER FLAG
	CPI	FIGS
	JNZ	FCASE
	LXI	H,TTABLE ;THIRD CASE TABLE ADDRESS
	JMP	CLRFLG
; 
FCASE:	CPI	LTRS	;CHECK FOR LTRS LAST
	JNZ	CLRFLG
	LXI	H,FTABLE ;FOURTH CASE TABLE ADDRESS
; 
CLRFLG:	XRA	A	;READY TO CLEAR FLAG
; 
SETFLG:	STA	FLAG	;LTRS-FIGS LAST FLAG
	SHLD	CASAVE	;SAVE PRESENT CASE
	MVI	A,0FFH	;'IGNORE FLAG'
	POP	H	;RESTORE HL REGS.
	RET		;RETURN TO CALLING PROGRAM
; 
; THIS IS THE LOWER-CASE TABLE.
; 
LTABLE:	DB	0,'E',LF,'A SIU',CR,'DRJNFCK'
	DB	'TZLWHYPQOBG',FIGS,'MXV'
; 
; THIS IS THE UPPER-CASE TABLE.
; 
UTABLE:	DB	0,'3',LF,'- ',BELL,'87',CR,'$4'
	DB	APOS,',!:(5")2#6019?&',FIGS,'./;'
; 
; THIS IS THE THIRD-CASE TABLE.
; IT IS USED FOR SPECIAL CHARACTERS.
; THE FIRST COLUMN IN THE TABLE
; THE ASCII CHARACTER EQUIVALENT.
; THE SECOND COLUMN IS THE SPECIAL
; CASE BAUDOT CHARACTER FROM WHICH
; THE CONVERSION IS MADE.
; 
TTABLE:	DB	0,CNTC,LF	;BL  3   LF
	DB	LARW,ASPC,ATSN	;-   SP  BELL
	DB	CNTV,CNTO,CR	;8   7   CR
	DB	ALMD,CNTE,PCT	;$   4   '
	DB	RUBT,EQUL,ESCP	;,   !   :
	DB	LETH,CNTH,LBKT	;(   5   "
	DB	GRTH,CNTB,STAR	;)   2   #
	DB	CNTI,CNTZ,CNTA	;6   0   1
	DB	CNTX,UARW,PLUS	;9   ?   &
	DB	0,RBKT,RESL	;FIG .   /
	DB	0	        ;;
; 
; THIS IS THE FOURTH CASE TABLE
; FOR LOWER-CASE ALPHA CHARACTERS.
; 
FTABLE:	DB	0,65H,LF,61H,ASPC,73H
	DB	69H,75H,CR,64H,72H,6AH
	DB	6EH,66H,63H,6BH,74H,7AH
	DB	6CH,77H,68H,79H,70H,71H
	DB	6FH,62H,67H,FIGS,6DH,78H
	DB	76H
; 
; TEMPORARY STORAGE AREA
; 
CASAVE:	DW	LTABLE	;PRESENT CASE REMINDER
FLAG:	DB	0	;FIGS/LTRS LAST FLAG
; 
	END
  
; THIS IS A SAMPLE OF THE POLLING ROUTINE
; USED TO ALLOW INPUT FROM EITHER THE ASCII
; OR BAUDOT KEYBOARD INPUT PORTS.  IT CAN
; BE LINKED TO ANY PROGRAM WHICH USES A
; NORMAL INPUT ROUTINE WHICH RETURNS WITH
; THE ASCII CHARACTER IN THE ACCUMULATOR.
; 
POLL:	IN	BSTATUS	;BAUDOT UART STATUS PORT
	ANI	RDA	;TEST FOR RCVE DATA AVAIL FLAG
	JZ	POLL2	;NO CHAR. TEST ASCII (MAY NEED JNZ HERE)
	CALL	ASCRCV4	;CHARACTER THERE, GET AND CONVERT
	CPI	0FFH	;IGNORE FLAG THERE?
	RNZ		;NO, RETURN WITH ASCII CHARACTER
; 
POLL2:	IN	ASTATUS	;GET ASCII UART STATUS
	ANI	RDA	;TEST DATA AVAIL. FLAG
	JZ	POLL	;NO CHAR., RESUME POLLING (MAY NEED JNZ HERE)
	IN	ADATA	;GET ASCII UART DATA
	ANI	7FH	;STRIP PARITY BIT
	RET		;ASCII CHAR. IN ACCUMULATOR
; 
; END OF SAMPLE POLLING ROUTINE.
 
