home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / DTS.Samples / SC03AnimDemo / AnimDemo.asm next >
Encoding:
Assembly Source File  |  1990-05-19  |  39.7 KB  |  1,070 lines  |  [04] ASCII Text (0x0000)

  1. *******************************************************************************
  2. * AnimDemo
  3. *
  4. * (C)  Copyright Apple Computer, Inc. 1988-1990
  5. * All rights reserved.
  6. *
  7. * Version 3.0   Jim Mensch
  8. *
  9. * This program is designed to show 3 different styles of animation techniques
  10. * that can be used on the Apple IIgs.
  11. *
  12. * NOTE: This program shows simple animation techniques that can be used as 
  13. * templates for your own applications.  Every attempt has been made to insure 
  14. * maximum understandability of the source code. Speed has been sacrificed for
  15. * clarity in a few of the examples.  Two techniques that are not used here but
  16. * are worth mentioning are Using the vertical count register to know when to
  17. * start drawing (discussed in Apple IIgs tech note #39) and Shielding the
  18. * cursor when using the event manager (discussed in Apple IIgs Tech Note #34).
  19. *
  20. *******************************************************************************
  21. **********************************************************************
  22. *                                                                    *
  23. *             Apple IIGS Source Code Sampler, Volume I               *
  24. *                                                                    *
  25. *           Copyright (c) Apple Computer, Inc. 1988-1990             *
  26. *                       All Rights Reserved                          *
  27. *                                                                    *
  28. *            Written by Apple II Developer Tech Support              *
  29. *                                                                    *
  30. *                                                                    *
  31. *                                                                    *
  32. *  ----------------------------------------------------------------  *
  33. *                                                                    *
  34. *     This program and its derivatives are licensed only for         *
  35. *     use on Apple computers.                                        *
  36. *                                                                    *
  37. *     Works based on this program must contain and                   *
  38. *     conspicuously display this notice.                             *
  39. *                                                                    *
  40. *     This software is provided for your evaluation and to           *
  41. *     assist you in developing software for the Apple IIGS           *
  42. *     computer.                                                      *
  43. *                                                                    *
  44. *     DISCLAIMER OF WARRANTY                                         *
  45. *                                                                    *
  46. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  47. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  48. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  49. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  50. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  51. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  52. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  53. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  54. *     REPAIR OR CORRECTION.                                          *
  55. *                                                                    *
  56. *     Apple does not warrant that the functions                      *
  57. *     contained in the Software will meet your requirements          *
  58. *     or that the operation of the Software will be                  *
  59. *     uninterrupted or error free or that defects in the             *
  60. *     Software will be corrected.                                    *
  61. *                                                                    *
  62. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  63. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  64. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  65. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  66. *     WHICH VARY FROM STATE TO STATE.                                *
  67. *                                                                    *
  68. *                                                                    *
  69. **********************************************************************
  70.                     eject
  71.  
  72.                     case on
  73.  
  74.                     copy  2/ainclude/E16.memory
  75.                     mcopy macros/animdemo.macros
  76.                     
  77. DPHandle            gequ 0
  78. DPPointer           gequ DPHandle+4
  79. Counter             gequ DPPointer+4
  80. LastTick            gequ Counter+2
  81. temp1               gequ LastTick+2
  82. temp2               gequ temp1+2
  83. LinePt              gequ temp2+2
  84. ScreenTab           gequ LinePt+4
  85. MyBitMap            gequ ScreenTab+4
  86. MyBitMask           gequ MyBitMap+4
  87. CurX                gequ MyBitMask+4
  88. CurY                gequ CurX+2
  89. DDPoint1            gequ CurY+2
  90. DDPoint2            gequ DDPoint1+4
  91. DDPoint3            gequ DDPoint2+4
  92. DDTemp              gequ DDPoint3+4
  93. DDXInc              gequ DDTemp+4
  94. DDYInc              gequ DDXInc+2
  95.  
  96. ScreenMode          gequ 0
  97. ScreenWidth         gequ 320
  98.  
  99.                     EJECT
  100. *******************************************************************************
  101. *
  102. AnimDemo            start
  103. *
  104. * Description:      This is the main loop of the animation demo
  105. *
  106. *
  107. * Inputs:           None
  108. *
  109. * Outputs:          None
  110. *
  111. * External Refs:
  112. *                   Import InitTools
  113. *                   Import InitApp
  114. *                   Import MainLoop
  115. *                   Import CloseApp
  116. *                   Import CloseTools
  117. *                   Import QuitParms
  118. *
  119. * Entry Points:
  120. *
  121. *******************************************************************************
  122.  
  123.                     jsr InitTools
  124.                     jsr InitApp
  125.                     jsr MainLoop
  126.                     jsr CloseApp
  127.                     jsr CloseTools
  128.  
  129.                     _Quit QuitParms
  130.  
  131.                     end
  132.  
  133.  
  134.                     EJECT
  135. *******************************************************************************
  136. *
  137. Globals             data
  138. *
  139. * Description:      Data used throughout the program
  140. *
  141. *
  142. * Inputs:           None
  143. *
  144. * Outputs:          None
  145. *
  146. * External Refs:    None
  147. *
  148. * Entry Points:
  149. *                   Export QuitParms
  150. *
  151. *******************************************************************************
  152. MyID                ds 2                ; application ID
  153. QuitParms           dc i4'0'            ; standard parms to make the quit call
  154.                     dc i2'$00'          ; return to the launching application
  155.                     dc i2'0'
  156.  
  157. DTSString           dc c'Apple IIgs Power to Animate'
  158.                     dc i1'0'
  159. AutString           dc c'By Jim Mensch Apple DTS'
  160.                     dc i1'0'
  161.  
  162. Trigger             dc i2'0'
  163.  
  164. EventRecord         ANOP
  165. EventWhat           ds 2
  166. EventMessage        ds 4
  167. EventWhen           ds 4
  168. EventWhere          ds 4
  169. EventModifiers      ds 2
  170.  
  171. Rect                ds 8
  172.  
  173. BitMap              dc i2'$7700,$7777,$0077' ; Bit maps of our animated character
  174.                     dc i2'$6607,$7667,$7066'
  175.                     dc i2'$6676,$7667,$6766'
  176.                     dc i2'$6776,$7777,$6776'
  177.                     dc i2'$6776,$0000,$6776'
  178.                     dc i2'$7777,$0000,$7777'
  179.                     dc i2'$7777,$0000,$7777'
  180.                     dc i2'$6776,$0000,$6776'
  181.                     dc i2'$6776,$7777,$6776'
  182.                     dc i2'$6676,$7667,$6766'
  183.                     dc i2'$6607,$7667,$7066'
  184.                     dc i2'$7700,$7777,$0077'
  185.  
  186. BitMask             dc i2'$FF00,$FFFF,$00FF' ; Mask of our animated character
  187.                     dc i2'$FF0F,$FFFF,$F0FF' ; to be used for seethru drawing
  188.                     dc i2'$FFFF,$FFFF,$FFFF'
  189.                     dc i2'$FFFF,$FFFF,$FFFF'
  190.                     dc i2'$FFFF,$0000,$FFFF'
  191.                     dc i2'$FFFF,$0000,$FFFF'
  192.                     dc i2'$FFFF,$0000,$FFFF'
  193.                     dc i2'$FFFF,$0000,$FFFF'
  194.                     dc i2'$FFFF,$FFFF,$FFFF'
  195.                     dc i2'$FFFF,$FFFF,$FFFF'
  196.                     dc i2'$FF0F,$FFFF,$F0FF'
  197.                     dc i2'$FF00,$FFFF,$00FF'
  198.  
  199. MyDP                ds 2                ; My zero page storage
  200.  
  201.  
  202.                     end
  203.                     
  204.                     EJECT
  205. *******************************************************************************
  206. *
  207. InitTools           start
  208. *
  209. * Description:      Routine that loads and starts up all the tools that we will
  210. *                   be using in this program
  211. *
  212. *
  213. * Inputs:           None
  214. *
  215. * Outputs:          None
  216. *
  217. * External Refs:    
  218. *                   Import FatalError
  219. *
  220. * Entry Points:     None
  221. *
  222. *******************************************************************************
  223.                     using Globals
  224. ;
  225. ;   Tool Direct page offsets here
  226. ;
  227. QDDPage             equ $0000
  228. EMDPage             equ QDDPage+$0300
  229. SEQDPage            equ EMDPage+$0100
  230. ToolDPSize          equ SEQDPage+$0200
  231.  
  232.                     phk                 ; Save program bank register and
  233.                     plb                 ; load it as the data bank register
  234.  
  235.                     tdc
  236.                     sta MyDP            ; Save direct register
  237.  
  238.                     _TLStartup          ; Start Tool Locator
  239.  
  240.                     PushWord            ; Space for result
  241.                     _MMStartup          ; Start memory manager
  242.                     PullWord MyID       ; Save it for later use
  243.  
  244.                     _MTStartup          ; Start up Misc Tools
  245.  
  246.                     _IMStartup          ; Start integer math toolset
  247.  
  248. ;                   PushLong #ToolTable ; Pointer to Tool table
  249. ;                   _LoadTools          ; Load all RAM based tools
  250. ;                   bcc IT0005          ; Carry clear means no error
  251. ;                   brl FatalError      ; Tools can't be loaded. Fatal error!
  252.  
  253. IT0005              ANOP
  254.  
  255. ; Get memory for Tool Direct pages
  256.  
  257.                     PushLong #0         ; Room for result
  258.                     PushLong #ToolDPSize ; Number of bytes needed
  259.                     PushWord MyID       ; ID of this application
  260.                     PushWord #attrLocked+attrFixed+attrPage+attrBank
  261.                     PushLong #0         ; Allocate them in bank 0
  262.                     _NewHandle
  263.                     bcc IT0010          ; Test carry for error
  264.                     brl FatalError      ; If no memory we got a fatal error!
  265.  
  266. IT0010              PullLong DPHandle   ; Retrieve handle to our DPage area
  267.  
  268.                     lda [DPHandle]      ; Dereference the handle to get a ptr
  269.                     sta DPPointer       ; to our direct page area and save it.
  270.  
  271.                     PushWord DPPointer  ; QuickDraw uses 3 pages of Dpage
  272.                     PushWord #ScreenMode ; Used to set all master SCB's
  273.                     PushWord #0         ; Zero means use default buf size
  274.                     PushWord MyID       ; Application ID for allocating data
  275.                     _QDStartup          ; Start QuickDraw, turn on SHR Screen
  276.                     bcc IT0015
  277.                     brl FatalError      ; If it can't be started then bomb
  278.  
  279. IT0015              ANOP
  280.                     lda DPPointer       ; Create address for Event Mgr DPage by
  281.                     clc                 ; loading in the pointer to the start
  282.                     adc #EMDPage        ; of DPage and adding Evt Mgr offset.
  283.                     pha                 ; Now push it on the stack.
  284.                     PushWord #20        ; Size of event queue.
  285.                     PushWord #0         ; MouseClamp values.
  286.                     PushWord #ScreenWidth ; These will clamp mouse to screen
  287.                     PushWord #0         ; area only.
  288.                     PushWord #200
  289.                     PushWord MyID
  290.                     _EMStartup          ; Start the event manager
  291.                     bcc IT0020
  292.                     brl FatalError      ; Event manager is also a must
  293. IT0020              ANOP
  294.  
  295.                     RTS
  296. ToolTable           dc i2'2'
  297.                     dc i2'25,$0100'     ; note synth
  298.                     dc i2'26,$0100'     ; note sequencer
  299.  
  300.                     end
  301.                     
  302.                     
  303.                     EJECT
  304. *******************************************************************************
  305. *
  306. FatalError          start
  307. *
  308. * Description:      Routine that is called whenever a tool sends back an error
  309. *                   that can not be recovered from. This routine prints the
  310. *                   error on the screen, waits for a keypress then quits back
  311. *                   to whoever started this application up!
  312. *
  313. *
  314. * Inputs:           A = Error number
  315. *
  316. * Outputs:          NONE (program exits)
  317. *
  318. * External Refs:
  319. *                   Import CloseTools
  320. *
  321. * Entry Points:     NONE
  322. *
  323. *******************************************************************************
  324.                     using Globals
  325.  
  326.                     pha                 ; Push the error code
  327.                     PushLong #ErrNumStr ; Address of storage area
  328.                     PushWord #4         ; Length of string
  329.                     _Int2Hex
  330.  
  331.                     _GrafOff            ; If QD Started, shut off graphics
  332.  
  333.                     PushLong #ErrStr    ; Write error message to the screen
  334.                     _WriteCString
  335.  
  336.                     pha                 ; Space for result
  337.                     PushWord #0         ; No echo
  338.                     _ReadChar           ; Wait for a key to be pressed
  339.                     pla                 ; Discard the key
  340.  
  341.                     jsr CloseTools      ; Shut down all the tools in case
  342. ;                                         any got started up
  343.  
  344.                     _Quit QuitParms     ; Quit back to where we came from.
  345.  
  346.                     brk $FF             ; If the quit fails then just break
  347.                     
  348. ErrStr              dc c'A fatal error has occured $'
  349. ErrNumStr           dc c'xxxx   press any key to exit'
  350.                     dc i1'0'
  351.  
  352.                     end
  353.  
  354.                     EJECT
  355. *******************************************************************************
  356. *
  357. CloseTools          start
  358. *
  359. * Description:      Closes all the tools that were started when the application
  360. *                   called InitTools.
  361. *
  362. *
  363. * Inputs:           None
  364. *
  365. * Outputs:          None
  366. *
  367. * External Refs:    None
  368. *
  369. * Entry Points:     None
  370. *
  371. *******************************************************************************
  372.                     using Globals
  373.  
  374.                     _GrafOff
  375.                     _EMShutDown
  376.                     _QDShutDown
  377.                     _MTShutDown
  378.  
  379.                     PushLong DPHandle   ; Dispose of all the DP memory
  380.                     _DisposeHandle
  381.  
  382.                     PushWord MyID
  383.                     _MMShutDown
  384.                     _TLShutDown
  385.                     rts
  386.                     end
  387.  
  388.  
  389.                     EJECT
  390. *******************************************************************************
  391. *
  392. InitApp             start
  393. *
  394. * Description:      This procedure will draw the initial screen display and
  395. *                   install all the heartbeat tasks for the various animation
  396. *                   routines.
  397. *
  398. *
  399. * Inputs:           None
  400. *
  401. * Outputs:          None
  402. *
  403. * External Refs:    None
  404. *                   Import ScrollTask
  405. *                   Import LightTask
  406. *                   Import TrigrTask
  407. *
  408. * Entry Points:     None
  409. *
  410. *******************************************************************************
  411.                     using Globals
  412.  
  413.                     Stz LinePt          ; use line pt as temp flag!
  414.  
  415.                     PushWord #5         ; Erase Screen to DkGreen
  416.                     _SetSolidPenPat
  417.  
  418.                     PushLong #ScrnRect
  419.                     _PaintRect
  420.  
  421.                     PushWord #0
  422.                     _SetSolidPenPat
  423.  
  424.                     PushLong #Marq1Rect ; Erase the Marquee area to black
  425.                     _PaintRect
  426.  
  427.                     PushLong #CoinRect  ; Erase the coin area to black
  428.                     _PaintRect
  429.  
  430.                     Inc CoinRect        ; InsetRect(CoinRect,-1,-1)
  431.                     inc CoinRect+2
  432.                     dec CoinRect+4
  433.                     dec CoinRect+6
  434.  
  435.                     PushWord #4         ; give the coin rectangle a green boarded
  436.                     _SetSolidPenPat
  437.  
  438.                     PushLong #Rect
  439.                     _FrameRect
  440.  
  441.  
  442.                     lda #20             ; set up a rectangle for the first
  443.                     sta Rect            ; Marquee light in the top row 
  444.                     sta Rect+2          ; 
  445.                     lda #30
  446.                     sta Rect+4
  447.                     sta Rect+6
  448.  
  449.                     PushWord #9         ; draw then in Yellow
  450.                     _SetSolidPenPat
  451.                     
  452.                     jsr DrawLightsH     ; and draw a row of horizontal lights
  453.  
  454.                     lda #30
  455.                     sta Rect+2          ; update the left and right values of
  456.                     lda #40             ; the rectangle to start 10 pixels over
  457.                     sta Rect+6          
  458.                     
  459.                     PushWord #1         ; set the color to dark gray
  460.                     _SetSolidPenPat     
  461.                     
  462.                     jsr DrawLightsH     ; and draw a row of gray lights next to the yellow ones
  463.                     
  464.                     lda #100            ; Now create the rectangle for the bottom row of 
  465.                     sta Rect            ; lights
  466.                     lda #30
  467.                     sta Rect+2
  468.                     lda #110
  469.                     sta Rect+4
  470.                     lda #40
  471.                     sta Rect+6
  472.  
  473.                     jsr DrawLightsH     ; and draw this row in Dk Gray
  474.  
  475.                     lda #20             ; now reset to draw the yellow lights in this row
  476.                     sta Rect+2
  477.                     lda #30
  478.                     sta Rect+6
  479.                     
  480.                     PushWord #9
  481.                     _SetSolidPenPat
  482.  
  483.                     jsr DrawLightsH
  484.  
  485. ; Now draw the vertical lights
  486.                     lda #20             ; set up a rectangle for the first
  487.                     sta Rect            ; Marquee light in the left column 
  488.                     sta Rect+2          ; 
  489.                     lda #30
  490.                     sta Rect+4
  491.                     sta Rect+6
  492.  
  493.                     PushWord #9         ; draw then in Yellow
  494.                     _SetSolidPenPat
  495.                     
  496.                     jsr DrawLightsV     ; and draw a Col of vert lights
  497.  
  498.  
  499.                     lda #30
  500.                     sta Rect            ; update the top and bottom values of
  501.                     lda #40             ; the rectangle to start 10 pixels over
  502.                     sta Rect+4          
  503.                     
  504.                     PushWord #1         ; set the color to dark gray
  505.                     _SetSolidPenPat     
  506.                     
  507.                     jsr DrawLightsV     ; and draw a row of gray lights under the yellow 
  508.  
  509.                     lda #30             ; Now create the rectangle for the bottom row of 
  510.                     sta Rect            ; lights
  511.                     lda #290
  512.                     sta Rect+2
  513.                     lda #40
  514.                     sta Rect+4
  515.                     lda #300
  516.                     sta Rect+6
  517.  
  518.                     jsr DrawLightsV     ; and draw this row in Dk Gray
  519.  
  520.                     lda #20             ; now reset to draw the yellow lights in this row
  521.                     sta Rect
  522.                     lda #30
  523.                     sta Rect+4
  524.                     
  525.                     PushWord #9
  526.                     _SetSolidPenPat
  527.  
  528.                     jsr DrawLightsV
  529.  
  530.                     PushWord #15        ; Now, Erase the text area to white
  531.                     _SetSolidPenPat
  532.  
  533.                     PushLong #Marq2Rect
  534.                     _PaintRect
  535.  
  536.                     PushWord #0         ; Draw the strings in the marquee
  537.                     _SetSolidPenPat
  538.  
  539.                     PushWord #50
  540.                     PushWord #60
  541.                     _MoveTo
  542.  
  543.                     PushLong #DTSString
  544.                     _DrawCString
  545.  
  546.                     PushWord #62
  547.                     PushWord #80
  548.                     _MoveTo
  549.  
  550.                     PushLong #AutString
  551.                     _DrawCString
  552.  
  553.                     PushLong #0         ; Get the address of the screen 
  554.                     PushWord #1         ; address table for use in our
  555.                     _GetAddress         ; animation routines
  556.                     PullLong ScreenTab
  557.  
  558.                     lda #BitMap         ; Now create a pointer to our bitmap
  559.                     sta MyBitMap
  560.                     lda #BitMap|-16
  561.                     sta MyBitMap+2
  562.  
  563.                     lda #BitMask        ; Now create a pointer to our bitMask
  564.                     sta MyBitMask
  565.                     lda #BitMask|-16
  566.                     sta MyBitMask+2
  567.  
  568.                     lda #20             ; initialize the starting location
  569.                     sta CurX            ; of the coin.
  570.                     lda #141
  571.                     sta CurY
  572.  
  573.                     lda #1              ; and set the current increment
  574.                     sta DDXInc
  575.                     sta DDYInc
  576.  
  577.                     PushLong #ScrollTask ;Install the scrolling routine in
  578.                     _SetHeartBeat       ; Heart beat queue
  579.  
  580.                     PushLong #LightTask ; install the Marquee light
  581.                     _SetHeartBeat       ; heartbeat task
  582.  
  583.                     PushLong #TrigrTask ; and install our heartbeat trigger
  584.                     _SetHeartBeat
  585.  
  586.                     rts
  587.  
  588. ; The following routine, given the starting rectangle of the first light to draw
  589. ; Will draw a horizontal row of 14 lights across the screen at 20 pixel intervals
  590. DrawLightsH         ANOP
  591.                     stz Counter         ; Init the ligh counter
  592. IA001               PushLong #Rect      ; draw the first light
  593.                     _PaintOval
  594.  
  595.                     lda Rect+2          ; OffsetRect(Rect,20,0)
  596.                     clc                 ; do this by adding 20 to Rect.left
  597.                     adc #20
  598.                     sta Rect+2
  599.                     lda Rect+6          ; and rect.right
  600.                     clc
  601.                     adc #20
  602.                     sta Rect+6
  603.  
  604.                     ldy Counter         ; bump the counter
  605.                     iny
  606.                     sty Counter
  607.                     cpy #14             ; test to see if we are done
  608.                     bne IA001           ; if not, draw another light
  609.                     rts                 ; if so, then simply end
  610. ;
  611. ; This routine is the same as above only it creates vertical lights
  612. DrawLightsV         ANOP
  613.                     stz Counter
  614. IA011               PushLong #Rect      ; draw the light
  615.                     _PaintOval
  616.  
  617.                     lda Rect            ; OffsetRect(Rect,0,20)
  618.                     clc
  619.                     adc #20
  620.                     sta Rect
  621.                     
  622.                     lda Rect+4
  623.                     clc
  624.                     adc #20
  625.                     sta Rect+4
  626.                     
  627.                     ldy Counter         ; Bump the counter
  628.                     iny
  629.                     sty Counter
  630.                     cpy #4
  631.                     bne IA011           ; if not done draw another light
  632.                     rts                 ; if done, then return
  633.                     
  634. ScrnRect            dc i2'0,0,200,320'
  635. Marq1Rect           dc i2'18,18,112,302'
  636. Marq2Rect           dc i2'32,32,98,288'
  637. CoinRect            dc i2'139,38,183,292'
  638.  
  639.                     end
  640.  
  641.                     EJECT
  642. *******************************************************************************
  643. *
  644. MainLoop            start
  645. *
  646. * Description:      This routine runs in a continuous loop until the user
  647. *                   presses the mouse button. At that time, it ends. While
  648. *                   it is looping, this routine checks Trigger, if the Trigger
  649. *                   is set, it calls the walk routine to move the coin
  650. *
  651. *
  652. * Inputs:           None
  653. *
  654. * Outputs:          None
  655. *
  656. * External Refs:
  657. *
  658. * Entry Points:
  659. *                   Import DoWalk
  660. *
  661. *******************************************************************************
  662.                     using Globals
  663.  
  664.                     lda Trigger         ; test VBL Trigger value
  665.                     beq EL0010          ; if its zero then don't move the coin
  666.  
  667.                     jsr DoWalk          ; Walk a ball around a square
  668. EL0010              ANOP
  669.                     PushWord #0         ; get an event
  670.                     PushWord #$FFFF
  671.                     PushLong #EventRecord
  672.                     _GetNextEvent
  673.  
  674.                     pla
  675.                     lda EventWhat
  676.                     cmp #1              ; is it a mousedown???
  677.                     bne MainLoop        ; if not get another event
  678.                     rts                 ; if so, then just end
  679.                     end
  680.  
  681.                     EJECT
  682. *******************************************************************************
  683. *
  684. CloseApp            start
  685. *
  686. * Description:      This routine removes all our heartbeat tasks at the end
  687. *                   of the program.
  688. *
  689. *
  690. * Inputs:           None
  691. *
  692. * Outputs:          None
  693. *
  694. * External Refs:
  695. *                   Import TrigrTask
  696. *                   Import LightTask
  697. *                   Import ScrollTask
  698. *
  699. * Entry Points:
  700. *
  701. *******************************************************************************
  702.                     PushLong #TrigrTask
  703.                     _DelHeartBeat
  704.  
  705.                     PushLong #ScrollTask
  706.                     _DelHeartBeat
  707.  
  708.                     PushLong #LightTask
  709.                     _DelHeartBeat
  710.  
  711.                     rts
  712.                     end
  713.  
  714.  
  715.                     EJECT
  716. *******************************************************************************
  717. *
  718. TriggerP            start
  719. *
  720. * Description:      Trigger heartbeat task. Every 1/60 of a second this routine
  721. *                   will set a trigger value. The program can then read this 
  722. *                   value and use it to base our coin animation.
  723. *
  724. *
  725. * Inputs:           None
  726. *
  727. * Outputs:          None
  728. *
  729. * External Refs:    None
  730. *
  731. * Entry Points:     None
  732. *                   Export TrigrTask
  733. *
  734. *******************************************************************************
  735.                     using Globals
  736. TrigrTask           entry
  737.                     dc i4'0'            ; heartbeat task header
  738. TrgTaskCnt          dc i2'3'            ; Number of ticks before running
  739.                     dc i2'$A55A'        ; heartbeat task signature
  740.                     
  741.                     php                 ; save the current proc state
  742.                     REP #$30            ; set long A,I and M
  743.                     lda #1              ; set the trigger to true
  744.                     sta >Trigger        
  745.                     lda #1              ; set the task up to be fired again
  746.                     sta >TrgTaskCnt     ; in 1/60th of a second
  747.  
  748.                     plp                 ; restore the proc status
  749.                     RTL                 ; and leave this routine
  750.                     end
  751.  
  752.                     EJECT
  753. *******************************************************************************
  754. *
  755. LightAnim           start
  756. *
  757. * Description:      Marquee ligh animation. This heartbeat task will switch the
  758. *                   color table entries of color 9 and color 1 every 1/10 of
  759. *                   a second. This will give the illusion of moving lights
  760. *                   much like movie theatres used to use.
  761. *
  762. *
  763. * Inputs:           None
  764. *
  765. * Outputs:          None
  766. *
  767. * External Refs:    None
  768. *
  769. * Entry Points:     
  770. *                   Export LightTask
  771. *
  772. *******************************************************************************
  773. LightTask           entry
  774.                     dc i4'0'
  775. LghTaskCnt          dc i2'5'            ; number of ticks before running
  776.                     dc i2'$A55A'        ; heartbeat signature
  777.  
  778.                     php                 ; save the current processor state
  779.                     Rep #$30            ; and set full 16 bit mode.
  780.  
  781.                     PushWord #0         ; get the current color table entry
  782.                     PushWord #0         ; for color #9
  783.                     PushWord #9
  784.                     _GetColorEntry
  785.                     pla
  786.                     sta >tempC1         ; and save it for later use
  787.  
  788.                     PushWord #0         ; and get the color table entry for 
  789.                     PushWord #0         ; color 1
  790.                     PushWord #1
  791.                     _GetColorEntry
  792.                     pla
  793.                     sta >tempC2         ; and save it for later
  794.  
  795.                     PushWord #0         ; now set the entry for color #1
  796.                     PushWord #1         ; to be that of what #9 was
  797.                     PushWord >tempC1
  798.                     _SetColorEntry
  799.  
  800.                     PushWord #0         ; and set color #9 to what Color#1
  801.                     PushWord #9         ; was
  802.                     PushWord >tempC2
  803.                     _SetColorEntry
  804.  
  805.  
  806.                     lda #6              ; Re-arm the task to be fired again
  807.                     Sta >LghTaskCnt     ; in 1/10th of a second
  808.                     plp                 ; restore the proc status
  809.                     Rtl                 ; and leave
  810. tempC1              ds 2
  811. tempC2              ds 2
  812.                     end
  813.  
  814.                     EJECT
  815. *******************************************************************************
  816. *
  817. ScrollAnim          start
  818. *
  819. * Description:      This routine will move an area of the screen over 4 pixels
  820. *                   and wrap the stuff that falls off the edge to the end of
  821. *                   the same line (to give the image of circular scrolling).
  822. *                   This routine gets called aprox every 1/30th of a second
  823. *
  824. * Inputs:           None
  825. *
  826. * Outputs:          None
  827. *
  828. * External Refs:
  829. *
  830. * Entry Points:
  831. *                   Export ScrollTask
  832. *
  833. *******************************************************************************
  834.                     using Globals
  835. ScrollTask          entry
  836.                     dc i4'0'            ; Heartbeat task header
  837. ScrTaskCnt          dc i2'2'
  838.                     dc i2'$A55A'
  839.                     
  840.                     phd                 ; save direct register
  841.                     php                 ; and proc status
  842.  
  843.                     REP #$30            ; turn on full 16 bit mode...
  844.                     lda >MyDP           ; get my Direct page
  845.                     TCD                 ; and make it current
  846.  
  847.                     lda #46             ; starting scan line
  848.                     sta Counter
  849.                     lda #$E1
  850.                     sta LinePt+2        ; set up high byte of scrn address
  851.  
  852. SA010               lda Counter         ; get starting address of scan line
  853.                     asl A               ; multiply by 2!
  854.                     tay
  855.                     lda [ScreenTab],y   ; get next line of screen tab
  856.                     sta LinePt          ; store it in our pointer
  857.                     ldy #16             ; start out 8 bytes in...
  858.                     lda [LinePt],y      ; get first byte of area
  859.                     sta temp1           ; save it for later...
  860.  
  861.                     ldy #142            ; end of rect to scroll
  862. SA020               lda [LinePt],y      ; get byte to scroll
  863.                     tax                 ; save it in X
  864.                     lda temp1           ; get proper byte value
  865.                     sta [LinePt],y      ; now save it...
  866.                     txa                 ; get saved value
  867.                     sta temp1           ; and save it...
  868.                     dey
  869.                     dey
  870.                     cpy #14             ; did we store the last one???
  871.                     bne SA020
  872.                     inc Counter         ; go to next line
  873.                     lda Counter
  874.                     cmp #82             ; are we done yet???
  875.                     bne SA010           ; nope... not yet!
  876.  
  877.                     lda #2              ; reset the task timer to 2 60th
  878.                     sta >ScrTaskCnt     ; of a second (1/30th)
  879.  
  880.                     plp                 ; restore the previous processor flags
  881.                     pld                 ; and the direct page register
  882.  
  883.                     rtl
  884.                     end
  885.  
  886.                     EJECT
  887. *******************************************************************************
  888. *
  889. DoWalk              start
  890. *
  891. * Description:      This routine erases the coin from the screen, when the
  892. *                   coin hits an edge, this routine adjusts the increments
  893. *                   properly.
  894. *
  895. *
  896. * Inputs:           None
  897. *
  898. * Outputs:          None
  899. *
  900. * External Refs:
  901. *                   Import DoErase
  902. *                   Import DoDraw
  903. *
  904. * Entry Points:
  905. *
  906. *******************************************************************************
  907.                     using Globals
  908.  
  909.  
  910.                     stz Trigger         ; clear the trigger for next time
  911.                     jsr DoErase         ; erase the coin
  912.                     lda CurX            ; test to see if we hit the left
  913.                     cmp #20             ; edge
  914.                     blt DW005           ; if so, then change directions
  915.                     cmp #140            ; test the right edge
  916.                     blt DW010           ; if not exceeded then check top & bottom
  917. DW005               lda #0              ; this will reverse the direction of
  918.                     SEC                 ; the coins horiz movement by negating
  919.                     SBC DDXInc          ; the current x increment
  920.                     sta DDXInc
  921.  
  922. DW010               lda CurY            ; now test the top and bottom
  923.                     cmp #140            ; past the top?
  924.                     blt DW015           ; if so, change dir
  925.                     cmp #170            ; past the bottom?
  926.                     blt DW020           ; if not skip the next section
  927. DW015               lda #0              ; negate the vertical increment
  928.                     sec
  929.                     sbc DDYInc
  930.                     sta DDYInc
  931.  
  932. DW020               ANOP
  933.                     lda CurX            ; now that the increment is correct
  934.                     clc                 ; bump our location counters to
  935.                     adc DDXInc          ; the new position
  936.                     sta CurX
  937.                     lda CurY
  938.                     clc
  939.                     adc DDYInc
  940.                     sta CurY
  941.                     jsr DoDraw          ; and re-draw the coin
  942. DW030               ANOP
  943.                     rts
  944.                     end
  945.  
  946.                     EJECT
  947. *******************************************************************************
  948. *
  949. DoErase             start
  950. *
  951. * Description:      This erases the coin from its current location
  952. *
  953. *
  954. * Inputs:           None
  955. *
  956. * Outputs:          None
  957. *
  958. * External Refs:
  959. *
  960. * Entry Points:
  961. *
  962. *******************************************************************************
  963.                     using Globals
  964.  
  965. ; First calculate the starting scan line *2 and the ending scanline *2. Place
  966. ; the starting scan line into the X register and the ending in DDTemp
  967.  
  968.                     lda CurY            ; get the Y posn and multiply it by 2
  969.                     asl A               ; to get the current screen line offset 
  970.                     tax                 ; store for later use..
  971.                     clc                 ; add 24 to it (12 scan lines *2)
  972.                     adc #24             ; to make the terminating value for
  973.                     sta DDTemp          ; our loop
  974.  
  975. ; next calculates the memory location of the upper left hand corner
  976. ; of our object on the screen. This routine uses the scan line address table
  977. ; given to us by quickdraw. 
  978. DE010               txy                 ; retrieve the current scan line index
  979.                     lda CurX            ; get XCord in bytes. and Add it to
  980.                     clc                 ; the address of the current ycord scan
  981.                     adc [ScreenTab],y   ; line to create the screen address. 
  982.                     sta DDPoint1        ; Save it in Direct page so we can use
  983.                     lda #$E1            ; it as a long pointer. NOTE: The screen
  984.                     sta DDPoint1+2      ; is always in bank $E1
  985. ; Now that DDPoint1 contains the pointer we need start copying Black over the 
  986. ; screen area that the coin was in, two bytes at a time.
  987.  
  988.                     ldy #$0000          ; zero the index
  989. DE0020              lda #$0000          ; erase with black...
  990.                     sta [DDPoint1],y    ; save it to the screen
  991.                     iny                 ; bump our line counter 2
  992.                     iny
  993.                     cpy #6              ; are we done with current line???
  994.                     bne DE0020          ; if not do another word
  995.                     inx                 ; if so bump the screen line tbl offset
  996.                     inx                 ; by two
  997.                     cpx DDTemp          ; see if we finished the whole picture
  998.                     bne DE010           ; if not, draw the next line
  999.                     rts                 ; if so, then end.
  1000.                     end
  1001.  
  1002.                     EJECT
  1003. *******************************************************************************
  1004. *
  1005. DoDraw              start
  1006. *
  1007. * Description:      This draws the coin at its current location
  1008. *
  1009. *
  1010. * Inputs:           None
  1011. *
  1012. * Outputs:          None
  1013. *
  1014. * External Refs:
  1015. *
  1016. * Entry Points:
  1017. *
  1018. *******************************************************************************
  1019.                     using Globals
  1020.  
  1021. ; First calculate the starting scan line *2 and the ending scanline *2. Place
  1022. ; the starting scan line into the X register and the ending in DDTemp
  1023.  
  1024.                     lda CurY            ; get the Y posn and multiply it by 2
  1025.                     asl A               ; to get the current screen line offset 
  1026.                     tax                 ; store for later use..
  1027.                     clc                 ; add 24 to it (12 scan lines *2)
  1028.                     adc #24             ; to make the terminating value for
  1029.                     sta DDTemp          ; our loop
  1030.  
  1031.                     lda MyBitMap        ; get address for my coin data
  1032.                     sta DDPoint2        ; and store it in a direct page ptr
  1033.                     lda MyBitMap+2
  1034.                     sta DDPoint2+2
  1035.  
  1036. ; next calculates the memory location of the upper left hand corner
  1037. ; of our object on the screen. This routine uses the scan line address table
  1038. ; given to us by quickdraw. 
  1039. DD010               txy                 ; retrieve the current scan line index
  1040.                     lda CurX            ; get XCord in bytes. and Add it to
  1041.                     clc                 ; the address of the current ycord scan
  1042.                     adc [ScreenTab],y   ; line to create the screen address. 
  1043.                     sta DDPoint1        ; Save it in Direct page so we can use
  1044.                     lda #$E1            ; it as a long pointer. NOTE: The screen
  1045.                     sta DDPoint1+2      ; is always in bank $E1
  1046. ; Now that DDPoint1 contains the pointer we need start copying the coin data 
  1047. ; to the screen, two bytes at a time.
  1048.  
  1049.                     ldy #$0000          ; zero the index
  1050. DD0020              lda [DDPoint2],y    ; get the next byte of data to copy
  1051.                     sta [DDPoint1],y    ; save it to the screen
  1052.                     iny                 ; bump the byte counter by 2
  1053.                     iny
  1054.                     cpy #6              ; are we done with line???
  1055.                     bne DD0020          ; if not, do another word
  1056.  
  1057.                     lda DDPoint2        ; Now bump up pointer to
  1058.                     clc                 ; the BitMap
  1059.                     adc #6              ; by RowBytes....
  1060.                     sta DDPoint2
  1061.                     inx                 ; bump the screen line...
  1062.                     inx                 ; by two (tbl offset)
  1063.                     cpx DDTemp          ; see if we done whole picture
  1064.                     bne DD010           ; nope do next line
  1065.                     rts
  1066.                     end
  1067.  
  1068.                     END
  1069.