static void mt_mem_free(void* p_addr) { mem_mgr_free_param_t param = {0}; param.id = MEM_SYS_PARTITION; param.p_addr = p_addr; param.user_id = SYS_MODULE_SYSTEM; mem_mgr_free(¶m); }
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; 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); } } } } }
int* toy_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax) { int ds_base = *((int*)0x0fe8); task_t* task = task_now(); console_t* console = (console_t*)(*((int*)0x0fec)); layer_mgr_t* layermgr = (layer_mgr_t*)(*((int*)0x0fe4)); layer_t* layer; int* reg = &eax + 1; /* address after eax */ /* * force to modify value of pushad * reg[0] : edi, reg[1] : esi, reg[2] : ebp, reg[3] : esp * reg[4] : ebx, reg[5] : edx, reg[6] : ecx, reg[7] : eax */ switch (edx) { case 1: console_putchar(console, eax & 0xff, 1); break; case 2: console_putstr0(console, (char*)ebx + ds_base); break; case 3: console_putstr1(console, (char*)ebx + ds_base, ecx); break; case 4: return &(task->tss.esp0); case 5: { layer = layer_alloc(layermgr); layer_setbuf(layer, (char*)ebx + ds_base, esi, edi, eax); make_window8((char*)ebx + ds_base, esi, edi, (char*)ecx + ds_base, 0); layer_slide(layer, 100, 50); layer_updown(layer, 3); reg[7] = (int)layer; } break; case 6: { layer = (layer_t*)ebx; draw_font8_asc(layer->buf, layer->w_size, esi, edi, eax, (char*)ebp + ds_base); layers_refresh(layer, esi, edi, esi + ecx * 8, edi + 16); } break; case 7: { layer = (layer_t*)ebx; fill_box8(layer->buf, layer->w_size, ebp, eax, ecx, esi, edi); layers_refresh(layer, eax, ecx, esi + 1, edi + 1); } break; case 8: { mem_mgr_init((mem_mgr_t*)(ebx + ds_base)); ecx &= 0xfffffff0; /* unit: 16bytes */ mem_mgr_free((mem_mgr_t*)(ebx + ds_base), eax, ecx); } break; case 9: { ecx = (ecx + 0x0f) & 0xfffffff0; reg[7] = mem_mgr_alloc((mem_mgr_t*)(ebx + ds_base), ecx); } break; case 10: { ecx = (ecx + 0x0f) & 0xfffffff0; mem_mgr_free((mem_mgr_t*)(ebx + ds_base), eax, ecx); } break; } return 0; }
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) { 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); } } } } }
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) { 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) { 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); } } } }