/**
 * Scout - The Amiga System Monitor
 *
 *------------------------------------------------------------------
 *
 * 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
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * You must not use this source code to gain profit of any kind!
 *
 *------------------------------------------------------------------
 *
 * @author Andreas Gelhausen
 * @author Richard Körber <rkoerber@gmx.de>
 */



#define USE_SCOUT_LOGO_COLORS
#define USE_SCOUT_LOGO_BODY

#include "scout_extras.h"
#include "/scout_logo.h"

#define WINDOWTITLELEN  80

extern struct Library   *GfxBase;
extern struct ExecBase  *SysBase;
extern APTR AboutText;

static char SPACE40[] = "                                        ";

UBYTE  updatetimetext[] = "1.0\0\0\0\0\0";
ULONG  updatetimestate;

ULONG MakeListID (char a, char b, char c, char d) {

   if (opts.SingleWindows) {
      return ((ULONG) ('L')<<24 | (ULONG) ('I')<<16 | (ULONG) ('S')<<8 | (ULONG) ('T'));
   } else {
      return ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d));
   }
}

ULONG MakeDetailID (char a, char b, char c, char d) {

//   if (opts.SingleWindows) {
//      return ((ULONG) ('M')<<24 | (ULONG) ('O')<<16 | (ULONG) ('R')<<8 | (ULONG) ('E'));
//   } else {
      return ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d));
//   }
}

struct Node *HandleNodeDetails (APTR list, char *type) {
   struct ListEntry  *entryp;
   struct Node       *node = NULL;

   if (entryp = GetActiveEntry (list)) {
      node = MyFindName (type, entryp->le_address);
      if (!node)
         MyRequest ("Continue", "Sorry, can't find that %ls!", type);
   }
   return (node);
}

void MySetContents (APTR textfield, char *fmt, ...) {
   va_list arg;
   char buf[512];

   va_start(arg,fmt);
   vsprintf(buf, fmt, arg);
   va_end(arg);

   set (textfield, MUIA_Text_Contents, buf);
}

void MySetContentsHealed (APTR textfield, char *fmt, ...) {
   va_list arg;
   char buf[512];

   va_start(arg,fmt);
   vsprintf(buf, fmt, arg);
   va_end(arg);

   healstring (buf);
   set (textfield, MUIA_Text_Contents, buf);
}

void MyFreeStructs (struct Remember **rem, APTR listtext, APTR list) {
   if (*rem) {
      if (AP_Scout) {
         if (listtext)
            set (listtext,MUIA_Text_Contents,"");
         if (list)
            DoMethod (list,MUIM_List_Clear);
      }
      FreeRemember (rem, TRUE);
      *rem = NULL;
   }
}

void SetCountText (APTR counttext, int structcnt) {
   MySetContents (counttext, ESC "r%04d", structcnt);
}

void SetCloseRequest (APTR window, int id) {
   DoMethod (window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,AP_Scout,2,MUIM_Application_ReturnID,id);
}

struct WinFree *SingleDetailWinFree = NULL;

char *MyGetWindowTitle (char *titleptr, char *type) {
   int i;

   if (type[0] == '\0') {
      strcpy (tmpstr, "SCOUT");
   } else {
      sprintf (tmpstr, "SCOUT: %ls", type);
   }
   Forbid();
   if (FindPort ("AMITCP")) {
      Permit();
      if (opts.Host) {
         strcat (tmpstr, "   [ ");
         strcat (tmpstr, opts.Host);
         strcat (tmpstr, " ]");
      } else {
         Permit();
         strcat (tmpstr, "   [ LOCALHOST ]");
      }
   }

   for (i = 7; i < strlen (tmpstr); i++) {
      tmpstr[i] = toupper (tmpstr[i]);
   }
   strcpy (titleptr, tmpstr);
   return (titleptr);
}

void HandleFlagsButtonPressed (APTR button, struct WinFree *ptr, char *title2, char *fieldname, ULONG flags, struct LongFlag *longflag, struct MaskedLongFlag *mlongflag, char fieldtype) {
   struct WinFlag *winflag;

   if (winflag = AllocRemember (&ptr->wf_RememberKey, sizeof (struct WinFlag), MEMF_ANY|MEMF_CLEAR)) {
      winflag->wf_title2 = title2;
      winflag->wf_fieldname = fieldname;
      winflag->wf_flags = flags;
      winflag->wf_longflag = longflag;
      winflag->wf_mlongflag = mlongflag;
      winflag->wf_fieldtype = fieldtype;
      DoMethod (button,MUIM_Notify,MUIA_Pressed,FALSE,AP_Scout,3,MUIM_WriteLong,(ULONG) winflag,(ULONG *) &WinFlag_ToDo);
   }
}

void HandleWindowOpen (struct WinFree *ptr, char *titlepart1, char *titlepart2) {
   UBYTE *fulltitle;
   UBYTE *titlepart2ptr;

   if (opts.SingleWindows && SingleDetailWinFree) {
      WinFree_ToDo = SingleDetailWinFree;
      RemoveWinFree ();
   }
   SingleDetailWinFree = ptr;
   titlepart2ptr = nonetest (titlepart2);

   fulltitle = AllocRemember (&ptr->wf_RememberKey, strlen(titlepart1) + strlen(titlepart2ptr) + 4, MEMF_ANY|MEMF_CLEAR);
   sprintf (fulltitle, "%s%s", titlepart1, titlepart2ptr);
   healstring (fulltitle);

   set (ptr->wf_Window,MUIA_Window_Title,fulltitle);
   DoMethod (AP_Scout,OM_ADDMEMBER,ptr->wf_Window);
   SetWindowOpen (ptr->wf_Window,NULL,NULL);
}

void HandleWindowClose (struct WinFree *ptr) {
   DoMethod (ptr->wf_Window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,AP_Scout,3,MUIM_WriteLong,(ULONG) ptr,(ULONG *) &WinFree_ToDo);
   SetCloseRequest (ptr->wf_Window,ID_REMOVEWINFREE);
}

ULONG LastListID = NULL;

void SetWindowOpen (APTR window, APTR active, ULONG ListID) {
   if (opts.SingleWindows) {
      if (ListID) {
         if (LastListID && (LastListID != ListID)) {
            if (SingleDetailWinFree) {
               WinFree_ToDo = SingleDetailWinFree;
               RemoveWinFree ();
            }
          DoMethod (AP_Scout,MUIM_Application_ReturnID,LastListID);
         }
         LastListID = ListID;
      }
   }

   set (window,MUIA_Window_Open,TRUE);
}

void SetWindowClose (APTR window, BOOL IsList) {
   if (opts.SingleWindows && IsList) {
      if (SingleDetailWinFree) {
         WinFree_ToDo = SingleDetailWinFree;
         RemoveWinFree ();
      }
   }
   set (window,MUIA_Window_Open,FALSE);
}

void ApplicationSleep (void) {
   set (AP_Scout,MUIA_Application_Sleep,TRUE);
}

void AwakeApplication (void) {
   set (AP_Scout,MUIA_Application_Sleep,FALSE);
}

void RedrawActiveEntry (APTR list) {
   DoMethod (list, MUIM_List_Redraw, MUIV_List_Redraw_Active);
}

void RemoveActiveEntry (APTR list) {
   DoMethod (list, MUIM_List_Remove, MUIV_List_Redraw_Active);
}

void InsertBottomEntry (APTR list, APTR *entry) {
   DoMethod (list, MUIM_List_Insert, entry, 1, MUIV_List_Insert_Bottom);
}

void InsertSortedEntry (APTR list, APTR *entry) {
   DoMethod (list, MUIM_List_Insert, entry, 1, MUIV_List_Insert_Sorted);
}

struct ListEntry *GetActiveEntry (APTR list) {
   struct ListEntry *result = NULL;
   
   if (list)
      DoMethod (list,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&result);
   return (result);
}

void SetListActive (APTR list, int id) {
   DoMethod (list,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,AP_Scout,2,MUIM_Application_ReturnID,id);
}

void SetListviewDoubleClick (APTR list, int id) {
   if (! clientstate)
      DoMethod (list,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,AP_Scout,2,MUIM_Application_ReturnID,id);
}

APTR KeyButtonA (char *buttontext, int buttonid) {
   APTR result;
   result = MUI_MakeObject (MUIO_Button, buttontext);
   DoMethod (result,MUIM_Notify,MUIA_Pressed,FALSE,AP_Scout,2,MUIM_Application_ReturnID,buttonid);
   return (result);
}

APTR KeyButtonB (char *buttontext, char key, int buttonid) {
   APTR result;
   result = KeyButton (buttontext, key);
   DoMethod (result,MUIM_Notify,MUIA_Pressed,FALSE,AP_Scout,2,MUIM_Application_ReturnID,buttonid);
   return (result);
}

APTR KeyButtonF (char fieldtype, ULONG flags) {
   APTR result;
   char buttontext[16];

   if (fieldtype == 'l') {
      sprintf (buttontext, ESC "b$%08lx", (ULONG) flags);
   } else if (fieldtype == 'w') {
      sprintf (buttontext, ESC "b$%04lx", (UWORD) flags);
   } else {
      sprintf (buttontext, ESC "b%%%ls", ltob ((ULONG) flags, 8));
   }
   result = TextObject,\
                ButtonFrame,\
                      MUIA_Text_Contents, buttontext,\
                MUIA_Text_PreParse, "\33r",\
                MUIA_InputMode    , MUIV_InputMode_RelVerify,\
                MUIA_Background   , MUII_ButtonBack,\
                End;

   DoMethod (result,MUIM_Notify,MUIA_Pressed,FALSE,AP_Scout,2,MUIM_Application_ReturnID,ID_FLAGWINDOW);
   return (result);
}

__asm LONG flaglist_dspfunc(register __a2 char **array, register __a1 struct FlagEntry *flagentry, register __a0 struct Hook *hook) {
   if (flagentry) {
      *array++ = flagentry->fe_name;
      *array++ = flagentry->fe_text;
      *array   = NULL;
   }
   return(0);
}

struct Hook flaglist_dsphook = {
 {NULL, NULL},
 (ULONG (* )())flaglist_dspfunc,
 NULL, NULL
};

void GetFlagsMore (char *title2, char *fieldname, ULONG flags, struct LongFlag *longflag, struct MaskedLongFlag *mlongflag, char fieldtype) {
   unsigned char     flaglabel[40];
   struct   WinFree  *ptr;
   APTR  flagsmorelist;


   if (fieldtype == 'l') {
      sprintf ((char *) &flaglabel, "%ls = $%08lx", fieldname, flags);
   } else if (fieldtype == 'w') {
      sprintf ((char *) &flaglabel, "%ls = $%04lx", fieldname, flags);
   } else {
      sprintf ((char *) &flaglabel, "%ls = %%%ls", fieldname, ltob ((ULONG) flags, 8));
   }

   if (ptr = AllocWinFree()) {
      ptr->wf_Window = (APTR) WindowObject,

//      MUIA_Window_SizeGadget, FALSE,
      MUIA_Window_ID, MakeDetailID('F','L','A','G'),
      WindowContents, VGroup,
         Child, HGroup,
            Child, MyHSpace (0),
            Child, MyLabel2 (flaglabel),
            Child, MyHSpace (0),
         End,
         Child, flagsmorelist = ListviewObject,
            MUIA_Listview_DoubleClick, TRUE,
            MUIA_Listview_Input, FALSE,
            MUIA_Listview_List, ListObject,
            MUIA_List_Format, "COL=0 DELTA=8,COL=1",
//            MUIA_List_Title, TRUE,
            MUIA_List_DisplayHook, &flaglist_dsphook,
            ReadListFrame,
         End, End,
      End, End;

      if (ptr->wf_Window) {
         int i = 0;

         set(flagsmorelist,MUIA_List_Quiet,TRUE);
         if (longflag) {
            while (((struct LongFlag *) &longflag[i])->lf_name) {
               if (flags & ((struct LongFlag *) &longflag[i])->lf_value) {
                  DoMethod (flagsmorelist,MUIM_List_InsertSingle,((struct FlagEntry *) &((struct LongFlag *) &longflag[i])->lf_name),MUIV_List_Insert_Bottom);
               }
               i++;
            }
         }
         i = 0;
         if (mlongflag) {
            while (((struct MaskedLongFlag *) &mlongflag[i])->mlf_name) {
               if ((flags & ((struct MaskedLongFlag *) &mlongflag[i])->mlf_mask) == ((struct MaskedLongFlag *) &mlongflag[i])->mlf_value) {
                  DoMethod (flagsmorelist,MUIM_List_InsertSingle,((struct FlagEntry *) &((struct MaskedLongFlag *) &mlongflag[i])->mlf_name),MUIV_List_Insert_Bottom);
               }
               i++;
            }
         }
         set(flagsmorelist,MUIA_List_Quiet,FALSE);

         HandleWindowOpen (ptr, "FLAGS  ", title2);
         set (ptr->wf_Window,MUIA_Window_ActiveObject,flagsmorelist);
         HandleWindowClose (ptr);
      }
   }
}

