home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / mac / programm / 18158 < prev    next >
Encoding:
Text File  |  1992-11-09  |  5.8 KB  |  195 lines

  1. Path: sparky!uunet!dtix!darwin.sura.net!spool.mu.edu!umn.edu!csus.edu!ucdavis!taquito.engr.ucdavis.edu!cklarson
  2. From: cklarson@taquito.engr.ucdavis.edu (Christopher Klaus Larson)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: INIT's/System Extension Questions
  5. Keywords: INIT extensions
  6. Message-ID: <19028@ucdavis.ucdavis.edu>
  7. Date: 9 Nov 92 01:08:45 GMT
  8. References: <1992Nov5.184623.15326@asuvax.eas.asu.edu>
  9. Sender: usenet@ucdavis.ucdavis.edu
  10. Organization: College of Engineering - University of California - Davis
  11. Lines: 182
  12.  
  13. In article <1992Nov5.184623.15326@asuvax.eas.asu.edu> system@asuvax.eas.asu.edu (Marc Lesure) writes:
  14.  
  15. >Also, are there any snippets showing the best way to show an INIT icon
  16. >during the booting sequence?
  17.  
  18. I'm not sure if this is the _best_ way to show an icon during startup, but
  19. it has always worked for me. :-)
  20.  
  21. Feel free to use this as you see fit. Optimizations and bug fixes welcome.
  22.  
  23. It is written in THINK C and requires the inclusion of the MacTraps library.
  24. Hopefully the comments within the code are a sufficient explination of how
  25. it works.
  26.  
  27. I have seen other examples that perform this operation but they were
  28. written in assembly.
  29.  
  30. Sorry about the lines longer than 80 characters.
  31.  
  32. -- Chris
  33. cklarson@engr.ucdavis.edu
  34.  
  35. Code Follows ...
  36. ----------------------
  37.  
  38. /******************************************************************************
  39.  
  40.     Draw_Init_Icon.c    1992 - Chris Larson
  41.  
  42.     This function will draw an Init's icon on the screen during startup.
  43.     
  44.     Include the line,
  45.     
  46.         extern void Draw_Init_Icon (short icon_id);
  47.         
  48.     in your INIT source with your function prototypes and pass in the
  49.     resource ID of the icon you wish to be drawn. If color QD exists, the
  50.     function will attempt to draw a 'cicn' resource. If there is no color QD,
  51.     it will draw an 'icn#'. If an error occurs, SysBeep is called and nothing
  52.     is drawn.
  53.     
  54. ******************************************************************************/
  55.  
  56. #include <Quickdraw.h>
  57. #include <Types.h>
  58. #include <OSUtils.h>
  59. #include <Resources.h>
  60. #include <Memory.h>
  61. #include <LoMem.h>
  62.  
  63. #define DI_INITIAL_OFFSET       8
  64. #define DI_BOTTOM_OFFSET        8
  65. #define DI_ICON_HEIGHT          32
  66. #define DI_ICON_WIDTH           32
  67. #define DI_ICON_OFFSET          8
  68. #define DI_NO_COLOR_QD          0x4000
  69. #define DI_BEEP_LENGTH          30
  70. #define DI_ICNPOUND_ROWBYTES    4
  71. #define DI_INCPOUND_MASK_OFFSET 128
  72. #define DI_CHECKSUM_CONSTANT    0x1021
  73. #define DI_PVT_GBL_SIZE         76
  74.  
  75. #define LEFT_OFFSET_POINTER ((short *)0x092C) /* Last 4 bytes of CurAppName */
  76. #define CHECKSUM_POINTER    ((short *)0x092E) /* hold position & checksum   */
  77.  
  78. typedef struct
  79.     {
  80.     Byte        QD_Private_Global_Space[DI_PVT_GBL_SIZE];
  81.     long        randseed;
  82.     BitMap      screenBits;
  83.     Cursor      arrow;
  84.     Pattern     dkGray;
  85.     Pattern     ltGray;
  86.     Pattern     gray;
  87.     Pattern     black;
  88.     Pattern     white;
  89.     GrafPtr     thePort;
  90.     } QD_Variables;
  91.  
  92. void Draw_Init_Icon (short icon_id);
  93.  
  94. void Draw_Init_Icon (short icon_id)
  95. {
  96.     CIconHandle     icon_handle = NULL;
  97.     Rect            destination_rect;
  98.     Rect            source_rect;
  99.     BitMap          icon_bitmap;
  100.     BitMap          mask_bitmap;
  101.     GrafPort        local_port;
  102.     QD_Variables    my_vars;
  103.     long            our_a5;
  104.     long            old_a5;
  105.     
  106.     /* Prepare A5 for InitGraf call */
  107.     
  108.     asm 68000
  109.         {
  110.         move.l  a5,old_a5
  111.         lea     our_a5,a5
  112.         move.l  a5,CurrentA5
  113.         }
  114.     
  115.     /* InitGraf and open our GrafPort */
  116.     
  117.     InitGraf (&(my_vars.thePort));
  118.     OpenPort (&local_port);
  119.     
  120.     /* Determine if position is valid. If not, set to initial value.
  121.        If so, do nothing. */
  122.     
  123.     if ((((*LEFT_OFFSET_POINTER)<<1)^DI_CHECKSUM_CONSTANT) != (*CHECKSUM_POINTER))
  124.         *LEFT_OFFSET_POINTER = DI_INITIAL_OFFSET;
  125.     
  126.     /* Compute destination Rect. */
  127.     
  128.     destination_rect.bottom = local_port.portRect.bottom - DI_BOTTOM_OFFSET;
  129.     destination_rect.left = local_port.portRect.left + *LEFT_OFFSET_POINTER;
  130.     destination_rect.top = destination_rect.bottom - DI_ICON_HEIGHT;
  131.     destination_rect.right = destination_rect.left + DI_ICON_WIDTH;
  132.     
  133.     /* If color QD exists, use 'cicn'. If not, use 'ICN#'.
  134.        SysBeep and return if resource unavailable. */
  135.     
  136.     if (!(ROM85&DI_NO_COLOR_QD))
  137.         {
  138.         icon_handle = GetCIcon (icon_id);
  139.         if (!icon_handle)
  140.             {
  141.             SysBeep (DI_BEEP_LENGTH);
  142.             return;
  143.             }
  144.         PlotCIcon (&destination_rect,icon_handle);
  145.         DisposCIcon (icon_handle);
  146.         }
  147.     else
  148.         {
  149.         icon_handle = (CIconHandle)GetResource ('ICN#',icon_id);
  150.         if (!icon_handle)
  151.             {
  152.             SysBeep(DI_BEEP_LENGTH);
  153.             return;
  154.             }
  155.         
  156.         HLock (icon_handle);
  157.         
  158.         /* Set source Rect and intialize source BitMaps. */
  159.         
  160.         SetRect (&source_rect,0,0,DI_ICON_HEIGHT,DI_ICON_WIDTH);
  161.         
  162.         icon_bitmap.bounds  = mask_bitmap.bounds = source_rect;
  163.         icon_bitmap.rowBytes = mask_bitmap.rowBytes = DI_ICNPOUND_ROWBYTES;
  164.         icon_bitmap.baseAddr = (Ptr)(*icon_handle);
  165.         mask_bitmap.baseAddr = (Ptr)(((Byte *)(*icon_handle))+DI_INCPOUND_MASK_OFFSET);
  166.         
  167.         /* Draw the 'ICN#' using its mask. */
  168.         
  169.         CopyMask (&icon_bitmap,&mask_bitmap,&(local_port.portBits),&source_rect,&source_rect,&destination_rect);
  170.         
  171.         HUnlock (icon_handle);
  172.         ReleaseResource (icon_handle);
  173.         }
  174.     
  175.     ClosePort (&local_port);
  176.     
  177.     /* Update drawing position and checksum. */
  178.     
  179.     *LEFT_OFFSET_POINTER += DI_ICON_WIDTH+DI_ICON_OFFSET;
  180.     
  181.     *CHECKSUM_POINTER = ((*LEFT_OFFSET_POINTER)<<1)^DI_CHECKSUM_CONSTANT;
  182.     
  183.     /* Reset A5 */
  184.     
  185.     asm 68000
  186.         {
  187.         movea.l old_a5,a5
  188.         move.l  a5,CurrentA5
  189.         }
  190.     
  191.     /* We're outa here. */
  192.     
  193.     return;
  194. }
  195.