/*
 *  TALK.C
 *
 *  TALK addr port
 *
 *  Send continuous chatter to the specified port
 */

#include "defs.h"
#include <exec/types.h>
#include <exec/io.h>
#include <exec/ports.h>
#include <libraries/dos.h>
#include <devices/parnet.h>

typedef struct IORequest IOR;

IOParReq iob;

extern PORT *CreatePort();

int
brk(void)
{
    return(0);
}

void
main(ac, av)
int ac;
char *av[];
{
    PORT *port = CreatePort(NULL, 0);
    char buf[16];
    int cnt = 0;

    onbreak(brk);
    iob.io_Message.mn_ReplyPort = port;
    iob.io_Addr = atoi(av[1]);
    iob.io_Port = atoi(av[2]);
    iob.io_Flags= PRO_DGRAM;

    if (OpenDevice("parnet.device", 0, (IOR *)&iob, 0)) {
	printf("Unable to open parnet.device, error %d %d\n", iob.io_Error, iob.io_Actual);
	exit(1);
    }
    printf("Device $%08lx Unit $%08lx\n", iob.io_Device, iob.io_Unit);
    for (;;) {
	if (SetSignal(0, SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F) & SIGBREAKF_CTRL_E)
	    break;
	sprintf(buf, "%07ld\n", cnt++);
	printf(buf);
	iob.io_Command = CMD_WRITE;
	iob.io_Data    = (APTR)buf;
	iob.io_Length  = 8;
	DoIO((IOR *)&iob);
	printf("write %d error %d\n", iob.io_Actual, iob.io_Error);
    }
    CloseDevice((IOR *)&iob);
    DeletePort(port);
}


