/* 12/19/09 */

/* Sysinfo.c, system info with LCARS graphics */


#include "sysinfo.h"



/* SysInfoHddCapacity() was modified from the following,
	since the DJGPP function for this doesn't work properly:
 * hdd.c
 * Copyright (C) 1998, 1999, 2000, 2001 Prashant TR
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * See the file COPYING.TR for more details.
 *
*/
/* Returns HDD capacity in MB, doesn't work on XP Home Edition,
	perhaps not on others.  Not called if Windows is detected */
int SysInfoHddCapacity()
{
/*  comments removed to rem out and compile with MinGW */
/*
	char output[256];
	unsigned char lasthdd;
	__dpmi_regs regs;
	int cyl, sect, head;

	
	lasthdd = 0x80;
	do {

		regs.h.ah = 0x15;
		regs.h.dl = lasthdd; 
		__dpmi_int (0x13, &regs);
		
		if (regs.x.flags & 1 || regs.h.ah != 3) {
			return ( (cyl * sect * head * .5)/1024 );
		}
		
		regs.h.ah = 8;
		regs.h.dl = lasthdd; 
		__dpmi_int (0x13, &regs);

		
		cyl = ((regs.h.cl & 0xc0) << 2) + regs.h.ch + 1;
		sect = regs.h.cl & 0x3f;
		head = 	regs.h.dh + 1;

		
		lasthdd++;
	} while (1);
*/
	return(0);
}
int SysInfoMakeCpuInfoFile()
{
/* This calls a program supplied by Intel */
/* We probably could have written something better. */
/*
	if(! exists("c:\\lcars24\\system\\cpuspeed.exe")) return(86);
	system("c:\\lcars24\\system\\cpuspeed>c:\\lcars24\\data\\cpu.txt");
*/
	return(0);
}

/* All Starfleet code from here! Simple, but doesn't rely on
	cheater files supplied by manufacturers.
	It does use some DJGPP functions that may not work as advertised.
*/