APTR MyListviewObject (unsigned char *formatstring, APTR displayhook) {
   return (ListviewObject,
            MUIA_Listview_List, ListObject,
            MUIA_List_Format, formatstring,
            MUIA_List_Title, TRUE,
            MUIA_List_DisplayHook, displayhook,
            InputListFrame,
           End, End);
}

/*
APTR MyBelowSortedListview (APTR *text, APTR *count, APTR *cycle, const char *sorttext[], int sortstate) {
 return (HGroup,
            Child, VGroup,
               Child, *text = MyTextObject5(SPACE40),
                  Child, MyLabel ("sorted by:"),
               End,
               Child, VGroup, MUIA_HorizWeight, 0,
                  Child, HGroup,
                     Child, MyLabel (" Cnt:"),
                     Child, *count = MyTextObject4("0000"),
                  End,
                  Child, *cycle = CycleObject,
                     MUIA_Cycle_Entries, sorttext,
                     MUIA_Cycle_Active, sortstate,
                  End,
               End,
            End);
}
*/

APTR MyBelowSortedListview (APTR *text, APTR *count, APTR *cycle, const char *sorttext[], int sortstate) {
 return (HGroup,
            Child, *text = MyTextObject5(SPACE40),
            Child, HGroup, MUIA_HorizWeight, 0,
               Child, MyLabel (" Cnt:"),
               Child, *count = MyTextObject4("0000"),
               Child, MyLabel ("sorted by:"),
               Child, *cycle = CycleObject,
                  MUIA_Cycle_Entries, sorttext,
                  MUIA_Cycle_Active, sortstate,
               End,
            End,
         End);
}

APTR MyBelowListview (APTR *text, APTR *count) {
 return (HGroup,
         Child, *text = MyTextObject5(SPACE40),
         Child, HGroup, MUIA_HorizWeight, 0,
            Child, MyLabel (" Cnt:"),
            Child, *count = MyTextObject4("0000"),
         End,End);
}

APTR MyLabel (char *labeltext) {
   return (LabelA (labeltext));
}

APTR MyLabel2 (char *labeltext) {
   return (LabelB (labeltext));
}

APTR MyHSpace (int size) {
   return (HSpace (size));
}

APTR MyVSpace (int size) {
   return (VSpace (size));
}

APTR MyTextObject () {
   return ( TextObject, MyTextFrame, End );
}

APTR MyTextObject2 () {
   return ( TextObject, MyTextFrame, MUIA_Text_SetMax, TRUE, End );
}

APTR MyTextObject3 (char *text) {
   return ( TextObject, MyTextFrame, MUIA_Text_Contents, text, End );
}

APTR MyTextObject4 (char *text) {
   return ( TextObject, MyTextFrame, MUIA_Text_SetMax, TRUE, MUIA_Text_Contents, text, End );
}

APTR MyTextObject5 (char *text) {
   return ( TextObject, MyTextFrame, MUIA_Text_SetMin, TRUE, MUIA_Text_Contents, text, End );
}

const char *AboutText1  = MUIX_C "\n"\
                          PROGNAME " V" PROGVERSION "." PROGREVISION "\n"\
                          "Release " RELEASEVERSION "." RELEASEREVISION " (" RELEASEDATE ")\n"\
                          COPYRIGHT "\nAll Rights Reserved\n\n"\
                          "This program is \33bFreeWare\33n.\n"\
                          "MUI is © by Stefan Stuntz.\n\n"\
                          "\33lEMail: " EMAIL "\nURL: " URL "\n\n"\
                          "ARexx port name: ";

static char *VectorPages[] = { "ResetVecs","AutoVecInts","IntVecs",NULL };
static char *AllocationsPages[] = { "CIA","Ports",NULL };
char  LibDevResFormatText[] = "COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8 P=\33r,COL=5";

__asm LONG list_cmpaddressfunc (register __a1 struct ListEntry *le1, register __a2 struct ListEntry *le2) {
   return (strcmpi (le1->le_address, le2->le_address));
}

struct Hook list_cmpaddresshook = {
 {NULL, NULL},
 (ULONG (* )())list_cmpaddressfunc,
 NULL, NULL
};

__asm LONG list_cmpnormalfunc (register __a1 struct ListEntry *le1, register __a2 struct ListEntry *le2) {
   return (1);
}

struct Hook list_cmpnormalhook = {
 {NULL, NULL},
 (ULONG (* )())list_cmpnormalfunc,
 NULL, NULL
};

__asm LONG list_cmpnamefunc (register __a1 struct ListEntry *le1, register __a2 struct ListEntry *le2) {
   LONG result;
   if (result = strcmpi (le1->le_name, le2->le_name))
      return (result);
   return (1);
}

struct Hook list_cmpnamehook = {
 {NULL, NULL},
 (ULONG (* )())list_cmpnamefunc,
 NULL, NULL
};

__asm LONG locklist_cmppathfunc (register __a1 struct LockEntry *le1, register __a2 struct LockEntry *le2) {
   return (strcmpi (le1->lock_path, le2->lock_path));
}

struct Hook locklist_cmppathhook = {
 {NULL, NULL},
 (ULONG (* )())locklist_cmppathfunc,
 NULL, NULL
};

__asm LONG tasklist_cmpprifunc (register __a1 struct TaskEntry *te1, register __a2 struct TaskEntry *te2) {
   long  eins = NULL, zwei = NULL;

   IsDec (te1->ts_pri, &eins);
   IsDec (te2->ts_pri, &zwei);
   if (eins < zwei)
      return (1);
   return (-1);
}

struct Hook tasklist_cmpprihook = {
 {NULL, NULL},
 (ULONG (* )())tasklist_cmpprifunc,
 NULL, NULL
};

__asm LONG tasklist_cmpaddressfunc (register __a1 struct ListEntry *le1, register __a2 struct ListEntry *le2) {
   if (le1->le_adr < le2->le_adr)
      return (-1);
   return (1);
}

struct Hook tasklist_cmpaddresshook = {
 {NULL, NULL},
 (ULONG (* )())tasklist_cmpaddressfunc,
 NULL, NULL
};

__asm LONG cxlist_cmpprifunc (register __a1 struct CxEntry *ce1, register __a2 struct CxEntry *ce2) {
   long  eins = NULL, zwei = NULL;

   IsDec (ce1->cxe_pri, &eins);
   IsDec (ce2->cxe_pri, &zwei);
   if (eins < zwei)
      return (1);
   return (-1);
}

struct Hook cxlist_cmpprihook = {
 {NULL, NULL},
 (ULONG (* )())cxlist_cmpprifunc,
 NULL, NULL
};

__asm LONG cxlist_cmpaddressfunc (register __a1 struct CxEntry *ce1, register __a2 struct CxEntry *ce2) {
   if (ce1->cxe_adr < ce2->cxe_adr)
      return (-1);
   return (1);
}

struct Hook cxlist_cmpaddresshook = {
 {NULL, NULL},
 (ULONG (* )())cxlist_cmpaddressfunc,
 NULL, NULL
};

__asm LONG cxlist_cmpnamefunc (register __a1 struct CxEntry *ce1, register __a2 struct CxEntry *ce2) {
   LONG result;
   if (result = strcmpi (ce1->cxe_name, ce2->cxe_name))
      return (result);
   return (1);
}

struct Hook cxlist_cmpnamehook = {
 {NULL, NULL},
 (ULONG (* )())cxlist_cmpnamefunc,
 NULL, NULL
};

__asm LONG classlist_cmpaddressfunc (register __a1 struct ClassEntry *ce1, register __a2 struct ClassEntry *ce2) {
   if (ce1->cse_adr < ce2->cse_adr)
      return (-1);
   return (1);
}

struct Hook classlist_cmpaddresshook = {
 {NULL, NULL},
 (ULONG (* )())classlist_cmpaddressfunc,
 NULL, NULL
};

__asm LONG classlist_cmpnamefunc (register __a1 struct ClassEntry *ce1, register __a2 struct ClassEntry *ce2) {
   LONG result;
   if (result = strcmpi (ce1->cse_classname, ce2->cse_classname))
      return (result);
   return (1);
}

struct Hook classlist_cmpnamehook = {
 {NULL, NULL},
 (ULONG (* )())classlist_cmpnamefunc,
 NULL, NULL
};

__asm LONG classlist_cmpsuperfunc (register __a1 struct ClassEntry *ce1, register __a2 struct ClassEntry *ce2) {
   LONG result;
   if (result = strcmpi (ce1->cse_super, ce2->cse_super))
      return (result);
   return (1);
}

struct Hook classlist_cmpsuperhook = {
 {NULL, NULL},
 (ULONG (* )())classlist_cmpsuperfunc,
 NULL, NULL
};

__asm LONG smodelist_cmpidfunc (register __a1 struct SModeEntry *se1, register __a2 struct SModeEntry *se2) {
   if (se1->sme_smodeid < se2->sme_smodeid)
      return (-1);
   return (1);
}

struct Hook smodelist_cmpidhook = {
 {NULL, NULL},
 (ULONG (* )())smodelist_cmpidfunc,
 NULL, NULL
};

__asm LONG smodelist_cmpresfunc (register __a1 struct SModeEntry *se1, register __a2 struct SModeEntry *se2) {
   long  eins = NULL, zwei = NULL;

   IsDec (se1->sme_width, &eins);
   IsDec (se2->sme_width, &zwei);
   if(eins!=zwei) return(eins>zwei ? 1 : -1);
   IsDec (se1->sme_height, &eins);
   IsDec (se2->sme_height, &zwei);
   if(eins!=zwei) return(eins>zwei ? 1 : -1);
   IsDec (se1->sme_depth, &eins);
   IsDec (se2->sme_depth, &zwei);
   return(eins>zwei ? 1 : -1);
}

struct Hook smodelist_cmpreshook = {
 {NULL, NULL},
 (ULONG (* )())smodelist_cmpresfunc,
 NULL, NULL
};

__asm LONG smodelist_cmpnamefunc (register __a1 struct SModeEntry *se1, register __a2 struct SModeEntry *se2) {
   STRPTR s1 = se1->sme_name, s2 = se2->sme_name;
   LONG result;

//*   if(*s1=='\033') s1+=2;
//*   if(*s2=='\033') s2+=2;

   if (result = strcmpi (s1,s2))
      return (result);
   return (1);
}

struct Hook smodelist_cmpnamehook = {
 {NULL, NULL},
 (ULONG (* )())smodelist_cmpnamefunc,
 NULL, NULL
};


char main_title[WINDOWTITLELEN];

