/*

	$VER: SomeInfo.c 2.0 (25.02.1997) Copyright 1991, 1997 by Dalibor Kezele

	First version: Thursday, February 16, 1991
	Last version:  Tuesday, February 25, 1997

	Source code compiled with Aztec C 5.0a.
	e-mail: dkezele@mia.os.carnet.hr

*/

#include <time.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <libraries/dos.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>

/* -------------------------------------------------------------------- */

static char version[] = 
	"$VER: SomeInfo 2.0 (25.02.1997) Copyright 1991, 1997 by Dalibor Kezele";

struct ExecBase *SysBase;
struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;

/* -------------------------------------------------------------------- */

struct TextAttr Topaz8Font = { (UBYTE *)"topaz.font", 8, 0, 0 };

char weekday[7][10] =
{"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

UBYTE *led = (UBYTE *)0xbfe001;

/* -------------------------------------------------------------------- */

struct IntuiText GText = { 1, 0, JAM1, 23, 2, &Topaz8Font, (UBYTE *)"OK", 0L };

short GCoords1[] = { 0, 10, 0, 0, 61, 0 };
short GCoords[] = { 61, 0, 61, 10, 0, 10};

struct Border GBorder1 = { 0, 0, 2, 0, JAM1, 3, &GCoords1[0], 0L };
struct Border GBorder = { 0, 0, 1, 0, JAM1, 3, &GCoords[0], &GBorder1};

struct Gadget OKGadget = { 0L, 189, 164, 62, 11, GADGHCOMP,
			GADGIMMEDIATE|RELVERIFY, BOOLGADGET, (APTR)&GBorder,
			0L, &GText, 0L, 0L, 1, 0L };

/* -------------------------------------------------------------------- */
struct Screen *WB;
struct Window *window;
struct IntuiMessage *message;

struct NewWindow newwindow = {
				100, 20, 440, 181, 0, 1,
				GADGETUP|VANILLAKEY,
				ACTIVATE|WINDOWDRAG|SMART_REFRESH|NOCAREREFRESH,
				(struct Gadget *)&OKGadget, 0L, 
				(UBYTE *)"Some Info", 0L, 0L,
				0, 0, 0, 0, CUSTOMSCREEN};

/* -------------------------------------------------------------------- */

unsigned char infostring[17][80];
struct IntuiText infotext[17];

int infocoords[17] =
{ 0, 8, 18, 26, 36, 44, 52, 62, 70, 78, 88, 96, 106, 116, 124, 132, 147 };

short Squadre2[] = { 0, 0, 0, 143, -1, 143, -1, 0, 399, 0 };
short Squadre1[] = { 399, 144, 399, 0, 400, 0, 400, 144, 1, 144 };

struct Border Border2 = { 0, 0, 2, 0, JAM1, 5, &Squadre2[0], 0L };
struct Border Border1 = { 0, 0, 1, 0, JAM1, 5, &Squadre1[0], &Border2 };

/* -------------------------------------------------------------------- */

char *number(long n)
{
	static char string1[80];
	char string2[80];
	int i, j = 0, k = 0;

	sprintf(string2, "%ld", n);

	for(i = strlen(string2)-1; i >= 0; i--) {
		if (k == 3) {
			string1[j++] = ',';
			k = 0;
			}
		string1[j] = string2[i];
		j++;
		k++;
		}
	k = strlen(string1);
	for(i = 1; i <= k; i++) string2[i-1] = string1[k-i];
	string2[k] = 0;

	return string2;
}

/* -------------------------------------------------------------------- */

int main(void)
{
long ChipMem, FastMem, LargMem;
ULONG upperstack, lowerstack;
register unsigned short count;
struct DateStamp Current;
unsigned long currenttime;
struct tm *time;
int hrs, min, sec, day, mon, yea, wee;
unsigned char clean[8] = "CHANGED", changed[8] = "  CLEAN", *string;

/* -------------------------------------------------------------------- */

if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L)))
	return 0;

if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0L))) {
	CloseLibrary(GfxBase);
	return 0;
	}

/* -------------------------------------------------------------------- */

ChipMem = AvailMem(MEMF_CHIP);
FastMem = AvailMem(MEMF_FAST);
LargMem = AvailMem(MEMF_LARGEST);

sprintf(&infostring[0], "Free CHIP memory           (bytes)   %10s", number(ChipMem));
sprintf(&infostring[1], "Free FAST memory           (bytes)   %10s", number(FastMem));
sprintf(&infostring[2], "Total free memory          (bytes)   %10s", number(ChipMem+FastMem));
sprintf(&infostring[3], "Largest free memory block  (bytes)   %10s", number(LargMem));

