echo ; /*  Note that this declares an int available externally
 lc -cfikrsu -b1 -d0 -v -qram: -ms -O -y ecs.c
 blink ecs.o TO ecs MAP ecs.map,FHLOSX,PLAIN LIB lib:amiga.lib DEFINE _stdout=_echo SMALLDATA SMALLCODE NODEBUG VERBOSE
 quit
*/

#include <stdio.h>
#include <exec/types.h>
#include "exec/exec.h"
#include "exec/execbase.h"
#include <graphics/gfxbase.h>
#include <hardware/custom.h>
#include "libraries/dos.h"
#include "proto/exec.h"
#include "proto/dos.h"

#undef printf /* Disable Lattice 5.0 Auto-Conversion of printf() */
              /* into _writes() and _tinyprintf()                */

/**********************/
/* Global Definitions */
/**********************/
#define GFXF_HR_AGNUS   1    /* Defined in v1.4 Alpha Includes     */
#define GFXF_HR_DENISE  2    /* Defined in v1.4 Alpha Includes     */

/********************/
/* Global Variables */
/********************/
struct GfxBase    *GfxBase;  /* Graphics.Library Base Vector       */
struct DosLibrary *DOSBase;  /* Dos.Library      Base Vector       */

                             /* Pickup a Ptr to Custom Chip Region */
struct Custom     *chips = (struct Custom *)0xDFF000;

/***********************/
/* Function Prototypes */
/***********************/
void ecs(void);
int  printf(char *, );

/**********************************************************************/
/*         Enhanced Chipset (ECS) Detector Program (June '89)         */
/*              Public Domain - Do With It What You Will              *
/*                                                                    */
/*   by Jeff Rush                                                     */
/*      Sysop of Rising Star BBS @ (214) 231-1372                     */
/*      Fidonet: 1:124/4206                                           */
/*      BIX:     jrush                                                */
/*                                                                    */
/**********************************************************************/
void
ecs()
{
    UWORD agnus_id, denise_id;
    UBYTE osflags;

    if (!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0)))
        return;

    echo = (int)Output();

    printf("Enhanced Chipset (ECS) Detector Program, June '89\n");
    printf("Full Public Domain - Do What You Will\n\n");

    agnus_id  = (chips->vposr    & 0x7F00);
    denise_id = (chips->pad7c[0] & 0x00FF);;

    printf("Hardware Present:\n");
    switch (agnus_id) {
    case 0x0000: printf("  Normal Agnus Chip (PAL)\n");  break;
    case 0x1000: printf("  Normal Agnus Chip (NTSC)\n"); break;
    case 0x2000: printf("  Super Agnus Chip (PAL)\n");   break;
    case 0x3000: printf("  Super Agnus Chip (NTCS)\n");  break;
    default:     printf("  Unrecognized Agnus Chip (ID# 0x%04X)\n", agnus_id); break;
    }

    if (denise_id == 0x00FC) printf("  Super Denise Chip\n");
    else                     printf("  Normal Denise Chip\n");

    printf("\n");

    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
    if (GfxBase != NULL) {
        osflags = (GfxBase->reserved[0] >> 24) & 0x000000FF;

        if (agnus_id == 0x2000 || agnus_id == 0x3000) { /* If Super Agnus Present */
            printf("Operating System is %s of the Presence of the Super Agnus Chip\n",
                (osflags & GFXF_HR_AGNUS) ? "Aware" : "-Unaware-");
        }

        if (denise_id == 0x00FC) { /* If Super Denise Present */
            printf("Operating System is %s of the Presence of the Super Denise Chip\n",
                (osflags & GFXF_HR_DENISE) ? "Aware" : "-Unaware-");
        }

        CloseLibrary((struct Library *)GfxBase);
    } else
        printf("Error - Unable to Open GRAPHICS.LIBRARY\n");

    CloseLibrary((struct Library *)DOSBase);
}

