home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / Hard_examples / clearmem.asm < prev    next >
Encoding:
Assembly Source File  |  1992-08-21  |  2.6 KB  |  75 lines

  1. ;
  2. ; clearmem.asm
  3. ;
  4. ;   Blitter example---memory clear (link with amiga.lib)
  5. ;
  6.         include 'exec/types.i'
  7.         include 'hardware/custom.i'
  8.         include 'hardware/dmabits.i'
  9.         include 'hardware/blit.i'
  10.         include 'hardware/hw_examples.i"
  11.  
  12.         xref    _custom
  13.  
  14. ;
  15. ;   Wait for previous blit to complete.
  16. ;
  17. waitblit:
  18.         btst.b  #DMAB_BLTDONE-8,DMACONR(a1)
  19. waitblit2:
  20.         btst.b  #DMAB_BLTDONE-8,DMACONR(a1)
  21.         bne     waitblit2
  22.         rts
  23. ;
  24. ;   This routine uses a side effect in the blitter.  When each
  25. ;   of the blits is finished, the pointer in the blitter is pointing
  26. ;   to the next word to be blitted.
  27. ;
  28. ;   When this routine returns, the last blit is started and might
  29. ;   not be finished, so be sure to call waitblit above before
  30. ;   assuming the data is clear.
  31. ;
  32. ;   a0 = pointer to first word to clear
  33. ;   d0 = number of bytes to clear (must be even)
  34. ;
  35.         xdef    clearmem
  36. clearmem:
  37.         lea     _custom,a1      ; Get pointer to chip registers
  38.         bsr     waitblit        ; Make sure previous blit is done
  39.         move.l  a0,BLTDPT(a1)   ; Set up the D pointer to the region to clear
  40.         clr.w   BLTDMOD(a1)     ; Clear the D modulo (don't skip no bytes)
  41.         asr.l   #1,d0           ; Get number of words from number of bytes
  42.         clr.w   BLTCON1(a1)     ; No special modes
  43.         move.w  #DEST,BLTCON0(a1)       ; only enable destination
  44. ;
  45. ;   First we deal with the smaller blits
  46. ;
  47.         moveq   #$3f,d1         ; Mask out mod 64 words
  48.         and.w   d0,d1
  49.         beq     dorest          ; none?  good, do one blit
  50.         sub.l   d1,d0           ; otherwise remove remainder
  51.         or.l    #$40,d1         ; set the height to 1, width to n
  52.         move.w  d1,BLTSIZE(a1)  ; trigger the blit
  53. ;
  54. ;   Here we do the rest of the words, as chunks of 128k
  55. ;
  56. dorest:
  57.         move.w  #$ffc0,d1       ; look at some more upper bits
  58.         and.w   d0,d1           ; extract 10 more bits
  59.         beq     dorest2         ; any to do?
  60.         sub.l   d1,d0           ; pull of the ones we're doing here
  61.         bsr     waitblit        ; wait for prev blit to complete
  62.         move.w  d0,BLTSIZE(a1)  ; do another blit
  63. dorest2:
  64.         swap    d0              ; more?
  65.         beq     done            ; nope.
  66.         clr.w   d1              ; do a 1024x64 word blit (128K)
  67. keepon:
  68.         bsr     waitblit        ; finish up this blit
  69.         move.w  d1,BLTSIZE(a1)  ; and again, blit
  70.         subq.w  #1,d0           ; still more?
  71.         bne     keepon          ; keep on going.
  72. done:
  73.         rts                     ; finished.  Blit still in progress.
  74.         end
  75.