/* DUMP.C: Test sending large amount of data from PC to amiga
 * 1. on your amiga, type: machaddr 5
 *                         get 4
 * 2. on the PC, type:     dump 5 4
 *
 * When your interface & cables are ok, you will see dots appearing on the
 * screen, each representing a packet successfully sent. After each 15th
 * packet the number of Kbytes sent will be printed.
 *
 * (port & destination addresses can ofcourse be changed)
 */
#include <stdio.h>
#include <signal.h>
#include "pardev.h"

Header hdr;

/* length of data field in packet */
#define PLENGTH 512

void ParAbort(void)
{
  par_stop();
  printf("Aborted.\n");
  exit(1);
}

/* when writing are interrupts not really needed */
int parint(int dev)
{
}

main(int argc,char **argv)
{
 unsigned int dest,port;
 unsigned long count;              /* just some counter */
 int length;                       /* actual number of bytes sent */
 unsigned char buffer[PLENGTH];    /* buffer to be sent */

 par_init(1,LPTADDR);
 ctrlbrk(ParAbort);                /* abort this program with CTRL-C */

 dest=atoi(argv[1]);
 port=atoi(argv[2]);

 printf("Dumping data size %d to destination %d port %d\n",PLENGTH,dest,port);

 /* fill the PARnet header */
 put16((char *)&hdr.port,port);
 hdr.chksum = 0;
 put32((char *)&hdr.length,PLENGTH);

 /* writing buffer to line */
 for (count=1;count<65535;count++)     /* do this many times */
 { 
  length=parwriteV(dest,&hdr,sizeof(hdr),buffer,PLENGTH,NULL,NULL);
  if (length < 0)
    printf("ERROR %d\n",length);
  else
  { if (!(count & 15))
         printf("WROTE %08lu %d KBYTES\n",count,count * PLENGTH /1024);
    else printf(".");
  }
 }
 ParAbort();
}
