home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / system / setdefmon / setdefmon.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  5KB  |  173 lines

  1. ;/* DICE invocation sequence
  2.   stack 50000
  3.   dcc setdefmon.c -v -mi -ms -r -proto -mD -c -3.0 -no-env
  4.   dlink setdefmon.o -osetdefmon -v
  5.   protect setdefmon +p 
  6.   quit 0 ;                                                 */
  7. /* SetDefMon - sets the systems default monitor from wb/cli  */
  8. /*        (w) 1992-1993 by Franz_Schwarz@mil.ka.sub.org      */
  9. /*                         Franz Schwarz FIDO 2:2476/506.18  */
  10. /* version history                                           */
  11. /* 21 Dec 92 initial release 1.0                             */
  12. /* 15 Jan 93 1.1 added modification of GfxBase->DisplayFlags */
  13. /*               added Disable()/Enable() to modify GfxBase  */
  14. /* 12 Jul 93 1.1a modified to use  DICE #pragma calls        */
  15. /*                the executable is now pure, reentrant.     */
  16. /* 09 Sep 93 1.2  added support for SUPER72, DBLNTSC, DBLPAL */
  17. /*                now requires 3.0 Includes                  */
  18.  
  19.  
  20. #include <graphics/gfxbase.h>
  21. #include <graphics/displayinfo.h>
  22. #include <intuition/intuition.h>
  23. #include <workbench/startup.h>
  24. #include <workbench/workbench.h>
  25. #include <exec/execbase.h>
  26. #include <exec/alerts.h>
  27. #include <exec/ports.h>
  28. #include <proto/exec.h>
  29. #include <proto/intuition.h>
  30. #include <proto/dos.h>
  31. #include <proto/icon.h>
  32. #include <proto/graphics.h>
  33.  
  34. #define NUM_MODES 6
  35.  
  36. LONG Main (VOID);
  37. LONG
  38. Start (VOID)
  39. {
  40.   return Main ();
  41. };
  42.  
  43. const char vers[] = "\0$VER: SetDefMon 1.2 (9.9.93)";
  44.  
  45. const char tmpl[] = "PAL/S,NTSC/S,EURO36/S,SUPER72/S,DBLNTSC/S,DBLPAL/S";
  46. const char *const modenames[] =
  47. {"PAL", "NTSC", "EURO36", "SUPER72", "DBLNTSC", "DBLPAL"};
  48. const ULONG monitors[NUM_MODES] =
  49. {PAL_MONITOR_ID, NTSC_MONITOR_ID, EURO36_MONITOR_ID, SUPER72_MONITOR_ID,
  50.  DBLNTSC_MONITOR_ID, DBLPAL_MONITOR_ID};
  51. const char vblank[NUM_MODES] =
  52. {50, 60, 70, 70, 60, 50};
  53. const UWORD flags[NUM_MODES] =
  54. {PAL, NTSC, NTSC, NTSC, NTSC, PAL};
  55.  
  56. #define NEED_AGA ((1<<4) + (1<<5))
  57.  
  58. struct ArgsT
  59.   {
  60.     ULONG larr[NUM_MODES];
  61.   };
  62.  
  63. const struct ArgsT cargs =
  64. {0, 0, 0, 0, 0, 0};
  65.  
  66.  
  67. LONG
  68. Main (VOID)
  69. {
  70.   APTR IntuitionBase, DOSBase, IconBase;
  71.   struct ExecBase *SysBase;
  72.   struct GfxBase *GfxBase;
  73.   LONG i = 0, mon = -1;
  74.   struct RDArgs *rda;
  75.   struct Process *me;
  76.   struct DiskObject *dskobj;
  77.   struct WBStartup *msg;
  78.   struct ArgsT args;
  79.   struct Rectangle r;
  80.   BPTR lock;
  81.   LONG rc = 20;
  82.   args = cargs;
  83.   SysBase = *(VOID **) 0x00000004;
  84.   if (!((me = (struct Process *) FindTask (NULL))->pr_CLI))
  85.     {
  86.       WaitPort (&me->pr_MsgPort);
  87.       msg = (struct WBStartup *) GetMsg (&me->pr_MsgPort);
  88.     }
  89.   if (DOSBase = OpenLibrary ("dos.library", 37))
  90.     {
  91.       if (GfxBase = OpenLibrary ("graphics.library", 37))
  92.     {
  93.       if (IntuitionBase = OpenLibrary ("intuition.library", 37))
  94.         {
  95.           if (!me->pr_CLI)
  96.         if (IconBase = OpenLibrary ("icon.library", 37))
  97.           {
  98.             lock = CurrentDir (msg->sm_ArgList->wa_Lock);
  99.             if (dskobj = GetDiskObjectNew (msg->sm_ArgList->wa_Name))
  100.               {
  101.             for (; i < NUM_MODES; i++)
  102.               if (FindToolType (dskobj->do_ToolTypes, modenames[i]))
  103.                 mon = (mon == -1 ? i : -2);
  104.             FreeDiskObject (dskobj);
  105.               }
  106.             CurrentDir (lock);
  107.             CloseLibrary (IconBase);
  108.           }
  109.         else
  110.           Alert (AT_Recovery | AG_OpenLib | AO_IconLib | AN_Unknown);
  111.           else if (rda = ReadArgs (tmpl, args.larr, NULL))
  112.         {
  113.           for (; i < NUM_MODES; i++)
  114.             if (args.larr[i])
  115.               mon = (mon == -1 ? i : -2);
  116.           FreeArgs (rda);
  117.         }
  118.           switch (mon)
  119.         {
  120.         case -1:
  121.           SetIoErr (ERROR_REQUIRED_ARG_MISSING);
  122.           break;
  123.         case -2:
  124.           SetIoErr (ERROR_TOO_MANY_ARGS);
  125.           break;
  126.         default:
  127.           if (!ModeNotAvailable (monitors[mon] | HIRES_KEY) &&
  128.               QueryOverscan (monitors[mon] | HIRES_KEY, &r, OSCAN_TEXT))
  129.             {
  130.               if (((1 << mon) & NEED_AGA) ?
  131.               ((GfxBase->ChipRevBits0 & (GFXF_AA_ALICE | GFXF_AA_LISA))
  132.                == (GFXF_AA_ALICE | GFXF_AA_LISA)) : TRUE)
  133.             {
  134.               Disable ();
  135.               GfxBase->DisplayFlags &= ~(NTSC | PAL);
  136.               GfxBase->DisplayFlags |= flags[mon];
  137.               GfxBase->NormalDisplayColumns = r.MaxX + 1;
  138.               GfxBase->NormalDisplayRows = r.MaxY + 1;
  139.               GfxBase->monitor_id = monitors[mon] >> 16;
  140.               SysBase->VBlankFrequency = vblank[mon];
  141.               Enable ();
  142.               rc = 0;
  143.             }
  144.               else
  145.             SetIoErr (ERROR_OBJECT_WRONG_TYPE);
  146.             }
  147.           else
  148.             SetIoErr (ERROR_OBJECT_NOT_FOUND);
  149.         }
  150.           if (!me->pr_CLI && rc)
  151.         DisplayBeep (NULL);
  152.           CloseLibrary (IntuitionBase);
  153.         }
  154.       else
  155.         Alert (AT_Recovery | AG_OpenLib | AO_Intuition | AN_Unknown);
  156.       CloseLibrary ((struct Library *) GfxBase);
  157.     }
  158.       else
  159.     Alert (AT_Recovery | AG_OpenLib | AO_GraphicsLib | AN_Unknown);
  160.       if (rc)
  161.     FPuts (Output (), "SetDefMon failed!\n");
  162.       CloseLibrary (DOSBase);
  163.     }
  164.   else
  165.     Alert (AT_Recovery | AG_OpenLib | AO_DOSLib | AN_Unknown);
  166.   if (!me->pr_CLI)
  167.     {
  168.       Forbid ();
  169.       ReplyMsg ((struct Message *) msg);
  170.     }
  171.   return rc;
  172. }
  173.