1
1
#include <stdio.h>
2
2
3
3
#include "bootpack.h"
4
+ #include "console.h"
4
5
#include "desctbl.h"
5
6
#include "fifo.h"
6
7
#include "graphic.h"
14
15
#include "timer.h"
15
16
#include "window.h"
16
17
17
- void console_task (struct Sheet * sheet ) {
18
+ void console_task (struct Sheet * sheet , unsigned int memtotal ) {
18
19
struct Task * task = task_now ();
19
20
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 ;
22
23
23
24
fifo32_init (& task -> fifo , 128 , fifobuf , task );
24
25
@@ -69,8 +70,8 @@ void console_task(struct Sheet *sheet) {
69
70
// 退格键
70
71
if (cursor_x > 16 ) {
71
72
// 用空白擦除光标后将光标前移一位
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 );
74
75
cursor_x -= 8 ;
75
76
}
76
77
} else if (data == 10 + 256 ) {
@@ -79,23 +80,26 @@ void console_task(struct Sheet *sheet) {
79
80
put_fonts8_asc_sht (sheet , cursor_x , cursor_y , COL8_FFFFFF ,
80
81
COL8_000000 , " " , 1 );
81
82
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 );
99
103
}
100
104
101
105
// 显示提示符
@@ -105,7 +109,8 @@ void console_task(struct Sheet *sheet) {
105
109
} else {
106
110
if (cursor_x < 240 ) {
107
111
s [0 ] = data - 256 ;
108
- s [1 ] = 0 ;
112
+ s [1 ] = '\0' ;
113
+ cmdline [cursor_x / 8 - 2 ] = data - 256 ;
109
114
put_fonts8_asc_sht (sheet , cursor_x , cursor_y , COL8_FFFFFF ,
110
115
COL8_000000 , s , 1 );
111
116
cursor_x += 8 ;
@@ -182,7 +187,7 @@ int main(void) {
182
187
make_window8 (buf_cons , 256 , 165 , "console" , 0 );
183
188
make_textbox8 (sht_cons , 8 , 28 , 240 , 128 , COL8_000000 );
184
189
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 ;
186
191
task_cons -> tss .eip = (int )& console_task ;
187
192
task_cons -> tss .es = 1 * 8 ;
188
193
task_cons -> tss .cs = 2 * 8 ;
@@ -191,6 +196,7 @@ int main(void) {
191
196
task_cons -> tss .fs = 1 * 8 ;
192
197
task_cons -> tss .gs = 1 * 8 ;
193
198
* ((int * )(task_cons -> tss .esp + 4 )) = (int )sht_cons ;
199
+ * ((int * )(task_cons -> tss .esp + 8 )) = memtotal ;
194
200
task_run (task_cons , 2 , 2 );
195
201
196
202
// sht_win
@@ -221,12 +227,6 @@ int main(void) {
221
227
sheet_updown (sht_win , 2 );
222
228
sheet_updown (sht_mouse , 3 );
223
229
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
-
230
230
// 避免与键盘状态冲突
231
231
fifo32_put (& keycmd , KEYCMD_LED );
232
232
fifo32_put (& keycmd , key_leds );
@@ -249,12 +249,6 @@ int main(void) {
249
249
250
250
if (256 <= data && data <= 511 ) {
251
251
// 键盘数据
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
-
258
252
if (data < 0x80 + 256 ) {
259
253
if (key_shift == 0 ) {
260
254
s [0 ] = keytable0 [data - 256 ];
@@ -383,19 +377,6 @@ int main(void) {
383
377
} else if (512 <= data && data <= 767 ) {
384
378
// 鼠标数据
385
379
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
-
399
380
// 移动光标
400
381
mx += mdec .x ;
401
382
my += mdec .y ;
@@ -413,8 +394,6 @@ int main(void) {
413
394
my = binfo -> scrny - 1 ;
414
395
}
415
396
416
- sprintf (s , "(%3d, %3d)" , mx , my );
417
- put_fonts8_asc_sht (sht_back , 0 , 0 , COL8_FFFFFF , COL8_008484 , s , 10 );
418
397
sheet_slide (sht_mouse , mx , my );
419
398
420
399
if (mdec .btn & 0x01 ) {
0 commit comments