void close_console(struct SHEET *sht) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct TASK *task = sht->task; memman_free_4k(memman, (int) sht->buf, 256 * 165); sheet_free(sht); close_constask(task); return; }
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax) { struct TASK *task = task_now(); int ds_base = task->ds_base; struct CONSOLE *cons = task->cons; struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4); struct SHEET *sht; struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec); int *reg = &eax + 1; /* 返し値 */ int i; struct FILEINFO *finfo; struct FILEHANDLE *fh; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; unsigned char *p; int *memtotal = (int *) *((int *) 0x0fe2); struct TASK *task2; struct FIFO32 *fifo; struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; int bpp = binfo->vmode; unsigned short *sp; unsigned int *ip; struct PICTURE *pic; if (edx == 1) { cons_putchar(cons, eax & 0xff, 1); } else if (edx == 2) { cons_putstr0(cons, (char *) ebx + ds_base); } else if (edx == 3) { cons_putstr1(cons, (char *) ebx + ds_base, ecx); } else if (edx == 4) { return &(task->tss.esp0); } else if (edx == 5) { sht = sheet_alloc(shtctl); sht->task = task; sht->flags |= 0x10; sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax); make_window((unsigned int *) ((char *) ebx + ds_base), esi, edi, (char *) ecx + ds_base, 0, 0); sht->windowname = (char *) ecx + ds_base; sheet_slide(sht, ((shtctl->xsize - esi) / 2) & ~3, (shtctl->ysize - edi) / 2); keywin_off(shtctl->sheets[shtctl->top - 2]); sheet_updown(sht, shtctl->top - 1); keywin_on(sht); fifo32_put(sys_fifo, 0x4000); /* key_win変更要求 */ reg[7] = (int) sht; } else if (edx == 6) { sht = (struct SHEET *) (ebx & 0xfffffffe); putfonts((unsigned int *) (sht->buf), sht->bxsize, esi, edi, get_color(1, eax), (char *) ebp + ds_base); if ((ebx & 1) == 0) { sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16); } } else if (edx == 7) { sht = (struct SHEET *) (ebx & 0xfffffffe); boxfill((unsigned int *) (sht->buf), sht->bxsize, get_color(1, ebp), eax, ecx, esi, edi); if ((ebx & 1) == 0) { sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); } } else if (edx == 8) { memman_init((struct MEMMAN *) (ebx + ds_base)); ecx &= 0xfffffff0; /* 16バイト単位にする */ memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx); } else if (edx == 9) { ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */ reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx); } else if (edx == 10) { ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */ memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx); } else if (edx == 11) { sht = (struct SHEET *) (ebx & 0xfffffffe); i = get_color(1, eax); if (bpp == 8) { sht->buf[sht->bxsize * edi + esi] = get_color(bpp, i); } else if (bpp == 16) { sp = (unsigned short *) (sht->buf); sp[sht->bxsize * edi + esi] = get_color(bpp, i); } else if (bpp == 24) { ip = (unsigned int *) (sht->buf); ip[sht->bxsize * edi + esi] = get_color(bpp, i); } if ((ebx & 1) == 0) { sheet_refresh(sht, esi, edi, esi + 1, edi + 1); } } else if (edx == 12) { sht = (struct SHEET *) ebx; sheet_refresh(sht, eax, ecx, esi, edi); } else if (edx == 13) { sht = (struct SHEET *) (ebx & 0xfffffffe); hrb_api_linewin(sht, eax, ecx, esi, edi, get_color(1, ebp)); if ((ebx & 1) == 0) { if (eax > esi) { i = eax; eax = esi; esi = i; } if (ecx > edi) { i = ecx; ecx = edi; edi = i; } sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); } } else if (edx == 14) { sheet_free((struct SHEET *) ebx); keywin_on(shtctl->sheets[shtctl->top - 2]); } else if (edx == 15) { for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { if (eax != 0) { /* fifoカラッポ */ task_sleep(task); /* 寝て待つ */ } else { io_sti(); reg[7] = -1; return 0; } } i = fifo32_get(&task->fifo); io_sti(); if (i <= 1) { /* カーソル用 */ /* アプリ実行中はカーソルが出ないので、いつも次は表示用の1を注文 */ timer_init(cons->timer, &task->fifo, 1); timer_settime(cons->timer, 50); } if (i == 2) { /* カーソルON */ cons->curcol = 0xffffff; } if (i == 3) { /* カーソルOFF */ cons->curcol = -1; } if (i == 4) { timer_cancel(cons->timer); io_cli(); fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024); /* 2024〜2279 */ cons->sht = 0; io_sti(); } if (i >= 256) { reg[7] = i - 256; return 0; } } } else if (edx == 16) { reg[7] = (int) timer_alloc(); ((struct TIMER *) reg[7])->flags2 = 1; /* 自動キャンセル有効 */ } else if (edx == 17) { timer_init((struct TIMER *) ebx, &task->fifo, eax + 256); } else if (edx == 18) { timer_settime((struct TIMER *) ebx, eax); } else if (edx == 19) { timer_free((struct TIMER *) ebx); } else if (edx == 20) { if (eax == 0) { /* 音を消す */ i = io_in8(0x61); io_out8(0x61, i & 0x0d); } else { i = 1193180000 / eax; io_out8(0x43, 0xb6); io_out8(0x42, i & 0xff); io_out8(0x42, i >> 8); i = io_in8(0x61); io_out8(0x61, (i | 0x03) & 0x0f); } } else if (edx == 21) {
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct FILEINFO *finfo; char name[18], *p, *q; struct TASK *task = task_now(); int i, segsiz, datsiz, esp, dathrb; struct SHTCTL *shtctl; struct SHEET *sht; /* コマンドラインからファイル名を生成 */ for (i = 0; i < 13; i++) { if (cmdline[i] <= ' ') { break; } name[i] = cmdline[i]; } name[i] = 0; /* とりあえずファイル名の後ろを0にする */ /* ファイルを探す */ finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); if (finfo == 0 && name[i - 1] != '.') { /* 見つからなかったので後ろに".HRB"をつけてもう一度探してみる */ name[i ] = '.'; name[i + 1] = 'H'; name[i + 2] = 'R'; name[i + 3] = 'B'; name[i + 4] = 0; finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); } if (finfo != 0) { /* ファイルが見つかった場合 */ p = (char *) memman_alloc_4k(memman, finfo->size); file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00)); if (finfo->size >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00) { segsiz = *((int *) (p + 0x0000)); esp = *((int *) (p + 0x000c)); datsiz = *((int *) (p + 0x0010)); dathrb = *((int *) (p + 0x0014)); q = (char *) memman_alloc_4k(memman, segsiz); task->ds_base = (int) q; set_segmdesc(task->ldt + 0, finfo->size - 1, (int) p, AR_CODE32_ER + 0x60); set_segmdesc(task->ldt + 1, segsiz - 1, (int) q, AR_DATA32_RW + 0x60); for (i = 0; i < datsiz; i++) { q[esp + i] = p[dathrb + i]; } start_app(0x1b, 0 * 8 + 4, esp, 1 * 8 + 4, &(task->tss.esp0)); shtctl = (struct SHTCTL *) *((int *) 0x0fe4); for (i = 0; i < MAX_SHEETS; i++) { sht = &(shtctl->sheets0[i]); if ((sht->flags & 0x11) == 0x11 && sht->task == task) { /* アプリが開きっぱなしにした下じきを発見 */ sheet_free(sht); /* 閉じる */ } } for (i = 0; i < 8; i++) { /* クローズしてないファイルをクローズ */ if (task->fhandle[i].buf != 0) { memman_free_4k(memman, (int) task->fhandle[i].buf, task->fhandle[i].size); task->fhandle[i].buf = 0; } } timer_cancelall(&task->fifo); memman_free_4k(memman, (int) q, segsiz); } else { cons_putstr0(cons, ".hrb file format error.\n"); } memman_free_4k(memman, (int) p, finfo->size); cons_newline(cons); return 1; } /* ファイルが見つからなかった場合 */ return 0; }
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax) { struct TASK *task = task_now(); int ds_base = task->ds_base; struct CONSOLE *cons = task->cons; struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4); struct SHEET *sht; struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec); int *reg = &eax + 1; /* eaxの次の番地 */ /* 保存のためのPUSHADを強引に書き換える */ /* reg[0] : EDI, reg[1] : ESI, reg[2] : EBP, reg[3] : ESP */ /* reg[4] : EBX, reg[5] : EDX, reg[6] : ECX, reg[7] : EAX */ int i; struct FILEINFO *finfo; struct FILEHANDLE *fh; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; if (edx == 1) { cons_putchar(cons, eax & 0xff, 1); } else if (edx == 2) { cons_putstr0(cons, (char *) ebx + ds_base); } else if (edx == 3) { cons_putstr1(cons, (char *) ebx + ds_base, ecx); } else if (edx == 4) { return &(task->tss.esp0); } else if (edx == 5) { sht = sheet_alloc(shtctl); sht->task = task; sht->flags |= 0x10; sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax); make_window8((char *) ebx + ds_base, esi, edi, (char *) ecx + ds_base, 0); sheet_slide(sht, ((shtctl->xsize - esi) / 2) & ~3, (shtctl->ysize - edi) / 2); sheet_updown(sht, shtctl->top); /* 今のマウスと同じ高さになるように指定: マウスはこの上になる */ reg[7] = (int) sht; } else if (edx == 6) { sht = (struct SHEET *) (ebx & 0xfffffffe); putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base); if ((ebx & 1) == 0) { sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16); } } else if (edx == 7) { sht = (struct SHEET *) (ebx & 0xfffffffe); boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi); if ((ebx & 1) == 0) { sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); } } else if (edx == 8) { memman_init((struct MEMMAN *) (ebx + ds_base)); ecx &= 0xfffffff0; /* 16バイト単位に */ memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx); } else if (edx == 9) { ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */ reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx); } else if (edx == 10) { ecx = (ecx + 0x0f) & 0xfffffff0; /* 16バイト単位に切り上げ */ memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx); } else if (edx == 11) { sht = (struct SHEET *) (ebx & 0xfffffffe); sht->buf[sht->bxsize * edi + esi] = eax; if ((ebx & 1) == 0) { sheet_refresh(sht, esi, edi, esi + 1, edi + 1); } } else if (edx == 12) { sht = (struct SHEET *) ebx; sheet_refresh(sht, eax, ecx, esi, edi); } else if (edx == 13) { sht = (struct SHEET *) (ebx & 0xfffffffe); hrb_api_linewin(sht, eax, ecx, esi, edi, ebp); if ((ebx & 1) == 0) { sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); } } else if (edx == 14) { sheet_free((struct SHEET *) ebx); } else if (edx == 15) { for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { if (eax != 0) { task_sleep(task); /* FIFOが空なので寝て待つ */ } else { io_sti(); reg[7] = -1; return 0; } } i = fifo32_get(&task->fifo); io_sti(); if (i <= 1 && cons->sht != 0) { /* カーソル用タイマ */ /* アプリ実行中はカーソルが出ないので、いつも次は表示用の1を注文しておく */ timer_init(cons->timer, &task->fifo, 1); /* 次は1を */ timer_settime(cons->timer, 50); } if (i == 2) { /* カーソルON */ cons->cur_c = COL8_FFFFFF; } if (i == 3) { /* カーソルOFF */ cons->cur_c = -1; } if (i == 4) { /* コンソールだけを閉じる */ timer_cancel(cons->timer); io_cli(); fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024); /* 2024〜2279 */ cons->sht = 0; io_sti(); } if (i >= 256) { /* キーボードデータ(タスクA経由)など */ reg[7] = i - 256; return 0; } } } else if (edx == 16) { reg[7] = (int) timer_alloc(); ((struct TIMER *) reg[7])->flags2 = 1; /* 自動キャンセル有効 */ } else if (edx == 17) { timer_init((struct TIMER *) ebx, &task->fifo, eax + 256); } else if (edx == 18) { timer_settime((struct TIMER *) ebx, eax); } else if (edx == 19) { timer_free((struct TIMER *) ebx); } else if (edx == 20) { if (eax == 0) { i = io_in8(0x61); io_out8(0x61, i & 0x0d); } else { i = 1193180000 / eax; io_out8(0x43, 0xb6); io_out8(0x42, i & 0xff); io_out8(0x42, i >> 8); i = io_in8(0x61); io_out8(0x61, (i | 0x03) & 0x0f); } } else if (edx == 21) {
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の読み込み */ nihongo = (unsigned char *) memman_alloc_4k(memman, 16 * 256 + 32 * 94 * 47); 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) { file_loadfile(finfo->clustno, finfo->size, nihongo, fat, (char *) (ADR_DISKIMG + 0x003e00)); } else { 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) { /* 通常文字、バックスペース、Enter */ fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f && key_win != 0) { /* Tab */ keywin_off(key_win); j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on(key_win); } if (i == 256 + 0x2a) { /* 左シフト ON */ key_shift |= 1; } if (i == 256 + 0x36) { /* 右シフト ON */ key_shift |= 2; } if (i == 256 + 0xaa) { /* 左シフト OFF */ key_shift &= ~1; } if (i == 256 + 0xb6) { /* 右シフト OFF */ key_shift &= ~2; } if (i == 256 + 0x3a) { /* CapsLock */ key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { /* NumLock */ key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { /* ScrollLock */ key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */ task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { cons_putstr0(task->cons, "\nBreak(key) :\n"); io_cli(); /* 強制終了処理中にタスクが変わると困るから */ task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti(); 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) { /* マウスカーソルの移動 */ 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) { int mmx = -1, mmy = -1, mmx2 = 0; struct SHEET *sht = 0, *key_win; struct BOOTINFO *binfo = (struct BOOTINFO *)0x0ff0; int xsize = (*binfo).scrnx; int ysize = (*binfo).scrny; int mx = xsize/2; int my = ysize/2; int new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0; int fifobuf[128], keycmd_buf[32], *cons_fifo[2]; struct MOUSE_DEC mdec; unsigned char s[32]; unsigned int memtotal; struct MEMMAN *memman = (struct MEMMAN *)MEMMAN_ADDR; int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1; struct SHTCTL *shtctl; struct SHEET *sht_back, *sht_mouse; unsigned char *buf_back, buf_mouse[256], *buf_cons[2]; struct TIMER *timer; struct FIFO32 fifo, keycmd; struct TASK *task_a, *task_cons[2]; static char keytable0[0x80] = { 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0 }; static char keytable1[0x80] = { 0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', '|', 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 }; extern char hankaku[4096]; init_gdtidt (); init_pic (); io_sti (); fifo32_init(&fifo, 32, fifobuf, 0); fifo32_init(&keycmd, 32, keycmd_buf, 0); init_pit(); io_out8(PIC0_IMR, 0xf8); /* Allow PIT and Keyboard (11111000) */ io_out8(PIC1_IMR, 0xef); /* Allow Mouse (11101111) */ init_keyboard (&fifo, 256); enable_mouse (&fifo, 512, &mdec); timer = timer_alloc(); timer_init(timer, &fifo, 1); timer_settime(timer, 50); memtotal = memtest(0x00400000, 0xbfffffff); memman_init (memman); memman_free (memman, 0x00001000, 0x009e000); /* 0x00001000 - 0x0009efff */ memman_free (memman, 0x00400000, memtotal - 0x00400000); init_pallete(); shtctl = shtctl_init (memman, binfo->vram, binfo->scrnx, binfo->scrny); sht_back = sheet_alloc(shtctl); sht_mouse = sheet_alloc(shtctl); buf_back = (unsigned char *)memman_alloc_4k (memman, binfo->scrnx * binfo->scrny); sheet_setbuf (sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); sheet_setbuf (sht_mouse, buf_mouse, 16, 16, 99); init_screen (buf_back, xsize, ysize); init_mouse_cursor8 (buf_mouse, 99); *((int *) 0x0fec) = (int) &fifo; //===================== // Task Settings //===================== task_a = task_init(memman); fifo.task = task_a; task_a->langmode = 0; task_run (task_a, 1, 0); /* console sheet */ key_win = open_console (shtctl, memtotal); //======================= // Sheet Setting //======================= *((int *) 0x0fe4) = (int) shtctl; sheet_slide (sht_back, 0, 0); sheet_slide (key_win, 32, 4); sheet_slide (sht_mouse, mx, my); sheet_updown (sht_back, 0); sheet_updown (key_win, 1); sheet_updown (sht_mouse, 2); sheet_refresh (sht_back, 0, 0, binfo->scrnx, 48); keywin_on (key_win); fifo32_put (&keycmd, KEYCMD_LED); fifo32_put (&keycmd, key_leds); /* Reading nihongo.fnt */ unsigned char *nihongo = (unsigned char *)memman_alloc_4k (memman, 16 * 256 + 32 * 94 * 47); int *fat = (int *)memman_alloc_4k (memman, 4 * 2880); file_readfat (fat, (unsigned char *)(ADR_DISKIMG + 0x000200)); struct FILEINFO *finfo = file_search ("nihongo.fnt", (struct FILEINFO *)(ADR_DISKIMG + 0x002600), 224); if (finfo != 0) { int i = finfo->size; nihongo = file_loadfile2 (finfo->clustno, &i, fat); } else { nihongo = (unsigned char *)memman_alloc_4k (memman, 16 * 256 + 32 * 94 * 47); for (int i = 0; i < 16 * 256; i++) { nihongo[i] = hankaku[i]; } for (int i = 16 * 256; i < 16 * 256 + 32 * 94 * 47; i++) { nihongo[i] = 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) { /* execute draw if FIFO is empty */ if (new_mx >= 0) { io_sti (); sheet_slide (sht_mouse, new_mx, new_my); new_mx = -1; } else if (new_wx != 0x7fffffff) { io_sti (); sheet_slide (sht, new_wx, new_wy); new_wx = 0x7fffffff; } else { task_sleep(task_a); io_sti(); } } else { int i = fifo32_get(&fifo); io_sti(); if (key_win != 0 && key_win->flags == 0) { // input Window is closed if (shtctl->top == 1) { // ony mouse and background key_win = 0; } else { key_win = shtctl->sheets[shtctl->top - 1]; keywin_on (key_win); } } if (256 <= i && i <= 511) { // Keyboard Data if (i < 0x80 + 256) { if (key_shift == 0) { s[0] = keytable0[i - 256]; } else { s[0] = keytable1[i - 256]; } } else { s[0] = 0; } if ('A' <= s[0] && s[0] <= 'Z') { if (((key_leds & 4) == 0 && key_shift == 0) || ((key_leds & 4) != 0 && key_shift != 0)) { s[0] += 0x20; } } if (s[0] != 0 && key_win != 0) { fifo32_put(&key_win->task->fifo, s[0] + 256); } if (i == 256 + 0x0f && key_win != 0) { // Tab keywin_off (key_win); int j = key_win->height - 1; if (j == 0) { j = shtctl->top - 1; } key_win = shtctl->sheets[j]; keywin_on (key_win); } if (i == 256 + 0x2a) { // Left Shift ON key_shift |= 1; } if (i == 256 + 0x36) { // Right Shift ON key_shift |= 2; } if (i == 256 + 0xaa) { // Left Shift OFF key_shift &= ~1; } if (i == 256 + 0xb6) { // Right Shift ON key_shift &= ~2; } if (i == 256 + 0x3a) { // CapsLock key_leds ^= 4; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x45) { // NumLock key_leds ^= 2; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x46) { // ScrollLock key_leds ^= 1; fifo32_put(&keycmd, KEYCMD_LED); fifo32_put(&keycmd, key_leds); } if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { struct TASK *task = key_win->task; if (task != 0 && task->tss.ss0 != 0) { /* Shift+F1 */ cons_putstr0 (task->cons, "\nBreak(key) : \n"); io_cli (); task->tss.eax = (int) &(task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti (); 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) { // KeyBoard receive Data keycmd_wait = -1; } if (i == 256 + 0xfe) { // KeyBoard failed to receive Data wait_KBC_sendready (); io_out8(PORT_KEYDAT, keycmd_wait); } } else if (512 <= i && i <= 767) { // Mouse Data if (mouse_decode(&mdec, i-512) != 0) { mx += mdec.x; my += mdec.y; if (mx < 0) { mx = 0; } if (mx > binfo->scrnx - 1) { mx = binfo->scrnx - 1; } if (my < 0) { my = 0; } if (my > binfo->scrny - 1) { my = binfo->scrny - 1; } // sprintf(s, "(%d, %d)", mx, my); // putfonts8_asc_sht (sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10); sheet_slide (sht_mouse, mx, my); new_mx = mx; new_my = my; if ((mdec.btn & 0x01) != 0) { /* Left Mouse Button is down */ if (mmx < 0) { /* Normal Mode */ for (int j = shtctl->top - 1; j > 0; j--) { sht = shtctl->sheets[j]; int x = mx - sht->vx0; int y = my - sht->vy0; if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) { if (sht->buf[y * sht->bxsize + x] != sht->col_inv) { sheet_updown (sht, shtctl->top - 1); if (sht != key_win) { keywin_off (key_win); key_win = sht; keywin_on (key_win); } if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) { mmx = mx; mmy = my; mmx2 = sht->vx0; new_wy = sht->vy0; } if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) { // "X" button is clicked if ((sht->flags & 0x10) != 0) { // Window is made by Application? struct TASK *task = sht->task; cons_putstr0 (task->cons, "\nBreak(mouse) :\n"); io_cli (); task->tss.eax = (int) & (task->tss.esp0); task->tss.eip = (int) asm_end_app; io_sti (); task_run (task, -1, 0); } else { struct TASK *task = sht->task; sheet_updown (sht, -1); keywin_off (key_win); key_win = shtctl->sheets[shtctl->top-1]; keywin_off (key_win); io_cli (); fifo32_put (&task->fifo, 4); io_sti (); } } break; } } } } else { // Moving window mode int x = mx - mmx; int y = my - mmy; new_wx = (mmx2 + x + 2) & ~3; new_wy = new_wy + y; mmy = my; } } else { mmx = -1; if (new_wx != 0x7fffffff) { sheet_slide (sht, new_wx, new_wy); new_wx = 0x7fffffff; } } } } else if (768 <= i && i <= 1023) { close_console (shtctl->sheets0 + (i - 768)); } else if (1024 <= i && i < 2023) { close_constask (taskctl->tasks0 + (i - 1024)); } else if (2024 <= i && i <= 2279) { struct SHEET *sht2 = shtctl->sheets0 + (i - 2024); memman_free_4k (memman, (int)sht2->buf, 256 * 165); sheet_free (sht2); } } } }
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); } } } }
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax) { struct TASK *task = task_now(); int ds_base = task->ds_base; struct CONSOLE *cons = task->cons; struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4); struct SHEET *sht; struct FIFO32 *sys_fifo = (struct FIFO32 *) *((int *) 0x0fec); int *reg = &eax + 1; /* eax�� ���� ���� */ /* ������ ���� PUSHAD�� ������ ���� */ /* reg[0] : EDI, reg[1] : ESI, reg[2] : EBP, reg[3] : ESP */ /* reg[4] : EBX, reg[5] : EDX, reg[6] : ECX, reg[7] : EAX */ int i; struct FILEINFO *finfo; struct FILEHANDLE *fh; struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; if (edx == 1) { // api_putchar cons_putchar(cons, eax & 0xff, 1); } else if (edx == 2) { // api_putstr0 cons_putstr0(cons, (char *) ebx + ds_base); } else if (edx == 3) { // api_putstr1 cons_putstr1(cons, (char *) ebx + ds_base, ecx); } else if (edx == 4) { // api_end return &(task->tss.esp0); } else if (edx == 5) { // api_openwin sht = sheet_alloc(shtctl); sht->task = task; sht->flags |= 0x10; sheet_setbuf(sht, (char *) ebx + ds_base, esi, edi, eax); make_window8((char *) ebx + ds_base, esi, edi, (char *) ecx + ds_base, 0); sheet_slide(sht, ((shtctl->xsize - esi) / 2) & ~3, (shtctl->ysize - edi) / 2); sheet_updown(sht, shtctl->top); /* ������ ���콺�� ���� ���̰� �ǵ��� ������ ���콺�� �� ���� �ȴ� */ reg[7] = (int) sht; } else if (edx == 6) { // api_putstrwin sht = (struct SHEET *) (ebx & 0xfffffffe); putfonts8_asc(sht->buf, sht->bxsize, esi, edi, eax, (char *) ebp + ds_base); if ((ebx & 1) == 0) { sheet_refresh(sht, esi, edi, esi + ecx * 8, edi + 16); } } else if (edx == 7) { // api_boxfilwin sht = (struct SHEET *) (ebx & 0xfffffffe); boxfill8(sht->buf, sht->bxsize, ebp, eax, ecx, esi, edi); if ((ebx & 1) == 0) { sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); } } else if (edx == 8) { // api_initmalloc memman_init((struct MEMMAN *) (ebx + ds_base)); ecx &= 0xfffffff0; /* 16����Ʈ ������ */ memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx); } else if (edx == 9) { // api_malloc ecx = (ecx + 0x0f) & 0xfffffff0; /* 16����Ʈ ������ ���� */ reg[7] = memman_alloc((struct MEMMAN *) (ebx + ds_base), ecx); } else if (edx == 10) { // api_free ecx = (ecx + 0x0f) & 0xfffffff0; /* 16����Ʈ ������ ���� */ memman_free((struct MEMMAN *) (ebx + ds_base), eax, ecx); } else if (edx == 11) { // api_point sht = (struct SHEET *) (ebx & 0xfffffffe); sht->buf[sht->bxsize * edi + esi] = eax; if ((ebx & 1) == 0) { sheet_refresh(sht, esi, edi, esi + 1, edi + 1); } } else if (edx == 12) { // api_refreshwin sht = (struct SHEET *) ebx; sheet_refresh(sht, eax, ecx, esi, edi); } else if (edx == 13) { // api_linewin sht = (struct SHEET *) (ebx & 0xfffffffe); hrb_api_linewin(sht, eax, ecx, esi, edi, ebp); if ((ebx & 1) == 0) { if (eax > esi) { i = eax; eax = esi; esi = i; } if (ecx > edi) { i = ecx; ecx = edi; edi = i; } sheet_refresh(sht, eax, ecx, esi + 1, edi + 1); } } else if (edx == 14) { // api_closewin sheet_free((struct SHEET *) ebx); } else if (edx == 15) { // api_getkey for (;;) { io_cli(); if (fifo32_status(&task->fifo) == 0) { if (eax != 0) { task_sleep(task); /* FIFO�� ������Ƿ� ��ٸ��� */ } else { io_sti(); reg[7] = -1; return 0; } } i = fifo32_get(&task->fifo); io_sti(); if (i <= 1 && cons->sht != 0) { /* Ŀ���� Ÿ�̸� */ /* ���ø����̼� �������� Ŀ���� ������ �ʱ� ������, ǥ�ÿ� 1�� call */ timer_init(cons->timer, &task->fifo, 1); /* ������ 1�� */ timer_settime(cons->timer, 50); } if (i == 2) { /* Ŀ�� ON */ cons->cur_c = COL8_FFFFFF; } if (i == 3) { /* Ŀ�� OFF */ cons->cur_c = -1; } if (i == 4) { /* �ָܼ��� �ݴ´� */ timer_cancel(cons->timer); io_cli(); fifo32_put(sys_fifo, cons->sht - shtctl->sheets0 + 2024); /* 2024~2279 */ cons->sht = 0; io_sti(); } if (i >= 256) { /* Ű���� ������(�½�ũ A����) �� */ reg[7] = i - 256; return 0; } } } else if (edx == 16) { // api_alloctimer reg[7] = (int) timer_alloc(); ((struct TIMER *) reg[7])->flags2 = 1; /* �ڵ� ĵ�� ��ȿ */ } else if (edx == 17) { // api_inittimer timer_init((struct TIMER *) ebx, &task->fifo, eax + 256); } else if (edx == 18) { // api_settimer timer_settime((struct TIMER *) ebx, eax); } else if (edx == 19) { // api_freetimer timer_free((struct TIMER *) ebx); } else if (edx == 20) { // api_beep if (eax == 0) { i = io_in8(0x61); io_out8(0x61, i & 0x0d); } else { i = 1193180000 / eax; io_out8(0x43, 0xb6); io_out8(0x42, i & 0xff); io_out8(0x42, i >> 8); i = io_in8(0x61); io_out8(0x61, (i | 0x03) & 0x0f); } } else if (edx == 21) {
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline) { struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR; struct FILEINFO *finfo; char name[18], *p, *q; struct TASK *task = task_now(); int i, segsiz, datsiz, esp, dathrb, appsiz; struct SHTCTL *shtctl; struct SHEET *sht; /* Ŀ�ǵ� �������κ��� ���ϸ��� ���� */ for (i = 0; i < 13; i++) { if (cmdline[i] <= ' ') { break; } name[i] = cmdline[i]; } name[i] = 0; /* �켱 ���ϸ��� �ڸ� 0���� �Ѵ� */ /* ������ ã�´� */ finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); if (finfo == 0 && name[i - 1] != '.') { /* �߰ߵ��� �ʾұ� ������ �ڷ� ".HRB"�� �ٿ� �ѹ� �� ã�� ���� */ name[i ] = '.'; name[i + 1] = 'H'; name[i + 2] = 'R'; name[i + 3] = 'B'; name[i + 4] = 0; finfo = file_search(name, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224); } if (finfo != 0) { /* ������ �߰ߵǾ��� ��� */ appsiz = finfo->size; p = file_loadfile2(finfo->clustno, &appsiz, fat); if (appsiz >= 36 && strncmp(p + 4, "Hari", 4) == 0 && *p == 0x00) { segsiz = *((int *) (p + 0x0000)); esp = *((int *) (p + 0x000c)); datsiz = *((int *) (p + 0x0010)); dathrb = *((int *) (p + 0x0014)); q = (char *) memman_alloc_4k(memman, segsiz); task->ds_base = (int) q; set_segmdesc(task->ldt + 0, appsiz - 1, (int) p, AR_CODE32_ER + 0x60); set_segmdesc(task->ldt + 1, segsiz - 1, (int) q, AR_DATA32_RW + 0x60); for (i = 0; i < datsiz; i++) { q[esp + i] = p[dathrb + i]; } start_app(0x1b, 0 * 8 + 4, esp, 1 * 8 + 4, &(task->tss.esp0)); strcpy(task->name, "console"); shtctl = (struct SHTCTL *) *((int *) 0x0fe4); for (i = 0; i < MAX_SHEETS; i++) { sht = &(shtctl->sheets0[i]); if ((sht->flags & 0x11) == 0x11 && sht->task == task) { /* ���ø����̼� open & ���̾� �߰� */ sheet_free(sht); /* �ݴ´� */ } } for (i = 0; i < 8; i++) { /* Ŭ�ο��� ���� �ʴ� ������ Ŭ�ο��� */ if (task->fhandle[i].buf != 0) { memman_free_4k(memman, (int) task->fhandle[i].buf, task->fhandle[i].size); task->fhandle[i].buf = 0; } } timer_cancelall(&task->fifo); memman_free_4k(memman, (int) q, segsiz); task->langbyte1 = 0; } else { cons_putstr0(cons, ".hrb file format error.\n"); } memman_free_4k(memman, (int) p, appsiz); cons_newline(cons); return 1; } /* ������ �߰ߵ��� �ʾ��� ��� */ return 0; }