// bootpack.c #include "bootpack.h" #include void HariMain(void) { PBOOTINFO pbinfo = (PBOOTINFO) ADDR_BOOTINFO; char str[256], keybuf[32], mousebuf[128]; unsigned int memtotal; int mx, my, i; MOUSE_DEC mdec; PMEMMAN memman = (PMEMMAN ) MEMMAN_ADDR; PSHTCTL shtctl; PSHEET sht_back, sht_mouse; unsigned char *buf_back, buf_mouse[256]; init_gdtidt(); init_pic(); io_sti(); // IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 // FIFO生成 fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); io_out8(PIC0_IMR, 0xf9); // 1111 1001(PIC1とキーボードを許可) io_out8(PIC1_IMR, 0xef); // 1110 1111(マウスを許可) init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); // 0x00001000 - 0x0009efff memman_free(memman, 0x00400000, memtotal - 0x00400000); set_palette(COL8_BLACK, COL8_DARKGRAY, init_palette()); // ------------------------------------------------------------------ // シート管理構造体を作成 // メモリ領域、VRAMアドレス、画面Xサイズ、画面Yサイズ // ------------------------------------------------------------------ shtctl = shtctl_init(memman, pbinfo->vram, pbinfo->scrnx, pbinfo->scrny); // 2枚のシート領域を作成。画面全部のシートとマウスのシート sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); // 画面全部のシート用のメモリ確保 buf_back = (unsigned char *) memman_alloc_4k( memman, pbinfo->scrnx * pbinfo->scrny); // 画面全部のシートとマウスのシートを設定 sheet_setbuf(sht_back, buf_back, pbinfo->scrnx, pbinfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_screen8(buf_back, pbinfo->scrnx, pbinfo->scrny); init_mouse_cursor8(buf_mouse, 99); // 画面全部シートを描画 sheet_slide(shtctl, sht_back, 0, 0); // マウスの座標計算 mx = ((pbinfo->scrnx - 16) / 4) * 3; my = ((pbinfo->scrny - 28 - 16) / 4) * 3; // マウスシートを描画 sheet_slide(shtctl, sht_mouse, mx, my); sheet_updown(shtctl, sht_back, 0); sheet_updown(shtctl, sht_mouse, 1); // マウス描画 //init_mouse_cursor8(buf_mouse, COL8_DARKWATER); //putblock8_8(pbinfo->vram, pbinfo->scrnx, 16, 16, mx, my, mcursor, 16); // マウス位置を文字列で表示 sprintf(str, "mouse is (x, y) = (%d, %d)", mx, my); putfonts8_asc(buf_back, pbinfo->scrnx, 0, 0, COL8_WHITE, str); // 文字列を表示 sprintf(str, "I will make the hariboteOS after 25 days."); putfonts8_asc(buf_back, pbinfo->scrnx, 0, 32, COL8_YELLOW, str); sprintf(str, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, pbinfo->scrnx, 0, 64, COL8_WHITE, str); sheet_refresh(shtctl, sht_back, 0, 0, pbinfo->scrnx, 128); while (1) { // 無限ループ(割り込みで取得したデータを監視) io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); // マウスもキーボードもデータなしなら休む } else { if (fifo8_status(&keyfifo) != 0) { // キーボードデータがあるなら i = fifo8_get(&keyfifo); // FIFOから取得 io_sti(); sprintf(str, "%02X", i); // 出力 boxfill8(buf_back, pbinfo->scrnx, COL8_DARKWATER, 0, 16, 15, 31); putfonts8_asc(buf_back, pbinfo->scrnx, 0, 16, COL8_WHITE, str); sheet_refresh(shtctl, sht_back, 0, 16, 16, 32); } else if (fifo8_status(&mousefifo) != 0) { // マウスデータがあるなら i = fifo8_get(&mousefifo); // FIFOから取得 io_sti(); if (mouse_decode(&mdec, i) != 0) { // データが3バイト揃ったので表示 sprintf(str, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) str[1] = 'L'; if ((mdec.btn & 0x02) != 0) str[3] = 'R'; if ((mdec.btn & 0x04) != 0) str[2] = 'C'; boxfill8(buf_back, pbinfo->scrnx, COL8_DARKWATER, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(buf_back, pbinfo->scrnx, 32, 16, COL8_WHITE, str); // マウスカーソルの移動 //boxfill8(buf_back, pbinfo->scrnx, COL8_DARKWATER, // mx, my, mx + 15, my + 15); // マウス消す sheet_refresh(shtctl, sht_back, 32, 16, 32 + 15 * 8, 32); mx += mdec.x; my += mdec.y; if (mx < 0) mx = 0; if (my < 0) my = 0; if (mx > pbinfo->scrnx - 16) mx = pbinfo->scrnx - 16; if (my > pbinfo->scrny - 16) my = pbinfo->scrny - 16; sprintf(str, "mouse is (x, y) = (%d, %d)", mx, my); putfonts8_asc(buf_back, pbinfo->scrnx, 0, 0, COL8_WHITE, str); boxfill8(buf_back, pbinfo->scrnx, COL8_DARKWATER, 0, 0, 299, 15); putfonts8_asc(buf_back, pbinfo->scrnx, 0, 0, COL8_WHITE, str); //putblock8_8(buf_back, pbinfo->scrnx, // 16, 16, mx, my, buf_mouse, 16); sheet_refresh(shtctl, sht_back, 0, 0, 300, 16); sheet_slide(shtctl, sht_mouse, mx, my); } } } } }