APTR GetApplication (void) {
   AP_Scout = ApplicationObject,
      MUIA_Application_Title      , PROGNAME,
      MUIA_Application_Version    , "$VER: " VERSIONSTRING,
      MUIA_Application_Copyright  , COPYRIGHT,
      MUIA_Application_Author     , AUTHOR,
      MUIA_Application_Description, DESCRIPTION,
      MUIA_Application_Base       , PROGNAME,
      MUIA_Application_Commands   , arexx_list,
      MUIA_Application_Menu       , menu_list,
//      MUIA_Application_SingleTask , TRUE,
//      MUIA_Application_DiskObject , &scout_sleep_dobj,
      MUIA_Application_HelpFile   , "scout.guide",
   End;

   if (AP_Scout) {
      WI_Main = WindowObject,
      MUIA_Window_Title, MyGetWindowTitle (main_title, ""),
         MUIA_HelpNode, "Main",
         MUIA_Window_ID, MakeID('M','A','I','N'),
         WindowContents, HGroup,
            MUIA_Group_SameHeight, TRUE,
            Child, VGroup,                  /* This is the SCOUT logo */
               MUIA_Weight    , 0,
               MUIA_Frame     , MUIV_Frame_Text,
               MUIA_Background, MUII_SHADOW,
               Child, VSpace(0),
               Child, BodychunkObject,
                  MUIA_FixWidth             , SCOUT_LOGO_WIDTH ,
                  MUIA_FixHeight            , SCOUT_LOGO_HEIGHT,
                  MUIA_Bitmap_Width         , SCOUT_LOGO_WIDTH ,
                  MUIA_Bitmap_Height        , SCOUT_LOGO_HEIGHT,
                  MUIA_Bodychunk_Depth      , SCOUT_LOGO_DEPTH ,
                  MUIA_Bodychunk_Body       , scout_logo_body  ,
                  MUIA_Bodychunk_Compression, SCOUT_LOGO_COMPRESSION,
                  MUIA_Bodychunk_Masking    , SCOUT_LOGO_MASKING,
                  MUIA_Bitmap_SourceColors  , scout_logo_colors,
                  MUIA_Bitmap_Transparent   , 0,
               End,
               Child, VSpace(0),
            End,
            Child, ColGroup(5),             /* And this are the buttons */
               Child, BT_Libraries    = KeyButtonB (LibrariesText    ,'l',ID_LIBRARIES),
               Child, BT_Devices      = KeyButtonB (DevicesText      ,'d',ID_DEVICES),
               Child, BT_Resources    = KeyButtonB (ResourcesText    ,'u',ID_RESOURCES),
               Child, BT_Semaphores   = KeyButtonB (SemaphoresText   ,'s',ID_SEMAPHORES),
               Child, BT_Allocations  = KeyButtonB (AllocationsText  ,'a',ID_ALLOCATIONS),

               Child, BT_Tasks        = KeyButtonB (TasksText        ,'t',ID_TASKS),
               Child, BT_Ports        = KeyButtonB (PortsText        ,'p',ID_PORTS),
               Child, BT_Commodities  = KeyButtonB (CommoditiesText  ,'k',ID_COMMODITIES),
               Child, BT_Interrupts   = KeyButtonB (InterruptsText   ,'i',ID_INTERRUPTS),
               Child, BT_Vectors      = KeyButtonB (VectorsText      ,'v',ID_VECTORS),

               Child, BT_ScreenMode   = KeyButtonB (ScreenModeText   ,'z',ID_SCREENMODE),
               Child, BT_Windows      = KeyButtonB (WindowsText      ,'w',ID_WINDOWS),
               Child, BT_Fonts        = KeyButtonB (FontsText        ,'f',ID_FONTS),
               Child, BT_Classes      = KeyButtonB (ClassesText      ,'b',ID_CLASSES),
               Child, BT_InputHandler = KeyButtonB (InputHandlersText,'h',ID_INPUTHANDLER),

               Child, BT_Assigns      = KeyButtonB (AssignsText      ,'g',ID_ASSIGNS),
               Child, BT_Locks        = KeyButtonB (LocksText        ,'o',ID_LOCKS),
               Child, BT_Mount        = KeyButtonB (MountText        ,'n',ID_MOUNT),
               Child, BT_Commands     = KeyButtonB (CommandsText     ,'c',ID_COMMANDS),
               Child, BT_Timer        = KeyButtonB (TimerText        ,'e',ID_TIMER),

               Child, BT_System       = KeyButtonB (SystemText       ,'y',ID_SYSTEM),
               Child, BT_Expansions   = KeyButtonB (ExpansionsText   ,'x',ID_EXPANSIONS),
               Child, BT_Memory       = KeyButtonB (MemoryText       ,'m',ID_MEMORY),
               Child, BT_LowMemory    = KeyButtonB (LowMemoryText    ,'j',ID_LOWMEMORY),
               Child, BT_Residents    = KeyButtonB (ResidentsText    ,'r',ID_RESIDENTS),
            End,
         End,
      End;

      if (WI_Main) {
         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Main);
         SetCloseRequest (WI_Main,(int) MUIV_Application_ReturnID_Quit);
         DoMethod (WI_Main,MUIM_Window_SetCycleChain,
                    BT_Libraries,BT_Devices,BT_Resources,BT_System,
                    BT_Tasks,BT_Ports,BT_Commands,BT_Commodities,
                    BT_Expansions,BT_Memory,BT_Residents,BT_LowMemory,
                    BT_Assigns,BT_Locks,BT_Mount,BT_Timer,
                    BT_InputHandler,BT_Interrupts,BT_Vectors,BT_Allocations,
                    BT_Fonts,BT_Semaphores,BT_Windows,BT_ScreenMode,NULL);

//         DoMethod (AP_Scout,MUIM_Notify,MUIA_Application_DoubleStart,TRUE,AsP_Scout,2,MUIM_Application_ReturnID,ID_DOUBLESTART);
      }
   }
   return (AP_Scout);
}

char mount_title[WINDOWTITLELEN];

void MountWindow (BOOL state) {
   if (state) {
      if (WI_Mount) {
         ShowMounts();
      } else {
         WI_Mount = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (mount_title, "MOUNTED DEVICES"),
         MUIA_HelpNode, MountText,
         MUIA_Window_ID, MakeListID('M','O','D','E'),
         WindowContents, VGroup,
            Child, mountlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8 P=\33r,COL=5 DELTA=8 P=\33c,COL=6 DELTA=8 P=\33c,COL=7",&mountlist_dsphook),
            Child, MyBelowListview (&mounttext, &mountcount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_MountUpdate = KeyButtonA (UpdateText,ID_MOUNTUPDATE),
               Child, BT_MountPrint  = KeyButtonA (PrintText ,ID_MOUNTPRINT),
               Child, BT_MountMore   = KeyButtonA (MoreText  ,ID_MOUNTMORE),
               Child, BT_MountExit   = KeyButtonA (ExitText  ,ID_MOUNTEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Mount);
         DoMethod (WI_Mount,MUIM_Window_SetCycleChain,mountlist,BT_MountUpdate,BT_MountPrint,BT_MountMore,BT_MountExit,NULL);

         SetCloseRequest (WI_Mount,ID_MOUNTEXIT);
         SetListActive (mountlist,ID_MOUNTLV_ACTIVE);
         SetListviewDoubleClick (mountlist,ID_MOUNTMORE);

         ShowMounts();

         SetWindowOpen (WI_Mount,mountlist,ID_MOUNTEXIT);
      }
   } else if ((! state) && (WI_Mount)) {
      SetWindowClose (WI_Mount,TRUE);

      FreeMounts();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Mount);
      MUI_DisposeObject (WI_Mount);
      WI_Mount = NULL;
      mountlist = NULL;
   }
}

char windows_title[WINDOWTITLELEN];

void WindowsWindow (BOOL state) {
   if (state) {
      if (WI_Windows) {
         ShowWindows();
      } else {
         WI_Windows = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (windows_title, "WINDOWS & SCREENS"),
         MUIA_HelpNode, WindowsText,
         MUIA_Window_ID, MakeListID('W','I','N','D'),
         WindowContents, VGroup,
            Child, winlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8 P=\33c,COL=2 DELTA=8 P=\33c,COL=3 DELTA=8,COL=4 DELTA=8,COL=5",&winlist_dsphook),
            Child, wintext = MyTextObject(),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_WinUpdate  = KeyButtonA (UpdateText,ID_WINUPDATE),
               Child, BT_WinPrint   = KeyButtonA (PrintText ,ID_WINPRINT),
               Child, BT_WinClose   = KeyButtonA (CloseText ,ID_WINCLOSE),
               Child, BT_WinToFront = KeyButtonA (ToFrontText ,ID_WINTOFRONT),
               Child, BT_WinMore    = KeyButtonA (MoreText  ,ID_WINMORE),
               Child, BT_WinExit    = KeyButtonA (ExitText  ,ID_WINEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Windows);
         DoMethod (WI_Windows,MUIM_Window_SetCycleChain,winlist,BT_WinUpdate,BT_WinPrint,BT_WinClose,BT_WinToFront,BT_WinMore,BT_WinExit,NULL);

         SetCloseRequest (WI_Windows,ID_WINEXIT);
         SetListActive (winlist,ID_WINLV_ACTIVE);
         SetListviewDoubleClick (winlist,ID_WINMORE);

         SetWindowOpen (WI_Windows,winlist,ID_WINEXIT);

         ShowWindows();
      }
   } else if ((! state) && (WI_Windows)) {
      SetWindowClose (WI_Windows,TRUE);

      FreeWindows();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Windows);
      MUI_DisposeObject (WI_Windows);
      WI_Windows = NULL;
      winlist = NULL;
   }
}

char residents_title[WINDOWTITLELEN];

void ResidentsWindow (BOOL state) {
   if (state) {
      if (WI_Residents) {
         ShowResidents();
      } else {
         WI_Residents = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (residents_title, "RESIDENTS"),
         MUIA_HelpNode, ResidentsText,
         MUIA_Window_ID, MakeListID('R','E','S','I'),
         WindowContents, VGroup,
            Child, resilist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3",&resilist_dsphook),
            Child, MyBelowListview (&resitext, &resicount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_ResiUpdate     = KeyButtonA (UpdateText,ID_RESIUPDATE),
               Child, BT_ResiPrint      = KeyButtonA (PrintText ,ID_RESIPRINT),
               Child, BT_ResiMore       = KeyButtonA (MoreText  ,ID_RESIMORE),
               Child, BT_ResiExit       = KeyButtonA (ExitText  ,ID_RESIEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Residents);
         DoMethod (WI_Residents,MUIM_Window_SetCycleChain,resilist,BT_ResiUpdate,BT_ResiPrint,BT_ResiMore,BT_ResiExit,NULL);

         SetCloseRequest (WI_Residents,ID_RESIEXIT);
         SetListActive (resilist,ID_RESILV_ACTIVE);
         SetListviewDoubleClick (resilist,ID_RESIMORE);

         ShowResidents();

         SetWindowOpen (WI_Residents,resilist,ID_RESIEXIT);
      }
   } else if ((! state) && (WI_Residents)) {
      SetWindowClose (WI_Residents,TRUE);

      FreeResidents();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Residents);
      MUI_DisposeObject (WI_Residents);
      WI_Residents = NULL;
      resilist = NULL;
   }
}

char expansions_title[WINDOWTITLELEN];

void ExpansionsWindow (BOOL state) {
   if (state) {
      if (WI_Expansions) {
         ShowExpansions();
      } else {
         WI_Expansions = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (expansions_title, "EXPANSIONS"),
         MUIA_HelpNode, ExpansionsText,
         MUIA_Window_ID, MakeListID('E','X','P','A'),
         WindowContents, VGroup,
            Child, explist = MyListviewObject ("DELTA=8,DELTA=8,DELTA=8,,",&explist_dsphook),
            Child, exptext = MyTextObject(),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_ExpPrint     = KeyButtonA (PrintText,ID_EXPPRINT),
               Child, BT_ExpMore      = KeyButtonA (MoreText ,ID_EXPMORE),
               Child, BT_ExpExit      = KeyButtonA (ExitText ,ID_EXPEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Expansions);
         DoMethod (WI_Expansions,MUIM_Window_SetCycleChain,explist,BT_ExpPrint,BT_ExpMore,BT_ExpExit,NULL);

         SetCloseRequest (WI_Expansions,ID_EXPEXIT);
         SetListActive (explist,ID_EXPLV_ACTIVE);
         SetListviewDoubleClick (explist,ID_EXPMORE);

         ShowExpansions();

         SetWindowOpen (WI_Expansions,explist,ID_EXPEXIT);
      }
   } else if ((! state) && (WI_Expansions)) {
      SetWindowClose (WI_Expansions,TRUE);

      FreeExpansions();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Expansions);
      MUI_DisposeObject (WI_Expansions);
      WI_Expansions = NULL;
      explist = NULL;
   }
}

char inputhandler_title[WINDOWTITLELEN];

