Detecting Colour and Monochrome Monitors: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(fixed error in commenting.)
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(6 intermediate revisions by 4 users not shown)
Line 1:
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 ==
<syntaxhighlight lang="c">
<pre>
#include <stdint.h>
/*
 
Video card mono/colour detection.
enum video_type
Return values: false=colour
true=monochrome
*/
_Bool detectVideoType(void)
{
VIDEO_TYPE_NONE = 0x00,
_Bool type;
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;
return(true); //Monochrome monitor.
return *bda_detected_hardware_ptr;
} else {
}
return(false); //Colour monitor.
 
}
enum video_type get_bios_area_video_type(void)
{
return (enum video_type) (detect_bios_area_hardware() & 0x30);
}
</syntaxhighlight>
</pre>
 
[[Category:Video]]
[[Category:Hardware Detection]]