Compare commits

...

3 Commits

Author SHA1 Message Date
Yourtion
fcd87ee302 日文文字显示(2) 2016-05-18 12:58:00 +08:00
Yourtion
ac8b6b1411 日文文字显示(1) 2016-05-18 12:43:01 +08:00
Yourtion
86791cd7f4 命令行API 2016-05-18 11:41:34 +08:00
22 changed files with 294 additions and 32 deletions

View File

@@ -21,11 +21,11 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
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
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:haribote/jp.nas to:@: \
copy from:make.bat to:@: \
copy from:a/a.hrb to:@: \
copy from:hello3/hello3.hrb to:@: \
@@ -47,6 +47,9 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
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
#命令
@@ -83,6 +86,8 @@ full :
$(MAKE) -C sosu2
$(MAKE) -C sosu3
$(MAKE) -C typeipl
$(MAKE) -C type
$(MAKE) -C iroha
$(MAKE) haribote.img
run_full :
@@ -128,6 +133,8 @@ clean_full :
$(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
@@ -151,7 +158,9 @@ src_only_full :
$(MAKE) -C sosu src_only
$(MAKE) -C sosu2 src_only
$(MAKE) -C sosu3 src_only
$(MAKE) -C typeipl src_only
$(MAKE) -C typeipl src_only
$(MAKE) -C type src_only
$(MAKE) -C iroha src_only
-$(DEL) haribote.img
refresh :

View File

@@ -23,3 +23,4 @@ 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);
int api_cmdline(char *buf, int maxsize);

View File

@@ -2,7 +2,7 @@ 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
api025.obj api026.obj alloca.obj
TOOLPATH = ../../z_tools/
INCPATH = ../../z_tools/haribote/

17
28_day/apilib/api026.nas Normal file
View File

@@ -0,0 +1,17 @@
[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

View File

@@ -47,6 +47,10 @@ void HariMain(void)
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();
@@ -71,6 +75,7 @@ void HariMain(void)
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);
@@ -96,10 +101,28 @@ void HariMain(void)
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) {
/* 如果存在向键盘控制器发送的数据,则发送它 */

View File

@@ -216,6 +216,8 @@ struct TASK {
int ds_base, cons_stack;
struct FILEHANDLE *fhandle;
int *fat;
char *cmdline;
unsigned char langmode, langbyte1;
};
struct TASKLEVEL {
int running; /*正在运行的任务数量*/
@@ -264,10 +266,10 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal);
void cmd_mem(struct CONSOLE *cons, int memtotal);
void cmd_cls(struct CONSOLE *cons);
void cmd_dir(struct CONSOLE *cons);
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline);
void cmd_exit(struct CONSOLE *cons, int *fat);
void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal);
void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal);
void cmd_langmode(struct CONSOLE *cons, char *cmdline);
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline);
int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int eax);
int *inthandler0d(int *esp);

View File

