static void task_b_main(layer_t* win_layer_b) { fifo32_t fifo; timer_t* timer_1s; int data, count = 0, count1 = 0; int fifobuf[128]; char buf[32]; fifo_init(&fifo, fifobuf, 128, 0); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_settimer(timer_1s, 100); for ( ; ; ) { ++count; io_cli(); if (0 == fifo_size(&fifo)) io_sti(); else { data = fifo_get(&fifo); io_sti(); if (100 == data) { sprintf(buf, "%011d", count - count1); drawstring_and_refresh(win_layer_b, 24, 28, COLOR8_000000, COLOR8_C6C6C6, buf, 11); count1 = count; timer_settimer(timer_1s, 100); } } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; char debug_info[64], mouse_cursor[256], keybuf[32]; int mouse_x, mouse_y; init_gdt_idt(); init_pic(); io_sti(); fifo_init(&g_keybuf, keybuf, 32); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_keyboard(); /* initialize keyboard */ init_palette(); init_screen(binfo->vram, binfo->screen_x, binfo->screen_y); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; init_mouse_cursor8(mouse_cursor, COLOR8_848484); draw_block8_8(binfo->vram, binfo->screen_x, 16, 16, mouse_x, mouse_y, mouse_cursor, 16); draw_font8_asc(binfo->vram, binfo->screen_x, 8, 8, COLOR8_FFFFFF, "HELLO BOYS:"); draw_font8_asc(binfo->vram, binfo->screen_x, 9, 9, COLOR8_000000, "HELLO BOYS:"); draw_font8_asc(binfo->vram, binfo->screen_x, 31, 31, COLOR8_000000, "WELCOME TO THE LOVELY TOY-OS."); draw_font8_asc(binfo->vram, binfo->screen_x, 30, 30, COLOR8_FFFFFF, "WELCOME TO THE LOVELY TOY-OS."); sprintf(debug_info, "screen=>{%d, %d}", binfo->screen_x, binfo->screen_y); draw_font8_asc(binfo->vram, binfo->screen_x, 16, 64, COLOR8_FF0000, debug_info); enable_mouse(); /* enabled mouse */ for ( ; ; ) { int data; io_cli(); if (0 == fifo_size(&g_keybuf)) io_stihlt(); else { data = fifo_get(&g_keybuf); io_sti(); sprintf(debug_info, "%02X", data); fill_box8(binfo->vram, binfo->screen_x, COLOR8_008484, 0, 16, 15, 31); draw_font8_asc(binfo->vram, binfo->screen_x, 0, 16, COLOR8_FFFFFF, debug_info); } } }
static void task_b_main(layer_t* back_layer) { fifo32_t fifo; timer_t* timer_put; timer_t* timer_1s; int data, count = 0, count1 = 0; int fifobuf[128]; char buf[32]; fifo_init(&fifo, fifobuf, 128); timer_put = timer_alloc(); timer_init(timer_put, &fifo, 1); timer_settimer(timer_put, 1); timer_1s = timer_alloc(); timer_init(timer_1s, &fifo, 100); timer_settimer(timer_1s, 100); for ( ; ; ) { ++count; io_cli(); if (0 == fifo_size(&fifo)) io_sti(); else { data = fifo_get(&fifo); io_sti(); if (1 == data) { sprintf(buf, "%011d", count); drawstring_and_refresh(back_layer, 0, 144, COLOR8_FFFFFF, COLOR8_848484, buf, 11); timer_settimer(timer_put, 1); } else if (100 == data) { sprintf(buf, "%011d", count - count1); drawstring_and_refresh(back_layer, 0, 128, COLOR8_FFFFFF, COLOR8_848484, buf, 11); count1 = count; timer_settimer(timer_1s, 100); } } } }
static void console_task(layer_t* layer) { fifo32_t fifo; timer_t* timer; task_t* task = task_now(); int data, fifobuf[128], cursor_x = 8, cursor_c = COLOR8_000000; fifo_init(&fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settimer(timer, 50); for ( ; ; ) { io_cli(); if (0 == fifo_size(&fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &fifo, 0); cursor_c = COLOR8_FFFFFF; } else { timer_init(timer, &fifo, 1); cursor_c = COLOR8_000000; } timer_settimer(timer, 50); fill_box8(layer->buf, layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(layer, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; char debug_info[64], keybuf[32], mousebuf[128]; 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; unsigned char* back_buf; unsigned char mouse_buf[256]; init_gdt_idt(); init_pic(); io_sti(); fifo_init(&g_keybuf, keybuf, 32); fifo_init(&g_mousebuf, mousebuf, 128); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); 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); 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); layer_setbuf(mouse_layer, mouse_buf, 16, 16, 99); init_screen(back_buf, binfo->screen_x, binfo->screen_y); init_mouse_cursor8(mouse_buf, 99); layer_slide(layer_mgr, back_layer, 0, 0); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; layer_slide(layer_mgr, mouse_layer, mouse_x, mouse_y); layer_updown(layer_mgr, back_layer, 0); layer_updown(layer_mgr, mouse_layer, 1); 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(layer_mgr, back_layer, 0, 0, binfo->screen_x, 48); for ( ; ; ) { io_cli(); if (0 == fifo_size(&g_keybuf) && 0 == fifo_size(&g_mousebuf)) 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(layer_mgr, 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(layer_mgr, 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(layer_mgr, back_layer, 0, 0, 80, 16); layer_slide(layer_mgr, mouse_layer, mouse_x, mouse_y); } } } } }
void console_task(layer_t* layer, unsigned int memtotal) { #define INPUT_BEG_POS_X (16) #define INPUT_BEG_POS_Y (28) timer_t* timer; task_t* task = task_now(); mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR; int data, fifobuf[128]; int* fat = (int*)mem_mgr_alloc_4k(memmgr, 4 * 2880); char cmdline[32]; console_t console; console.layer = layer; console.cur_x = 8; console.cur_y = INPUT_BEG_POS_Y; console.cur_c = -1; *((int*)0x0fec) = (int)&console; fifo_init(&task->fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settimer(timer, 50); file_readfat(fat, (unsigned char*)(ADR_DISKIMG + 0x000200)); /* display the prompt of console window */ console_putchar(&console, '>', 1); for ( ; ; ) { io_cli(); if (0 == fifo_size(&task->fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&task->fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &task->fifo, 0); if (console.cur_c >= 0) console.cur_c = COLOR8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); if (console.cur_c >= 0) console.cur_c = COLOR8_000000; } timer_settimer(timer, 50); } if (2 == data) /* cursor ON */ console.cur_c = COLOR8_FFFFFF; if (3 == data) { /* cursor OFF */ fill_box8(layer->buf, layer->w_size, COLOR8_000000, console.cur_x, console.cur_y, console.cur_x + 7, console.cur_y + 15); console.cur_c = -1; } if (256 <= data && data <= 511) { /* keyboard data */ if ((8 + 256) == data) { /* backspace */ if (console.cur_x > INPUT_BEG_POS_X) { /* erase the cursor and move forward one character */ console_putchar(&console, ' ', 0); console.cur_x -= 8; } } else if ((10 + 256) == data) { /* Enter Key */ /* erase cursor by space */ console_putchar(&console, ' ', 0); cmdline[console.cur_x / 8 - 2] = 0; console_newline(&console); console_runcmd(&console, cmdline, fat, memtotal); /* show the prompt */ console_putchar(&console, '>', 1); } else { /* general character */ if (console.cur_x < 240) { /* display one character and move backward one character */ cmdline[console.cur_x / 8 - 2] = data - 256; console_putchar(&console, data - 256, 1); } } } /* show the cursor again */ if (console.cur_c >= 0) { fill_box8(layer->buf, layer->w_size, console.cur_c, console.cur_x, console.cur_y, console.cur_x + 7, console.cur_y + 15); } layers_refresh(layer, console.cur_x, console.cur_y, console.cur_x + 8, console.cur_y + 16); } } }
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); } } } }
static void console_task(layer_t* layer) { #define INPUT_BEG_POS_X (24) #define INPUT_BEG_POS_Y (28) #define PROMPT_CHAR ("> ") #define PROMPT_LEN (2) timer_t* timer; task_t* task = task_now(); int data, fifobuf[128]; int cursor_x = INPUT_BEG_POS_X, cursor_y = INPUT_BEG_POS_Y; int cursor_c = -1; char buf[2]; int x, y; fifo_init(&task->fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settimer(timer, 50); /* display the prompt of console window */ drawstring_and_refresh(layer, 8, 28, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); for ( ; ; ) { io_cli(); if (0 == fifo_size(&task->fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&task->fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &task->fifo, 0); if (cursor_c >= 0) cursor_c = COLOR8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); if (cursor_c >= 0) cursor_c = COLOR8_000000; } timer_settimer(timer, 50); } if (2 == data) /* cursor ON */ cursor_c = COLOR8_FFFFFF; if (3 == data) { /* cursor OFF */ fill_box8(layer->buf, layer->w_size, COLOR8_000000, cursor_x, 28, cursor_x + 7, cursor_y + 15); cursor_c = -1; } if (256 <= data && data <= 511) { /* keyboard data */ if ((8 + 256) == data) { /* backspace */ if (cursor_x > INPUT_BEG_POS_X) { /* erase the cursor and move forward one character */ drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1); cursor_x -= 8; } } else if ((10 + 256) == data) { /* Enter Key */ /* erase cursor by space */ drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1); if (cursor_y < (INPUT_BEG_POS_Y + 112)) cursor_y += 16; else { /* scroll */ for (y = INPUT_BEG_POS_Y; y < INPUT_BEG_POS_Y + 112; ++y) { for (x = 8; x < 8 + 240; ++x) { layer->buf[x + y * layer->w_size] = layer->buf[x + (y + 16) * layer->w_size]; } } for (y = INPUT_BEG_POS_Y + 112; y < INPUT_BEG_POS_Y + 128; ++y) { for (x = 8; x < 8 + 240; ++x) layer->buf[x + y * layer->w_size] = COLOR8_000000; } layers_refresh(layer, 8, INPUT_BEG_POS_Y, 8 + 240, INPUT_BEG_POS_Y + 128); } /* show prompt */ drawstring_and_refresh(layer, 8, cursor_y, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); cursor_x = INPUT_BEG_POS_X; } else { /* general character */ if (cursor_x < 240) { /* display one character and move backward one character */ buf[0] = data - 256; buf[1] = 0; drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, buf, 1); cursor_x += 8; } } } /* show the cursor again */ if (cursor_c >= 0) { fill_box8(layer->buf, layer->w_size, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); } layers_refresh(layer, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); } } }
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); } } } } }
static void console_task(layer_t* layer) { #define INPUT_BEG_POS (24) #define PROMPT_CHAR ("> ") #define PROMPT_LEN (2) timer_t* timer; task_t* task = task_now(); int data, fifobuf[128]; int cursor_x = INPUT_BEG_POS, cursor_c = COLOR8_000000; char buf[2]; fifo_init(&task->fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settimer(timer, 50); /* display the prompt of console window */ drawstring_and_refresh(layer, 8, 28, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); for ( ; ; ) { io_cli(); if (0 == fifo_size(&task->fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&task->fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &task->fifo, 0); cursor_c = COLOR8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); cursor_c = COLOR8_000000; } timer_settimer(timer, 50); } if (256 <= data && data <= 511) { /* keyboard data */ if ((8 + 256) == data) { /* backspace */ if (cursor_x > INPUT_BEG_POS) { /* erase the cursor and move forward one character */ drawstring_and_refresh(layer, cursor_x, 28, COLOR8_FFFFFF, COLOR8_000000, " ", 1); cursor_x -= 8; } } else { /* general character */ if (cursor_x < 240) { /* display one character and move backward one character */ buf[0] = data - 256; buf[1] = 0; drawstring_and_refresh(layer, cursor_x, 28, COLOR8_FFFFFF, COLOR8_000000, buf, 1); cursor_x += 8; } } } /* show the cursor again */ fill_box8(layer->buf, layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(layer, 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); } } } }
static void console_task(layer_t* layer, unsigned int mem_total) { #define INPUT_BEG_POS_X (24) #define INPUT_BEG_POS_Y (28) #define PROMPT_CHAR ("> ") #define PROMPT_LEN (2) timer_t* timer; task_t* task = task_now(); int data, fifobuf[128]; int cursor_x = INPUT_BEG_POS_X, cursor_y = INPUT_BEG_POS_Y; int cursor_c = -1; char buf[32], cmdline[32]; mem_mgr_t* memmgr = (mem_mgr_t*)MEMMGR_ADDR; fifo_init(&task->fifo, fifobuf, 128, task); timer = timer_alloc(); timer_init(timer, &task->fifo, 1); timer_settimer(timer, 50); /* display the prompt of console window */ drawstring_and_refresh(layer, 8, 28, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); for ( ; ; ) { io_cli(); if (0 == fifo_size(&task->fifo)) { task_sleep(task); io_sti(); } else { data = fifo_get(&task->fifo); io_sti(); if (data <= 1) { /* timer for cursor */ if (0 != data) { timer_init(timer, &task->fifo, 0); if (cursor_c >= 0) cursor_c = COLOR8_FFFFFF; } else { timer_init(timer, &task->fifo, 1); if (cursor_c >= 0) cursor_c = COLOR8_000000; } timer_settimer(timer, 50); } if (2 == data) /* cursor ON */ cursor_c = COLOR8_FFFFFF; if (3 == data) { /* cursor OFF */ fill_box8(layer->buf, layer->w_size, COLOR8_000000, cursor_x, 28, cursor_x + 7, cursor_y + 15); cursor_c = -1; } if (256 <= data && data <= 511) { /* keyboard data */ if ((8 + 256) == data) { /* backspace */ if (cursor_x > INPUT_BEG_POS_X) { /* erase the cursor and move forward one character */ drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1); cursor_x -= 8; } } else if ((10 + 256) == data) { /* Enter Key */ /* erase cursor by space */ drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, " ", 1); cmdline[cursor_x / 8 - 3] = 0; cursor_y = console_newline(cursor_y, layer); /* execute command */ if (0 == strcmp("mem", cmdline)) { /* check memory command */ cursor_y = memory_command(layer, memmgr, mem_total, cursor_y); } else if (0 == strcmp("clear", cmdline)) { /* clear command */ cursor_y = clear_command(layer); } else if (0 == strcmp("ls", cmdline)) { /* ls(dir) command */ cursor_y = list_command(layer, cursor_y); } else if (0 == strncmp("cat ", cmdline, 4)) { /* cat command */ cursor_y = cat_command(layer, cursor_x, cursor_y, cmdline); } else if (0 != cmdline[0]) { /* neither command nor null string */ drawstring_and_refresh(layer, 8, cursor_y, COLOR8_FFFFFF, COLOR8_000000, "Bad Command.", 12); cursor_y = console_newline(cursor_y, layer); cursor_y = console_newline(cursor_y, layer); } /* show prompt */ drawstring_and_refresh(layer, 8, cursor_y, COLOR8_FFFFFF, COLOR8_000000, PROMPT_CHAR, PROMPT_LEN); cursor_x = INPUT_BEG_POS_X; } else { /* general character */ if (cursor_x < 240) { /* display one character and move backward one character */ buf[0] = data - 256; buf[1] = 0; cmdline[cursor_x / 8 - 3] = data - 256; drawstring_and_refresh(layer, cursor_x, cursor_y, COLOR8_FFFFFF, COLOR8_000000, buf, 1); cursor_x += 8; } } } /* show the cursor again */ if (cursor_c >= 0) { fill_box8(layer->buf, layer->w_size, cursor_c, cursor_x, cursor_y, cursor_x + 7, cursor_y + 15); } layers_refresh(layer, cursor_x, cursor_y, cursor_x + 8, cursor_y + 16); } } }
void HariMain(void) { boot_info_t* binfo = (boot_info_t*)ADR_BOOTINFO; char debug_info[64], mouse_cursor[256], keybuf[32], mousebuf[128]; int mouse_x, mouse_y; int data; mouse_dec_t mdec; init_gdt_idt(); init_pic(); io_sti(); fifo_init(&g_keybuf, keybuf, 32); fifo_init(&g_mousebuf, mousebuf, 128); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_keyboard(); /* initialize keyboard */ init_palette(); init_screen(binfo->vram, binfo->screen_x, binfo->screen_y); mouse_x = (binfo->screen_x - 16) / 2; mouse_y = (binfo->screen_y - 28 - 16) / 2; init_mouse_cursor8(mouse_cursor, COLOR8_848484); draw_block8_8(binfo->vram, binfo->screen_x, 16, 16, mouse_x, mouse_y, mouse_cursor, 16); sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); draw_font8_asc(binfo->vram, binfo->screen_x, 0, 0, COLOR8_FFFFFF, debug_info); enable_mouse(&mdec); /* enabled mouse */ for ( ; ; ) { io_cli(); if (0 == fifo_size(&g_keybuf) && 0 == fifo_size(&g_mousebuf)) io_stihlt(); else { if (0 != fifo_size(&g_keybuf)) { data = fifo_get(&g_keybuf); io_sti(); sprintf(debug_info, "%02X", data); fill_box8(binfo->vram, binfo->screen_x, COLOR8_848484, 0, 16, 15, 31); draw_font8_asc(binfo->vram, binfo->screen_x, 0, 16, COLOR8_FFFFFF, debug_info); } 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(binfo->vram, binfo->screen_x, COLOR8_848484, 32, 16, 32 + 15 * 8 - 1, 31); draw_font8_asc(binfo->vram, binfo->screen_x, 32, 16, COLOR8_FFFFFF, debug_info); /* move mouse pointer */ fill_box8(binfo->vram, binfo->screen_x, COLOR8_848484, mouse_x, mouse_y, mouse_x + 15, mouse_y + 15);/* hide mouse */ 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 - 16) mouse_x = binfo->screen_x - 16; if (mouse_y > binfo->screen_y - 16) mouse_y = binfo->screen_y - 16; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); fill_box8(binfo->vram, binfo->screen_x, COLOR8_848484, 0, 0, 79, 15); /* hide mouse position */ draw_font8_asc(binfo->vram, binfo->screen_x, 0, 0, COLOR8_FFFFFF, debug_info); /* show mouse position */ draw_block8_8(binfo->vram, binfo->screen_x, 16, 16, mouse_x, mouse_y, mouse_cursor, 16); /* draw mouse */ } } } } }
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, cursor_x, cursor_c, task_b_esp; 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; 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', '.' }; tss32_t tss_a, tss_b; segment_descriptor_t* gdt = (segment_descriptor_t*)ADR_GDT; 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 */ set490(&fifo, 1); 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, "Window"); make_text8(win_layer, 8, 28, 144, 16, COLOR8_FFFFFF); cursor_x = 8; cursor_c = COLOR8_FFFFFF; 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); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_b.ldtr = 0; tss_b.iomap = 0x40000000; set_segment_descriptor(gdt + 3, 103, (int)&tss_a, AR_TSS32); set_segment_descriptor(gdt + 4, 103, (int)&tss_b, AR_TSS32); load_tr(3 * 8); task_b_esp = mem_mgr_alloc_4k(mem_mgr, 64 * 1024) + 64 * 1024 - 8; 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 = 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; *((int*)(task_b_esp + 4)) = (int)back_layer; mt_init(); for ( ; ; ) { io_cli(); if (0 == fifo_size(&fifo)) io_stihlt(); 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 < 144) { /* 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 (10 == data) { drawstring_and_refresh(back_layer, 0, 64, COLOR8_FFFFFF, COLOR8_848484, "10[sec]", 7); } else if (3 == data) { drawstring_and_refresh(back_layer, 0, 80, COLOR8_FFFFFF, COLOR8_848484, "03[sec]", 7); } else if (data <= 1) { /* timer by cursor */ if (0 != data) { timer_init(timer3, &fifo, 0); cursor_c = COLOR8_000000; } else { timer_init(timer3, &fifo, 1); cursor_c = COLOR8_FFFFFF; } timer_settimer(timer3, 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); } } } }
int main() { Fifo fifo; fifo_init(&fifo); printf("Size (0): %i\n", fifo_size(&fifo)); char c; // put a char fifo_put(&fifo, 'a'); printf("%i %i\n",fifo.in, fifo.out); printf("Size (1): %i\n", fifo_size(&fifo)); fifo_pop(&fifo, &c); printf("Pop a: %c\n",c); // Pop when zero elements printf("Pop (0,a): %i, %c\n", fifo_pop(&fifo, &c), c); // Print the size fifo_put(&fifo, 'a'); printf("Size (1): %i\n", fifo_size(&fifo)); fifo_pop(&fifo, &c); // put several chars fifo_put(&fifo, 'a'); fifo_put(&fifo, 'b'); fifo_put(&fifo, 'c'); printf("Size (3): %i\n", fifo_size(&fifo)); fifo_pop(&fifo, &c); printf("Pop a: %c\n",c); fifo_pop(&fifo, &c); printf("Pop b: %c\n",c); fifo_pop(&fifo, &c); printf("Pop c: %c\n",c); // Print int 1 fifo_put(&fifo, 1); fifo_pop(&fifo, &c); printf("Pop 1: %i\n",c); // put negative number fifo_put(&fifo, -127); fifo_pop(&fifo, &c); printf("Pop -127: %i\n",c); // Check peek fifo_put(&fifo, 34); fifo_peek(&fifo, &c); printf("Peek 34: %i\n",c); printf("Size 1: %i\n", fifo_size(&fifo)); fifo_pop(&fifo,&c); // Check peek 2 fifo_put(&fifo, 75); fifo_put(&fifo, 32); fifo_peek_at(&fifo, &c, 1); printf("Peek 32: %i\n",c); printf("Size 2: %i\n", fifo_size(&fifo)); // overflowtest (does not add any more elements) printf("Size (2): %i\n", fifo_size(&fifo)); int j; for(j = 0; j < 130; j++) { //printf("Size: %i (%i,%i)\n", fifo_size(&fifo), fifo.in, fifo.out); fifo_put(&fifo, j); } printf("Size (127): %i\n", fifo_size(&fifo)); //printf("in: %i, out: %i\n", fifo.in, fifo.out); fifo_pop(&fifo, &c); printf("Pop 75: %i\n", c); fifo_pop(&fifo, &c); printf("Pop 32: %i\n", c); printf("Size (125): %i\n", fifo_size(&fifo)); // Second FIFO Fifo fifo2; fifo_init(&fifo); fifo_put(&fifo2, 'b'); printf("Size: %i\n", fifo_size(&fifo2)); fifo_pop(&fifo2, &c); printf("Pop b: %c\n",c); return 1; }
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; 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); } } } }