**
** Apfelmännchen Iterationen von Martin Giese & Tobias Ferber
**
** 20-21.Oktober '92
**

  ; Functions to replace SetAPPen() ...  WritePixel() stuff.
  ; + void init_quickplot(struct BitMap *)
  ; + void quickplot(UBYTE)

  include "intuition/screens.i"
  include "graphics/rastport.i"

  section quickplot,code

  xdef _init_quickplot
  xdef _quickplot
  xdef _init_quickrect
  xdef _quickrect

_init_quickplot:

  movem.l D0/A0/A1,-(sp)
  move.l  16(sp),A0                   ; 3*4+4  (struct BitMap *)
  move.l  rp_BitMap(A0),A0
  moveq   #0,D0
  move.b  bm_Depth(A0),D0
  subq    #1,D0
  move.w  D0,depth
  move.w  bm_BytesPerRow(A0),bpr
  lea     bm_Planes(A0),A0
  lea     planes,A1
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.w  #%1000000000000000,plotmask
  movem.l (sp)+,D0/A0/A1
  rts


_quickplot:
  movem.l D0/D1/D2/D3/D4/A0/A1,-(sp)
  move.l  32(sp),D0                   ; 7*4+4 (pen)
  move.w  plotmask,D1                 ; OR.W mask
  move.w  D1,D2
  eor.w   #$FFFF,D2                   ; AND.W mask
  moveq   #0,D3
  move.w  depth,D3
  moveq   #0,D4                       ; pen bit counter

  lea     planes,A0
\loop:
  move.l  (A0)+,A1
  btst.b  D4,D0
  beq.s   \notset
  or.w    D1,(A1)
  bra.s   \next
\notset:
  and.w   D2,(A1)
\next:
  addq    #1,D4
  dbra.s  D3,\loop

  lsr.w   #1,D1
  cmpi.w  #0,D1
  bne.s   \exit

  move.w  #%1000000000000000,D1       ; reset plotmask
  lea     planes,A0
  add.l   #2,(A0)+
  add.l   #2,(A0)+
  add.l   #2,(A0)+
  add.l   #2,(A0)+
  add.l   #2,(A0)+
  add.l   #2,(A0)+

\exit:
  move.w  D1,plotmask
  movem.l (sp)+,D0/D1/D2/D3/D4/A0/A1
  rts


_init_quickrect:

  movem.l D0/A0/A1,-(sp)
  move.l  16(sp),A0                   ; 3*4+4  (struct BitMap *)
  move.l  rp_BitMap(A0),A0
  lea     bm_Planes(A0),A0
  lea     planes,A1
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  move.l  (A0)+,(A1)+
  lea     masks,A0
  move.l  20(sp),D0                   ; size of the rectangle
  subq.w  #1,D0                       ; DBRA correction
  move.w  D0,rsize
  lsl.w   #2,D0                       ; table offset correction
  move.l  0(A0,D0.W),rectmask
  move.w  #0,shifts
  move.w  #0,xpos
  movem.l (sp)+,D0/A0/A1
  rts

_quickrect:

  movem.l D0-D7/A0/A1,-(sp)
  move.l  44(sp),D0                   ; (8+2)*4+4   (pen)
  move.l  rectmask,D1                 ; OR mask
  move.l  D1,D2
  eor.l   #$FFFFFFFF,D2               ; AND mask
  moveq   #0,D3
  move.w  depth,D3
  moveq   #0,D4                       ; pen bit counter
  moveq   #0,D5
  move.w  rsize,D5                    ; size of the (square) rectangle
  moveq   #0,D7
  move.w  bpr,D7

  lea     planes,A0
\loop:
  move.l  D5,D6
  move.l  (A0)+,A1
  btst.b  D4,D0
  beq.s   \unset
\set:
  or.l    D1,(A1)
  add.l   D7,A1
  dbra    D6,\set
  bra.S   \next
\unset:
  and.l   D2,(A1)
  add.l   D7,A1
  dbra    D6,\unset
\next:
  addq    #1,D4
  dbra.S  D3,\loop

  addq    #1,D5
  lsr.l   D5,D1                       ; shift next mask
  move.w  shifts,D0
  add.w   D5,D0
  cmp.w   #$000F,D0
  ble     \done

  subq    #1,D5                       ; undo the addq further up
  moveq   #2,D4                       ; #of moved bytes
  move.w  xpos,D6
  addq.w  #2,D6
  move.w  D6,xpos
  sub.w   D7,D6
  bmi     \moveon
  mulu    D5,D7                       ; size (height) * bytes per row
  add.l   D7,D4
  move.w  #0,xpos
\moveon:
  lea     planes,A0
  add.l   D4,(A0)+
  add.l   D4,(A0)+
  add.l   D4,(A0)+
  add.l   D4,(A0)+
  add.l   D4,(A0)+
  add.l   D4,(A0)+
  
  moveq   #0,D0
  lea     masks,A0
  lsl.w   #2,D5                       ; table offset correction
  move.l  0(A0,D5),D1                 ; reset mask

\done:
  move.w  D0,shifts
  move.l  D1,rectmask
  movem.l (sp)+,D0-D7/A0/A1
  rts

  section quickplot,data

depth:    dc.w 0                      ; #of planes
bpr:      dc.w 0                      ; bitmap's bytes per row
xpos:     dc.w 0                      ; byte offest in the current line
rsize:    dc.w 0                      ; size of the (square) rectangle
shifts:   dc.w 0                      ; #of LSR's performed on rectmask

planes:   dc.l 0
          dc.l 0
          dc.l 0
          dc.l 0
          dc.l 0
          dc.l 0
          dc.l 0
          dc.l 0

plotmask: dc.w %1000000000000000

rectmask: dc.l %11111111111111110000000000000000

masks:    dc.l %10000000000000000000000000000000
          dc.l %11000000000000000000000000000000
          dc.l %11100000000000000000000000000000
          dc.l %11110000000000000000000000000000
          dc.l %11111000000000000000000000000000
          dc.l %11111100000000000000000000000000
          dc.l %11111110000000000000000000000000
          dc.l %11111111000000000000000000000000
          dc.l %11111111100000000000000000000000
          dc.l %11111111110000000000000000000000
          dc.l %11111111111000000000000000000000
          dc.l %11111111111100000000000000000000
          dc.l %11111111111110000000000000000000
          dc.l %11111111111111000000000000000000
          dc.l %11111111111111100000000000000000
          dc.l %11111111111111110000000000000000

          dc.l %11111111111111110000000000000000
          dc.l %01111111111111110000000000000000
          dc.l %00111111111111110000000000000000
          dc.l %00011111111111110000000000000000
          dc.l %00001111111111110000000000000000
          dc.l %00000111111111110000000000000000
          dc.l %00000011111111110000000000000000
          dc.l %00000001111111110000000000000000
          dc.l %00000000111111110000000000000000
          dc.l %00000000011111110000000000000000
          dc.l %00000000001111110000000000000000
          dc.l %00000000000111110000000000000000
          dc.l %00000000000011110000000000000000
          dc.l %00000000000001110000000000000000
          dc.l %00000000000000110000000000000000
          dc.l %00000000000000010000000000000000


  END