@@ -12,12 +12,14 @@ void console_task(struct SHEET *sheet, int memtotal)
struct FILEHANDLE fhandle[8];
struct CONSOLE cons;
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();
@@ -30,6 +32,12 @@ void console_task(struct SHEET *sheet, int memtotal)
}
task->fhandle = fhandle;
task->fat = fat;
if (nihongo[4096] != 0xff) { /* 是否载入了字库?*/
task->langmode = 1;
} else {
task->langmode = 0;
}
task->langbyte1 = 0;
/*显示提示符*/
cons_putchar(&cons, '>', 1);
@@ -151,6 +159,7 @@ void cons_newline(struct CONSOLE *cons)
{
int x, y;
struct SHEET *sheet = cons->sht;
struct TASK *task = task_now();
if (cons->cur_y < 28 + 112) {
cons->cur_y += 16; /*到下一行*/
} else {
@@ -170,6 +179,9 @@ void cons_newline(struct CONSOLE *cons)
}
}
cons->cur_x = 8;
if (task->langmode == 1 && task->langbyte1 != 0) {
cons->cur_x += 8;
}
return;
}
@@ -198,15 +210,15 @@ void cons_runcmd(char *cmdline, struct CONSOLE *cons, int *fat, int memtotal)
cmd_cls(cons);
} else if ((strcmp(cmdline, "dir") == 0 || strcmp(cmdline, "ls") == 0) && cons->sht != 0) {
cmd_dir(cons);
} else if (strncmp(cmdline, "type ", 5) == 0 && cons->sht != 0) {
cmd_type(cons, fat, cmdline);
} 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) {
} 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");
@@ -264,25 +276,6 @@ void cmd_dir(struct CONSOLE *cons)
return;
}
void cmd_type(struct CONSOLE *cons, int *fat, char *cmdline)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
struct FILEINFO *finfo = file_search(cmdline + 5, (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
char *p;
if (finfo != 0) {
/*找到文件的情况*/
p = (char *) memman_alloc_4k(memman, finfo->size);
file_loadfile(finfo->clustno, finfo->size, p, fat, (char *) (ADR_DISKIMG + 0x003e00));
cons_putstr1(cons, p, finfo->size);
memman_free_4k(memman, (int) p, finfo->size);
} else {
/*没有找到文件的情况*/
cons_putstr0(cons, "File not found.\n");
}
cons_newline(cons);
return;
}
void cmd_exit(struct CONSOLE *cons, int *fat)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
@@ -337,6 +330,19 @@ void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal)
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;
}
int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
{
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
@@ -402,6 +408,7 @@ int cmd_app(struct CONSOLE *cons, int *fat, char *cmdline)
}
timer_cancelall(&task->fifo);
memman_free_4k(memman, (int) q, segsiz);
task->langbyte1 = 0;
} else {
cons_putstr0(cons, ".hrb file format error.\n");
}
@@ -600,6 +607,19 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
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;
}

View File

@@ -107,10 +107,45 @@ void putfont8(char *vram, int xsize, int x, int y, char c, char *font)
void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s)
{
extern char hankaku[4096];
/* C语言中字符串都是以0x00结尾 */
for (; *s != 0x00; s++) {
putfont8(vram, xsize, x, y, c, hankaku + *s * 16);
x += 8;
struct TASK *task = task_now();
char *nihongo = (char *) *((int *) 0x0fe8), *font;
int k, t;
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++) {
if (task->langbyte1 == 0) {
if ((0x81 <= *s && *s <= 0x9f) || (0xe0 <= *s && *s <= 0xfc)) {
task->langbyte1 = *s;
} else {
putfont8(vram, xsize, x, y, c, nihongo + *s * 16);
}
} else {
if (0x81 <= task->langbyte1 && task->langbyte1 <= 0x9f) {
k = (task->langbyte1 - 0x81) * 2;
} else {
k = (task->langbyte1 - 0xe0) * 2 + 62;
}
if (0x40 <= *s && *s <= 0x7e) {
t = *s - 0x40;
} else if (0x80 <= *s && *s <= 0x9e) {
t = *s - 0x80 + 63;
} else {
t = *s - 0x9f;
k++;
}
task->langbyte1 = 0;
font = nihongo + 256 * 16 + (k * 94 + t) * 32;
putfont8(vram, xsize, x - 8, y, c, font ); /* 左半部分 */
putfont8(vram, xsize, x , y, c, font + 16); /* 右半部分 */
}
x += 8;
}
}
return;
}

107
28_day/haribote/jp.nas Normal file
View File

