たなしょのメモ

日々勉強していることをつらつらと

OS作成奮闘記day40

本では28日目に突入しました。
素数アプリを作っていきます。

sosu/Makefile

APP      = sosu
STACK    = 2k
MALLOC   = 0k

include ../app_make.txt

sosu.c

#include <stdio.h>
#include "apilib.h"

#define MAX        1000

void HariMain(void)
{
    char flag[MAX], s[8];
    int i, j;
    for (i = 0; i < MAX; i++) {
        flag[i] = 0;
    }
    for (i = 2; i < MAX; i++) {
        if (flag[i] == 0) {
            /* 印がついていないので素数だ! */
            sprintf(s, "%d ", i);
            api_putstr0(s);
            for (j = i * 2; j < MAX; j += i) {
                flag[i] = 1;   /* 倍数には印をつける */
            }
        }
    }
    api_end();
}

sosu2/Makefile

APP      = sosu2
STACK    = 11k
MALLOC   = 0k

include ../app_make.txt

sosu2.c

#include <stdio.h>
#include "apilib.h"

#define MAX        10000

void HariMain(void)
{
    char flag[MAX], s[8];
    int i, j;
    for (i = 0; i < MAX; i++) {
        flag[i] = 0;
    }
    for (i = 2; i < MAX; i++) {
        if (flag[i] == 0) {
            /* 印がついていないので素数だ! */
            sprintf(s, "%d ", i);
            api_putstr0(s);
            for (j = i * 2; j < MAX; j += i) {
                flag[j] = 1;   /* 倍数には印をつける */
            }
        }
    }
    api_end();
}

sosu3/Makefile

APP      = sosu3
STACK    = 1k
MALLOC   = 42k

include ../app_make.txt

sosu3.c

#include <stdio.h>
#include "apilib.h"

#define MAX        10000

void HariMain(void)
{
    char *flag, s[8];
    int i, j;
    api_initmalloc();
    flag = api_malloc(MAX);
    for (i = 0; i < MAX; i++) {
        flag[i] = 0;
    }
    for (i = 2; i < MAX; i++) {
        if (flag[i] == 0) {
            /* 印がついていないので素数だ! */
            sprintf(s, "%d ", i);
            api_putstr0(s);
            for (j = i * 2; j < MAX; j += i) {
                flag[j] = 1;   /* 倍数には印をつける */
            }
        }
    }
    api_end();
}

Makefile

TOOLPATH = ..\..\z_tools\\

INCPATH  = ..\..\z_tools\haribote\\

MAKE     = $(TOOLPATH)make.exe -r
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
GOLIB    = $(TOOLPATH)golib00.exe
COPY     = cmd.exe /C copy
DEL      = rm -f

# default operation

default :
    $(MAKE) haribote.img

# file making rule


haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
        a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \
        winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \
        star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \
        lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \
        beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \
        sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb
    $(EDIMG)   imgin:../../z_tools/fdimg0at.tek \
        wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \
        copy from:haribote/haribote.sys to:@: \
        copy from:haribote/ipl10.nas to:@: \
        copy from:make.bat to:@: \
        copy from:a/a.hrb to:@: \
        copy from:hello3/hello3.hrb to:@: \
        copy from:hello4/hello4.hrb to:@: \
        copy from:hello5/hello5.hrb to:@: \
        copy from:winhelo/winhelo.hrb to:@: \
        copy from:winhelo2/winhelo2.hrb to:@: \
        copy from:winhelo3/winhelo3.hrb to:@: \
        copy from:star1/star1.hrb to:@: \
        copy from:stars/stars.hrb to:@: \
        copy from:stars2/stars2.hrb to:@: \
        copy from:lines/lines.hrb to:@: \
        copy from:walk/walk.hrb to:@: \
        copy from:noodle/noodle.hrb to:@: \
        copy from:beepdown/beepdown.hrb to:@: \
        copy from:color/color.hrb to:@: \
        copy from:color2/color2.hrb to:@: \
        copy from:sosu/sosu.hrb to:@: \
        copy from:sosu2/sosu2.hrb to:@: \
        copy from:sosu3/sosu3.hrb to:@: \
        imgout:haribote.img


# command

run :
    $(MAKE) haribote.img
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install :
    $(MAKE) haribote.img
    $(IMGTOL) w a: haribote.img

full :
    $(MAKE) -C haribote
    $(MAKE) -C apilib
    $(MAKE) -C a
    $(MAKE) -C hello3
    $(MAKE) -C hello4
    $(MAKE) -C hello5
    $(MAKE) -C winhelo
    $(MAKE) -C winhelo2
    $(MAKE) -C winhelo3
    $(MAKE) -C star1
    $(MAKE) -C stars
    $(MAKE) -C stars2
    $(MAKE) -C lines
    $(MAKE) -C walk
    $(MAKE) -C noodle
    $(MAKE) -C beepdown
    $(MAKE) -C color
    $(MAKE) -C color2
    $(MAKE) -C sosu
    $(MAKE) -C sosu2
    $(MAKE) -C sosu3
    $(MAKE) haribote.img

run_full :
    $(MAKE) full
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install_full :
    $(MAKE) full
    $(IMGTOL) w a: haribote.img

