home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / disk / misc / tracked / source.lha / sources / main.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  19KB  |  552 lines

  1.  
  2. /* main.c  contains init- and close routines and main message-loop */
  3.  
  4. #include <exec/io.h>
  5. #include <exec/devices.h>
  6. #include <exec/memory.h>
  7. #include <devices/inputevent.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <libraries/gadtools.h>
  11. #include <clib/intuition_protos.h>
  12. #include <clib/gadtools_protos.h>
  13.  
  14. struct Requester *BlockInput();
  15. UBYTE CXPos();
  16. void CleanExit();
  17.  
  18. struct IntuitionBase *IntuitionBase;
  19. struct Library *GadToolsBase, *AslBase;
  20. struct Device *ConsoleDevice;
  21. struct Window *Window;
  22. struct RastPort *RPort;
  23. struct Image_plus *Images;
  24. struct Requester *OBlock;
  25. APTR My_VisualInfo;
  26. struct Menu *My_MenuStrip;
  27. UBYTE *BB, *RB;
  28. struct IOStdReq ConReq;
  29. int drive, lastdrive;
  30. ULONG CurBlock;
  31. UBYTE CursorX, CursorY, OldCursorX, OldCursorY, RealCursorY;
  32.  
  33. extern struct NewMenu My_NewMenu[];
  34.  
  35. struct Image_plus
  36. {
  37.    UWORD  Im_Data[40];
  38.    struct Image  Im_Im;
  39. };
  40.  
  41. struct Image_plus Up_arrow =
  42. {
  43.    0x0000, 0x0000, 0x0000, 0x1000, 0x0060, 0x1000, 0x00f0, 0x1000,
  44.    0x01f8, 0x1000, 0x03fc, 0x1000, 0x07fe, 0x1000, 0x0fff, 0x1000,
  45.    0x0000, 0x1000, 0xffff, 0xf000,
  46.    0xffff, 0xf000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  47.    0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  48.    0x8000, 0x0000, 0x0000, 0x0000,
  49.    0, 0, 20, 10, 2, NULL, 3, 0, NULL
  50. };
  51.  
  52. struct Image_plus Down_arrow =
  53. {
  54.    0x0000, 0x0000, 0x0000, 0x1000, 0x0fff, 0x1000, 0x07fe, 0x1000,
  55.    0x03fc, 0x1000, 0x01f8, 0x1000, 0x00f0, 0x1000, 0x0060, 0x1000,
  56.    0x0000, 0x1000, 0xffff, 0xf000,
  57.    0xffff, 0xf000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  58.    0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  59.    0x8000, 0x0000, 0x0000, 0x0000,
  60.    0, 0, 20, 10, 2, NULL, 3, 0, NULL
  61. };
  62.  
  63. struct TextAttr  Style =
  64. {  (UBYTE *)"topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  65.  
  66. struct IntuiText
  67. Cursor     = {  1, 0, INVERSVID | COMPLEMENT, 0, 0, &Style, (UBYTE *)" ", NULL  },
  68. DriveText  = {  1, 0, JAM2, 50, 18, &Style, (UBYTE *)"Drive Unit", NULL  },
  69. DF0Text    = {  1, 0, JAM2, 6, 3, &Style, (UBYTE *)"DF0:", &DriveText  },
  70. DF1Text    = {  1, 0, JAM2, 6, 3, &Style, (UBYTE *)"DF1:", NULL  },
  71. DF2Text    = {  1, 0, JAM2, 6, 3, &Style, (UBYTE *)"DF2:", NULL  },
  72. DF3Text    = {  1, 0, JAM2, 6, 3, &Style, (UBYTE *)"DF3:", NULL  },
  73. TrackText  = {  1, 0, JAM2, 9, 18, &Style, (UBYTE *)"Track", NULL  },
  74. SectorText = {  1, 0, JAM2, 5, 18, &Style, (UBYTE *)"Sector", NULL  },
  75. BlockText  = {  1, 0, JAM2, 9, 18, &Style, (UBYTE *)"Block", NULL  },
  76. TestText2  = {  2, 3, JAM2, 440, 0, &Style, (UBYTE *)"0123456789ABCDEF", NULL  },
  77. TestText   = {  1, 0, JAM2, 0, 0, &Style, (UBYTE *)
  78.    "000: 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF", &TestText2  };
  79.  
  80.  
  81. WORD
  82. Boxpairs[]     = { 573, 1, 573, 131, 0, 131},
  83. Boxpairsa[]    = { 0, 130, 0, 0, 573, 0 },
  84. StrPairs[]     = { 44, 1, 44, 19, 0, 19 },
  85. StrPairsa[]    = { 0, 18, 0, 0, 44, 0 },
  86. DrivesPairs[]  = { 99, 1, 99, 11, 0, 11 },
  87. DrivesPairsa[] = { 0, 10, 0, 0, 99, 0 },
  88. TitlePairs[]   = { 51, 1, 51, 11, 0, 11 },
  89. TitlePairsa[]  = { 0, 10, 0, 0, 51, 0 },
  90. FourPairs[]    = { 44, 1, 44, 13, 0, 13 },
  91. FourPairsa[]   = { 0, 12, 0, 0, 44, 0 };
  92.  
  93. struct Border
  94. BoxBordera     = { 0, 0, 1, 0, JAM1, 3, Boxpairsa, NULL },
  95. BoxBorder      = { 0, 0, 2, 0, JAM1, 3, Boxpairs, &BoxBordera },
  96. StrBordera     = { -3, -6, 2, 0, JAM1, 3, StrPairsa, NULL },
  97. StrBorder      = { -3, -6, 1 ,0, JAM1, 3, StrPairs, &StrBordera },
  98. DrivesBordera  = { 0, 0, 1, 0, JAM1, 3, DrivesPairsa, NULL },
  99. DrivesBorder   = { 0, 0, 2, 0, JAM1, 3, DrivesPairs, &DrivesBordera },
  100. TitleBordera   = { 0, 0, 1, 0, JAM1, 3, TitlePairsa, NULL },
  101. TitleBorder    = { 0, 0, 2, 0, JAM1, 3, TitlePairs, &TitleBordera },
  102. FourBordera    = { 0, 0, 2, 0, JAM1, 3, FourPairsa, NULL },
  103. FourBorder     = { 0, 0, 1, 0, JAM1, 3, FourPairs, &FourBordera },
  104. FourBorderInva = { 0, 0, 1, 0, JAM1, 3, FourPairsa, NULL },
  105. FourBorderInv  = { 0, 0, 2, 0, JAM1, 3, FourPairs, &FourBorderInva };
  106.  
  107. UBYTE TrackBuffer[4], SectorBuffer[3], BlockBuffer[5];
  108.  
  109. struct PropInfo  Schuif_info =
  110. {  PROPNEWLOOK | FREEVERT | AUTOKNOB, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0, 0   };
  111.  
  112. struct StringInfo
  113. Track_info  = { TrackBuffer, NULL, 0, 4, 0, 0, 0, 0, 0, 0, NULL, 0, NULL },
  114. Sector_info = { SectorBuffer, NULL, 0, 3, 0, 0, 0, 0, 0, 0, NULL, 0, NULL },
  115. Block_info  = { BlockBuffer, NULL, 0, 5, 0, 0, 0, 0, 0, 0, NULL, 0, NULL };
  116.  
  117. /* Gadget ID's */
  118. #define g_DF0    1
  119. #define g_DF1    2
  120. #define g_DF2    3
  121. #define g_DF3    4
  122. #define g_Track  5
  123. #define g_Sector 6
  124. #define g_Block  7
  125. #define g_Schuif 8
  126. #define g_TrUp   9
  127. #define g_TrDown 10
  128. #define g_SeUp   11
  129. #define g_SeDown 12
  130. #define g_BlUp   13
  131. #define g_BlDown 14
  132. #define g_Box    15
  133.  
  134. /* Raw-codes for cursor keys */
  135. #define c_links  79
  136. #define c_rechts 78
  137. #define c_op     76
  138. #define c_neer   77
  139. #define c_min    76
  140. #define c_max    79
  141.  
  142. struct Gadget
  143. BoxGadget = {
  144.    NULL, 63, 18, 528, 128, GFLG_GADGHNONE, GACT_IMMEDIATE, GTYP_BOOLGADGET,
  145.    NULL, NULL, NULL, NULL, NULL, g_Box, NULL },
  146. SchuifGadget = {
  147.    &BoxGadget, 600, 16, 20, 132, GFLG_GADGHCOMP,
  148.    GACT_RELVERIFY, GTYP_PROPGADGET,
  149.    &Up_arrow.Im_Im, NULL, NULL, NULL, &Schuif_info, g_Schuif, NULL },
  150. BlDownGadget = {
  151.    &SchuifGadget, 494, 167, 20, 10, GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  152.    GACT_RELVERIFY, GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, g_BlDown,
  153.    NULL },
  154. BlUpGadget = {
  155.    &BlDownGadget, 494, 157, 20, 10, GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  156.    GACT_RELVERIFY, GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, g_BlUp,
  157.    NULL },
  158. SeDownGadget = {
  159.    &BlUpGadget, 394, 167, 20, 10, GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  160.    GACT_RELVERIFY, GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, g_SeDown,
  161.    NULL },
  162. SeUpGadget = {
  163.    &SeDownGadget, 394, 157, 20, 10, GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  164.    GACT_RELVERIFY, GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, g_SeUp,
  165.    NULL },
  166. TrDownGadget = {
  167.    &SeUpGadget, 294, 167, 20, 10, GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  168.    GACT_RELVERIFY, GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, g_TrDown,
  169.    NULL },
  170. TrUpGadget = {
  171.    &TrDownGadget, 294, 157, 20, 10, GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  172.    GACT_RELVERIFY, GTYP_BOOLGADGET, NULL, NULL, NULL, NULL, NULL, g_TrUp,
  173.    NULL },
  174. BlockGadget = {
  175.    &TrUpGadget, 452, 163, 43, 13, GFLG_GADGHCOMP,
  176.    GACT_RELVERIFY | GACT_STRINGCENTER | GACT_LONGINT, GTYP_STRGADGET,
  177.    (APTR)&StrBorder, NULL, &BlockText, NULL, &Block_info, g_Block, NULL },
  178. SectorGadget = {
  179.    &BlockGadget, 352, 163, 43, 13, GFLG_GADGHCOMP,
  180.    GACT_RELVERIFY | GACT_STRINGCENTER | GACT_LONGINT, GTYP_STRGADGET,
  181.    (APTR)&StrBorder, NULL, &SectorText, NULL, &Sector_info, g_Sector, NULL },
  182. TrackGadget = {
  183.    &SectorGadget, 252, 163, 43, 13, GFLG_GADGHCOMP,
  184.    GACT_RELVERIFY | GACT_STRINGCENTER | GACT_LONGINT, GTYP_STRGADGET,
  185.    (APTR)&StrBorder, NULL, &TrackText, NULL, &Track_info, g_Track, NULL },
  186. DF3Gadget = {
  187.    &TrackGadget, 163, 160, 45, 14, GFLG_GADGHNONE, GACT_IMMEDIATE,
  188.    GTYP_BOOLGADGET, (APTR)&FourBorder, NULL, &DF3Text, NULL, NULL, g_DF3,
  189.    NULL },
  190. DF2Gadget = {
  191.    &DF3Gadget, 118, 160, 45, 14, GFLG_GADGHNONE, GACT_IMMEDIATE,
  192.    GTYP_BOOLGADGET, (APTR)&FourBorder, NULL, &DF2Text, NULL, NULL, g_DF2,
  193.    NULL },
  194. DF1Gadget = {
  195.    &DF2Gadget, 73, 160, 45, 14, GFLG_GADGHNONE, GACT_IMMEDIATE,
  196.    GTYP_BOOLGADGET, (APTR)&FourBorder, NULL, &DF1Text, NULL, NULL, g_DF1,
  197.    NULL },
  198. DF0Gadget = {
  199.    &DF1Gadget, 28, 160, 45, 14, GFLG_GADGHNONE, GACT_IMMEDIATE,
  200.    GTYP_BOOLGADGET, (APTR)&FourBorderInv, NULL, &DF0Text, NULL, NULL, g_DF0,
  201.    NULL };
  202.  
  203. struct Gadget *DriveGadgets[] =
  204. {  &DF0Gadget, &DF1Gadget, &DF2Gadget, &DF3Gadget };
  205.  
  206. long main()
  207. {
  208.    struct IntuiMessage *message;
  209.    UWORD  code, GadgetNr;
  210.    struct InputEvent IE;
  211.    UBYTE IEString[20];
  212.    int drive2, td_err;
  213.    ULONG L;
  214.    BOOL loop = TRUE;
  215.  
  216.    Open_All();
  217.    td_err = ReadBlocks(drive, (WORD) Block_info.LongInt, 1, BB);
  218.    if (td_err) ProcessTDError(td_err);
  219.    CursorX = 0;
  220.    CursorY = 0;
  221.    UpDateSB();
  222.    UnBlockInput(OBlock, Window);
  223.  
  224.    while(loop)
  225.    {
  226.       if (!(message = (struct IntuiMessage *) GetMsg(Window->UserPort)))
  227.       {
  228.          Wait(1L << Window->UserPort->mp_SigBit);
  229.          continue;
  230.       }
  231.       code = message->Code;
  232.       if (message->Class & (IDCMP_GADGETUP | IDCMP_GADGETDOWN))
  233.          GadgetNr = ((struct Gadget *) message->IAddress)->GadgetID;
  234.       switch(message->Class)
  235.       {
  236.          case IDCMP_MENUPICK:
  237.             loop = DoMenu(MENUNUM(code), ITEMNUM(code), SUBNUM(code));
  238.             break;
  239.  
  240.          case IDCMP_RAWKEY:
  241.             if ((code >= c_min) && (code <= c_max))
  242.             {
  243.                switch(message->Code)
  244.                {
  245.                   case c_op:
  246.                      if (RealCursorY > 0)
  247.                      {
  248.                         RealCursorY--;
  249.                         if (CursorY == 0)
  250.                         {
  251.                            L = (ULONG) RealCursorY * 65536 / 16;
  252.                            NewModifyProp(&SchuifGadget, Window, NULL,
  253.                               Schuif_info.Flags, 0, (UWORD) L, 0,
  254.                               Schuif_info.VertBody, 1);
  255.                            UpDateSB();
  256.                         }
  257.                         else
  258.                         {
  259.                            CursorY--;
  260.                            UpDateCursor();
  261.                         }
  262.                      }
  263.                      break;
  264.  
  265.                   case c_neer:
  266.                      Cursor_Neer();
  267.                      break;
  268.  
  269.                   case c_links:
  270.                      if (CursorX > 0)
  271.                      {
  272.                         CursorX--;
  273.                         UpDateCursor();
  274.                      }
  275.                      break;
  276.  
  277.                   case c_rechts:
  278.                      if (CursorX < 47)
  279.                      {
  280.                         CursorX++;
  281.                         UpDateCursor();
  282.                      }
  283.                      break;
  284.                }
  285.             }
  286.             else if (code == 0x41)
  287.             {
  288.                if (CursorX > 0)
  289.                {
  290.                   CursorX--;
  291.                   UpDateCursor();
  292.                }
  293.             }
  294.             else if ((code == 0x44) && (RealCursorY != 31))
  295.             {
  296.                if (CursorX >= 32)
  297.                {
  298.                   CursorX = 32;
  299.                   Cursor_Neer();
  300.                }
  301.                else
  302.                {
  303.                   CursorX = 0;
  304.                   Cursor_Neer();
  305.                }
  306.             }
  307.  
  308.             else  /* Convert Rawkey to ASCII */
  309.             {
  310.                IE.ie_NextEvent = NULL;
  311.                IE.ie_Class = IECLASS_RAWKEY;
  312.                IE.ie_Code = code;
  313.                IE.ie_Qualifier = message->Qualifier;
  314.                if (RawKeyConvert(&IE, IEString, 20L, NULL) == 1)
  315.                   Process_VKey(IEString[0]);
  316.             }
  317.             break;
  318.  
  319.          case IDCMP_GADGETDOWN:
  320.             if (GadgetNr == g_Box)
  321.             {
  322.                Process_MPos((message->MouseX-63)/8, (message->MouseY-18)/8);
  323.             }
  324.             else if ((GadgetNr >= g_DF0) && (GadgetNr <= g_DF3))
  325.             {
  326.                drive2 = GadgetNr - g_DF0;
  327.                if (drive2 != drive)
  328.                {
  329.                   DriveGadgets[drive2]->GadgetRender = &FourBorderInv;
  330.                   DriveGadgets[drive]->GadgetRender = &FourBorder;
  331.                   RefreshGList(DriveGadgets[drive2], Window, NULL, 1);
  332.                   RefreshGList(DriveGadgets[drive], Window, NULL, 1);
  333.                   drive = drive2;
  334.                   CheckBlock();
  335.                }
  336.             }
  337.             break;
  338.  
  339.          case IDCMP_GADGETUP:
  340.             switch(GadgetNr)
  341.             {
  342.                case g_Track:
  343.                   if (Track_info.LongInt > 159L) Track_info.LongInt = 159L;
  344.                   if (Track_info.LongInt < 0L) Track_info.LongInt = 0L;
  345.                   sprintf(TrackBuffer, "%d\x00", Track_info.LongInt);
  346.                   RefreshGList(&TrackGadget, Window, NULL, 1);
  347.                   UpDateBlockG();
  348.                   CheckBlock();
  349.                   break;
  350.  
  351.                case g_Sector:
  352.                   if (Sector_info.LongInt > 10L) Sector_info.LongInt = 10L;
  353.                   if (Sector_info.LongInt < 0L) Sector_info.LongInt = 0L;
  354.                   sprintf(SectorBuffer, "%d\x00", Sector_info.LongInt);
  355.                   RefreshGList(&SectorGadget, Window, NULL, 1);
  356.                   UpDateBlockG();
  357.                   CheckBlock();
  358.                   break;
  359.  
  360.                case g_Block:
  361.                   if (Block_info.LongInt > 1759L) Block_info.LongInt = 1759L;
  362.                   if (Block_info.LongInt < 0L) Block_info.LongInt = 0L;
  363.                   sprintf(BlockBuffer, "%d\x00", Block_info.LongInt);
  364.                   RefreshGList(&BlockGadget, Window, NULL, 1);
  365.                   UpDateTrSeG();
  366.                   CheckBlock();
  367.                   break;
  368.  
  369.                case g_Schuif:
  370.                   UpDateSB();
  371.                   break;
  372.  
  373.                case g_TrUp:
  374.                   if (Track_info.LongInt < 159L)
  375.                   {
  376.                      sprintf(TrackBuffer, "%d\x00", ++Track_info.LongInt);
  377.                      RefreshGList(&TrackGadget, Window, NULL, 1);
  378.                      UpDateBlockG();
  379.                      CheckBlock();
  380.                   }
  381.                   break;
  382.  
  383.                case g_TrDown:
  384.                   if (Track_info.LongInt > 0L)
  385.                   {
  386.                      sprintf(TrackBuffer, "%d\x00", --Track_info.LongInt);
  387.                      RefreshGList(&TrackGadget, Window, NULL, 1);
  388.                      UpDateBlockG();
  389.                      CheckBlock();
  390.                   }
  391.                   break;
  392.  
  393.                case g_SeUp:
  394.                   if (Sector_info.LongInt < 21L)
  395.                   {
  396.                      sprintf(SectorBuffer, "%d\x00", ++Sector_info.LongInt);
  397.                      RefreshGList(&SectorGadget, Window, NULL, 1);
  398.                      UpDateBlockG();
  399.                      CheckBlock();
  400.                   }
  401.                   break;
  402.  
  403.                case g_SeDown:
  404.                   if (Sector_info.LongInt > 0L)
  405.                   {
  406.                      sprintf(SectorBuffer, "%d\x00", --Sector_info.LongInt);
  407.                      RefreshGList(&SectorGadget, Window, NULL, 1);
  408.                      UpDateBlockG();
  409.                      CheckBlock();
  410.                   }
  411.                   break;
  412.  
  413.                case g_BlUp:
  414.                   if (Block_info.LongInt < 1759L)
  415.                   {
  416.                      sprintf(BlockBuffer, "%d\x00", ++Block_info.LongInt);
  417.                      RefreshGList(&BlockGadget, Window, NULL, 1);
  418.                      UpDateTrSeG();
  419.                      CheckBlock();
  420.                   }
  421.                   break;
  422.  
  423.                case g_BlDown:
  424.                   if (Block_info.LongInt > 0L)
  425.                   {
  426.                      sprintf(BlockBuffer, "%d\x00", --Block_info.LongInt);
  427.                      RefreshGList(&BlockGadget, Window, NULL, 1);
  428.                      UpDateTrSeG();
  429.                      CheckBlock();
  430.                   }
  431.                   break;
  432.             }
  433.             break;
  434.       }
  435.       ReplyMsg((struct Message *)message);
  436.    }
  437.    Close_All();
  438.    return(0L);
  439. }
  440.  
  441. Open_All()
  442. {
  443.    struct IOStdReq IO;
  444.    int i;
  445.    BOOL menuok = FALSE;
  446.    ULONG MTC;
  447.  
  448.    IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0L);
  449.    if (IntuitionBase->LibNode.lib_Version < 37)
  450.       CleanExit(NULL, "This program requires Kickstart 2.0 or higher");
  451.    if (IntuitionBase->LibNode.lib_Version >= 39) MTC = 1;
  452.    else MTC = 2;
  453.    GadToolsBase = (struct Library *) OpenLibrary("gadtools.library", 37);
  454.    if (!GadToolsBase) CleanExit(NULL, "Could not open gadtools.library");
  455.  
  456.    CurBlock = 880L;
  457.    Block_info.LongInt = CurBlock;
  458.    sprintf(BlockBuffer, "%d\x00", Block_info.LongInt);
  459.  
  460.    drive = -1;
  461.    for (i = 0; i < 4; i++)
  462.    {
  463.       if (OpenDevice("trackdisk.device", i, &IO, 0))
  464.          DriveGadgets[i]->Flags |= GFLG_DISABLED;
  465.       else
  466.       {
  467.          CloseDevice(&IO);
  468.          if (drive < 0) drive = i;
  469.       }
  470.    }
  471.    if (drive < 0) CleanExit(NULL, "No diskdrives found");
  472.    lastdrive = drive;
  473.  
  474.    if (OpenDevice("console.device", -1L, &ConReq, 0L))
  475.       CleanExit(NULL, "Error opening console.device");
  476.    ConsoleDevice = ConReq.io_Device;
  477.  
  478.    Images = (struct Image_plus *) AllocMem(2*sizeof(struct Image_plus), MEMF_CHIP);
  479.    if (!Images) CleanExit(NULL, "Insufficient chip memory");
  480.    Images[0] = Up_arrow;
  481.    Images[1] = Down_arrow;
  482.    Images[0].Im_Im.ImageData = &Images[0].Im_Data[0];
  483.    Images[1].Im_Im.ImageData = &Images[1].Im_Data[0];
  484.    TrUpGadget.GadgetRender = &Images[0].Im_Im;
  485.    TrDownGadget.GadgetRender = &Images[1].Im_Im;
  486.    SeUpGadget.GadgetRender = &Images[0].Im_Im;
  487.    SeDownGadget.GadgetRender = &Images[1].Im_Im;
  488.    BlUpGadget.GadgetRender = &Images[0].Im_Im;
  489.    BlDownGadget.GadgetRender = &Images[1].Im_Im;
  490.  
  491.    Window = OpenWindowTags(NULL,
  492.       WA_Title,     "TrackEd",
  493.       WA_Flags,      0x00200000, /* OS3.0 white menus */
  494.       WA_Gadgets, &DF0Gadget,   WA_AutoAdjust,    TRUE,
  495.       WA_Top,           0,      WA_Left,             0,
  496.       WA_Width,       640,      WA_Height,         200,
  497.       WA_DragBar,    TRUE,      WA_DepthGadget,   TRUE,
  498.       WA_Activate,   TRUE,      WA_SmartRefresh,  TRUE,
  499.       WA_IDCMP, IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_MENUPICK |
  500.       IDCMP_RAWKEY,
  501.       TAG_END);
  502.  
  503.    if (!Window) CleanExit(NULL, "Unable to open window");
  504.    OBlock = BlockInput(Window);
  505.    RPort = Window->RPort;
  506.    UpDateTrSeG();
  507.    DrawBorder(RPort, &BoxBorder, 20L, 16L);
  508.    DrawBorder(RPort, &TitleBorder, 255L, 179L);
  509.    DrawBorder(RPort, &TitleBorder, 355L, 179L);
  510.    DrawBorder(RPort, &TitleBorder, 455L, 179L);
  511.    DrawBorder(RPort, &DrivesBorder, 68L, 176L);
  512.    BB = (UBYTE *) AllocMem(2*512L, MEMF_CHIP | MEMF_CLEAR);
  513.    if (!BB) CleanExit(Window, "Insufficient chip memory");
  514.    RB = &BB[512];
  515.    if (My_VisualInfo = GetVisualInfo(Window->WScreen, TAG_END))
  516.    {
  517.       if (My_MenuStrip = CreateMenus(My_NewMenu, GTMN_FrontPen, MTC, TAG_END))
  518.       {
  519.          if (LayoutMenus(My_MenuStrip, My_VisualInfo, TAG_END))
  520.          {
  521.             if (SetMenuStrip(Window, My_MenuStrip)) menuok = TRUE;
  522.          }
  523.       }
  524.    }
  525.    if (!menuok) CleanExit(Window, "Could not create menu");
  526. }
  527.  
  528. void CleanExit(window, string)
  529. struct Window *window;
  530. UBYTE *string;
  531. {
  532.    ShowText(window, string, "Exit");
  533.    Close_All();
  534.    exit(10);
  535. }
  536.  
  537. Close_All()
  538. {
  539.    if (ConsoleDevice) CloseDevice(&ConReq);
  540.    if (Window)
  541.    {
  542.       ClearMenuStrip(Window);
  543.       FreeMenus(My_MenuStrip);
  544.       FreeVisualInfo(My_VisualInfo);
  545.       CloseWindow(Window);
  546.    }
  547.    if (BB) FreeMem(BB, 2*512L);
  548.    if (Images) FreeMem(Images, 2*sizeof(struct Image_plus));
  549.    if (GadToolsBase) CloseLibrary(GadToolsBase);
  550.    if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  551. }
  552.