home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / software / testi / corsoasm / sorgenti6 / lezione10r.s < prev    next >
Text File  |  1995-10-23  |  9KB  |  335 lines

  1.  
  2. ; Lezione10r.s    Riempimento un poligono chiuso
  3. ;        tasto destro per blittare, sinistro per uscire
  4.  
  5.     SECTION    CiriCop,CODE
  6.  
  7. ;    Include    "DaWorkBench.s"    ; togliere il ; prima di salvare con "WO"
  8.  
  9. *****************************************************************************
  10.     include    "startup1.s"    ; Salva Copperlist Etc.
  11. *****************************************************************************
  12.  
  13.         ;5432109876543210
  14. DMASET    EQU    %1000001111000000    ; copper,bitplane,blitter DMA
  15.  
  16.  
  17. START:
  18. ;    Puntiamo la PIC "vuota"
  19.  
  20.     MOVE.L    #BITPLANE,d0    ; dove puntare
  21.     LEA    BPLPOINTERS,A1    ; puntatori COP
  22.     move.w    d0,6(a1)
  23.     swap    d0
  24.     move.w    d0,2(a1)
  25.  
  26.     lea    $dff000,a5        ; CUSTOM REGISTER in a5
  27.     MOVE.W    #DMASET,$96(a5)        ; DMACON - abilita bitplane, copper
  28.     move.l    #COPPERLIST,$80(a5)    ; Puntiamo la nostra COP
  29.     move.w    d0,$88(a5)        ; Facciamo partire la COP
  30.     move.w    #0,$1fc(a5)        ; Disattiva l'AGA
  31.     move.w    #$c00,$106(a5)        ; Disattiva l'AGA
  32.     move.w    #$11,$10c(a5)        ; Disattiva l'AGA
  33.  
  34.     bsr.w    InitLine    ; inizializza line-mode
  35.  
  36.     move.w    #$ffff,d0    ; linea continua
  37.     bsr.w    SetPattern    ; definisce pattern
  38.  
  39.     move.w    #30,d0        ; x1
  40.     move.w    #125,d1        ; y1
  41.     move.w    #130,d2        ; x2
  42.     move.w    #180,d3        ; y2
  43.     lea    bitplane,a0
  44.     bsr.w    DrawlineFill
  45.  
  46.     move.w    #220,d0        ; x1
  47.     move.w    #105,d1        ; y1
  48.     move.w    #130,d2        ; x2
  49.     move.w    #180,d3        ; y2
  50.     lea    bitplane,a0
  51.     bsr.w    DrawlineFill
  52.  
  53.     move.w    #220,d0        ; x1
  54.     move.w    #105,d1        ; y1
  55.     move.w    #150,d2        ; x2
  56.     move.w    #60,d3        ; y2
  57.     lea    bitplane,a0
  58.     bsr.w    DrawlineFill
  59.  
  60.     move.w    #30,d0        ; x1
  61.     move.w    #125,d1        ; y1
  62.     move.w    #150,d2        ; x2
  63.     move.w    #60,d3        ; y2
  64.     lea    bitplane,a0
  65.     bsr.s    DrawlineFill
  66.  
  67. mouse1:
  68.     btst    #2,$dff016    ; tasto destro del mouse premuto?
  69.     bne.s    mouse1
  70.  
  71.     move.w    #0,d0            ; inclusivo
  72.     move.w    #0,d1            ; CARRYIN=0
  73.     lea    bitplane+180*40+28,a0
  74.     bsr.s    Fill
  75.  
  76. mouse2:
  77.     btst    #6,$bfe001    ; mouse premuto?
  78.     bne.s    mouse2
  79.     rts
  80.  
  81.  
  82. ;****************************************************************************
  83. ; Questa routine copia un rettangolo di schermo da una posizione fissa
  84. ; ad un indirizzo specificato come parametro. Il rettangolo di schermo che
  85. ; viene copiato racchiude interamente le 2 linee.
  86. ; Durante la copia viene effettuato anche il riempmento. Il tipo di riempimento
  87. ; e` specificato tramite i parametri.
  88. ; I parametri sono:
  89. ; A0 - indirizzo destinazione
  90. ; D0 - se vale 0 allora effettua fill inclusivo, altrimenti fa fill esclusivo
  91. ; D1 - se vale 0 allora effettua FILL_CARRYIN=0, altrimenti FILL_CARRYIN=1
  92. ;****************************************************************************
  93.  
  94. Fill:
  95.     btst    #6,2(a5) ; dmaconr
  96. WBlit1:
  97.     btst    #6,2(a5) ; dmaconr - attendi che il blitter abbia finito
  98.     bne.s    wblit1
  99.  
  100.     move.w    #$09f0,$40(a5)        ; BLTCON0 copia normale
  101.  
  102.     tst.w    d0            ; testa D0 per decidere il tipo di fill
  103.     bne.s    fill_esclusivo
  104.     move.w    #$000a,d2        ; valore di BLTCON1: settati i bit del
  105.                     ; fill inclusivo e del modo discendente
  106.     bra.s    test_fill_carry
  107.  
  108. fill_esclusivo:
  109.     move.w    #$0012,d2        ; valore di BLTCON1: settati i bit del
  110.                     ; fill esclusivo e del modo discendente
  111.  
  112. test_fill_carry:
  113.     tst.w    d1            ; testa D1 per vedere se deve settare
  114.                     ; il bit FILL_CARRYIN
  115.  
  116.     beq.s    fatto_bltcon1        ; se D1=0 salta..
  117.     bset    #2,d2            ; altrimenti setta il bit 2 di D2
  118.  
  119. fatto_bltcon1:
  120.     move.w    d2,$42(a5)        ; BLTCON1
  121.  
  122.     move.w    #12,$64(a5)        ; BLTAMOD larghezza 13 words (40-28=12)
  123.     move.w    #12,$66(a5)        ; BLTDMOD (40-28=12)
  124.  
  125.     move.l    #bitplane+180*40+28,$50(a5)
  126.                     ; BLTAPT (fisso al rettangolo sorgente)
  127.                     ; il rettangolo sorgente racchiude
  128.                     ; interamente le 2 linee.
  129.                     ; puntiamo l'ultima word del rettangolo
  130.                     ; per via del modo discendente
  131.  
  132.     move.l    a0,$54(a5)        ; BLTDPT  carica il parametro
  133.     move.w    #(64*121)+14,$58(a5)    ; BLTSIZE (via al blitter !)
  134.                     ; larghezza 14 words
  135.                     ; altezza 121 righe (1 plane)
  136.     rts
  137.  
  138. ;******************************************************************************
  139. ; Questa routine effettua il disegno di una linea, usando la speciale modalita`
  140. ; che consente di effettuare correttamente il fill. Prende come parametri gli
  141. ; estremi della linea P1 e P2, e l'indirizzo del bitplane su cui disegnarla.
  142. ; D0 - X1 (coord. X di P1)
  143. ; D1 - Y1 (coord. Y di P1)
  144. ; D2 - X2 (coord. X di P2)
  145. ; D3 - Y2 (coord. Y di P2)
  146. ; A0 - indirizzo bitplane
  147. ;******************************************************************************
  148.  
  149. ;       ("`-/")_.-'"``-._
  150. ;        . . `; -._    )-;-,_`)
  151. ;       (v_,)'  _  )`-.\  ``-'
  152. ;      _.- _..-_/ / ((.'
  153. ;    ((,.-'   ((,/
  154.  
  155. DrawlineFill:
  156.  
  157. * scelta ottante
  158.  
  159.     sub.w    d0,d2        ; D2=X2-X1
  160.     bmi.s    DRAW4        ; se negativo salta, altrimenti D2=DiffX
  161.     sub.w    d1,d3        ; D3=Y2-Y1
  162.     bmi.s    DRAW2        ; se negativo salta, altrimenti D3=DiffY
  163.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  164.     bmi.s    DRAW1        ; se D2<D3 salta..
  165.                 ; .. altrimenti D3=DY e D2=DX
  166.     moveq    #$10,d5        ; codice ottante
  167.     bra.s    DRAWL
  168. DRAW1:
  169.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  170.     moveq    #$00,d5        ; codice ottante
  171.     bra.s    DRAWL
  172. DRAW2:
  173.     neg.w    d3        ; rende D3 positivo
  174.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  175.     bmi.s    DRAW3        ; se D2<D3 salta..
  176.                 ; .. altrimenti D3=DY e D2=DX
  177.     moveq    #$18,d5        ; codice ottante
  178.     bra.s    DRAWL
  179. DRAW3:
  180.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  181.     moveq    #$04,d5        ; codice ottante
  182.     bra.s    DRAWL
  183. DRAW4:
  184.     neg.w    d2        ; rende D2 positivo
  185.     sub.w    d1,d3        ; D3=Y2-Y1
  186.     bmi.s    DRAW6        ; se negativo salta, altrimenti D3=DiffY
  187.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  188.     bmi.s    DRAW5        ; se D2<D3 salta..
  189.                 ; .. altrimenti D3=DY e D2=DX
  190.     moveq    #$14,d5        ; codice ottante
  191.     bra.s    DRAWL
  192. DRAW5:
  193.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  194.     moveq    #$08,d5        ; codice ottante
  195.     bra.s    DRAWL
  196. DRAW6:
  197.     neg.w    d3        ; rende D3 positivo
  198.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  199.     bmi.s    DRAW7        ; se D2<D3 salta..
  200.                 ; .. altrimenti D3=DY e D2=DX
  201.     moveq    #$1c,d5        ; codice ottante
  202.     bra.s    DRAWL
  203. DRAW7:
  204.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  205.     moveq    #$0c,d5        ; codice ottante
  206.  
  207. ; Quando l'esecuzione raggiunge questo punto, abbiamo:
  208. ; D2 = DX
  209. ; D3 = DY
  210. ; D5 = codice ottante
  211.  
  212. DRAWL:
  213.     mulu.w    #40,d1        ; offset Y
  214.     add.l    d1,a0        ; aggiunge l'offset Y all'indirizzo
  215.  
  216.     move.w    d0,d1        ; copia la coordinata X
  217.     and.w    #$000F,d0    ; seleziona i 4 bit piu` bassi della X..
  218.     ror.w    #4,d0        ; .. e li sposta nei bit da 12 a 15
  219.     or.w    #$0B4A,d0    ; con un OR ottengo il valore da scrivere
  220.                 ; in BLTCON0. Con questo valore di LF ($4A)
  221.                 ; si disegnano linee in EOR con lo sfondo.
  222.  
  223.     lsr.w    #4,d1        ; cancella i 4 bit bassi della X
  224.     add.w    d1,d1        ; ottiene l'offset X in bytes
  225.     add.w    d1,a0        ; aggiunge l'offset X all'indirizzo
  226.  
  227.     move.w    d2,d1        ; copia DX in D1
  228.     addq.w    #1,d1        ; D1=DX+1
  229.     lsl.w    #$06,d1        ; calcola in D1 il valore da mettere in BLTSIZE
  230.     addq.w    #2,d1        ; aggiunge la larghezza, pari a 2 words
  231.  
  232.     lsl.w    #$02,d3        ; D3=4*DY
  233.     add.w    d2,d2        ; D2=2*DX
  234.  
  235.     btst    #$06,$02(a5)
  236. WaitLine:
  237.     btst    #$06,$02(a5)    ; aspetta blitter fermo
  238.     bne.s    WaitLine
  239.  
  240.     move.w    d3,$62(a5)    ; BLTBMOD=4*DY
  241.     sub.w    d2,d3        ; D3=4*DY-2*DX
  242.     move.w    d3,$52(a5)    ; BLTAPTL=4*DY-2*DX
  243.  
  244.                 ; prepara valore da scrivere in BLTCON1
  245.     or.w    #$0003,d5    ; setta bit 0 (attiva line-mode), e
  246.                 ; il bit 1 (linee speciali per fill)
  247.  
  248.     tst.w    d3
  249.     bpl.s    OK1        ; se 4*DY-2*DX>0 salta..
  250.     or.w    #$0040,d5    ; altrimenti setta il bit SIGN
  251. OK1:
  252.     move.w    d0,$40(a5)    ; BLTCON0
  253.     move.w    d5,$42(a5)    ; BLTCON1
  254.     sub.w    d2,d3        ; D3=4*DY-4*DX
  255.     move.w    d3,$64(a5)    ; BLTAMOD=4*DY-4*DX
  256.     move.l    a0,$48(a5)    ; BLTCPT - indirizzo schermo
  257.     move.l    a0,$54(a5)    ; BLTDPT - indirizzo schermo
  258.     move.w    d1,$58(a5)    ; BLTSIZE
  259.     rts
  260.     
  261.  
  262. ;******************************************************************************
  263. ; Questa routine setta i registri del blitter che non devono essere
  264. ; cambiati tra una line e l'altra
  265. ;******************************************************************************
  266.  
  267. InitLine
  268.     btst    #6,2(a5) ; dmaconr
  269. WBlit_Init:
  270.     btst    #6,2(a5) ; dmaconr - attendi che il blitter abbia finito
  271.     bne.s    Wblit_Init
  272.  
  273.     moveq    #-1,d5
  274.     move.l    d5,$44(a5)        ; BLTAFWM/BLTALWM = $FFFF
  275.     move.w    #$8000,$74(a5)        ; BLTADAT = $8000
  276.     move.w    #40,$60(a5)        ; BLTCMOD = 40
  277.     move.w    #40,$66(a5)        ; BLTDMOD = 40
  278.     rts
  279.  
  280. ;******************************************************************************
  281. ; Questa routine definisce il pattern che deve essere usato per disegnare
  282. ; le linee. In pratica si limita a settare il registro BLTBDAT.
  283. ; D0 - contiene il pattern della linea 
  284. ;******************************************************************************
  285.  
  286. SetPattern
  287.     btst    #6,2(a5) ; dmaconr
  288. WBlit_Set:
  289.     btst    #6,2(a5) ; dmaconr - attendi che il blitter abbia finito
  290.     bne.s    Wblit_Set
  291.  
  292.     move.w    d0,$72(a5)    ; BLTBDAT = pattern delle linee
  293.     rts
  294.  
  295.  
  296. ;****************************************************************************
  297.  
  298.     SECTION    GRAPHIC,DATA_C
  299.  
  300. COPPERLIST:
  301.     dc.w    $8E,$2c81    ; DiwStrt
  302.     dc.w    $90,$2cc1    ; DiwStop
  303.     dc.w    $92,$38        ; DdfStart
  304.     dc.w    $94,$d0        ; DdfStop
  305.     dc.w    $102,0        ; BplCon1
  306.     dc.w    $104,0        ; BplCon2
  307.     dc.w    $108,0        ; Bpl1Mod
  308.     dc.w    $10a,0        ; Bpl2Mod
  309.  
  310.     dc.w    $100,$1200    ; Bplcon0 - 1 bitplane lowres
  311.  
  312. BPLPOINTERS:
  313.     dc.w    $e0,$0000,$e2,$0000    ;primo     bitplane
  314.  
  315.     dc.w    $0180,$000    ; color0
  316.     dc.w    $0182,$eee    ; color1
  317.     dc.w    $FFFF,$FFFE    ; Fine della copperlist
  318.  
  319. ;****************************************************************************
  320.  
  321.     Section    IlMioPlane,bss_C
  322.  
  323. BITPLANE:
  324.     ds.b    40*256        ; bitplane azzerato lowres
  325.  
  326.     end
  327.  
  328. ;****************************************************************************
  329.  
  330. In questo esempio disegnamo un poligono chiuso mediante linee.
  331. Come potete vedere sorge un piccolo problema nei punti in cui le linee si
  332. toccano, come abbiamo spiegato nella lezione.
  333. Nel prossimo esempio vedrete la soluzione a questo problema.
  334.  
  335.