run_os :
    $(MAKE) -C haribote
    $(MAKE) run

clean :
# 何もしない

src_only :
    $(MAKE) clean
    -$(DEL) haribote.img
    
clean_full :
    $(MAKE) -C haribote     clean
    $(MAKE) -C apilib       clean
    $(MAKE) -C a            clean
    $(MAKE) -C hello3       clean
    $(MAKE) -C hello4       clean
    $(MAKE) -C hello5       clean
    $(MAKE) -C winhelo      clean
    $(MAKE) -C winhelo2     clean
    $(MAKE) -C winhelo3     clean
    $(MAKE) -C star1        clean
    $(MAKE) -C stars        clean
    $(MAKE) -C stars2       clean
    $(MAKE) -C lines        clean
    $(MAKE) -C walk         clean   
    $(MAKE) -C noodle       clean
    $(MAKE) -C beepdown     clean
    $(MAKE) -C color        clean
    $(MAKE) -C color2       clean
    $(MAKE) -C sosu         clean
    $(MAKE) -C sosu2        clean
    $(MAKE) -C sosu3        clean

src_only_full :
    $(MAKE) -C haribote     src_only
    $(MAKE) -C apilib       src_only
    $(MAKE) -C a            src_only
    $(MAKE) -C hello3       src_only
    $(MAKE) -C hello4       src_only
    $(MAKE) -C hello5       src_only
    $(MAKE) -C winhelo      src_only
    $(MAKE) -C winhelo2     src_only
    $(MAKE) -C winhelo3     src_only
    $(MAKE) -C star1        src_only
    $(MAKE) -C stars        src_only
    $(MAKE) -C stars2       src_only
    $(MAKE) -C lines        src_only
    $(MAKE) -C walk         src_only    
    $(MAKE) -C noodle       src_only
    $(MAKE) -C beepdown     src_only
    $(MAKE) -C color        src_only
    $(MAKE) -C color2       src_only
    $(MAKE) -C sosu         src_only
    $(MAKE) -C sosu2        src_only
    $(MAKE) -C sosu3        src_only
    -$(DEL) haribote.img

refresh :
    $(MAKE) full
    $(MAKE) clean_full
    -$(DEL) haribote.img

__allocaを作っていきます。

alloca.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "alloca.nas"]

        GLOBAL  __alloca

[SECTION .text]

__alloca:
        ADD     EAX,-4
        SUB     ESP,EAX
        JMP     DWORD [ESP+EAX]     ; RET‚Ì‘ã‚í‚è

apilib/Makefile

OBJS_API =  api001.obj api002.obj api003.obj api004.obj api005.obj api006.obj \
            api007.obj api008.obj api009.obj api010.obj api011.obj api012.obj \
            api013.obj api014.obj api015.obj api016.obj api017.obj api018.obj \
            api019.obj api020.obj \
            alloca.obj

winhelo.c

#include "apilib.h"

void HariMain(void)
{
    int win;
    char buf[150 * 50];
    win = api_openwin(buf, 150, 50, -1, "hello");
    for (;;) {
        if (api_getkey(1) == 0x0a) {
            break; /* Enter‚È‚çbreak; */
        }
    }
    api_end();
}

winhelo2.c

#include "apilib.h"

void HariMain(void)
{
    int win;
    char buf[150 * 50];
    win = api_openwin(buf, 150, 50, -1, "hello");
    api_boxfilwin(win,  8, 36, 141, 43, 3 /* ‰© */);
    api_putstrwin(win, 28, 28, 0 /* • */, 12, "hello, world");
    for (;;) {
        if (api_getkey(1) == 0x0a) {
            break; /* Enter‚È‚çbreak; */
        }
    }
    api_end();
}

ファイルのオープンやクローズ等をするAPIを追加したいとおもいます。

bootpack.h

struct TASK {
    int sel, flags; /* selはGDTの番号のこと */
    int level, priority;
    struct FIFO32 fifo;
    struct TSS32 tss;
    struct SEGMENT_DESCRIPTOR ldt[2];
    struct CONSOLE *cons;
    int ds_base, cons_stack;
    struct FILEHANDLE *fhandle;
    int *fat;
};
/* console.c */
struct CONSOLE {
    struct SHEET *sht;
    int cur_x, cur_y, cur_c;
    struct TIMER *timer;
};
struct FILEHANDLE {
    char *buf;
    int size;
    int pos;
};

console.c

