home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / compresn / dvpeg / src1b / banks.asm < prev    next >
Encoding:
Assembly Source File  |  1992-06-09  |  19.7 KB  |  1,096 lines

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