/*
	Z0232.C

   This program demonstrates the use of the Z180 serial port 0 configured
	for either a 3 wire RS232 communication or 4 wire full duplex RS485 
	communication.

	It also illustrates "reloading" the programming port vector, so that the
	programming port can also be used in an application. Note that once this
	is done, serial port 0 cannot be debugged.
*/

#use "default.h"

#define IBAUD   9600         /*baud rate
                                with modem either 2400 or 1200
                                without modem => 19200,9600, 4800, etc   */
#define TBUFSIZE 384         // size of transmit buffer
#define RBUFSIZE 384         // size of receive buffer

char ismodem = 0;            // set to 1 if you want modem
char isecho = 1;             // set to 1 if you want character echoed back to the pc
extern void Dz0_circ_int();

main()
{
int ercode;
int i;
int count;
char tbuf[TBUFSIZE];     // transmit buffer
char rbuf[RBUFSIZE];     // receive buffer
char buf[20];         // dummy buffer for receiving a complete command

    reload_vec(14,Dz0_circ_int); // "reload" the programming port vector

    Dinit_z0(rbuf, tbuf, RBUFSIZE, TBUFSIZE, 4, IBAUD / 1200, ismodem, isecho);

    if (!ismodem)           // if no modem, you have to service your own screen
    {                       // at power up
        Dz0send_prompt();
    }

    for (;;) // endless loop constantly monitoring for new command line
    {
		  hitwd();
        if( Dread_z0(buf, ENTER) != 0 )
        {
            Dz0send_prompt();
            Dwrite_z0("i got the message", 17);
            Dz0send_prompt();
        }
    }
}