{
    struct TASK *task = task_now();
    struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
    int i, *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
    struct CONSOLE cons;
    struct FILEHANDLE fhandle[8];
    char cmdline[30];

    cons.sht = sheet;
    cons.cur_x =  8;
    cons.cur_y = 28;
    cons.cur_c = -1;
    task->cons = &cons;

    if (cons.sht != 0) {
        cons.timer = timer_alloc();
        timer_init(cons.timer, &task->fifo, 1);
        timer_settime(cons.timer, 50);
    }
    file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));
    for (i = 0; i < 8; i++) {
        fhandle[i].buf = 0; /* 未使用マーク */
    }
    task->fhandle = fhandle;
    task->fat = fat;
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;
    }
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) {
        for (i = 0; i < 8; i++) {
            if (task->fhandle[i].buf == 0) {
                break;
            }
        }
        fh = &task->fhandle[i];
        reg[7] = 0;
        if (i < 8) {
            finfo = file_search((char *) ebx + ds_base,
                    (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
            if (finfo != 0) {
                reg[7] = (int) fh;
                fh->buf = (char *) memman_alloc_4k(memman, finfo->size);
                fh->size = finfo->size;
                fh->pos = 0;
                file_loadfile(finfo->clustno, finfo->size, fh->buf, task->fat, (char *) (ADR_DISKIMG + 0x003e00));
            }
        }
    } else if (edx == 22) {
        fh = (struct FILEHANDLE *) eax;
        memman_free_4k(memman, (int) fh->buf, fh->size);
        fh->buf = 0;
    } else if (edx == 23) {
        fh = (struct FILEHANDLE *) eax;
        if (ecx == 0) {
            fh->pos = ebx;
        } else if (ecx == 1) {
            fh->pos += ebx;
        } else if (ecx == 2) {
            fh->pos = fh->size + ebx;
        }
        if (fh->pos < 0) {
            fh->pos = 0;
        }
        if (fh->pos > fh->size) {
            fh->pos = fh->size;
        }
    } else if (edx == 24) {
        fh = (struct FILEHANDLE *) eax;
        if (ecx == 0) {
            reg[7] = fh->size;
        } else if (ecx == 1) {
            reg[7] = fh->pos;
        } else if (ecx == 2) {
            reg[7] = fh->pos - fh->size;
        }
    } else if (edx == 25) {
        fh = (struct FILEHANDLE *) eax;
        for (i = 0; i < ecx; i++) {
            if (fh->pos == fh->size) {
                break;
            }
            *((char *) ebx + ds_base + i) = fh->buf[fh->pos];
            fh->pos++;
        }
        reg[7] = i;
    }
    return 0;
}

api021.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api021.nas"]

        GLOBAL  _api_fopen

[SECTION .text]

_api_fopen:         ; int api_fopen(char *fname);
        PUSH    EBX
        MOV     EDX,21
        MOV     EBX,[ESP+8]         ; fname
        INT     0x40
        POP     EBX
        RET

api022.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api022.nas"]

        GLOBAL  _api_fclose

[SECTION .text]

_api_fclose:        ; void api_fclose(int fhandle);
        MOV     EDX,22
        MOV     EAX,[ESP+4]         ; fhandle
        INT     0x40
        RET

api023.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api023.nas"]

        GLOBAL  _api_fseek

[SECTION .text]

_api_fseek:         ; void api_fseek(int fhandle, int offset, int mode);
        PUSH    EBX
        MOV     EDX,23
        MOV     EAX,[ESP+8]         ; fhandle
        MOV     ECX,[ESP+16]        ; mode
        MOV     EBX,[ESP+12]        ; offset
        INT     0x40
        POP     EBX
        RET

api024.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api024.nas"]

        GLOBAL  _api_fsize

[SECTION .text]

_api_fsize:         ; int api_fsize(int fhandle, int mode);
        MOV     EDX,24
        MOV     EAX,[ESP+4]         ; fhandle
        MOV     ECX,[ESP+8]         ; mode
        INT     0x40
        RET

api025.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api025.nas"]

        GLOBAL  _api_fread

[SECTION .text]

_api_fread:         ; int api_fread(char *buf, int maxsize, int fhandle);
        PUSH    EBX
        MOV     EDX,25
        MOV     EAX,[ESP+16]        ; fhandle
        MOV     ECX,[ESP+12]        ; maxsize
        MOV     EBX,[ESP+8]         ; buf
        INT     0x40
        POP     EBX
        RET

apilib/Makefile

OBJS_API =  api001.obj api002.obj api003.obj api004.obj api005.obj api006.obj \
            api007.obj api008.obj api009.obj api010.obj api011.obj api012.obj \
            api013.obj api014.obj api015.obj api016.obj api017.obj api018.obj \
            api019.obj api020.obj api021.obj api022.obj api023.obj api024.obj \
            api025.obj alloca.obj

apilib.h

int api_fopen(char *fname);
void api_fclose(int fhandle);
void api_fseek(int fhandle, int offset, int mode);
int api_fsize(int fhandle, int mode);
int api_fread(char *buf, int maxsize, int fhandle);

typeipl/Makefile

APP      = typeipl
STACK    = 1k
MALLOC   = 0k

include ../app_make.txt

typeipl/typeipl.c

#include "apilib.h"

void HariMain(void)
{
    int fh;
    char c;
    fh = api_fopen("ipl10.nas");
    if (fh != 0) {
        for (;;) {
            if (api_fread(&c, 1, fh) == 0) {
                break;
            }
            api_putchar(c);
        }
    }
    api_end();
}

Makefile

TOOLPATH = ..\..\z_tools\\

INCPATH  = ..\..\z_tools\haribote\\

MAKE     = $(TOOLPATH)make.exe -r
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
GOLIB    = $(TOOLPATH)golib00.exe
COPY     = cmd.exe /C copy
DEL      = rm -f

# default operation

default :
    $(MAKE) haribote.img

# file making rule

haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
        a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \
        winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \
        star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \
        lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \
        beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \
        sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \
        typeipl/typeipl.hrb
    $(EDIMG)   imgin:../../z_tools/fdimg0at.tek \
        wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \
        copy from:haribote/haribote.sys to:@: \
        copy from:haribote/ipl10.nas to:@: \
        copy from:make.bat to:@: \
        copy from:a/a.hrb to:@: \
        copy from:hello3/hello3.hrb to:@: \
        copy from:hello4/hello4.hrb to:@: \
        copy from:hello5/hello5.hrb to:@: \
        copy from:winhelo/winhelo.hrb to:@: \
        copy from:winhelo2/winhelo2.hrb to:@: \
        copy from:winhelo3/winhelo3.hrb to:@: \
        copy from:star1/star1.hrb to:@: \
        copy from:stars/stars.hrb to:@: \
        copy from:stars2/stars2.hrb to:@: \
        copy from:lines/lines.hrb to:@: \
        copy from:walk/walk.hrb to:@: \
        copy from:noodle/noodle.hrb to:@: \
        copy from:beepdown/beepdown.hrb to:@: \
        copy from:color/color.hrb to:@: \
        copy from:color2/color2.hrb to:@: \
        copy from:sosu/sosu.hrb to:@: \
        copy from:sosu2/sosu2.hrb to:@: \
        copy from:sosu3/sosu3.hrb to:@: \
        copy from:typeipl/typeipl.hrb to:@: \
        imgout:haribote.img

# command

run :
    $(MAKE) haribote.img
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install :
    $(MAKE) haribote.img
    $(IMGTOL) w a: haribote.img

full :
    $(MAKE) -C haribote
    $(MAKE) -C apilib
    $(MAKE) -C a
    $(MAKE) -C hello3
    $(MAKE) -C hello4
    $(MAKE) -C hello5
    $(MAKE) -C winhelo
    $(MAKE) -C winhelo2
    $(MAKE) -C winhelo3
    $(MAKE) -C star1
    $(MAKE) -C stars
    $(MAKE) -C stars2
    $(MAKE) -C lines
    $(MAKE) -C walk
    $(MAKE) -C noodle
    $(MAKE) -C beepdown
    $(MAKE) -C color
    $(MAKE) -C color2
    $(MAKE) -C sosu
    $(MAKE) -C sosu2
    $(MAKE) -C sosu3
    $(MAKE) -C typeipl
    $(MAKE) haribote.img

run_full :
    $(MAKE) full
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install_full :
    $(MAKE) full
    $(IMGTOL) w a: haribote.img

run_os :
    $(MAKE) -C haribote
    $(MAKE) run

clean :
# 何もしない

src_only :
    $(MAKE) clean
    -$(DEL) haribote.img
    
clean_full :
    $(MAKE) -C haribote     clean
    $(MAKE) -C apilib       clean
    $(MAKE) -C a            clean
    $(MAKE) -C hello3       clean
    $(MAKE) -C hello4       clean
    $(MAKE) -C hello5       clean
    $(MAKE) -C winhelo      clean
    $(MAKE) -C winhelo2     clean
    $(MAKE) -C winhelo3     clean
    $(MAKE) -C star1        clean
    $(MAKE) -C stars        clean
    $(MAKE) -C stars2       clean
    $(MAKE) -C lines        clean
    $(MAKE) -C walk         clean   
    $(MAKE) -C noodle       clean
    $(MAKE) -C beepdown     clean
    $(MAKE) -C color        clean
    $(MAKE) -C color2       clean
    $(MAKE) -C sosu         clean
    $(MAKE) -C sosu2        clean
    $(MAKE) -C sosu3        clean
    $(MAKE) -C typeipl      clean

src_only_full :
    $(MAKE) -C haribote     src_only
    $(MAKE) -C apilib       src_only
    $(MAKE) -C a            src_only
    $(MAKE) -C hello3       src_only
    $(MAKE) -C hello4       src_only
    $(MAKE) -C hello5       src_only
    $(MAKE) -C winhelo      src_only
    $(MAKE) -C winhelo2     src_only
    $(MAKE) -C winhelo3     src_only
    $(MAKE) -C star1        src_only
    $(MAKE) -C stars        src_only
    $(MAKE) -C stars2       src_only
    $(MAKE) -C lines        src_only
    $(MAKE) -C walk         src_only    
    $(MAKE) -C noodle       src_only
    $(MAKE) -C beepdown     src_only
    $(MAKE) -C color        src_only
    $(MAKE) -C color2       src_only
    $(MAKE) -C sosu         src_only
    $(MAKE) -C sosu2        src_only
    $(MAKE) -C sosu3        src_only
    $(MAKE) -C typeipl      src_only
    -$(DEL) haribote.img

refresh :
    $(MAKE) full
    $(MAKE) clean_full
    -$(DEL) haribote.img

typeコマンドを作成指定したいと思います。
bootpack.h

struct TASK {
    int sel, flags; /* selはGDTの番号のこと */
    int level, priority;
    struct FIFO32 fifo;
    struct TSS32 tss;
    struct SEGMENT_DESCRIPTOR ldt[2];
    struct CONSOLE *cons;
    int ds_base, cons_stack;
    struct FILEHANDLE *fhandle;
    int *fat;
    char *cmdline;
};

console.c

task->cons = &cons;
task->cmdline = cmdline;
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
{
    if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) {
        cmd_mem(cons, memtotal);
    } else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) {
        cmd_cls(cons);
    } else if (strcmp(cmdline, "dir") == 0 && cons->sht != 0) {
        cmd_dir(cons);
    } else if (strcmp(cmdline, "exit") == 0) {
        cmd_exit(cons, fat);
    } else if (strncmp(cmdline, "start ", 6) == 0) {
        cmd_start(cons, cmdline, memtotal);
    } else if (strncmp(cmdline, "ncst ", 5) == 0) {
        cmd_ncst(cons, cmdline, memtotal);
    } else if (cmdline[0] != 0) {
        if (cmd_app(cons, fat, cmdline) == 0) {
            /* コマンドではなく、アプリでもなく、さらに空行でもない */
            cons_putstr0(cons, "Bad command.\n\n");
        }
    }
    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;  /* 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) {
        for (i = 0; i < 8; i++) {
            if (task->fhandle[i].buf == 0) {
                break;
            }
        }
        fh = &task->fhandle[i];
        reg[7] = 0;
        if (i < 8) {
            finfo = file_search((char *) ebx + ds_base,
                    (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
            if (finfo != 0) {
                reg[7] = (int) fh;
                fh->buf = (char *) memman_alloc_4k(memman, finfo->size);
                fh->size = finfo->size;
                fh->pos = 0;
                file_loadfile(finfo->clustno, finfo->size, fh->buf, task->fat, (char *) (ADR_DISKIMG + 0x003e00));
            }
        }
    } else if (edx == 22) {
        fh = (struct FILEHANDLE *) eax;
        memman_free_4k(memman, (int) fh->buf, fh->size);
        fh->buf = 0;
    } else if (edx == 23) {
        fh = (struct FILEHANDLE *) eax;
        if (ecx == 0) {
            fh->pos = ebx;
        } else if (ecx == 1) {
            fh->pos += ebx;
        } else if (ecx == 2) {
            fh->pos = fh->size + ebx;
        }
        if (fh->pos < 0) {
            fh->pos = 0;
        }
        if (fh->pos > fh->size) {
            fh->pos = fh->size;
        }
    } else if (edx == 24) {
        fh = (struct FILEHANDLE *) eax;
        if (ecx == 0) {
            reg[7] = fh->size;
        } else if (ecx == 1) {
            reg[7] = fh->pos;
        } else if (ecx == 2) {
            reg[7] = fh->pos - fh->size;
        }
    } else if (edx == 25) {
        fh = (struct FILEHANDLE *) eax;
        for (i = 0; i < ecx; i++) {
            if (fh->pos == fh->size) {
                break;
            }
            *((char *) ebx + ds_base + i) = fh->buf[fh->pos];
            fh->pos++;
        }
        reg[7] = i;
    } else if (edx == 26) {
        i = 0;
        for (;;) {
            *((char *) ebx + ds_base + i) =  task->cmdline[i];
            if (task->cmdline[i] == 0) {
                break;
            }
            if (i >= ecx) {
                break;
            }
            i++;
        }
        reg[7] = i;
    }
    return 0;
}

api026.nas

[FORMAT "WCOFF"]
[INSTRSET "i486p"]
[BITS 32]
[FILE "api026.nas"]

        GLOBAL  _api_cmdline

[SECTION .text]

_api_cmdline:       ; int api_cmdline(char *buf, int maxsize);
        PUSH    EBX
        MOV     EDX,26
        MOV     ECX,[ESP+12]        ; maxsize
        MOV     EBX,[ESP+8]         ; buf
        INT     0x40
        POP     EBX
        RET

apilib/Makefile

OBJS_API =  api001.obj api002.obj api003.obj api004.obj api005.obj api006.obj \
            api007.obj api008.obj api009.obj api010.obj api011.obj api012.obj \
            api013.obj api014.obj api015.obj api016.obj api017.obj api018.obj \
            api019.obj api020.obj api021.obj api022.obj api023.obj api024.obj \
            api025.obj api026.obj alloca.obj

type/Makefile

APP      = type
STACK    = 1k
MALLOC   = 0k

include ../app_make.txt

type/type.c

#include "apilib.h"

void HariMain(void)
{
    int fh;
    char c, cmdline[30], *p;

    api_cmdline(cmdline, 30);
    for (p = cmdline; *p > ' '; p++) { }  /* スペースが来るまで読み飛ばす */
    for (; *p == ' '; p++) { }   /* スペースを読み飛ばす */
    fh = api_fopen(p);
    if (fh != 0) {
        for (;;) {
            if (api_fread(&c, 1, fh) == 0) {
                break;
            }
            api_putchar(c);
        }
    } else {
        api_putstr0("File not found.\n");
    }
    api_end();
}

