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

  1. ;
  2. ; rotatebits.asm
  3. ;
  4. ;   Here we rotate bits.  This code takes a single raster row of a
  5. ;   bitplane, and `rotates' it into an array of 16-bit words, setting
  6. ;   the specified bit of each word in the array according to the
  7. ;   corresponding bit in the raster row.  We use the line mode in
  8. ;   conjunction with patterns to do this magic. Link this code with amiga.lib.
  9. ;
  10. ;   Input:  d0 contains the number of words in the raster row.  d1
  11. ;   contains the number of the bit to set (0..15).  a0 contains a
  12. ;   pointer to the raster data, and a1 contains a pointer to the
  13. ;   array we are filling; the array must be at least (d0)*16 words
  14. ;   (or (d0)*32 bytes) long.
  15. ;
  16. ;
  17.         include 'exec/types.i'
  18.         include 'hardware/custom.i'
  19.         include 'hardware/blit.i'
  20.         include 'hardware/dmabits.i'
  21.  
  22.         include 'hardware/hw_examples.i'
  23. ;
  24.         xref    _custom
  25. ;
  26.         xdef    rotatebits
  27. ;
  28. ;
  29. ;   Our entry point.
  30. ;
  31. rotatebits:
  32.         lea     _custom,a2      ; We need to access the custom registers
  33.         tst     d0              ; if no words, just return
  34.         beq     gone
  35.         lea     DMACONR(a2),a3  ; get the address of dmaconr
  36.         moveq.l #DMAB_BLTDONE-8,d2      ; get the bit number BLTDONE
  37.         btst    d2,(a3)         ; check to see if we're done
  38. wait1:
  39.         btst    d2,(a3)         ; check again.
  40.         bne     wait1           ; not done?  Keep waiting
  41.         moveq.l #-30,d3         ; Line mode:  aptr = 4Y-2X, Y=0; X=15
  42.         move.l  d3,BLTAPT(a2)
  43.         move.w  #-60,BLTAMOD(a2)        ; amod = 4Y-4X
  44.         clr.w   BLTBMOD(a2)     ; bmod = 4Y
  45.         move.w  #2,BLTCMOD(a2)  ; cmod = width of bitmap (2)
  46.         move.w  #2,BLTDMOD(a2)  ; ditto
  47.         ror.w   #4,d1           ; grab the four bits of the bit number
  48.         and.w   #$f000,d1       ; mask them out
  49.         or.w    #$bca,d1        ; USEA, USEC, USED, F=AB+~AC
  50.         move.w  d1,BLTCON0(a2)  ; stuff it
  51.         move.w  #$f049,BLTCON1(a2)      ; BSH=15, SGN, LINE
  52.         move.w  #$8000,BLTADAT(a2)      ; Initialize A dat for line
  53.         move.w  #$ffff,BLTAFWM(a2)      ; Initialize masks
  54.         move.w  #$ffff,BLTALWM(a2)
  55.         move.l  a1,BLTCPT(a2)   ; Initialize pointer
  56.         move.l  a1,BLTDPT(a2)
  57.         lea     BLTBDAT(a2),a4  ; For quick access, we grab these two
  58.         lea     BLTSIZE(a2),a5  ; addresses
  59.         move.w  #$402,d1        ; Stuff bltsize; width=2, height=16
  60.         move.w  (a0)+,d3        ; Get next word
  61.         bra     inloop          ; Go into the loop
  62. again:
  63.         move.w  (a0)+,d3        ; Grab another word
  64.         btst    d2,(a3)         ; Check blit done
  65. wait2:
  66.         btst    d2,(a3)         ; Check again
  67.         bne     wait2           ; oops, not ready, loop around
  68. inloop:
  69.         move.w  d3,(a4)         ; stuff new word to make vertical
  70.         move.w  d1,(a5)         ; start the blit
  71.         subq.w  #1,d0           ; is that the last word?
  72.         bne     again           ; keep going if not
  73. gone:
  74.         rts
  75.         end
  76.