home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / QLsource / ROMsrc / VDU / VDU_asm
Encoding:
Text File  |  1978-03-06  |  18.6 KB  |  903 lines

  1.     SECTION    VDU
  2.  
  3.     INCLUDE    '/INC/QDOS_inc'
  4.     INCLUDE    '/INC/AMIGA_inc'
  5.     INCLUDE    '/INC/AMIGQDOS_inc'
  6.  
  7. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. ; VDU1_asm - VDU routines
  9. ;      - last modified 30/08/95
  10.  
  11. ; These are all the necessary screen related sources, required
  12. ; to implement a QL-like screen on the Amiga computer.
  13.  
  14. ; Amiga-QDOS sources by Rainer Kowallik
  15. ;    ...latest changes by Mark J Swift
  16.  
  17. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. ;  ROM header
  19.  
  20. BASE:
  21.     dc.l    $4AFB0001    ; ROM recognition code
  22.     dc.w    PROC_DEF-BASE    ; add BASIC procs here
  23.     dc.w    ROM_START-BASE
  24.     dc.b    0,32,'Amiga-QDOS QL-like screen v1.25',$A
  25.  
  26. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. ;  start of ROM code
  28.  
  29. ROM_START:
  30.     movem.l    d0-d3/a0-a3,-(a7)
  31.  
  32. ; --------------------------------------------------------------
  33. ;  allocate memory for VDU patch variables
  34.  
  35.     move.l    #VV_LEN,d1
  36.     moveq    #MT.ALCHP,d0
  37.     moveq    #0,d2
  38.     trap    #1
  39.  
  40. ; --------------------------------------------------------------
  41. ;  address of VDU patch variables
  42.  
  43.     move.l    a0,AV.VDUV
  44.     move.l    a0,a3
  45.  
  46. ; --------------------------------------------------------------
  47. ;  enter supervisor mode and disable interrupts
  48.  
  49.     trap    #0
  50.  
  51.     ori.w    #$0700,sr    ; disable interrupts
  52.  
  53. ; --------------------------------------------------------------
  54. ;  link a custom routine into level 7 interrupt server
  55.  
  56.     lea    AV.LVL7link,a1
  57.     lea    VV.LVL7link(a3),a2
  58.  
  59.     move.l    (a1),(a2)
  60.     move.l    a2,(a1)
  61.  
  62.     lea    MY_LVL7(pc),a1
  63.     move.l    a1,$04(a2)
  64.  
  65. ; --------------------------------------------------------------
  66. ;  initialise hardware
  67.  
  68.     bsr.s    INIT_HW
  69.  
  70. ; -------------------------------------------------------------
  71. ; link in external interrupt to act on blitter
  72.  
  73.     lea    XINT_SERver(pc),a1 ; address of routine
  74.     lea    VV.XINTLink(a3),a0
  75.     move.l    a1,4(a0)
  76.     moveq    #MT.LXINT,d0
  77.     trap    #1
  78.  
  79. ; --------------------------------------------------------------
  80. ;  link in polled task to control screen blitter
  81.  
  82.     lea    POLL_SERver(pc),a1 ; address of routine
  83.     lea    VV.POLLLink(a3),a0
  84.     move.l    a1,4(a0)
  85.     moveq    #MT.LPOLL,d0
  86.     trap    #1
  87.  
  88. ; --------------------------------------------------------------
  89. ;  enable interrupts and re-enter user mode
  90.  
  91.     andi.w    #$D8FF,sr
  92.  
  93. ; --------------------------------------------------------------
  94. ROM_EXIT:
  95.     movem.l    (a7)+,d0-d3/a0-a3
  96.     rts
  97.  
  98. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99. ;  initialise screen parameters
  100.  
  101. INIT_HW:
  102.     movem.l    d0/a0/a3,-(a7)
  103.  
  104. INIT_BZY:
  105.     btst    #6,DMACONR    ; wait for blitter
  106.     bne.s    INIT_BZY
  107.  
  108.     move.w    #%0000001111100000,DMACON ; disable cop, blt...
  109.  
  110.     move.w    #$20,BEAMCON0    ; set PAL bit, reset ECS bit
  111.     move.w    #0,FMODE     ; set for no sprite or
  112.                 ; bitplane scan doubling, plus
  113.                 ; sprite and bitplane fetch by
  114.                 ; 2 bytes (as pre AGA).
  115.     move.w    #0,BPLCON3    ; select lower color bank
  116.                 ; from palette
  117.  
  118.     lea    SPRNULL,a0
  119.     lea    SPRTBL(PC),a3
  120.     move.w    #((SPREND-SPRTBL)/4),d0
  121.  
  122. SPR_LUP:
  123.     move.l    (a3)+,(a0)+
  124.     dbra    d0,SPR_LUP
  125.  
  126.     lea    COPLST,a0
  127.     lea    COPTBL(PC),a3
  128.     move.w    #((COPEND-COPTBL)/4),d0
  129.  
  130. COP_LUP:
  131.     move.l    (a3)+,(a0)+
  132.     dbra    d0,COP_LUP
  133.  
  134.  
  135.     lea    COPLST,a0    ; start of copper list
  136.     move.l    a0,COP1LC    ; Set copper start address
  137.     move.l    a0,COP2LC
  138.  
  139.     move.w    #0,COPCON    ; inhibit blitter control by
  140.                 ; copper
  141.     move.w    #0,COPJMP1    ; set copper PC
  142.  
  143. ; -------------------------------------------------------------
  144. ;  allow DMA by video, blitter, copper.
  145.  
  146.     move.w    #%1000001111100000,DMACON ; DMA for copper,
  147.                         ; blitter, video.
  148.     move.w    #%0000010000000000,DMACON ; clear blitter
  149.                         ; priority.
  150.  
  151. ; -------------------------------------------------------------
  152. ;  initialise variables that control screen blitter
  153.  
  154.     move.l    AV.VDUV,a3
  155.  
  156.     bclr.b    #7,AV.FLGS1
  157.     bclr.b    #6,AV.FLGS1
  158.  
  159.     move.w    #0,VV.PRICNt(a3)    ; initialise screen count
  160.     move.w    #0,VV.PRIACc(a3)    ; initialise accumulated pri
  161.     move.b    #1,VV.PRIBNd(a3)    ; set screen priority to
  162.     move.b    #4,VV.PRIINc(a3)    ; move (4/1)*(1/16)th QL
  163.                 ; screen every 1/50th sec
  164.  
  165.     bset    #MC..M256,VV.STAT(a3)
  166.  
  167.     move.w    #BLACK,VV.4COL0(a3)
  168.     move.w    #RED,VV.4COL1(a3)
  169.     move.w    #GREEN,VV.4COL2(a3)
  170.     move.w    #WHITE,VV.4COL3(a3)
  171.  
  172.     move.w    #BLACK,VV.8COL0(a3)
  173.     move.w    #$0708,VV.8COL1(a3)
  174.     move.w    #$00FA,VV.8COL2(a3)
  175.     move.w    #WHITE,VV.8COL3(a3)
  176.  
  177.     ; move.w   VV.8COL0(a3),COPLST+COPCOL0-COPTBL
  178.     ; move.w   VV.8COL1(a3),COPLST+COPCOL1-COPTBL
  179.     ; move.w   VV.8COL2(a3),COPLST+COPCOL2-COPTBL
  180.     ; move.w   VV.8COL3(a3),COPLST+COPCOL3-COPTBL
  181.  
  182.     move.w    VV.8COL0(a3),COLOR00
  183.     move.w    VV.8COL1(a3),COLOR01
  184.     move.w    VV.8COL2(a3),COLOR02
  185.     move.w    VV.8COL3(a3),COLOR03
  186.  
  187.     movem.l    (a7)+,d0/a0/a3
  188.     rts
  189.  
  190. ; -------------------------------------------------------------
  191. SPRTBL:
  192.  
  193. ; null sprite
  194.     dc.w    $FF00,$FF66
  195.     dc.w    0,0
  196.  
  197. ; pointer sprite
  198.     dc.w    (($2C&$FF)<<8)|($A0>>1)
  199.     dc.w    ((($2C+$10)&$FF)<<8)|($2C&1)<<2|(($2C+$10)&1)<<1|($A0&1)
  200.  
  201.     dc.w    %1100000000000000,%0100000000000000
  202.     dc.w    %0111000000000000,%1011000000000000
  203.     dc.w    %0011110000000000,%0100110000000000
  204.     dc.w    %0011111100000000,%0100001100000000
  205.     dc.w    %0001111111000000,%0010000011000000
  206.     dc.w    %0001111111000000,%0010000000000000
  207.     dc.w    %0000111100000000,%0001000100000000
  208.     dc.w    %0000110110000000,%0001001010000000
  209.     dc.w    %0000010011000000,%0000100101000000
  210.     dc.w    %0000010001100000,%0000100010100000
  211.     dc.w    %0000000000100000,%0000000001000000
  212.     dc.w    %0000000000000000,%0000000000000000
  213.     dc.w    %0000000000000000,%0000000000000000
  214.     dc.w    %0000000000000000,%0000000000000000
  215.     dc.w    %0000000000000000,%0000000000000000
  216.     dc.w    %0000000000000000,%0000000000000000
  217.  
  218.     dc.w    0,0
  219.  
  220. SPREND:
  221. ; -------------------------------------------------------------
  222. COPTBL:
  223.     ; move #0,BPL1PTH
  224.     dc.w    BPL1PTH&$1FE,0
  225.  
  226.     ; move    #$FFFF,DIWSTRT
  227.     dc.w    DIWSTRT&$1FE,$FFFF
  228.  
  229.     ; move    #%1000001000000000,BPLCON0
  230.     ; Hires, 0 planes, colour
  231.     dc.w    BPLCON0&$1FE,%1000001000000000
  232.  
  233.     ; move    #BLACK,COLOR00
  234.     ; dc.w      COLOR00&$1FE,BLACK
  235. COPSPR0:
  236.     ; move SPRNULL.hi,SPR0PTH
  237.     dc.w    SPR0PTH&$1FE,SPRNULL>>16
  238.  
  239.     ; move SPRNULL.lo,SPR0PTL
  240.     dc.w    SPR0PTL&$1FE,SPRNULL&$FFFF
  241.  
  242.     ; move SPRNULL.hi,SPR1PTH
  243.     dc.w    SPR1PTH&$1FE,SPRNULL>>16
  244.  
  245.     ; move SPRNULL.lo,SPR1PTL
  246.     dc.w    SPR1PTL&$1FE,SPRNULL&$FFFF
  247.  
  248.     ; move SPRNULL.hi,SPR2PTH
  249.     dc.w    SPR2PTH&$1FE,SPRNULL>>16
  250.  
  251.     ; move SPRNULL.lo,SPR2PTL
  252.     dc.w    SPR2PTL&$1FE,SPRNULL&$FFFF
  253.  
  254.     ; move SPRNULL.hi,SPR3PTH
  255.     dc.w    SPR3PTH&$1FE,SPRNULL>>16
  256.  
  257.     ; move SPRNULL.lo,SPR3PTL
  258.     dc.w    SPR3PTL&$1FE,SPRNULL&$FFFF
  259.  
  260.     ; move SPRNULL.hi,SPR4PTH
  261.     dc.w    SPR4PTH&$1FE,SPRNULL>>16
  262.  
  263.     ; move SPRNULL.lo,SPR4PTL
  264.     dc.w    SPR4PTL&$1FE,SPRNULL&$FFFF
  265.  
  266.     ; move SPRNULL.hi,SPR5PTH
  267.     dc.w    SPR5PTH&$1FE,SPRNULL>>16
  268.  
  269.     ; move SPRNULL.lo,SPR5PTL
  270.     dc.w    SPR5PTL&$1FE,SPRNULL&$FFFF
  271.  
  272.     ; move SPRNULL.hi,SPR6PTH
  273.     dc.w    SPR6PTH&$1FE,SPRNULL>>16
  274.  
  275.     ; move SPRNULL.lo,SPR6PTL
  276.     dc.w    SPR6PTL&$1FE,SPRNULL&$FFFF
  277.  
  278.     ; move SPRNULL.hi,SPR7PTH
  279.     dc.w    SPR7PTH&$1FE,SPRNULL>>16
  280.  
  281.     ; move SPRNULL.lo,SPR7PTL
  282.     dc.w    SPR7PTL&$1FE,SPRNULL&$FFFF
  283.  
  284.     ; wait vpos $0C hpos $00
  285.     dc.w    (($0C00)&$FFFE)+1,$FFFE
  286.  
  287.     ; wait vpos $2B hpos $00
  288.     dc.w    (($2B00)&$FFFE)+1,$FFFE
  289.  
  290.     ; move    #BLACK,COLOR00
  291.     ; dc.w      COLOR00&$1FE
  292. COPCOL0:
  293.     ; dc.w      BLACK
  294.  
  295.     ; move    #RED,COLOR01
  296.     ; dc.w      COLOR01&$1FE
  297. COPCOL1:
  298.     ; dc.w      RED
  299.  
  300.     ; move    #GREEN,COLOR02
  301.     ; dc.w      COLOR02&$1FE
  302. COPCOL2:
  303.     ; dc.w      GREEN
  304.  
  305.     ; move    #WHITE,COLOR03
  306.     ; dc.w      COLOR03&$1FE
  307. COPCOL3:
  308.     ; dc.w      WHITE
  309.  
  310.     ; move    #$0E44,COLOR16
  311.     dc.w    COLOR16&$1FE,$0E44
  312.  
  313.     ; move    #$0E44,COLOR17
  314.     dc.w    COLOR17&$1FE,$0E44
  315.  
  316.     ; move    #$0000,COLOR18
  317.     dc.w    COLOR18&$1FE,$0000
  318.  
  319.     ; move    #$0EEC,COLOR19
  320.     dc.w    COLOR19&$1FE,$0EEC
  321.  
  322.     ; move BPLANE1.hi,BPL1PTH
  323.     dc.w    BPL1PTH&$1FE,BPLANE1>>16
  324.  
  325.     ; move BPLANE1.lo,BPL1PTL
  326.     dc.w    BPL1PTL&$1FE,BPLANE1&$FFFF
  327.  
  328.     ; move BPLANE2.hi,BPL2PTH
  329.     dc.w    BPL2PTH&$1FE,BPLANE2>>16
  330.  
  331.     ; move BPLANE2.lo,BPL2PTL
  332.     dc.w    BPL2PTL&$1FE,BPLANE2&$FFFF
  333.  
  334.     ; move BPLANE3.hi,BPL3PTH
  335.     dc.w    BPL3PTH&$1FE,BPLANE3>>16
  336.  
  337.     ; move BPLANE3.lo,BPL3PTL
  338.     dc.w    BPL3PTL&$1FE,BPLANE3&$FFFF
  339.  
  340.     ; move    #$2CA1,DIWSTRT     V & H start (44,161)
  341.     dc.w    DIWSTRT&$1FE,$2CA1
  342.  
  343.     ; move    #$2CA1,DIWSTOP  V&H stop (256+44+1,256+161+1)
  344.     dc.w    DIWSTOP&$1FE,$2CA1
  345.  
  346.     ; (Hstart/2-4.5) AND $FFF8 = ($A1/2-4.5) AND $FFF8
  347.     ; move    #$004C,DDFSTRT
  348.     dc.w    DDFSTRT&$1FE,$004C
  349.  
  350.     ; DDFSTRT + (pixels per line/4 -8) = $4C+(512/4-8)
  351.     ; move    #$00C4,DDFSTOP
  352.     dc.w    DDFSTOP&$1FE,$00CC
  353.  
  354.     ; move    #0,BPL1MOD
  355.     dc.w    BPL1MOD&$1FE,$FFFC
  356.  
  357.     ; move    #0,BPL2MOD
  358.     dc.w    BPL2MOD&$1FE,$FFFC
  359.  
  360.     ; move $2100,diwhigh ; upper bits for display window
  361.                ; start, stop     (ECS only)
  362.     dc.w    DIWHIGH&$1FE,$2100
  363.  
  364.     ; move    #%0100100,BPLCON2
  365.     dc.w    BPLCON2&$1FE,%0100100
  366.  
  367.     ; move    #0,BPLCON1
  368.     dc.w    BPLCON1&$1FE,$0000
  369.  
  370. COPCON0:
  371.     ; move    #%1010001000000000,BPLCON0
  372.     ; Hires, 2 planes, colour
  373.     dc.w    BPLCON0&$1FE,%1010001000000000
  374.  
  375.     ; wait vpos $2C hpos $00
  376.     dc.w    (($2C00)&$FFFE)+1,$FFFE
  377.  
  378.     ; wait forever
  379.     dc.w    $FFFF,$FFFE
  380.  
  381. COPEND:
  382.  
  383. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  384. ;  external interrupt server
  385.  
  386. XINT_SERver:
  387.     movem.l    d7/a0,-(a7)
  388.  
  389.     move.w    INTENAR,d7    ; read interrupt enable reg
  390.     btst    #6,d7        ; branch if BLIT ints not on
  391.     beq    XINT_OTHer
  392.  
  393.     move.w    INTREQR,d7    ; read interrupt request reg
  394.     btst    #6,d7        ; blitter ready interrupt?
  395.     bne    BLIT_SERver
  396.  
  397.  
  398. ; --------------------------------------------------------------
  399. ;  otherwise let another external interrupt server handle it
  400.  
  401. XINT_OTHer:
  402.     movem.l    (a7)+,d7/a0
  403.     rts
  404.  
  405. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  406. ;  server for blitter interrupt
  407.  
  408. BLIT_SERver:
  409.     movem.l    a3,-(a7)
  410.  
  411.     move.l    AV.VDUV,a3
  412.  
  413.     move.w    VV.PRICNt(a3),d7
  414.     bclr    #15,d7        ; decide if my blitter int
  415.     bne    BLIT_MINe
  416.  
  417.     movem.l    (a7)+,a3
  418.     bra    XINT_OTHer    ; ...not my problem
  419.  
  420. BLIT_MINe:
  421.     move.w    #%0000000001000000,INTENA ; disable blitter
  422.                         ; interrupt
  423.     move.w    #%0000000001000000,INTREQ ; clear interrupts
  424.  
  425.     move.w    d7,VV.PRICNt(a3)    ; signal no longer my blitr
  426.  
  427.     bclr.b    #6,AV.FLGS1    ; signal blitter now free
  428.  
  429.     bsr    TRY_BLIT
  430.  
  431. BLIT_EXIt:
  432.     movem.l    (a7)+,a3
  433.  
  434. ; -------------------------------------------------------------
  435. XINT_EXIt:
  436.     bra.s    XINT_OTHer
  437.  
  438. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  439. ; Start screen refresh if blitter free
  440.  
  441. TRY_BLIT:
  442.     movem.l    d0/d6-d7/a4-a6,-(a7)
  443.  
  444.     move.w    VV.PRIACc(a3),d6    ; accumulated screen
  445.                 ; priority
  446.     moveq    #0,d7
  447.     move.b    VV.PRIBNd(a3),d7    ; Priority bounds
  448.     sub.w    d7,d6        ; decide whether
  449.     bcs    TRY_EXIt     ; or not to blit again
  450.  
  451.     btst    #MC..BLNK,MC_STAT ; should we show a screen?
  452.     bne    TRY_EXIt     ; no.
  453.  
  454.     move.w    d6,VV.PRIACc(a3)    ; store accumulated priority
  455.  
  456.     btst.b    #7,AV.FLGS1    ; request blit disable?
  457.     bne    TRY_EXIt     ; ...yes, exit
  458.  
  459.     bset.b    #6,AV.FLGS1    ; try to grab blitter
  460.     bne    TRY_EXIt     ; ...exit if in use
  461.  
  462.     move.w    VV.PRICNt(a3),d7
  463.     bset    #15,d7        ; signal my blitter int
  464.     move.w    d7,VV.PRICNt(a3)
  465.  
  466. ; -------------------------------------------------------------
  467. ;  Start screen refresh
  468.  
  469. BLITSCRN:
  470.     move.w    VV.PRICNt(a3),d0
  471.     btst    #0,d0
  472.     beq    BLITODD        ; plane to show is odd
  473.  
  474. ; --------------------------------------------------------------
  475. ;  show even plane (green)
  476.  
  477. BLITEVN:
  478.  
  479. ; update priority counter
  480.  
  481.     move.w    VV.PRICNt(a3),d0
  482.     andi.w    #%1000111111111111,d0
  483.     addq    #1,d0
  484.     move.w    d0,VV.PRICNt(a3)
  485.  
  486. ; show first 1024 bytes of even bit plane
  487.  
  488.     andi.w    #$000E,d0
  489.     ror.w    #5,d0
  490.  
  491.     btst    #MC..SCRN,MC_STAT ; should we show screen#2?
  492.     beq.s    BLITEVN1
  493.  
  494.     move.l    #HW_SCRN2,a4    ; address of second screen
  495.     bra.s    BLITEVNX
  496.  
  497. BLITEVN1:
  498.     move.l    #HW_SCRN1,a4    ; address of first screen
  499.  
  500. BLITEVNX:
  501.     lea    0(a4,d0.w),a4    ; actual source A
  502.  
  503.     move.l    a4,a5
  504.     addq    #2,a5        ; src B
  505.  
  506.     move.w    #$0000,d6    ; shiftcount for A
  507.     move.w    #$8000,d7    ; shiftcount for B
  508.  
  509.     lsr.w    #1,d0
  510.     move.l    #BPLANE2,a6
  511.     lea    0(a6,d0.w),a6    ; destination address
  512.  
  513.     bsr    BLITBEGIn
  514.  
  515.     bra.s    TRY_EXIt
  516.  
  517. ; --------------------------------------------------------------
  518. ;  show odd plane (red)
  519.  
  520. BLITODD:
  521.  
  522. ; update priority counter
  523.  
  524.     move.w    VV.PRICNt(a3),d0
  525.     andi.w    #%1000111111111111,d0
  526.     addq    #1,d0
  527.     move.w    d0,VV.PRICNt(a3)
  528.  
  529. ; show first 1024 bytes of odd bit plane
  530.  
  531.     andi.w    #$000E,d0
  532.     ror.w    #5,d0
  533.  
  534.     btst    #MC..SCRN,MC_STAT ; should we show screen#2?
  535.     beq.s    BLITODD1
  536.  
  537.     move.l    #HW_SCRN2,a4    ; address of second screen
  538.     bra.s    BLITODDX
  539.  
  540. BLITODD1:
  541.     move.l    #HW_SCRN1,a4    ; address of first screen
  542.  
  543. BLITODDX:
  544.  
  545. ; move a single word so as to initialise blitter data
  546.  
  547.     lea    4(a4,d0.w),a4    ; actual source A
  548.  
  549.     move.l    a4,a5
  550.     subq    #2,a5        ; src B
  551.  
  552.     move.w    #$8000,d6    ; shiftcount for A
  553.     move.w    #$0000,d7    ; shiftcount for B
  554.  
  555.     lsr.w    #1,d0
  556.     move.l    #BPLANE1,a6
  557.     lea    0(a6,d0.w),a6    ; destination address
  558.  
  559.     bsr    BLITBEGIn    ; set registers, start DMA
  560.  
  561.     move.b    -1(a5),d0    ; replace first byte
  562.     move.b    d0,0(a6)
  563.  
  564. TRY_EXIt:
  565.     movem.l    (a7)+,d0/d6-d7/a4-a6
  566.  
  567.     rts
  568.  
  569. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  570. ;  Control blitter operation
  571. ;
  572. ; a4=src A , a5=src B , a6=dest
  573. ; d6= shift A , d7= shift B
  574.  
  575. ; The blitter takes the three sources A,B & C and performs a
  576. ; number of logical operations to give a result D, which is
  577. ; stored in the destination address. Each operation, (called
  578. ; a miniterm) is enabled via a bit in the bottom eight bits of
  579. ; the register BLTCON0.
  580. ; The operations performed on the source data are as folows:
  581.  
  582. ;(A*B*C) (A*B*c) (A*b*C) (A*b*c) (a*B*C) (a*B*c) (a*b*C) (a*b*c)
  583.  
  584. ; where a lowercase letter denotes a logical inversion of the
  585. ; relavent source data, * denotes a logical AND, + a logical OR.
  586.  
  587. ; We will be using C as a mask, to enable the high or low byte
  588. ; of a data word fetched from the QL screen. C will hold the
  589. ; constant $FF00
  590.  
  591. ; We require (A*C)+(B*c) = ((A*B*C)+(A*b*C))+((A*B*c)+(a*B*c))
  592.  
  593. ;   1       1      1     0    0       1       0       0
  594. ;(A.B.C) (A.B.c) (A.b.C) (A.b.c) (a.B.C) (a.B.c) (a.b.C) (a.b.c)
  595.  
  596. ; so BLTCON0 will hold %xxxxxxxx11100100
  597.  
  598. BLITBEGIn:
  599.  
  600. BLITBUSY:
  601.     move.w    DMACONR,d0
  602.     btst    #14,d0        ; blitter busy?
  603.     bne    BLITBUSY
  604.  
  605.     move.l    a4,BLTAPTH    ; write source address A to
  606.                 ; blitter
  607.     move.l    a5,BLTBPTH    ; write source address B to
  608.                 ; blitter
  609.     move.l    a6,BLTDPTH    ; write destination D to
  610.                 ; blitter
  611.  
  612.     move.w    #2,BLTAMOD    ; Modulo Source A
  613.     move.w    #2,BLTBMOD    ; same for B
  614.     move.w    #0,BLTDMOD    ; Modulo Destination
  615.  
  616.     move.w    #$FFFF,BLTAFWM    ; Mask for first word
  617.     move.w    #$FFFF,BLTALWM    ; same for last word
  618.     move.w    #$FF00,BLTCDAT    ; We use the C source for
  619.                 ; masking A and B
  620.  
  621.     move.w    d6,d0        ; shift count for src A
  622.     or.w    #%0000110100000000,d0 ; DMA for Src A,B and
  623.                     ; Dest D
  624.  
  625.     move.b    #%11100100,d0    ; src (A and C) or (B and c)
  626.                 ; miniterm
  627.     move.w    d0,BLTCON0    ; initialize Control
  628.                 ; register 0
  629.     move.w    d7,BLTCON1    ; shift for source B
  630.  
  631.     move.w    #$0001,BLTSIZE    ; =1024 lines * 64 + 1 Word
  632.                 ; per column
  633.  
  634.     move.w    #%1000000001000000,INTENA ; enable blitter
  635.                         ; interrupt
  636.     rts
  637.  
  638. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  639. ;  Polled routine to provide a  QL screen refresh via blitter
  640.  
  641. POLL_SERver:
  642.  
  643.     movem.l    d6-d7/a3,-(a7)
  644.  
  645.     btst.b    #7,AV.FLGS1    ; request blit disable?
  646.     bne    POLL_EXIt    ; ...yes, exit
  647.  
  648.     move.l    AV.VDUV,a3
  649.  
  650.     move.w    VV.PRIACc(a3),d6    ; accumulated screen
  651.                 ; priority
  652.     moveq    #0,d7
  653.     move.b    VV.PRIBNd(a3),d7
  654.     cmp.w    d7,d6
  655.     bcc.s    POLL_blnk    ; continue
  656.  
  657.     move.b    VV.PRIINc(a3),d7    ; Priority increment
  658.  
  659.     add.w    d7,d6        ; increment priority
  660.     move.w    d6,VV.PRIACc(a3)    ; store accumulated priority
  661.  
  662. ; blank screen if necessary
  663.  
  664. POLL_blnk
  665.     btst    #MC..BLNK,MC_STAT ; check blanking bit
  666.     beq.s    POLL_son
  667.  
  668. POLL_soff:
  669.     bset    #MC..BLNK,VV.STAT(a3)
  670.     bne    POLL_EXIt    ; already off, so exit
  671.  
  672.     move.w    #BLACK,COLOR00    ; all colours to black
  673.     move.w    #BLACK,COLOR01
  674.     move.w    #BLACK,COLOR02
  675.     move.w    #BLACK,COLOR03
  676.  
  677.     bra    POLL_EXIt    ; ...and exit
  678.  
  679. POLL_son:
  680.     bclr    #MC..BLNK,VV.STAT(a3)
  681.     beq.s    POLL_mode    ; already on
  682.  
  683.     btst    #MC..M256,MC_STAT ; check screen mode
  684.     bne.s    POLL_s8
  685.  
  686. POLL_s4:
  687.     bclr    #MC..M256,VV.STAT(a3)
  688.     bra.s    POLL_do4
  689.  
  690. POLL_s8:
  691.     bset    #MC..M256,VV.STAT(a3)
  692.     bra.s    POLL_do8
  693.  
  694. ; switch colours if in 8 colour mode ...a compromise.
  695.  
  696. POLL_mode
  697.     btst    #MC..M256,MC_STAT ; check screen mode
  698.     bne.s    POLL_8COl
  699.  
  700. POLL_4COl:
  701.     bclr    #MC..M256,VV.STAT(a3)
  702.     beq.s    POLL_1
  703.  
  704. POLL_do4:
  705.     ; move.w   VV.4COL0(a3),COPLST+COPCOL0-COPTBL
  706.     ; move.w   VV.4COL1(a3),COPLST+COPCOL1-COPTBL
  707.     ; move.w   VV.4COL2(a3),COPLST+COPCOL2-COPTBL
  708.     ; move.w   VV.4COL3(a3),COPLST+COPCOL3-COPTBL
  709.  
  710.     move.w    VV.4COL0(a3),COLOR00
  711.     move.w    VV.4COL1(a3),COLOR01
  712.     move.w    VV.4COL2(a3),COLOR02
  713.     move.w    VV.4COL3(a3),COLOR03
  714.  
  715.     bra    POLL_1        ; ...and do it
  716.  
  717. POLL_8COl:
  718.     bset    #MC..M256,VV.STAT(a3)
  719.     bne.s    POLL_1
  720.  
  721. POLL_do8:
  722.     ; move.w   VV.8COL0(a3),COPLST+COPCOL0-COPTBL
  723.     ; move.w   VV.8COL1(a3),COPLST+COPCOL1-COPTBL
  724.     ; move.w   VV.8COL2(a3),COPLST+COPCOL2-COPTBL
  725.     ; move.w   VV.8COL3(a3),COPLST+COPCOL3-COPTBL
  726.  
  727.     move.w    VV.8COL0(a3),COLOR00
  728.     move.w    VV.8COL1(a3),COLOR01
  729.     move.w    VV.8COL2(a3),COLOR02
  730.     move.w    VV.8COL3(a3),COLOR03
  731.  
  732. POLL_1:
  733.     bsr    TRY_BLIT
  734.  
  735. POLL_EXIt:
  736.     movem.l    (a7)+,d6-d7/a3
  737.     rts
  738.  
  739. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  740. ;  Custom LVL7 routine to initialise hardware
  741.  
  742. MY_LVL7:
  743.     bsr    INIT_HW
  744.  
  745.     subq.l    #4,a7
  746.     movem.l    a3,-(a7)
  747.     move.l    AV.VDUV,a3
  748.     move.l    VV.LVL7link(a3),a3
  749.     move.l    4(a3),4(a7)    ; address of next routine
  750.     movem.l    (a7)+,a3
  751.  
  752.     rts
  753.  
  754. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  755. ;  BASIC extensions specific to AMIGA QDOS
  756.  
  757. PROC_DEF:
  758.     dc.w    4
  759.     dc.w    B_SB_PRIority-*
  760.     dc.b    12,'SCR_PRIORITY',0
  761.     dc.w    B_PTR_ON-*
  762.     dc.b    6,'PTR_ON',0
  763.     dc.w    B_PTR_OFF-*
  764.     dc.b    7,'PTR_OFF'
  765.  
  766.     dc.w    0
  767.  
  768.     dc.w    0
  769.  
  770.     dc.w    0
  771.  
  772. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  773. ;  Usage... SCR_PRIORITY inc,bnd
  774.  
  775. ;  allow blitter to move (inc/bnd)*(1/16)th of the screen
  776. ;  every 1/50th of a second.
  777.  
  778. B_SB_PRIority:
  779.     bsr    FETCH_W
  780.     bne.s    B_SB_PRX
  781.  
  782.     move.w    d1,d2
  783.  
  784.     bsr    FETCH_W
  785.     bne.s    B_SB_PRX
  786.  
  787.     cmp.l    a3,a5
  788.     bne    RPRT_BP
  789.  
  790.     cmp.w    #256,d1
  791.     bcc    RPRT_BP
  792.  
  793.     tst.b    d1
  794.     beq    RPRT_BP
  795.  
  796.     cmp.w    #256,d2
  797.     bcc    RPRT_BP
  798.  
  799.     tst.b    d2
  800.     beq    RPRT_BP
  801.  
  802.     move.l    AV.VDUV,a0
  803.  
  804.     move.w    #0,VV.PRIACc(a0)
  805.     move.b    d2,VV.PRIINc(a0)
  806.     move.b    d1,VV.PRIBNd(a0)
  807.  
  808.     moveq    #0,d0
  809.  
  810. B_SB_PRX:
  811.     rts
  812.  
  813. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  814. B_PTR_ON:
  815.     cmp.l    a3,a5
  816.     bne    RPRT_BP
  817.  
  818.     move.w    #SPRLST>>16,COPLST+COPSPR0-COPTBL+2
  819.     move.w    #SPRLST&$FFFF,COPLST+COPSPR0-COPTBL+6
  820.     moveq    #0,d0
  821.     RTS
  822.  
  823. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  824. B_PTR_OFF:
  825.     cmp.l    a3,a5
  826.     bne    RPRT_BP
  827.  
  828.     move.w    #SPRNULL>>16,COPLST+COPSPR0-COPTBL+2
  829.     move.w    #SPRNULL&$FFFF,COPLST+COPSPR0-COPTBL+6
  830.     moveq    #0,d0
  831.     RTS
  832.  
  833. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  834. ; Fetch one Word
  835.  
  836. FETCH_W:
  837.     movem.l    a2,-(a7)
  838.  
  839.     move.w    CA.GTINT,a2
  840.     bsr.s    GET_ONE
  841.     bne.s    FETCH_WX
  842.  
  843.     move.l    a1,BV_RIP(a6)
  844.     moveq    #0,d1
  845.     move.w    0(a6,a1.l),d1
  846.     addq.l    #2,BV_RIP(a6)
  847.  
  848. FETCH_WX:
  849.     movem.l    (a7)+,a2
  850.     tst.l    d0
  851.     rts
  852.  
  853. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  854. ;  This routine gets one parameter and returns it on the maths
  855. ;  stack, pointed to by (A1).
  856. ;
  857. ; Entry: A2.L   routine to call (i.e. CA.GTINT)
  858. ;    A3.L   pointer to first parameter
  859. ;    A5.L   pointer to last parameter
  860. ;
  861. ; Exit:    A3.L   updated
  862. ;    A5.L   updated
  863. ;    A1.L   updated pointer to top of maths stack
  864. ;    D0.L   error code
  865.  
  866. GET_ONE:
  867.     movem.l    d1-d6/a0/a2,-(a7)
  868.  
  869.     lea    8(a3),a0
  870.     cmp.l    a0,a5
  871.     blt.s    GET_ONEBp
  872.  
  873.     move.l    BV_RIP(a6),a1
  874.     move.l    a5,-(a7)
  875.     move.l    a0,a5
  876.     move.l    a5,-(a7)
  877.     jsr    (a2)
  878.     movem.l    (a7)+,a0/a5
  879.  
  880.     tst.l    d0
  881.     bne.s    GET_ONEX
  882.  
  883.     move.l    a0,a3
  884.     move.l    a1,BV_RIP(a6)
  885.  
  886.     bra.s    GET_ONEX
  887.  
  888. GET_ONEBp:
  889.     moveq    #ERR.BP,d0
  890.  
  891. GET_ONEX:
  892.     movem.l    (a7)+,d1-d6/a0/a2
  893.     tst.l    d0
  894.     rts
  895.  
  896. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  897. RPRT_BP:
  898.     moveq    #ERR.BP,d0
  899.     rts
  900.  
  901. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  902.     END
  903.