home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / VGAKIT60.ZIP / banks.asm next >
Assembly Source File  |  1994-01-01  |  21KB  |  1,265 lines

  1.  
  2.     include    model.inc
  3.     include    vesa.inc
  4. ;
  5. ;    VGAKIT Version 6.0
  6. ;
  7. ;    Copyright 1988,89,90,91,92,93,94 John Bridges
  8. ;    Free for use in commercial, shareware or freeware applications
  9. ;
  10. ;    BANKS.ASM
  11. ;
  12. .data?
  13.  
  14.     public    curbk
  15.  
  16. curbk    dw    ?
  17.  
  18.     public    vgamem,bksize
  19.  
  20. vgamem    dw    ?        ;amount of memory on VGA card in K
  21. bksize    dw    ?        ;size of memory banks in K
  22.  
  23.     extern    justvesa:word    ;only check for VESA, no chipset tests
  24.     extern    novesa:word    ;disable all VESA VBE checks
  25.     extern    nosvga:word    ;disable all SVGA checks including VESA
  26.  
  27.     public    cirrus,everex,acumos,paradise,tseng,trident,t8900
  28.     public    ativga,aheada,aheadb,oaktech,video7
  29.     public    chipstech,tseng4,genoa,ncr,compaq,vesa,dactype
  30.  
  31. cirrus    dw    ?
  32. everex    dw    ?
  33. acumos    dw    ?
  34. paradise dw    ?
  35. tseng    dw    ?
  36. trident    dw    ?
  37. t8900    dw    ?
  38. ativga    dw    ?
  39. aheada    dw    ?
  40. aheadb    dw    ?
  41. oaktech    dw    ?        ;Oak Technology Inc OTI-067 and OTI-077
  42. video7    dw    ?
  43. chipstech dw    ?
  44. tseng4    dw    ?
  45. genoa    dw    ?
  46. ncr    dw    ?
  47. compaq    dw    ?
  48. vesa    dw    ?
  49.  
  50. dactype    dw    ?        ; 0 = Normal DAC
  51.                 ; 1 = Sierra SC11481, SC11486, SC11488
  52.                 ; 2 = Sierra SC11485, SC11487, SC11489
  53.                 ; 3 = AT&T ATT20C491
  54.                 ; 4 = ACUMOS ADAC1
  55.  
  56. first    dw    ?        ;flag so whichvga() is only called once
  57. retval    dw    ?        ;first return value from whichvga()
  58.  
  59. .data
  60.  
  61. OSEG    equ    SS:        ;segment override for variable access
  62.  
  63.     public    bankadr
  64.  
  65. if @Codesize
  66. bankadr    dw    offset _nobank
  67.     dw    seg _nobank
  68. else
  69. bankadr    dw    offset _nobank
  70. endif
  71.  
  72.     public    vesafunc
  73.  
  74. vesafunc dw    0
  75.     dw    0
  76.  
  77. vesamodes label word
  78.     dw    100h,     640, 400, 8
  79.     dw    101h,     640, 480, 8
  80.     dw    102h,     800, 600, 4
  81.     dw    103h,     800, 600, 8
  82.     dw    104h,    1024, 768, 4
  83.     dw    105h,    1024, 768, 8
  84.     dw    106h,    1280,1024, 4
  85.     dw    107h,    1280,1024, 8
  86.     dw    10Dh,     320, 200,16
  87.     dw    10Eh,     320, 200,16
  88.     dw    10Fh,     320, 200,24
  89.     dw    110h,     640, 480,16
  90.     dw    111h,     640, 480,16
  91.     dw    112h,     640, 480,24
  92.     dw    113h,     800, 600,16
  93.     dw    114h,     800, 600,16
  94.     dw    115h,     800, 600,24
  95.     dw    116h,    1024, 768,16
  96.     dw    117h,    1024, 768,16
  97.     dw    118h,    1024, 768,24
  98.     dw    119h,    1280,1024,16
  99.     dw    11Ah,    1280,1024,16
  100.     dw    11Bh,    1280,1024,24
  101.     dw    0
  102. .code
  103.  
  104.     public    newbank
  105.     public    whichvga
  106.  
  107. newbank    proc            ;bank number is in AX
  108. if @Codesize
  109.     jmp    dword ptr OSEG[bankadr]
  110. else
  111.     jmp    OSEG[bankadr]
  112. endif
  113.  
  114. _tseng::            ;Tseng 3000 series
  115.     push    ax
  116.     push    dx
  117.     cli
  118.     mov    OSEG[curbk],ax
  119.     and    al,7
  120.     mov    ah,al
  121.     shl    al,1
  122.     shl    al,1
  123.     shl    al,1
  124.     or    al,ah
  125.     or    al,01000000b
  126.     mov    dx,3cdh
  127.     out    dx,al
  128.     sti
  129.     pop    dx
  130.     pop    ax
  131.     ret
  132.  
  133.  
  134. _tseng4::            ;Tseng 4000 series
  135.     push    ax
  136.     push    dx
  137.     cli
  138.     mov    OSEG[curbk],ax
  139.     mov    ah,al
  140.     mov    dx,3bfh        ;Enable access to extended registers
  141.     mov    al,3
  142.     out    dx,al
  143.     mov    dl,0d8h
  144.     mov    al,0a0h
  145.     out    dx,al
  146.     and    ah,15
  147.     mov    al,ah
  148.     shl    al,1
  149.     shl    al,1
  150.     shl    al,1
  151.     shl    al,1
  152.     or    al,ah
  153.     mov    dl,0cdh
  154.     out    dx,al
  155.     sti
  156.     pop    dx
  157.     pop    ax
  158.     ret
  159.  
  160.  
  161. _trident::            ;Trident
  162.     push    ax
  163.     push    dx
  164.     push    ax
  165.     cli
  166.     mov    OSEG[curbk],ax
  167.     mov    dx,3ceh        ;set pagesize to 64k
  168.     mov    al,6
  169.     out    dx,al
  170.     inc    dl
  171.     in    al,dx
  172.     dec    dl
  173.     or    al,4
  174.     mov    ah,al
  175.     mov    al,6
  176.     out    dx,ax
  177.  
  178.     mov    dl,0c4h        ;switch to BPS mode
  179.     mov    al,0bh
  180.     out    dx,al
  181.     inc    dl
  182.     in    al,dx
  183.     dec    dl
  184.  
  185.     pop    ax
  186.     mov    ah,al
  187.     xor    ah,2
  188.     mov    dx,3c4h
  189.     mov    al,0eh
  190.     out    dx,ax
  191.     sti
  192.     pop    dx
  193.     pop    ax
  194.     ret
  195.  
  196.  
  197. _video7::            ;Video 7
  198.     push    ax
  199.     push    dx
  200.     push    cx
  201.     cli
  202.     mov    OSEG[curbk],ax
  203.     and    ax,15
  204.     mov    ch,al
  205.     mov    dx,3c4h
  206.     mov    ax,0ea06h
  207.     out    dx,ax
  208.     mov    ah,ch
  209.     and    ah,1
  210.     mov    al,0f9h
  211.     out    dx,ax
  212.     mov    al,ch
  213.     and    al,1100b
  214.     mov    ah,al
  215.     shr    ah,1
  216.     shr    ah,1
  217.     or    ah,al
  218.     mov    al,0f6h
  219.     out    dx,al
  220.     inc    dx
  221.     in    al,dx
  222.     dec    dx
  223.     and    al,not 1111b
  224.     or    ah,al
  225.     mov    al,0f6h
  226.     out    dx,ax
  227.     mov    ah,ch
  228.     mov    cl,4
  229.     shl    ah,cl
  230.     and    ah,100000b
  231.     mov    dl,0cch
  232.     in    al,dx
  233.     mov    dl,0c2h
  234.     and    al,not 100000b
  235.     or    al,ah
  236.     out    dx,al
  237.     sti
  238.     pop    cx
  239.     pop    dx
  240.     pop    ax
  241.     ret
  242.  
  243.  
  244. _paradise::            ;Paradise
  245.     push    ax
  246.     push    dx
  247.     push    ax
  248.     cli
  249.     mov    OSEG[curbk],ax
  250.     mov    dx,3ceh
  251.     mov    ax,50fh        ;turn off write protect on VGA registers
  252.     out    dx,ax
  253.     pop    ax
  254.     mov    ah,al
  255.     mov    al,9
  256.     out    dx,ax
  257.     sti
  258.     pop    dx
  259.     pop    ax
  260.     ret
  261.  
  262. _acumos::            ;AcuMos
  263.     push    ax
  264.     push    dx
  265.     push    ax
  266.     cli
  267.     mov    OSEG[curbk],ax
  268.     mov    dx,3c4h        ;Sequencer index 6
  269.     mov    ax,1206h    ;turn off write protect on VGA registers
  270.     out    dx,ax
  271.     mov    dx,3ceh
  272.     pop    ax
  273.     mov    ah,al
  274.     mov    al,9
  275.     out    dx,ax
  276.     sti
  277.     pop    dx
  278.     pop    ax
  279.     ret
  280.  
  281.  
  282. _chipstech::            ;Chips & Tech
  283.     push    ax
  284.     push    dx
  285.     push    ax
  286.     cli
  287.     mov    OSEG[curbk],ax
  288.     mov    dx,46e8h    ;place chip in setup mode
  289.     mov    ax,1eh
  290.     out    dx,ax
  291.     mov    dx,103h        ;enable extended registers
  292.     mov    ax,0080h
  293.     out    dx,ax
  294.     mov    dx,46e8h    ;bring chip out of setup mode
  295.     mov    ax,0eh
  296.     out    dx,ax
  297.     pop    ax
  298.     mov    ah,al
  299.     mov    al,10h
  300.     mov    dx,3d6h
  301.     out    dx,ax
  302.     sti
  303.     pop    dx
  304.     pop    ax
  305.     ret
  306.  
  307.  
  308. _ativga::            ;ATI VGA Wonder
  309.     push    ax
  310.     push    dx
  311.     cli
  312.     mov    OSEG[curbk],ax
  313.     mov    ah,al
  314.     mov    dx,1ceh
  315.     mov    al,0b2h
  316.     out    dx,al
  317.     inc    dl
  318.     in    al,dx
  319.     shl    ah,1
  320.     and    al,0e1h
  321.     or    ah,al
  322.     mov    al,0b2h
  323.     dec    dl
  324.     out    dx,ax
  325.     sti
  326.     pop    dx
  327.     pop    ax
  328.     ret
  329.  
  330.  
  331. _everex::            ;Everex
  332.     push    ax
  333.     push    dx
  334.     push    cx
  335.     cli
  336.     mov    OSEG[curbk],ax
  337.     mov    cl,al
  338.     mov    dx,3c4h
  339.     mov    al,8
  340.     out    dx,al
  341.     inc    dl
  342.     in    al,dx
  343.     dec    dl
  344.     shl    al,1
  345.     shr    cl,1
  346.     rcr    al,1
  347.     mov    ah,al
  348.     mov    al,8
  349.     out    dx,ax
  350.     mov    dl,0cch
  351.     in    al,dx
  352.     mov    dl,0c2h
  353.     and    al,0dfh
  354.     shr    cl,1
  355.     jc    nob2
  356.     or    al,20h
  357. nob2:    out    dx,al
  358.     sti
  359.     pop    cx
  360.     pop    dx
  361.     pop    ax
  362.     ret
  363.  
  364.  
  365. _aheada::            ;Ahead Systems Ver A
  366.     push    ax
  367.     push    dx
  368.     push    cx
  369.     cli
  370.     mov    OSEG[curbk],ax
  371.     mov    ch,al
  372.     mov    dx,3ceh        ;Enable extended registers
  373.     mov    ax,200fh
  374.     out    dx,ax
  375.     mov    dl,0cch        ;bit 0
  376.     in    al,dx
  377.     mov    dl,0c2h
  378.     and    al,11011111b
  379.     shr    ch,1
  380.     jnc    skpa
  381.     or    al,00100000b
  382. skpa:    out    dx,al
  383.     mov    dl,0cfh        ;bits 1,2,3
  384.     mov    al,0
  385.     out    dx,al
  386.     inc    dx
  387.     in    al,dx
  388.     dec    dx
  389.     and    al,11111000b
  390.     or    al,ch
  391.     mov    ah,al
  392.     mov    al,0
  393.     out    dx,ax
  394.     sti
  395.     pop    cx
  396.     pop    dx
  397.     pop    ax
  398.     ret
  399.  
  400.  
  401. _aheadb::            ;Ahead Systems Ver A
  402.     push    ax
  403.     push    dx
  404.     push    cx
  405.     cli
  406.     mov    OSEG[curbk],ax
  407.     mov    ch,al
  408.     mov    dx,3ceh        ;Enable extended registers
  409.     mov    ax,200fh
  410.     out    dx,ax
  411.     mov    ah,ch
  412.     mov    cl,4
  413.     shl    ah,cl
  414.     or    ah,ch
  415.     mov    al,0dh
  416.     out    dx,ax
  417.     sti
  418.     pop    cx
  419.     pop    dx
  420.     pop    ax
  421.     ret
  422.  
  423.  
  424. _oaktech::            ;Oak Technology Inc OTI-067 and OTI-077
  425.     push    ax
  426.     push    dx
  427.     cli
  428.     mov    OSEG[curbk],ax
  429.     and    al,15
  430.     mov    ah,al
  431.     shl    al,1
  432.     shl    al,1
  433.     shl    al,1
  434.     shl    al,1
  435.     or    ah,al
  436.     mov    al,11h
  437.     mov    dx,3deh
  438.     out    dx,ax
  439.     sti
  440.     pop    dx
  441.     pop    ax
  442.     ret
  443.  
  444. _genoa::            ;GENOA GVGA
  445.     push    ax
  446.     push    dx
  447.     cli
  448.     mov    OSEG[curbk],ax
  449.     mov    ah,al
  450.     shl    al,1
  451.     shl    al,1
  452.     shl    al,1
  453.     or    ah,al
  454.     mov    al,6
  455.     or    ah,40h
  456.     mov    dx,3c4h
  457.     out    dx,ax
  458.     sti
  459.     pop    dx
  460.     pop    ax
  461.     ret
  462.  
  463. _ncr::                ;NCR 77C22E
  464.     push    ax
  465.     push    dx
  466.     cli
  467.     mov    OSEG[curbk],ax
  468.     mov    ah,al
  469.     mov    al,18h
  470.     mov    dx,3c4h
  471.     out    dx,ax
  472.     mov    ax,19h
  473.     out    dx,ax
  474.     sti
  475.     pop    dx
  476.     pop    ax
  477.     ret
  478.  
  479. _compaq::            ;Compaq
  480.     push    ax
  481.     push    dx
  482.     push    ax
  483.     cli
  484.     mov    OSEG[curbk],ax
  485.     mov    dx,3ceh
  486.     mov    ax,50fh        ;unlock extended registers
  487.     out    dx,ax
  488.     pop    ax
  489.     mov    ah,al
  490.     mov    al,45h
  491.     out    dx,ax
  492.     sti
  493.     pop    dx
  494.     pop    ax
  495.     ret
  496.  
  497. _vesa::                ;Vesa SVGA interface
  498.     push    ax
  499.     push    bx
  500.     push    dx
  501.     cli
  502.     mov    OSEG[curbk],ax
  503.     mov    dx,ax
  504.     xor    bx,bx
  505.     call    dword ptr OSEG[vesafunc]
  506.     mov    dx,OSEG[curbk]
  507.     mov    bx,1
  508.     call    dword ptr OSEG[vesafunc]
  509.     sti
  510.     pop    dx
  511.     pop    bx
  512.     pop    ax
  513.     ret
  514.  
  515. _nobank::
  516.     cli
  517.     mov    OSEG[curbk],ax
  518.     sti
  519.     ret
  520.  
  521. newbank    endp
  522.  
  523. bkadr    macro    func
  524.     mov    [func],1
  525.     mov    word ptr [bankadr],offset _&func
  526. if @Codesize
  527.     mov    word ptr [bankadr+2],seg _&func
  528. endif
  529.     endm
  530.  
  531. nojmp    macro
  532.     local    lbl
  533.     jmp    lbl
  534. lbl:
  535.     endm
  536.  
  537. dummyvesa proc    far
  538.     ret
  539. dummyvesa endp
  540.  
  541. whichvga proc    uses si di es
  542.     local    vesabuf[512]:byte    ; extra large to make up for
  543.                     ; bugs in some VESA VBE's
  544.  
  545.     cmp    [first],'FI'
  546.     jnz    gotest
  547.     mov    ax,[retval]
  548.     ret
  549. gotest:    mov    word ptr [bankadr],offset _nobank
  550. if @Codesize
  551.     mov    word ptr [bankadr+2],seg _nobank
  552. endif
  553.     mov    [vgamem],256
  554.     mov    [bksize],64
  555.     xor    ax,ax
  556.     mov    [curbk],ax
  557.     mov    [cirrus],ax
  558.     mov    [everex],ax
  559.     mov    [paradise],ax
  560.     mov    [tseng],ax
  561.     mov    [trident],ax
  562.     mov    [t8900],ax
  563.     mov    [ativga],ax
  564.     mov    [aheada],ax
  565.     mov    [aheadb],ax
  566.     mov    [oaktech],ax
  567.     mov    [video7],ax
  568.     mov    [chipstech],ax
  569.     mov    [tseng4],ax
  570.     mov    [genoa],ax
  571.     mov    [ncr],ax
  572.     mov    [compaq],ax
  573.     mov    [vesa],ax
  574.     mov    [dactype],ax
  575.     mov    [first],'FI'
  576.  
  577.     cmp    [nosvga],0        ;if true abort all SVGA detect code
  578.     jz    oksvga
  579.     mov    [retval],ax        ;always return zero for no SVGA
  580.     ret
  581.  
  582. oksvga:    mov    si,1            ;flag for SVGA found
  583.  
  584.     cmp    [novesa],0
  585.     jz    chkvesa
  586.     jmp    nonvesa
  587. chkvesa:
  588.     mov    ax,ss
  589.     mov    es,ax
  590.     lea    di,vesabuf[0]
  591.     mov    ax,4f00h
  592.     int    10h
  593.     cmp    ax,4fh
  594.     jnz    nonvesa
  595.     mov    [bksize],64        ; (for now)
  596.     mov    [vesafunc],offset dummyvesa
  597.     mov    [vesafunc+2],cs
  598.     bkadr    vesa
  599.     mov    si,offset vesamodes
  600.     cld
  601. vesalp:    lodsw
  602.     mov    cx,ax
  603.     jcxz    endvesa
  604.     mov    ax,ss
  605.     mov    es,ax
  606.     lea    di,vesabuf[0]
  607.     mov    ax,4f01h        ;is mode available?
  608.     int    10h
  609.     or    ah,ah
  610.     jnz    notmode
  611.     test    byte ptr es:[di],1
  612.     jz    notmode            ;if mode not available skip mem size
  613.     lodsw
  614.     mov    cx,ax
  615.     lodsw
  616.     mov    bx,ax
  617.     lodsw
  618.     mul    cx            ;multiple by bits per pixel
  619.     shr    dx,1            ;shift right 3 times to get # of bytes
  620.     rcr    ax,1
  621.     shr    dx,1
  622.     rcr    ax,1
  623.     shr    dx,1
  624.     rcr    ax,1
  625.     mul    bx            ;multiply by number of scanlines
  626.     mov    bx,1024
  627.     add    ax,bx            ;round up to nearest kilobyte
  628.     dec    ax
  629.     adc    dx,0
  630.     div    bx
  631.     cmp    ax,[vgamem]        ;if mode requires more memory
  632.     jbe    vesalp
  633.     mov    [vgamem],ax        ;increase amount of vga memory
  634.     mov    ax,vesabuf.vesamode.WinSize
  635.     mov    [bksize],ax
  636.     jmp    short vesalp
  637. notmode:
  638.     add    si,6            ;skip to next mode in list
  639.     jmp    short vesalp
  640. endvesa:
  641.     mov    ax,[vgamem]
  642.     inc    ah
  643.     dec    ax
  644.     mov    al,0            ;round up to nearest 256k
  645.     cmp    ax,1024
  646.     jb    nomegs
  647.     add    ax,1023            ;round up to nearest megabyte
  648.     and    ax,not 1023
  649. nomegs:    mov    [vgamem],ax
  650.  
  651. nonvesa:
  652.     cmp    [justvesa],0
  653.     jz    nofini
  654.     jmp    fini            ;disable other tests if VESA VBE found
  655.  
  656. nofini:    mov    ax,0c000h        ;ATI VGA detect (largely from ATI example code)
  657.     mov    es,ax
  658.     cmp    word ptr es:[40h],'13'    ;ATI Signiture on the Video BIOS
  659.     jnz    noati
  660.     bkadr    ativga
  661.     mov    [bksize],64        ; 64k bank size
  662.     mov    dx,es:[10h]        ; Get value of ATI extended register
  663.     mov    bl,es:[43h]        ; Get value of ATI chip version
  664.     cmp    bl,'3'
  665.     jae    v6up            ; Use different method to determine
  666.     mov    al,0bbh         ; memory size of chip version is 3 or higher
  667.     cli
  668.     out    dx,al
  669.     inc    dx
  670.     in    al,dx            ; Get ramsize byte for chip versions 1 & 2
  671.     sti
  672.     test    al,20h
  673.     jz    no512
  674.     mov    [vgamem],512
  675.     jmp    short no512
  676.  
  677. v6up:    mov    al,0b0h            ; Method used for newer ATI chip versions
  678.     cli
  679.     out    dx,al
  680.     inc    dx
  681.     in    al,dx            ; Get ramsize byte for versions 3-5
  682.     sti
  683.     test    al,10h            ; Check if ramsize byte indicates 256K or 512K bytes
  684.     jz    v7up
  685.     mov    [vgamem],512
  686. v7up:    cmp    bl,'4'            ; Check for ramsize for ATI chip versions 4 & 5
  687.     jb    no512
  688.     test    al,8            ; Check if version 5 ATI chip has 1024K
  689.     jz    no512
  690.     mov    [vgamem],1024
  691. no512:    jmp    fini
  692.  
  693. noati:    mov    ax,7000h        ;Test for Everex
  694.     xor    bx,bx
  695.     cld
  696.     int    10h
  697.     cmp    al,70h
  698.     jnz    noev
  699.     bkadr    everex
  700.     mov    [bksize],64        ; 64k bank size
  701.     and    ch,11000000b        ;how much memory on board
  702.     jz    skp
  703.     mov    [vgamem],512
  704. skp:                    ;fall through for Everex boards using Trident or Tseng4000
  705.  
  706. noev:    mov    ax,0bf03h        ;Test for Compaq
  707.     xor    bx,bx
  708.     mov    cx,bx
  709.     int    10h
  710.     cmp    ax,0bf03h
  711.     jnz    nocp
  712.     test    cl,40h            ;is 640x480x256 available?
  713.     jz    nocp
  714.     bkadr    compaq
  715.     mov    [bksize],4        ; 4k bank size
  716.     mov    [vgamem],512
  717.     jmp    fini
  718.  
  719. nocp:    mov    dx,3c4h            ;Test for NCR 77C22E
  720.     mov    ax,0ff05h
  721.     call    _isport2
  722.     jnz    noncr
  723.     mov    ax,5            ;Disable extended registers
  724.     out    dx,ax
  725.     mov    ax,0ff10h        ;Try to write to extended register 10
  726.     call    _isport2        ;If it writes then not NCR
  727.     jz    noncr
  728.     mov    ax,105h            ;Enable extended registers
  729.     out    dx,ax
  730.     mov    ax,0ff10h
  731.     call    _isport2
  732.     jnz    noncr            ;If it does NOT write then not NCR
  733.     bkadr    ncr
  734.     mov    [bksize],16        ; 16k bank size
  735.     mov    [vgamem],512
  736.     jmp    fini
  737.  
  738. noncr:    mov    dx,3c4h            ;Test for Trident
  739.     mov    al,0bh
  740.     out    dx,al
  741.     inc    dl
  742.     in    al,dx
  743.     and    al,0fh
  744.     cmp    al,06h
  745.     ja    notri
  746.     cmp    al,2
  747.     jb    notri
  748.     bkadr    trident
  749.     mov    [bksize],64        ; 64k bank size
  750.     cmp    al,3
  751.     jb    no89
  752.     mov    [t8900],1
  753.     mov    dx,3d4h
  754.     mov    al,1fh
  755.     out    dx,al
  756.     inc    dx
  757.     in    al,dx
  758.     and    ax,3
  759.     inc    al
  760.     xchg    al,ah
  761.     mov    [vgamem],ax
  762.     jmp    fini
  763.  
  764. no89:    mov    [vgamem],512
  765.     jmp    fini
  766.  
  767. notri:    mov    ax,6f00h        ;Test for Video 7
  768.     xor    bx,bx
  769.     cld
  770.     int    10h
  771.     cmp    bx,'V7'
  772.     jnz    nov7
  773.     bkadr    video7
  774.     mov    [bksize],64        ; 64k bank size
  775.     mov    ax,6f07h
  776.     cld
  777.     int    10h
  778.     and    ah,7fh
  779.     cmp    ah,1
  780.     jbe    skp2
  781.     mov    [vgamem],512
  782. skp2:    cmp    ah,3
  783.     jbe    skp3
  784.     mov    [vgamem],1024
  785. skp3:    jmp    fini
  786.  
  787. nov7:    mov    dx,3d4h            ;Test for GENOA GVGA
  788.     mov    al,2eh            ;check for Herchi Register top 6 bits
  789.     out    dx,al
  790.     inc    dx
  791.     in    al,dx
  792.     dec    dx
  793.     test    al,11111100b        ;top 6 bits should be zero
  794.     jnz    nogn
  795.     mov    ax,032eh        ;check for Herchi Register
  796.     call    _isport2
  797.     jnz    nogn
  798.     mov    dx,3c4h
  799.     mov    al,7
  800.     out    dx,al
  801.     inc    dx
  802.     in    al,dx
  803.     dec    dx
  804.     test    al,10001000b
  805.     jnz    nogn
  806.     mov    al,10h
  807.     out    dx,al
  808.     inc    dx
  809.     in    al,dx
  810.     dec    dx
  811.     and    al,00110000b
  812.     cmp    al,00100000b
  813.     jnz    nogn
  814.     mov    dx,3ceh
  815.     mov    ax,0ff0bh
  816.     call    _isport2
  817.     jnz    nogn
  818.     mov    dx,3c4h            ;check for memory segment register
  819.     mov    ax,3f06h
  820.     call    _isport2
  821.     jnz    nogn
  822.     mov    dx,3ceh
  823.     mov    ax,0ff0ah
  824.     call    _isport2
  825.     jnz    nogn
  826.     bkadr    genoa
  827.     mov    [bksize],64        ; 64k bank size
  828.     mov    [vgamem],512
  829.     jmp    fini
  830.  
  831. nogn:    call    _cirrus            ;Test for Cirrus
  832.     cmp    [cirrus],0
  833.     je    noci
  834.     jmp    fini
  835.  
  836. noci:    mov    dx,3ceh            ;Test for Paradise
  837.     mov    al,9            ;check Bank switch register
  838.     out    dx,al
  839.     inc    dx
  840.     in    al,dx
  841.     dec    dx
  842.     or    al,al
  843.     jnz    nopd
  844.  
  845.     mov    ax,50fh            ;turn off write protect on VGA registers
  846.     out    dx,ax
  847.     mov    dx,offset _paradise
  848.     mov    cx,1
  849.     call    _chkbk
  850.     jc    nopd            ;if bank 0 and 1 same not paradise
  851.     bkadr    paradise
  852.     mov    [bksize],4        ; 4k bank size
  853.     mov    dx,3ceh
  854.     mov    al,0bh            ;512k detect from Bob Berry
  855.     out    dx,al
  856.     inc    dx
  857.     in    al,dx
  858.     test    al,80h            ;if top bit set then 512k
  859.     jz    nop512
  860.     test    al,40h
  861.     jz    nop1024
  862.     mov    [vgamem],1024
  863.     jmp    fini
  864. nop1024:
  865.     mov    [vgamem],512
  866. nop512:    jmp    fini
  867.  
  868. nopd:    mov    ax,5f00h        ;Test for Chips & Tech
  869.     xor    bx,bx
  870.     cld
  871.     int    10h
  872.     cmp    al,5fh
  873.     jnz    noct
  874.     bkadr    chipstech
  875.     mov    [bksize],16        ; 16k bank size
  876.     cmp    bh,1
  877.     jb    skp4
  878.     mov    [vgamem],512
  879. skp4:    jmp    fini
  880.  
  881. noct:    mov    dx,3dah            ;Test for Tseng 4000 & 3000
  882.     in    al,dx            ;bit 8 is opposite of bit 4
  883.     mov    ah,al            ;(vertical retrace bit)
  884.     shr    ah,1
  885.     shr    ah,1
  886.     shr    ah,1
  887.     shr    ah,1
  888.     xor    al,ah
  889.     test    al,00001000b
  890.     jz    nots
  891.     mov    dx,3d4h            ;check for Tseng 4000 series
  892.     mov    ax,0f33h
  893.     call    _isport2
  894.     jnz    not4
  895.     mov    ax,0ff33h        ;top 4 bits should not be there
  896.     call    _isport2
  897.     jz    nots
  898.  
  899.     mov    dx,3bfh            ;Enable access to extended registers
  900.     mov    al,3
  901.     out    dx,al
  902.     mov    dx,3d8h
  903.     mov    al,0a0h
  904.     out    dx,al
  905.     mov    al,0ffh
  906.     mov    dx,3cdh            ;test bank switch register
  907.     call    _isport1
  908.     jnz    not4
  909.     bkadr    tseng
  910.     mov    [bksize],64        ; 64k bank size
  911.     mov    ax,10f1h        ;Extended BIOS call to get DAC type on Tseng4000
  912.     int    10h
  913.     cmp    ax,10h
  914.     jnz    nodac
  915.     mov    bh,0
  916.     mov    [dactype],bx
  917. nodac:    mov    dx,3d4h            ;Tseng 4000 memory detect 1meg
  918.     mov    al,37h
  919.     out    dx,al
  920.     inc    dx
  921.     in    al,dx
  922.     test    al,1000b        ;if using 64kx4 RAMs then no more than 256k
  923.     jz    nomem
  924.     and    al,3
  925.     cmp    al,1            ;if 8 bit wide bus then only two 256kx4 RAMs
  926.     jbe    nomem
  927.     mov    [vgamem],512
  928.     cmp    al,2            ;if 16 bit wide bus then four 256kx4 RAMs
  929.     je    nomem
  930.     mov    [vgamem],1024        ;full meg with eight 256kx4 RAMs
  931. nomem:    bkadr    tseng4
  932.     mov    [bksize],64        ; 64k bank size
  933.     jmp    fini
  934.  
  935. not4:    mov    dx,3d4h            ;Test for Tseng 3000
  936.     mov    ax,1f25h        ;is the Overflow High register there?
  937.     call    _isport2
  938.     jnz    nots
  939.     mov    al,03fh            ;bottom six bits only
  940.     mov    dx,3cdh            ;test bank switch register
  941.     call    _isport1
  942.     jnz    nots
  943.     bkadr    tseng
  944.     mov    [bksize],64        ; 64k bank size
  945.     call    _t3memchk
  946.     jmp    fini
  947.  
  948. nots:    mov    dx,3ceh            ;Test for Ahead A or B chipsets
  949.     mov    ax,0ff0fh        ;register should not be fully available
  950.     call    _isport2
  951.     jz    noab
  952.     mov    ax,200fh
  953.     out    dx,ax
  954.     inc    dx
  955.     nojmp
  956.     in    al,dx
  957.     cmp    al,21h
  958.     jz    verb
  959.     cmp    al,20h
  960.     jnz    noab
  961.     bkadr    aheada
  962.     mov    [bksize],64        ; 64k bank size
  963.     mov    [vgamem],512
  964.     jmp    fini
  965.  
  966. verb:    bkadr    aheadb
  967.     mov    [bksize],64        ; 64k bank size
  968.     mov    [vgamem],512
  969.     jmp    fini
  970.  
  971. noab:    mov    dx,3c4h            ;Test for AcuMos chipsets
  972.     mov    ax,0006h        ;disable extended registers
  973.     out    dx,ax
  974.     mov    ax,0ff09h
  975.     call    _isport2        ;is scratchpad at index 9 writeable ?
  976.     jz    noacu
  977.     mov    ax,0ff0ah
  978.     call    _isport2        ;is scratchpad at index 10 writable ?
  979.     jz    noacu
  980.     mov    ax,1206h
  981.     out    dx,ax
  982.     mov    ax,0ff09h
  983.     call    _isport2
  984.     jnz    noacu
  985.     mov    ax,0ff0ah
  986.     call    _isport2
  987.     jnz    noacu
  988.     mov    dx,offset _acumos
  989.     mov    cx,1
  990.     call    _chkbk
  991.     jc    noacu            ;if bank 0 and 1 same not acumos
  992.     bkadr    acumos
  993.     mov    [bksize],4        ; 4k bank size
  994.     mov    dx,3c4h
  995.     mov    al,0ah
  996.     out    dx,al
  997.     inc    dx
  998.     in    al,dx            ;get scratchpad index 10
  999.     and    al,3
  1000.     cmp    al,1
  1001.     jb    noamem
  1002.     mov    [vgamem],512
  1003.     cmp    al,2
  1004.     jb    noamem
  1005.     mov    [vgamem],1024
  1006.     cmp    al,3
  1007.     jb    noamem
  1008.     mov    [vgamem],2048
  1009. noamem:    jmp    short fini
  1010.  
  1011. noacu:    mov    dx,3deh            ;Test for Oak Technology Inc OTI-067 and OTI-077
  1012.     mov    ax,07711h        ;look for bank switch register
  1013.     call    _isport2
  1014.     jnz    nooak
  1015.     mov    al,1ah            ;Check from Oak's VESA VBE
  1016.     out    dx,al            ;researched by Rick Gould
  1017.     in    al,dx
  1018.     cmp    al,5ah
  1019.     jz    okoak
  1020.     cmp    al,7ah
  1021.     jnz    nooak
  1022. okoak:    bkadr    oaktech
  1023.     mov    [bksize],64        ; 64k bank size
  1024.     mov    al,0dh
  1025.     out    dx,al
  1026.     inc    dx
  1027.     nojmp
  1028.     in    al,dx
  1029.     test    al,11000000b
  1030.     jz    no4ram
  1031.     mov    [vgamem],512
  1032.     test    al,01000000b
  1033.     jz    no4ram
  1034.     mov    [vgamem],1024
  1035. no4ram:    jmp    short fini
  1036.  
  1037. nooak:
  1038.     mov    si,0
  1039.  
  1040. fini:    cmp    [vesa],0
  1041.     jz    novbank
  1042.     bkadr    vesa            ; Always use VESA bank switch
  1043.                     ; even if we have detected chipset
  1044. novbank:
  1045.     mov    ax,si
  1046.     mov    [retval],ax
  1047.     ret
  1048. whichvga endp
  1049.  
  1050.  
  1051. ;Segment to access video buffer (based on GR[6])
  1052. buftbl    dw    0A000h,0A000h,0B000h,0B800h
  1053.  
  1054. _t3memchk proc                ;[Charles Marslett -- ET3000 memory ck]
  1055.     mov    dx,3dah
  1056.     in    al,dx            ;Reset the attribute flop (read 0x3DA)
  1057.     mov    dx,03c0h
  1058.     mov    al,36h
  1059.     out    dx,al
  1060.     inc    dx
  1061.     in    al,dx            ;Save contents of ATTR[0x16]
  1062.     push    ax
  1063.     or    al,10h
  1064.     dec    dx
  1065.     out    dx,al
  1066.     mov    dx,3ceh            ;Find the RAM buffer...
  1067.     mov    al,6
  1068.     out    dx,al
  1069.     inc    dx
  1070.     in    al,dx
  1071.     and    ax,000Ch
  1072.     shr    ax,1
  1073.  
  1074.     mov    bx,ax
  1075.     push    es
  1076.     mov    es,cs:buftbl[bx]
  1077.     mov    ax,09C65h
  1078.     mov    bx,1
  1079.     mov    es:[bx],ax
  1080.     mov    es:[bx+2],ax
  1081.     inc    bx
  1082.     mov    ax,es:[bx]
  1083.     pop    es
  1084.     cmp    ax,0659Ch
  1085.     jne    et3k_256
  1086.     mov    [vgamem],512
  1087. et3k_256:
  1088.     mov    dx,3c0h
  1089.     mov    al,36h
  1090.     out    dx,al
  1091.     pop    ax
  1092.     out    dx,al            ;Restore ATTR[16h]
  1093.     ret
  1094. _t3memchk endp
  1095.  
  1096. _cirrus    proc    near
  1097.     mov    dx,3d4h        ; assume 3dx addressing
  1098.     mov    al,0ch        ; screen a start address hi
  1099.     out    dx,al        ; select index
  1100.     inc    dx        ; point to data
  1101.     mov    ah,al        ; save index in ah
  1102.     in    al,dx        ; get screen a start address hi
  1103.     xchg    ah,al        ; swap index and data
  1104.     push    ax        ; save old value
  1105.     push    dx        ; save crtc address
  1106.     xor    al,al        ; clear crc
  1107.     out    dx,al        ; and out to the crtc
  1108.  
  1109.     mov    al,1fh        ; Eagle ID register
  1110.     dec    dx        ; back to index
  1111.     out    dx,al        ; select index
  1112.     inc    dx        ; point to data
  1113.     in    al,dx        ; read the id register
  1114.     mov    bh,al        ; and save it in bh
  1115.  
  1116.     mov    cl,4        ; nibble swap rotate count
  1117.     mov    dx,3c4h        ; sequencer/extensions
  1118.     mov    bl,6        ; extensions enable register
  1119.  
  1120.     ror    bh,cl        ; compute extensions disable value
  1121.     mov    ax,bx        ; extensions disable
  1122.     out    dx,ax        ; disable extensions
  1123.     inc    dx        ; point to data
  1124.     in    al,dx        ; read enable flag
  1125.     or    al,al        ; disabled ?
  1126.     jnz    exit        ; nope, not an cirrus
  1127.  
  1128.     ror    bh,cl        ; compute extensions enable value
  1129.     dec    dx        ; point to index
  1130.     mov    ax,bx        ; extensions enable
  1131.     out    dx,ax        ; enable extensions
  1132.     inc    dx        ; point to data
  1133.     in    al,dx        ; read enable flag
  1134.     cmp    al,1        ; enabled ?
  1135.     jne    exit        ; nope, not an cirrus
  1136.     mov    [cirrus],1
  1137.     mov    word ptr [bankadr],offset _nobank
  1138. if @Codesize
  1139.     mov    word ptr [bankadr+2],seg _nobank
  1140. endif
  1141. exit:    pop    dx        ; restore crtc address
  1142.     dec    dx        ; point to index
  1143.     pop    ax        ; recover crc index and data
  1144.     out    dx,ax        ; restore crc value
  1145.     ret
  1146. _cirrus    endp
  1147.  
  1148. _chkbk    proc    near        ;bank switch check routine
  1149.     mov    di,0b800h
  1150.     mov    es,di
  1151.     xor    di,di
  1152.     mov    bx,1234h
  1153.     call    _gochk
  1154.     jnz    badchk
  1155.     mov    bx,4321h
  1156.     call    _gochk
  1157.     jnz    badchk
  1158.     clc
  1159.     ret
  1160. badchk:    stc
  1161.     ret
  1162. _chkbk    endp
  1163.  
  1164. calldx    macro
  1165. if @Codesize
  1166.     push    cs
  1167. endif
  1168.     call    dx
  1169.     endm
  1170.  
  1171. _gochk    proc    near
  1172.     push    si
  1173.     mov    si,bx
  1174.  
  1175.     mov    al,cl
  1176.     calldx
  1177.     xchg    bl,es:[di]
  1178.     mov    al,ch
  1179.     calldx
  1180.     xchg    bh,es:[di]
  1181.  
  1182.     xchg    si,bx
  1183.  
  1184.     mov    al,cl
  1185.     calldx
  1186.     xor    bl,es:[di]
  1187.     mov    al,ch
  1188.     calldx
  1189.     xor    bh,es:[di]
  1190.  
  1191.     xchg    si,bx
  1192.  
  1193.     mov    al,ch
  1194.     calldx
  1195.     mov    es:[di],bh
  1196.     mov    al,cl
  1197.     calldx
  1198.     mov    es:[di],bl
  1199.  
  1200.     mov    al,0
  1201.     calldx
  1202.     or    si,si
  1203.     pop    si
  1204.     ret
  1205. _gochk    endp
  1206.  
  1207. _isport2 proc    near        ;check for valid indexed i/o port, al is index, ah is bit mask
  1208.     push    bx
  1209.     mov    bx,ax
  1210.     out    dx,al
  1211.     mov    ah,al
  1212.     inc    dx
  1213.     in    al,dx
  1214.     dec    dx
  1215.     xchg    al,ah
  1216.     push    ax
  1217.     mov    ax,bx
  1218.     out    dx,ax
  1219.     out    dx,al
  1220.     mov    ah,al
  1221.     inc    dx
  1222.     in    al,dx
  1223.     dec    dx
  1224.     and    al,bh
  1225.     cmp    al,bh
  1226.     jnz    noport
  1227.     mov    al,ah
  1228.     mov    ah,0
  1229.     out    dx,ax
  1230.     out    dx,al
  1231.     mov    ah,al
  1232.     inc    dx
  1233.     in    al,dx
  1234.     dec    dx
  1235.     and    al,bh
  1236.     cmp    al,0
  1237. noport:    pop    ax
  1238.     out    dx,ax
  1239.     pop    bx
  1240.     ret
  1241. _isport2 endp
  1242.  
  1243. _isport1 proc    near        ;check for valid i/o port, al is bit mask
  1244.     mov    ah,al
  1245.     in    al,dx
  1246.     push    ax
  1247.     mov    al,ah
  1248.     out    dx,al
  1249.     in    al,dx
  1250.     and    al,ah
  1251.     cmp    al,ah
  1252.     jnz    noport
  1253.     mov    al,0
  1254.     out    dx,al
  1255.     in    al,dx
  1256.     and    al,ah
  1257.     cmp    al,0
  1258. noport:    pop    ax
  1259.     out    dx,al
  1260.     ret
  1261. _isport1 endp
  1262.  
  1263.     end
  1264.  
  1265.