
#include <proto/exec.h>
#include <proto/dos.h>
#include <dos/notify.h>
#include <libraries/delfina.h>

struct Library *DelfinaBase;

#define TYPE DMEMF_XDATA

static unsigned short buf[8192];
int mem;

compare(void) {
	int x,delf,amy,errors=0,loop;
	
	for (loop=0;loop<100;loop++) {
		Delf_CopyMem((int)buf,mem,16384,DCPF_16BIT|TYPE|DCPF_TO_DELFINA);
		for (x=0;x<8192;x++) {
			Delf_Peek(mem+8192,TYPE);
			delf=Delf_Peek(mem+x,TYPE);
			if (delf & 0xff0000) errors++;
			delf&=0xffff;
			amy=buf[x] & 0xffff;
			if (delf!=amy) errors++;
		}
	}
	printf("%d errors in 819200 reads, %5f%%\n\n",errors,errors/8192.0);
}

main()
{
	int x;

	DelfinaBase=OpenLibrary("delfina.library",0);
	if (!DelfinaBase) {
		printf("Can't open delfina.library");
		return;
	}

	mem=Delf_AllocMem(8193,TYPE|DMEMF_ALIGN_8K|DMEMF_CLEAR);
	if (!mem) {
		CloseLibrary(DelfinaBase);
		printf("Need 8k of X memory in delfina!\n");
		return(0);
	}

	for (x=0;x<8192;x++) buf[x]=0xfffe;
	
	printf("worst case:\n");
	compare();


	for (x=0;x<8192;x++) buf[x]=x<<3;
	
	printf("real world:\n");
	compare();
	
	Delf_FreeMem(mem,TYPE);

	CloseLibrary(DelfinaBase);
}
	