home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / DX Clock 1.31 / DX Clockƒ / ShowINIT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-01  |  8.3 KB  |  258 lines  |  [TEXT/KAHL]

  1. #include    "Picker.h"
  2.  
  3. pascal void ShowINIT(short iconID , short moveX) ;
  4.  
  5. pascal void ShowINIT(short iconID , short moveX) {
  6. asm {
  7.  
  8. #define    True            1
  9. #define    False            0
  10.  
  11. #define    Debug            True
  12.  
  13. #define    myH                CurApName+32-4        /* a GREAT place to store 4 bytes (it was Darin's idea) */
  14. #define    myCheck            myH+2            ; a simple checksum of myH to determine first-timeness
  15. #define    firstX            8            ; X coordinate of first icon to be drawn
  16. #define    bottomEdge        8+32            ; this far from bottom of screen
  17. #define    iconWidth        32            ; size of icon (square normally)
  18. #define    defaultMoveX    40            ; default amount to move icons
  19. #define    checksumConst    0x1021            ; constant used for computing checksum
  20. #define    minColorDepth    4            ; minimum bits/pixel for drawing color icons
  21.  
  22. #define    maskOffset        128            ; offset to mask in ICN#
  23. #define    iconRowBytes    32/8            ; 32/8 bits
  24.  
  25. #define    hasCQDBit        6            ; this bit in ROM85 is cleared if Color QuickDraw is available
  26.  
  27. #define    iconID            6+4            ; positive stackframe objects
  28. #define    moveX            4+4
  29. #define    showINITArgs    4
  30. #define    iconPtrHdl        6+4
  31. #define    initDrawArgs    6
  32.  
  33. #define    saveA5            -4
  34. #define    localA5            -8
  35. #define    thePort            localA5-4            ; my own QuickDraw (required!)
  36. #define    gravVars        thePort-206+4
  37. #define    destRect        gravVars-sizeof(Rect)
  38. #define    myBitMap        destRect-sizeof(BitMap)
  39. #define    myPort            myBitMap-sizeof(GrafPort)
  40. #define    varsSize        myPort
  41.  
  42.  
  43. ;------------------------------------------------------------------------------------------------
  44. ;                                
  45. ;    Displays the ICN# (cicn when in 4 bit mode or higher) specified by iconID and
  46. ;     move the pen horizontally by moveX.
  47. ;    Pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s
  48. ;
  49. ;    PROCEDURE ShowINIT(iconID: Integer; moveX: Integer); EXTERNAL
  50. ;
  51. ;    pascal void ShowINIT(iconID, moveX)
  52. ;        short iconID, moveX;
  53. ;        extern;
  54. ;
  55. ;------------------------------------------------------------------------------------------------
  56. ShowINIT:
  57.  
  58. ;        link    a6,#0                    ; create stack frame
  59.         movem.l    d3-d7/a2-a4,-(sp)        ; save standard registers
  60.  
  61.         btst.b    #hasCQDBit,ROM85        ; try to get a color icon if CQD exists
  62.         beq.s    @ShowINITCQD            ; I could use SysEnvirons but I don't want to
  63. @ShowINIT1Bit
  64.         clr.l    -(sp)                    ; try to get the icon resource
  65.         move.l    #'ICN#',-(sp)
  66.         move.w    iconID(a6),-(sp)
  67.         _GetResource
  68.         move.l    (sp)+,d0
  69.         beq.s    @ShowINITError            ; can't get it, give up
  70.  
  71.         move.l    d0,-(sp)                ; leave handle on the stack for ReleaseResource
  72.         move.l    d0,a0
  73.         move.l    (a0),a0                    ; dereference
  74.         move.l    a0,-(sp)                ; icon pointer
  75.         move.w    moveX(a6),-(sp)            ; moveX
  76.         bsr        @INITDraw1Bit            ; draw
  77.         _ReleaseResource                ; release the resource
  78.  
  79. ShowINITExit:
  80.         movem.l    (sp)+,d3-d7/a2-a4        ; restore registers
  81.         unlk    a6                        ; ditch stack frame
  82.         move.l    (sp)+,a0                ; get return address
  83.         addq.l    #showINITArgs,sp        ; ditch incoming arguments
  84.         jmp        (a0)                    ; return to caller
  85.  
  86. ShowINITError:
  87.         bra.s    @ShowINITExit
  88.  
  89.  
  90. ShowINITCQD:
  91.         move.l    MainDevice,a0            ; get handle to main device
  92.         move.l    (a0),a0                    ; dereference
  93.         move.l    OFFSET(GDevice,gdPMap)(a0),a0        ; get its pixmap handle
  94.         move.l    (a0),a0                    ; dereference it
  95.         cmp.w    #minColorDepth,OFFSET(PixMap,pixelSize)(a0)    ; is it deep enough for us to draw in color?
  96.         blt.s    @ShowINIT1Bit            ;  no
  97.  
  98.         clr.l    -(sp)                    ; can a color icon be found?
  99.         move.w    iconID(a6),-(sp)
  100.         _GetCIcon
  101.         move.l    (sp)+,d0
  102.         beq.s    @ShowINIT1Bit            ;  no, so try for regular icon
  103.  
  104.         move.l    d0,-(sp)                ; leave handle on the stack for DisposCIcon
  105.         move.l    d0,-(sp)                ; cicn handle
  106.         move.w    moveX(a6),-(sp)            ; moveX
  107.         bsr        @INITDrawCQD            ; do the actual drawing
  108.         _DisposCIcon
  109.  
  110.         bra.s    @ShowINITExit
  111.  
  112.  
  113. ShowINITCredits:
  114. ;        dc.w    'ShowINIT by Paul Mercer'
  115. ;        dc.w    'Copyright 1987-1988'
  116. ;        dc.w    'Version of 7/15/88'
  117.  
  118.  
  119. ;------------------------------------------------------------------------------------------------
  120. ;
  121. ;    Initializes the world and sets up the drawing rectangle
  122. ;
  123. ;------------------------------------------------------------------------------------------------
  124. INITInit:
  125.  
  126.         move.l    CurrentA5,saveA5(a6)        ; PM 10/6 save host A5
  127.         lea        localA5(a6),a5                ; PM7/21
  128.         move.l    a5,CurrentA5
  129.         pea        thePort(a6)                    ; PM 10/6 use a5 reference instead of a6
  130.         _InitGraf                            ; fixes color bug as per DA@ICOM
  131.         pea        myPort(a6)
  132.         _OpenPort
  133.  
  134.         move.w    myH,d0                        ; get my h var
  135.         rol.w    #1,d0                        ; compare against checksum
  136.         eor.w    #checksumConst,d0
  137.         cmp.w    myCheck,d0
  138.         beq.s    @ScratchOK                    ; checks, so go on
  139.         move    #firstX,myH                    ; else initialize as first time
  140. ScratchOK:
  141.         lea        myPort(a6),a0                ; compute the destination rectangle
  142.         move.w    OFFSET(GrafPort,portBits)+OFFSET(BitMap,bounds)+OFFSET(Rect,bottom)(a0),d0
  143.         sub.w    #bottomEdge,d0
  144.         swap    d0
  145.         move.w    myH,d0
  146.  
  147.         move.l    d0,destRect(a6)
  148.         move.l    d0,destRect+OFFSET(Rect,bottom)(a6)
  149.         add.w    #iconWidth,destRect+OFFSET(Rect,right)(a6)
  150.         add.w    #iconWidth,destRect+OFFSET(Rect,bottom)(a6)
  151.  
  152.         rts
  153.  
  154.  
  155. ;------------------------------------------------------------------------------------------------
  156. ;
  157. ;    Cleans up the work done by INITInit and advances the icon drawing position
  158. ;
  159. ;------------------------------------------------------------------------------------------------
  160. INITCleanup:
  161.  
  162.         move.w    myH,d0                    ; get current position
  163.         move.w    moveX(a6),d1            ; get delta x
  164.         bpl.s    @NotDefault                ; not default (-1)
  165.         move.w    #defaultMoveX,d1        ; default
  166. NotDefault:
  167.         add.w    d1,d0                    ; increment icon position
  168.         move.w    d0,myH                    ;  and save in ‘global’
  169.         rol.w    #1,d0                    ; recompute checksum
  170.         eor.w    #checksumConst,d0
  171.         move.w    d0,myCheck                ;  and save it
  172. Exit:
  173.         pea    myPort(a6)
  174.         _ClosePort
  175.         ; *** (DBA) I think that QuickDraw leaves handles around.
  176.         ; *** (DBA) Too bad we can't get rid of them...
  177.         move.l    saveA5(a6),a5        ; PM 10/6 restore host A5
  178.         move.l    a5,CurrentA5
  179.         rts
  180.  
  181. ;------------------------------------------------------------------------------------------------
  182. ;                                
  183. ;    display the ICN# pointed to by iconPtr and move the pen horizontally by moveX
  184. ;     pass a -1 in moveX to move the standard amount, moveX should be 40 for most ICN#'s
  185. ;
  186. ;    PROCEDURE INITDraw1Bit(iconPtr: ICONListPtr; moveX: Integer); EXTERNAL
  187. ;
  188. ;    pascal void INITDraw1Bit(iconPtr, moveX)
  189. ;        ICONList *iconPtr;
  190. ;        short moveX;
  191. ;        extern;
  192. ;
  193. ;------------------------------------------------------------------------------------------------
  194. INITDraw1Bit:
  195.  
  196.         link    a6,#varsSize                ; create stack frame
  197.         movem.l    d3-d7/a2-a4,-(sp)            ; save standard registers
  198.         bsr        @INITInit                    ; initialize for drawing
  199.  
  200.         move.l    iconPtrHdl(a6),a3            ; get ICN# pointer
  201.         lea        myBitMap(a6),a4                ; point to bitmap structure
  202.         move.l    a3,OFFSET(BitMap,baseAddr)(a4)        ; fill it out
  203.         add.l    #maskOffset,OFFSET(BitMap,baseAddr)(a4) ; skip to mask
  204.         move    #iconRowBytes,OFFSET(BitMap,rowBytes)(a4)
  205.         move.l    #0,OFFSET(BitMap,bounds)(a4)        ; 0,0 topleft
  206.         move.w    #iconWidth,OFFSET(BitMap,bounds)+OFFSET(Rect,bottom)(a4) ; 32,32 botright
  207.         move.w    #iconWidth,OFFSET(BitMap,bounds)+OFFSET(Rect,right)(a4)
  208.  
  209.         move.l    a4,-(sp)                    ; punch hole with mask
  210.         lea        myPort(a6),a2                ; get the desk port
  211.         pea        OFFSET(GrafPort,portBits)(a2)        ;  for its portbits
  212.         pea        @srcRect
  213.         pea        destRect(a6)
  214.         move    #srcBic,-(sp)                ; punch a hole
  215.         clr.l    -(sp)                        ; no clip region
  216.         _CopyBits
  217.  
  218.         sub.l    #128,OFFSET(BitMap,baseAddr)(a4)
  219.         move.l    a4,-(sp)                    ; now draw (or) icon
  220.         pea        OFFSET(GrafPort,portBits)(a2)
  221.         pea        @srcRect
  222.         pea        destRect(a6)
  223.         move    #srcOr,-(sp)
  224.         clr.l    -(sp)
  225.         _CopyBits
  226.  
  227.         bsr        @INITCleanup                ; cleanup, advance icon location
  228.         movem.l    (sp)+,d3-d7/a2-a4            ; restore registers
  229.         unlk    a6                            ; ditch stack frame
  230.         move.l    (sp)+,a0                    ; get return address
  231.         addq.l    #initDrawArgs,sp            ; ditch incoming
  232.         jmp        (a0)                        ; back to caller
  233.  
  234. srcRect:    dc.w    0,0,32,32                ; for copybits
  235.  
  236.  
  237. ;------------------------------------------------------------------------------------------------
  238. ;    same as above except with color icon handle
  239. ;------------------------------------------------------------------------------------------------
  240. INITDrawCQD:
  241.  
  242.         link    a6,#varsSize                ; create stack frame
  243.         movem.l    d3-d7/a2-a4,-(sp)            ; save standard registers
  244.         bsr        @INITInit                    ; initialize for drawing
  245.  
  246.         pea        destRect(a6)                ; destination rect
  247.         move.l    iconPtrHdl(a6),-(sp)        ; cicn handle
  248.         _PlotCIcon                            ; draw it
  249.  
  250.         bsr        @INITCleanup                ; cleanup, advance icon location
  251.         movem.l    (sp)+,d3-d7/a2-a4            ; restore registers
  252.         unlk    a6                            ; ditch stack frame
  253.         move.l    (sp)+,a0                    ; get return address
  254.         addq.l    #initDrawArgs,sp            ; ditch incoming
  255.         jmp        (a0)                        ; back to caller
  256.  
  257.     }
  258. }