home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / aga_software / tmap-demo / ylrfill.asm < prev   
Assembly Source File  |  1993-02-18  |  7KB  |  365 lines

  1. ; $$TABS=8
  2.  
  3.     include    'demo.i'
  4.     xref    yadrtable,rightmasktable,leftmasktable
  5.     xref    vtable
  6.  
  7. YLRFill::
  8. ; fill a list of horizontal spans
  9. ; handles reversal cases (left > right)! However, this is an unlikely case
  10. ; so it is more optimal for the other case.
  11. ; This routine is optimized for SMALL polygons (the only interesting ones)
  12. ; input:
  13. ;  (a0)=ylr array, terminated with y<0.
  14. ; trashes: a0/a1/d1-d7
  15. ; register usage:
  16. ;  d0=color
  17. ;  d7=$fffc    ( x adr mask)
  18. ;  a0=array
  19.  
  20. ; lwordofs[x]=(x>>2)*4
  21. ; right mask table=00ffffff, 0000ffff, 000000ff, 00000000
  22. ; left masktable=  00000000  ff000000  ffff0000  ffffff00
  23.     ONTIMER    10
  24.     moveq    #$fffffffc,d7
  25.     move.l    current_color(a6),d0
  26.     move.w    (a0)+,d1    ; ycoord
  27.     bmi.s    done_fill    ; handle empty case? why?
  28. nextylr:
  29.     move.l    (yadrtable.w,a6,d1.w*4),a1    ; a1=screen array ptr
  30.     move.w    (a0)+,d1            ; d1=leftx
  31.     move.w    (a0)+,d2            ; d2=rightx
  32.     cmp.w    d1,d2
  33.     blt.s    ylr_reverse1
  34. re_enter:
  35.     move.w    d1,d3                ; save leftx
  36.     move.w    d2,d4                ; save rightx
  37.     and.w    d7,d3                ; convert coordinate to lword offset
  38.     and.w    d7,d4                ; convert to lword offset
  39.     add    d3,a1                ; offset address register
  40.     sub.w    d3,d4                ; determine # of bytes
  41.     beq.s    one_lword_case
  42.     lsr.w    #2,d4
  43. ; now do left side
  44.     move.l    (leftmasktable.w,a6,d1.w*4),d1
  45.     move.l    (a1),d6
  46.     and.l    d1,d6
  47.     not.l    d1
  48.     and.l    d0,d1
  49.     or.l    d1,d6
  50.     move.l    d6,(a1)+
  51. ; now, determine # of full words to do
  52.     subq    #2,d4                ; adjust for ends and dbra
  53.     bmi.s    no_middle
  54. 1$:    move.l    d0,(a1)+
  55.     dbra    d4,1$
  56. no_middle:
  57.     move.l    (rightmasktable.w,a6,d2.w*4),d2
  58.     move.l    (a1),d1
  59.     and.l    d2,d1
  60.     not.l    d2
  61.     and.l    d0,d2
  62.     or.l    d2,d1
  63.     move.l    d1,(a1)
  64.     move.w    (a0)+,d1    ; fetch next y
  65.     bpl.s    nextylr
  66. done_fill:
  67.     OFFTIMER    10
  68.     rts
  69.  
  70. one_lword_case:
  71. ; start and end are in one lword, so:
  72. ; mask=lmask | rmask
  73. ; if (mask=-1), right and left are reversed!
  74.     move.l    (leftmasktable.w,a6,d1.w*4),d6
  75.     or.l    (rightmasktable.w,a6,d2.w*4),d6
  76.     move.l    (a1),d1
  77.     and.l    d6,d1
  78.     not.l    d6
  79.     and.l    d0,d6
  80.     or.l    d6,d1
  81.     move.l    d1,(a1)
  82.     move.w    (a0)+,d1
  83.     bpl.s    nextylr
  84.     OFFTIMER    10
  85.     rts
  86.  
  87. ylr_reverse1:
  88. ; oh no! a backwards one has occurred due to precision problems!
  89. ; let's handle it as inefficiently as possible!
  90.     exg    d1,d2
  91.     bra.s    re_enter
  92.  
  93. YLRCCFill::
  94. ; fill gradient shaded polygons
  95.     ONTIMER    10
  96.     move.w    (a0)+,d1    ; ycoord
  97.     bmi.s    done_ylrcc
  98. nextylrcc:
  99.     move.l    (yadrtable.w,a6,d1.w*4),a1
  100.     movem.w    (a0)+,d1/d2/d3/d4    ; lx,rx, lc, rc
  101.     cmp.w    d1,d2
  102.     bge.s    no_ccrev
  103.     exg    d3,d4
  104.     exg    d1,d2
  105. no_ccrev:
  106. ; now, determine delta color = (rc-lc)+1/(rc-lx+1)
  107.     add    d1,a1        ; adjust pointer
  108.     sub    d1,d2        ; d2=rx-lx
  109.     addq    #1,d2        ; rx-lc+1
  110.     sub    d3,d4        ; dc
  111.     addq    #1,d4        ; dc+1
  112.     ext.l    d4        ; for divide
  113.     divs    d2,d4        ; d4=dc*256
  114. ; now,
  115. ; d2=dbra count for output pixels
  116. ; d4=dc (8.8)
  117. ; d3=c (8.8)
  118. ; a1=output ptr
  119.     ror.w    #8,d3        ; d3=f.i
  120.     move.b    d3,d0        ; d0=c.i
  121.     clr.b    d3        ; d3=c.f
  122.     ror.w    #8,d4
  123.     move.b    d4,d1
  124.     ext.w    d1
  125.     clr.b    d4
  126.     subq    #1,d2
  127.     lsr.w    #1,d2
  128.     bcc.s    ccfill_even
  129.     move.b    d0,(a1)+
  130.     add.w    d4,d3
  131.     addx.w    d1,d0
  132. ccfill_even:
  133.     subq    #1,d2
  134.     bmi.s    ccfill_done
  135. ccfill_bytes:
  136.     move.b    d0,(a1)+
  137.     add.w    d4,d3
  138.     addx.w    d1,d0
  139.     move.b    d0,(a1)+
  140.     add.w    d4,d3
  141.     addx.w    d1,d0
  142.     dbra    d2,ccfill_bytes
  143. ccfill_done:
  144.     move.w    (a0)+,d1
  145.     bpl.s    nextylrcc
  146. done_ylrcc:
  147.     OFFTIMER    10
  148.     rts
  149.  
  150. YLRUUFill::
  151. ; fill texture mapped polygons
  152. ; vbuffer contains v(x)
  153. ; out=*(tmapadr+v(x)+u(x)<<8)
  154. ;    bra    YLRUUFillT
  155.     move.l    current_ltab(a6),d0
  156.     bne.s    YLRUULFill
  157.     move.w    (a0)+,d1    ; ycoord
  158.     bmi.s    done_ylrcc
  159. nextylruu:    move.l    (yadrtable.w,a6,d1.w*4),a1    ; dest coord
  160.     movem.w    (a0)+,d1/d2/d3/d4    ; lx,rx, lu, ru
  161.     cmp.w    d1,d2
  162.     bge.s    no_uurev
  163.     exg    d3,d4
  164.     exg    d1,d2
  165. no_uurev:
  166. ; now, determine delta color = (rc-lc)+1/(rc-lx+1)
  167.     lea    (vtable.w,a6,d1.w*4),a2    ; vtable
  168.     add    d1,a1        ; adjust pointer
  169.     sub    d1,d2        ; d2=rx-lx
  170.     addq    #1,d2        ; rx-lc+1
  171.     sub    d3,d4        ; dc
  172.     addq    #1,d4        ; dc+1
  173.     ext.l    d4        ; for divide
  174.     divs    d2,d4        ; d4=dc*256
  175. ; now,
  176. ; d2=dbra count
  177. ; d4=du (8.8)
  178. ; d3=u (8.8)
  179. ; a1=output ptr
  180. ; a2=vtable
  181.     ror.w    #8,d3        ; d3=f.i
  182.     moveq    #0,d0
  183.     move.b    d3,d0        ; d0=c.i
  184.     clr.b    d3        ; d3=c.f
  185.     ror.w    #8,d4
  186.     move.b    d4,d1
  187.     ext.w    d1
  188.     clr.b    d4
  189.     ONTIMER    10
  190.     lsr.w    #1,d2
  191.     bcc.s    uufill_even
  192.     move.l    (a2)+,a3
  193.     move.b    (a3,d0.w),(a1)+
  194.     add.w    d4,d3
  195.     addx.w    d1,d0
  196. uufill_even:
  197.     subq    #1,d2
  198.     bmi.s    fetchnextuu
  199. uufill_bytes:
  200.     move.l    (a2)+,a3
  201.     move.b    (a3,d0.w),(a1)+
  202.     add.w    d4,d3
  203.     addx.w    d1,d0
  204.     move.l    (a2)+,a3
  205.     move.b    (a3,d0.w),(a1)+
  206.     add.w    d4,d3
  207.     addx.w    d1,d0
  208.     dbra    d2,uufill_bytes
  209. fetchnextuu:
  210.     OFFTIMER    10
  211.     move.w    (a0)+,d1
  212.     bpl.s    nextylruu
  213. done_ylruu:
  214.     rts
  215.  
  216. YLRUULFill::
  217. ; fill texture mapped polygons, lighting with current_ltab
  218. ; vbuffer contains v(x)
  219. ; out=*(tmapadr+v(x)+u(x)<<8)
  220.     move.l    d0,a4
  221.     move.w    (a0)+,d1    ; ycoord
  222.     bmi.s    done_ylruu
  223. nextylruul:
  224.     move.l    (yadrtable.w,a6,d1.w*4),a1    ; dest coord
  225.     movem.w    (a0)+,d1/d2/d3/d4    ; lx,rx, lu, ru
  226.     cmp.w    d1,d2
  227.     bge.s    no_uurevl
  228.     exg    d3,d4
  229.     exg    d1,d2
  230. no_uurevl:
  231. ; now, determine delta color = (rc-lc)+1/(rc-lx+1)
  232.     lea    (vtable.w,a6,d1.w*4),a2    ; vtable
  233.     add    d1,a1        ; adjust pointer
  234.     sub    d1,d2        ; d2=rx-lx
  235.     addq    #1,d2        ; rx-lc+1
  236.     sub    d3,d4        ; dc
  237.     addq    #1,d4        ; dc+1
  238.     ext.l    d4        ; for divide
  239.     divs    d2,d4        ; d4=dc*256
  240. ; now,
  241. ; d2=dbra count
  242. ; d4=du (8.8)
  243. ; d3=u (8.8)
  244. ; a1=output ptr
  245. ; a2=vtable
  246.     ror.w    #8,d3        ; d3=f.i
  247.     moveq    #0,d0
  248.     move.b    d3,d0        ; d0=c.i
  249.     clr.b    d3        ; d3=c.f
  250.     ror.w    #8,d4
  251.     move.b    d4,d1
  252.     ext.w    d1
  253.     clr.b    d4
  254.     moveq    #0,d7
  255.     ONTIMER    10
  256.     lsr.w    #1,d2
  257.     bcc.s    uufill_evenl
  258.     move.l    (a2)+,a3
  259.     move.b    (a3,d0.w),d7
  260.     move.b    (a4,d7.w),(a1)+
  261.     add.w    d4,d3
  262.     addx.w    d1,d0
  263. uufill_evenl:
  264.     subq    #1,d2
  265.     bmi.s    fetchnextuul
  266. uufill_bytesl:
  267.     move.l    (a2)+,a3
  268.     move.b    (a3,d0.w),d7
  269.     move.b    (a4,d7.w),(a1)+
  270.     add.w    d4,d3
  271.     addx.w    d1,d0
  272.     move.l    (a2)+,a3
  273.     move.b    (a3,d0.w),d7
  274.     move.b    (a4,d7.w),(a1)+
  275.     add.w    d4,d3
  276.     addx.w    d1,d0
  277.     dbra    d2,uufill_bytesl
  278. fetchnextuul:
  279.     OFFTIMER    10
  280.     move.w    (a0)+,d1
  281.     bpl    nextylruul
  282. rts1    rts
  283.  
  284.  
  285.     xref    blend_table
  286.  
  287. YLRUUFillT::
  288. ; fill texture mapped transparent polygons
  289. ; vbuffer contains v(x)
  290. ; out=*(tmapadr+v(x)+u(x)<<8)
  291.     move.l    #blend_table,a4
  292.     move.w    (a0)+,d1    ; ycoord
  293.     bmi.s    rts1
  294. nextylruut:
  295.     move.l    (yadrtable.w,a6,d1.w*4),a1    ; dest coord
  296.     movem.w    (a0)+,d1/d2/d3/d4    ; lx,rx, lu, ru
  297.     cmp.w    d1,d2
  298.     bge.s    no_uurevt
  299.     exg    d3,d4
  300.     exg    d1,d2
  301. no_uurevt:
  302. ; now, determine delta color = (rc-lc)+1/(rc-lx+1)
  303.     lea    (vtable.w,a6,d1.w*4),a2    ; vtable
  304.     add    d1,a1        ; adjust pointer
  305.     sub    d1,d2        ; d2=rx-lx
  306.     addq    #1,d2        ; rx-lc+1
  307.     sub    d3,d4        ; dc
  308.     addq    #1,d4        ; dc+1
  309.     ext.l    d4        ; for divide
  310.     divs    d2,d4        ; d4=dc*256
  311. ; now,
  312. ; d2=dbra count
  313. ; d4=du (8.8)
  314. ; d3=u (8.8)
  315. ; a1=output ptr
  316. ; a2=vtable
  317. ; a4=ltable
  318.     ror.w    #8,d3        ; d3=f.i
  319.     moveq    #0,d0
  320.     move.b    d3,d0        ; d0=c.i
  321.     clr.b    d3        ; d3=c.f
  322.     ror.w    #8,d4
  323.     move.b    d4,d1
  324.     ext.w    d1
  325.     clr.b    d4
  326.     ONTIMER    10
  327.     lsr.w    #1,d2
  328.     bcc.s    uufill_event
  329.     move.l    (a2)+,a3
  330.     move.w    -1(a3,d0.w),d7
  331.     move.b    (a1),d7
  332.     move.b    (a4,d7.w),(a1)+
  333.     add.w    d4,d3
  334.     addx.w    d1,d0
  335. uufill_event:
  336.     subq    #1,d2
  337.     bmi.s    fetchnextuut
  338. uufill_bytest:
  339.     move.l    (a2)+,a3
  340.     move.w    -1(a3,d0.w),d7
  341.     move.b    (a1),d7
  342.     move.b    (a4,d7.w),(a1)+
  343.     add.w    d4,d3
  344.     addx.w    d1,d0
  345.     move.l    (a2)+,a3
  346.     move.w    -1(a3,d0.w),d7
  347.     move.b    (a1),d7
  348.     move.b    (a4,d7.w),(a1)+
  349.     add.w    d4,d3
  350.     addx.w    d1,d0
  351.     dbra    d2,uufill_bytest
  352. fetchnextuut:
  353.     OFFTIMER    10
  354.     move.w    (a0)+,d1
  355.     bpl    nextylruut
  356.     rts
  357.  
  358.  
  359.     section    __MERGED,data
  360.  
  361. current_color::
  362.     dc.l    $ffffffff
  363. current_ltab::
  364.     dc.l    0
  365.