$nopaging compact rom optimize(2) debug
IBM$IO: DO; 
DECLARE (DONE,COUNT,CHR) BYTE; 
 
declare true	literally '0ffh',
		false	literally '0';

DECLARE int14 POINTER; 

declare timer$pointer pointer,
		timer$byte based timer$pointer byte;

declare uart structure (baud byte, par byte, dbits byte, sbits byte);

$include(dos2.ext)

declare	 
	bios_call (*) BYTE DATA( 
	5AH,              /* POP DX */ 
	58H,              /* POP AX (DROP CODE-SEG) */ 
	58H,              /* POP AX */ 
	52H,              /* PUSH DX */ 
	0bah,00,0,		  /* mov dx,0 */
	0CDH,14H,         /* INT 14H */ 
	5AH,              /* POP DX */ 
	5FH,              /* POP DI */ 
	5BH,              /* POP BX */ 
	8EH,0C3H,         /* MOV ES,BX*/ 
	26H,89H,05H,      /* MOV ES:[DI],AL */ 
	52H,              /* PUSH DX */ 
	0C3H);            /* RET NEAR */ 
 
 
declare char word;
declare foo word;

get$prams: procedure;
	declare conn selector,
			buff(80h) byte,
			(actual,i) byte,
			(status,x) word;
			
	CONN = df_open(0,@('xfer.def',0),@STATUS);
	if status>0 then return;
	actual = df_READ(conn,80h,@buff,@STATUS);
	if actual=0 then return;
	x=findb(@('9','4','2','1','3'),buff(0),5);
	if x>4 then return;
	uart.baud=x;
	x=findb(@buff,',',5);
	if x>4 then return;
	i=x+1;
	x=findb(@('n','e','o'),buff(i),3);
	if x>2 then return;
	uart.par=x;
	if buff(i+1)<>',' then return;
	i=i+2;
	x=findb(@('8','7'),buff(i),2);
	if x>1 then return;
	uart.dbits=x;
	if buff(i+1)<>',' then return;
	i=i+2;
	x=findb(@('1','2'),buff(i),2);
	if x>1 then return;
	uart.sbits=x;
end;
	
	

u_init: procedure public;
	declare (dummy,bio,par,status) word;
	par=0;
	uart.baud=0; /* 0-9600 1-4800 2-2400 3-1200 4-300 */
	uart.par=0;  /* 0-n 1-e 2-o */
	uart.dbits=0; /* 0-8 1-7 */
	uart.sbits=0; /* 0-1 1-2 */
	call get$prams;

	do case uart.baud;
		do; BIO = df_WRITE(1,5,@('9600,'),@STATUS); par=0e0h; end;
		do; BIO = df_WRITE(1,5,@('4800,'),@STATUS); par=0c0h; end;
		do; BIO = df_WRITE(1,5,@('2400,'),@STATUS); par=0a0h; end;
		do; BIO = df_WRITE(1,5,@('1200,'),@STATUS); par=080h; end;
		do; BIO = df_WRITE(1,4,@('300,'),@STATUS); par=040h; end;
	end;

	do case uart.par;
		do; BIO = df_WRITE(1,2,@('n,'),@STATUS); end;
		do; BIO = df_WRITE(1,2,@('e,'),@STATUS); par=par or 018h; end;
		do; BIO = df_WRITE(1,2,@('o,'),@STATUS); par=par or 0e8h; end;
	end;

	do case uart.dbits;
		do; BIO = df_WRITE(1,2,@('8,'),@STATUS); par=par or 3; end;
		do; BIO = df_WRITE(1,2,@('7,'),@STATUS); par=par or 2; end;
	end;

	do case uart.sbits;
		do; BIO = df_WRITE(1,1,@('1'),@STATUS); end;
		do; BIO = df_WRITE(1,1,@('2'),@STATUS); par=par or 4; end;
	end;

	INT14=@bios_call;
	call int14(@char,par);
	output(03fch) = 3;

	timer$pointer = 46ch;

end u_init;

time$out: procedure byte public;
	declare counter$done byte;
	counter$done = timer$byte + 20;
	do while counter$done <> timer$byte;
		if u_char then return false;
	end;
	return true;
end time$out;


u_GET: PROCEDURE BYTE PUBLIC; 
	do while (input(3fdh) and 1)=0; end;
	return input(3f8h);
end u_get;
 
U_PUT: PROCEDURE (CHAR) PUBLIC; 
	DECLARE CHAR byte;
	do while (input(3fdh) and 20h)=0; end;
	output(3f8h)=char;
END U_PUT; 

u_char: procedure byte public;
	if (input(3fdh) and 1)=0 then return false;
							 else return true;
end u_char;
 
 
END IBM$IO; 
