Code for detecting color and monochrome displays

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Code for detecting color and monochrome displays

Post 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
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Post by JackScott »

The page has been fixed. It was an error I put in while correcting the syntax. Sorry for the inconvenience.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post 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:
Every good solution is obvious once you've found it.
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Post by JackScott »

Not clever enough. :P
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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 ;)
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

false is allways zero in C/C++ as it is the standard but true is not defined.
Author of COBOS
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

Code: Select all

_Bool detectVideoType(void) {
    return true; // color monitor
}
Who uses a monochrome monitor anyways?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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:
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Post Reply