apilib.h

int api_cmdline(char *buf, int maxsize);    

Makefile

TOOLPATH = ..\..\z_tools\\

INCPATH  = ..\..\z_tools\haribote\\

MAKE     = $(TOOLPATH)make.exe -r
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
GOLIB    = $(TOOLPATH)golib00.exe
COPY     = cmd.exe /C copy
DEL      = rm -f

# default operation

default :
    $(MAKE) haribote.img

# file making rule

haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
        a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \
        winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \
        star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \
        lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \
        beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \
        sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \
        typeipl/typeipl.hrb type/type.hrb
    $(EDIMG)   imgin:../../z_tools/fdimg0at.tek \
        wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \
        copy from:haribote/haribote.sys to:@: \
        copy from:haribote/ipl10.nas to:@: \
        copy from:make.bat to:@: \
        copy from:a/a.hrb to:@: \
        copy from:hello3/hello3.hrb to:@: \
        copy from:hello4/hello4.hrb to:@: \
        copy from:hello5/hello5.hrb to:@: \
        copy from:winhelo/winhelo.hrb to:@: \
        copy from:winhelo2/winhelo2.hrb to:@: \
        copy from:winhelo3/winhelo3.hrb to:@: \
        copy from:star1/star1.hrb to:@: \
        copy from:stars/stars.hrb to:@: \
        copy from:stars2/stars2.hrb to:@: \
        copy from:lines/lines.hrb to:@: \
        copy from:walk/walk.hrb to:@: \
        copy from:noodle/noodle.hrb to:@: \
        copy from:beepdown/beepdown.hrb to:@: \
        copy from:color/color.hrb to:@: \
        copy from:color2/color2.hrb to:@: \
        copy from:sosu/sosu.hrb to:@: \
        copy from:sosu2/sosu2.hrb to:@: \
        copy from:sosu3/sosu3.hrb to:@: \
        copy from:typeipl/typeipl.hrb to:@: \
        copy from:type/type.hrb to:@: \
        imgout:haribote.img

