-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootpack.c
295 lines (280 loc) · 9.85 KB
/
bootpack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include "bootpack.h"
void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act);
void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c);
void task_b_main(struct SHEET *sht_win_b);
void HariMain(void)
{
struct BOOTINFO *binfo = (struct BOOTINFO *) ADR_BOOTINFO; // 结构体指针指向储存系统信息的地址
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
struct FIFO32 fifo;
int fifobuf[128];
struct SHTCTL *shtctl;
// 图层背景,鼠标
struct SHEET *sht_back, *sht_mouse, *sht_win, *sht_win_b[3];
// 定义背景缓冲区、鼠标缓冲区
unsigned char *buf_back, buf_mouse[256], *buf_win, *buf_win_b;
// 键盘按键字符表
static char keytable[0x54] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', 0, 0,
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 0, 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', '.'
};
unsigned int memtotal;
char s[40];
struct TIMER *timer;
int i, mx, my, cursor_x, cursor_c;
struct TASK *task_a, *task_b[3];
init_gdtidt(); // 初始化 全局段记录表,中断记录表
init_pic(); // 初始化 PIC
io_sti(); // IDT/PIC 的初始化已经完成,开放 CPU 的中断
init_pit(); // 设定定时器频率
io_out8(PIC0_IMR, 0xf8); // 开放PIC1和键盘中断(11111001)
io_out8(PIC1_IMR, 0xef); // 开放鼠标中断(11101111)
fifo32_init(&fifo, 128, fifobuf, 0);
timer = timer_alloc();
timer_init(timer, &fifo, 1);
timer_settime(timer, 50);
init_keyboard(&fifo, 256);
enable_mouse(&fifo, 512, &mdec);
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, 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_screen(buf_back, binfo->scrnx, binfo->scrny);
// sht_win_b
for (i = 0; i < 3; i++) {
sht_win_b[i] = sheet_alloc(shtctl);
buf_win_b = (unsigned char *) memman_alloc_4k(memman, 144 * 52);
sheet_setbuf(sht_win_b[i], buf_win_b, 144, 52, -1);
sprintf(s, "task_b[%d]", i);
make_window8(buf_win_b, 144, 52, s, 0);
task_b[i] = task_alloc();
task_b[i]->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
task_b[i]->tss.eip = (int) &task_b_main;
task_b[i]->tss.es = 1 * 8;
task_b[i]->tss.cs = 2 * 8;
task_b[i]->tss.ss = 1 * 8;
task_b[i]->tss.ds = 1 * 8;
task_b[i]->tss.fs = 1 * 8;
task_b[i]->tss.gs = 1 * 8;
*((int *) (task_b[i]->tss.esp + 4)) = (int) sht_win_b[i];
task_run(task_b[i], 2, i + 1);
}
// sht_win
sht_win = sheet_alloc(shtctl);
buf_win = (unsigned char *) memman_alloc_4k(memman, 160 * 52);
sheet_setbuf(sht_win, buf_win, 144, 52, -1); // 没有透明色
make_window8(buf_win, 144, 52, "task_a", 1); // 创建窗口
make_textbox8(sht_win, 8, 28, 128, 16, COL8_FFFFFF); // 创建输入盒子
cursor_x = 8;
// sht_mouse
sht_mouse = sheet_alloc(shtctl);
sheet_setbuf(sht_mouse, buf_mouse, 16, 16, 99); // 透明色号 99
init_mouse_cursor8(buf_mouse, 99); // 背景色号 99
cursor_c = COL8_FFFFFF;
mx = (binfo->scrnx - 16) / 2;
my = (binfo->scrny - 28 - 16) / 2;
// 设置在移动图层时进行局部画面刷新
sheet_slide(sht_back, 0, 0);
sheet_slide(sht_win_b[0], 168, 56);
sheet_slide(sht_win_b[1], 8, 116);
sheet_slide(sht_win_b[2], 168, 116);
sheet_slide(sht_win, 8, 56);
sheet_slide(sht_mouse, mx, my);
// 设置叠加显示优先级
sheet_updown(sht_back, 0);
sheet_updown(sht_win_b[0], 1);
sheet_updown(sht_win_b[1], 2);
sheet_updown(sht_win_b[2], 3);
sheet_updown(sht_win, 4);
sheet_updown(sht_mouse, 5);
sprintf(s, "memory %dMB free: %dKB", memtotal / (1024 * 1024), memman_total(memman) / 1024);
putfonts8_str_sht(sht_back, 0, 50, COL8_FFFFFF, COL8_008484, s);
for (;;) {
// 计时器开始
// 屏蔽其他中断
io_cli();
// 接收中断并进入等待
if (fifo32_status(&fifo) == 0) {
task_sleep(task_a);
io_sti();
}
else {
i = fifo32_get(&fifo);
io_sti();
// 处理键盘数据
if (256 <= i && i <= 511) {
sprintf(s, "%02X", i - 256);
putfonts8_str_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s);
if (i < 256 + 0x54) {
if (keytable[i - 256] != 0 && cursor_x < 128) {
// 显示一个字符就后移一次光标
s[0] = keytable[i - 256];
s[1] = 0;
putfonts8_str_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, s);
cursor_x += 8;
}
}
// 退格键处理,前移一次光标
if (i == 256 + 0x0e && cursor_x > 8) {
putfonts8_str_sht(sht_win, cursor_x, 28, COL8_000000, COL8_FFFFFF, " ");
cursor_x -= 8;
}
boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
} else if (512 <= i && i <= 767) {
if (mouse_decode(&mdec, i - 512) != 0) {
sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y);
if ((mdec.btn & 0x01) != 0) {
s[1] = 'L';
sheet_slide(sht_win, mx - 80, my - 8);
}
if ((mdec.btn & 0x02) != 0) s[3] = 'R';
if ((mdec.btn & 0x04) != 0) s[2] = 'C';
putfonts8_str_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s);
// 鼠标移动
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;
sprintf(s, "(%4d %4d)", mx, my);
// 显示坐标
putfonts8_str_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s);
// 描绘鼠标
sheet_slide(sht_mouse, mx, my);
}
}
switch (i) {
// 模拟光标
case 1:
timer_init(timer, &fifo, 0);
cursor_c = COL8_000000;
boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
timer_settime(timer, 50);
sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
break;
case 0:
timer_init(timer, &fifo, 1);
cursor_c = COL8_FFFFFF;
boxfill8(sht_win->buf, sht_win->bxsize, cursor_c, cursor_x, 28, cursor_x + 7, 43);
timer_settime(timer, 50);
sheet_refresh(sht_win, cursor_x, 28, cursor_x + 8, 44);
break;
}
}
}
}
void make_window8(unsigned char *buf, int xsize, int ysize, char *title, char act)
{
static char closebtn[14][16] = {
"OOOOOOOOOOOOOOO@",
"OQQQQQQQQQQQQQ$@",
"OQQQQQQQQQQQQQ$@",
"OQQQ@@QQQQ@@QQ$@",
"OQQQQ@@QQ@@QQQ$@",
"OQQQQQ@@@@QQQQ$@",
"OQQQQQQ@@QQQQQ$@",
"OQQQQQ@@@@QQQQ$@",
"OQQQQ@@QQ@@QQQ$@",
"OQQQ@@QQQQ@@QQ$@",
"OQQQQQQQQQQQQQ$@",
"OQQQQQQQQQQQQQ$@",
"O$$$$$$$$$$$$$$@",
"@@@@@@@@@@@@@@@@"
};
int x, y;
char c, tc, tbc;
if (act != 0) {
tc = COL8_FFFFFF;
tbc = COL8_000084;
} else {
tc = COL8_C6C6C6;
tbc = COL8_848484;
}
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, xsize - 1, 0 );
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, xsize - 2, 1 );
boxfill8(buf, xsize, COL8_C6C6C6, 0, 0, 0, ysize - 1);
boxfill8(buf, xsize, COL8_FFFFFF, 1, 1, 1, ysize - 2);
boxfill8(buf, xsize, COL8_848484, xsize - 2, 1, xsize - 2, ysize - 2);
boxfill8(buf, xsize, COL8_000000, xsize - 1, 0, xsize - 1, ysize - 1);
boxfill8(buf, xsize, COL8_C6C6C6, 2, 2, xsize - 3, ysize - 3);
boxfill8(buf, xsize, tbc, 3, 3, xsize - 4, 20 );
boxfill8(buf, xsize, COL8_848484, 1, ysize - 2, xsize - 2, ysize - 2);
boxfill8(buf, xsize, COL8_000000, 0, ysize - 1, xsize - 1, ysize - 1);
putfonts8_str(buf, xsize, 24, 4, tc, title);
for (y = 0; y < 14; y++) {
for (x = 0; x < 16; x++) {
c = closebtn[y][x];
switch (c) {
case '@':
c = COL8_000000;
break;
case '$':
c = COL8_848484;
break;
case 'Q':
c = COL8_C6C6C6;
break;
default:
c = COL8_FFFFFF;
}
buf[(5 + y) * xsize + (xsize - 21 + x)] = c;
}
}
}
void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)
{
int x1 = x0 + sx, y1 = y0 + sy;
boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 2, y0 - 3, x1 + 1, y0 - 3);
boxfill8(sht->buf, sht->bxsize, COL8_848484, x0 - 3, y0 - 3, x0 - 3, y1 + 1);
boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x0 - 3, y1 + 2, x1 + 1, y1 + 2);
boxfill8(sht->buf, sht->bxsize, COL8_FFFFFF, x1 + 2, y0 - 3, x1 + 2, y1 + 2);
boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 1, y0 - 2, x1 + 0, y0 - 2);
boxfill8(sht->buf, sht->bxsize, COL8_000000, x0 - 2, y0 - 2, x0 - 2, y1 + 0);
boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x0 - 2, y1 + 1, x1 + 0, y1 + 1);
boxfill8(sht->buf, sht->bxsize, COL8_C6C6C6, x1 + 1, y0 - 2, x1 + 1, y1 + 1);
boxfill8(sht->buf, sht->bxsize, c, x0 - 1, y0 - 1, x1 + 0, y1 + 0);
}
void task_b_main(struct SHEET *sht_win_b)
{
struct FIFO32 fifo;
struct TIMER *timer_1s;
int fifobuf[128], count = 0, count0 = 0;
char s[12];
fifo32_init(&fifo, 128, fifobuf, 0);
timer_1s = timer_alloc();
timer_init(timer_1s, &fifo, 100);
timer_settime(timer_1s, 100);
for (;;) {
io_cli();
count++;
if (fifo32_status(&fifo) == 0) io_sti();
else {
io_sti();
switch (fifo32_get(&fifo)) {
case 100:
sprintf(s, "%011d", count - count0);
putfonts8_str_sht(sht_win_b, 24, 28, COL8_000000, COL8_C6C6C6, s);
count0 = count;
timer_settime(timer_1s, 100);
break;
}
}
}
}