home *** CD-ROM | disk | FTP | other *** search
/ Brotikasten / BROTCD01.iso / amiga / frodov13.lha / src / c2p4.asm < prev    next >
Assembly Source File  |  1995-02-07  |  15KB  |  638 lines

  1.         XDEF    _c2p4
  2.         XDEF    Initc2p4
  3.         XDEF    Exitc2p4
  4.  
  5. ; ---------------------------------------------------------------------
  6. ; void __asm c2p4 (register __a2 UBYTE *fBUFFER,
  7. ;                  register __a3 UBYTE *fBUFFER_CMP,
  8. ;                  register __a4 PLANEPTR *planes,
  9. ;                  register __a5 struct Task *task,
  10. ;                  register __d0 ULONG signals);
  11. ;
  12. ; 4-plane unpacked chunky to planar converter.
  13. ; Optimised for 68020/30 with fastmem.
  14. ;
  15. ; Author: Peter McGavin (e-mail peterm@maths.grace.cri.nz), 6 April 1994
  16. ; Based on James McCoull's 4-pass blitter algorithm.
  17. ;
  18. ; This code is public domain.
  19. ;
  20. ; Use chunky comparison buffer.  Return immediately if no diffs found.
  21. ; Perform first 2 passes (Fast->Chip) with the CPU (in 1 pass).
  22. ; Update chunky comparison buffer.
  23. ; Perform passes 3 & 4 with QBlit().
  24. ; Return immediately after launching blits.
  25. ; Signal task from CleanUp() on completion.
  26. ; Task should wait for signal before next call to c2p4().
  27. ;
  28. ; (Unimplemented speedup idea: Might be possible to signal task after pass 3,
  29. ; but will probably need another Wait() somewhere.)
  30. ;
  31. ; Approx timing (A4000/030, 320x200x4):
  32. ;    CPU pass max 18ms (then return)
  33. ;    Asynchronous blitter passes add 31ms
  34. ;
  35. ; Example usage:
  36. ;
  37. ;    /* clear fBUFFER, fBUFFER_CMP, and planes here */
  38. ;    if ((sigbit = AllocSignal(-1)) == -1)
  39. ;        die ("Can't allocate signal!\n");
  40. ;    safe = TRUE;
  41. ;    for (;;) {
  42. ;        ... /* render to fBUFFER here */
  43. ;        if (!safe) {
  44. ;            Wait (1<<sigbit);  // wait for previous c2p4 to finish
  45. ;            safe = TRUE;
  46. ;        }
  47. ;            c2p4 (fBUFFER, fBUFFER_CMP, &RASTPORT->BitMap->Planes[0],
  48. ;            FindTask(NULL), 1<<sigbit);
  49. ;        safe = FALSE;
  50. ;    }
  51. ;    if (!safe)
  52. ;        Wait (1<<sigbit);  // wait for last c2p4 to finish
  53. ;    FreeSignal(sigbit);
  54. ;
  55. ; <20.Jan.95: Angepa▀t fⁿr den Frodo C64-Emulator und an OCS
  56. ;             von Christian Bauer>
  57.  
  58.  
  59. width        equ    $180    ; must be a multiple of 32
  60. height        equ    $110
  61. toplinestoskip    equ    0
  62.  
  63. plsiz         equ    (width/8)*height
  64. pixels        equ    width*height
  65. offset        equ    (width/8)*toplinestoskip
  66.  
  67. cleanup        equ    $40
  68.  
  69.         INCLUDE    "exec/types.i"
  70.         INCLUDE    "exec/macros.i"
  71.         INCLUDE    "exec/memory.i"
  72.         INCLUDE    "graphics/gfxbase.i"
  73.         INCLUDE    "hardware/custom.i"
  74.  
  75.         XREF    _SysBase
  76.         XREF    _GfxBase
  77.  
  78.         SECTION    "CODE",CODE
  79.  
  80. ; Installierte Chips ermitteln (OCS/ECS) und buff2 belegen
  81. ; R▄ckgabe: d0#0: OK
  82. Initc2p4    move.l    _GfxBase,a0
  83.         btst    #GFXB_BIG_BLITS,gb_ChipRevBits0(a0)
  84.         bne    1$
  85.  
  86.         move.l    #blit43,qblitfunc
  87.         move.l    #blit43,initblitfunc
  88.         move.w    #-1,wehaveocs
  89.  
  90.         move.l    a6,-(sp)
  91.         move.l    _SysBase,a6
  92.         move.l    #pixels/2,d0
  93.         move.l    #MEMF_ANY,d1
  94.         JSRLIB    AllocVec
  95.         move.l    d0,buff2ptr
  96.         move.l    (sp)+,a6
  97.         rts
  98.  
  99. 1$        move.l    #blit31,qblitfunc
  100.         move.l    #blit31,initblitfunc
  101.         clr.w    wehaveocs
  102.  
  103.         move.l    a6,-(sp)
  104.         move.l    _SysBase,a6
  105.         move.l    #pixels/2,d0
  106.         move.l    #MEMF_CHIP,d1
  107.         JSRLIB    AllocVec
  108.         move.l    d0,buff2ptr
  109.         move.l    (sp)+,a6
  110.         rts
  111.  
  112. Exitc2p4    move.l    a6,-(sp)
  113.         move.l    _SysBase,a6
  114.         move.l    buff2ptr,d0
  115.         beq    1$
  116.         move.l    d0,a1
  117.         JSRLIB    FreeVec
  118. 1$        move.l    (sp)+,a6
  119.         rts
  120.  
  121. _c2p4:        movem.l    d2-d7/a2-a6,-(sp)
  122.  
  123. ; save arguments
  124.  
  125.         move.l    #mybltnode,a0
  126.         move.l    a2,(chunky-mybltnode,a0)
  127.         move.l    a4,(planes-mybltnode,a0)
  128.         move.l    a5,(task-mybltnode,a0)
  129.         move.l    d0,(signals-mybltnode,a0)
  130.  
  131. ;-------------------------------------------------
  132. ;original chunky data
  133. ;0        ........a3a2a1a0 ........b3b2b1b0
  134. ;2        ........c3c2c1c0 ........d3d2d1d0
  135. ;4        ........e3e2e1e0 ........f3f2f1f0
  136. ;6        ........g3g2g1g0 ........h3h2h1h0
  137. ;8        ........i3i2i1i0 ........j3j2j1j0
  138. ;10        ........k3k2k1k0 ........l3l2l1l0
  139. ;12        ........m3m2m1m0 ........n3n2n1n0
  140. ;14        ........o3o2o1o0 ........p3p2p1p0
  141. ;16        ........q3q2q1q0 ........r3r2r1r0
  142. ;18        ........s3s2s1s0 ........t3t2t1t0
  143. ;20        ........u3u2u1u0 ........v3v2v1v0
  144. ;22        ........w3w2w1w0 ........x3x2x1x0
  145. ;24        ........y3y2y1y0 ........z3z2z1z0
  146. ;26        ........A3A2A1A0 ........B3B2B1B0
  147. ;28        ........C3C2C1C0 ........D3D2D1D0
  148. ;30        ........E3E2E1E0 ........F3F2F1F0
  149. ;-------------------------------------------------
  150.  
  151.         move.l    buff2ptr,a4    ; a4 -> buff2
  152.         move.l    #$00ff00ff,d7    ; constant
  153.         move.w    #pixels/32,d6    ; loop counter
  154.  
  155.         bra.b    end_pass1loop
  156.  
  157.         CNOP    0,4
  158.  
  159. ; main loop (starts here) processes 32 chunky pixels at a time
  160. ; compare next 32 pixels with compare page, looking for differences
  161.  
  162. initpass1loop:    cmpm.l    (a2)+,(a3)+
  163.         bne.w    fix1
  164.         cmpm.l    (a2)+,(a3)+
  165.         bne.w    fix2
  166.         cmpm.l    (a2)+,(a3)+
  167.         bne.b    fix3
  168.         cmpm.l    (a2)+,(a3)+
  169.         bne.b    fix4
  170.         cmpm.l    (a2)+,(a3)+
  171.         bne.b    fix5
  172.         cmpm.l    (a2)+,(a3)+
  173.         bne.b    fix6
  174.         cmpm.l    (a2)+,(a3)+
  175.         bne.b    fix7
  176.         cmpm.l    (a2)+,(a3)+
  177.         bne.b    fix8
  178.  
  179.         addq.l    #8,a4        ; skip 8 bytes in output
  180.  
  181. end_pass1loop:    dbra    d6,initpass1loop
  182.  
  183. ; If we get to here then no difference was found.
  184. ; Signal the task and return.
  185.  
  186.         move.l    (task-mybltnode,a0),a1
  187.         move.l    (signals-mybltnode,a0),d0
  188.         move.l    (4).w,a6
  189.         JSRLIB    Signal
  190.  
  191.         movem.l    (sp)+,d2-d7/a2-a6
  192.         rts
  193.  
  194. ; This becomes the main loop after the first difference is found
  195.  
  196. pass1loop:    cmpm.l    (a2)+,(a3)+
  197.         bne.b    fix1
  198.         cmpm.l    (a2)+,(a3)+
  199.         bne.b    fix2
  200.         cmpm.l    (a2)+,(a3)+
  201.         bne.b    fix3
  202.         cmpm.l    (a2)+,(a3)+
  203.         bne.b    fix4
  204.         cmpm.l    (a2)+,(a3)+
  205.         bne.b    fix5
  206.         cmpm.l    (a2)+,(a3)+
  207.         bne.b    fix6
  208.         cmpm.l    (a2)+,(a3)+
  209.         bne.b    fix7
  210.         cmpm.l    (a2)+,(a3)+
  211.         bne.b    fix8
  212.  
  213.         addq.l    #8,a4        ; skip 8 bytes in output
  214.  
  215.         dbra    d6,pass1loop
  216.  
  217.         bra.w    done
  218.  
  219. ; difference found, restore a2 and a3
  220.  
  221. fix8:        subq.l    #4,a2
  222.         subq.l    #4,a3
  223. fix7:        sub.w    #28,a2
  224.         sub.w    #28,a3
  225.         bra.b    go_c2p
  226.  
  227. fix6:        subq.l    #4,a2
  228.         subq.l    #4,a3
  229. fix5:        sub.w    #20,a2
  230.         sub.w    #20,a3
  231.         bra.b    go_c2p
  232.  
  233. fix4:        subq.l    #4,a2
  234.         subq.l    #4,a3
  235. fix3:        sub.w    #12,a2
  236.         sub.w    #12,a3
  237.         bra.b    go_c2p
  238.  
  239. fix2:        subq.l    #4,a2
  240.         subq.l    #4,a3
  241. fix1:        subq.l    #4,a2
  242.         subq.l    #4,a3
  243.  
  244. ; convert 32 pixels (passes 1 and 2 combined)
  245.  
  246. go_c2p:        movem.l    (a2)+,d0-d3/a0/a1/a5/a6    ; ABCD EFGH IJKL MNOP QRST UVWX YZ01 2345
  247.  
  248.         move.l    #$0f0f0f0f,d4    ;<Obere Nibbles l÷schen>
  249.         and.l    d4,d0
  250.         and.l    d4,d1
  251.         and.l    d4,d2
  252.         and.l    d4,d3
  253.  
  254.         movem.l    d0-d3/a0/a1/a5/a6,(a3)    ; update compare buffer
  255.         adda.w    #32,a3
  256.  
  257.         lsl.l    #4,d0        ; A.B.C.D.
  258.         move.l    d0,d4        ; A.B.C.D.
  259.         and.l    d7,d4        ; ..B...D.
  260.         eor.l    d4,d0        ; A...C...
  261.  
  262.         move.l    d1,d5        ; .E.F.G.H
  263.         and.l    d7,d5        ; ...F...H
  264.         eor.l    d5,d1        ; .E...G..
  265.  
  266.         or.l    d1,d0        ; AE..CG..
  267.         or.l    d5,d4        ; ..BF..DH
  268.  
  269.         move.l    d2,d1        ; .I.J.K.L
  270.         and.l    d7,d1        ; ...J...L
  271.  
  272.         move.l    d3,d5        ; .M.N.O.P
  273.         and.l    d7,d5        ; ...N...P
  274.  
  275.         lsl.l    #4,d4        ; .BF..DH.
  276.         or.l    d1,d4        ; .BFJ.DHL
  277.         lsl.l    #4,d4        ; BFJ.DHL.
  278.         or.l    d5,d4        ; BFJNDHLP
  279.  
  280.         move.l    d4,(pixels/4,a4)
  281.  
  282.         eor.l    d5,d3        ; .M...O..
  283.         lsr.l    #4,d3        ; ..M...O.
  284.         eor.l    d1,d2        ; .I...K..
  285.         or.l    d3,d2        ; .IM..KO.
  286.         lsr.l    #4,d2        ; ..IM..KO
  287.         or.l    d2,d0        ; AEIMCGKO
  288.  
  289.         move.l    a6,d3
  290.         move.l    a5,d2
  291.         move.l    a1,d1
  292.  
  293.         move.l    d0,(a4)+
  294.  
  295.         move.l    a0,d0
  296.  
  297.         move.l    #$0f0f0f0f,d4    ;<Obere Nibbles l÷schen>
  298.         and.l    d4,d0
  299.         and.l    d4,d1
  300.         and.l    d4,d2
  301.         and.l    d4,d3
  302.  
  303.         lsl.l    #4,d0        ; Q.R.S.T.
  304.         move.l    d0,d4        ; Q.R.S.T.
  305.         and.l    d7,d4        ; ..R...T.
  306.         eor.l    d4,d0        ; Q...S...
  307.  
  308.         move.l    d1,d5        ; .U.V.W.X
  309.         and.l    d7,d5        ; ...V...X
  310.         eor.l    d5,d1        ; .U...W..
  311.  
  312.         or.l    d1,d0        ; QU..SW..
  313.         or.l    d5,d4        ; ..RV..TX
  314.  
  315.         move.l    d2,d1        ; .Y.Z.0.1
  316.         and.l    d7,d1        ; ...Z...1
  317.  
  318.         move.l    d3,d5        ; .2.3.4.5
  319.         and.l    d7,d5        ; ...3...5
  320.  
  321.         lsl.l    #4,d4        ; .RV..TX.
  322.         or.l    d1,d4        ; .RVZ.TX1
  323.         lsl.l    #4,d4        ; RVZ.TX1.
  324.         or.l    d5,d4        ; RVZ3TX15
  325.  
  326.         move.l    d4,(pixels/4,a4)
  327.  
  328.         eor.l    d5,d3        ; .2...4..
  329.         lsr.l    #4,d3        ; ..2...4.
  330.         eor.l    d1,d2        ; .Y...0..
  331.         or.l    d3,d2        ; .Y2..04.
  332.         lsr.l    #4,d2        ; ..Y2..04
  333.         or.l    d2,d0        ; QUY2SW04
  334.  
  335.         move.l    d0,(a4)+
  336.  
  337.         dbra    d6,pass1loop
  338.  
  339. ; start the blitter in the background for passes 3 & 4
  340. ; <OCS: pass 4 only, pass 3 is done by CPU>
  341.  
  342. done:        tst.w    wehaveocs
  343.         beq    3$
  344.  
  345.         move.w    #pixels/8-1,d7        ;blit31
  346.         move.l    buff2ptr,a0
  347.         move.l    buff2ptr,a1
  348.         addq.l    #2,a1
  349.         lea    buff3,a2
  350.         move.w    #$cccc,d2
  351. 1$        move.w    (a0)+,d0
  352.         addq.l    #2,a0
  353.         and.w    d2,d0
  354.         move.w    (a1)+,d1
  355.         addq.l    #2,a1
  356.         and.w    d2,d1
  357.         lsr.w    #2,d1
  358.         or.w    d1,d0
  359.         move.w    d0,(a2)+
  360.         dbra    d7,1$
  361.  
  362.         move.w    #pixels/8-1,d7        ;blit32
  363.         move.l    buff2ptr,a0
  364.         add.l    #pixels/2-2,a0
  365.         move.l    buff2ptr,a1
  366.         add.l    #pixels/2,a1
  367.         lea    buff3+pixels/2,a2
  368.         move.w    #$3333,d2
  369. 2$        move.w    -(a0),d0
  370.         subq.l    #2,a0
  371.         and.w    d2,d0
  372.         lsl.w    #2,d0
  373.         move.w    -(a1),d1
  374.         subq.l    #2,a1
  375.         and.w    d2,d1
  376.         or.w    d1,d0
  377.         move.w    d0,-(a2)
  378.         dbra    d7,2$
  379.  
  380. 3$        lea    mybltnode,a1
  381.         move.l    _GfxBase,a6
  382.         JSRLIB    QBlit
  383.  
  384.         movem.l    (sp)+,d2-d7