#include <aes.h>
#include <stdio.h>
#include <stdlib.h>
#include <macros.h>
#include <osbind.h>

#ifndef _sysbase
#define _sysbase  0x0004F2
#endif


SYSHDR *tos_hdr;
int    tos_ver;
long   tos_date;
char   tos_info1[30];
char   tos_info2[30];
char   gemdos_info[30];
char   res_info[30];
char   mem_info[30];
char   buf[256];
int    ap_id;
int    aes_msg[8];


void get_tos_ver ()
{
   tos_hdr = *((SYSHDR **) _sysbase);
   if (tos_hdr != NULL)
   {
      tos_ver  = tos_hdr->os_version;
      tos_date = tos_hdr->os_gendat;
   }
}


int main ()
{
   int  i, x, y, w, h;

   Supexec (get_tos_ver);
   if (tos_hdr == NULL)
   {
      sprintf (tos_info1, "*** TOS not found ***");
      strcpy (tos_info2, "_sysbase is null");

   } else {

      i = hiword (tos_date);
      sprintf (tos_info1, "TOS %X.%02X, Rel. %02X-%02X-%04X",
         hibyte (tos_ver), lobyte (tos_ver),
         hibyte (i), lobyte (i), loword (tos_date));         
         
      sprintf (tos_info2, "_sysbase = $%06lX", (long) tos_hdr);
   }

   i = Sversion ();
   sprintf (gemdos_info, "Gemdos %d.%d", lobyte (i), hibyte (i));

   sprintf (res_info, "Resolution XBios(4): %d", (int) Getrez());
   sprintf (mem_info, "%ld bytes free", (long) Malloc (-1L));

   ap_id = appl_init ();
   if ((ap_id == -1) || (global[0] == 0))
   {
      printf ("\n%s\n%s\n%s, AES not available\n%s\n%s\n",
         tos_info1, tos_info2, gemdos_info, res_info, mem_info);

      printf ("\npress any key...");
      getch ();
      printf ("\n");

   } else {

      wind_get (0, WF_CURRXYWH, &x, &y, &w, &h);
      sprintf (res_info, "Resolution: %d * %d", w, h);

      sprintf (buf, "[0][%s |%s |%s,  AES %X.%02X |%s |%s ][ OK ]",
         tos_info1, tos_info2, gemdos_info,
         hibyte (global[0]), lobyte (global[0]),
         res_info, mem_info);

      if (!_app)
      {
         menu_register (ap_id, "  XInfo...");
         for (;;)
         {
            evnt_mesag (aes_msg);
            if (aes_msg[0] == AC_OPEN)
               form_alert (1, buf);
         }
      } else {
         form_alert (1, buf);
         appl_exit ();
     }
   }

   return (0);
}
  
