Detecting Colour and Monochrome Monitors: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
No edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Detecting if you have a colour or monochrome video card is trivial. You can use the values stored in the BIOS data segment to determine this.
Detecting whether a user has a colour or monochrome video card is a trivial task. The [[BIOS]] [[Memory Map (x86)#BIOS Data Area .28BDA.29|data segment]] has a value in it for this information. Below is a function (in ISO C) to retrieve this:


== The Function ==
Here is some C source example of how I do it.
<syntaxhighlight lang="c">
#include <stdint.h>


enum video_type
<pre>
/* video card mono/colour detection by Dark Fiber
* returns 0=mono, 1=colour
*/
int detect_video_type(void)
{
{
VIDEO_TYPE_NONE = 0x00,
int rc;
VIDEO_TYPE_COLOUR = 0x20,
char c=(*(volatile USHORT*)0x410)&0x30;
VIDEO_TYPE_MONOCHROME = 0x30,
};


uint16_t detect_bios_area_hardware(void)
/* C can be 0x00 or 0x20 for colour, 0x30 for mono
{
if(c==0x30){
const uint16_t* bda_detected_hardware_ptr = (const uint16_t*) 0x410;
rc=0; // mono
return *bda_detected_hardware_ptr;
}
}
else

{
enum video_type get_bios_area_video_type(void)
rc=1; // colour
{
}
return (enum video_type) (detect_bios_area_hardware() & 0x30);
return rc;
}
}
</syntaxhighlight>
</pre>


[[Category:Video]]
[[Category:Video]]
[[Category:Hardware Detection]]

Latest revision as of 05:13, 9 June 2024

Detecting whether a user has a colour or monochrome video card is a trivial task. The BIOS data segment has a value in it for this information. Below is a function (in ISO C) to retrieve this:

The Function

#include <stdint.h>

enum video_type
{
    VIDEO_TYPE_NONE = 0x00,
    VIDEO_TYPE_COLOUR = 0x20,
    VIDEO_TYPE_MONOCHROME = 0x30,
};

uint16_t detect_bios_area_hardware(void)
{
    const uint16_t* bda_detected_hardware_ptr = (const uint16_t*) 0x410;
    return *bda_detected_hardware_ptr;
}

enum video_type get_bios_area_video_type(void)
{
    return (enum video_type) (detect_bios_area_hardware() & 0x30);
}