/***************************************************************************
* sysinfo.c: gibt einige Systeminfos mit Hilfe von TextRequest() der       *
*	     req.library aus						   *
*									   *
* created: 16-May-91 Mtwx						   *							  *
* updated: 16-May-91 Mtwx						   *
***************************************************************************/
#include "messages.h"

static struct CPU
{
  char CPU_Id[6];
  char MaC_Id[6];
} CPU;

static struct Controls
{
  long size_chip;
  long size_fast;
  long size_total;
  char *CPU_Id;
  char *MaC_Id;
} Controls;

static struct TRStructure TRStruct;

extern struct ReqLib *ReqBase;

static struct CPU CheckCPU(void);

void	  SysInfo(void)
{
  char	    Text[1024];

  Controls.size_chip = AvailMem(MEMF_CHIP);
  Controls.size_fast = AvailMem(MEMF_FAST);
  Controls.size_total=Controls.size_chip+Controls.size_fast;
  strcpy(Text,"System Info:\n\n");
  strcat(Text,FREE_CHIP);
  strcat(Text,FREE_FAST);
  strcat(Text,FREE_TOTAL);
  CPU = CheckCPU();
  strcat(Text,"CPU-Type         : %5s\n");
  Controls.CPU_Id=CPU.CPU_Id;
  strcat(Text,"Math Coprocessor : %5s");
  Controls.MaC_Id=CPU.MaC_Id;
  TRStruct.Text=Text;
  TRStruct.Controls=(char *) &Controls;
  TRStruct.NegativeText=RESUME_TEXT;
  TRStruct.Title="System-Information";
  TRStruct.textcolor=8;
  TextRequest(&TRStruct);
}

static struct CPU CheckCPU(void)
{
  char	    banner[6];

			  /* set up Intuition/AmigaDOS structure pointers */
  struct DOSBase *DOSBase;
  struct ExecBase **SysBase;
  register struct ExecBase *ExecBase;

			 /* define other variables as registers,
			  to save space */
  register int attnflag;	       /* processor type bits from ExecBase struct */

  strcpy(banner,"680");
  strcpy(CPU.CPU_Id,"");
  strcpy(CPU.MaC_Id,"");

			 /* Set up the ExecBase pointer manually,
			  since we don't link with anybody */
  SysBase = (struct ExecBase **) (4L);
  ExecBase = *SysBase;
  DOSBase = (struct DOSBase *) ReqBase->DosLib;

			 /* Only read the ExecBase structure once,
			  to save space */
  attnflag = ExecBase->AttnFlags;

  if (attnflag & AFF_68020)
    strcat(banner,"20");
  else
  {
    if (attnflag & AFF_68010)
      strcat(banner,"10");
    else
      strcat(banner,"00");
  }

  strcpy(CPU.CPU_Id, banner);

			 /* check for math co-processor */
  if (attnflag & AFF_68881)
    strcpy(CPU.MaC_Id, "68881");
  else
    strcpy(CPU.MaC_Id, "-----");

			 /* Clean up and go home */
  return (CPU);
}