# command

run :
    $(MAKE) haribote.img
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install :
    $(MAKE) haribote.img
    $(IMGTOL) w a: haribote.img

full :
    $(MAKE) -C haribote
    $(MAKE) -C apilib
    $(MAKE) -C a
    $(MAKE) -C hello3
    $(MAKE) -C hello4
    $(MAKE) -C hello5
    $(MAKE) -C winhelo
    $(MAKE) -C winhelo2
    $(MAKE) -C winhelo3
    $(MAKE) -C star1
    $(MAKE) -C stars
    $(MAKE) -C stars2
    $(MAKE) -C lines
    $(MAKE) -C walk
    $(MAKE) -C noodle
    $(MAKE) -C beepdown
    $(MAKE) -C color
    $(MAKE) -C color2
    $(MAKE) -C sosu
    $(MAKE) -C sosu2
    $(MAKE) -C sosu3
    $(MAKE) -C typeipl
    $(MAKE) -C type
    $(MAKE) haribote.img

run_full :
    $(MAKE) full
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install_full :
    $(MAKE) full
    $(IMGTOL) w a: haribote.img

run_os :
    $(MAKE) -C haribote
    $(MAKE) run

clean :
# 何もしない

src_only :
    $(MAKE) clean
    -$(DEL) haribote.img
    
