typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned int DWORD; enum Colour{ BLACK=0, BLUE, GREEN, CYAN, RED, MAGNETA, BROWN, LGRAY, \ DGRAY=8, LBLUE, LGREEN, LCYAN, LRED, LMAGNETA, YELLOW, WHITE}; #define COLOUR(forecolour, backcolour) ((backcolour) << 4 | (forecolour) & 0x0F) void WriteString(int y, int x, BYTE colour, char *string) { volatile WORD *pvram; for (DWORD i=0;string[i]!=0; x++, i++) { pvram = (volatile WORD *)0xB8000 + y * 80 + x; *pvram = (BYTE)string[i] | colour << 8; } } void WriteCharacter(int y, int x, BYTE colour, BYTE ch) { volatile WORD * pvram; pvram = (volatile WORD *)0xB8000 + (y * 80 + x) ; *pvram = ch | (colour << 8); } int main() { WriteCharacter(1,0, COLOUR(RED, BLACK), 'H'); WriteCharacter(1,1, COLOUR(RED, BLACK), 'i'); WriteString(1, 3, COLOUR(GREEN, BLACK), "Martin."); }
在螢幕座標(y,x) = (1, 0) 秀出 Hi Martin.
ps. 如果想畫一個點陣圖請參考 mode 13h, 解析度為320*200, 256色, 透過寫入A000:0來完成
題外話, 我用了以上的技巧寫了一個Dos版的source code Editor, 名稱叫E editor (下圖)。 平常工作時都會開個Dos模擬器跑Dos tool,享受Dos單純的美。
F1: Copy Line
F2: Paste Line
F3: Delete Line
F10: Save File
下載: (password: martinlee)
E Editor