#define COL8_BLACK 0 // 黒色 #define COL8_RED 1 // 赤色 #define COL8_GREEN 2 // 緑色 #define COL8_YELLOW 3 // 黄色 #define COL8_BLUE 4 // 青色 #define COL8_PURPLE 5 // 紫色 #define COL8_WATER 6 // 水色 #define COL8_WHITE 7 // 白色 #define COL8_GRAY 8 // 灰色 #define COL8_DARKRED 9 // 赤色(暗い) #define COL8_DARKGREEN 10 // 緑色(暗い) #define COL8_DARKYELLOW 11 // 黄色(暗い) #define COL8_DARKBLUE 12 // 青色(暗い) #define COL8_DARKPURPLE 13 // 紫色(暗い) #define COL8_DARKWATER 14 // 水色(暗い) #define COL8_DARKGRAY 15 // 灰色(暗い) // naskfunc.nasで定義している関数群 void io_hlt(void); void io_cli(void); void io_sti(void); void io_out8(int port, int data); int io_load_eflags(void); void io_store_eflags(int eflags); // bootpack.cで定義している関数群 unsigned char *init_palette(void); void set_palette(int start, int end, unsigned char *rgb); void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1); // ------------------------------------------------------------------ // メイン関数 // ------------------------------------------------------------------ void HariMain(void) { int i; // VRAMのアドレス char *vram = (char *)0xa0000; int xsize = 320; // 画面のX軸のサイズ int ysize = 200; // 画面のY軸のサイズ // パレットの初期化 set_palette(COL8_BLACK, COL8_DARKGRAY, init_palette()); // 画面の描画 for (i = COL8_BLACK; i <= COL8_DARKGRAY; i++) boxfill8(vram, xsize, i, (i * 20), 0, ((i + 1) * 20) - 1, ysize - 1); while(1) // 無限ループ io_hlt(); // HLT命令でCPUを休ませておく } // ------------------------------------------------------------------ // パケットデータを設定する関数(RGBで設定) // ------------------------------------------------------------------ unsigned char *init_palette(void) { // 色情報をRGBで持っておく static unsigned char table_rgb[16 * 3] = { 0x00, 0x00, 0x00, // 0:黒色 0xff, 0x00, 0x00, // 1:赤色 0x00, 0xff, 0x00, // 2:緑色 0xff, 0xff, 0x00, // 3:黄色 0x00, 0x00, 0xff, // 4:青色 0xff, 0x00, 0xff, // 5:紫色 0x00, 0xff, 0xff, // 6:水色 0xff, 0xff, 0xff, // 7:白色 0xc6, 0xc6, 0xc6, // 8:灰色 0x84, 0x00, 0x00, // 9:赤色(暗い) 0x00, 0x84, 0x00, // 10:緑色(暗い) 0x84, 0x84, 0x00, // 11:黄色(暗い) 0x00, 0x00, 0x84, // 12:青色(暗い) 0x84, 0x00, 0x84, // 13:紫色(暗い) 0x00, 0x84, 0x84, // 14:水色(暗い) 0x84, 0x84, 0x84 // 15:灰色(暗い) }; return table_rgb; } // ------------------------------------------------------------------ // VRAMにパレットをセットする関数 // この関数の詳しい解説は http://community.osdev.info/?VGA を見るべし // ------------------------------------------------------------------ void set_palette(int start, int end, unsigned char *rgb) { //int eflags = io_load_eflags();// 現在のフラグレジスタを記憶 io_cli(); // 許可フラグを0にして割り込み禁止にする io_out8(0x03c8, start); while(start++ <= end) { io_out8(0x03c9, rgb[0] / 4); // 16色の情報を設定 io_out8(0x03c9, rgb[1] / 4); // 1つの色はRGBで3バイトなので、 io_out8(0x03c9, rgb[2] / 4); // このように3回使って設定する rgb += 3; } io_sti(); //io_store_eflags(eflags); // フラグレジスタを復元 return; } // ------------------------------------------------------------------ // 長方形を描く関数 // ------------------------------------------------------------------ void boxfill8(unsigned char *vram, // VRAMのアドレス int xsize, // X軸のサイズ unsigned char c, // 色情報 int x0, int y0, // 開始座標(左上の1点) int x1, int y1 // 終了座標(右下の1点) ) { int x, y; for (y = y0; y <= y1; y++) { // VRAMのアドレスへ for (x = x0; x <= x1; x++) // 1バイトずつ長方形のデータを vram[y * xsize + x] = c; // 書き込んでいく } }