DIRECT: DO;

$INCLUDE (:F1:COMMON.LIT)

$EJECT


$INCLUDE (:F1:DEFIO)

$EJECT


DECL CHAR BYTE;
DECL CHR BYTE;
DECL CRFLG BYTE;
DECL MAXCNT LIT'LENGTH(TCHAR)';
DECL TCNTIN BYTE;
DECL TCNTOUT BYTE;
DECL TCHAR(256) BYTE;


CO: PROCEDURE (ODB) EXTERNAL;
	DECL ODB BYTE;
 END CO;

IOCCOM: PROCEDURE (COMMAND) BYTE PUBLIC;
  DECL COMMAND BYTE;
  DECL STIN BYTE;
  OUTPUT (CPUC) = DISABL;
	DO WHILE ((INPUT (IOCS) ) AND (OBF OR IBF OR FO)) <> 0;
	END;
  OUTPUT (IOCS) = COMMAND;
	DO WHILE (INPUT (IOCS) AND (OBF OR IBF OR FO)) <> OBF;
	END;
  STIN = INPUT (IOCI);
  OUTPUT (CPUC) = ENABL;
  RETURN (STIN);
 END IOCCOM;



SCHAR: PROCEDURE (CHAR) EXTERNAL;
  DECL CHAR BYTE;
 END;



GETCHR: PROCEDURE;
 TCNTIN = TCNTIN + 1;
 TCHAR(TCNTIN) = CHR;
 IF CHR = CR THEN
	DO;
	 CRFLG = TRUE;
	 TCNTIN = TCNTIN + 1;
	 TCHAR(TCNTIN) = LF;
	END;
  ELSE
	CRFLG = FALSE;
END GETCHR;




ISCAN: PROCEDURE BYTE PUBLIC;

 DO FOREVER;
 IF (INPUT(SIO$STAT) AND SIO$RXRDY) > 0 THEN
	DO;
	 CHR = (INPUT(SIO$DATA) AND 07FH);
	 IF ((CHR > 0) AND ((CRFLG = FALSE) OR
	  ((CRFLG = TRUE) AND (CHR <> LF)))) THEN
		CALL GETCHR;
	 IF ((CRFLG = TRUE) AND (CHR = LF)) THEN CRFLG = FALSE;
	END;
  IF (TCNTIN - TCNTOUT) <> 0 THEN
	DO;
	 IF (INPUT(IOCS) AND (FO OR IBF OR OBF)) = 0 THEN
		DO;
		 TCNTOUT = TCNTOUT + 1;
		 CALL CO(TCHAR(TCNTOUT));
		END;
	END;
 IF (INPUT(IOCS) AND (FO OR IBF OR OBF)) = 0 THEN
	DO;
	 IF((IOCCOM(KSTS)) AND KBD$RDY) > 0 THEN
		DO;
		 RETURN(IOCCOM(KEYC) AND 07FH);
		END;
	END;
 END;
 
 END;



DIRECT: PROCEDURE PUBLIC;
 TCNTIN = 0;
 TCNTOUT = 0;
 CRFLG = FALSE;
 DO FOREVER;
  CHAR=ISCAN;
  IF CHAR=PRCNT THEN
	DO;
	 CALL CO (CHAR);
		DO WHILE CHAR <> CR;
		 CHAR = ISCAN;
		 CALL SCHAR(CHAR);
		END;
	 RETURN;
	END;
  CALL SCHAR (CHAR);
	DO WHILE CHAR <> CR;
	 CHAR = ISCAN;
	 CALL SCHAR (CHAR) ;
	END;
  END;
 END DIRECT;



BAUD: PROCEDURE (BDCODEADR) BYTE PUBLIC;
 DECL BDCODEADR ADDRESS;
 DECL (BDCODE BASED BDCODEADR) (122) BYTE;
 DECL I BYTE;
 DECL J BYTE;
 DECL K BYTE;


 DECL BAUD$RATES(*) BYTE DATA ('110    ',3,'300    ',3,
                               '1200   ',4,'2400   ',4,
                               '4800   ',4,'9600   ',4);
 DECL ENTRY$LNGTH LIT '8';
 DECL MAX$BAUD LIT '6';
 DECL USRT$FCTRS(*) BYTE DATA (0CEH,04EH,04EH,04EH,04EH,04EH,0);
 DECL BAUD$FCTRS(*) ADDRESS DATA (698,256,64,32,16,08,0);
 DECL USRT$CMND LIT '027H';
 DECL SIO$RSET LIT '040H';
 DECL CNTR$CMND LIT '076H';
 DECL CNTR$CTRL LIT '0F3H';
 DECL CNTR      LIT '0F1H';

I,J,K = 0;


	DO WHILE ((K <= LENGTH(BAUD$RATES))
	  AND (J < BAUD$RATES(K + ENTRY$LNGTH-1)));
	 IF BDCODE(J) <> BAUD$RATES(K+J) THEN
		DO;
		 K = K + ENTRY$LNGTH;
		 J = 0;
		END;
	  ELSE
		DO;
		 J = J + 1;
		END;
	END;
 K = SHR(K,3);/* ASSUMES ENTRY$LNGTH = 8 */
 IF K >= MAX$BAUD THEN RETURN(1);

 OUTPUT(CNTR$CTRL) = CNTR$CMND;
 OUTPUT(CNTR) = LOW(BAUD$FCTRS(K));
 OUTPUT(CNTR) = HIGH(BAUD$FCTRS(K));
 OUTPUT(SIO$STAT) = SIO$RSET;
 CALL TIME(1);
 OUTPUT(SIO$STAT) = USRT$FCTRS(K);
 OUTPUT(SIO$STAT) = USRT$CMND;
 RETURN(0);
END BAUD;

END;
EOF;
