home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 429.DETECTGR.ASM < prev    next >
Assembly Source File  |  1993-03-19  |  75KB  |  2,629 lines

  1. ;****************************************************************************
  2. ;*
  3. ;*                        MegaGraph Graphics Library
  4. ;*
  5. ;*                  Copyright (C) 1993 Kendall Bennett.
  6. ;*                            All rights reserved.
  7. ;*
  8. ;* Filename:    $RCSfile: detectgr.asm $
  9. ;* Version:        $Revision: 1.2 $
  10. ;*
  11. ;* Language:    80386 Assembler
  12. ;* Environment:    IBM PC (MS DOS)
  13. ;*
  14. ;* Description:    This module contains the auto detection routines to detect
  15. ;*                the presence of all the standard graphics adapters
  16. ;*                supported by the MegaGraph graphics library.
  17. ;*
  18. ;* $Id: detectgr.asm 1.2 1993/03/07 04:03:22 kjb Exp $
  19. ;*
  20. ;* Revision History:
  21. ;* -----------------
  22. ;*
  23. ;* $Log: detectgr.asm $
  24. ;* Revision 1.2  1993/03/07  04:03:22  kjb
  25. ;* Numerous bug fixes and enhancements.
  26. ;*
  27. ;* Revision 1.1  1993/03/03  10:45:16  kjb
  28. ;* Initial revision
  29. ;*
  30. ;****************************************************************************
  31.  
  32.         IDEAL
  33.         JUMPS                    ; Fix jumps out of range
  34.         P386                    ; Use 80386 instructions
  35.  
  36. INCLUDE "model.mac"                ; Memory model macros
  37.  
  38. header    detectgr                ; Set up memory model
  39.  
  40. ;****************************************************************************
  41. ;
  42. ; Equates used by detectgraph routine.
  43. ;
  44. ;****************************************************************************
  45.  
  46. CRTC        EQU    3D4h            ; Port of CRTC registers
  47.  
  48. INCLUDE    "MGRAPH.EQU"            ; Include equates for Mgraph routines
  49.  
  50. begdataseg    detectgr
  51.  
  52. INCLUDE    "MGRAPH.VAR"            ; Include variable references
  53.  
  54. enddataseg    detectgr
  55.  
  56. begcodeseg    detectgr            ; Start of code segment
  57.  
  58. ;****************************************************************************
  59. ;
  60. ; Global variables used by detectgraph routines.
  61. ;
  62. ;****************************************************************************
  63.  
  64. SaveDS            dw    ?            ; Place to save the value of DS register
  65.  
  66. VesaBuf            db    256 dup (?)    ; VESA Video information block
  67. VideoChipID        dw    0            ; Internal SuperVGA chip ID
  68. VideoMem        dw    256            ; Size of video memory (kb)
  69. VideoModes        dw    DefModes    ; Pointer to list of available SuperVGA
  70. PageFlip        dw    false        ; True if page flipping is available
  71.                                 ; Video modes.
  72. DacType            dw    grVGADAC    ; Video DAC type
  73. ForceDAC        dw    0            ; Value to force dac with
  74. old                db    0            ; Scratch place to store values
  75.  
  76. ;****************************************************************************
  77. ;
  78. ; Initialised data used by the detectgraph routines.
  79. ;
  80. ;****************************************************************************
  81.  
  82. ; Delimited list of video modes for all supported video cards. This list
  83. ; may need to be modified depending on display memory restrictions etc.
  84. ;
  85. ; During chip identification, it may be found that the chipset detected
  86. ; does not support all of the specified modes. In this case, the
  87. ; unsupported video modes should be set to a zero (use the UnsupportedMode
  88. ; routine for this).
  89. ;
  90. ; HiColor and TrueColor modes should be specified after the particular
  91. ; chip in question. If the appropriate DAC is detected, a zero should
  92. ; be used to replace the -1 delimiter to add the list of HiColor or
  93. ; TrueColor video modes.
  94.  
  95. DefModes:        db    -1
  96.  
  97. AheadModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  98.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  99.                 db    grSVGA_800x600x256,grSVGA_1024x768x256,-1
  100.  
  101. ATIModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  102.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  103.                 db    grSVGA_800x600x256,grSVGA_1024x768x256
  104. ATI32KModes:    db    -1,grSVGA_640x480x32k,grSVGA_800x600x32k,-1
  105.  
  106. ChipsModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  107.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  108.                 db    grSVGA_800x600x256,grSVGA_1024x768x256,-1
  109.  
  110. EverexModes:    db    grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  111.                 db    grSVGA_640x350x256,grSVGA_640x400x256
  112.                 db    grSVGA_640x480x256,grSVGA_800x600x256
  113.                 db    grSVGA_1024x768x256
  114. Everex32KModes:    db    -1,grSVGA_320x200x32k,grSVGA_640x480x32k
  115. EverexTCModes:    db    -1,grSVGA_640x480x16m,-1
  116.  
  117. GenoaModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  118.                 db    grSVGA_640x350x256,grSVGA_640x400x256
  119.                 db    grSVGA_640x480x256,grSVGA_800x600x256,-1
  120.  
  121. OAKModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  122.                 db    grSVGA_640x480x256,grSVGA_800x600x256
  123.                 db    grSVGA_1024x768x256
  124. OAK32KModes:    db    -1,grSVGA_640x400x32k,grSVGA_640x480x32k,-1
  125.  
  126. ParadiseModes:    db    grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  127.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  128.                 db    grSVGA_800x600x256,grSVGA_1024x768x256
  129. Parad32KModes:    db    -1,grSVGA_640x480x32k,grSVGA_800x600x32k,-1
  130.  
  131. Trident88Modes:    db    grSVGA_800x600x16,grSVGA_1024x768x16
  132.                 db    grSVGA_640x400x256,grSVGA_640x480x256,-1
  133.  
  134. Trident89Modes:    db    grSVGA_800x600x16,grSVGA_1024x768x16
  135.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  136.                 db    grSVGA_800x600x256,grSVGA_1024x768x256,-1
  137.  
  138. Video7Modes:    db    grSVGA_800x600x16,grSVGA_1024x768x16
  139.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  140.                 db    grSVGA_800x600x256,grSVGA_1024x768x256,-1
  141.  
  142. ET3000Modes:    db    grSVGA_800x600x16,grSVGA_1024x768x16
  143.                 db    grSVGA_640x350x256,grSVGA_640x480x256
  144.                 db    grSVGA_800x600x256,-1
  145.  
  146. ET4000Modes:    db    grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  147.                 db    grSVGA_640x350x256,grSVGA_640x400x256
  148.                 db    grSVGA_640x480x256,grSVGA_800x600x256
  149.                 db    grSVGA_1024x768x256
  150. ET400032KModes:    db    -1,grSVGA_320x200x32k,grSVGA_640x350x32k
  151.                 db    grSVGA_640x400x32k,grSVGA_640x480x32k,grSVGA_800x600x32k
  152. ET4000TCModes:    db    -1,grSVGA_640x350x16m,grSVGA_640x400x16m
  153.                 db    grSVGA_640x480x16m,-1
  154.  
  155. NCRModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  156.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  157.                 db    grSVGA_800x600x256,grSVGA_1024x768x256
  158.                 db    grSVGA_1280x1024x256
  159. NCR32KModes:    db    -1,grSVGA_640x480x32k,grSVGA_800x600x32k,-1
  160.  
  161. S3Modes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  162.                 db    grSVGA_640x480x256,grSVGA_800x600x256
  163.                 db  grSVGA_1024x768x256
  164. S332KModes:        db    -1,grSVGA_640x480x32k,-1
  165. S3TCModes:        db    -1
  166.  
  167. CirrusModes:    db    grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  168.                 db    grSVGA_640x480x256,grSVGA_800x600x256
  169.                 db    grSVGA_1024x768x256
  170. Cirrus32kModes:    db    -1,grSVGA_640x480x32k,grSVGA_800x600x32k,-1
  171. CirrusTCModes:    db    -1,grSVGA_320x200x16m,grSVGA_640x480x16m,-1
  172.  
  173. AcuMosModes:    db    grSVGA_800x600x16,grSVGA_1024x768x16
  174.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  175.                 db    grSVGA_800x600x256,-1
  176.  
  177. AL2101Modes:    db  grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  178.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  179.                 db    grSVGA_800x600x256,grSVGA_1024x768x256
  180.                 db    grSVGA_1280x1024x256,-1
  181.  
  182. MXICModes:        db    grSVGA_800x600x16,grSVGA_1024x768x16
  183.                 db    grSVGA_640x350x256,grSVGA_640x400x256
  184.                 db    grSVGA_640x480x256,grSVGA_800x600x256
  185.                 db    grSVGA_1024x768x256,-1
  186.  
  187. P2000Modes:        db  grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  188.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  189.                 db    grSVGA_800x600x256,grSVGA_1024x768x256
  190.                 db    grSVGA_1280x1024x256
  191. P200032KModes:    db    -1,grSVGA_640x350x32k,grSVGA_640x400x32k
  192.                 db    grSVGA_640x480x32k,grSVGA_800x600x32k,-1
  193.  
  194. RT3106Modes:    db  grSVGA_800x600x16,grSVGA_1024x768x16,grSVGA_1280x1024x16
  195.                 db    grSVGA_640x400x256,grSVGA_640x480x256
  196.                 db    grSVGA_800x600x256,grSVGA_1024x768x256
  197.                 db    grSVGA_1280x1024x256,-1
  198.  
  199. VesaModes:        db    20 dup (-1)
  200.  
  201. ; Table to translate EGA display types
  202.  
  203. EGADisplays        db    grEGA,grEGA_640x200x16    ; 0000b,0001b CGA Display
  204.                 db    grEGA,grEGA_640x350x16    ; 0010b,0011b EGA Display
  205.                 db    grEGAMONO,0                ; 0100b,0101b MDA Display
  206.                 db    grEGA,grEGA_640x200x16    ; 0110b,0111b CGA Display
  207.                 db    grEGA,grEGA_640x350x16    ; 1000b,1001b EGA Display
  208.                 db    grEGAMONO,0                ; 1010b,1011b MDA Display
  209.  
  210. ; Table of possible VESA video mode numbers and display memory required
  211. ; rounded up to the nearest half megabyte or megabyte depending on
  212. ; resolution. Cards generally have 256k, 512k, 1M, 2M or 4M on board.
  213.  
  214. AllVesaModes:    dw    100h, 256,  grSVGA_640x400x256
  215.                 dw    101h, 512,  grSVGA_640x480x256
  216.                 dw    102h, 256,  grSVGA_800x600x16
  217.                 dw    103h, 512,  grSVGA_800x600x256
  218.                 dw    104h, 512,  grSVGA_1024x768x16
  219.                 dw    105h, 1024, grSVGA_1024x768x256
  220.                 dw    106h, 1024, grSVGA_1280x1024x16
  221.                 dw    107h, 2048, grSVGA_1280x1024x256
  222.                 dw    10Dh, 256,  grSVGA_320x200x32k
  223.                 dw    10Fh, 256,  grSVGA_320x200x16m
  224.                 dw    110h, 1024, grSVGA_640x480x32k
  225.                 dw    112h, 1024, grSVGA_640x480x16m
  226.                 dw    113h, 1024, grSVGA_800x600x32k
  227.                 dw    115h, 2048, grSVGA_800x600x16m
  228.                 dw    116h, 2048, grSVGA_1024x768x32k
  229.                 dw    118h, 4096, grSVGA_1024x768x16m
  230.                 dw    119h, 4096, grSVGA_1280x1024x32k
  231.                 dw    11Bh, 4096, grSVGA_1280x1024x16m
  232.                 dw    0
  233.  
  234. ;****************************************************************************
  235. ;
  236. ; Set of macros to make the following code more readable, but probably
  237. ; less efficient. Efficiency here is not a major concern, but correctness
  238. ; definately is :-).
  239. ;
  240. ;****************************************************************************
  241.  
  242. MACRO    check    boardName
  243.         call    Find&boardName        ; Check for a particular SuperVGA card
  244.         jc        @@FoundOne
  245. ENDM
  246.  
  247. ; Macro to add the HiColor video modes for this video card to the mode
  248. ; table.
  249.  
  250. MACRO    Add32kColor    ModeTable
  251.         local    NoHiColor
  252.         cmp        [DacType],grHCDAC
  253.         jl        NoHiColor
  254.         mov        bx,offset ModeTable
  255.         mov        [BYTE cs:bx],0        ; Clear the -1 termination flag
  256. NoHiColor:
  257. ENDM
  258.  
  259. ; Macro to add the TrueColor video modes for this video card to the mode
  260. ; table.
  261.  
  262. MACRO    AddTrueColor    ModeTable
  263.         local    NoTrueColor
  264.         cmp        [DacType],grTCDAC
  265.         jl        NoTrueColor
  266.         mov        bx,offset ModeTable
  267.         mov        [BYTE cs:bx],0        ; Clear the -1 termination flag
  268. NoTrueColor:
  269. ENDM
  270.  
  271. MACRO    ClearMode    Mode, ModeTable
  272.         mov        al,Mode
  273.         mov        bx,offset ModeTable
  274.         call    UnsupportedMode        ; Clear the unsupported video mode
  275. ENDM
  276.  
  277. INCLUDE    "SV_PORTS.ASM"
  278. INCLUDE "SV_MAXPG.ASM"
  279.  
  280. ;----------------------------------------------------------------------------
  281. ; void MGL_detectGraph(int far *graphdriver,int far *chipID,int far *memory,
  282. ;    int far *dac,int far *graphmode);
  283. ;----------------------------------------------------------------------------
  284. ; Autodetects the standard graphics adapters supported by the MegaGraph
  285. ; graphics library.
  286. ;----------------------------------------------------------------------------
  287. procstart    _MGL_detectGraph
  288.  
  289.         ARG        driver:DWORD, chipID:DWORD, memory:DWORD, dac:DWORD,    \
  290.                 mode:DWORD
  291.  
  292.         enter    0,0
  293.         pusha
  294.         push    ds
  295.  
  296.         mov        ax,DGROUP        ; Save data segment for later use
  297.         mov        [cs:SaveDS],ax
  298.  
  299.         lds        si,[dac]
  300.         mov        ax,[si]
  301.         mov        [ForceDAC],ax    ; Save value of forced dac type
  302.  
  303.         lds        di,[driver]        ; Load the address of driver in DS:DI
  304.         les        si,[mode]        ; Load the address of mode in ES:SI
  305.  
  306.         push    ds
  307.         mov        ds,[cs:SaveDS]    ; Address data segment
  308.         mov        [__grResult],grOK
  309.         pop        ds
  310.  
  311. ; Look for the various subsystems using the subroutines in the order of
  312. ; highest performance first. Ie: look for PS/2's then EGA, CGA, then
  313. ; hercules monochrome.
  314.  
  315.         call    FindPS2            ; Is an MCGA or VGA out there?
  316.         jc        @@Exit
  317.         call    FindEGA            ; Is an EGA out there?
  318.         jc        @@Exit
  319.         call    FindCGA            ; Is a CGA out there?
  320.         jc        @@Exit
  321.         call    FindHGC            ; Is a Hercules out there?
  322.         jc        @@Exit
  323.  
  324.         push    ds
  325.         mov        ds,[cs:SaveDS]    ; Address data segment
  326.         mov        [__grResult],grNotDetected
  327.         pop        ds
  328.  
  329. @@Exit:
  330.         lds        si,[chipID]        ; Load the address of chip ID in DS:SI
  331.         mov        ax,[VideoChipID]; AX := value of internal chip ID
  332.         mov        [si],ax            ; Store the chip ID value
  333.         lds        si,[memory]
  334.         mov        ax,[VideoMem]
  335.         mov        [si],ax
  336.         lds        si,[dac]
  337.         mov        ax,[DacType]
  338.         mov        [si],ax            ; Store dac type
  339.         pop        ds
  340.         popa
  341.         leave
  342.         ret
  343.  
  344. procend        _MGL_detectGraph
  345.  
  346. ;----------------------------------------------------------------------------
  347. ; char far * _getSuperVGAModes(void)
  348. ;----------------------------------------------------------------------------
  349. ; Returns the address of the list of available video modes.
  350. ;----------------------------------------------------------------------------
  351. procstart    __getSuperVGAModes
  352.  
  353.         mov        dx,seg DefModes
  354.         mov        ax,[WORD VideoModes]
  355.         ret
  356.  
  357. procend        __getSuperVGAModes
  358.  
  359. ;----------------------------------------------------------------------------
  360. ; int _getSuperVGAPages(int mode,int memory,long *pagesize)
  361. ;----------------------------------------------------------------------------
  362. ; Returns the number of available video pages for a specific video mode.
  363. ; It also returns the size in bytes of each video page (rounded to the
  364. ; nearest bank value).
  365. ;----------------------------------------------------------------------------
  366. procstart    __getSuperVGAPages
  367.  
  368.         ARG        mode:WORD, memory:WORD, pagesize:DWORD
  369.  
  370.         enter    0,0
  371.         push    di
  372.  
  373.         mov        ax,[mode]
  374.         mov        cx,ax
  375.         and        ax,7Fh
  376.         xor        ebx,ebx
  377.         mov        bx,[memory]
  378.         test    cx,80h
  379.         jnz        @@ExtendedPageFlip
  380.         cmp        [PageFlip],true
  381.         je        @@ExtendedPageFlip
  382.  
  383. ; Extended page flipping is not available, so calculate pages using only
  384. ; 256k of memory.
  385.  
  386.         cmp        ax,grVGA_320x200x256
  387.         jl        @@VGAMode
  388.         mov        ax,1
  389.         jmp        @@Done
  390.  
  391. @@VGAMode:
  392.         mov        bx,256
  393.  
  394. @@ExtendedPageFlip:
  395.         shl        ebx,10
  396.         call    numPages
  397.         les        di,[pagesize]
  398.         mov        [es:di],ebx            ; Store the page size for later
  399.  
  400. @@Done:
  401.         pop        di
  402.         leave
  403.         ret
  404.  
  405. procend        __getSuperVGAPages
  406.  
  407. ;****************************************************************************
  408. ;
  409. ; Internal routines used by the detectgraph routine.
  410. ;
  411. ;****************************************************************************
  412.  
  413. ;----------------------------------------------------------------------------
  414. ; FindPS2    Determine if a PS2 is out there, and get susbsystem types
  415. ;----------------------------------------------------------------------------
  416. ;
  417. ; Routine calls INT10h function 1Ah to determine the video BIOS
  418. ; Display Combination Code (DCC) for each video subsystem. If the
  419. ; PS2 BIOS is not out there, then none of the regs are changed. If
  420. ; it is out there, then 1Ah comes back in AL. If there is a PS/2 BIOS, we
  421. ; only use it to detect the VGA and MCGA adapters.
  422. ;
  423. ; Entry:        DS:DI    ->    Address of driver variable
  424. ;                ES:SI    ->    Address of mode variable
  425. ;
  426. ; Exit:            Carry flag is set if an MCGA,VGA,SVGA was detected
  427. ;
  428. ; Registers:    AX,BX,CX
  429. ;
  430. ;----------------------------------------------------------------------------
  431. PROC    FindPS2 near
  432.  
  433.         mov        ax,1A00h        ; call video BIOS for info
  434.         int        10h
  435.  
  436.         cmp        al,1Ah            ; Is the BIOS out there (1Ah in AL)
  437.         clc
  438.         jne        @@Exit
  439.  
  440. ; Determine if VGA,MCGA,SVGA present from BIOS DCC's
  441.  
  442.         mov        cl,bh            ; BL := active subsystem, BH := inactive
  443.         xor        bh,bh            ; BX := DCC of active subsystem
  444.         xor        ch,ch            ; CX := DCC of inactive subsystem
  445.  
  446.         cmp        bx,07h            ; Active VGA Mono?
  447.         je        @@VGA
  448.         cmp        cx,07h            ; Inactive VGA Mono?
  449.         je        @@VGA
  450.         cmp        bx,08h            ; Active VGA Color?
  451.         je        @@VGA
  452.         cmp        cx,08h            ; Inactive VGA Color?
  453.         jne        @@CheckMCGA
  454. @@VGA:
  455.         mov        [WORD DS:DI],grVGA
  456.         mov        [WORD ES:SI],grVGA_640x480x16
  457.  
  458.         push    ds
  459.         mov        ds,[cs:SaveDS]    ; Address data segment
  460.         cmp        [__ignoreSVGA],1
  461.         pop        ds
  462.         je        @@SkipSVGA
  463.  
  464.         call    FindSuperVGA    ; Check to see if a SuperVGA is out there
  465.  
  466. @@SkipSVGA:
  467.         stc                     ; We at least found a VGA card
  468.         jmp        @@Exit
  469.  
  470. @@CheckMCGA:
  471.         cmp        bx,0Ch            ; Active MCGA color?
  472.         je        @@MCGA
  473.         cmp        cx,0Ch            ; Inactive MCGA color?
  474.         clc
  475.         jne        @@Exit
  476.  
  477. @@MCGA:
  478.         mov        [WORD DS:DI],grMCGA
  479.         mov        [WORD DS:SI],grVGA_320x200x256
  480.         stc                        ; Set the carry flag
  481.  
  482. @@Exit:
  483.         ret
  484.  
  485. ENDP    FindPS2
  486.  
  487. ;----------------------------------------------------------------------------
  488. ; FindEGA    Determine if an EGA is out there and get system configuration
  489. ;----------------------------------------------------------------------------
  490. ;
  491. ; Routine calls INT10h function 12h to get the EGA BIOS to return system
  492. ; configuration info. If the EGA BIOS is not there, then the regs return
  493. ; unscathed. Specifically, if BH changes, then the EGA is out there.
  494. ;
  495. ; Entry:        DS:DI    ->    Address of driver variable
  496. ;                ES:SI    ->    Address of mode variable
  497. ;
  498. ; Exit:            Carry flag set if an EGA was detected
  499. ;
  500. ; Registers:    AX,BX,CX
  501. ;
  502. ;----------------------------------------------------------------------------
  503. PROC    FindEGA near
  504.  
  505.         mov        bl,10h            ; BL := 10h (return ega info)
  506.         mov        ah,12h            ; AH := INT10h function number
  507.         int        10h                ; Call EGA BIOS for info.
  508.                                 ; If EGA is present, BL <> 10h and
  509.                                 ; CL = EGA switch settings
  510.         cmp        bl,10h
  511.         clc
  512.         je        @@Exit            ; jump if EGA BIOS not present
  513.  
  514.         and        bl,3            ; Mask out the Video Ram bits
  515.         push    bx                ; Save Video Ram bits on stack
  516.  
  517.         mov        al,cl            ; AL := configuration switches
  518.         xor        ah,ah            ; AX := configuration switches
  519.         and        al,11111110b    ; Mask bit 1
  520.         mov        bx,offset cs:EGADisplays
  521.         add        bx,ax            ; Index into table
  522.         xor        ah,ah
  523.         mov        al,[cs:bx]        ; Translate code
  524.         mov        [WORD DS:DI],ax
  525.         mov        al,[cs:bx + 1]
  526.         mov        [WORD ES:SI],ax
  527.  
  528.         pop        cx                ; Restore Video Ram Bits
  529.         or        cx,cx            ; 64kb of EGA RAM?
  530.         stc
  531.         jne        @@Exit            ; We are done...
  532.         inc        [WORD DS:DI]    ; Convert to EGA64 and EGA64MONO
  533.         stc
  534.  
  535. @@Exit:
  536.         ret
  537.  
  538. ENDP    FindEGA
  539.  
  540. ;----------------------------------------------------------------------------
  541. ; FindCGA    Determine if a CGA adapter is out there and get info
  542. ;----------------------------------------------------------------------------
  543. ;
  544. ; Routine checks for a CGA by looking for the CGA's 6845 CRTC at I/O port
  545. ; 3D4h.
  546. ;
  547. ; Entry:        DS:DI    ->    Address of driver variable
  548. ;                ES:SI    ->    Address of mode variable
  549. ;
  550. ; Exit:            Carry flag set if a CGA was detected
  551. ;
  552. ; Registers:    AX,BX,CX,DX
  553. ;
  554. ;----------------------------------------------------------------------------
  555. PROC    FindCGA        near
  556.  
  557.         mov        dx,3D4h            ; DX := CRTC address port
  558.         call    Find6845
  559.         jnc        @@Exit
  560.  
  561.         mov        [WORD DS:DI],grCGA
  562.         mov        [WORD ES:SI],0
  563.         stc                        ; Set carry flag
  564.  
  565. @@Exit:
  566.         ret
  567.  
  568. ENDP    FindCGA
  569.  
  570. ;----------------------------------------------------------------------------
  571. ; FindHGC    Determine if a Hercules card is out there.
  572. ;----------------------------------------------------------------------------
  573. ;
  574. ; This is done by looking for the MDA's 6845 CRTC at I/O port 3B4h. If
  575. ; a 6845 is found, the subroutine distinguishes between an MDA and a
  576. ; Hercules adapter by monitoring bit 7 of the CRT Staus byte. This bit
  577. ; changes on Hercules adapters but does not change on an MDA.
  578. ;
  579. ; Entry:        DS:DI    ->    Address of driver variable
  580. ;                ES:SI    ->    Address of mode variable
  581. ;
  582. ; Exit:            Carry flag set if an HGC was detected
  583. ;
  584. ; Registers:    AX,BX,CX,DX
  585. ;
  586. ;----------------------------------------------------------------------------
  587. PROC    FindHGC    near
  588.  
  589.         mov        dx,3B4h            ; DX := CRTC address port
  590.         call    Find6845
  591.         jnc        @@Exit            ; jump if not present
  592.  
  593.         mov        dx,3BAh            ; DX := 3BAh (Status port)
  594.         in        al,dx
  595.         and        al,80h
  596.         mov        ah,al            ; AH := bit 7 (Vertical sync on HGC)
  597.         mov        cx,8000h        ; do this 32768 times
  598.  
  599. @@WaitForChange:
  600.         in        al,dx
  601.         and        al,80h            ; isolate bit 7
  602.         cmp        ah,al
  603.         loope    @@WaitForChange    ; wait for bit 7 to change
  604.  
  605.         clc
  606.         je        @@Exit            ; if bit 7 didn't change, it's an MDA
  607.  
  608.         mov        [WORD DS:DI],grHERCMONO
  609.         mov        [WORD ES:SI],0
  610.         stc
  611.  
  612. @@Exit:
  613.         ret
  614.  
  615. ENDP    FindHGC
  616.  
  617. ;----------------------------------------------------------------------------
  618. ; FindDAC    Routine to detect the presence of HiColor and TrueColor DAC's
  619. ;----------------------------------------------------------------------------
  620. ;
  621. ; This routine attempts to determine the type of RAM dac installed in the
  622. ; video card. This can be used by the following detection routines to
  623. ; determine if HiColor or TrueColor video mode support should be included
  624. ; in the video mode tables.
  625. ;
  626. ; Exit:            DacType updated with Video DAC type
  627. ;
  628. ; Registers:    AX,BX,CX,DX
  629. ;
  630. ;----------------------------------------------------------------------------
  631. PROC    FindDAC
  632.  
  633.         push    si
  634.         push    di
  635.  
  636. ; Test for the SS24 TrueColor DAC first.
  637.  
  638.         DacToPel
  639.         in        al,dx                ; Wait for the same value twice
  640. @@L1:    mov        bl,al
  641.         in        al,dx
  642.         cmp        al,bl
  643.         jne        @@L1
  644.         DacToCommand
  645.         cmp        al,8Eh
  646.         je        @@HaveSS24            ; We have an SS24 TrueColor DAC
  647.         mov        cx,8
  648. @@L2:    in        al,dx
  649.         cmp        al,8Eh
  650.         je        @@HaveSS24            ; Found an SS24 TrueColor DAC
  651.         loop    @@L2
  652.  
  653. ; Save the state of the command and PEL registers
  654.  
  655.         DacToCommand
  656.         in        al,dx
  657.         mov        si,ax                ; SI := Old value of command register
  658.         DacToPel
  659.         in        al,dx
  660.         mov        di,ax                ; DI := Old value of PEL register
  661.  
  662.         mov        ax,si
  663.         xor        al,0FFh                ; AL := old command reg XOR FFh
  664.         mov        bl,al                ; Save value in BL
  665.         out        dx,al                ; Write value to PEL register
  666.         DacToCommand
  667.         in        al,dx                ; Read value of command register
  668.         cmp        al,bl                ; If value are the same, Normal DAC
  669.         je        @@NormalDAC            ; Normal DAC, so reset PEL reg and exit
  670.  
  671. ; We have a HiColor or TrueColor DAC of some type, so figure out what
  672. ; sort it is.
  673.  
  674.         DacToCommand
  675.         mov        ax,si
  676.         xor        al,60h                ; AL := Old command reg XOR 60h
  677.         mov        bl,al                ; Save value in BL
  678.         out        dx,al                ; Write to command register
  679.         DacToCommand
  680.         in        al,dx
  681.         and        al,0E0h
  682.         and        bl,0E0h
  683.         cmp        al,bl
  684.         jne        @@HaveHiColor        ; Found an SC11486 HiColor DAC
  685.  
  686.         in        al,dx
  687.         mov        bl,al
  688.         DacToPel
  689.         in        al,dx
  690.         cmp        al,bl
  691.         je        @@HaveTrueColor        ; Must be an ATT 20c491/2 or some other DAC
  692.  
  693. ; Fall through for Sierra 32k/64k DAC's
  694.  
  695. @@HaveHiColor:
  696.         mov        ax,grHCDAC            ; DAC is HiColor
  697.         mov        [DacType],ax
  698.         jmp        @@ResetCommand
  699.  
  700. @@HaveTrueColor:
  701.         mov        ax,grTCDAC            ; DAC is TrueColor
  702.         mov        [DacType],ax
  703.  
  704. @@ResetCommand:
  705.         DacToCommand
  706.         mov        ax,si                ; AL := Old value of command register
  707.         out        dx,al
  708.  
  709. @@NormalDAC:
  710.         DacToPel
  711.         mov        ax,di                ; AL := Old value of PEL register
  712.         out        dx,al                ; Reset to old value
  713.         jmp        @@Exit
  714.  
  715. @@HaveSS24:
  716.         mov        ax,grTCDAC            ; SS24 is TrueColor DAC
  717.         mov        [DacType],ax
  718.         jmp        @@Exit
  719.  
  720. @@Exit:
  721.         mov        ax,[ForceDAC]        ; Get value of forced DAC
  722.         or        ax,ax                ; Negative if we dont want to force
  723.         js        @@1
  724.         mov        [DacType],ax        ; Force the dac type
  725. @@1:    pop        si
  726.         pop        di
  727.         ret
  728.  
  729. ENDP    FindDAC
  730.  
  731. ;----------------------------------------------------------------------------
  732. ; FindSuperVGA    Determine if a SuperVGA is out there, and get information
  733. ;----------------------------------------------------------------------------
  734. ;
  735. ; Routine performs a number of SuperVGA detection routines to determine
  736. ; if a SuperVGA video card is out there. If one is found, we set the driver
  737. ; variable to reflect this and exit. Note that we also detect how much
  738. ; memory is present on the card and what video modes are available.
  739. ;
  740. ; This code first appeared in John Bridges VGAKIT library, however it has
  741. ; been factorised into a number of independant functions to detect each
  742. ; video card.
  743. ;
  744. ; Entry:        DS:DI    ->    Address of driver variable
  745. ;
  746. ; Exit:            Carry flag is set if a SuperVGA was detected
  747. ;
  748. ; Registers:    AX,BX,CX,DX
  749. ;
  750. ;----------------------------------------------------------------------------
  751. PROC    FindSuperVGA    near
  752.  
  753.         push    ds
  754.         push    es
  755.         push    si
  756.         push    di
  757.  
  758.         call    FindDAC                ; Detect the Video DAC installed
  759.  
  760.         mov        [PageFlip],false    ; Default to no page flipping
  761.  
  762.         push    ds
  763.         mov        ds,[cs:SaveDS]        ; Address data segment
  764.         cmp        [__VESAFirst],1        ; Check _VESAFirst flag
  765.         pop        ds
  766.         jne        @@SkipVESA
  767.  
  768.         check    VESA
  769.  
  770. @@SkipVESA:
  771.         check    Chips
  772.         check    Paradise
  773.         check    Video7
  774.         check    Genoa
  775.         check    Everex
  776.         check    Trident
  777.         check    ATI
  778.         check    Ahead
  779.         check    NCR
  780.         check    S3
  781.         check    AL2101
  782.         check    MXIC
  783.         check    Cirrus
  784.         check    AcuMos
  785.         check    Tseng
  786.         check    RT3106
  787.         check    P2000
  788.         check    Oaktech
  789.         check    VESA
  790.  
  791.         pop        di
  792.         pop        si
  793.         pop        es
  794.         pop        ds
  795.         clc
  796.         ret
  797.  
  798. @@FoundOne:
  799.         pop        di
  800.         pop        si
  801.         pop        es
  802.         pop        ds
  803.         mov        [WORD ds:di],ax    ; Store the SuperVGA card identifier
  804.         stc
  805.         ret
  806.  
  807. ENDP    FindSuperVGA
  808.  
  809. ;----------------------------------------------------------------------------
  810. ; UnsupportedMode    Flags a video mode as unsupported for this card
  811. ;----------------------------------------------------------------------------
  812. ;
  813. ; Flags a video mode as unsupported for this video card, by writing a
  814. ; zero into the position where the mode is located.
  815. ;
  816. ; Entry:        AL    - Number of unsupported mode
  817. ;                BX    - Offset of video mode table
  818. ;
  819. ; Exit:            BX    - Offset of video mode table
  820. ;
  821. ; Registers:    AX,BX
  822. ;
  823. ;----------------------------------------------------------------------------
  824. PROC    UnsupportedMode
  825.  
  826. ; Find the index of the video mode
  827.  
  828.         push    bx
  829. @@Loop:
  830.         mov        ah,[BYTE cs:bx]
  831.         cmp        ah,al                ; Found the video mode?
  832.         je        @@FoundIt
  833.         cmp        ah,-1
  834.         je        @@Exit
  835.         inc        bx
  836.         jmp        @@Loop
  837.  
  838. @@FoundIt:
  839.         mov        [BYTE cs:bx],0
  840. @@Exit:
  841.         pop        bx
  842.         ret
  843.  
  844. ENDP    UnsupportedMode
  845.  
  846. ;----------------------------------------------------------------------------
  847. ; FindVESA    Detect the presence of VESA Compatible SuperVGA board
  848. ;----------------------------------------------------------------------------
  849. ;
  850. ; Routine detects if the SuperVGA boards is present and determines how much
  851. ; memory is on it.
  852. ;
  853. ; Exit:            Carry flag is set if board was detected
  854. ;
  855. ;                AX                - Video card identifier
  856. ;                [VideoMem]        - Amount of video memory on board
  857. ;
  858. ;----------------------------------------------------------------------------
  859. PROC    FindVESA    near
  860.  
  861. ; Check to see if a VESA extended video BIOS is out there. If it is,
  862. ; we have a Super VGA card.
  863.  
  864.         mov        ax,seg VesaBuf
  865.         mov        es,ax
  866.         mov        di,offset VesaBuf
  867.         mov        ax,04F00h
  868.         int        10h                ; Call the VESA video BIOS
  869.         cmp        ax,004Fh
  870.         jne        @@NoVESA
  871.         cmp        [WORD es:di],'EV'
  872.         jne        @@NoVESA
  873.         cmp        [WORD es:di+2],'AS'
  874.         jne        @@NoVESA
  875.  
  876. ; We have a VESA compatible SuperVGA, so determine how much memory must
  877. ; be on the video board by finding the amount of memory used by the
  878. ; highest resolution video mode supported.
  879. ;
  880. ; At the same time initialise the table of valid video modes for this
  881. ; SuperVGA, and bytes per line values for the video mode.
  882.  
  883.         push    ds
  884.         push    bp
  885.         mov        ax,[WORD es:di+16]
  886.         mov        ds,ax
  887.         mov        bp,[WORD es:di+14]    ; DS:BP -> List of valid VESA modes
  888.         mov     si,offset AllVesaModes
  889.         mov        bx,offset VesaModes
  890.         cld
  891.  
  892. @@VesaMemLoop:
  893.         lods    [WORD cs:si]        ; Load VESA mode number
  894.         mov        cx,ax
  895.         jcxz    @@EndVESA            ; Finished when mode number is zero
  896.         lods    [WORD cs:si]        ; Load amount of memory required for mode
  897.         push    ax                  ;   and save on stack
  898.         lods    [WORD cs:si]        ; Load MGL video mode number
  899.         push    ax                    ;   and save on stack
  900.  
  901. ; First check to see if the mode is a valid VESA mode.
  902.  
  903.         mov        di,bp                ; DS:DI -> mode list
  904. @@CheckMode:
  905.         mov        ax,[WORD ds:di]
  906.         inc        di
  907.         inc        di
  908.         cmp        ax,-1
  909.         je        @@NotFound
  910.         cmp        ax,cx
  911.         je        @@FoundMode            ; Yes mode was found
  912.         jmp        @@CheckMode            ; Loop for all valid modes
  913.  
  914. @@NotFound:
  915.         pop        ax                    ; Restore stack
  916.         pop        ax
  917.         jmp        @@VesaMemLoop        ; Continue loop
  918.  
  919. @@FoundMode:
  920.         mov        ax,seg VesaBuf
  921.         mov        es,ax
  922.         mov        di,offset VesaBuf
  923.         mov        ax,4F01h            ; AX := Query Mode Information
  924.         int        10h
  925.         pop        dx                    ; DX := MGL Mode Number
  926.         pop        cx                    ; CX := Video memory required
  927.         or        ah,ah
  928.         jnz        @@VesaMemLoop        ; Mode not supported, try next one
  929.         test    [BYTE es:di],1
  930.         jz        @@VesaMemLoop        ; Mode not supported, try next one
  931.  
  932. ; Video mode is supported, so add to mode table.
  933.  
  934.         push    bx
  935.         mov        bx,[WORD es:di+16]
  936.         mov        ax,dx
  937.         call    setBytesPerLine        ; Set the bytes per line value for mode
  938.         pop        bx
  939.         mov        [BYTE cs:bx],dl        ; Store the mode number
  940.         inc        bx
  941.  
  942.         cmp        cx,[WORD VideoMem]
  943.         jle        @@VesaMemLoop        ; Memory is less, try next mode
  944.         mov        [WORD VideoMem],cx    ; Increase the memory size
  945.         jmp        @@VesaMemLoop
  946.  
  947. @@EndVESA:
  948.         pop        bp
  949.         pop        ds
  950.         call    checkVESAPageFlip    ; Does VESA support page flipping?
  951.         jc        @@NoFlip
  952.         mov        [PageFlip],true
  953.  
  954. @@NoFlip:
  955.         mov        [WORD VideoModes],offset VesaModes
  956.         mov        ax,grSVGA
  957.         stc
  958.         ret
  959.  
  960. @@NoVESA:
  961.         clc
  962.         ret
  963.  
  964. ENDP    FindVESA
  965.  
  966. ;----------------------------------------------------------------------------
  967. ; FindS3    Detect the presence of an S3 based SuperVGA board
  968. ;----------------------------------------------------------------------------
  969. ;
  970. ; Routine detects if the SuperVGA boards is present and determines how much
  971. ; memory is on it.
  972. ;
  973. ; Exit:            Carry flag is set if board was detected
  974. ;
  975. ;                AX                - Video card identifier
  976. ;                [VideoMem]        - Amount of video memory on board
  977. ;                [VideoChipID]    - Chip revision id
  978. ;
  979. ;----------------------------------------------------------------------------
  980. PROC    FindS3    near
  981.  
  982.         wrinx    CRTC, 38h, 0    ; Lock S3 extended registers
  983.         tstinx    CRTC, 35h, 0Fh    ; Check for locked S3 bank switch register
  984.         jz        @@NoS3            ; Bank reg was writeable, not an S3
  985.  
  986.         wrinx    CRTC, 38h, 48h    ; Unlock S3 extended registers
  987.         tstinx    CRTC, 35h, 0Fh    ; Check for unlocked S3 bank switch register
  988.         jnz        @@NoS3            ; Test failed, not an S3
  989.  
  990. ; Determine the chip ID for the video card and save it for later
  991.  
  992.         rdinx    CRTC, 30h        ; Read chip ID register
  993.         mov        bx,grS3_928
  994.         cmp        al,90h
  995.         je        @@FindMem        ; We have an 86c928 chip
  996.         mov        bx,grS3_801_805
  997.         cmp        al,0A0h
  998.         je        @@FindMem        ; We have an 86c801/86c805 chip
  999.         mov        bx,grS3_924
  1000.         cmp        al,82h
  1001.         je        @@FindMem        ; We have an 86c924 chip
  1002.         mov        bx,grS3_911        ; Fall through for the 86c911 chip
  1003.  
  1004. ; Determine how much video RAM is on the card
  1005.  
  1006. @@FindMem:
  1007.         mov        [VideoChipID],bx; Save the chip ID
  1008.         rdinx    CRTC, 36h        ; Read configuration register 1
  1009.         and        al,11100000b    ; Mask out bits 7-5
  1010.         cmp        bx,grS3_924
  1011.         jle        @@Mem911
  1012.  
  1013. ; We have an 86c801/805/928 based S3.
  1014.  
  1015.         mov        [WORD VideoMem],512
  1016.         cmp        al,11100000b
  1017.         je        @@DoneMem        ; Card has 512k on board
  1018.         mov        [WORD VideoMem],1024
  1019.         cmp        al,11000000b
  1020.         je        @@DoneMem        ; Card has 1Mb on board
  1021.         mov        [WORD VideoMem],2048
  1022.         cmp        al,10000000b
  1023.         je        @@DoneMem        ; Card has 2Mb on board
  1024.         mov        [WORD VideoMem],3072
  1025.         cmp        al,01000000b
  1026.         je        @@DoneMem        ; Card has 3Mb on board
  1027.         mov        [WORD VideoMem],4096
  1028.         jmp        @@DoneMem        ; Card has 4Mb on board
  1029.  
  1030. ; We have an 86c911/924.
  1031.  
  1032. @@Mem911:
  1033.         mov        [WORD VideoMem],512
  1034.         test    al,100000b        ; Bit 5 is set for 512k
  1035.         jnz        @@DoneMem
  1036.         mov        [WORD VideoMem],1024
  1037.  
  1038. @@DoneMem:
  1039.         wrinx    CRTC, 38h, 0    ; Lock S3 extended registers
  1040.  
  1041.         call    ModifyS3BytesPerLine
  1042.         mov        [PageFlip],true    ; Card supports extended page flipping
  1043.         Add32kColor        S332KModes
  1044.         AddTrueColor    S3TCModes
  1045.         mov        [WORD VideoModes],offset S3Modes
  1046.         mov        ax,grSVGA_S3
  1047.         stc
  1048.         ret
  1049.  
  1050. @@NoS3:
  1051.         clc
  1052.         ret
  1053.  
  1054. ENDP    FindS3
  1055.  
  1056. ;----------------------------------------------------------------------------
  1057. ; FindATI    Detect the presence of an ATI Technologies SuperVGA board
  1058. ;----------------------------------------------------------------------------
  1059. ;
  1060. ; Routine detects if the SuperVGA boards is present and determines how much
  1061. ; memory is on it.
  1062. ;
  1063. ; Exit:            Carry flag is set if board was detected
  1064. ;
  1065. ;                AX                - Video card identifier
  1066. ;                [VideoMem]        - Amount of video memory on board
  1067. ;                [VideoChipID]    - Chip revision id
  1068. ;
  1069. ;----------------------------------------------------------------------------
  1070. PROC    FindATI    near
  1071.  
  1072.         mov        ax,0C000h
  1073.         mov        es,ax
  1074.         cmp        [WORD es:40h],'13'    ; ATI Signature for VGA cards
  1075.         jne        @@NoATI
  1076.  
  1077. ; Check for the ATI product code string '761295520'
  1078.  
  1079.         cmp        [WORD es:31h],'67'
  1080.         jne        @@NoATI
  1081.         cmp        [WORD es:31h+2],'21'
  1082.         jne        @@NoATI
  1083.         cmp        [WORD es:31h+4],'59'
  1084.         jne        @@NoATI
  1085.         cmp        [WORD es:31h+6],'25'
  1086.         jne        @@NoATI
  1087.         cmp        [BYTE es:31h+8],'0'
  1088.         jne        @@NoATI
  1089.  
  1090.         mov        dx,1CEh                ; DX := port of ATI extended registers
  1091.         mov        bl,[BYTE es:43h]    ; BL := ATI Chip Version
  1092.         cmp        bl,'3'
  1093.         jae        @@Ver6up            ; Check for memory on later chip versions
  1094.  
  1095.         mov        [VideoChipID],grATI_18800_1
  1096.         cmp        bl,'1'
  1097.         jne        @@Not18800
  1098.  
  1099. ; Remove unsupported video modes for (18800 chip)
  1100.  
  1101.         mov        [VideoChipID],grATI_18800
  1102.         ClearMode    grSVGA_1024x768x16, ATIModes
  1103.  
  1104. ; Determine the memory size on chip versions 3-4 (18800, 18800-1)
  1105.  
  1106. @@Not18800:
  1107.         rdinx    1CEh, 0BBh            ; Get RamSize bits
  1108.         and        al,20h
  1109.         jz        @@DoneATI
  1110.  
  1111.         mov        [WORD VideoMem],512    ; Card has 512kb of memory
  1112.         jmp        @@DoneATI
  1113.  
  1114. ; Determine memory size on chip versions 6+ (28800-2, 28800-4, 28800-5)
  1115.  
  1116. @@Ver6up:
  1117.         mov        [VideoChipID],grATI_28800_2
  1118.         rdinx    1CEh, 0B0h            ; Get RamSize bits
  1119.         test    al,10h                ; Check if RamSize is 256k or 512k
  1120.         jz        @@Ver7Check
  1121.         mov        [WORD VideoMem],512    ; Card has at least 512k of memory
  1122.  
  1123. @@Ver7Check:
  1124.         cmp        bl,'4'
  1125.         jb        @@DoneATI            ; Done for version 6 chips
  1126.         mov        [VideoChipID],grATI_28800_4
  1127.         cmp        bl,'5'
  1128.         jb        @@Not28800_5
  1129.         mov        [VideoChipID],grATI_28800_5
  1130.  
  1131. @@Not28800_5:
  1132.         test    al,8                ; Check version 7+ chip memory size
  1133.         jz        @@DoneATI
  1134.         mov        [WORD VideoMem],1024; Card has 1024k of memory
  1135.  
  1136. @@DoneATI:
  1137.         mov        [DacType],grVGADAC    ; Default to normal DAC
  1138.         test    [BYTE es:44h],8        ; Check bit 7 for HiColor DAC
  1139.         jz        @@NoHiColor
  1140.  
  1141.         mov        [DacType],grHCDAC    ; We have a 15 bit HiColor DAC
  1142.         Add32kColor    ATI32KModes
  1143.  
  1144. @@NoHiColor:
  1145.         mov        [PageFlip],true        ; Card supports extended page flipping
  1146.         mov        [WORD VideoModes],offset ATIModes
  1147.         mov        ax,grSVGA_ATI
  1148.         stc
  1149.         ret
  1150.  
  1151. @@NoATI:
  1152.         clc
  1153.         ret
  1154.  
  1155. ENDP    FindATI
  1156.  
  1157. ;----------------------------------------------------------------------------
  1158. ; FindNCR    Detect the presence of the NCR 77C22E SuperVGA boards
  1159. ;----------------------------------------------------------------------------
  1160. ;
  1161. ; Routine detects if the SuperVGA boards is present and determines how much
  1162. ; memory is on it.
  1163. ;
  1164. ; Exit:            Carry flag is set if board was detected
  1165. ;
  1166. ;                AX                - Video card identifier
  1167. ;                [VideoMem]        - Amount of video memory on board
  1168. ;                [VideoChipID]    - Chip revision id
  1169. ;
  1170. ;----------------------------------------------------------------------------
  1171. PROC    FindNCR    near
  1172.  
  1173.         tstinx    3C4h, 5, 5            ; Test for extended register enable chip
  1174.         jnz        @@NoNCR                ; Check failed, so not an NCR
  1175.  
  1176.         wrinx    3C4h, 5, 0            ; Disable extended registers
  1177.         tstinx    3C4h, 10h, 0FFh        ; Test Cursor location y register
  1178.         jz        @@NoNCR                ; Reg was writeable, so test failed
  1179.  
  1180.         wrinx    3C4h, 5, 1            ; Enable extended registers
  1181.         tstinx    3C4h, 10h, 0FFh        ; Test Cursor location y register
  1182.         jnz        @@NoNCR                ; Reg was not writeable, so not NCR
  1183.  
  1184. ; Determine the chip revision
  1185.  
  1186.         rdinx    3C4h, 8                ; Get chip version number
  1187.         shr        al,4
  1188.         cmp        al,2
  1189.         jae        @@NCR77C22E
  1190.  
  1191. ; We have an NCR77C20/21 chip. These do not support certain modes.
  1192.  
  1193.         ClearMode    grSVGA_1280x1024x16, NCRModes
  1194.         ClearMode    grSVGA_1024x768x256, NCRModes
  1195.         ClearMode    grSVGA_1280x1024x256, NCRModes
  1196.  
  1197. @@NCR77C22E:
  1198.         mov        ax,4096                ; Maximum of 4Mb memory
  1199.         mov        bx,offset NCRSwitch    ; Offset of bank switch routine
  1200.         mov        cx,5Eh                ; Values to set 640x400x256
  1201.         xor        dx,dx
  1202.         call    CheckMem            ; Manually check amount of memory
  1203.  
  1204.         mov        [PageFlip],true        ; Card supports extended page flipping
  1205.         Add32kColor    NCR32KModes
  1206.         mov        [WORD VideoModes],offset NCRModes
  1207.         mov        ax,grSVGA_NCR
  1208.         stc
  1209.         ret
  1210.  
  1211. @@NoNCR:
  1212.         clc
  1213.         ret
  1214.  
  1215. ENDP    FindNCR
  1216.  
  1217. ;----------------------------------------------------------------------------
  1218. ; FindTrident    Detect the presence of the Trident SuperVGA boards
  1219. ;----------------------------------------------------------------------------
  1220. ;
  1221. ; Routine detects if the SuperVGA boards is present and determines how much
  1222. ; memory is on it.
  1223. ;
  1224. ; Exit:            Carry flag is set if board was detected
  1225. ;
  1226. ;                AX                - Video card identifier
  1227. ;                [VideoMem]        - Amount of video memory on board
  1228. ;                [VideoChipID]    - Chip revision id
  1229. ;
  1230. ;----------------------------------------------------------------------------
  1231. PROC    FindTrident    near
  1232.  
  1233. ; When we force the old defintions on Trident TVGA's, they tend to hang up
  1234. ; if you do it with a 16 bit port instruction. Doing it with 8 bit
  1235. ; instructions fixes the problem (seems to happen on older cards).
  1236. ;
  1237. ; Note that the test in VGADOC that writes stuff to the bank switch
  1238. ; registers causes some TVGA's to hang up severly (the one I tested it on
  1239. ; it did). Seems that if you reset the card by setting a video mode before
  1240. ; doing any bank switching, the problem goes away, but if you dont do this,
  1241. ; the machine goes off into the never never ...
  1242.  
  1243.         mov        dx,3C4h
  1244.         mov        al,0Bh
  1245.         out        dx,al
  1246.         inc        dl
  1247.         xor        al,al
  1248.         out        dx,al                ; Force old definitions
  1249.         in        al,dx                ; Force new definitions
  1250.         and        al,0Fh
  1251.         cmp        al,2
  1252.         jb        @@NoTrident            ; Trident 8800BR only has 128k banks
  1253.         cmp        al,2
  1254.         je        @@Trident88            ; We have a Trident 8800CS
  1255.  
  1256. ; Must be a Trident 8900, 8900C or 9000
  1257.  
  1258.         rdinx    CRTC, 1Fh            ; Read memory size register
  1259.         and        al,3
  1260.         cmp        al,1
  1261.         jb        @@LowMem
  1262.         mov        [WORD VideoMem],512        ; Card has 512kb of memory
  1263.         cmp        al,3
  1264.         jb        @@LowMem
  1265.         mov        [WORD VideoMem],1024    ; Card has 1Mb of memory
  1266.  
  1267. @@LowMem:
  1268.         mov        [PageFlip],true        ; Card supports extended page flipping
  1269.         mov        [WORD VideoModes],offset Trident89Modes
  1270.         mov        ax,grSVGA_TRIDENT89
  1271.         stc
  1272.         ret
  1273.  
  1274. @@Trident88:
  1275.         rdinx    CRTC, 1Fh            ; Read memory size register
  1276.         and        al,2
  1277.         jz        @@LowMem88
  1278.         mov        [WORD VideoMem],512        ; Card has 512kb of memory
  1279.  
  1280. @@LowMem88:
  1281.         mov        [PageFlip],true        ; Card supports extended page flipping
  1282.         mov        [WORD VideoModes],offset Trident88Modes
  1283.         mov        ax,grSVGA_TRIDENT88
  1284.         stc
  1285.         ret
  1286.  
  1287. @@NoTrident:
  1288.         clc
  1289.         ret
  1290.  
  1291. ENDP    FindTrident
  1292.  
  1293. ;----------------------------------------------------------------------------
  1294. ; FindVideo7    Detect the presence of a Video7 SuperVGA board
  1295. ;----------------------------------------------------------------------------
  1296. ;
  1297. ; Routine detects if the SuperVGA boards is present and determines how much
  1298. ; memory is on it.
  1299. ;
  1300. ; Exit:            Carry flag is set if board was detected
  1301. ;
  1302. ;                AX                - Video card identifier
  1303. ;                [VideoMem]        - Amount of video memory on board
  1304. ;                [VideoChipID]    - Chip revision id
  1305. ;
  1306. ;----------------------------------------------------------------------------
  1307. PROC    FindVideo7    near
  1308.  
  1309.         mov        ax,6F00h
  1310.         xor        bx,bx
  1311.         int        10h
  1312.         cmp        bx,'V7'
  1313.         jnz        @@NoVideo7
  1314.  
  1315.         mov        ax,6F07h            ; Determine how much memory is present
  1316.         int        10h
  1317.         and        ah,7Fh
  1318.         cmp        ah,2
  1319.         jb        @@1
  1320.         mov        [WORD VideoMem],512        ; Card has 512kb of memory
  1321. @@1:    cmp        ah,4
  1322.         jb        @@2
  1323.         mov        [WORD VideoMem],1024
  1324. @@2:    mov        [WORD VideoModes],offset Video7Modes
  1325.         mov        [PageFlip],true        ; Card supports extended page flipping
  1326.         mov        ax,grSVGA_VIDEO7
  1327.         stc
  1328.         ret
  1329.  
  1330. @@NoVideo7:
  1331.         clc
  1332.         ret
  1333.  
  1334. ENDP    FindVideo7
  1335.  
  1336. ;----------------------------------------------------------------------------
  1337. ; FindGenoa    Detect the presence of a Genoa GVGA SuperVGA board
  1338. ;----------------------------------------------------------------------------
  1339. ;
  1340. ; Routine detects if the SuperVGA boards is present and determines how much
  1341. ; memory is on it.
  1342. ;
  1343. ; Exit:            Carry flag is set if board was detected
  1344. ;
  1345. ;                AX                - Video card identifier
  1346. ;                [VideoMem]        - Amount of video memory on board
  1347. ;                [VideoChipID]    - Chip revision id
  1348. ;
  1349. ;----------------------------------------------------------------------------
  1350. PROC    FindGenoa    near
  1351.  
  1352.         mov        ax,0C000h
  1353.         mov        es,ax
  1354.         mov        bx,[es:37h]            ; Get offset of information table
  1355.         cmp        [BYTE es:bx],77h
  1356.         jne        @@NoGenoa
  1357.         cmp        [WORD es:bx+2],6699h
  1358.         jne        @@NoGenoa
  1359.  
  1360.         mov        al,[BYTE es:bx+1]    ; Get card version number
  1361.         or        al,al
  1362.         jz        @@HaveGenoa256        ; Found a Genoa 62/300
  1363.         cmp        al,11h
  1364.         je        @@HaveGenoa512        ; Found a Genoa 64/600
  1365.         cmp        al,22h
  1366.         je        @@HaveGenoa256        ; Found a Genoa 6100
  1367.         jmp        @@NoGenoa            ; Other Genoa's have Tseng chips
  1368.  
  1369. @@HaveGenoa512:
  1370.         mov        [WORD VideoMem],512
  1371.  
  1372. @@HaveGenoa256:
  1373.         mov        [WORD VideoModes],offset GenoaModes
  1374.         mov        ax,grSVGA_GENOA
  1375.         stc
  1376.         ret
  1377.  
  1378. @@NoGenoa:
  1379.         clc
  1380.         ret
  1381.  
  1382. ENDP    FindGenoa
  1383.  
  1384. ;----------------------------------------------------------------------------
  1385. ; FindParadise    Detect the presence of a Paradise SuperVGA board
  1386. ;----------------------------------------------------------------------------
  1387. ;
  1388. ; Routine detects if the SuperVGA boards is present and determines how much
  1389. ; memory is on it.
  1390. ;
  1391. ; Exit:            Carry flag is set if board was detected
  1392. ;
  1393. ;                AX                - Video card identifier
  1394. ;                [VideoMem]        - Amount of video memory on board
  1395. ;                [VideoChipID]    - Chip revision id
  1396. ;
  1397. ;----------------------------------------------------------------------------
  1398. PROC    FindParadise    near
  1399.  
  1400.         rdinx    3CEh, 0Fh            ; Read old register value
  1401.         mov        [old],al            ; Save old value
  1402.         modinx    3CEh, 0Fh, 17h, 0    ; Lock paradise registers
  1403.         tstinx    3CEh, 9, 7Fh        ; Test if bank register is there
  1404.         jz        @@NoParadise        ; Register wrote, so not paradise
  1405.  
  1406.         wrinx    3CEh, 0Fh, 5        ; Unlock paradise registers
  1407.         tstinx    3CEh, 9, 7Fh        ; Test if bank register is there
  1408.         jnz        @@NoParadise        ; Register wouldn't write, not paradise
  1409.  
  1410. ; We have a Paradise SuperVGA, so determine what chip it is.
  1411.  
  1412.         rdinx    CRTC, 29h            ; Read value of WD90Cxx register lock
  1413.         mov        [old],al            ; Save old value
  1414.         modinx    CRTC, 29h, 8Fh, 85h    ; Unlock WD90Cxx registers
  1415.         tstinx    CRTC, 2Bh, 0FFh        ; Test WD90Cxx scratch register
  1416.         jnz        @@HavePVGA            ; We have a PVGA1
  1417.  
  1418.         rdinx    3C4h, 6                ; Read value of WD90C1x register
  1419.         mov        [old],al            ; Save old value
  1420.         wrinx    3C4h, 6, 48h
  1421.         tstinx    3C4h, 7, 0F0h
  1422.         jnz        @@HaveWD90C00
  1423.         tstinx    3C4h, 10h, 0FFh
  1424.         jnz        @@HavePVGA            ; WD90C2x has same modes as PVGA
  1425.  
  1426.         tstinx    3C4h, 14h, 0Fh
  1427.         jnz        @@HaveWD90C1x
  1428.  
  1429.         rdinx    CRTC, 37h
  1430.         cmp        al,31h
  1431.         mov        [VideoChipID],grPARA_90c31
  1432.         je        @@MemCheck            ; Have a WD90C31
  1433.  
  1434. ; Chip is a WD90C30.
  1435.  
  1436.         mov        [VideoChipID],grPARA_90c30
  1437.         wrinx    3C4h, 6, [old]        ; Restore register value
  1438.         ClearMode    grSVGA_1280x1024x16, ParadiseModes
  1439.         jmp        @@MemCheck
  1440.  
  1441. @@HaveWD90C1x:
  1442.         wrinx    3C4h, 6, [old]        ; Restore register value
  1443.         ClearMode    grSVGA_1280x1024x16, ParadiseModes
  1444.         ClearMode    grSVGA_1024x768x256, ParadiseModes
  1445.         mov        [VideoChipID],grPARA_90c10
  1446.         tstinx    3C4h, 0Ah, 04h
  1447.         jnz        @@MemCheck
  1448.         mov        [VideoChipID],grPARA_90c11
  1449.         jmp        @@MemCheck
  1450.  
  1451. @@HaveWD90C00:
  1452.         mov        [VideoChipID],grPARA_90c00
  1453.         wrinx    3C4h, 6, [old]        ; Restore register value
  1454.         ClearMode    grSVGA_1280x1024x16, ParadiseModes
  1455.         ClearMode    grSVGA_1024x768x256, ParadiseModes
  1456.         jmp        @@MemCheck
  1457.  
  1458. @@HavePVGA:
  1459.         mov        [VideoChipID],grPARA_PVGA1A
  1460.         wrinx    CRTC, 29h, [old]    ; Restore value of WD90Cxx register lock
  1461.         ClearMode    grSVGA_1024x768x16, ParadiseModes
  1462.         ClearMode    grSVGA_1280x1024x16, ParadiseModes
  1463.         ClearMode    grSVGA_800x600x256, ParadiseModes
  1464.         ClearMode    grSVGA_1024x768x256, ParadiseModes
  1465.         jmp        @@MemCheck
  1466.  
  1467. @@MemCheck:
  1468.         rdinx    3CEh, 0Bh            ; Read memory size register
  1469.         shr        al,6
  1470.         cmp        al,2
  1471.         jb        @@DoneMem
  1472.         mov        [WORD VideoMem],512    ; Card has 512kb of memory
  1473.         cmp        al,3
  1474.         jb        @@DoneMem
  1475.         mov        [WORD VideoMem],1024; Card has 1024kb of memory
  1476.  
  1477. @@DoneMem:
  1478.         mov        [PageFlip],true        ; Card supports extended page flipping
  1479.         Add32kColor    Parad32KModes
  1480.         mov        [WORD VideoModes],offset ParadiseModes
  1481.  
  1482. ; Ok, now check to see if the card is capable of 800x600x16 color mode. If
  1483. ; it isn't, then the card is probably running on an LCD display, so we
  1484. ; disable all modes above 640x480.
  1485.  
  1486.         call    saveMode
  1487.         mov     ax,58h or 80h       ; Don't clear the memory!
  1488.         int        10h
  1489.         call    CheckGraphics
  1490.         jc        @@Have800x600
  1491.  
  1492.         ClearMode    grSVGA_800x600x16, ParadiseModes
  1493.         ClearMode    grSVGA_1024x768x16, ParadiseModes
  1494.         ClearMode    grSVGA_800x600x256, ParadiseModes
  1495.         ClearMode    grSVGA_1024x768x256, ParadiseModes
  1496.         ClearMode    grSVGA_800x600x32k, ParadiseModes
  1497.  
  1498. @@Have800x600:
  1499.         call    restoreMode
  1500.         mov        ax,grSVGA_PARADISE
  1501.         stc
  1502.         ret
  1503.  
  1504. @@NoParadise:
  1505.         wrinx    3CEh, 15, [old]        ; Restore old register value
  1506.         clc
  1507.         ret
  1508.  
  1509. ENDP    FindParadise
  1510.  
  1511. ;----------------------------------------------------------------------------
  1512. ; FindChips    Detect the presence of a Chips & Technologies SuperVGA board
  1513. ;----------------------------------------------------------------------------
  1514. ;
  1515. ; Routine detects if the SuperVGA boards is present and determines how much
  1516. ; memory is on it.
  1517. ;
  1518. ; Exit:            Carry flag is set if board was detected
  1519. ;
  1520. ;                AX                - Video card identifier
  1521. ;                [VideoMem]        - Amount of video memory on board
  1522. ;                [VideoChipID]    - Chip revision id
  1523. ;
  1524. ;----------------------------------------------------------------------------
  1525. PROC    FindChips    near
  1526.  
  1527.         mov        ax,5F00h            ; Get controller info servic
  1528.         xor        bx,bx
  1529.         int        10h
  1530.         cmp        al,5Fh                ; AL == 5F we have a Chips
  1531.         jnz        @@NoChips
  1532.  
  1533. ; We have a Chips & Tech SuperVGA, so determine what chipset it is
  1534.  
  1535.         mov        [PageFlip],true        ; Card supports extended page flipping
  1536.  
  1537.         shr        bl,4
  1538.         cmp        bl,0
  1539.         je        @@Have82c451
  1540.         cmp        bl,1
  1541.         je        @@Have82c452
  1542.         cmp        bl,2
  1543.         je        @@Have82c451        ; 82c455 has same modes as 451
  1544.         cmp        bl,4
  1545.         je        @@Have82c451        ; 82c456 has same modes as 451
  1546.         mov        [VideoChipID],grCHIPS_82c453
  1547.         jmp        @@CheckMem            ; 82c453+ support all modes
  1548.  
  1549. @@Have82c451:
  1550.         mov        [PageFlip],false    ; No page flipping on this chip
  1551.         ClearMode    grSVGA_1024x768x16, ChipsModes
  1552.         ClearMode    grSVGA_640x480x256, ChipsModes
  1553.         ClearMode    grSVGA_800x600x256, ChipsModes
  1554.         ClearMode    grSVGA_1024x768x256, ChipsModes
  1555.         mov        [VideoChipID],grCHIPS_82c451
  1556.         jmp        @@CheckMem
  1557.  
  1558. @@Have82c452:
  1559.         ClearMode    grSVGA_800x600x256, ChipsModes
  1560.         ClearMode    grSVGA_1024x768x256, ChipsModes
  1561.         mov        [VideoChipID],grCHIPS_82c452
  1562.         jmp        @@CheckMem
  1563.  
  1564. ; Determine memory size
  1565.  
  1566. @@CheckMem:
  1567.         cmp        bh,1
  1568.         jb        @@DoneMem
  1569.         mov        [WORD VideoMem],512
  1570.         cmp        bh,2
  1571.         jb        @@DoneMem
  1572.         mov        [WORD VideoMem],1024
  1573.  
  1574. @@DoneMem:
  1575.         mov        [WORD VideoModes],offset ChipsModes
  1576.         mov        ax,grSVGA_CHIPS
  1577.         stc
  1578.         ret
  1579.  
  1580. @@NoChips:
  1581.         clc
  1582.         ret
  1583.  
  1584. ENDP    FindChips
  1585.  
  1586. ;----------------------------------------------------------------------------
  1587. ; FindTseng    Detect the presence of the ET3000 and ET4000 SuperVGA boards
  1588. ;----------------------------------------------------------------------------
  1589. ;
  1590. ; Routine detects if the SuperVGA boards is present and determines how much
  1591. ; memory is on it.
  1592. ;
  1593. ; Exit:            Carry flag is set if board was detected
  1594. ;
  1595. ;                AX                - Video card identifier
  1596. ;                [VideoMem]        - Amount of video memory on board
  1597. ;                [VideoChipID]    - Chip revision id
  1598. ;
  1599. ;----------------------------------------------------------------------------
  1600. PROC    FindTseng    near
  1601.  
  1602.         outp    3BFh, 3
  1603.         outp    3D8h, 0A0h            ; Enable ET4000 extensions
  1604.         tstreg    3CDh, 3Fh            ; Test bank switch register
  1605.         jnz        @@NoTseng            ; Test failed, not a Tseng
  1606.  
  1607. ; We have a Tseng card, so determine if it is an ET3000 or ET4000
  1608.  
  1609.         tstinx    CRTC, 33h, 0Fh        ; Test for ET4000 extended start address
  1610.         jz        @@ET4000
  1611.  
  1612. ; We have an ET3000 board, so check the amount of memory installed
  1613.  
  1614.         mov        ax,512                ; Maximum of 512k on board
  1615.         mov        bx,offset ET3000Switch
  1616.         mov        cx,2Dh                ; Values to set 640x350x256
  1617.         xor        dx,dx
  1618.         call    CheckMem
  1619.  
  1620.         mov        [PageFlip],true        ; Card supports extended page flipping
  1621.         mov        [WORD VideoModes],offset ET3000Modes
  1622.         mov        ax,grSVGA_ET3000
  1623.         stc
  1624.         ret
  1625.  
  1626. ; We have an ET4000 board, so determine the amount of memory installed
  1627.  
  1628. @@ET4000:
  1629.         rdinx    CRTC, 37h            ; Read memory size bits
  1630.         and        al,0Bh
  1631.         cmp        al,0Ah
  1632.         jb        @@1
  1633.         mov        [WORD VideoMem],512
  1634. @@1:    cmp        al,0Bh
  1635.         jb        @@2
  1636.         mov        [WORD VideoMem],1024
  1637.  
  1638. ; If the board has a 32k color DAC on board, check to see if we can set
  1639. ; the 320x200 32k color mode which is not available on all boards.
  1640.  
  1641. @@2:
  1642.         mov        [VideoChipID],grET4000_MEGAEVA
  1643.         call    SaveMode
  1644.         cmp        [DacType],grHCDAC
  1645.         jl        @@Check1280
  1646.         mov        ax,10F0h
  1647.         mov        bx,13h or 80h
  1648.         int        10h
  1649.         cmp        ax,0010h
  1650.         je        @@CheckTC
  1651.  
  1652.         ClearMode    grSVGA_320x200x32k, ET400032KModes+1
  1653.  
  1654. ; If the board has a 24 bit video DAC on board, determine what type of
  1655. ; board it is (MegaEva/2, Speedstar 24, Genoa 7900), which all have
  1656. ; different video mode numbers.
  1657.  
  1658. @@CheckTC:
  1659.         cmp        [DacType],grTCDAC
  1660.         jne        @@Check1280
  1661.  
  1662. ; Assume board is a MegaEva/2, unless we find otherwise
  1663.  
  1664.         mov        ax,10E0h
  1665.         mov        bx,2Eh or 80h
  1666.         int        10h
  1667.         cmp        ax,0010h
  1668.         jne        @@CheckGenoa        ; Not speedstar, check for Genoa 7900
  1669.  
  1670. ; Board is a Diamond Speedstar 24
  1671.  
  1672.         mov        [VideoChipID],grET4000_SPEEDSTAR
  1673.         ClearMode    grSVGA_640x350x16m, ET4000TCModes+1
  1674.         ClearMode    grSVGA_640x400x16m, ET4000TCModes+1
  1675.         jmp        @@Check1280
  1676.  
  1677. @@CheckGenoa:
  1678.         mov        ax,10F0h
  1679.         mov        bx,3Eh or 80h
  1680.         int        10h
  1681.         cmp        ax,0010h
  1682.         jne        @@Check1280            ; Not a Genoa, must be MegaEva/2...
  1683.  
  1684. ; Board is a Genoa 7900
  1685.  
  1686.         mov        [VideoChipID],grET4000_GENOA
  1687.         ClearMode    grSVGA_640x350x16m, ET4000TCModes+1
  1688.         ClearMode    grSVGA_640x400x16m, ET4000TCModes+1
  1689.  
  1690. ; Check to see if the 1280x1024x16 color video mode is available.
  1691.  
  1692. @@Check1280:
  1693.         mov        ax,03Dh or 80h        ; 1280x1024x16 color video mode
  1694.         int        10h
  1695.         call    CheckGraphics
  1696.         jc        @@DoneCheck            ; Yes, mode is available
  1697.  
  1698.         ClearMode    grSVGA_1280x1024x16, ET4000Modes
  1699.  
  1700. @@DoneCheck:
  1701.         call    RestoreMode
  1702.  
  1703.         mov        [PageFlip],true        ; Card supports extended page flipping
  1704.         Add32kColor        ET400032KModes
  1705.         AddTrueColor    ET4000TCModes
  1706.         mov        [WORD VideoModes],offset ET4000Modes
  1707.         mov        ax,grSVGA_ET4000
  1708.         stc
  1709.         ret
  1710.  
  1711. @@NoTseng:
  1712.         clc
  1713.         ret
  1714.  
  1715. ENDP    FindTseng
  1716.  
  1717. ;----------------------------------------------------------------------------
  1718. ; FindEverex    Detect the presence of an Everex SuperVGA board
  1719. ;----------------------------------------------------------------------------
  1720. ;
  1721. ; Routine detects if the SuperVGA boards is present and determines how much
  1722. ; memory is on it.
  1723. ;
  1724. ; Exit:            Carry flag is set if board was detected
  1725. ;
  1726. ;                AX                - Video card identifier
  1727. ;                [VideoMem]        - Amount of video memory on board
  1728. ;                [VideoChipID]    - Chip revision id
  1729. ;
  1730. ;----------------------------------------------------------------------------
  1731. PROC    FindEverex    near
  1732.  
  1733.         mov        ax,7000h
  1734.         xor        bx,bx
  1735.         int        10h
  1736.         cmp        al,70h
  1737.         jnz        @@NoEverex
  1738.  
  1739. ; Some Everex boards use Trident and ET4000 chipsets. These boards will be
  1740. ; picked up by the low level INIT_everex routine. We do however determine
  1741. ; the chipset type here, since all everex boards use the same video
  1742. ; mode numbers.
  1743.  
  1744.         mov        [PageFlip],true        ; Default to page flipping
  1745.         shr        dx,4
  1746.         mov        [VideoChipID],grEVEREX_Ev236
  1747.         cmp        dx,236h                ; UltraGraphics - Trident Chip
  1748.         je        @@CheckMem
  1749.         mov        [VideoChipID],grEVEREX_Ev620
  1750.         cmp        dx,620h                ; Vision VGA - Trident Chip
  1751.         je        @@CheckMem
  1752.         mov        [VideoChipID],grEVEREX_Ev629
  1753.         cmp        dx,629h                ; ViewPoint TC - ET4000 Chip
  1754.         je        @@CheckMem
  1755.         mov        [VideoChipID],grEVEREX_Ev673
  1756.         cmp        dx,673h                ; EVGA - Trident Chip
  1757.         je        @@CheckMem
  1758.         mov        [VideoChipID],grEVEREX_Ev678
  1759.         cmp        dx,678h                ; Viewpoint - Trident Chip
  1760.         je        @@CheckMem
  1761.  
  1762.         mov        [VideoChipID],grEVEREX_EvNR
  1763.         mov        [PageFlip],false    ; No page flipping on this card
  1764.  
  1765. @@CheckMem:
  1766.         shr        ch,6
  1767.         cmp        ch,1
  1768.         jb        @@DoneMem
  1769.         mov        [WORD VideoMem],512        ; Card has 512kb of memory
  1770.         cmp        ch,2
  1771.         jb        @@DoneMem
  1772.         mov        [WORD VideoMem],1024    ; Card has 1024kb of memory
  1773.         cmp        ch,3
  1774.         jb        @@DoneMem
  1775.         mov        [WORD VideoMem],2048    ; Card has 2048kb of memory
  1776.  
  1777. @@DoneMem:
  1778.         Add32kColor        Everex32KModes
  1779.         AddTrueColor    EverexTCModes
  1780.         mov        [WORD VideoModes],offset EverexModes
  1781.         mov        ax,grSVGA_EVEREX
  1782.         stc
  1783.         ret
  1784.  
  1785. @@NoEverex:
  1786.         clc
  1787.         ret
  1788.  
  1789. ENDP    FindEverex
  1790.  
  1791. ;----------------------------------------------------------------------------
  1792. ; FindAhead    Detect the presence of a Ahead A or B SuperVGA board
  1793. ;----------------------------------------------------------------------------
  1794. ;
  1795. ; Routine detects if the SuperVGA boards is present and determines how much
  1796. ; memory is on it.
  1797. ;
  1798. ; Exit:            Carry flag is set if board was detected
  1799. ;
  1800. ;                AX                - Video card identifier
  1801. ;                [VideoMem]        - Amount of video memory on board
  1802. ;                [VideoChipID]    - Chip revision id
  1803. ;
  1804. ;----------------------------------------------------------------------------
  1805. PROC    FindAhead    near
  1806.  
  1807.         rdinx    3CEh, 0Fh
  1808.         mov        [old],al
  1809.         wrinx    3CEh, 0Fh, 0        ; Disable extended registers
  1810.         tstinx    3CEh, 0Dh, 0FFh        ; Test for bank switch register
  1811.         jz        @@NoAhead            ; Register wrote, so not Ahead
  1812.  
  1813.         wrinx    3CEh, 0Fh, 20h        ; Enable extended registers
  1814.         tstinx    3CEh, 0Dh, 0FFh        ; Test for bank switch register
  1815.         jnz        @@NoAhead            ; Register didn't write, so not Ahead
  1816.  
  1817. ; SuperVGA is an Ahead, so determine type.
  1818.  
  1819.         rdinx    3CEh, 0Fh            ; Read chip version register
  1820.         and        al,0Fh
  1821.         jnz        @@AheadB            ; We have an Ahead B
  1822.  
  1823.         ClearMode    grSVGA_1024x768x256, AheadModes
  1824.         mov        ax,512                ; Maximum of 512k on board
  1825.         mov        bx,offset AHEADASwitch
  1826.         mov        cx,60h                ; Values to set 640x400x256
  1827.         xor        dx,dx
  1828.         call    CheckMem
  1829.         mov        [WORD VideoModes],offset AheadModes
  1830.         mov        ax,grSVGA_AHEADA
  1831.         stc
  1832.         ret
  1833.  
  1834. @@AheadB:
  1835.         mov        ax,1024                ; Maximum of 1024k on board
  1836.         mov        bx,offset AHEADBSwitch
  1837.         mov        cx,60h                ; Values to set 640x400x256
  1838.         xor        dx,dx
  1839.         call    CheckMem
  1840.         mov        [PageFlip],true        ; Card supports extended page flipping
  1841.         mov        [WORD VideoModes],offset AheadModes
  1842.         mov        ax,grSVGA_AHEADB
  1843.         stc
  1844.         ret
  1845.  
  1846. @@NoAhead:
  1847.         wrinx    3CEh, 0Fh, [old]    ; Restore register
  1848.         clc
  1849.         ret
  1850.  
  1851. ENDP    FindAhead
  1852.  
  1853. ;----------------------------------------------------------------------------
  1854. ; FindCirrus    Detect the presence of an Cirrus 54xx SuperVGA board
  1855. ;----------------------------------------------------------------------------
  1856. ;
  1857. ; Routine detects if the SuperVGA boards is present and determines how much
  1858. ; memory is on it.
  1859. ;
  1860. ; Exit:            Carry flag is set if board was detected
  1861. ;
  1862. ;                AX                - Video card identifier
  1863. ;                [VideoMem]        - Amount of video memory on board
  1864. ;                [VideoChipID]    - Chip revision id
  1865. ;
  1866. ;----------------------------------------------------------------------------
  1867. PROC    FindCirrus    near
  1868.  
  1869.         rdinx    3C4h, 6
  1870.         mov        [old],al            ; Save of value of register
  1871.         wrinx    3C4h, 6, 12h        ; Enable extended registers
  1872.         rdinx    3C4h, 6
  1873.         cmp        al,12h                ; Check value in extended register lock
  1874.         jne        @@NoCirrus
  1875.         tstinx    3C4h, 1Eh, 3Fh
  1876.         jnz        @@NoCirrus            ; Reg wasn't writeable, test failed
  1877.         tstinx    CRTC, 1Bh, 0FFh
  1878.         jnz        @@NoCirrus            ; Reg wasn't writeable, test failed
  1879.  
  1880. ; We have a Cirrus 54xx SuperVGA, so determine how much memory is on board
  1881.  
  1882.         rdinx    3C4h, 0Fh            ; Get value of memory size register
  1883.         shr        al,3
  1884.         and        al,3
  1885.         cmp        al,1
  1886.         jb        @@DoneCirrus
  1887.         mov        [WORD VideoMem],512
  1888.         cmp        al,2
  1889.         jb        @@DoneCirrus
  1890.         mov        [WORD VideoMem],1024
  1891.         cmp        al,3
  1892.  
  1893. @@DoneCirrus:
  1894.         Add32kColor        Cirrus32KModes
  1895.         AddTrueColor    CirrusTCModes
  1896.         mov        [PageFlip],true        ; Card supports page flipping
  1897.         mov        [WORD VideoModes],offset CirrusModes
  1898.         mov        [VideoChipID],grCIRRUS_5422
  1899.         mov        ax,grSVGA_CIRRUS54
  1900.         stc
  1901.         ret
  1902.  
  1903. @@NoCirrus:
  1904.         wrinx    3C4h, 6, [old]        ; Restore extended register enable
  1905.         clc
  1906.         ret
  1907.  
  1908. ENDP    FindCirrus
  1909.  
  1910. ;----------------------------------------------------------------------------
  1911. ; FindAcuMos    Detect the presence of an AcuMos SuperVGA board
  1912. ;----------------------------------------------------------------------------
  1913. ;
  1914. ; Routine detects if the SuperVGA boards is present and determines how much
  1915. ; memory is on it.
  1916. ;
  1917. ; Exit:            Carry flag is set if board was detected
  1918. ;
  1919. ;                AX                - Video card identifier
  1920. ;                [VideoMem]        - Amount of video memory on board
  1921. ;                [VideoChipID]    - Chip revision id
  1922. ;
  1923. ;----------------------------------------------------------------------------
  1924. PROC    FindAcuMos    near
  1925.  
  1926.         rdinx    3C4h, 6
  1927.         mov        [old],al            ; Save of value of register
  1928.         wrinx    3C4h, 6, 12h        ; Enable extended registers
  1929.         tstinx    3CEh, 9, 30h        ; Test scratchpad 9 again
  1930.         jnz        @@NoAcuMos            ; Reg not wasn't writeable, test failed
  1931.  
  1932. ; We have an AcuMos SuperVGA, so determine how much memory is on board
  1933.  
  1934.         rdinx    3C4h, 0Ah            ; Get scratchpad index 10
  1935.         and        al,3
  1936.         cmp        al,1
  1937.         jb        @@DoneAcuMos
  1938.         mov        [WORD VideoMem],512
  1939.         cmp        al,2
  1940.         jb        @@DoneAcuMos
  1941.         mov        [WORD VideoMem],1024
  1942.         cmp        al,3
  1943.         jb        @@DoneAcuMos
  1944.         mov        [WORD VideoMem],2048
  1945.  
  1946. @@DoneAcuMos:
  1947.         mov        [WORD VideoModes],offset AcuMosModes
  1948.         mov        ax,grSVGA_ACUMOS
  1949.         stc
  1950.         ret
  1951.  
  1952. @@NoAcuMos:
  1953.         wrinx    3C4h, 6, [old]        ; Restore extended register enable
  1954.         clc
  1955.         ret
  1956.  
  1957. ENDP    FindAcuMos
  1958.  
  1959. ;----------------------------------------------------------------------------
  1960. ; FindOaktech    Detect the presence of an Oak Technologies SuperVGA board
  1961. ;----------------------------------------------------------------------------
  1962. ;
  1963. ; Routine detects if the SuperVGA boards is present and determines how much
  1964. ; memory is on it.
  1965. ;
  1966. ; Exit:            Carry flag is set if board was detected
  1967. ;
  1968. ;                AX                - Video card identifier
  1969. ;                [VideoMem]        - Amount of video memory on board
  1970. ;                [VideoChipID]    - Chip revision id
  1971. ;
  1972. ;----------------------------------------------------------------------------
  1973. PROC    FindOaktech    near
  1974.  
  1975.         tstinx    3DEh, 0Dh, 38h        ; Test for memory size register
  1976.         jnz        @@NoOakTech            ; Do not have an OakTech board
  1977.  
  1978. ; We have an Oak Technologies SuperVGA, so determine the type. The OTI-037C
  1979. ; bank switching registers are read only, so the following test will fail
  1980. ; for these cards.
  1981.  
  1982.         tstinx    3DEh, 11h, 0FFh        ; Look for R/W bank switch register
  1983.         jnz        @@Have037C            ; Have an OTI-037C
  1984.  
  1985. ; We have an OAK SuperVGA, so determine what chipset it is
  1986.  
  1987.         rdinx    3DEh, 0Bh            ; Read Chip Revision register
  1988.         shr        al,5
  1989.         cmp        al,5
  1990.         mov        [VideoChipID],grOAK_077
  1991.         je        @@Have077            ; Chip is an OTI-077
  1992.  
  1993.         mov        [VideoChipID],grOAK_067
  1994.         ClearMode    grSVGA_1024x768x256, OAKModes
  1995.  
  1996. @@Have077:
  1997.         rdinx    3DEh, 0Dh            ; Read memory size register
  1998.         shr        al,6
  1999.         or        al,al
  2000.         jz        @@DoneMem                    ; Board has 256k
  2001.         mov        [WORD VideoMem],512
  2002.         cmp        al,2
  2003.         je        @@DoneMem
  2004.         mov        [WORD VideoMem],1024
  2005.         jmp        @@DoneMem
  2006.  
  2007. ; We have an OTI-037C SuperVGA. The only supported video mode is 800x600x16
  2008. ; with 256k of memory.
  2009.  
  2010. @@Have037C:
  2011.         mov        [VideoChipID],grOAK_037C
  2012.         rdinx    3DEh, 0Dh            ; Read memory size register
  2013.         shr        al,6
  2014.         or        al,al
  2015.         jz        @@DoneMem                    ; Board has 256k
  2016.         mov        [WORD VideoMem],512
  2017.  
  2018. @@DoneMem:
  2019.         Add32kColor    OAK32KModes
  2020.         mov        [WORD VideoModes],offset OAKModes
  2021.         mov        ax,grSVGA_OAKTECH
  2022.         stc
  2023.         ret
  2024.  
  2025. @@NoOaktech:
  2026.         clc
  2027.         ret
  2028.  
  2029. ENDP    FindOaktech
  2030.  
  2031. ;----------------------------------------------------------------------------
  2032. ; FindAL2101    Detect the presence of an Advance Logic 2101 SuperVGA board
  2033. ;----------------------------------------------------------------------------
  2034. ;
  2035. ; Routine detects if the SuperVGA boards is present and determines how much
  2036. ; memory is on it.
  2037. ;
  2038. ; Exit:            Carry flag is set if board was detected
  2039. ;
  2040. ;                AX                - Video card identifier
  2041. ;                [VideoMem]        - Amount of video memory on board
  2042. ;                [VideoChipID]    - Chip revision id
  2043. ;
  2044. ;----------------------------------------------------------------------------
  2045. PROC    FindAL2101    near
  2046.  
  2047.         tstreg    8286h, 0FFh            ; Check for Start Pixel Low register
  2048.         jnz        @@NoAL2101            ; Test failed, no AL2101
  2049.         tstinx    CRTC, 1Fh, 3Bh        ; Check for Emulation register
  2050.         jnz        @@NoAL2101            ; Test failed, no AL2101
  2051.         tstinx    3CEh, 0Dh, 0Fh        ; Check for Fill Color register
  2052.         jnz        @@NoAL2101            ; Test failed, no AL2101
  2053.  
  2054. ; We have an AL2101 based SuperVGA
  2055.  
  2056.         rdinx    CRTC, 1Eh            ; Read memory size register
  2057.         and        al,3
  2058.         cmp        al,1
  2059.         jb        @@DoneMem
  2060.         mov        [WORD VideoMem],512
  2061.         cmp        al,2
  2062.         jb        @@DoneMem
  2063.         mov        [WORD VideoMem],1024
  2064.         cmp        al,3
  2065.         jb        @@DoneMem
  2066.         mov        [WORD VideoMem],2048
  2067.  
  2068. @@DoneMem:
  2069.         mov        [DacType],grHC2DAC    ; AL2101 has a 16 bit DAC
  2070.         mov        [WORD VideoModes],offset AL2101Modes
  2071.         mov        ax,grSVGA_AL2101
  2072.         stc
  2073.         ret
  2074.  
  2075. @@NoAL2101:
  2076.         clc
  2077.         ret
  2078.  
  2079. ENDP    FindAL2101
  2080.  
  2081. ;----------------------------------------------------------------------------
  2082. ; FindMXIC    Detect the presence of an MXIC 68010 SuperVGA board
  2083. ;----------------------------------------------------------------------------
  2084. ;
  2085. ; Routine detects if the SuperVGA boards is present and determines how much
  2086. ; memory is on it.
  2087. ;
  2088. ; Exit:            Carry flag is set if board was detected
  2089. ;
  2090. ;                AX                - Video card identifier
  2091. ;                [VideoMem]        - Amount of video memory on board
  2092. ;                [VideoChipID]    - Chip revision id
  2093. ;
  2094. ;----------------------------------------------------------------------------
  2095. PROC    FindMXIC    near
  2096.  
  2097.         rdinx    3C4h, 0A7h            ; Read extend reg enable value
  2098.         mov        [old],al
  2099.         wrinx    3C4h, 0A7h, 0        ; Disable extended registers
  2100.         tstinx    3C4h, 0C5h, 0FFh    ; Test for bank switch register
  2101.         jz        @@NoMXIC            ; Test passed, so not MXIC
  2102.  
  2103.         wrinx    3C4h, 0A7h, 87h        ; Enable extended registers
  2104.         tstinx    3C4h, 0C5h, 0FFh    ; Test for bank switch register
  2105.         jnz        @@NoMXIC            ; Test failed, so not MXIC
  2106.  
  2107. ; We have an MXIC SuperVGA.
  2108.  
  2109.         rdinx    3C4h, 0C2h            ; Read memory size register
  2110.         shr        al,2
  2111.         and        al,3
  2112.         cmp        al,1
  2113.         jb        @@DoneMem
  2114.         mov        [WORD VideoMem],512
  2115.         cmp        al,2
  2116.         jb        @@DoneMem
  2117.         mov        [WORD VideoMem],1024
  2118.  
  2119. @@DoneMem:
  2120.         mov        [WORD VideoModes],offset MXICModes
  2121.         mov        ax,grSVGA_MXIC
  2122.         stc
  2123.         ret
  2124.  
  2125. @@NoMXIC:
  2126.         wrinx    3C4h, 0A7h, [old]    ; Restore register
  2127.         clc
  2128.         ret
  2129.  
  2130. ENDP    FindMXIC
  2131.  
  2132. ;----------------------------------------------------------------------------
  2133. ; FindP2000    Detect the presence of a Primus 2000 SuperVGA board
  2134. ;----------------------------------------------------------------------------
  2135. ;
  2136. ; Routine detects if the SuperVGA boards is present and determines how much
  2137. ; memory is on it.
  2138. ;
  2139. ; Exit:            Carry flag is set if board was detected
  2140. ;
  2141. ;                AX                - Video card identifier
  2142. ;                [VideoMem]        - Amount of video memory on board
  2143. ;                [VideoChipID]    - Chip revision id
  2144. ;
  2145. ;----------------------------------------------------------------------------
  2146. PROC    FindP2000    near
  2147.  
  2148.         tstinx    3CEh, 3Dh, 03Fh        ; Check for Status command register
  2149.         jnz        @@NoP2000            ; Test failed, not P2000
  2150.         tstreg    3D6h, 01Fh            ; Check for bank switch register
  2151.         jnz        @@NoP2000            ; Test failed, not P2000
  2152.         tstreg    3D7h, 01Fh            ; Check for bank switch register
  2153.         jnz        @@NoP2000            ; Test failed, not P2000
  2154.  
  2155. ; We have a Primus P2000 SuperVGA card.
  2156.  
  2157.         mov        ax,2048                ; Maximum of 2048k on board
  2158.         mov        bx,offset P2000Switch
  2159.         mov        cx,2Ch                ; Values to set 640x400x256
  2160.         xor        dx,dx
  2161.         call    CheckMem
  2162.  
  2163.         Add32kColor    P200032KModes
  2164.         mov        [PageFlip],true        ; Card supports extended page flipping
  2165.         mov        [WORD VideoModes],offset P2000Modes
  2166.         mov        ax,grSVGA_P2000
  2167.         stc
  2168.         ret
  2169.  
  2170. @@NoP2000:
  2171.         clc
  2172.         ret
  2173.  
  2174. ENDP    FindP2000
  2175.  
  2176. ;----------------------------------------------------------------------------
  2177. ; FindRT3106    Detect the presence of a RealTek 3106 SuperVGA board
  2178. ;----------------------------------------------------------------------------
  2179. ;
  2180. ; Routine detects if the SuperVGA boards is present and determines how much
  2181. ; memory is on it.
  2182. ;
  2183. ; Exit:            Carry flag is set if board was detected
  2184. ;
  2185. ;                AX                - Video card identifier
  2186. ;                [VideoMem]        - Amount of video memory on board
  2187. ;                [VideoChipID]    - Chip revision id
  2188. ;
  2189. ;----------------------------------------------------------------------------
  2190. PROC    FindRT3106    near
  2191.  
  2192.         tstinx    CRTC, 1Fh, 3h        ; Test for scratch register
  2193.         jnz        @@NoRT3106
  2194.         tstreg    3D6h, 0Fh            ; Test for bank switch register
  2195.         jnz        @@NoRT3106
  2196.         tstreg    3D7h, 0Fh            ; Test for bank switch register
  2197.         jnz        @@NoRT3106
  2198.  
  2199. ; We have a RealTek 3106 SuperVGA
  2200.  
  2201.         rdinx    CRTC, 1Ah            ; Get chip version number
  2202.         mov        bl,al                ; Save chip version number
  2203.         shr        bl,6
  2204.         rdinx    CRTC, 1Eh            ; Get memory size register
  2205.         and        al,15
  2206.         cmp        al,1
  2207.         jb        @@DoneMem
  2208.         mov        [WORD VideoMem],512
  2209.         cmp        al,2
  2210.         jb        @@DoneMem
  2211.         or        bl,bl
  2212.         jz        @@Version0
  2213.         mov        [WORD VideoMem],1024
  2214.         cmp        al,3
  2215.         jb        @@DoneMem
  2216.         mov        [WORD VideoMem],2048
  2217.         jmp        @@DoneMem
  2218.  
  2219. @@Version0:
  2220.         cmp        al,3
  2221.         jb        @@DoneMem
  2222.         mov        [WORD VideoMem],1024
  2223.  
  2224. @@DoneMem:
  2225.         mov        [WORD VideoModes],offset RT3106Modes
  2226.         mov        ax,grSVGA_RT3106
  2227.         stc
  2228.         ret
  2229.  
  2230. @@NoRT3106:
  2231.         clc
  2232.         ret
  2233.  
  2234. ENDP    FindRT3106
  2235.  
  2236. OldBIOSMode        db    ?                ; Old BIOS mode
  2237. Old50Lines        db    ?
  2238. Oldx            db    ?                ; Old cursor position
  2239. Oldy            db    ?
  2240.  
  2241. ;----------------------------------------------------------------------------
  2242. ; SaveMode    - Saves the current video BIOS mode, for later restoration
  2243. ;----------------------------------------------------------------------------
  2244. ;
  2245. ; Registers:    none.
  2246. ;
  2247. ;----------------------------------------------------------------------------
  2248. PROC    SaveMode
  2249.  
  2250.         pusha
  2251.  
  2252. ; Find the current video mode so that we can restore it easily
  2253.  
  2254.         mov        ah,0Fh                ; Get current video mode service
  2255.         int        10h
  2256.         mov        [OldBIOSMode],al    ; Save old video mode
  2257.         mov        ah,03h                ; Get cursor position
  2258.         int        10h
  2259.         mov        [Oldx],dl
  2260.         mov        [Oldy],dh
  2261.         mov        [Old50Lines],0        ; Default to non-50 line mode
  2262.  
  2263.         mov        ax,1130h            ; AH := INT 10h function number
  2264.                                     ; AL := Get character gen information
  2265.         mov        bh,00                ; Get contents of INT 1Fh
  2266.         xor        dl,dl                ; Clear dl
  2267.         int        10h                    ; Determine number of lines (in dl)
  2268.         cmp        dl,49                ; 50 line mode?
  2269.         jne        @@Done                ; No, must have been 25 lines
  2270.         mov        [Old50Lines],1        ; Yes, 50 line mode was on
  2271.  
  2272. @@Done:
  2273.         popa
  2274.         ret
  2275.  
  2276. ENDP    SaveMode
  2277.  
  2278. ;----------------------------------------------------------------------------
  2279. ; RestoreMode    - Restores the VIDEO BIOS mode previously saved.
  2280. ;----------------------------------------------------------------------------
  2281. ;
  2282. ; Registers:    none.
  2283. ;
  2284. ;----------------------------------------------------------------------------
  2285. PROC    RestoreMode
  2286.  
  2287.         pusha
  2288.         mov        ah,0                ; Set video mode service
  2289.         mov        al,[OldBIOSMode]    ; Get old BIOS mode number
  2290.         or        al,80h                ; Set the don't clear memory bit
  2291.         int        10h                    ; Set the video mode
  2292.  
  2293.         cmp        [Old50Lines],0        ; Was 50 line mode set?
  2294.         je        @@Exit                ; No, don't set it up
  2295.  
  2296.         mov        ax,1112h            ; AH := INT 10h function number
  2297.                                     ; AL := 8x8 character set load
  2298.         mov        bl,0                ; BL := block to load
  2299.         int        10h                    ; load 8x8 characters into RAM
  2300.  
  2301. @@Exit:
  2302.         mov        ah,02h
  2303.         mov        dl,[Oldx]
  2304.         mov        dh,[Oldy]
  2305.         xor        bh,bh
  2306.         int        10h                    ; Set cursor location
  2307.         popa
  2308.         ret
  2309.  
  2310. ENDP    RestoreMode
  2311.  
  2312. ;----------------------------------------------------------------------------
  2313. ; CheckGraphics    - Check to see if graphics mode is currently active.
  2314. ;----------------------------------------------------------------------------
  2315. ;
  2316. ; This routine checks to see if a graphics mode was successfully set,
  2317. ; setting the carry flag if it was.
  2318. ;
  2319. ; Exit:            carry - Set if graphics mode is set.
  2320. ;
  2321. ; Registers:    None.
  2322. ;
  2323. ;----------------------------------------------------------------------------
  2324. PROC    CheckGraphics
  2325.  
  2326.         push    ax
  2327.         mov        ax,40h
  2328.         mov        es,ax
  2329.         xor        ax,ax
  2330.         cmp        [BYTE es:49h],3        ; Mode is still text mode, did not set
  2331.         ja        @@IsGraphics
  2332.  
  2333.         pop        ax
  2334.         clc
  2335.         ret
  2336.  
  2337. @@IsGraphics:
  2338.         pop        ax
  2339.         stc
  2340.         ret
  2341.  
  2342. ENDP    CheckGraphics
  2343.  
  2344. ;----------------------------------------------------------------------------
  2345. ; CheckMem    Performs a manual memory test
  2346. ;----------------------------------------------------------------------------
  2347. ;
  2348. ; Does a manual memory test by attempting to read and write values at
  2349. ; various places in memory, determining when they fail.
  2350. ;
  2351. ; Entry:        AX    - Maximum amount of memory installed
  2352. ;                BX    - Offset of bank switching routine
  2353. ;                CX    - Value in AX to set 256 color mode
  2354. ;                DX    - Value in BX to set 256 color mode
  2355. ;
  2356. ; Exit:            [VideoMem] set to the correct value
  2357. ;
  2358. ; Registers:    AX,BX,CX,DX
  2359. ;
  2360. ;----------------------------------------------------------------------------
  2361. PROC    CheckMem
  2362.  
  2363.         push    si
  2364.         push    di
  2365.         push    bp
  2366.  
  2367.         push    ax
  2368.         push    bx
  2369.         push    cx
  2370.         push    dx
  2371.  
  2372. ; Find the current video mode so that we can restore it easily
  2373.  
  2374.         mov        ah,0Fh                ; Get current video mode service
  2375.         int        10h
  2376.         mov        [OldBIOSMode],al    ; Save old video mode
  2377.         mov        [Old50Lines],0        ; Default to non-50 line mode
  2378.  
  2379.         mov        ax,1130h            ; AH := INT 10h function number
  2380.                                     ; AL := Get character gen information
  2381.         mov        bh,00                ; Get contents of INT 1Fh
  2382.         xor        dl,dl                ; Clear dl
  2383.         int        10h                    ; Determine number of lines (in dl)
  2384.         cmp        dl,49                ; 50 line mode?
  2385.         jne        @@SetMode            ; No, must have been 25 lines
  2386.         mov        [Old50Lines],1        ; Yes, 50 line mode was on
  2387.  
  2388. @@SetMode:
  2389.         pop        bx                    ; Pop value for BX
  2390.         pop        ax                    ; Pop value for AX
  2391.         int        10h                    ; Set the video mode
  2392.  
  2393. ; Now perform the memory check
  2394.  
  2395.         mov        ax,0A000h
  2396.         mov        es,ax
  2397.         pop        bx
  2398.         pop        bp
  2399.         shr        bp,6                ; BP := maximum number of 64k banks
  2400.         xor        di,di                ; ES:DI -> offset in video RAM
  2401.  
  2402.         mov        dx,4                ; Start by checking for 256k RAM
  2403.  
  2404. @@CheckLoop:
  2405.         mov        ax,dx
  2406.         dec        ax
  2407.         call    bx                    ; Setup to to read/write maxbank-1
  2408.         mov        cx,[es:di]            ; Read a value from memory
  2409.         mov        si,cx                ; Save the old value
  2410.         xor        cx,0AAAAh            ; Modify the value
  2411.         mov        [es:di],cx            ; Put the value back again
  2412.         mov        cx,[es:di]            ; Read the value back again
  2413.         mov        [es:di],si            ; Put the old value back
  2414.         xor        cx,0AAAAh            ; Attempt to get old value back
  2415.         cmp        cx,si                ; Old value the same?
  2416.         jne        @@TestFailed        ; The test failed, so we ran outa memory!
  2417.  
  2418.         mov        ax,dx
  2419.         shr        ax,1
  2420.         dec        ax
  2421.         call    bx                    ; Setup for (bank/2) - 1
  2422.         mov        ax,si
  2423.         xor        ax,5555h
  2424.         mov        [es:di],ax            ; Set modified value
  2425.         mov        ax,dx
  2426.         dec        ax
  2427.         call    bx                    ; Setup for bank-1
  2428.         mov        ax,[es:di]
  2429.         xor        ax,5555h
  2430.         cmp        ax,si
  2431.         je        @@TestFailed
  2432.  
  2433.         cmp        dx,bp                ; Have we reached maximum amount?
  2434.         je        @@FullMemory        ; Yes, so we have maximum memory...
  2435.  
  2436.         shl        dx,1                ; Keep on trying
  2437.         jmp        @@CheckLoop
  2438.  
  2439. @@FullMemory:
  2440.         shl        dx,1                ; Indicate that we would have failed
  2441.                                     ;  on next bank
  2442. @@TestFailed:
  2443.         shl        dx,5                ; DX := amount of video memory
  2444.         mov        [VideoMem],dx        ; Save the memory value found
  2445.  
  2446. ; Restore the old video mode before leaving
  2447.  
  2448.         mov        ah,0                ; Set video mode service
  2449.         mov        al,[OldBIOSMode]    ; Get old BIOS mode number
  2450.         int        10h                    ; Set the video mode
  2451.  
  2452.         cmp        [Old50Lines],0        ; Was 50 line mode set?
  2453.         je        @@Exit                ; No, don't set it up
  2454.  
  2455.         mov        ax,1112h            ; AH := INT 10h function number
  2456.                                     ; AL := 8x8 character set load
  2457.         mov        bl,0                ; BL := block to load
  2458.         int        10h                    ; load 8x8 characters into RAM
  2459.  
  2460. @@Exit:
  2461.         pop        bp
  2462.         pop        di
  2463.         pop        si
  2464.         ret
  2465.  
  2466. ENDP    CheckMem
  2467.  
  2468. ;----------------------------------------------------------------------------
  2469. ; NCRSwitch    NCR 77C22E bank switching routine
  2470. ;----------------------------------------------------------------------------
  2471. ;
  2472. ; Entry:        AL    - Bank number to switch to
  2473. ;
  2474. ;----------------------------------------------------------------------------
  2475. PROC    NCRSwitch
  2476.  
  2477.         push    dx
  2478.         shl        al,2                ; Change 64k bank into 16k bank number
  2479.         mov        ah,al
  2480.         mov        al,18h
  2481.         mov        dx,3C4h
  2482.         out        dx,ax                ; Set write bank number
  2483.         mov        al,1Ch
  2484.         out        dx,ax                ; Set read bank number
  2485.         pop        dx
  2486.         ret
  2487.  
  2488. ENDP    NCRSwitch
  2489.  
  2490. ;----------------------------------------------------------------------------
  2491. ; ET3000Switch    ET3000 bank switching routine
  2492. ;----------------------------------------------------------------------------
  2493. ;
  2494. ; Entry:        AL    - Bank number to switch to
  2495. ;
  2496. ;----------------------------------------------------------------------------
  2497. PROC    ET3000Switch
  2498.  
  2499.         push    dx
  2500.         and        al,7                ; Mask out bottom 3 bits
  2501.         mov        ah,al                ; Combine read and write bank values in al
  2502.         shl        ah,3
  2503.         or        al,ah
  2504.         or        al,40h                ; Set bit 6 to select 64k segments
  2505.         mov        dx,3CDh                ; Point to memory segment register
  2506.         out        dx,al                ; Set the new bank value
  2507.         pop        dx
  2508.         ret
  2509.  
  2510. ENDP    ET3000Switch
  2511.  
  2512. ;----------------------------------------------------------------------------
  2513. ; AHEADASwitch    Ahead A bank switching routine
  2514. ;----------------------------------------------------------------------------
  2515. ;
  2516. ; Entry:        AL    - Bank number to switch to
  2517. ;
  2518. ;----------------------------------------------------------------------------
  2519. PROC    AHEADASwitch
  2520.  
  2521.         push    dx
  2522.         mov        ch,al
  2523.         mov        dx,03CCh            ; bit 0 in bit 5 of Misc Output reg
  2524.         in        al,dx                ; Read Misc output register
  2525.         mov        dl,0C2h
  2526.         and        al,11011111b
  2527.         shr        ch,1                ; Need to set the bit?
  2528.         jnc        @@SkpA                ; No, so skip it
  2529.         or        al,00100000b
  2530. @@SkpA:    out        dx,al                ; Set the new value
  2531.         mov        dx,3CEh                ; bits 3-1 in bits 2-0 of Segment Reg
  2532.         mov        al,0Dh                ; Index 0Dh for segment reg
  2533.         mov        ah,ch                ; ch contains top three bits shr 1
  2534.         out        dx,ax                ; Set the new value
  2535.         pop        dx
  2536.         ret
  2537.  
  2538. ENDP    AHEADASwitch
  2539.  
  2540. ;----------------------------------------------------------------------------
  2541. ; AHEADBSwitch    Ahead B bank switching routine
  2542. ;----------------------------------------------------------------------------
  2543. ;
  2544. ; Entry:        AL    - Bank number to switch to
  2545. ;
  2546. ;----------------------------------------------------------------------------
  2547. PROC    AHEADBSwitch
  2548.  
  2549.         push    dx
  2550.         mov        ah,al                ; Combine read/write bank numbers
  2551.         shl        ah,4
  2552.         or        ah,al
  2553.         mov        al,0Dh                ; Index of Bank Switch register
  2554.         mov        dx,3CEh
  2555.         out        dx,ax                ; Set the register
  2556.         pop        dx
  2557.         ret
  2558.  
  2559. ENDP    AHEADBSwitch
  2560.  
  2561. ;----------------------------------------------------------------------------
  2562. ; P2000Switch    Primus P2000 bank switching routine
  2563. ;----------------------------------------------------------------------------
  2564. ;
  2565. ; Entry:        AL    - Bank number to switch to
  2566. ;
  2567. ;----------------------------------------------------------------------------
  2568. PROC    P2000Switch
  2569.  
  2570.         push    dx
  2571.         mov        dx,3D6h
  2572.         out        dx,al                ; Set read bank
  2573.         inc        dx
  2574.         out        dx,al                ; Set write bank
  2575.         pop        dx
  2576.         ret
  2577.  
  2578. ENDP    P2000Switch
  2579.  
  2580. ;----------------------------------------------------------------------------
  2581. ; Find6845    Determine if a 6845 CRTC is at the required port
  2582. ;----------------------------------------------------------------------------
  2583. ;
  2584. ; Routine detects the presence of the CRTC on an MDA, CGA, or HGC.
  2585. ; The technique is to write and read register 0Fh of the chip (Cursor
  2586. ; Location Low). If the same value is read as written, assume the chip
  2587. ; is present at the specified location.
  2588. ;
  2589. ; Entry:        DX = port address of 6845 CRTC
  2590. ;
  2591. ; Exit:            Carry flag is set if 6845 is present
  2592. ;
  2593. ; Registers:    AX,CX,DX
  2594. ;
  2595. ;----------------------------------------------------------------------------
  2596. PROC    Find6845 near
  2597.  
  2598.         mov        al,0Fh
  2599.         out        dx,al            ; Select 6845 reg 0Fh (Cursor low)
  2600.         inc        dx
  2601.  
  2602.         in        al,dx            ; AL := current Cursor Low value
  2603.         mov        ah,al            ; Preserve in AH
  2604.         mov        al,66h            ; AL := arbitrary value
  2605.         out        dx,al            ; Try to write 6845
  2606.  
  2607.         mov        cx,100h
  2608. @@Wait:
  2609.         loop    @@Wait            ; wait for 6845 to respond
  2610.  
  2611.         in        al,dx
  2612.         xchg    ah,al            ; AH := returned value
  2613.                                 ; AL := original value
  2614.         out        dx,al            ; Restore original value
  2615.  
  2616.         cmp        ah,66h            ; test whether 6845 responded
  2617.         jne        @@Exit            ; Jump if it didn't (cf is reset)
  2618.  
  2619.         stc                        ; Set carry if 6845 present
  2620.  
  2621. @@Exit:
  2622.         ret
  2623.  
  2624. ENDP    Find6845
  2625.  
  2626. endcodeseg    detectgr
  2627.  
  2628.         END                        ; End of module
  2629.