VGA モニターのプログラミングでは、画面に文字を印刷するために、特定のメモリ位置に 16 ビット値を書き込みます。これは、この 16 ビット値のさまざまなビットが画面に表示される文字に変換される方法です。
列挙型を使用して、さまざまな背景/前景色を表しました。
typedef enum
{
eBlack ,
eBlue ,
eGreen ,
eCyan,
eRed,
eMagenta,
eBrown,
eLightGrey,
eDarkGrey,
eLightBlue,
eLightGreen,
eLightCyan,
eLightRed,
eLightMagenta,
eLightBrown,
eWhite
} textColor ;
この関数を作成して、ユーザーが印刷したい文字、前景色と背景色の 3 つに基づいてこの 16 ビット値を作成しました。
前提:私のプラットフォームでは、int 32 ビット、unsigned short 16 ビット、char 8 ビット
void printCharacterOnScreen ( char c , textColor bgColor, textColor fgColor )
{
unsigned char higherByte = ( bgColor << 4 ) | (fgColor ) ;
unsigned char lowerByte = c ;
unsigned short higherByteAs16bitValue = higherByte & 0 ;
higherByteAs16bitValue = higherByteAs16bitValue << 8 ;
unsigned short lowerByteAs16bitValue = lowerByte & 0 ;
unsigned short complete16bitValue = higherByteAs16bitValue & lowerByteAs16bitValue ;
// Then write this value at the special address for VGA devices.
}
Q.コードは正しいですか? また、そのような値を作成する書き込み方法はありますか? この種の操作を行う標準的な方法はありますか?
Q.私のアプローチはプラットフォームに依存しませんか? コードに関するその他のコメントはありますか?