home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tegl_ii / svga / svgamode.asm < prev    next >
Encoding:
Assembly Source File  |  1991-10-08  |  9.5 KB  |  546 lines

  1.  
  2.         include grphdrvr.inc
  3.  
  4. ;******************************************************************************}
  5. ;                TEGL Windows ToolKit II                   }
  6. ;           Copyright (C) 1990, TEGL Systems Corporation            }
  7. ;                 All Rights Reserved.                   }
  8. ;******************************************************************************}
  9.  
  10.         .code
  11.  
  12. vga512flag    dw   ?
  13. vga1024flag    dw   ?
  14. svgatype    dw   0
  15.  
  16. x_cirrus    equ    1
  17. x_everex    equ    2
  18. x_paradise    equ    3
  19. x_tseng     equ    4
  20. x_trident    equ    5
  21. x_t8900     equ    6
  22. x_ativga    equ    7
  23. x_aheada    equ    8
  24. x_aheadb    equ    9
  25. x_oaktech    equ    10
  26. x_video7    equ    11
  27. x_chipstech    equ    12
  28. x_tseng4    equ    13
  29. x_genoa     equ    14
  30. x_ncr        equ    15
  31. x_compaq    equ    16
  32. x_vesa        equ    17
  33.  
  34.  
  35. getsvgatype    proc    far vgatype:dword,memsize:dword
  36.         public    getsvgatype
  37.  
  38.         push    es
  39.         push    di
  40.         push    ds
  41.         push    si
  42.         push    dx
  43.         push    cx
  44.         push    bx
  45.  
  46.         mov    cs:vga512flag,0
  47.         mov    cs:vga1024flag,0
  48.         mov    cs:svgatype,-10
  49.  
  50.         call    getvgatype
  51.  
  52.         lds    si,vgatype    ;get variable address
  53.         mov    ax,cs:svgatype
  54.         mov    ds:[si],ax
  55.  
  56.         lds    si,memsize    ;get variable address
  57.  
  58.         mov    ax,1024
  59.         test    cs:vga1024flag,1
  60.         jnz    okmem
  61.         mov    ax,512
  62.         test    cs:vga512flag,1
  63.         jnz    okmem
  64.         mov    ax,256
  65. okmem:        mov    ds:[si],ax
  66.  
  67.         pop    bx
  68.         pop    cx
  69.         pop    dx
  70.         pop    si
  71.         pop    ds
  72.         pop    di
  73.         pop    es
  74.         ret
  75. getsvgatype    endp
  76.  
  77. ;----------------------------------------------------------------------------;
  78. ;                                         ;
  79. ;----------------------------------------------------------------------------;
  80. nojmp    macro
  81.     local    lbl
  82.     jmp    lbl
  83. lbl:
  84.     endm
  85.  
  86.  
  87. getvgatype    proc    near
  88.         mov    si,1
  89.         mov    ax,0c000h
  90.         mov    es,ax
  91.         cmp    word ptr es:[40h],'13'  ;ATI Signiture on the Video BIOS
  92.         jnz    noati
  93.  
  94.         mov    cs:svgatype,x_ativga
  95.         cli
  96.         mov    dx,1ceh
  97.         mov    al,0bbh
  98.         out    dx,al
  99.         inc    dl
  100.         in    al,dx
  101.         sti
  102.         and    al,20h
  103.         jz    no512
  104.         mov    cs:vga512flag,1
  105. no512:        jmp    fini
  106.  
  107. noati:        mov    ax,7000h        ;Test for Everex
  108.         xor    bx,bx
  109.         cld
  110.         int    10h
  111.         cmp    al,70h
  112.         jnz    noev
  113.  
  114.         mov    cs:svgatype,x_everex
  115.         and    ch,11000000b        ;how much memory on board
  116.         jz    skp
  117.         mov    cs:vga512flag,1
  118. skp:                        ;fall through for Everex boards using Trident or Tseng4000
  119.  
  120. noev:        mov    ax,0bf03h        ;Test for Compaq
  121.         xor    bx,bx
  122.         mov    cx,bx
  123.         int    10h
  124.         cmp    ax,0bf03h
  125.         jnz    nocp
  126.         test    cl,40h            ;is 640x480x256 available?
  127.         jz    nocp
  128.         mov    cs:svgatype,x_compaq
  129.         mov    cs:vga512flag,1
  130.         jmp    fini
  131.  
  132. nocp:        mov    dx,3c4h         ;Test for NCR 77C22E
  133.         mov    ax,0ff05h
  134.         call    _isport2
  135.         jnz    noncr
  136.         mov    ax,5            ;Disable extended registers
  137.         out    dx,ax
  138.         mov    ax,0ff10h        ;Try to write to extended register 10
  139.         call    _isport2        ;If it writes then not NCR
  140.         jz    noncr
  141.         mov    ax,105h         ;Enable extended registers
  142.         out    dx,ax
  143.         mov    ax,0ff10h
  144.         call    _isport2
  145.         jnz    noncr            ;If it does NOT write then not NCR
  146.         mov    cs:svgatype,x_ncr
  147.         mov    cs:vga512flag,1
  148.         jmp    fini
  149.  
  150. noncr:        mov    dx,3c4h         ;Test for Trident
  151.         mov    al,0bh
  152.         out    dx,al
  153.         inc    dl
  154.         in    al,dx
  155.         cmp    al,06h
  156.         ja    notri
  157.         cmp    al,2
  158.         jb    notri
  159.         mov    cs:svgatype,x_trident
  160.         cmp    al,3
  161.         jb    no89
  162.         mov    cs:svgatype,x_t8900
  163.         mov    dx,3d5h
  164.         mov    al,1fh
  165.         out    dx,al
  166.         inc    dx
  167.         in    al,dx
  168.         and    al,3
  169.         cmp    al,1
  170.         jb    notmem
  171.         mov    cs:vga512flag,1
  172.         je    notmem
  173.         mov    cs:vga1024flag,1
  174. notmem:     jmp    fini
  175.  
  176. no89:        mov    cs:vga512flag,1
  177.         jmp    fini
  178.  
  179. notri:        mov    ax,6f00h        ;Test for Video 7
  180.         xor    bx,bx
  181.         cld
  182.         int    10h
  183.         cmp    bx,'V7'
  184.         jnz    nov7
  185.         mov    cs:svgatype,x_video7
  186.         mov    ax,6f07h
  187.         cld
  188.         int    10h
  189.         and    ah,7fh
  190.         cmp    ah,1
  191.         jbe    skp2
  192.         mov    cs:vga512flag,1
  193. skp2:        cmp    ah,3
  194.         jbe    skp3
  195.         mov    cs:vga1024flag,1
  196. skp3:        jmp    fini
  197.  
  198. nov7:        mov    dx,3d4h         ;Test for GENOA GVGA
  199.         mov    ax,032eh        ;check for Herchi Register
  200.         call    _isport2
  201.         jnz    nogn
  202.         mov    dx,3c4h         ;check for memory segment register
  203.         mov    ax,3f06h
  204.         call    _isport2
  205.         jnz    nogn
  206.         mov    cs:svgatype,x_genoa
  207.         mov    cs:vga512flag,1
  208.         jmp    fini
  209.  
  210. nogn:        call    _cirrus         ;Test for Cirrus
  211.         cmp    cs:svgatype,x_cirrus
  212.         jne    noci
  213.         jmp    fini
  214.  
  215. noci:        mov    dx,3ceh         ;Test for Paradise
  216.         mov    al,9            ;check Bank switch register
  217.         out    dx,al
  218.         inc    dx
  219.         in    al,dx
  220.         dec    dx
  221.         or    al,al
  222.         jnz    nopd
  223.  
  224.         mov    ax,50fh         ;turn off write protect on VGA registers
  225.         out    dx,ax
  226.         mov    cx,1
  227.         mov    dx,3ceh         ;Test for Paradise
  228.         call    _chkbk
  229.         jc    nopd            ;if bank 0 and 1 same not paradise
  230.         mov    cs:svgatype,x_paradise
  231.         mov    dx,3ceh
  232.         mov    al,0bh            ;512k detect from Bob Berry
  233.         out    dx,al
  234.         inc    dx
  235.         in    al,dx
  236.         test    al,80h            ;if top bit set then 512k
  237.         jz    nop512
  238.         mov    cs:vga512flag,1
  239. nop512:     jmp    fini
  240.  
  241. nopd:        mov    ax,5f00h        ;Test for Chips & Tech
  242.         xor    bx,bx
  243.         cld
  244.         int    10h
  245.         cmp    al,5fh
  246.         jnz    noct
  247.         mov    cs:svgatype,x_chipstech
  248.         cmp    bh,1
  249.         jb    skp4
  250.         mov    cs:vga512flag,1
  251. skp4:        jmp    fini
  252.  
  253. noct:        mov    ch,0
  254.         mov    dx,3d4h         ;check for Tseng 4000 series
  255.         mov    ax,0f33h
  256.         call    _isport2
  257.         jnz    not4
  258.         mov    ch,1
  259.  
  260.         mov    dx,3bfh         ;Enable access to extended registers
  261.         mov    al,3
  262.         out    dx,al
  263.         mov    dx,3d8h
  264.         mov    al,0a0h
  265.         out    dx,al
  266.         jmp    short yes4
  267.  
  268. not4:        mov    dx,3d4h         ;Test for Tseng 3000 or 4000
  269.         mov    ax,1f25h        ;is the Overflow High register there?
  270.         call    _isport2
  271.         jnz    nots
  272.         mov    al,03fh         ;bottom six bits only
  273.         jmp    short yes3
  274. yes4:        mov    al,0ffh
  275. yes3:        mov    dx,3cdh         ;test bank switch register
  276.         call    _isport1
  277.         jnz    nots
  278.         mov    cs:svgatype,x_tseng
  279.         cmp    ch,0
  280.         jnz    t4mem
  281.         mov    cs:vga512flag,1
  282.         jmp    fini
  283.  
  284. t4mem:        mov    dx,3d4h         ;Tseng 4000 memory detect 1meg
  285.         mov    al,37h
  286.         out    dx,al
  287.         inc    dx
  288.         in    al,dx
  289.         test    al,1000b        ;if using 64kx4 RAMs then no more than 256k
  290.         jz    nomem
  291.         and    al,3
  292.         cmp    al,1            ;if 8 bit wide bus then only two 256kx4 RAMs
  293.         jbe    nomem
  294.         mov    cs:vga512flag,1
  295.         cmp    al,2            ;if 16 bit wide bus then four 256kx4 RAMs
  296.         je    nomem
  297.         mov    cs:vga1024flag,1    ;full meg with eight 256kx4 RAMs
  298. nomem:        mov    cs:svgatype,x_tseng4
  299.         jmp    fini
  300.  
  301. nots:
  302.         mov    dx,3ceh         ;Test for Above A or B chipsets
  303.         mov    ax,200fh
  304.         out    dx,ax
  305.         inc    dx
  306.         nojmp
  307.         in    al,dx
  308.         cmp    al,21h
  309.         jz    verb
  310.         cmp    al,20h
  311.         jnz    noab
  312.         mov    cs:svgatype,x_aheada
  313.         mov    cs:vga512flag,1
  314.         jmp    short fini
  315.  
  316. verb:        mov    cs:svgatype,x_aheadb
  317.         mov    cs:vga512flag,1
  318.         jmp    short fini
  319.  
  320. noab:        mov    dx,3deh         ;Test for Oak Technology
  321.         mov    ax,0ff11h        ;look for bank switch register
  322.         call    _isport2
  323.         jz    oakok
  324.  
  325.         push    es
  326.         push    di
  327.         push    cx
  328.  
  329.         cld
  330.         mov    ax,0c000h
  331.         mov    es,ax
  332.         xor    di,di
  333.         mov    cx,256
  334.  
  335.         mov    al,'O'
  336. findoak:    repne    scasb
  337.         jcxz    notoak
  338.  
  339.         cmp    byte ptr es:[di],'A'
  340.         jne    findoak
  341.  
  342.         cmp    byte ptr es:[di+1],'K'
  343.         jne    findoak
  344.  
  345.         pop    cx
  346.         pop    di
  347.         pop    es
  348.         jmp    short oakok
  349.  
  350.  
  351. notoak:     pop    cx
  352.         pop    di
  353.         pop    es
  354.         jmp    short nooak
  355.  
  356. oakok:        mov    cs:svgatype,x_oaktech
  357.         mov    al,0dh
  358.         out    dx,al
  359.         inc    dx
  360.         nojmp
  361.         in    al,dx
  362.         test    al,80h
  363.         jz    no4ram
  364.         mov    cs:vga512flag,1
  365. no4ram:     jmp    short fini
  366.  
  367. nooak:        mov    si,0
  368.  
  369. fini:        mov    ax,si
  370.         ret
  371. getvgatype    endp
  372.  
  373.  
  374. _cirrus     proc near
  375.         mov    dx,3d4h     ; assume 3dx addressing
  376.         mov    al,0ch        ; screen a start address hi
  377.         out    dx,al        ; select index
  378.         inc    dx        ; point to data
  379.         mov    ah,al        ; save index in ah
  380.         in    al,dx        ; get screen a start address hi
  381.         xchg    ah,al        ; swap index and data
  382.         push    ax        ; save old value
  383.         push    dx        ; save crtc address
  384.         xor    al,al        ; clear crc
  385.         out    dx,al        ; and out to the crtc
  386.  
  387.         mov    al,1fh        ; Eagle ID register
  388.         dec    dx        ; back    to index
  389.         out    dx,al        ; select index
  390.         inc    dx        ; point to data
  391.         in    al,dx        ; read the id register
  392.         mov    bh,al        ; and save it in bh
  393.  
  394.         mov    cl,4        ; nibble swap rotate count
  395.         mov    dx,3c4h     ; sequencer/extensions
  396.         mov    bl,6        ; extensions enable register
  397.  
  398.         ror    bh,cl        ; compute extensions disable value
  399.         mov    ax,bx        ; extensions disable
  400.         out    dx,ax        ; disable extensions
  401.         inc    dx        ; point to data
  402.         in    al,dx        ; read enable flag
  403.         or    al,al        ; disabled ?
  404.         jnz    exit        ; nope, not an cirrus
  405.  
  406.         ror    bh,cl        ; compute extensions enable value
  407.         dec    dx        ; point to index
  408.         mov    ax,bx        ; extensions enable
  409.         out    dx,ax        ; enable extensions
  410.         inc    dx        ; point to data
  411.         in    al,dx        ; read enable flag
  412.         cmp    al,1        ; enabled ?
  413.         jne    exit        ; nope, not an cirrus
  414.         mov    cs:svgatype,x_cirrus
  415.  
  416. exit:        pop    dx        ; restore crtc address
  417.         dec    dx        ; point to index
  418.         pop    ax        ; recover crc index and data
  419.         out    dx,ax        ; restore crc value
  420.         ret
  421. _cirrus     endp
  422.  
  423. _chkbk        proc    near        ;bank switch check routine
  424.         push    es
  425.         mov    di,0b800h
  426.         mov    es,di
  427.         xor    di,di
  428.         mov    bx,1234h
  429.         call    _gochk
  430.         jnz    badchk
  431.         mov    bx,4321h
  432.         call    _gochk
  433.         jnz    badchk
  434.         clc
  435.         pop    es
  436.         ret
  437. badchk:     stc
  438.         pop    es
  439.         ret
  440. _chkbk        endp
  441.  
  442. _gochk        proc    near
  443.         push    si
  444.         push    es
  445.         mov    si,bx
  446.  
  447.         mov    al,cl
  448.         call    _pdrsub
  449.         xchg    bl,es:[di]
  450.         mov    al,ch
  451.         call    _pdrsub
  452.         xchg    bh,es:[di]
  453.  
  454.         xchg    si,bx
  455.  
  456.         mov    al,cl
  457.         call    _pdrsub
  458.         xor    bl,es:[di]
  459.         mov    al,ch
  460.         call    _pdrsub
  461.         xor    bh,es:[di]
  462.  
  463.         xchg    si,bx
  464.  
  465.         mov    al,ch
  466.         call    _pdrsub
  467.         mov    es:[di],bh
  468.         mov    al,cl
  469.         call    _pdrsub
  470.         mov    es:[di],bl
  471.  
  472.         mov    al,0
  473.         call    _pdrsub
  474.         or    si,si
  475.         pop    es
  476.         pop    si
  477.         ret
  478. _gochk        endp
  479.  
  480.  
  481. _pdrsub     proc    near        ;Paradise
  482.         mov    ah,al
  483.         mov    al,9
  484.         out    dx,ax
  485.         ret
  486. _pdrsub     endp
  487.  
  488.  
  489. _isport2    proc   near
  490.         push    bx
  491.         mov    bx,ax
  492.         out    dx,al
  493.         mov    ah,al
  494.         inc    dx
  495.         in    al,dx
  496.         dec    dx
  497.         xchg    al,ah
  498.         push    ax
  499.         mov    ax,bx
  500.         out    dx,ax
  501.         out    dx,al
  502.         mov    ah,al
  503.         inc    dx
  504.         in    al,dx
  505.         dec    dx
  506.         and    al,bh
  507.         cmp    al,bh
  508.         jnz    noport2
  509.         mov    al,ah
  510.         mov    ah,0
  511.         out    dx,ax
  512.         out    dx,al
  513.         mov    ah,al
  514.         inc    dx
  515.         in    al,dx
  516.         dec    dx
  517.         and    al,bh
  518.         cmp    al,0
  519. noport2:    pop    ax
  520.         out    dx,ax
  521.         pop    bx
  522.         ret
  523. _isport2    endp
  524.  
  525. _isport1    proc   near
  526.         mov    ah,al
  527.         in    al,dx
  528.         push    ax
  529.         mov    al,ah
  530.         out    dx,al
  531.         in    al,dx
  532.         and    al,ah
  533.         cmp    al,ah
  534.         jnz    noport1
  535.         mov    al,0
  536.         out    dx,al
  537.         in    al,dx
  538.         and    al,ah
  539.         cmp    al,0
  540. noport1:    pop    ax
  541.         out    dx,al
  542.         ret
  543. _isport1    endp
  544.  
  545.         end
  546.