void SysInfoNetwork()
{
/*
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);

	PutsFont21(t1,y,ORANGE,"Network:");
	PutsFont21(t2,y,PALEBLUE,"Not installed");
*/
}
void SysInfoFiles()
{
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);

	PutsFont21(t1,y,ORANGE,"Text:");
	PutsFont21(t2,y,PALEBLUE,"txt, bat, c, cpp, cfg, h, pas,");
	y+=32;
	PutsFont21(t2,y,PALEBLUE,"config.sys, htm, sfm, msd");
	y+=32;
	PutsFont21(t1,y,ORANGE,"Image:");
	PutsFont21(t2,y,PALEBLUE,"bmp, jpg, gif");
	y+=32;
	PutsFont21(t1,y,ORANGE,"Sound:");
	PutsFont21(t2,y,PALEBLUE,"wav, mp3, mid");
	y+=32;
	PutsFont21(t1,y,ORANGE,"Rendering:");
	PutsFont21(t2,y,PALEBLUE,"htm, sfm, msd");
}
void SysInfoFonts()
{
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);

	PutsFont21(t1,y,ORANGE,"LCARS Standard:");
	PutsFont21(t2,y,PALEBLUE,"14, 19, 21, 26, 36, (56 + 28x)");
	y+=32;
	PutsFont21(t1,y,ORANGE,"Cartography:");
	PutsFont21(t2,y,PALEBLUE,"8, 11, 13, 24");
	y+=32;
	PutsFont21(t1,y,ORANGE,"Typescript:");
	PutsFont21(t2,y,PALEBLUE,"13");
	y+=32;
	PutsFont21(t1,y,ORANGE,"Web-Page Default:");
	PutsFont21(t2,y,PALEBLUE,"10");
}
void SysInfoColors()
{
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5)-18;
	int t3=47+(36*9);

	if(Endgame==0) PutsFont21(t1,y,ORANGE,"Standard:");
		else PutsFont21(t1,y,PALEBLUE,"Endgame mode:");

	if(Endgame==0) OfflineType4(t2,y,ORANGE, "FF9900");
		else OfflineType4(t2,y,ORANGE, "FF9933");
	OfflineType2(t3,y,MANGO, "FF9966");
	y+=47;
	if(Endgame==0) OfflineType4(t2,y,LILAC, "CC99CC");
		else OfflineType4(t2,y,LILAC, "FFCCFF");
	if(Endgame==0) OfflineType2(t3,y,PURPLE, "CC6699");
		else OfflineType2(t3,y,PURPLE, "996699");
	y+=47;
	if(Endgame==0) OfflineType4(t2,y,BRICK, "CC6666");
		else OfflineType4(t2,y,BRICK, "FF6666");
	OfflineType2(t3,y,NAPLES, "FFCC99");
	y+=47;
	if(Endgame==0) OfflineType4(t2,y,SKYBLUE, "99CCFF"); /* new */
		else OfflineType4(t2,y,SKYBLUE, "33FFCC");
	if(Endgame==0) OfflineType2(t3,y,PALEBLUE, "9999FF");
		else OfflineType2(t3,y,PALEBLUE, "33CC99");
	y+=47;
	ButtonType1(t1+18,y,WHITE,"CCCCFF");
	OfflineType4(t2,y,BIGBLUE, "6666FF");
	if(Endgame==0) OfflineType2(t3,y,TAN, "CC9966");
		else OfflineType2(t3,y,TAN, "FF0066");      /* new */
	y+=47;
	ButtonType1(t1+18,y,RED,"FF3300");
	OfflineType4(t2,y,SEABLUE, "6699CC");  /* new */
	OfflineType2(t3,y,KHAKI, "CCCC66");	/* new */
	y+=47;
	ButtonType1(t1+18,y,DARKRED,"993300");
	OfflineType4(t2,y,LAVENDER, "9966FF");  /* new, formerly GRAY (999999) */
	OfflineType2(t3,y,OLIVE, "999933");
}
void SysInfoEquip()
{
/*
	char OutStr[80];
	char *s;
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);
	unsigned equip, equipcode;

	equip = biosequip();

	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"Math coprocessor:");
	if( equip & 0x0002) strcpy(OutStr,"Installed");
		else strcpy(OutStr,"None Installed");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"DMA:");
	if( equip & 0x0100) strcpy(OutStr,"Not Available");
		else strcpy(OutStr,"Available");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"Floppy-Disk Drive:");
	if( equip & 0x0001) strcpy(OutStr,"Connected");
		else strcpy(OutStr,"None Connected");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Hard-Disk Drive:");
	if(DosDetected==TRUE) {
		sprintf(OutStr,"%d",SysInfoHddCapacity());
		strcat(OutStr," megabytes");
	} else strcpy(OutStr, "Capacity not detectable under Windows");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Printer Port:");
	if( equip & 0xc000) strcpy(OutStr,"Equipped");
		else strcpy(OutStr,"None");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Serial Ports:");
	equipcode = equip & 0x0e00;
	sprintf(OutStr, "%ld", equipcode >>9);
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;

	PutsFont21(t1,y,ORANGE,"Game I/O:");
	if( biosequip() & 0x1000) strcpy(OutStr,"Installed");
		else strcpy(OutStr,"None");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Pointing Device:");
	if( biosequip() & 0x0004) strcpy(OutStr,"Port Equipped");
		else strcpy(OutStr,"None");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Hardware Modem:");
	if( biosequip() & 0x2000) strcpy(OutStr,"Installed");
		else strcpy(OutStr,"None");
	PutsFont21(t2,y,PALEBLUE,OutStr);
*/
}
void SysInfoAudio()
{
	char OutStr[80];
	char OutStr2[80];
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);
	int j,k;
        size_t i;

	install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT,"DETECT");
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"Sound Card:");
	strcpy(OutStr,digi_driver->name);
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Specifications:");

	strcpy(OutStr,digi_driver->desc);

	if(strlen(OutStr) > 30) {
		i=0;
		do {
			t = OutStr[i];
			if( t == ',') break;
			if( t == 0) break;
			++i;
		} while(1);
		i+=2;
		k=i;
		j=0;
		do {
			t = OutStr[i];
			OutStr2[j]=(t);
			if( t == 0) break;
			++i;
			++j;
		} while(1);

		i=strlen(OutStr);
		for(j=k; j < i; ++j) OutStr[j]=(null);

		PutsFont21(t2,y,PALEBLUE,OutStr);
		y+=32;
		PutsFont21(t2,y,PALEBLUE,OutStr2);
	} else 	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"MIDI Interface:");
	strcpy(OutStr,"Windows MIDI System");
	PutsFont21(t2,y,PALEBLUE,OutStr); 
	y+=32;
	PutsFont21(t1,y,ORANGE,"Specifications:");