clean_full :
    $(MAKE) -C haribote     clean
    $(MAKE) -C apilib       clean
    $(MAKE) -C a            clean
    $(MAKE) -C hello3       clean
    $(MAKE) -C hello4       clean
    $(MAKE) -C hello5       clean
    $(MAKE) -C winhelo      clean
    $(MAKE) -C winhelo2     clean
    $(MAKE) -C winhelo3     clean
    $(MAKE) -C star1        clean
    $(MAKE) -C stars        clean
    $(MAKE) -C stars2       clean
    $(MAKE) -C lines        clean
    $(MAKE) -C walk         clean   
    $(MAKE) -C noodle       clean
    $(MAKE) -C beepdown     clean
    $(MAKE) -C color        clean
    $(MAKE) -C color2       clean
    $(MAKE) -C sosu         clean
    $(MAKE) -C sosu2        clean
    $(MAKE) -C sosu3        clean
    $(MAKE) -C typeipl      clean
    $(MAKE) -C type         clean

src_only_full :
    $(MAKE) -C haribote     src_only
    $(MAKE) -C apilib       src_only
    $(MAKE) -C a            src_only
    $(MAKE) -C hello3       src_only
    $(MAKE) -C hello4       src_only
    $(MAKE) -C hello5       src_only
    $(MAKE) -C winhelo      src_only
    $(MAKE) -C winhelo2     src_only
    $(MAKE) -C winhelo3     src_only
    $(MAKE) -C star1        src_only
    $(MAKE) -C stars        src_only
    $(MAKE) -C stars2       src_only
    $(MAKE) -C lines        src_only
    $(MAKE) -C walk         src_only    
    $(MAKE) -C noodle       src_only
    $(MAKE) -C beepdown     src_only
    $(MAKE) -C color        src_only
    $(MAKE) -C color2       src_only
    $(MAKE) -C sosu         src_only
    $(MAKE) -C sosu2        src_only
    $(MAKE) -C sosu3        src_only
    $(MAKE) -C typeipl      src_only
    $(MAKE) -C type         src_only
    -$(DEL) haribote.img

