/* This program bashes on the ROM; basically, just copying the ROM around
   several times. */

#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/ports.h>
#include <exec/tasks.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <devices/timer.h>
#include <libraries/dos.h>

struct Task *FindTask();
void SubTime(), *AllocMem();
struct Device *TimerBase;

/* This routine wastes time, based on ROM access. */

#define	ROMBASE		0x00FC0000L
#define ROMSIZE		0x00030000L

void ROMBash() {
   short ctr;
   ULONG *mem;

   mem = AllocMem(ROMSIZE,0L);
   for (ctr = 0; ctr < 100; ++ctr) {
      CopyMemQuick(ROMBASE,mem,ROMSIZE);
   }
   FreeMem(mem,ROMSIZE);
}

/* This is the main program. */

void main()
{
   struct MsgPort port;
   struct timerequest treq;
   long pass;
   struct timeval origtime, finaltime;

  /* Initialize the timer stuff */
   port.mp_Node.ln_Name = "ROMBash";
   port.mp_Flags = PA_SIGNAL;
   port.mp_SigTask = FindTask(0L);
   port.mp_SigBit = AllocSignal(-1L);
   AddPort(&port);
   treq.tr_node.io_Message.mn_ReplyPort = &port;

   if (OpenDevice(TIMERNAME,0L,&treq,0L) != 0) {
      printf("Error: Can't get \"%s\"\n",TIMERNAME);
      exit(20);
   }
   TimerBase = treq.tr_node.io_Device;
   treq.tr_node.io_Command = TR_GETSYSTIME;

  /* Find the starting time */
   DoIO(&treq);
   origtime = treq.tr_time;

   ROMBash();

  /* Find the ending time */
   DoIO(&treq);
   finaltime = treq.tr_time;   

   SubTime(&finaltime,&origtime);
   
   printf("DONE: Elapsed time = %ld.%6ld seconds\n",
          finaltime.tv_secs,finaltime.tv_micro);

   CloseDevice(&treq);
   RemPort(&port);
   FreeSignal((ULONG)port.mp_SigBit);
}
