home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / screen / fsm.lha / FixScreenMode.c next >
C/C++ Source or Header  |  1992-10-20  |  5KB  |  241 lines

  1. /*    ts;4    */
  2. /*
  3.     lc -v -O -cs FixScreenMode
  4.     asm -ILATTICE:asm/ NewOpenScreenTagList.asm
  5.     blink from FixScreenMode.o NewOpenScreenTagList.o TO FixScreenMode SC SD ND
  6. */
  7. #include <exec/types.h>
  8. #include <exec/alerts.h>
  9. #include <exec/execbase.h>
  10. #include <exec/libraries.h>
  11. #include <dos/dosextens.h>
  12. #include <utility/tagitem.h>
  13. #include <graphics/gfxbase.h>
  14. #include <intuition/screens.h>
  15. #include <intuition/intuition.h>
  16. #include <intuition/intuitionbase.h>
  17.  
  18. #include <clib/exec_protos.h>
  19. #include <clib/dos_protos.h>
  20. #include <clib/utility_protos.h>
  21. #include <clib/graphics_protos.h>
  22. #include <clib/intuition_protos.h>
  23.  
  24. #define LIB_2_0        36
  25. #define ABSEXECBASE    ((struct ExecBase **) 0x4)
  26.  
  27. #include <pragma/exec_lib.fd.h>
  28. #include <pragma/dos_lib.fd.h>
  29. #include <pragma/utility_lib.fd.h>
  30. #include <pragma/graphics_lib.fd.h>
  31. #include <pragma/intuition_lib.fd.h>
  32.  
  33. #define DOSNAME            "dos.library"
  34. #define UTILITYNAME        "utility.library"
  35. #define GRAPHICSNAME    "graphics.library"
  36. #define INTUITIONNAME    "intuition.library"
  37.  
  38. extern struct ExecBase        *ExecBase;
  39. extern struct DosLibrary    *DOSBase;
  40. extern struct Library        *far UtilityBase;
  41. extern struct IntuitionBase    *IntuitionBase;
  42. extern struct GfxBase        *GfxBase;
  43.  
  44. extern struct TagItem    far ScreenTags[];
  45. extern LONG    EasyRequestStub(
  46.     struct Window *Window,
  47.     struct EasyStruct *EasyStruct,
  48.     ULONG *IdcmpPtr,
  49.     ...
  50. );
  51.  
  52. #define OPENSCREENTAGLIST    (-612)
  53. extern APTR        far OldOpenScreenTagList;
  54. extern ULONG    far NewOpenScreenTagList();
  55.  
  56. #define WIDTH_TAG        0
  57. #define HEIGTH_TAG        WIDTH_TAG + 1
  58. #define DISPALYID_TAG    HEIGTH_TAG + 1
  59.  
  60. extern char                    NewName[];
  61. extern struct EasyStruct    EasyStruct;
  62.  
  63. #define DONE    0
  64. __saveds LONG    Start()
  65. {
  66.     register LONG    RetVal = !DONE;
  67.  
  68.     register struct Process    *Process;
  69.     register struct CommandLineInterface    *CLI;
  70.     register struct Message    *Message;
  71.     register struct Task    *Task;
  72.     register char            *OldName;
  73.     register struct Screen    *WorkBench;
  74.  
  75.     ExecBase = (*ABSEXECBASE);
  76.     if(ExecBase->LibNode.lib_Version < LIB_2_0)
  77.     {
  78.         Alert(AG_OpenLib | AO_ExecLib);
  79.         goto    NoExecBase;
  80.     }
  81.  
  82.     if(!(DOSBase = (struct DosLibrary *)
  83.         OpenLibrary(DOSNAME, LIB_2_0)))
  84.     {
  85.         Alert(AG_OpenLib | AO_DOSLib);
  86.         goto    NoDOSBase;
  87.     }
  88.  
  89.     if(!(UtilityBase = (struct Library *) 
  90.         OpenLibrary(UTILITYNAME, LIB_2_0))
  91.     )
  92.     {
  93.         Alert(AG_OpenLib | AO_UtilityLib);
  94.         goto    NoUtilityBase;
  95.     }
  96.  
  97.     if(!(GfxBase = (struct GfxBase *)
  98.         OpenLibrary(GRAPHICSNAME, LIB_2_0))
  99.     )
  100.     {
  101.         Alert(AG_OpenLib | AO_GraphicsLib);
  102.         goto    NoGfxBase;
  103.     }
  104.  
  105.     if(!(IntuitionBase = (struct IntuitionBase *)
  106.         OpenLibrary(INTUITIONNAME, LIB_2_0))
  107.     )
  108.     {
  109.         Alert(AG_OpenLib | AO_Intuition);
  110.         goto    NoIntuitionBase;
  111.     }
  112.  
  113.     Process = (struct Process *) ExecBase->ThisTask;
  114.     if(!(CLI = Cli()))
  115.     {
  116.         WaitPort(&Process->pr_MsgPort);
  117.         Message = GetMsg(&Process->pr_MsgPort);
  118.     }
  119.  
  120.     if(!(Task = FindTask(NewName)))
  121.         goto    FirstTime;
  122.  
  123.     RetVal = DONE;
  124.  
  125.     Signal(Task, SIGBREAKF_CTRL_C);
  126.  
  127.     EasyRequestStub(NULL, &EasyStruct, NULL, "OFF");
  128.  
  129.     goto    SecondTime;
  130. FirstTime:
  131.     Task = (struct Task *) Process;
  132.     OldName = Task->tc_Node.ln_Name;
  133.     Task->tc_Node.ln_Name = NewName;
  134.  
  135.     if(!(WorkBench = LockPubScreen("Workbench")))
  136.         goto    NoWorkbench;
  137.  
  138.     ScreenTags[WIDTH_TAG].ti_Data = (ULONG) WorkBench->Width;
  139.     ScreenTags[HEIGTH_TAG].ti_Data = (ULONG) WorkBench->Height;
  140.     ScreenTags[DISPALYID_TAG].ti_Data = (ULONG) GetVPModeID(&WorkBench->ViewPort);
  141.  
  142.     UnlockPubScreen(NULL, WorkBench);
  143.  
  144.     if(!
  145.         (OldOpenScreenTagList =
  146.             SetFunction(
  147.                 (struct Library *) IntuitionBase,
  148.                 (LONG) OPENSCREENTAGLIST,
  149.                 (ULONG (*)()) NewOpenScreenTagList
  150.             )
  151.         )
  152.     )
  153.         goto    NoSetOpenScreenTagList;
  154.  
  155.     EasyRequestStub(NULL, &EasyStruct, NULL, "ON");
  156.  
  157.     Wait(SIGBREAKF_CTRL_C);
  158.  
  159.     RetVal = DONE;
  160.  
  161.     SetFunction(
  162.         (struct Library *) IntuitionBase,
  163.         (LONG) OPENSCREENTAGLIST,
  164.         (ULONG (*)()) OldOpenScreenTagList
  165.     );
  166.  
  167. NoSetOpenScreenTagList:
  168.  
  169. NoWorkbench:
  170.  
  171.     Task->tc_Node.ln_Name = OldName;
  172. SecondTime:
  173.  
  174.     if(!CLI)
  175.     {
  176.         Forbid();
  177.         ReplyMsg(Message);
  178.     }
  179.  
  180.     CloseLibrary((struct Library *) IntuitionBase);
  181. NoIntuitionBase:
  182.  
  183.     CloseLibrary((struct Library *) GfxBase);
  184. NoGfxBase:
  185.  
  186.     CloseLibrary((struct Library *) UtilityBase);
  187. NoUtilityBase:
  188.  
  189.     CloseLibrary((struct Library *) DOSBase);
  190. NoDOSBase:
  191.  
  192. NoExecBase:
  193.  
  194.     return(RetVal);
  195. }
  196.  
  197. static char    Version[] = "\0$VER: FixScreenMode 1.0 (10.20.92)";
  198.  
  199. struct ExecBase            *ExecBase;
  200. struct DosLibrary        *DOSBase;
  201. struct Library            *far UtilityBase;
  202. struct IntuitionBase    *IntuitionBase;
  203. struct GfxBase            *GfxBase;
  204.  
  205. struct TagItem    far ScreenTags[] =
  206. {
  207.     {SA_Width, (ULONG) 0},        /*    WorkBench->Width                    */
  208.     {SA_Height, (ULONG) 0},        /*    WorkBench->Height                    */
  209.     {SA_DisplayID, (ULONG) 0},    /*    GetVPModeID(&WorkBench->ViewPort)    */
  210.     {TAG_MORE, (ULONG) 0}        /*    original ScreenTags                    */
  211. };
  212.  
  213. APTR    far OldOpenScreenTagList;
  214.  
  215. LONG    EasyRequestStub(
  216.     struct Window *Window,
  217.     struct EasyStruct *EasyStruct,
  218.     ULONG *IdcmpPtr,
  219.     ...
  220. )
  221. {
  222.     return(
  223.         EasyRequestArgs(
  224.             Window,
  225.             EasyStruct,
  226.             IdcmpPtr,
  227.             (UWORD *) (&IdcmpPtr + 1)
  228.         )
  229.     );
  230. }
  231.  
  232. char                NewName[] = "FixScreenMode-Task";
  233. struct EasyStruct    EasyStruct =
  234. {
  235.     sizeof(struct EasyStruct),
  236.     0,
  237.     "Version 1.0",
  238.     "FixScreenMode\nSwitched %s\n",
  239.     "OK!|OK!"
  240. };
  241.