/* -------------------------------------------------------------------- */

upperstack = (ULONG)SysBase -> SysStkUpper;
lowerstack = (ULONG)SysBase -> SysStkLower;

sprintf(&infostring[4], "System stack lower address   (hex)    %8lxh", lowerstack);
sprintf(&infostring[5], "System stack upper address   (hex)    %8lxh", upperstack);
sprintf(&infostring[6], "System stack size          (bytes)     %8u", upperstack-lowerstack);

/* -------------------------------------------------------------------- */

if(!(SysBase -> ColdCapture)) string = &changed[0]; else string = &clean[0];
sprintf(&infostring[7], "ColdCapture vector     (condition)      %s", string);

if(!(SysBase -> CoolCapture)) string = &changed[0]; else string = &clean[0];
sprintf(&infostring[8], "ColdCapture vector     (condition)      %s", string);

if(!(SysBase -> WarmCapture)) string = &changed[0]; else string = &clean[0];
sprintf(&infostring[9], "ColdCapture vector     (condition)      %s", string);

/* -------------------------------------------------------------------- */

WB = (struct Screen *)IntuitionBase -> ActiveScreen;

sprintf(&infostring[10], "Active resolution           (size)   %4d x%4d",
 (UWORD) WB -> Width, (UWORD) WB -> Height);

switch((UWORD) GfxBase -> DisplayFlags) {
	case NTSC  :
	sprintf(&infostring[11], "Display                     (type)         NTSC");
	break;
	case GENLOC:
	sprintf(&infostring[11], "Display                     (type)      GENLOCK");
	break;
	case PAL   :
	sprintf(&infostring[11], "Display                     (type)          PAL");
	break;
	default    :
	sprintf(&infostring[11], "Display                     (type)      UNKNOWN");
	}

/* -------------------------------------------------------------------- */

if(!(*led & 2))
	sprintf(&infostring[12], "LED filter             (condition)           ON");
else
	sprintf(&infostring[12], "LED filter             (condition)          OFF");

/* -------------------------------------------------------------------- */

DateStamp(&Current);
currenttime = Current.ds_Days * 24 * 60 * 60;
currenttime += Current.ds_Minute * 60;
currenttime += Current.ds_Tick / TICKS_PER_SECOND;
time = localtime(&currenttime);
time -> tm_year += 1908;
hrs = time -> tm_hour; min = time -> tm_min; sec = time -> tm_sec;
day = time -> tm_mday; mon = (time -> tm_mon) + 1; yea = time -> tm_year;
wee = time -> tm_wday;

sprintf(&infostring[13], "Current time                           %02d:%02d:%02d", hrs, min, sec);
sprintf(&infostring[14], "Current date                         %02d.%02d.%04d", day, mon, yea);
sprintf(&infostring[15], "And today is %34s", weekday[wee]);

/* -------------------------------------------------------------------- */

sprintf(&infostring[16], "Some Info 2.0 1997            by Dalibor Kezele");

for(count = 0; count < 17; count++) {
	infotext[count].FrontPen = 1;
	infotext[count].BackPen = 0;
	infotext[count].DrawMode = JAM1;
	infotext[count].LeftEdge = 0;
	infotext[count].TopEdge = (long)infocoords[count];
	infotext[count].ITextFont = &Topaz8Font;
	infotext[count].IText = (UBYTE *)&infostring[count][0];
	infotext[count].NextText = 0L;
	}

newwindow.TopEdge = ((WB -> Height) - (newwindow.Height)) / 2;
newwindow.LeftEdge = ((WB -> Width) - (newwindow.Width)) / 2;
newwindow.Screen = (struct Screen *) WB;

if(!(window = (struct Window *)OpenWindow(&newwindow))) {
	DisplayBeep(0L);
	CloseLibrary(IntuitionBase);
	CloseLibrary(GfxBase);
	return 0;
	}

DrawBorder(window -> RPort, &Border1, 20L, 15L);

for(count = 0; count < 17; count++)
	PrintIText(window -> RPort, &infotext[count], 32L, 18L);

while(1) {
	Delay(10L);
	message = (struct IntuiMessage *) GetMsg(window -> UserPort);
	if(message -> Class == GADGETUP)
		break;
	if(message -> Class == VANILLAKEY)
		if(message -> Code == 13 || message -> Code == 27)
			break;
	}

ReplyMsg(message);
CloseWindow(window);
CloseLibrary(IntuitionBase);
CloseLibrary(GfxBase);

return 0;
}

/* -------------------------------------------------------------------- */

