home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 245.lha / FastGro_v1.0 / Wander.asm < prev   
Assembly Source File  |  1989-04-09  |  4KB  |  183 lines

  1. ; wander.asm - optimized wandering routine for random fractal
  2.  
  3.     far    code
  4.     far    data
  5.  
  6.     public    _wander_asm    ; defined here
  7.     public    _setbit
  8.     public    _checkbit
  9.  
  10.     public    _WritePixel    ; needed here
  11.     public    _row
  12.     public    _randoms
  13.     public    _next_random
  14.     public    _hires_rp
  15.  
  16. _wander_asm:
  17. ;    4(sp)    &x    ; x and y hold initial values!
  18. ;    8(sp)    &y
  19. ;wander_asm( retx, rety)
  20. ;  int *retx, *rety
  21.  
  22.     movem.l    d2/d3/a2/a3/a4,-(sp)
  23.  
  24.     move.l    _next_random,a4    ; a4 points to random numbers
  25.  
  26.     move.l    20+4(sp),a0    ; d2 = x
  27.     move.w    (a0),d2        
  28.  
  29.     move.l    20+8(sp),a0
  30.     move.w    (a0),d0
  31.     ext.l    d0        ; get initial row address (from y)
  32.     asl.l    #2,d0
  33.     lea    _row,a2
  34.     adda.l    d0,a2        ; a2 = address of row pointer
  35.     move.l    (a2),a3        ; a3 = ptr to row
  36.  
  37. loop    move.w    d2,d0        ; is this space occupied?
  38.     asr.w    #3,d0        ; calculate byte and bit address
  39.     btst.b    d2,(a3,d0.w)
  40.     bne    loopend        ; no
  41.  
  42. ;    bsr    write_pixel    ; to show how it is working
  43.  
  44. ; get random number here
  45.  
  46.     move.b    (a4)+,d0    ; d0 = next random number
  47.     bne.s    1$
  48.     move.l    _randoms,a4    ; wrap around if needed
  49. 1$
  50.     eor.b    d0,d3        ; exclusive or it
  51.     move.b    d3,d0        ; put in 0..14 range (8 posibilities)
  52.     and.w    #$E,d0
  53.     
  54.  
  55. ; depending on number, go different directions
  56.  
  57.     move.w    vectors(pc,d0.w),d0
  58. before_jmp
  59.     jmp    (pc,d0.w)
  60.  
  61. quad0:    addq.w    #1,d2        ; x++
  62.     bra.s    loop
  63.  
  64. quad1:    addq.w    #1,d2        ; x++
  65.     move.l    -(a2),a3    ; y--
  66.     bra.s    loop
  67.  
  68. quad2:    move.l    -(a2),a3    ; y--
  69.     bra.s    loop
  70.  
  71. quad3:    subq.w    #1,d2        ; x--
  72.     move.l    -(a2),a3    ; y--
  73.     bra.s    loop
  74.  
  75. quad4:    subq.w    #1,d2        ; x--
  76.     bra.s    loop
  77.  
  78. quad5:    subq.w    #1,d2        ; x--
  79.     addq.w    #4,a2        ; y++
  80.     move.l    (a2),a3
  81.     bra.s    loop
  82.  
  83. quad6:    addq.w    #4,a2        ; y++
  84.     move.l    (a2),a3
  85.     bra.s    loop
  86.  
  87. quad7:    addq.w    #1,d2        ; x++
  88.     addq.w    #4,a2        ; y++
  89.     move.l    (a2),a3
  90.     bra.s    loop
  91.     
  92. vectors:
  93.     dc.w    quad0-before_jmp-2
  94.     dc.w    quad1-before_jmp-2
  95.     dc.w    quad2-before_jmp-2
  96.     dc.w    quad3-before_jmp-2
  97.     dc.w    quad4-before_jmp-2
  98.     dc.w    quad5-before_jmp-2
  99.     dc.w    quad6-before_jmp-2
  100.     dc.w    quad7-before_jmp-2
  101.  
  102. loopend:
  103.  
  104.     move.l    20+4(sp),a0    ; return x
  105.     move.w    d2,(a0)
  106.     move.l    20+8(sp),a0    ; return y
  107.     move.l    a2,d0    
  108.     lea    _row,a1
  109.     sub.l    a1,d0
  110.     asr.w    #2,d0    
  111.     move.w    d0,(a0)
  112.  
  113.     move.l    a4,_next_random    ; keep track of random number pointer
  114.  
  115.     movem.l    (sp)+,d2/d3/a2/a3/a4
  116.     rts
  117.  
  118. write_pixel:
  119. ;    a2 = raw index into row
  120. ;    d2 = x
  121.  
  122.     move.l    a2,d0        ; get raw row pointer address
  123.     lea    _row,a1
  124.     sub.l    a1,d0    ; subtract off base to get raw index
  125.     asr.l    #2,d0        ; 
  126.     move.l    d0,-(sp)
  127.  
  128.     ext.l    d2
  129.     move.l    d2,-(sp)
  130.     
  131.     move.l    _hires_rp,-(sp)
  132.     jsr    _WritePixel
  133.     lea    12(sp),sp
  134.     rts    
  135.  
  136.  
  137. ;=========================================================================
  138.  
  139. _setbit        ; setbit( row, x, y )
  140. ;    row is the address of an array of pointers to rows
  141. ;    x and y are 16 bit
  142. ;    This sets the given bit
  143. ;    
  144. ;    10(sp).w    y
  145. ;    8(sp).w        x
  146. ;    4(sp).l        address of array of pointers to rows
  147.  
  148.  
  149.     move.l    4(sp),a0    ; a0 = address of base of array
  150.     move.w    10(sp),d0    ; d0 = y
  151.     asl.w    #2,d0
  152.     move.l    (a0,d0.w),a0    ; a0 = address of row
  153.     move.w    8(sp),d0    ; compute bit address
  154.     move.w    d0,d1        ; bit # in d0 (low 3 bits)
  155.     asr.w    #3,d1        ; compute byte offset
  156.     bset    d0,(a0,d1.w)    ; set it!
  157.     rts
  158.  
  159. _checkbit        ; checkbit( row, x, y )
  160. ;    row is the address of an array of pointers to rows
  161. ;    x and y are 16 bit
  162. ;    This checks the given bit, and returns a 16 bit boolean value
  163. ;    
  164. ;    10(sp).w    y
  165. ;    8(sp).w        x
  166. ;    4(sp).l        address of array of pointers to rows
  167.  
  168.  
  169.     move.l    4(sp),a0    ; a0 = address of base of array
  170.     move.w    10(sp),d0    ; d0 = y
  171.     asl.w    #2,d0
  172.     move.l    (a0,d0.w),a0    ; a0 = address of row
  173.     move.w    8(sp),d0    ; compute bit address
  174.     move.w    d0,d1        ; bit # in d0 (low 3 bits)
  175.     asr.w    #3,d1        ; compute byte offset
  176.     btst    d0,(a0,d1.w)    ; check it!
  177.     sne    d0
  178.     ext.w    d0        ; d0.w = bit set
  179.     rts
  180.  
  181.  
  182.     end
  183.