/*	strcpy(OutStr,midi_driver->desc); */
/*	PutsFont21(t2,y,PALEBLUE,OutStr); */

	remove_sound();
}
void SysInfoVideo()
{
	char OutStr[80];
	char CatStr[20];
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);

	memset(OutStr,(null),80);
	memset(CatStr,(null),20);
	PutsFont21(t1,y,ORANGE,"Current Mode:");

	if(ScreenSize==1024) strcpy(OutStr,"1024 x 768 pixels, ");
		else strcpy(OutStr,"800 x 600 pixels, ");

	sprintf(CatStr,"%d",DepthFound);
	strcat(OutStr,CatStr);

	strcat(OutStr,"-bit color");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Driver:");
	strcpy(OutStr,gfx_driver->name);
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Video RAM:");
	sprintf(OutStr, "%ld kilobytes", gfx_driver->vid_mem/1024);
	PutsFont21(t2,y,PALEBLUE,OutStr);
}
void SysInfoOS()
{
	char OutStr[80];
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);

	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"OS Type:");
	if(os_type==OSTYPE_UNKNOWN) strcpy(OutStr,"DOS");
		else strcpy(OutStr,"High-Overhead Type");
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
/*
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"DOS Version:");
	PutsFont21(t2,y,PALEBLUE,DosVerStr);
	y+=32;
*/
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"User Interface:");
	PutsFont21(t2,y,PALEBLUE,"LCARS 24 v. 4.0.6W, January 2010");
}
void SysInfoCpu()
{
/*

	char OutStr[80];
	int y=47+(32*4);
	int t1=83;
	int t2=47+(36*5);
	int i,j, Result;

	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"CPU Vender:");
	sprintf(OutStr,"%s",cpu_vendor);
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	PutsFont21(t1,y,ORANGE,"Family:");
	if(cpu_family==4) PutsFont21(t2,y,PALEBLUE,"486");
	if(cpu_family==5) PutsFont21(t2,y,PALEBLUE,"Pentium");
	if(cpu_family==6) PutsFont21(t2,y,PALEBLUE,"Pentium Pro");
	y+=32;
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"Model:");
	sprintf(OutStr,"%d",cpu_model);
	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"Capabilities:");
	sprintf(OutStr,"%d",cpu_capabilities);

	if(cpu_capabilities & CPU_FPU) strcat(OutStr,", FPU");
	if(cpu_capabilities & CPU_SSE) strcat(OutStr,", SSE");
	if(cpu_capabilities & CPU_SSE2) strcat(OutStr,", SSE2");
	if(cpu_capabilities & CPU_MMX) strcat(OutStr,", MMX");
	if(cpu_capabilities & CPU_MMXPLUS) strcat(OutStr,", MMX+");
	if(cpu_capabilities & CPU_3DNOW) strcat(OutStr,", 3DNow!");
	if(cpu_capabilities & CPU_ENH3DNOW) strcat(OutStr,", Enh 3DNow!");

	PutsFont21(t2,y,PALEBLUE,OutStr);
	y+=32;
	memset(OutStr,(null),80);
	PutsFont21(t1,y,ORANGE,"Speed:");
	memset(OutStr,(null),80);

	if( ! DosDetected) {
		strcpy(OutStr,"OS busy; speed compromised");
		goto skiptest;
	}

	if(DosDetected) Result=SysInfoMakeCpuInfoFile();
		else {
			strcpy(OutStr,"CPU overtaxed in background");
			goto skiptest;
		}
	if( Result==86) {
		strcpy(OutStr,"Intel test program missing");
		goto skiptest;
	}

	SetCurrentFile("\\DATA\\CPU.TXT");
	LoadTextFile();
	i=0;
	do {
		t = Ln[EndText-2][i];
		if( isdigit(t)) break;
		if( t == 0) break;
		++i;
	} while(1);
	j=0;
	do {
		t = Ln[EndText-2][i];
		OutStr[j]=(t);
		if( t == 0) break;
		++i;
		++j;
	} while(1);
skiptest:
	PutsFont21(t2,y,PALEBLUE,OutStr);
*/

}
void SysInfoButtons(int Button, int Status)
{
	int KeyColor=NAPLES;

	rectfill(screen,47,50,541,550, BLACK);
	switch( Button )
	{
		case 1: rectfill(screen,542,64,713,101, BLACK);
			if(Status) {
				OfflineType4(47, 111, LILAC, "F1");
	PutsScorpio(184, 117, LILAC, "OPERATING SYSTEM & GUI");
			} else {
				ButtonType4(543, 64, LILAC, "OS", "F1", KeyColor);
			}
			return;
		case 2: rectfill(screen,542,64+47,713,148, BLACK);
			if(Status) {
				OfflineType4(47, 111, PURPLE, "F2");
	PutsScorpio(184, 117, PURPLE, "CENTRAL PROCESSING UNIT");
			} else {
				ButtonType4(543, 64+47, PURPLE, "CPU", "F2", KeyColor);
			}
			return;
		case 3: rectfill(screen,542,64+(47*2),713,101+(47*2), BLACK);
			if(Status) {
				OfflineType4(47, 111, LILAC, "F3");
	PutsScorpio(184, 117, LILAC, "VIDEO");
			} else {
				ButtonType4(543, 64+(47*2), LILAC, "VIDEO", "F3", KeyColor);
			}
			return;
		case 4: rectfill(screen,542,64+(47*3),713,101+(47*3), BLACK);
			if(Status) {
				OfflineType4(47, 111, PURPLE, "F4");
	PutsScorpio(184, 117, PURPLE, "AUDIO");
			} else {
				ButtonType4(543, 64+(47*3), PURPLE, "AUDIO", "F4", KeyColor);
			}
			return;
		case 5: rectfill(screen,542,64+(47*4),713,101+(47*4), BLACK);
			if(Status) {
				OfflineType4(47, 111, LILAC, "F5");
	PutsScorpio(184, 117, LILAC, "EQUIPMENT");
			} else {
				ButtonType4(543, 64+(47*4), LILAC, "EQUIPMENT", "F5", KeyColor);
			}
			return;
		case 6: rectfill(screen,542,64+(47*5),713,101+(47*5), BLACK);
			if(Status) {
				OfflineType4(47, 111, PURPLE, "F6");
	PutsScorpio(184, 117, PURPLE, "LCARS GUI COLORS");
			} else {
				ButtonType4(543, 64+(47*5), PURPLE, "LCARS COLORS", "F6", KeyColor);
			}
			return;
		case 7: rectfill(screen,542,64+(47*6),713,101+(47*6), BLACK);
			if(Status) {
				OfflineType4(47, 111, LILAC, "F7");
	PutsScorpio(184, 117, LILAC, "FONT SIZES");
			} else {
				ButtonType4(543, 64+(47*6), LILAC, "FONTS", "F7", KeyColor);
			}
			return;
		case 8: rectfill(screen,542,64+(47*7),713,101+(47*7), BLACK);
			if(Status) {
				OfflineType4(47, 111, PURPLE, "F8");
	PutsScorpio(184, 117, PURPLE, "FILE FORMATS SUPPORTED");
			} else {
				ButtonType4(543, 64+(47*7), PURPLE, "FILE FORMATS", "F8", KeyColor);
			}
			return;
		case 9: rectfill(screen,542,64+(47*8),713,101+(47*8), BLACK);
			if(Status) {
				OfflineType4(47, 111, LILAC, "F9");
	PutsScorpio(184, 117, LILAC, "NETWORK");
			} else {
				ButtonType4(543, 64+(47*8), LILAC, "NETWORK", "F9", KeyColor);
			}
			return;
		default: return;
	}
}
int SystemInfoWindowActive()
{
	char CurrentButton=1;

	SysInfoButtons(2, 0);
	SysInfoButtons(3, 0);
	SysInfoButtons(4, 0);
	SysInfoButtons(5, 0);
	SysInfoButtons(6, 0);
	SysInfoButtons(7, 0);
	SysInfoButtons(8, 0);
	SysInfoButtons(9, 0);
	SysInfoButtons(1, 0);
	SysInfoButtons(1, 1);
	SysInfoOS();

loopback:
	PanelBeep();
	do {
		PopPutTime(1);
	} while(!keypressed());
	c = GetKey();
	switch( c )
		{
			case F12: 	return(0);
			case F1:	if(CurrentButton==1) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(1, 1);
					CurrentButton=1;
					SysInfoOS();
					goto loopback;
			case F2:		ScoldUser();
					goto loopback;
					if(CurrentButton==2) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(2, 1);
					CurrentButton=2;
					SysInfoCpu();
					goto loopback;
			case F3:	if(CurrentButton==3) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(3, 1);
					CurrentButton=3;
					SysInfoVideo();
					goto loopback;
			case F4:	if(CurrentButton==4) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(4, 1);
					CurrentButton=4;
					SysInfoAudio();
					goto loopback;
			case F5:		ScoldUser();
					goto loopback;
					if(CurrentButton==5) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(5, 1);
					CurrentButton=5;
					SysInfoEquip();
					goto loopback;
			case F6:	if(CurrentButton==6) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(6, 1);
					CurrentButton=6;
					SysInfoColors();
					goto loopback;
			case F7:	if(CurrentButton==7) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(7, 1);
					CurrentButton=7;
					SysInfoFonts();
					goto loopback;
			case F8:	if(CurrentButton==8) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(8, 1);
					CurrentButton=8;
					SysInfoFiles();
					goto loopback;
			case F9:		ScoldUser();
					goto loopback;
					if(CurrentButton==9) goto loopback;
					SysInfoButtons(CurrentButton, 0);
					SysInfoButtons(9, 1);
					CurrentButton=9;
					SysInfoNetwork();
					goto loopback;
			case CTRL_F1: Screenshot792("SysInfo8.bmp");
					PanelBeep();
					goto loopback;
			default:  ScoldUser();
					goto loopback;
		}
}

int SystemInfoMode()
{
	int Result;

	rectfill(screen,0,0,800,600,BLACK);
	PopsicleSticks(LILAC);
	PutsLuna(679,575-9, BLACK,LILAC, "CLOSE: F12");
	null=0;
	Title("SYSTEM INFO");
	Result = SystemInfoWindowActive();

	return(Result);
}

