/*
	Z0CRTS.C

	This program tests the CTS0 and RTS0 lines from port z0 of the Z180 for
	those boards which support 5 wire communication and handshaking.

	Configure port z0 for 5 wire communication and loop back RTS0 to CTS0.
	This program should toggle the RTS0 line regardless (verified by a scope).
	The state of the RTS0 line is monitored and printed continuously.

	If using port z0 of the Z180 for programming, do not connect RTS0 to CTS0.
	This will result in a loss of communication with Dynamic C.

	If you wish to	observe the effect on CTS0 with the stdio window, use an
	XP8700/UART expansion board for the programming port. This will free up the
	z0 port of the Z180 so that RTS0 can be tied to CTS0 for observation within
	the stdio window of Dynamic C.
*/

main()
{
auto char oldCTS, newCTS, RTSState;
	
	oldCTS = 0;
	RTSState = 0;

	while(1)
	{
		newCTS = inport(CNTLB0) & 0x20;				//	get new CTS status

		if (oldCTS != newCTS) {							//	CTS changed state?
			printf("CTS is now %d\n",newCTS?1:0);	//	gets printed
			oldCTS = newCTS;								//	store current state
		}
		
		outport(CNTLA0,(inport(CNTLA0)&0xef)|(RTSState?0x10:0));

		RTSState = !RTSState;	//	toggle the RTS state
		printf("RTS is now %d\n",RTSState);	//	gets printed

		hitwd();
	}
}