home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #2 / amigaacscoverdisc1998-021998.iso / games / doom / adoom / src / amiga_draw.s next >
Text File  |  1998-01-08  |  17KB  |  780 lines

  1.         mc68020
  2.             multipass
  3.         debug    on,lattice4
  4.  
  5.         xdef    @R_DrawColumn_040
  6.         xdef    @R_DrawSpan_040
  7.         xdef    @R_DrawColumn_060
  8.         xdef    @R_DrawSpan_060
  9.  
  10.         xref    _dc_yl
  11.         xref    _dc_yh
  12.         xref    _dc_x
  13.         xref    _columnofs
  14.         xref    _ylookup
  15.         xref    _dc_iscale
  16.         xref    _centery
  17.         xref    _dc_texturemid
  18.         xref    _dc_source
  19.         xref    _dc_colormap
  20.         xref    _ds_xfrac
  21.         xref    _ds_yfrac
  22.         xref    _ds_x1
  23.         xref    _ds_y
  24.         xref    _ds_x2
  25.         xref    _ds_xstep
  26.         xref    _ds_ystep
  27.         xref    _ds_source
  28.         xref    _ds_colormap
  29.  
  30. SCREENWIDTH equ 320
  31. FRACBITS    equ 16
  32.  
  33. ;***********************************************************************
  34. ;@R_DrawColumn  movem.l d3-d7/a2-a5,-(sp)
  35. ;       move.l  (_dc_yl),d0
  36. ;       move.l  (_dc_yh),d7
  37. ;       sub.l   d0,d7
  38. ;       bmi.b   1$
  39. ;       move.l  (_dc_x),d1
  40. ;       lea (_columnofs),a5
  41. ;       lea (a5,d1.l*4),a1
  42. ;       lea (_ylookup),a5
  43. ;       movea.l (a5,d0.l*4),a2
  44. ;       adda.l  (a1),a2
  45. ;       move.l  (_dc_iscale),d6
  46. ;       sub.l   (_centery),d0
  47. ;       muls.l  d6,d0
  48. ;       move.l  (_dc_texturemid),d5
  49. ;       add.l   d0,d5
  50. ;       movea.l (_dc_source),a3
  51. ;       movea.l (_dc_colormap),a4
  52. ;       moveq   #127,d4
  53. ;       move.l  #SCREENWIDTH,d3
  54. ;       moveq   #0,d1       ; ensure high bits of d1 are clear
  55. ;
  56. ;;2$        move.l  d5,d0       ; frac
  57. ;;      swap    d0
  58. ;;      and.w   d4,d0       ; (frac>>16)&127
  59. ;;      move.b  (a3,d0.w),d1    ; dc_source[(frac>>FRACBITS)&127]
  60. ;;      move.b  (a4,d1.w),(a2)  ; *dest = dc_colormap[d1]
  61. ;;      adda.l  d3,a2       ; dest += SCREENWIDTH
  62. ;;      add.l   d6,d5       ; frac += fracstep
  63. ;;      dbra    d7,2$
  64. ;;1$        movem.l (sp)+,d3-d7/a2-a5
  65. ;;      rts
  66. ;
  67. ;; faster routine from j.selck@flensburg.netsurf.de:
  68. ;
  69. ;       add.w   d6,d5       ; frac += fracstep (also sets X flag)
  70. ;       swap    d5      ; swap(frac)
  71. ;       swap    d6      ; swap(fracstep)
  72. ;       and.w   d4,d5       ; (frac>>16)&127
  73. ;2$     move.b  (a3,d5.w),d1    ; dc_source[(frac>>FRACBITS)&127]
  74. ;       move.b  (a4,d1.w),(a2)  ; *dest = dc_colormap[d1]
  75. ;       addx.l  d6,d5       ; swap(frac += fracstep), use & set X
  76. ;       adda.l  d3,a2       ; dest += SCREENWIDTH
  77. ;       and.w   d4,d5       ; (frac>>16)&127
  78. ;       dbra    d7,2$       ; !! dbra slow on 68060 !!
  79. ;1$     movem.l (sp)+,d3-d7/a2-a5
  80. ;       rts
  81.  
  82.  
  83. ; This even faster version by Aki M Laukkanen <amlaukka@cc.helsinki.fi>
  84.  
  85.         cnop    0,4
  86.  
  87. @R_DrawColumn_060
  88.         movem.l d2-d3/d5-d7/a2/a3,-(sp)
  89.  
  90.         move.l  (_dc_yh),d7     ; count = _dc_yh - _dc_yl
  91.         move.l  (_dc_yl),d0
  92.         sub.l   d0,d7
  93.         bmi     .end
  94.  
  95.         move.l  (_dc_x),d1      ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  96.         lea     (_ylookup),a0
  97.         move.l  (a0,d0.l*4),a0
  98.         lea     (_columnofs),a1
  99.         add.l   (a1,d1.l*4),a0
  100.  
  101.         move.l  (_dc_colormap),a2
  102.         move.l  (_dc_source),a1
  103.  
  104.         move.l  (_dc_iscale),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  105.         sub.l   (_centery),d0
  106.         muls.l  d1,d0
  107.         add.l   (_dc_texturemid),d0
  108.  
  109.         moveq   #$7f,d3
  110.         move.l  #SCREENWIDTH,a3
  111.  
  112.         move.l  d7,d6           ; Do the leftover iterations in
  113.         and.w   #3,d6           ; this loop.
  114.         beq     .skip
  115. .skip_loop
  116.         move.l  d0,d5
  117.         swap    d5
  118.         and.l   d3,d5
  119.         move.b  (a1,d5.w),d5
  120.         add.l   d1,d0
  121.         move.b  (a2,d5.w),(a0)
  122.         add.l   a3,a0
  123.         subq.l  #1,d6
  124.         bne     .skip_loop
  125.  
  126. ; d7: cnt >> 2
  127. ; a0: chunky
  128. ; a1: texture
  129. ; a2: light_table
  130. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  131. ; d1: dfrac*2   (.......................................)
  132. ; d2: frac+dfrac(.......................................)
  133. ; d3: $7f
  134. ; a3: SCREENWIDTH
  135.  
  136. .skip
  137.         lsr.l   #2,d7
  138.         subq.l  #1,d7
  139.         bmi     .end
  140.  
  141.         add.l   a3,a3
  142.  
  143.         move.l  d0,d2
  144.         add.l   a3,a3
  145.         add.l   d1,d2
  146.         add.l   d1,d1
  147.  
  148.         eor.w   d0,d2           ; swap the fraction part for addx
  149.         eor.w   d2,d0           ; assuming 16.16 fixed point
  150.         eor.w   d0,d2
  151.  
  152.         swap    d0              ; swap decimals and fraction
  153.         swap    d1
  154.         swap    d2
  155.  
  156.         moveq   #0,d5
  157.         and.w   d3,d2
  158.         and.w   d3,d0
  159.  
  160.         sub.w   d1,d0
  161.         add.l   d1,d0           ; setup the X flag
  162.  
  163.         move.b  (a1,d2.w),d5
  164. .loop
  165.         ; This should be reasonably scheduled for
  166.         ; m68060. It should perform well on other processors
  167.         ; too. That AGU stall still bothers me though.
  168.  
  169.         move.b  (a1,d0.w),d6        ; stall + pOEP but allows sOEP
  170.         addx.l  d1,d2               ; pOEP only
  171.         move.b  (a2,d5.l),d5        ; pOEP but allows sOEP
  172.         and.w   d3,d2               ; sOEP
  173.         move.b  (a2,d6.l),d6        ; pOEP but allows sOEP
  174.         move.b  d5,(SCREENWIDTH,a0) ; sOEP
  175.         addx.l  d1,d0               ; pOEP only
  176.         move.b  (a1,d2.w),d5        ; pOEP but allows sOEP
  177.         and.w   d3,d0               ; sOEP
  178.         move.b  d6,(a0)             ; pOEP
  179.                         ; = ~4 cycles/pixel
  180.                         ; + cache misses
  181.  
  182.         ; The vertical writes are the true timehog of the loop
  183.         ; because of the characteristics of the copyback cache
  184.         ; operation.
  185.         
  186.         ; Better mark the chunky buffer as write through
  187.         ; with the MMU and have all the horizontal writes
  188.         ; be longs aligned to longword boundary.
  189.  
  190.         move.b  (a1,d0.w),d6
  191.         addx.l  d1,d2
  192.         move.b  (a2,d5.l),d5
  193.         and.w   d3,d2
  194.         move.b  (a2,d6.l),d6
  195.         move.b  d5,(SCREENWIDTH*3,a0)
  196.         addx.l  d1,d0
  197.         move.b  (a1,d2.w),d5
  198.         and.w   d3,d0
  199.         move.b  d6,(SCREENWIDTH*2,a0)
  200.  
  201.         add.l   a3,a0
  202. .loop_end
  203.         dbf d7,.loop
  204.  
  205.         ; it's faster to divide it to two lines on 060
  206.         ; and shouldn't be slower on 040.
  207.  
  208.         move.b  (a1,d0.w),d6    ; new
  209.         move.b  (a2,d6.l),d6    ; new
  210.         move.b  d6,(a0)     ; new
  211.  
  212. .end
  213.         movem.l (sp)+,d2-d3/d5-d7/a2/a3
  214.         rts
  215.  
  216.         cnop    0,4
  217.  
  218. ; 030/040 version
  219.  
  220. @R_DrawColumn_040
  221.         movem.l d2-d4/d6-d7/a2/a3,-(sp)
  222.  
  223.         move.l  (_dc_yh),d7     ; count = _dc_yh - _dc_yl
  224.         move.l  (_dc_yl),d0
  225.         sub.l   d0,d7
  226.         bmi     .end
  227.         addq.l  #1,d7
  228.  
  229.         move.l  (_dc_x),d1      ; dest = ylookup[_dc_yl] + columnofs[_dc_x]
  230.         lea     (_ylookup),a0
  231.         move.l  (a0,d0.l*4),a0
  232.         lea     (_columnofs),a1
  233.         add.l   (a1,d1.l*4),a0
  234.  
  235.         move.l  (_dc_colormap),d4
  236.         move.l  (_dc_source),a1
  237.  
  238.         move.l  (_dc_iscale),d1 ; frac = _dc_texturemid + (_dc_yl-centery)*fracstep
  239.         sub.l   (_centery),d0
  240.         muls.l  d1,d0
  241.         add.l   (_dc_texturemid),d0
  242.  
  243.         moveq   #$7f,d3
  244.         move.l  #SCREENWIDTH,a3
  245.  
  246.         move.l  d7,d6           ; Do the leftover iterations in
  247.         and.w   #3,d6           ; this loop.
  248.         beq     .skip
  249. .skip_loop
  250.         move.l  d0,d2
  251.         swap    d2
  252.         and.l   d3,d2
  253.         move.b  (a1,d2.w),d4
  254.         move.l  d4,a2
  255.         move.b  (a2),(a0)
  256.         add.l   d1,d0
  257.         add.l   a3,a0
  258.         subq.l  #1,d6
  259.         bne     .skip_loop
  260.  
  261. ; d7: cnt >> 2
  262. ; a0: chunky
  263. ; a1: texture
  264. ; d0: frac  (uuuu uuuu uuuu uuuu 0000 0000 0UUU UUUU)
  265. ; d1: dfrac (.......................................)
  266. ; d3: $7f
  267. ; d4: light table aligned to 256 byte boundary
  268. ; a3: SCREENWIDTH
  269.  
  270. .skip
  271.         lsr.l   #2,d7
  272.         subq.l  #1,d7
  273.         bmi     .end
  274.  
  275.         add.l   a3,a3
  276.         add.l   a3,a3
  277.  
  278.         swap    d0              ; swap decimals and fraction
  279.         swap    d1
  280.  
  281.         and.w   d3,d0
  282.  
  283.         sub.w   d1,d0
  284.         add.l   d1,d0           ; setup the X flag
  285.  
  286. .loop
  287.         move.b  (a1,d0.w),d4
  288.         addx.l  d1,d0
  289.         move.l  d4,a2
  290.         and.w   d3,d0
  291.         move.b  (a2),(a0)
  292.         move.b  (a1,d0.w),d4
  293.         addx.l  d1,d0
  294.         move.l  d4,a2
  295.         and.w   d3,d0
  296.         move.b  (a2),(SCREENWIDTH,a0)
  297.         move.b  (a1,d0.w),d4
  298.         addx.l  d1,d0
  299.         move.l  d4,a2
  300.         and.w   d3,d0
  301.         move.b  (a2),(SCREENWIDTH*2,a0)
  302.         move.b  (a1,d0.w),d4
  303.         addx.l  d1,d0
  304.         move.l  d4,a2
  305.         and.w   d3,d0
  306.         move.b  (a2),(SCREENWIDTH*3,a0)
  307.  
  308.         add.l   a3,a0
  309. .loop_end
  310.         dbf d7,.loop
  311. .end
  312.         movem.l (sp)+,d2-d4/d6-d7/a2/a3
  313.         rts
  314.  
  315.  
  316. ;void R_DrawColumn (void)
  317. ;{
  318. ;  int count;
  319. ;  byte* dest;
  320. ;  fixed_t frac;
  321. ;  fixed_t fracstep;
  322. ;
  323. ;  count = dc_yh - dc_yl;
  324. ;  if (count < 0)
  325. ;    return;
  326. ;  dest = ylookup[dc_yl] + columnofs[dc_x];
  327. ;  fracstep = dc_iscale;
  328. ;  frac = dc_texturemid + (dc_yl-centery)*fracstep;
  329. ;  do {
  330. ;    *dest = dc_colormap[dc_source[(frac>>FRACBITS)&127]];
  331. ;    dest += SCREENWIDTH;
  332. ;    frac += fracstep;
  333. ;  } while (count--);
  334. ;}
  335.  
  336. ;***********************************************************************
  337. ;@R_DrawSpan    movem.l d2-d7/a2-a5,-(a7)
  338. ;       move.l  (_ds_x1),d0
  339. ;       lea (_columnofs),a5
  340. ;       lea (a5,d0.l*4),a1
  341. ;       move.l  (_ds_y),d1
  342. ;       lea (_ylookup),a5
  343. ;       movea.l (a5,d1.l*4),a2
  344. ;       adda.l  (a1),a2
  345. ;       move.l  (_ds_x2),d5
  346. ;       sub.l   d0,d5       ; count
  347. ;       movea.l (_ds_source),a3
  348. ;       movea.l (_ds_colormap),a4
  349. ;       move.l  (_ds_xstep),d3
  350. ;       move.l  (_ds_ystep),d4
  351. ;;-
  352. ;       moveq   #10,d2
  353. ;       moveq   #63,d6
  354. ;       move.l  #63*64,d7
  355. ;       movea.l (_ds_xfrac),a0  ; xfrac
  356. ;       movea.l (_ds_yfrac),a1  ; yfrac
  357. ;1$     move.l  a0,d0       ; xfrac
  358. ;       swap    d0
  359. ;       and.l   d6,d0       ; (xfrac>>16)&63
  360. ;       move.l  a1,d1       ; yfrac
  361. ;       asr.l   d2,d1
  362. ;       and.l   d7,d1       ; (yfrac>>10)&(63*64)
  363. ;       add.l   d0,d1       ; spot
  364. ;       moveq   #0,d0
  365. ;       move.b  (a3,d1.l),d0    ; ds_source[spot]
  366. ;       move.b  (a4,d0.w),(a2)+ ; *dest++ = ds_colormap[...]
  367. ;       adda.l  d3,a0       ; xfrac += ds_xstep
  368. ;       adda.l  d4,a1       ; yfrac += ds_ystep
  369. ;       dbra    d5,1$
  370. ;       movem.l (a7)+,d2-d7/a2-a5
  371. ;       rts
  372.  
  373. ; This faster version by Aki M Laukkanen <amlaukka@cc.helsinki.fi>
  374.  
  375.         cnop    0,4
  376.  
  377. @R_DrawSpan_060
  378.         movem.l d2-d7/a2/a3,-(sp)
  379.  
  380.         move.l  (_ds_y),d0
  381.         move.l  (_ds_x1),d1     ; dest = ylookup[_ds_y] + columnofs[_ds_x1]
  382.         lea     (_ylookup),a0
  383.         move.l  (a0,d0.l*4),a0
  384.         lea     (_columnofs),a1
  385.         add.l   (a1,d1.l*4),a0
  386.  
  387.         move.l  (_ds_source),a1
  388.         move.l  (_ds_colormap),a2
  389.  
  390.         move.l  (_ds_x2),d7     ; count = _ds_x2 - _ds_x1
  391.         sub.l   d1,d7
  392.         addq.l  #1,d7
  393.  
  394.         move.l  (_ds_xfrac),d0
  395.         move.l  (_ds_yfrac),d1
  396.         move.l  (_ds_xstep),d2
  397.         move.l  (_ds_ystep),d3
  398.  
  399.         move.l  a0,d4
  400.         btst    #0,d4
  401.         beq     .skipb
  402.  
  403.         move.l  d0,d5           ; do the unaligned pixels
  404.         move.l  d1,d6           ; so we can write to longword
  405.         swap    d5              ; boundary in the main loop
  406.         swap    d6
  407.         and.w   #$3f,d5
  408.         and.w   #$3f,d6
  409.         lsl.w   #6,d6
  410.         or.w    d5,d6
  411.         move.b  (a1,d6.w),d5
  412.         add.l   d2,d0
  413.         move.b  (a2,d5.w),(a0)+
  414.         add.l   d3,d1
  415.         move.l  a0,d4
  416.         subq.l  #1,d7
  417. .skipb
  418.         btst    #1,d4
  419.         beq     .skips
  420.         moveq   #2,d4
  421.         cmp.l   d4,d7
  422.         bls     .skips
  423.  
  424.         move.l  d0,d5           ; write two pixels
  425.         move.l  d1,d6
  426.         swap    d5
  427.         swap    d6
  428.         and.w   #$3f,d5
  429.         and.w   #$3f,d6
  430.         lsl.w   #6,d6
  431.         or.w    d5,d6
  432.         move.b  (a1,d6.w),d5
  433.         move.w  (a2,d5.w),d4
  434.         add.l   d2,d0
  435.         add.l   d3,d1
  436.         move.l  d0,d5
  437.         move.l  d1,d6
  438.         swap    d5
  439.         swap    d6
  440.         and.w   #$3f,d5
  441.         and.w   #$3f,d6
  442.         lsl.w   #6,d6
  443.         or.w    d5,d6
  444.         move.b  (a1,d6.w),d5
  445.         move.b  (a2,d5.w),d4
  446.         add.l   d2,d0
  447.         move.w  d4,(a0)+
  448.         add.l   d3,d1
  449.         subq.l  #2,d7
  450. .skips
  451.  
  452. ; a0: chunky
  453. ; a1: texture
  454. ; a2: light_table
  455. ; d7: count >> 2 
  456. ; d0: xfrac (vvvv vvvv vvvv vvvv 1111 1111 11UU UUUU)
  457. ; d1: yfrac (uuuu uuuu uuuu uuuu 1111 VVVV VV11 1111)
  458. ; d2: dxfrac
  459. ; d3: dyfrac
  460.  
  461.         move.l  d7,d6           ; setup registers
  462.         and.w   #3,d6
  463.         move.l  d6,a3
  464.  
  465.         eor.w   d0,d1           ; swap fraction parts for addx
  466.         eor.w   d2,d3
  467.         eor.w   d1,d0
  468.         eor.w   d3,d2
  469.         eor.w   d0,d1
  470.         eor.w   d2,d3
  471.  
  472.         swap    d0
  473.         swap    d1
  474.         swap    d2
  475.         swap    d3
  476.  
  477.         lsl.w   #6,d1
  478.         lsl.w   #6,d3
  479.  
  480.         moveq   #0,d6
  481.         moveq   #0,d5
  482.  
  483.         sub.l   #$f000,a1
  484.  
  485.         lsr.l   #2,d7
  486.         beq     .skip_loop2
  487.         subq.l  #1,d7
  488.  
  489.         sub.w   d3,d1
  490.         add.l   d3,d1           ; setup the X flag
  491.  
  492.         or.w    #$ffc0,d0
  493.         or.w    #$f03f,d1
  494.  
  495.         move.w  d0,d6
  496.         and.w   d1,d6
  497.         bra     .start_loop2
  498.  
  499.         cnop    0,8
  500. .loop2
  501.         ; This should be reasonably scheduled for m68060.
  502.         ; It writes long words to long word aligned locations.
  503.         ; First of all that's the optimal way if you write
  504.         ; directly to a frame buffer on graphics cards.
  505.         ; Same holds true if you change the chunky buffer
  506.         ; cache mode to write through. See R_DrawColumn().
  507.  
  508.         or.w    #$ffc0,d0       ; pOEP
  509.         or.w    #$f03f,d1       ; sOEP
  510.         move.b  (a2,d5.l),d4    ; pOEP but allows sOEP
  511.         move.w  d0,d6           ; sOEP
  512.         and.w   d1,d6           ; pOEP
  513.         move.l  d4,(a0)+        ; sOEP
  514. .start_loop2
  515.         addx.l  d2,d0           ; pOEP only
  516.         addx.l  d3,d1           ; pOEP only
  517.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  518.  
  519.         or.w    #$ffc0,d0       ; sOEP
  520.         or.w    #$f03f,d1       ; pOEP
  521.         move.w  d0,d6           ; sOEP
  522.         move.w  (a2,d5.l),d4    ; pOEP but allows sOEP
  523.         and.w   d1,d6           ; sOEP
  524.         addx.l  d2,d0           ; pOEP only
  525.         addx.l  d3,d1           ; pOEP only
  526.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  527.  
  528.         or.w    #$ffc0,d0       ; sOEP
  529.         or.w    #$f03f,d1       ; pOEP
  530.         move.w  d0,d6           ; sOEP
  531.         move.b  (a2,d5.l),d4    ; pOEP but allows sOEP
  532.         and.w   d1,d6           ; sOEP
  533.         addx.l  d2,d0           ; pOEP only
  534.         addx.l  d3,d1           ; pOEP only
  535.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  536.         
  537.         or.w    #$ffc0,d0       ; sOEP
  538.         or.w    #$f03f,d1       ; pOEP
  539.         move.w  d0,d6           ; sOEP
  540.         swap    d4              ; pOEP only
  541.         move.w  (a2,d5.l),d4    ; pOEP but allows sOEP
  542.         and.w   d1,d6           ; sOEP
  543.         addx.l  d2,d0           ; pOEP only
  544.         addx.l  d3,d1           ; pOEP only
  545.         move.b  (a1,d6.l),d5    ; pOEP but allows sOEP
  546.         dbf     d7,.loop2       ; pOEP only
  547.                     ; = 7.75 cycles/pixel
  548.         move.b  (a2,d5.l),d4
  549.         move.l  d4,(a0)+
  550. .skip_loop2
  551.  
  552.         sub.w   d3,d1
  553.         add.l   d3,d1
  554.  
  555.         move.l  a3,d7
  556.         bra     .loop_end2
  557. .loop3
  558.         or.w    #$ffc0,d0
  559.         or.w    #$f03f,d1
  560.         move.w  d0,d6
  561.         and.w   d1,d6
  562.         addx.l  d2,d0
  563.         addx.l  d3,d1
  564.         move.b  (a1,d6.l),d5
  565.         move.b  (a2,d5.l),(a0)+
  566. .loop_end2
  567.         dbf     d7,.loop3
  568. .end2
  569.         movem.l (sp)+,d2-d7/a2/a3
  570.         rts
  571.  
  572.         cnop    0,4
  573.  
  574. ; 030/040 version
  575.  
  576. @R_DrawSpan_040
  577.         movem.l d2-d7/a2-a4,-(sp)
  578.  
  579.         move.l  (_ds_y),d0
  580.         move.l  (_ds_x1),d1     ; dest = ylookup[_ds_y] + columnofs[_ds_x1]
  581.         lea     (_ylookup),a0
  582.         move.l  (a0,d0.l*4),a0
  583.         lea     (_columnofs),a1
  584.         add.l   (a1,d1.l*4),a0
  585.  
  586.         move.l  (_ds_source),a1
  587.         move.l  (_ds_colormap),a2
  588.  
  589.         move.l  (_ds_x2),d7     ; count = _ds_x2 - _ds_x1
  590.         sub.l   d1,d7
  591.         addq.l  #1,d7
  592.  
  593.         move.l  (_ds_xfrac),d0
  594.         move.l  (_ds_yfrac),d1
  595.         move.l  (_ds_xstep),d2
  596.         move.l  (_ds_ystep),d3
  597.  
  598.         move.l  a0,d4
  599.         btst    #0,d4
  600.         beq     .skipb
  601.  
  602.         move.l  d0,d5           ; do the unaligned pixels
  603.         move.l  d1,d6           ; so we can write to longword
  604.         swap    d5              ; boundary in the main loop
  605.         swap    d6
  606.         and.w   #$3f,d5
  607.         and.w   #$3f,d6
  608.         lsl.w   #6,d6
  609.         or.w    d5,d6
  610.         move.b  (a1,d6.w),d5
  611.         add.l   d2,d0
  612.         move.b  (a2,d5.w),(a0)+
  613.         add.l   d3,d1
  614.         move.l  a0,d4
  615.         subq.l  #1,d7
  616. .skipb
  617.         btst    #1,d4
  618.         beq     .skips
  619.         moveq   #2,d4
  620.         cmp.l   d4,d7
  621.         bls     .skips
  622.  
  623.         move.l  d0,d5           ; write two pixels
  624.         move.l  d1,d6
  625.         swap    d5
  626.         swap    d6
  627.         and.w   #$3f,d5
  628.         and.w   #$3f,d6
  629.         lsl.w   #6,d6
  630.         or.w    d5,d6
  631.         move.b  (a1,d6.w),d5
  632.         move.w  (a2,d5.w),d4
  633.         add.l   d2,d0
  634.         add.l   d3,d1
  635.         move.l  d0,d5
  636.         move.l  d1,d6
  637.         swap    d5
  638.         swap    d6
  639.         and.w   #$3f,d5
  640.         and.w   #$3f,d6
  641.         lsl.w   #6,d6
  642.         or.w    d5,d6
  643.         move.b  (a1,d6.w),d5
  644.         move.b  (a2,d5.w),d4
  645.         add.l   d2,d0
  646.         move.w  d4,(a0)+
  647.         add.l   d3,d1
  648.         subq.l  #2,d7
  649. .skips
  650.  
  651. ; a0: chunky
  652. ; a4: chunky end
  653. ; a1: texture
  654. ; d4: light_table
  655. ; d0: xfrac (vvvv vvvv vvvv vvvv 1111 1111 11UU UUUU)
  656. ; d1: yfrac (uuuu uuuu uuuu uuuu 1111 VVVV VV11 1111)
  657. ; d2: dxfrac
  658. ; d3: dyfrac
  659. ; d6: x_or
  660. ; d7: y_or
  661.  
  662.         move.l  a2,d4
  663.         add.l   #$1000,a1       ; catch 22
  664.  
  665.         move.l  a0,a3
  666.         add.l   d7,a3
  667.  
  668.         move.l  d7,d5
  669.         and.b   #~3,d5
  670.  
  671.         move.l  a0,a4
  672.         add.l   d5,a4
  673.  
  674.         eor.w   d0,d1           ; swap fraction parts for addx
  675.         eor.w   d2,d3
  676.         eor.w   d1,d0
  677.         eor.w   d3,d2
  678.         eor.w   d0,d1
  679.         eor.w   d2,d3
  680.  
  681.         swap    d0
  682.         swap    d1
  683.         swap    d2
  684.         swap    d3
  685.  
  686.         lsl.w   #6,d1
  687.         lsl.w   #6,d3
  688.  
  689.         move.w  #$ffc0,d6
  690.         move.w  #$f03f,d7
  691.  
  692.         lsr.w   #2,d5
  693.         beq     .skip_loop2
  694.  
  695.         sub.w   d3,d1
  696.         add.l   d3,d1           ; setup the X flag
  697.  
  698. .loop2
  699.         or.w    d6,d0
  700.         or.w    d7,d1
  701.         and.w   d1,d0
  702.         addx.l  d2,d0
  703.         addx.l  d3,d1
  704.         move.b  (a1,d0.w),d4
  705.         move.l  d4,a2
  706.         move.w  (a2),d5
  707.         or.w    d6,d0
  708.         or.w    d7,d1
  709.         and.w   d1,d0
  710.         addx.l  d2,d0
  711.         addx.l  d3,d1
  712.         move.b  (a1,d0.w),d4
  713.         move.l  d4,a2
  714.         move.b  (a2),d5
  715.         swap    d5
  716.         or.w    d6,d0
  717.         or.w    d7,d1
  718.         and.w   d1,d0
  719.         addx.l  d2,d0
  720.         addx.l  d3,d1
  721.         move.b  (a1,d0.w),d4
  722.         move.l  d4,a2
  723.         move.w  (a2),d5
  724.         or.w    d6,d0
  725.         or.w    d7,d1
  726.         and.w   d1,d0
  727.         addx.l  d2,d0
  728.         addx.l  d3,d1
  729.         move.b  (a1,d0.w),d4
  730.         move.l  d4,a2
  731.         move.b  (a2),d5
  732.  
  733.         move.l  d5,(a0)+
  734.         cmp.l   a0,a4
  735.         bne     .loop2
  736. .skip_loop2
  737.  
  738.         sub.w   d3,d1
  739.         add.l   d3,d1
  740.  
  741.         bra     .loop_end2
  742. .loop3
  743.         or.w    d6,d0
  744.         or.w    d7,d1
  745.         and.w   d1,d0
  746.         addx.l  d2,d0
  747.         addx.l  d3,d1
  748.         move.b  (a1,d0.w),d4
  749.         move.l  d4,a2
  750.         move.b  (a2),(a0)+
  751. .loop_end2
  752.         cmp.l   a0,a3
  753.         bne     .loop3
  754. .end2
  755.         movem.l (sp)+,d2-d7/a2-a4
  756.         rts
  757.  
  758.  
  759. ;void R_DrawSpan (void)
  760. ;{
  761. ;  fixed_t xfrac, yfrac;
  762. ;  byte* dest;
  763. ;  int count, spot;
  764. ;
  765. ;  xfrac = ds_xfrac;
  766. ;  yfrac = ds_yfrac;
  767. ;  dest = ylookup[ds_y] + columnofs[ds_x1];
  768. ;  count = ds_x2 - ds_x1;
  769. ;  do {
  770. ;    spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63);
  771. ;    *dest++ = ds_colormap[ds_source[spot]];
  772. ;    xfrac += ds_xstep;
  773. ;    yfrac += ds_ystep;
  774. ;  } while (count--);
  775. ;}
  776.  
  777. ;***********************************************************************
  778.  
  779. end
  780.