void InputHandlerWindow (BOOL state) {
   if (state) {
      if (WI_InputHandler) {
         ShowInputHandler();
      } else {
         WI_InputHandler = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (inputhandler_title, "INPUTHANDLERS"),
         MUIA_HelpNode, InputHandlersText,
         MUIA_Window_ID, MakeListID('I','N','P','U'),
         WindowContents, VGroup,
            Child, inputlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8,COL=5",&inputlist_dsphook),
            Child, MyBelowListview (&inputtext, &inputcount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_InputUpdate    = KeyButtonA (UpdateText  ,ID_INPUTUPDATE),
               Child, BT_InputPrint     = KeyButtonA (PrintText   ,ID_INPUTPRINT),
               Child, BT_InputRemove    = KeyButtonA (RemoveText  ,ID_INPUTREMOVE),
               Child, BT_InputPriority  = KeyButtonA (PriorityText,ID_INPUTPRIORITY),
               Child, BT_InputExit      = KeyButtonA (ExitText    ,ID_INPUTEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_InputHandler);
         DoMethod (WI_InputHandler,MUIM_Window_SetCycleChain,inputlist,BT_InputUpdate,BT_InputPrint,BT_InputRemove,BT_InputPriority,BT_InputExit,NULL);

         SetCloseRequest (WI_InputHandler,ID_INPUTEXIT);
         SetListActive (inputlist,ID_INPUTLV_ACTIVE);

         ShowInputHandler();

         SetWindowOpen (WI_InputHandler,inputlist,ID_INPUTEXIT);
      }
   } else if ((! state) && (WI_InputHandler)) {
      SetWindowClose (WI_InputHandler,TRUE);

      FreeInputHandler();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_InputHandler);
      MUI_DisposeObject (WI_InputHandler);
      WI_InputHandler = NULL;
      inputlist = NULL;
   }
}

char lowmemory_title[WINDOWTITLELEN];

void LowMemoryWindow (BOOL state) {
   if (state) {
      if (WI_LowMemory) {
         ShowLowMemory();
      } else {
         WI_LowMemory = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (lowmemory_title, "LOWMEMORY"),
         MUIA_HelpNode, LowMemoryText,
         MUIA_Window_ID, MakeListID('L','O','W','M'),
         WindowContents, VGroup,
            Child, lowmemorylist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8,COL=5",&lowmemorylist_dsphook),
            Child, MyBelowListview (&lowmemorytext, &lowmemorycount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_LowMemoryUpdate    = KeyButtonA (UpdateText  ,ID_LOWMEMORYUPDATE),
               Child, BT_LowMemoryPrint     = KeyButtonA (PrintText   ,ID_LOWMEMORYPRINT),
//*               Child, BT_LowMemoryCause     = KeyButtonA (CauseText   ,ID_LOWMEMORYCAUSE),
               Child, BT_LowMemoryRemove    = KeyButtonA (RemoveText  ,ID_LOWMEMORYREMOVE),
               Child, BT_LowMemoryPriority  = KeyButtonA (PriorityText,ID_LOWMEMORYPRIORITY),
               Child, BT_LowMemoryExit      = KeyButtonA (ExitText    ,ID_LOWMEMORYEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_LowMemory);
         DoMethod (WI_LowMemory,MUIM_Window_SetCycleChain,lowmemorylist,BT_LowMemoryUpdate,BT_LowMemoryPrint,BT_LowMemoryRemove,BT_LowMemoryPriority,BT_LowMemoryExit,NULL);

         SetCloseRequest (WI_LowMemory,ID_LOWMEMORYEXIT);
         SetListActive (lowmemorylist,ID_LOWMEMORYLV_ACTIVE);

         ShowLowMemory();

         SetWindowOpen (WI_LowMemory,lowmemorylist,ID_LOWMEMORYEXIT);
      }
   } else if ((! state) && (WI_LowMemory)) {
      SetWindowClose (WI_LowMemory,TRUE);

      FreeLowMemory();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_LowMemory);
      MUI_DisposeObject (WI_LowMemory);
      WI_LowMemory = NULL;
      lowmemorylist = NULL;
   }
}




char timer_title[WINDOWTITLELEN];

void TimerWindow (BOOL state) {
   if (state) {
      if (WI_Timer) {
         ShowTimer();
      } else {
         WI_Timer = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (timer_title, "TIMER REQUESTS"),
         MUIA_HelpNode, TimerText,
         MUIA_Window_ID, MakeListID('T','I','M','R'),
         WindowContents, VGroup,
            Child, timerlist = MyListviewObject ("DELTA=8,DELTA=8,DELTA=8 P=\33r,DELTA=8 P=\33c,",&timerlist_dsphook),
            Child, MyBelowListview (&timertext, &timercount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_TimerUpdate    = KeyButtonA (UpdateText  ,ID_TIMERUPDATE),
               Child, BT_TimerPrint     = KeyButtonA (PrintText   ,ID_TIMERPRINT),
//*               Child, BT_TimerRemove    = KeyButtonA (RemoveText  ,ID_TIMERREMOVE),
               Child, BT_TimerExit      = KeyButtonA (ExitText    ,ID_TIMEREXIT),
            End,
         End, End;

         set(timerlist,MUIA_List_CompareHook,&list_cmpaddresshook);

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Timer);
         DoMethod (WI_Timer,MUIM_Window_SetCycleChain,timerlist,BT_TimerUpdate,BT_TimerPrint,BT_TimerExit,NULL);

         SetCloseRequest (WI_Timer,ID_TIMEREXIT);
         SetListActive (timerlist,ID_TIMERLV_ACTIVE);

         ShowTimer();

         SetWindowOpen (WI_Timer,timerlist,ID_TIMEREXIT);
      }
   } else if ((! state) && (WI_Timer)) {
      SetWindowClose (WI_Timer,TRUE);

      FreeTimer();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Timer);
      MUI_DisposeObject (WI_Timer);
      WI_Timer = NULL;
      timerlist = NULL;
   }
}


char semaphores_title[WINDOWTITLELEN];

void SemaphoresWindow (BOOL state) {
   if (state) {
      if (WI_Semaphores) {
         ShowSemaphores();
      } else {
         WI_Semaphores = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (semaphores_title, "SEMAPHORES"),
         MUIA_HelpNode, SemaphoresText,
         MUIA_Window_ID, MakeListID('S','E','M','A'),
         WindowContents, VGroup,
            Child, semlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8",&semlist_dsphook),
            Child, MyBelowListview (&semtext, &semcount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_SemUpdate   = KeyButtonA (UpdateText ,ID_SEMUPDATE),
               Child, BT_SemPrint    = KeyButtonA (PrintText  ,ID_SEMPRINT),
               Child, BT_SemObtain   = KeyButtonA (ObtainText ,ID_SEMOBTAIN),
               Child, BT_SemRelease  = KeyButtonA (ReleaseText,ID_SEMRELEASE),
               Child, BT_SemRemove   = KeyButtonA (RemoveText ,ID_SEMREMOVE),
               Child, BT_SemExit     = KeyButtonA (ExitText   ,ID_SEMEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Semaphores);
         DoMethod (WI_Semaphores,MUIM_Window_SetCycleChain,semlist,BT_SemUpdate,BT_SemPrint,BT_SemObtain,BT_SemRelease,BT_SemRemove,BT_SemExit,NULL);

         SetCloseRequest (WI_Semaphores,ID_SEMEXIT);
         SetListActive (semlist,ID_SEMLV_ACTIVE);

         ShowSemaphores();

         SetWindowOpen (WI_Semaphores,semlist,ID_SEMEXIT);
      }
   } else if ((! state) && (WI_Semaphores)) {
      SetWindowClose (WI_Semaphores,TRUE);

      FreeSemaphores();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Semaphores);
      MUI_DisposeObject (WI_Semaphores);
      WI_Semaphores = NULL;
      semlist = NULL;
   }
}

char interrupts_title[WINDOWTITLELEN];

void InterruptsWindow (BOOL state) {
   if (state) {
      if (WI_Interrupts) {
         ShowInterrupts();
      } else {
         WI_Interrupts = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (interrupts_title, "INTERRUPTS"),
         MUIA_HelpNode, InterruptsText,
         MUIA_Window_ID, MakeListID('I','N','T','E'),
         WindowContents, VGroup,
            Child, intlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8,COL=4 DELTA=8,COL=5 DELTA=8 P=\33r,COL=6",&intlist_dsphook),
            Child, MyBelowListview (&inttext, &intcount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_IntUpdate   = KeyButtonA (UpdateText,ID_INTUPDATE),
               Child, BT_IntPrint    = KeyButtonA (PrintText ,ID_INTPRINT),
               Child, BT_IntRemove   = KeyButtonA (RemoveText,ID_INTREMOVE),
               Child, BT_IntMore     = KeyButtonA (MoreText  ,ID_INTMORE),
               Child, BT_IntExit     = KeyButtonA (ExitText  ,ID_INTEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Interrupts);
         DoMethod (WI_Interrupts,MUIM_Window_SetCycleChain,intlist,BT_IntUpdate,BT_IntPrint,BT_IntRemove,BT_IntMore,BT_IntExit,NULL);

         SetCloseRequest (WI_Interrupts,ID_INTEXIT);
         SetListActive (intlist,ID_INTLV_ACTIVE);
         SetListviewDoubleClick (intlist,ID_INTMORE);

         ShowInterrupts();

         SetWindowOpen (WI_Interrupts,intlist,ID_INTEXIT);
      }
   } else if ((! state) && (WI_Interrupts)) {
      SetWindowClose (WI_Interrupts,TRUE);

      FreeInterrupts();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Interrupts);
      MUI_DisposeObject (WI_Interrupts);
      WI_Interrupts = NULL;
      intlist = NULL;
   }
}

char fonts_title[WINDOWTITLELEN];

void FontsWindow (BOOL state) {
   if (state) {
      if (WI_Fonts) {
         ShowFonts();
      } else {
         WI_Fonts = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (fonts_title, "FONTS"),
         MUIA_HelpNode, FontsText,
         MUIA_Window_ID, MakeListID('F','O','N','T'),
         WindowContents, VGroup,
            Child, fontlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8 P=\33r,COL=2 DELTA=8,COL=3 DELTA=8,COL=4 DELTA=8 P=\33r,COL=5 DELTA=8 P=\33r,COL=6 DELTA=8 P=\33r,COL=7 DELTA=8,COL=8",&fontlist_dsphook),
            Child, MyBelowListview (&fonttext, &fontcount),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_FontUpdate  = KeyButtonA (UpdateText,ID_FONTUPDATE),
               Child, BT_FontPrint   = KeyButtonA (PrintText ,ID_FONTPRINT),
               Child, BT_FontClose   = KeyButtonA (CloseText,ID_FONTCLOSE),
               Child, BT_FontRemove  = KeyButtonA (RemoveText,ID_FONTREMOVE),
               Child, BT_FontExit    = KeyButtonA (ExitText  ,ID_FONTEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Fonts);
         DoMethod (WI_Fonts,MUIM_Window_SetCycleChain,fontlist,BT_FontUpdate,BT_FontPrint,BT_FontClose,BT_FontRemove,BT_FontExit,NULL);

         SetCloseRequest (WI_Fonts,ID_FONTEXIT);
         SetListActive (fontlist,ID_FONTLV_ACTIVE);

         ShowFonts();

         SetWindowOpen (WI_Fonts,fontlist,ID_FONTEXIT);
      }
   } else if ((! state) && (WI_Fonts)) {
      SetWindowClose (WI_Fonts,TRUE);

      FreeFonts();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Fonts);
      MUI_DisposeObject (WI_Fonts);
      WI_Fonts = NULL;
      fontlist = NULL;
   }
}

static const char *CYA_CpuUsageText[] = {
   "off",
   "full",
   " in % ",
   NULL
};

