Page 1 of 1

Code for detecting color and monochrome displays

Posted: Thu Oct 25, 2007 3:38 pm
by madeofstaples
Just noticed this wiki entry while anticipating the next steps for my project:

http://www.osdev.org/wiki/Detecting_Col ... e_Monitors:

Code: Select all

/* 
    Video card mono/colour detection.
    Return values:  false=mono
                    true=colour
*/
_Bool detectVideoType(void)
{
    _Bool type;
    char c=(*(volatile USHORT*)0x410)&0x30;

    //c can be 0x00 or 0x20 for colour, 0x30 for mono.
    if(c==0x30){
        return(true);	//Monochrome monitor.
    } else {
        return(false);	//Colour monitor.
    }
}
namely the lines:
Return values: false=mono
true=colour
then,
return(true); //Monochrome monitor.
} else {
return(false); //Colour monitor.
I assume the second block is correct, given the comment explaining the reasoning just before the if statement

Posted: Thu Oct 25, 2007 6:09 pm
by JackScott
The page has been fixed. It was an error I put in while correcting the syntax. Sorry for the inconvenience.

Posted: Fri Oct 26, 2007 12:15 am
by Solar
Hm... while you were at it brushing up the syntax (and laudably removing a completely redundant local variable in the process), why didn't you do away with the if ( ... ) true; else false stuff altogether? :wink:

Posted: Fri Oct 26, 2007 2:09 am
by JackScott
Not clever enough. :P

Posted: Fri Oct 26, 2007 10:35 am
by JamesM
Solar wrote:Hm... while you were at it brushing up the syntax (and laudably removing a completely redundant local variable in the process), why didn't you do away with the if ( ... ) true; else false stuff altogether? :wink:

Code: Select all

typedef 0 true;
typedef 1 false;
Who says the above code isn't being used? Noone in their right mind would, but it's possible ;)

Posted: Fri Oct 26, 2007 11:59 am
by os64dev
false is allways zero in C/C++ as it is the standard but true is not defined.

Posted: Fri Oct 26, 2007 12:19 pm
by Craze Frog

Code: Select all

_Bool detectVideoType(void) {
    return true; // color monitor
}
Who uses a monochrome monitor anyways?

Posted: Fri Oct 26, 2007 12:22 pm
by Brynet-Inc
Craze Frog wrote:Who uses a monochrome monitor anyways?
I'm guilty of owning a few.. nothing wrong with supporting them..

Modern technology is so over rated :wink: