/*-----------------------------------------------------------------------*/ void init_all_and_POST(void) { int i = 0; /* TF卡 */ TCHAR *path = "0:"; disable_watchdog(); init_modes_and_clock(); initEMIOS_0MotorAndSteer(); initEMIOS_0Image();/* 摄像头输入中断初始化 */ init_pit(); init_led(); init_DIP(); init_serial_port_0(); init_serial_port_1(); init_serial_port_2(); //init_ADC(); //init_serial_port_3(); init_supersonic_receive_0(); init_supersonic_receive_1(); // init_supersonic_receive_2(); // init_supersonic_receive_3(); init_supersonic_trigger_0(); init_supersonic_trigger_1(); // init_supersonic_trigger_2(); // init_supersonic_trigger_3(); // init_optical_encoder(); //init_DSPI_2(); //init_I2C(); init_choose_mode(); /* 初始化SPI总线 */ init_DSPI_1(); /* 开启外部总中断 */ enable_irq(); /* 初始化显示屏 */ initLCD(); //LCD_DISPLAY(); LCD_Fill(0xFF); /* 亮屏 */ delay_ms(50); LCD_Fill(0x00); /* 黑屏 */ delay_ms(50); #if 1 /* 初始化TF卡 */ LCD_P8x16Str(0,0, (BYTE*)"TF.."); if (!SD_init()) { /* 挂载TF卡文件系统 */ if (FR_OK == f_mount(&fatfs1, path, 1)) { /* 文件读写测试 */ if (!test_file_system()) { g_devices_init_status.TFCard_is_OK = 1; } } } if (g_devices_init_status.TFCard_is_OK) { LCD_P8x16Str(0,0, (BYTE*)"TF..OK"); } else { LCD_P8x16Str(0,0, (BYTE*)"TF..NOK"); suicide(); } /* 读取设备号 */ LCD_P8x16Str(0, 4, (BYTE*)"DeviceNo="); if (!read_device_no_from_TF()) { if (WIFI_ADDRESS_WITHOUT_INIT != g_device_NO) { LCD_PrintoutInt(72, 4, g_device_NO); } else { suicide(); } } else { suicide(); } /* 开启RFID读卡器主动模式 */ if (!init_RFID_modul_type()) { g_devices_init_status.RFIDCard_energetic_mode_enable_is_OK = 1; LCD_P8x16Str(0, 6, (BYTE*)"RFID..OK"); } else { g_devices_init_status.RFIDCard_energetic_mode_enable_is_OK = 0; LCD_P8x16Str(0, 6, (BYTE*)"RFID..NOK"); suicide(); } delay_ms(1000); /* 换屏 */ LCD_Fill(0x00); /* 读取舵机参数 */ LCD_P8x16Str(0, 0, (BYTE*)"StH.L="); if (read_steer_helm_data_from_TF()) { suicide(); } update_steer_helm_basement_to_steer_helm(); LCD_PrintoutInt(48, 0, data_steer_helm_basement.left_limit); set_steer_helm_basement(data_steer_helm_basement.left_limit); delay_ms(500); LCD_P8x16Str(0, 2, (BYTE*)"StH.R="); LCD_PrintoutInt(48, 2, data_steer_helm_basement.right_limit); set_steer_helm_basement(data_steer_helm_basement.right_limit); delay_ms(500); LCD_P8x16Str(0, 4, (BYTE*)"StH.C="); LCD_PrintoutInt(48, 4, data_steer_helm_basement.center); set_steer_helm_basement(data_steer_helm_basement.center); /* 读取mode号 */ LCD_P8x16Str(0, 6, (BYTE*)"MODE="); LCD_PrintoutInt(40, 6, mode); //set_pos_target(); delay_ms(1000); /* 换屏 */ LCD_Fill(0x00); /* 速度闭环测试 */ g_f_enable_speed_control = 1; LCD_P8x16Str(0, 4, (BYTE*)"S.T=0"); set_speed_target(0); delay_ms(2000); /* 换屏 */ LCD_Fill(0x00); #endif }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256]; struct SHEET *sht_back, *sht_mouse; struct TASK *task_a, *task; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; int j, x, y, mmx = -1, mmy = -1, mmx2 = 0; struct SHEET *sht = 0, *key_win; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); *((int *) 0x0fec) = (int) &fifo; init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); *((int *) 0x0fe4) = (int) shtctl; /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ key_win = open_console(shtctl, memtotal); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(key_win, 32, 4); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(key_win, 1); sheet_updown(sht_mouse, 2); keywin_on(key_win); /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* キーボードコントローラに送るデータがあれば、送る */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { /* FIFOがからっぽになったので、保留している描画があれば実行する */ if (new_mx >= 0) { io_sti(); sheet_slide(sht_mouse, new_mx, new_my); new_mx = -1; } else if (new_wx != 0x7fffffff) { io_sti(); sheet_slide(sht, new_wx, new_wy); new_wx = 0x7fffffff; } else { task_sleep(task_a); io_sti(); } } else { i = fifo32_get(&fifo); io_sti(); if (key_win != 0 && key_win->flags == 0) { /* ウィンドウが閉じられた */ if (shtctl->top == 1) { /* もうマウスと背景しかない */ key_win = 0; } else { key_win = shtctl->sheets[shtctl->top - 1]; keywin_on(key_win); } } if (256 <= i && i <= 511) { /* キーボードデータ */ if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 入力文字がアルファベット */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 大文字を小文字に変換 */ } } if (s[0] != 0 && key_win != 0) { /* 通常文字、バックスペース、Enter */ fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f && key_win != 0) { /* Tab */ keywin_off(key_win); j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on(key_win); } if (i == 256 + 0x2a) { /* 左シフト ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右シフト ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左シフト OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右シフト OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */ task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { cons_putstr0(task->cons, "\nBreak(key) :\n"); io_cli(); /* 強制終了処理中にタスクが変わると困るから */ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); } } if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */ /* 新しく作ったコンソールを入力選択状態にする(そのほうが親切だよね?) */ if (key_win != 0) { keywin_off(key_win); } key_win = open_console(shtctl, memtotal); sheet_slide(key_win, 32, 4); sheet_updown(key_win, shtctl->top); keywin_on(key_win); } if (i == 256 + 0x57) { /* F11 */ sheet_updown(shtctl->sheets[1], shtctl->top - 1); } if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* キーボードがデータを無事に受け取れなかった */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } new_mx = mx; new_my = my; if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押している */ if (mmx < 0) { /* 通常モードの場合 */ /* 上の下じきから順番にマウスが指している下じきを探す */ for (j = shtctl->top - 1; j > 0; j--) { sht = shtctl->sheets[j]; x = mx - sht->vx0; y = my - sht->vy0; if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown(sht, shtctl->top - 1); if (sht != key_win) { keywin_off(key_win); key_win = sht; keywin_on(key_win); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { mmx = mx; /* ウィンドウ移動モードへ */ mmy = my; mmx2 = sht->vx0; new_wy = sht->vy0; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) { /* 「×」ボタンクリック */ if ((sht->flags & 0x10) != 0) { /* アプリが作ったウィンドウか? */ task = sht->task; cons_putstr0(task->cons, "\nBreak(mouse) :\n"); io_cli(); /* 強制終了処理中にタスクが変わると困るから */ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); } } break; } } } } else { /* ウィンドウ移動モードの場合 */ x = mx - mmx; /* マウスの移動量を計算 */ y = my - mmy; new_wx = (mmx2 + x + 2) & ~3; new_wy = new_wy + y; mmy = my; /* 移動後の座標に更新 */ } } else { /* 左ボタンを押していない */ mmx = -1; /* 通常モードへ */ if (new_wx != 0x7fffffff) { sheet_slide(sht, new_wx, new_wy); /* 一度確定させる */ new_wx = 0x7fffffff; } } } } else if (768 <= i && i <= 1023) { /* コンソール終了処理 */ close_console(shtctl->sheets0 + (i - 768)); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i, cursor_x, cursor_c; // cursor_x: 记录光标显示位置 unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, '\\', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; init_gdtidt(); init_pic(); io_sti(); /* IDT/PIC的初始化结束,开启CPU中断 */ fifo32_init(&fifo, 128, fifobuf); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* 许可PIC1和键盘(11111000) */ io_out8(PIC1_IMR, 0xef); /* 许可鼠标(11101111) */ timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); // 使用的内存空间,包含了0x00400000前已用的内存 memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 没有透明色 */ sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // 透明色号99 sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 没有透明色 */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "window"); make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { /* J char ss[10]; sprintf(ss, "%c", "J"); putfonts8_asc(binfo->vram, binfo->scrnx, 100, 100, COL8_FFFFFF, ss); */ io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* 键盘数据 */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 256 + 0x54) { if (keytable[i - 256] != 0 && cursor_x < 144) { /* 通常文字 */ /* 显示1个字符就前移1次光标 */ s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { /* 退格键 */ /* 用空格键把光标消去后,后移1次光标 */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } /* カーソルの再表示 */ boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* 鼠标的3个字节都齐了,显示出来 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* 移动鼠标 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 按下左键、移动sht_win */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i == 10) { /* 10秒定时器 */ putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (i == 3) { /* 3秒定时器 */ putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i <= 1) { /* 光标用定时器 */ if (i != 0) { timer_init(timer3, &fifo, 0); /* 下面设定0 */ cursor_c = COL8_000000; } else { timer_init(timer3, &fifo, 1); /* 下面设定1 */ cursor_c = COL8_FFFFFF; } timer_settime(timer3, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
/* Check if MAGIC is valid and print the Multiboot information structure pointed by ADDR. */ void entry (unsigned long magic, unsigned long addr) { multiboot_info_t *mbi; uint8_t* filesystem_address; /* Clear the screen. */ clear(); /* Am I booted by a Multiboot-compliant boot loader? */ if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { printf ("Invalid magic number: 0x%#x\n", (unsigned) magic); return; } /* Set MBI to the address of the Multiboot information structure. */ mbi = (multiboot_info_t *) addr; /* Print out the flags. */ printf ("flags = 0x%#x\n", (unsigned) mbi->flags); /* Are mem_* valid? */ if (CHECK_FLAG (mbi->flags, 0)) printf ("mem_lower = %uKB, mem_upper = %uKB\n", (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper); /* Is boot_device valid? */ if (CHECK_FLAG (mbi->flags, 1)) printf ("boot_device = 0x%#x\n", (unsigned) mbi->boot_device); /* Is the command line passed? */ if (CHECK_FLAG (mbi->flags, 2)) printf ("cmdline = %s\n", (char *) mbi->cmdline); if (CHECK_FLAG (mbi->flags, 3)) { int mod_count = 0; int i; module_t* mod = (module_t*)mbi->mods_addr; while(mod_count < mbi->mods_count) { filesystem_address = (uint8_t*)mod->mod_start; printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start); printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end); printf("First few bytes of module:\n"); for(i = 0; i<16; i++) { printf("0x%x ", *((char*)(mod->mod_start+i))); } printf("\n"); mod_count++; mod++; } } /* Bits 4 and 5 are mutually exclusive! */ if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5)) { printf ("Both bits 4 and 5 are set.\n"); return; } /* Is the section header table of ELF valid? */ if (CHECK_FLAG (mbi->flags, 5)) { elf_section_header_table_t *elf_sec = &(mbi->elf_sec); printf ("elf_sec: num = %u, size = 0x%#x," " addr = 0x%#x, shndx = 0x%#x\n", (unsigned) elf_sec->num, (unsigned) elf_sec->size, (unsigned) elf_sec->addr, (unsigned) elf_sec->shndx); } /* Are mmap_* valid? */ if (CHECK_FLAG (mbi->flags, 6)) { memory_map_t *mmap; printf ("mmap_addr = 0x%#x, mmap_length = 0x%x\n", (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length); for (mmap = (memory_map_t *) mbi->mmap_addr; (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; mmap = (memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof (mmap->size))) printf (" size = 0x%x, base_addr = 0x%#x%#x\n" " type = 0x%x, length = 0x%#x%#x\n", (unsigned) mmap->size, (unsigned) mmap->base_addr_high, (unsigned) mmap->base_addr_low, (unsigned) mmap->type, (unsigned) mmap->length_high, (unsigned) mmap->length_low); } /* Construct an LDT entry in the GDT */ { seg_desc_t the_ldt_desc; the_ldt_desc.granularity = 0; the_ldt_desc.opsize = 1; the_ldt_desc.reserved = 0; the_ldt_desc.avail = 0; the_ldt_desc.present = 1; the_ldt_desc.dpl = 0x0; the_ldt_desc.sys = 0; the_ldt_desc.type = 0x2; SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size); ldt_desc_ptr = the_ldt_desc; lldt(KERNEL_LDT); } /* Construct a TSS entry in the GDT */ { seg_desc_t the_tss_desc; the_tss_desc.granularity = 0; the_tss_desc.opsize = 0; the_tss_desc.reserved = 0; the_tss_desc.avail = 0; the_tss_desc.seg_lim_19_16 = TSS_SIZE & 0x000F0000; the_tss_desc.present = 1; the_tss_desc.dpl = 0x0; the_tss_desc.sys = 0; the_tss_desc.type = 0x9; the_tss_desc.seg_lim_15_00 = TSS_SIZE & 0x0000FFFF; SET_TSS_PARAMS(the_tss_desc, &tss, tss_size); tss_desc_ptr = the_tss_desc; tss.ldt_segment_selector = KERNEL_LDT; tss.ss0 = KERNEL_DS; tss.esp0 = 0x800000; ltr(KERNEL_TSS); } int z = 0; reset_scr(); //set the IDT set_idt(); lidt(idt_desc_ptr); /* Init the PIC */ i8259_init(); /* Initialize devices, memory, filesystem, enable device interrupts on the * PIC, any other initialization stuff... */ //init paging init_paging(); //init filesystem init_filesys(filesystem_address); //init keyboard init_keyboard(); //init the rtc init_rtc(); //init the mouse init_mouse(); //clear the screen reset_scr(); // boot_screen(); for(z = 0; z < 3; z++) { terminal_init(); } node* buffer = screens[0]; reset_buf(buffer); //display the status bar /* Enable interrupts */ sti(); /* Do not enable the following until after you have set up your * IDT correctly otherwise QEMU will triple fault and simple close * without showing you any output */ boot_screen(); //sample mario sound for(z = 0; z < 500000; z++) play_sound(1000); for(z = 0; z < 500000; z++) play_sound(100); for(z = 0; z < 500000; z++) play_sound(900); for(z = 0; z < 50000; z++) play_sound(200); for(z = 0; z < 500000; z++) play_sound(800); for(z = 0; z < 500000; z++) play_sound(300); for(z = 0; z < 500000; z++) play_sound(700); for(z = 0; z < 500000; z++) play_sound(400); for(z = 0; z < 500000; z++) play_sound(600); for(z = 0; z < 500000; z++) play_sound(500); for(z = 0; z < 500000; z++) play_sound(500); for(z = 0; z < 500000; z++) play_sound(1000); for(z = 0; z < 500000; z++) play_sound(400); for(z = 0; z < 500000; z++) play_sound(300); for(z = 0; z < 500000; z++) play_sound(300); for(z = 0; z < 500000; z++) play_sound(200); //boot_screen(); nosound(); reset_scr(); //init PIT for sound, timer init_pit(0, 100); ///////////////////////////////////////////////////////////// // void imperial(); status_bar(); /* Execute the first program (`shell') ... */ uint8_t fname[33] = "shell"; execute(fname); /* We should never get to this point */ //printf("Initial shell halted."); /* Spin (nicely, so we don't chew up cycles) */ asm volatile(".1: hlt; jmp .1;"); }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i, cursor_x, cursor_c, task_b_esp; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; struct TSS32 tss_a, tss_b; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; init_gdtidt(); init_pic(); io_sti(); fifo32_init(&fifo, 128, fifobuf); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "window"); make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB" , memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_b.ldtr = 0; tss_b.iomap = 0x40000000; set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32); set_segmdesc(gdt + 4, 103, (int) &tss_b, AR_TSS32); load_tr(3 * 8); task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024; tss_b.eip = (int) &task_b_main; tss_b.eflags = 0x00000202; tss_b.eax = 0; tss_b.ecx = 0; tss_b.edx = 0; tss_b.ebx = 0; tss_b.esp = task_b_esp; tss_b.ebp = 0; tss_b.esi = 0; tss_b.edi = 0; tss_b.es = 1 * 8; tss_b.cs = 2 * 8; tss_b.ss = 1 * 8; tss_b.ds = 1 * 8; tss_b.fs = 1 * 8; tss_b.gs = 1 * 8; for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <=i && i <= 511) { sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x54 + 256) { if (keytable[i - 256] != 0 && cursor_x < 144) { s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x , 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { if (mouse_decode(&mdec, i - 512) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i == 10) { putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); taskswitch4(); } else if (i == 3) { putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i <= 1) { if (i != 0) { timer_init(timer3, &fifo, 0); cursor_c = COL8_000000; } else { timer_init(timer3, &fifo, 1); cursor_c = COL8_FFFFFF; } timer_settime(timer3, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO8 timerfifo, timerfifo2, timerfifo3; char s[40], keybuf[32], mousebuf[128], timerbuf[8], timerbuf2[8], timerbuf3[8]; struct TIMER *timer, *timer2, *timer3; int mx, my, i; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); init_pit(); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); fifo8_init(&timerfifo, 8, timerbuf); timer = timer_alloc(); timer_init(timer, &timerfifo, 1); timer_settime(timer, 1000); fifo8_init(&timerfifo2, 8, timerbuf2); timer2 = timer_alloc(); timer_init(timer2, &timerfifo2, 1); timer_settime(timer2, 300); fifo8_init(&timerfifo3, 8, timerbuf3); timer3 = timer_alloc(); timer_init(timer3, &timerfifo3, 1); timer_settime(timer3, 50); init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { sprintf(s, "%010d", timerctl.count); putfonts8_asc_sht(sht_win, 40, 28, COL8_000000, COL8_C6C6C6, s, 10); io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) + fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3) == 0) { io_sti(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); } } else if (fifo8_status(&timerfifo) != 0) { i = fifo8_get(&timerfifo); io_sti(); putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (fifo8_status(&timerfifo2) != 0) { i = fifo8_get(&timerfifo2); io_sti(); putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (fifo8_status(&timerfifo3) != 0) { i = fifo8_get(&timerfifo3); io_sti(); if (i != 0) { timer_init(timer3, &timerfifo3, 0); boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); } else { timer_init(timer3, &timerfifo3, 1); boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); } timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } } }
void HariMain(void) { int i; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; char *vram = (*binfo).vram; char msg[40], mcursor[256]; int mx = xsize/2; int my = ysize/2; int fifobuf[128]; struct MOUSE_DEC mdec; unsigned char s[32]; unsigned int memtotal, count = 0; struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; int cursor_x, cursor_c; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_win_b[3]; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_win_b; struct TIMER *timer; struct FIFO32 fifo; struct TASK *task_a, *task_b[3]; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; init_gdtidt (); init_pic (); io_sti (); fifo32_init(&fifo, 32, fifobuf, 0); init_pit(); io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */ io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */ init_keyboard (&fifo, 256); enable_mouse (&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init (memman); memman_free (memman, 0x00001000, 0x009e000); /* 0x00001000 - 0x0009efff */ memman_free (memman, 0x00400000, memtotal - 0x00400000); init_pallete(); shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k (memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *)memman_alloc_4k (memman, 160 * 52); sheet_setbuf (sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf (sht_win, buf_win, 160, 52, -1); init_screen (buf_back, xsize, ysize); init_mouse_cursor8 (buf_mouse, 99); make_window8(buf_win, 160, 52, "task_a", 1); sprintf (s, "(%d, %d)", mx, my); putfonts8_asc (buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf (s, "Memory %dMB, free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); make_textbox8 (sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; //===================== // Task Settings //===================== task_a = task_init(memman); fifo.task = task_a; for (i = 0; i < 3; i++) { sht_win_b[i] = sheet_alloc(shtctl); buf_win_b = (unsigned char *)memman_alloc_4k(memman, 144 * 52); sheet_setbuf(sht_win_b[i], buf_win_b, 144, 52, -1); sprintf(s, "task_b%d", i); make_window8(buf_win_b, 144, 52, s, 0); task_b[i] = task_alloc(); task_b[i]->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; task_b[i]->tss.eip = (int)&task_b_main; task_b[i]->tss.es = 1 * 8; task_b[i]->tss.cs = 2 * 8; task_b[i]->tss.ss = 1 * 8; task_b[i]->tss.ds = 1 * 8; task_b[i]->tss.fs = 1 * 8; task_b[i]->tss.gs = 1 * 8; *((int *)(task_b[i]->tss.esp + 4)) = (int)sht_win_b[i]; task_run (task_b[i], i+1); } //======================= // Sheet Setting //======================= sheet_slide (sht_back, 0, 0); sheet_slide (sht_mouse, mx, my); sheet_slide (sht_win_b[0], 168, 56); sheet_slide (sht_win_b[1], 8, 116); sheet_slide (sht_win_b[2], 168, 116); sheet_slide (sht_win, 8, 56); sheet_updown (sht_back, 0); sheet_updown (sht_win_b[0], 1); sheet_updown (sht_win_b[1], 2); sheet_updown (sht_win_b[2], 3); sheet_updown (sht_win, 4); sheet_updown (sht_mouse, 5); sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48); for (;;) { count ++; io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { // Keyboard Data sprintf (s, "%x", i - 256); putfonts8_asc_sht (sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 256 + 0x54) { if (keytable[i - 256] != 0) { s[0] = keytable[i-256]; s[1] = 0; putfonts8_asc_sht (sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { // Backspace putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { // Mouse Data if (mouse_decode(&mdec, i-512) != 0) { sprintf (s, "[lcr %d %d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht (sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%d, %d)", mx, my); putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide (sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide (sht_win, mx - 80, my - 8); } } } else if (i == 10) { putfonts8_asc_sht (sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (i == 3) { putfonts8_asc_sht (sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); count = 0; } else if (i <= 1) { if (i != 0) { timer_init(timer, &fifo, 0); cursor_c = COL8_000000; } else { timer_init(timer, &fifo, 1); cursor_c = COL8_FFFFFF; } timer_settime(timer, 50); boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256]; struct SHEET *sht_back, *sht_mouse; struct TASK *task_a, *task; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; int j, x, y, mmx = -1, mmy = -1, mmx2 = 0; struct SHEET *sht = 0, *key_win; init_gdtidt(); init_pic(); io_sti(); fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); *((int *) 0x0fe4) = (int) shtctl; sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); key_win = open_console(shtctl, memtotal); sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(key_win, 32, 4); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(key_win, 1); sheet_updown(sht_mouse, 2); keywin_on(key_win); fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { if (new_mx >= 0) { io_sti(); sheet_slide(sht_mouse, new_mx, new_my); new_mx = -1; } else if (new_wx != 0x7fffffff) { io_sti(); sheet_slide(sht, new_wx, new_wy); new_wx = 0x7fffffff; } else { task_sleep(task_a); io_sti(); } } else { i = fifo32_get(&fifo); io_sti(); if (key_win->flags == 0) { key_win = shtctl->sheets[shtctl->top - 1]; keywin_on(key_win); } if (256 <=i && i <= 511) { if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0) { fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f) { keywin_off(key_win); j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on(key_win); } if (i == 256 + 0x2a) { key_shift |= 1; } if (i == 256 + 0x36) { key_shift |= 2; } if (i == 256 + 0xaa) { key_shift &= ~1; } if (i == 256 + 0xb6) { key_shift &= ~2; } if (i == 256 + 0x3a) { key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0) { task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { cons_putstr0(task->cons, "\nBreak(key) :\n"); io_cli(); task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); } } if (i == 256 + 0x3c && key_shift != 0 ) { keywin_off(key_win); key_win = open_console(shtctl, memtotal); sheet_slide(key_win, 32, 4); sheet_updown(key_win, shtctl->top); keywin_on(key_win); } if (i == 256 + 0x57) { sheet_updown(shtctl->sheets[1], shtctl->top - 1); } if (i == 256 + 0xfa) { keycmd_wait = -1; } if (i == 256 + 0xfe) { wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } } else if (512 <= i && i <= 767) { if (mouse_decode(&mdec, i - 512) != 0) { mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } new_mx = mx; new_my = my; if ((mdec.btn & 0x01) != 0) { if (mmx < 0) { for (j = shtctl->top - 1; j > 0; j--) { sht = shtctl->sheets[j]; x = mx - sht->vx0; y = my - sht->vy0; if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown(sht, shtctl->top - 1); if (sht != key_win) { keywin_off(key_win); key_win = sht; keywin_on(key_win); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { mmx = mx; mmy = my; mmx2 = sht->vx0; new_wy = sht->vy0; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <=y && y < 19) { if ((sht->flags & 0x10) != 0) { task = sht->task; cons_putstr0(task->cons, "\nBreak(mouse) :\n"); io_cli(); task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); } } break; } } } } else { x = mx - mmx; y = my -mmy; new_wx = (mmx2 + x + 2) & ~3; new_wy = new_wy + y; mmy = my; } } else { mmx = -1; if (new_wx != 0x7fffffff) { sheet_slide(sht, new_wx, new_wy); new_wx = 0x7fffffff; } } } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; struct TASK *task_a, *task_cons; struct TIMER *timer; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; struct CONSOLE *cons; init_gdtidt(); init_pic(); io_sti(); fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = memtotal; task_run(task_cons, 2, 2); sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <=i && i <= 511) { if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0) { if (key_to == 0) { if (cursor_x < 128) { s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { if (key_to == 0) { if (cursor_x > 8) { putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x1c) { if (key_to != 0) { fifo32_put(&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x0f) { if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put(&task_cons->fifo, 2); } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; fifo32_put(&task_cons->fifo, 3); } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { key_shift |= 1; } if (i == 256 + 0x36) { key_shift |= 2; } if (i == 256 + 0xaa) { key_shift &= ~1; } if (i == 256 + 0xb6) { key_shift &= ~2; } if (i == 256 + 0x3a) { key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && task_cons->tss.ss0 != 0) { cons = (struct CONSOLE *) *((int *) 0x0fec); cons_putstr0(cons, "\nBreak(key) :\n"); io_cli(); task_cons->tss.eax = (int) &(task_cons->tss.esp0); task_cons->tss.eip = (int) asm_end_app; io_sti(); } if (i == 256 + 0xfa) { keycmd_wait = -1; } if (i == 256 + 0xfe) { wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { if (mouse_decode(&mdec, i - 512) != 0) { mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { if (i != 0) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; fifo32_t fifo; int fifobuf[128]; char debug_info[64]; int mouse_x, mouse_y, cursor_x, cursor_c; int data; int i; mouse_dec_t mdec; unsigned int memory_total; mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR; layer_mgr_t* layer_mgr; layer_t* back_layer; layer_t* mouse_layer; layer_t* win_layer; layer_t* win_layer_b[3]; unsigned char* back_buf; unsigned char mouse_buf[256]; unsigned char* win_buf; unsigned char* win_buf_b; static char s_keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 0, '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; task_t* task_a; task_t* task_b[3]; timer_t* timer; init_gdt_idt(); init_pic(); io_sti(); /* after initialize IDT/PIC, allow all CPU's interruptors */ fifo_init(&fifo, fifobuf, 128, 0); init_pit(); /* initialize programmable interval timer */ init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* set PIT/PIC1/keyboard permission 11111000 */ io_out8(PIC1_IMR, 0xef); /* set mouse permission 11101111 */ memory_total = memory_test(0x00400000, 0xbfffffff); mem_mgr_init(mem_mgr); mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000); /*0x00001000~0x0009e000*/ mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000); init_palette(); layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, binfo->screen_x, binfo->screen_y); task_a = task_init(mem_mgr); fifo.task = task_a; task_run(task_a, 1, 2); /* back layer */ back_layer = layer_alloc(layer_mgr); back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, binfo->screen_x * binfo->screen_y); layer_setbuf(back_layer, back_buf, binfo->screen_x, binfo->screen_y, -1); init_screen(back_buf, binfo->screen_x, binfo->screen_y); /* window layer b */ for (i = 0; i < 3; ++i) { win_layer_b[i] = layer_alloc(layer_mgr); win_buf_b = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 144 * 52); layer_setbuf(win_layer_b[i], win_buf_b, 144, 52, -1); /* transparent */ sprintf(debug_info, "TASK-B%d", i); make_window8(win_buf_b, 144, 52, debug_info, 0); task_b[i] = task_alloc(); task_b[i]->tss.esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8; task_b[i]->tss.eip = (int)&task_b_main; task_b[i]->tss.es = 1 * 8; task_b[i]->tss.cs = 2 * 8; task_b[i]->tss.ss = 1 * 8; task_b[i]->tss.ds = 1 * 8; task_b[i]->tss.fs = 1 * 8; task_b[i]->tss.gs = 1 * 8; *((int*)(task_b[i]->tss.esp + 4)) = (int)win_layer_b[i]; task_run(task_b[i], 2, i + 1); } /* window layer */ win_layer = layer_alloc(layer_mgr); win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52); layer_setbuf(win_layer, win_buf, 144, 52, -1); make_window8(win_buf, 144, 52, "TASK-A", 1); make_text8(win_layer, 8, 28, 128, 16, COLOR8_FFFFFF); cursor_x = 8; cursor_c = COLOR8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settimer(timer, 50); /* mouse layer */ mouse_layer = layer_alloc(layer_mgr); layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99); init_mouse_cursor8(mouse_buf, 99); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; layer_slide(back_layer, 0, 0); layer_slide(win_layer_b[0], 168, 56); layer_slide(win_layer_b[1], 8, 116); layer_slide(win_layer_b[2], 168, 116); layer_slide(win_layer, 8, 56); layer_slide(mouse_layer, mouse_x, mouse_y); layer_updown(back_layer, 0); layer_updown(win_layer_b[0], 1); layer_updown(win_layer_b[1], 2); layer_updown(win_layer_b[2], 3); layer_updown(win_layer, 4); layer_updown(mouse_layer, 5); sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); sprintf(debug_info, "memory total: %dMB, free space: %dKB", memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024); drawstring_and_refresh(back_layer, 0, 32, COLOR8_FFFFFF, COLOR8_848484, debug_info, 40); for ( ; ; ) { io_cli(); if (0 == fifo_size(&fifo)) { task_sleep(task_a); io_sti(); } else { data = fifo_get(&fifo); io_sti(); if (256 <= data && data <= 511) { sprintf(debug_info, "%02X", data - 256); drawstring_and_refresh(back_layer, 0, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 2); if (data < (256 + 0x54)) { if (0 != s_keytable[data - 256] && cursor_x < 128) { /* normal character, show 1 character, move cursor 1 time */ debug_info[0] = s_keytable[data - 256]; debug_info[1] = 0; drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, debug_info, 1); cursor_x += 8; } } if ((256 + 0x0e) == data && cursor_x > 8) { /* backspace, recover cursor by sapce, move back cursor 1 time */ drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, " ", 1); cursor_x -= 8; } /* show cursor again */ fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= data && data <= 767) { if (0 != mouse_decode(&mdec, data - 512)) { /* show all mouse bytes code */ sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y); if (0 != (mdec.state & 0x01)) debug_info[1] = 'L'; if (0 != (mdec.state & 0x02)) debug_info[3] = 'R'; if (0 != (mdec.state & 0x04)) debug_info[2] = 'C'; drawstring_and_refresh(back_layer, 32, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 15); mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); layer_slide(mouse_layer, mouse_x, mouse_y); if (0 != (mdec.state & 0x01)) { /* down left click, move window */ layer_slide(win_layer, mouse_x - 80, mouse_y - 8); } } } else if (data <= 1) { /* timer by cursor */ if (0 != data) { timer_init(timer, &fifo, 0); cursor_c = COLOR8_000000; } else { timer_init(timer, &fifo, 1); cursor_c = COLOR8_FFFFFF; } timer_settimer(timer, 50); fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; /* 定义一个公共的队列缓冲区管理结构 */ char s[40]; /* 输出缓冲区 */ int fifobuf[128]; /* 队列缓冲区 */ struct TIMER *timer, *timer2, *timer3; int mx, my, i, count = 0; unsigned int memtotal; /* memtotal存放内存大小 */ struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; /* 定义一个MEMMAN结构指针, 指向MEMMAN_ADDR也就是0x3c0000 这就相当于将MEMMAN结构将被存放在0x3c0000处 */ struct SHTCTL *shtctl; /* 图层管理结构指针 */ struct SHEET *sht_back, *sht_mouse, *sht_win; /* 背景、鼠标以及窗口的图层指针 */ unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); /* 初始化GDT, IDT */ init_pic(); /* 初始化PIC */ io_sti(); /* 打开所有可屏蔽中断 */ fifo32_init(&fifo, 128, fifobuf); /* 初始化键盘缓冲区结构体 */ init_pit(); /* 初始化PIT */ init_keyboard(&fifo, 256); /* 初始化键盘控制电路 */ enable_mouse(&fifo, 512, &mdec); /* 激活鼠标 */ io_out8(PIC0_IMR, 0xf8); /* PIC0(11111000) (打开IRQ0时钟中断、IRQ1键盘中断和连接从PIC的IRQ2)*/ io_out8(PIC1_IMR, 0xef); /* PIC1(11101111) (打开PS2鼠标中断 即IRQ12)*/ timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); /* 检测4M~3G-1的内存 memtotal是内存实际大小 */ memman_init(memman); /* 初始化内存管理结构 */ memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ /* 这段内存是4K~636K-1, 这段内存是"安全"的 具体这段内存中有哪些数据可参考群共享中的 "内存分布图.wps"(注意:此时我们引导扇区即ipl10 的512B也在此范围之内,所以说那512B内存现在也是空闲的) */ memman_free(memman, 0x00400000, memtotal - 0x00400000); /* 4M~内存实际大小 */ init_palette(); /* 初始化调色板 */ shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); /* 初始化图层管理结构 */ sht_back = sheet_alloc(shtctl); /* 创建"桌面"图层 */ sht_mouse = sheet_alloc(shtctl); /* 创建鼠标图层 */ sht_win = sheet_alloc(shtctl); /* 创建窗口图层 */ /* 分配内存空间 用于绘制"桌面" */ buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); /* 分配内存空间 用于绘制"窗口 */ sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 设置"桌面"图层信息 */ sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); /* 设置鼠标图层信息 */ sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 设置窗口图层信息 */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* 绘制"桌面" 注意:这里的第一个参数是buf_back而不是原来的binfo->vram */ /* 上面让buf_back指向一块新分配的内存,也就是说原本要画在图形缓冲区的"桌面" 画在了新分配的那块内存,那块内存存放的就是"桌面"图层需要显示的图形 同时 我们要清楚,现在屏幕上并没有原本的桌面背景,因为我们还没有让"桌面"图层显示出来*/ init_mouse_cursor8(buf_mouse, 99); /* 绘制鼠标图形 */ make_window8(buf_win, 160, 52, "counter"); /* 绘制窗口图形 */ sheet_slide(sht_back, 0, 0); /* 设置"桌面"图层的位置 */ mx = (binfo->scrnx - 16) / 2; /* 计算鼠标图形在屏幕上的位置 它在整个桌面的中心位置 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); /* 设置鼠标图层的位置 */ sheet_slide(sht_win, 80, 72); /* 设置窗口图层的位置 */ sheet_updown(sht_back, 0); /* 调整"桌面"图层、鼠标图层和窗口图层的高度 */ sheet_updown(sht_win, 1); /* 并且会显示"桌面"、鼠标和窗口图形 */ sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); /* 在屏幕上输出s的内容 */ sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); /* 在屏幕上输出s的内容 */ for (;;) { count++; io_cli(); if (fifo32_status(&fifo) == 0) { /* 缓冲区中没有数据 */ io_sti(); } else { i = fifo32_get(&fifo); /* 取得缓冲区中的数据 */ io_sti(); if (256 <= i && i <= 511) { /* 属于键盘的数据 */ sprintf(s, "%02X", i - 256); /* 直接输出 */ putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); } else if (512 <= i && i <= 767) { /* 属于鼠标数据 */ if (mouse_decode(&mdec, i - 512) != 0) { /* 接收鼠标发送的数据 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { /* 如果左键被按下 */ s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { /* 如果右键被按下 */ s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { /* 如果滚轮被按下 */ s[2] = 'C'; } /* 输出s的内容 */ putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* 更新新的鼠标位置 */ mx += mdec.x; my += mdec.y; if (mx < 0) { /* 鼠标的位置不能小于0 */ mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { /* 同样是范围控制 */ mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); /* 输出s的内容 */ putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); /* 更新鼠标图层的位置并显示新的鼠标图层 */ sheet_slide(sht_mouse, mx, my); } } else if (i == 10) { /* 10定时器*/ /* 在屏幕上显示"10[sec]"并输出count的值 */ putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); sprintf(s, "%010d", count); putfonts8_asc_sht(sht_win, 40, 28, COL8_000000, COL8_C6C6C6, s, 10); } else if (i == 3) { /* 3定时器 */ /* 在屏幕上显示"10[sec]"并将count清零 */ putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); count = 0; /* 开始测试 */ } else if (i == 1) { /* 光标用定时器 */ timer_init(timer3, &fifo, 0); /* 下面是设定0 */ /* 描绘一个小矩形 */ boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); /* 设置半秒 */ timer_settime(timer3, 50); /* 在屏幕上显示那个小矩形 */ sheet_refresh(sht_back, 8, 96, 16, 112); } else if (i == 0) { /* 光标用定时器 */ timer_init(timer3, &fifo, 1); /* 下面是设定1 */ /* 描绘一个小矩形 */ boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); /* 设置半秒 */ timer_settime(timer3, 50); /* 在屏幕上显示那个小矩形 */ sheet_refresh(sht_back, 8, 96, 16, 112); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; g_binfo = binfo; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i; int cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; struct TSS32 tss_a, tss_b; int task_b_esp; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR*)ADR_GDT; init_gdtidt(); init_pic(); io_sti(); /* GDT,IDT,PIC*/ fifo32_init(&fifo, 128, fifobuf); // timer init_pit(); timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); io_out8(PIC0_IMR, 0xf8); // 11111001,PIC1和IRQ1, io_out8(PIC1_IMR, 0xef); // 11101111, IRQ12 init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); /*没有透明色*/ init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(0x%x, 0x%x)", mx, my); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory 0x%xMB, free : 0x%xKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_b.ldtr = 0; tss_b.iomap = 0x40000000; set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32); set_segmdesc(gdt + 4, 103, (int) &tss_b, AR_TSS32); load_tr(3 * 8); task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; *((int *) (task_b_esp + 4)) = (int) sht_back; tss_b.eip = (int)&task_b_main - ADR_BOTPAK; tss_b.eflags = 0x00000202; /* IF = 1*/ tss_b.eax = 0; tss_b.ecx = 0; tss_b.edx = 0; tss_b.ebx = 0; tss_b.esp = task_b_esp; tss_b.ebp = 0; tss_b.esi = 0; tss_b.edi = 0; tss_b.es = 1 * 8; tss_b.cs = 2 * 8; tss_b.ss = 1 * 8; tss_b.ds = 1 * 8; tss_b.fs = 1 * 8; tss_b.gs = 1 * 8; mt_init(); for(;;) { io_cli(); if(0 == fifo32_status(&fifo)) { io_sti(); }else{ i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { sprintf(s, "0x%x", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 8); if (i < 256 + 0x54) { if (0 != keytable[i - 256] && cursor_x < 144) { s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_C6C6C6, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { // Backspace putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } // if key status else if (512 <= i && i <= 767) { if (0 != mouse_decode(&mdec, i - 512)) { sprintf(s, "[lcr 0x%x 0x%x 0x%x]", mdec.buf[0], mdec.buf[1], mdec.buf[2]); if (0 != (mdec.btn & 0x01)) { s[1] = 'L'; } if (0 != (mdec.btn & 0x02)) { s[3] = 'R'; } if (0 != (mdec.btn & 0x04)) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 64, 16, COL8_FFFFFF, COL8_008484, s, 24); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(0x%x, 0x%x)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 16); sheet_slide(sht_mouse, mx, my); /* 显示鼠标 */ // if ((mdec.btn & 0x01) != 0) { sheet_slide(sht_win, mx - 80, my - 8); } } // if mouse decode } // if 512 767 else if (10 == i) { putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (3 == i) { putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i <= 1) { if (0 != i) { timer_init(timer3, &fifo, 0); // set to 0 cursor_c = COL8_000000; } else { timer_init(timer3, &fifo, 1); cursor_c = COL8_FFFFFF; } boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } // else 0 == getstatus fifo } // for return; }
// the main function void HariMain(void) { char *vram; int xsize; int ysize; unsigned int memtotal; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR ; struct BOOTINFO *binfo; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win,*sht_cons; unsigned char *buf_back, buf_mouse[256],*buf_win; int i; int fifobuf[128]; char s[40]; struct FIFO fifo; fifo_init(&fifo,128,fifobuf,0); static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; init_gdtidt(); init_pic(); io_sti(); init_pit(); // timer io_out8(PIC0_IMR, 0xf8); /* PIC1 (11111000) irq0 */ io_out8(PIC1_IMR, 0xef); //11101111 , allow irq12 struct TIMER *timer; timer = timer_alloc(); timer_set(timer,50,&fifo,1); init_keyboard(&fifo,256); // memory test memtotal = memtest(0x00400000, 0xbfffffff); // available maxmium address memman_init(memman); memman_free(memman,0x00001000,0x0009e000); memman_free(memman,0x00400000,memtotal-0x00400000); init_palette(); binfo = (struct BOOTINFO *) 0x0ff0; xsize = binfo->scrnx; ysize = binfo->scrny; vram = binfo->vram; // sheet setting shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman,160 * 52); // window sheet buffer sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // col_inv 99 sheet_setbuf(sht_win, buf_win,144,52,-1); /* initlize OS background */ init_screen(buf_back,xsize,ysize); int mx,my; // mouse position // mouse cursor struct MOUSE_DEC mdec; enable_mouse(&fifo,512,&mdec); init_mouse_cursor8(buf_mouse,99); // window a setting make_window8(buf_win,144,52,"task a",1); int cursor_x,cursor_c; // cursor color make_textbox8(sht_win, 8,28,128,16,COL8_FFFFFF); // heigth is 16 cursor_x = 8; cursor_c = COL8_FFFFFF; mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; // task block struct TASK *curr,*console; curr = task_init(memman); fifo.task = curr; taskrun(curr,1,0); // set to level 1 // sheet console unsigned char *buf_cons; sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256*165); sheet_setbuf(sht_cons,buf_cons,256,165,-1); make_shell(buf_cons,256,165,"console",0); //make_textbox8(sht_cons, 8,28,240,128,COL8_000084); console = task_alloc(); console->tss.esp = memman_alloc_4k(memman,64*1024) + 64 * 1024 -8; console->tss.eip = (int) &task_console; console->tss.es = 1*8; console->tss.cs = 2*8; console->tss.ss = 1*8; console->tss.ds = 1*8; console->tss.fs = 1*8; console->tss.gs = 1*8; *((int *) (console->tss.esp + 4)) = (int) sht_cons; // memory share taskrun(console,2,2); // level2,different priorities sheet_move(sht_back,0,0);// move background sheet sheet_move(sht_mouse,mx,my); sheet_move(sht_win,8,56); sheet_move(sht_cons,100,200); sheet_updown(sht_back,0); // height 0, at the bottom sheet_updown(sht_cons,1); sheet_updown(sht_win,2); sheet_updown(sht_mouse,3); sprintf(s,"%3d %3d",mx,my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory %dMB free %dkb", memtotal/(1024*1024), memman_total(memman)/1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back,0,0,binfo->scrnx,48); // tab key int key_to=0; int key_shift = 0; int key_leds = ((binfo->leds) >> 4) & 7; // caps,numlock,scrolllock for(;;) { io_cli(); // forbid all interrupts if(fifo_status(&fifo) == 0) {task_sleep(curr); io_sti(); } else { i=fifo_get(&fifo); io_sti(); // open interrupts if(255 < i && i < 512) {sprintf(s, "%02X", i-256); boxfill8(buf_back, binfo->scrnx, COL8_008400, 0, 16, 15, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(sht_back,0,16,16,32); if(i<256 +0x80) { if(key_shift == 0) s[0]= keytable0[i-256]; else s[0]= keytable1[i-256]; } else s[0] =0; if(s[0] >= 'A' && s[0]<= 'Z') { if(((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) == 1 && key_shift != 0)) s[0]+=0x20; } if (s[0] != 0) { // common character if (key_to == 0) { /* ^XNAÖ */ if (cursor_x < 128) { s[1] = 0; bps(sht_win, cursor_x, 28, COL8_FFFFFF, COL8_000000, s, 1); cursor_x += 8; } } else// send to console fifo_put(&console->fifo, s[0] + 256); } if(i == 256 + 0x0e && cursor_x > 8) // backspace key { if(key_to == 0) { bps(sht_win,cursor_x,28,COL8_FFFFFF,COL8_000000," ",1); cursor_x -=8; } else { fifo_put(&console->fifo,8+256); } } if(i == 256 + 0x0f) // Tab key { if(key_to == 0) { key_to =1; make_wtitle8(buf_win, sht_win->bxsize,"task a",0); shell_title(buf_cons, sht_cons->bxsize,"console",1); } else { key_to =0; make_wtitle8(buf_win, sht_win->bxsize,"task a",1); shell_title(buf_cons, sht_cons->bxsize,"console",0); } sheet_refresh(sht_win,0,0,sht_win->bxsize,21); sheet_refresh(sht_cons,0,0,sht_cons->bxsize,21); } if (i == 256 + 0x2a) key_shift |= 1; if (i == 256 + 0x36) key_shift |= 2; if (i == 256 + 0xaa) key_shift &= ~1; if (i == 256 + 0xb6) key_shift &= ~2; if (i == 256 + 0x3a) // CapsLock key_leds ^= 4; if (i == 256 + 0x45) // NumLock key_leds ^= 2; if (i == 256 + 0x46) // ScrollLock key_leds ^= 1; boxfill8(sht_win ->buf, sht_win->bxsize, cursor_c,cursor_x,28,cursor_x+7,43); sheet_refresh(sht_win,cursor_x,28,cursor_x+8,44); } else if(511 < i && i < 768) { if(mouse_decode(&mdec,i-512) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x,mdec.y); if((mdec.btn & 0x01) != 0) s[1]='L'; if((mdec.btn & 0x02) != 0) s[3]='R'; if((mdec.btn & 0x04) != 0) s[2]='C'; boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32+15*8-1, 31); // after filling,show ok putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s); sheet_refresh(sht_back,32,16,32+15*8,32); // the move of mouse mx +=mdec.x; my +=mdec.y; if(mx <0) mx = 0; if(my <0) my = 0; if(mx > binfo->scrnx -1 ) mx = binfo->scrnx -1; if(my > binfo->scrny -1 ) my = binfo->scrny -1; // control the mouse move area sprintf(s, "(%3d,%3d)", mx,my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0,79, 15); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sheet_refresh(sht_back,0,0,80,16); sheet_move(sht_mouse,mx,my); // move the window, vram -> sht -> move if((mdec.btn & 0x01) != 0) sheet_move(sht_win,mx-80,my-8); } } else if(i == 1) { timer_set(timer,50,&fifo,0); boxfill8(sht_win->buf,sht_win->bxsize, COL8_000000, cursor_x, 28,cursor_x+7, 43); sheet_refresh(sht_win,cursor_x,28,cursor_x + 8, 44); } else if(i==0) { timer_set(timer,50,&fifo,1); // keep the data boxfill8(sht_win->buf,sht_win->bxsize, COL8_FFFFFF,cursor_x, 28,cursor_x + 7, 43); sheet_refresh(sht_win,cursor_x,28,cursor_x + 8, 44); } } } }
void main(){ struct BOOTINFO *binfo; struct FIFO32 fifo; binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[MAX_LENGTH]; char mcursor[256]; // mouse and keyboard data int fifobuf[BUF_LEN]; struct TIMER *timer, *timer2, *timer3; int fifo_data; struct MOUSE_DEC mdec; int mx,my; // memory manager struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned int memtotal; // overlay control struct SHTCTL *shtctl; struct SHEET *sht_win, *sht_mouse; unsigned char *buf_back, buf_mouse[256]; unsigned char *buf_win; // gdt control init_gdtidt(); init_pic(); init_pit(); _io_sti(); // init fifo fifo32_init(&fifo, BUF_LEN, fifobuf); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3,&fifo, 1); timer_settime(timer3, 50); // must after init pit // qemu 1000 = 10s // bochs 1000 = 1s _io_out8(PIC0_IMR,0xf8); _io_out8(PIC1_IMR,0xef); // mouse and keyboard control // memory set memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); // this is ERROR! // c400 is system memman_free(memman, 0x00400000, memtotal - 0x00400000); /************************************************** * screen * ----------------------------------------------*/ // video initialize init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); // background sheet sht_mouse = sheet_alloc(shtctl); // mouse sheet sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); // background buffer buf_win = (unsigned char *) memman_alloc_4k(memman,160*52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); // bind buf sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen(buf_back, binfo->scrnx, binfo->scrny); // init color init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); // init slide sheet_slide(sht_back, 0, 0); // initial mouse position mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; int cursor_x, cursor_c; make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; // init mouse slide // init position 0,0 sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win,80,72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); /*------------------------------------------------- * screen * ***********************************************/ /*************** memory info *********/ /* itoa(s,memtotal / 1024 /1024,MAX_LENGTH); putfont8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); itoa(s,memman_total(memman) / 1024,MAX_LENGTH); putfont8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 32, binfo->scrnx, 80); */ /*************** memory info *********/ /* * TSS */ struct TSS32 tss_a, tss_b; tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_b.ldtr = 0; tss_b.iomap = 0x40000000; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; set_segmdesc(gdt+3, 103, (int) &tss_a, AR_TSS32); set_segmdesc(gdt+4, 103, (int) &tss_b, AR_TSS32); int task_b_esp; // current tr _load_tr(3 * 8); task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024; tss_b.eip = (int) &task_b_main; tss_b.eflags = 0x00000202; /* IF = 1; */ tss_b.eax = 0; tss_b.ecx = 0; tss_b.edx = 0; tss_b.ebx = 0; tss_b.esp = task_b_esp; tss_b.ebp = 0; tss_b.esi = 0; tss_b.edi = 0; tss_b.es = 2 * 8; tss_b.cs = 1 * 8; tss_b.ss = 2 * 8; tss_b.ds = 2 * 8; tss_b.fs = 2 * 8; tss_b.gs = 2 * 8; int count = 0; mt_init(); for(;;){ count ++; _io_cli(); if(0 == (fifo32_status(&fifo) )){ _io_stihlt(); //_io_sti(); // too fast } else{ fifo_data = fifo32_get(&fifo); _io_sti(); if(256 <= fifo_data && fifo_data < 512){ // keyboard data if(fifo_data < 256 + 0x54){ if(keytable[fifo_data-256] != 0){ s[0] = keytable[fifo_data-256]; s[1] = 0; putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF,s, 1); cursor_x += 8; // next pos } if(fifo_data == 256 + 0x0e && cursor_x >= 8){ putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF," ", 1); cursor_x -= 8; } // boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x+7, 43); // sheet_refresh(sht_win, cursor_x, 28, cursor_x+7, 43); } } else if(512 <= fifo_data && fifo_data < 768){ // mouse data // fifo_data -= 512; //have some error if (mouse_decode(&mdec,fifo_data - 512) != 0){ mx += mdec.x; my += mdec.y; if(mx < 0){ mx = 0; } if(my < 0){ my = 0; } if(mx > binfo->scrnx - 1){ mx = binfo->scrnx -1; } if(my > binfo->scrny - 1){ my = binfo->scrny -1; } sheet_slide(sht_mouse, mx, my); if( (mdec.btn & 0x01) != 0 && (mx > sht_win->vx0 && mx < (sht_win->vx0 + sht_win->bxsize)) && ( my > sht_win->vy0 - sht_win->bysize*2 && my < (sht_win->vy0 + sht_win->bysize * 2) ) ){ sheet_slide(sht_win, mx - 80, my - 8); } } } else if( fifo_data == 10){ putfont8_asc_sht(sht_back, 0, 140, COL8_FFFFFF, COL8_008484,"10[sec]", 7); itoa(s,count,MAX_LENGTH); putfont8_asc_sht(sht_back, 140, 28, COL8_000000, COL8_C6C6C6, s ,12 ); } else if( fifo_data == 3){ putfont8_asc_sht(sht_back, 100, 0, COL8_FFFFFF, COL8_008484,"3[sec]", 6); } else{ if(fifo_data != 0){ timer_init(timer3, &fifo, 0); boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); } else{ timer_init(timer3, &fifo, 1); boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); } timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], keybuf[32], mousebuf[128]; struct FIFO8 timerfifo, timerfifo2, timerfifo3; char timerbuf[8], timerbuf2[8], timerbuf3[8]; struct TIMER *timer, *timer2, *timer3; int mx, my, i; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); /* IDT/PIC的初始化结束,开启CPU中断 */ fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); init_pit(); io_out8(PIC0_IMR, 0xf8); /* 许可PIC1和键盘(11111000) */ io_out8(PIC1_IMR, 0xef); /* 许可鼠标(11101111) */ fifo8_init(&timerfifo, 8, timerbuf); timer = timer_alloc(); timer_init(timer, &timerfifo, 1); timer_settime(timer, 1000); fifo8_init(&timerfifo2, 8, timerbuf2); timer2 = timer_alloc(); timer_init(timer2, &timerfifo2, 1); timer_settime(timer2, 300); fifo8_init(&timerfifo3, 8, timerbuf3); timer3 = timer_alloc(); timer_init(timer3, &timerfifo3, 1); timer_settime(timer3, 50); init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); // 使用的内存空间,包含了0x00400000前已用的内存 memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 没有透明色 */ sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // 透明色号99 sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 没有透明色 */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); for (;;) { sprintf(s, "%010d", timerctl.count); /* 一共输出10位,没有数的地方用0代替。 */ boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43); putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s); sheet_refresh(sht_win, 40, 28, 120, 44); io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) + fifo8_status(&timerfifo) + fifo8_status(&timerfifo2) + fifo8_status(&timerfifo3) == 0) { /* J char ss[10]; sprintf(ss, "%c", "J"); putfonts8_asc(binfo->vram, binfo->scrnx, 100, 100, COL8_FFFFFF, ss); */ io_sti(); } else if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 16, 16, 32); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { /* 鼠标的3个字节都齐了,显示出来 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s); sheet_refresh(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 > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0, 79, 15); /* 隐藏坐标 */ putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); /* 显示坐标 */ sheet_refresh(sht_back, 0, 0, 80, 16); sheet_slide(sht_mouse, mx, my); } } else if (fifo8_status(&timerfifo) != 0) { i = fifo8_get(&timerfifo); /* 首先读入(为了设定起始点) */ io_sti(); putfonts8_asc(buf_back, binfo->scrnx, 0, 64, COL8_FFFFFF, "10[sec]"); sheet_refresh(sht_back, 0, 64, 56, 80); } else if (fifo8_status(&timerfifo2) != 0) { i = fifo8_get(&timerfifo2); /* 首先读入(为了设定起始点) */ io_sti(); putfonts8_asc(buf_back, binfo->scrnx, 0, 80, COL8_FFFFFF, "3[sec]"); sheet_refresh(sht_back, 0, 80, 48, 96); } else if (fifo8_status(&timerfifo3) != 0) { /* 模拟光标 */ i = fifo8_get(&timerfifo3); io_sti(); if (i != 0) { timer_init(timer3, &timerfifo3, 0); /* 然后设置0 */ boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); } else { timer_init(timer3, &timerfifo3, 1); /* 然后设置1 */ boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); } timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; fifo32_t fifo; int fifobuf[128]; char debug_info[64]; timer_t* timer1; timer_t* timer2; timer_t* timer3; int mouse_x, mouse_y; int data; mouse_dec_t mdec; unsigned int memory_total; mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR; layer_mgr_t* layer_mgr; layer_t* back_layer; layer_t* mouse_layer; layer_t* win_layer; unsigned char* back_buf; unsigned char mouse_buf[256]; unsigned char* win_buf; unsigned int count = 0; init_gdt_idt(); init_pic(); io_sti(); /* after initialize IDT/PIC, allow all CPU's interruptors */ fifo_init(&fifo, fifobuf, 128); init_pit(); /* initialize programmable interval timer */ init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* set PIT/PIC1/keyboard permission 11111000 */ io_out8(PIC1_IMR, 0xef); /* set mouse permission 11101111 */ timer1 = timer_alloc(); timer_init(timer1, &fifo, 10); timer_settimer(timer1, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settimer(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settimer(timer3, 50); memory_total = memory_test(0x00400000, 0xbfffffff); mem_mgr_init(mem_mgr); mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000); /*0x00001000~0x0009e000*/ mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000); init_palette(); layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, binfo->screen_x, binfo->screen_y); back_layer = layer_alloc(layer_mgr); mouse_layer = layer_alloc(layer_mgr); win_layer = layer_alloc(layer_mgr); back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, binfo->screen_x * binfo->screen_y); win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52); layer_setbuf(back_layer, back_buf, binfo->screen_x, binfo->screen_y, -1); layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99); layer_setbuf(win_layer, win_buf, 160, 52, -1); init_screen(back_buf, binfo->screen_x, binfo->screen_y); init_mouse_cursor8(mouse_buf, 99); make_window8(win_buf, 160, 52, "Counter"); layer_slide(back_layer, 0, 0); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; layer_slide(mouse_layer, mouse_x, mouse_y); layer_slide(win_layer, 80, 72); layer_updown(back_layer, 0); layer_updown(win_layer, 1); layer_updown(mouse_layer, 2); sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); sprintf(debug_info, "memory total: %dMB, free space: %dKB", memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024); drawstring_and_refresh(back_layer, 0, 32, COLOR8_FFFFFF, COLOR8_848484, debug_info, 40); for ( ; ; ) { /* sprintf(debug_info, "%010d", g_timerctl.count); drawstring_and_refresh(win_layer, 40, 28, COLOR8_000000, COLOR8_C6C6C6, debug_info, 10); */ ++count; io_cli(); if (0 == fifo_size(&fifo)) io_sti(); else { data = fifo_get(&fifo); io_sti(); if (256 <= data && data <= 511) { sprintf(debug_info, "%02X", data - 256); drawstring_and_refresh(back_layer, 0, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 2); } else if (512 <= data && data <= 767) { if (0 != mouse_decode(&mdec, data - 512)) { /* show all mouse bytes code */ sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y); if (0 != (mdec.state & 0x01)) debug_info[1] = 'L'; if (0 != (mdec.state & 0x02)) debug_info[3] = 'R'; if (0 != (mdec.state & 0x04)) debug_info[2] = 'C'; drawstring_and_refresh(back_layer, 32, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 15); mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); layer_slide(mouse_layer, mouse_x, mouse_y); } } else if (10 == data) { drawstring_and_refresh(back_layer, 0, 64, COLOR8_FFFFFF, COLOR8_848484, "10[sec]", 7); sprintf(debug_info, "%010d", count); drawstring_and_refresh(win_layer, 40, 28, COLOR8_000000, COLOR8_C6C6C6, debug_info, 10); } else if (3 == data) { drawstring_and_refresh(back_layer, 0, 80, COLOR8_FFFFFF, COLOR8_848484, "03[sec]", 7); count = 0; } else if (1 == data) { timer_init(timer3, &fifo, 0); fill_box8(back_buf, binfo->screen_x, COLOR8_FFFFFF, 8, 96, 15, 111); timer_settimer(timer3, 50); layers_refresh(back_layer, 8, 96, 16, 112); } else if (0 == data) { timer_init(timer3, &fifo, 1); fill_box8(back_buf, binfo->screen_x, COLOR8_848484, 8, 96, 15, 111); timer_settimer(timer3, 50); layers_refresh(back_layer, 8, 96, 16, 112); } } } }
void HariMain(void) { struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; struct MOUSE_DEC mdec; unsigned int memtotal; struct SHTCTL *shtctl; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct TASK *task_a, *task_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; int cursor_x, cursor_c, mx, my, i; // cursor_x: 记录光标显示位置 struct TIMER *timer; char s[40]; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', 0, '\\', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; // key_to为1时,console窗口有效 init_gdtidt(); init_pic(); io_sti(); /* IDT/PIC的初始化结束,开启CPU中断 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* 许可PIC1和键盘(11111000) */ io_out8(PIC1_IMR, 0xef); /* 许可鼠标(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); // 使用的内存空间,包含了0x00400000前已用的内存 memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); // 为什么没给tss.eip、tss.esp赋值?task_a什么都不干。 fifo.task = task_a; task_run(task_a, 1, 2); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 没有透明色 */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 无透明色 */ make_window8(buf_cons, 256, 165, "console", 0); // act为1时,颜色不变;act为0时,标题栏变灰色。 make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; // 与bootpack.c相同的地址段,asmkfunc.nas中bootpack启动部分 task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; // 传参 task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 没有透明色 */ make_window8(buf_win, 144, 52, "task_a", 1); // act为1时,颜色不变;act为0时,标题栏变灰色。 make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // 透明色号99 init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back , 0, 0); sheet_slide(sht_cons , 32, 4); sheet_slide(sht_win , 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win , 2); sheet_updown(sht_mouse, 3); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); /* 为了避免和键盘当前状态冲突,在一开始先进行设置 */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* 如果存在想键盘控制器发送的数据,则发送 */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { /* J char ss[10]; sprintf(ss, "%c", "J"); putfonts8_asc(binfo->vram, binfo->scrnx, 100, 100, COL8_FFFFFF, ss); */ task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* 键盘数据 */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x80 + 256) { /* 将按键编码转换为字符编码 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 当输入字符为应为字符时 */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 将大写字母转换为小写字母 */ } } if (s[0] != 0) { /* 通常文字 */ if (key_to == 0) { /* 发送给任务A */ if (cursor_x < 128) { /* 显示1个字符就前移1次光标 */ s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { /* 发送给命令行窗口 */ fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { /* 退格键 */ if (key_to == 0) { /* 发送给任务A */ if (cursor_x > 8) { /* 用空格键把光标消去后,后移1次光标 */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { /* 发送给命令行窗口 */ fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x0f) { /* Tab */ if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { /* 左Shift ON */ key_shift |= 1; // 直接赋值呢? } if (i == 256 + 0x36) { /* 右Shift ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左Shift OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右Shift OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { /* 键盘成功接收到数据 */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* 键盘没有成功接收到数据 */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } /* カーソルの再表示 */ boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* 鼠标的3个字节都齐了,显示出来 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* 移动鼠标 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 按下左键、移动sht_win */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* 光标用定时器 */ if (i != 0) { timer_init(timer, &fifo, 0); /* 下面设定0 */ cursor_c = COL8_000000; } else { timer_init(timer, &fifo, 1); /* 下面设定1 */ cursor_c = COL8_FFFFFF; } timer_settime(timer, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; fifo32_t fifo, keycmd; int fifobuf[128], keycmd_buf[32]; char debug_info[64]; int mouse_x, mouse_y, cursor_x, cursor_c; int data; mouse_dec_t mdec; unsigned int memory_total; mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR; layer_mgr_t* layer_mgr; layer_t* back_layer; layer_t* mouse_layer; layer_t* win_layer; layer_t* cons_layer; unsigned char* back_buf; unsigned char mouse_buf[256]; unsigned char* win_buf; unsigned char* cons_buf; static char s_keytable[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 0, '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static char s_keytable_shift[0x80] = { 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"','~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; task_t* task_a; task_t* task_cons; timer_t* timer; int key_to = 0, key_shift = 0; int key_leds = (binfo->leds >> 4) & 7; /* CapsLock state */ int keycmd_wait = -1; init_gdt_idt(); init_pic(); io_sti(); /* after initialize IDT/PIC, allow all CPU's interruptors */ fifo_init(&fifo, fifobuf, 128, 0); init_pit(); /* initialize programmable interval timer */ init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* set PIT/PIC1/keyboard permission 11111000 */ io_out8(PIC1_IMR, 0xef); /* set mouse permission 11101111 */ fifo_init(&keycmd, keycmd_buf, 32, 0); memory_total = memory_test(0x00400000, 0xbfffffff); mem_mgr_init(mem_mgr); mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000); /*0x00001000~0x0009e000*/ mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000); init_palette(); layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, binfo->screen_x, binfo->screen_y); task_a = task_init(mem_mgr); fifo.task = task_a; task_run(task_a, 1, 2); /* back layer */ back_layer = layer_alloc(layer_mgr); back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, binfo->screen_x * binfo->screen_y); layer_setbuf(back_layer, back_buf, binfo->screen_x, binfo->screen_y, -1); init_screen(back_buf, binfo->screen_x, binfo->screen_y); /* console task */ cons_layer = layer_alloc(layer_mgr); cons_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 256 * 165); layer_setbuf(cons_layer, cons_buf, 256, 165, -1); /* transparent */ make_window8(cons_buf, 256, 165, "Console", 0); make_text8(cons_layer, 8, 28, 240, 128, COLOR8_000000); task_cons = task_alloc(); task_cons->tss.esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8; task_cons->tss.eip = (int)&console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int*)(task_cons->tss.esp + 4)) = (int)cons_layer; task_run(task_cons, 2, 2); /* level = 2, priority = 2 */ /* window layer */ win_layer = layer_alloc(layer_mgr); win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52); layer_setbuf(win_layer, win_buf, 144, 52, -1); make_window8(win_buf, 144, 52, "TASK-A", 1); make_text8(win_layer, 8, 28, 128, 16, COLOR8_FFFFFF); cursor_x = 8; cursor_c = COLOR8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settimer(timer, 50); /* mouse layer */ mouse_layer = layer_alloc(layer_mgr); layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99); init_mouse_cursor8(mouse_buf, 99); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; layer_slide(back_layer, 0, 0); layer_slide(cons_layer, 32, 4); layer_slide(win_layer, 64, 56); layer_slide(mouse_layer, mouse_x, mouse_y); layer_updown(back_layer, 0); layer_updown(cons_layer, 1); layer_updown(win_layer, 2); layer_updown(mouse_layer, 3); sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); sprintf(debug_info, "memory total: %dMB, free space: %dKB", memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024); drawstring_and_refresh(back_layer, 0, 32, COLOR8_FFFFFF, COLOR8_848484, debug_info, 40); fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); for ( ; ; ) { if (fifo_size(&keycmd) > 0 && keycmd_wait < 0) { /* send it when send data to keyboard controller */ keycmd_wait = fifo_get(&keycmd); wait_kbc_sendready(); io_out8(PORT_KEYDATA, keycmd_wait); } io_cli(); if (0 == fifo_size(&fifo)) { task_sleep(task_a); io_sti(); } else { data = fifo_get(&fifo); io_sti(); if (256 <= data && data <= 511) { sprintf(debug_info, "%02X", data - 256); drawstring_and_refresh(back_layer, 0, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 2); if (data < (256 + 0x80)) { /* translation character */ if (0 == key_shift) debug_info[0] = s_keytable[data - 256]; else debug_info[0] = s_keytable_shift[data - 256]; } else debug_info[0] = 0; if ('A' <= debug_info[0] && debug_info[0] <= 'Z') { /* it's an english character */ if ((0 == (key_leds & 4) && 0 == key_shift) || (0 != (key_leds & 4) && 0 != key_shift)) debug_info[0] += 0x20; /* character lower ('A' -> 'a') */ } if (0 != debug_info[0]) { /* general character */ if (0 == key_to) { /* send character data to TASK-A */ if (cursor_x < 128) { /* display one character and cursor move backward one */ debug_info[1] = 0; drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, debug_info, 1); cursor_x += 8; } } else /* send character data to console window */ fifo_put(&task_cons->fifo, debug_info[0] + 256); } if ((256 + 0x0e) == data) { /* backspace, recover cursor by sapce, move back cursor 1 time */ if (0 == key_to) { if (cursor_x > 8) { drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, " ", 1); cursor_x -= 8; } } else fifo_put(&task_cons->fifo, 8 + 256); } if ((256 + 0x0f) == data) { /* TAB */ if (0 == key_to) { key_to = 1; make_title8(win_buf, win_layer->w_size, "TASK-A", 0); make_title8(cons_buf, cons_layer->w_size, "Console", 1); cursor_c = -1; /* don't show the cursor */ fill_box8(win_layer->buf, win_layer->w_size, COLOR8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); } else { key_to = 0; make_title8(win_buf, win_layer->w_size, "TASK-A", 1); make_title8(cons_buf, cons_layer->w_size, "Console", 0); cursor_c = COLOR8_000000; /* show the cursor */ } layers_refresh(win_layer, 0, 0, win_layer->w_size, 21); layers_refresh(cons_layer, 0, 0, cons_layer->w_size, 21); } if ((256 + 0x2a) == data) /* left shift down */ key_shift |= 1; if ((256 + 0x36) == data) /* right shift down */ key_shift |= 2; if ((256 + 0xaa) == data) /* left shift up */ key_shift &= ~1; if ((256 + 0xb6) == data) /* right shift up */ key_shift &= ~2; if ((256 + 0x3a) == data) { /* CapsLock */ key_leds ^= 4; fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); } if ((256 + 0x45) == data) { /* NumLock */ key_leds ^= 2; fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); } if ((256 + 0x46) == data) { /* ScrollLock */ key_leds ^= 1; fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); } if ((256 + 0xfa) == data) /* keyboard recevie data success */ keycmd_wait = -1; if ((256 + 0xfe) == data) { /* keyboard recevie data failed */ wait_kbc_sendready(); io_out8(PORT_KEYDATA, keycmd_wait); } /* show cursor again */ if (cursor_c >= 0) { fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); } layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= data && data <= 767) { if (0 != mouse_decode(&mdec, data - 512)) { /* show all mouse bytes code */ sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y); if (0 != (mdec.state & 0x01)) debug_info[1] = 'L'; if (0 != (mdec.state & 0x02)) debug_info[3] = 'R'; if (0 != (mdec.state & 0x04)) debug_info[2] = 'C'; drawstring_and_refresh(back_layer, 32, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 15); mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); layer_slide(mouse_layer, mouse_x, mouse_y); if (0 != (mdec.state & 0x01)) { /* down left click, move window */ layer_slide(win_layer, mouse_x - 80, mouse_y - 8); } } } else if (data <= 1) { /* timer by cursor */ if (0 != data) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) cursor_c = COLOR8_000000; } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) cursor_c = COLOR8_FFFFFF; } timer_settimer(timer, 50); if (cursor_c >= 0) { fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } } } } }
timer_v1::closure_t* init_timer() { kconsole << "Initializing interrupt timer." << endl; init_pit(100); return &timer; }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo, keycmd; char s[40]; int fifobuf[128], keycmd_buf[32]; struct TIMER *timer; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct TASK *task_a, *task_cons; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 0, '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; init_gdtidt(); init_pic(); io_sti(); fifo32_init(&fifo, 128, fifobuf, 0); fifo32_init(&keycmd, 32, keycmd_buf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e00); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 0); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = memtotal; task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160*52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); /* 为了避免和键盘当前状态冲突 在一开始先进行设置 */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for(;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* 如果存在向键盘控制器发送的数据 则发送 */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* 键盘数据 */ if (i < 0x80 + 256) { /* 将按键编码转换为字符编码 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 当输入字母为英文字母时 */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0) {/* 一般字符 */ if (key_to == 0) { /* 发送给任务A */ if (cursor_x < 128) { /* 显示1个字符就后移1次光标 */ s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { /* 发给命令行窗口 */ fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { /* 退格键 */ if (key_to == 0) { /* 发送给任务A */ if (cursor_x > 8) { /* 用空白擦除光标后将光标前移一位 */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { /* 发给命令行窗口 */ fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x0f) { /* Tab */ if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; /* 不显示光标 */ boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put(&task_cons->fifo, 2); /* 命令行窗口光标ON */ } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; /* 显示光标 */ fifo32_put(&task_cons->fifo, 3); /* 命令行窗口OFF */ } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x1c) { /* Enter */ if (key_to != 0) { /* 发送至命令行窗口 */ fifo32_put(&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x2a) { /* 左Shift ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右Shift ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左Shift OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右Shift OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { /* 键盘成功接受到数据 */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* 键盘没有成功接收到数据 */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } /* 光标再显示 */ if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* 鼠标数据 */ if (mouse_decode(&mdec, i - 512) != 0) { /* 鼠标指针的移动 */ mx += mdec.x / 100; my += mdec.y / 100; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 按下左键 移动sht_win */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* 光标用定时器 */ if (i != 0) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; fifo32_t fifo, keycmd; int fifobuf[128], keycmd_buf[32]; char debug_info[64]; int mouse_x, mouse_y, cursor_x, cursor_c; int data; mouse_dec_t mdec; unsigned int memory_total; mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR; layer_mgr_t* layer_mgr; layer_t* back_layer; layer_t* mouse_layer; layer_t* win_layer; layer_t* cons_layer; unsigned char* back_buf; unsigned char mouse_buf[256]; unsigned char* win_buf; unsigned char* cons_buf; static char s_keytable[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'','`', 0, '\\','Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static char s_keytable_shift[0x80] = { 0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"','~', 0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; task_t* task_a; task_t* task_cons; timer_t* timer; int key_to = 0, key_shift = 0; int key_leds = (binfo->leds >> 4) & 7; /* CapsLock state */ int keycmd_wait = -1; console_t* console; int j, x, y; int movemode_x = -1, movemode_y = -1; layer_t* layer = 0; init_gdt_idt(); init_pic(); io_sti(); /* after initialize IDT/PIC, allow all CPU's interruptors */ fifo_init(&fifo, fifobuf, 128, 0); init_pit(); /* initialize programmable interval timer */ init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* set PIT/PIC1/keyboard permission 11111000 */ io_out8(PIC1_IMR, 0xef); /* set mouse permission 11101111 */ fifo_init(&keycmd, keycmd_buf, 32, 0); memory_total = memory_test(0x00400000, 0xbfffffff); mem_mgr_init(mem_mgr); mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000); /*0x00001000~0x0009e000*/ mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000); init_palette(); layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, binfo->screen_x, binfo->screen_y); task_a = task_init(mem_mgr); fifo.task = task_a; task_run(task_a, 1, 2); *((int*)0x0fe4) = (int)layer_mgr; /* back layer */ back_layer = layer_alloc(layer_mgr); back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, binfo->screen_x * binfo->screen_y); layer_setbuf(back_layer, back_buf, binfo->screen_x, binfo->screen_y, -1); init_screen(back_buf, binfo->screen_x, binfo->screen_y); /* console task */ cons_layer = layer_alloc(layer_mgr); cons_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 256 * 165); layer_setbuf(cons_layer, cons_buf, 256, 165, -1); /* transparent */ make_window8(cons_buf, 256, 165, "Console", 0); make_text8(cons_layer, 8, 28, 240, 128, COLOR8_000000); task_cons = task_alloc(); task_cons->tss.esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int)&console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int*)(task_cons->tss.esp + 4)) = (int)cons_layer; *((int*)(task_cons->tss.esp + 8)) = memory_total; task_run(task_cons, 2, 2); /* level = 2, priority = 2 */ /* window layer */ win_layer = layer_alloc(layer_mgr); win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52); layer_setbuf(win_layer, win_buf, 144, 52, -1); make_window8(win_buf, 144, 52, "TASK-A", 1); make_text8(win_layer, 8, 28, 128, 16, COLOR8_FFFFFF); cursor_x = 8; cursor_c = COLOR8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settimer(timer, 50); /* mouse layer */ mouse_layer = layer_alloc(layer_mgr); layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99); init_mouse_cursor8(mouse_buf, 99); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; layer_slide(back_layer, 0, 0); layer_slide(cons_layer, 32, 4); layer_slide(win_layer, 64, 56); layer_slide(mouse_layer, mouse_x, mouse_y); layer_updown(back_layer, 0); layer_updown(cons_layer, 1); layer_updown(win_layer, 2); layer_updown(mouse_layer, 3); fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); for ( ; ; ) { if (fifo_size(&keycmd) > 0 && keycmd_wait < 0) { /* send it when send data to keyboard controller */ keycmd_wait = fifo_get(&keycmd); wait_kbc_sendready(); io_out8(PORT_KEYDATA, keycmd_wait); } io_cli(); if (0 == fifo_size(&fifo)) { task_sleep(task_a); io_sti(); } else { data = fifo_get(&fifo); io_sti(); if (256 <= data && data <= 511) { if (data < (256 + 0x80)) { /* translation character */ if (0 == key_shift) debug_info[0] = s_keytable[data - 256]; else debug_info[0] = s_keytable_shift[data - 256]; } else debug_info[0] = 0; if ('A' <= debug_info[0] && debug_info[0] <= 'Z') { /* it's an english character */ if ((0 == (key_leds & 4) && 0 == key_shift) || (0 != (key_leds & 4) && 0 != key_shift)) debug_info[0] += 0x20; /* character lower ('A' -> 'a') */ } if (0 != debug_info[0]) { /* general character */ if (0 == key_to) { /* send character data to TASK-A */ if (cursor_x < 128) { /* display one character and cursor move backward one */ debug_info[1] = 0; drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, debug_info, 1); cursor_x += 8; } } else /* send character data to console window */ fifo_put(&task_cons->fifo, debug_info[0] + 256); } if ((256 + 0x0e) == data) { /* backspace, recover cursor by sapce, move back cursor 1 time */ if (0 == key_to) { if (cursor_x > 8) { drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, " ", 1); cursor_x -= 8; } } else fifo_put(&task_cons->fifo, 8 + 256); } if ((256 + 0x1c) == data) { /* Enter Key */ if (0 != key_to) /* send to Console window */ fifo_put(&task_cons->fifo, 10 + 256); } if ((256 + 0x0f) == data) { /* TAB */ if (0 == key_to) { key_to = 1; make_title8(win_buf, win_layer->w_size, "TASK-A", 0); make_title8(cons_buf, cons_layer->w_size, "Console", 1); cursor_c = -1; /* don't show the cursor */ fill_box8(win_layer->buf, win_layer->w_size, COLOR8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo_put(&task_cons->fifo, 2); /* console cursor -> ON */ } else { key_to = 0; make_title8(win_buf, win_layer->w_size, "TASK-A", 1); make_title8(cons_buf, cons_layer->w_size, "Console", 0); cursor_c = COLOR8_000000; /* show the cursor */ fifo_put(&task_cons->fifo, 3); /* console cursor -> OFF */ } layers_refresh(win_layer, 0, 0, win_layer->w_size, 21); layers_refresh(cons_layer, 0, 0, cons_layer->w_size, 21); } if ((256 + 0x2a) == data) /* left shift down */ key_shift |= 1; if ((256 + 0x36) == data) /* right shift down */ key_shift |= 2; if ((256 + 0xaa) == data) /* left shift up */ key_shift &= ~1; if ((256 + 0xb6) == data) /* right shift up */ key_shift &= ~2; if ((256 + 0x3a) == data) { /* CapsLock */ key_leds ^= 4; fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); } if ((256 + 0x45) == data) { /* NumLock */ key_leds ^= 2; fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); } if ((256 + 0x46) == data) { /* ScrollLock */ key_leds ^= 1; fifo_put(&keycmd, KEYCMD_LED); fifo_put(&keycmd, key_leds); } if (((256 + 0x3e) == data) && (0 != key_shift) && (0 != task_cons->tss.ss0)) { /* Shift + F4 force to stop user application */ console = (console_t*)*((int*)0x0fec); console_putstr0(console, "\nbreak(key) :\n"); io_cli(); task_cons->tss.eax = (int)&(task_cons->tss.esp0); task_cons->tss.eip = (int)asm_stop_user_app; io_sti(); } if (((256 + 0x57) == data) && (layer_mgr->top > 2)) { /* F11 switch window */ layer_updown(layer_mgr->layers_addr[1], layer_mgr->top - 1); } if ((256 + 0xfa) == data) /* keyboard recevie data success */ keycmd_wait = -1; if ((256 + 0xfe) == data) { /* keyboard recevie data failed */ wait_kbc_sendready(); io_out8(PORT_KEYDATA, keycmd_wait); } /* show cursor again */ if (cursor_c >= 0) { fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); } layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= data && data <= 767) { if (0 != mouse_decode(&mdec, data - 512)) { mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; layer_slide(mouse_layer, mouse_x, mouse_y); if (0 != (mdec.state & 0x01)) { /* left click button down */ if (movemode_x < 0) { /* down left click, move window */ /* find the layer of mouse on */ for (j = layer_mgr->top - 1; j > 0; --j) { layer = layer_mgr->layers_addr[j]; x = mouse_x - layer->x; y = mouse_y - layer->y; if (0 <= x && x < layer->w_size && 0 <= y && y < layer->h_size) { if (layer->buf[y * layer->w_size + x] != layer->alpha) { layer_updown(layer, layer_mgr->top - 1); if (3 <= x && x < layer->w_size - 3 && 3 <= y && y < 21) { movemode_x = mouse_x; movemode_y = mouse_y; } if (layer->w_size - 21 <= x && x < layer->w_size - 5 && 5 <= y && y < 19) { /* click close button of the window */ if (0 != layer->task) { /* whether it's the window of application */ console = (console_t*)*((int*)0x0fec); console_putstr0(console, "\nbreak(mouse) : \n"); io_cli(); task_cons->tss.eax = (int)&task_cons->tss.esp0; task_cons->tss.eip = (int)asm_stop_user_app; io_sti(); } } break; } } } } else { /* on move mode */ x = mouse_x - movemode_x; y = mouse_y - movemode_y; layer_slide(layer, layer->x + x, layer->y + y); movemode_x = mouse_x; movemode_y = mouse_y; } } else movemode_x = -1; /* return to normal mode */ } } else if (data <= 1) { /* timer by cursor */ if (0 != data) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) cursor_c = COLOR8_000000; } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) cursor_c = COLOR8_FFFFFF; } timer_settimer(timer, 50); if (cursor_c >= 0) { fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; fifo8_t timerfifo; char debug_info[64], keybuf[32], mousebuf[128], timerbuf[8]; int mouse_x, mouse_y; int data; mouse_dec_t mdec; unsigned int memory_total; mem_mgr_t* mem_mgr = (mem_mgr_t*)MEMMGR_ADDR; layer_mgr_t* layer_mgr; layer_t* back_layer; layer_t* mouse_layer; layer_t* win_layer; unsigned char* back_buf; unsigned char mouse_buf[256]; unsigned char* win_buf; init_gdt_idt(); init_pic(); io_sti(); /* after initialize IDT/PIC, allow all CPU's interruptors */ fifo_init(&g_keybuf, keybuf, 32); fifo_init(&g_mousebuf, mousebuf, 128); init_pit(); /* initialize programmable interval timer */ io_out8(PIC0_IMR, 0xf8); /* set PIT/PIC1/keyboard permission 11111000 */ io_out8(PIC1_IMR, 0xef); /* set mouse permission 11101111 */ fifo_init(&timerfifo, timerbuf, 8); set_timer(1000, &timerfifo, 1); init_keyboard(); /* initialize keyboard */ enable_mouse(&mdec); /* enabled mouse */ memory_total = memory_test(0x00400000, 0xbfffffff); mem_mgr_init(mem_mgr); mem_mgr_free(mem_mgr, 0x00001000, 0x0009e000); /*0x00001000~0x0009e000*/ mem_mgr_free(mem_mgr, 0x00400000, memory_total - 0x00400000); init_palette(); layer_mgr = layer_mgr_init(mem_mgr, binfo->vram, binfo->screen_x, binfo->screen_y); back_layer = layer_alloc(layer_mgr); mouse_layer = layer_alloc(layer_mgr); win_layer = layer_alloc(layer_mgr); back_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, binfo->screen_x * binfo->screen_y); win_buf = (unsigned char*)mem_mgr_alloc_4k(mem_mgr, 160 * 52); layer_setbuf(back_layer, back_buf, binfo->screen_x, binfo->screen_y, -1); layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99); layer_setbuf(win_layer, win_buf, 160, 52, -1); init_screen(back_buf, binfo->screen_x, binfo->screen_y); init_mouse_cursor8(mouse_buf, 99); make_window8(win_buf, 160, 52, "Counter"); layer_slide(back_layer, 0, 0); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; layer_slide(mouse_layer, mouse_x, mouse_y); layer_slide(win_layer, 80, 72); layer_updown(back_layer, 0); layer_updown(win_layer, 1); layer_updown(mouse_layer, 2); sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); draw_font8_asc(back_buf, binfo->screen_x, 0, 0, COLOR8_FFFFFF, debug_info); sprintf(debug_info, "memory total: %dMB, free space: %dKB", memory_total / (1024 * 1024), mem_mgr_total(mem_mgr) / 1024); draw_font8_asc(back_buf, binfo->screen_x, 0, 32, COLOR8_FFFFFF, debug_info); layers_refresh(back_layer, 0, 0, binfo->screen_x, 48); for ( ; ; ) { sprintf(debug_info, "%010d", g_timerctl.count); fill_box8(win_buf, 160, COLOR8_C6C6C6, 40, 28, 119, 43); draw_font8_asc(win_buf, 160, 40, 28, COLOR8_000000, debug_info); layers_refresh(win_layer, 40, 28, 120, 44); io_cli(); if (0 == fifo_size(&g_keybuf) && 0 == fifo_size(&g_mousebuf) && 0 == fifo_size(&timerfifo)) io_stihlt(); else { if (0 != fifo_size(&g_keybuf)) { data = fifo_get(&g_keybuf); io_sti(); sprintf(debug_info, "%02X", data); fill_box8(back_buf, binfo->screen_x, COLOR8_848484, 0, 16, 15, 31); draw_font8_asc(back_buf, binfo->screen_x, 0, 16, COLOR8_FFFFFF, debug_info); layers_refresh(back_layer, 0, 16, 16, 32); } else if (0 != fifo_size(&g_mousebuf)) { data = fifo_get(&g_mousebuf); io_sti(); if (0 != mouse_decode(&mdec, data)) { /* show all mouse bytes code */ sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y); if (0 != (mdec.state & 0x01)) debug_info[1] = 'L'; if (0 != (mdec.state & 0x02)) debug_info[3] = 'R'; if (0 != (mdec.state & 0x04)) debug_info[2] = 'C'; fill_box8(back_buf, binfo->screen_x, COLOR8_848484, 32, 16, 32 + 15 * 8 - 1, 31); draw_font8_asc(back_buf, binfo->screen_x, 32, 16, COLOR8_FFFFFF, debug_info); layers_refresh(back_layer, 32, 16, 32 + 15 * 8, 32); mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); fill_box8(back_buf, binfo->screen_x, COLOR8_848484, 0, 0, 79, 15); /* hide mouse position */ draw_font8_asc(back_buf, binfo->screen_x, 0, 0, COLOR8_FFFFFF, debug_info); /* show mouse position */ layers_refresh(back_layer, 0, 0, 80, 16); layer_slide(mouse_layer, mouse_x, mouse_y); } } else if (0 != fifo_size(&timerfifo)) { data = fifo_get(&timerfifo); io_sti(); draw_font8_asc(back_buf, binfo->screen_x, 0, 64, COLOR8_FFFFFF, "10[sec]"); layers_refresh(back_layer, 0, 64, 56, 80); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_win_b; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_win_b[3]; struct TASK *task_a, *task_b[3]; struct TIMER *timer; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_win_b */ for (i = 0; i < 3; i++) { sht_win_b[i] = sheet_alloc(shtctl); buf_win_b = (unsigned char *) memman_alloc_4k(memman, 144 * 52); sheet_setbuf(sht_win_b[i], buf_win_b, 144, 52, -1); /* 透明色なし */ sprintf(s, "task_b%d", i); make_window8(buf_win_b, 144, 52, s, 0); task_b[i] = task_alloc(); task_b[i]->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; task_b[i]->tss.eip = (int) &task_b_main; task_b[i]->tss.es = 1 * 8; task_b[i]->tss.cs = 2 * 8; task_b[i]->tss.ss = 1 * 8; task_b[i]->tss.ds = 1 * 8; task_b[i]->tss.fs = 1 * 8; task_b[i]->tss.gs = 1 * 8; *((int *) (task_b[i]->tss.esp + 4)) = (int) sht_win_b[i]; task_run(task_b[i]); } /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 透明色なし */ make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_win_b[0], 168, 56); sheet_slide(sht_win_b[1], 8, 116); sheet_slide(sht_win_b[2], 168, 116); sheet_slide(sht_win, 8, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_win_b[0], 1); sheet_updown(sht_win_b[1], 2); sheet_updown(sht_win_b[2], 3); sheet_updown(sht_win, 4); sheet_updown(sht_mouse, 5); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x54 + 256) { if (keytable[i - 256] != 0 && cursor_x < 128) { /* 通常文字 */ /* 一文字表示してから、カーソルを1つ進める */ s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { /* バックスペース */ /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } /* カーソルの再表示 */ boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押していたら、sht_winを動かす */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &fifo, 0); /* 次は0を */ cursor_c = COL8_000000; } else { timer_init(timer, &fifo, 1); /* 次は1を */ cursor_c = COL8_FFFFFF; } timer_settime(timer, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "window"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i == 0x1e + 256) { putfonts8_asc_sht(sht_win, 40, 28, COL8_000000, COL8_C6C6C6, "A", 1); } } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); } } else if (i == 10) { /* 10秒タイマ */ putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (i == 3) { /* 3秒タイマ */ putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i == 1) { /* カーソル用タイマ */ timer_init(timer3, &fifo, 0); /* 次は0を */ boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } else if (i == 0) { /* カーソル用タイマ */ timer_init(timer3, &fifo, 1); /* 次は1を */ boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } } }
void HariMain(void) { int i; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; int mx = xsize/2; int my = ysize/2; int fifobuf[128], keycmd_buf[32]; struct MOUSE_DEC mdec; unsigned char s[32]; unsigned int memtotal; struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; int cursor_x, cursor_c; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct TIMER *timer; struct FIFO32 fifo, keycmd; struct CONSOLE *cons; struct TASK *task_a, *task_cons; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; init_gdtidt (); init_pic (); io_sti (); fifo32_init(&fifo, 32, fifobuf, 0); fifo32_init(&keycmd, 32, keycmd_buf, 0); init_pit(); io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */ io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */ init_keyboard (&fifo, 256); enable_mouse (&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init (memman); memman_free (memman, 0x00001000, 0x009e000); /* 0x00001000 - 0x0009efff */ memman_free (memman, 0x00400000, memtotal - 0x00400000); init_pallete(); shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k (memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *)memman_alloc_4k (memman, 160 * 52); sheet_setbuf (sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf (sht_win, buf_win, 160, 52, -1); init_screen (buf_back, xsize, ysize); init_mouse_cursor8 (buf_mouse, 99); make_window8(buf_win, 160, 52, "task_a", 1); // sprintf (s, "(%d, %d)", mx, my); // putfonts8_asc (buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); // sprintf (s, "Memory %dMB, free : %dKB", // memtotal / (1024 * 1024), memman_total(memman) / 1024); // putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); make_textbox8 (sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; //===================== // Task Settings //===================== task_a = task_init(memman); fifo.task = task_a; task_run (task_a, 1, 0); /* console sheet */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *)memman_alloc_4k(memman, 256 * 165); sheet_setbuf (sht_cons, buf_cons, 256, 165, -1); make_window8 (buf_cons, 256, 165, "console", 0); make_textbox8 (sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc (); task_cons->tss.esp = memman_alloc_4k (memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int)&console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = (int) memtotal; task_run (task_cons, 1, 0); /* level = 2, priority = 2 */ //======================= // Sheet Setting //======================= sheet_slide (sht_back, 0, 0); sheet_slide (sht_mouse, mx, my); sheet_slide (sht_cons, 32, 4); sheet_slide (sht_win, 64, 56); sheet_updown (sht_back, 0); sheet_updown (sht_cons, 1); sheet_updown (sht_win, 2); sheet_updown (sht_mouse, 3); sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48); fifo32_put (&keycmd, KEYCMD_LED); fifo32_put (&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { // Keyboard Data // sprintf (s, "%x", i - 256); // putfonts8_asc_sht (sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0) { if (key_to == 0) { if (cursor_x < 128) { s[1] = 0; putfonts8_asc_sht (sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { // To Console fifo32_put (&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { // Backspace if (key_to == 0) { // To Task-A if (cursor_x > 8) { putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x0f) { // Tab if (key_to == 0) { key_to = 1; make_wtitle8 (buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8 (buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; // Delete cursor boxfill8 (sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put (&task_cons->fifo, 2); // cursor ON console } else { key_to = 0; make_wtitle8 (buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8 (buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; // Delete cursor fifo32_put (&task_cons->fifo, 3); // cursor OFF console } sheet_refresh (sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh (sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x1c) { if (key_to != 0) { fifo32_put (&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x2a) { // Left Shift ON key_shift |= 1; } if (i == 256 + 0x36) { // Right Shift ON key_shift |= 2; } if (i == 256 + 0xaa) { // Left Shift OFF key_shift &= ~1; } if (i == 256 + 0xb6) { // Right Shift ON key_shift &= ~2; } if (i == 256 + 0x3a) { // CapsLock key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { // NumLock key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { // ScrollLock key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { // KeyBoard receive Data keycmd_wait = -1; } if (i == 256 + 0xfe) { // KeyBoard failed to receive Data wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } if (i == 256 + 0x3b && key_shift != 0 && task_cons->tss.ss0 != 0) { /* Shift+F1 */ cons = (struct CONSOLE *) *((int *) 0x0fec); cons_putstr0 (cons, "\nBreak(key) : \n"); io_cli (); task_cons->tss.eax = (int) &(task_cons->tss.esp0); task_cons->tss.eip = (int) asm_end_app; io_sti (); } // Redraw cursor if (cursor_c >= 0) { boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { // Mouse Data if (mouse_decode(&mdec, i-512) != 0) { // sprintf (s, "[lcr %d %d]", mdec.x, mdec.y); // if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } // if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } // if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } // putfonts8_asc_sht (sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } // sprintf(s, "(%d, %d)", mx, my); // putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide (sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide (sht_win, mx - 80, my - 8); } } } else if (i <= 1) { if (i != 0) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8 (sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { int i; int mmx = -1, mmy = -1, mmx2 = 0; struct SHEET *sht = 0, *key_win; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; int mx = xsize/2; int my = ysize/2; int new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; int fifobuf[128], keycmd_buf[32], *cons_fifo[2]; struct MOUSE_DEC mdec; unsigned char s[32]; unsigned int memtotal; struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse; unsigned char *buf_back, buf_mouse[256], *buf_cons[2]; struct TIMER *timer; struct FIFO32 fifo, keycmd; struct TASK *task_a, *task_cons[2]; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; init_gdtidt (); init_pic (); io_sti (); fifo32_init(&fifo, 32, fifobuf, 0); fifo32_init(&keycmd, 32, keycmd_buf, 0); init_pit(); io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */ io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */ init_keyboard (&fifo, 256); enable_mouse (&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init (memman); memman_free (memman, 0x00001000, 0x009e000); /* 0x00001000 - 0x0009efff */ memman_free (memman, 0x00400000, memtotal - 0x00400000); init_pallete(); shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k (memman, binfo->scrnx * binfo->scrny); sheet_setbuf (sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99); init_screen (buf_back, xsize, ysize); init_mouse_cursor8 (buf_mouse, 99); *((int *) 0x0fec) = (int) &fifo; //===================== // Task Settings //===================== task_a = task_init(memman); fifo.task = task_a; task_run (task_a, 1, 0); /* console sheet */ key_win = open_console (shtctl, memtotal); //======================= // Sheet Setting //======================= *((int *) 0x0fe4) = (int) shtctl; sheet_slide (sht_back, 0, 0); sheet_slide (key_win, 32, 4); sheet_slide (sht_mouse, mx, my); sheet_updown (sht_back, 0); sheet_updown (key_win, 1); sheet_updown (sht_mouse, 2); sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48); keywin_on (key_win); fifo32_put (&keycmd, KEYCMD_LED); fifo32_put (&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { /* execute draw if FIFO is empty */ if (new_mx >= 0) { io_sti (); sheet_slide (sht_mouse, new_mx, new_my); new_mx = -1; } else if (new_wx != 0x7fffffff) { io_sti (); sheet_slide (sht, new_wx, new_wy); new_wx = 0x7fffffff; } else { task_sleep(task_a); io_sti(); } } else { i = fifo32_get(&fifo); io_sti(); if (key_win != 0 && key_win->flags == 0) { // input Window is closed if (shtctl->top == 1) { // ony mouse and background key_win = 0; } else { key_win = shtctl->sheets[shtctl->top - 1]; keywin_on (key_win); } } if (256 <= i && i <= 511) { // Keyboard Data if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0 && key_win != 0) { fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f && key_win != 0) { // Tab keywin_off (key_win); int j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on (key_win); } if (i == 256 + 0x2a) { // Left Shift ON key_shift |= 1; } if (i == 256 + 0x36) { // Right Shift ON key_shift |= 2; } if (i == 256 + 0xaa) { // Left Shift OFF key_shift &= ~1; } if (i == 256 + 0xb6) { // Right Shift ON key_shift &= ~2; } if (i == 256 + 0x3a) { // CapsLock key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { // NumLock key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { // ScrollLock key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { struct TASK *task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { /* Shift+F1 */ cons_putstr0 (task->cons, "\nBreak(key) : \n"); io_cli (); task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti (); } } if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */ if (key_win != 0) { keywin_off (key_win); } key_win = open_console (shtctl, memtotal); sheet_slide (key_win, 32, 4); sheet_updown (key_win, shtctl->top); keywin_on (key_win); } if (i == 256 + 0x57) { /* F11 */ sheet_updown (shtctl->sheets[1], shtctl->top-1); } if (i == 256 + 0xfa) { // KeyBoard receive Data keycmd_wait = -1; } if (i == 256 + 0xfe) { // KeyBoard failed to receive Data wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } } else if (512 <= i && i <= 767) { // Mouse Data if (mouse_decode(&mdec, i-512) != 0) { mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } // sprintf(s, "(%d, %d)", mx, my); // putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide (sht_mouse, mx, my); new_mx = mx; new_my = my; if ((mdec.btn & 0x01) != 0) { /* Left Mouse Button is down */ if (mmx < 0) { /* Normal Mode */ for (int j = shtctl->top - 1; j > 0; j--) { sht = shtctl->sheets[j]; int x = mx - sht->vx0; int y = my - sht->vy0; if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown (sht, shtctl->top - 1); if (sht != key_win) { keywin_off (key_win); key_win = sht; keywin_on (key_win); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { mmx = mx; mmy = my; mmx2 = sht->vx0; new_wy = sht->vy0; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) { if ((sht->flags & 0x10) != 0) { struct TASK *task = sht->task; cons_putstr0 (task->cons, "\nBreak(mouse) :\n"); io_cli (); task->tss.eax = (int) & (task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti (); } else { struct TASK *task = sht->task; io_cli (); fifo32_put (&task->fifo, 4); io_sti (); } } break; } } } } else { // Moving window mode int x = mx - mmx; int y = my - mmy; new_wx = (mmx2 + x + 2) & ~3; new_wy = new_wy + y; mmy = my; } } else { mmx = -1; if (new_wx != 0x7fffffff) { sheet_slide (sht, new_wx, new_wy); new_wx = 0x7fffffff; } } } } else if (768 <= i && i <= 1023) { close_console (shtctl->sheets0 + (i - 768)); } else if (1024 <= i && i < 2023) { close_constask (taskctl->tasks0 + (i - 1024)); } } } }
void HariMain(void) { char *vram; int xsize; int ysize; unsigned int memtotal; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR ; struct BOOTINFO *binfo; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256],*buf_win; int i; int fifobuf[128]; char s[40]; struct FIFO fifo; fifo_init(&fifo,128,fifobuf); static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; init_gdtidt(); init_pic(); io_sti(); init_pit(); // timer io_out8(PIC0_IMR, 0xf8); /* PIC1 (11111001) irq0 */ io_out8(PIC1_IMR, 0xef); //11101111 , allow irq12 struct TIMER *timer,*timer2,*timer3; timer = timer_alloc(); timer2 = timer_alloc(); timer3 = timer_alloc(); timer_set(timer,1000,&fifo,10); timer_set(timer2,300,&fifo,3); timer_set(timer3,50,&fifo,1); init_keyboard(&fifo,256); // memory test memtotal = memtest(0x00400000, 0xbfffffff); // available maxmium address memman_init(memman); memman_free(memman,0x00001000,0x0009e000); memman_free(memman,0x00400000,memtotal-0x00400000); init_palette(); binfo = (struct BOOTINFO *) 0x0ff0; xsize = binfo->scrnx; ysize = binfo->scrny; vram = binfo->vram; // sheet setting shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman,160 * 52); // window sheet buffer sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // col_inv 99 sheet_setbuf(sht_win, buf_win,160,52,-1); /* initlize OS background */ init_screen(buf_back,xsize,ysize); int mx,my; // mouse position // mouse cursor struct MOUSE_DEC mdec; enable_mouse(&fifo,512,&mdec); init_mouse_cursor8(buf_mouse,99); make_window8(buf_win,160,52,"window"); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_move(sht_back,0,0);// move background sheet sheet_move(sht_mouse,mx,my); sheet_move(sht_win,80,72); sheet_updown(sht_back,0); // height 0, at the bottom sheet_updown(sht_win,1); sheet_updown(sht_mouse,2); // height 2,on the top sprintf(s,"%3d %3d",mx,my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory %dMB free %dkb", memtotal/(1024*1024), memman_total(memman)/1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back,0,0,binfo->scrnx,48); int cursor_x,cursor_c; // cursor color make_textbox8(sht_win, 8,28,144,16,COL8_FFFFFF); // heigth is 16 cursor_x = 8; cursor_c = COL8_FFFFFF; for(;;) { //sprintf(s,"%010d",timerctl.count); //bps(sht_win,40,28, COL8_C6C6C6,COL8_000000,s,10); io_cli(); // forbid all interrupts if(fifo_status(&fifo) == 0) io_stihlt(); // read data until it's empty else { i=fifo_get(&fifo); io_sti(); // open interrupts if(255 < i && i < 512) {sprintf(s, "%02X", i-256); boxfill8(buf_back, binfo->scrnx, COL8_008400, 0, 16, 15, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(sht_back,0,16,16,32); if(i<256 +0x54) { if(keytable[i-256] != 0 && cursor_x < 144) { s[0]= keytable[i-256]; s[1]= '\0'; bps(sht_win,cursor_x,28, COL8_FFFFFF,COL8_000000,s,1); // 4th parm is background color cursor_x +=8; // cursor move forward } } if(i == 256 + 0x0e && cursor_x > 8) { bps(sht_win,cursor_x,28,COL8_FFFFFF,COL8_000000," ",1); cursor_x -=8; } boxfill8(sht_win ->buf, sht_win->bxsize, cursor_c,cursor_x,28,cursor_x+7,43); sheet_refresh(sht_win,cursor_x,28,cursor_x+8,44); } else if(511 < i && i < 768) { if(mouse_decode(&mdec,i-512) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x,mdec.y); if((mdec.btn & 0x01) != 0) s[1]='L'; if((mdec.btn & 0x02) != 0) s[3]='R'; if((mdec.btn & 0x04) != 0) s[2]='C'; boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32+15*8-1, 31); // after filling,show ok putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s); sheet_refresh(sht_back,32,16,32+15*8,32); // the move of mouse mx +=mdec.x; my +=mdec.y; if(mx <0) mx = 0; if(my <0) my = 0; if(mx > binfo->scrnx -1 ) mx = binfo->scrnx -1; if(my > binfo->scrny -1 ) my = binfo->scrny -1; // control the mouse move area sprintf(s, "(%3d,%3d)", mx,my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0,79, 15); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sheet_refresh(sht_back,0,0,80,16); sheet_move(sht_mouse,mx,my); // move the window, vram -> sht -> move if(mdec.btn & 0x01 != 0) sheet_move(sht_win,mx-80,my-8); } } else if(i==10) {putfonts8_asc(buf_back, binfo->scrnx,0,64, COL8_FFFFFF,"10"); sheet_refresh(sht_back,0,0,100,100); } else if(i ==3) {putfonts8_asc(buf_back, binfo->scrnx,0,80, COL8_FFFFFF,"3s"); sheet_refresh(sht_back,0,0,100,100); } else if(i == 1) { timer_set(timer3,50,&fifo,0); boxfill8(sht_win->buf,sht_win->bxsize, COL8_000000, cursor_x, 28,cursor_x+7, 43); sheet_refresh(sht_win,cursor_x,28,cursor_x + 8, 44); } else if(i==0) { timer_set(timer3,50,&fifo,1); // keep the data boxfill8(sht_win->buf,sht_win->bxsize, COL8_FFFFFF,cursor_x, 28,cursor_x + 7, 43); sheet_refresh(sht_win,cursor_x,28,cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], keybuf[32], mousebuf[128]; int mx, my, i; unsigned int memtotal, count = 0; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); init_pit(); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); for (;;) { count++; sprintf(s, "%010d", count); boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43); putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s); sheet_refresh(sht_win, 40, 28, 120, 44); io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_sti(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 16, 16, 32); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s); sheet_refresh(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 > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0, 79, 15); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, 80, 16); sheet_slide(sht_mouse, mx, my); } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; struct TASK *task_a, *task_cons; struct TIMER *timer; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; struct CONSOLE *cons; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); *((int *) 0x0fe4) = (int) shtctl; /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 透明色なし */ make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = memtotal; task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 透明色なし */ make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* キーボードコントローラに送るデータがあれば、送る */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 入力文字がアルファベット */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 大文字を小文字に変換 */ } } if (s[0] != 0) { /* 通常文字 */ if (key_to == 0) { /* タスクAへ */ if (cursor_x < 128) { /* 一文字表示してから、カーソルを1つ進める */ s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { /* コンソールへ */ fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { /* バックスペース */ if (key_to == 0) { /* タスクAへ */ if (cursor_x > 8) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { /* コンソールへ */ fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x1c) { /* Enter */ if (key_to != 0) { /* コンソールへ */ fifo32_put(&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x0f) { /* Tab */ if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; /* カーソルを消す */ boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put(&task_cons->fifo, 2); /* コンソールのカーソルON */ } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; /* カーソルを出す */ fifo32_put(&task_cons->fifo, 3); /* コンソールのカーソルOFF */ } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { /* 左シフト ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右シフト ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左シフト OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右シフト OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && task_cons->tss.ss0 != 0) { /* Shift+F1 */ cons = (struct CONSOLE *) *((int *) 0x0fec); cons_putstr0(cons, "\nBreak(key) :\n"); io_cli(); /* 強制終了処理中にタスクが変わると困るから */ task_cons->tss.eax = (int) &(task_cons->tss.esp0); task_cons->tss.eip = (int) asm_end_app; io_sti(); } if (i == 256 + 0x57 && shtctl->top > 2) { /* F11 */ sheet_updown(shtctl->sheets[1], shtctl->top - 1); } if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* キーボードがデータを無事に受け取れなかった */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } /* カーソルの再表示 */ if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押していたら、sht_winを動かす */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &fifo, 0); /* 次は0を */ if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); /* 次は1を */ if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { //bootinfo struct pointer struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; char s[50]; struct TIMER *timer; int mx, my; unsigned int i; //鼠标相关,mouse_phase,鼠标状态; struct MOUSE_DEC mdec; init_gdtidt(); init_pic();//初始化PIC io_sti();//PIC初始化完成,开中断 init_pit(); //必须先初始化pit,然后才能使用settimer struct FIFO32 fifo; unsigned int fifobuf[128]; fifo32_init(&fifo, sizeof(fifobuf)/sizeof(fifobuf[0]), fifobuf, 0); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); io_out8(PIC0_IMR, 0xf8); /* PIC1打开中断(11111000) */ io_out8(PIC1_IMR, 0xef); /* 打开键盘中断(11101111) */ init_palette(); //keyboard and mouse init init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); unsigned int memtotal;//memtotal memory 总数 struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; memtotal = memtest(0x00400000, 0xbfffffff);//获取内存真实的大小 memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); //图层控制器初始化 struct SHTCTL *shtctl; shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); *((int *)0x0fe4) = (int)shtctl;//保存shtctl供其他用 struct SHEET *sht_back, *sht_mouse, *sht_win;//背景和鼠标图层 sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); unsigned char *buf_back, buf_mouse[256], *buf_win; buf_back = (unsigned char *)memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *)memman_alloc_4k(memman, 160*52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1);//没有透明色 sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);//透明色号99 sheet_setbuf(sht_win, buf_win, 144, 52, -1);//透明色号99 init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99);//背景色号99 make_window8(sht_win->buf, 144, 52, "task_a", 1);// make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); //鼠标初始位置 mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 16) / 2; //task_a struct TASK *task_a; task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 0); //sht_cons struct TASK *task_cons; struct SHEET *sht_cons; unsigned char *buf_cons; sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *)memman_alloc_4k(memman, 256*165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1);//无透明色 make_window8(buf_cons,256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc();//分配一个task struct task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 -16; task_cons->tss.eip = (int)&console_task; task_cons->tss.es = 1*8; task_cons->tss.cs = 2*8; task_cons->tss.ss = 1*8; task_cons->tss.ds = 1*8; task_cons->tss.fs = 1*8; task_cons->tss.gs = 1*8; *((int *)(task_cons->tss.esp+4)) = (int)sht_cons; *((int *)(task_cons->tss.esp+8)) = (int)memtotal; *((int *)(task_cons->tss.esp+12)) = (int)sht_back; task_run(task_cons, 2, 2);//level=2,priority=2 sheet_slide(sht_back, 0, 0); sheet_slide(sht_win, 64, 56); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_mouse, mx, my);//移动鼠标到中心,显示出来 sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); int cursor_x = 8;//光标位置 int cursor_c = COL8_FFFFFF;//光标初始颜色 int key_to = 0; int key_shift = 0;//shift状态 int key_leds = (binfo->leds>>4) & 7;//键盘指示灯状态 int keycmd_wait = -1; struct SHEET *key_win = sht_win;//初始化输入对应的应用窗口 sht_cons->task = task_cons; sht_cons->flags |= 0x20;//有光标模式 struct FIFO32 keycmd;//键盘控制器设定FIFO int keycmd_buf[32]; fifo32_init(&keycmd, sizeof(keycmd_buf), keycmd_buf, 0); //为了避免和键盘当前状态的冲突,在一开始先进行设置 fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { //如果存在向键盘控制器发送的数据,则发送出去 keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, key_leds); } io_cli(); if (0 == fifo32_status(&fifo)){ task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (key_win->flags == 0) {//输入窗口被关闭 key_win = shtctl->sheets[shtctl->top - 1];//如果输入窗口被关闭,则将输入窗口设置为最上层的窗口 cursor_c = keywin_on(key_win, sht_win, cursor_c); } if (256 <= i && i <= 511) {//键盘数据 //CAPSLOCK,大写锁定键 if (i == 256 + 0x3a) { key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } //Numlock if (i == 256 + 0x45) { key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } //ScrollLock if (i == 256 + 0x46) { key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) {//键盘成功接收到数据 keycmd_wait = -1; } if (i == 256 + 0xfe) {//键盘没有成功接收到数据 wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } if (i < 0x54 + 256 ) {//按键盘编码为字符编码 if (key_shift == 0) { s[0] = keytable0[i - 256]; } else if (key_shift == 1 || key_shift == 2) { s[0] = keytable1[i - 256]; } else { s[0] = 0; } //大小写字符转换 if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds&4) == 0 && key_shift == 0) //大写字符锁定键没有打开,shift没有按下 || ((key_leds&4) != 0 && key_shift != 0)) { s[0] += 0X20; } } if (s[0] != 0) {//一般字符 if (key_win == sht_win) {//发送给任务a if (cursor_x < 128) { s[1] = 0; putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, strlen(s)); cursor_x += 8; } } else {//向命令行窗口发送字符 fifo32_put(&key_win->task->fifo, s[0]+256); } } } if (i == 256+0x0e) {//退格键 if (key_win == sht_win) {//发送给任务a if (cursor_x > 8) { putfont8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { fifo32_put(&key_win->task->fifo, 8+256); } } //回车键 if (i == 256+0x1c) { if (key_win != sht_win) { fifo32_put(&key_win->task->fifo, 10+256); } } //tab键 if (i == 256 + 0x0f) { cursor_c = keywin_off(key_win, sht_win, cursor_c, cursor_x); int j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; cursor_c = keywin_on(key_win, sht_win, cursor_c); } //shift+F1,结束应用程序 if (i == 256 + 0x3b && key_shift != 0 && task_cons->tss.ss0 != 0) { struct CONSOLE *cons = (struct CONSOLE *)*((int *)0x0fec); cons_putstr0(cons,"Break(KEY)\n"); io_cli();//修改寄存器时禁止中断 task_cons->tss.eax = (int)&(task_cons->tss.esp0); task_cons->tss.eip = (int)asm_end_app; io_sti(); } //F11 if (i == 256 + 0x57 && shtctl->top > 2) { sheet_updown(shtctl->sheets[1], shtctl->top - 1); } //重新显示光标 if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x+7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x+8, 44); if (i == 256 + 0x2a) {//左shift on key_shift |= 1; } if (i == 256 + 0x36) {//右shift on key_shift |= 2; } if (i == 256 + 0xaa) {//左shift off key_shift &= ~1; } if (i == 256 + 0xb6) {//右shift off key_shift &= ~2; } } else if (512 <= i && i <= 767) {//鼠标数据 //鼠标的3个字节都齐全了,显示出来 if (mouse_decode(&mdec, i-512) != 0) { //计算鼠标新的位置 mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfont8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, strlen(s)); //滑动鼠标显示,包含sheet_reflush sheet_slide(sht_mouse, mx, my); static int j, x, y; static int mmx = -1, mmy = -1; static struct SHEET *sht = 0; if ((mdec.btn & 0x01) != 0) {//鼠标左键按 //按照从上到下的顺序寻找鼠标所指向的图层 if (mmx < 0) { for (j = shtctl->top-1; j > 0; j--) { sht = shtctl->sheets[j]; x = mx - sht->vx0; y = my - sht->vy0; if (0 <= x &&//鼠标在sheet图层内,因为是从最上层开始查看就没有问题。 x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) {//图层此处不是透明色 sheet_updown(sht, shtctl->top - 1);//将sht图层提升最上层 if (sht != key_win) { cursor_c = keywin_off(key_win, sht_win, cursor_c, cursor_x); key_win = sht; cursor_c = keywin_on(key_win, sht_win, cursor_c); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21 ) {//光标处于标题栏 mmx = mx; mmy = my; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) {//光标处于X位置,并点击 if ((sht->flags & 0x10) != 0) {//窗口为某应用程序的 struct CONSOLE *cons = (struct CONSOLE *)*((int *)0xfec); cons_putstr0(cons, "\nBreak(mouse) :\n"); io_cli();//强制结束处理中禁止切换任务 task_cons->tss.eax = (int)&(task_cons->tss.esp0); task_cons->tss.eip = (int)asm_end_app; io_sti(); } } break; } } } } else { //如果已经处于move mode x = mx - mmx; y = my - mmy; sheet_slide(sht, sht->vx0 + x, sht->vy0 + y); mmx = mx;//更新移动后的坐标 mmy = my; } } else { //没有按下键 mmx = -1; } } } else if (10 == i) {//10s timer putfont8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (3 == i){//3s timer putfont8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i <= 1) { if(1 == i) {//I1 timer_init(timer, &fifo, 0);//设置为0 if (cursor_c >= 0){ cursor_c = COL8_000000; } } else if(0 == i){ timer_init(timer, &fifo, 1);//设置为1 if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x+7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x+8, 44); } } else { } } } }