home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / video_id / videoid.asm < prev    next >
Encoding:
Assembly Source File  |  1988-10-12  |  8.2 KB  |  327 lines

  1.  
  2.                         TITLE  'VideoID'
  3.                         NAME    VideoID
  4.                         PAGE    55,132
  5.  
  6. ; This routine to identify the PC's graphics card comes from:
  7. ; Programmers Guide to PC & PS/2 Video Systems.
  8. ; R. Wilton, Microsoft Press, Redmond, WA.  1987
  9.  
  10. ARGpVID         EQU     word ptr [bp+4]
  11. ; If you want to use this in a large memory model, above line should be:
  12. ;ARGpVID         EQU     word ptr [bp+6]
  13.  
  14. VIDstruct       STRUC
  15. Video0Type      DB      ?
  16. Display0Type    DB      ?
  17. Video1Type      DB      ?
  18. Display1Type    DB      ?
  19.  
  20. VIDstruct        ENDS
  21.  
  22. Device0         EQU     word ptr Video0Type[di]
  23. Device1         EQU     word ptr Video1Type[di]
  24.  
  25. MDA             EQU     1
  26. CGA             EQU     2
  27. EGA             EQU     3
  28. MCGA            EQU     4
  29. VGA             EQU     5
  30. HGC             EQU     80h
  31. HGCPlus         EQU     81h
  32. InColor         EQU     82h
  33.  
  34. MDADisplay      EQU     1
  35. CGADisplay      EQU     2
  36. EGAColorDisplay EQU     3
  37. PS2MonoDisplay  EQU     4
  38. PS2ColorDisplay EQU     5
  39.  
  40. True            EQU     1
  41. False           EQU     0
  42.  
  43.  
  44. DGROUP          GROUP   _DATA
  45. _text           SEGMENT byte public 'CODE'
  46.                 ASSUME  cs:_text,ds:DGROUP
  47.  
  48.                 PUBLIC  _VideoID
  49. _VideoID        PROC    near
  50.  
  51. ;If you want to use this in a large memory model, above lines should be:
  52. ;vid_text        SEGMENT byte public 'CODE'
  53. ;                ASSUME  cs:vid_text,ds:DGROUP
  54. ;_VideoID        PROC    far
  55.  
  56.                 push    bp
  57.                 mov     bp,sp
  58.                 push    si
  59.                 push    di
  60.  
  61.                 mov     di,ARGpVID
  62.  
  63.                 mov     Device0,0
  64.                 mov     Device1,0
  65.  
  66.                 mov     byte ptr CGAflag,TRUE
  67.                 mov     byte ptr EGAflag,TRUE
  68.                 mov     byte ptr Monoflag,TRUE
  69.                 mov     cx, NumberOfTests
  70.                 mov     si, offset DGROUP:TestSequence
  71.  
  72. L01:            lodsb
  73.                 test    al,al
  74.                 lodsw
  75.                 jz      L02
  76.                 push    si
  77.                 push    cx
  78.                 call    ax
  79.                 pop     cx
  80.                 pop     si
  81.  
  82. L02:            loop    L01
  83.                 call    FindActive
  84.                 pop     di
  85.                 pop     si
  86.                 mov     sp,bp
  87.                 pop     bp
  88.                 ret
  89.  
  90. _VideoID        ENDP
  91.  
  92. FindPS2         PROC    near
  93.  
  94.                 mov     ax,1A00h
  95.                 int     10h
  96.                 cmp     al,1Ah
  97.                 jne     L13
  98.  
  99.                 mov     cx,bx
  100.                 xor     bh,bh
  101.                 or      ch,ch
  102.                 jz      L11
  103.  
  104.                 mov     bl,ch
  105.                 add     bx,bx
  106.                 mov     ax,[bx+offset DGROUP:DCCtable]
  107.  
  108.                 mov     Device1,ax
  109.  
  110.                 mov     bl,cl
  111.                 xor     bh,bh
  112.  
  113. L11:            add     bx,bx
  114.                 mov     ax,[bx+offset DGROUP:DCCtable]
  115.  
  116.                 mov     Device0,ax
  117.  
  118.                 mov     byte ptr CGAflag,FALSE
  119.                 mov     byte ptr EGAflag,FALSE
  120.                 mov     byte ptr Monoflag,FALSE
  121.  
  122.                 lea     bx,Video0Type[di]
  123.                 cmp     byte ptr [bx],MDA
  124.                 je      L12
  125.  
  126.  
  127.                 lea     bx,Video1Type[di]
  128.                 cmp     byte ptr [bx],MDA
  129.                 jne      L13
  130.  
  131. L12:            mov     word ptr [bx],0
  132.                 mov     byte ptr Monoflag,TRUE
  133.  
  134. L13:            ret
  135.  
  136. FindPS2         ENDP
  137.  
  138. FindEGA         PROC    near
  139.                 mov     bl,10h
  140.                 mov     ah,12h
  141.                 int     10h
  142.  
  143.                 cmp     bl,10h
  144.                 je      L22
  145.                 mov     al,cl
  146.                 shr     al,1
  147.                 mov     bx,offset DGROUP:EGADisplays
  148.                 xlat
  149.                 mov     ah,al
  150.                 mov     al,EGA
  151.                 call    FoundDevice
  152.  
  153.                 cmp     ah,MDADisplay
  154.                 je      L21
  155.                 mov     CGAflag,FALSE
  156.                 jmp     short L22
  157.  
  158. L21:            mov     Monoflag,FALSE
  159.  
  160. L22:            ret
  161. FindEGA         ENDP
  162.  
  163. FindCGA         PROC    near
  164.                 mov     dx,3D4h
  165.                 call    find6845
  166.                 jc      L31
  167.  
  168.                 mov     al,CGA
  169.                 mov     ah,CGADisplay
  170.                 call    FoundDevice
  171.  
  172. L31:            ret
  173. FindCGA         ENDP
  174.  
  175.  
  176. FindMono        PROC    near
  177.  
  178.                 mov     dx,3B4h
  179.                 call    Find6845
  180.                 jc      L44
  181.  
  182.                 mov     dl,0BAh
  183.                 in      al,dx
  184.                 and     al,80h
  185.                 mov     ah,al
  186.                 mov     cx,8000h
  187. L41:            in      al,dx
  188.                 and     al,80h
  189.                 cmp     ah,al
  190.                 loope   L41
  191.  
  192.                 jne     L42
  193.                 mov     al,MDA
  194.                 mov     ah,MDADisplay
  195.                 call    FoundDevice
  196.                 jmp     short L44
  197.  
  198. L42:            in      al,dx
  199.                 mov     dl,al
  200.                 mov     ah,MDADisplay
  201.  
  202.                 mov     al,HGC
  203.                 and     dl,01110000b
  204.                 jz      L43
  205.  
  206.                 mov     al,HGCPlus
  207.                 and     dl,00010000b
  208.                 je      L43
  209.  
  210.  
  211.  
  212.                 mov     al,InColor
  213.                 mov     ah,EGAColorDisplay
  214.  
  215. L43:            call    FoundDevice
  216. L44:            ret
  217. FindMono        ENDP
  218.  
  219. Find6845        PROC    near
  220.                 mov     al,0Fh
  221.                 out     dx,al
  222.                 inc     dx
  223.                 in      al,dx
  224.                 mov     ah,al
  225.                 mov     al,66h
  226.                 out     dx,al
  227.                 mov     cx,100h
  228.  
  229. L51:            loop    L51
  230.                 in      al,dx
  231.                 xchg    ah,al
  232.                 out     dx,al
  233.                 cmp     ah,66h
  234.                 je      L52
  235.                 stc
  236.  
  237. L52:            ret
  238. Find6845        ENDP
  239.  
  240. FindActive      PROC    near
  241.                 cmp     word ptr Device1,0
  242.                 je      L63
  243.                 cmp     Video0Type[di],4
  244.                 jge     L63
  245.                 cmp     Video1Type[di],4
  246.                 jge     L63
  247.  
  248.                 mov     ah,0Fh
  249.                 int     10h
  250.                 and     al,7
  251.                 cmp     al,7
  252.                 je      L61
  253.  
  254.                 cmp     Display0Type[di],MDADisplay
  255.                 jne     L63
  256.                 jmp     short L62
  257.  
  258. L61:            cmp     Display0Type[di],MDADisplay
  259.                 je     L63
  260.  
  261. L62:            mov     ax,Device0
  262.                 xchg    ax,Device1
  263.                 mov     Device0,ax
  264.  
  265. L63:            ret
  266. FindActive      ENDP
  267.  
  268. FoundDevice     PROC    near
  269.                 lea     bx,Video0Type[di]
  270.                 cmp     byte ptr [bx],0
  271.                 je      L71
  272.                 lea     bx,Video1Type[di]
  273.  
  274. L71:            mov     [bx],ax
  275.                 ret
  276.  
  277. FoundDevice     ENDP
  278.  
  279. ;If you want to use this in a large memory model, next line should be:
  280. ;vid_text           ENDS
  281. _text           ENDS
  282.  
  283. _DATA           SEGMENT word public 'DATA'
  284.  
  285. EGADisplays     DB      CGADisplay
  286.                 DB      EGAColorDisplay
  287.                 DB      MDADisplay
  288.                 DB      CGADisplay
  289.                 DB      EGAColorDisplay
  290.                 DB      MDADisplay
  291.  
  292. DCCtable        DB      0,0
  293.                 DB      MDA,MDADisplay
  294.                 DB      CGA,CGADisplay
  295.                 DB      0,0
  296.                 DB      EGA,EGAColorDisplay
  297.                 DB      EGA,MDADisplay
  298.                 DB      0,0
  299.                 DB      VGA,PS2MonoDisplay
  300.                 DB      VGA,PS2ColorDisplay
  301.                 DB      0,0
  302.                 DB      MCGA,EGAColorDisplay
  303.                 DB      MCGA,PS2MonoDisplay
  304.                 DB      MCGA,PS2ColorDisplay
  305.  
  306. TestSequence    DB      ?
  307.                 DW      FindPS2
  308.  
  309. EGAflag         DB      ?
  310.                 DW      FindEGA
  311.  
  312. CGAflag         DB      ?
  313.                 DW      FindCGA
  314.  
  315. Monoflag        DB      ?
  316.                 DW      FindMono
  317.  
  318. NumberOfTests   EQU     ($-TestSequence) /3
  319.  
  320. _DATA           ENDS
  321.  
  322.                 END
  323.  
  324.  
  325.  
  326.  
  327.