home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference_library / hardware / hard_examples / sprite_move.asm < prev   
Assembly Source File  |  1992-08-20  |  3KB  |  56 lines

  1. ;
  2. ; sprite_move.asm
  3. ;
  4. ; In this example of moving a sprite, the spaceship is bounced around
  5. ; on the screen, changing  direction whenever it reaches an edge.
  6. ;
  7. ; The sprite position data, containing VSTART and HSTART, lives in
  8. ; memory at $25000. VSTOP is located at $25002. You write to these
  9. ; locations to move the sprite. Once during each frame, VSTART is
  10. ; incremented (or decremented) by 1 and HSTART by 2. Then a new VSTOP
  11. ; is calculated, which will be the new VSTART + 6.
  12. ;
  13.         MOVE.B  #151,d0         ;Initialize horizontal count
  14.         MOVE.B  #194,d1         ;Initialize vertical count
  15.         MOVE.B  #64,d2          ;Initialize horizontal position
  16.         MOVE.B  #44,d3          ;Initialize vertical position
  17.         MOVE.B  #1,d4           ;Initialize horizontal increment value
  18.         MOVE.B  #1,d5           ;Initialize vertical increment value
  19. ;
  20. ;Here we wait for the start of the screen updating.
  21. ;This ensures a glitch-free display.
  22. ;
  23.         LEA     CUSTOM,a0       ;Set custom chip base pointer
  24. VLOOP:
  25.         MOVE.B  VHPOSR(a0),d6   ;Read Vertical beam position.
  26. ;Only insert the following line if you are using a PAL machine.
  27. ;       CMP.B   #$20,d6         ;Compare with end of PAL screen.
  28.         BNE.S   VLOOP           ;Loop if not end of screen.
  29. ;Alternatively you can use the following code:
  30. ;VLOOP:
  31. ;       MOVE.W  INTREQR(a0),d6          ;Read interrupt request word
  32. ;       AND.W   #$0020,d6               ;Mask off all but vertical blank bit
  33. ;       BEQ     VLOOP                   ;Loop until bit is a 1
  34. ;       MOVE.W  #$0020,INTREQ(a0)       ;Vertical bit is on, so reset it
  35. ;
  36. ;Please note that this will only work if you have turned OFF the Vertical
  37. ;blanking interrupt enable (not recommended for long periods).
  38.  
  39.         ADD.B   d4,d2           ;Increment horizontal value
  40.         SUBQ.B  #1,d0           ;Decrement horizontal counter
  41.         BNE     L1
  42.         MOVE.B  #151,d0         ;Count exhausted, reset to 151
  43.         EOR.B   #$FE,d4         ;Negate the increment value
  44. L1:     MOVE.B  d2,$25001       ;Write new HSTART value to sprite
  45.         ADD.B   d5,d3           ;Increment vertical value
  46.         SUBQ.B  #1,d1           ;Decrement vertical counter
  47.         BNE     L2
  48.         MOVE.B  #194,d1         ;Count exhausted, reset to 194
  49.         EOR.B   #$FE,d5         ;Negate the increment value
  50. L2:     MOVE.B  d3,$25000       ;Write new VSTART value to sprite
  51.         MOVE.B  d3,d6           ;Must now calculate new VSTOP
  52.         ADD.B   #6,d6           ;VSTOP always VSTART+6 for spaceship
  53.         MOVE.B  d6,$25002       ;Write new VSTOP to sprite
  54.         BRA     VLOOP           ;Loop forever
  55.  
  56.