(c)  Copyright 1989 Commodore-Amiga, Inc.   All rights reserved.
The information contained herein is subject to change without notice, and 
is provided "as is" without warranty of any kind, either expressed or implied.  
The entire risk as to the use of this information is assumed by the user.



             OPENING FULL SIZE SCREENS AND WINDOWS ON ANY SYSTEM

                        Carolyn Scheppner - CATS


        When writing international software, it is important that your
     screen and window code adapt to both NTSC and PAL screen dimensions.
     In addition to conforming with NTSC (200 line) and PAL (256) line
     displays, you may also wish to adapt to interlace Workbench or any
     additional rows and columns enabled by Morerows (Fish Disk #54).
     
        The 1.2 system software supports both PAL and NTSC, and provides
     several methods for application software to do the same.  The GfxBase
     member DisplayFlags contains flag bits for PAL and NTSC.  Two other
     members, NormalDisplayColumns and NormalDisplayRows, contain the
     default width and height for a non-interlace Workbench screen.  A 
     new Intuition function GetScreenData can provide you with a copy of
     the system's Workbench (or CLI) Screen structure.  In addition, the
     new 1.2 Intuition constant STDSCREENHEIGHT can be specified for
     NewScreen.Height, causing OpenScreen to supply the correct screen
     height for the system you are running on and the ViewMode you
     have requested.  Proper use of these system features should also
     insure compatibility with any future Amiga screen resolutions.
        
        The example program FullScreen.c takes advantage of these new
     features to open a full-screen Workbench window, and two full-size
     custom screens and windows, one lo-res, the other hi-res interlace.
     The display sizes are automatically adjusted for NTSC, PAL, Morerows,
     and interlace Workbench.  Please note that when using any new 1.2
     features or functions, version number 33 should be specified when
     opening system libraries.  In addition, programs which use sprites
     may wish to refuse to run in a Morerows environment because the
     additional DMA cycles needed for the Morerows display can interfere
     with the proper display of sprites.  
          


/*
 *  FullScreen.c --- Opens full-size screens/windows on any
 *                     NTSC/PAL/Interlace/Morerows system
 *                           C. Scheppner  CBM  06/87 
 */

#include <exec/types.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>


struct   IntuitionBase  *IntuitionBase;
struct   GfxBase        *GfxBase;

#define IS_PAL  (((struct GfxBase *)GfxBase)->DisplayFlags & PAL)
#define IS_NTSC (((struct GfxBase *)GfxBase)->DisplayFlags & NTSC)


#define NOTYET (0)
#define DEPTH  (2)

struct   Screen         *loScreen, *hiScreen;
struct   Window         *loWindow, *hiWindow, *wbWindow;

ULONG    signals, waitMask, wbSig, loSig, hiSig;
BOOL     FromWB, Done;


struct   TextAttr       MyFont = {
   "topaz.font",                    /* Font Name   */
   TOPAZ_EIGHTY,                    /* Font Height */
   FS_NORMAL,                       /* Style       */
   FPF_ROMFONT,                     /* Preferences */
   };


struct   NewScreen      ns = {
   0, 0,                                  /* LeftEdge and TopEdge   */
   NOTYET,NOTYET,                         /* Width and Height       */
   DEPTH,                                 /* Depth                  */
   0, 1,                                  /* DetailPen and BlockPen */
   NOTYET,                                /* Special display modes  */
   CUSTOMSCREEN,                          /* Screen Type            */
   &MyFont,                               /* Use my font            */
   "==== Screen Title ====",              /* Title                  */
   NULL,                                  /* No gadgets             */
   NULL,                                  /* No bitmap supplied     */
   };

struct   NewWindow      nw = {
   0, 0,                                  /* LeftEdge and TopEdge */
   NOTYET, NOTYET,                        /* Width and Height */
   -1, -1,                                /* DetailPen and BlockPen */
   CLOSEWINDOW,                           /* IDCMP Flags */
   WINDOWDEPTH|WINDOWSIZING|              /* Flags */
   WINDOWDRAG|WINDOWCLOSE|
   SMART_REFRESH|ACTIVATE,
   NULL, NULL,                            /* Gadget and Image pointers */
   NOTYET,                                /* Title string */
   NULL,                                  /* Ptr to window's Screen */
   NULL,                                  /* BitMap pointer */
   40, 20,                                /* MinWidth and MinHeight */
   -1, -1,                                /* MaxWidth and MaxHeight */
   NOTYET                                 /* Type of window */
   };



main(argc,argv)
int argc;
char** argv;
   {
   struct Screen wbScrData;

   FromWB = (argc==0) ? TRUE : FALSE;

   /* Open Libraries - Need at least 1.2 for PAL and NTSC support */

   if(!(IntuitionBase =
      (struct IntuitionBase *)OpenLibrary("intuition.library", 33)))
         cleanexit("At least V1.2 intuition required\n");

   if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",33)))
      cleanexit("At least V1.2 graphics required\n");


   /* OPEN FULL-SIZE WINDOW ON WORKBENCH SCREEN */
B
   /* Get parameters of the existing Workbench screen */
   if(!(GetScreenData(&wbScrData,sizeof(struct Screen),WBENCHSCREEN,NULL)))
      cleanexit("Can't get default screen info\n");

   /* Set NewWindow sizes to match */
   nw.Width  = wbScrData.Width;
   nw.Height = wbScrData.Height;
   nw.Type   = WBENCHSCREEN;
   nw.Title  = ">>>> Workbench Window <<<<";

   /* Open the window */
   if(!(wbWindow = (struct Window *)OpenWindow(&nw)))
      cleanexit("Can't open wbWindow\n");

   /* Output info about this window */
   showInfo(wbWindow);


   /* OPEN A FULL-SIZE LO-RES CUSTOM SCREEN AND WINDOW */

   /* Set NewScreen sizes */
   ns.ViewModes   = NULL;                 /* Lo-res non-interlace screen */
   ns.Width       = wbScrData.Width >> 1;     /* Lo-res is half WB width */
   ns.Height      = STDSCREENHEIGHT;             /* From 1.2 intuition.h */

   /* Open the screen */
   if(!(loScreen = (struct Screen *)OpenScreen(&ns)))
      cleanexit("Can't open loScreen\n");

   /* Set NewWindow sizes to match */
   nw.Screen = loScreen;
   nw.Width  = loScreen->Width;
   nw.Height = loScreen->Height;
   nw.Type   = CUSTOMSCREEN;
   nw.Title  = ">>>> Lo-res <<<<";

   /* Open the window */
   if(!(loWindow = (struct Window *)OpenWindow(&nw)))
      cleanexit("Can't open loWindow\n");

   /* Output info about this window */
   showInfo(loWindow);


   /* OPEN A FULL-SIZE HI-RES LACE CUSTOM SCREEN AND WINDOW */

   /* Set NewScreen sizes */
   ns.ViewModes = HIRES|LACE;                 /* Hi-res interlace screen */
   ns.Width     = wbScrData.Width;            /* Same width as Workbench */
   ns.Height    = STDSCREENHEIGHT;               /* From 1.2 intuition.h */

   /* Open the screen */
   if(!(hiScreen = (struct Screen *)OpenScreen(&ns)))
      cleanexit("Can't open hiScreen\n");

   /* Set NewWindow sizes to match */
   nw.Screen = hiScreen;
   nw.Width  = hiScreen->Width;
   nw.Height = hiScreen->Height;
   nw.Type   = CUSTOMSCREEN;
   nw.Title  = ">>>> Hi-res Lace <<<<";

   /* Open the window */
   if(!(hiWindow = (struct Window *)OpenWindow(&nw)))
      cleanexit("Can't open hiWindow\n");

   /* Output info about this window */
   showInfo(hiWindow);


   /* Set up signal mask for each window */
   wbSig = 1 << wbWindow->UserPort->mp_SigBit;
   loSig = 1 << loWindow->UserPort->mp_SigBit;
   hiSig = 1 << hiWindow->UserPort->mp_SigBit;
   waitMask = wbSig|loSig|hiSig;    /* Will knock out each as closed */

   /* Wait for signals, Done when all windows are closed */
   Done = FALSE;
   while(!Done)
      {
      signals = Wait(waitMask);

      /* chkmsg will set Done = TRUE when all windows are closed */
      if(signals & wbSig)  chkmsg(wbWindow);
      if(signals & loSig)  chkmsg(loWindow);
      if(signals & hiSig)  chkmsg(hiWindow);
      }

   /* All closed - keep cleanup from re-closing */
   loWindow = hiWindow = wbWindow = NULL;
   loScreen = hiScreen = NULL;
   cleanup();
   }


showInfo(win)
struct Window *win;
   {
   struct RastPort *rp;
   char sbuf[80], *s;

   rp = win->RPort;
   SetAPen(rp,1);

   Move(rp,20,40);
   if(IS_PAL)        s = "Running on a PAL system";
   else if(IS_NTSC)  s = "Running on an NTSC system";
   Text(rp,s,strlen(s));

   Move(rp,20,80);
   sprintf(sbuf,"Screen Size: %ld by %ld",
              win->WScreen->Width, win->WScreen->Height);
   Text(rp,sbuf,strlen(sbuf));

   Move(rp,20,120);
   sprintf(sbuf,"( Close all windows to end demo )");
   Text(rp,sbuf,strlen(sbuf));

   Delay(100);
   }


chkmsg(win)
struct Window *win;
   {
   struct IntuiMessage *msg;
   ULONG  class, code;
   BOOL   CloseIt = FALSE;

   while(msg = (struct IntuiMessage *)GetMsg(win->UserPort))
      {
      class = msg->Class;
      code  = msg->Code;

      ReplyMsg(msg);
      switch(class)
         {
         case CLOSEWINDOW:
            CloseIt = TRUE;
            break;
         default:
            break;
         }
      }

   /* Handle Close after out of the GetMsg loop! */
   if(CloseIt)
      {
      /* Stop waiting on this one - Set Done = TRUE if none left */
      waitMask &= ~(1 << win->UserPort->mp_SigBit);
      if(!waitMask)  Done = TRUE;

      /* Close this display */
      closeDisplay(win, win->WScreen);
      }
   }

cleanexit(s)
char *s;
   {
   LONG wh;

   cleanup();
   if(*s)
      {
      if(FromWB)
         {
         if(wh = (Open("CON:40/40/600/100/>>>> Error <<<<",MODE_OLDFILE)))
            {
            Write(wh,s,strlen(s));
            Delay(200);
            Close(wh);
            }
          }
       else  printf(s);
       }
   exit(0);
   }


cleanup()
   {
   closeDisplay(hiWindow, hiScreen);
   closeDisplay(loWindow, loScreen);
   closeDisplay(wbWindow, NULL);

   if (GfxBase) CloseLibrary(GfxBase);
   if (IntuitionBase) CloseLibrary(IntuitionBase);
   }


closeDisplay(win,scr)
struct Window *win;
struct Screen *scr;
   {
   struct IntuiMessage *msg;

   /* Close the window */
   if(win)
      {
      while(msg = (struct IntuiMessage *)GetMsg(win->UserPort))
         {
         ReplyMsg(msg);
         }
      CloseWindow(win);
      }

   /* If not on WorkBench screen, close screen also */
   if((scr)&&((scr->Flags & SCREENTYPE)!=WBENCHSCREEN))  CloseScreen(scr);
   }


strlen(s)
char *s;
   {
   int i = 0;
   while(*s++) i++;
   return(i);
   }

/* end */
      
     



 

