void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], keybuf[32], mousebuf[128]; int mx, my, i; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse; unsigned char *buf_back, buf_mouse[256]; init_gdtidt(); init_pic(); io_sti(); /* GDT,IDT,PIC*/ fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); io_out8(PIC0_IMR, 0xf9); // 11111001,PIC1和IRQ1, io_out8(PIC1_IMR, 0xef); // 11101111, IRQ12 init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); sheet_slide(shtctl, sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(shtctl, sht_mouse, mx, my); sheet_updown(shtctl, sht_back, 0); sheet_updown(shtctl, sht_mouse, 1); sprintf(s, "(0x%x, 0x%x)", mx, my); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory 0x%xMB, free : 0x%xKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(shtctl, sht_back, 0, 0, binfo->scrnx, 48); for(;;) { io_cli(); if(0 == fifo8_status(&keyfifo) + fifo8_status(&mousefifo)) { io_stihlt(); } else { if(0 != fifo8_status(&keyfifo)) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "0x%x", i); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 16, 8 * 8 - 1, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(shtctl, sht_back, 0, 16, 8 * 8, 32); } else if (0 != fifo8_status(&mousefifo)) { i = fifo8_get(&mousefifo); io_sti(); if (0 != mouse_decode(&mdec, i)) { sprintf(s, "[lcr 0x%x 0x%x 0x%x]", mdec.buf[0], mdec.buf[1], mdec.buf[2]); if (0 != (mdec.btn & 0x01)) { s[1] = 'L'; } if (0 != (mdec.btn & 0x02)) { s[3] = 'R'; } if (0 != (mdec.btn & 0x04)) { s[2] = 'C'; } boxfill8(buf_back, binfo->scrnx, COL8_008484, 64, 16, 64 + 24 * 8 - 1, 31); putfonts8_asc(buf_back, binfo->scrnx, 64, 16, COL8_FFFFFF, s); sheet_refresh(shtctl, sht_back, 64, 16, 64 + 24 * 8, 32); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 16) { mx = binfo->scrnx - 16; } if (my > binfo->scrny - 16) { my = binfo->scrny - 16; } sprintf(s, "(0x%x, 0x%x)", mx, my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0, 8 * 16 - 1, 15); /* 隐藏坐标*/ putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); /* 显示坐标*/ sheet_refresh(shtctl, sht_back, 0, 0, 8 * 16, 16); sheet_slide(shtctl, sht_mouse, mx, my); /* 显示鼠标 */ } } } } return; }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256]; struct SHEET *sht_back, *sht_mouse; struct TASK *task_a, *task; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; int j, x, y, mmx = -1, mmy = -1, mmx2 = 0; struct SHEET *sht = 0, *key_win, *sht2; int *fat; unsigned char *nihongo; struct FILEINFO *finfo; extern char hankaku[4096]; init_gdtidt(); init_pic(); io_sti(); /* IDT/PIC的初始化已经完成,于是开放CPU的中断 */ fifo32_init(&fifo, 128, fifobuf, 0); *((int *) 0x0fec) = (int) &fifo; init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* 设定PIT和PIC1以及键盘为许可(11111000) */ io_out8(PIC1_IMR, 0xef); /* 开放鼠标中断(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); *((int *) 0x0fe4) = (int) shtctl; task_a->langmode = 0; /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 无透明色 */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ key_win = open_console(shtctl, memtotal); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 计算坐标使其位于画面中央 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(key_win, 32, 4); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(key_win, 1); sheet_updown(sht_mouse, 2); keywin_on(key_win); /* 为了避免和键盘当前状态冲突,在一开始先进行设置 */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); /* 载入nihongo.fnt */ fat = (int *) memman_alloc_4k(memman, 4 * 2880); file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200)); finfo = file_search("nihongo.fnt", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); if (finfo != 0) { i = finfo->size; nihongo = file_loadfile2(finfo->clustno, &i, fat); } else { nihongo = (unsigned char *) memman_alloc_4k(memman, 16 * 256 + 32 * 94 * 47); for (i = 0; i < 16 * 256; i++) { nihongo[i] = hankaku[i]; /*没有字库,半角部分直接复制英文字库*/ } for (i = 16 * 256; i < 16 * 256 + 32 * 94 * 47; i++) { nihongo[i] = 0xff; /* 没有字库,全角部分以0xff填充 */ } } *((int *) 0x0fe8) = (int) nihongo; memman_free_4k(memman, (int) fat, 4 * 2880); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* 如果存在向键盘控制器发送的数据,则发送它 */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { /* FIFO为空,当存在搁置的绘图操作时立即执行*/ if (new_mx >= 0) { io_sti(); sheet_slide(sht_mouse, new_mx, new_my); new_mx = -1; } else if (new_wx != 0x7fffffff) { io_sti(); sheet_slide(sht, new_wx, new_wy); new_wx = 0x7fffffff; } else { task_sleep(task_a); io_sti(); } } else { i = fifo32_get(&fifo); io_sti(); if (key_win != 0 && key_win->flags == 0) { /*窗口被关闭*/ if (shtctl->top == 1) { /*当画面上只剩鼠标和背景时*/ key_win = 0; } else { key_win = shtctl->sheets[shtctl->top - 1]; keywin_on(key_win); } } if (256 <= i && i <= 511) { /* 键盘数据*/ if (i < 0x80 + 256) { /*将按键编码转换为字符编码*/ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /*当输入字符为英文字母时*/ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /*将大写字母转换为小写字母*/ } } if (s[0] != 0 && key_win != 0) { /*一般字符、退格键、回车键*/ fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f && key_win != 0) { /* Tab键 */ keywin_off(key_win); j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on(key_win); } if (i == 256 + 0x2a) { /*左Shift ON */ key_shift |= 1; } if (i == 256 + 0x36) { /*右Shift ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /*左Shift OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /*右Shift OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */ task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { cons_putstr0(task->cons, "\nBreak(key) :\n"); io_cli(); /*强制结束处理时禁止任务切换*/ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); task_run(task, -1, 0); /*为了确实执行结束处理,如果处于休眠状态则唤醒*/ } } if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */ if (key_win != 0) { keywin_off(key_win); } key_win = open_console(shtctl, memtotal); sheet_slide(key_win, 32, 4); sheet_updown(key_win, shtctl->top); keywin_on(key_win); } if (i == 256 + 0x57) { /* F11 */ sheet_updown(shtctl->sheets[1], shtctl->top - 1); } if (i == 256 + 0xfa) { /*键盘成功接收到数据*/ keycmd_wait = -1; } if (i == 256 + 0xfe) { /*键盘没有成功接收到数据*/ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } } else if (512 <= i && i <= 767) { /* 鼠标数据*/ if (mouse_decode(&mdec, i - 512) != 0) { /* 已经收集了3字节的数据,移动光标 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } new_mx = mx; new_my = my; if ((mdec.btn & 0x01) != 0) { /* 按下左键 */ if (mmx < 0) { /*如果处于通常模式*/ /*按照从上到下的顺序寻找鼠标所指向的图层*/ for (j = shtctl->top - 1; j > 0; j--) { sht = shtctl->sheets[j]; x = mx - sht->vx0; y = my - sht->vy0; if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown(sht, shtctl->top - 1); if (sht != key_win) { keywin_off(key_win); key_win = sht; keywin_on(key_win); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { mmx = mx; /*进入窗口移动模式*/ mmy = my; mmx2 = sht->vx0; new_wy = sht->vy0; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) { /*点击“×”按钮*/ if ((sht->flags & 0x10) != 0) { /*该窗口是否为应用程序窗口?*/ task = sht->task; cons_putstr0(task->cons, "\nBreak(mouse) :\n"); io_cli(); /*强制结束处理时禁止任务切换*/ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); task_run(task, -1, 0); } else { /*命令行窗口*/ task = sht->task; sheet_updown(sht, -1); /*暂且隐藏该图层*/ keywin_off(key_win); key_win = shtctl->sheets[shtctl->top - 1]; keywin_on(key_win); io_cli(); fifo32_put(&task->fifo, 4); io_sti(); } } break; } } } } else { /*如果处于窗口移动模式*/ x = mx - mmx; /*计算鼠标指针移动量*/ y = my - mmy; new_wx = (mmx2 + x + 2) & ~3; new_wy = new_wy + y; mmy = my; } } else { /*没有按下左键*/ mmx = -1; /*切换到一般模式*/ if (new_wx != 0x7fffffff) { sheet_slide(sht, new_wx, new_wy); /*固定图层位置*/ new_wx = 0x7fffffff; } } } } else if (768 <= i && i <= 1023) { /*命令行窗口关闭处理*/ close_console(shtctl->sheets0 + (i - 768)); } else if (1024 <= i && i <= 2023) { close_constask(taskctl->tasks0 + (i - 1024)); } else if (2024 <= i && i <= 2279) { /*只关闭命令行窗口*/ sht2 = shtctl->sheets0 + (i - 2024); memman_free_4k(memman, (int) sht2->buf, 256 * 165); sheet_free(sht2); } } } }
void HariMain(void) { /* **最初的这部分变量没有通过内存管理来分配,它们本身属于操作系统的一部分,存在于bootpack.hrb所在的那块儿内存空间中 */ BOOTINFO *binfo = (BOOTINFO *) ADR_BOOTINFO; MOUSE_DECODE mouse_dec; MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR; LAYER_MANAGE *layer_manage; LAYER *layer_bg, *layer_mouse, *layer_window, *layer_console; TIMER *timer; FIFO fifo_mutual; //缓冲区管理,所有中断公用的 FIFO keycmd_fifo; TASK *task_a, *task_console; int fifobuf[128]; //缓冲区 int keycmd_buf[32]; int cursor_x = 8, cursor_color = COL8_000000; //分别代表输入字符后的那个闪烁光标的横坐标和颜色 int mCursorX, mCursorY; //鼠标光标显示位置的横纵坐标 int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; //标志键盘输入到哪个窗口中 unsigned int memory_total, i; char buf_cursor[mCursorWidth * mCursorHeight]; unsigned char *buf_bg, *buf_window, *buf_console; //屏幕的大背景会在init_screen的时候画出来,这里只需要一个指向它的指针即可 unsigned char strings[40]; mCursorX = binfo->scrnx / 2; mCursorY = (binfo->scrny - 28)/ 2; //减去下方任务栏的高度 /*内存检查*/ i = memtest(0x00400000, 0xbfffffff) / (1024 * 1024); //i的单位是MB /*内存管理*/ memmanage_init(memmanage); memory_total = i * 1024 * 1024; memmanage_free_4K(memmanage, 0x00001000, 0x0009e000); memmanage_free_4K(memmanage, 0x00400000, memory_total - 0x00400000); init_fifo(&keycmd_fifo, 32, keycmd_buf, 0); /*初始化接收中断的缓冲区*/ init_fifo(&fifo_mutual, 128, fifobuf, 0); //初始化mouseFIFO缓冲区,现在还没任务,先指定为0 /*初始化GDT和IDT表以及PIC板的数据*/ init_GDTandIDT(); //初始化GDT和IDT表 init_pic(); //初始化PIC主从板数据,除了IRQ2禁止了全部中断 io_sti(); //开始接收中断 /*初始化PIT中断控制*/ init_PIT(); /*若要接收鼠标中断需要两个步骤,首先必须使鼠标控制电路(就是键盘控制电路的一部分)有效,然后要使鼠标本身有效*/ init_keyboard(&fifo_mutual, 256); //初始化键盘控制器电路 enable_mouse(&fifo_mutual, 512, &mouse_dec); //激活鼠标 /*开放各种中断*/ io_out8(PIC0_IMR, 0xf8); //PIC0开发IRQ(11111000),开放IRQ0、IRQ1和IRQ2,定时器、键盘中断和从PIC板 io_out8(PIC1_IMR, 0xef); //PIC1开放IRQ(11101111), 开放鼠标中断 /*初始化任务切换管理*/ task_a = task_init(memmanage); //这个task_a其实代表的就是这些鼠标键盘等的任务 fifo_mutual.task = task_a; //为鼠标键盘等的缓冲区指定唤醒任务为task_a task_run(task_a, 1, 2); /*初始化调色板,为图形界面做准备*/ init_palette(); //初始化调色板 /*初始化图层管理,并且初始化鼠标光标和背景的图层*/ layer_manage = layer_man_init(memmanage, binfo->vram, binfo->scrnx, binfo->scrny); layer_bg = layer_alloc(layer_manage); //为背景分配图层 layer_mouse = layer_alloc(layer_manage); //为鼠标分配图层 layer_window = layer_alloc(layer_manage); //为窗口分配图层 buf_bg = (unsigned char *)memmanage_alloc_4K(memmanage, binfo->scrnx * binfo->scrny); //为背景图形的内容分配内存 buf_window = (unsigned char *)memmanage_alloc_4K(memmanage, 160 * 52); //为窗口图形的内容分配内存 /*为各个图形的图层内容进行设定*/ layer_set(layer_bg, buf_bg, binfo->scrnx, binfo->scrny, -1); layer_set(layer_mouse, buf_cursor, 16, 16 ,99); layer_set(layer_window, buf_window, 160, 52, -1); /*初始化整个桌面背景*/ init_screen(buf_bg, binfo->scrnx, binfo->scrny); //这个时候的init_screen不再是直接画出背景,而是在mBg内存地址中填写好背景内容 layer_slide(layer_bg, 0, 0); //把背景图层从(0,0)坐标开始画 /*初始化鼠标图标*/ init_mouse_cursor(buf_cursor, 99); //初始化鼠标光标 layer_slide(layer_mouse, mCursorX, mCursorY); //现在显示图形不需要再用displayShape函数了,直接用这个图层管理的绘图函数就行 /*初始化窗口*/ create_window(buf_window, 160, 52, "task_a", ACTIVE); //制作窗口 layer_slide(layer_window, 80, 100); //在指定位置显示出窗口 create_textbox(layer_window, 8, 28, 144, 16, COL8_FFFFFF); //在这个窗口中创建一个输入框 /*执行一个命令行窗口任务*/ layer_console = layer_alloc(layer_manage); buf_console = (unsigned char *)memmanage_alloc_4K(memmanage, 256 * 165); layer_set(layer_console, buf_console, 256, 165, -1); create_window(buf_console, 256, 165, "console", INACTIVE); create_textbox(layer_console, 8, 28, 240, 128, COL8_000000); task_console = task_alloc(); task_console->tss.esp = memmanage_alloc_4K(memmanage, 64 * 1024) + 64 * 1024 - 12; //由于这里要传入两个参数,所以减去了12 task_console->tss.eip = (int) &console_task; task_console->tss.es = 1 * 8; task_console->tss.cs = 2 * 8; task_console->tss.ss = 1 * 8; task_console->tss.ds = 1 * 8; task_console->tss.fs = 1 * 8; task_console->tss.gs = 1 * 8; *((int *) (task_console->tss.esp + 4)) = (int) layer_console; *((int *) (task_console->tss.esp + 8)) = memory_total; task_run(task_console, 2, 2); /* level=2, priority=2 */ layer_slide(layer_console, 32, 60); /*设置好各个图层的高度*/ layer_switch(layer_bg, 0); //把背景图层调为最底层,高度为0 layer_switch(layer_console, 1); //命令行窗口图层调节为第三层,高度为2 layer_switch(layer_window, 2); //窗口图层调节为第二层,高度为1 layer_switch(layer_mouse, 3); //鼠标图层调为最高层,高度为3 /*定时器的初始化及其设置*/ timer = timer_alloc(); timer_init(timer, &fifo_mutual, 1); timer_set(timer, 50); // fifo_put(&keycmd_fifo, KEYCMD_LED); fifo_put(&keycmd_fifo, key_leds); for(;;) { if(fifo_status(&keycmd_fifo) > 0 && keycmd_wait < 0) { keycmd_wait = fifo_get(&keycmd_fifo); wait_KBC_sendready(); io_out8(PORT_KEYDATA, keycmd_wait); } /*只有在从中断返回的缓冲区中读取数据的时候才需要禁止中断,因为如果这个时候来了中断而没有禁止的话, **有可能读脏数据,即把还没有读出的数据的给抹掉或换成别的数据 */ io_cli(); if(0 == fifo_status(&fifo_mutual)) //当前没有中断产生 { task_sleep(task_a); //如果没有需要处理的数据,就自己让自己休眠 /*上面的那个函数直接就跳转到另一个任务中去了,不过,因为每个人物的默认eflags都是开启中断的, **所以不用担心,这个任务还是能被唤醒的,耳环醒后的第一个动作就是为了以防万一先开启中断 */ io_sti(); //万一只有自己在运行的话,则无法睡眠,那么就执行hlt指令好了,这样省电嘛 } else { i = fifo_get(&fifo_mutual); io_sti(); //如果是键盘中断的话,需要处理键盘发送来的中断数据 if((keyboard_offset <= i) && (i <= keyboard_offset + 255)) { //判断shift键是否按下,然后使用不同的keytable表 if(i < 0x80 + keyboard_offset) { if(0 == key_shift) { strings[0] = key_table[i - keyboard_offset]; } else { strings[0] = key_table_shift[i - keyboard_offset]; } } else { strings[0] = 0; } //判断Caps和Shift键的情况以确定输入大写还是小写字母 if('A' <= strings[0] && strings[0] <= 'Z') { //小写字母的情况 if((0 == (key_leds & 4) && 0 == key_shift) || (0 != (key_leds & 4) && 0 != key_shift)) { strings[0] += 0x20; } } //判断按下的字符是否为一般字符,0对应的字符不处理 if(strings[0] != 0) { //发送给task_a任务的窗口 if(0 == key_to) { //所有可打印的字符都需要打印出来 if(cursor_x < 144) { strings[1] = 0; displayStrings_atLayer(layer_window, cursor_x, 28, COL8_000000, COL8_FFFFFF, strings); cursor_x += 8; //光标的位置随着每一个字符的输入向后移动一个字符宽度的位置即8像素 } } //发送给命令行窗口 else { fifo_put(&task_console->fifo, strings[0] + 256); } } /*这些都是那些不能打印的特殊按键,它们对应的都是0*/ //按下了“退格键”的情况,退格键的号码是0x0e if((keyboard_offset + 0x0e == i)) { if(0 == key_to) { //只有当前的输入位置上有字符了才能向前删除 if(cursor_x > 8) { cursor_x -= 8; /*本来退格键应该只填充一个空格就行的,但是这样的话没办法刷新光标所在的那块儿区域了, **会留下光标的黑色痕迹,所以直接填充两个空格,刷新之后就不会有痕迹了 */ displayStrings_atLayer(layer_window, cursor_x, 28, COL8_000000, COL8_FFFFFF, " "); } } else { fifo_put(&task_console->fifo, 8 + keyboard_offset); } } //由于光标坐标后退了或者因删除字符而前移了,为了及时显示它,需要立即重绘光标 if(cursor_color > 0) //这个光标的颜色值如果大于0,说明当前需要task_a来显示光标 { drawRectangle(layer_window->buffer, layer_window->length, cursor_color, cursor_x, 28, 2, 15); } layer_part_refresh(layer_window, cursor_x, 28, cursor_x + 8, 44); //按下“TAB键”的处理情况,切换输入窗口 if(keyboard_offset + 0x0f == i) { if(0 == key_to) //当前最前面窗口为task_a,则让console窗口成为最前端窗口 { key_to = 1; create_titlebar(buf_window, layer_window->length, "task_a", INACTIVE); create_titlebar(buf_console, layer_console->length, "console", ACTIVE); cursor_color = -1; //task_a不显示光标 drawRectangle(layer_window->buffer, layer_window->length, COL8_FFFFFF, cursor_x, 28, 2, 15); fifo_put(&task_console->fifo, 2); //当缓冲区中传入数据2时表示命令行窗口光标显示 } else //task_a任务的窗口成为最前端窗口 { key_to = 0; create_titlebar(buf_window, layer_window->length, "task_a", ACTIVE); create_titlebar(buf_console, layer_console->length, "console", INACTIVE); cursor_color = COL8_000000; fifo_put(&task_console->fifo, 3); //当缓冲区中传入数据3时表示命令行窗口光标不显示 } layer_part_refresh(layer_window, 0, 0, layer_window->length, 21); layer_part_refresh(layer_console, 0, 0, layer_console->length, 21); } //按下“回车键”的处理情况 if(keyboard_offset + 0x1c == i) { //发送至命令行窗口 if(0 != key_to) { fifo_put(&task_console->fifo, 10 + keyboard_offset); //传入10代表按下了回车键 } } //左shift ON if(0x2a + keyboard_offset == i) { key_shift |= 1; } //右shift ON if(0x36 + keyboard_offset == i) { key_shift |= 2; } //左shift OFF if(0xaa + keyboard_offset == i) { key_shift &= ~1; } //左shift OFF if(0xb6 + keyboard_offset == i) { key_shift &= ~2; } /*对各种锁定键的处理*/ //CapsLock键 if(i == keyboard_offset + 0x3a) { key_leds ^= 4; fifo_put(&keycmd_fifo, KEYCMD_LED); fifo_put(&keycmd_fifo, key_leds); } //NumLock键 if(i == keyboard_offset + 0x45) { key_leds ^= 2; fifo_put(&keycmd_fifo, KEYCMD_LED); fifo_put(&keycmd_fifo, key_leds); } //ScrollLock键 if(i == keyboard_offset + 0x46) { key_leds ^= 1; fifo_put(&keycmd_fifo, KEYCMD_LED); fifo_put(&keycmd_fifo, key_leds); } //键盘成功接收到数据 if(i == keyboard_offset + 0xfa) { keycmd_wait = -1; } //键盘没有成功接收到数据 if(i == keyboard_offset + 0xfe) { wait_KBC_sendready(); io_out8(PORT_KEYDATA, keycmd_wait); } } //如果是鼠标中断的话,需要处理鼠标发送来的中断数据 else if((mouse_offset <= i) && (i <= mouse_offset + 255)) { if(0 != mouse_decode(&mouse_dec, i - mouse_offset)) //只有返回值为1的时候才说明成功接收完成一次鼠标的中断 { if(0 != (mouse_dec.btn & 0x01)) //按下了左键 { layer_slide(layer_window, mCursorX - 80, mCursorY -8); //这行代码是移动窗口的 } /*鼠标的移动*/ //根据mouse_dec里存储的鼠标信息画出新的鼠标图像 mCursorX += mouse_dec.x; mCursorY += mouse_dec.y; //不能让鼠标移出画面 if(mCursorX < 0) { mCursorX = 0; } if(mCursorY < 0) { mCursorY = 0; } if(mCursorX > binfo->scrnx - 1) { mCursorX = binfo->scrnx - 1; } if(mCursorY > binfo->scrny - 1) { mCursorY = binfo->scrny - 1; } layer_slide(layer_mouse, mCursorX, mCursorY); } } //如果是定时器中断的话,需要处理定时器对应的任务 else if(1 == i || 0 == i) { if(0 != i) //这个timer的数据为1的时候显示光标 { timer_init(timer, &fifo_mutual, 0); if(cursor_color >= 0) //需要当前显示光标的时候,才对这个颜色值进行赋值 { cursor_color = COL8_000000; } } else //这个timer的数据为0的时候不显示光标 { timer_init(timer, &fifo_mutual, 1); if(cursor_color >= 0) { cursor_color = COL8_FFFFFF; } } timer_set(timer, 50); if(cursor_color >= 0) { drawRectangle(layer_window->buffer, layer_window->length, cursor_color, cursor_x, 28, 2, 15); layer_part_refresh(layer_window, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32], *cons_fifo[2]; int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256], *buf_cons[2]; struct SHEET *sht_back, *sht_mouse, *sht_cons[2]; struct TASK *task_a, *task_cons[2], *task; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; int j, x, y, mmx = -1, mmy = -1, mmx2 = 0; struct SHEET *sht = 0, *key_win; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); *((int *) 0x0fe4) = (int) shtctl; /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ for (i = 0; i < 2; i++) { sht_cons[i] = sheet_alloc(shtctl); buf_cons[i] = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons[i], buf_cons[i], 256, 165, -1); /* 透明色なし */ make_window8(buf_cons[i], 256, 165, "console", 0); make_textbox8(sht_cons[i], 8, 28, 240, 128, COL8_000000); task_cons[i] = task_alloc(); task_cons[i]->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12; task_cons[i]->tss.eip = (int) &console_task; task_cons[i]->tss.es = 1 * 8; task_cons[i]->tss.cs = 2 * 8; task_cons[i]->tss.ss = 1 * 8; task_cons[i]->tss.ds = 1 * 8; task_cons[i]->tss.fs = 1 * 8; task_cons[i]->tss.gs = 1 * 8; *((int *) (task_cons[i]->tss.esp + 4)) = (int) sht_cons[i]; *((int *) (task_cons[i]->tss.esp + 8)) = memtotal; task_run(task_cons[i], 2, 2); /* level=2, priority=2 */ sht_cons[i]->task = task_cons[i]; sht_cons[i]->flags |= 0x20; /* カーソルあり */ cons_fifo[i] = (int *) memman_alloc_4k(memman, 128 * 4); fifo32_init(&task_cons[i]->fifo, 128, cons_fifo[i], task_cons[i]); } /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons[1], 56, 6); sheet_slide(sht_cons[0], 8, 2); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons[1], 1); sheet_updown(sht_cons[0], 2); sheet_updown(sht_mouse, 3); key_win = sht_cons[0]; keywin_on(key_win); /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* キーボードコントローラに送るデータがあれば、送る */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { /* FIFOがからっぽになったので、保留している描画があれば実行する */ if (new_mx >= 0) { io_sti(); sheet_slide(sht_mouse, new_mx, new_my); new_mx = -1; } else if (new_wx != 0x7fffffff) { io_sti(); sheet_slide(sht, new_wx, new_wy); new_wx = 0x7fffffff; } else { task_sleep(task_a); io_sti(); } } else { i = fifo32_get(&fifo); io_sti(); if (key_win->flags == 0) { /* ウィンドウが閉じられた */ key_win = shtctl->sheets[shtctl->top - 1]; keywin_on(key_win); } if (256 <= i && i <= 511) { /* キーボードデータ */ if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 入力文字がアルファベット */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 大文字を小文字に変換 */ } } if (s[0] != 0) { /* 通常文字、バックスペース、Enter */ fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f) { /* Tab */ keywin_off(key_win); j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on(key_win); } if (i == 256 + 0x2a) { /* 左シフト ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右シフト ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左シフト OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右シフト OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0) { task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { /* Shift+F1 */ cons_putstr0(task->cons, "\nBreak(key) :\n"); io_cli(); /* 強制終了処理中にタスクが変わると困るから */ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); } } if (i == 256 + 0x57) { /* F11 */ sheet_updown(shtctl->sheets[1], shtctl->top - 1); } if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* キーボードがデータを無事に受け取れなかった */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } new_mx = mx; new_my = my; if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押している */ if (mmx < 0) { /* 通常モードの場合 */ /* 上の下じきから順番にマウスが指している下じきを探す */ for (j = shtctl->top - 1; j > 0; j--) { sht = shtctl->sheets[j]; x = mx - sht->vx0; y = my - sht->vy0; if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown(sht, shtctl->top - 1); if (sht != key_win) { keywin_off(key_win); key_win = sht; keywin_on(key_win); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { mmx = mx; /* ウィンドウ移動モードへ */ mmy = my; mmx2 = sht->vx0; new_wy = sht->vy0; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) { /* 「×」ボタンクリック */ if ((sht->flags & 0x10) != 0) { /* アプリが作ったウィンドウか? */ task = sht->task; cons_putstr0(task->cons, "\nBreak(mouse) :\n"); io_cli(); /* 強制終了処理中にタスクが変わると困るから */ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); } } break; } } } } else { /* ウィンドウ移動モードの場合 */ x = mx - mmx; /* マウスの移動量を計算 */ y = my - mmy; new_wx = (mmx2 + x + 2) & ~3; new_wy = new_wy + y; mmy = my; /* 移動後の座標に更新 */ } } else { /* 左ボタンを押していない */ mmx = -1; /* 通常モードへ */ if (new_wx != 0x7fffffff) { sheet_slide(sht, new_wx, new_wy); /* 一度確定させる */ new_wx = 0x7fffffff; } } } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], mcursor[256], keybuf[32], mousebuf[128]; int mx, my, i; struct MOUSE_DEC mdec; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); io_out8(PIC0_IMR, 0xf9); /* PIC1とキーボードを許可(11111001) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ init_keyboard(); init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; init_mouse_cursor8(mcursor, COL8_008484); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); enable_mouse(&mdec); for (;;) { io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, s); /* マウスカーソルの移動 */ boxfill8(binfo->vram, binfo->scrnx, COL8_008484, mx, my, mx + 15, my + 15); /* マウス消す */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 16) { mx = binfo->scrnx - 16; } if (my > binfo->scrny - 16) { my = binfo->scrny - 16; } sprintf(s, "(%3d, %3d)", mx, my); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 0, 79, 15); /* 座標消す */ putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); /* 座標書く */ putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); /* マウス描く */ } } } } }
void HariMain(void) { /*-----相关变量定义----*/ struct BOOTINFO *stBootInfo= (struct BOOTINFO *) 0x0ff0;//获取启动时候保存的信息 char s[100];//输出缓冲区 char szTemp[40]; //KeyBuf[32], MouseBuf[128]; int SysBuf[256]; struct MOUSE_DEC mdec; /* 定义一个MEMMAN结构指针(内存管理), 指向MEMMAN_ADDR也就是0x3c0000*/ struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; /* 图层管理结构指针 */ struct SHEET *Sht_Back, *Sht_Mouse, *Sht_Win,*Sht_TaskWin[2]; /* 背景以及鼠标的图层指针 */ unsigned char *Buf_Back, Buf_Mouse[256],*Buf_Win,*Buf_TaskWin[2]; struct TIMER *timer; struct TASK *task_a, *task_b[3]; //struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; /* 申请一个段描述符 */ //窗体移动相关变量 // int mmx=-1,mmy=-1; struct SHEET *sht=0; /* 没有按shift */ static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; /* 按下shift后 */ static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_shift = 0; int key_leds = (stBootInfo->leds >> 4) & 7; int key_wait = -1; /*-----系统初始化操作----*/ unsigned char *vram=stBootInfo->vram; int nXSize=stBootInfo->scrnx; int nYSize=stBootInfo->scrny; init_palette(); /* 初始化调色板 */ init_gdtidt(); //初始化GDT, IDT 表 Init_PIC(); /* 初始化PIC */ io_sti(); /* 打开所有可屏蔽中断 */ init_pit(); /*初始化 时钟中断*/ io_out8(PIC0_IMR, 0xf8); /* PIC0(11111000) (打开IRQ0时钟中断、IRQ1键盘中断和连接从PIC的IRQ2)*/ io_out8(PIC1_IMR, 0xef); /* PIC1(11101111) (打开PS2鼠标中断 即IRQ12)*/ /*----初始化鼠标键盘操作----*/ nKeyData0=256; nMouseData0=512; // io_out8(PIC0_IMR, 0xf9); /* 这个bug调我N久,注视下留个纪念。。*/ //io_out8(PIC1_IMR, 0xef); /* PIC1(11101111) (打开PS2鼠标中断 即IRQ12)*/ Init_Keyboard();/*初始化键盘控制电路*/ Enable_Mouse(&mdec); /* 激活鼠标 */ /*----内存操作----*/ /* 检测4M~3G-1的内存,4M之前被占用,不能检测 */ unsigned int nMemMaxSize=memtest(0x00400000, 0xbfffffff); memman_init(memman); /* 初始化内存管理结构 */ /* 这段内存是4K~636K-1,这段内存是4K~636K-1,映像刚开始载入内存的内容,包括引导程序那部分*/ memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, nMemMaxSize - 0x00400000); /* 4M~内存实际大小,4M之前用于保存相关数据,预留了很多空间备用 */ /*----图形操作----*/ shtctl = shtctl_init(memman,vram,nXSize,nYSize); /* 初始化图层管理结构 */ Sht_Back = sheet_alloc(shtctl); /* 创建背景图层 */ Sht_Mouse = sheet_alloc(shtctl); /* 创建鼠标图层 */ Sht_Win = sheet_alloc(shtctl); /* 创建窗口图层 */ Sht_TaskWin[0] = sheet_alloc(shtctl); /* 创建任务1图层 */ Sht_TaskWin[1] = sheet_alloc(shtctl); /* 创建任务2图层 */ Buf_Back = (unsigned char *) memman_alloc_4k(memman, nXSize * nYSize); /* 分配内存空间 用于绘制背景*/ Buf_Win = (unsigned char *) memman_alloc_4k(memman, 450 * 300); /* 分配内存空间 用于绘制"窗口 */ Buf_TaskWin[0] = (unsigned char *) memman_alloc_4k(memman, 170 * 75); Buf_TaskWin[1] = (unsigned char *) memman_alloc_4k(memman, 170 * 75); sheet_setbuf(Sht_Back, Buf_Back, nXSize,nYSize, -1); /* 设置背景图层信息 */ sheet_setbuf(Sht_Mouse, Buf_Mouse, 16, 16, COL_BACK_BLUE); /* 设置鼠标图层信息 */ sheet_setbuf(Sht_Win, Buf_Win, 450, 300, -1); /* 设置窗口图层信息 */ sheet_setbuf(Sht_TaskWin[0], Buf_TaskWin[0], 170, 75, -1); sheet_setbuf(Sht_TaskWin[1], Buf_TaskWin[1], 170, 75, -1); Init_MouseCur(Buf_Mouse, COL_BACK_BLUE); /* 初始化鼠标图形 */ DrawBack(Buf_Back, nXSize, nYSize); /* 绘制背景 */ make_window8(Buf_Win, 450, 300, "NoteWindow"); /* 绘制窗口图形 */ make_window_edit(Buf_Win, 450, 300); /* 绘制窗口图形 */ make_window8(Buf_TaskWin[0], 170, 75, "Task1"); /* 绘制窗口图形 */ make_window8(Buf_TaskWin[1], 170, 75, "Task2"); /* 绘制窗口图形 */ sheet_slide(Sht_Back, 0, 0); /* 设置背景图层的位置 */ sheet_slide(Sht_Win, 85, 160); /* 设置窗口图层的位置 */ sheet_slide(Sht_TaskWin[0], nYSize - 20, 60); /* 设置窗口图层的位置 */ sheet_slide(Sht_TaskWin[1], nYSize - 20, 140); /* 设置窗口图层的位置 */ int mx = (nXSize- 16) / 2; /* 计算鼠标图形在屏幕上的位置 它在整个桌面的中心位置 */ int my = (nYSize - 28 - 16) / 2; sheet_slide(Sht_Mouse, mx, my); /* 设置鼠标图层的位置 */ sheet_updown(Sht_Back, 0); /* 调整背景图层和鼠标图层的高度 */ sheet_updown(Sht_TaskWin[0], 1); sheet_updown(Sht_TaskWin[1], 2); sheet_updown(Sht_Win, -1); /* 调整默认窗口 */ sheet_updown(Sht_Mouse, 4); /* 并且会显示背景与鼠标图层 */ /*---任务切换相关---*/ int i; /* 任务切换初始化(*/ task_a = task_init(memman);//task_a 是内核任务 fifo32_init(&SysFifo, 256, SysBuf,task_a); task_run(task_a, -1, 2); /* 设置任务a的level和优先级 */ for(i=0;i<3;i++) { task_b[i]=task_alloc();//分配一个任务 task_b[i]->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; /* 创建任务B的堆栈,64K */; 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; } task_b[0]->tss.eip = (int) &task_b_main; /* 设置任务B的寄存器 */ task_b[1]->tss.eip = (int) &task_b_main1; /* 设置任务B的寄存器 */ task_b[2]->tss.eip = (int) &task_win_main; /* 设置任务Window的寄存器 */ /* 先将task_b_esp + 4转换成int类型的指针 即(int *) (task_b_esp + 4) */ /* 再将(int) sht_back赋值到该地址处*((int *) (task_b_esp + 4)) */ *((int *) (task_b[0]->tss.esp + 4)) = (int) Sht_TaskWin[0]; *((int *) (task_b[1]->tss.esp + 4)) = (int) Sht_TaskWin[1]; *((int *) (task_b[2]->tss.esp + 4)) = (int) Sht_Win; //task_run(task_a, 10);//分配给内核最高优先级 //task_run(task_b[0], 1); //task_run(task_b[1], 2); //task_run(task_b[2], 2); /*----显示系统信息----*/ //sprintf(s, "(%3d, %3d)", mx, my); sprintf(szTemp, " Screen:(%d, %d)", nXSize, nYSize); putfonts8_asc_sht(Sht_Back, 0, 0,COL_RED,COL_WHITE, szTemp, 20);//在图层上显示文字 sprintf(szTemp, "MemMaxSize:%d MB", nMemMaxSize/(1024*1024)); putfonts8_asc_sht(Sht_Back, 0, 57,COL_BLACK,COL_GREEN, szTemp, 17);//在图层上显示文字 sprintf(szTemp, "MemFree:%d KB", memman_total(memman) /1024); putfonts8_asc_sht(Sht_Back, 0, 76,COL_BLACK,COL_GREEN, szTemp, 17);//在图层上显示文字 /*----定时器设置----*/ timer = timer_alloc(); /* 创建定时器 */ timer_init(timer, &SysFifo, 100); /* 定时器初始化 */ timer_settime(timer, 100); /* 定时器设置 */ unsigned char cTemp=0x25;//颜色测试语句 /*---内核循环---*/ for (;;) { io_cli(); /* 关闭所有可屏蔽中断 */ /* 系统缓冲区没有数据 */ if(fifo32_status(&SysFifo)== 0) { //io_stihlt(); /* 开中断并待机 直到下一次中断来临 */ task_sleep(task_a);//休眠内核任务,在fifo有数据的时候才被重新激活 io_sti(); } else { i = fifo32_get(&SysFifo); io_sti();//打开中断 if(nKeyData0<=i && i<=nKeyData0+0xFF)/*键盘缓冲区有数据 */ { i-=nKeyData0; sprintf(s, "%02X", i); putfonts8_asc_sht(Sht_Back, 0, 20,COL_BLACK,COL_GREEN, s, 2);//在图层上显示文字 //---------------------------------------------------------------------------------------- if (i < 0x80) { if (key_shift == 0)/* 如果shift没有被按下 */ { s[0] = keytable0[i]; /* 将键值转换成字符的ASCII码 */ } else/* 如果shift被按下了 */ { s[0] = keytable1[i]; /* 将键值转换成字符的ASCII码 */ } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z')/* 如果输入的是英文字母 */ { /* CapsLock为OFF并且Shift为OFF 或者 CapsLock为ON并且Shift为ON */ if (((key_leds & 4) == 0 && key_shift == 0) ||((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 将大写字母转换成小写字母 */ /* 同一个字母的大小写ASCII码相差0x20 */ } } if (i == 0x0e)/* 退格键 */ { if(task_b[2]->fifo)//如果fifo存在 { fifo32_put(task_b[2]->fifo, 8 + 256); } } else if (i == 0x1c)/* 换行键 */ { if(task_b[2]->fifo)//如果fifo存在 { fifo32_put(task_b[2]->fifo, 7 + 256); } } else if (s[0] != 0) /* 一般字符 */ { if(task_b[2]->fifo)//如果fifo存在 { fifo32_put(task_b[2]->fifo, s[0] + 256); } } /* key_shift变量的bit0和bit1分别标识了左shift和右shift的开启与关闭状态 */ if (i == 0x2a)/* 左shift ON */ { key_shift |= 1; } if (i == 0x36)/* 右shift ON */ { key_shift |= 2; } if (i == 0xaa)/* 左shift OFF */ { key_shift &= ~1; } if (i == 0xb6)/* 右shift OFF */ { key_shift &= ~2; } // 0xfa是ACK信息 if (i == 0xfa) // 键盘成功接收到数据 { key_wait = -1; //等于-1表示可以发送指令 putfonts8_asc_sht(Sht_Back, 20, 18,COL_BLACK,COL_RED, s, 2);//在图层上显示文字 } if (i == 0xfe)// 键盘没有成功接收到数据 { wait_KBC_sendready(); io_out8(PORT_KEYDAT, key_wait); // 重新发送上次的指令 putfonts8_asc_sht(Sht_Back, 20, 16,COL_BLACK,COL_YELLOW, s, 2);//在图层上显示文字 } //---------------------------------------------------------------------------------------- } else if (nMouseData0<=i && i<=nMouseData0+0xFF) /* 鼠标缓冲区有数据 */ { i-=nMouseData0; if (Mouse_Decode(&mdec, i) != 0) { /* 接收鼠标发送的数据 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) /* 如果左键被按下 */ { s[1] = 'L'; //----移动窗体到最顶层------------------------------------------- int j,x,y; if(mmx<0)//普通模式(mmx负数) { //遍历图层 for (j = shtctl->top - 1; j > 0; j--) { sht = shtctl->p_sheets[j]; //vx0, vy0图层左上角的坐标 x = mx - sht->vx0;//鼠标与窗口左上角长度距离 y = my - sht->vy0;//鼠标与窗口左上角高度距离 //在图层的大小范围内 if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { //按中 关闭按钮,隐藏窗体 if(x > sht->bxsize-25 && x < sht->bxsize-5 && y > 4 && y < 17) { sheet_updown(sht, -1); break; } //不是透明色 if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown(sht, shtctl->top - 1); if(y<22)//在标题栏中,则进入拖动模式 { mmx=mx; mmy=my; } break; } } } } else//进入拖动模式 { x=mx-mmx;//计算鼠标移动距离 y=my-mmy;//这里mmx,mmx是上一次鼠标位置 //移动船体 sheet_slide(sht, sht->vx0+x, sht->vy0+y); mmx=mx; mmy=my; } } else { mmx=-1;//返回通常模式(左键放开时) } //----------------------------------------------------------------- if ((mdec.btn & 0x02) != 0) /* 如果右键被按下 */ { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) /* 如果滚轮被按下 */ { s[2] = 'C'; } putfonts8_asc_sht(Sht_Back, 32, 20,COL_BLACK,COL_GREEN, s, 16);//在图层上显示文字 mx += mdec.x; /* 更新新的鼠标位置 */ my += mdec.y; if (mx < 0) /* 鼠标的位置不能小于0,即不能超出屏幕位置 */ { mx = 0; } if (my < 0) { my = 0; } if (mx > nXSize - 1) /* 范围控制 ,防止超出屏幕*/ { mx = nXSize - 1; } if (my > nYSize-1 ) { my = nYSize-1; } sheet_slide(Sht_Mouse, mx, my); /* 更新鼠标图层的位置并显示新的鼠标图层 */ sprintf(s, "MousePos:(%3d, %3d)", mx, my); putfonts8_asc_sht(Sht_Back, 0, 39,COL_BLACK,COL_GREEN, s, 20);//在图层上显示文字 } } else if (i == 100) /* 定时器数据 ,100是设置的写入data*/ { //-----------任务栏秒数显示---------------------------------- sprintf(s, "%03d Sec", timerctl.count/100); putfonts8_asc_sht(Sht_Back, nXSize-60, nYSize-23,COL_WHITE,COL_BLACK, s, 9);//在图层上显示文字 if(timerctl.count/100==2)//2秒时候开始 { //根据预处理命令判断是否在测试中 #if TEST_ING sheet_updown(Sht_Win,shtctl->top-1); //弹出笔记本窗口 task_run(task_b[2],2,2); #else task_run(task_b[0], 2,1); task_run(task_b[1], 2,2); #endif } else if(timerctl.count/100==7)//7秒时候停止 { //根据预处理命令判断是否在测试中 #if TEST_ING #else task_sleep(task_b[0]); task_sleep(task_b[1]); #endif } else if(timerctl.count/100==8) { #if TEST_ING #else sheet_updown(Sht_Win,shtctl->top-1); //弹出笔记本窗口 task_run(task_b[2],2,2); #endif } /*颜色测试语句 sprintf(s, "%X", cTemp); RectFill(vram,nXSize,cTemp,0,0,nXSize,nYSize); PutFont_Asc(vram, nXSize, 100, 250, COL_WHITE, s); cTemp++;*/ timer_settime(timer, 100); /* 定时器设置 */ } } } }
void HariMain(void) { char *vram; int xsize; int ysize; //short *binfo_scrnx,*binfo_scrny; //int *binfo_vram; struct BOOTINFO *binfo; extern char hankaku[4096]; /*static char font_A[16] = { 0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00 };*/ int i; char s[40]; init_gdtidt(); init_pic(); io_sti(); init_keyboard(); init_palette(); binfo = (struct BOOTINFO *) 0x0ff0; xsize = binfo->scrnx; ysize = binfo->scrny; vram = binfo->vram; /* initlize the os background */ init_screen(vram,xsize,ysize); putfont8(binfo->vram, binfo->scrnx, 8, 8, COL8_FFFFFF, hankaku+'A'*16); putfont8(binfo->vram, binfo->scrnx, 16, 8, COL8_FFFFFF, hankaku+'B'*16); putfont8(binfo->vram, binfo->scrnx, 24, 8, COL8_FFFFFF, hankaku+'C'*16); putfont8(binfo->vram, binfo->scrnx, 40, 8, COL8_FFFFFF, hankaku+'1'*16); putfont8(binfo->vram, binfo->scrnx, 48, 8, COL8_FFFFFF, hankaku+'2'*16); putfonts8_asc(binfo->vram,binfo->scrnx,60,50,COL8_FFFFFF,"hello os."); // interaction input sprintf(s,"scrnx= %d",binfo->scrnx); putfonts8_asc(binfo->vram,binfo->scrnx,16,64,COL8_FFFFFF,s); char mcursor[256],keybuf[32]; int mx, my; mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; // mouse image enable_mouse(); init_mouse_cursor8(mcursor,COL8_008484); putblock8_8(binfo->vram,binfo->scrnx,16,16,mx,my,mcursor,16); io_out8(PIC0_IMR, 0xf9); /* PIC1�ƃL�[�{�[�h������(11111001) */ io_out8(PIC1_IMR, 0xef); //11101111 , allow irq12 // keyboard fifo8_init(&keyfifo,32,keybuf); for(;;) { io_cli(); // forbid all interrupts if(fifo8_status(&keyfifo) == 0) io_stihlt(); // read data until it's empty else { i=fifo8_get(&keyfifo); io_sti(); // open interrupts sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i, count = 0; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { count++; io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); } } else if (i == 10) { /* 10秒タイマ */ putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); sprintf(s, "%010d", count); putfonts8_asc_sht(sht_win, 40, 28, COL8_000000, COL8_C6C6C6, s, 10); } else if (i == 3) { /* 3秒タイマ */ putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); count = 0; /* 測定開始 */ } else if (i == 1) { /* カーソル用タイマ */ timer_init(timer3, &fifo, 0); /* 次は0を */ boxfill8(buf_back, binfo->scrnx, COL8_FFFFFF, 8, 96, 15, 111); timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } else if (i == 0) { /* カーソル用タイマ */ timer_init(timer3, &fifo, 1); /* 次は1を */ boxfill8(buf_back, binfo->scrnx, COL8_008484, 8, 96, 15, 111); timer_settime(timer3, 50); sheet_refresh(sht_back, 8, 96, 16, 112); } } } }
void HariMain(void) { 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); } } } }
void HariMain(void) { /* **最初的这部分变量没有通过内存管理来分配,它们本身属于操作系统的一部分,存在于bootpack.hrb所在的那块儿内存空间中 */ BOOTINFO *binfo = (BOOTINFO *) ADR_BOOTINFO; MOUSE_DECODE mouse_dec; MEMMANAGE *memmanage = (MEMMANAGE *)MEMMANAGE_ADDR; LAYER_MANAGE *layer_manage; LAYER *layer_bg, *layer_mouse, *layer_window, *layer_windowB[3]; TIMER *timer; FIFO fifo_mutual; //缓冲区管理,所有中断公用的 TASK *task_a, *task_b[3]; int fifobuf[128]; //缓冲区 int cursor_x = 8, cursor_color = COL8_FFFFFF; //分别代表输入字符后的那个闪烁光标的横坐标和颜色 int mCursorX, mCursorY; //鼠标光标显示位置的横纵坐标 unsigned int memory_total, i; char buf_cursor[mCursorWidth * mCursorHeight]; unsigned char *buf_bg, *buf_window, *buf_windowB; //屏幕的大背景会在init_screen的时候画出来,这里只需要一个指向它的指针即可 unsigned char strings[40]; mCursorX = binfo->scrnx / 2; mCursorY = (binfo->scrny - 28)/ 2; //减去下方任务栏的高度 /*内存检查*/ i = memtest(0x00400000, 0xbfffffff) / (1024 * 1024); //i的单位是MB /*内存管理*/ memmanage_init(memmanage); memory_total = i * 1024 * 1024; memmanage_free_4K(memmanage, 0x00001000, 0x0009e000); memmanage_free_4K(memmanage, 0x00400000, memory_total - 0x00400000); /*初始化接收中断的缓冲区*/ init_fifo(&fifo_mutual, 128, fifobuf, 0); //初始化mouseFIFO缓冲区,现在还没任务,先指定为0 /*初始化GDT和IDT表以及PIC板的数据*/ init_GDTandIDT(); //初始化GDT和IDT表 init_pic(); //初始化PIC主从板数据,除了IRQ2禁止了全部中断 io_sti(); //开始接收中断 /*初始化PIT中断控制*/ init_PIT(); /*若要接收鼠标中断需要两个步骤,首先必须使鼠标控制电路(就是键盘控制电路的一部分)有效,然后要使鼠标本身有效*/ init_keyboard(&fifo_mutual, 256); //初始化键盘控制器电路 enable_mouse(&fifo_mutual, 512, &mouse_dec); //激活鼠标 /*开放各种中断*/ io_out8(PIC0_IMR, 0xf8); //PIC0开发IRQ(11111000),开放IRQ0、IRQ1和IRQ2,定时器、键盘中断和从PIC板 io_out8(PIC1_IMR, 0xef); //PIC1开放IRQ(11101111), 开放鼠标中断 /*初始化任务切换管理*/ task_a = task_init(memmanage); //这个task_a其实代表的就是这些鼠标键盘等的任务 fifo_mutual.task = task_a; //为鼠标键盘等的缓冲区指定唤醒任务为task_a task_run(task_a, 1, 2); /*初始化调色板,为图形界面做准备*/ init_palette(); //初始化调色板 /*初始化图层管理,并且初始化鼠标光标和背景的图层*/ layer_manage = layer_man_init(memmanage, binfo->vram, binfo->scrnx, binfo->scrny); layer_bg = layer_alloc(layer_manage); //为背景分配图层 layer_mouse = layer_alloc(layer_manage); //为鼠标分配图层 layer_window = layer_alloc(layer_manage); //为窗口分配图层 buf_bg = (unsigned char *)memmanage_alloc_4K(memmanage, binfo->scrnx * binfo->scrny); //为背景图形的内容分配内存 buf_window = (unsigned char *)memmanage_alloc_4K(memmanage, 160 * 52); //为窗口图形的内容分配内存 /*为各个图形的图层内容进行设定*/ layer_set(layer_bg, buf_bg, binfo->scrnx, binfo->scrny, -1); layer_set(layer_mouse, buf_cursor, 16, 16 ,99); layer_set(layer_window, buf_window, 160, 52, -1); /*初始化整个桌面背景*/ init_screen(buf_bg, binfo->scrnx, binfo->scrny); //这个时候的init_screen不再是直接画出背景,而是在mBg内存地址中填写好背景内容 layer_slide(layer_bg, 0, 0); //把背景图层从(0,0)坐标开始画 /*初始化鼠标图标*/ init_mouse_cursor(buf_cursor, 99); //初始化鼠标光标 layer_slide(layer_mouse, mCursorX, mCursorY); //现在显示图形不需要再用displayShape函数了,直接用这个图层管理的绘图函数就行 /*初始化窗口*/ create_window(buf_window, 160, 52, "task_a", ACTIVE); //制作窗口 layer_slide(layer_window, 80, 72); //在指定位置显示出窗口 create_textbox(layer_window, 8, 28, 144, 16, COL8_FFFFFF); //在这个窗口中创建一个输入框 /*再画出3个窗口*/ for (i = 0; i < 3; i++) { layer_windowB[i] = layer_alloc(layer_manage); buf_windowB = (unsigned char *)memmanage_alloc_4K(memmanage, 144 * 52); layer_set(layer_windowB[i], buf_windowB, 144, 52, -1); //无透明色 sprintf(strings, "task_b%d", i); create_window(buf_windowB, 144, 52, strings, INACTIVE); task_b[i] = task_alloc(); task_b[i]->tss.esp = memmanage_alloc_4K(memmanage, 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) layer_windowB[i]; task_run(task_b[i], 2, i + 1); } task_run(task_a, 1, 0); layer_slide(layer_windowB[0], 240, 72); layer_slide(layer_windowB[1], 80, 132); layer_slide(layer_windowB[2], 240, 132); /*设置好各个图层的高度*/ layer_switch(layer_bg, 0); //把背景图层调为最底层,高度为0 layer_switch(layer_windowB[0], 1); //窗口图层调节为第二层,高度为1 layer_switch(layer_windowB[1], 2); //窗口图层调节为第二层,高度为1 layer_switch(layer_windowB[2], 3); //窗口图层调节为第二层,高度为1 layer_switch(layer_window, 4); //窗口图层调节为第二层,高度为1 layer_switch(layer_mouse, 5); //鼠标图层调为最高层,高度为2 /*定时器的初始化及其设置*/ timer = timer_alloc(); timer_init(timer, &fifo_mutual, 1); timer_set(timer, 50); /*在屏幕上显示一些内存、鼠标和键盘等信息*/ sprintf(strings, "Memory has %dMB", i); displayStrings_CS(buf_bg, binfo->scrnx, 0, 48, COL8_FFFFFF,strings); layer_refresh(layer_bg, 0, 48, binfo->scrnx, 80); sprintf(strings, "free memory:%dKB",memmanage_total(memmanage) / 1024); displayStrings_CS(buf_bg, binfo->scrnx, 120, 48, COL8_FFFFFF,strings); //用字体显示当前内存容量 layer_refresh(layer_bg, 120, 48, binfo->scrnx, 80); for(;;) { /*只有在从中断返回的缓冲区中读取数据的时候才需要禁止中断,因为如果这个时候来了中断而没有禁止的话, **有可能读脏数据,即把还没有读出的数据的给抹掉或换成别的数据 */ io_cli(); if(0 == fifo_status(&fifo_mutual)) //当前没有中断产生 { task_sleep(task_a); //如果没有需要处理的数据,就自己让自己休眠 /*上面的那个函数直接就跳转到另一个任务中去了,不过,因为每个人物的默认eflags都是开启中断的, **所以不用担心,这个任务还是能被唤醒的,耳环醒后的第一个动作就是为了以防万一先开启中断 */ io_sti(); //万一只有自己在运行的话,则无法睡眠,那么就执行hlt指令好了,这样省电嘛 } else { i = fifo_get(&fifo_mutual); io_sti(); if((keyboard_offset <= i) && (i <= keyboard_offset + 255)) //键盘数据 { sprintf(strings, "%2X", i - keyboard_offset); displayStrings_atLayer(layer_bg, 0, 0, COL8_FFFFFF, COL8_008484, strings); //由于向背景图层中添加了新东西,需要重绘各个图层 if(i < keyboard_offset + 0x54) //判断按下的字符是否可打印 { if(0 != key_table[i - keyboard_offset] && cursor_x < 144) //0对应的字符无法打印出来 { strings[0] = key_table[i - keyboard_offset]; strings[1] = 0; displayStrings_atLayer(layer_window, cursor_x, 28, COL8_000000, COL8_FFFFFF, strings); cursor_x += 8; //光标的位置随着每一个字符的输入向后移动一个字符宽度的位置即8像素 } if((keyboard_offset + 0x0e == i) && cursor_x > 8) //按下了退格键的情况,退格键的号码是0x0e { cursor_x -= 8; /*本来退格键应该只填充一个空格就行的,但是这样的话没办法刷新光标所在的那块儿区域了, **会留下光标的黑色痕迹,所以直接填充两个空格,刷新之后就不会有痕迹了 */ displayStrings_atLayer(layer_window, cursor_x, 28, COL8_000000, COL8_FFFFFF, " "); } //由于光标坐标后退了,为了及时显示它,需要立即重绘光标 drawRectangle(layer_window->buffer, layer_window->length, cursor_color, cursor_x, 28, 2, 15); layer_refresh(layer_window, cursor_x, 28, cursor_x + 8, 44); } } else if((mouse_offset <= i) && (i <= mouse_offset + 255)) //鼠标数据 { if(0 != mouse_decode(&mouse_dec, i - mouse_offset)) //只有返回值为1的时候才说明成功接收完成一次鼠标的中断 { /*显示鼠标的信息*/ sprintf(strings,"[lcr %3d,%3d]",mouse_dec.x, mouse_dec.y); if(0 != (mouse_dec.btn & 0x01)) //按下了左键 { strings[1] = 'L'; layer_slide(layer_window, mCursorX - 80, mCursorY -8); //这行代码是移动窗口的 } if(0 != (mouse_dec.btn & 0x02)) //按下了右键 { strings[3] = 'R'; } if(0 != (mouse_dec.btn & 0x04)) //按下了中键 { strings[2] = 'C'; } displayStrings_atLayer(layer_bg, 0, 16, COL8_FFFFFF, COL8_008484, strings); /*鼠标的移动*/ //根据mouse_dec里存储的鼠标信息画出新的鼠标图像 mCursorX += mouse_dec.x; mCursorY += mouse_dec.y; //不能让鼠标移出画面 if(mCursorX < 0) { mCursorX = 0; } if(mCursorY < 0) { mCursorY = 0; } if(mCursorX > binfo->scrnx - 1) { mCursorX = binfo->scrnx - 1; } if(mCursorY > binfo->scrny - 1) { mCursorY = binfo->scrny - 1; } sprintf(strings, "(%3d,%3d)", mCursorX, mCursorY); displayStrings_atLayer(layer_bg, 40, 32, COL8_FFFFFF, COL8_008484, strings); layer_slide(layer_mouse, mCursorX, mCursorY); } } else if(1 == i || 0 == i) //光标闪烁定时器 { if(0 != i) //这个timer的数据为1的时候显示光标 { timer_init(timer, &fifo_mutual, 0); cursor_color = COL8_000000; } else //这个timer的数据为0的时候不显示光标 { timer_init(timer, &fifo_mutual, 1); cursor_color = COL8_FFFFFF; } timer_set(timer, 50); drawRectangle(layer_window->buffer, layer_window->length, cursor_color, cursor_x, 28, 2, 15); layer_refresh(layer_window, 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; 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[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_cons; 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); /* 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); for ( ; ; ) { io_cli(); if (0 == fifo_size(&fifo)) { task_sleep(task_a); io_sti(); } else { data = fifo_get(&fifo); io_sti(); if (256 <= data && data <= 511) { sprintf(debug_info, "%02X", data - 256); drawstring_and_refresh(back_layer, 0, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 2); if (data < (256 + 0x54)) { if (0 != s_keytable[data - 256] && cursor_x < 128) { /* normal character, show 1 character, move cursor 1 time */ debug_info[0] = s_keytable[data - 256]; debug_info[1] = 0; drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, debug_info, 1); cursor_x += 8; } } if ((256 + 0x0e) == data && cursor_x > 8) { /* backspace, recover cursor by sapce, move back cursor 1 time */ drawstring_and_refresh(win_layer, cursor_x, 28, COLOR8_000000, COLOR8_FFFFFF, " ", 1); cursor_x -= 8; } /* show cursor again */ fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= data && data <= 767) { if (0 != mouse_decode(&mdec, data - 512)) { /* show all mouse bytes code */ sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y); if (0 != (mdec.state & 0x01)) debug_info[1] = 'L'; if (0 != (mdec.state & 0x02)) debug_info[3] = 'R'; if (0 != (mdec.state & 0x04)) debug_info[2] = 'C'; drawstring_and_refresh(back_layer, 32, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 15); mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); layer_slide(mouse_layer, mouse_x, mouse_y); if (0 != (mdec.state & 0x01)) { /* down left click, move window */ layer_slide(win_layer, mouse_x - 80, mouse_y - 8); } } } else if (data <= 1) { /* timer by cursor */ if (0 != data) { timer_init(timer, &fifo, 0); cursor_c = COLOR8_000000; } else { timer_init(timer, &fifo, 1); cursor_c = COLOR8_FFFFFF; } timer_settimer(timer, 50); fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], mcursor[256], keybuf[32], mousebuf[128]; int mx, my, i; unsigned char mouse_dbuf[3], mouse_phase; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_keyboard(); init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; init_mouse_cursor8(mcursor, COL8_008484); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); sprintf(s, "(%d, %d)", mx, my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); enable_mouse(); mouse_phase = 0; for (;;) { io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_phase == 0) { if (i == 0xfa) { mouse_phase = 1; } } else if (mouse_phase == 1) { mouse_dbuf[0] = i; mouse_phase = 2; } else if (mouse_phase == 2) { mouse_dbuf[1] = i; mouse_phase = 3; } else if (mouse_phase == 3) { mouse_dbuf[2] = i; mouse_phase = 1; sprintf(s, "%02X %02X %02X", mouse_dbuf[0], mouse_dbuf[1], mouse_dbuf[2]); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 32 + 8 * 8 - 1, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, s); } } } } }
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); } 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); } 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 */ fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= data && data <= 767) { if (0 != mouse_decode(&mdec, data - 512)) { /* show all mouse bytes code */ sprintf(debug_info, "[lcr %4d %4d]", mdec.x, mdec.y); if (0 != (mdec.state & 0x01)) debug_info[1] = 'L'; if (0 != (mdec.state & 0x02)) debug_info[3] = 'R'; if (0 != (mdec.state & 0x04)) debug_info[2] = 'C'; drawstring_and_refresh(back_layer, 32, 16, COLOR8_FFFFFF, COLOR8_848484, debug_info, 15); mouse_x += mdec.x; mouse_y += mdec.y; if (mouse_x < 0) mouse_x = 0; if (mouse_y < 0) mouse_y = 0; if (mouse_x > binfo->screen_x - 1) mouse_x = binfo->screen_x - 1; if (mouse_y > binfo->screen_y - 1) mouse_y = binfo->screen_y - 1; sprintf(debug_info, "(%3d, %3d)", mouse_x, mouse_y); drawstring_and_refresh(back_layer, 0, 0, COLOR8_FFFFFF, COLOR8_848484, debug_info, 10); layer_slide(mouse_layer, mouse_x, mouse_y); if (0 != (mdec.state & 0x01)) { /* down left click, move window */ layer_slide(win_layer, mouse_x - 80, mouse_y - 8); } } } else if (data <= 1) { /* timer by cursor */ if (0 != data) { timer_init(timer, &fifo, 0); cursor_c = COLOR8_000000; } else { timer_init(timer, &fifo, 1); cursor_c = COLOR8_FFFFFF; } timer_settimer(timer, 50); fill_box8(win_layer->buf, win_layer->w_size, cursor_c, cursor_x, 28, cursor_x + 7, 43); layers_refresh(win_layer, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; struct TASK *task_a, *task_cons; struct TIMER *timer; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; init_gdtidt(); init_pic(); io_sti(); fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; *((int *) (task_cons->tss.esp + 8)) = memtotal; task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0) { if (key_to == 0) { if (cursor_x < 128) { s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { if (key_to == 0) { if (cursor_x > 8) { putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x1c) { if (key_to != 0) { fifo32_put(&task_cons->fifo, 10 + 256); } } if (i == 256 + 0x0f) { if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put(&task_cons->fifo, 2); } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; fifo32_put(&task_cons->fifo, 3); } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { key_shift |= 1; } if (i == 256 + 0x36) { key_shift |= 2; } if (i == 256 + 0xaa) { key_shift &= ~1; } if (i == 256 + 0xb6) { key_shift &= ~2; } if (i == 256 + 0x3a) { key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { keycmd_wait = -1; } if (i == 256 + 0xfe) { wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { if (mouse_decode(&mdec, i - 512) != 0) { mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { if (i != 0) { timer_init(timer, &fifo, 0); if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], mcursor[256], keybuf[32], mousebuf[128]; int mx, my, i; struct MOUSE_DEC mdec; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); init_keyboard(); init_palette(); init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; init_mouse_cursor8(mcursor, COL8_008484); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); sprintf(s, "(%d, %d)", mx, my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); enable_mouse(&mdec); for (;;) { io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { // 鼠标的3个字节都齐了,都显示出来 sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, s); // 鼠标指针移动 boxfill8(binfo->vram, binfo->scrnx, COL8_008484, mx, my, mx + 15, my + 15); /* ƒ}ƒEƒXÁ‚· */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 16) { mx = binfo->scrnx - 16; } if (my > binfo->scrny - 16) { my = binfo->scrny - 16; } sprintf(s, "(%3d, %3d)", mx, my); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 0, 79, 15); /* À•WÁ‚· */ putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, s); /* À•W‘‚ */ putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); /* ƒ}ƒEƒX•`‚ */ } } } } }
void HariMain(void) { init_gdtidt(); init_pic(); /* set interruption flag to one so that it's able to accespt interruptsion, it was cleared during set_pallete() */ io_sti(); init_palette(); struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; init_screen8(binfo->vram, binfo->scrnx, binfo->scrny); int mx, my, i; unsigned int memtotal; mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 20 - 16) / 2; /* mouse is generating way more interruption than key, therefore we bump up the buffer to 128 */ char mouse[256], buffer[40], keybuf[32], mousebuf[128]; sprintf(buffer, "(%d, %d)", mx, my); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, buffer); init_mouse_cursor8(mouse, COL8_008484); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mouse, 16); /* accept interruption from mouse and keyboard */ io_out8(PIC0_IMR, 0xf9); io_out8(PIC1_IMR, 0xef); /* initialize unbounded buffer */ fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); /* initilize keyboard and mouse*/ init_keyboard(); struct MOUSE_DEC mdec; enable_mouse(&mdec); /* initialize memory management */ struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; memtotal = memtest(0x00400000, 0xbfffffff); /* byte */ memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); sprintf(buffer, "memory %dMB free : %dKB", memtotal/(1024 * 1024), memman_total(memman)/1024); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 32, COL8_FFFFFF, buffer); /* this loop will keep looking at keybuf, if an interruption happens and keybuf is set then it prints the data */ for(;;) { io_cli(); /* use unbounded buffer */ /* check size first */ if(fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); } else { if(fifo8_status(&keyfifo) != 0) { /* i can't be -1 as we already checked size */ i = fifo8_get(&keyfifo); io_sti(); sprintf(buffer, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, buffer); } /* we handle keyboard int in higher priority */ else if(fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); /* once we have gathered all three signals, print it on screen */ if(mouse_decode(&mdec, i) != 0) { sprintf(buffer, "[lcr %04d %04d]", mdec.x, mdec.y); /* note: unless we realase a button, the mdec.btn mask will always be set and letter will alawys be captial */ if((mdec.btn & 0x01) != 0) { buffer[1] = 'L'; } if((mdec.btn & 0x02) != 0) { buffer[3] = 'R'; } if((mdec.btn & 0x04) != 0) { buffer[2] = 'C'; } boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, buffer); /* move mouse */ /* first clear mouse */ boxfill8(binfo->vram, binfo->scrnx, COL8_008484, mx, my, mx + 15, my + 15); mx += mdec.x; my += mdec.y; if(mx < 0) { mx = 0; } if(my < 0) { my = 0; } if(mx > binfo->scrnx - 16) { mx = binfo->scrnx - 16; } if(my > binfo->scrny - 16) { my = binfo->scrny - 16; } sprintf(buffer, "(%3d, %3d)", mx, my); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 0, 79, 15); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 0, COL8_FFFFFF, buffer); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mouse, 16); } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; char s[40], keybuf[32], mousebuf[128]; int mx, my, i; unsigned int memtotal, count = 0; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; init_gdtidt(); init_pic(); io_sti(); fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); init_pit(); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); init_keyboard(); enable_mouse(&mdec); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "counter"); sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); for (;;) { sprintf(s, "%010d", timerctl.count); boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43); putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s); sheet_refresh(sht_win, 40, 28, 120, 44); io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_sti(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 16, 16, 32); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s); sheet_refresh(sht_back, 32, 16, 32 + 15 * 8, 32); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0, 79, 15); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, 80, 16); sheet_slide(sht_mouse, mx, my); } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct SHTCTL *shtctl; char s[40]; struct FIFO32 fifo, keycmd; int fifobuf[128], keycmd_buf[32]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; struct TASK *task_a, *task_cons; struct TIMER *timer; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0 }; int key_to = 0, key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ fifo32_init(&keycmd, 32, keycmd_buf, 0); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 透明色なし */ make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 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) sht_cons; task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 透明色なし */ make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); /* 最初にキーボード状態との食い違いがないように、設定しておくことにする */ fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); for (;;) { if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) { /* キーボードコントローラに送るデータがあれば、送る */ keycmd_wait = fifo32_get(&keycmd); wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x80 + 256) { /* キーコードを文字コードに変換 */ if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { /* 入力文字がアルファベット */ if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; /* 大文字を小文字に変換 */ } } if (s[0] != 0) { /* 通常文字 */ if (key_to == 0) { /* タスクAへ */ if (cursor_x < 128) { /* 一文字表示してから、カーソルを1つ進める */ s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } else { /* コンソールへ */ fifo32_put(&task_cons->fifo, s[0] + 256); } } if (i == 256 + 0x0e) { /* バックスペース */ if (key_to == 0) { /* タスクAへ */ if (cursor_x > 8) { /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } } else { /* コンソールへ */ fifo32_put(&task_cons->fifo, 8 + 256); } } if (i == 256 + 0x0f) { /* Tab */ if (key_to == 0) { key_to = 1; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 0); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 1); cursor_c = -1; /* カーソルを消す */ boxfill8(sht_win->buf, sht_win->bxsize, COL8_FFFFFF, cursor_x, 28, cursor_x + 7, 43); fifo32_put(&task_cons->fifo, 2); /* コンソールのカーソルON */ } else { key_to = 0; make_wtitle8(buf_win, sht_win->bxsize, "task_a", 1); make_wtitle8(buf_cons, sht_cons->bxsize, "console", 0); cursor_c = COL8_000000; /* カーソルを出す */ fifo32_put(&task_cons->fifo, 3); /* コンソールのカーソルOFF */ } sheet_refresh(sht_win, 0, 0, sht_win->bxsize, 21); sheet_refresh(sht_cons, 0, 0, sht_cons->bxsize, 21); } if (i == 256 + 0x2a) { /* 左シフト ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右シフト ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左シフト OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右シフト OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0xfa) { /* キーボードがデータを無事に受け取った */ keycmd_wait = -1; } if (i == 256 + 0xfe) { /* キーボードがデータを無事に受け取れなかった */ wait_KBC_sendready(); io_out8(PORT_KEYDAT, keycmd_wait); } /* カーソルの再表示 */ if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); } sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押していたら、sht_winを動かす */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &fifo, 0); /* 次は0を */ if (cursor_c >= 0) { cursor_c = COL8_000000; } } else { timer_init(timer, &fifo, 1); /* 次は1を */ if (cursor_c >= 0) { cursor_c = COL8_FFFFFF; } } timer_settime(timer, 50); if (cursor_c >= 0) { boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; init_gdtidt(); init_pic(); io_sti(); fifo32_init(&fifo, 128, fifobuf); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); io_out8(PIC1_IMR, 0xef); timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "window"); make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB" , memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <=i && i <= 511) { sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x54 + 256) { if (keytable[i - 256] != 0 && cursor_x < 144) { s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x , 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { if (mouse_decode(&mdec, i - 512) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i == 10) { putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); } else if (i == 3) { putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i <= 1) { if (i != 0) { timer_init(timer3, &fifo, 0); cursor_c = COL8_000000; } else { timer_init(timer3, &fifo, 1); cursor_c = COL8_FFFFFF; } timer_settime(timer3, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; struct SHTCTL *shtctl; char s[40]; int fifobuf[128]; int mx, my, i, cursor_x, cursor_c; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_cons; struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_cons; struct TASK *task_a, *task_cons; struct TIMER *timer; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf, 0); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); task_a = task_init(memman); fifo.task = task_a; task_run(task_a, 1, 2); /* sht_back */ sht_back = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); /* sht_cons */ sht_cons = sheet_alloc(shtctl); buf_cons = (unsigned char *) memman_alloc_4k(memman, 256 * 165); sheet_setbuf(sht_cons, buf_cons, 256, 165, -1); /* 透明色なし */ make_window8(buf_cons, 256, 165, "console", 0); make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000); task_cons = task_alloc(); task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8; task_cons->tss.eip = (int) &console_task; task_cons->tss.es = 1 * 8; task_cons->tss.cs = 2 * 8; task_cons->tss.ss = 1 * 8; task_cons->tss.ds = 1 * 8; task_cons->tss.fs = 1 * 8; task_cons->tss.gs = 1 * 8; *((int *) (task_cons->tss.esp + 4)) = (int) sht_cons; task_run(task_cons, 2, 2); /* level=2, priority=2 */ /* sht_win */ sht_win = sheet_alloc(shtctl); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_win, buf_win, 144, 52, -1); /* 透明色なし */ make_window8(buf_win, 144, 52, "task_a", 1); make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); /* sht_mouse */ sht_mouse = sheet_alloc(shtctl); sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); init_mouse_cursor8(buf_mouse, 99); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_back, 0, 0); sheet_slide(sht_cons, 32, 4); sheet_slide(sht_win, 64, 56); sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_cons, 1); sheet_updown(sht_win, 2); sheet_updown(sht_mouse, 3); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { task_sleep(task_a); io_sti(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x54 + 256) { if (keytable[i - 256] != 0 && cursor_x < 128) { /* 通常文字 */ /* 一文字表示してから、カーソルを1つ進める */ s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { /* バックスペース */ /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } /* カーソルの再表示 */ boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押していたら、sht_winを動かす */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer, &fifo, 0); /* 次は0を */ cursor_c = COL8_000000; } else { timer_init(timer, &fifo, 1); /* 次は1を */ cursor_c = COL8_FFFFFF; } timer_settime(timer, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { BOOTINFO_t *binfo; int mx, my, i; unsigned int memsize, count = 0; char s[40], keybuf[32], mousebuf[128]; MOUSE_DEC_t mdec; MEMMAN_t * memman = (MEMMAN_t*) MEMMAN_ADDR; // os is nubility... SHTCTL_t *shtctl; SHEET_t *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; binfo = (BOOTINFO_t *)BOOTINFO_ENTRY; fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); // init programmable interrupt controller init_gdtidt(); init_pic(); io_sti(); // 开启中断 // init fifo buffer // ...... io_out8(PIC0_IMR, 0xf9); /* PIC1‚ƃL[ƒ{[ƒh‚ð‹–‰Â(11111001) 设置PIC0 中断mask */ io_out8(PIC1_IMR, 0xef); /* ƒ}ƒEƒX‚ð‹–‰Â(11101111) 设置PIC1 中断mask */ init_keyboard(); // 初始化键盘控制芯片中的鼠标控制器 init_palette(); enable_mouse(&mdec); // 通知开启鼠标中断信息产生 // init memory manager memsize = memtest(0x00000000, 0xc0000000); memman_init(memman); //memman_free(memman, 0x00001000, 0x0009e000); // 0x00000ff0 - 0x00000ffb 是 BOOTINFO_ENTRY memman_free(memman, 0x00001000, 0x0009f000); // 书上是用的 0x00001000-0x0009efff, 但是 0x00100000(1MB) 之前就没有被使用的区域了 memman_free(memman, 0x00400000, memsize - 0x00400000); // init sheet controller shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *)memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); // -1 no invisable color sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // 99 is the invisable color sheet_setbuf(sht_win, buf_win, 160, 52, -1); init_screen8(buf_back, binfo->scrnx, binfo->scrny); mx = my = 100; init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 68, "counter"); sheet_slide(sht_back, 0, 0); sheet_slide(sht_win, 80, 72); mx = (binfo->scrnx - 16) / 2; my = (binfo->scrny - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); //putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); // static char font_A[16] = { // 0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24, // 0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00 // }; // putfont8(binfo->vram, binfo->scrnx, 8, 8, COL8_0000FF, hankaku+'A'*16); // putfonts8_asc(binfo->vram, binfo->scrnx, 16, 8, COL8_0000FF, "BC 123"); // putfonts8_asc(binfo->vram, binfo->scrnx, 31, 31, COL8_000000, "EasyOS."); // putfonts8_asc(binfo->vram, binfo->scrnx, 30, 30, COL8_FFFFFF, "EasyOS."); //memsize = memtest(0x00400000, 0xbfffffff) / (1024*1024); sprintf(s, "memory %uMB free %uKB %dx%d", memsize/(1024*1024), memman_total(memman)/1024, binfo->scrnx, binfo->scrny); putfonts8_asc(buf_back, binfo->scrnx, 0, 32, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, binfo->scrnx, 48); for (;;) { count++; sprintf(s, "%010d", count); boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43); putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s); sheet_refresh(sht_win, 40, 28, 120, 44); io_cli(); if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_sti(); } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(buf_back, binfo->scrnx, 0, 16, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 16, 16, 32); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); if (mouse_decode(&mdec, i) != 0) { sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } boxfill8(buf_back, binfo->scrnx, COL8_008484, 32, 16, 32 + 15 * 8 - 1, 31); putfonts8_asc(buf_back, binfo->scrnx, 32, 16, COL8_FFFFFF, s); sheet_refresh(sht_back, 32, 16, 32 + 15 * 8, 32); //boxfill8(buf_mouse, binfo->scrnx, COL8_008484, mx, my, mx + 15, my + 15); // hide mouse mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); boxfill8(buf_back, binfo->scrnx, COL8_008484, 0, 0, 79, 15); putfonts8_asc(buf_back, binfo->scrnx, 0, 0, COL8_FFFFFF, s); sheet_refresh(sht_back, 0, 0, 80, 16); //putblock8_8(buf_mouse, binfo->scrnx, 16, 16, mx, my, mcursor, 16); // show new position of mouse sheet_slide(sht_mouse, mx, my); } } } } fin: io_hlt(); goto fin; }
void HariMain(void) { struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; struct FIFO32 fifo; char s[40]; int fifobuf[128]; struct TIMER *timer, *timer2, *timer3; int mx, my, i, cursor_x, cursor_c, task_b_esp; unsigned int memtotal; struct MOUSE_DEC mdec; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse, *sht_win; unsigned char *buf_back, buf_mouse[256], *buf_win; static char keytable[0x54] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.' }; struct TSS32 tss_a, tss_b; struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT; init_gdtidt(); init_pic(); io_sti(); /* IDT/PICの初期化が終わったのでCPUの割り込み禁止を解除 */ fifo32_init(&fifo, 128, fifobuf); init_pit(); init_keyboard(&fifo, 256); enable_mouse(&fifo, 512, &mdec); io_out8(PIC0_IMR, 0xf8); /* PITとPIC1とキーボードを許可(11111000) */ io_out8(PIC1_IMR, 0xef); /* マウスを許可(11101111) */ timer = timer_alloc(); timer_init(timer, &fifo, 10); timer_settime(timer, 1000); timer2 = timer_alloc(); timer_init(timer2, &fifo, 3); timer_settime(timer2, 300); timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */ memman_free(memman, 0x00400000, memtotal - 0x00400000); init_palette(); shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); sht_win = sheet_alloc(shtctl); buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny); buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52); sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 透明色なし */ sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); sheet_setbuf(sht_win, buf_win, 160, 52, -1); /* 透明色なし */ init_screen8(buf_back, binfo->scrnx, binfo->scrny); init_mouse_cursor8(buf_mouse, 99); make_window8(buf_win, 160, 52, "window"); make_textbox8(sht_win, 8, 28, 144, 16, COL8_FFFFFF); cursor_x = 8; cursor_c = COL8_FFFFFF; sheet_slide(sht_back, 0, 0); mx = (binfo->scrnx - 16) / 2; /* 画面中央になるように座標計算 */ my = (binfo->scrny - 28 - 16) / 2; sheet_slide(sht_mouse, mx, my); sheet_slide(sht_win, 80, 72); sheet_updown(sht_back, 0); sheet_updown(sht_win, 1); sheet_updown(sht_mouse, 2); sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sprintf(s, "memory %dMB free : %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024); putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40); tss_a.ldtr = 0; tss_a.iomap = 0x40000000; tss_b.ldtr = 0; tss_b.iomap = 0x40000000; set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32); set_segmdesc(gdt + 4, 103, (int) &tss_b, AR_TSS32); load_tr(3 * 8); task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024; tss_b.eip = (int) &task_b_main; tss_b.eflags = 0x00000202; /* 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; for (;;) { io_cli(); if (fifo32_status(&fifo) == 0) { io_stihlt(); } else { i = fifo32_get(&fifo); io_sti(); if (256 <= i && i <= 511) { /* キーボードデータ */ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x54 + 256) { if (keytable[i - 256] != 0 && cursor_x < 144) { /* 通常文字 */ /* 一文字表示してから、カーソルを1つ進める */ s[0] = keytable[i - 256]; s[1] = 0; putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s, 1); cursor_x += 8; } } if (i == 256 + 0x0e && cursor_x > 8) { /* バックスペース */ /* カーソルをスペースで消してから、カーソルを1つ戻す */ putfonts8_asc_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ", 1); cursor_x -= 8; } /* カーソルの再表示 */ boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } else if (512 <= i && i <= 767) { /* マウスデータ */ if (mouse_decode(&mdec, i - 512) != 0) { /* データが3バイト揃ったので表示 */ sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y); if ((mdec.btn & 0x01) != 0) { s[1] = 'L'; } if ((mdec.btn & 0x02) != 0) { s[3] = 'R'; } if ((mdec.btn & 0x04) != 0) { s[2] = 'C'; } putfonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15); /* マウスカーソルの移動 */ mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (my < 0) { my = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } sprintf(s, "(%3d, %3d)", mx, my); putfonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide(sht_mouse, mx, my); if ((mdec.btn & 0x01) != 0) { /* 左ボタンを押していたら、sht_winを動かす */ sheet_slide(sht_win, mx - 80, my - 8); } } } else if (i == 10) { /* 10秒タイマ */ putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7); taskswitch4(); } else if (i == 3) { /* 3秒タイマ */ putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6); } else if (i <= 1) { /* カーソル用タイマ */ if (i != 0) { timer_init(timer3, &fifo, 0); /* 次は0を */ cursor_c = COL8_000000; } else { timer_init(timer3, &fifo, 1); /* 次は1を */ cursor_c = COL8_FFFFFF; } timer_settime(timer3, 50); boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43); sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44); } } } }
void HariMain(void) { BOOTINFO_t *binfo; char mcursor[16*16]; int mx, my, i; extern char hankaku[4096]; char s[40], keybuf[32], mousebuf[128]; binfo = (BOOTINFO_t *)BOOTINFO_ENTRY; fifo8_init(&keyfifo, 32, keybuf); fifo8_init(&mousefifo, 128, mousebuf); // init programmable interrupt controller init_gdtidt(); init_pic(); io_sti(); // 开启中断 // init fifo buffer // ...... io_out8(PIC0_IMR, 0xf9); /* (11111001) 设置PIC0 中断mask , 打开irq1 */ io_out8(PIC1_IMR, 0xef); /* (11101111) 设置PIC1 中断mask , 打开irq12 */ init_keyboard(); // 初始化键盘控制芯片中的鼠标控制器 init_palette(); init_screen(binfo->vram, binfo->scrnx, binfo->scrny); // static char font_A[16] = { // 0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24, // 0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00 // }; putfont8(binfo->vram, binfo->scrnx, 8, 8, COL8_0000FF, hankaku+'A'*16); putfonts8_asc(binfo->vram, binfo->scrnx, 16, 8, COL8_0000FF, "BC 123"); putfonts8_asc(binfo->vram, binfo->scrnx, 31, 31, COL8_000000, "EasyOS."); putfonts8_asc(binfo->vram, binfo->scrnx, 30, 30, COL8_FFFFFF, "EasyOS."); mx = my = 100; init_mouse_cursor8(mcursor, COL8_008484); putblock8_8(binfo->vram, binfo->scrnx, 16, 16, mx, my, mcursor, 16); enable_mouse(); // 通知开启鼠标中断信息产生 for (;;) { io_cli(); // 屏蔽中断 if (fifo8_status(&keyfifo) + fifo8_status(&mousefifo) == 0) { io_stihlt(); // 恢复中断并挂起 } else { if (fifo8_status(&keyfifo) != 0) { i = fifo8_get(&keyfifo); io_sti(); sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 0, 16, 15, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 0, 16, COL8_FFFFFF, s); } else if (fifo8_status(&mousefifo) != 0) { i = fifo8_get(&mousefifo); io_sti(); sprintf(s, "%02X", i); boxfill8(binfo->vram, binfo->scrnx, COL8_008484, 32, 16, 47, 31); putfonts8_asc(binfo->vram, binfo->scrnx, 32, 16, COL8_FFFFFF, s); } } } fin: io_hlt(); goto fin; }