home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 2 / agavol2.iso / software / utilities / programmers / source / chunky / rotatepicture.s < prev    next >
Encoding:
Text File  |  1978-06-29  |  8.4 KB  |  377 lines

  1.  
  2. ; Chunky copper rotation example. (c) 1994 Ranulf Doswell.
  3. ; This demo produces a 107*86 resolution 4096 colour chunky display, running
  4. ; at 25 fps on an unexpanded 1200. I would like to see it on a fast ram amiga...
  5.  
  6. ; Or 75*72 resolution at 50fps!!!
  7.  
  8. ; The demo needs a 256*256*12 bit picture file called pic to assemble.
  9. ; This is basically an $xRGB quad for each pixel, stored in sequential
  10. ; (planar) format
  11.  
  12. ; Write me at: Ranulf Doswell,
  13. ;        1 Ayr Street, Lancaster, Lancashire, LA1 3DT, England
  14.  
  15. ; My chunky copper display code. Idea based on COPASM.A by Patrick van Logchem
  16.  
  17. HPIXELS            equ    75    107
  18. VPIXELS            equ    72    86
  19. OFFSET_NEXT_LINE    equ    4*(2+HPIXELS+((HPIXELS/32)+1))
  20. LINES            equ    3    must be 3 else looks distorted
  21. ANGLE_SPEED        equ    27
  22. ZOOM_SPEED        equ    11
  23.  
  24. ;at 50fps, can run at up to 75*72
  25.  
  26. ;max for 2 lines - HPIXELS=89
  27. ;maximum for _smooth_ scrolling is 118x86,128x79,89x114 (for old scrolling stuff)
  28.  
  29.         include    exec/exec_lib.i
  30.         include    libraries/mathffp_lib.i
  31.         include    libraries/mathtrans_lib.i
  32.         include    hardware/custom.i
  33.  
  34.         bsr    MakeSinTable
  35.         incbin    source:startup.bin    based on howtocode 7
  36.         incbin    GetControl        since 1.3 days... erm.
  37.  
  38. ;someday I'll mix my two startup things to make a coherent single interface
  39. ;that does everything ;-)
  40. ;
  41. ; source:startup.bin handles loadview() etc to ensure that works with multisyncs
  42. ; getcontrol restores system copper, dma and int masks to defualt settings
  43.  
  44.         lea    $dff000,a6
  45.         move.w    #$7fff,intena(a6)    disable all interrupts...
  46.  
  47.         bsr    InitCopper
  48.  
  49.         move.l    PixelTable+8,cop1lc(a6)
  50.         move.w    #0,copjmp1(a6)
  51.  
  52. wait        btst    #50,$dff016
  53.         beq.s    wait
  54.  
  55.         move.w    angle,d0
  56.         move.w    size,d1
  57.         bsr    TranslateBuffer
  58.  
  59.         add.w    #ANGLE_SPEED,angle
  60.         add.w    #ZOOM_SPEED,size
  61.  
  62.         bsr    SwapBuffers
  63.  
  64.         btst    #6,$bfe001
  65.         bne.s    wait
  66.         rts
  67.         
  68. angle        dc.w    0
  69. size        dc.w    3192
  70. colour        dc.w    0
  71.  
  72. InitCopper    lea    CopperBuffer,a0
  73.         lea    PixelTable,a3
  74.  
  75.         lea    16(a3),a2
  76.         bsr    .docopper
  77. .docopper
  78.         move.l    a0,8(a3)
  79.         move.l    a2,(a3)+
  80.  
  81.         move.l    #$2001fffe,(a0)+
  82.  
  83.     ;    move.l    #$01800000,(a0)+    ; color0  = $0000
  84.     ;    move.l    #$010c0011,(a0)+    ; bplcon4 = $0011
  85.         move.l    #$008e277b,(a0)+    ; diwstrt = $2c81
  86.         move.l    #$01007201,(a0)+    ; bplcon0 = $0211
  87.         move.l    #$01040224,(a0)+    ; bplcon2 = $0224
  88.         move.l    #$009029bb,(a0)+    ; diwstop = $2cc1
  89.         move.l    #$00920018,(a0)+    ; ddfstrt = $0038
  90.         move.l    #$009400b8,(a0)+    ; ddfstop = $00d8
  91.         move.l    #$0102ccaa,(a0)+    ; bplcon1 = $0000
  92.         move.l    #$0108ffd0,(a0)+    ; bpl1mod = $ffd0 (-48)
  93.         move.l    #$010affd0,(a0)+    ; bpl2mod = $ffd0 (-48)
  94.         move.l    #$01e42100,(a0)+    ; diwhigh = $2100
  95.         move.l    #$01fc0003,(a0)+    ; fmode   = $0003
  96.         move.l    #$01dc0020,(a0)+    ; beamcon0= $0020 PAL settings
  97.  
  98.         move.l    #SpritesNull,d0
  99.         move.w    #$120,d1
  100.         moveq    #8-1,d2
  101. .wipesprites    move.w    d1,(a0)+
  102.         swap    d0
  103.         move.w    d0,(a0)+
  104.         swap    d0
  105.         addq.w    #2,d1
  106.         move.w    d1,(a0)+
  107.         addq.w    #2,d1
  108.         move.w    d0,(a0)+
  109.         dbf    d2,.wipesprites        store 8 copies of blank sprite
  110.  
  111.         move.l    #Bitplanes,d0
  112.         move.w    #$e0,d1
  113.         moveq    #7-1,d2            7 bitplanes
  114.         moveq    #40,d3            length of a plane...
  115.  
  116.         moveq    #-1,d4            flag=save colour pointer
  117.  
  118. .bploop        move.w    d1,(a0)+
  119.         swap    d0
  120.         move.w    d0,(a0)+
  121.         swap    d0
  122.         addq.w    #2,d1
  123.         move.w    d1,(a0)+
  124.         addq.w    #2,d1
  125.         move.w    d0,(a0)+
  126.         add.l    d3,d0
  127.         dbf    d2,.bploop        store the bitplane pointers
  128.  
  129.         move.l    #$01068c60,d0        select bank instruc
  130.         move.l    #$2407fffe,d1        wait line instruction
  131.         move.l    #$010c0011,d2        magic the change line bit
  132.         move.w    #$0180,d3        change colour reg
  133.         
  134.         move.w    #VPIXELS-1,d7        number of lines
  135. .lineloop    move.l    d0,d5
  136.         add.w    #$8000,d0
  137.         move.l    d1,(a0)+        put in wait line
  138.         add.l    #LINES<<24,d1
  139.         move.l    d2,(a0)+        change line colour
  140.         add.w    #$8000,d2
  141.  
  142.         move.w    #HPIXELS,d6        number of colours to do
  143.         bra.s    .selbank
  144. .pixelloop    move.w    d3,(a0)+        store change colour instruc
  145.  
  146.         tst.l    d4
  147.         beq.s    .nostoretable
  148.         move.l    a0,(a2)+        store address if on first line
  149.  
  150. .nostoretable    clr.w    (a0)+
  151.  
  152.         addq.w    #$0002,d3        next colour reg
  153.         cmp.w    #$01c0,d3        end of bank?
  154.         bne.s    .nextpix
  155. .selbank    move.w    #$0180,d3        restart colours with new bank
  156.         move.l    d5,(a0)+        select new bank
  157.         add.w    #$2000,d5        set next bank after this
  158. .nextpix    dbf    d6,.pixelloop
  159.  
  160.         moveq    #0,d4            so x pointers only on 1st line
  161.  
  162.         dbf    d7,.lineloop
  163.  
  164.         move.l    d1,(a0)+
  165.         move.l    d2,(a0)+        for the last line
  166.  
  167.         move.l    #$fffffffe,(a0)+    end copper list
  168.  
  169.         rts
  170.  
  171. SwapBuffers    lea    PixelTable,a0
  172.         movem.l    (a0),d0-d3
  173.         exg    d0,d1
  174.         exg    d2,d3
  175.         movem.l    d0-d3,(a0)
  176.         move.l    d3,cop1lc(a6)
  177.  
  178. .wait        move.l    vposr(a6),d0
  179.         lsr.l    #8,d0
  180.         and.w    #$1ff,d0
  181.         cmp.w    #$1f,d0
  182.         bne.s    .wait
  183.  
  184.         move.l    d3,cop1lc(a6)
  185.         move.w    d3,copjmp1(a6)
  186.  
  187.         rts
  188.  
  189. TranslateBuffer        ;d0=angle,d1=zoom factor
  190.  
  191.         movem.l    d2/d4-d7/a2-a5,-(a7)
  192.  
  193.         lea    SinBuffer,a1
  194.         and.w    #4095,d0
  195.         move.w    (a1,d0.w*2),d5    D5=16384 sin ø
  196.         add.w    #1024,d0
  197.         move.w    (a1,d0.w*2),d4    D4=16384 cos ø
  198.  
  199.         and.w    #4095,d1
  200.         move.w    (a1,d1.w*2),d1    D1=16384 sin zoom
  201.  
  202.     ;    asr.w    #6,d1        choice of lines-determines how far
  203.     ;    add.w    #256+32,d1    out the zoom can go.
  204.         asr.w    #4,d1
  205.         add.w    #1030,d1
  206.  
  207.         muls    d1,d4
  208.         muls    d1,d5        multiply by scale factor (zoom)
  209.  
  210.         asr.l    #8,d4
  211.         asr.l    #6,d4
  212.         asr.l    #8,d5
  213.         asr.l    #6,d5        get to range. 1.0->256 at zoom 1:1
  214.  
  215. ; / addtopx    addx    \ _ / cos ø    -sin ø    \ _ / Ix Jx \
  216. ; \ addtopy    addy    / - \ sin ø    cos ø    / - \ Iy Jy /
  217.  
  218.         move.w    #-VPIXELS/2,d6
  219.         muls    d4,d6
  220.         move.w    #-HPIXELS/2,d7
  221.         muls    d5,d7
  222.         add.l    d7,d6
  223.         move.w    d6,a3
  224.  
  225.         move.w    #-VPIXELS/2,d6
  226.         muls    d5,d6
  227.         move.w    #HPIXELS/2,d7
  228.         muls    d4,d7
  229.         add.l    d7,d6            do rotated offset to centre of
  230.         move.w    d6,a4            the screen
  231.  
  232.         add.w    #XOFFSET*256+128,a3    x coord of centre
  233.         add.w    #YOFFSET*256+128,a4    y coord
  234.  
  235.         lea    PictureBuffer,a0
  236.         move.l    PixelTable,a1        a0=buffer to read
  237.  
  238.         move.w    #OFFSET_NEXT_LINE,d3    offset between copper lines
  239.         moveq.w    #HPIXELS-1,d0        width (# copper pixels)
  240.  
  241.         moveq    #0,d2            so we can use unisgned addressing
  242.  
  243. ;this is the important loop of the demo. It (easily) fits in the cache as it
  244. ;is only about 38 bytes long. Note that we now only use integer addition and
  245. ;subtraction, as multiplications take _ages_
  246.  
  247. .horizloop    moveq.w    #VPIXELS-1,d1
  248.         move.l    (a1)+,a2        get next horizontal address
  249.  
  250.         move.w    a3,d6
  251.         move.w    a4,d7            get topx,topy
  252.         add.w    d5,a3
  253.         sub.w    d4,a4            change topx,topy for next horiz
  254.  
  255. .vertloop        ;    store pixel (d6>>8,d7>>8) to (a2)
  256.         move.w    d6,d2
  257.         ror.w    #8,d7
  258.         move.b    d7,d2
  259.         rol.w    #8,d7            D2=offset of this pixel
  260.  
  261.         add.w    d4,d6
  262.         add.w    d5,d7            next pixel vertically
  263.         
  264.         move.w    (a0,d2.l*2),(a2)    copy the colour
  265.         add.w    d3,a2            next vertical copper pixel
  266.         dbf    d1,.vertloop
  267.         dbf    d0,.horizloop
  268.  
  269.         movem.l    (a7)+,d2/d4-d7/a2-a5
  270.         rts
  271.  
  272. ANGLE_CONSTANT    equ    $C90FDB37    2*pi/32768/512=3.7450703e-7
  273. SIN_CONSTANT    equ    $8000004F    16384
  274.  
  275. MakeSinTable    move.l    4.w,a6
  276.         lea    MathTrans(pc),a1
  277.         moveq    #0,d0
  278.         jsr    _LVOOpenLibrary(a6)
  279.         move.l    d0,a5
  280.         move.l    a5,d0
  281.         beq.s    .notrans
  282.  
  283.         lea    MathFFP(pc),a1
  284.         moveq    #0,d0
  285.         jsr    _LVOOpenLibrary(a6)
  286.         move.l    d0,a6
  287.         move.l    a6,d0
  288.         beq.s    .noffp
  289.         
  290.         lea    SinBuffer,a2
  291.         moveq    #0,d2
  292.         move.w    #4095+1024,d3
  293.  
  294. .loop        move.l    d2,d0
  295.         jsr    _LVOSPFlt(a6)
  296.         move.l    #ANGLE_CONSTANT,d1
  297.         jsr    _LVOSPMul(a6)
  298.         exg    a6,a5
  299.         jsr    _LVOSPSin(a6)
  300.         exg    a5,a6
  301.         move.l    #SIN_CONSTANT,d1
  302.         jsr    _LVOSPMul(a6)
  303.         jsr    _LVOSPFix(a6)
  304.         move.w    d0,(a2)+
  305.         
  306.         addq.w    #1,d2
  307.         dbf    d3,.loop
  308.  
  309.         move.l    a6,a1
  310.         move.l    4.w,a6
  311.         jsr    _LVOCloseLibrary(a6)
  312. .noffp        move.l    a5,a1
  313.         jsr    _LVOCloseLibrary(a6)
  314. .notrans    moveq    #0,d0
  315.         rts
  316.  
  317. MathTrans    dc.b    "mathtrans.library",0
  318. MathFFP        dc.b    "mathffp.library",0
  319.         even
  320.         section    ChipGfx,data_c
  321.  
  322. SpritesNull    dc.l    0,0,0,0
  323.  
  324. Bitplanes    dc.l    $1c71c71c,$71c71c71,$c71c71c7
  325.         dc.l    $1c71c71c,$71c71c71,$c71c71c7
  326.         dc.l    $1c71c71c,$71c71c71,$c71c71c7
  327.         dc.l    $1c71c71c
  328.  
  329.         dc.l    $03f03f03,$f03f03f0,$3f03f03f
  330.         dc.l    $03f03f03,$f03f03f0,$3f03f03f
  331.         dc.l    $03f03f03,$f03f03f0,$3f03f03f
  332.         dc.l    $03f03f03
  333.  
  334.         dc.l    $000fff00,$0fff000f,$ff000fff
  335.         dc.l    $000fff00,$0fff000f,$ff000fff
  336.         dc.l    $000fff00,$0fff000f,$ff000fff
  337.         dc.l    $000fff00
  338.  
  339.         dc.l    $000000ff,$ffff0000,$00ffffff
  340.         dc.l    $000000ff,$ffff0000,$00ffffff
  341.         dc.l    $000000ff,$ffff0000,$00ffffff
  342.         dc.l    $000000ff
  343.  
  344.         dc.l    $00000000,$0000ffff,$ffffffff
  345.         dc.l    $00000000,$0000ffff,$ffffffff
  346.         dc.l    $00000000,$0000ffff,$ffffffff
  347.         dc.l    $00000000
  348.  
  349.         dc.l    $00000000,$00000000,$00000000
  350.         dc.l    $ffffffff,$ffffffff,$ffffffff
  351.         dc.l    $00000000,$00000000,$00000000
  352.         dc.l    $ffffffff
  353.  
  354.         dc.l    $00000000,$00000000,$00000000
  355.         dc.l    $00000000,$00000000,$00000000
  356.         dc.l    $ffffffff,$ffffffff,$ffffffff
  357.         dc.l    $ffffffff
  358.  
  359.         section    sourcedata,data
  360.  
  361. PictureBuffer    incbin pic
  362.  
  363. XOFFSET        equ    127    31            ;127
  364. YOFFSET        equ    127    145            ;127
  365.  
  366.         section    copper,bss_c
  367.  
  368. ;PixelTable    dc.l    pixels_for_copper_1,pixels_for_copper_2
  369. ;        dc.l    copper_1,copper_2
  370.  
  371. PixelTable    ds.l    4
  372.         ds.l    2*HPIXELS
  373. CopperBuffer    ds.l    2*(VPIXELS*OFFSET_NEXT_LINE+100)
  374.  
  375.         bss
  376. SinBuffer    ds.w    4096+1024
  377.