home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / screen / shdwmstr.lha / source / savers / savermain.h < prev    next >
C/C++ Source or Header  |  1991-12-03  |  3KB  |  85 lines

  1. /*
  2.  * This is the "startup" code for many (all?) of the savers. It gets included
  3.  * into them in the appropriate place, mostly because I got tired of tweaking
  4.  * _all_ the savers when I made a change in this code...
  5.  *
  6.  * Copyright 1991, Mike Meyer
  7.  * All Rights Reserved
  8.  *
  9.  * See the file "ShadowMaster:Distribution" for information on distribution.
  10.  */
  11.  
  12. static USHORT __chip SpriteData[] = {
  13.     0,0,
  14.     0,0,
  15.     0,0
  16.     } ;
  17. #include <string.h>
  18. /*
  19.  * This is the starting point. It sets up the world, and calls your
  20.  * graphics routine (dographics()), then cleans up after itself when you
  21.  * return. Nothing in here should need changing.
  22.  */
  23. #define done(x)    do { status = x; goto out; } while (0) ;
  24. int __saveds
  25. start(void) {
  26.     int status = RETURN_OK, old_prio ;
  27. #ifndef    NORAND
  28.     struct DateStamp ds ;
  29. #endif
  30.  
  31.     SysBase = *((struct ExecBase **) 4);
  32.     if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 37)) == NULL)
  33.         done(RETURN_FAIL) ;
  34.     if ((IntuitionBase = (struct IntuitionBase *)
  35.         OpenLibrary("intuition.library", 37)) == NULL)
  36.         done(RETURN_FAIL) ;
  37.     if ((GfxBase = (struct GfxBase *)
  38.         OpenLibrary("graphics.library", 37)) == NULL)
  39.         done(RETURN_FAIL) ;
  40.  
  41.     if ((screen = OpenScreenTagList(NULL, ScreenTags)) == NULL)
  42.         done(RETURN_FAIL) ;
  43.     WindowTags[0].ti_Data = (ULONG) screen ;
  44.  
  45.     /* Window is to clear the sprite */
  46.     if ((window = OpenWindowTagList(NULL, WindowTags)) == NULL)
  47.         done(RETURN_FAIL) ;
  48.     SetPointer(window, SpriteData, 1, 1, 0, 0);
  49.  
  50.     /* Draw our name into the window, just in case... */
  51.     Move(window->RPort, 
  52.         (window->Width - TextLength(window->RPort, Title, strlen(Title))) / 2,
  53.         screen->Height / 2) ;
  54.     Text(window->RPort, Title, strlen(Title)) ;
  55.  
  56. #ifndef    NORAND
  57.     /* Seed the random number generator before we drop task priority */
  58.     DateStamp(&ds) ;
  59.     srand(ds.ds_Tick) ;
  60. #endif
  61.     /* One last check before drop our priority through the ground */
  62.     if (CheckSignal(SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) done(RETURN_OK) ;
  63.     old_prio = SetTaskPri(FindTask(0L), -100L) ;
  64.     
  65.     Delay(50) ;
  66.     SetRast(&screen->RastPort, 0) ;
  67.     dographics() ;
  68.  
  69.     /* Here's how we exit this mess */
  70.     SetTaskPri(FindTask(0L), old_prio) ;
  71. out:
  72.     if (window) {
  73.         ClearPointer(window) ;
  74.         CloseWindow(window) ;
  75.         }
  76.     if (screen) CloseScreen(screen) ;
  77.     if (GfxBase)  CloseLibrary((struct Library *) GfxBase) ;
  78.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase) ;
  79.     if (DOSBase) CloseLibrary((struct Library *) DOSBase) ;
  80.     return status ;
  81.     }
  82.  
  83. /* Make sure we don't screw up any following code... */
  84. #undef done
  85.