@@ -0,0 +1,107 @@
; haribote-ipl
; TAB=4
CYLS EQU 10 ; どこまで読み込むか
ORG 0x7c00 ; このプログラムがどこに読み込まれるのか
; 以下は標準的なFAT12フォーマットフロッピーディスクのための記述
JMP entry
DB 0x90
DB "HARIBOTE" ; ブートセクタの名前を自由に書いてよい8バイト
DW 512 ; 1セクタの大きさ512にしなければいけない
DB 1 ; クラスタの大きさ1セクタにしなければいけない
DW 1 ; FATがどこから始まるか普通は1セクタ目からにする
DB 2 ; FATの個数2にしなければいけない
DW 224 ; ルートディレクトリ領域の大きさ普通は224エントリにする
DW 2880 ; このドライブの大きさ2880セクタにしなければいけない
DB 0xf0 ; メディアのタイプ0xf0にしなければいけない
DW 9 ; FAT領域の長さ9セクタにしなければいけない
DW 18 ; 1トラックにいくつのセクタがあるか18にしなければいけない
DW 2 ; ヘッドの数2にしなければいけない
DD 0 ; パーティションを使ってないのでここは必ず0
DD 2880 ; このドライブ大きさをもう一度書く
DB 0,0,0x29 ; よくわからないけどこの値にしておくといいらしい
DD 0xffffffff ; たぶんボリュームシリアル番号
DB "HARIBOTEOS " ; ディスクの名前11バイト
DB "FAT12 " ; フォーマットの名前8バイト
RESB 18 ; とりあえず18バイトあけておく
; プログラム本体
entry:
MOV AX,0 ; レジスタ初期化
MOV SS,AX
MOV SP,0x7c00
MOV DS,AX
; ディスクを読む
MOV AX,0x0820
MOV ES,AX
MOV CH,0 ; シリンダ0
MOV DH,0 ; ヘッド0
MOV CL,2 ; セクタ2
readloop:
MOV SI,0 ; 失敗回数を数えるレジスタ
retry:
MOV AH,0x02 ; AH=0x02 : ディスク読み込み
MOV AL,1 ; 1セクタ
MOV BX,0
MOV DL,0x00 ; Aドライブ
INT 0x13 ; ディスクBIOS呼び出し
JNC next ; エラーがおきなければnextへ
ADD SI,1 ; SIに1を足す
CMP SI,5 ; SIと5を比較
JAE error ; SI >= 5 だったらerrorへ
MOV AH,0x00
MOV DL,0x00 ; Aドライブ
INT 0x13 ; ドライブのリセット
JMP retry
next:
MOV AX,ES ; アドレスを0x200進める
ADD AX,0x0020
MOV ES,AX ; ADD ES,0x020 という命令がないのでこうしている
ADD CL,1 ; CLに1を足す
CMP CL,18 ; CLと18を比較
JBE readloop ; CL <= 18 だったらreadloopへ
MOV CL,1
ADD DH,1
CMP DH,2
JB readloop ; DH < 2 だったらreadloopへ
MOV DH,0
ADD CH,1
CMP CH,CYLS
JB readloop ; CH < CYLS だったらreadloopへ
; 読み終わったのでharibote.sysを実行だ
MOV [0x0ff0],CH ; IPLがどこまで読んだのかをメモ
JMP 0xc200
error:
MOV AX,0
MOV ES,AX
MOV SI,msg
putloop:
MOV AL,[SI]
ADD SI,1 ; SIに1を足す
CMP AL,0
JE fin
MOV AH,0x0e ; 一文字表示ファンクション
MOV BX,15 ; カラーコード
INT 0x10 ; ビデオBIOS呼び出し
JMP putloop
fin:
HLT ; 何かあるまでCPUを停止させる
JMP fin ; 無限ループ
msg:
DB 0x0a, 0x0a ; 改行を2つ
DB "load error"
DB 0x0a ; 改行
DB 0
RESB 0x7dfe-$ ; 0x7dfeまでを0x00で埋める命令
DB 0x55, 0xaa

View File

@@ -0,0 +1 @@
command

View File

@@ -0,0 +1 @@
cmd.exe

5
28_day/iroha/Makefile Normal file
View File

@@ -0,0 +1,5 @@
APP = iroha
STACK = 1k
MALLOC = 0k
include ../app_make.txt

9
28_day/iroha/iroha.c Normal file
View File

@@ -0,0 +1,9 @@
#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();
}

1
28_day/iroha/make.bat Normal file
View File

@@ -0,0 +1 @@
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

BIN
28_day/nihongo/jpn16v00.bin Normal file

Binary file not shown.

BIN
28_day/nihongo/jpn16v00.fnt Normal file

Binary file not shown.

BIN
28_day/nihongo/nihongo.fnt Normal file

Binary file not shown.

1
28_day/type/!cons_9x.bat Normal file
View File

@@ -0,0 +1 @@
command

1
28_day/type/!cons_nt.bat Normal file
View File

@@ -0,0 +1 @@
cmd.exe

5
28_day/type/Makefile Normal file
View File

@@ -0,0 +1,5 @@
APP = type
STACK = 1k
MALLOC = 0k
include ../app_make.txt

1
28_day/type/make.bat Normal file
View File

@@ -0,0 +1 @@
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

23
28_day/type/type.c Normal file
View File

@@ -0,0 +1,23 @@
#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();
}