/*
	AddCV3DMem.c

	1997 by Roberto Ragusa. This code is Public Domain.


	02-Oct-1997	Initial release.
*/

#include <string.h>

#include <exec/exec.h>
#include <libraries/configvars.h>

#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/expansion.h>

ULONG __nocommandline = 0;
void __chkabort(void) {}	/* Disable CTRL-C handling */

char template[]="KBYTES/N/A,PRIORITY/N";
LONG *array[]={NULL,NULL};

/* The default priority, set low because memory is not too fast */
#define DEFPRI 10

char versiontag[] = "\0$VER: AddCV3DMem 1.0 (02.10.97)";

char memname[] = "CV64/3D Memory";

int main(void)
{
	struct ConfigDev *cd;
	struct RDArgs* rdargs;
	int RC = 20;
	char *namememory;

	if(rdargs = ReadArgs(template,(LONG*)&array[0],NULL))
	{
		if(*array[0]<=4096 && *array[0]>0)
		{
			if(cd = FindConfigDev(NULL,8512,67)) /* find the CV64/3D board */
			{	
				if(namememory = AllocMem(strlen(memname)+1,MEMF_PUBLIC))
				{
					strcpy(namememory, memname);

					/* Graphics memory starts at offset 0x04800000 */

					AddMemList((*array[0])*1024-1024,
								  MEMF_PUBLIC|MEMF_FAST,
								  array[1]?*array[1]:DEFPRI,
								  (void *)((char *)(cd->cd_BoardAddr) + 0x04800000 + 0x400000-(*array[0]*1024)),
								  namememory);
               Printf("Memory added to system\n");
					RC=0;
				}
				else /* be paranoid ;-) */
					PrintFault(ERROR_NO_FREE_STORE, NULL);
			}
			else
				Printf("No CV64/3D installed!\n");
		}
		else
			Printf("Not more than 4096K (= 4M)!\n");

		FreeArgs(rdargs);
	}
	else
		PrintFault(IoErr(),NULL);

	return(RC);
}