refresh :
    $(MAKE) full
    $(MAKE) clean_full
    -$(DEL) haribote.img

表示する文字について日本語で対応してみたいと思います。
bootpack.c

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;
/* 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);

bootpack.h

struct TASK {
    int sel, flags; /* selはGDTの番号のこと */
    int level, priority;
    struct FIFO32 fifo;
    struct TSS32 tss;
    struct SEGMENT_DESCRIPTOR ldt[2];
    struct CONSOLE *cons;
    int ds_base, cons_stack;
    struct FILEHANDLE *fhandle;
    int *fat;
    char *cmdline;
    char langmode;
};

graphic.c

void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s)
{
    extern char hankaku[4096];
    struct TASK *task = task_now();
    char *nihongo = (char *) *((int *) 0x0fe8);
    
    if (task->langmode == 0) {
        for (; *s != 0x00; s++) {
            putfont8(vram, xsize, x, y, c, hankaku + *s * 16);
            x += 8;
        }
    }
    if (task->langmode == 1) {
        for (; *s != 0x00; s++) {
            putfont8(vram, xsize, x, y, c, nihongo + *s * 16);
            x += 8;
        }
    }
    return;
}

console.c

void console_task(struct SHEET *sheet, int memtotal)
{
    struct TASK *task = task_now();
    struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
    int i, *fat = (int *) memman_alloc_4k(memman, 4 * 2880);
    struct CONSOLE cons;
    struct FILEHANDLE fhandle[8];
    char cmdline[30];
    unsigned char *nihongo = (char *) *((int *) 0x0fe8);

    cons.sht = sheet;
    cons.cur_x =  8;
    cons.cur_y = 28;
    cons.cur_c = -1;
    task->cons = &cons;
    task->cmdline = cmdline;

    if (cons.sht != 0) {
        cons.timer = timer_alloc();
        timer_init(cons.timer, &task->fifo, 1);
        timer_settime(cons.timer, 50);
    }
    file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));
    for (i = 0; i < 8; i++) {
        fhandle[i].buf = 0;    /* 未使用マーク */
    }
    task->fhandle = fhandle;
    task->fat = fat;
    if (nihongo[4096] != 0xff) {    /* 日本語フォントファイルを読み込めたか? */
        task->langmode = 1;
    } else {
        task->langmode = 0;
    }
void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
{
    if (strcmp(cmdline, "mem") == 0 && cons->sht != 0) {
        cmd_mem(cons, memtotal);
    } else if (strcmp(cmdline, "cls") == 0 && cons->sht != 0) {
        cmd_cls(cons);
    } else if (strcmp(cmdline, "dir") == 0 && cons->sht != 0) {
        cmd_dir(cons);
    } else if (strcmp(cmdline, "exit") == 0) {
        cmd_exit(cons, fat);
    } else if (strncmp(cmdline, "start ", 6) == 0) {
        cmd_start(cons, cmdline, memtotal);
    } else if (strncmp(cmdline, "ncst ", 5) == 0) {
        cmd_ncst(cons, cmdline, memtotal);
    } else if (strncmp(cmdline, "langmode ", 9) == 0) {
        cmd_langmode(cons, cmdline);
    } else if (cmdline[0] != 0) {
        if (cmd_app(cons, fat, cmdline) == 0) {
            /* コマンドではなく、アプリでもなく、さらに空行でもない */
            cons_putstr0(cons, "Bad command.\n\n");
        }
    }
    return;
}
void cmd_langmode(struct CONSOLE *cons, char *cmdline)
{
    struct TASK *task = task_now();
    unsigned char mode = cmdline[9] - '0';
    if (mode <= 1) {
        task->langmode = mode;
    } else {
        cons_putstr0(cons, "mode number error.\n");
    }
    cons_newline(cons);
    return;
}

Makefile

APP      = iroha
STACK    = 1k
MALLOC   = 0k

include ../app_make.txt

iroha.c

#include "apilib.h"

void HariMain(void)
{
    static char s[9] = { 0xb2, 0xdb, 0xca, 0xc6, 0xce, 0xcd, 0xc4, 0x0a, 0x00 };
        /* 半角のイロハニホヘトの文字コード+改行+0 */
    api_putstr0(s);
    api_end();
}

Makefile

TOOLPATH = ..\..\z_tools\\

INCPATH  = ..\..\z_tools\haribote\\

MAKE     = $(TOOLPATH)make.exe -r
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
GOLIB    = $(TOOLPATH)golib00.exe
COPY     = cmd.exe /C copy
DEL      = rm -f

# default operation

default :
    $(MAKE) haribote.img

# file making rule

haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
        a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \
        winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \
        star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \
        lines/lines.hrb walk/walk.hrb noodle/noodle.hrb \
        beepdown/beepdown.hrb color/color.hrb color2/color2.hrb \
        sosu/sosu.hrb sosu2/sosu2.hrb sosu3/sosu3.hrb \
        typeipl/typeipl.hrb type/type.hrb iroha/iroha.hrb
    $(EDIMG)   imgin:../../z_tools/fdimg0at.tek \
        wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \
        copy from:haribote/haribote.sys to:@: \
        copy from:haribote/ipl10.nas to:@: \
        copy from:make.bat to:@: \
        copy from:a/a.hrb to:@: \
        copy from:hello3/hello3.hrb to:@: \
        copy from:hello4/hello4.hrb to:@: \
        copy from:hello5/hello5.hrb to:@: \
        copy from:winhelo/winhelo.hrb to:@: \
        copy from:winhelo2/winhelo2.hrb to:@: \
        copy from:winhelo3/winhelo3.hrb to:@: \
        copy from:star1/star1.hrb to:@: \
        copy from:stars/stars.hrb to:@: \
        copy from:stars2/stars2.hrb to:@: \
        copy from:lines/lines.hrb to:@: \
        copy from:walk/walk.hrb to:@: \
        copy from:noodle/noodle.hrb to:@: \
        copy from:beepdown/beepdown.hrb to:@: \
        copy from:color/color.hrb to:@: \
        copy from:color2/color2.hrb to:@: \
        copy from:sosu/sosu.hrb to:@: \
        copy from:sosu2/sosu2.hrb to:@: \
        copy from:sosu3/sosu3.hrb to:@: \
        copy from:typeipl/typeipl.hrb to:@: \
        copy from:type/type.hrb to:@: \
        copy from:iroha/iroha.hrb to:@: \
        copy from:nihongo/nihongo.fnt to:@: \
        imgout:haribote.img

# command

run :
    $(MAKE) haribote.img
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install :
    $(MAKE) haribote.img
    $(IMGTOL) w a: haribote.img

full :
    $(MAKE) -C haribote
    $(MAKE) -C apilib
    $(MAKE) -C a
    $(MAKE) -C hello3
    $(MAKE) -C hello4
    $(MAKE) -C hello5
    $(MAKE) -C winhelo
    $(MAKE) -C winhelo2
    $(MAKE) -C winhelo3
    $(MAKE) -C star1
    $(MAKE) -C stars
    $(MAKE) -C stars2
    $(MAKE) -C lines
    $(MAKE) -C walk
    $(MAKE) -C noodle
    $(MAKE) -C beepdown
    $(MAKE) -C color
    $(MAKE) -C color2
    $(MAKE) -C sosu
    $(MAKE) -C sosu2
    $(MAKE) -C sosu3
    $(MAKE) -C typeipl
    $(MAKE) -C type
    $(MAKE) -C iroha
    $(MAKE) haribote.img

run_full :
    $(MAKE) full
    $(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
    $(MAKE) -C ..\..\z_tools\qemu

install_full :
    $(MAKE) full
    $(IMGTOL) w a: haribote.img

run_os :
    $(MAKE) -C haribote
    $(MAKE) run

clean :
# 何もしない

src_only :
    $(MAKE) clean
    -$(DEL) haribote.img
    
clean_full :
    $(MAKE) -C haribote     clean
    $(MAKE) -C apilib       clean
    $(MAKE) -C a            clean
    $(MAKE) -C hello3       clean
    $(MAKE) -C hello4       clean
    $(MAKE) -C hello5       clean
    $(MAKE) -C winhelo      clean
    $(MAKE) -C winhelo2     clean
    $(MAKE) -C winhelo3     clean
    $(MAKE) -C star1        clean
    $(MAKE) -C stars        clean
    $(MAKE) -C stars2       clean
    $(MAKE) -C lines        clean
    $(MAKE) -C walk         clean   
    $(MAKE) -C noodle       clean
    $(MAKE) -C beepdown     clean
    $(MAKE) -C color        clean
    $(MAKE) -C color2       clean
    $(MAKE) -C sosu         clean
    $(MAKE) -C sosu2        clean
    $(MAKE) -C sosu3        clean
    $(MAKE) -C typeipl      clean
    $(MAKE) -C type         clean
    $(MAKE) -C iroha        clean

src_only_full :
    $(MAKE) -C haribote     src_only
    $(MAKE) -C apilib       src_only
    $(MAKE) -C a            src_only
    $(MAKE) -C hello3       src_only
    $(MAKE) -C hello4       src_only
    $(MAKE) -C hello5       src_only
    $(MAKE) -C winhelo      src_only
    $(MAKE) -C winhelo2     src_only
    $(MAKE) -C winhelo3     src_only
    $(MAKE) -C star1        src_only
    $(MAKE) -C stars        src_only
    $(MAKE) -C stars2       src_only
    $(MAKE) -C lines        src_only
    $(MAKE) -C walk         src_only    
    $(MAKE) -C noodle       src_only
    $(MAKE) -C beepdown     src_only
    $(MAKE) -C color        src_only
    $(MAKE) -C color2       src_only
    $(MAKE) -C sosu         src_only
    $(MAKE) -C sosu2        src_only
    $(MAKE) -C sosu3        src_only
    $(MAKE) -C typeipl      src_only
    $(MAKE) -C type         src_only
    $(MAKE) -C iroha        src_only
    -$(DEL) haribote.img

refresh :
    $(MAKE) full
    $(MAKE) clean_full
    -$(DEL) haribote.img

実装過程
・ ef3652dca4d13ad2086011fd97d050308b14aa01