Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mandrill!gatech!ncsuvx!sam
From: sam@ncsuvx.ncsu.edu (Whad Upp)
Newsgroups: comp.sys.ibm.pc
Subject: Re: Hercules detection ???
Message-ID: <1924@ncsuvx.ncsu.edu>
Date: 21 Jun 88 17:34:45 GMT
References: <323@krafla.rhi.hi.is> <1351@spdcc.COM>
Reply-To: sam@ncsuvx.UUCP (Whad Upp)
Organization: NCSU Computing Center, Raleigh, NC
Lines: 188



This code will test for a couple of display and adapter types. Some
are assumed. The techniques are from:

         _Programmer's Guide To PC & PS/2 Video Systems_
                        by Richard Wilton 

A good book. His code does more than this and is in assembler. This
code is taken from another system. I think I have all the vital parts.

The last poster said it was impossible to detect the Herc card. This
code has always work for me. 

=============================================================================\
Sam "Gookie" Moore     ||         "Good morning Mr. Tree                    ||
NCSU COmputing Center  ||          We're very glad to see you               ||
Raleigh, NC            ||          Wake up Mr. Tree                         ||
sam@ncsuvx.ncsu.edu    ||          It's day time can't you see"             ||
                       ||             - Lucy (Lucy's Toy Shop)              ||
=============================================================================/

- Cut -

/*
 *      The techniques used here came from:
 *
 *         _Programmer's Guide To PC & PS/2 Video Systems_
 *                       by Richard Wilton 
 *
 *      Microsoft C.
 *
 */

/*
 *      Video Device Data.
 */

#define WHO_KNOWS       0
#define MONO_monitor    1
#define CGA_monitor     2
#define EGA_monitor     3

#define MONO_adapter    1
#define CGA_adapter     2
#define EGA_adapter     3
#define MCGA_adapter    4
#define HGC_adapter     5
#define HGCP_adapter    6
#define INCOLOR_adapter 7

/*
 *      Video Device Data.
 */

int     MonitorType = WHO_KNOWS,
        AdapterType = WHO_KNOWS;

char    *MonitorName[] = {  "Who Knows?",
                            "Monochrome Monitor",
                            "CGA Monitor",
                            "EGA Monitor"
};
        
char    *AdapterName[] = {  "Who Knows?",
                            "Monochrome Adapter",
                            "CGA Adapter",
                            "EGA Adapter",
                            "MCGA Adapter",
                            "HGC Adapter",
                            "HGC+ Adapter",
                            "InColor Card"
};

/*
 *      Find display adapter and display types.
 */

void check_video()
{
union REGS  regs;
unsigned    dipswitches;
int         i, j, k;

/*
 *  Check for MCGA or VGA.
 */

regs.x.ax = 0x1a00;
int86(0x10, ®s, ®s);

if (regs.h.al == 0x1a) {
    AdapterType = MCGA_adapter;
    return;
}

/*
 *  Check for EGA.
 */

regs.h.ah = 0x12;
regs.h.bl = 0x10;
int86(0x10, ®s, ®s);

if (regs.h.bl != 0x10) {
    AdapterType = EGA_adapter;

    dipswitches = regs.h.cl & 0x0e;
    dipswitches = (dipswitches >= 6 ? dipswitches-6 : dipswitches);
    if (dipswitches == 4)
        MonitorType = MONO_monitor;
    else if (dipswitches == 2)
        MonitorType = EGA_monitor;
    else if (dipswitches == 0)
        MonitorType = CGA_monitor;
    else
        MonitorType = CGA_monitor;
    return;
}

/*
 *  Check for CGA.
 */

if (check_6845(0x03d4)) {
    AdapterType = CGA_adapter;
    return;
}

/*
 *  Check for MONO.
 */

if (check_6845(0x03b4)) {

    i = inp(0x3ba);
    i &= 0x80;
    for (j = 0; j < 32768; j++) {
        k = inp(0x3ba);
        k &= 0x80;
        if (k != i)
            break;
    }

    MonitorType = MONO_monitor;
    
    if (k == i)
        AdapterType = MONO_adapter;
    else {
        k = inp(0x3ba);
        if ((k & 0x70) == 0)        
            AdapterType = HGC_adapter;
        else if ((k & 0x10) == 0x10)
            AdapterType = HGCP_adapter;
        else {
            AdapterType = INCOLOR_adapter;
            MonitorType = EGA_monitor;
        }
    }

}

return;
}

/*
 *  Check for presence of 6845.
 */

int check_6845(address)
int     address;
{
int     i, j;

outp(address++, 0x0f);
i = inp(address);
outp(address, 0x66);

for (j = 0; j < 1000; j++)
    ;

j = inp(address);
outp(address, i);

return(j == 0x66);
}

- Cut -