Skip to content

Commit 40d25e6

Browse files
committed
mem command.
1 parent ba34476 commit 40d25e6

File tree

4 files changed

+66
-52
lines changed

4 files changed

+66
-52
lines changed

day18/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ L_OBJS := libc/stdio/stdio.bin
2020
# Kernel Objects
2121
K_OBJS := bootpack.bin io.bin pm.bin hankaku.bin desctbl.bin graphic.bin \
2222
int.bin inthandler.bin fifo.bin keyboard.bin mouse.bin \
23-
memory.bin sheet.bin window.bin timer.bin task.bin mtask.bin
23+
memory.bin sheet.bin window.bin timer.bin task.bin mtask.bin \
24+
console.bin
2425
SYS := haribote.sys
2526
IMG := haribote.img
2627

day18/bootpack.c

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <stdio.h>
22

33
#include "bootpack.h"
4+
#include "console.h"
45
#include "desctbl.h"
56
#include "fifo.h"
67
#include "graphic.h"
@@ -14,11 +15,11 @@
1415
#include "timer.h"
1516
#include "window.h"
1617

17-
void console_task(struct Sheet *sheet) {
18+
void console_task(struct Sheet *sheet, unsigned int memtotal) {
1819
struct Task *task = task_now();
1920
int fifobuf[128], cursor_x = 16, cursor_y = 28, cursor_c = -1;
20-
char s[2];
21-
int x, y;
21+
char s[30], cmdline[30];
22+
struct MemMan *memman = (struct MemMan *)MEMMAN_ADDR;
2223

2324
fifo32_init(&task->fifo, 128, fifobuf, task);
2425

@@ -69,8 +70,8 @@ void console_task(struct Sheet *sheet) {
6970
// 退格键
7071
if (cursor_x > 16) {
7172
// 用空白擦除光标后将光标前移一位
72-
put_fonts8_asc_sht(sheet, cursor_x, 28, COL8_FFFFFF, COL8_000000,
73-
" ", 1);
73+
put_fonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF,
74+
COL8_000000, " ", 1);
7475
cursor_x -= 8;
7576
}
7677
} else if (data == 10 + 256) {
@@ -79,23 +80,26 @@ void console_task(struct Sheet *sheet) {
7980
put_fonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF,
8081
COL8_000000, " ", 1);
8182

82-
if (cursor_y < 28 + 112) {
83-
84-
cursor_y += 16;
85-
} else {
86-
// 滚动
87-
for (y = 28; y < 28 + 112; y++) {
88-
for (x = 8; x < 8 + 240; x++) {
89-
sheet->buf[x + y * sheet->bxsize] =
90-
sheet->buf[x + (y + 16) * sheet->bxsize];
91-
}
92-
}
93-
for (y = 28 + 112; y < 28 + 128; y++) {
94-
for (x = 8; x < 8 + 240; x++) {
95-
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
96-
}
97-
}
98-
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
83+
cmdline[cursor_x / 8 - 2] = '\0';
84+
cursor_y = cons_newline(cursor_y, sheet);
85+
86+
if (cmdline[0] == 'm' && cmdline[1] == 'e' && cmdline[2] == 'm' &&
87+
cmdline[3] == '\0') {
88+
// mem命令
89+
sprintf(s, "total %dMB", memtotal / (1024 * 1024));
90+
put_fonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s,
91+
30);
92+
cursor_y = cons_newline(cursor_y, sheet);
93+
sprintf(s, "free %dKB", memman_total(memman) / 1024);
94+
put_fonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000, s,
95+
30);
96+
cursor_y = cons_newline(cursor_y, sheet);
97+
cursor_y = cons_newline(cursor_y, sheet);
98+
} else if (cmdline[0] != '\0') {
99+
put_fonts8_asc_sht(sheet, 8, cursor_y, COL8_FFFFFF, COL8_000000,
100+
"Bad command.", 12);
101+
cursor_y = cons_newline(cursor_y, sheet);
102+
cursor_y = cons_newline(cursor_y, sheet);
99103
}
100104

101105
// 显示提示符
@@ -105,7 +109,8 @@ void console_task(struct Sheet *sheet) {
105109
} else {
106110
if (cursor_x < 240) {
107111
s[0] = data - 256;
108-
s[1] = 0;
112+
s[1] = '\0';
113+
cmdline[cursor_x / 8 - 2] = data - 256;
109114
put_fonts8_asc_sht(sheet, cursor_x, cursor_y, COL8_FFFFFF,
110115
COL8_000000, s, 1);
111116
cursor_x += 8;
@@ -182,7 +187,7 @@ int main(void) {
182187
make_window8(buf_cons, 256, 165, "console", 0);
183188
make_textbox8(sht_cons, 8, 28, 240, 128, COL8_000000);
184189
struct Task *task_cons = task_alloc();
185-
task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
190+
task_cons->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 12;
186191
task_cons->tss.eip = (int)&console_task;
187192
task_cons->tss.es = 1 * 8;
188193
task_cons->tss.cs = 2 * 8;
@@ -191,6 +196,7 @@ int main(void) {
191196
task_cons->tss.fs = 1 * 8;
192197
task_cons->tss.gs = 1 * 8;
193198
*((int *)(task_cons->tss.esp + 4)) = (int)sht_cons;
199+
*((int *)(task_cons->tss.esp + 8)) = memtotal;
194200
task_run(task_cons, 2, 2);
195201

196202
// sht_win
@@ -221,12 +227,6 @@ int main(void) {
221227
sheet_updown(sht_win, 2);
222228
sheet_updown(sht_mouse, 3);
223229

224-
sprintf(s, "(%3d, %3d)", mx, my);
225-
put_fonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10);
226-
sprintf(s, "memory %dMB, free: %dKB", memtotal / (1024 * 1024),
227-
memman_total(memman) / 1024);
228-
put_fonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40);
229-
230230
// 避免与键盘状态冲突
231231
fifo32_put(&keycmd, KEYCMD_LED);
232232
fifo32_put(&keycmd, key_leds);
@@ -249,12 +249,6 @@ int main(void) {
249249

250250
if (256 <= data && data <= 511) {
251251
// 键盘数据
252-
sprintf(s, "%02X", data - 256);
253-
put_fonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2);
254-
255-
sprintf(s, "%d", key_leds);
256-
put_fonts8_asc_sht(sht_back, 0, 160, COL8_FFFFFF, COL8_008484, s, 10);
257-
258252
if (data < 0x80 + 256) {
259253
if (key_shift == 0) {
260254
s[0] = keytable0[data - 256];
@@ -383,19 +377,6 @@ int main(void) {
383377
} else if (512 <= data && data <= 767) {
384378
// 鼠标数据
385379
if (mouse_decode(&mdec, data - 512)) {
386-
sprintf(s, "[lcr %4d %4d]", mdec.x, mdec.y);
387-
if ((mdec.btn & 0x01)) {
388-
s[1] = 'L';
389-
}
390-
if ((mdec.btn & 0x02)) {
391-
s[3] = 'R';
392-
}
393-
if ((mdec.btn & 0x04)) {
394-
s[2] = 'C';
395-
}
396-
397-
put_fonts8_asc_sht(sht_back, 32, 16, COL8_FFFFFF, COL8_008484, s, 15);
398-
399380
// 移动光标
400381
mx += mdec.x;
401382
my += mdec.y;
@@ -413,8 +394,6 @@ int main(void) {
413394
my = binfo->scrny - 1;
414395
}
415396

416-
sprintf(s, "(%3d, %3d)", mx, my);
417-
put_fonts8_asc_sht(sht_back, 0, 0, COL8_FFFFFF, COL8_008484, s, 10);
418397
sheet_slide(sht_mouse, mx, my);
419398

420399
if (mdec.btn & 0x01) {

day18/console.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "console.h"
2+
#include "graphic.h"
3+
#include "sheet.h"
4+
5+
int cons_newline(int cursor_y, struct Sheet *sheet) {
6+
if (cursor_y < 28 + 112) {
7+
cursor_y += 16;
8+
} else {
9+
// 滚动
10+
for (int y = 28; y < 28 + 112; y++) {
11+
for (int x = 8; x < 8 + 240; x++) {
12+
sheet->buf[x + y * sheet->bxsize] =
13+
sheet->buf[x + (y + 16) * sheet->bxsize];
14+
}
15+
}
16+
for (int y = 28 + 112; y < 28 + 128; y++) {
17+
for (int x = 8; x < 8 + 240; x++) {
18+
sheet->buf[x + y * sheet->bxsize] = COL8_000000;
19+
}
20+
}
21+
22+
sheet_refresh(sheet, 8, 28, 8 + 240, 28 + 128);
23+
}
24+
25+
return cursor_y;
26+
}

day18/include/console.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "sheet.h"
2+
3+
#ifndef _CONSOLE_H_
4+
#define _CONSOLE_H_
5+
6+
int cons_newline(int cursor_y, struct Sheet *sheet);
7+
8+
#endif // _CONSOLE_H_

0 commit comments

Comments
 (0)