home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / DEMOS / MEGADEMO / PASSIONP.ARJ / PASSIONP.MSA / SHADING / SHADE.S < prev    next >
Text File  |  1997-03-05  |  25KB  |  990 lines

  1. ; *************************************************************************
  2. ; *****                      *****
  3. ; *****    Routine which draws a 4-planes shaded polygon.          *****
  4. ; *****                By Alain BROBECKER.              *****
  5. ; *****       Coded between 22nd and 23rd of june 1994.          *****
  6. ; *****      Rewritten & Optimised on 25th of june 1994.          *****
  7. ; *****                      *****
  8. ; *************************************************************************
  9. ; Parameters:    a0.l = ramvideo adress.
  10. ;    a1.l = adress of brows coords and intensities.
  11. ;    d0.w = nb of brows.
  12. ;
  13. ; The brows coords and intensities are organised like this:
  14. ; 1 word: x.
  15. ; 1 word: y.
  16. ; 1 word: intensity. (Integer part of it in the 4 most significant bits.)
  17. ; The brows must be placed anticlockwise. Also, the min intensity must be
  18. ; 2 and the max one must be 14 as there sometimes is an imprecision of
  19. ; one color during the interpolation.
  20. ; *************************************************************************
  21.  
  22.   movem.l    d0-a6,-(sp)
  23.  
  24. ; *************************************************************************
  25. ; * First copy the brows once just after their first appearance in a1.l, so
  26. ; * the "tracking" of the min & max lines will be easier. At the same time
  27. ; * search ymin & ymax of the poly.
  28. .copy_and_search:
  29.   move.l    a1,a2
  30.   move.l    a2,a3
  31.   move.w    d0,d1    ; 6 words per brow.
  32.   add.w    d1,d1
  33.   add.w    d0,d1
  34.   add.w    d1,d1
  35.   add.w    d1,a3    ; a3 points just after the brows.
  36.   move.w    #800,d6    ; d6=ymin.
  37.   move.w    #-600,d7    ; d7=ymax.
  38.   subq.w    #$1,d0    ; Beware the dbra.
  39.   
  40. .copy_one_brow:
  41.   move.l    (a2)+,d1    ; Load x and y in d1.
  42.   move.l    d1,(a3)+    ; Copy them.
  43.   cmp.w    d1,d6    ; This y lower than ymin?
  44.   blt.s    .not_ymin
  45.   move.w    d1,d6    ; Yes, then it's the new ymin.
  46. .not_ymin:
  47.   cmp.w    d1,d7    ; This y bigger than ymax?
  48.   bgt.s    .not_ymax
  49.   move.w    d1,d7    ; Yes, then it' s the new ymax.
  50. .not_ymax:
  51.   move.w    (a2)+,(a3)+    ; Copy intensity.
  52.   dbra    d0,.copy_one_brow ; Next brow.
  53.   
  54. ; *************************************************************************
  55. ; * When ymin and ymax are found, we can see if the poly is in the screen,
  56. ; * if it' s partly hidden (y_clipping only) or if it' s invisible.
  57.  
  58. .poly_visibility:
  59.   cmp.w    d6,d7    ; ymin=ymax?
  60.   beq.s    .poly_invisible
  61.   tst.w    d7    ; ymax=<0?
  62.   ble.s    .poly_invisible
  63.   cmp.w    #198,d6    ; ymin>=199?
  64.   ble.s    .poly_clipping
  65. .poly_invisible:    ; Poly out of the screen, so...
  66.   movem.l    (sp)+,d0-a6
  67.   rts
  68.   
  69. .poly_clipping:        ; The poly is (partly?) visible.
  70.   moveq.l    #$0,d0    ; d0=nb h_lines to pass at the beginning.
  71.   move.w    d7,d1
  72.   sub.w    d6,d1    ; d1=ymax-ymin=nb h_lines to draw-1.
  73.   tst.w    d6    ; ymin<0?
  74.   bge.s    .no_clip_up
  75. .clip_up:        ; Yes, so cut the first -ymin h_lines.
  76.   move.w    d6,d0    ; Pass -ymin h_lines at the beginning.
  77.   neg.w    d0
  78.   move.w    d7,d1    ; Nb lines to draw=ymax-0.
  79.   bra.s    .no_clip_down    ; I assume the poly is not that big.
  80. .no_clip_up:
  81.   cmp.w    #199,d7    ; ymax>199.
  82.   ble.s    .no_clip_down
  83. .clip_down:
  84.   move.w    #199,d1    ; Yes, so reduce the nb of h_lines.
  85.   sub.w    d6,d1
  86. .no_clip_down:
  87.   move.w    d0,.nb_lines_2_pass
  88.   addq.w    #$1,d1
  89.   move.w    d1,.nb_lines_2_draw
  90.   
  91. ; *************************************************************************
  92. ; * Not very hard or important, but we must do it, so....
  93.  
  94.   move.l    #.y_table,a2    ; The faster way to multiply by 160???
  95.   move.w    d6,d5
  96.   add.w    d0,d5    ; d5=first seen y.
  97.   add.w    d5,d5    ; One word per y.
  98.   add.w    (a2,d5.w),a0    ; a0 points on first line.
  99.  
  100. ; *************************************************************************
  101. ; * Now, the first important part. We "track" the max_lines, which are on
  102. ; * the right of the poly and calculate xmax and intensity_max for each
  103. ; * y between ymin-ymax by using linear interpolations.
  104.  
  105. .xmax_tracking:        ; First, search the upper right brow.
  106.   subq.w    #$6,a3    ; Next point in clockwise cycle.
  107.   cmp.w    $2(a3),d6    ; y=ymin?
  108.   bne.s    .xmax_tracking
  109. .xmax_ymin_found:    ; If the next brow=ymin, then it' s more
  110.   cmp.w    -$4(a3),d6    ; on the right...
  111.   bne.s    .xmax_ymin_ok
  112.   subq.w    #$6,a3    ; It is the upper right brow.
  113. .xmax_ymin_ok:        ; a3 points on the good brow.
  114.  
  115.   move.l    #.xmax_buffer,a2 ; Store int_maxs and xmaxs here.
  116.   move.l    #.inverses,a4    ; Inverse table.
  117.   move.l    #.xmax_ad,a5    ; The adresses for the jump.
  118. .xmax_one_line:        ; Interpolate on one line.
  119.   move.w    (a3),d0    ; d0=x1.
  120.   move.w    $2(a3),d1    ; d1=y1.
  121.   cmp.w    d1,d7    ; y1=ymax?
  122.   beq    .xmax_end    ; Yes, then it' s finished.
  123.   move.w    $4(a3),d2    ; d2=intensity1.
  124.   subq.l    #$6,a3    ; Next brow.
  125.   move.w    (a3),d3    ; d3=x2.
  126.   move.w    $2(a3),d4    ; d4=y2.
  127.   move.w    $4(a3),d5    ; d5=intensity2.
  128.   sub.w    d1,d4    ; d4=y2-y1, always <>0.
  129.   add.w    d4,d4    ; One word per inverse.
  130.   move.w    (a4,d4.w),d1    ; d1=16384/(y2-y1).
  131.   add.w    d4,d4    ; Two words per jump adress.
  132.   move.l    (a5,d4.w),a6    ; a6=adress where to jump.
  133.   sub.w    d2,d5    ; d5=int2-int1.
  134.   muls.w    d1,d5
  135.   lsl.l    #$2,d5    ; d5=65536*(int2-int1)/dy.
  136.   sub.w    d0,d3    ; d3=x2-x1.
  137.   muls.w    d1,d3
  138.   lsl.l    #$2,d3    ; d3=65536*(dx/dy).
  139.   swap.w    d3
  140.   move.w    d3,d5    ; up(d5)=dint/dy ; low(d5)=int(dx/dy).
  141.   swap.w    d3    ; low(d3)=reg(dx/dy).
  142.   swap.w    d2
  143.   move.w    d0,d2    ; up(d2)=intensity ; low(d2)=x.
  144.   moveq.l    #$0,d0    ; d0=error.
  145.   jmp    (a6)
  146.  
  147.  rept    300
  148.   move.l    d2,(a2)+    ; Save intensity and x.
  149.   add.w    d3,d0    ; error=error+reg(dx/dy).
  150.   addx.l    d5,d2    ; int=int+inc ; x=x+int(dy/dx)+eXtend.
  151.  endr
  152. .xmax_line_end:
  153.   subq.w    #$4,a2    ; Erase last point.
  154.   bra    .xmax_one_line
  155. .xmax_end:
  156.  
  157. ; *************************************************************************
  158. ; * Do the same with the min_lines, which are on the right of the poly
  159. ; * and calculate xmin and intensity_min for each y between ymin-ymax by
  160. ; * using linear interpolations.
  161.  
  162.   subq.w    #$6,a1
  163. .xmin_tracking:        ; First, search the upper left brow.
  164.   addq.w    #$6,a1    ; Next point in anticlockwise cycle.
  165.   cmp.w    $2(a1),d6    ; y=ymin?
  166.   bne.s    .xmin_tracking
  167. .xmin_ymin_found:    ; If the next brow=ymin, then it' s more
  168.   cmp.w    $a(a1),d6    ; on the left...
  169.   bne.s    .xmin_ymin_ok
  170.   addq.w    #$6,a3    ; It is the upper left brow.
  171. .xmin_ymin_ok:        ; a1 points on the good brow.
  172.  
  173.   move.l    #.xmin_buffer,a2 ; Store int_mins and xmins here.
  174.   move.l    #.inverses,a4    ; Inverse table.
  175.   move.l    #.xmin_ad,a5    ; The adresses for the jump.
  176. .xmin_one_line:        ; Interpolate on one line.
  177.   move.w    (a1)+,d0    ; d0=x1.
  178.   move.w    (a1)+,d1    ; d1=y1.
  179.   cmp.w    d1,d7    ; y1=ymax?
  180.   beq    .xmin_end    ; Yes, then it' s finished.
  181.   move.w    (a1)+,d2    ; d2=intensity1.
  182.   move.w    (a1),d3    ; d3=x2.
  183.   move.w    $2(a1),d4    ; d4=y2.
  184.   move.w    $4(a1),d5    ; d5=intensity2.
  185.   sub.w    d1,d4    ; d4=y2-y1, always <>0.
  186.   add.w    d4,d4    ; One word per inverse.
  187.   move.w    (a4,d4.w),d1    ; d1=16384/(y2-y1).
  188.   add.w    d4,d4    ; Two words per jump adress.
  189.   move.l    (a5,d4.w),a6    ; a6=adress where to jump.
  190.   sub.w    d2,d5    ; d5=int2-int1.
  191.   muls.w    d1,d5
  192.   lsl.l    #$2,d5    ; d5=65536*(int2-int1)/dy.
  193.   sub.w    d0,d3    ; d3=x2-x1.
  194.   muls.w    d1,d3
  195.   lsl.l    #$2,d3    ; d3=65536*(dx/dy).
  196.   swap.w    d3
  197.   move.w    d3,d5    ; up(d5)=dint/dy ; low(d5)=int(dx/dy).
  198.   swap.w    d3    ; low(d3)=reg(dx/dy).
  199.   swap.w    d2
  200.   move.w    d0,d2    ; up(d2)=intensity ; low(d2)=x.
  201.   moveq.l    #$0,d0    ; d0=error.
  202.   jmp    (a6)
  203.  
  204.  rept    300
  205.   move.l    d2,(a2)+    ; Save intensity and x.
  206.   add.w    d3,d0    ; error=error+reg(dx/dy).
  207.   addx.l    d5,d2    ; int=int+inc ; x=x+int(dy/dx)+eXtend.
  208.  endr
  209. .xmin_line_end:
  210.   subq.w    #$4,a2    ; Erase last point.
  211.   bra    .xmin_one_line
  212. .xmin_end:
  213.  
  214. ; *************************************************************************
  215. ; * Ok, now we have all we want, it' s now time to draw the poly on the
  216. ; * screen. I proceed by drawing each h_line one after another, and as
  217. ; * intensity_min and intensity_max are different, I have to do an
  218. ; * interpolation between them.
  219.  
  220. .draw_shaded:
  221.   move.l    #.xmin_buffer,a1
  222.   move.w    .nb_lines_2_pass,d0
  223.   add.w    d0,d0    ; 4 bytes per int+x.
  224.   add.w    d0,d0
  225.   add.w    d0,a1    ; Pass the invisible lines.
  226.   move.l    #.points_ad,-(sp) ; Store the table x->adress.
  227.   move.l    #.endrouts_ad,-(sp) ; Table xmax mod(16)->endrout adress.
  228.   move.w    .nb_lines_2_draw,d0 ; The counter.
  229.   subq.w    #$1,d0    ; Beware dbra..
  230.   move.w    d0,-(sp)    ; Store the counter.
  231.   move.l    #.inverses,a2
  232. .draw_one_hline:
  233.   move.w    d0,(sp)    ; Store the counter.
  234.   move.w    (a1)+,d5    ; d5=int_min.
  235.   move.w    1198(a1),d6    ; d6=int_max.
  236.   move.w    (a1)+,d0    ; d0=xmin.
  237.   move.w    1198(a1),d1    ; d1=xmax.
  238.   move.w    d1,d2
  239.   sub.w    d0,d2    ; d2=xmax-xmin=dx.
  240.   ble.s    .next_line    ; Don' t draw if xmin>=xmax.
  241.   add.w    d2,d2
  242.   move.w    (a2,d2.w),d2    ; d2=16384/dx.
  243.   sub.w    d5,d6    ; d6=int_max-int_min=dint.
  244.   add.w    d5,d5    ; The intensity in the 4 Msbits...
  245.   muls.w    d2,d6
  246.   lsl.l    #$3,d6    ; d6=2*65536*(dint/dx). No more sign bit.
  247.   swap.w    d6    ; In the lowerword please.
  248.   move.w    d6,d7
  249.   add.w    #$800,d6    ; d6=inc1=0.5+(dint/dx).
  250.   sub.w    #$800,d7    ; d7=inc2=-0.5+(dint/dx).
  251.   move.l    $2(sp),a4    ; a4=endrouts_ad table.
  252.   move.w    d1,d2
  253.   moveq.l    #$f,d3
  254.   and.w    d3,d2    ; d2=xmax mod(16).
  255.   add.w    d2,d2    ; One long per adress.
  256.   add.w    d2,d2
  257.   move.l    (a4,d2.w),a4    ; a4 points on the endrout to use.
  258.   move.l    $6(sp),a5    ; points_ad table.
  259.   and.w    d0,d3    ; d3=xmin mod(16).
  260.   sub.w    d3,d0    ; d0=xmin-xmin mod(16).
  261.   add.w    d3,d3
  262.   add.w    d3,d3
  263.   move.l    (a5,d3.w),a3    ; a3 points on first point.
  264.   sub.w    d0,d1    ; d1=xmax-(xmin-xmin mod(16)).
  265.   add.w    d1,d1
  266.   add.w    d1,d1
  267.   move.l    (a5,d1.w),a5    ; a5 points on last point-1.
  268.   move.w    #$4ed4,(a5)    ; Put the "jump (a4)".
  269.   lsr.w    #$1,d0    ; d0=offset to xmin.
  270.   move.l    a0,a6
  271.   add.w    d0,a6    ; a6 points on first word.
  272.   add.w    #$a0,a0    ; Next line.
  273.   moveq.l    #$0,d1    ; Clear bitplanes.
  274.   moveq.l    #$0,d2
  275.   moveq.l    #$0,d3
  276.   moveq.l    #$0,d4
  277.   jmp    (a3)    ; Go on first point.
  278.   
  279. .next_line:
  280.   move.w    (sp),d0    ; Load the counter.
  281.   dbra    d0,.draw_one_hline
  282.   add.w    #$a,sp    ; Fuck the stored tiddies.
  283. .the_end:
  284.   movem.l    (sp)+,d0-a6
  285.   rts
  286.  
  287. .draw_one_hline2:
  288.   move.w    d0,(sp)    ; Store the counter.
  289.   move.w    (a1)+,d5    ; d5=int_min.
  290.   move.w    1198(a1),d6    ; d6=int_max.
  291.   move.w    (a1)+,d0    ; d0=xmin.
  292.   move.w    1198(a1),d1    ; d1=xmax.
  293.   move.w    d1,d2
  294.   sub.w    d0,d2    ; d2=xmax-xmin=dx.
  295.   ble.s    .next_line2    ; Don' t draw if xmin>=xmax.
  296.   add.w    d2,d2
  297.   move.w    (a2,d2.w),d2    ; d2=16384/dx.
  298.   sub.w    d5,d6    ; d6=int_max-int_min=dint.
  299.   add.w    d5,d5    ; The intensity in the 4 Msbits...
  300.   muls.w    d2,d6
  301.   lsl.l    #$3,d6    ; d6=2*65536*(dint/dx). No more sign bit.
  302.   swap.w    d6    ; In the lowerword please.
  303.   move.w    d6,d7
  304.   sub.w    #$800,d6    ; d6=inc1=0.5+(dint/dx).
  305.   add.w    #$800,d7    ; d7=inc2=-0.5+(dint/dx).
  306.   move.l    $2(sp),a4    ; a4=endrouts_ad table.
  307.   move.w    d1,d2
  308.   moveq.l    #$f,d3
  309.   and.w    d3,d2    ; d2=xmax mod(16).
  310.   add.w    d2,d2    ; One long per adress.
  311.   add.w    d2,d2
  312.   move.l    16*4(a4,d2.w),a4 ; a4 points on the endrout to use.
  313.   move.l    $6(sp),a5    ; points_ad table.
  314.   and.w    d0,d3    ; d3=xmin mod(16).
  315.   sub.w    d3,d0    ; d0=xmin-xmin mod(16).
  316.   add.w    d3,d3
  317.   add.w    d3,d3
  318.   move.l    (a5,d3.w),a3    ; a3 points on first point.
  319.   sub.w    d0,d1    ; d1=xmax-(xmin-xmin mod(16)).
  320.   add.w    d1,d1
  321.   add.w    d1,d1
  322.   move.l    (a5,d1.w),a5    ; a5 points on last point-1.
  323.   move.w    #$4ed4,(a5)    ; Put the "jump (a4)".
  324.   lsr.w    #$1,d0    ; d0=offset to xmin.
  325.   move.l    a0,a6
  326.   add.w    d0,a6    ; a6 points on first word.
  327.   add.w    #$a0,a0    ; Next line.
  328.   moveq.l    #$0,d1    ; Clear bitplanes.
  329.   moveq.l    #$0,d2
  330.   moveq.l    #$0,d3
  331.   moveq.l    #$0,d4
  332.   jmp    (a3)    ; Go on first point.
  333.   
  334. .next_line2:
  335.   move.w    (sp),d0    ; Load the counter.
  336.   dbra    d0,.draw_one_hline
  337.   add.w    #$a,sp    ; Fuck the stored tiddies.
  338. .the_end2:
  339.   movem.l    (sp)+,d0-a6
  340.   rts
  341.  
  342. ; *************************************************************************
  343. ; * We have to use different endroutines in order to gain speed, cos the
  344. ; * ending bitplanes must be rotated and they must be "or.w".
  345.  
  346. shademac1:    MACRO
  347.   add.w    d5,d5
  348.   addx.w    d4,d4
  349.   add.w    d5,d5
  350.   addx.w    d3,d3
  351.   add.w    d5,d5
  352.   addx.w    d2,d2
  353.   add.w    d5,d5
  354.   addx.w    d1,d1
  355.       ENDM
  356.  
  357. shademac2:    MACRO
  358.   and.w    d0,d1
  359.   and.w    d0,d2
  360.   and.w    d0,d3
  361.   and.w    d0,d4
  362.     ENDM
  363.  
  364. shademac3:    MACRO
  365.   or.w    d1,(a6)+
  366.   or.w    d2,(a6)+
  367.   or.w    d3,(a6)+
  368.   or.w    d4,(a6)+
  369.       ENDM
  370.  
  371. shademac4:    MACRO
  372.   move.w    #$3005,(a5)    ; Restore initial code.
  373.   move.w    (sp),d0    ; Load counter.
  374.   dbra    d0,.draw_one_hline2
  375.   add.w    #$a,sp    ; Fuck the stored tiddies.
  376.   movem.l    (sp)+,d0-a6    ; The end.
  377.   rts
  378.     ENDM
  379.  
  380.  
  381. .endrout_0:
  382.   shademac1        ; Convert last point.
  383.   ror.w    #$1,d1    ; Rotate the bitplanes.
  384.   ror.w    #$1,d2
  385.   ror.w    #$1,d3
  386.   ror.w    #$1,d4
  387.   move.w    #$8000,d0    ; For destroying unusefull bits.
  388.   shademac2        ; Fuck them.
  389.   shademac3        ; Print last word.
  390.   shademac4
  391.  
  392. .endrout_1:
  393.   shademac1        ; Convert last point.
  394.   ror.w    #$2,d1    ; Rotate the bitplanes.
  395.   ror.w    #$2,d2
  396.   ror.w    #$2,d3
  397.   ror.w    #$2,d4
  398.   move.w    #$c000,d0    ; For destroying unusefull bits.
  399.   shademac2        ; Fuck them.
  400.   shademac3        ; Print last word.
  401.   shademac4
  402.  
  403. .endrout_2:
  404.   shademac1        ; Convert last point.
  405.   ror.w    #$3,d1    ; Rotate the bitplanes.
  406.   ror.w    #$3,d2
  407.   ror.w    #$3,d3
  408.   ror.w    #$3,d4
  409.   move.w    #$e000,d0    ; For destroying unusefull bits.
  410.   shademac2        ; Fuck them.
  411.   shademac3        ; Print last word.
  412.   shademac4
  413.  
  414. .endrout_3:
  415.   shademac1        ; Convert last point.
  416.   ror.w    #$4,d1    ; Rotate the bitplanes.
  417.   ror.w    #$4,d2
  418.   ror.w    #$4,d3
  419.   ror.w    #$4,d4
  420.   move.w    #$f000,d0    ; For destroying unusefull bits.
  421.   shademac2        ; Fuck them.
  422.   shademac3        ; Print last word.
  423.   shademac4
  424.  
  425. .endrout_4:
  426.   shademac1        ; Convert last point.
  427.   ror.w    #$5,d1    ; Rotate the bitplanes.
  428.   ror.w    #$5,d2
  429.   ror.w    #$5,d3
  430.   ror.w    #$5,d4
  431.   move.w    #$f800,d0    ; For destroying unusefull bits.
  432.   shademac2        ; Fuck them.
  433.   shademac3        ; Print last word.
  434.   shademac4
  435.  
  436. .endrout_5:
  437.   shademac1        ; Convert last point.
  438.   ror.w    #$6,d1    ; Rotate the bitplanes.
  439.   ror.w    #$6,d2
  440.   ror.w    #$6,d3
  441.   ror.w    #$6,d4
  442.   move.w    #$fc00,d0    ; For destroying unusefull bits.
  443.   shademac2        ; Fuck them.
  444.   shademac3        ; Print last word.
  445.   shademac4
  446.  
  447. .endrout_6:
  448.   shademac1        ; Convert last point.
  449.   ror.w    #$7,d1    ; Rotate the bitplanes.
  450.   ror.w    #$7,d2
  451.   ror.w    #$7,d3
  452.   ror.w    #$7,d4
  453.   move.w    #$fe00,d0    ; For destroying unusefull bits.
  454.   shademac2        ; Fuck them.
  455.   shademac3        ; Print last word.
  456.   shademac4
  457.  
  458. .endrout_7:
  459.   shademac1        ; Convert last point.
  460.   lsl.w    #$8,d1    ; Rotate the bitplanes.
  461.   lsl.w    #$8,d2
  462.   lsl.w    #$8,d3
  463.   lsl.w    #$8,d4
  464.   shademac3        ; Print last word.
  465.   shademac4
  466.  
  467. .endrout_8:
  468.   shademac1        ; Convert last point.
  469.   lsl.w    #$7,d1    ; Rotate the bitplanes.
  470.   lsl.w    #$7,d2
  471.   lsl.w    #$7,d3
  472.   lsl.w    #$7,d4
  473.   shademac3        ; Print last word.
  474.   shademac4
  475.  
  476. .endrout_9:
  477.   shademac1        ; Convert last point.
  478.   lsl.w    #$6,d1    ; Rotate the bitplanes.
  479.   lsl.w    #$6,d2
  480.   lsl.w    #$6,d3
  481.   lsl.w    #$6,d4
  482.   shademac3        ; Print last word.
  483.   shademac4
  484.  
  485. .endrout_a:
  486.   shademac1        ; Convert last point.
  487.   lsl.w    #$5,d1    ; Rotate the bitplanes.
  488.   lsl.w    #$5,d2
  489.   lsl.w    #$5,d3
  490.   lsl.w    #$5,d4
  491.   shademac3        ; Print last word.
  492.   shademac4
  493.  
  494. .endrout_b:
  495.   shademac1        ; Convert last point.
  496.   lsl.w    #$4,d1    ; Rotate the bitplanes.
  497.   lsl.w    #$4,d2
  498.   lsl.w    #$4,d3
  499.   lsl.w    #$4,d4
  500.   shademac3        ; Print last word.
  501.   shademac4
  502.  
  503. .endrout_c:
  504.   shademac1        ; Convert last point.
  505.   lsl.w    #$3,d1    ; Rotate the bitplanes.
  506.   lsl.w    #$3,d2
  507.   lsl.w    #$3,d3
  508.   lsl.w    #$3,d4
  509.   shademac3        ; Print last word.
  510.   shademac4
  511.  
  512. .endrout_d:
  513.   shademac1        ; Convert last point.
  514.   lsl.w    #$2,d1    ; Rotate the bitplanes.
  515.   lsl.w    #$2,d2
  516.   lsl.w    #$2,d3
  517.   lsl.w    #$2,d4
  518.   shademac3        ; Print last word.
  519.   shademac4
  520.  
  521. .endrout_e:
  522.   shademac1        ; Convert last point.
  523.   add.w    d1,d1    ; Rotate the bitplanes.
  524.   add.w    d2,d2
  525.   add.w    d3,d3
  526.   add.w    d4,d4
  527.   shademac3        ; Print last word.
  528.   shademac4
  529.  
  530. .endrout_f:
  531.   shademac1        ; Convert last point.
  532.   shademac3
  533.   shademac4
  534.  
  535.  
  536. shademac42:    MACRO
  537.   move.w    #$3005,(a5)    ; Restore initial code.
  538.   move.w    (sp),d0    ; Load counter.
  539.   dbra    d0,.draw_one_hline
  540.   add.w    #$a,sp    ; Fuck the stored tiddies.
  541.   movem.l    (sp)+,d0-a6    ; The end.
  542.   rts
  543.     ENDM
  544.  
  545.  
  546. .endrout_10:
  547.   shademac1        ; Convert last point.
  548.   ror.w    #$1,d1    ; Rotate the bitplanes.
  549.   ror.w    #$1,d2
  550.   ror.w    #$1,d3
  551.   ror.w    #$1,d4
  552.   move.w    #$8000,d0    ; For destroying unusefull bits.
  553.   shademac2        ; Fuck them.
  554.   shademac3        ; Print last word.
  555.   shademac42
  556.  
  557. .endrout_11:
  558.   shademac1        ; Convert last point.
  559.   ror.w    #$2,d1    ; Rotate the bitplanes.
  560.   ror.w    #$2,d2
  561.   ror.w    #$2,d3
  562.   ror.w    #$2,d4
  563.   move.w    #$c000,d0    ; For destroying unusefull bits.
  564.   shademac2        ; Fuck them.
  565.   shademac3        ; Print last word.
  566.   shademac42
  567.  
  568. .endrout_12:
  569.   shademac1        ; Convert last point.
  570.   ror.w    #$3,d1    ; Rotate the bitplanes.
  571.   ror.w    #$3,d2
  572.   ror.w    #$3,d3
  573.   ror.w    #$3,d4
  574.   move.w    #$e000,d0    ; For destroying unusefull bits.
  575.   shademac2        ; Fuck them.
  576.   shademac3        ; Print last word.
  577.   shademac42
  578.  
  579. .endrout_13:
  580.   shademac1        ; Convert last point.
  581.   ror.w    #$4,d1    ; Rotate the bitplanes.
  582.   ror.w    #$4,d2
  583.   ror.w    #$4,d3
  584.   ror.w    #$4,d4
  585.   move.w    #$f000,d0    ; For destroying unusefull bits.
  586.   shademac2        ; Fuck them.
  587.   shademac3        ; Print last word.
  588.   shademac42
  589.  
  590. .endrout_14:
  591.   shademac1        ; Convert last point.
  592.   ror.w    #$5,d1    ; Rotate the bitplanes.
  593.   ror.w    #$5,d2
  594.   ror.w    #$5,d3
  595.   ror.w    #$5,d4
  596.   move.w    #$f800,d0    ; For destroying unusefull bits.
  597.   shademac2        ; Fuck them.
  598.   shademac3        ; Print last word.
  599.   shademac42
  600.  
  601. .endrout_15:
  602.   shademac1        ; Convert last point.
  603.   ror.w    #$6,d1    ; Rotate the bitplanes.
  604.   ror.w    #$6,d2
  605.   ror.w    #$6,d3
  606.   ror.w    #$6,d4
  607.   move.w    #$fc00,d0    ; For destroying unusefull bits.
  608.   shademac2        ; Fuck them.
  609.   shademac3        ; Print last word.
  610.   shademac42
  611.  
  612. .endrout_16:
  613.   shademac1        ; Convert last point.
  614.   ror.w    #$7,d1    ; Rotate the bitplanes.
  615.   ror.w    #$7,d2
  616.   ror.w    #$7,d3
  617.   ror.w    #$7,d4
  618.   move.w    #$fe00,d0    ; For destroying unusefull bits.
  619.   shademac2        ; Fuck them.
  620.   shademac3        ; Print last word.
  621.   shademac42
  622.  
  623. .endrout_17:
  624.   shademac1        ; Convert last point.
  625.   lsl.w    #$8,d1    ; Rotate the bitplanes.
  626.   lsl.w    #$8,d2
  627.   lsl.w    #$8,d3
  628.   lsl.w    #$8,d4
  629.   shademac3        ; Print last word.
  630.   shademac42
  631.  
  632. .endrout_18:
  633.   shademac1        ; Convert last point.
  634.   lsl.w    #$7,d1    ; Rotate the bitplanes.
  635.   lsl.w    #$7,d2
  636.   lsl.w    #$7,d3
  637.   lsl.w    #$7,d4
  638.   shademac3        ; Print last word.
  639.   shademac42
  640.  
  641. .endrout_19:
  642.   shademac1        ; Convert last point.
  643.   lsl.w    #$6,d1    ; Rotate the bitplanes.
  644.   lsl.w    #$6,d2
  645.   lsl.w    #$6,d3
  646.   lsl.w    #$6,d4
  647.   shademac3        ; Print last word.
  648.   shademac42
  649.  
  650. .endrout_1a:
  651.   shademac1        ; Convert last point.
  652.   lsl.w    #$5,d1    ; Rotate the bitplanes.
  653.   lsl.w    #$5,d2
  654.   lsl.w    #$5,d3
  655.   lsl.w    #$5,d4
  656.   shademac3        ; Print last word.
  657.   shademac42
  658.  
  659. .endrout_1b:
  660.   shademac1        ; Convert last point.
  661.   lsl.w    #$4,d1    ; Rotate the bitplanes.
  662.   lsl.w    #$4,d2
  663.   lsl.w    #$4,d3
  664.   lsl.w    #$4,d4
  665.   shademac3        ; Print last word.
  666.   shademac42
  667.  
  668. .endrout_1c:
  669.   shademac1        ; Convert last point.
  670.   lsl.w    #$3,d1    ; Rotate the bitplanes.
  671.   lsl.w    #$3,d2
  672.   lsl.w    #$3,d3
  673.   lsl.w    #$3,d4
  674.   shademac3        ; Print last word.
  675.   shademac42
  676.  
  677. .endrout_1d:
  678.   shademac1        ; Convert last point.
  679.   lsl.w    #$2,d1    ; Rotate the bitplanes.
  680.   lsl.w    #$2,d2
  681.   lsl.w    #$2,d3
  682.   lsl.w    #$2,d4
  683.   shademac3        ; Print last word.
  684.   shademac42
  685.  
  686. .endrout_1e:
  687.   shademac1        ; Convert last point.
  688.   add.w    d1,d1    ; Rotate the bitplanes.
  689.   add.w    d2,d2
  690.   add.w    d3,d3
  691.   add.w    d4,d4
  692.   shademac3        ; Print last word.
  693.   shademac42
  694.  
  695. .endrout_1f:
  696.   shademac1        ; Convert last point.
  697.   shademac3
  698.   shademac42
  699.  
  700. ; *************************************************************************
  701. ; * The core of the shading poly routine... Very repetitive, cos I don' t
  702. ; * like the dbra and I LOOOOooove Speed....
  703.  
  704. shademac5:    MACRO
  705.   move.w    d5,d0    ; Convert first point.
  706.   add.w    d0,d0
  707.   addx.w    d4,d4
  708.   add.w    d0,d0
  709.   addx.w    d3,d3
  710.   add.w    d0,d0
  711.   addx.w    d2,d2
  712.   add.w    d0,d0
  713.   addx.w    d1,d1
  714.   add.w    d6,d5    ; intensity=intensity+increment1.
  715.   move.w    d5,d0    ; Convert second point.
  716.   add.w    d0,d0
  717.   addx.w    d4,d4
  718.   add.w    d0,d0
  719.   addx.w    d3,d3
  720.   add.w    d0,d0
  721.   addx.w    d2,d2
  722.   add.w    d0,d0
  723.   addx.w    d1,d1
  724.   add.w    d7,d5    ; intensity=intensity+increment2.
  725.   move.w    d5,d0
  726.   add.w    d0,d0
  727.   addx.w    d4,d4
  728.   add.w    d0,d0
  729.   addx.w    d3,d3
  730.   add.w    d0,d0
  731.   addx.w    d2,d2
  732.   add.w    d0,d0
  733.   addx.w    d1,d1
  734.   add.w    d6,d5    ; intensity=intensity+increment1.
  735.   move.w    d5,d0
  736.   add.w    d0,d0
  737.   addx.w    d4,d4
  738.   add.w    d0,d0
  739.   addx.w    d3,d3
  740.   add.w    d0,d0
  741.   addx.w    d2,d2
  742.   add.w    d0,d0
  743.   addx.w    d1,d1
  744.   add.w    d7,d5
  745.   move.w    d5,d0
  746.   add.w    d0,d0
  747.   addx.w    d4,d4
  748.   add.w    d0,d0
  749.   addx.w    d3,d3
  750.   add.w    d0,d0
  751.   addx.w    d2,d2
  752.   add.w    d0,d0
  753.   addx.w    d1,d1
  754.   add.w    d6,d5    ; intensity=intensity+increment1.
  755.   move.w    d5,d0
  756.   add.w    d0,d0
  757.   addx.w    d4,d4
  758.   add.w    d0,d0
  759.   addx.w    d3,d3
  760.   add.w    d0,d0
  761.   addx.w    d2,d2
  762.   add.w    d0,d0
  763.   addx.w    d1,d1
  764.   add.w    d7,d5    ; intensity=intensity+increment2.
  765.   move.w    d5,d0
  766.   add.w    d0,d0
  767.   addx.w    d4,d4
  768.   add.w    d0,d0
  769.   addx.w    d3,d3
  770.   add.w    d0,d0
  771.   addx.w    d2,d2
  772.   add.w    d0,d0
  773.   addx.w    d1,d1
  774.   add.w    d6,d5    ; intensity=intensity+increment1.
  775.   move.w    d5,d0
  776.   add.w    d0,d0
  777.   addx.w    d4,d4
  778.   add.w    d0,d0
  779.   addx.w    d3,d3
  780.   add.w    d0,d0
  781.   addx.w    d2,d2
  782.   add.w    d0,d0
  783.   addx.w    d1,d1
  784.   add.w    d7,d5    ; Intensity=intensity+increment2.
  785.   move.w    d5,d0
  786.   add.w    d0,d0
  787.   addx.w    d4,d4
  788.   add.w    d0,d0
  789.   addx.w    d3,d3
  790.   add.w    d0,d0
  791.   addx.w    d2,d2
  792.   add.w    d0,d0
  793.   addx.w    d1,d1
  794.   add.w    d6,d5    ; intensity=intensity+increment1.
  795.   move.w    d5,d0
  796.   add.w    d0,d0
  797.   addx.w    d4,d4
  798.   add.w    d0,d0
  799.   addx.w    d3,d3
  800.   add.w    d0,d0
  801.   addx.w    d2,d2
  802.   add.w    d0,d0
  803.   addx.w    d1,d1
  804.   add.w    d7,d5    ; intensity=intensity+increment2.
  805.   move.w    d5,d0
  806.   add.w    d0,d0
  807.   addx.w    d4,d4
  808.   add.w    d0,d0
  809.   addx.w    d3,d3
  810.   add.w    d0,d0
  811.   addx.w    d2,d2
  812.   add.w    d0,d0
  813.   addx.w    d1,d1
  814.   add.w    d6,d5    ; intensity=intensity+increment1.
  815.   move.w    d5,d0
  816.   add.w    d0,d0
  817.   addx.w    d4,d4
  818.   add.w    d0,d0
  819.   addx.w    d3,d3
  820.   add.w    d0,d0
  821.   addx.w    d2,d2
  822.   add.w    d0,d0
  823.   addx.w    d1,d1
  824.   add.w    d7,d5
  825.   move.w    d5,d0
  826.   add.w    d0,d0
  827.   addx.w    d4,d4
  828.   add.w    d0,d0
  829.   addx.w    d3,d3
  830.   add.w    d0,d0
  831.   addx.w    d2,d2
  832.   add.w    d0,d0
  833.   addx.w    d1,d1
  834.   add.w    d6,d5    ; intensity=intensity+increment1.
  835.   move.w    d5,d0
  836.   add.w    d0,d0
  837.   addx.w    d4,d4
  838.   add.w    d0,d0
  839.   addx.w    d3,d3
  840.   add.w    d0,d0
  841.   addx.w    d2,d2
  842.   add.w    d0,d0
  843.   addx.w    d1,d1
  844.   add.w    d7,d5    ; intensity=intensity+increment2.
  845.   move.w    d5,d0
  846.   add.w    d0,d0
  847.   addx.w    d4,d4
  848.   add.w    d0,d0
  849.   addx.w    d3,d3
  850.   add.w    d0,d0
  851.   addx.w    d2,d2
  852.   add.w    d0,d0
  853.   addx.w    d1,d1
  854.   add.w    d6,d5    ; intensity=intensity+increment1.
  855.   move.w    d5,d0
  856.   add.w    d0,d0
  857.   addx.w    d4,d4
  858.   add.w    d0,d0
  859.   addx.w    d3,d3
  860.   add.w    d0,d0
  861.   addx.w    d2,d2
  862.   add.w    d0,d0
  863.   addx.w    d1,d1
  864.   add.w    d7,d5    ; Intensity=intensity+increment2.
  865.     ENDM
  866.  
  867. .core:
  868.   shademac5        ; 16 pixies.
  869.   or.w    d1,(a6)+    ; Print first bitlanes.
  870.   or.w    d2,(a6)+
  871.   or.w    d3,(a6)+
  872.   or.w    d4,(a6)+
  873.  
  874. .core_2:
  875.   shademac5        ; Do 16 pixies.
  876.   movem.w    d1-d4,(a6)    ; Store planes.
  877.   addq.w    #$8,a6
  878.   shademac5
  879.   movem.w    d1-d4,(a6)
  880.   addq.w    #$8,a6
  881.   shademac5
  882.   movem.w    d1-d4,(a6)
  883.   addq.w    #$8,a6
  884.   shademac5
  885.   movem.w    d1-d4,(a6)
  886.   addq.w    #$8,a6
  887.   shademac5
  888.   movem.w    d1-d4,(a6)
  889.   addq.w    #$8,a6
  890.   shademac5
  891.   movem.w    d1-d4,(a6)
  892.   addq.w    #$8,a6
  893.   shademac5
  894.   movem.w    d1-d4,(a6)
  895.   addq.w    #$8,a6
  896.   shademac5
  897.   movem.w    d1-d4,(a6)
  898.   addq.w    #$8,a6
  899.   shademac5
  900.   movem.w    d1-d4,(a6)
  901.   addq.w    #$8,a6
  902.   shademac5
  903.   movem.w    d1-d4,(a6)
  904.   addq.w    #$8,a6
  905.   shademac5
  906.   movem.w    d1-d4,(a6)
  907.   addq.w    #$8,a6
  908.   shademac5
  909.   movem.w    d1-d4,(a6)
  910.   addq.w    #$8,a6
  911.   shademac5
  912.   movem.w    d1-d4,(a6)
  913.   addq.w    #$8,a6
  914.   shademac5
  915.   movem.w    d1-d4,(a6)
  916.   addq.w    #$8,a6
  917.   shademac5
  918.   movem.w    d1-d4,(a6)
  919.   addq.w    #$8,a6
  920.  
  921.  
  922. ; *************************************************************************
  923.   Section DATA
  924.   
  925. .y_table:        ; Table for y->y*160 conversions.
  926. N set 0
  927.  rept    200
  928.   dc.w    N  
  929. N set N+160
  930.  endr
  931.  
  932. .inverses:        ; Table n->16384/n.
  933.   incbin    'a:\shading\inverses.xxx'
  934.  
  935. .xmax_ad:        ; Table of adresses for the jump.
  936. N set 6
  937.  rept    300
  938.   dc.l    .xmax_line_end-N
  939. N set N+6
  940.  endr
  941.  
  942. .xmin_ad:        ; The same for the xmin tracking.
  943. N set 6
  944.  rept    300
  945.   dc.l    .xmin_line_end-N
  946. N set N+6
  947.  endr
  948.  
  949. .points_ad:        ; Convert x->adress in the "core".
  950. N set 0        ; For the first 16 pixies.
  951.  rept    16
  952.   dc.l    .core+N
  953. N set N+20
  954.  endr
  955. N set 0        ; For the next ones.
  956.  rept    15    ; 240 points.
  957.   dc.l    .core_2+000+N,.core_2+020+N
  958.   dc.l    .core_2+040+N,.core_2+060+N
  959.   dc.l    .core_2+080+N,.core_2+100+N
  960.   dc.l    .core_2+120+N,.core_2+140+N
  961.   dc.l    .core_2+160+N,.core_2+180+N
  962.   dc.l    .core_2+200+N,.core_2+220+N
  963.   dc.l    .core_2+240+N,.core_2+260+N
  964.   dc.l    .core_2+280+N,.core_2+300+N
  965. N set N+320+6
  966.  endr
  967.  
  968. .endrouts_ad:        ; Table for the endrouts adresses. 
  969.   dc.l    .endrout_0,.endrout_1,.endrout_2,.endrout_3
  970.   dc.l    .endrout_4,.endrout_5,.endrout_6,.endrout_7
  971.   dc.l    .endrout_8,.endrout_9,.endrout_a,.endrout_b
  972.   dc.l    .endrout_c,.endrout_d,.endrout_e,.endrout_f
  973.   dc.l    .endrout_10,.endrout_11,.endrout_12,.endrout_13
  974.   dc.l    .endrout_14,.endrout_15,.endrout_16,.endrout_17
  975.   dc.l    .endrout_18,.endrout_19,.endrout_1a,.endrout_1b
  976.   dc.l    .endrout_1c,.endrout_1d,.endrout_1e,.endrout_1f
  977.    
  978.  
  979. ; *************************************************************************
  980.   Section BSS
  981.   
  982. .nb_lines_2_pass:    ; This two vars are used for the clipping.
  983.   ds.w    1
  984. .nb_lines_2_draw:
  985.   ds.w    1
  986. .xmin_buffer:
  987.   ds.l    300
  988. .xmax_buffer:
  989.   ds.l    300
  990.