__asm void cpuinterval_callfunc(register __a1 unsigned char **contents) {
   int      i, j, t;
   long     micros = NULL;
   UBYTE    text[8];

   if ((switchstate) && (*switchstate)) {
      AbortIO ((struct IORequest *) &TimerIORequest);
   }

   strncpy (text, *contents, 6);

   i = 0;
   while ((text[i] != '\0') && (text[i] != '.')) {
      i++;
   }
   if (text[i] == '.') {
      t = 1;
      text[i] = '\0';
      while (isdigit (text[++i])) {
         if (j = (int) (text[i] - '0')) {
            t *= 10;
            micros += (1000000 / t) * j;
         }
      }
   }
   cpumicros = micros;
   cpuseconds = atol ((char const *) &text);
   strcpy (updatetimetext,*contents);

   if ((switchstate) && (*switchstate)) {
      TimerIORequest.tr_time.tv_secs = cpuseconds;
      TimerIORequest.tr_time.tv_micro = cpumicros;
      TimerIORequest.tr_node.io_Command = TR_ADDREQUEST;
      SendIO ((struct IORequest *) &TimerIORequest);
   }
}

struct Hook cpuinterval_callhook = {
 {NULL, NULL},
 (ULONG (* )())cpuinterval_callfunc,
 NULL, NULL
};

/* Beispiel-EditHook aus RKM-Libraries Seite 164 */
/*
__asm ULONG realstring_editfunc(register __a0 struct Hook *hook, register __a2 struct SGWork *sgw, register __a1 ULONG *msg) {
   UBYTE *work_ptr;
   ULONG return_code;

   return_code = ~0L;

   if (*msg == SGH_KEY) {
      if ((sgw->EditOp == EO_REPLACECHAR) || (sgw->EditOp == EO_INSERTCHAR)) {
         if (!IsHexDigit (sgw->Code)) {
            sgw->Actions |= SGA_BEEP;
            sgw->Actions &= ~SGA_USE;
         } else {
            sgw->WorkBuffer[sgw->BufferPos - 1] = ToUpper (sgw->Code);
         }
      }
   } else if (*msg == SGH_CLICK) {
      if (sgw->BufferPos < sgw->NumChars) {
         work_ptr = sgw->WorkBuffer + sgw->BufferPos;
         *work_ptr = '0';
      }
   } else {
      return_code = 0;
   }
   return (return_code);
}
*/

__asm ULONG hexstring_editfunc (register __a0 struct Hook *hook, register __a2 struct SGWork *sgw, register __a1 ULONG *msg) {
   ULONG return_code;
   int   i = 0;
   char  c;

   return_code = ~0L;

   if (*msg == SGH_KEY) {
      long  tmplong;

      if ((sgw->EditOp == EO_REPLACECHAR) || (sgw->EditOp == EO_INSERTCHAR)) {
         if (sgw->WorkBuffer[0] == '$')
            i = 1;
         if (! strncmp ("0x", sgw->WorkBuffer, 2))
            i = 2;
         while (c = sgw->WorkBuffer[i]) {
            if ((! ((c >= '0') && (c <= '9'))) \
              && (! ((c >= 'a') && (c <= 'f'))) \
              && (! ((c >= 'A') && (c <= 'F')))) {
               sgw->Actions |= SGA_BEEP;
               sgw->Actions &= ~SGA_USE;
               break;
            }
            i++;
         }
      } else if ((sgw->EditOp == EO_ENTER) && (! IsHex (sgw->WorkBuffer, &tmplong))) { 
         sgw->Actions |= SGA_BEEP;
         sgw->Actions &= ~SGA_END;
      }
   } else {
      return_code = 0;
   }
   return (return_code);
}

struct Hook hexstring_edithook = {
 {NULL, NULL},
 (ULONG (* )())hexstring_editfunc,
 NULL, NULL
};

__asm ULONG realstring_editfunc(register __a0 struct Hook *hook, register __a2 struct SGWork *sgw, register __a1 ULONG *msg) {
   ULONG return_code;
   int   i = 0,punkte = 0,notzeros = 0;

   return_code = ~0L;

   if (*msg == SGH_KEY) {
      if ((sgw->EditOp == EO_REPLACECHAR) || (sgw->EditOp == EO_INSERTCHAR)) {
         while (sgw->WorkBuffer[i]) {
            if (sgw->WorkBuffer[i++] == '.')
               punkte++;
         }
         if ((punkte > 1) || ((!isdigit (sgw->Code)) && (sgw->Code != '.'))) {
            sgw->Actions |= SGA_BEEP;
            sgw->Actions &= ~SGA_USE;
         }
      } else if (sgw->EditOp == EO_ENTER) {
         while (sgw->WorkBuffer[i]) {
            if ((sgw->WorkBuffer[i] >= '1') && (sgw->WorkBuffer[i] <= '9'))
               notzeros++;
            i++;
         }
         if ((sgw->EditOp == EO_ENTER) && (!notzeros)) { 
            sgw->Actions |= SGA_BEEP;
            sgw->Actions &= ~SGA_END;
         }
      }
   } else {
      return_code = 0;
   }
   return (return_code);
}

struct Hook realstring_edithook = {
 {NULL, NULL},
 (ULONG (* )())realstring_editfunc,
 NULL, NULL
};

APTR TaskSortList[] = {
   &tasklist_cmpaddresshook,
   &list_cmpnamehook,
   &tasklist_cmpprihook,
   NULL
};

static const char *CYA_TaskSortText[] = {
   "address",
   "name",
   "priority",
   NULL
};

APTR WI_Tasks, tasklist, tasktext, tasktext2, taskcount, CY_TaskSort;
int  tasksortstate = 0;
APTR BT_TaskPrint, BT_TaskFreeze, BT_TaskActivate, cpucount, CY_CpuUsage;
APTR BT_TaskUpdate, BT_TaskRemove, BT_TaskSignal, BT_TaskBreak, BT_TaskPriority, BT_TaskMore, BT_TaskExit;

char tasks_title[WINDOWTITLELEN];

void TasksWindow (BOOL state) {
   if (state) {
      if (WI_Tasks) {
         ShowTasks();
      } else {
         WI_Tasks = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (tasks_title, "TASKS"),
         MUIA_HelpNode, TasksText,
         MUIA_Window_ID, MakeListID('T','A','S','K'),
         WindowContents, VGroup,
            Child, tasklist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8 P=\33c,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8 P=\33c,COL=5 DELTA=8,COL=6 DELTA=8 P=\33r,COL=7",&tasklist_dsphook),
            Child, MyBelowSortedListview (&tasktext, &taskcount, &CY_TaskSort, CYA_TaskSortText, tasksortstate),
            Child, MyVSpace(2),
            Child, VGroup,
               Child, HGroup, MUIA_Group_SameSize, TRUE,
                  Child, BT_TaskPrint    = KeyButtonA (PrintText   ,ID_TASKPRINT),
                  Child, BT_TaskFreeze   = KeyButtonA (FreezeText  ,ID_TASKFREEZE),
                  Child, BT_TaskActivate = KeyButtonA (ActivateText,ID_TASKACTIVATE),
                  Child, HGroup,
                     Child, MyLabel2 (" CPU:"),
//*                     Child, cpucount = MyTextObject3(ESC "c-----"),
                     Child, cpucount = GaugeObject,
                       MUIA_Frame         , MUIV_Frame_Gauge,
                       MUIA_Gauge_Horiz   , TRUE,
                       MUIA_Gauge_Max     , 100,
                       MUIA_Gauge_InfoText, "\0330-----",
                       MUIA_Gauge_Current , 0,
                     End,
                  End,
                  Child, CY_CpuUsage = CycleObject,
                     MUIA_Weight, 0,
                     MUIA_Cycle_Entries, CYA_CpuUsageText,
                     MUIA_Cycle_Active, updatetimestate,
                  End,
                  Child, HGroup,
                     Child, MyLabel2 (" Secs:"),
                     Child, tasktext2 = StringObject,
                        MUIA_String_BufferPos, 1,
                        MUIA_String_MaxLen, 6, StringFrame,
                        MUIA_String_EditHook, &realstring_edithook,
                        MUIA_String_Contents, updatetimetext,
                     End,
                  End,
               End,
               Child, HGroup, MUIA_Group_SameSize, TRUE,
                  Child, BT_TaskUpdate   = KeyButtonA (UpdateText  ,ID_TASKUPDATE),
                  Child, BT_TaskRemove   = KeyButtonA (RemoveText  ,ID_TASKREMOVE),
                  Child, BT_TaskSignal   = KeyButtonA (SignalText  ,ID_TASKSIGNAL),
                  Child, BT_TaskBreak    = KeyButtonA (BreakText   ,ID_TASKBREAK),
                  Child, BT_TaskPriority = KeyButtonA (PriorityText,ID_TASKPRIORITY),
                  Child, BT_TaskMore     = KeyButtonA (MoreText    ,ID_TASKMORE),
                  Child, BT_TaskExit     = KeyButtonA (ExitText    ,ID_TASKEXIT),
               End,
            End,
         End, End;

         if (WI_Tasks) {
            DoMethod (AP_Scout,OM_ADDMEMBER,WI_Tasks);
            DoMethod (WI_Tasks,MUIM_Window_SetCycleChain,tasklist,CY_TaskSort,BT_TaskPrint,BT_TaskFreeze,BT_TaskActivate,CY_CpuUsage,tasktext2,BT_TaskUpdate,BT_TaskRemove,BT_TaskSignal,BT_TaskBreak,BT_TaskPriority,BT_TaskMore,BT_TaskExit,NULL);
            DoMethod (CY_CpuUsage, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_CPUUSAGE);
            DoMethod (CY_TaskSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_TASKSORT);
            DoMethod (tasktext2,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,tasktext2,3,MUIM_CallHook,&cpuinterval_callhook,MUIV_TriggerValue);

            SetCloseRequest (WI_Tasks,ID_TASKEXIT);
            SetListActive (tasklist,ID_TASKLV_ACTIVE);
            SetListviewDoubleClick (tasklist,ID_TASKMORE);

            ShowTasks();

            SetWindowOpen (WI_Tasks,tasklist,ID_TASKEXIT);

            if (updatetimestate)
               CheckCPUUsage();
         }
      }
   } else if ((! state) && (WI_Tasks)) {
      if (patchsem)
         *switchstate = FALSE;

      if (cheattask)
         RemoveCheatTask();

      SetWindowClose (WI_Tasks,TRUE);

      FreeTasks();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Tasks);
      MUI_DisposeObject (WI_Tasks);
      WI_Tasks = NULL;
      tasklist = NULL;
   }
}

APTR CxSortList[] = {
   &cxlist_cmpaddresshook,
   &cxlist_cmpnamehook,
   &cxlist_cmpprihook,
   NULL
};

static const char *CYA_CxSortText[] = {
   "address",
   "name",
   "priority",
   NULL
};

APTR WI_Cx, cxlist, cxtext, cxcount, CY_CxSort;
int  cxsortstate = 0;
APTR BT_CxAppear, BT_CxDisappear, BT_CxEnable, BT_CxDisable, BT_CxKill, BT_CxListChg, BT_CxUnique;
APTR BT_CxUpdate, BT_CxPrint, BT_CxPriority, BT_CxRemove, BT_CxMore, BT_CxExit;

char cx_title[WINDOWTITLELEN];

