Skip to content

Commit febac10

Browse files
committed
IPL的改良
1 parent 0e31ff0 commit febac10

File tree

5 files changed

+174
-10
lines changed

5 files changed

+174
-10
lines changed

30_day/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default :
1414

1515
#文件生成规则
1616

17-
haribote.img : haribote/ipl20.bin haribote/haribote.sys Makefile \
17+
haribote.img : haribote/ipl10.bin haribote/haribote.sys Makefile \
1818
a/a.hrb hello3/hello3.hrb hello4/hello4.hrb hello5/hello5.hrb \
1919
winhelo/winhelo.hrb winhelo2/winhelo2.hrb winhelo3/winhelo3.hrb \
2020
star1/star1.hrb stars/stars.hrb stars2/stars2.hrb \
@@ -25,7 +25,7 @@ haribote.img : haribote/ipl20.bin haribote/haribote.sys Makefile \
2525
notrec/notrec.hrb bball/bball.hrb invader/invader.hrb \
2626
calc/calc.hrb tview/tview.hrb mmlplay/mmlplay.hrb gview/gview.hrb
2727
$(EDIMG) imgin:../z_tools/fdimg0at.tek \
28-
wbinimg src:haribote/ipl20.bin len:512 from:0 to:0 \
28+
wbinimg src:haribote/ipl10.bin len:512 from:0 to:0 \
2929
copy from:haribote/haribote.sys to:@: \
3030
copy from:haribote/jp.nas to:@: \
3131
copy from:make.bat to:@: \

30_day/app_make.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ $(STDAPP).bim : $(APP).obj $(STDLIBPATH)stdlib.lib Makefile ../app_make.txt
3535
$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \
3636
$(APP).obj $(STDLIBPATH)stdlib.lib
3737

38-
haribote.img : ../haribote/ipl20.bin ../haribote/haribote.sys $(APP).hrb \
38+
haribote.img : ../haribote/ipl10.bin ../haribote/haribote.sys $(APP).hrb \
3939
Makefile ../app_make.txt
4040
$(EDIMG) imgin:../../z_tools/fdimg0at.tek \
41-
wbinimg src:../haribote/ipl20.bin len:512 from:0 to:0 \
41+
wbinimg src:../haribote/ipl10.bin len:512 from:0 to:0 \
4242
copy from:../haribote/haribote.sys to:@: \
4343
copy from:$(APP).hrb to:@: \
4444
copy from:../nihongo/nihongo.fnt to:@: \

30_day/haribote/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ DEL = del
2323
#默认动作
2424

2525
default :
26-
$(MAKE) ipl20.bin
26+
$(MAKE) ipl10.bin
2727
$(MAKE) haribote.sys
2828

2929
# 镜像文件生成
3030

31-
ipl20.bin : ipl20.nas Makefile
32-
$(NASK) ipl20.nas ipl20.bin ipl20.lst
31+
ipl10.bin : ipl10.nas Makefile
32+
$(NASK) ipl10.nas ipl10.bin ipl10.lst
3333

3434
asmhead.bin : asmhead.nas Makefile
3535
$(NASK) asmhead.nas asmhead.bin asmhead.lst
@@ -75,5 +75,5 @@ clean :
7575

7676
src_only :
7777
$(MAKE) clean
78-
-$(DEL) ipl20.bin
78+
-$(DEL) ipl10.bin
7979
-$(DEL) haribote.sys

