home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / compresn / dvpeg / src / banks.asm < prev    next >
Encoding:
Assembly Source File  |  1992-05-04  |  15.7 KB  |  1,072 lines

  1.  
  2.     include    model.h
  3.  
  4. ;
  5. ;    VGAKIT Version 4.1
  6. ;
  7. ;    Copyright 1988,89,90,91 John Bridges
  8. ;    Free for use in commercial, shareware or freeware applications
  9. ;
  10. ;    BANKS.ASM
  11. ;
  12. .data
  13.  
  14. OSEG    equ    DS:        ;segment override for variable access
  15.  
  16. bankadr    dw    ?
  17. if @Codesize
  18. bankseg    dw    ?
  19. endif
  20.  
  21.     public    curbk
  22.  
  23. curbk    dw    ?
  24.  
  25.     public    vga512,vga1024
  26.  
  27. vga512    dw    ?
  28. vga1024    dw    ?
  29.  
  30.     public    cirrus,everex,paradise,tseng,trident,t8900
  31.     public    ativga,aheada,aheadb,oaktech,video7
  32.     public    chipstech,tseng4,genoa,ncr,compaq,vesa
  33.  
  34. cirrus    dw    ?
  35. everex    dw    ?
  36. paradise dw    ?
  37. tseng        dw    ?
  38. trident    dw    ?
  39. t8900        dw    ?
  40. ativga    dw    ?
  41. aheada    dw    ?
  42. aheadb    dw    ?
  43. oaktech    dw    ?
  44. video7    dw    ?
  45. chipstech dw    ?
  46. tseng4    dw    ?
  47. genoa        dw    ?
  48. ncr        dw    ?
  49. compaq    dw    ?
  50. vesa        dw    ?
  51.  
  52. first        dw    ?        ;flag so whichvga() is only called once
  53. retval    dw    ?        ;first return value from whichvga()
  54.  
  55. vgainfo    label    word
  56. vesaid    db    'VESA'        ; 4 signature bytes
  57. vesaver    dw    ?        ; VESA version number
  58. oemstr    dd    ?        ; Pointer to OEM string
  59. capabil    db    4 dup (?)    ; Capabilities of the video environment
  60. modelst    dd    ?        ; Pointer to supported Super VGA modes
  61.  
  62. vesashift db    0        ; number of bits to shift bank number left
  63.  
  64. .code
  65.  
  66.     public    newbank
  67.     public    whichvga
  68.     public    forcevga
  69.  
  70. newbank    proc            ;bank number is in AX
  71.     cli
  72.     mov    OSEG[curbk],ax
  73. if @Codesize
  74.     jmp    dword ptr OSEG[bankadr]
  75. else
  76.     jmp    word ptr OSEG[bankadr]
  77. endif
  78.  
  79.  
  80. _tseng:                ;Tseng
  81.     push    ax
  82.     push    dx
  83.     and    al,7
  84.     mov    ah,al
  85.     shl    al,1
  86.     shl    al,1
  87.     shl    al,1
  88.     or    al,ah
  89.     or    al,01000000b
  90.     mov    dx,3cdh
  91.     out    dx,al
  92.     sti
  93.     pop    dx
  94.     pop    ax
  95.     ret
  96.  
  97.  
  98. _tseng4:                ;Tseng 4000 series
  99.     push    ax
  100.     push    dx
  101.     mov    ah,al
  102.     mov    dx,3bfh            ;Enable access to extended registers
  103.     mov    al,3
  104.     out    dx,al
  105.     mov    dl,0d8h
  106.     mov    al,0a0h
  107.     out    dx,al
  108.     and    ah,15
  109.     mov    al,ah
  110.     shl    al,1
  111.     shl    al,1
  112.     shl    al,1
  113.     shl    al,1
  114.     or    al,ah
  115.     mov    dl,0cdh
  116.     out    dx,al
  117.     sti
  118.     pop    dx
  119.     pop    ax
  120.     ret
  121.  
  122.  
  123. _trident:            ;Trident
  124.     push    ax
  125.     push    dx
  126.     mov    dx,3ceh        ;set pagesize to 64k
  127.     mov    al,6
  128.     out    dx,al
  129.     inc    dl
  130.     in    al,dx
  131.     dec    dl
  132.     or    al,4
  133.     mov    ah,al
  134.     mov    al,6
  135.     out    dx,ax
  136.  
  137.     mov    dl,0c4h        ;switch to BPS mode
  138.     mov    al,0bh
  139.     out    dx,al
  140.     inc    dl
  141.     in    al,dx
  142.     dec    dl
  143.  
  144.     mov    ah,byte ptr OSEG[curbk]
  145.     xor    ah,2
  146.     mov    dx,3c4h
  147.     mov    al,0eh
  148.     out    dx,ax
  149.     sti
  150.     pop    dx
  151.     pop    ax
  152.     ret
  153.  
  154.  
  155. _video7:            ;Video 7
  156.     push    ax
  157.     push    dx
  158.     push    cx
  159.     and    ax,15
  160.     mov    ch,al
  161.     mov    dx,3c4h
  162.     mov    ax,0ea06h
  163.     out    dx,ax
  164.     mov    ah,ch
  165.     and    ah,1
  166.     mov    al,0f9h
  167.     out    dx,ax
  168.     mov    al,ch
  169.     and    al,1100b
  170.     mov    ah,al
  171.     shr    ah,1
  172.     shr    ah,1
  173.     or    ah,al
  174.     mov    al,0f6h
  175.     out    dx,al
  176.     inc    dx
  177.     in    al,dx
  178.     dec    dx
  179.     and    al,not 1111b
  180.     or    ah,al
  181.     mov    al,0f6h
  182.     out    dx,ax
  183.     mov    ah,ch
  184.     mov    cl,4
  185.     shl    ah,cl
  186.     and    ah,100000b
  187.     mov    dl,0cch
  188.     in    al,dx
  189.     mov    dl,0c2h
  190.     and    al,not 100000b
  191.     or    al,ah
  192.     out    dx,al
  193.     sti
  194.     pop    cx
  195.     pop    dx
  196.     pop    ax
  197.     ret
  198.  
  199.  
  200. _paradise:            ;Paradise
  201.     push    ax
  202.     push    dx
  203.     mov    dx,3ceh
  204.     mov    ax,50fh        ;turn off write protect on VGA registers
  205.     out    dx,ax
  206.     mov    ah,byte ptr OSEG[curbk]
  207.     shl    ah,1        ;change 64k bank number into 4k bank number
  208.     shl    ah,1
  209.     shl    ah,1
  210.     shl    ah,1
  211.     mov    al,9
  212.     out    dx,ax
  213.     sti
  214.     pop    dx
  215.     pop    ax
  216.     ret
  217.  
  218.  
  219. _chipstech:            ;Chips & Tech
  220.     push    ax
  221.     push    dx
  222.     mov    dx,46e8h    ;place chip in setup mode
  223.     mov    ax,1eh
  224.     out    dx,ax
  225.     mov    dx,103h        ;enable extended registers
  226.     mov    ax,0080h
  227.     out    dx,ax
  228.     mov    dx,46e8h    ;bring chip out of setup mode
  229.     mov    ax,0eh
  230.     out    dx,ax
  231.     mov    ah,byte ptr OSEG[curbk]
  232.     shl    ah,1        ;change 64k bank number into 16k bank number
  233.     shl    ah,1
  234.     mov    al,10h
  235.     mov    dx,3d6h
  236.     out    dx,ax
  237.     sti
  238.     pop    dx
  239.     pop    ax
  240.     ret
  241.  
  242.  
  243. _ativga:            ;ATI VGA Wonder
  244.     push    ax
  245.     push    dx
  246.     mov    ah,al
  247.     mov    dx,1ceh
  248.     mov    al,0b2h
  249.     out    dx,al
  250.     inc    dl
  251.     in    al,dx
  252.     shl    ah,1
  253.     and    al,0e1h
  254.     or    ah,al
  255.     mov    al,0b2h
  256.     dec    dl
  257.     out    dx,ax
  258.     sti
  259.     pop    dx
  260.     pop    ax
  261.     ret
  262.  
  263.  
  264. _everex:            ;Everex
  265.     push    ax
  266.     push    dx
  267.     push    cx
  268.     mov    cl,al
  269.     mov    dx,3c4h
  270.     mov    al,8
  271.     out    dx,al
  272.     inc    dl
  273.     in    al,dx
  274.     dec    dl
  275.     shl    al,1
  276.     shr    cl,1
  277.     rcr    al,1
  278.     mov    ah,al
  279.     mov    al,8
  280.     out    dx,ax
  281.     mov    dl,0cch
  282.     in    al,dx
  283.     mov    dl,0c2h
  284.     and    al,0dfh
  285.     shr    cl,1
  286.     jc    nob2
  287.     or    al,20h
  288. nob2:    out    dx,al
  289.     sti
  290.     pop    cx
  291.     pop    dx
  292.     pop    ax
  293.     ret
  294.  
  295.  
  296. _aheada:            ;Ahead Systems Ver A
  297.     push    ax
  298.     push    dx
  299.     push    cx
  300.     mov    ch,al
  301.     mov    dx,3ceh        ;Enable extended registers
  302.     mov    ax,200fh
  303.     out    dx,ax
  304.     mov    dl,0cch        ;bit 0
  305.     in    al,dx
  306.     mov    dl,0c2h
  307.     and    al,11011111b
  308.     shr    ch,1
  309.     jnc    skpa
  310.     or    al,00100000b
  311. skpa:    out    dx,al
  312.     mov    dl,0cfh        ;bits 1,2,3
  313.     mov    al,0
  314.     out    dx,al
  315.     inc    dx
  316.     in    al,dx
  317.     dec    dx
  318.     and    al,11111000b
  319.     or    al,ch
  320.     mov    ah,al
  321.     mov    al,0
  322.     out    dx,ax
  323.     sti
  324.     pop    cx
  325.     pop    dx
  326.     pop    ax
  327.     ret
  328.  
  329.  
  330. _aheadb:            ;Ahead Systems Ver A
  331.     push    ax
  332.     push    dx
  333.     push    cx
  334.     mov    ch,al
  335.     mov    dx,3ceh        ;Enable extended registers
  336.     mov    ax,200fh
  337.     out    dx,ax
  338.     mov    ah,ch
  339.     mov    cl,4
  340.     shl    ah,cl
  341.     or    ah,ch
  342.     mov    al,0dh
  343.     out    dx,ax
  344.     sti
  345.     pop    cx
  346.     pop    dx
  347.     pop    ax
  348.     ret
  349.  
  350.  
  351. _oaktech:            ;Oak Technology Inc OTI-067
  352.     push    ax
  353.     push    dx
  354.     and    al,15
  355.     mov    ah,al
  356.     shl    al,1
  357.     shl    al,1
  358.     shl    al,1
  359.     shl    al,1
  360.     or    ah,al
  361.     mov    al,11h
  362.     mov    dx,3deh
  363.     out    dx,ax
  364.     sti
  365.     pop    dx
  366.     pop    ax
  367.     ret
  368.  
  369. _genoa:            ;GENOA GVGA
  370.     push    ax
  371.     push    dx
  372.     mov    ah,al
  373.     shl    al,1
  374.     shl    al,1
  375.     shl    al,1
  376.     or    ah,al
  377.     mov    al,6
  378.     or    ah,40h
  379.     mov    dx,3c4h
  380.     out    dx,ax
  381.     sti
  382.     pop    dx
  383.     pop    ax
  384.     ret
  385.  
  386. _ncr:                ;NCR 77C22E
  387.     push    ax
  388.     push    dx
  389.     shl    al,1        ;change 64k bank number into 16k bank number
  390.     shl    al,1
  391.     mov    ah,al
  392.     mov    al,18h
  393.     mov    dx,3c4h
  394.     out    dx,ax
  395.     mov    ax,19h
  396.     out    dx,ax
  397.     sti
  398.     pop    dx
  399.     pop    ax
  400.     ret
  401.  
  402. _compaq:            ;Compaq
  403.     push    ax
  404.     push    dx
  405.     mov    dx,3ceh
  406.     mov    ax,50fh        ;unlock extended registers
  407.     out    dx,ax
  408.     mov    ah,byte ptr OSEG[curbk]
  409.     shl    ah,1        ;change 64k bank number into 4k bank number
  410.     shl    ah,1
  411.     shl    ah,1
  412.     shl    ah,1
  413.     mov    al,45h
  414.     out    dx,ax
  415.     sti
  416.     pop    dx
  417.     pop    ax
  418.     ret
  419.  
  420. _vesa:                ;Vesa SVGA interface
  421.     push    ax
  422.     push    bx
  423.     push    cx
  424.     push    dx
  425.     mov    cl,[vesashift]
  426.     shl    ax,cl
  427.     mov    dx,ax
  428.     xor    bx,bx
  429.     mov    ax,4f05h
  430.     int    10h
  431.     sti
  432.     pop    dx
  433.     pop    cx
  434.     pop    bx
  435.     pop    ax
  436.     ret
  437.  
  438. _nobank:
  439.     sti
  440.     ret
  441.  
  442. newbank    endp
  443.  
  444. bkadr    macro    func
  445.     mov    [func],1
  446.     mov    [bankadr],offset _&func
  447. if @Codesize
  448.     mov    [bankseg],seg _&func
  449. endif
  450.     endm
  451.  
  452. nojmp    macro
  453.     local    lbl
  454.     jmp    lbl
  455. lbl:
  456.     endm
  457.  
  458.  
  459. forcevga proc vid_card:word            ;force video card to one type
  460.  
  461.     mov ax, [vid_card]
  462.  
  463.     mov    [bankadr],offset _nobank    ; default for Cirrus???
  464. if @Codesize
  465.     mov    [bankseg],seg _nobank
  466. endif
  467.  
  468.     cmp    ax, 15
  469.     jnz    no_vesa
  470.     bkadr    vesa
  471.     mov    [vga512],1
  472.     mov    [vga1024],1
  473.     jmp    fini
  474.  
  475. no_vesa:
  476.     cmp    ax, 1
  477.     jnz    no_ati
  478.     bkadr    ativga
  479.     mov    [vga512],1        ; forcing 512k may not exist
  480.     jmp    fini
  481.  
  482. no_ati:        ;Test for Everex
  483.     cmp    ax, 3
  484.     jnz    no_ev
  485.     bkadr    everex
  486.     mov    [vga512],1
  487.     jmp    fini
  488.  
  489. no_ev:            ;Test for Compaq
  490.     cmp    ax, 14
  491.     jnz    no_cp
  492.     bkadr    compaq
  493.     mov    [vga512],1
  494.     jmp    fini
  495.  
  496. no_cp:                ;Test for NCR 77C22E
  497.     cmp    ax, 6
  498.     jnz    non_cr
  499.     bkadr    ncr
  500.     mov    [vga512],1
  501.     jmp    fini
  502.  
  503. non_cr:            ;Test for Trident
  504.     cmp    ax, 8
  505.     jnz    try_8900
  506.     bkadr    trident
  507.     jmp    fini
  508.  
  509. try_8900:                        ; test Trident 8900 assume 1 Meg
  510.     cmp    ax, 9
  511.     jnz    no_tri
  512.     bkadr trident
  513.     mov    [vga1024],1
  514.     jmp    fini
  515.  
  516. no_tri:        ;Test for Video 7
  517.     cmp    ax, 12
  518.     jnz    nov_7
  519.     bkadr    video7
  520.     mov    [vga1024],1
  521.     jmp    fini
  522.  
  523. nov_7:            ;Test for GENOA GVGA
  524.     cmp    ax, 5
  525.     jnz    no_ci
  526.     bkadr    genoa
  527.     mov    [vga512],1
  528.     jmp    fini
  529.  
  530. no_ci:            ;Test for Paradise
  531.     cmp    ax, 7
  532.     jnz    no_pd
  533.     bkadr    paradise
  534.     mov    [vga512],1
  535.     jmp    fini
  536.  
  537. no_pd:        ;Test for Chips & Tech
  538.     cmp    ax, 2
  539.     jnz    no_ct
  540.     bkadr    chipstech
  541.     mov    [vga512],1
  542.     jmp    fini
  543.  
  544. no_ct:
  545.     cmp    ax, 10
  546.     jnz    t4_mem
  547.     bkadr    tseng
  548.     mov    [vga512],1
  549.     jmp    fini
  550.  
  551. t4_mem:            ;Tseng 4000 memory detect 1meg
  552.     cmp    ax, 11
  553.     jnz    no_ts
  554.     mov    [vga1024],1        ;full meg with eight 256kx4 RAMs
  555.     bkadr    tseng4
  556.     jmp    fini
  557.  
  558. no_ts:
  559.     cmp    ax, 1
  560.     jnz    no_ab
  561.     bkadr    aheada
  562.     mov    [vga512],1
  563.     jmp    fini
  564.  
  565. ;verb:                ; can't force ahead b yet
  566. ;    cmp    ax,
  567. ;    bkadr    aheadb
  568. ;    mov    [vga512],1
  569. ;    jmp    short fini
  570.  
  571. no_ab:            ;Test for Oak Technology
  572.     cmp    ax, 4
  573.     jnz    no_gn
  574.     bkadr    oaktech
  575.     mov    [vga512],1
  576.     jmp    fini
  577.  
  578. no_gn:            ;Test for Cirrus
  579.  
  580.     jmp    finish
  581.  
  582. finish:
  583.     ret
  584. forcevga endp
  585.  
  586.  
  587.  
  588. whichvga proc    uses si di
  589.     local    vesabuf[256]:byte
  590.  
  591.     cmp    [first],'FI'
  592.     jnz    gotest
  593.     mov    ax,[retval]
  594.     ret
  595. gotest:    mov    [bankadr],offset _nobank
  596. if @Codesize
  597.     mov    [bankseg],seg _nobank
  598. endif
  599.     xor    ax,ax
  600.     mov    [curbk],ax
  601.     mov    [vga512],ax
  602.     mov    [vga1024],ax
  603.     mov    [cirrus],ax
  604.     mov    [everex],ax
  605.     mov    [paradise],ax
  606.     mov    [tseng],ax
  607.     mov    [trident],ax
  608.     mov    [t8900],ax
  609.     mov    [ativga],ax
  610.     mov    [aheada],ax
  611.     mov    [aheadb],ax
  612.     mov    [oaktech],ax
  613.     mov    [video7],ax
  614.     mov    [chipstech],ax
  615.     mov    [tseng4],ax
  616.     mov    [genoa],ax
  617.     mov    [ncr],ax
  618.     mov    [compaq],ax
  619.     mov    [vesa],ax
  620.     mov    [first],'FI'
  621.  
  622.     mov    ax,ss
  623.     mov    es,ax
  624.     lea    di,vesabuf[0]
  625.     mov    ax,4f00h
  626.     int    10h
  627.     cmp    ax,4fh
  628.     jnz    novesa
  629.     lea    si,vesabuf[0]
  630.     mov    di,offset vgainfo
  631.     mov    ax,ds
  632.     mov    es,ax
  633.     push    ds
  634.     mov    ax,ss
  635.     mov    ds,ax
  636.     mov    cx,7
  637.     cld
  638.     rep    movsw
  639.     pop    ds
  640.     bkadr    vesa
  641.     mov    [vga512],1
  642.     mov    [vga1024],1
  643. ;    jmp    fini
  644.  
  645. novesa:    mov    si,1
  646.     mov    ax,0c000h
  647.     mov    es,ax
  648.     cmp    word ptr es:[40h],'13'    ;ATI Signiture on the Video BIOS
  649.     jnz    noati
  650.     bkadr    ativga
  651.     cli
  652.     mov    dx,1ceh
  653.     mov    al,0bbh
  654.     out    dx,al
  655.     inc    dl
  656.     in    al,dx
  657.     sti
  658.     and    al,20h
  659.     jz    no512
  660.     mov    [vga512],1
  661. no512:    jmp    fini
  662.  
  663. noati:    mov    ax,7000h        ;Test for Everex
  664.     xor    bx,bx
  665.     cld
  666.     int    10h
  667.     cmp    al,70h
  668.     jnz    noev
  669.     bkadr    everex
  670.     and    ch,11000000b        ;how much memory on board
  671.     jz    skp
  672.     mov    [vga512],1
  673. skp:                    ;fall through for Everex boards using Trident or Tseng4000
  674.  
  675. noev:    mov    ax,0bf03h        ;Test for Compaq
  676.     xor    bx,bx
  677.     mov    cx,bx
  678.     int    10h
  679.     cmp    ax,0bf03h
  680.     jnz    nocp
  681.     test    cl,40h            ;is 640x480x256 available?
  682.     jz    nocp
  683.     bkadr    compaq
  684.     mov    [vga512],1
  685.     jmp    fini
  686.  
  687. nocp:    mov    dx,3c4h            ;Test for NCR 77C22E
  688.     mov    ax,0ff05h
  689.     call    _isport2
  690.     jnz    noncr
  691.     mov    ax,5            ;Disable extended registers
  692.     out    dx,ax
  693.     mov    ax,0ff10h        ;Try to write to extended register 10
  694.     call    _isport2        ;If it writes then not NCR
  695.     jz    noncr
  696.     mov    ax,105h            ;Enable extended registers
  697.     out    dx,ax
  698.     mov    ax,0ff10h
  699.     call    _isport2
  700.     jnz    noncr            ;If it does NOT write then not NCR
  701.     bkadr    ncr
  702.     mov    [vga512],1
  703.     jmp    fini
  704.  
  705. noncr:    mov    dx,3c4h            ;Test for Trident
  706.     mov    al,0bh
  707.     out    dx,al
  708.     inc    dl
  709.     in    al,dx
  710.     cmp    al,06h
  711.     ja    notri
  712.     cmp    al,2
  713.     jb    notri
  714.     bkadr    trident
  715.     cmp    al,3
  716.     jb    no89
  717.     mov    [t8900],1
  718.     mov    dx,3d5h
  719.     mov    al,1fh
  720.     out    dx,al
  721.     inc    dx
  722.     in    al,dx
  723.     and    al,3
  724.     cmp    al,1
  725.     jb    notmem
  726.     mov    [vga512],1
  727.     je    notmem
  728.     mov    [vga1024],1
  729. notmem:    jmp    fini
  730.  
  731. no89:    mov    [vga512],1
  732.     jmp    fini
  733.  
  734. notri:    mov    ax,6f00h        ;Test for Video 7
  735.     xor    bx,bx
  736.     cld
  737.     int    10h
  738.     cmp    bx,'V7'
  739.     jnz    nov7
  740.     bkadr    video7
  741.     mov    ax,6f07h
  742.     cld
  743.     int    10h
  744.     and    ah,7fh
  745.     cmp    ah,1
  746.     jbe    skp2
  747.     mov    [vga512],1
  748. skp2:    cmp    ah,3
  749.     jbe    skp3
  750.     mov    [vga1024],1
  751. skp3:    jmp    fini
  752.  
  753. nov7:    mov    dx,3d4h            ;Test for GENOA GVGA
  754.     mov    ax,032eh        ;check for Herchi Register
  755.     call    _isport2
  756.     jnz    nogn
  757.     mov    dx,3c4h            ;check for memory segment register
  758.     mov    ax,3f06h
  759.     call    _isport2
  760.     jnz    nogn
  761.     bkadr    genoa
  762.     mov    [vga512],1
  763.     jmp    fini
  764.  
  765. nogn:    call    _cirrus            ;Test for Cirrus
  766.     cmp    [cirrus],0
  767.     je    noci
  768.     jmp    fini
  769.  
  770. noci:    mov    dx,3ceh            ;Test for Paradise
  771.     mov    al,9            ;check Bank switch register
  772.     out    dx,al
  773.     inc    dx
  774.     in    al,dx
  775.     dec    dx
  776.     or    al,al
  777.     jnz    nopd
  778.  
  779.     mov    ax,50fh            ;turn off write protect on VGA registers
  780.     out    dx,ax
  781.     mov    dx,offset _pdrsub
  782.     mov    cx,1
  783.     call    _chkbk
  784.     jc    nopd            ;if bank 0 and 1 same not paradise
  785.     bkadr    paradise
  786.     mov    dx,3ceh
  787.     mov    al,0bh            ;512k detect from Bob Berry
  788.     out    dx,al
  789.     inc    dx
  790.     in    al,dx
  791.     test    al,80h            ;if top bit set then 512k
  792.     jz    nop512
  793.     mov    [vga512],1
  794. nop512:    jmp    fini
  795.  
  796. nopd:    mov    ax,5f00h        ;Test for Chips & Tech
  797.     xor    bx,bx
  798.     cld
  799.     int    10h
  800.     cmp    al,5fh
  801.     jnz    noct
  802.     bkadr    chipstech
  803.     cmp    bh,1
  804.     jb    skp4
  805.     mov    [vga512],1
  806. skp4:    jmp    fini
  807.  
  808. noct:    mov    ch,0
  809.     mov    dx,3d4h            ;check for Tseng 4000 series
  810.     mov    ax,0f33h
  811.     call    _isport2
  812.     jnz    not4
  813.     mov    ch,1
  814.  
  815.     mov    dx,3bfh            ;Enable access to extended registers
  816.     mov    al,3
  817.     out    dx,al
  818.     mov    dx,3d8h
  819.     mov    al,0a0h
  820.     out    dx,al
  821.     jmp    short yes4
  822.  
  823. not4:    mov    dx,3d4h            ;Test for Tseng 3000 or 4000
  824.     mov    ax,1f25h        ;is the Overflow High register there?
  825.     call    _isport2
  826.     jnz    nots
  827.     mov    al,03fh            ;bottom six bits only
  828.     jmp    short yes3
  829. yes4:    mov    al,0ffh
  830. yes3:    mov    dx,3cdh            ;test bank switch register
  831.     call    _isport1
  832.     jnz    nots
  833.     bkadr    tseng
  834.     cmp    ch,0
  835.     jnz    t4mem
  836.     mov    [vga512],1
  837.     jmp    fini
  838.  
  839. t4mem:    mov    dx,3d4h            ;Tseng 4000 memory detect 1meg
  840.     mov    al,37h
  841.     out    dx,al
  842.     inc    dx
  843.     in    al,dx
  844.     test    al,1000b        ;if using 64kx4 RAMs then no more than 256k
  845.     jz    nomem
  846.     and    al,3
  847.     cmp    al,1            ;if 8 bit wide bus then only two 256kx4 RAMs
  848.     jbe    nomem
  849.     mov    [vga512],1
  850.     cmp    al,2            ;if 16 bit wide bus then four 256kx4 RAMs
  851.     je    nomem
  852.     mov    [vga1024],1        ;full meg with eight 256kx4 RAMs
  853. nomem:    bkadr    tseng4
  854.     jmp    short fini
  855.  
  856. nots:
  857.     mov    dx,3ceh            ;Test for Above A or B chipsets
  858.     mov    ax,200fh
  859.     out    dx,ax
  860.     inc    dx
  861.     nojmp
  862.     in    al,dx
  863.     cmp    al,21h
  864.     jz    verb
  865.     cmp    al,20h
  866.     jnz    noab
  867.     bkadr    aheada
  868.     mov    [vga512],1
  869.     jmp    short fini
  870.  
  871. verb:    bkadr    aheadb
  872.     mov    [vga512],1
  873.     jmp    short fini
  874.  
  875. noab:    mov    dx,3deh            ;Test for Oak Technology
  876.     mov    ax,0ff11h        ;look for bank switch register
  877.     call    _isport2
  878.     jnz    nooak
  879.     bkadr    oaktech
  880.     mov    al,0dh
  881.     out    dx,al
  882.     inc    dx
  883.     nojmp
  884.     in    al,dx
  885.     test    al,80h
  886.     jz    no4ram
  887.     mov    [vga512],1
  888. no4ram:    jmp    short fini
  889.  
  890. nooak:    mov    si,0
  891.  
  892. fini:    mov    ax,si
  893.     mov    [retval],ax
  894.     ret
  895. whichvga endp
  896.  
  897.  
  898. _cirrus    proc    near
  899.     mov    dx,3d4h        ; assume 3dx addressing
  900.     mov    al,0ch        ; screen a start address hi
  901.     out    dx,al        ; select index
  902.     inc    dx        ; point to data
  903.     mov    ah,al        ; save index in ah
  904.     in    al,dx        ; get screen a start address hi
  905.     xchg    ah,al        ; swap index and data
  906.     push    ax        ; save old value
  907.     push    dx        ; save crtc address
  908.     xor    al,al        ; clear crc
  909.     out    dx,al        ; and out to the crtc
  910.  
  911.     mov    al,1fh        ; Eagle ID register
  912.     dec    dx        ; back to index
  913.     out    dx,al        ; select index
  914.     inc    dx        ; point to data
  915.     in    al,dx        ; read the id register
  916.     mov    bh,al        ; and save it in bh
  917.  
  918.     mov    cl,4        ; nibble swap rotate count
  919.     mov    dx,3c4h        ; sequencer/extensions
  920.     mov    bl,6        ; extensions enable register
  921.  
  922.     ror    bh,cl        ; compute extensions disable value
  923.     mov    ax,bx        ; extensions disable
  924.     out    dx,ax        ; disable extensions
  925.     inc    dx        ; point to data
  926.     in    al,dx        ; read enable flag
  927.     or    al,al        ; disabled ?
  928.     jnz    exit        ; nope, not an cirrus
  929.  
  930.     ror    bh,cl        ; compute extensions enable value
  931.     dec    dx        ; point to index
  932.     mov    ax,bx        ; extensions enable
  933.     out    dx,ax        ; enable extensions
  934.     inc    dx        ; point to data
  935.     in    al,dx        ; read enable flag
  936.     cmp    al,1        ; enabled ?
  937.     jne    exit        ; nope, not an cirrus
  938.     mov    [cirrus],1
  939.     mov    [bankadr],offset _nobank
  940. if @Codesize
  941.     mov    [bankseg],seg _nobank
  942. endif
  943. exit:    pop    dx        ; restore crtc address
  944.     dec    dx        ; point to index
  945.     pop    ax        ; recover crc index and data
  946.     out    dx,ax        ; restore crc value
  947.     ret
  948. _cirrus    endp
  949.  
  950. _chkbk    proc    near        ;bank switch check routine
  951.     mov    di,0b800h
  952.     mov    es,di
  953.     xor    di,di
  954.     mov    bx,1234h
  955.     call    _gochk
  956.     jnz    badchk
  957.     mov    bx,4321h
  958.     call    _gochk
  959.     jnz    badchk
  960.     clc
  961.     ret
  962. badchk:    stc
  963.     ret
  964. _chkbk    endp
  965.  
  966. _gochk    proc    near
  967.     push    si
  968.     mov    si,bx
  969.  
  970.     mov    al,cl
  971.     call    dx
  972.     xchg    bl,es:[di]
  973.     mov    al,ch
  974.     call    dx
  975.     xchg    bh,es:[di]
  976.  
  977.     xchg    si,bx
  978.  
  979.     mov    al,cl
  980.     call    dx
  981.     xor    bl,es:[di]
  982.     mov    al,ch
  983.     call    dx
  984.     xor    bh,es:[di]
  985.  
  986.     xchg    si,bx
  987.  
  988.     mov    al,ch
  989.     call    dx
  990.     mov    es:[di],bh
  991.     mov    al,cl
  992.     call    dx
  993.     mov    es:[di],bl
  994.  
  995.     mov    al,0
  996.     call    dx
  997.     or    si,si
  998.     pop    si
  999.     ret
  1000. _gochk    endp
  1001.  
  1002.  
  1003. _pdrsub    proc    near        ;Paradise
  1004.     push    dx
  1005.     mov    ah,al
  1006.     mov    dx,3ceh
  1007.     mov    al,9
  1008.     out    dx,ax
  1009.     pop    dx
  1010.     ret
  1011. _pdrsub    endp
  1012.  
  1013.  
  1014. _isport2 proc    near
  1015.     push    bx
  1016.     mov    bx,ax
  1017.     out    dx,al
  1018.     mov    ah,al
  1019.     inc    dx
  1020.     in    al,dx
  1021.     dec    dx
  1022.     xchg    al,ah
  1023.     push    ax
  1024.     mov    ax,bx
  1025.     out    dx,ax
  1026.     out    dx,al
  1027.     mov    ah,al
  1028.     inc    dx
  1029.     in    al,dx
  1030.     dec    dx
  1031.     and    al,bh
  1032.     cmp    al,bh
  1033.     jnz    noport
  1034.     mov    al,ah
  1035.     mov    ah,0
  1036.     out    dx,ax
  1037.     out    dx,al
  1038.     mov    ah,al
  1039.     inc    dx
  1040.     in    al,dx
  1041.     dec    dx
  1042.     and    al,bh
  1043.     cmp    al,0
  1044. noport:    pop    ax
  1045.     out    dx,ax
  1046.     pop    bx
  1047.     ret
  1048. _isport2 endp
  1049.  
  1050. _isport1 proc    near
  1051.     mov    ah,al
  1052.     in    al,dx
  1053.     push    ax
  1054.     mov    al,ah
  1055.     out    dx,al
  1056.     in    al,dx
  1057.     and    al,ah
  1058.     cmp    al,ah
  1059.     jnz    noport2
  1060.     mov    al,0
  1061.     out    dx,al
  1062.     in    al,dx
  1063.     and    al,ah
  1064.     cmp    al,0
  1065. noport2:    pop    ax
  1066.     out    dx,al
  1067.     ret
  1068. _isport1 endp
  1069.  
  1070.     end
  1071.  
  1072.