/*	CPU
 *
 *	Displays CPU type and presence of a math co-processor.
 *	Also Displays video type and whether system clocking is internal
 *	    or from a GenLock.
 *
 *	Thad Floryan
 *
 *	V1.0	29-March-1987	original program
 *	V1.1	22-July-1988	separated test for 68881 from 68020 test
 *	V2.0	12-August-1988	added video type and system clocking display
 *
 * Building instructions (Manx):
 *
 *	CLI> cc cpu
 *	CLI> ln cpu -lc
 */

#include <stdio.h>
#include <exec/exec.h>
#include <exec/types.h>
#include <exec/execbase.h>
#include <exec/libraries.h>
#include <graphics/gfxbase.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>

extern char		 *AllocMem();
extern void		  CloseLibrary();
extern void		  FreeMem();
extern struct Library	 *OpenLibrary();
extern struct FileHandle *Output();
extern void		  Write();

extern struct ExecBase	 *SysBase;

static char		 *buf;
static char		 *bufptr;
static struct FileHandle *outfile;

static char *Version = "CPU V2.0, Thad Floryan, 12-Aug-1988";

#define _WCHR(s) *bufptr++ = s

main()
{
    void WSTR();
    register UWORD		 Flags;
    register struct GfxBase	*GfxBase;

    outfile = Output();		/* initialize output handle */

    buf = bufptr = AllocMem(200L, MEMF_CLEAR);

    WSTR("The CPU is a 680");

    Flags = SysBase->AttnFlags;

    if (Flags & AFF_68010)
    {
        if (Flags & AFF_68020)
	    _WCHR('2');		/* 68020 */
	else
	    _WCHR('1');		/* 68010 */
    }
    else _WCHR('0');		/* 68000 */
    _WCHR('0');

    if (Flags & AFF_68881)
	WSTR(" with a 68881");
    _WCHR('\n');

    GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 33L);

    if (GfxBase)
    {
	WSTR("The video is ");
	if (GfxBase->DisplayFlags & NTSC)
	    WSTR("NTSC");
	else
	    if (GfxBase->DisplayFlags & PAL)
		WSTR("PAL");
	    else
		WSTR("other");

	WSTR(" and system clocking is ");
	if (GfxBase->DisplayFlags & GENLOC)
	    WSTR("from a GenLock\n");
	else
	    WSTR("internal\n");

	CloseLibrary(GfxBase);
    }

    _WCHR('\0');

    Write(outfile, buf, (long)strlen(buf));
    FreeMem(buf, 200L);
}

/*
 *	WSTR()  --  appends a string to currently-being-built display buffer
 */

void WSTR(sptr)
    char  *sptr;
{
    while (*sptr)
    {
	_WCHR(*sptr++);
    }
}