void CxWindow (BOOL state) {
   if (state) {
      if (WI_Cx) {
         ShowCx();
      } else {
         WI_Cx = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (cx_title, "COMMODITIES"),
         MUIA_HelpNode, CommoditiesText,
         MUIA_Window_ID, MakeListID('C','D','I','T'),
         WindowContents, VGroup,
            Child, cxlist = MyListviewObject ("DELTA=8,DELTA=8 P=\33c,DELTA=8 P=\33c,DELTA=8 P=\33c,DELTA=8,",&cxlist_dsphook),
            Child, MyBelowSortedListview (&cxtext, &cxcount, &CY_CxSort, CYA_CxSortText, cxsortstate),
            Child, MyVSpace(2),
            Child, VGroup,
               Child, HGroup, MUIA_Group_SameSize, TRUE,
                  Child, BT_CxAppear     = KeyButtonA (AppearText   ,ID_CXAPPEAR),
                  Child, BT_CxDisappear  = KeyButtonA (DisappearText,ID_CXDISAPPEAR),
                  Child, BT_CxEnable     = KeyButtonA (EnableText   ,ID_CXENABLE),
                  Child, BT_CxDisable    = KeyButtonA (DisableText  ,ID_CXDISABLE),
                  Child, BT_CxKill       = KeyButtonA (KillText     ,ID_CXKILL),
                  Child, BT_CxListChg    = KeyButtonA (ListChgText  ,ID_CXLISTCHG),
                  Child, BT_CxUnique     = KeyButtonA (UniqueText   ,ID_CXUNIQUE),
               End,
               Child, HGroup, MUIA_Group_SameSize, TRUE,
                  Child, BT_CxUpdate     = KeyButtonA (UpdateText   ,ID_CXUPDATE),
                  Child, BT_CxPrint      = KeyButtonA (PrintText    ,ID_CXPRINT),
                  Child, BT_CxPriority   = KeyButtonA (PriorityText ,ID_CXPRIORITY),
                  Child, BT_CxRemove     = KeyButtonA (RemoveText   ,ID_CXREMOVE),
                  Child, BT_CxMore       = KeyButtonA (MoreText     ,ID_CXMORE),
                  Child, BT_CxExit       = KeyButtonA (ExitText     ,ID_CXEXIT),
               End,
            End,
         End, End;

         if (WI_Cx) {
            DoMethod (AP_Scout,OM_ADDMEMBER,WI_Cx);
            DoMethod (WI_Cx,MUIM_Window_SetCycleChain,cxlist,CY_CxSort,BT_CxAppear,BT_CxDisappear,BT_CxEnable,BT_CxDisable,BT_CxKill,BT_CxListChg,BT_CxUnique,BT_CxUpdate,BT_CxPrint,BT_CxPriority,BT_CxRemove,BT_CxMore,BT_CxExit,NULL);
            DoMethod (CY_CxSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_CXSORT);

            SetCloseRequest (WI_Cx,ID_CXEXIT);
            SetListActive (cxlist,ID_CXLV_ACTIVE);
            SetListviewDoubleClick (cxlist,ID_CXMORE);

            ShowCx();

            SetWindowOpen (WI_Cx,cxlist,ID_CXEXIT);
         }
      }
   } else if ((! state) && (WI_Cx)) {
      SetWindowClose (WI_Cx,TRUE);
      FreeCx();
      DoMethod (AP_Scout,OM_REMMEMBER,WI_Cx);
      MUI_DisposeObject (WI_Cx);
      WI_Cx = NULL;
      cxlist = NULL;
   }
}


APTR ClassSortList[] = {
   &classlist_cmpaddresshook,
   &classlist_cmpnamehook,
   &classlist_cmpsuperhook,
   NULL
};

static const char *CYA_ClassSortText[] = {
   "address",
   "name",
   "superclass",
   NULL
};

APTR WI_Class, classlist, classtext, classcount, CY_ClassSort;
int  classsortstate = 0;
APTR BT_ClassUpdate, BT_ClassPrint, BT_ClassRemove, BT_ClassMore, BT_ClassExit;

char class_title[WINDOWTITLELEN];

void ClassWindow (BOOL state) {
   if (state) {
      if (WI_Class) {
         ShowClass();
      } else {
         WI_Class = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (cx_title, "CLASSES"),
         MUIA_HelpNode, ClassesText,
         MUIA_Window_ID, MakeListID('C','L','A','S'),
         WindowContents, VGroup,
            Child, classlist = MyListviewObject ("DELTA=8,DELTA=8,DELTA=8,DELTA=8,DELTA=8,",&classlist_dsphook),
            Child, MyBelowSortedListview (&classtext, &classcount, &CY_ClassSort, CYA_ClassSortText, classsortstate),
            Child, MyVSpace(2),
            Child, VGroup,
               Child, HGroup, MUIA_Group_SameSize, TRUE,
                  Child, BT_ClassUpdate     = KeyButtonA (UpdateText   ,ID_CLASSUPDATE),
                  Child, BT_ClassPrint      = KeyButtonA (PrintText    ,ID_CLASSPRINT),
                  Child, BT_ClassRemove     = KeyButtonA (RemoveText   ,ID_CLASSREMOVE),
                  Child, BT_ClassMore       = KeyButtonA (MoreText     ,ID_CLASSMORE),
                  Child, BT_ClassExit       = KeyButtonA (ExitText     ,ID_CLASSEXIT),
               End,
            End,
         End, End;

         if (WI_Class) {
            DoMethod (AP_Scout,OM_ADDMEMBER,WI_Class);
            DoMethod (WI_Class,MUIM_Window_SetCycleChain,classlist,CY_ClassSort,BT_ClassUpdate,BT_ClassPrint,BT_ClassRemove,BT_ClassMore,BT_ClassExit,NULL);
            DoMethod (CY_ClassSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_CLASSSORT);

            SetCloseRequest (WI_Class,ID_CLASSEXIT);
            SetListActive (classlist,ID_CLASSLV_ACTIVE);
            SetListviewDoubleClick (classlist,ID_CLASSMORE);

            ShowClass();

            SetWindowOpen (WI_Class,classlist,ID_CLASSEXIT);
         }
      }
   } else if ((! state) && (WI_Class)) {
      SetWindowClose (WI_Class,TRUE);
      FFreeClass();
      DoMethod (AP_Scout,OM_REMMEMBER,WI_Class);
      MUI_DisposeObject (WI_Class);
      WI_Class = NULL;
      classlist = NULL;
   }
}

APTR SModeSortList[] = {
   &smodelist_cmpidhook,
   &smodelist_cmpnamehook,
   &smodelist_cmpreshook,
   NULL
};

static const char *CYA_SModeSortText[] = {
   "ModeID",
   "name",
   "resolution",
   NULL
};

APTR WI_SMode, smodelist, smodetext, smodecount, CY_SModeSort;
int  smodesortstate = 0;
APTR BT_SModeUpdate, BT_SModePrint, BT_SModeMore, BT_SModeExit;

char smode_title[WINDOWTITLELEN];

