home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tegl_ii / svga / grvga256.asm < prev    next >
Encoding:
Assembly Source File  |  1991-10-15  |  60.0 KB  |  3,466 lines

  1.  
  2.         include grphdrvr.inc
  3.  
  4. ;******************************************************************************}
  5. ;                TEGL Windows ToolKit II                   }
  6. ;           Copyright (C) 1990, TEGL Systems Corporation            }
  7. ;                 All Rights Reserved.                   }
  8. ;******************************************************************************}
  9.  
  10.         .code
  11.  
  12.         db   'RT',8,8,'TGI Device Driver (VGA320x200/SVGA640x480)x256 1.1  - May  8 1991',13,10
  13.         db   'Copyright (c) 1989,1990 TEGL Systems Corporation',13,10
  14.         db   01ah         ; end of file for TYPE
  15.         db   00          ; end of Copyright Header
  16.  
  17.         db   8,'GRVGA256',0   ; driver module name
  18.  
  19.         ; VGA320x200x256
  20. mode0:        db    14,'VGA320x200x256',0,0,0,0,0,0,0
  21.         dw    0         ; Mode Number
  22.         dw    319         ; Device Full Resolution in X
  23.         dw    199         ; Device Full Resolution in Y
  24.         dw    8         ; Standard char size X
  25.         dw    8         ; Standard char size Y
  26.         dw    255         ; Number of colors
  27.         dw    2         ; Number of pages
  28.         dw    256         ; max palette
  29.         dw    0         ; buffer offset for 2 page
  30.         dw    0A000h         ; Screen Segment
  31.         dw    320         ; bytes per line
  32.         dw    7750         ; x aspect
  33.         dw    10000         ; y aspect
  34.         dd    0         ; Driver Pointer
  35.         dd    0         ; Driver Name Pointer
  36.         dd    0         ; Driver Jump Table
  37.         dd    0         ; Graphics Work Buffer
  38.         dw    0         ; Graphics Buffer Size
  39.         dw    0         ; Read/Write modes
  40.         db    0         ; transparency on-$ff/off-$00
  41.         db    0         ; jagged characters
  42.         dd    0         ; pointer to font table
  43.         db    0         ; allow EGA palette changes
  44.         db    1         ; allow VGA 256 palette changes
  45.         db    1         ; proportional font switch
  46.         dw    0ffffh         ; fillmask for lines
  47.         dw    0         ; viewport - minx
  48.         dw    0         ; viewport - miny
  49.         dw    319         ; viewport - maxx
  50.         dw    199         ; viewport - maxy
  51.         db    1         ; viewport - clipping on/off
  52.         dw    15         ; Mouse color
  53.         dw    0         ; Mouse hotspot
  54.         dw    0         ; Mouse hotspot
  55.         dd    0         ; Mouse Cursor Mask
  56.         dd    0         ; Next VideoMode
  57.  
  58. mode1:        db    15,'SVGA640x480x256',0,0,0,0,0,0
  59.         dw    1         ; Mode Number
  60.         dw    639         ; Device Full Resolution in X
  61.         dw    479         ; Device Full Resolution in Y
  62.         dw    8         ; Standard char size X
  63.         dw    8         ; Standard char size Y
  64.         dw    255         ; Number of colors
  65.         dw    1         ; Number of pages
  66.         dw    256         ; max palette
  67.         dw    0         ; buffer offset for 2 page
  68.         dw    0A000h         ; Screen Segment
  69.         dw    640         ; bytes per line
  70.         dw    10000         ; x aspect
  71.         dw    10000         ; y aspect
  72.         dd    0         ; Driver Pointer
  73.         dd    0         ; Driver Name Pointer
  74.         dd    0         ; Driver Jump Table
  75.         dd    0         ; Graphics Work Buffer
  76.         dw    0         ; Graphics Buffer Size
  77.         dw    0         ; Read/Write modes
  78.         db    0         ; transparency on-$ff/off-$00
  79.         db    0         ; jagged characters
  80.         dd    0         ; pointer to font table
  81.         db    0         ; allow EGA palette changes
  82.         db    1         ; allow VGA 256 palette changes
  83.         db    1         ; proportional font switch
  84.         dw    0ffffh         ; fillmask for lines
  85.         dw    0         ; viewport - minx
  86.         dw    0         ; viewport - miny
  87.         dw    639         ; viewport - maxx
  88.         dw    479         ; viewport - maxy
  89.         db    1         ; viewport - clipping on/off
  90.         dw    15         ; Mouse color
  91.         dw    0         ; Mouse hotspot
  92.         dw    0         ; Mouse hotspot
  93.         dd    0         ; Mouse Cursor Mask
  94.         dd    0         ; Next VideoMode
  95.  
  96. mode2:        db    15,'SVGA800x600x256',0,0,0,0,0,0
  97.         dw    2         ; Mode Number
  98.         dw    799         ; Device Full Resolution in X
  99.         dw    599         ; Device Full Resolution in Y
  100.         dw    8         ; Standard char size X
  101.         dw    8         ; Standard char size Y
  102.         dw    255         ; Number of colors
  103.         dw    1         ; Number of pages
  104.         dw    256         ; max palette
  105.         dw    0         ; buffer offset for 2 page
  106.         dw    0A000h         ; Screen Segment
  107.         dw    800         ; bytes per line
  108.         dw    9500         ; x aspect
  109.         dw    10000         ; y aspect
  110.         dd    0         ; Driver Pointer
  111.         dd    0         ; Driver Name Pointer
  112.         dd    0         ; Driver Jump Table
  113.         dd    0         ; Graphics Work Buffer
  114.         dw    0         ; Graphics Buffer Size
  115.         dw    0         ; Read/Write modes
  116.         db    0         ; transparency on-$ff/off-$00
  117.         db    0         ; jagged characters
  118.         dd    0         ; pointer to font table
  119.         db    0         ; allow EGA palette changes
  120.         db    1         ; allow VGA 256 palette changes
  121.         db    1         ; proportional font switch
  122.         dw    0ffffh         ; fillmask for lines
  123.         dw    0         ; viewport - minx
  124.         dw    0         ; viewport - miny
  125.         dw    799         ; viewport - maxx
  126.         dw    599         ; viewport - maxy
  127.         db    1         ; viewport - clipping on/off
  128.         dw    15         ; Mouse color
  129.         dw    0         ; Mouse hotspot
  130.         dw    0         ; Mouse hotspot
  131.         dd    0         ; Mouse Cursor Mask
  132.         dd    0         ; Next VideoMode
  133.  
  134. mode3:        db    16,'SVGA1024x768x256',0,0,0,0,0
  135.         dw    3         ; Mode Number
  136.         dw    1023         ; Device Full Resolution in X
  137.         dw    767         ; Device Full Resolution in Y
  138.         dw    8         ; Standard char size X
  139.         dw    8         ; Standard char size Y
  140.         dw    255         ; Number of colors
  141.         dw    1         ; Number of pages
  142.         dw    256         ; max palette
  143.         dw    0         ; buffer offset for 2 page
  144.         dw    0A000h         ; Screen Segment
  145.         dw    1024         ; bytes per line
  146.         dw    10000         ; x aspect
  147.         dw    10000         ; y aspect
  148.         dd    0         ; Driver Pointer
  149.         dd    0         ; Driver Name Pointer
  150.         dd    0         ; Driver Jump Table
  151.         dd    0         ; Graphics Work Buffer
  152.         dw    0         ; Graphics Buffer Size
  153.         dw    0         ; Read/Write modes
  154.         db    0         ; transparency on-$ff/off-$00
  155.         db    0         ; jagged characters
  156.         dd    0         ; pointer to font table
  157.         db    0         ; allow EGA palette changes
  158.         db    1         ; allow VGA 256 palette changes
  159.         db    1         ; proportional font switch
  160.         dw    0ffffh         ; fillmask for lines
  161.         dw    0         ; viewport - minx
  162.         dw    0         ; viewport - miny
  163.         dw    1023         ; viewport - maxx
  164.         dw    767         ; viewport - maxy
  165.         db    1         ; viewport - clipping on/off
  166.         dw    15         ; Mouse color
  167.         dw    0         ; Mouse hotspot
  168.         dw    0         ; Mouse hotspot
  169.         dd    0         ; Mouse Cursor Mask
  170.         dd    0         ; Next VideoMode
  171.  
  172. modeend:    dw    0ffffh         ; 0ffff - last mode
  173.  
  174. drvjumptable:    dw   initvideomode   ; mode:word,TEGLTable:dword,initflg:byte
  175.         dw   setxlattable    ; XlatTable:dword
  176.         dw   setvideotable   ; TEGLTable:dword
  177.         dw   getvideotable   ; returns pointer to TEGLTable
  178.         dw   imagesize         ; argx1:word,argy1:word,argx2:word,argy2:word
  179.         dw   fastline         ; argx1:word,argy1:word,argx2:word,argy2:word,color:word
  180.         dw   scanborder      ; argx:word,argy:word,bordercolor:word,scan:word
  181.         dw   putpixs         ; argx:word,argy:word,color:word
  182.         dw   getpixs         ; argx:word,argy:word
  183.         dw   getbiti         ; argx0:word,argy0:word,argx1:word,argy1:word,addrbuf:dword
  184.         dw   putbiti         ; argx:word,argy:word,addrbuf:dword,rmwb:word
  185.         dw   extractimg      ; argx0:word,argy0:word,argx1:word,argy1:word,addrbuf1:dword,addrbuf2:dword
  186.         dw   overlayimg      ; argx0:word,argy0:word,addrbuf1:dword,addrbuf2:dword
  187.         dw   extractpixs     ; argx0:word,argy0:word,addrbuff:dword
  188.         dw   wrtchar         ; argc:word,argx:word,argy:word,argfgd:word
  189.         dw   mcursoroff      ;
  190.         dw   mcursoron         ; argx:word,argy:word
  191.         dw   msetpos         ; argx:word,argy:word
  192.         dw   movevideopixels ; argx0:word,argy0:word,argx1:word,argy1:word,argx2:word,argy2:word,vertlines:word,horzlines:word,spage:word,tpage:word
  193.         dw   setvpage         ; pagen:word
  194.         dw   setapage         ; pagen:word
  195.  
  196.         db   16 dup (0) ;required for driver alignment
  197.  
  198. ; 16 bytes/row * 16rows + 5 byte header
  199. mcursorsavearea db   262 dup (0)
  200. mflag        dw   0
  201. scradrofs    dw   0
  202. scradrseg    dw   0
  203. scradrpg    dw   0
  204. current64kpage    dw   0
  205. TDTable     dd   0
  206. XLTable     dd   0
  207. vesashift    db   0
  208.  
  209.  
  210. vga512flag    dw   ?
  211. vga1024flag    dw   ?
  212. svgatype    dw   0             ;flag so whichvga() is only called once
  213. bankadr     dw   ?
  214.  
  215. ;x_genoa     equ     1
  216. ;x_paradise     equ     2
  217. ;x_ati         equ     3
  218. ;x_everex     equ     4
  219. ;x_trident     equ     5
  220. ;x_video7     equ     6
  221. ;x_chiptech     equ     7
  222. ;x_tseng4     equ     8
  223. ;x_tseng     equ     9
  224. ;x_ahead     equ     10
  225. ;x_aheadb     equ     11
  226. ;x_oak         equ     12
  227. ;x_cirrus     equ     13
  228.  
  229. x_cirrus    equ    1
  230. x_everex    equ    2
  231. x_paradise    equ    3
  232. x_tseng     equ    4
  233. x_trident    equ    5
  234. x_t8900     equ    6
  235. x_ativga    equ    7
  236. x_aheada    equ    8
  237. x_aheadb    equ    9
  238. x_oaktech    equ    10
  239. x_video7    equ    11
  240. x_chipstech    equ    12
  241. x_tseng4    equ    13
  242. x_genoa     equ    14
  243. x_ncr        equ    15
  244. x_compaq    equ    16
  245. x_vesa        equ    17
  246.  
  247.  
  248. initvideomode    proc    far
  249.  
  250.         push    ds
  251.         push    si
  252.         lds    si,cs:TDTable
  253.         mov    bx,ds:[si].vmodenum
  254.         pop    si
  255.         pop    ds
  256.  
  257.         mov    ax,ds
  258.         or    ax,ax
  259.         mov    ax,-10
  260.         jz    initviddone
  261.  
  262.         or    bx,bx
  263.         jnz    nxtevgamode
  264.  
  265.         call    setsvga320x200
  266.         jmp    short initviddone
  267.  
  268. nxtevgamode:    cmp    bx,1
  269.         jnz    trysvgamode
  270.         call    setsvga640x480
  271.         jmp    short initviddone
  272.  
  273. trysvgamode:    cmp    bx,2
  274.         jnz    try1024mode
  275.         call    setsvga800x600
  276.         jmp    short initviddone
  277.  
  278. try1024mode:    cmp    bx,3
  279.         jnz    initviddone
  280.         call    setsvga1024x768
  281.  
  282. initviddone:    ret
  283. initvideomode    endp
  284.  
  285. SetSVGA320x200    proc    near
  286.         mov    ax,cs:svgatype
  287.         cmp    ax,0
  288.         jb    no200type
  289.  
  290.         cmp    ax,0
  291.         jnz    ok200type
  292.  
  293.         call    whichsvga
  294.         jc    no200type
  295.  
  296. ok200type:    mov    ax,013h
  297.         int    10h
  298.         xor    ax,ax
  299.  
  300. no200type:    ret
  301. SetSVGA320x200    endp
  302.  
  303. SetSVGA640x480    proc    near
  304.         mov    ax,cs:svgatype
  305.         cmp    ax,0
  306.         jnz    okset
  307.  
  308.         call    whichsvga
  309.         mov    ax,cs:svgatype
  310.         cmp    ax,0
  311.  
  312. okset:        jb    nohardware
  313.         mov    cx,ax
  314.         test    vga512flag,1
  315.         jz    nohardware
  316.  
  317.         cmp    cx,x_genoa
  318.         mov    ax,5ch
  319.         je    set480
  320.  
  321.         cmp    cx,x_paradise
  322.         mov    ax,5fh
  323.         je    set480
  324.         cmp    cx,x_compaq
  325.         je    set480
  326.  
  327.         cmp    cx,x_ativga
  328.         mov    ax,62h
  329.         je    set480
  330.  
  331.         cmp    cx,x_everex
  332.         mov    ax,70h
  333.         mov    bl,30h
  334.         je    set480
  335.  
  336.         cmp    cx,x_trident
  337.         mov    ax,5dh
  338.         je    set480
  339.         cmp    cx,x_t8900
  340.         je    set480
  341.  
  342.         cmp    cx,x_video7
  343.         mov    ax,6f05h
  344.         mov    bl,67h
  345.         je    set480
  346.  
  347.         cmp    cx,x_chipstech
  348.         mov    ax,79h
  349.         je    set480
  350.  
  351.         cmp    cx,x_tseng4
  352.         mov    ax,2eh
  353.         je    set480
  354.         cmp    cx,x_tseng
  355.         je    set480
  356.  
  357.         cmp    cx,x_aheada
  358.         mov    ax,61h
  359.         je    set480
  360.         cmp    cx,x_aheadb
  361.         je    set480
  362.  
  363.         cmp    cx,x_oaktech
  364.         mov    ax,53h
  365.         je    set480
  366.  
  367.         cmp    cx,x_ncr
  368.         mov    ax,5fh
  369.         je    set480
  370.  
  371. ;        cmp    cx,x_cirrus    ;cirrus doesn't have a 640x480(256)
  372. nohardware:    mov    ax,-2
  373.         jmp    short nosvgatype
  374.  
  375. set480:     int    10h
  376.         xor    ax,ax
  377. nosvgatype:
  378.         ret
  379. SetSVGA640x480    endp
  380.  
  381.  
  382. SetSVGA800x600    proc    near
  383.         mov    ax,cs:svgatype
  384.         cmp    ax,0
  385.         jnz    oksets
  386.  
  387.         call    whichsvga
  388.         mov    ax,cs:svgatype
  389.         cmp    ax,0
  390.  
  391. oksets:     jb    nosvgatypes
  392.         mov    cx,ax
  393.         test    vga512flag,1
  394.         jz    nohardwares
  395.  
  396.         cmp    cx,x_genoa
  397.         mov    ax,30h
  398.         je    set600
  399.  
  400.         cmp    cx,x_paradise    ;paradise doesn't have a 800x600(256)
  401.         jz    nohardwares
  402.  
  403.         cmp    cx,x_ativga
  404.         mov    ax,63h
  405.         je    set600
  406.  
  407.         cmp    cx,x_everex
  408.         mov    ax,70h
  409.         mov    bl,31h
  410.         je    set600
  411.  
  412.         cmp    cx,x_trident
  413.         mov    ax,5eh
  414.         je    set600
  415.         cmp    cx,x_t8900
  416.         je    set600
  417.  
  418.         cmp    cx,x_video7
  419.         mov    ax,6f05h
  420.         mov    bl,69h
  421.         je    set600
  422.  
  423.         cmp    cx,x_chipstech
  424.         mov    ax,7bh
  425.         je    set600
  426.  
  427.         cmp    cx,x_tseng4
  428.         mov    ax,30h
  429.         je    set600
  430.  
  431.         cmp    cx,x_tseng
  432.         mov    ax,30h
  433.         je    set600
  434.  
  435.         cmp    cx,x_aheada
  436.         mov    ax,62h
  437.         je    set600
  438.         cmp    cx,x_aheadb
  439.         je    set600
  440.  
  441.         cmp    cx,x_oaktech
  442.         mov    ax,54h
  443.         je    set600
  444.  
  445.         cmp    cx,x_ncr
  446.         mov    ax,5ch
  447.         je    set600
  448.  
  449. nohardwares:    mov    ax,-2
  450.         jmp    short nosvgatypes
  451.  
  452. set600:     int    10h
  453.         xor    ax,ax
  454. nosvgatypes:
  455.         ret
  456. SetSVGA800x600    endp
  457.  
  458. SetSVGA1024x768 proc    near
  459.         mov    ax,cs:svgatype
  460.         cmp    ax,0
  461.         jnz    oksets2
  462.  
  463.         call    whichsvga
  464.         mov    ax,cs:svgatype
  465.         cmp    ax,0
  466.  
  467. oksets2:    jb    nosvgatypes2
  468.         mov    cx,ax
  469.         test    vga1024flag,1
  470.         jz    nohardwares2
  471.  
  472.         cmp    cx,x_genoa
  473.         mov    ax,38h
  474.         je    set768
  475.  
  476.         cmp    cx,x_paradise    ;paradise doesn't have a 1024x768(256)
  477.         jz    nohardwares2
  478.  
  479.         cmp    cx,x_ativga    ;ATI doesn't have a 1024x768(256)
  480.         jz    nohardwares2
  481.  
  482.         cmp    cx,x_everex    ;everex doesn't have a 1024x768(256)
  483.         jz    nohardwares2
  484.  
  485.         cmp    cx,x_trident    ;old trident doesn't have a 1024x768(256)
  486.         jz    nohardwares2
  487.  
  488.         cmp    cx,x_t8900
  489.         mov    ax,62h
  490.         je    set768
  491.  
  492.         cmp    cx,x_video7    ;new video7
  493.         mov    ax,6f05h
  494.         mov    bl,6ah
  495.         jz    nosvgatypes2
  496.  
  497.         cmp    cx,x_chipstech    ;chiptech doesn't have a 1024x768(256)
  498.         jz    nohardwares2
  499.  
  500.         cmp    cx,x_tseng4
  501.         mov    ax,38h
  502.         je    set768
  503.  
  504.         cmp    cx,x_tseng
  505.         mov    ax,38h
  506.         je    set768
  507.  
  508. ;        cmp    cx,x_aheada    ;ahead doesn't have a 1024x768(256)
  509. ;        jz    nohardwares2
  510.  
  511. ;        cmp    cx,x_aheadb    ;aheadb doesn't have a 1024x768(256)
  512. ;        jz    nohardwares2
  513.  
  514. ;        cmp    cx,x_oaktech    ;oak doesn't have a 1024x768(256)
  515. ;        jz    nohardwares2
  516.  
  517. nohardwares2:    mov    ax,-2
  518.         jmp    short nosvgatypes2
  519.  
  520. set768:     int    10h
  521.         xor    ax,ax
  522. nosvgatypes2:
  523.         ret
  524. SetSVGA1024x768 endp
  525.  
  526.  
  527. setxlattable    proc    far XlatTable:dword
  528.         push    es
  529.         push    di
  530.  
  531.         les    di,XlatTable
  532.         mov    word ptr cs:XLTable,di
  533.         mov    word ptr cs:XLTable+2,es
  534.  
  535.         pop    di
  536.         pop    es
  537.         ret
  538. setxlattable    endp
  539.  
  540.  
  541. setvideotable    proc    far TEGLTable:dword
  542.         push    es
  543.         push    di
  544.  
  545.         les    di,TEGLTable
  546.         mov    word ptr cs:TDTable,di
  547.         mov    word ptr cs:TDTable+2,es
  548.  
  549.         cmp    cs:svgatype,0
  550.         jnz    svgainitdone
  551.  
  552.         call    whichsvga
  553.  
  554. svgainitdone:
  555.         pop    di
  556.         pop    es
  557.         ret
  558. setvideotable    endp
  559.  
  560. getvideotable    proc    far
  561.  
  562.         mov    ax,word ptr cs:TDTable
  563.         mov    dx,word ptr cs:TDTable+2
  564.  
  565.         ret
  566. getvideotable    endp
  567.  
  568. imagesize    proc    far argx1:word,argy1:word,argx2:word,argy2:word
  569.         push    bx
  570.  
  571.         mov    ax,argx2        ;x1-x+1
  572.         sub    ax,argx1
  573.         inc    ax
  574.  
  575.         mov    bx,argy2        ;y1-y+1
  576.         sub    bx,argy1
  577.         inc    bx
  578.  
  579.         mul    bx            ;rows x bytes per row
  580.         add    ax,6            ;add 6 for header
  581.         adc    dx,0
  582.  
  583.         pop    bx
  584.         ret
  585. imagesize    endp
  586.  
  587.  
  588. fastline    proc    far argx1:word,argy1:word,argx2:word,argy2:word,color:word
  589.         local    varincr1:word,varincr2:word,varroutine:word
  590.         local    rmwb:word,fillmask:byte,bpline:word,transparent:byte
  591.  
  592.         push    ds
  593.         push    si
  594.         push    es
  595.         push    di
  596.  
  597.         cld
  598.         colorxlat color
  599.  
  600.         lds    si,cs:TDtable
  601.         mov    ax,ds:[si].rmwbits
  602.         mov    rmwb,ax
  603.  
  604.         mov    ax,ds:[si].vbytesperline
  605.         mov    bpline,ax
  606.  
  607.         mov    al,byte ptr ds:[si].teglfillmask
  608.         mov    fillmask,al
  609.  
  610.         mov    al,ds:[si].transparency
  611.         mov    transparent,al
  612.  
  613.         cmp    rmwb,80h    ; not?
  614.         jnz    oknot
  615.         not    color
  616. oknot:
  617.  
  618. ; check for vertical line
  619.  
  620.         mov    si,bpline    ; initial y-increment
  621.         mov    cx,argx2
  622.         sub    cx,argx1    ; cx := x2 - x1
  623.         jz    vertline13    ; jump if vertical line
  624.  
  625. ; force x1 < x2
  626.  
  627.         jns    l01        ; jump if x2 > x1
  628.         neg    cx        ; cx := x1 - x2
  629.         mov    bx,argx2    ; exchange x1 and x2
  630.         xchg    bx,argx1
  631.         mov    argx2,bx
  632.  
  633.         mov    bx,argy2    ; exchange y1 and y2
  634.         xchg    bx,argy1
  635.         mov    argy2,bx
  636.  
  637. ; calculate dy = abs(y2-y1)
  638.  
  639. l01:        mov    bx,argy2
  640.         sub    bx,argy1    ; bx := y2 - y1
  641.         jnz    l02
  642.         jmp    horizline13    ; jump if horizontal line
  643.  
  644. l02:        jns    l03        ; jump if slope is positive
  645.  
  646.         neg    bx        ; bx := y1 - y2
  647.         neg    si        ; negate y-increment
  648.  
  649. ; select appropriate routine for slope of line
  650.  
  651. l03:        push    si        ; preserve y-increment
  652.  
  653.         mov    varroutine,0    ; loslopeline13
  654.         cmp    bx,cx
  655.         jle    l04        ; jump if dy <= dx (slope <= 1)
  656.         mov    varroutine,1    ; hislopeline13
  657.         xchg    bx,cx        ; exchange dy and dx
  658.  
  659. ; calculate initial decision variable and increments
  660.  
  661. l04:        shl    bx,1        ; bx := 2 * dy
  662.         mov    varincr1,bx    ; incr1 := 2 * dy
  663.         sub    bx,cx
  664.         mov    si,bx        ; si := d = 2 * dy - dx
  665.         sub    bx,cx
  666.         mov    varincr2,bx    ; incr2 := 2 * (dy - dx)
  667.  
  668. ; calculate first pixel address
  669.  
  670.         push    cx        ; preserve this register
  671.         mov    ax,argy1    ; ax := y
  672.         mov    bx,argx1    ; bx := x
  673.         call    activeaddr    ; es:bx -> buffer
  674.  
  675.         mov    di,bx        ; es:di -> buffer
  676.  
  677.         pop    cx        ; restore this register
  678.         inc    cx        ; cx := # of pixels to draw
  679.  
  680.         pop    bx        ; bx := y-increment
  681.         test    varroutine,1    ; jump to appropriate routine for slope
  682.         jnz    jmphislopeline
  683.         jmp    loslopeline13
  684. jmphislopeline: jmp    hislopeline13
  685.  
  686.  
  687. ; routine for vertical lines
  688.  
  689. vertline13:    mov    ax,argy1    ; ax := y1
  690.         mov    bx,argy2    ; bx := y2
  691.         mov    cx,bx
  692.         sub    cx,ax        ; cx := dy
  693.         jge    l31        ; jump if dy >= 0
  694.  
  695.         neg    cx        ; force dy >= 0
  696.         mov    ax,bx        ; ax := y2
  697.  
  698. l31:        inc    cx        ; cx := # of pixels to draw
  699.         mov    bx,argx1    ; bx := x
  700.         push    cx        ; preserve this register
  701.         call    activeaddr    ; es:bx -> video buffer
  702.  
  703.         pop    cx
  704.         mov    di,bx        ; es:di -> video buffer
  705.  
  706.         mov    al,byte ptr [color] ; al := pixel value
  707.         mov    bl,fillmask
  708.  
  709.         cmp    rmwb,18h    ; fgxor
  710.         jz    vgl36a        ; jump if pixel should be xored
  711.  
  712.         test    rmwb,08h    ; fgand
  713.         jnz    vgl35a        ; jump if pixel should be anded
  714.  
  715.         test    rmwb,10h    ; fgor
  716.         jnz    vgl37a        ; jump if pixel should be ored
  717.  
  718. ;------------------ [fgnorm] set bit
  719. ;<<<<<Write pixel>>>>>>
  720. l32:        ror    bl,1
  721.         jnc    l32b
  722.         mov    es:[di],al    ; set pixel value in buffer
  723. l32b:        add    di,si        ; increment to next line
  724.         jnc    l32a
  725.         call    nextpage
  726. l32a:        loop    l32
  727.         jmp    svlexit
  728.  
  729. ;------------------ [fgxor] set bit
  730. ;<<<<<Write pixel>>>>>>
  731. vgl36a:     ror    bl,1
  732.         jnc    vgl36b
  733.         xor    es:[di],al    ; set pixel value in buffer
  734. vgl36b:     add    di,si        ; increment to next line
  735.         jnc    vgl36c
  736.         call    nextpage
  737. vgl36c:     loop    vgl36a
  738.         jmp    svlexit
  739.  
  740. ;------------------ [fgand] set bit
  741. ;<<<<<Write pixel>>>>>>
  742. vgl35a:     ror    bl,1
  743.         jnc    vgl35b
  744.         and    es:[di],al    ; set pixel value in buffer
  745. vgl35b:     add    di,si        ; increment to next line
  746.         jnc    vgl35c
  747.         call    nextpage
  748. vgl35c:     loop    vgl35a
  749.         jmp    svlexit
  750.  
  751. ;------------------ [fgor] set bit
  752. ;<<<<<Write pixel>>>>>>
  753. vgl37a:     ror    bl,1
  754.         jnc    vgl37b
  755.         or    es:[di],al    ; set pixel value in buffer
  756. vgl37b:     add    di,si        ; increment to next line
  757.         jnc    vgl37c
  758.         call    nextpage
  759. vgl37c:     loop    vgl37a
  760.         jmp    svlexit
  761.  
  762.  
  763.  
  764. ; routine for horizontal lines (slope = 0)
  765.  
  766. horizline13:
  767.         push    cx        ; preserve cx
  768.         mov    ax,argy1
  769.         mov    bx,argx1
  770.         call    activeaddr    ; es:bx -> video buffer
  771.         mov    di,bx        ; es:di -> buffer
  772.  
  773.         pop    cx
  774.         inc    cx        ; cx := number of pixels to draw
  775.  
  776.         mov    al,byte ptr [color] ; al := pixel value
  777.  
  778.         xor    dx,dx
  779.         push    di
  780.         add    di,cx
  781.         jc    h13a        ; exceed 64k boundary
  782.  
  783. ;------------------ Within Boundary Solid Line
  784.         pop    di
  785. ;<<<<<Write pixel>>>>>>
  786.         mov    bl,fillmask
  787.         push    bx
  788.         xor    bl,0ffh
  789.         pop    bx
  790.         jnz    h13c
  791.  
  792.         test    rmwb,0ffh
  793.         jnz    h13c
  794.  
  795.         rep    stosb        ; update the video buffer
  796.         jmp    svlexit
  797.  
  798.  
  799. ;------------------ Cross Boundary Horizontal
  800. h13a:        mov    dx,di        ; remainder
  801.         pop    di
  802.         mov    cx,di
  803.         neg    cx
  804.  
  805.         mov    bl,fillmask
  806.         push    bx
  807.         xor    bl,0ffh
  808.         pop    bx
  809.         jnz    h13c
  810.  
  811.         test    rmwb,0ffh
  812.         jnz    h13c
  813.  
  814. ;------------------ Cross Boundary Horizontal Solid Line
  815. ;<<<<<Write pixel>>>>>>
  816.         rep    stosb        ; update the video buffer
  817.         mov    cx,dx
  818.         jcxz    cxbsldone
  819.         call    nextpage
  820. ;<<<<<Write pixel>>>>>>
  821.         rep    stosb        ; update the video buffer
  822. cxbsldone:    jmp    svlexit
  823.  
  824.  
  825. ;------------------ Cross Boundary Horizontal Dotted Line
  826. h13c:        cmp    rmwb,18h    ; fgxor
  827.         jz    vgl14a        ; jump if pixel should be xored
  828.  
  829.         test    rmwb,08h    ; fgand
  830.         jnz    vgl15a        ; jump if pixel should be anded
  831.  
  832.         test    rmwb,10h    ; fgor
  833.         jnz    vgl16a        ; jump if pixel should be ored
  834.  
  835. ;------------------ [fgnorm] set bit
  836. ;<<<<<Write pixel>>>>>>
  837.         mov    bh,transparent
  838.         not    bh
  839.  
  840.         or    bh,bh        ; if transparency off 0xff then
  841.         jnz    vgl13a        ; line is in bar fill mode
  842.  
  843.         push    cx
  844.         mov    cx,argx1
  845.         and    cl,7
  846. ;        xor    cl,7
  847.         rol    bl,cl        ; ***********fillmask
  848. ;        ror    bl,1        ; ***********fillmask
  849.         pop    cx
  850.  
  851. vgl13a:     rol    bl,1
  852.         jnc    vgl13ba
  853.         mov    es:[di],al
  854.         inc    di
  855.         loop    vgl13a
  856.         jmp    short vgl13b
  857.  
  858. vgl13ba:    and    es:[di],bh
  859.         inc    di
  860.         loop    vgl13a
  861.  
  862. vgl13b:     mov    cx,dx
  863.         jcxz    vgl13e
  864.  
  865.         call    nextpage
  866. ;<<<<<Write pixel>>>>>>
  867. vgl13c:     rol    bl,1
  868.         jnc    vgl13da
  869.         mov    es:[di],al
  870. vgl13d:     inc    di
  871.         loop    vgl13c
  872. vgl13e:     jmp    svlexit
  873.  
  874. vgl13da:    and    es:[di],bh
  875.         jmp    short vgl13d
  876.  
  877. ;------------------ [fgxor] set bit
  878. ;<<<<<Write pixel>>>>>>
  879. vgl14a:     rol    bl,1
  880.         jnc    vgl14b
  881.         xor    es:[di],al
  882. vgl14b:     inc    di
  883.         loop    vgl14a
  884.  
  885.         mov    cx,dx
  886.         jcxz    vgl14e
  887.  
  888.         call    nextpage
  889. ;<<<<<Write pixel>>>>>>
  890. vgl14c:     rol    bl,1
  891.         jnc    vgl14d
  892.         xor    es:[di],al
  893. vgl14d:     inc    di
  894.         loop    vgl14c
  895. vgl14e:     jmp    svlexit
  896.  
  897. ;------------------ [fgand] set bit
  898. ;<<<<<Write pixel>>>>>>
  899. vgl15a:     rol    bl,1
  900.         jnc    vgl15b
  901.         and    es:[di],al
  902. vgl15b:     inc    di
  903.         loop    vgl15a
  904.  
  905.         mov    cx,dx
  906.         jcxz    vgl15e
  907.  
  908.         call    nextpage
  909. ;<<<<<Write pixel>>>>>>
  910. vgl15c:     rol    bl,1
  911.         jnc    vgl15d
  912.         and    es:[di],al
  913. vgl15d:     inc    di
  914.         loop    vgl15c
  915. vgl15e:     jmp    svlexit
  916.  
  917. ;------------------ [fgor] set bit
  918. ;<<<<<Write pixel>>>>>>
  919. vgl16a:     rol    bl,1
  920.         jnc    vgl16b
  921.         or    es:[di],al
  922. vgl16b:     inc    di
  923.         loop    vgl16a
  924.  
  925.         mov    cx,dx
  926.         jcxz    vgl16e
  927.  
  928.         call    nextpage
  929. ;<<<<<Write pixel>>>>>>
  930. vgl16c:     rol    bl,1
  931.         jnc    vgl16d
  932.         or    es:[di],al
  933. vgl16d:     inc    di
  934.         loop    vgl16c
  935. vgl16e:     jmp    svlexit
  936.  
  937.  
  938. ; routine for dy <= dx (slope <= 1)    ; es:di -> video buffer
  939.                     ; bx = y-increment
  940.                     ; cx = #pixels to draw
  941.                     ; si = decision variable
  942. loslopeline13:
  943.  
  944.         mov    al,byte ptr [color] ; al := pixel value
  945.         mov    dl,fillmask
  946.         mov    dh,byte ptr [rmwb]
  947.  
  948. ;<<<<<Write pixel>>>>>>
  949. l11:        ror    dl,1
  950.         jnc    l11b
  951.  
  952.         test    dh,0ffh     ; fgnorm
  953.         jz    sl11a
  954.  
  955.         cmp    dh,18h        ; fgxor
  956.         jnz    sl11b
  957.         xor    es:[di],al
  958.         jmp    short l11b
  959.  
  960. sl11b:        test    dh,08h        ; fgand
  961.         jz    sl11c
  962.         and    es:[di],al
  963.         jmp    short l11b
  964.  
  965. sl11c:        test    dh,10h        ; fgor
  966.         jz    sl11a
  967.         or    es:[di],al
  968.         jmp    short l11b
  969.  
  970. sl11a:        mov    es:[di],al    ; store pixel, increment x
  971.  
  972. l11b:        inc    di
  973.         jnz    l11a
  974.         call    nextpage
  975.  
  976. l11a:        or    si,si        ; test sign of d
  977.         jns    l12        ; jump if d >= 0
  978.  
  979.         add    si,varincr1    ; d := d + incr1
  980.         loop    l11
  981.         jmp    svlexit
  982.  
  983. l12:        add    si,varincr2    ; d := d + incr2
  984.         or    bx,bx
  985.         js    l12b
  986.         add    di,bx        ; increment y
  987.         jnc    l12a
  988.         call    nextpage
  989.         jmp    short l12a
  990.  
  991. l12b:
  992.         add    di,bx        ; increment y
  993.         jc    l12a
  994.         call    lastpage
  995.  
  996. l12a:        loop    l11
  997.         jmp    short svlexit
  998.  
  999.  
  1000. ; routine for dy > dx (slope > 1)    ; es:di -> video buffer
  1001.                     ; bx = y-increment
  1002.                     ; cx = #pixels to draw
  1003.                     ; si = decision variable
  1004. hislopeline13:
  1005.         mov    al,byte ptr [color] ; al := pixel value
  1006.         mov    dl,fillmask
  1007.         mov    dh,byte ptr [rmwb]
  1008.  
  1009. ;<<<<<Write pixel>>>>>>
  1010. l21:        ror    dl,1        ; update next pixel, increment x
  1011.         jnc    l21c
  1012.  
  1013.         test    dh,0ffh     ; fgnorm
  1014.         jz    sl21a
  1015.  
  1016.         cmp    dh,18h        ; fgxor
  1017.         jnz    sl21b
  1018.         xor    es:[di],al
  1019.         jmp    short l21c
  1020.  
  1021. sl21b:        test    dh,08h        ; fgand
  1022.         jz    sl21c
  1023.         and    es:[di],al
  1024.         jmp    short l21c
  1025.  
  1026. sl21c:        test    dh,10h        ; fgor
  1027.         jz    sl21a
  1028.         or    es:[di],al
  1029.         jmp    short l21c
  1030.  
  1031. sl21a:        mov    es:[di],al
  1032.  
  1033. l21c:        inc    di
  1034.         jnz    l21a
  1035.         call    nextpage
  1036.  
  1037. l21a:        or    bx,bx
  1038.         js    l21b
  1039.  
  1040.         add    di,bx        ; increment y
  1041.         jnc    l22
  1042.         call    nextpage
  1043.         jmp    short l22
  1044.  
  1045. l21b:        add    di,bx        ; increment y
  1046.         jc    l22
  1047.         call    lastpage
  1048.  
  1049. l22:        or    si,si        ; test sign of d
  1050.         jns    l23        ; jump if d >= 0
  1051.  
  1052.         add    si,varincr1    ; d := d + incr1
  1053.  
  1054.         or    di,di        ; going up!!
  1055.         jnz    l22b
  1056.         call    lastpage
  1057.  
  1058. l22b:        dec    di        ; decrement x (already incremented
  1059.         loop    l21        ;  by stosb)
  1060.         jmp    short svlexit
  1061.  
  1062. l23:        add    si,varincr2    ; d := d + incr2
  1063.         loop    l21
  1064.  
  1065. svlexit:    pop    di
  1066.         pop    es
  1067.         pop    si
  1068.         pop    ds
  1069.         ret
  1070.  
  1071. fastline    endp
  1072.  
  1073.  
  1074. putpixs     proc    far argx:word,argy:word,color:word
  1075.         local    rmwb:word
  1076.  
  1077.         push    ds
  1078.         push    si
  1079.         push    es
  1080.         push    di
  1081.  
  1082.         cld
  1083.         colorxlat color
  1084.  
  1085.         lds    si,cs:TDtable
  1086.         mov    ax,ds:[si].rmwbits
  1087.         mov    rmwb,ax
  1088.  
  1089.         mov    ax,ds:[si].wminy
  1090.         cmp    argy,ax
  1091.         jl    putpx04
  1092.  
  1093.         mov    ax,ds:[si].wmaxy
  1094.         cmp    argy,ax
  1095.         jg    putpx04
  1096.  
  1097.         mov    ax,ds:[si].wminx
  1098.         cmp    argx,ax
  1099.         jl    putpx04
  1100.  
  1101.         mov    ax,ds:[si].wmaxx
  1102.         cmp    argx,ax
  1103.         jg    putpx04
  1104.  
  1105.         mov    ax,argy     ; ax := y
  1106.         mov    bx,argx     ; bx := x
  1107.         call    activeaddr    ; es:bx -> buffer
  1108.         mov    di,bx
  1109.  
  1110.         mov    bx,rmwb
  1111.         mov    al,byte ptr [color]
  1112.  
  1113.         or    bl,bl
  1114.         jz    putpx02
  1115.  
  1116.         cmp    bl,80h        ; fgnot
  1117.         jnz    putpx01
  1118.         not    al
  1119.         jmp    short putpx02
  1120.  
  1121. putpx01:    cmp    bl,18h        ; fgxor
  1122.         jz    putpx03
  1123.         xor    es:[di],al
  1124.         jmp    short putpx04
  1125.  
  1126. putpx03:    test    bl,08h        ; fgand
  1127.         jnz    putpx05
  1128.         and    es:[di],al
  1129.         jmp    short putpx04
  1130.  
  1131. putpx05:    test    bl,10h        ; fgor
  1132.         jnz    putpx02
  1133.         or    es:[di],al
  1134.         jmp    short putpx04
  1135.  
  1136. putpx02:    stosb            ; fgnorm
  1137.  
  1138. putpx04:    pop    di
  1139.         pop    es
  1140.         pop    si
  1141.         pop    ds
  1142.  
  1143.         ret
  1144. putpixs     endp
  1145.  
  1146.  
  1147. scanborder    proc    far argx:word,argy:word,bordercolor:word,scan:word
  1148.         local    swminx:word,swmaxx:word
  1149.         push    ds
  1150.         push    si
  1151.         push    es
  1152.         push    di
  1153.  
  1154.         lds    si,cs:TDtable
  1155.         mov    ax,ds:[si].wminx
  1156.         mov    swminx,ax
  1157.         mov    ax,ds:[si].wmaxx
  1158.         mov    swmaxx,ax
  1159.  
  1160.         mov    ax,argy     ; ax := y
  1161. ;        xor    bx,bx        ; bx := x = 0
  1162.         mov    bx,argx
  1163.         call    activeaddr    ; ah := bit mask
  1164.                     ; es:bx -> buffer
  1165.         mov    di,bx        ; es:di -> buffer
  1166.  
  1167.         mov    al,byte ptr [bordercolor]  ; ah := color for comparing
  1168.         mov    si,argx
  1169.  
  1170.         test    scan,8000h
  1171.         jz    forwscan
  1172.  
  1173.         ; scan for color match
  1174. backscan:    mov    cx,si
  1175.         inc    cx
  1176.         sub    cx,swminx
  1177.         jle    scanl08
  1178.         jcxz    scanl08
  1179.  
  1180. scanl01:    cmp    al,es:[di]
  1181.         je    scanl08
  1182.         dec    si
  1183.         sub    di,1
  1184.         jnc    scanl02
  1185.         call    lastpage
  1186. scanl02:    loop    scanl01
  1187.         cld
  1188.         jmp    short scanl08
  1189.  
  1190.  
  1191. forwscan:    mov    cx,swmaxx
  1192.         inc    cx
  1193.         sub    cx,argx
  1194.         jle    scanl08
  1195.         jcxz    scanl08
  1196.  
  1197. scanl03:    cmp    al,es:[di]
  1198.         je    scanl08
  1199.         inc    si
  1200.         inc    di
  1201.         jnz    scanl04
  1202.         call    nextpage
  1203. scanl04:    loop    scanl03
  1204.  
  1205. scanl08:    mov    ax,si
  1206.         pop    di
  1207.         pop    es
  1208.         pop    si
  1209.         pop    ds
  1210.         ret
  1211. scanborder    endp
  1212.  
  1213. getpixs     proc    far argx:word,argy:word
  1214.         push    es
  1215.         push    di
  1216.  
  1217.         mov    ax,argy     ; ax := y
  1218.         mov    bx,argx     ; bx := x
  1219.         call    activeaddr    ; es:bx -> buffer
  1220.         mov    di,bx
  1221.  
  1222.         xor    ax,ax
  1223.         mov    al,es:[di]
  1224.  
  1225.         pop    di
  1226.         pop    es
  1227.         ret
  1228. getpixs     endp
  1229.  
  1230.  
  1231. getbiti     proc    far argx0:word,argy0:word,argx1:word,argy1:word,addrbuf:dword
  1232.         local    varpixelrows : word, varpixelrowlen : word
  1233.         local    bpline:word
  1234.  
  1235.         push    ds
  1236.         push    si
  1237.         push    di
  1238.  
  1239.         cld
  1240.         lds    si,cs:TDtable
  1241.         mov    ax,ds:[si].vbytesperline
  1242.         mov    bpline,ax
  1243.  
  1244.         mov    ax,argy0
  1245.         mov    bx,argx0
  1246.         call    activeaddr
  1247.         push    es
  1248.         pop    ds
  1249.         mov    si,bx            ; ds:si for screen address
  1250.  
  1251.         les    di,addrbuf        ; es:di save buffer
  1252.  
  1253.         mov    ax,argy1
  1254.         sub    ax,argy0
  1255.         inc    ax
  1256.         mov    varpixelrows,ax
  1257.         stosw
  1258.         mov    cx,ax
  1259.  
  1260.         mov    ax,argx1
  1261.         sub    ax,argx0
  1262.         inc    ax
  1263.         mov    varpixelrowlen,ax
  1264.         stosw
  1265.  
  1266.         mov    bx,bpline        ; next line after current
  1267.         sub    bx,ax            ; position
  1268.         mov    bpline,bx
  1269.  
  1270.         xor    ax,ax
  1271.         stosb
  1272.  
  1273.  
  1274. getbl01:    push    cx
  1275.         mov    cx,varpixelrowlen
  1276.  
  1277.         mov    bx,si
  1278.         add    bx,cx
  1279.         jnc    getbl02
  1280.  
  1281.         mov    cx,si
  1282.         neg    cx
  1283.         rep    movsb
  1284.         call    nextpage
  1285.         mov    cx,bx
  1286.  
  1287. getbl02:    rep    movsb
  1288.  
  1289.         add    si,bpline
  1290.         jnc    getbl03
  1291.         call    nextpage
  1292.  
  1293. getbl03:    pop    cx
  1294.         test    di,08000h
  1295.         jz    getbl04
  1296.         normalize es,di     ;pointer to stored bit block
  1297. getbl04:    loop    getbl01
  1298.  
  1299.         pop    di
  1300.         pop    si
  1301.         pop    ds
  1302.         ret
  1303. getbiti     endp
  1304.  
  1305.  
  1306. putbiti     proc    far argx:word,argy:word,addrbuf:dword,rmwb:word
  1307.         local    varpixelrows:word,varpixelrowlen:word
  1308.         local    bpline:word
  1309.  
  1310.         push    ds
  1311.         push    si
  1312.         push    es
  1313.         push    di
  1314.  
  1315.         cld
  1316.         lds    si,cs:TDtable
  1317.         mov    ax,ds:[si].vbytesperline
  1318.         mov    bpline,ax
  1319.  
  1320.         mov    ax,argy
  1321.         mov    bx,argx
  1322.         call    activeaddr
  1323.         mov    di,bx            ; es:di for screen address
  1324.  
  1325.         lds    si,addrbuf        ; ds:si save buffer
  1326.  
  1327.         lodsw
  1328.         mov    varpixelrows,ax
  1329.         mov    cx,ax
  1330.  
  1331.         lodsw
  1332.         mov    varpixelrowlen,ax
  1333.  
  1334.         mov    bx,bpline        ; next line after current
  1335.         sub    bx,ax            ; position
  1336.         mov    bpline,bx
  1337.  
  1338.         lodsb
  1339.  
  1340.         mov    bx,rmwb
  1341.         or    bl,bl
  1342.         jz    putbl01
  1343.  
  1344.         cmp    bl,80h        ; fgnot
  1345.         jz    putnot01
  1346.  
  1347.         cmp    bl,18h        ; fgxor
  1348.         jnz    putbl01b
  1349.         jmp    putxor01
  1350.  
  1351. putbl01b:    test    bl,08h        ; fgand
  1352.         jz    putbl01a
  1353.         jmp    putand01
  1354.  
  1355. putbl01a:    test    bl,10h        ; fgor
  1356.         jz    putbl01
  1357.         jmp    put_or01
  1358.  
  1359. ;------------------ [fgnorm] put biti
  1360. putbl01:    push    cx
  1361.         mov    cx,varpixelrowlen
  1362.  
  1363.         mov    bx,di
  1364.         add    bx,cx
  1365.         jnc    putbl02
  1366.  
  1367.         mov    cx,di
  1368.         neg    cx
  1369.         rep    movsb
  1370.         call    nextpage
  1371.         mov    cx,bx
  1372.  
  1373. putbl02:    rep    movsb
  1374.         add    di,bpline
  1375.         jnc    putbl03
  1376.         call    nextpage
  1377. putbl03:    pop    cx
  1378.         test    si,8000h
  1379.         jz    putbl04
  1380.         normalize ds,si     ;pointer to stored bit block
  1381. putbl04:    loop    putbl01
  1382.         jmp    putbitdone
  1383.  
  1384. ;------------------ [fgnot] put biti
  1385. putnot01:    push    cx
  1386.         mov    cx,varpixelrowlen
  1387.  
  1388. putnot02:    mov    al,ds:[si]
  1389.         not    al
  1390.         mov    es:[di],al
  1391.  
  1392.         inc    si
  1393.         inc    di
  1394.         jnz    putnt2a
  1395.         call    nextpage
  1396. putnt2a:    loop    putnot02
  1397.  
  1398.         add    di,bpline
  1399.         jnc    putnot03
  1400.         call    nextpage
  1401. putnot03:    pop    cx
  1402.         test    si,8000h
  1403.         jz    putnot04
  1404.         normalize ds,si     ;pointer to stored bit block
  1405. putnot04:    loop    putnot01
  1406.         jmp    putbitdone
  1407.  
  1408. ;------------------ [fgxor] put biti
  1409. putxor01:    push    cx
  1410.         mov    cx,varpixelrowlen
  1411.  
  1412. putxor02:    mov    al,ds:[si]
  1413.         xor    es:[di],al
  1414.         inc    si
  1415.         inc    di
  1416.         jnz    putxr2a
  1417.         call    nextpage
  1418. putxr2a:    loop    putxor02
  1419.  
  1420.         add    di,bpline
  1421.         jnc    putxor03
  1422.         call    nextpage
  1423. putxor03:    pop    cx
  1424.         test    si,8000h
  1425.         jz    putxor04
  1426.         normalize ds,si     ;pointer to stored bit block
  1427. putxor04:    loop    putxor01
  1428.         jmp    short putbitdone
  1429.  
  1430. ;------------------ [fgand] put biti
  1431. putand01:    push    cx
  1432.         mov    cx,varpixelrowlen
  1433.  
  1434. putand02:    mov    al,ds:[si]
  1435.         and    es:[di],al
  1436.         inc    si
  1437.         inc    di
  1438.         jnz    putan2a
  1439.         call    nextpage
  1440. putan2a:    loop    putand02
  1441.  
  1442.         add    di,bpline
  1443.         jnc    putand03
  1444.         call    nextpage
  1445. putand03:    pop    cx
  1446.         test    si,8000h
  1447.         jz    putand04
  1448.         normalize ds,si     ;pointer to stored bit block
  1449. putand04:    loop    putand01
  1450.         jmp    short putbitdone
  1451.  
  1452. ;------------------ [fgor] put biti
  1453. put_or01:    push    cx
  1454.         mov    cx,varpixelrowlen
  1455.  
  1456. put_or02:    mov    al,ds:[si]
  1457.         or    es:[di],al
  1458.         inc    si
  1459.         inc    di
  1460.         jnz    putor2a
  1461.         call    nextpage
  1462. putor2a:    loop    put_or02
  1463.  
  1464.         add    di,bpline
  1465.         jnc    put_or03
  1466.         call    nextpage
  1467. put_or03:    pop    cx
  1468.         test    si,8000h
  1469.         jz    put_or04
  1470.         normalize ds,si     ;pointer to stored bit block
  1471. put_or04:    loop    put_or01
  1472.  
  1473. putbitdone:    pop    di
  1474.         pop    es
  1475.         pop    si
  1476.         pop    ds
  1477.         ret
  1478. putbiti     endp
  1479.  
  1480.  
  1481. ; extract from buffer2 to buffer1
  1482. extractimg    proc    far argx0:word,argy0:word,argx1:word,argy1:word,addrbuf1:dword,addrbuf2:dword
  1483.         local    var1pixelrows : word, var1pixelrowlen  : word
  1484.         local    var2pixelrows : word, var2pixelrowlen  : word
  1485.  
  1486.         push    ds
  1487.         push    si
  1488.         push    es
  1489.         push    di
  1490.  
  1491.         les    di,addrbuf1
  1492.         lds    si,addrbuf2
  1493.  
  1494.         cld
  1495.         lodsw                ; var2pixelrows
  1496.         mov    var2pixelrows,ax
  1497.         lodsw                ; var2pixelrows
  1498.         mov    var2pixelrowlen,ax
  1499.         lodsb
  1500.  
  1501. ; compute dimensions of bit block
  1502. ; build 5-byte bit block header
  1503.  
  1504.         ; number of pixel rows
  1505.         mov    ax,argy1
  1506.         sub    ax,argy0
  1507.         inc    ax
  1508.         mov    var1pixelrows,ax
  1509.         stosw
  1510.  
  1511.         ; number of bytes per row
  1512.         mov    ax,argx1
  1513.         sub    ax,argx0
  1514.         inc    ax
  1515.         mov    var1pixelrowlen,ax
  1516.         stosw
  1517.  
  1518.         mov    al,0
  1519.         stosb
  1520.  
  1521.         mov    ax,argy0
  1522.         mov    bx,argx0
  1523.  
  1524.         mov    dx,var2pixelrowlen
  1525.         mul    dx            ; multiply rows by bytesperrow
  1526.         add    bx,ax
  1527.         adc    dx,0
  1528.  
  1529.         add    bx,si
  1530.         adc    dx,0
  1531.  
  1532.         push    bx
  1533.         shr    dx,1
  1534.         rcr    bx,1
  1535.         shr    dx,1
  1536.         rcr    bx,1
  1537.         shr    dx,1
  1538.         rcr    bx,1
  1539.         shr    dx,1
  1540.         rcr    bx,1
  1541.  
  1542.         mov    cx,ds
  1543.         add    cx,bx
  1544.         mov    ds,cx
  1545.         pop    si
  1546.         and    si,0fh
  1547.  
  1548.         mov    bx,var2pixelrowlen
  1549.         sub    bx,var1pixelrowlen
  1550.         mov    cx,var1pixelrows
  1551.  
  1552. ; copy from bit block2 to bit block1
  1553.  
  1554. extrc06:    push    cx
  1555.         mov    cx,var1pixelrowlen
  1556.  
  1557.         rep    movsb
  1558.  
  1559.         add    si,bx
  1560.         test    si,8000h
  1561.         jz    extrc07
  1562.         normalize ds,si
  1563. extrc07:    test    di,8000h
  1564.         jz    extrc08
  1565.         normalize es,di
  1566. extrc08:    pop    cx
  1567.         loop    extrc06
  1568.  
  1569.         pop    di
  1570.         pop    es
  1571.         pop    si
  1572.         pop    ds
  1573.         ret
  1574. extractimg    endp
  1575.  
  1576.  
  1577. ; overlay image from addrbuf1 to addrbuf2 at x,y
  1578. overlayimg    proc    far argx0:word,argy0:word,addrbuf1:dword,addrbuf2:dword
  1579.         local    var1pixelrows : word, var1pixelrowlen  : word
  1580.         local    var2pixelrows : word, var2pixelrowlen  : word
  1581.  
  1582.         push    ds
  1583.         push    si
  1584.         push    es
  1585.         push    di
  1586.  
  1587.         cld
  1588.  
  1589.         lds    si,addrbuf2
  1590.         lodsw                ; var2pixelrows
  1591.         mov    var2pixelrows,ax
  1592.         lodsw                ; var2pixelrows
  1593.         mov    var2pixelrowlen,ax
  1594.         lodsb
  1595.  
  1596.         push    ds
  1597.         push    si
  1598.         pop    di
  1599.         pop    es
  1600.  
  1601.         lds    si,addrbuf1
  1602.         lodsw                ; var1pixelrows
  1603.         mov    var1pixelrows,ax
  1604.         lodsw                ; var1pixelrows
  1605.         mov    var1pixelrowlen,ax
  1606.         lodsb
  1607.  
  1608.         mov    ax,argy0
  1609.         mov    bx,argx0
  1610.  
  1611.         mov    dx,var2pixelrowlen
  1612.         mul    dx            ; multiply rows by bytesperrow
  1613.         add    bx,ax
  1614.         adc    dx,0
  1615.  
  1616.         add    bx,di
  1617.         adc    dx,0
  1618.  
  1619.         push    bx
  1620.         shr    dx,1
  1621.         rcr    bx,1
  1622.         shr    dx,1
  1623.         rcr    bx,1
  1624.         shr    dx,1
  1625.         rcr    bx,1
  1626.         shr    dx,1
  1627.         rcr    bx,1
  1628.  
  1629.         mov    cx,es
  1630.         add    cx,bx
  1631.         mov    es,cx
  1632.         pop    di
  1633.         and    di,0fh
  1634.  
  1635.         mov    bx,var2pixelrowlen
  1636.         sub    bx,var1pixelrowlen
  1637.         mov    cx,var1pixelrows
  1638.  
  1639. ; copy from bit block2 to bit block1
  1640.  
  1641. ovrl06:     push    cx
  1642.         mov    cx,var1pixelrowlen
  1643.  
  1644.         rep    movsb
  1645.  
  1646.         add    di,bx
  1647.         test    di,8000h
  1648.         jz    ovrl07
  1649.         normalize es,di
  1650. ovrl07:     test    si,8000h
  1651.         jz    ovrl08
  1652.         normalize ds,si
  1653. ovrl08:     pop    cx
  1654.         loop    ovrl06
  1655.  
  1656.         pop    di
  1657.         pop    es
  1658.         pop    si
  1659.         pop    ds
  1660.         ret
  1661.  
  1662. overlayimg    endp
  1663.  
  1664.  
  1665. extractpixs    proc    far argx0:word,argy0:word,addrbuff:dword
  1666.         local    varpixelrows : word, varpixelrowlen  : word
  1667.  
  1668.         push    ds
  1669.         push    si
  1670.         push    es
  1671.         push    di
  1672.  
  1673.         lds    si,addrbuff
  1674.  
  1675.         cld
  1676.         lodsw                ; var2pixelrows
  1677.         mov    varpixelrows,ax
  1678.         lodsw                ; var2pixelrows
  1679.         mov    varpixelrowlen,ax
  1680.         lodsb
  1681.  
  1682.  
  1683.         mov    ax,argy0
  1684.         mov    bx,argx0
  1685.  
  1686.         mov    dx,varpixelrowlen
  1687.         mul    dx            ; multiply rows by bytesperrow
  1688.         add    bx,ax
  1689.         adc    dx,0
  1690.  
  1691.         add    bx,si
  1692.         adc    dx,0
  1693.  
  1694.         push    bx
  1695.         shr    dx,1
  1696.         rcr    bx,1
  1697.         shr    dx,1
  1698.         rcr    bx,1
  1699.         shr    dx,1
  1700.         rcr    bx,1
  1701.         shr    dx,1
  1702.         rcr    bx,1
  1703.  
  1704.         mov    cx,ds
  1705.         add    cx,bx
  1706.         mov    ds,cx
  1707.         pop    si
  1708.         and    si,0fh
  1709.  
  1710.         mov    ax,ds:[si]
  1711.  
  1712.         pop    di
  1713.         pop    es
  1714.         pop    si
  1715.         pop    ds
  1716.         ret
  1717. extractpixs    endp
  1718.  
  1719.  
  1720. wrtchar     proc    far argc:word,argx:word,argy:word,argfgd:word,argbgd:word
  1721.         local    jaggy:word,transparent:byte,charshift:byte
  1722.         local    rmwb:word,bpline:word,bpchar:byte,lastbytemask:byte
  1723.  
  1724.         push    ds
  1725.         push    si
  1726.         push    es
  1727.         push    di
  1728.  
  1729.         colorxlat argfgd
  1730. ;        colorxlat argbgd
  1731.  
  1732. ; set up character definition table addressing
  1733.  
  1734.         lds    si,cs:TDtable
  1735.         les    di,ds:[si].fonttable
  1736.  
  1737.         mov    ax,argc     ; al := character code
  1738.         xor    ah,ah
  1739.         cmp    al,es:[di].FontAsciiStart
  1740.         jb    nowrtjmp
  1741.         cmp    al,es:[di].FontAsciiEnd
  1742.         jbe    okwrtjmp
  1743.  
  1744. nowrtjmp:    jmp    nowrt
  1745.  
  1746.  
  1747. okwrtjmp:
  1748.         mov    ax,ds:[si].rmwbits
  1749.         mov    rmwb,ax
  1750.  
  1751.         mov    ax,ds:[si].vbytesperline
  1752.         mov    bpline,ax
  1753.  
  1754.         mov    al,ds:[si].transparency
  1755.         mov    transparent,al
  1756.  
  1757.         xor    ax,ax
  1758.         mov    al,ds:[si].jagged
  1759.         and    al,1
  1760.         xchg    al,ah
  1761.         mov    jaggy,ax
  1762.  
  1763.  
  1764. ; calculate first pixel address
  1765.         push    es
  1766.  
  1767.         mov    ax,argy     ; ax := y
  1768.         mov    bx,argx     ; bx := x
  1769.         call    activeaddr    ; es:bx -> buffer
  1770.  
  1771.         push    es        ; transfer video buffer segment
  1772.         pop    ds        ; to ds:si
  1773.         mov    si,bx
  1774.  
  1775. ; set up character definition table addressing
  1776.         pop    es
  1777.         xor    ax,ax
  1778.         mov    al,es:[di].FontHeight ;Multiply fontheight by fontwidth
  1779.         mov    cx,ax
  1780.  
  1781.         xor    bx,bx
  1782.         mov    bl,es:[di].fontbytewidth
  1783.         mov    bpchar,bl
  1784.         mul    bx
  1785.  
  1786.         mov    dx,argc     ; dl := character code
  1787.         sub    dl,es:[di].FontAsciiStart
  1788.         mul    dx        ; ax := offset into char def table
  1789.                     ;  (points * char code)
  1790.  
  1791.         add    di,255 + size TEGLFontInfo ;skip font table info
  1792.         add    di,ax        ; add character offset
  1793.  
  1794.         mov    bl,byte ptr [argfgd] ; bl := foreground pixel value
  1795.         mov    bh,byte ptr [argbgd] ; bh := background pixel value
  1796.  
  1797.         mov    ch,bpchar    ; bytes per character
  1798.         xor    ax,ax
  1799.         mov    al,ch        ; number of bytes per char width
  1800.         shl    al,1
  1801.         shl    al,1
  1802.         shl    al,1
  1803.         mov    dx,bpline
  1804.         sub    dx,ax
  1805.  
  1806. ;***This driver has not been adapted to use Transparency
  1807.         mov    bl,byte ptr [rmwb]   ; bl := read-modify-write bits
  1808.         mov    al,byte ptr [argfgd] ; al := foreground pixel value
  1809. ;        mov    ch,0
  1810. ;        dec    cl
  1811. ;***This driver has not been adapted to use Transparency or extended bits
  1812.  
  1813.         cmp    bl,80h        ; fgnot
  1814.         jnz    wrtcl10
  1815.         not    al
  1816.         mov    bl,0
  1817.  
  1818. wrtcl10:    mov    ah,es:[di]    ; ah := pattern for next row of pixels
  1819.  
  1820.         xchg    cl,byte ptr jaggy
  1821.         shr    ah,cl        ; jaggies
  1822.         xchg    cl,byte ptr jaggy
  1823.  
  1824.         mov    bh,8
  1825. wrt12:        rol    ah,1
  1826.         jnc    wrt11
  1827.  
  1828.         or    bl,bl
  1829.         jnz    otherwrt
  1830.  
  1831. wrtpx02:    mov    ds:[si],al    ; fgnorm
  1832. wrt11:        inc    si
  1833.         jnz    wrt11a
  1834.         call    nextpage
  1835. wrt11a:     dec    bh
  1836.         jnz    wrt12
  1837.  
  1838.         inc    di        ; es:di -> next byte in char def table
  1839.         dec    ch        ; width bytes
  1840.         jnz    wrtcl10
  1841.  
  1842.         add    si,dx        ; increment to next line in video buffer
  1843.         jnc    wrt11b
  1844.         call    nextpage
  1845. wrt11b:
  1846.         xchg    dx,jaggy
  1847.         xchg    dl,dh
  1848.         xchg    dx,jaggy
  1849.  
  1850.         mov    ch,bpchar
  1851.         dec    cl
  1852.         jnz    wrtcl10
  1853.  
  1854. nowrt:        pop    di
  1855.         pop    es
  1856.         pop    si
  1857.         pop    ds
  1858.         ret
  1859.  
  1860. otherwrt:    cmp    bl,18h        ; fgxor
  1861.         jz    wrtpx03
  1862.  
  1863.         test    bl,08h        ; fgand
  1864.         jnz    wrtpx05
  1865.  
  1866.         or    ds:[si],al    ; fgor
  1867.         jmp    wrt11
  1868.  
  1869. wrtpx05:    and    ds:[si],al
  1870.         jmp    wrt11
  1871.  
  1872. wrtpx03:    xor    ds:[si],al
  1873.         jmp    wrt11
  1874.  
  1875. wrtchar     endp
  1876.  
  1877.  
  1878. ; ax := y
  1879. ; bx := x
  1880. ; returns es:bx page offset
  1881. ;      dx    64k page number
  1882. activeaddr    proc    near
  1883.  
  1884.         push    ax
  1885.         push    ds
  1886.         push    si
  1887.  
  1888.         lds    si,cs:TDtable
  1889.         mov    dx,ds:[si].vbytesperline
  1890.         mul    dx            ;Multiply y*bytesrow
  1891.  
  1892.         add    bx,ax            ;Add in x coordinate
  1893.         adc    dx,0            ; and any carry
  1894.  
  1895. ;        cmp    dx,cs:current64kpage
  1896. ;        jz    nonewpage
  1897.         mov    ax,dx
  1898.         call    changepage
  1899.  
  1900. nonewpage:    mov    ax,0a000h
  1901.         mov    es,ax            ;ES:BX = byte address of pixel
  1902.  
  1903.         pop    si
  1904.         pop    ds
  1905.         pop    ax
  1906.         ret
  1907. activeaddr    endp
  1908.  
  1909.  
  1910. mcursoroff    proc    far
  1911.         push    es
  1912.         push    di
  1913.         push    ds
  1914.         push    si
  1915.  
  1916. ; replace mouse cursor area
  1917.         test    cs:mflag,1
  1918.         jz    nomoff
  1919.  
  1920.         mov    cs:mflag,0
  1921.  
  1922.         mov    ax,cs:current64kpage
  1923.         push    ax
  1924.  
  1925. ;    modify putbiti to put an array of 16x16 bytes
  1926.         les    di,dword ptr cs:scradrofs
  1927.         mov    ax,cs:scradrpg
  1928.         cmp    ax,cs:current64kpage
  1929.         jz    nompage
  1930.         call    changepage
  1931.  
  1932. nompage:    push    cs
  1933.         pop    ds
  1934.         mov    si,offset mcursorsavearea
  1935.         call    mputblock
  1936.  
  1937.         pop    ax
  1938.         cmp    ax,cs:current64kpage
  1939.         je    nomoff
  1940.         call    changepage    ; restore video page
  1941.  
  1942. nomoff:     pop    si        ; restore caller registers and return
  1943.         pop    ds
  1944.         pop    di
  1945.         pop    es
  1946.         ret
  1947. mcursoroff    endp
  1948.  
  1949.  
  1950. mcursoron    proc    far argx:word,argy:word
  1951.         local    varshift:word,wordmask:word,mscolor:byte,bpline:word
  1952.         local    last64kpage:word
  1953. ;        assume    ds:@data
  1954.  
  1955.         push    es
  1956.         push    di
  1957.         push    ds
  1958.         push    si
  1959.  
  1960.         mov    ax,cs:current64kpage
  1961.         push    ax
  1962.  
  1963. ; save mouse cursor area
  1964.         lds    si,cs:TDtable
  1965.         mov    ax,ds:[si].vbytesperline
  1966.         sub    ax,16
  1967.         mov    bpline,ax
  1968.  
  1969.         mov    ax,ds:[si].mousecolor
  1970.         mov    mscolor,al
  1971.  
  1972.         mov    cs:mflag,1     ; mouse cursor on
  1973.  
  1974.         mov    ax,argy     ; ax := y
  1975.         sub    ax,ds:[si].mousehotspot_yofs
  1976.         jnc    hotset1
  1977.         mov    ax,argy
  1978.  
  1979. hotset1:    mov    bx,argx     ; bx := x
  1980.         sub    bx,ds:[si].mousehotspot_xofs
  1981.         jnc    hotset2
  1982.         mov    bx,argx
  1983.  
  1984. hotset2:    call    activeaddr    ; es:bx -> buffer
  1985.         mov    cs:scradrseg,es
  1986.         mov    cs:scradrofs,bx
  1987.         mov    cs:scradrpg,dx
  1988.         mov    last64kpage,dx
  1989.  
  1990.         push    es
  1991.         push    cs
  1992.         pop    es
  1993.         pop    ds
  1994.  
  1995.         mov    si,bx        ; ds:si -> screen buffer
  1996.         mov    di,offset mcursorsavearea ; es:di -> mcursorsave
  1997.         call    mgetblock
  1998.  
  1999. ; set up mouse cursor table addressing
  2000.  
  2001.         mov    cx,16        ; number of pixel rows in cursor
  2002.         lds    si,cs:TDtable
  2003.         lds    si,ds:[si].mousemask
  2004.         les    di,dword ptr cs:scradrofs
  2005.  
  2006.         mov    ax,last64kpage
  2007.         cmp    ax,cs:current64kpage
  2008.         jz    mcl10
  2009.         call    changepage
  2010.  
  2011. mcl10:        push    cx
  2012. ;        push    si
  2013.  
  2014.         mov    bx,ds:[si]
  2015.         mov    cx,16        ; number of pixel per row
  2016.         xor    ax,ax
  2017.         mov    ah,mscolor
  2018.         mov    dx,ds:[si+32]
  2019.  
  2020. mcl12:        rol    bx,1
  2021.         jc    mcl11
  2022.         mov    es:[di],al
  2023. mcl11:        rol    dx,1
  2024.         jnc    mcl11b
  2025.         mov    es:[di],ah
  2026. mcl11b:     inc    di
  2027.         jnz    mcl11a
  2028.         call    nextpage
  2029. mcl11a:     loop    mcl12
  2030.  
  2031. ;        pop    si
  2032.         pop    cx
  2033.  
  2034.         inc    si
  2035.         inc    si
  2036.  
  2037.         add    di,bpline
  2038.         jnc    mcl11c
  2039.         call    nextpage
  2040. mcl11c:     loop    mcl10
  2041.  
  2042.         pop    ax
  2043.         cmp    ax,cs:current64kpage
  2044.         je    mcl11d
  2045.         call    changepage    ; restore video page
  2046.  
  2047. mcl11d:     pop    si        ; restore caller registers and return
  2048.         pop    ds
  2049.         pop    di
  2050.         pop    es
  2051.  
  2052.         ret
  2053. mcursoron    endp
  2054.  
  2055. msetpos     proc    far argx:word,argy:word
  2056.         push    ds
  2057.  
  2058.         test    cs:mflag,1
  2059.         jz    nomset
  2060.  
  2061.         call    mcursoroff
  2062.  
  2063.         mov    ax,argx
  2064.         push    ax
  2065.         mov    ax,argy
  2066.         push    ax
  2067.         call    mcursoron
  2068.  
  2069. nomset:     pop    ds
  2070.         ret
  2071. msetpos     endp
  2072.  
  2073.  
  2074. ; assume ds:si=addrbuf    es:di=screenadr
  2075. mputblock    proc    near
  2076.         push    si
  2077.         push    di
  2078.         push    bx
  2079.  
  2080.         mov    dx,ds
  2081.         mov    ax,si
  2082.         lds    si,cs:TDtable
  2083.         mov    bx,ds:[si].vbytesperline
  2084.         sub    bx,16
  2085.         mov    si,ax
  2086.         mov    ds,dx
  2087.  
  2088.         cld
  2089.         mov    cx,16
  2090. mcputblck02:    push    cx
  2091.         mov    cx,16
  2092.  
  2093. mcputblck04:    movsb
  2094.         or    di,di
  2095.         jnz    mcputblck01
  2096.         call    nextpage
  2097. mcputblck01:    loop    mcputblck04
  2098.  
  2099.         add    di,bx
  2100.         jnc    mcputblck03
  2101.         call    nextpage
  2102. mcputblck03:    pop    cx
  2103.         loop    mcputblck02
  2104.  
  2105.         pop    bx
  2106.         pop    di
  2107.         pop    si
  2108.         ret
  2109. mputblock    endp
  2110.  
  2111.  
  2112. ; assume es:di=addrbuf    ds:si=screenadr
  2113. mgetblock    proc    near
  2114.         push    si
  2115.         push    di
  2116.         push    bx
  2117.  
  2118.         mov    dx,ds
  2119.         mov    ax,si
  2120.         lds    si,cs:TDtable
  2121.         mov    bx,ds:[si].vbytesperline
  2122.         sub    bx,16
  2123.         mov    si,ax
  2124.         mov    ds,dx
  2125.  
  2126.         cld
  2127.         mov    cx,16
  2128. mcgetblck02:    push    cx
  2129.  
  2130.         mov    cx,16
  2131. mcgetblck04:    movsb
  2132.         or    si,si
  2133.         jnz    mcgetblck05
  2134.         call    nextpage
  2135. mcgetblck05:    loop    mcgetblck04
  2136.  
  2137.         add    si,bx
  2138.         jnc    mcgetblck03
  2139.         call    nextpage
  2140. mcgetblck03:    pop    cx
  2141.         loop    mcgetblck02
  2142.  
  2143.         pop    bx
  2144.         pop    di
  2145.         pop    si
  2146.         ret
  2147. mgetblock    endp
  2148.  
  2149.  
  2150.  
  2151. lastpage    proc    near
  2152.         push    ax
  2153.  
  2154.         mov    ax,cs:current64kpage
  2155.         dec    ax
  2156.  
  2157.         call    changepage
  2158.  
  2159.         pop    ax
  2160.         ret
  2161.  
  2162. lastpage    endp
  2163.  
  2164. nextpage    proc    near
  2165.         push    ax
  2166.  
  2167.         mov    ax,cs:current64kpage
  2168.         inc    ax
  2169.  
  2170.         call    changepage
  2171.  
  2172.         pop    ax
  2173.         ret
  2174.  
  2175. nextpage    endp
  2176.  
  2177.  
  2178. movevideopixels proc    far argx0:word,argy0:word,argx1:word,argy1:word,argx2:word,argy2:word,vertlines:word,horzlines:word,spage:dword,tpage:dword
  2179.         local    bpline:word,varpixelrows:word,varpixelrowlen:word
  2180.         local    sourcescr:dword,sourcepage:word,pagechange:word
  2181.         local    targetscr:dword,targetpage:word,workbuffer:dword
  2182.  
  2183.         push    ds
  2184.         push    es
  2185.         push    si
  2186.         push    di
  2187.  
  2188. ;-----------------------------------------------
  2189.         cld
  2190.  
  2191.         lds    si,cs:TDtable
  2192.         mov    ax,ds:[si].vbytesperline
  2193.         mov    bpline,ax
  2194.  
  2195.         les    di,ds:[si].vgraphbuffer
  2196.         mov    word ptr [workbuffer],di
  2197.         mov    word ptr [workbuffer+2],es
  2198.  
  2199.         mov    pagechange,1
  2200. ;-----------------------------------------------
  2201.         mov    ax,horzlines
  2202.         or    ax,ax
  2203.         jz    noadj_89
  2204.  
  2205.         mov    ax,horzlines
  2206.         test    ah,80h
  2207.         jz    notneg1     ;scroll left?    ;   +-+--------+
  2208.                             ;   | <<<< -1  |
  2209.                             ;   +-+--------+
  2210.         mov    bx,argx0
  2211.         sub    bx,ax
  2212.         mov    argx0,bx
  2213.         jmp    short noadj_89
  2214.  
  2215. notneg1:    mov    bx,argx2    ;scroll right?    ;   +--------+-+
  2216.         add    bx,ax                ;   | 1   >>>> |
  2217.         mov    argx2,bx            ;   +--------+-+
  2218.  
  2219.         mov    bx,argx1
  2220.         sub    bx,ax
  2221.         mov    argx1,bx
  2222.  
  2223. noadj_89:
  2224.         mov    ax,argx1
  2225.         sub    ax,argx0
  2226.         inc    ax        ;number of bytes to mov
  2227.         mov    varpixelrowlen,ax
  2228.  
  2229.         mov    ax,argy1    ;number of lines
  2230.         sub    ax,argy0    ;number of lines
  2231.         inc    ax
  2232.  
  2233. ;-----------------------------------------------
  2234. ; extablish addressing
  2235.         test    vertlines,8000h
  2236.         jnz    bottomupmove
  2237.  
  2238.         sub    ax,vertlines
  2239.         mov    varpixelrows,ax
  2240.  
  2241.         mov    ax,argy0    ;source     ;   +----------+
  2242.         add    ax,vertlines            ;   +----/\----+
  2243.         mov    bx,argx0            ;   |           |
  2244.                             ;   |           |
  2245.                             ;   +----------+
  2246.  
  2247.         mov    dx,bpline
  2248.         mul    dx            ;Multiply y*bytesrow
  2249.  
  2250.         add    bx,ax            ;Add in x coordinate
  2251.         adc    dx,0            ; and any carry
  2252.  
  2253.         mov    ax,word ptr [spage]
  2254.         and    ax,000fh
  2255.         add    bx,ax
  2256.         adc    dx,0            ; and any carry
  2257.  
  2258.         mov    ax,word ptr [spage]
  2259.         shr    ax,1
  2260.         shr    ax,1
  2261.         shr    ax,1
  2262.         shr    ax,1
  2263.         add    ax,word ptr [spage+2]
  2264.  
  2265.         mov    sourcepage,dx
  2266.         mov    word ptr [sourcescr],bx
  2267.         mov    word ptr [sourcescr+2],ax
  2268.  
  2269. ;-------
  2270.         mov    ax,argy2    ;target
  2271.         mov    bx,argx2
  2272.         mov    dx,bpline
  2273.         mul    dx
  2274.         add    bx,ax
  2275.         adc    dx,0            ; and any carry
  2276.  
  2277.         mov    ax,word ptr [tpage]
  2278.         and    ax,000fh
  2279.         add    bx,ax
  2280.         adc    dx,0            ; and any carry
  2281.  
  2282.         mov    ax,word ptr [tpage]
  2283.         shr    ax,1
  2284.         shr    ax,1
  2285.         shr    ax,1
  2286.         shr    ax,1
  2287.         add    ax,word ptr [tpage+2]
  2288.  
  2289.         mov    targetpage,dx
  2290.         mov    word ptr [targetscr],bx
  2291.         mov    word ptr [targetscr+2],ax
  2292.         jmp    movevideobl_01
  2293.  
  2294.  
  2295. bottomupmove:    add    ax,vertlines
  2296.         mov    varpixelrows,ax
  2297.  
  2298.         mov    ax,argy0    ;source     ;   +----------+
  2299.         add    ax,varpixelrows         ;   |           |
  2300.         dec    ax                ;   |           |
  2301.         mov    bx,argx0            ;   +----\/----+
  2302.                             ;   +----------+
  2303.         mov    dx,bpline
  2304.         mul    dx
  2305.         add    bx,ax            ;Add in x coordinate
  2306.         adc    dx,0            ; and any carry
  2307.  
  2308.         mov    ax,word ptr [spage]
  2309.         and    ax,000fh
  2310.         add    bx,ax
  2311.         adc    dx,0            ; and any carry
  2312.  
  2313.         mov    ax,word ptr [spage]
  2314.         shr    ax,1
  2315.         shr    ax,1
  2316.         shr    ax,1
  2317.         shr    ax,1
  2318.         add    ax,word ptr [spage+2]
  2319.  
  2320.         mov    sourcepage,dx
  2321.         mov    word ptr [sourcescr],bx
  2322.         mov    word ptr [sourcescr+2],ax
  2323.  
  2324.  
  2325.         mov    ax,argy1
  2326.         sub    ax,argy0
  2327.         add    ax,argy2
  2328.         mov    bx,argx2    ;target
  2329.  
  2330.         mov    dx,bpline
  2331.         mul    dx
  2332.         add    bx,ax
  2333.         adc    dx,0            ; and any carry
  2334.  
  2335.         mov    ax,word ptr [tpage]
  2336.         and    ax,000fh
  2337.         add    bx,ax
  2338.         adc    dx,0            ; and any carry
  2339.  
  2340.         mov    ax,word ptr [tpage]
  2341.         shr    ax,1
  2342.         shr    ax,1
  2343.         shr    ax,1
  2344.         shr    ax,1
  2345.         add    ax,word ptr [tpage+2]
  2346.  
  2347.         mov    targetpage,dx
  2348.         mov    word ptr [targetscr],bx
  2349.         mov    word ptr [targetscr+2],ax
  2350.  
  2351. ;        xor    ax,ax
  2352. ;        sub    ax,bpline        ; negate bpline
  2353. ;        mov    bpline,ax
  2354.  
  2355.         xor    ax,ax
  2356.         sub    ax,pagechange
  2357.         mov    pagechange,ax
  2358.  
  2359. ;-----------------------------------------------------move screen to buffer
  2360. movevideobl_01:
  2361.         les    di,workbuffer
  2362.         lds    si,sourcescr
  2363.         mov    ax,sourcepage
  2364.         call    changepage
  2365.  
  2366.         mov    cx,varpixelrowlen
  2367.         mov    bx,si
  2368.         add    bx,cx
  2369.         jnc    movevideobl_02
  2370.  
  2371.         mov    cx,si
  2372.         neg    cx
  2373.         shr    cx,1
  2374.         rep    movsw
  2375.         adc    cx,0
  2376.         rep    movsb
  2377.         call    nextpage
  2378.         mov    cx,bx
  2379.  
  2380. movevideobl_02: shr    cx,1
  2381.         rep    movsw
  2382.         adc    cx,0
  2383.         rep    movsb
  2384.  
  2385. ;-----------------------------------------------------move buffer to screen
  2386. mvetoscr_09:    lds    si,workbuffer
  2387.         les    di,targetscr
  2388.         mov    ax,targetpage
  2389.         call    changepage
  2390.  
  2391.         mov    cx,varpixelrowlen
  2392.         mov    bx,di
  2393.         add    bx,cx
  2394.         jnc    movetoscr_10
  2395.  
  2396.         mov    cx,di
  2397.         neg    cx
  2398.         shr    cx,1
  2399.         rep    movsw
  2400.         adc    cx,0
  2401.         rep    movsb
  2402.         call    nextpage
  2403.         mov    cx,bx
  2404.  
  2405. movetoscr_10:    shr    cx,1
  2406.         rep    movsw
  2407.         adc    cx,0
  2408.         rep    movsb
  2409. ;-----------------------------------------------------move buffer to screen
  2410. mvetoscr_30:    mov    ax,bpline
  2411.         mov    bx,pagechange
  2412.         test    bx,08000h      ;check if we are going backwards
  2413.         jz    mvetoscr_fwd
  2414.  
  2415.         sub    word ptr [targetscr],ax
  2416.         sbb    targetpage,0
  2417.         sub    word ptr [sourcescr],ax
  2418.         sbb    sourcepage,0
  2419.         jmp    short mvetoscr_32
  2420.  
  2421.  
  2422. mvetoscr_fwd:    add    word ptr [targetscr],ax
  2423.         adc    targetpage,0
  2424.         add    word ptr [sourcescr],ax
  2425.         adc    sourcepage,0
  2426.  
  2427. mvetoscr_32:    dec    varpixelrows
  2428.         jz    mvetoscr_33
  2429.         jmp    movevideobl_01
  2430.  
  2431. mvetoscr_33:
  2432.         pop    di
  2433.         pop    si
  2434.         pop    es
  2435.         pop    ds
  2436.         ret
  2437. movevideopixels endp
  2438.  
  2439.  
  2440.  
  2441. setvpage    proc    far pagen:word
  2442.         push    ds
  2443.         push    si
  2444.         push    es
  2445.         push    di
  2446.  
  2447.         lds    si,cs:TDtable
  2448.         mov    ax,pagen
  2449.         cmp    ax,ds:[si].vmaxpages
  2450.         jg    novpage
  2451.  
  2452.         mov    bx,40h
  2453.         mov    ds,bx
  2454.         mov    si,62h
  2455.         mov    ds:[si],al
  2456.         mov    si,4eh
  2457.         xor    bx,bx
  2458.         or    al,al
  2459.         jz    vpageit
  2460.         mov    bx,8000h
  2461. vpageit:    mov    ds:[si],bx
  2462.  
  2463.         mov    ah,5
  2464.         int    10h
  2465.  
  2466. novpage:    pop    di
  2467.         pop    es
  2468.         pop    si
  2469.         pop    ds
  2470.         ret
  2471. setvpage    endp
  2472.  
  2473. setapage    proc    far pagen:word
  2474.         push    ds
  2475.         push    si
  2476.         push    es
  2477.         push    di
  2478.  
  2479.         lds    si,cs:TDtable
  2480.         mov    ax,pagen
  2481.         cmp    ax,ds:[si].vmaxpages
  2482.         jg    noapage
  2483.  
  2484.         or    al,al        ; if 0 then mov 0 to activepage
  2485.         mov    ds:[si].activepage,0
  2486.         jz    noapage
  2487.         mov    ds:[si].activepage,8000h
  2488.  
  2489. noapage:    pop    di
  2490.         pop    es
  2491.         pop    si
  2492.         pop    ds
  2493.         ret
  2494. setapage    endp
  2495.  
  2496.  
  2497. ;----------------------------------------------------------------------------;
  2498. ;                                         ;
  2499. ;----------------------------------------------------------------------------;
  2500.  
  2501. changepage    proc    near    ;bank number is in AX
  2502.         cli
  2503.         mov    cs:current64kpage,ax
  2504.         jmp    word ptr cs:bankadr
  2505. changepage    endp
  2506.  
  2507. _tseng        proc    near    ;Tseng
  2508.         push    ax
  2509.         push    dx
  2510.         and    al,7
  2511.         mov    ah,al
  2512.         shl    al,1
  2513.         shl    al,1
  2514.         shl    al,1
  2515.         or    al,ah
  2516.         or    al,01000000b
  2517.         mov    dx,3cdh
  2518.         out    dx,al
  2519.         sti
  2520.         pop    dx
  2521.         pop    ax
  2522.         ret
  2523. _tseng        endp
  2524.  
  2525.  
  2526. _tseng4     proc    near    ;Tseng 4000 series
  2527.         push    ax
  2528.         push    dx
  2529.         mov    ah,al
  2530.         mov    dx,3bfh         ;Enable access to extended registers
  2531.         mov    al,3
  2532.         out    dx,al
  2533.         mov    dl,0d8h
  2534.         mov    al,0a0h
  2535.         out    dx,al
  2536.         and    ah,15
  2537.         mov    al,ah
  2538.         shl    al,1
  2539.         shl    al,1
  2540.         shl    al,1
  2541.         shl    al,1
  2542.         or    al,ah
  2543.         mov    dl,0cdh
  2544.         out    dx,al
  2545.         sti
  2546.         pop    dx
  2547.         pop    ax
  2548.         ret
  2549. _tseng4     endp
  2550.  
  2551.  
  2552. _trident    proc    near    ;Trident
  2553.         push    ax
  2554.         push    dx
  2555.         mov    dx,3ceh     ;set page size to 64k
  2556.         mov    al,6
  2557.         out    dx,al
  2558.         inc    dl
  2559.         in    al,dx
  2560.         dec    dl
  2561.         or    al,4
  2562.         mov    ah,al
  2563.         mov    al,6
  2564.         out    dx,ax
  2565.  
  2566.         mov    dl,0c4h     ;switch to BPS mode
  2567.         mov    al,0bh
  2568.         out    dx,al
  2569.         inc    dl
  2570.         in    al,dx
  2571.         dec    dl
  2572.  
  2573.         mov    ah,byte ptr cs:current64kpage       ;OSEG
  2574.         xor    ah,2
  2575.         mov    dx,3c4h
  2576.         mov    al,0eh
  2577.         out    dx,ax
  2578.         sti
  2579.         pop    dx
  2580.         pop    ax
  2581.         ret
  2582. _trident    endp
  2583.  
  2584.  
  2585. _video7     proc    near    ;Video 7
  2586.         push    ax
  2587.         push    dx
  2588.         push    cx
  2589.         and    ax,15
  2590.         mov    ch,al
  2591.         mov    dx,3c4h
  2592.         mov    ax,0ea06h
  2593.         out    dx,ax
  2594.         mov    ah,ch
  2595.         and    ah,1
  2596.         mov    al,0f9h
  2597.         out    dx,ax
  2598.         mov    al,ch
  2599.         and    al,1100b
  2600.         mov    ah,al
  2601.         shr    ah,1
  2602.         shr    ah,1
  2603.         or    ah,al
  2604.         mov    al,0f6h
  2605.         out    dx,al
  2606.         inc    dx
  2607.         in    al,dx
  2608.         dec    dx
  2609.         and    al,not 1111b
  2610.         or    ah,al
  2611.         mov    al,0f6h
  2612.         out    dx,ax
  2613.         mov    ah,ch
  2614.         mov    cl,4
  2615.         shl    ah,cl
  2616.         and    ah,100000b
  2617.         mov    dl,0cch
  2618.         in    al,dx
  2619.         mov    dl,0c2h
  2620.         and    al,not 100000b
  2621.         or    al,ah
  2622.         out    dx,al
  2623.         sti
  2624.         pop    cx
  2625.         pop    dx
  2626.         pop    ax
  2627.         ret
  2628. _video7     endp
  2629.  
  2630.  
  2631. _paradise    proc    near    ;Paradise
  2632.         push    ax
  2633.         push    dx
  2634.         mov    dx,3ceh
  2635.         mov    ax,50fh     ;turn off write protect on VGA registers
  2636.         out    dx,ax
  2637.         mov    ah,byte ptr cs:current64kpage     ;OSEG
  2638.         shl    ah,1
  2639.         shl    ah,1
  2640.         shl    ah,1
  2641.         shl    ah,1
  2642.         mov    al,9
  2643.         out    dx,ax
  2644.         sti
  2645.         pop    dx
  2646.         pop    ax
  2647.         ret
  2648. _paradise    endp
  2649.  
  2650.  
  2651. _chipstech    proc    near    ;Chips & Tech
  2652.         push    ax
  2653.         push    dx
  2654.         mov    dx,46e8h    ;place chip in setup mode
  2655.         mov    ax,1eh
  2656.         out    dx,ax
  2657.         mov    dx,103h     ;enable extended registers
  2658.         mov    ax,0080h
  2659.         out    dx,ax
  2660.         mov    dx,46e8h    ;bring chip out of setup mode
  2661.         mov    ax,0eh
  2662.         out    dx,ax
  2663.         mov    ah,byte ptr cs:current64kpage     ;OSEG[curbk]
  2664.         shl    ah,1        ;change 64k bank number into 16k bank number
  2665.         shl    ah,1
  2666.         mov    al,10h
  2667.         mov    dx,3d6h
  2668.         out    dx,ax
  2669.         sti
  2670.         pop    dx
  2671.         pop    ax
  2672.         ret
  2673. _chipstech    endp
  2674.  
  2675.  
  2676. _ativga     proc    near    ;ATI VGA Wonder
  2677.         push    ax
  2678.         push    dx
  2679.         mov    ah,al
  2680.         mov    dx,1ceh
  2681.         mov    al,0b2h
  2682.         out    dx,al
  2683.         inc    dl
  2684.         in    al,dx
  2685.         shl    ah,1
  2686.         and    al,0e1h
  2687.         or    ah,al
  2688.         mov    al,0b2h
  2689.         dec    dl
  2690.         out    dx,ax
  2691.         sti
  2692.         pop    dx
  2693.         pop    ax
  2694.         ret
  2695. _ativga     endp
  2696.  
  2697.  
  2698. _everex     proc    near    ;Everex
  2699.         push    ax
  2700.         push    dx
  2701.         push    cx
  2702.         mov    cl,al
  2703.         mov    dx,3c4h
  2704.         mov    al,8
  2705.         out    dx,al
  2706.         inc    dl
  2707.         in    al,dx
  2708.         dec    dl
  2709.         shl    al,1
  2710.         shr    cl,1
  2711.         rcr    al,1
  2712.         mov    ah,al
  2713.         mov    al,8
  2714.         out    dx,ax
  2715.         mov    dl,0cch
  2716.         in    al,dx
  2717.         mov    dl,0c2h
  2718.         and    al,0dfh
  2719.         shr    cl,1
  2720.         jc    nob2
  2721.         or    al,20h
  2722. nob2:        out    dx,al
  2723.         sti
  2724.         pop    cx
  2725.         pop    dx
  2726.         pop    ax
  2727.         ret
  2728. _everex     endp
  2729.  
  2730.  
  2731. _aheada     proc    near    ;Ahead Systems Ver A
  2732.         push    ax
  2733.         push    dx
  2734.         push    cx
  2735.         mov    ch,al
  2736.         mov    dx,3ceh     ;Enable extended registers
  2737.         mov    ax,200fh
  2738.         out    dx,ax
  2739.         mov    dl,0cch     ;bit 0
  2740.         in    al,dx
  2741.         mov    dl,0c2h
  2742.         and    al,11011111b
  2743.         shr    ch,1
  2744.         jnc    skpa
  2745.         or    al,00100000b
  2746. skpa:        out    dx,al
  2747.         mov    dl,0cfh     ;bits 1,2,3
  2748.         mov    al,0
  2749.         out    dx,al
  2750.         inc    dx
  2751.         in    al,dx
  2752.         dec    dx
  2753.         and    al,11111000b
  2754.         or    al,ch
  2755.         mov    ah,al
  2756.         mov    al,0
  2757.         out    dx,ax
  2758.         sti
  2759.         pop    cx
  2760.         pop    dx
  2761.         pop    ax
  2762.         ret
  2763. _aheada     endp
  2764.  
  2765.  
  2766. _aheadb     proc    near    ;Ahead Systems Ver A
  2767.         push    ax
  2768.         push    dx
  2769.         push    cx
  2770.         mov    ch,al
  2771.         mov    dx,3ceh     ;Enable extended registers
  2772.         mov    ax,200fh
  2773.         out    dx,ax
  2774.         mov    ah,ch
  2775.         mov    cl,4
  2776.         shl    ah,cl
  2777.         or    ah,ch
  2778.         mov    al,0dh
  2779.         out    dx,ax
  2780.         sti
  2781.         pop    cx
  2782.         pop    dx
  2783.         pop    ax
  2784.         ret
  2785. _aheadb     endp
  2786.  
  2787.  
  2788. _oaktech    proc    near    ;Oak Technology Inc OTI-067
  2789.         push    ax
  2790.         push    dx
  2791.         and    al,15
  2792.         mov    ah,al
  2793.         shl    al,1
  2794.         shl    al,1
  2795.         shl    al,1
  2796.         shl    al,1
  2797.         or    ah,al
  2798.         mov    al,11h
  2799.         mov    dx,3deh
  2800.         out    dx,ax
  2801.         sti
  2802.         pop    dx
  2803.         pop    ax
  2804.         ret
  2805. _oaktech    endp
  2806.  
  2807. _genoa        proc    near
  2808.         push    ax
  2809.         push    dx
  2810.         mov    ah,al
  2811.         shl    al,1
  2812.         shl    al,1
  2813.         shl    al,1
  2814.         or    ah,al
  2815.         mov    al,6
  2816.         or    ah,40h
  2817.         mov    dx,3c4h
  2818.         out    dx,ax
  2819.         sti
  2820.         pop    dx
  2821.         pop    ax
  2822.         ret
  2823. _genoa        endp
  2824.  
  2825. _ncr        proc near    ;NCR 77C22E
  2826.         push    ax
  2827.         push    dx
  2828.         shl    al,1    ;change 64k bank number into 16k bank number
  2829.         shl    al,1
  2830.         mov    ah,al
  2831.         mov    al,18h
  2832.         mov    dx,3c4h
  2833.         out    dx,ax
  2834.         mov    ax,19h
  2835.         out    dx,ax
  2836.         sti
  2837.         pop    dx
  2838.         pop    ax
  2839.         ret
  2840. _ncr        endp
  2841.  
  2842. _compaq     proc near    ;Compaq
  2843.         push    ax
  2844.         push    dx
  2845.         mov    dx,3ceh
  2846.         mov    ax,50fh ;unlock extended registers
  2847.         out    dx,ax
  2848.         mov    ah,byte ptr cs:current64kpage  ;OSEG[curbk]
  2849.         shl    ah,1    ;change 64k bank number into 4k bank number
  2850.         shl    ah,1
  2851.         shl    ah,1
  2852.         shl    ah,1
  2853.         mov    al,45h
  2854.         out    dx,ax
  2855.         sti
  2856.         pop    dx
  2857.         pop    ax
  2858.         ret
  2859. _compaq     endp
  2860.  
  2861. _vesa        proc near    ;Vesa SVGA interface
  2862.         push    ax
  2863.         push    bx
  2864.         push    cx
  2865.         push    dx
  2866.         mov    cl,[vesashift]
  2867.         shl    ax,cl
  2868.         mov    dx,ax
  2869.         xor    bx,bx
  2870.         mov    ax,4f05h
  2871.         int    10h
  2872.         sti
  2873.         pop    dx
  2874.         pop    cx
  2875.         pop    bx
  2876.         pop    ax
  2877.         ret
  2878. _vesa        endp
  2879.  
  2880.  
  2881. _nobank     proc    near
  2882.         sti
  2883.         ret
  2884. _nobank     endp
  2885.  
  2886.  
  2887. ;----------------------------------------------------------------------------;
  2888. ;                                         ;
  2889. ;----------------------------------------------------------------------------;
  2890. whichsvga    proc    near
  2891.         push    es
  2892.         push    di
  2893.         push    ds
  2894.         push    si
  2895.         push    dx
  2896.         push    cx
  2897.         push    bx
  2898.  
  2899.         lds    si,cs:TDTable
  2900.         lds    si,ds:[si].vjumptable
  2901.         add    si,_nobank-drvjumptable
  2902.         mov    cs:bankadr,si
  2903.  
  2904.         mov    cs:current64kpage,0
  2905.         mov    cs:vga512flag,0
  2906.         mov    cs:vga1024flag,0
  2907.         mov    cs:svgatype,-2
  2908.  
  2909.         call    getvgatype
  2910.  
  2911.         mov    ax,cs:svgatype
  2912.         cmp    ax,x_genoa
  2913.         mov    bx,_genoa-drvjumptable
  2914.         je    found
  2915.  
  2916.         cmp    ax,x_paradise
  2917.         mov    bx,_paradise-drvjumptable
  2918.         je    found
  2919.  
  2920.         cmp    ax,x_ativga
  2921.         mov    bx,_ativga-drvjumptable
  2922.         je    found
  2923.  
  2924.         cmp    ax,x_everex
  2925.         mov    bx,_everex-drvjumptable
  2926.         je    found
  2927.  
  2928.         cmp    ax,x_trident
  2929.         mov    bx,_trident-drvjumptable
  2930.         je    found
  2931.         cmp    ax,x_t8900
  2932.         je    found
  2933.  
  2934.         cmp    ax,x_video7
  2935.         mov    bx,_video7-drvjumptable
  2936.         je    found
  2937.  
  2938.         cmp    ax,x_chipstech
  2939.         mov    bx,_chipstech-drvjumptable
  2940.         je    found
  2941.  
  2942.         cmp    ax,x_tseng4
  2943.         mov    bx,_tseng4-drvjumptable
  2944.         je    found
  2945.  
  2946.         cmp    ax,x_tseng
  2947.         mov    bx,_tseng-drvjumptable
  2948.         je    found
  2949.  
  2950.         cmp    ax,x_aheada
  2951.         mov    bx,_aheada-drvjumptable
  2952.         je    found
  2953.  
  2954.         cmp    ax,x_aheadb
  2955.         mov    bx,_aheadb-drvjumptable
  2956.         je    found
  2957.  
  2958.         cmp    ax,x_oaktech
  2959.         mov    bx,_oaktech-drvjumptable
  2960.         je    found
  2961.  
  2962.         cmp    ax,x_cirrus
  2963.         mov    bx,_nobank-drvjumptable
  2964.         je    found
  2965.  
  2966.         cmp    ax,x_ncr
  2967.         mov    bx,_ncr-drvjumptable
  2968.         je    found
  2969.  
  2970.         cmp    ax,x_compaq
  2971.         mov    bx,_compaq-drvjumptable
  2972.         je    found
  2973.  
  2974.         cmp    ax,x_vesa
  2975.         mov    bx,_vesa-drvjumptable
  2976.  
  2977.         stc
  2978.         jne    nofnd
  2979.  
  2980. found:        lds    si,cs:TDTable
  2981.         lds    si,ds:[si].vjumptable
  2982.         add    si,bx
  2983.         mov    cs:bankadr,si
  2984.  
  2985.         clc
  2986. nofnd:        pop    bx
  2987.         pop    cx
  2988.         pop    dx
  2989.         pop    si
  2990.         pop    ds
  2991.         pop    di
  2992.         pop    es
  2993.         ret
  2994. whichsvga    endp
  2995.  
  2996. ;----------------------------------------------------------------------------;
  2997. ;                                         ;
  2998. ;----------------------------------------------------------------------------;
  2999. nojmp    macro
  3000.     local    lbl
  3001.     jmp    lbl
  3002. lbl:
  3003.     endm
  3004.  
  3005.  
  3006. getvgatype    proc    near
  3007.         mov    si,1
  3008.         mov    ax,0c000h
  3009.         mov    es,ax
  3010.         cmp    word ptr es:[40h],'13'  ;ATI Signiture on the Video BIOS
  3011.         jnz    noati
  3012.  
  3013.         mov    cs:svgatype,x_ativga
  3014.         cli
  3015.         mov    dx,1ceh
  3016.         mov    al,0bbh
  3017.         out    dx,al
  3018.         inc    dl
  3019.         in    al,dx
  3020.         sti
  3021.         and    al,20h
  3022.         jz    no512
  3023.         mov    cs:vga512flag,1
  3024. no512:        jmp    fini
  3025.  
  3026. noati:        mov    ax,7000h        ;Test for Everex
  3027.         xor    bx,bx
  3028.         cld
  3029.         int    10h
  3030.         cmp    al,70h
  3031.         jnz    noev
  3032.  
  3033.         mov    cs:svgatype,x_everex
  3034.         and    ch,11000000b        ;how much memory on board
  3035.         jz    skp
  3036.         mov    cs:vga512flag,1
  3037. skp:                        ;fall through for Everex boards using Trident or Tseng4000
  3038.  
  3039. noev:        mov    ax,0bf03h        ;Test for Compaq
  3040.         xor    bx,bx
  3041.         mov    cx,bx
  3042.         int    10h
  3043.         cmp    ax,0bf03h
  3044.         jnz    nocp
  3045.         test    cl,40h            ;is 640x480x256 available?
  3046.         jz    nocp
  3047.         mov    cs:svgatype,x_compaq
  3048.         mov    cs:vga512flag,1
  3049.         jmp    fini
  3050.  
  3051. nocp:        mov    dx,3c4h         ;Test for NCR 77C22E
  3052.         mov    ax,0ff05h
  3053.         call    _isport2
  3054.         jnz    noncr
  3055.         mov    ax,5            ;Disable extended registers
  3056.         out    dx,ax
  3057.         mov    ax,0ff10h        ;Try to write to extended register 10
  3058.         call    _isport2        ;If it writes then not NCR
  3059.         jz    noncr
  3060.         mov    ax,105h         ;Enable extended registers
  3061.         out    dx,ax
  3062.         mov    ax,0ff10h
  3063.         call    _isport2
  3064.         jnz    noncr            ;If it does NOT write then not NCR
  3065.         mov    cs:svgatype,x_ncr
  3066.         mov    cs:vga512flag,1
  3067.         jmp    fini
  3068.  
  3069. noncr:        mov    dx,3c4h         ;Test for Trident
  3070.         mov    al,0bh
  3071.         out    dx,al
  3072.         inc    dl
  3073.         in    al,dx
  3074.         cmp    al,06h
  3075.         ja    notri
  3076.         cmp    al,2
  3077.         jb    notri
  3078.         mov    cs:svgatype,x_trident
  3079.         cmp    al,3
  3080.         jb    no89
  3081.         mov    cs:svgatype,x_t8900
  3082.         mov    dx,3d5h
  3083.         mov    al,1fh
  3084.         out    dx,al
  3085.         inc    dx
  3086.         in    al,dx
  3087.         and    al,3
  3088.         cmp    al,1
  3089.         jb    notmem
  3090.         mov    cs:vga512flag,1
  3091.         je    notmem
  3092.         mov    cs:vga1024flag,1
  3093. notmem:     jmp    fini
  3094.  
  3095. no89:        mov    cs:vga512flag,1
  3096.         jmp    fini
  3097.  
  3098. notri:        mov    ax,6f00h        ;Test for Video 7
  3099.         xor    bx,bx
  3100.         cld
  3101.         int    10h
  3102.         cmp    bx,'V7'
  3103.         jnz    nov7
  3104.         mov    cs:svgatype,x_video7
  3105.         mov    ax,6f07h
  3106.         cld
  3107.         int    10h
  3108.         and    ah,7fh
  3109.         cmp    ah,1
  3110.         jbe    skp2
  3111.         mov    cs:vga512flag,1
  3112. skp2:        cmp    ah,3
  3113.         jbe    skp3
  3114.         mov    cs:vga1024flag,1
  3115. skp3:        jmp    fini
  3116.  
  3117. nov7:        mov    dx,3d4h         ;Test for GENOA GVGA
  3118.         mov    ax,032eh        ;check for Herchi Register
  3119.         call    _isport2
  3120.         jnz    nogn
  3121.         mov    dx,3c4h         ;check for memory segment register
  3122.         mov    ax,3f06h
  3123.         call    _isport2
  3124.         jnz    nogn
  3125.         mov    cs:svgatype,x_genoa
  3126.         mov    cs:vga512flag,1
  3127.         jmp    fini
  3128.  
  3129. nogn:        call    _cirrus         ;Test for Cirrus
  3130.         cmp    cs:svgatype,x_cirrus
  3131.         jne    noci
  3132.         jmp    fini
  3133.  
  3134. noci:        mov    dx,3ceh         ;Test for Paradise
  3135.         mov    al,9            ;check Bank switch register
  3136.         out    dx,al
  3137.         inc    dx
  3138.         in    al,dx
  3139.         dec    dx
  3140.         or    al,al
  3141.         jnz    nopd
  3142.  
  3143.         mov    ax,50fh         ;turn off write protect on VGA registers
  3144.         out    dx,ax
  3145.         mov    cx,1
  3146.         mov    dx,3ceh         ;Test for Paradise
  3147.         call    _chkbk
  3148.         jc    nopd            ;if bank 0 and 1 same not paradise
  3149.         mov    cs:svgatype,x_paradise
  3150.         mov    dx,3ceh
  3151.         mov    al,0bh            ;512k detect from Bob Berry
  3152.         out    dx,al
  3153.         inc    dx
  3154.         in    al,dx
  3155.         test    al,80h            ;if top bit set then 512k
  3156.         jz    nop512
  3157.         mov    cs:vga512flag,1
  3158. nop512:     jmp    fini
  3159.  
  3160. nopd:        mov    ax,5f00h        ;Test for Chips & Tech
  3161.         xor    bx,bx
  3162.         cld
  3163.         int    10h
  3164.         cmp    al,5fh
  3165.         jnz    noct
  3166.         mov    cs:svgatype,x_chipstech
  3167.         cmp    bh,1
  3168.         jb    skp4
  3169.         mov    cs:vga512flag,1
  3170. skp4:        jmp    fini
  3171.  
  3172. noct:        mov    ch,0
  3173.         mov    dx,3d4h         ;check for Tseng 4000 series
  3174.         mov    ax,0f33h
  3175.         call    _isport2
  3176.         jnz    not4
  3177.         mov    ch,1
  3178.  
  3179.         mov    dx,3bfh         ;Enable access to extended registers
  3180.         mov    al,3
  3181.         out    dx,al
  3182.         mov    dx,3d8h
  3183.         mov    al,0a0h
  3184.         out    dx,al
  3185.         jmp    short yes4
  3186.  
  3187. not4:        mov    dx,3d4h         ;Test for Tseng 3000 or 4000
  3188.         mov    ax,1f25h        ;is the Overflow High register there?
  3189.         call    _isport2
  3190.         jnz    nots
  3191.         mov    al,03fh         ;bottom six bits only
  3192.         jmp    short yes3
  3193. yes4:        mov    al,0ffh
  3194. yes3:        mov    dx,3cdh         ;test bank switch register
  3195.         call    _isport1
  3196.         jnz    nots
  3197.         mov    cs:svgatype,x_tseng
  3198.         cmp    ch,0
  3199.         jnz    t4mem
  3200.         mov    cs:vga512flag,1
  3201.         jmp    fini
  3202.  
  3203. t4mem:        mov    dx,3d4h         ;Tseng 4000 memory detect 1meg
  3204.         mov    al,37h
  3205.         out    dx,al
  3206.         inc    dx
  3207.         in    al,dx
  3208.         test    al,1000b        ;if using 64kx4 RAMs then no more than 256k
  3209.         jz    nomem
  3210.         and    al,3
  3211.         cmp    al,1            ;if 8 bit wide bus then only two 256kx4 RAMs
  3212.         jbe    nomem
  3213.         mov    cs:vga512flag,1
  3214.         cmp    al,2            ;if 16 bit wide bus then four 256kx4 RAMs
  3215.         je    nomem
  3216.         mov    cs:vga1024flag,1    ;full meg with eight 256kx4 RAMs
  3217. nomem:        mov    cs:svgatype,x_tseng4
  3218.         jmp    fini
  3219.  
  3220. nots:
  3221.         mov    dx,3ceh         ;Test for Above A or B chipsets
  3222.         mov    ax,200fh
  3223.         out    dx,ax
  3224.         inc    dx
  3225.         nojmp
  3226.         in    al,dx
  3227.         cmp    al,21h
  3228.         jz    verb
  3229.         cmp    al,20h
  3230.         jnz    noab
  3231.         mov    cs:svgatype,x_aheada
  3232.         mov    cs:vga512flag,1
  3233.         jmp    short fini
  3234.  
  3235. verb:        mov    cs:svgatype,x_aheadb
  3236.         mov    cs:vga512flag,1
  3237.         jmp    short fini
  3238.  
  3239. noab:        mov    dx,3deh         ;Test for Oak Technology
  3240.         mov    ax,0ff11h        ;look for bank switch register
  3241.         call    _isport2
  3242.         jz    oakok
  3243.  
  3244.         push    es
  3245.         push    di
  3246.         push    cx
  3247.  
  3248.         cld
  3249.         mov    ax,0c000h
  3250.         mov    es,ax
  3251.         xor    di,di
  3252.         mov    cx,256
  3253.  
  3254.         mov    al,'O'
  3255. findoak:    repne    scasb
  3256.         jcxz    notoak
  3257.  
  3258.         cmp    byte ptr es:[di],'A'
  3259.         jne    findoak
  3260.  
  3261.         cmp    byte ptr es:[di+1],'K'
  3262.         jne    findoak
  3263.  
  3264.         pop    cx
  3265.         pop    di
  3266.         pop    es
  3267.         jmp    short oakok
  3268.  
  3269.  
  3270. notoak:     pop    cx
  3271.         pop    di
  3272.         pop    es
  3273.         jmp    short nooak
  3274.  
  3275. oakok:        mov    cs:svgatype,x_oaktech
  3276.         mov    al,0dh
  3277.         out    dx,al
  3278.         inc    dx
  3279.         nojmp
  3280.         in    al,dx
  3281.         test    al,80h
  3282.         jz    no4ram
  3283.         mov    cs:vga512flag,1
  3284. no4ram:     jmp    short fini
  3285.  
  3286. nooak:        mov    si,0
  3287.  
  3288. fini:        mov    ax,si
  3289.         ret
  3290. getvgatype    endp
  3291.  
  3292.  
  3293. _cirrus     proc near
  3294.         mov    dx,3d4h     ; assume 3dx addressing
  3295.         mov    al,0ch        ; screen a start address hi
  3296.         out    dx,al        ; select index
  3297.         inc    dx        ; point to data
  3298.         mov    ah,al        ; save index in ah
  3299.         in    al,dx        ; get screen a start address hi
  3300.         xchg    ah,al        ; swap index and data
  3301.         push    ax        ; save old value
  3302.         push    dx        ; save crtc address
  3303.         xor    al,al        ; clear crc
  3304.         out    dx,al        ; and out to the crtc
  3305.  
  3306.         mov    al,1fh        ; Eagle ID register
  3307.         dec    dx        ; back    to index
  3308.         out    dx,al        ; select index
  3309.         inc    dx        ; point to data
  3310.         in    al,dx        ; read the id register
  3311.         mov    bh,al        ; and save it in bh
  3312.  
  3313.         mov    cl,4        ; nibble swap rotate count
  3314.         mov    dx,3c4h     ; sequencer/extensions
  3315.         mov    bl,6        ; extensions enable register
  3316.  
  3317.         ror    bh,cl        ; compute extensions disable value
  3318.         mov    ax,bx        ; extensions disable
  3319.         out    dx,ax        ; disable extensions
  3320.         inc    dx        ; point to data
  3321.         in    al,dx        ; read enable flag
  3322.         or    al,al        ; disabled ?
  3323.         jnz    exit        ; nope, not an cirrus
  3324.  
  3325.         ror    bh,cl        ; compute extensions enable value
  3326.         dec    dx        ; point to index
  3327.         mov    ax,bx        ; extensions enable
  3328.         out    dx,ax        ; enable extensions
  3329.         inc    dx        ; point to data
  3330.         in    al,dx        ; read enable flag
  3331.         cmp    al,1        ; enabled ?
  3332.         jne    exit        ; nope, not an cirrus
  3333.         mov    cs:svgatype,x_cirrus
  3334.  
  3335. exit:        pop    dx        ; restore crtc address
  3336.         dec    dx        ; point to index
  3337.         pop    ax        ; recover crc index and data
  3338.         out    dx,ax        ; restore crc value
  3339.         ret
  3340. _cirrus     endp
  3341.  
  3342. _chkbk        proc    near        ;bank switch check routine
  3343.         push    es
  3344.         mov    di,0b800h
  3345.         mov    es,di
  3346.         xor    di,di
  3347.         mov    bx,1234h
  3348.         call    _gochk
  3349.         jnz    badchk
  3350.         mov    bx,4321h
  3351.         call    _gochk
  3352.         jnz    badchk
  3353.         clc
  3354.         pop    es
  3355.         ret
  3356. badchk:     stc
  3357.         pop    es
  3358.         ret
  3359. _chkbk        endp
  3360.  
  3361. _gochk        proc    near
  3362.         push    si
  3363.         push    es
  3364.         mov    si,bx
  3365.  
  3366.         mov    al,cl
  3367.         call    _pdrsub
  3368.         xchg    bl,es:[di]
  3369.         mov    al,ch
  3370.         call    _pdrsub
  3371.         xchg    bh,es:[di]
  3372.  
  3373.         xchg    si,bx
  3374.  
  3375.         mov    al,cl
  3376.         call    _pdrsub
  3377.         xor    bl,es:[di]
  3378.         mov    al,ch
  3379.         call    _pdrsub
  3380.         xor    bh,es:[di]
  3381.  
  3382.         xchg    si,bx
  3383.  
  3384.         mov    al,ch
  3385.         call    _pdrsub
  3386.         mov    es:[di],bh
  3387.         mov    al,cl
  3388.         call    _pdrsub
  3389.         mov    es:[di],bl
  3390.  
  3391.         mov    al,0
  3392.         call    _pdrsub
  3393.         or    si,si
  3394.         pop    es
  3395.         pop    si
  3396.         ret
  3397. _gochk        endp
  3398.  
  3399.  
  3400. _pdrsub     proc    near        ;Paradise
  3401.         mov    ah,al
  3402.         mov    al,9
  3403.         out    dx,ax
  3404.         ret
  3405. _pdrsub     endp
  3406.  
  3407.  
  3408. _isport2    proc   near
  3409.         push    bx
  3410.         mov    bx,ax
  3411.         out    dx,al
  3412.         mov    ah,al
  3413.         inc    dx
  3414.         in    al,dx
  3415.         dec    dx
  3416.         xchg    al,ah
  3417.         push    ax
  3418.         mov    ax,bx
  3419.         out    dx,ax
  3420.         out    dx,al
  3421.         mov    ah,al
  3422.         inc    dx
  3423.         in    al,dx
  3424.         dec    dx
  3425.         and    al,bh
  3426.         cmp    al,bh
  3427.         jnz    noport2
  3428.         mov    al,ah
  3429.         mov    ah,0
  3430.         out    dx,ax
  3431.         out    dx,al
  3432.         mov    ah,al
  3433.         inc    dx
  3434.         in    al,dx
  3435.         dec    dx
  3436.         and    al,bh
  3437.         cmp    al,0
  3438. noport2:    pop    ax
  3439.         out    dx,ax
  3440.         pop    bx
  3441.         ret
  3442. _isport2    endp
  3443.  
  3444. _isport1    proc   near
  3445.         mov    ah,al
  3446.         in    al,dx
  3447.         push    ax
  3448.         mov    al,ah
  3449.         out    dx,al
  3450.         in    al,dx
  3451.         and    al,ah
  3452.         cmp    al,ah
  3453.         jnz    noport1
  3454.         mov    al,0
  3455.         out    dx,al
  3456.         in    al,dx
  3457.         and    al,ah
  3458.         cmp    al,0
  3459. noport1:    pop    ax
  3460.         out    dx,al
  3461.         ret
  3462. _isport1    endp
  3463.  
  3464.  
  3465.         end
  3466.