home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / tools / Forth / video.inc < prev   
Encoding:
Text File  |  2006-10-19  |  15.3 KB  |  1,138 lines

  1. ;    V9t9: the TI Emulator! v6.0 Source 
  2. ;    Copyright (c) 1996 by Edward Swartz
  3.  
  4.  
  5.  
  6.  
  7. ;    Initialize video.  Defaults to text mode.
  8. ;
  9.  
  10. vinit    si    SP,4
  11.     mov    11,@2(SP)
  12.     mov    0,*SP
  13.  
  14.     li    0,15
  15.     mov    0,@vcrstimer            ; set up standard blink
  16.     sb    @vcurs,@vcurs            ; it's off
  17.  
  18.     li    1,>0107
  19.     mov    1,@vfg
  20.  
  21.     blwp    @vtextsetup
  22.     blwp    @vscreenon
  23.  
  24.     mov    +*SP,0
  25.     mov    +*SP,11
  26.     rt
  27.  
  28.  
  29.  
  30. ;=========================================================================
  31. ;    Internally called routines
  32. ;    
  33. ;    (IM=0)
  34. ;=========================================================================
  35.  
  36.  
  37. ;    Set GROM write addr in R0
  38. ;
  39.  
  40. gwaddr    movb    0,@>9c02
  41.     swpb    0
  42.     movb    0,@>9c02
  43.     swpb    0
  44.     rt
  45.  
  46.  
  47.  
  48. ;    Set VDP write/read addr in R0
  49. ;
  50.  
  51. vwaddr    ori    0,>4000
  52. vraddr    swpb    0
  53.     movb    0,@>8c02
  54.     swpb    0
  55.     movb    0,@>8c02
  56.     andi    0,>3fff
  57.     rt
  58.  
  59.  
  60. ;    Video clear.
  61. ;
  62. ;    R0=addr
  63. ;    R1=char
  64. ;    R2=#
  65.  
  66. vclr    si    SP,4
  67.     mov    11,@2(SP)
  68.     mov    2,*SP
  69.  
  70.     bl    @vwaddr
  71. vclr0    movb    1,@>8c00
  72.     dec    2
  73.     jgt    vclr0
  74.     
  75.     mov    +*SP,2
  76.     mov    +*SP,11
  77.     rt
  78.  
  79.  
  80.  
  81. ;    Figure screen addr for text.
  82. ;
  83. ;    hi(R0) = X in window
  84. ;    lo(R0) = Y in window
  85. ;
  86. ;    Returns R0=addr
  87.  
  88. d40    data    40
  89.  
  90. vtextaddr si    SP,4
  91.     mov    1,@2(SP)
  92.     mov    2,*SP
  93.     
  94.     mov    0,2                ; save X
  95.     swpb    0
  96.  
  97.     ab    @vwy,0
  98.     srl    0,8
  99.     mpy    @d40,0                ; get row offset in R1
  100.  
  101.     movb    2,0
  102.     ab    @vwx,0
  103.     srl    0,8                   ; get column offset
  104.  
  105.     a    1,0                ; column+row
  106.     a    @vscreen,0            ; R0=addr
  107.  
  108.     mov    +*SP,2
  109.     mov    +*SP,1
  110.     rt
  111.  
  112.  
  113.  
  114. ;    Figure screen addr for gfx.
  115. ;
  116. ;    hi(R0) = X in window
  117. ;    lo(R0) = Y in window
  118. ;
  119. ;    Returns R0=addr
  120.  
  121. vgraphaddr si    SP,4
  122.     mov    1,@2(SP)
  123.     mov    2,*SP
  124.     
  125.     mov    0,2                ; save X
  126.     swpb    0
  127.  
  128.     ab    @vwy,0
  129.     srl    0,8
  130.     sla    0,5
  131.  
  132.     movb    2,1
  133.     ab    @vwx,1
  134.     srl    1,8                   ; get column offset
  135.  
  136.     a    1,0                ; column+row
  137.     a    @vscreen,0            ; R0=addr
  138.  
  139.     mov    +*SP,2
  140.     mov    +*SP,1
  141.     rt
  142.  
  143.  
  144. ;    Figure screen addr for bitmap.
  145. ;
  146. ;    hi(R0) = X in window
  147. ;    lo(R0) = Y in window
  148. ;
  149. ;    Returns R0=addr
  150.  
  151. vbitaddr si    SP,4
  152.     mov    1,@2(SP)
  153.     mov    2,*SP
  154.     
  155.     mov    0,2                ; save X
  156.  
  157.     andi    0,>ff                ; get >00YY
  158.     swpb    0                ; >yy * bitoffs = >yy00
  159.     ab    @vwy,0
  160.  
  161.     movb    2,1
  162.     ab    @vwx,1
  163.     srl    1,8                   ; get column offset
  164.     sla    1,3
  165.  
  166.     a    1,0                ; column+row
  167.                         ; R0 = offs only
  168.  
  169.     mov    +*SP,2
  170.     mov    +*SP,1
  171.     rt
  172.  
  173.  
  174.  
  175.  
  176. ;    Clear some text line.
  177. ;    
  178. ;    R0=coord
  179. ;    R1=char
  180. ;    R2=length
  181.  
  182. vtextclearline
  183.     si    SP,6
  184.     mov    0,@4(SP)
  185.     mov    3,@2(SP)
  186.     mov    11,*SP
  187.  
  188.     mov    @vcoordaddr,3
  189.     bl    *3
  190.     bl    @vclr                ; clear out line
  191.  
  192.     mov    +*SP,11
  193.     mov    +*SP,3
  194.     mov    +*SP,0
  195.     rt
  196.  
  197.  
  198. ;    Clear some bitmapped line.
  199. ;    
  200. ;    R0=coord
  201. ;    R1=char
  202. ;    R2=length
  203.  
  204. vbitclearline
  205.     si    SP,8
  206.     mov    0,@6(SP)
  207.     mov    1,@4(SP)
  208.     mov    3,@2(SP)
  209.     mov    11,*SP
  210.  
  211.     clr    1
  212.  
  213.     mov    @vcoordaddr,3
  214.     bl    *3
  215.  
  216.     mov    0,3
  217.     a    @vpatts,0
  218.     bl    @vclr                ; clear out line
  219.  
  220.     movb    @vmono,@vmono
  221.     jne    vbclbl
  222.  
  223.     mov    3,0
  224.     a    @vcolors,0
  225.  
  226.     clr    1
  227.     movb    @vfg,1
  228.     sla    1,4
  229.     socb    @vbg,1
  230.     bl    @vclr                ; clear out line
  231.  
  232. vbclbl:
  233.     mov    +*SP,11
  234.     mov    +*SP,3
  235.     mov    +*SP,1
  236.     mov    +*SP,0
  237.     rt
  238.  
  239.  
  240.  
  241.  
  242. ;==========================================================================
  243. ;    Externally called video functions.
  244. ;
  245. ;    IM=1, so we must turn off interrupts to use VDP.
  246. ;
  247. ;    Use BLWP @ for new workspace AND assurance of correct
  248. ;    IM on exit.
  249. ;==========================================================================
  250.  
  251.  
  252. ;    Turn the screen on or off.
  253. ;
  254. ;    NOTE:    TIMER & KBD interrupt call these.  
  255. ;    Don't change any registers or use the stack!
  256. ;
  257. ;    NOTE:  
  258. ;
  259.  
  260. vscreenoff data    vidws,vscreenoff 4+
  261.     szcb     @h40,@vregs 1+
  262.     jmp    vreg1set
  263. vscreenon data     vidws,vscreenon 4+
  264.     socb    @h40,@vregs 1+
  265. vreg1set:
  266.     limi    0
  267.     movb    @vregs 1 +,@>8c02
  268.     movb    @h81,@>8c02
  269.     rtwp
  270.  
  271.  
  272.  
  273. ;-------------------------------------------------------------------------
  274. ;        0=graphics mode
  275. ;            >0000 = screen
  276. ;            >0300 = sprites
  277. ;            >0380 = colors
  278. ;            >03A0 = sprite motion
  279. ;            >0420 = sprite patterns (really 0->800)
  280. ;            >0800 = char patts
  281. ;            >1000+= free
  282. ;
  283. ;        1=text mode
  284. ;            >0000 = screen
  285. ;            >0800 = patts
  286. ;            >1000+= free
  287. ;
  288. ;        2=bitmap mode
  289. ;            >0000 = patts
  290. ;            >1800 = screen
  291. ;            >1B00 = sprites
  292. ;            >1B80 = sprite motion
  293. ;            >1C00 = sprite patts
  294. ;            >2000 = colors
  295. ;            >3800+= free
  296. ;
  297. ;        3=monochrome bitmap mode
  298. ;            >0000 = patts
  299. ;            >1800 = screen
  300. ;            >1B00 = sprites
  301. ;            >1B80 = sprite motion
  302. ;            >1C00 = sprite patts
  303. ;            >2000 = colors
  304. ;            >2040+= free
  305. ;
  306. ;
  307. ;-------------------------------------------------------------------------
  308.  
  309. vtmap    dw    vscreen,vsprites,vcolors,vsprpat,vpatts,vfree
  310.     dw    vdrawchar,vscroll,vclear,vwidth,vcursor,vcoordaddr
  311.  
  312. vgfx     db    >0,>A0,>0,>E,>1,>6,>0,>f    ; last byte*>80 = motion tbl
  313. vgfxt    dw    >0,>300,>380,>0,>800,>1000
  314.     dw    vtextchar,vgraphscroll,vtextclear,>2018,vtextcursor,vgraphaddr
  315.  
  316. vtxt     db    >0,>B0,>0,>0,>1,>0,>0,0
  317. vtxtt    dw    >0,>0,>0,>0,>800,>1000
  318.     dw    vtextchar,vtextscroll,vtextclear,>2818,vtextcursor,vtextaddr
  319.  
  320. vbit     db    >2,>A0,>6,>ff,>03,>36,>3,>37
  321. vbitt    dw    >1800,>1b00,>2000,>1800,>0,>3800
  322.     dw    vbitchar,vbitscroll,vbitclear,>2018,vbitcursor,vbitaddr
  323.  
  324.  
  325. vsetupregs:
  326.     li    12,>8c02
  327.     li    0,>8000
  328.     mov    *1,@vregs
  329.  
  330.     li    2,7
  331. vts0    movb    +*1,*12
  332.     movb    0,*12
  333.     ai    0,>100
  334.     dec    2
  335.     jgt    vts0
  336.  
  337.     movb    +*1,2
  338.     srl    2,9
  339.     mov    2,@vsprmot
  340.  
  341.     clr    1
  342.     movb    @vfg,1
  343.     sla    1,4
  344.     socb    @vbg,1
  345.     movb    1,*12
  346.     movb    0,*12
  347.  
  348.     rt
  349.  
  350.  
  351. vsetupaddrs:
  352.     li    0,vtmap
  353.     li    2,12
  354. vts1    mov    +*1,3
  355.     mov    +*0,4
  356.     mov    3,*4
  357.     dec    2
  358.     jgt    vts1
  359.     rt
  360.  
  361.  
  362. vtextsetup     data vidws,vtextsetup 4+
  363.     limi    0
  364.     li    SP,vstack vstacksize +
  365.  
  366.     li    1,M_text 256 *
  367.     movb    1,@vidmode
  368.  
  369.     li    1,vtxt
  370.     bl    @vsetupregs
  371.  
  372.     li    1,vtxtt
  373.     bl    @vsetupaddrs
  374.  
  375.     clr    0
  376.     li    1,>2000
  377.     li    2,960
  378.     bl    @vclr
  379.  
  380.     clr    0
  381.     bl    @vgetfont
  382.  
  383.     movb    @hunder,@vcurschar
  384.  
  385.     rtwp
  386.  
  387.  
  388. vgraphsetup     data vidws,vgraphsetup 4+
  389.     limi    0
  390.     li    SP,vstack vstacksize +
  391.  
  392.     li    1,M_graph 256 *
  393.     movb    1,@vidmode
  394.  
  395.     li    1,vgfx
  396.     bl    @vsetupregs
  397.  
  398.     li    1,vgfxt
  399.     bl    @vsetupaddrs
  400.  
  401.     mov    @vsprites,0
  402.     clr    1
  403.     li    2,128
  404.     bl    @vclr
  405.  
  406.     mov    @vcolors,0
  407.     li    1,>1000
  408.     li    2,32
  409.     bl    @vclr
  410.  
  411.     clr    0
  412.     li    1,>2000
  413.     li    2,768
  414.     bl    @vclr
  415.  
  416.     mov    @vsprmot,0
  417.     clr    1
  418.     li    2,128
  419.     bl    @vclr
  420.  
  421.  
  422.     movb    @hunder,@vcurschar
  423.  
  424.  
  425.     clr    0
  426.     bl    @vgetfont
  427.  
  428.     rtwp
  429.  
  430.  
  431. vbitmapsetup     data vidws,vbitmapsetup 4+
  432.     limi    0
  433.     li    SP,vstack vstacksize +
  434.  
  435.     movb    @h00,@vmono
  436.  
  437. vbitsentr:
  438.     li    1,M_bit 256 *
  439.     movb    1,@vidmode
  440.  
  441.     li    1,vbit
  442.     bl    @vsetupregs
  443.  
  444.     li    1,vbitt
  445.     bl    @vsetupaddrs
  446.  
  447.     movb    @Hff,@vcurschar
  448.  
  449.     mov    @vpatts,0
  450.     clr    1
  451.     li    2,>1800
  452.     bl    @vclr
  453.  
  454.     mov    @vcolors,0
  455.     clr    1
  456.     movb    @vfg,1
  457.     sla    1,4
  458.     socb    @vbg,1
  459. ;    li    2,>1800
  460.     bl    @vclr
  461.  
  462.     mov    @vsprites,0
  463.     clr    1
  464.     li    2,128
  465.     bl    @vclr
  466.  
  467.     mov    @vsprmot,0
  468.     clr    1
  469. ;    li    2,128
  470.     bl    @vclr
  471.  
  472.  
  473.  
  474.     mov    @vscreen,0
  475.     bl    @vwaddr
  476.     clr    1
  477.     li    2,768
  478. vbs2    movb    1,@>8c00
  479.     ai    1,>100
  480.     dec    2
  481.     jgt    vbs2
  482.  
  483.  
  484.     rtwp
  485.  
  486.  
  487. vmonosetup     data vidws,vmonosetup 4+
  488.     limi    0
  489.     li    SP,vstack vstacksize +
  490.  
  491.     movb    @h01,@vmono
  492.     jmp    vbitsentr
  493.  
  494.  
  495. ;    Get a font from GROM and load into pattern table.
  496. ;
  497. ;    (All) R0= font #
  498. ;
  499. ;
  500. vgetfont si    SP,6
  501.     mov    0,@4(SP)
  502.     mov    2,@2(SP)
  503.     mov    11,*SP
  504.  
  505.     sla    0,11                ; * >800
  506.     ai    0,grom_fonts
  507.     
  508.     bl    @gwaddr
  509.  
  510.     li    0,>800
  511.     bl    @vwaddr
  512.  
  513.     li    2,>800
  514. vgf1    movb    @>9800,@>8c00
  515.     dec    2
  516.     jgt    vgf1
  517.  
  518.     mov    +*SP,11
  519.     mov    +*SP,2
  520.     mov    +*SP,0
  521.     rt
  522.  
  523.  
  524.  
  525. ;========================================================================
  526.  
  527.  
  528.  
  529.  
  530. ;    Turn off the cursor.
  531. ;
  532. ;    Call before moving it or changing the char under the cursor.
  533. ;
  534. ;    NOT a BLWP @ function because it's unnecessary.
  535. ;
  536.  
  537. vcursoroff
  538.     cb    @vcurs,@h00
  539.     jeq    vcursisoff
  540.     dect    SP
  541.     mov    0,*SP
  542.     movb    @h80,@vcurs        ; force an "off" next time
  543.     mov    @vcursor,0
  544.     blwp    *0
  545.     mov    +*SP,0
  546. vcursisoff    rt
  547.  
  548.  
  549.  
  550. ;--------------------------------------------------------------------------
  551. ;    Text mode window functions.
  552. ;--------------------------------------------------------------------------
  553.  
  554.  
  555. ;    Draw a char in the window.
  556. ;
  557. ;    VCH=char
  558. ;    VX+VWX=screen coord X
  559. ;    VY+VWY=screen coord Y
  560. ;    VFG/VBG=color
  561.  
  562.  
  563. vtextchar data vidws,vtextchar 4+
  564.     limi    0
  565.     li    SP,vstack vstacksize +
  566.  
  567.     mov    @vx,0
  568.     mov    @vcoordaddr,1
  569.     bl    *1                ; get address
  570.  
  571.     bl    @vwaddr                ; set VDP addr
  572.     movb    @vch,@>8c00            ; draw
  573.     rtwp
  574.  
  575.  
  576. ;    Draw a char in the window.
  577. ;
  578. ;    VCH=char
  579. ;    VX+VWX=screen coord X
  580. ;    VY+VWY=screen coord Y
  581. ;    VFG/VBG=color
  582.  
  583.  
  584. vbitchar data vidws,vbitchar 4+
  585.     limi    0
  586.     li    SP,vstack vstacksize +
  587.  
  588.  
  589.     mov    @vx,0
  590.     mov    @vcoordaddr,1
  591.     bl    *1                ; get address
  592.  
  593.     mov    0,4
  594.     a    @vpatts,0
  595.     bl    @vwaddr                ; set VDP addr for patt
  596.  
  597.     li    0,grom_fonts
  598.     movb    @vch,1
  599.     srl    1,8
  600.     sla    1,3
  601.     a    1,0
  602.     bl    @gwaddr                ; set GROM addr
  603.     li    1,>9800
  604.     li    3,>8c00
  605.  
  606.     movb    *1,*3
  607.     movb    *1,*3
  608.     movb    *1,*3
  609.     movb    *1,*3
  610.     movb    *1,*3
  611.     movb    *1,*3
  612.     movb    *1,*3
  613.     movb    *1,*3
  614.     
  615.     movb    @vmono,@vmono
  616.     jne    vbcnocol
  617.  
  618.     mov    4,0
  619.     a    @vcolors,0            ; draw color
  620.     bl    @vwaddr
  621.  
  622.     movb    @vfg,1
  623.     sla    1,4
  624.     andi    1,>f000
  625.     movb    @vbg,2
  626.     andi    2,>0f00
  627.     soc    2,1
  628.  
  629.     movb    1,*3
  630.     movb    1,*3
  631.     movb    1,*3
  632.     movb    1,*3
  633.     movb    1,*3
  634.     movb    1,*3
  635.     movb    1,*3
  636.     movb    1,*3
  637.  
  638. vbcnocol:
  639.     rtwp
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646. ;    Clear the text window.
  647. ;
  648. ;    VWX/VWXS & VWY/VWYS are window coords
  649. ;    
  650. ;    VFG/VBG = fill color
  651. ;    
  652. vtextclear data    vidws,vtextclear 4+
  653.     limi    0
  654.     li    SP,vstack vstacksize +
  655.  
  656.     movb    @h20,@vcursunder
  657.  
  658.     li    1,>2000
  659.     movb    @vwxs,2
  660.     srl    2,8
  661.     li    6,vtextclearline
  662.  
  663. vtcentr    clr    0
  664.     movb    @vwys,3
  665.     srl    3,8
  666.  
  667.  
  668. vtcloop    bl    *6
  669.     inc    0                ; next 'Y'
  670.     dec    3
  671.     jgt    vtcloop
  672.  
  673.     clr    @vx
  674.  
  675.     rtwp
  676.  
  677.  
  678. ;    Clear the text window.
  679. ;
  680. ;    VWX/VWXS & VWY/VWYS are window coords
  681. ;    
  682. ;    VFG/VBG = fill color
  683. ;    
  684. vbitclear data    vidws,vbitclear 4+
  685.  
  686.     limi    0
  687.     li    SP,vstack vstacksize +
  688.  
  689.     sb    @vcursunder,@vcursunder
  690.  
  691.     clr    1
  692.     movb    @vwxs,2
  693.     srl    2,8
  694.     sla    2,3
  695.     li    6,vbitclearline
  696.  
  697.     jmp    vtcentr
  698.  
  699.  
  700. ;    
  701. ;    Blink the cursor.
  702. ;
  703. ;    Expects "vcursunder" to be valid.
  704. ;
  705. ;    Called from interrupt.
  706.  
  707. vtextcursor    data vidws,vtextcursor 4+
  708.     limi    0
  709.     li    SP,vstack vstacksize +
  710.  
  711.     li    12,>8c00
  712.     mov    @vx,0
  713.     mov    @vcoordaddr,1
  714.     bl    *1
  715.  
  716.     ab    @h80,@vcurs
  717.     jeq    vtcoff
  718.  
  719.     bl    @vraddr            ; read char under cursor
  720.     movb    @>8800,@vcursunder
  721.  
  722.     bl    @vwaddr
  723.     movb    @vcurschar,*12        ; draw cursor
  724.  
  725.     jmp    vtcout
  726.  
  727. vtcoff:
  728.     bl    @vwaddr
  729.     movb    @vcursunder,*12        ; restore char under cursor
  730.  
  731. vtcout:
  732.     rtwp
  733.  
  734.  
  735.  
  736. ;    
  737. ;    Blink the cursor.
  738. ;
  739. ;    Expects "vcursunder" to be valid.
  740. ;
  741. ;    Called from interrupt.
  742.  
  743. vbitcursor    data vidws,vbitcursor 4+
  744.  
  745.     limi    0
  746.     li    SP,vstack vstacksize +
  747.  
  748.     li    12,>8c00
  749.     mov    @vx,0
  750.     mov    @vcoordaddr,1
  751.     bl    *1
  752.     ai    0,7            ; point to bottom of char
  753.     a    @vpatts,0        ; only change patt
  754.  
  755.     ab    @h80,@vcurs
  756.     jeq    vbcoff
  757.  
  758.     bl    @vraddr            ; read char under cursor
  759.     movb    @>8800,@vcursunder
  760.  
  761.     bl    @vwaddr
  762.     movb    @vcurschar,*12        ; draw cursor
  763.  
  764.     jmp    vbcout
  765.  
  766. vbcoff:
  767.     bl    @vwaddr
  768.     movb    @vcursunder,*12        ; restore char under cursor
  769.  
  770. vbcout:
  771.     rtwp
  772.  
  773.  
  774.  
  775.  
  776. ;---------------------------------------------------------------
  777.  
  778. ;    Scroll the text cursor down.
  779. ;
  780. ;    VWX/VWXS & VWY/VWYS are window coords
  781. ;    
  782. ;    VFG/VBG = fill color
  783.  
  784. vbitscroll data    vidws,vbitscroll 4+
  785.  
  786.     limi    0
  787.     li    SP,vstack vstacksize +
  788.  
  789.     li    0,13
  790.     clr    1
  791.     jmp    vtext0
  792.  
  793. vgraphscroll data vidws,vtextscroll 4+
  794. vtextscroll data vidws,vtextscroll 4+
  795.     limi    0
  796.     li    SP,vstack vstacksize +
  797.  
  798.     clr    0
  799.     li    1,>2000                ; clear char
  800.  
  801. vtext0     movb    @vwxs,2                ; length
  802.     srl    2,8
  803.     src    2,0
  804.  
  805.     mov    @vx,0
  806.     andi    0,>ff                ; get coord for lower-left
  807.     bl    @vtextclearline
  808.     inc    0
  809.     swpb    0
  810.     cb    0,@vwys
  811.     jl    vtext1
  812.           sb    0,0
  813. vtext1    swpb    0
  814.     bl    @vtextclearline
  815.     
  816.     rtwp
  817.  
  818.  
  819. ;    This routine will draw a line on the screen.
  820. ;
  821. ;    (R1,R2) - (R3,R4)  (x,y)   VFG/VBG
  822.  
  823. vbitline data    vidws,vbitline 4+
  824.     limi    0
  825.     li    SP,vstack vstacksize +
  826.  
  827.     li    1,M_bit 256 *
  828.     cb    1,@vidmode
  829.     jeq    vblcont
  830.  
  831.     rtwp
  832.  
  833. vblcont:
  834.     mov    @2(13),1
  835.     mov    @4(13),2
  836.     mov    @6(13),3
  837.     mov    @8(13),4
  838.  
  839.     mov    1,5
  840.     s    3,5
  841.     abs    5
  842.  
  843.     mov    2,6
  844.     s    4,6
  845.     abs    6
  846.  
  847.     c    5,6                ; which axis is longer?
  848.                         ; R6>=0 means Y is longer
  849.                         ; R6<0  means X is longer
  850.     jgt    vbl_x
  851.  
  852. ;    Y is the longer axis.  For this case, Y will step by +-1 and
  853. ;    X will step +-(dX/dY).
  854. ;
  855. ;    Set up R7 to be a pointer to a MINOR incrementer (+-X) and
  856. ;           R8 to                 a MAJOR incrementer (+-Y).
  857. ;           R9 to                 the MINOR increment value (+)
  858. ;           R0 to be the address and bit offset. 
  859.  
  860.     bl    @vbl_getaddr            ; get start addr
  861.  
  862.     mov    6,12                ; R12 = # pixels
  863.  
  864.     li    7,vbl_xincs
  865.     li    8,vbl_yincs            ; both point to positives
  866.  
  867.     mov    5,9
  868.     clr    10
  869.     div    6,9                ; R9 = increment
  870.     clr    6
  871.     jno    vbl_ymajnostr
  872.  
  873.     inct    6
  874.     clr    9                ; use force-carry
  875.  
  876. vbl_ymajnostr:
  877.     c    1,3
  878.     jlt    vbl_ymajxord
  879.     inct    7                ; R7 -> decrementer
  880.  
  881. vbl_ymajxord:
  882.     c    2,4
  883.     jlt    vbl_ymajyord
  884.     inct    8                ; R8 -> decrementer
  885.  
  886. vbl_ymajyord:
  887.     jmp    vbl_draw
  888.  
  889.  
  890. vbl_x:
  891. ;    X is the longer axis.  For this case, X will step by +-1 and
  892. ;    Y will step +-(dY/dX).
  893. ;
  894. ;    Set up R7 to be a pointer to a MINOR incrementer (+-Y) and
  895. ;           R8 to                 a MAJOR incrementer (+-X).
  896. ;           R9 to                 the MINOR increment value (+)
  897. ;           R0 to be the address and bit offset. 
  898.  
  899.     bl    @vbl_getaddr            ; get start addr
  900.     
  901.     mov    5,12                ; R12 = # pixels
  902.     
  903.     li    7,vbl_yincs
  904.     li    8,vbl_xincs
  905.  
  906.     mov    6,9
  907.     clr    10
  908.     div    5,9                ; R9 = incrementer
  909.     clr    6
  910.     jno    vbl_xmajnostr
  911.  
  912.     clr    9                ; use another routine
  913.     inct    6
  914.  
  915. vbl_xmajnostr:
  916.     c    1,3
  917.     jlt    vbl_xmajxord
  918.     inct    8
  919.  
  920. vbl_xmajxord:
  921.     c    2,4
  922.     jlt    vbl_xmajyord
  923.     inct    7
  924.  
  925. vbl_xmajyord:
  926.  
  927.  
  928. ;    During drawing:
  929. ;
  930. ;    R0 = vdp addr offset
  931. ;    R1 = shift index (0-7)
  932. ;    R2 = color byte
  933. ;    
  934. ;    With incremental increment (fractional):
  935. ;        R9  = increment (unsigned)
  936. ;        R3 = incrementer
  937. ;        when C=1, call *R9
  938. ;
  939. ;    *R6 = straight-line fix
  940. ;    *R7 = minor increment
  941. ;    *R8 = major increment/decrement
  942. ;    R12 = # pixels to draw
  943. ;
  944.  
  945. vbl_draw:
  946.     mov    *7,7
  947.     mov    *8,8
  948.  
  949.     mov    6,6                ; diagonal?
  950.     jeq    vbl_dno6            ; nope
  951.  
  952.     mov    7,6
  953.     jmp    vbl_draw0            ; inc every time
  954.  
  955. vbl_dno6 li    6,vbl_dinc
  956.  
  957. vbl_Draw0:
  958.     mov    0,1
  959.     andi    1,7                ; R1 = bit offs
  960.     srl    0,3                ; R0 = vdp offset
  961.  
  962.     clr    2
  963.     movb    @vfg,2
  964.     sla    2,4
  965.     socb    @vbg,2                ; R2= color byte
  966.  
  967.     clr    3                ; clear incrementer
  968. vbl_loop:
  969.     bl    @vbl_drawpixel            ; draw a pixel
  970.  
  971.     bl    *8                ; major increment
  972.     bl    *6                ; minor
  973.     dec    12                ; go through all the pixels
  974.     jgt    vbl_loop
  975.     rtwp
  976.  
  977.  
  978. vbl_dinc a    9,3
  979.     jnc    vbl_dinc0
  980. vbl_nop    b    *7                ; major increment
  981. vbl_dinc0 rt
  982.  
  983.  
  984. ;    Get the starting VDP offset, scaling the coords 
  985. ;    and saving in "vlinex" and "vliney"
  986. ;
  987. ;    (R1,R2) = coord.
  988. ;
  989. ;    Return R0=offset*8+bit offset (0-7)
  990. ;    Destroys R9, R12
  991.  
  992. h256    data    256
  993. h192    data    192
  994. hneg1    data    >ffff
  995.  
  996. vbl_getaddr
  997.  
  998. ;-----------------------------
  999.  
  1000.     si    SP,8
  1001.     mov    1,@6(SP)
  1002.     mov    2,@4(SP)
  1003.     mov    3,@2(SP)
  1004.     mov    4,*SP
  1005.  
  1006.     andi    1,>ff                ; scale down X
  1007.     mov    1,@vlinex
  1008.  
  1009.     clr    3
  1010.     mov    2,4
  1011.     jgt    vbl_posy
  1012.  
  1013.     ai    4,32640                ; make positive
  1014. vbl_posy:
  1015.     div    @h192,3
  1016.     mov    4,@vliney
  1017.     mov    4,2                ; scale down Y
  1018.  
  1019.     mov    +*SP,4
  1020.     mov    +*SP,3
  1021.     mov    +*SP,2
  1022.     mov    +*SP,1
  1023.  
  1024. ;-----------------------------
  1025.  
  1026.     mov    @vliney,0             ; copy Y coord
  1027.  
  1028.     sla    0,5                ; R0=Y offset (row8) ++
  1029.     soc    @vliney,0             ; R0=Y offset (row) ++
  1030.     andi    0,>ff07                ; R0=complete Y offset
  1031.  
  1032.     mov    @vlinex,12
  1033.     mov    12,9                      ; R2=copy of X
  1034.     andi    12,7                ; R1=complete X bit offs
  1035.     a    9,0                ; R0=Y-X offset ++
  1036.     s    12,0                ; R0=complete Y-X offset
  1037.     sla    0,3                ; shift up
  1038.     soc    12,0                ; R0=offset & bit val
  1039.     rt
  1040.  
  1041.  
  1042. ;    Draw a pixel.
  1043. ;
  1044. ;    R0=addr, @vbl_shifts(r1) = bit mask.
  1045. ;    R2=color byte
  1046. ;
  1047. ;    Destroys R4.
  1048.  
  1049. vbl_drawpixel
  1050.     mov    11,10
  1051.     bl    @vraddr                ; patts always at 0
  1052.     movb    @>8800,4            ; get old byte
  1053.     socb    @vbl_shifts(1),4        ; set bit
  1054.     bl    @vwaddr                
  1055.     movb    4,@>8c00            ; write back
  1056.     movb    @vmono,@vmono
  1057.     jne    vbl_dpnocol
  1058.  
  1059.     a    @vcolors,0            ; point to colors
  1060.     bl    @vwaddr                
  1061.     movb    2,@>8c00            ; set color
  1062.     s    @vcolors,0
  1063. vbl_dpnocol:
  1064.     b    *10            
  1065.  
  1066.  
  1067. vbl_shifts byte    >80,>40,>20,>10,>8,>4,>2,>1
  1068. vbl_xincs data    vbl_xpos,vbl_xneg
  1069. vbl_yincs data    vbl_ypos,vbl_yneg
  1070.  
  1071.  
  1072. h8    data    8
  1073.  
  1074. ;----------------------------
  1075. vbl_xpos:                    ; increment X
  1076.     inc    1
  1077.     andi    1,7
  1078.     jne    vbl_xpos1            ; rollover?
  1079.     ai    0,8                ; next X cell
  1080. vbl_xpos0:
  1081.     a    @h8,@vlinex
  1082.     c    @vlinex,@h256
  1083.     jl    vbl_xpos1
  1084.     s    @h256,@vlinex
  1085.     si    0,256
  1086. vbl_xpos1:
  1087.     rt
  1088.  
  1089. ;----------------------------
  1090.  
  1091. vbl_xneg:                    ; increment Y
  1092.     dec    1
  1093.     joc    vbl_xneg1            ; rollover?
  1094.     si    0,8                ; previous X cell
  1095. vbl_xneg0:
  1096.     andi    1,7
  1097.     s    @h8,@vlinex
  1098.     c    @vlinex,@hneg1
  1099.     jgt    vbl_xneg1
  1100.     a    @h256,@vlinex
  1101.     ai    0,256
  1102. vbl_xneg1:
  1103.     rt
  1104.  
  1105. ;----------------------------
  1106.  
  1107. vbl_ypos:
  1108.     inc    0                ; down one row
  1109.     czc    @h7,0                ; out of cell block?
  1110.     jne    vbl_ypos1
  1111.     ai    0,248                ; next cell row
  1112. vbl_yposmnot:
  1113.     a    @h8,@vliney
  1114.     c    @vliney,@h192
  1115.     jl    vbl_ypos1
  1116.     s    @h192,@vliney
  1117.     si    0,>1800
  1118. vbl_ypos1:
  1119.     rt
  1120.  
  1121. ;----------------------------
  1122.  
  1123. vbl_yneg:
  1124.     dec    0                    ; up one row
  1125.     coc    @h7,0                ; out of cell block?
  1126.     jne    vbl_yneg1
  1127.     si    0,248                ; previous cell row
  1128. vbl_ynegmnot:
  1129.     s    @h8,@vliney
  1130.     c    @vliney,@hneg1
  1131.     jgt    vbl_yneg1
  1132.     a    @h192,@vliney
  1133.     ai    0,>1800
  1134. vbl_yneg1:
  1135.     rt
  1136.     
  1137.  
  1138.