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

  1.  
  2. ; Lezione10t1.s    Disegna una linea larga 2 pixel
  3.  
  4.     SECTION    CiriCop,CODE
  5.  
  6. ;    Include    "DaWorkBench.s"    ; togliere il ; prima di salvare con "WO"
  7.  
  8. *****************************************************************************
  9.     include    "startup1.s"    ; Salva Copperlist Etc.
  10. *****************************************************************************
  11.  
  12.         ;5432109876543210
  13. DMASET    EQU    %1000001111000000    ; copper,bitplane,blitter DMA
  14.  
  15.  
  16. START:
  17. ;    Puntiamo la PIC "vuota"
  18.  
  19.     MOVE.L    #BITPLANE,d0    ; dove puntare
  20.     LEA    BPLPOINTERS,A1    ; puntatori COP
  21.     move.w    d0,6(a1)
  22.     swap    d0
  23.     move.w    d0,2(a1)
  24.  
  25.     lea    $dff000,a5        ; CUSTOM REGISTER in a5
  26.     MOVE.W    #DMASET,$96(a5)        ; DMACON - abilita bitplane, copper
  27.     move.l    #COPPERLIST,$80(a5)    ; Puntiamo la nostra COP
  28.     move.w    d0,$88(a5)        ; Facciamo partire la COP
  29.     move.w    #0,$1fc(a5)        ; Disattiva l'AGA
  30.     move.w    #$c00,$106(a5)        ; Disattiva l'AGA
  31.     move.w    #$11,$10c(a5)        ; Disattiva l'AGA
  32.  
  33.     bsr.w    InitLine    ; inizializza line-mode
  34.  
  35.     move.w    #$ffff,d0    ; linea continua
  36.     bsr.w    SetPattern    ; definisce pattern
  37.  
  38.     move.w    #100,d0        ; x1
  39.     move.w    #100,d1        ; y1
  40.     move.w    #70,d2        ; x2
  41.     move.w    #220,d3        ; y2
  42.     lea    bitplane,a0
  43.     bsr.s    Drawline
  44.  
  45.     move.w    #160,d0        ; x1
  46.     move.w    #85,d1        ; y1
  47.     move.w    #160,d2        ; x2
  48.     move.w    #140,d3        ; y2
  49.     lea    bitplane,a0
  50.     bsr.s    Drawline
  51.  
  52.     move.w    #$f0f0,d0    ; linea trattegiata
  53.     bsr.w    SetPattern    ; definisce pattern
  54.  
  55.     move.w    #300,d0        ; x1
  56.     move.w    #200,d1        ; y1
  57.     move.w    #240,d2        ; x2
  58.     move.w    #90,d3        ; y2
  59.     lea    bitplane,a0
  60.     bsr.s    Drawline
  61.  
  62. mouse:
  63.     btst    #6,$bfe001    ; mouse premuto?
  64.     bne.s    mouse
  65.  
  66.     rts
  67.  
  68.  
  69. ;******************************************************************************
  70. ; Questa routine effettua il disegno della linea. prende come parametri gli
  71. ; estremi della linea P1 e P2, e l'indirizzo del bitplane su cui disegnarla.
  72. ; D0 - X1 (coord. X di P1)
  73. ; D1 - Y1 (coord. Y di P1)
  74. ; D2 - X2 (coord. X di P2)
  75. ; D3 - Y2 (coord. Y di P2)
  76. ; A0 - indirizzo bitplane
  77. ;******************************************************************************
  78.  
  79. Drawline:
  80.  
  81. * scelta ottante
  82.  
  83.     sub.w    d0,d2        ; D2=X2-X1
  84.     bmi.s    DRAW4        ; se negativo salta, altrimenti D2=DiffX
  85.     sub.w    d1,d3        ; D3=Y2-Y1
  86.     bmi.s    DRAW2        ; se negativo salta, altrimenti D3=DiffY
  87.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  88.     bmi.s    DRAW1        ; se D2<D3 salta..
  89.                 ; .. altrimenti D3=DY e D2=DX
  90.     moveq    #$10,d5        ; codice ottante
  91.     bra.s    DRAWL
  92. DRAW1:
  93.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  94.     moveq    #$00,d5        ; codice ottante
  95.     bra.s    DRAWL
  96. DRAW2:
  97.     neg.w    d3        ; rende D3 positivo
  98.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  99.     bmi.s    DRAW3        ; se D2<D3 salta..
  100.                 ; .. altrimenti D3=DY e D2=DX
  101.     moveq    #$18,d5        ; codice ottante
  102.     bra.s    DRAWL
  103. DRAW3:
  104.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  105.     moveq    #$04,d5        ; codice ottante
  106.     bra.s    DRAWL
  107. DRAW4:
  108.     neg.w    d2        ; rende D2 positivo
  109.     sub.w    d1,d3        ; D3=Y2-Y1
  110.     bmi.s    DRAW6        ; se negativo salta, altrimenti D3=DiffY
  111.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  112.     bmi.s    DRAW5        ; se D2<D3 salta..
  113.                 ; .. altrimenti D3=DY e D2=DX
  114.     moveq    #$14,d5        ; codice ottante
  115.     bra.s    DRAWL
  116. DRAW5:
  117.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  118.     moveq    #$08,d5        ; codice ottante
  119.     bra.s    DRAWL
  120. DRAW6:
  121.     neg.w    d3        ; rende D3 positivo
  122.     cmp.w    d3,d2        ; confronta DiffX e DiffY
  123.     bmi.s    DRAW7        ; se D2<D3 salta..
  124.                 ; .. altrimenti D3=DY e D2=DX
  125.     moveq    #$1c,d5        ; codice ottante
  126.     bra.s    DRAWL
  127. DRAW7:
  128.     exg.l    d2,d3        ; scambia D2 e D3, in modo che D3=DY e D2=DX
  129.     moveq    #$0c,d5        ; codice ottante
  130.  
  131. ; Quando l'esecuzione raggiunge questo punto, abbiamo:
  132. ; D2 = DX
  133. ; D3 = DY
  134. ; D5 = codice ottante
  135.  
  136. DRAWL:
  137.     mulu.w    #40,d1        ; offset Y
  138.     add.l    d1,a0        ; aggiunge l'offset Y all'indirizzo
  139.  
  140.     move.w    d0,d1        ; copia la coordinata X
  141.     and.w    #$000F,d0    ; seleziona i 4 bit piu` bassi della X..
  142.     ror.w    #4,d0        ; .. e li sposta nei bit da 12 a 15
  143.     or.w    #$0B4A,d0    ; con un OR ottengo il valore da scrivere
  144.                 ; in BLTCON0. Con questo valore di LF ($4A)
  145.                 ; si disegnano linee in EOR con lo sfondo.
  146.  
  147.     lsr.w    #4,d1        ; cancella i 4 bit bassi della X
  148.     add.w    d1,d1        ; ottiene l'offset X in bytes
  149.     add.w    d1,a0        ; aggiunge l'offset X all'indirizzo
  150.  
  151.     move.w    d2,d1        ; copia DX in D1
  152.     addq.w    #1,d1        ; D1=DX+1
  153.     lsl.w    #$06,d1        ; calcola in D1 il valore da mettere in BLTSIZE
  154.     addq.w    #2,d1        ; aggiunge la larghezza, pari a 2 words
  155.  
  156.     lsl.w    #$02,d3        ; D3=4*DY
  157.     add.w    d2,d2        ; D2=2*DX
  158.  
  159.     btst    #$06,$02(a5)
  160. WaitLine:
  161.     btst    #$06,$02(a5)    ; aspetta blitter fermo
  162.     bne.s    WaitLine
  163.  
  164.     move.w    d3,$62(a5)    ; BLTBMOD=4*DY
  165.     sub.w    d2,d3        ; D3=4*DY-2*DX
  166.     move.w    d3,$52(a5)    ; BLTAPTL=4*DY-2*DX
  167.  
  168.                 ; prepara valore da scrivere in BLTCON1
  169.     or.w    #$0001,d5    ; setta bit 0 (attiva line-mode)
  170.     tst.w    d3
  171.     bpl.s    OK1        ; se 4*DY-2*DX>0 salta..
  172.     or.w    #$0040,d5    ; altrimenti setta il bit SIGN
  173. OK1:
  174.     move.w    d0,$40(a5)    ; BLTCON0
  175.     move.w    d5,$42(a5)    ; BLTCON1
  176.     sub.w    d2,d3        ; D3=4*DY-4*DX
  177.     move.w    d3,$64(a5)    ; BLTAMOD=4*DY-4*DX
  178.     move.l    a0,$48(a5)    ; BLTCPT - indirizzo schermo
  179.     move.l    a0,$54(a5)    ; BLTDPT - indirizzo schermo
  180.     move.w    d1,$58(a5)    ; BLTSIZE
  181.     rts
  182.     
  183.  
  184. ;******************************************************************************
  185. ; Questa routine setta i registri del blitter che non devono essere
  186. ; cambiati tra una line e l'altra, settando BLTADAT in modo da tracciare
  187. ; linee doppie.
  188. ;******************************************************************************
  189.  
  190. InitLine:
  191.     btst    #6,2(a5) ; dmaconr
  192. WBlit_Init:
  193.     btst    #6,2(a5) ; dmaconr - attendi che il blitter abbia finito
  194.     bne.s    Wblit_Init
  195.  
  196.     moveq    #-1,d5
  197.     move.l    d5,$44(a5)        ; BLTAFWM/BLTALWM = $FFFF
  198.  
  199. ;      )\._.,--....,'``.
  200. ;     /,   _.. \   _\  (`._ ,.
  201. ;    `._.-(,_..'--(,_..'`-.;.'
  202.  
  203.     move.w    #$C000,$74(a5)        ; BLTADAT = $C000 - linee doppie
  204.     move.w    #40,$60(a5)        ; BLTCMOD = 40
  205.     move.w    #40,$66(a5)        ; BLTDMOD = 40
  206.     rts
  207.  
  208. ;******************************************************************************
  209. ; Questa routine definisce il pattern che deve essere usato per disegnare
  210. ; le linee. In pratica si limita a settare il registro BLTBDAT.
  211. ; D0 - contiene il pattern della linea 
  212. ;******************************************************************************
  213. SetPattern:
  214.     btst    #6,2(a5) ; dmaconr
  215. WBlit_Set:
  216.     btst    #6,2(a5) ; dmaconr - attendi che il blitter abbia finito
  217.     bne.s    Wblit_Set
  218.  
  219.     move.w    d0,$72(a5)    ; BLTBDAT = pattern linee
  220.     rts
  221.  
  222.  
  223. ;****************************************************************************
  224.  
  225.     SECTION    GRAPHIC,DATA_C
  226.  
  227. COPPERLIST:
  228.     dc.w    $8E,$2c81    ; DiwStrt
  229.     dc.w    $90,$2cc1    ; DiwStop
  230.     dc.w    $92,$38        ; DdfStart
  231.     dc.w    $94,$d0        ; DdfStop
  232.     dc.w    $102,0        ; BplCon1
  233.     dc.w    $104,0        ; BplCon2
  234.     dc.w    $108,0        ; Bpl1Mod
  235.     dc.w    $10a,0        ; Bpl2Mod
  236.  
  237.     dc.w    $100,$1200    ; Bplcon0 - 1 bitplane lowres
  238.  
  239. BPLPOINTERS:
  240.     dc.w    $e0,$0000,$e2,$0000    ;primo     bitplane
  241.  
  242.     dc.w    $0180,$000    ; color0
  243.     dc.w    $0182,$eee    ; color1
  244.     dc.w    $FFFF,$FFFE    ; Fine della copperlist
  245.  
  246. ;****************************************************************************
  247.  
  248.     Section    IlMioPlane,bss_C
  249.  
  250. BITPLANE:
  251.     ds.b    40*256        ; bitplane azzerato lowres
  252.  
  253.     end
  254.  
  255. ;****************************************************************************
  256.  
  257. In questo esempio vediamo come sia possibile tracciare linee larghe 2 pixel.
  258. Si procede esattamente come per le linee normali ma si inizializza BLTADAT
  259. con il valore $C000.
  260.  
  261.