home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 262.lha / SpriteWizard_v1.0 / SW_AsmDemo.asm < prev    next >
Assembly Source File  |  1989-06-30  |  13KB  |  333 lines

  1. *  Assembler demo on how to use SpriteWiz created data  -  By D. Visage
  2. *
  3. *  Message Software
  4. *  James Messa and David A. Visage
  5. *  GET THE MESSAGE!
  6. *
  7. *  Note : This code will not assemble with the MetaComco assembler.
  8. *         It will only assemble with the Manx 3.4 assembler.
  9. *         You can, however, use the generated sprite data with both.
  10. *
  11. *  Note : To assemble and link (Two drives hopefully) -
  12. *
  13. *         as SW_AsmDemo.asm
  14. *         ln SW_AsmDemo.o -lc32
  15. *
  16.               include   "exec/types.i"
  17.               include   "intuition/intuition.i"
  18.               include   "graphics/sprite.i"
  19.               include   "DV.i"
  20. *
  21. *  A few standard equates
  22. *
  23. AbsExecBase   equ       $0004             ; The famous AbsExecBase
  24. *
  25. DELAY_VAL     equ       25                ; Alas, it is hard coded!
  26. MAX_WIDTH     equ       640
  27. MAX_HEIGHT    equ       200
  28. WINDOW_FLAGS  equ       WINDOWCLOSE | SMART_REFRESH | ACTIVATE
  29. *
  30. COLOR00       equ       00
  31. COLOR01       equ       01
  32. COLOR02       equ       02
  33. COLOR21       equ       21
  34. COLOR22       equ       22
  35. COLOR23       equ       23
  36. *
  37. SPRITE02      equ       02
  38. SPR_HEIGHT    equ       16
  39. SPRITE_X      equ       320
  40. SPRITE_Y      equ       100
  41. *
  42. *  Macros for declaring and calling Amiga routines
  43. *
  44. XLIB          macro
  45.               public    _LVO\1
  46.               endm
  47. *
  48. EXECALL       macro
  49.               move.l    AbsExecBase,a6
  50.               jsr       _LVO\1(a6)
  51.               endm
  52. *
  53. GFXCALL       macro
  54.               move.l    GfxBase,a6
  55.               jsr       _LVO\1(a6)
  56.               endm
  57. *
  58. INTCALL       macro
  59.               move.l    IntuiBase,a6
  60.               jsr       _LVO\1(a6)
  61.               endm
  62. *
  63. DOSCALL       macro
  64.               move.l    DosBase,a6
  65.               jsr       _LVO\1(a6)
  66.               endm
  67. *
  68. *  You must not remove references to _main or .begin
  69. *
  70.               public    _main
  71.               public    .begin
  72.               XLIB      OpenLibrary
  73.               XLIB      CloseLibrary
  74.               XLIB      GetMsg
  75.               XLIB      ReplyMsg
  76.               XLIB      OpenWindow
  77.               XLIB      CloseWindow
  78.               XLIB      ViewPortAddress
  79.               XLIB      SetRGB4
  80.               XLIB      LoadRGB4
  81.               XLIB      GetSprite
  82.               XLIB      ChangeSprite
  83.               XLIB      FreeSprite
  84.               XLIB      Delay
  85. *
  86.               cseg
  87. _main:
  88.               jsr       OpenLibs               ; Open all needed libraries
  89.               jsr       InitAll                ; Init display and sprite
  90.               move.l    #NUM_SPRITES,d0        ; Get number of sprites
  91.               lea       SPR00COL,a0            ; Get first sprite pointer
  92. Loop:
  93.               move.l    d0,SaveSprNum          ; Number of sprites
  94.               move.l    a0,SaveSprPtr          ; Current sprite pointer
  95.               jsr       ChangeImage            ; Change sprite image
  96.               jsr       CheckClose             ; Close gadget hit?
  97.               beq.s     EndProg                ; Yep!
  98. *
  99.               moveq     #DELAY_VAL,d1          ; Timeout value in d1
  100.               DOSCALL   Delay                  ; Call delay function
  101. *
  102.               move.l    SaveSprPtr,a0          ; Get current sprite pointer
  103.               adda.l    #si_SizeOf,a0          ; Get next sprite image
  104.               move.l    SaveSprNum,d0          ; Get Sprite number counter
  105.               subq      #$01,d0                ; Decrement counter
  106.               bne.s     Loop                   ; Keep looping
  107. *
  108.               move.l    #NUM_SPRITES,d0        ; Re-initialize counter
  109.               lea       SPR00COL,a0            ; Point back to first sprite
  110.               bra.s     Loop                   ; Keep looping
  111. EndProg:
  112.               jsr       FreeAll                ; Free display and sprite
  113.               jsr       CloseLibs              ; Close all used libraries
  114.               rts
  115. *
  116. *  Open all needed libraries  --> intuition, graphics, and dos
  117. *
  118. OpenLibs:
  119.               clr.l     d0                     ; Any version of dos
  120.               lea       DosName,a1             ; Points to library name
  121.               EXECALL   OpenLibrary            ; Call OpenLibrary
  122.               move.l    d0,DosBase             ; Save library base pointer
  123. *
  124.               clr.l     d0                     ; Any version of intuition
  125.               lea       IntuiName,a1           ; Points to library name
  126.               EXECALL   OpenLibrary            ; Call OpenLibrary
  127.               move.l    d0,IntuiBase           ; Save library base pointer
  128. *
  129.               clr.l     d0                     ; Any version of graphics
  130.               lea       GfxName,a1             ; Points to library name
  131.               EXECALL   OpenLibrary            ; Call OpenLibrary
  132.               move.l    d0,GfxBase             ; Save library base pointer
  133.               rts                              ; Back to caller
  134. *
  135. *  Open initial display and allocate sprite to play with
  136. *
  137. InitAll:
  138.               lea       MyWindow,a0            ; Pointer to NewWindow
  139.               INTCALL   OpenWindow             ; Call OpenWindow
  140.               move.l    d0,WindowPtr           ; Save window pointer
  141. *
  142.               move.l    d0,a0                  ; Window pointer in a0
  143.               INTCALL   ViewPortAddress        ; Call ViewPortAddress
  144.               move.l    d0,VPortPtr            ; Save ViewPort pointer
  145. *
  146.               move.l    d0,a0                  ; ViewPort pointer in a0
  147.               lea       ColorTable,a1          ; Table pointer in a1
  148.               moveq     #$03,d0                ; Number of colors
  149.               GFXCALL   LoadRGB4               ; Set screen colors
  150. *
  151. *  Initialize a sprite to play with
  152. *
  153.               lea       MySprite,a0            ; SimpleSprite pointer in a0
  154.               moveq     #SPRITE02,d0           ; Sprite number in d0
  155.               GFXCALL   GetSprite              ; Call GetSprite
  156. *
  157.               lea       MySprite,a0            ; Get SimpleSprite pointer
  158.               move.w    d0,ss_num(a0)          ; Store sprite number
  159.               move.w    #SPR_HEIGHT,d0         ; Get Sprite Height
  160.               move.w    d0,ss_height(a0)       ; Store Height
  161.               move.w    #SPRITE_X,d0           ; Get Sprite X
  162.               move.w    d0,ss_x(a0)            ; Store X Coordinate
  163.               move.w    #SPRITE_Y,d0           ; Get Sprite Y
  164.               move.w    d0,ss_y(a0)            ; Store Y Coordinate
  165.               rts                              ; Back to caller
  166. *
  167. *  Change sprite image to next in sequence
  168. *
  169. ChangeImage:
  170.               move.l    SaveSprPtr,a0          ; Get current sprite in a0
  171. *
  172.               move.w    si_SprColor1(a0),d1    ; Packed UWORD color in d1
  173.               moveq     #COLOR21,d0            ; Register to set in d0
  174.               jsr       SetColor               ; Set sprite color
  175. *
  176.               move.w    si_SprColor2(a0),d1    ; Packed UWORD color in d1
  177.               moveq     #COLOR22,d0            ; Register to set in d1
  178.               jsr       SetColor               ; Set sprite color
  179. *
  180.               move.w    si_SprColor3(a0),d1    ; Packed UWORD color in d1
  181.               moveq     #COLOR23,d0            ; Register to set in d0
  182.               jsr       SetColor               ; Set sprite color
  183. *
  184.               lea       si_SprData(a0),a2      ; Pointer to sprite image
  185.               move.l    VPortPtr,a0            ; ViewPort pointer in a0
  186.               lea       MySprite,a1            ; SimpleSprite pointer in a1
  187.               GFXCALL   ChangeSprite           ; Call ChangeSprite
  188.               rts                              ; Back to caller              
  189. *
  190. *  Set indicated color register (d0) to desired color (d1)
  191. *
  192. SetColor:
  193.               movem.l   d0-d3/a0-a3,SaveReg    ; Save used registers
  194.               andi.l    #$0fff,d1              ; Clear high nybble of d1
  195.               move.l    d1,SaveColor           ; Save color value
  196.               moveq     #$08,d2                ; Initial shift value
  197.               lea       RedBits,a0             ; Start of RGB color table
  198. ColorLoop:
  199.               move.l    SaveColor,d1           ; Get color in d1
  200.               lsr.l     d2,d1                  ; Shift d1 right by (8,4,0)
  201.               andi.l    #$0f,d1                ; Mask off low nybble
  202.               move.l    d1,(a0)                ; Save d1 in current color
  203.               adda.l    #$04,a0                ; Point to next color
  204.               subq      #$04,d2                ; Get next shift value
  205.               bpl.s     ColorLoop              ; Loop till mask is negative
  206. *
  207.               move.l    VPortPtr,a0            ; ViewPort pointer in a0
  208.               move.l    RedBits,d1             ; Amount of red in d1
  209.               move.l    GreenBits,d2           ; Amount of green in d2
  210.               move.l    BlueBits,d3            ; Amount of blue in d3
  211.               GFXCALL   SetRGB4                ; Call SetRGB4 function
  212.               movem.l   SaveReg,d0-d3/a0-a3    ; Restore used registers
  213.               rts                              ; Back to caller
  214. *
  215. *  Read close gadget and return 0 if depressed
  216. *
  217. CheckClose:
  218.               move.l    WindowPtr,a1           ; Window pointer in a1
  219.               move.l    wd_UserPort(a1),a0     ; Window reply port in a0
  220.               EXECALL   GetMsg                 ; Call GetMsg
  221.               cmpi.l    #$0,d0                 ; Is a message available?
  222.               beq.s     NoMessage              ; Nope!
  223.               move.l    d0,MessagePtr          ; Save MessagePtr
  224. *
  225.               move.l    d0,a1                  ; Message pointer in a1
  226.               EXECALL   ReplyMsg               ; Reply to message
  227. *
  228.               move.l    MessagePtr,a0          ; Get message pointer
  229.               move.l    im_Class(a0),d1        ; Get class of message
  230.               cmpi.l    #CLOSEWINDOW,d1        ; Was close gadget hit?
  231.               bne.s     NoMessage              ; Nope!
  232.               moveq     #$0,d0                 ; Indicate gadget was hit
  233.               rts                              ; Back to caller
  234. *
  235. NoMessage:    moveq     #$1,d0                 ; Something else happened
  236.               rts                              ; Back to caller
  237. *
  238. *  Free display and sprite
  239. *
  240. FreeAll:
  241.               moveq     #SPRITE02,d0           ; Sprite number in d0
  242.               GFXCALL   FreeSprite             ; Call FreeSprite
  243. *
  244.               move.l    WindowPtr,a0           ; Pointer to window in a0
  245.               INTCALL   CloseWindow            ; Call CloseWindow
  246.               rts                              ; Back to caller
  247. *
  248. *  Close all used libraries
  249. *
  250. CloseLibs:
  251.               move.l    DosBase,a1             ; Dos library base
  252.               EXECALL   CloseLibrary           ; Call CloseLibrary
  253. *
  254.               move.l    IntuiBase,a1           ; Intuition library base
  255.               EXECALL   CloseLibrary           ; Call CloseLibrary
  256. *
  257.               move.l    GfxBase,a1             ; Graphics library base
  258.               EXECALL   CloseLibrary           ; Call CloseLibrary
  259.               rts                              ; Back to caller
  260. *
  261.               dseg
  262. *
  263. *  Character strings used in program
  264. *
  265. DosName:      dc.b      'dos.library',0
  266.               ds.w      0
  267. *
  268. IntuiName:    dc.b      'intuition.library',0
  269.               ds.w      0
  270. *
  271. GfxName:      dc.b      'graphics.library',0
  272.               ds.w      0
  273. *
  274. WindowTitle:  dc.b      ' SpriteWiz assembler demo  -  By D. Visage',0
  275.               ds.w      0
  276. *
  277. *  Definition of default NewWindow structure
  278. *
  279. MyWindow:
  280.               dc.w      0,0                    ; LeftEdge, TopEdge
  281.               dc.w      MAX_WIDTH,MAX_HEIGHT   ; Width, Height
  282.               dc.b      COLOR00,COLOR01        ; DetailPen, BlockPen
  283.               dc.l      CLOSEWINDOW            ; IDCMPFlags
  284.               dc.l      WINDOW_FLAGS           ; User defined flags
  285.               dc.l      0                      ; struct Gadget *FirstGadget
  286.               dc.l      0                      ; struct Image *Checkmark
  287.               dc.l      WindowTitle            ; UBYTE *Title;
  288.               dc.l      0                      ; struct Screen *Screen
  289.               dc.l      0                      ; struct BitMap *BitMap
  290.               dc.w      0,0                    ; MinWidth, MinHeight
  291.               dc.w      0,0                    ; MaxWidth, MaxHeight
  292.               dc.w      WBENCHSCREEN           ; Good old WorkBench
  293. *
  294. *  Initial colors - BackGround Black, Borders White, Everthing else Red
  295. *
  296. ColorTable    dc.w      $000,$fff,$f00
  297. *
  298. *  Storage for SimpleSprite structure
  299. *
  300. MySprite      ds.b      ss_SIZEOF              ; This is in bytes
  301. *
  302. *  Storage for converting packed UWORDS to RGB values
  303. *
  304. RedBits       ds.l      1
  305. GreenBits     ds.l      1
  306. BlueBits      ds.l      1
  307. SaveColor     ds.l      1
  308. *
  309. *  Storage for global library base pointers
  310. *
  311. DosBase       ds.l      1
  312. IntuiBase     ds.l      1
  313. GfxBase       ds.l      1
  314. *
  315. *  Storage for pointers to Window,ViewPort, and IntuiMessages
  316. *
  317. WindowPtr     ds.l      1
  318. VPortPtr      ds.l      1
  319. MessagePtr    ds.l      1
  320. *
  321. *  These are used for the animation sequence
  322. *
  323. SaveSprNum    ds.l      1
  324. SaveSprPtr    ds.l      1
  325. *
  326. *  Register storage
  327. *
  328. SaveReg       ds.l      8                    ; d0-d3/a0-a3
  329. *
  330.               end
  331.  
  332.  
  333.