void SModeWindow (BOOL state) {
   if (state) {
      if (WI_SMode) {
         ShowSMode();
      } else {
         WI_SMode = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (smode_title, "SCREENMODE"),
         MUIA_HelpNode, ScreenModeText,
         MUIA_Window_ID, MakeListID('S','M','D','E'),
         WindowContents, VGroup,
            Child, smodelist = MyListviewObject ("DELTA=8,DELTA=8,DELTA=8,DELTA=8,",&smodelist_dsphook),
            Child, MyBelowSortedListview (&smodetext, &smodecount, &CY_SModeSort, CYA_SModeSortText, smodesortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_SModeUpdate     = KeyButtonA (UpdateText   ,ID_SMODEUPDATE),
               Child, BT_SModePrint      = KeyButtonA (PrintText    ,ID_SMODEPRINT),
               Child, BT_SModeMore       = KeyButtonA (MoreText     ,ID_SMODEMORE),
               Child, BT_SModeExit       = KeyButtonA (ExitText     ,ID_SMODEEXIT),
            End,
         End, End;

         if (WI_SMode) {
            DoMethod (AP_Scout,OM_ADDMEMBER,WI_SMode);
            DoMethod (WI_SMode,MUIM_Window_SetCycleChain,smodelist,CY_SModeSort,BT_SModeUpdate,BT_SModePrint,BT_SModeMore,BT_SModeExit,NULL);
            DoMethod (CY_SModeSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_SMODESORT);

            SetCloseRequest (WI_SMode,ID_SMODEEXIT);
            SetListActive (smodelist,ID_SMODELV_ACTIVE);
            SetListviewDoubleClick (smodelist,ID_SMODEMORE);

            ShowSMode();

            SetWindowOpen (WI_SMode,smodelist,ID_SMODEEXIT);
         }
      }
   } else if ((! state) && (WI_SMode)) {
      SetWindowClose (WI_SMode,TRUE);
      FreeSMode();
      DoMethod (AP_Scout,OM_REMMEMBER,WI_SMode);
      MUI_DisposeObject (WI_SMode);
      WI_SMode = NULL;
      smodelist = NULL;
   }
}

APTR LibSortList[] = {
   &list_cmpnormalhook,
   &list_cmpnamehook,
   &list_cmpaddresshook,
   NULL
};

static const char *CYA_LibSortText[] = {
   "priority",
   "name",
   "address",
   NULL
};

APTR WI_Libraries, liblist, libtext, libcount, CY_LibSort;
int  libsortstate = 0;
APTR BT_LibUpdate, BT_LibPrint, BT_LibPriority, BT_LibClose, BT_LibRemove, BT_LibFunctions, BT_LibMore, BT_LibExit;

char libraries_title[WINDOWTITLELEN];

void LibrariesWindow (BOOL state) {
   if (state) {
      if (WI_Libraries) {
         ShowLibraries();
      } else {
         WI_Libraries = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (libraries_title, "LIBRARIES"),
         MUIA_HelpNode, LibrariesText,
         MUIA_Window_ID, MakeListID('L','I','B','S'),
         WindowContents, VGroup,
            Child, liblist = MyListviewObject (LibDevResFormatText,&liblist_dsphook),
            Child, MyBelowSortedListview (&libtext, &libcount, &CY_LibSort, CYA_LibSortText, libsortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_LibPriority  = KeyButtonA (PriorityText ,ID_LIBPRIORITY),
               Child, BT_LibClose     = KeyButtonA (CloseText    ,ID_LIBCLOSE),
               Child, BT_LibRemove    = KeyButtonA (RemoveText   ,ID_LIBREMOVE),
               Child, BT_LibFunctions = KeyButtonA (FunctionsText,ID_LIBFUNCTIONS),
            End,
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_LibUpdate    = KeyButtonA (UpdateText  ,ID_LIBUPDATE),
               Child, BT_LibPrint     = KeyButtonA (PrintText   ,ID_LIBPRINT),
               Child, BT_LibMore      = KeyButtonA (MoreText    ,ID_LIBMORE),
               Child, BT_LibExit      = KeyButtonA (ExitText    ,ID_LIBEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Libraries);
         DoMethod (WI_Libraries,MUIM_Window_SetCycleChain,liblist,CY_LibSort,BT_LibUpdate,BT_LibPrint,BT_LibPriority,BT_LibClose,BT_LibRemove,BT_LibFunctions,BT_LibMore,BT_LibExit,NULL);
         DoMethod (CY_LibSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_LIBSORT);

         SetCloseRequest (WI_Libraries,ID_LIBEXIT);
         SetListActive (liblist,ID_LIBLV_ACTIVE);
         SetListviewDoubleClick (liblist,ID_LIBMORE);

         ShowLibraries();

         SetWindowOpen (WI_Libraries,liblist,ID_LIBEXIT);
      }
   } else if ((! state) && (WI_Libraries)) {
      SetWindowClose (WI_Libraries,TRUE);

      FreeLibraries();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Libraries);
      MUI_DisposeObject (WI_Libraries);
      WI_Libraries = NULL;
      liblist = NULL;
   }
}

APTR WI_Devices, devlist, devtext, devcount, CY_DevSort;
int  devsortstate = 0;
APTR BT_DevUpdate, BT_DevPrint, BT_DevPriority, BT_DevRemove, BT_DevFunctions, BT_DevMore, BT_DevExit;

char devices_title[WINDOWTITLELEN];

void DevicesWindow (BOOL state) {
   if (state) {
      if (WI_Devices) {
         ShowDevices();
      } else {
         WI_Devices = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (devices_title, "DEVICES"),
         MUIA_HelpNode, DevicesText,
         MUIA_Window_ID, MakeListID('D','E','V','S'),
         WindowContents, VGroup,
            Child, devlist = MyListviewObject (LibDevResFormatText,&liblist_dsphook),
            Child, MyBelowSortedListview (&devtext, &devcount, &CY_DevSort, CYA_LibSortText, devsortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_DevPriority  = KeyButtonA (PriorityText ,ID_DEVPRIORITY),
               Child, BT_DevRemove    = KeyButtonA (RemoveText   ,ID_DEVREMOVE),
               Child, BT_DevFunctions = KeyButtonA (FunctionsText,ID_DEVFUNCTIONS),
            End,
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_DevUpdate    = KeyButtonA (UpdateText   ,ID_DEVUPDATE),
               Child, BT_DevPrint     = KeyButtonA (PrintText    ,ID_DEVPRINT),
               Child, BT_DevMore      = KeyButtonA (MoreText     ,ID_DEVMORE),
               Child, BT_DevExit      = KeyButtonA (ExitText     ,ID_DEVEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Devices);
         DoMethod (WI_Devices,MUIM_Window_SetCycleChain,devlist,CY_DevSort,BT_DevUpdate,BT_DevPrint,BT_DevPriority,BT_DevRemove,BT_DevMore,BT_DevFunctions,BT_DevExit,NULL);
         DoMethod (CY_DevSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_DEVSORT);

         SetCloseRequest (WI_Devices,ID_DEVEXIT);
         SetListActive (devlist,ID_DEVLV_ACTIVE);
         SetListviewDoubleClick (devlist,ID_DEVMORE);

         ShowDevices();

         SetWindowOpen (WI_Devices,devlist,ID_DEVEXIT);
      }
   } else if ((! state) && (WI_Devices)) {
      SetWindowClose (WI_Devices,TRUE);

      FreeDevices();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Devices);
      MUI_DisposeObject (WI_Devices);
      WI_Devices = NULL;
      devlist = NULL;
   }
}

APTR WI_Resources, reslist, restext, rescount, CY_ResSort;
int  ressortstate = 0;
APTR BT_ResUpdate, BT_ResPrint, BT_ResPriority, BT_ResRemove, BT_ResFunctions, BT_ResMore, BT_ResExit;

char resources_title[WINDOWTITLELEN];

void ResourcesWindow (BOOL state) {
   if (state) {
      if (WI_Resources) {
         ShowResources();
      } else {
         WI_Resources = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (resources_title, "RESOURCES"),
         MUIA_HelpNode, ResourcesText,
         MUIA_Window_ID, MakeListID('R','E','S','O'),
         WindowContents, VGroup,
            Child, reslist = MyListviewObject (LibDevResFormatText,&liblist_dsphook),
            Child, MyBelowSortedListview (&restext, &rescount, &CY_ResSort, CYA_LibSortText, ressortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_ResPriority  = KeyButtonA (PriorityText ,ID_RESPRIORITY),
               Child, BT_ResRemove    = KeyButtonA (RemoveText   ,ID_RESREMOVE),
               Child, BT_ResFunctions = KeyButtonA (FunctionsText,ID_RESFUNCTIONS),
            End,
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_ResUpdate    = KeyButtonA (UpdateText   ,ID_RESUPDATE),
               Child, BT_ResPrint     = KeyButtonA (PrintText    ,ID_RESPRINT),
               Child, BT_ResMore      = KeyButtonA (MoreText     ,ID_RESMORE),
               Child, BT_ResExit      = KeyButtonA (ExitText     ,ID_RESEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Resources);
         DoMethod (WI_Resources,MUIM_Window_SetCycleChain,reslist,CY_ResSort,BT_ResUpdate,BT_ResPrint,BT_ResPriority,BT_ResRemove,BT_ResFunctions,BT_ResMore,BT_ResExit,NULL);
         DoMethod (CY_ResSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_RESSORT);

         SetCloseRequest (WI_Resources,ID_RESEXIT);
         SetListActive (reslist,ID_RESLV_ACTIVE);
         SetListviewDoubleClick (reslist,ID_RESMORE);

         ShowResources();

         SetWindowOpen (WI_Resources,reslist,ID_RESEXIT);
      }
   } else if ((! state) && (WI_Resources)) {
      SetWindowClose (WI_Resources,TRUE);

      FreeResources();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Resources);
      MUI_DisposeObject (WI_Resources);
      WI_Resources = NULL;
      reslist = NULL;
   }
}

APTR WI_Locks, locklist, locktext, lockcount, CY_LockSort;
int  locksortstate = 0;
APTR lockpattern,locktext2;
APTR BT_LockUpdate, BT_LockPrint, BT_LockRemove, BT_LockExit;

APTR LockSortList[] = {
   &list_cmpnormalhook,
   &locklist_cmppathhook,
   &list_cmpaddresshook,
   NULL
};

static const char *CYA_LockSortText[] = {
   "normal",
   "path",
   "address",
   NULL
};

char locks_title[WINDOWTITLELEN];

void LocksWindow (BOOL state) {
   if (state) {
      if (WI_Locks) {
         ShowLocks();
      } else {
         WI_Locks = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (locks_title, "LOCKS"),
         MUIA_HelpNode, LocksText,
         MUIA_Window_ID, MakeListID('L','O','C','K'),
         WindowContents, VGroup,
            Child, locklist = ListviewObject,
               MUIA_Listview_MultiSelect, TRUE,
               MUIA_Listview_List, ListObject,
               MUIA_List_Format, "COL=0 DELTA=8,COL=1 DELTA=8 P=\33c,COL=2",
               MUIA_List_Title, TRUE,
               MUIA_List_DisplayHook, &locklist_dsphook,
               InputListFrame,
            End, End,
            Child, HGroup,
               Child, locktext = MyTextObject5(SPACE40),
               Child, HGroup, MUIA_HorizWeight, 0,
                  Child, MyLabel ("sorted by:"),
                  Child, CY_LockSort = CycleObject,
                     MUIA_Cycle_Entries, CYA_LockSortText,
                     MUIA_Cycle_Active, locksortstate,
                     MUIA_HorizWeight, 0,
                  End,
               End,
            End,
            Child, locktext2 = MyTextObject(),
            Child, HGroup,
               Child, KeyLabel("Pattern:", 'p'),
               Child, lockpattern = StringObject,
                  MUIA_String_Contents, "#?", MUIA_ControlChar, 'p',
                  MUIA_String_MaxLen, TEXTLENGTH, StringFrame,
               End,
            End,
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_LockUpdate   = KeyButtonA (UpdateText,ID_LOCKUPDATE),
               Child, BT_LockPrint    = KeyButtonA (PrintText ,ID_LOCKPRINT),
               Child, BT_LockRemove   = KeyButtonA (RemoveText,ID_LOCKREMOVE),
               Child, BT_LockExit     = KeyButtonA (ExitText  ,ID_LOCKEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Locks);
         DoMethod (WI_Locks,MUIM_Window_SetCycleChain,locklist,CY_LockSort,lockpattern,BT_LockUpdate,BT_LockPrint,BT_LockRemove,BT_LockExit,NULL);
         DoMethod (CY_LockSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_LOCKSORT);
         DoMethod (lockpattern,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,AP_Scout,2,MUIM_Application_ReturnID,ID_LOCKUPDATE);

         SetCloseRequest (WI_Locks,ID_LOCKEXIT);
         SetListActive (locklist,ID_LOCKLV_ACTIVE);

         SetWindowOpen (WI_Locks,lockpattern,ID_LOCKEXIT);
      }
   } else if ((! state) && (WI_Locks)) {
      SetWindowClose (WI_Locks,TRUE);

      FreeLocks();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Locks);
      MUI_DisposeObject (WI_Locks);
      WI_Locks = NULL;
      locklist = NULL;
   }
}

APTR WI_Ports, portlist, porttext, portcount, CY_PortSort;
int  portsortstate = 0;
APTR BT_PortUpdate, BT_PortPrint, BT_PortRemove, BT_PortPriority, BT_PortMore, BT_PortExit;

APTR PortSortList[] = {
   &tasklist_cmpprihook,
   &list_cmpnamehook,
   &tasklist_cmpaddresshook,
   NULL
};

static const char *CYA_PortSortText[] = {
   "priority",
   "name",
   "address",
   NULL
};

char ports_title[WINDOWTITLELEN];

void PortsWindow (BOOL state) {
   if (state) {
      if (WI_Ports) {
         ShowPorts();
      } else {
         WI_Ports = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (ports_title, "PORTS"),
         MUIA_HelpNode, PortsText,
         MUIA_Window_ID, MakeListID('P','O','R','T'),
         WindowContents, VGroup,
            Child, portlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33r,COL=3 DELTA=8 P=\33c,COL=4",&portlist_dsphook),
            Child, MyBelowSortedListview (&porttext, &portcount, &CY_PortSort, CYA_PortSortText, portsortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_PortUpdate   = KeyButtonA (UpdateText  ,ID_PORTUPDATE),
               Child, BT_PortPrint    = KeyButtonA (PrintText   ,ID_PORTPRINT),
               Child, BT_PortRemove   = KeyButtonA (RemoveText  ,ID_PORTREMOVE),
               Child, BT_PortPriority = KeyButtonA (PriorityText,ID_PORTPRIORITY),
               Child, BT_PortMore     = KeyButtonA (MoreText    ,ID_PORTMORE),
               Child, BT_PortExit     = KeyButtonA (ExitText    ,ID_PORTEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Ports);
         DoMethod (WI_Ports,MUIM_Window_SetCycleChain,portlist,CY_PortSort,BT_PortUpdate,BT_PortPrint,BT_PortRemove,BT_PortPriority,BT_PortMore,BT_PortExit,NULL);
         DoMethod (CY_PortSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_PORTSORT);

         SetCloseRequest (WI_Ports,ID_PORTEXIT);
         SetListActive (portlist,ID_PORTLV_ACTIVE);
         SetListviewDoubleClick (portlist,ID_PORTMORE);

         ShowPorts();

         SetWindowOpen (WI_Ports,portlist,ID_PORTEXIT);
      }
   } else if ((! state) && (WI_Ports)) {
      SetWindowClose (WI_Ports,TRUE);

      FreePorts();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Ports);
      MUI_DisposeObject (WI_Ports);
      WI_Ports = NULL;
      portlist = NULL;
   }
}

char memory_title[WINDOWTITLELEN];

void MemoryWindow (BOOL state) {
   if (state) {
      if (WI_Memory) {
         ShowMemory();
      } else {
         WI_Memory = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (memory_title, "MEMORY"),
         MUIA_HelpNode, MemoryText,
         MUIA_Window_ID, MakeListID('M','E','M','O'),
         WindowContents, VGroup,
            Child, memlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8,COL=3 DELTA=8 P=\33r,COL=4 DELTA=8,COL=5 DELTA=8,COL=6",&memlist_dsphook),
            Child, memtext = MyTextObject(),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_MemPrint    = KeyButtonA (PrintText   ,ID_MEMPRINT),
               Child, BT_MemPriority = KeyButtonA (PriorityText,ID_MEMPRIORITY),
               Child, BT_MemMore     = KeyButtonA (MoreText    ,ID_MEMMORE),
               Child, BT_MemExit     = KeyButtonA (ExitText    ,ID_MEMEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Memory);
         DoMethod (WI_Memory,MUIM_Window_SetCycleChain,memlist,BT_MemPrint,BT_MemPriority,BT_MemMore,BT_MemExit,NULL);

         SetCloseRequest (WI_Memory,ID_MEMEXIT);
         SetListActive (memlist,ID_MEMLV_ACTIVE);
         SetListviewDoubleClick (memlist,ID_MEMMORE);

         ShowMemory();

         SetWindowOpen (WI_Memory,memlist,ID_MEMEXIT);
      }
   } else if ((! state) && (WI_Memory)) {
      SetWindowClose (WI_Memory,TRUE);

      FreeMemory();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Memory);
      MUI_DisposeObject (WI_Memory);
      WI_Memory = NULL;
      memlist = NULL;
   }
}

APTR WI_Assigns, asslist, asstext, asscount, CY_AssSort;
int  asssortstate = 0;
APTR BT_AssUpdate, BT_AssPrint, BT_AssRemove, BT_AssExit;

APTR AssSortList[] = {
   &list_cmpnormalhook,
   &list_cmpnamehook,
   &list_cmpaddresshook,
   NULL
};

static const char *CYA_AssSortText[] = {
   "normal",
   "name",
   "address",
   NULL
};

char assigns_title[WINDOWTITLELEN];