30_day/haribote/ipl10.nas

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
; haribote-ipl
2+
; TAB=4
3+
4+
CYLS EQU 10 ; 声明CYLS=10
5+
6+
ORG 0x7c00 ; 指明程序装载地址
7+
8+
; 标准FAT12格式软盘专用的代码 Stand FAT12 format floppy code
9+
10+
JMP entry
11+
DB 0x90
12+
DB "HARIBOTE" ; 启动扇区名称(8字节)
13+
DW 512 ; 每个扇区(sector)大小(必须512字节)
14+
DB 1 ; 簇(cluster)大小(必须为1个扇区)
15+
DW 1 ; FAT起始位置(一般为第一个扇区)
16+
DB 2 ; FAT个数(必须为2)
17+
DW 224 ; 根目录大小(一般为224项)
18+
DW 2880 ; 该磁盘大小(必须为2880扇区1440*1024/512)
19+
DB 0xf0 ; 磁盘类型(必须为0xf0)
20+
DW 9 ; FAT的长度(必9扇区)
21+
DW 18 ; 一个磁道(track)有几个扇区(必须为18)
22+
DW 2 ; 磁头数(必2)
23+
DD 0 ; 不使用分区,必须是0
24+
DD 2880 ; 重写一次磁盘大小
25+
DB 0,0,0x29 ; 意义不明(固定)
26+
DD 0xffffffff ; (可能是)卷标号码
27+
DB "HARIBOTEOS " ; 磁盘的名称(必须为11字?,不足填空格)
28+
DB "FAT12 " ; 磁盘格式名称(必??8字?,不足填空格)
29+
RESB 18 ; 先空出18字节
30+
31+
; 程序主体
32+
33+
entry:
34+
MOV AX,0 ; 初始化寄存器
35+
MOV SS,AX
36+
MOV SP,0x7c00
37+
MOV DS,AX
38+
39+
; 读取磁盘
40+
41+
MOV AX,0x0820
42+
MOV ES,AX
43+
MOV CH,0 ; 柱面0
44+
MOV DH,0 ; 磁头0
45+
MOV CL,2 ; 扇区2
46+
MOV BX,18*2*CYLS-1 ; 要读取的合计扇区数
47+
CALL readfast ; 告诉读取
48+
49+
; 读取完毕,跳转到haribote.sys执行!
50+
MOV [0x0ff0],CH ; 记录IPL实际读取了多少内容
51+
JMP 0xc200
52+
53+
error:
54+
MOV AX,0
55+
MOV ES,AX
56+
MOV SI,msg
57+
putloop:
58+
MOV AL,[SI]
59+
ADD SI,1 ; 给SI加1
60+
CMP AL,0
61+
JE fin
62+
MOV AH,0x0e ; 显示一个文字
63+
MOV BX,15 ; 指定字符颜色
64+
INT 0x10 ; 调用显卡BIOS
65+
JMP putloop
66+
fin:
67+
HLT ; 让CPU停止,等待指令
68+
JMP fin ; 无限循环
69+
msg:
70+
DB 0x0a, 0x0a ; 换行两次
71+
DB "load error"
72+
DB 0x0a ; 换行
73+
DB 0
74+
75+
readfast: ; 使用AL尽量一次性读取数据 从此开始
76+
; ES:读取地址, CH:柱面, DH:磁头, CL:扇区, BX:读取扇区数
77+
78+
MOV AX,ES ; < 通过ES计算AL的最大值 >
79+
SHL AX,3 ; 将AX除以32,将结果存入AH(SHL是左移位指令)
80+
AND AH,0x7f ; AH是AH除以128所得的余数(512*128=64K)
81+
MOV AL,128 ; AL = 128 - AH; AH是AH除以128所得的余数(512*128=64K)
82+
SUB AL,AH
83+
84+
MOV AH,BL ; < 通过BX计算AL的最大值并存入AH >
85+
CMP BH,0 ; if (BH != 0) { AH = 18; }
86+
JE .skip1
87+
MOV AH,18
88+
.skip1:
89+
CMP AL,AH ; if (AL > AH) { AL = AH; }
90+
JBE .skip2
91+
MOV AL,AH
92+
.skip2:
93+
94+
MOV AH,19 ; < 通过CL计算AL的最大值并存入AH >
95+
SUB AH,CL ; AH = 19 - CL;
96+
CMP AL,AH ; if (AL > AH) { AL = AH; }
97+
JBE .skip3
98+
MOV AL,AH
99+
.skip3:
100+
101+
PUSH BX
102+
MOV SI,0 ; 计算失败次数的寄存器
103+
retry:
104+
MOV AH,0x02 ; AH=0x02 : 读取磁盘
105+
MOV BX,0
106+
MOV DL,0x00 ; A盘
107+
PUSH ES
108+
PUSH DX
109+
PUSH CX
110+
PUSH AX
111+
INT 0x13 ; 调用磁盘BIOS
112+
JNC next ; 没有出错的话则跳转至next
113+
ADD SI,1 ; 将SI加1
114+
CMP SI,5 ; 将SI与5比较
115+
JAE error ; SI >= 5则跳转至error
116+
MOV AH,0x00
117+
MOV DL,0x00 ; A盘
118+
INT 0x13 ; 驱动器重置
119+
POP AX
120+
POP CX
121+
POP DX
122+
POP ES
123+
JMP retry
124+
next:
125+
POP AX
126+
POP CX
127+
POP DX
128+
POP BX ; 将ES的内容存入BX
129+
SHR BX,5 ; 将BX由16字节为单位转换为512字节为单位
130+
MOV AH,0
131+
ADD BX,AX ; BX += AL;
132+
SHL BX,5 ; 将BX由512字节为单位转换为16字节为单位
133+
MOV ES,BX ; 相当于EX += AL * 0x20;
134+
POP BX
135+
SUB BX,AX
136+
JZ .ret
137+
ADD CL,AL ; 将CL加上AL
138+
CMP CL,18 ; 将CL与18比较
139+
JBE readfast ; CL <= 18则跳转至readfast
140+
MOV CL,1
141+
ADD DH,1
142+
CMP DH,2
143+
JB readfast ; DH < 2则跳转至readfast
144+
MOV DH,0
145+
ADD CH,1
146+
JMP readfast
147+
.ret:
148+
RET
149+
150+
RESB 0x7dfe-$ ; 到0x7dfe为止用0x00填充的指令
151+
152+
DB 0x55, 0xaa

30_day/invader/invader.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include <stdio.h> /* sprintf */
21
#include <string.h> /* strlen */
32
#include "apilib.h"
43

54
void putstr(int win, char *winbuf, int x, int y, int col, unsigned char *s);
65
void wait(int i, int timer, char *keyflag);
6+
void setdec8(char *s, int i);
77

88
static unsigned char charset[16 * 8] = {
99

@@ -171,7 +171,7 @@ void HariMain(void)
171171
/* hit ! */
172172
score += point;
173173
point++;
174-
sprintf(s, "%08d", score);
174+
setdec8(s, score);
175175
putstr(win, winbuf, 10, 0, 7, s);
176176
if (high < score) {
177177
high = score;
@@ -279,3 +279,15 @@ void wait(int i, int timer, char *keyflag)
279279
}
280280
return;
281281
}
282+
283+
void setdec8(char *s, int i)
284+
/*将i用十进制表示并存入s*/
285+
{
286+
int j;
287+
for (j = 7; j >= 0; j--) {
288+
s[j] = '0' + i % 10;
289+
i /= 10;
290+
}
291+
s[8] = 0;
292+
return;
293+
}

0 commit comments

Comments
 (0)