mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-04 18:43:25 +08:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
140774a293 | ||
|
|
7c2fc66927 | ||
|
|
636c1a8c3d | ||
|
|
c177821913 | ||
|
|
febac10ebf | ||
|
|
0e31ff06ca | ||
|
|
08d19d7512 | ||
|
|
b2d31a8e54 | ||
|
|
72532c8cd7 | ||
|
|
3871740126 | ||
|
|
70b335278d | ||
|
|
2c262f986d | ||
|
|
6b0457bed6 | ||
|
|
0adab9385e | ||
|
|
73b7421cf2 | ||
|
|
203dd63152 | ||
|
|
9df2b90ad3 | ||
|
|
633089d320 | ||
|
|
41a0252634 | ||
|
|
5a064e20c2 | ||
|
|
d925a8d992 | ||
|
|
7497159026 | ||
|
|
fcd87ee302 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1 +1,5 @@
|
||||
*.hrb
|
||||
*.lst
|
||||
*.map
|
||||
*.bim
|
||||
*.hrb
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,18 +14,19 @@ default :
|
||||
|
||||
#文件生成规则
|
||||
|
||||
haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
|
||||
haribote.img : haribote/ipl20.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
|
||||
typeipl/typeipl.hrb type/type.hrb iroha/iroha.hrb \
|
||||
chklang/chklang.hrb
|
||||
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
|
||||
wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \
|
||||
wbinimg src:haribote/ipl20.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:@: \
|
||||
@@ -49,6 +50,8 @@ haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
|
||||
copy from:typeipl/typeipl.hrb to:@: \
|
||||
copy from:type/type.hrb to:@: \
|
||||
copy from:iroha/iroha.hrb to:@: \
|
||||
copy from:chklang/chklang.hrb to:@: \
|
||||
copy from:euc.txt to:@: \
|
||||
copy from:nihongo/nihongo.fnt to:@: \
|
||||
imgout:haribote.img
|
||||
|
||||
@@ -88,6 +91,7 @@ full :
|
||||
$(MAKE) -C typeipl
|
||||
$(MAKE) -C type
|
||||
$(MAKE) -C iroha
|
||||
$(MAKE) -C chklang
|
||||
$(MAKE) haribote.img
|
||||
|
||||
run_full :
|
||||
@@ -112,55 +116,57 @@ src_only :
|
||||
|
||||
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 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 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 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
|
||||
$(MAKE) -C type clean
|
||||
$(MAKE) -C iroha clean
|
||||
$(MAKE) -C chklang 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 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 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 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
|
||||
$(MAKE) -C type src_only
|
||||
$(MAKE) -C iroha src_only
|
||||
$(MAKE) -C chklang src_only
|
||||
-$(DEL) haribote.img
|
||||
|
||||
refresh :
|
||||
|
||||
@@ -24,3 +24,4 @@ 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);
|
||||
int api_getlang(void);
|
||||
|
||||
@@ -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 api026.obj alloca.obj
|
||||
api025.obj api026.obj api027.obj alloca.obj
|
||||
|
||||
TOOLPATH = ../../z_tools/
|
||||
INCPATH = ../../z_tools/haribote/
|
||||
|
||||
13
28_day/apilib/api027.nas
Normal file
13
28_day/apilib/api027.nas
Normal file
@@ -0,0 +1,13 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api027.nas"]
|
||||
|
||||
GLOBAL _api_getlang
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_getlang: ; int api_getlang(void);
|
||||
MOV EDX,27
|
||||
INT 0x40
|
||||
RET
|
||||
Binary file not shown.
1
28_day/chklang/!cons_9x.bat
Normal file
1
28_day/chklang/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
28_day/chklang/!cons_nt.bat
Normal file
1
28_day/chklang/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
28_day/chklang/Makefile
Normal file
5
28_day/chklang/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = chklang
|
||||
STACK = 1k
|
||||
MALLOC = 0k
|
||||
|
||||
include ../app_make.txt
|
||||
24
28_day/chklang/chklang.c
Normal file
24
28_day/chklang/chklang.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "apilib.h"
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
int langmode = api_getlang();
|
||||
static char s1[23] = { /* 日本語シフトJISモード(日文Shift-JIS模式)*/
|
||||
0x93, 0xfa, 0x96, 0x7b, 0x8c, 0xea, 0x83, 0x56, 0x83, 0x74, 0x83, 0x67,
|
||||
0x4a, 0x49, 0x53, 0x83, 0x82, 0x81, 0x5b, 0x83, 0x68, 0x0a, 0x00
|
||||
};
|
||||
static char s2[17] = { /*日本語EUCモード(日文EUC模式)*/
|
||||
0xc6, 0xfc, 0xcb, 0xdc, 0xb8, 0xec, 0x45, 0x55, 0x43, 0xa5, 0xe2, 0xa1,
|
||||
0xbc, 0xa5, 0xc9, 0x0a, 0x00
|
||||
};
|
||||
if (langmode == 0) {
|
||||
api_putstr0("English ASCII mode\n");
|
||||
}
|
||||
if (langmode == 1) {
|
||||
api_putstr0(s1);
|
||||
}
|
||||
if (langmode == 2) {
|
||||
api_putstr0(s2);
|
||||
}
|
||||
api_end();
|
||||
}
|
||||
1
28_day/chklang/make.bat
Normal file
1
28_day/chklang/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
1
28_day/euc.txt
Normal file
1
28_day/euc.txt
Normal file
@@ -0,0 +1 @@
|
||||
日本語EUCで書いてみたよー
|
||||
@@ -23,7 +23,7 @@ DEL = del
|
||||
#默认动作
|
||||
|
||||
default :
|
||||
$(MAKE) ipl10.bin
|
||||
$(MAKE) ipl20.bin
|
||||
$(MAKE) haribote.sys
|
||||
|
||||
# 镜像文件生成
|
||||
@@ -31,6 +31,9 @@ default :
|
||||
ipl10.bin : ipl10.nas Makefile
|
||||
$(NASK) ipl10.nas ipl10.bin ipl10.lst
|
||||
|
||||
ipl20.bin : ipl20.nas Makefile
|
||||
$(NASK) ipl20.nas ipl20.bin ipl20.lst
|
||||
|
||||
asmhead.bin : asmhead.nas Makefile
|
||||
$(NASK) asmhead.nas asmhead.bin asmhead.lst
|
||||
|
||||
@@ -76,4 +79,5 @@ clean :
|
||||
src_only :
|
||||
$(MAKE) clean
|
||||
-$(DEL) ipl10.bin
|
||||
-$(DEL) ipl20.bin
|
||||
-$(DEL) haribote.sys
|
||||
|
||||
@@ -217,7 +217,7 @@ struct TASK {
|
||||
struct FILEHANDLE *fhandle;
|
||||
int *fat;
|
||||
char *cmdline;
|
||||
char langmode;
|
||||
unsigned char langmode, langbyte1;
|
||||
};
|
||||
struct TASKLEVEL {
|
||||
int running; /*正在运行的任务数量*/
|
||||
|
||||
@@ -37,6 +37,7 @@ void console_task(struct SHEET *sheet, int memtotal)
|
||||
} else {
|
||||
task->langmode = 0;
|
||||
}
|
||||
task->langbyte1 = 0;
|
||||
|
||||
/*显示提示符*/
|
||||
cons_putchar(&cons, '>', 1);
|
||||
@@ -158,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 {
|
||||
@@ -177,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;
|
||||
}
|
||||
|
||||
@@ -329,7 +334,7 @@ void cmd_langmode(struct CONSOLE *cons, char *cmdline)
|
||||
{
|
||||
struct TASK *task = task_now();
|
||||
unsigned char mode = cmdline[9] - '0';
|
||||
if (mode <= 1) {
|
||||
if (mode <= 2) {
|
||||
task->langmode = mode;
|
||||
} else {
|
||||
cons_putstr0(cons, "mode number error.\n");
|
||||
@@ -403,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");
|
||||
}
|
||||
@@ -614,6 +620,8 @@ int *hrb_api(int edi, int esi, int ebp, int esp, int ebx, int edx, int ecx, int
|
||||
i++;
|
||||
}
|
||||
reg[7] = i;
|
||||
} else if (edx == 27) {
|
||||
reg[7] = task->langmode;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,9 +107,10 @@ 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结尾 */
|
||||
struct TASK *task = task_now();
|
||||
char *nihongo = (char *) *((int *) 0x0fe8);
|
||||
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);
|
||||
@@ -118,7 +119,50 @@ void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s
|
||||
}
|
||||
if (task->langmode == 1) {
|
||||
for (; *s != 0x00; s++) {
|
||||
putfont8(vram, xsize, x, y, c, nihongo + *s * 16);
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (task->langmode == 2) {
|
||||
for (; *s != 0x00; s++) {
|
||||
if (task->langbyte1 == 0) {
|
||||
if (0x81 <= *s && *s <= 0xfe) {
|
||||
task->langbyte1 = *s;
|
||||
} else {
|
||||
putfont8(vram, xsize, x, y, c, nihongo + *s * 16);
|
||||
}
|
||||
} else {
|
||||
k = task->langbyte1 - 0xa1;
|
||||
t = *s - 0xa1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
109
28_day/haribote/ipl20.nas
Normal file
109
28_day/haribote/ipl20.nas
Normal file
@@ -0,0 +1,109 @@
|
||||
; haribote-ipl
|
||||
; TAB=4
|
||||
|
||||
CYLS EQU 20 ; 声明CYLS=20
|
||||
|
||||
ORG 0x7c00 ; 指明程序装载地址
|
||||
|
||||
; 标准FAT12格式软盘专用的代码 Stand FAT12 format floppy code
|
||||
|
||||
JMP entry
|
||||
DB 0x90
|
||||
DB "HARIBOTE" ; 启动扇区名称(8字节)
|
||||
DW 512 ; 每个扇区(sector)大小(必须512字节)
|
||||
DB 1 ; 簇(cluster)大小(必须为1个扇区)
|
||||
DW 1 ; FAT起始位置(一般为第一个扇区)
|
||||
DB 2 ; FAT个数(必须为2)
|
||||
DW 224 ; 根目录大小(一般为224项)
|
||||
DW 2880 ; 该磁盘大小(必须为2880扇区1440*1024/512)
|
||||
DB 0xf0 ; 磁盘类型(必须为0xf0)
|
||||
DW 9 ; FAT的长度(必??9扇区)
|
||||
DW 18 ; 一个磁道(track)有几个扇区(必须为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 ; 没出错则跳转到fin
|
||||
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(512/16十六进制转换)
|
||||
ADD AX,0x0020
|
||||
MOV ES,AX ; ADD ES,0x020因为没有ADD ES,只能通过AX进行
|
||||
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 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 ; 换行两次
|
||||
DB "load error"
|
||||
DB 0x0a ; 换行
|
||||
DB 0
|
||||
|
||||
RESB 0x7dfe-$ ; 填写0x00直到0x001fe
|
||||
|
||||
DB 0x55, 0xaa
|
||||
107
28_day/haribote/jp.nas
Normal file
107
28_day/haribote/jp.nas
Normal 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
|
||||
1
29_day/!cons_9x.bat
Normal file
1
29_day/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/!cons_nt.bat
Normal file
1
29_day/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
186
29_day/Makefile
Normal file
186
29_day/Makefile
Normal file
@@ -0,0 +1,186 @@
|
||||
TOOLPATH = ../z_tools/
|
||||
INCPATH = ../z_tools/haribote/
|
||||
|
||||
MAKE = $(TOOLPATH)make.exe -r
|
||||
EDIMG = $(TOOLPATH)edimg.exe
|
||||
IMGTOL = $(TOOLPATH)imgtol.com
|
||||
COPY = copy
|
||||
DEL = del
|
||||
|
||||
#默认动作
|
||||
|
||||
default :
|
||||
$(MAKE) haribote.img
|
||||
|
||||
#文件生成规则
|
||||
|
||||
haribote.img : haribote/ipl20.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 \
|
||||
type/type.hrb iroha/iroha.hrb chklang/chklang.hrb \
|
||||
notrec/notrec.hrb bball/bball.hrb invader/invader.hrb
|
||||
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
|
||||
wbinimg src:haribote/ipl20.bin len:512 from:0 to:0 \
|
||||
copy from:haribote/haribote.sys to:@: \
|
||||
copy from:haribote/jp.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:type/type.hrb to:@: \
|
||||
copy from:iroha/iroha.hrb to:@: \
|
||||
copy from:chklang/chklang.hrb to:@: \
|
||||
copy from:euc.txt to:@: \
|
||||
copy from:notrec/notrec.hrb to:@: \
|
||||
copy from:bball/bball.hrb to:@: \
|
||||
copy from:invader/invader.hrb to:@: \
|
||||
copy from:nihongo/nihongo.fnt to:@: \
|
||||
imgout:haribote.img
|
||||
|
||||
#命令
|
||||
|
||||
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 stdlib
|
||||
$(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 type
|
||||
$(MAKE) -C iroha
|
||||
$(MAKE) -C chklang
|
||||
$(MAKE) -C notrec
|
||||
$(MAKE) -C bball
|
||||
$(MAKE) -C invader
|
||||
$(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 stdlib 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 type clean
|
||||
$(MAKE) -C iroha clean
|
||||
$(MAKE) -C chklang clean
|
||||
$(MAKE) -C notrec clean
|
||||
$(MAKE) -C bball clean
|
||||
$(MAKE) -C invader clean
|
||||
|
||||
src_only_full :
|
||||
$(MAKE) -C haribote src_only
|
||||
$(MAKE) -C apilib src_only
|
||||
$(MAKE) -C stdlib 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 type src_only
|
||||
$(MAKE) -C iroha src_only
|
||||
$(MAKE) -C chklang src_only
|
||||
$(MAKE) -C notrec src_only
|
||||
$(MAKE) -C bball src_only
|
||||
$(MAKE) -C invader src_only
|
||||
-$(DEL) haribote.img
|
||||
|
||||
refresh :
|
||||
$(MAKE) full
|
||||
$(MAKE) clean_full
|
||||
-$(DEL) haribote.img
|
||||
1
29_day/a/!cons_9x.bat
Normal file
1
29_day/a/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/a/!cons_nt.bat
Normal file
1
29_day/a/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
29_day/a/Makefile
Normal file
5
29_day/a/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = a
|
||||
STACK = 1k
|
||||
MALLOC = 0k
|
||||
|
||||
include ../app_make.txt
|
||||
7
29_day/a/a.c
Normal file
7
29_day/a/a.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "apilib.h"
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
api_putchar('A');
|
||||
api_end();
|
||||
}
|
||||
1
29_day/a/make.bat
Normal file
1
29_day/a/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
27
29_day/apilib.h
Normal file
27
29_day/apilib.h
Normal file
@@ -0,0 +1,27 @@
|
||||
void api_putchar(int c);
|
||||
void api_putstr0(char *s);
|
||||
void api_putstr1(char *s, int l);
|
||||
void api_end(void);
|
||||
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
|
||||
void api_putstrwin(int win, int x, int y, int col, int len, char *str);
|
||||
void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
|
||||
void api_initmalloc(void);
|
||||
char *api_malloc(int size);
|
||||
void api_free(char *addr, int size);
|
||||
void api_point(int win, int x, int y, int col);
|
||||
void api_refreshwin(int win, int x0, int y0, int x1, int y1);
|
||||
void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
|
||||
void api_closewin(int win);
|
||||
int api_getkey(int mode);
|
||||
int api_alloctimer(void);
|
||||
void api_inittimer(int timer, int data);
|
||||
void api_settimer(int timer, int time);
|
||||
void api_freetimer(int timer);
|
||||
void api_beep(int tone);
|
||||
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);
|
||||
int api_cmdline(char *buf, int maxsize);
|
||||
int api_getlang(void);
|
||||
1
29_day/apilib/!cons_9x.bat
Normal file
1
29_day/apilib/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/apilib/!cons_nt.bat
Normal file
1
29_day/apilib/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
48
29_day/apilib/Makefile
Normal file
48
29_day/apilib/Makefile
Normal file
@@ -0,0 +1,48 @@
|
||||
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 api027.obj alloca.obj
|
||||
|
||||
TOOLPATH = ../../z_tools/
|
||||
INCPATH = ../../z_tools/haribote/
|
||||
|
||||
MAKE = $(TOOLPATH)make.exe -r
|
||||
NASK = $(TOOLPATH)nask.exe
|
||||
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
|
||||
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
|
||||
OBJ2BIM = $(TOOLPATH)obj2bim.exe
|
||||
MAKEFONT = $(TOOLPATH)makefont.exe
|
||||
BIN2OBJ = $(TOOLPATH)bin2obj.exe
|
||||
BIM2HRB = $(TOOLPATH)bim2hrb.exe
|
||||
RULEFILE = ../haribote.rul
|
||||
EDIMG = $(TOOLPATH)edimg.exe
|
||||
IMGTOL = $(TOOLPATH)imgtol.com
|
||||
GOLIB = $(TOOLPATH)golib00.exe
|
||||
COPY = copy
|
||||
DEL = del
|
||||
|
||||
#默认动作
|
||||
|
||||
default :
|
||||
$(MAKE) apilib.lib
|
||||
|
||||
#库生成规则
|
||||
|
||||
apilib.lib : Makefile $(OBJS_API)
|
||||
$(GOLIB) $(OBJS_API) out:apilib.lib
|
||||
|
||||
#文件生成规则
|
||||
|
||||
%.obj : %.nas Makefile
|
||||
$(NASK) $*.nas $*.obj $*.lst
|
||||
|
||||
#命令
|
||||
|
||||
clean :
|
||||
-$(DEL) *.lst
|
||||
-$(DEL) *.obj
|
||||
|
||||
src_only :
|
||||
$(MAKE) clean
|
||||
-$(DEL) apilib.lib
|
||||
13
29_day/apilib/alloca.nas
Normal file
13
29_day/apilib/alloca.nas
Normal file
@@ -0,0 +1,13 @@
|
||||
[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
|
||||
14
29_day/apilib/api001.nas
Normal file
14
29_day/apilib/api001.nas
Normal file
@@ -0,0 +1,14 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api001.nas"]
|
||||
|
||||
GLOBAL _api_putchar
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_putchar: ; void api_putchar(int c);
|
||||
MOV EDX,1
|
||||
MOV AL,[ESP+4] ; c
|
||||
INT 0x40
|
||||
RET
|
||||
16
29_day/apilib/api002.nas
Normal file
16
29_day/apilib/api002.nas
Normal file
@@ -0,0 +1,16 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api002.nas"]
|
||||
|
||||
GLOBAL _api_putstr0
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_putstr0: ; void api_putstr0(char *s);
|
||||
PUSH EBX
|
||||
MOV EDX,2
|
||||
MOV EBX,[ESP+8] ; s
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
17
29_day/apilib/api003.nas
Normal file
17
29_day/apilib/api003.nas
Normal file
@@ -0,0 +1,17 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api003.nas"]
|
||||
|
||||
GLOBAL _api_putstr1
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_putstr1: ; void api_putstr1(char *s, int l);
|
||||
PUSH EBX
|
||||
MOV EDX,3
|
||||
MOV EBX,[ESP+ 8] ; s
|
||||
MOV ECX,[ESP+12] ; l
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
12
29_day/apilib/api004.nas
Normal file
12
29_day/apilib/api004.nas
Normal file
@@ -0,0 +1,12 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api004.nas"]
|
||||
|
||||
GLOBAL _api_end
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_end: ; void api_end(void);
|
||||
MOV EDX,4
|
||||
INT 0x40
|
||||
24
29_day/apilib/api005.nas
Normal file
24
29_day/apilib/api005.nas
Normal file
@@ -0,0 +1,24 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api005.nas"]
|
||||
|
||||
GLOBAL _api_openwin
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_openwin: ; int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title);
|
||||
PUSH EDI
|
||||
PUSH ESI
|
||||
PUSH EBX
|
||||
MOV EDX,5
|
||||
MOV EBX,[ESP+16] ; buf
|
||||
MOV ESI,[ESP+20] ; xsiz
|
||||
MOV EDI,[ESP+24] ; ysiz
|
||||
MOV EAX,[ESP+28] ; col_inv
|
||||
MOV ECX,[ESP+32] ; title
|
||||
INT 0x40
|
||||
POP EBX
|
||||
POP ESI
|
||||
POP EDI
|
||||
RET
|
||||
27
29_day/apilib/api006.nas
Normal file
27
29_day/apilib/api006.nas
Normal file
@@ -0,0 +1,27 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api006.nas"]
|
||||
|
||||
GLOBAL _api_putstrwin
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_putstrwin: ; void api_putstrwin(int win, int x, int y, int col, int len, char *str);
|
||||
PUSH EDI
|
||||
PUSH ESI
|
||||
PUSH EBP
|
||||
PUSH EBX
|
||||
MOV EDX,6
|
||||
MOV EBX,[ESP+20] ; win
|
||||
MOV ESI,[ESP+24] ; x
|
||||
MOV EDI,[ESP+28] ; y
|
||||
MOV EAX,[ESP+32] ; col
|
||||
MOV ECX,[ESP+36] ; len
|
||||
MOV EBP,[ESP+40] ; str
|
||||
INT 0x40
|
||||
POP EBX
|
||||
POP EBP
|
||||
POP ESI
|
||||
POP EDI
|
||||
RET
|
||||
27
29_day/apilib/api007.nas
Normal file
27
29_day/apilib/api007.nas
Normal file
@@ -0,0 +1,27 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api007.nas"]
|
||||
|
||||
GLOBAL _api_boxfilwin
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_boxfilwin: ; void api_boxfilwin(int win, int x0, int y0, int x1, int y1, int col);
|
||||
PUSH EDI
|
||||
PUSH ESI
|
||||
PUSH EBP
|
||||
PUSH EBX
|
||||
MOV EDX,7
|
||||
MOV EBX,[ESP+20] ; win
|
||||
MOV EAX,[ESP+24] ; x0
|
||||
MOV ECX,[ESP+28] ; y0
|
||||
MOV ESI,[ESP+32] ; x1
|
||||
MOV EDI,[ESP+36] ; y1
|
||||
MOV EBP,[ESP+40] ; col
|
||||
INT 0x40
|
||||
POP EBX
|
||||
POP EBP
|
||||
POP ESI
|
||||
POP EDI
|
||||
RET
|
||||
20
29_day/apilib/api008.nas
Normal file
20
29_day/apilib/api008.nas
Normal file
@@ -0,0 +1,20 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api008.nas"]
|
||||
|
||||
GLOBAL _api_initmalloc
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_initmalloc: ; void api_initmalloc(void);
|
||||
PUSH EBX
|
||||
MOV EDX,8
|
||||
MOV EBX,[CS:0x0020] ; malloc内存空间的地址
|
||||
MOV EAX,EBX
|
||||
ADD EAX,32*1024 ; 加上32KB
|
||||
MOV ECX,[CS:0x0000] ; 数据段的大小
|
||||
SUB ECX,EAX
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
17
29_day/apilib/api009.nas
Normal file
17
29_day/apilib/api009.nas
Normal file
@@ -0,0 +1,17 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api009.nas"]
|
||||
|
||||
GLOBAL _api_malloc
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_malloc: ; char *api_malloc(int size);
|
||||
PUSH EBX
|
||||
MOV EDX,9
|
||||
MOV EBX,[CS:0x0020]
|
||||
MOV ECX,[ESP+8] ; size
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
18
29_day/apilib/api010.nas
Normal file
18
29_day/apilib/api010.nas
Normal file
@@ -0,0 +1,18 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api010.nas"]
|
||||
|
||||
GLOBAL _api_free
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_free: ; void api_free(char *addr, int size);
|
||||
PUSH EBX
|
||||
MOV EDX,10
|
||||
MOV EBX,[CS:0x0020]
|
||||
MOV EAX,[ESP+ 8] ; addr
|
||||
MOV ECX,[ESP+12] ; size
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
23
29_day/apilib/api011.nas
Normal file
23
29_day/apilib/api011.nas
Normal file
@@ -0,0 +1,23 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api011.nas"]
|
||||
|
||||
GLOBAL _api_point
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_point: ; void api_point(int win, int x, int y, int col);
|
||||
PUSH EDI
|
||||
PUSH ESI
|
||||
PUSH EBX
|
||||
MOV EDX,11
|
||||
MOV EBX,[ESP+16] ; win
|
||||
MOV ESI,[ESP+20] ; x
|
||||
MOV EDI,[ESP+24] ; y
|
||||
MOV EAX,[ESP+28] ; col
|
||||
INT 0x40
|
||||
POP EBX
|
||||
POP ESI
|
||||
POP EDI
|
||||
RET
|
||||
24
29_day/apilib/api012.nas
Normal file
24
29_day/apilib/api012.nas
Normal file
@@ -0,0 +1,24 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api012.nas"]
|
||||
|
||||
GLOBAL _api_refreshwin
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_refreshwin: ; void api_refreshwin(int win, int x0, int y0, int x1, int y1);
|
||||
PUSH EDI
|
||||
PUSH ESI
|
||||
PUSH EBX
|
||||
MOV EDX,12
|
||||
MOV EBX,[ESP+16] ; win
|
||||
MOV EAX,[ESP+20] ; x0
|
||||
MOV ECX,[ESP+24] ; y0
|
||||
MOV ESI,[ESP+28] ; x1
|
||||
MOV EDI,[ESP+32] ; y1
|
||||
INT 0x40
|
||||
POP EBX
|
||||
POP ESI
|
||||
POP EDI
|
||||
RET
|
||||
27
29_day/apilib/api013.nas
Normal file
27
29_day/apilib/api013.nas
Normal file
@@ -0,0 +1,27 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api013.nas"]
|
||||
|
||||
GLOBAL _api_linewin
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_linewin: ; void api_linewin(int win, int x0, int y0, int x1, int y1, int col);
|
||||
PUSH EDI
|
||||
PUSH ESI
|
||||
PUSH EBP
|
||||
PUSH EBX
|
||||
MOV EDX,13
|
||||
MOV EBX,[ESP+20] ; win
|
||||
MOV EAX,[ESP+24] ; x0
|
||||
MOV ECX,[ESP+28] ; y0
|
||||
MOV ESI,[ESP+32] ; x1
|
||||
MOV EDI,[ESP+36] ; y1
|
||||
MOV EBP,[ESP+40] ; col
|
||||
INT 0x40
|
||||
POP EBX
|
||||
POP EBP
|
||||
POP ESI
|
||||
POP EDI
|
||||
RET
|
||||
16
29_day/apilib/api014.nas
Normal file
16
29_day/apilib/api014.nas
Normal file
@@ -0,0 +1,16 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api014.nas"]
|
||||
|
||||
GLOBAL _api_closewin
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_closewin: ; void api_closewin(int win);
|
||||
PUSH EBX
|
||||
MOV EDX,14
|
||||
MOV EBX,[ESP+8] ; win
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
14
29_day/apilib/api015.nas
Normal file
14
29_day/apilib/api015.nas
Normal file
@@ -0,0 +1,14 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api015.nas"]
|
||||
|
||||
GLOBAL _api_getkey
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_getkey: ; int api_getkey(int mode);
|
||||
MOV EDX,15
|
||||
MOV EAX,[ESP+4] ; mode
|
||||
INT 0x40
|
||||
RET
|
||||
13
29_day/apilib/api016.nas
Normal file
13
29_day/apilib/api016.nas
Normal file
@@ -0,0 +1,13 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api016.nas"]
|
||||
|
||||
GLOBAL _api_alloctimer
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_alloctimer: ; int api_alloctimer(void);
|
||||
MOV EDX,16
|
||||
INT 0x40
|
||||
RET
|
||||
17
29_day/apilib/api017.nas
Normal file
17
29_day/apilib/api017.nas
Normal file
@@ -0,0 +1,17 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api017.nas"]
|
||||
|
||||
GLOBAL _api_inittimer
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_inittimer: ; void api_inittimer(int timer, int data);
|
||||
PUSH EBX
|
||||
MOV EDX,17
|
||||
MOV EBX,[ESP+ 8] ; timer
|
||||
MOV EAX,[ESP+12] ; data
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
17
29_day/apilib/api018.nas
Normal file
17
29_day/apilib/api018.nas
Normal file
@@ -0,0 +1,17 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api018.nas"]
|
||||
|
||||
GLOBAL _api_settimer
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_settimer: ; void api_settimer(int timer, int time);
|
||||
PUSH EBX
|
||||
MOV EDX,18
|
||||
MOV EBX,[ESP+ 8] ; timer
|
||||
MOV EAX,[ESP+12] ; time
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
16
29_day/apilib/api019.nas
Normal file
16
29_day/apilib/api019.nas
Normal file
@@ -0,0 +1,16 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api019.nas"]
|
||||
|
||||
GLOBAL _api_freetimer
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_freetimer: ; void api_freetimer(int timer);
|
||||
PUSH EBX
|
||||
MOV EDX,19
|
||||
MOV EBX,[ESP+ 8] ; timer
|
||||
INT 0x40
|
||||
POP EBX
|
||||
RET
|
||||
14
29_day/apilib/api020.nas
Normal file
14
29_day/apilib/api020.nas
Normal file
@@ -0,0 +1,14 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api020.nas"]
|
||||
|
||||
GLOBAL _api_beep
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_beep: ; void api_beep(int tone);
|
||||
MOV EDX,20
|
||||
MOV EAX,[ESP+4] ; tone
|
||||
INT 0x40
|
||||
RET
|
||||
16
29_day/apilib/api021.nas
Normal file
16
29_day/apilib/api021.nas
Normal file
@@ -0,0 +1,16 @@
|
||||
[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
|
||||
14
29_day/apilib/api022.nas
Normal file
14
29_day/apilib/api022.nas
Normal file
@@ -0,0 +1,14 @@
|
||||
[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
|
||||
18
29_day/apilib/api023.nas
Normal file
18
29_day/apilib/api023.nas
Normal file
@@ -0,0 +1,18 @@
|
||||
[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
|
||||
15
29_day/apilib/api024.nas
Normal file
15
29_day/apilib/api024.nas
Normal file
@@ -0,0 +1,15 @@
|
||||
[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
|
||||
18
29_day/apilib/api025.nas
Normal file
18
29_day/apilib/api025.nas
Normal file
@@ -0,0 +1,18 @@
|
||||
[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
|
||||
17
29_day/apilib/api026.nas
Normal file
17
29_day/apilib/api026.nas
Normal 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
|
||||
13
29_day/apilib/api027.nas
Normal file
13
29_day/apilib/api027.nas
Normal file
@@ -0,0 +1,13 @@
|
||||
[FORMAT "WCOFF"]
|
||||
[INSTRSET "i486p"]
|
||||
[BITS 32]
|
||||
[FILE "api027.nas"]
|
||||
|
||||
GLOBAL _api_getlang
|
||||
|
||||
[SECTION .text]
|
||||
|
||||
_api_getlang: ; int api_getlang(void);
|
||||
MOV EDX,27
|
||||
INT 0x40
|
||||
RET
|
||||
1
29_day/apilib/make.bat
Normal file
1
29_day/apilib/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
92
29_day/app_make.txt
Normal file
92
29_day/app_make.txt
Normal file
@@ -0,0 +1,92 @@
|
||||
TOOLPATH = ../../z_tools/
|
||||
INCPATH = ../../z_tools/haribote/
|
||||
APILIBPATH = ../apilib/
|
||||
STDLIBPATH = ../stdlib/
|
||||
HARIBOTEPATH = ../haribote/
|
||||
|
||||
MAKE = $(TOOLPATH)make.exe -r
|
||||
NASK = $(TOOLPATH)nask.exe
|
||||
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -I../ -Os -Wall -quiet
|
||||
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
|
||||
OBJ2BIM = $(TOOLPATH)obj2bim.exe
|
||||
MAKEFONT = $(TOOLPATH)makefont.exe
|
||||
BIN2OBJ = $(TOOLPATH)bin2obj.exe
|
||||
BIM2HRB = $(TOOLPATH)bim2hrb.exe
|
||||
BIM2BIN = $(TOOLPATH)bim2bin.exe
|
||||
RULEFILE = ../haribote.rul
|
||||
EDIMG = $(TOOLPATH)edimg.exe
|
||||
IMGTOL = $(TOOLPATH)imgtol.com
|
||||
GOLIB = $(TOOLPATH)golib00.exe
|
||||
COPY = copy
|
||||
DEL = del
|
||||
|
||||
#默认动作
|
||||
|
||||
default :
|
||||
$(MAKE) $(APP).hrb
|
||||
|
||||
#文件生成规则
|
||||
|
||||
$(APP).bim : $(APP).obj $(APILIBPATH)apilib.lib $(STDLIBPATH)stdlib.lib Makefile ../app_make.txt
|
||||
$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \
|
||||
$(APP).obj $(APILIBPATH)apilib.lib $(STDLIBPATH)stdlib.lib
|
||||
|
||||
$(STDAPP).bim : $(APP).obj $(STDLIBPATH)stdlib.lib Makefile ../app_make.txt
|
||||
$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \
|
||||
$(APP).obj $(STDLIBPATH)stdlib.lib
|
||||
|
||||
haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \
|
||||
Makefile ../app_make.txt
|
||||
$(EDIMG) imgin:../../z_tools/fdimg0at.tek \
|
||||
wbinimg src:../haribote/ipl20.bin len:512 from:0 to:0 \
|
||||
copy from:../haribote/haribote.sys to:@: \
|
||||
copy from:$(APP).hrb to:@: \
|
||||
copy from:../nihongo/nihongo.fnt to:@: \
|
||||
imgout:haribote.img
|
||||
|
||||
#一般规则
|
||||
|
||||
%.gas : %.c ../apilib.h ../stdlib.h Makefile ../app_make.txt
|
||||
$(CC1) -o $*.gas $*.c
|
||||
|
||||
%.nas : %.gas Makefile ../app_make.txt
|
||||
$(GAS2NASK) $*.gas $*.nas
|
||||
|
||||
%.obj : %.nas Makefile ../app_make.txt
|
||||
$(NASK) $*.nas $*.obj $*.lst
|
||||
|
||||
%.org : %.bim Makefile ../app_make.txt
|
||||
$(BIM2HRB) $*.bim $*.org $(MALLOC)
|
||||
|
||||
%.hrb : %.org Makefile ../app_make.txt
|
||||
$(BIM2BIN) -osacmp in:$*.org out:$*.hrb
|
||||
|
||||
#命令
|
||||
|
||||
run :
|
||||
$(MAKE) haribote.img
|
||||
$(COPY) haribote.img ..\..\z_tools\qemu\fdimage0.bin
|
||||
$(MAKE) -C ../../z_tools/qemu
|
||||
|
||||
full :
|
||||
$(MAKE) -C $(APILIBPATH)
|
||||
$(MAKE) -C $(STDLIBPATH)
|
||||
$(MAKE) $(APP).hrb
|
||||
|
||||
run_full :
|
||||
$(MAKE) -C $(APILIBPATH)
|
||||
$(MAKE) -C $(STDLIBPATH)
|
||||
$(MAKE) -C ../haribote
|
||||
$(MAKE) run
|
||||
|
||||
clean :
|
||||
-$(DEL) *.lst
|
||||
-$(DEL) *.obj
|
||||
-$(DEL) *.map
|
||||
-$(DEL) *.bim
|
||||
-$(DEL) *.org
|
||||
-$(DEL) haribote.img
|
||||
|
||||
src_only :
|
||||
$(MAKE) clean
|
||||
-$(DEL) $(APP).hrb
|
||||
1
29_day/bball/!cons_9x.bat
Normal file
1
29_day/bball/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/bball/!cons_nt.bat
Normal file
1
29_day/bball/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
29_day/bball/Makefile
Normal file
5
29_day/bball/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = bball
|
||||
STACK = 52k
|
||||
MALLOC = 0k
|
||||
|
||||
include ../app_make.txt
|
||||
37
29_day/bball/bball.c
Normal file
37
29_day/bball/bball.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "apilib.h"
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
int win, i, j, dis;
|
||||
char buf[216 * 237];
|
||||
struct POINT {
|
||||
int x, y;
|
||||
};
|
||||
static struct POINT table[16] = {
|
||||
{ 204, 129 }, { 195, 90 }, { 172, 58 }, { 137, 38 }, { 98, 34 },
|
||||
{ 61, 46 }, { 31, 73 }, { 15, 110 }, { 15, 148 }, { 31, 185 },
|
||||
{ 61, 212 }, { 98, 224 }, { 137, 220 }, { 172, 200 }, { 195, 168 },
|
||||
{ 204, 129 }
|
||||
};
|
||||
|
||||
win = api_openwin(buf, 216, 237, -1, "bball");
|
||||
api_boxfilwin(win, 8, 29, 207, 228, 0);
|
||||
for (i = 0; i <= 14; i++) {
|
||||
for (j = i + 1; j <= 15; j++) {
|
||||
dis = j - i; /*两点间的距离*/
|
||||
if (dis >= 8) {
|
||||
dis = 15 - dis; /*逆向计数*/
|
||||
}
|
||||
if (dis != 0) {
|
||||
api_linewin(win, table[i].x, table[i].y, table[j].x, table[j].y, 8 - dis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (api_getkey(1) == 0x0a) {
|
||||
break; /*按下回车键则break; */
|
||||
}
|
||||
}
|
||||
api_end();
|
||||
}
|
||||
1
29_day/bball/make.bat
Normal file
1
29_day/bball/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
1
29_day/beepdown/!cons_9x.bat
Normal file
1
29_day/beepdown/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/beepdown/!cons_nt.bat
Normal file
1
29_day/beepdown/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
29_day/beepdown/Makefile
Normal file
5
29_day/beepdown/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = beepdown
|
||||
STACK = 1k
|
||||
MALLOC = 40k
|
||||
|
||||
include ../app_make.txt
|
||||
19
29_day/beepdown/beepdown.c
Normal file
19
29_day/beepdown/beepdown.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "apilib.h"
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
int i, timer;
|
||||
timer = api_alloctimer();
|
||||
api_inittimer(timer, 128);
|
||||
for (i = 20000000; i >= 20000; i -= i / 100) {
|
||||
/* 20KHz~20Hz,即人类可以听到的声音范围*/
|
||||
/* i以1%的速度递减*/
|
||||
api_beep(i);
|
||||
api_settimer(timer, 1); /* 0.01秒*/
|
||||
if (api_getkey(1) != 128) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
api_beep(0);
|
||||
api_end();
|
||||
}
|
||||
1
29_day/beepdown/make.bat
Normal file
1
29_day/beepdown/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
1
29_day/chklang/!cons_9x.bat
Normal file
1
29_day/chklang/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/chklang/!cons_nt.bat
Normal file
1
29_day/chklang/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
29_day/chklang/Makefile
Normal file
5
29_day/chklang/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = chklang
|
||||
STACK = 1k
|
||||
MALLOC = 0k
|
||||
|
||||
include ../app_make.txt
|
||||
24
29_day/chklang/chklang.c
Normal file
24
29_day/chklang/chklang.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "apilib.h"
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
int langmode = api_getlang();
|
||||
static char s1[23] = { /* 日本語シフトJISモード(日文Shift-JIS模式)*/
|
||||
0x93, 0xfa, 0x96, 0x7b, 0x8c, 0xea, 0x83, 0x56, 0x83, 0x74, 0x83, 0x67,
|
||||
0x4a, 0x49, 0x53, 0x83, 0x82, 0x81, 0x5b, 0x83, 0x68, 0x0a, 0x00
|
||||
};
|
||||
static char s2[17] = { /*日本語EUCモード(日文EUC模式)*/
|
||||
0xc6, 0xfc, 0xcb, 0xdc, 0xb8, 0xec, 0x45, 0x55, 0x43, 0xa5, 0xe2, 0xa1,
|
||||
0xbc, 0xa5, 0xc9, 0x0a, 0x00
|
||||
};
|
||||
if (langmode == 0) {
|
||||
api_putstr0("English ASCII mode\n");
|
||||
}
|
||||
if (langmode == 1) {
|
||||
api_putstr0(s1);
|
||||
}
|
||||
if (langmode == 2) {
|
||||
api_putstr0(s2);
|
||||
}
|
||||
api_end();
|
||||
}
|
||||
1
29_day/chklang/make.bat
Normal file
1
29_day/chklang/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
1
29_day/color/!cons_9x.bat
Normal file
1
29_day/color/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/color/!cons_nt.bat
Normal file
1
29_day/color/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
29_day/color/Makefile
Normal file
5
29_day/color/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = color
|
||||
STACK = 1k
|
||||
MALLOC = 56k
|
||||
|
||||
include ../app_make.txt
|
||||
21
29_day/color/color.c
Normal file
21
29_day/color/color.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "apilib.h"
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
char *buf;
|
||||
int win, x, y, r, g, b;
|
||||
api_initmalloc();
|
||||
buf = api_malloc(144 * 164);
|
||||
win = api_openwin(buf, 144, 164, -1, "color");
|
||||
for (y = 0; y < 128; y++) {
|
||||
for (x = 0; x < 128; x++) {
|
||||
r = x * 2;
|
||||
g = y * 2;
|
||||
b = 0;
|
||||
buf[(x + 8) + (y + 28) * 144] = 16 + (r / 43) + (g / 43) * 6 + (b / 43) * 36;
|
||||
}
|
||||
}
|
||||
api_refreshwin(win, 8, 28, 136, 156);
|
||||
api_getkey(1); /*等待按下任意键*/
|
||||
api_end();
|
||||
}
|
||||
1
29_day/color/make.bat
Normal file
1
29_day/color/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
1
29_day/color2/!cons_9x.bat
Normal file
1
29_day/color2/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/color2/!cons_nt.bat
Normal file
1
29_day/color2/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
5
29_day/color2/Makefile
Normal file
5
29_day/color2/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
APP = color2
|
||||
STACK = 1k
|
||||
MALLOC = 56k
|
||||
|
||||
include ../app_make.txt
|
||||
36
29_day/color2/color2.c
Normal file
36
29_day/color2/color2.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "apilib.h"
|
||||
|
||||
unsigned char rgb2pal(int r, int g, int b, int x, int y);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
char *buf;
|
||||
int win, x, y;
|
||||
api_initmalloc();
|
||||
buf = api_malloc(144 * 164);
|
||||
win = api_openwin(buf, 144, 164, -1, "color2");
|
||||
for (y = 0; y < 128; y++) {
|
||||
for (x = 0; x < 128; x++) {
|
||||
buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y);
|
||||
}
|
||||
}
|
||||
api_refreshwin(win, 8, 28, 136, 156);
|
||||
api_getkey(1); /* <20>Ă<EFBFBD><C482>Ƃ<EFBFBD><C682>ȃL<C883>[<5B><><EFBFBD>͂<EFBFBD>҂<EFBFBD> */
|
||||
api_end();
|
||||
}
|
||||
|
||||
unsigned char rgb2pal(int r, int g, int b, int x, int y)
|
||||
{
|
||||
static int table[4] = { 3, 1, 0, 2 };
|
||||
int i;
|
||||
x &= 1; /*判断是偶数还是奇数*/
|
||||
y &= 1;
|
||||
i = table[x + y * 2]; /*用来生成中间色的常量*/
|
||||
r = (r * 21) / 256; /* r为0~20*/
|
||||
g = (g * 21) / 256;
|
||||
b = (b * 21) / 256;
|
||||
r = (r + i) / 4; /* r为0~5*/
|
||||
g = (g + i) / 4;
|
||||
b = (b + i) / 4;
|
||||
return 16 + r + g * 6 + b * 36;
|
||||
}
|
||||
1
29_day/color2/make.bat
Normal file
1
29_day/color2/make.bat
Normal file
@@ -0,0 +1 @@
|
||||
..\..\z_tools\make.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
|
||||
1
29_day/euc.txt
Normal file
1
29_day/euc.txt
Normal file
@@ -0,0 +1 @@
|
||||
日本語EUCで書いてみたよー
|
||||
10
29_day/haribote.rul
Normal file
10
29_day/haribote.rul
Normal file
@@ -0,0 +1,10 @@
|
||||
format:
|
||||
code(align:1, logic:0x24, file:0x24);
|
||||
data(align:4, logic:stack_end, file:code_end);
|
||||
|
||||
file:
|
||||
../../z_tools/haribote/harilibc.lib;
|
||||
../../z_tools/haribote/golibc.lib;
|
||||
|
||||
label:
|
||||
_HariStartup;
|
||||
1
29_day/haribote/!cons_9x.bat
Normal file
1
29_day/haribote/!cons_9x.bat
Normal file
@@ -0,0 +1 @@
|
||||
command
|
||||
1
29_day/haribote/!cons_nt.bat
Normal file
1
29_day/haribote/!cons_nt.bat
Normal file
@@ -0,0 +1 @@
|
||||
cmd.exe
|
||||
79
29_day/haribote/Makefile
Normal file
79
29_day/haribote/Makefile
Normal file
@@ -0,0 +1,79 @@
|
||||
OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \
|
||||
int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj \
|
||||
mtask.obj window.obj console.obj file.obj tek.obj
|
||||
|
||||
TOOLPATH = ../../z_tools/
|
||||
INCPATH = ../../z_tools/haribote/
|
||||
|
||||
MAKE = $(TOOLPATH)make.exe -r
|
||||
NASK = $(TOOLPATH)nask.exe
|
||||
CC1 = $(TOOLPATH)cc1.exe -I$(INCPATH) -Os -Wall -quiet
|
||||
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
|
||||
OBJ2BIM = $(TOOLPATH)obj2bim.exe
|
||||
MAKEFONT = $(TOOLPATH)makefont.exe
|
||||
BIN2OBJ = $(TOOLPATH)bin2obj.exe
|
||||
BIM2HRB = $(TOOLPATH)bim2hrb.exe
|
||||
RULEFILE = ../haribote.rul
|
||||
EDIMG = $(TOOLPATH)edimg.exe
|
||||
IMGTOL = $(TOOLPATH)imgtol.com
|
||||
GOLIB = $(TOOLPATH)golib00.exe
|
||||
COPY = copy
|
||||
DEL = del
|
||||
|
||||
#默认动作
|
||||
|
||||
default :
|
||||
$(MAKE) ipl20.bin
|
||||
$(MAKE) haribote.sys
|
||||
|
||||
# 镜像文件生成
|
||||
|
||||
ipl20.bin : ipl20.nas Makefile
|
||||
$(NASK) ipl20.nas ipl20.bin ipl20.lst
|
||||
|
||||
asmhead.bin : asmhead.nas Makefile
|
||||
$(NASK) asmhead.nas asmhead.bin asmhead.lst
|
||||
|
||||
hankaku.bin : hankaku.txt Makefile
|
||||
$(MAKEFONT) hankaku.txt hankaku.bin
|
||||
|
||||
hankaku.obj : hankaku.bin Makefile
|
||||
$(BIN2OBJ) hankaku.bin hankaku.obj _hankaku
|
||||
|
||||
bootpack.bim : $(OBJS_BOOTPACK) Makefile
|
||||
$(OBJ2BIM) @$(RULEFILE) out:bootpack.bim stack:3136k map:bootpack.map \
|
||||
$(OBJS_BOOTPACK)
|
||||
# 3MB+64KB=3136KB
|
||||
|
||||
bootpack.hrb : bootpack.bim Makefile
|
||||
$(BIM2HRB) bootpack.bim bootpack.hrb 0
|
||||
|
||||
haribote.sys : asmhead.bin bootpack.hrb Makefile
|
||||
copy /B asmhead.bin+bootpack.hrb haribote.sys
|
||||
|
||||
# 其他指令
|
||||
|
||||
%.gas : %.c bootpack.h Makefile
|
||||
$(CC1) -o $*.gas $*.c
|
||||
|
||||
%.nas : %.gas Makefile
|
||||
$(GAS2NASK) $*.gas $*.nas
|
||||
|
||||
%.obj : %.nas Makefile
|
||||
$(NASK) $*.nas $*.obj $*.lst
|
||||
|
||||
# 运行程序
|
||||
|
||||
clean :
|
||||
-$(DEL) asmhead.bin
|
||||
-$(DEL) hankaku.bin
|
||||
-$(DEL) *.lst
|
||||
-$(DEL) *.obj
|
||||
-$(DEL) *.map
|
||||
-$(DEL) *.bim
|
||||
-$(DEL) *.hrb
|
||||
|
||||
src_only :
|
||||
$(MAKE) clean
|
||||
-$(DEL) ipl20.bin
|
||||
-$(DEL) haribote.sys
|
||||
202
29_day/haribote/asmhead.nas
Normal file
202
29_day/haribote/asmhead.nas
Normal file
@@ -0,0 +1,202 @@
|
||||
; haribote-os boot asm
|
||||
; TAB=4
|
||||
|
||||
[INSTRSET "i486p"]
|
||||
|
||||
VBEMODE EQU 0x105 ; 1024 x 768 x 8bit 彩色
|
||||
; 显示模式
|
||||
; 0x100 : 640 x 400 x 8bit 彩色
|
||||
; 0x101 : 640 x 480 x 8bit 彩色
|
||||
; 0x103 : 800 x 600 x 8bit 彩色
|
||||
; 0x105 : 1024 x 768 x 8bit 彩色
|
||||
; 0x107 : 1280 x 1024 x 8bit 彩色
|
||||
|
||||
BOTPAK EQU 0x00280000 ; 加载bootpack
|
||||
DSKCAC EQU 0x00100000 ; 磁盘缓存的位置
|
||||
DSKCAC0 EQU 0x00008000 ; 磁盘缓存的位置(实模式)
|
||||
|
||||
; BOOT_INFO 相关
|
||||
CYLS EQU 0x0ff0 ; 引导扇区设置
|
||||
LEDS EQU 0x0ff1
|
||||
VMODE EQU 0x0ff2 ; 关于颜色的信息
|
||||
SCRNX EQU 0x0ff4 ; 分辨率X
|
||||
SCRNY EQU 0x0ff6 ; 分辨率Y
|
||||
VRAM EQU 0x0ff8 ; 图像缓冲区的起始地址
|
||||
|
||||
ORG 0xc200 ; 这个的程序要被装载的内存地址
|
||||
|
||||
; 确认VBE是否存在
|
||||
|
||||
MOV AX,0x9000
|
||||
MOV ES,AX
|
||||
MOV DI,0
|
||||
MOV AX,0x4f00
|
||||
INT 0x10
|
||||
CMP AX,0x004f
|
||||
JNE scrn320
|
||||
|
||||
; 检查VBE的版本
|
||||
|
||||
MOV AX,[ES:DI+4]
|
||||
CMP AX,0x0200
|
||||
JB scrn320 ; if (AX < 0x0200) goto scrn320
|
||||
|
||||
; 取得画面模式信息
|
||||
|
||||
MOV CX,VBEMODE
|
||||
MOV AX,0x4f01
|
||||
INT 0x10
|
||||
CMP AX,0x004f
|
||||
JNE scrn320
|
||||
|
||||
; 画面模式信息的确认
|
||||
CMP BYTE [ES:DI+0x19],8 ;颜色数必须为8
|
||||
JNE scrn320
|
||||
CMP BYTE [ES:DI+0x1b],4 ;颜色的指定方法必须为4(4是调色板模式)
|
||||
JNE scrn320
|
||||
MOV AX,[ES:DI+0x00] ;模式属性bit7不是1就不能加上0x4000
|
||||
AND AX,0x0080
|
||||
JZ scrn320 ; 模式属性的bit7是0,所以放弃
|
||||
|
||||
; 画面设置
|
||||
|
||||
MOV BX,VBEMODE+0x4000
|
||||
MOV AX,0x4f02
|
||||
INT 0x10
|
||||
MOV BYTE [VMODE],8 ; 屏幕的模式(参考C语言的引用)
|
||||
MOV AX,[ES:DI+0x12]
|
||||
MOV [SCRNX],AX
|
||||
MOV AX,[ES:DI+0x14]
|
||||
MOV [SCRNY],AX
|
||||
MOV EAX,[ES:DI+0x28] ;VRAM的地址
|
||||
MOV [VRAM],EAX
|
||||
JMP keystatus
|
||||
|
||||
scrn320:
|
||||
MOV AL,0x13 ; VGA图、320x200x8bit彩色
|
||||
MOV AH,0x00
|
||||
INT 0x10
|
||||
MOV BYTE [VMODE],8 ; 记下画面模式(参考C语言)
|
||||
MOV WORD [SCRNX],320
|
||||
MOV WORD [SCRNY],200
|
||||
MOV DWORD [VRAM],0x000a0000
|
||||
|
||||
; 通过 BIOS 获取指示灯状态
|
||||
|
||||
keystatus:
|
||||
MOV AH,0x02
|
||||
INT 0x16 ; keyboard BIOS
|
||||
MOV [LEDS],AL
|
||||
|
||||
; PIC关闭一切中断
|
||||
; 根据AT兼容机的规格,如果要初始化PIC,
|
||||
; 必须在CLI之前进行,否则有时会挂起。
|
||||
; 随后进行PIC的初始化。
|
||||
|
||||
MOV AL,0xff
|
||||
OUT 0x21,AL
|
||||
NOP ; 如果连续执行OUT指令,有些机种会无法正常运行
|
||||
OUT 0xa1,AL
|
||||
|
||||
CLI ; 禁止CPU级别的中断
|
||||
|
||||
; 为了让CPU能够访问1MB以上的内存空间,设定A20GATE
|
||||
|
||||
CALL waitkbdout
|
||||
MOV AL,0xd1
|
||||
OUT 0x64,AL
|
||||
CALL waitkbdout
|
||||
MOV AL,0xdf ; enable A20
|
||||
OUT 0x60,AL
|
||||
CALL waitkbdout
|
||||
|
||||
; 切换到保护模式
|
||||
|
||||
[INSTRSET "i486p"] ; 说明使用486指令
|
||||
|
||||
LGDT [GDTR0] ; 设置临时GDT
|
||||
MOV EAX,CR0
|
||||
AND EAX,0x7fffffff ; 设bit31为0(禁用分页)
|
||||
OR EAX,0x00000001 ; bit0到1转换(保护模式过渡)
|
||||
MOV CR0,EAX
|
||||
JMP pipelineflush
|
||||
pipelineflush:
|
||||
MOV AX,1*8 ; 可读写的段 32bit
|
||||
MOV DS,AX
|
||||
MOV ES,AX
|
||||
MOV FS,AX
|
||||
MOV GS,AX
|
||||
MOV SS,AX
|
||||
|
||||
; bootpack传递
|
||||
|
||||
MOV ESI,bootpack ; 转送源
|
||||
MOV EDI,BOTPAK ; 转送目标
|
||||
MOV ECX,512*1024/4
|
||||
CALL memcpy
|
||||
|
||||
; 磁盘数据最终转送到它本来的位置去
|
||||
; 首先从启动扇区开始
|
||||
|
||||
MOV ESI,0x7c00 ; 转送源
|
||||
MOV EDI,DSKCAC ; 转送目标
|
||||
MOV ECX,512/4
|
||||
CALL memcpy
|
||||
|
||||
; 剩余的全部
|
||||
|
||||
MOV ESI,DSKCAC0+512 ; 转送源
|
||||
MOV EDI,DSKCAC+512 ; 转送源目标
|
||||
MOV ECX,0
|
||||
MOV CL,BYTE [CYLS]
|
||||
IMUL ECX,512*18*2/4 ; 从柱面数变换为字节数/4
|
||||
SUB ECX,512/4 ; 减去 IPL 偏移量
|
||||
CALL memcpy
|
||||
|
||||
; 必须由asmhead来完成的工作,至此全部完毕
|
||||
; 以后就交由bootpack来完成
|
||||
|
||||
; bootpack启动
|
||||
|
||||
MOV EBX,BOTPAK
|
||||
MOV ECX,[EBX+16]
|
||||
ADD ECX,3 ; ECX += 3;
|
||||
SHR ECX,2 ; ECX /= 4;
|
||||
JZ skip ; 没有要转送的东西时
|
||||
MOV ESI,[EBX+20] ; 转送源
|
||||
ADD ESI,EBX
|
||||
MOV EDI,[EBX+12] ; 转送目标
|
||||
CALL memcpy
|
||||
skip:
|
||||
MOV ESP,[EBX+12] ; 堆栈的初始化
|
||||
JMP DWORD 2*8:0x0000001b
|
||||
|
||||
waitkbdout:
|
||||
IN AL,0x64
|
||||
AND AL,0x02
|
||||
JNZ waitkbdout ; AND的结果如果不是0,就跳到waitkbdout
|
||||
RET
|
||||
|
||||
memcpy:
|
||||
MOV EAX,[ESI]
|
||||
ADD ESI,4
|
||||
MOV [EDI],EAX
|
||||
ADD EDI,4
|
||||
SUB ECX,1
|
||||
JNZ memcpy ; 减法运算的结果如果不是0,就跳转到memcpy
|
||||
RET
|
||||
; memcpy地址前缀大小
|
||||
|
||||
ALIGNB 16
|
||||
GDT0:
|
||||
RESB 8 ; 初始值
|
||||
DW 0xffff,0x0000,0x9200,0x00cf ; 可以读写的段(segment)32bit
|
||||
DW 0xffff,0x0000,0x9a28,0x0047 ; 可执行的文件的32bit寄存器(bootpack用)
|
||||
|
||||
DW 0
|
||||
GDTR0:
|
||||
DW 8*3-1
|
||||
DD GDT0
|
||||
|
||||
ALIGNB 16
|
||||
bootpack:
|
||||
412
29_day/haribote/bootpack.c
Normal file
412
29_day/haribote/bootpack.c
Normal file
@@ -0,0 +1,412 @@
|
||||
/* bootpack */
|
||||
|
||||
#include "bootpack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define KEYCMD_LED 0xed
|
||||
|
||||
void keywin_off(struct SHEET *key_win);
|
||||
void keywin_on(struct SHEET *key_win);
|
||||
void close_console(struct SHEET *sht);
|
||||
void close_constask(struct TASK *task);
|
||||
|
||||
void HariMain(void)
|
||||
{
|
||||
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO;
|
||||
struct SHTCTL *shtctl;
|
||||
char s[40];
|
||||
struct FIFO32 fifo, keycmd;
|
||||
int fifobuf[128], keycmd_buf[32];
|
||||
int mx, my, i, new_mx = -1, new_my = 0, new_wx = 0x7fffffff, new_wy = 0;
|
||||
unsigned int memtotal;
|
||||
struct MOUSE_DEC mdec;
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
unsigned char *buf_back, buf_mouse[256];
|
||||
struct SHEET *sht_back, *sht_mouse;
|
||||
struct TASK *task_a, *task;
|
||||
static char keytable0[0x80] = {
|
||||
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '^', 0x08, 0,
|
||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '@', '[', 0x0a, 0, 'A', 'S',
|
||||
'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', ':', 0, 0, ']', 'Z', 'X', 'C', 'V',
|
||||
'B', 'N', 'M', ',', '.', '/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1',
|
||||
'2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0x5c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0
|
||||
};
|
||||
static char keytable1[0x80] = {
|
||||
0, 0, '!', 0x22, '#', '$', '%', '&', 0x27, '(', ')', '~', '=', '~', 0x08, 0,
|
||||
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '`', '{', 0x0a, 0, 'A', 'S',
|
||||
'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', '*', 0, 0, '}', 'Z', 'X', 'C', 'V',
|
||||
'B', 'N', 'M', '<', '>', '?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1',
|
||||
'2', '3', '0', '.', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, '_', 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0
|
||||
};
|
||||
int key_shift = 0, key_leds = (binfo->leds >> 4) & 7, keycmd_wait = -1;
|
||||
int j, x, y, mmx = -1, mmy = -1, mmx2 = 0;
|
||||
struct SHEET *sht = 0, *key_win, *sht2;
|
||||
int *fat;
|
||||
unsigned char *nihongo;
|
||||
struct FILEINFO *finfo;
|
||||
extern char hankaku[4096];
|
||||
|
||||
init_gdtidt();
|
||||
init_pic();
|
||||
io_sti(); /* IDT/PIC的初始化已经完成,于是开放CPU的中断 */
|
||||
fifo32_init(&fifo, 128, fifobuf, 0);
|
||||
*((int *) 0x0fec) = (int) &fifo;
|
||||
init_pit();
|
||||
init_keyboard(&fifo, 256);
|
||||
enable_mouse(&fifo, 512, &mdec);
|
||||
io_out8(PIC0_IMR, 0xf8); /* 设定PIT和PIC1以及键盘为许可(11111000) */
|
||||
io_out8(PIC1_IMR, 0xef); /* 开放鼠标中断(11101111) */
|
||||
fifo32_init(&keycmd, 32, keycmd_buf, 0);
|
||||
|
||||
memtotal = memtest(0x00400000, 0xbfffffff);
|
||||
memman_init(memman);
|
||||
memman_free(memman, 0x00001000, 0x0009e000); /* 0x00001000 - 0x0009efff */
|
||||
memman_free(memman, 0x00400000, memtotal - 0x00400000);
|
||||
|
||||
init_palette();
|
||||
shtctl = shtctl_init(memman, binfo->vram, binfo->scrnx, binfo->scrny);
|
||||
task_a = task_init(memman);
|
||||
fifo.task = task_a;
|
||||
task_run(task_a, 1, 2);
|
||||
*((int *) 0x0fe4) = (int) shtctl;
|
||||
task_a->langmode = 0;
|
||||
|
||||
/* sht_back */
|
||||
sht_back = sheet_alloc(shtctl);
|
||||
buf_back = (unsigned char *) memman_alloc_4k(memman, binfo->scrnx * binfo->scrny);
|
||||
sheet_setbuf(sht_back, buf_back, binfo->scrnx, binfo->scrny, -1); /* 无透明色 */
|
||||
init_screen8(buf_back, binfo->scrnx, binfo->scrny);
|
||||
|
||||
/* sht_cons */
|
||||
key_win = open_console(shtctl, memtotal);
|
||||
|
||||
/* sht_mouse */
|
||||
sht_mouse = sheet_alloc(shtctl);
|
||||
sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99);
|
||||
init_mouse_cursor8(buf_mouse, 99);
|
||||
mx = (binfo->scrnx - 16) / 2; /* 计算坐标使其位于画面中央 */
|
||||
my = (binfo->scrny - 28 - 16) / 2;
|
||||
|
||||
sheet_slide(sht_back, 0, 0);
|
||||
sheet_slide(key_win, 32, 4);
|
||||
sheet_slide(sht_mouse, mx, my);
|
||||
sheet_updown(sht_back, 0);
|
||||
sheet_updown(key_win, 1);
|
||||
sheet_updown(sht_mouse, 2);
|
||||
keywin_on(key_win);
|
||||
|
||||
/* 为了避免和键盘当前状态冲突,在一开始先进行设置 */
|
||||
fifo32_put(&keycmd, KEYCMD_LED);
|
||||
fifo32_put(&keycmd, key_leds);
|
||||
|
||||
/* 载入nihongo.fnt */
|
||||
fat = (int *) memman_alloc_4k(memman, 4 * 2880);
|
||||
file_readfat(fat, (unsigned char *) (ADR_DISKIMG + 0x000200));
|
||||
|
||||
finfo = file_search("nihongo.fnt", (struct FILEINFO *) (ADR_DISKIMG + 0x002600), 224);
|
||||
if (finfo != 0) {
|
||||
i = finfo->size;
|
||||
nihongo = file_loadfile2(finfo->clustno, &i, fat);
|
||||
} else {
|
||||
nihongo = (unsigned char *) memman_alloc_4k(memman, 16 * 256 + 32 * 94 * 47);
|
||||
for (i = 0; i < 16 * 256; i++) {
|
||||
nihongo[i] = hankaku[i]; /*没有字库,半角部分直接复制英文字库*/
|
||||
}
|
||||
for (i = 16 * 256; i < 16 * 256 + 32 * 94 * 47; i++) {
|
||||
nihongo[i] = 0xff; /* 没有字库,全角部分以0xff填充 */
|
||||
}
|
||||
}
|
||||
*((int *) 0x0fe8) = (int) nihongo;
|
||||
memman_free_4k(memman, (int) fat, 4 * 2880);
|
||||
|
||||
for (;;) {
|
||||
if (fifo32_status(&keycmd) > 0 && keycmd_wait < 0) {
|
||||
/* 如果存在向键盘控制器发送的数据,则发送它 */
|
||||
keycmd_wait = fifo32_get(&keycmd);
|
||||
wait_KBC_sendready();
|
||||
io_out8(PORT_KEYDAT, keycmd_wait);
|
||||
}
|
||||
io_cli();
|
||||
if (fifo32_status(&fifo) == 0) {
|
||||
/* FIFO为空,当存在搁置的绘图操作时立即执行*/
|
||||
if (new_mx >= 0) {
|
||||
io_sti();
|
||||
sheet_slide(sht_mouse, new_mx, new_my);
|
||||
new_mx = -1;
|
||||
} else if (new_wx != 0x7fffffff) {
|
||||
io_sti();
|
||||
sheet_slide(sht, new_wx, new_wy);
|
||||
new_wx = 0x7fffffff;
|
||||
} else {
|
||||
task_sleep(task_a);
|
||||
io_sti();
|
||||
}
|
||||
} else {
|
||||
i = fifo32_get(&fifo);
|
||||
io_sti();
|
||||
if (key_win != 0 && key_win->flags == 0) { /*窗口被关闭*/
|
||||
if (shtctl->top == 1) { /*当画面上只剩鼠标和背景时*/
|
||||
key_win = 0;
|
||||
} else {
|
||||
key_win = shtctl->sheets[shtctl->top - 1];
|
||||
keywin_on(key_win);
|
||||
}
|
||||
}
|
||||
if (256 <= i && i <= 511) { /* 键盘数据*/
|
||||
if (i < 0x80 + 256) { /*将按键编码转换为字符编码*/
|
||||
if (key_shift == 0) {
|
||||
s[0] = keytable0[i - 256];
|
||||
} else {
|
||||
s[0] = keytable1[i - 256];
|
||||
}
|
||||
} else {
|
||||
s[0] = 0;
|
||||
}
|
||||
if ('A' <= s[0] && s[0] <= 'Z') { /*当输入字符为英文字母时*/
|
||||
if (((key_leds & 4) == 0 && key_shift == 0) ||
|
||||
((key_leds & 4) != 0 && key_shift != 0)) {
|
||||
s[0] += 0x20; /*将大写字母转换为小写字母*/
|
||||
}
|
||||
}
|
||||
if (s[0] != 0 && key_win != 0) { /*一般字符、退格键、回车键*/
|
||||
fifo32_put(&key_win->task->fifo, s[0] + 256);
|
||||
}
|
||||
if (i == 256 + 0x0f && key_win != 0) { /* Tab键 */
|
||||
keywin_off(key_win);
|
||||
j = key_win->height - 1;
|
||||
if (j == 0) {
|
||||
j = shtctl->top - 1;
|
||||
}
|
||||
key_win = shtctl->sheets[j];
|
||||
keywin_on(key_win);
|
||||
}
|
||||
if (i == 256 + 0x2a) { /*左Shift ON */
|
||||
key_shift |= 1;
|
||||
}
|
||||
if (i == 256 + 0x36) { /*右Shift ON */
|
||||
key_shift |= 2;
|
||||
}
|
||||
if (i == 256 + 0xaa) { /*左Shift OFF */
|
||||
key_shift &= ~1;
|
||||
}
|
||||
if (i == 256 + 0xb6) { /*右Shift OFF */
|
||||
key_shift &= ~2;
|
||||
}
|
||||
if (i == 256 + 0x3a) { /* CapsLock */
|
||||
key_leds ^= 4;
|
||||
fifo32_put(&keycmd, KEYCMD_LED);
|
||||
fifo32_put(&keycmd, key_leds);
|
||||
}
|
||||
if (i == 256 + 0x45) { /* NumLock */
|
||||
key_leds ^= 2;
|
||||
fifo32_put(&keycmd, KEYCMD_LED);
|
||||
fifo32_put(&keycmd, key_leds);
|
||||
}
|
||||
if (i == 256 + 0x46) { /* ScrollLock */
|
||||
key_leds ^= 1;
|
||||
fifo32_put(&keycmd, KEYCMD_LED);
|
||||
fifo32_put(&keycmd, key_leds);
|
||||
}
|
||||
if (i == 256 + 0x3b && key_shift != 0 && key_win != 0) { /* Shift+F1 */
|
||||
task = key_win->task;
|
||||
if (task != 0 && task->tss.ss0 != 0) {
|
||||
cons_putstr0(task->cons, "\nBreak(key) :\n");
|
||||
io_cli(); /*强制结束处理时禁止任务切换*/
|
||||
task->tss.eax = (int) &(task->tss.esp0);
|
||||
task->tss.eip = (int) asm_end_app;
|
||||
io_sti();
|
||||
task_run(task, -1, 0); /*为了确实执行结束处理,如果处于休眠状态则唤醒*/
|
||||
}
|
||||
}
|
||||
if (i == 256 + 0x3c && key_shift != 0) { /* Shift+F2 */
|
||||
if (key_win != 0) {
|
||||
keywin_off(key_win);
|
||||
}
|
||||
key_win = open_console(shtctl, memtotal);
|
||||
sheet_slide(key_win, 32, 4);
|
||||
sheet_updown(key_win, shtctl->top);
|
||||
keywin_on(key_win);
|
||||
}
|
||||
if (i == 256 + 0x57) { /* F11 */
|
||||
sheet_updown(shtctl->sheets[1], shtctl->top - 1);
|
||||
}
|
||||
if (i == 256 + 0xfa) { /*键盘成功接收到数据*/
|
||||
keycmd_wait = -1;
|
||||
}
|
||||
if (i == 256 + 0xfe) { /*键盘没有成功接收到数据*/
|
||||
wait_KBC_sendready();
|
||||
io_out8(PORT_KEYDAT, keycmd_wait);
|
||||
}
|
||||
} else if (512 <= i && i <= 767) { /* 鼠标数据*/
|
||||
if (mouse_decode(&mdec, i - 512) != 0) {
|
||||
/* 已经收集了3字节的数据,移动光标 */
|
||||
mx += mdec.x;
|
||||
my += mdec.y;
|
||||
if (mx < 0) {
|
||||
mx = 0;
|
||||
}
|
||||
if (my < 0) {
|
||||
my = 0;
|
||||
}
|
||||
if (mx > binfo->scrnx - 1) {
|
||||
mx = binfo->scrnx - 1;
|
||||
}
|
||||
if (my > binfo->scrny - 1) {
|
||||
my = binfo->scrny - 1;
|
||||
}
|
||||
new_mx = mx;
|
||||
new_my = my;
|
||||
if ((mdec.btn & 0x01) != 0) { /* 按下左键 */
|
||||
if (mmx < 0) {
|
||||
/*如果处于通常模式*/
|
||||
/*按照从上到下的顺序寻找鼠标所指向的图层*/
|
||||
for (j = shtctl->top - 1; j > 0; j--) {
|
||||
sht = shtctl->sheets[j];
|
||||
x = mx - sht->vx0;
|
||||
y = my - sht->vy0;
|
||||
if (0 <= x && x < sht->bxsize && 0 <= y && y < sht->bysize) {
|
||||
if (sht->buf[y * sht->bxsize + x] != sht->col_inv) {
|
||||
sheet_updown(sht, shtctl->top - 1);
|
||||
if (sht != key_win) {
|
||||
keywin_off(key_win);
|
||||
key_win = sht;
|
||||
keywin_on(key_win);
|
||||
}
|
||||
if (3 <= x && x < sht->bxsize - 3 && 3 <= y && y < 21) {
|
||||
mmx = mx; /*进入窗口移动模式*/
|
||||
mmy = my;
|
||||
mmx2 = sht->vx0;
|
||||
new_wy = sht->vy0;
|
||||
}
|
||||
if (sht->bxsize - 21 <= x && x < sht->bxsize - 5 && 5 <= y && y < 19) {
|
||||
/*点击“×”按钮*/
|
||||
if ((sht->flags & 0x10) != 0) { /*该窗口是否为应用程序窗口?*/
|
||||
task = sht->task;
|
||||
cons_putstr0(task->cons, "\nBreak(mouse) :\n");
|
||||
io_cli(); /*强制结束处理时禁止任务切换*/
|
||||
task->tss.eax = (int) &(task->tss.esp0);
|
||||
task->tss.eip = (int) asm_end_app;
|
||||
io_sti();
|
||||
task_run(task, -1, 0);
|
||||
} else { /*命令行窗口*/
|
||||
task = sht->task;
|
||||
sheet_updown(sht, -1); /*暂且隐藏该图层*/
|
||||
keywin_off(key_win);
|
||||
key_win = shtctl->sheets[shtctl->top - 1];
|
||||
keywin_on(key_win);
|
||||
io_cli();
|
||||
fifo32_put(&task->fifo, 4);
|
||||
io_sti();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*如果处于窗口移动模式*/
|
||||
x = mx - mmx; /*计算鼠标指针移动量*/
|
||||
y = my - mmy;
|
||||
new_wx = (mmx2 + x + 2) & ~3;
|
||||
new_wy = new_wy + y;
|
||||
mmy = my;
|
||||
}
|
||||
} else {
|
||||
/*没有按下左键*/
|
||||
mmx = -1; /*切换到一般模式*/
|
||||
if (new_wx != 0x7fffffff) {
|
||||
sheet_slide(sht, new_wx, new_wy); /*固定图层位置*/
|
||||
new_wx = 0x7fffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (768 <= i && i <= 1023) { /*命令行窗口关闭处理*/
|
||||
close_console(shtctl->sheets0 + (i - 768));
|
||||
} else if (1024 <= i && i <= 2023) {
|
||||
close_constask(taskctl->tasks0 + (i - 1024));
|
||||
} else if (2024 <= i && i <= 2279) { /*只关闭命令行窗口*/
|
||||
sht2 = shtctl->sheets0 + (i - 2024);
|
||||
memman_free_4k(memman, (int) sht2->buf, 256 * 165);
|
||||
sheet_free(sht2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keywin_off(struct SHEET *key_win)
|
||||
{
|
||||
change_wtitle8(key_win, 0);
|
||||
if ((key_win->flags & 0x20) != 0) {
|
||||
fifo32_put(&key_win->task->fifo, 3); /*命令行窗口光标OFF */
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void keywin_on(struct SHEET *key_win)
|
||||
{
|
||||
change_wtitle8(key_win, 1);
|
||||
if ((key_win->flags & 0x20) != 0) {
|
||||
fifo32_put(&key_win->task->fifo, 2); /*命令行窗口光标ON */
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
struct TASK *task = task_alloc();
|
||||
int *cons_fifo = (int *) memman_alloc_4k(memman, 128 * 4);
|
||||
task->cons_stack = memman_alloc_4k(memman, 64 * 1024);
|
||||
task->tss.esp = task->cons_stack + 64 * 1024 - 12;
|
||||
task->tss.eip = (int) &console_task;
|
||||
task->tss.es = 1 * 8;
|
||||
task->tss.cs = 2 * 8;
|
||||
task->tss.ss = 1 * 8;
|
||||
task->tss.ds = 1 * 8;
|
||||
task->tss.fs = 1 * 8;
|
||||
task->tss.gs = 1 * 8;
|
||||
*((int *) (task->tss.esp + 4)) = (int) sht;
|
||||
*((int *) (task->tss.esp + 8)) = memtotal;
|
||||
task_run(task, 2, 2); /* level=2, priority=2 */
|
||||
fifo32_init(&task->fifo, 128, cons_fifo, task);
|
||||
return task;
|
||||
}
|
||||
|
||||
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
struct SHEET *sht = sheet_alloc(shtctl);
|
||||
unsigned char *buf = (unsigned char *) memman_alloc_4k(memman, 256 * 165);
|
||||
sheet_setbuf(sht, buf, 256, 165, -1); /*无透明色*/
|
||||
make_window8(buf, 256, 165, "console", 0);
|
||||
make_textbox8(sht, 8, 28, 240, 128, COL8_000000);
|
||||
sht->task = open_constask(sht, memtotal);
|
||||
sht->flags |= 0x20; /*有光标*/
|
||||
return sht;
|
||||
}
|
||||
|
||||
void close_constask(struct TASK *task)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
task_sleep(task);
|
||||
memman_free_4k(memman, task->cons_stack, 64 * 1024);
|
||||
memman_free_4k(memman, (int) task->fifo.buf, 128 * 4);
|
||||
task->flags = 0; /*用来替代task_free(task); */
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
297
29_day/haribote/bootpack.h
Normal file
297
29_day/haribote/bootpack.h
Normal file
@@ -0,0 +1,297 @@
|
||||
/* asmhead.nas */
|
||||
struct BOOTINFO { /* 0x0ff0-0x0fff */
|
||||
char cyls; /* 启动区读磁盘读到此为止 */
|
||||
char leds; /* 启动时键盘的LED的状态 */
|
||||
char vmode; /* 显卡模式为多少位彩色 */
|
||||
char reserve;
|
||||
short scrnx, scrny; /* 画面分辨率 */
|
||||
char *vram;
|
||||
};
|
||||
#define ADR_BOOTINFO 0x00000ff0
|
||||
#define ADR_DISKIMG 0x00100000
|
||||
|
||||
/* naskfunc.nas */
|
||||
void io_hlt(void);
|
||||
void io_cli(void);
|
||||
void io_sti(void);
|
||||
void io_stihlt(void);
|
||||
int io_in8(int port);
|
||||
void io_out8(int port, int data);
|
||||
int io_load_eflags(void);
|
||||
void io_store_eflags(int eflags);
|
||||
void load_gdtr(int limit, int addr);
|
||||
void load_idtr(int limit, int addr);
|
||||
int load_cr0(void);
|
||||
void store_cr0(int cr0);
|
||||
void load_tr(int tr);
|
||||
void asm_inthandler0c(void);
|
||||
void asm_inthandler0d(void);
|
||||
void asm_inthandler20(void);
|
||||
void asm_inthandler21(void);
|
||||
void asm_inthandler2c(void);
|
||||
unsigned int memtest_sub(unsigned int start, unsigned int end);
|
||||
void farjmp(int eip, int cs);
|
||||
void farcall(int eip, int cs);
|
||||
void asm_hrb_api(void);
|
||||
void start_app(int eip, int cs, int esp, int ds, int *tss_esp0);
|
||||
void asm_end_app(void);
|
||||
|
||||
/* fifo.c */
|
||||
struct FIFO32 {
|
||||
int *buf;
|
||||
int p, q, size, free, flags;
|
||||
struct TASK *task;
|
||||
};
|
||||
void fifo32_init(struct FIFO32 *fifo, int size, int *buf, struct TASK *task);
|
||||
int fifo32_put(struct FIFO32 *fifo, int data);
|
||||
int fifo32_get(struct FIFO32 *fifo);
|
||||
int fifo32_status(struct FIFO32 *fifo);
|
||||
|
||||
/* graphic.c */
|
||||
void init_palette(void);
|
||||
void set_palette(int start, int end, unsigned char *rgb);
|
||||
void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1);
|
||||
void init_screen8(char *vram, int x, int y);
|
||||
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);
|
||||
void init_mouse_cursor8(char *mouse, char bc);
|
||||
void putblock8_8(char *vram, int vxsize, int pxsize,
|
||||
int pysize, int px0, int py0, char *buf, int bxsize);
|
||||
#define COL8_000000 0
|
||||
#define COL8_FF0000 1
|
||||
#define COL8_00FF00 2
|
||||
#define COL8_FFFF00 3
|
||||
#define COL8_0000FF 4
|
||||
#define COL8_FF00FF 5
|
||||
#define COL8_00FFFF 6
|
||||
#define COL8_FFFFFF 7
|
||||
#define COL8_C6C6C6 8
|
||||
#define COL8_840000 9
|
||||
#define COL8_008400 10
|
||||
#define COL8_848400 11
|
||||
#define COL8_000084 12
|
||||
#define COL8_840084 13
|
||||
#define COL8_008484 14
|
||||
#define COL8_848484 15
|
||||
|
||||
/* dsctbl.c */
|
||||
struct SEGMENT_DESCRIPTOR {
|
||||
short limit_low, base_low;
|
||||
char base_mid, access_right;
|
||||
char limit_high, base_high;
|
||||
};
|
||||
struct GATE_DESCRIPTOR {
|
||||
short offset_low, selector;
|
||||
char dw_count, access_right;
|
||||
short offset_high;
|
||||
};
|
||||
void init_gdtidt(void);
|
||||
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar);
|
||||
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar);
|
||||
#define ADR_IDT 0x0026f800
|
||||
#define LIMIT_IDT 0x000007ff
|
||||
#define ADR_GDT 0x00270000
|
||||
#define LIMIT_GDT 0x0000ffff
|
||||
#define ADR_BOTPAK 0x00280000
|
||||
#define LIMIT_BOTPAK 0x0007ffff
|
||||
#define AR_DATA32_RW 0x4092
|
||||
#define AR_CODE32_ER 0x409a
|
||||
#define AR_LDT 0x0082
|
||||
#define AR_TSS32 0x0089
|
||||
#define AR_INTGATE32 0x008e
|
||||
|
||||
/* int.c */
|
||||
void init_pic(void);
|
||||
#define PIC0_ICW1 0x0020
|
||||
#define PIC0_OCW2 0x0020
|
||||
#define PIC0_IMR 0x0021
|
||||
#define PIC0_ICW2 0x0021
|
||||
#define PIC0_ICW3 0x0021
|
||||
#define PIC0_ICW4 0x0021
|
||||
#define PIC1_ICW1 0x00a0
|
||||
#define PIC1_OCW2 0x00a0
|
||||
#define PIC1_IMR 0x00a1
|
||||
#define PIC1_ICW2 0x00a1
|
||||
#define PIC1_ICW3 0x00a1
|
||||
#define PIC1_ICW4 0x00a1
|
||||
|
||||
/* keyboard.c */
|
||||
void inthandler21(int *esp);
|
||||
void wait_KBC_sendready(void);
|
||||
void init_keyboard(struct FIFO32 *fifo, int data0);
|
||||
#define PORT_KEYDAT 0x0060
|
||||
#define PORT_KEYCMD 0x0064
|
||||
|
||||
/* mouse.c */
|
||||
struct MOUSE_DEC {
|
||||
unsigned char buf[3], phase;
|
||||
int x, y, btn;
|
||||
};
|
||||
void inthandler2c(int *esp);
|
||||
void enable_mouse(struct FIFO32 *fifo, int data0, struct MOUSE_DEC *mdec);
|
||||
int mouse_decode(struct MOUSE_DEC *mdec, unsigned char dat);
|
||||
|
||||
/* memory.c */
|
||||
#define MEMMAN_FREES 4090 /* <20><><EFBFBD><EFBFBD>Ŗ<EFBFBD>32KB */
|
||||
#define MEMMAN_ADDR 0x003c0000
|
||||
struct FREEINFO { /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
unsigned int addr, size;
|
||||
};
|
||||
struct MEMMAN { /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǘ<EFBFBD> */
|
||||
int frees, maxfrees, lostsize, losts;
|
||||
struct FREEINFO free[MEMMAN_FREES];
|
||||
};
|
||||
unsigned int memtest(unsigned int start, unsigned int end);
|
||||
void memman_init(struct MEMMAN *man);
|
||||
unsigned int memman_total(struct MEMMAN *man);
|
||||
unsigned int memman_alloc(struct MEMMAN *man, unsigned int size);
|
||||
int memman_free(struct MEMMAN *man, unsigned int addr, unsigned int size);
|
||||
unsigned int memman_alloc_4k(struct MEMMAN *man, unsigned int size);
|
||||
int memman_free_4k(struct MEMMAN *man, unsigned int addr, unsigned int size);
|
||||
|
||||
/* sheet.c */
|
||||
#define MAX_SHEETS 256
|
||||
struct SHEET {
|
||||
unsigned char *buf;
|
||||
int bxsize, bysize, vx0, vy0, col_inv, height, flags;
|
||||
struct SHTCTL *ctl;
|
||||
struct TASK *task;
|
||||
};
|
||||
struct SHTCTL {
|
||||
unsigned char *vram, *map;
|
||||
int xsize, ysize, top;
|
||||
struct SHEET *sheets[MAX_SHEETS];
|
||||
struct SHEET sheets0[MAX_SHEETS];
|
||||
};
|
||||
struct SHTCTL *shtctl_init(struct MEMMAN *memman, unsigned char *vram, int xsize, int ysize);
|
||||
struct SHEET *sheet_alloc(struct SHTCTL *ctl);
|
||||
void sheet_setbuf(struct SHEET *sht, unsigned char *buf, int xsize, int ysize, int col_inv);
|
||||
void sheet_updown(struct SHEET *sht, int height);
|
||||
void sheet_refresh(struct SHEET *sht, int bx0, int by0, int bx1, int by1);
|
||||
void sheet_slide(struct SHEET *sht, int vx0, int vy0);
|
||||
void sheet_free(struct SHEET *sht);
|
||||
|
||||
/* timer.c */
|
||||
#define MAX_TIMER 500
|
||||
struct TIMER {
|
||||
struct TIMER *next;
|
||||
unsigned int timeout;
|
||||
char flags, flags2;
|
||||
struct FIFO32 *fifo;
|
||||
int data;
|
||||
};
|
||||
struct TIMERCTL {
|
||||
unsigned int count, next;
|
||||
struct TIMER *t0;
|
||||
struct TIMER timers0[MAX_TIMER];
|
||||
};
|
||||
extern struct TIMERCTL timerctl;
|
||||
void init_pit(void);
|
||||
struct TIMER *timer_alloc(void);
|
||||
void timer_free(struct TIMER *timer);
|
||||
void timer_init(struct TIMER *timer, struct FIFO32 *fifo, int data);
|
||||
void timer_settime(struct TIMER *timer, unsigned int timeout);
|
||||
void inthandler20(int *esp);
|
||||
int timer_cancel(struct TIMER *timer);
|
||||
void timer_cancelall(struct FIFO32 *fifo);
|
||||
|
||||
/* mtask.c */
|
||||
#define MAX_TASKS 1000 /*最大任务数量*/
|
||||
#define TASK_GDT0 3 /*定义从GDT的几号开始分配给TSS */
|
||||
#define MAX_TASKS_LV 100
|
||||
#define MAX_TASKLEVELS 10
|
||||
struct TSS32 {
|
||||
int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3;
|
||||
int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
|
||||
int es, cs, ss, ds, fs, gs;
|
||||
int ldtr, iomap;
|
||||
};
|
||||
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;
|
||||
unsigned char langmode, langbyte1;
|
||||
};
|
||||
struct TASKLEVEL {
|
||||
int running; /*正在运行的任务数量*/
|
||||
int now; /*这个变量用来记录当前正在运行的是哪个任务*/
|
||||
struct TASK *tasks[MAX_TASKS_LV];
|
||||
};
|
||||
struct TASKCTL {
|
||||
int now_lv; /*现在活动中的LEVEL */
|
||||
char lv_change; /*在下次任务切换时是否需要改变LEVEL */
|
||||
struct TASKLEVEL level[MAX_TASKLEVELS];
|
||||
struct TASK tasks0[MAX_TASKS];
|
||||
};
|
||||
extern struct TASKCTL *taskctl;
|
||||
extern struct TIMER *task_timer;
|
||||
struct TASK *task_now(void);
|
||||
struct TASK *task_init(struct MEMMAN *memman);
|
||||
struct TASK *task_alloc(void);
|
||||
void task_run(struct TASK *task, int level, int priority);
|
||||
void task_switch(void);
|
||||
void task_sleep(struct TASK *task);
|
||||
|
||||
/* window.c */
|
||||
void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act);
|
||||
void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l);
|
||||
void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c);
|
||||
void make_wtitle8(unsigned char *buf, int xsize, char *title, char act);
|
||||
void change_wtitle8(struct SHEET *sht, char act);
|
||||
|
||||
/* 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;
|
||||
};
|
||||
void console_task(struct SHEET *sheet, int memtotal);
|
||||
void cons_putchar(struct CONSOLE *cons, int chr, char move);
|
||||
void cons_newline(struct CONSOLE *cons);
|
||||
void cons_putstr0(struct CONSOLE *cons, char *s);
|
||||
void cons_putstr1(struct CONSOLE *cons, char *s, int l);
|
||||
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_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);
|
||||
int *inthandler0c(int *esp);
|
||||
void hrb_api_linewin(struct SHEET *sht, int x0, int y0, int x1, int y1, int col);
|
||||
|
||||
/* file.c */
|
||||
struct FILEINFO {
|
||||
unsigned char name[8], ext[3], type;
|
||||
char reserve[10];
|
||||
unsigned short time, date, clustno;
|
||||
unsigned int size;
|
||||
};
|
||||
void file_readfat(int *fat, unsigned char *img);
|
||||
void file_loadfile(int clustno, int size, char *buf, int *fat, char *img);
|
||||
struct FILEINFO *file_search(char *name, struct FILEINFO *finfo, int max);
|
||||
char *file_loadfile2(int clustno, int *psize, int *fat);
|
||||
|
||||
/* bootpack.c */
|
||||
struct TASK *open_constask(struct SHEET *sht, unsigned int memtotal);
|
||||
struct SHEET *open_console(struct SHTCTL *shtctl, unsigned int memtotal);
|
||||
|
||||
/* tek.c */
|
||||
int tek_getsize(unsigned char *p);
|
||||
int tek_decomp(unsigned char *p, char *q, int size);
|
||||
708
29_day/haribote/console.c
Normal file
708
29_day/haribote/console.c
Normal file
@@ -0,0 +1,708 @@
|
||||
/* 命令行窗口相关 */
|
||||
|
||||
#include "bootpack.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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 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();
|
||||
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;
|
||||
}
|
||||
task->langbyte1 = 0;
|
||||
|
||||
/*显示提示符*/
|
||||
cons_putchar(&cons, '>', 1);
|
||||
|
||||
for (;;) {
|
||||
io_cli();
|
||||
if (fifo32_status(&task->fifo) == 0) {
|
||||
task_sleep(task);
|
||||
io_sti();
|
||||
} else {
|
||||
i = fifo32_get(&task->fifo);
|
||||
io_sti();
|
||||
if (i <= 1 && cons.sht != 0) { /*光标用定时器*/
|
||||
if (i != 0) {
|
||||
timer_init(cons.timer, &task->fifo, 0); /*下次置0 */
|
||||
if (cons.cur_c >= 0) {
|
||||
cons.cur_c = COL8_FFFFFF;
|
||||
}
|
||||
} else {
|
||||
timer_init(cons.timer, &task->fifo, 1); /*下次置1 */
|
||||
if (cons.cur_c >= 0) {
|
||||
cons.cur_c = COL8_000000;
|
||||
}
|
||||
}
|
||||
timer_settime(cons.timer, 50);
|
||||
}
|
||||
if (i == 2) { /*光标ON */
|
||||
cons.cur_c = COL8_FFFFFF;
|
||||
}
|
||||
if (i == 3) { /*光标OFF */
|
||||
if (cons.sht != 0) {
|
||||
boxfill8(cons.sht->buf, cons.sht->bxsize, COL8_000000,
|
||||
cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
|
||||
}
|
||||
cons.cur_c = -1;
|
||||
}
|
||||
if (i == 4) { /*点击命令行窗口的“×”按钮*/
|
||||
cmd_exit(&cons, fat);
|
||||
}
|
||||
if (256 <= i && i <= 511) { /*键盘数据(通过任务A)*/
|
||||
if (i == 8 + 256) {
|
||||
/*退格键*/
|
||||
if (cons.cur_x > 16) {
|
||||
/*用空格擦除光标后将光标前移一位*/
|
||||
cons_putchar(&cons, ' ', 0);
|
||||
cons.cur_x -= 8;
|
||||
}
|
||||
} else if (i == 10 + 256) {
|
||||
/*回车键*/
|
||||
/*将光标用空格擦除后换行 */
|
||||
cons_putchar(&cons, ' ', 0);
|
||||
cmdline[cons.cur_x / 8 - 2] = 0;
|
||||
cons_newline(&cons);
|
||||
cons_runcmd(cmdline, &cons, fat, memtotal); /*运行命令*/
|
||||
if (cons.sht == 0) {
|
||||
cmd_exit(&cons, fat);
|
||||
}
|
||||
/*显示提示符*/
|
||||
cons_putchar(&cons, '>', 1);
|
||||
} else {
|
||||
/*一般字符*/
|
||||
if (cons.cur_x < 240) {
|
||||
/*显示一个字符之后将光标后移一位*/
|
||||
cmdline[cons.cur_x / 8 - 2] = i - 256;
|
||||
cons_putchar(&cons, i - 256, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*重新显示光标*/
|
||||
if (cons.sht != 0) {
|
||||
if (cons.cur_c >= 0) {
|
||||
boxfill8(cons.sht->buf, cons.sht->bxsize, cons.cur_c,
|
||||
cons.cur_x, cons.cur_y, cons.cur_x + 7, cons.cur_y + 15);
|
||||
}
|
||||
sheet_refresh(cons.sht, cons.cur_x, cons.cur_y, cons.cur_x + 8, cons.cur_y + 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cons_putchar(struct CONSOLE *cons, int chr, char move)
|
||||
{
|
||||
char s[2];
|
||||
s[0] = chr;
|
||||
s[1] = 0;
|
||||
if (s[0] == 0x09) { /*制表符*/
|
||||
for (;;) {
|
||||
if (cons->sht != 0) {
|
||||
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, " ", 1);
|
||||
}
|
||||
cons->cur_x += 8;
|
||||
if (cons->cur_x == 8 + 240) {
|
||||
cons_newline(cons);
|
||||
}
|
||||
if (((cons->cur_x - 8) & 0x1f) == 0) {
|
||||
break; /*被32整除则break*/
|
||||
}
|
||||
}
|
||||
} else if (s[0] == 0x0a) { /*换行*/
|
||||
cons_newline(cons);
|
||||
} else if (s[0] == 0x0d) { /*回车*/
|
||||
/*先不做任何操作*/
|
||||
} else { /*一般字符*/
|
||||
if (cons->sht != 0) {
|
||||
putfonts8_asc_sht(cons->sht, cons->cur_x, cons->cur_y, COL8_FFFFFF, COL8_000000, s, 1);
|
||||
}
|
||||
if (move != 0) {
|
||||
/* move为0时光标不后移*/
|
||||
cons->cur_x += 8;
|
||||
if (cons->cur_x == 8 + 240) {
|
||||
cons_newline(cons);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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 {
|
||||
/*滚动*/
|
||||
if (sheet != 0) {
|
||||
for (y = 28; y < 28 + 112; y++) {
|
||||
for (x = 8; x < 8 + 240; x++) {
|
||||
sheet->buf[x + y * sheet->bxsize] = sheet->buf[x + (y + 16) * sheet->bxsize];
|
||||
}
|
||||
}
|
||||
for (y = 28 + 112; y < 28 + 128; y++) {
|
||||
for (x = 8; x < 8 + 240; x++) {
|
||||
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
|
||||
}
|
||||
}
|
||||
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
|
||||
}
|
||||
}
|
||||
cons->cur_x = 8;
|
||||
if (task->langmode == 1 && task->langbyte1 != 0) {
|
||||
cons->cur_x += 8;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cons_putstr0(struct CONSOLE *cons, char *s)
|
||||
{
|
||||
for (; *s != 0; s++) {
|
||||
cons_putchar(cons, *s, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void cons_putstr1(struct CONSOLE *cons, char *s, int l)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < l; i++) {
|
||||
cons_putchar(cons, s[i], 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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 || strcmp(cmdline, "ls") == 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_mem(struct CONSOLE *cons, int memtotal)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
char s[60];
|
||||
sprintf(s, "total %dMB\nfree %dKB\n\n", memtotal / (1024 * 1024), memman_total(memman) / 1024);
|
||||
cons_putstr0(cons, s);
|
||||
return;
|
||||
}
|
||||
|
||||
void cmd_cls(struct CONSOLE *cons)
|
||||
{
|
||||
int x, y;
|
||||
struct SHEET *sheet = cons->sht;
|
||||
for (y = 28; y < 28 + 128; y++) {
|
||||
for (x = 8; x < 8 + 240; x++) {
|
||||
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
|
||||
}
|
||||
}
|
||||
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
|
||||
cons->cur_y = 28;
|
||||
return;
|
||||
}
|
||||
|
||||
void cmd_dir(struct CONSOLE *cons)
|
||||
{
|
||||
struct FILEINFO *finfo = (struct FILEINFO *) (ADR_DISKIMG + 0x002600);
|
||||
int i, j;
|
||||
char s[30];
|
||||
for (i = 0; i < 224; i++) {
|
||||
if (finfo[i].name[0] == 0x00) {
|
||||
break;
|
||||
}
|
||||
if (finfo[i].name[0] != 0xe5) {
|
||||
if ((finfo[i].type & 0x18) == 0) {
|
||||
sprintf(s, "filename.ext %7d\n", finfo[i].size);
|
||||
for (j = 0; j < 8; j++) {
|
||||
s[j] = finfo[i].name[j];
|
||||
}
|
||||
s[ 9] = finfo[i].ext[0];
|
||||
s[10] = finfo[i].ext[1];
|
||||
s[11] = finfo[i].ext[2];
|
||||
cons_putstr0(cons, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
cons_newline(cons);
|
||||
return;
|
||||
}
|
||||
|
||||
void cmd_exit(struct CONSOLE *cons, int *fat)
|
||||
{
|
||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||
struct TASK *task = task_now();
|
||||
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
|
||||
struct FIFO32 *fifo = (struct FIFO32 *) *((int *) 0x0fec);
|
||||
if (cons->sht != 0) {
|
||||
timer_cancel(cons->timer);
|
||||
}
|
||||
memman_free_4k(memman, (int) fat, 4 * 2880);
|
||||
io_cli();
|
||||
if (cons->sht != 0) {
|
||||
fifo32_put(fifo, cons->sht - shtctl->sheets0 + 768); /* 768〜1023 */
|
||||
} else {
|
||||
fifo32_put(fifo, task - taskctl->tasks0 + 1024); /*1024~2023*/
|
||||
}
|
||||
io_sti();
|
||||
for (;;) {
|
||||
task_sleep(task);
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_start(struct CONSOLE *cons, char *cmdline, int memtotal)
|
||||
{
|
||||
struct SHTCTL *shtctl = (struct SHTCTL *) *((int *) 0x0fe4);
|
||||
struct SHEET *sht = open_console(shtctl, memtotal);
|
||||
struct FIFO32 *fifo = &sht->task->fifo;
|
||||
int i;
|
||||
sheet_slide(sht, 32, 4);
|
||||
sheet_updown(sht, shtctl->top);
|
||||
/*将命令行输入的字符串逐字复制到新的命令行窗口中*/
|
||||
for (i = 6; cmdline[i] != 0; i++) {
|
||||
fifo32_put(fifo, cmdline[i] + 256);
|
||||
}
|
||||
fifo32_put(fifo, 10 + 256); /*回车键*/
|
||||
cons_newline(cons);
|
||||
return;
|
||||
}
|
||||
|
||||
void cmd_ncst(struct CONSOLE *cons, char *cmdline, int memtotal)
|
||||
{
|
||||
struct TASK *task = open_constask(0, memtotal);
|
||||
struct FIFO32 *fifo = &task->fifo;
|
||||
int i;
|
||||
|
||||
/*将命令行输入的字符串逐字复制到新的命令行窗口中*/
|
||||
for (i = 5; cmdline[i] != 0; i++) {
|
||||
fifo32_put(fifo, cmdline[i] + 256);
|
||||
}
|
||||
fifo32_put(fifo, 10 + 256); /*回车键*/
|
||||
cons_newline(cons);
|
||||
return;
|
||||
}
|
||||
|
||||
void cmd_langmode(struct CONSOLE *cons, char *cmdline)
|
||||
{
|
||||
struct TASK *task = task_now();
|
||||
unsigned char mode = cmdline[9] - '0';
|
||||
if (mode <= 2) {
|
||||
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;
|
||||
struct FILEINFO *finfo;
|
||||
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
|
||||
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, 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);
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
} 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) { /*光标用定时器*/
|
||||
/*应用程序运行时不需要显示光标,因此总是将下次显示用的值置为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_loadfile2(finfo->clustno, &fh->size, task->fat);
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
} else if (edx == 27) {
|
||||
reg[7] = task->langmode;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int *inthandler0c(int *esp)
|
||||
{
|
||||
struct TASK *task = task_now();
|
||||
struct CONSOLE *cons = task->cons;
|
||||
char s[30];
|
||||
cons_putstr0(cons, "\nINT 0C :\n Stack Exception.\n");
|
||||
sprintf(s, "EIP = %08X\n", esp[11]);
|
||||
cons_putstr0(cons, s);
|
||||
return &(task->tss.esp0); /*强制结束程序*/
|
||||
}
|
||||
|
||||
int *inthandler0d(int *esp)
|
||||
{
|
||||
struct TASK *task = task_now();
|
||||
struct CONSOLE *cons = task->cons;
|
||||
char s[30];
|
||||
cons_putstr0(cons, "\nINT 0D :\n General Protected Exception.\n");
|
||||
sprintf(s, "EIP = %08X\n", esp[11]);
|
||||
cons_putstr0(cons, s);
|
||||
return &(task->tss.esp0); /*强制结束程序*/
|
||||
}
|
||||
|
||||
void hrb_api_linewin(struct SHEET *sht, int x0, int y0, int x1, int y1, int col)
|
||||
{
|
||||
int i, x, y, len, dx, dy;
|
||||
|
||||
dx = x1 - x0;
|
||||
dy = y1 - y0;
|
||||
x = x0 << 10;
|
||||
y = y0 << 10;
|
||||
if (dx < 0) {
|
||||
dx = - dx;
|
||||
}
|
||||
if (dy < 0) {
|
||||
dy = - dy;
|
||||
}
|
||||
if (dx >= dy) {
|
||||
len = dx + 1;
|
||||
if (x0 > x1) {
|
||||
dx = -1024;
|
||||
} else {
|
||||
dx = 1024;
|
||||
}
|
||||
if (y0 <= y1) {
|
||||
dy = ((y1 - y0 + 1) << 10) / len;
|
||||
} else {
|
||||
dy = ((y1 - y0 - 1) << 10) / len;
|
||||
}
|
||||
} else {
|
||||
len = dy + 1;
|
||||
if (y0 > y1) {
|
||||
dy = -1024;
|
||||
} else {
|
||||
dy = 1024;
|
||||
}
|
||||
if (x0 <= x1) {
|
||||
dx = ((x1 - x0 + 1) << 10) / len;
|
||||
} else {
|
||||
dx = ((x1 - x0 - 1) << 10) / len;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
sht->buf[(y >> 10) * sht->bxsize + (x >> 10)] = col;
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
59
29_day/haribote/dsctbl.c
Normal file
59
29_day/haribote/dsctbl.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* GDT、IDT、descriptor table 关系处理 */
|
||||
|
||||
#include "bootpack.h"
|
||||
|
||||
void init_gdtidt(void)
|
||||
{
|
||||
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
|
||||
struct GATE_DESCRIPTOR *idt = (struct GATE_DESCRIPTOR *) ADR_IDT;
|
||||
int i;
|
||||
|
||||
/* GDT初始化 */
|
||||
for (i = 0; i <= LIMIT_GDT / 8; i++) {
|
||||
set_segmdesc(gdt + i, 0, 0, 0);
|
||||
}
|
||||
set_segmdesc(gdt + 1, 0xffffffff, 0x00000000, AR_DATA32_RW);
|
||||
set_segmdesc(gdt + 2, LIMIT_BOTPAK, ADR_BOTPAK, AR_CODE32_ER);
|
||||
load_gdtr(LIMIT_GDT, ADR_GDT);
|
||||
|
||||
/* IDT初始化 */
|
||||
for (i = 0; i <= LIMIT_IDT / 8; i++) {
|
||||
set_gatedesc(idt + i, 0, 0, 0);
|
||||
}
|
||||
load_idtr(LIMIT_IDT, ADR_IDT);
|
||||
|
||||
/* IDT设置*/
|
||||
set_gatedesc(idt + 0x0c, (int) asm_inthandler0c, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x0d, (int) asm_inthandler0d, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);
|
||||
set_gatedesc(idt + 0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32 + 0x60);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void set_segmdesc(struct SEGMENT_DESCRIPTOR *sd, unsigned int limit, int base, int ar)
|
||||
{
|
||||
if (limit > 0xfffff) {
|
||||
ar |= 0x8000; /* G_bit = 1 */
|
||||
limit /= 0x1000;
|
||||
}
|
||||
sd->limit_low = limit & 0xffff;
|
||||
sd->base_low = base & 0xffff;
|
||||
sd->base_mid = (base >> 16) & 0xff;
|
||||
sd->access_right = ar & 0xff;
|
||||
sd->limit_high = ((limit >> 16) & 0x0f) | ((ar >> 8) & 0xf0);
|
||||
sd->base_high = (base >> 24) & 0xff;
|
||||
return;
|
||||
}
|
||||
|
||||
void set_gatedesc(struct GATE_DESCRIPTOR *gd, int offset, int selector, int ar)
|
||||
{
|
||||
gd->offset_low = offset & 0xffff;
|
||||
gd->selector = selector;
|
||||
gd->dw_count = (ar >> 8) & 0xff;
|
||||
gd->access_right = ar & 0xff;
|
||||
gd->offset_high = (offset >> 16) & 0xffff;
|
||||
return;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user