void AssignsWindow (BOOL state) {
   if (state) {
      if (WI_Assigns) {
         ShowAssigns();
      } else {
         WI_Assigns = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (assigns_title, "ASSIGNS"),
         MUIA_HelpNode, AssignsText,
         MUIA_Window_ID, MakeListID('A','S','S','I'),
         WindowContents, VGroup,
            Child, asslist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2",&asslist_dsphook),
            Child, MyBelowSortedListview (&asstext, &asscount, &CY_AssSort, CYA_AssSortText, asssortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_AssUpdate  = KeyButtonA (UpdateText,ID_ASSUPDATE),
               Child, BT_AssPrint   = KeyButtonA (PrintText ,ID_ASSPRINT),
               Child, BT_AssRemove  = KeyButtonA (RemoveText,ID_ASSREMOVE),
               Child, BT_AssExit    = KeyButtonA (ExitText  ,ID_ASSEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Assigns);
         DoMethod (WI_Assigns,MUIM_Window_SetCycleChain,asslist,CY_AssSort,BT_AssUpdate,BT_AssPrint,BT_AssRemove,BT_AssExit,NULL);
         DoMethod (CY_AssSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_ASSSORT);

         SetCloseRequest (WI_Assigns,ID_ASSEXIT);
         SetListActive (asslist,ID_ASSLV_ACTIVE);

         ShowAssigns();

         SetWindowOpen (WI_Assigns,asslist,ID_ASSEXIT);
      }
   } else if ((! state) && (WI_Assigns)) {
      SetWindowClose (WI_Assigns,TRUE);

      FreeAssigns();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Assigns);
      MUI_DisposeObject (WI_Assigns);
      WI_Assigns = NULL;
      asslist = NULL;
   }
}

char vectors_title[WINDOWTITLELEN];

void VectorsWindow (BOOL state) {
   if (state) {
      if (WI_Vectors) {
         GetVectors();
      } else {
         WI_Vectors = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (vectors_title, "VECTORS"),
         MUIA_HelpNode, VectorsText,
         MUIA_Window_ID, MakeListID('V','E','C','T'),
         WindowContents, VGroup,

            Child, RegisterGroup(VectorPages),

               Child, HGroup, 
                  GroupFrameT("Reset Vectors"),
                  Child, HGroup,
                     Child, MyLabel2 (ESC "rColdCapture:\nCoolCapture:\nWarmCapture:\nKickMemPtr:\nKickTagPtr:\nKickCheckSum:"),
                     Child, vectext1 = MyTextObject2(),
                  End,
               End,

               Child, HGroup, 
                  GroupFrameT("Auto Vector Interrupts"),
                  Child, HGroup,
                     Child, MyLabel2 (ESC "rLevel1 ($0064):\nLevel2 ($0068):\nLevel3 ($006c):\nLevel4 ($0070):\nLevel5 ($0074):\nLevel6 ($0078):\nLevel7 ($007c):"),
                     Child, vectext2 = MyTextObject2(),
                  End,
               End,

               Child, HGroup, 
                  GroupFrameT("Interrupt Vectors"),
                  Child, HGroup,
                     Child, MyLabel (ESC "rTBE\nDSKBLK\nSOFTINT\nPORTS\nCOPPER\nVERTB\nBLITTER\nAUDIO0"),
                     Child, MyLabel (ESC "r 0:\n1:\n2:\n3:\n4:\n5:\n6:\n7:"),
                     Child, vectext3 = MyTextObject2(),
                  End,
                  Child, HGroup,
                     Child, MyLabel (ESC "rAUDIO1\nAUDIO2\nAUDIO3\nRBF\nDSKSYNC\nEXTER\nINTEN\nNMI"),
                     Child, MyLabel (ESC "r8:\n9:\n10:\n11:\n12:\n13:\n14:\n15:"),
                     Child, vectext4 = MyTextObject2(),
                  End,
               End,
            End,
#ifndef WINDOW_PROBLEMS
            Child, MyVSpace(4),
#endif
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_VecUpdate = KeyButtonA (UpdateText,ID_VECUPDATE),
               Child, BT_VecPrint  = KeyButtonA (PrintText ,ID_VECPRINT),
               Child, BT_VecExit   = KeyButtonA (ExitText  ,ID_VECEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Vectors);
         DoMethod (WI_Vectors,MUIM_Window_SetCycleChain,BT_VecUpdate,BT_VecPrint,BT_VecExit,NULL);
         SetCloseRequest (WI_Vectors,ID_VECEXIT);

         GetVectors();

         SetWindowOpen (WI_Vectors,NULL,ID_VECEXIT);
      }
   } else if ((! state) && (WI_Vectors)) {
      SetWindowClose (WI_Vectors,TRUE);

//      FreeVectors();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Vectors);
      MUI_DisposeObject (WI_Vectors);
      WI_Vectors = NULL;
   }
}


char allocations_title[WINDOWTITLELEN];

void AllocationsWindow (BOOL state) {
   if (state) {
      if (WI_Allocations) {
         GetAllocations();
      } else {
         WI_Allocations = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (allocations_title, "ALLOCATIONS"),
         MUIA_HelpNode, AllocationsText,
         MUIA_Window_ID, MakeListID('A','L','L','C'),
         WindowContents, VGroup,

            Child, RegisterGroup(AllocationsPages),

               Child, HGroup,
                  Child, HGroup,
                     GroupFrameT("CIA A"),
                     Child, HGroup,
                        Child, MyLabel2 (ESC "rTimer A:\nTimer B:\nAlarm:\nSerial:\nFlag:"),
                        Child, alctext1 = MyTextObject(),
                     End,
                  End,

                  Child, HGroup,
                     GroupFrameT("CIA B"),
                     Child, HGroup,
                        Child, MyLabel2 (ESC "rTimer A:\nTimer B:\nAlarm:\nSerial:\nFlag:"),
                        Child, alctext2 = MyTextObject(),
                     End,
                  End,
               End,

               Child, HGroup,
                  GroupFrameT("Ports"),
                  Child, HGroup,
                     Child, MyLabel2 (ESC "rSerial Port:\nSerial Control:\nParallel Port:\nParallel Control:"),
                     Child, alctext3 = MyTextObject(),
                  End,
               End,
            End,

#ifndef WINDOW_PROBLEMS
            Child, MyVSpace(4),
#endif
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_AlcUpdate = KeyButtonA (UpdateText,ID_ALCUPDATE),
               Child, BT_AlcPrint  = KeyButtonA (PrintText ,ID_ALCPRINT),
               Child, BT_AlcExit   = KeyButtonA (ExitText  ,ID_ALCEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Allocations);
         DoMethod (WI_Allocations,MUIM_Window_SetCycleChain,BT_AlcUpdate,BT_AlcPrint,BT_AlcExit,NULL);
         SetCloseRequest (WI_Allocations,ID_ALCEXIT);

         GetAllocations();

         SetWindowOpen (WI_Allocations,NULL,ID_ALCEXIT);
      }
   } else if ((! state) && (WI_Allocations)) {
      SetWindowClose (WI_Allocations,TRUE);

//      FreeAllocations();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Allocations);
      MUI_DisposeObject (WI_Allocations);
      WI_Allocations = NULL;
   }
}


APTR WI_Commands, comlist, comtext, comcount, CY_ComSort;
int  comsortstate = 0;
APTR BT_ComUpdate, BT_ComPrint, BT_ComRemove, BT_ComExit;

APTR ComSortList[] = {
   &list_cmpnormalhook,
   &list_cmpnamehook,
   &list_cmpaddresshook,
   NULL
};

static const char *CYA_ComSortText[] = {
   "normal",
   "name",
   "address",
   NULL
};

char commands_title[WINDOWTITLELEN];

void CommandsWindow (BOOL state) {
   if (state) {
      if (WI_Commands) {
         ShowCommands();
      } else {
         WI_Commands = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (commands_title, "RESIDENT COMMANDS"),
         MUIA_HelpNode, CommandsText,
         MUIA_Window_ID, MakeListID('R','C','O','M'),
         WindowContents, VGroup,
            Child, comlist = MyListviewObject ("COL=0 DELTA=8,COL=1 DELTA=8,COL=2 DELTA=8 P=\33c,COL=3 DELTA=8,COL=4 DELTA=8,COL=5 P=\33r",&comlist_dsphook),
            Child, MyBelowSortedListview (&comtext, &comcount, &CY_ComSort, CYA_ComSortText, comsortstate),
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_ComUpdate = KeyButtonA (UpdateText,ID_COMUPDATE),
               Child, BT_ComPrint  = KeyButtonA (PrintText ,ID_COMPRINT),
               Child, BT_ComRemove = KeyButtonA (RemoveText,ID_COMREMOVE),
               Child, BT_ComExit   = KeyButtonA (ExitText  ,ID_COMEXIT),
            End,
         End, End;

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_Commands);
         DoMethod (WI_Commands,MUIM_Window_SetCycleChain,comlist,CY_ComSort,BT_ComUpdate,BT_ComPrint,BT_ComRemove,BT_ComExit,NULL);
         DoMethod (CY_ComSort, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, AP_Scout, 2, MUIM_Application_ReturnID, ID_COMSORT);

         SetCloseRequest (WI_Commands,ID_COMEXIT);
         SetListActive (comlist,ID_COMLV_ACTIVE);

         ShowCommands();

         SetWindowOpen (WI_Commands,comlist,ID_COMEXIT);
      }
   } else if ((! state) && (WI_Commands)) {
      SetWindowClose (WI_Commands,TRUE);

      FreeCommands();

      DoMethod (AP_Scout,OM_REMMEMBER,WI_Commands);
      MUI_DisposeObject (WI_Commands);
      WI_Commands = NULL;
      comlist = NULL;
   }
}


APTR WI_System, syslist, systext;

char system_title[WINDOWTITLELEN];

void SystemWindow (BOOL state) {
   if (state) {
      if (WI_System) {
         ShowSystem();
      } else {
         WI_System = WindowObject,
         MUIA_Window_Title, MyGetWindowTitle (system_title, "SYSTEM"),
         MUIA_HelpNode, SystemText,
         MUIA_Window_ID, MakeListID('S','Y','S','T'),
         WindowContents, VGroup,
            Child, syslist = ListviewObject,
               MUIA_Listview_Input, FALSE,
               MUIA_Listview_List, ListObject,
                  MUIA_Font, MUIV_Font_Fixed,
                  ReadListFrame,
                  MUIA_List_Format, "DELTA=8 BAR P=\33r,",
                  MUIA_List_DisplayHook, &syslist_dsphook,
               End,
            End,
            Child, MyVSpace(2),
            Child, HGroup, MUIA_Group_SameSize, TRUE,
               Child, BT_SysUpdate = KeyButtonA (UpdateText,ID_SYSUPDATE),
               Child, BT_SysPrint  = KeyButtonA (PrintText ,ID_SYSPRINT),
               Child, BT_SysExit   = KeyButtonA (ExitText  ,ID_SYSEXIT),
            End,
         End, End;


         DoMethod (AP_Scout,OM_ADDMEMBER,WI_System);
         DoMethod (WI_System,MUIM_Window_SetCycleChain,syslist,BT_SysPrint,BT_SysExit,NULL);
         SetCloseRequest (WI_System,ID_SYSEXIT);

         ShowSystem();

         SetWindowOpen (WI_System,NULL,ID_SYSEXIT);
      }
   } else if ((! state) && (WI_System)) {
      SetWindowClose (WI_System,TRUE);
      FreeSystem();
      DoMethod (AP_Scout,OM_REMMEMBER,WI_System);
      MUI_DisposeObject (WI_System);
      WI_System = NULL;
   }
}


void AboutWindow (BOOL state) {
   if ((state) && (! WI_About)) {
      WI_About = WindowObject,
      MUIA_Window_Title, PROGNAME " " PROGVERSION "." PROGREVISION,
      WindowContents, VGroup,
         Child, AboutText= MyTextObject2(),
         Child, MyVSpace(4),
         Child, HGroup, MUIA_Group_SameSize, TRUE,
            Child, MyHSpace(0),
            Child, BT_AboutContinue = KeyButtonA (ContinueText,ID_ABOUTCONTINUE),
            Child, MyHSpace(0),
         End,
      End, End;

      if (WI_About) {
         MySetContents (AboutText,"%s%s\n",AboutText1,portname);

         DoMethod (AP_Scout,OM_ADDMEMBER,WI_About);
         SetCloseRequest (WI_About,ID_ABOUTCONTINUE);

         SetWindowOpen (WI_About,BT_AboutContinue,NULL);
      }
   } else if ((! state) && (WI_About)) {
      SetWindowClose (WI_About,FALSE);

      DoMethod (AP_Scout,OM_REMMEMBER,WI_About);
      MUI_DisposeObject (WI_About);
      WI_About = NULL;
   }
}

