コマンド改良
コンソールウィンドウのカーソル表示
@@ -10,6 +10,10 @@ | ||
10 | 10 | #include <bitnos/sheet.h> |
11 | 11 | #include <bitnos/window.h> |
12 | 12 | #include <string.h> |
13 | +#include <stdio.h> | |
14 | +#include <bitnos/memory.h> | |
15 | +#include <bitnos/timer.h> | |
16 | +#include <bitnos/specialtask.h> | |
13 | 17 | |
14 | 18 | namespace TaskConsole |
15 | 19 | { |
@@ -22,6 +26,10 @@ | ||
22 | 26 | |
23 | 27 | char cmdline[128]; |
24 | 28 | int cmdlineBegin; |
29 | + | |
30 | + Timer* tim; | |
31 | + bool cursor; | |
32 | + bool active; | |
25 | 33 | }; |
26 | 34 | |
27 | 35 | // コマンド実行機能なし |
@@ -32,10 +40,15 @@ | ||
32 | 40 | |
33 | 41 | void PutString0(Valiables* o, const char* str); |
34 | 42 | |
43 | +void PutString0(Valiables* o, const char* str, int len); | |
44 | + | |
35 | 45 | void ConsoleRefreshScreen(Valiables* o, int begin); |
36 | 46 | |
37 | 47 | void RunCommand(Valiables* o); |
38 | 48 | |
49 | +void ShowCursor(Valiables* o); | |
50 | +void EraseCursor(Valiables* o); | |
51 | + | |
39 | 52 | void Init(void* obj) |
40 | 53 | { |
41 | 54 | Valiables* o = (Valiables*)obj; |
@@ -44,10 +57,14 @@ | ||
44 | 57 | |
45 | 58 | Debug::WriteLine("Console Init"); |
46 | 59 | |
47 | - o->cons.height = 10; | |
48 | - o->cons.width = 29; | |
49 | - o->cons.bufHeight = 100; | |
50 | - o->cons.bufWidth = 29; | |
60 | + //o->cons.height = 10; | |
61 | + o->cons.height = 16; | |
62 | + // o->cons.width = 29; | |
63 | + o->cons.width = 50; | |
64 | + //o->cons.bufHeight = 100; | |
65 | + o->cons.bufHeight = o->cons.height; | |
66 | + //o->cons.bufWidth = 29; | |
67 | + o->cons.bufWidth = o->cons.width; | |
51 | 68 | o->cons.buf = new char[o->cons.bufHeight * o->cons.bufWidth]; |
52 | 69 | o->cons.startLine = o->cons.endLine = 0; |
53 | 70 | o->cons.xPos = 0; |
@@ -54,6 +71,8 @@ | ||
54 | 71 | o->cons.backColor = ConvRGB16(0, 0, 0); |
55 | 72 | o->cons.textColor = ConvRGB16(255, 255, 255); |
56 | 73 | o->cmdlineBegin = 0; |
74 | + o->cursor = false; | |
75 | + o->active = SpecialTask::Get(SpecialTask::Active) == task; | |
57 | 76 | |
58 | 77 | o->img = new Image( |
59 | 78 | 8 + fontHankaku->GetWidth() * o->cons.width, |
@@ -66,6 +85,9 @@ | ||
66 | 85 | o->sht->SetParentTask(task); |
67 | 86 | shtman->SetHeight(o->sht, 0, Sheet::Normal); |
68 | 87 | |
88 | + o->tim = timman->Alloc(task, 1); | |
89 | + o->tim->SetTime(80); | |
90 | + | |
69 | 91 | PutChar(o, '>'); |
70 | 92 | } |
71 | 93 |
@@ -75,8 +97,36 @@ | ||
75 | 97 | |
76 | 98 | if (msg->from == Message::From::Keyboard) { |
77 | 99 | if (msg->arg1 != 0) { |
100 | + if (o->cursor) { | |
101 | + EraseCursor(o); | |
102 | + } | |
78 | 103 | PutChar(o, msg->arg1); |
104 | + if (o->cursor) { | |
105 | + ShowCursor(o); | |
106 | + } | |
79 | 107 | } |
108 | + } else if (msg->from == Message::From::Timer) { | |
109 | + if (msg->arg1 == 1) { | |
110 | + if (o->active) { | |
111 | + o->tim->SetTime(70); | |
112 | + if (o->cursor) { | |
113 | + EraseCursor(o); | |
114 | + o->cursor = false; | |
115 | + } else { | |
116 | + ShowCursor(o); | |
117 | + o->cursor = true; | |
118 | + } | |
119 | + } | |
120 | + } | |
121 | + } else if (msg->from == Message::From::System) { | |
122 | + if (msg->arg1 == Message::System::WindowActivated) { | |
123 | + o->active = true; | |
124 | + o->tim->SetTime(20); | |
125 | + ShowCursor(o); | |
126 | + } else if (msg->arg1 == Message::System::WindowInactivated) { | |
127 | + o->active = false; | |
128 | + EraseCursor(o); | |
129 | + } | |
80 | 130 | } |
81 | 131 | } |
82 | 132 |
@@ -88,8 +138,14 @@ | ||
88 | 138 | o->cons.xPos++; |
89 | 139 | } |
90 | 140 | if (ch == '\b') { |
91 | - if (o->cons.xPos > 0) { | |
141 | + if (o->cons.endLine != o->cmdlineBegin) { | |
92 | 142 | o->cons.xPos--; |
143 | + if (o->cons.xPos < 0) { | |
144 | + o->cons.xPos = o->cons.bufWidth - 1; | |
145 | + o->cons.endLine--; | |
146 | + } | |
147 | + } else if (o->cons.endLine == o->cmdlineBegin && o->cons.xPos > 1) { | |
148 | + o->cons.xPos--; | |
93 | 149 | } |
94 | 150 | o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '\0'; |
95 | 151 | // 1文字だけ消去する |
@@ -241,6 +297,14 @@ | ||
241 | 297 | } |
242 | 298 | } |
243 | 299 | |
300 | +void PutString0(Valiables* o, const char* str, int len) | |
301 | +{ | |
302 | + while (len > 0 && *str != '\0') { | |
303 | + PutChar0(o, *str++); | |
304 | + len--; | |
305 | + } | |
306 | +} | |
307 | + | |
244 | 308 | void ConsoleRefreshScreen(Valiables* o, int begin) |
245 | 309 | { |
246 | 310 | int lines = o->cons.height; |
@@ -297,8 +361,42 @@ | ||
297 | 361 | |
298 | 362 | void RunCommand(Valiables* o) |
299 | 363 | { |
364 | + char s[256]; | |
300 | 365 | if (strncmp(o->cmdline, "mem", 4) == 0) { |
301 | - PutString0(o, "can't calculate memory size\n"); | |
366 | + PutString0(o, "mem : "); | |
367 | + sprintf(s, "%10d", physicalMemorySize); | |
368 | + if ((physicalMemorySize >> 30) != 0) { | |
369 | + PutString0(o, s + 0, 1); | |
370 | + PutChar0(o, ','); | |
371 | + } | |
372 | + if ((physicalMemorySize >> 20) != 0) { | |
373 | + PutString0(o, s + 1, 3); | |
374 | + PutChar0(o, ','); | |
375 | + } | |
376 | + if ((physicalMemorySize >> 10) != 0) { | |
377 | + PutString0(o, s + 4, 3); | |
378 | + PutChar0(o, ','); | |
379 | + } | |
380 | + PutString0(o, s + 7, 3); | |
381 | + PutString0(o, " B\n"); | |
382 | + | |
383 | + uint32_t freeSize = memman.GetFreeSize(); | |
384 | + PutString0(o, "free : "); | |
385 | + sprintf(s, "%10d", freeSize); | |
386 | + if ((freeSize >> 30) != 0) { | |
387 | + PutString0(o, s + 0, 1); | |
388 | + PutChar0(o, ','); | |
389 | + } | |
390 | + if ((freeSize >> 20) != 0) { | |
391 | + PutString0(o, s + 1, 3); | |
392 | + PutChar0(o, ','); | |
393 | + } | |
394 | + if ((freeSize >> 10) != 0) { | |
395 | + PutString0(o, s + 4, 3); | |
396 | + PutChar0(o, ','); | |
397 | + } | |
398 | + PutString0(o, s + 7, 3); | |
399 | + PutString0(o, " B\n"); | |
302 | 400 | } else if (strncmp(o->cmdline, "opencons", 9) == 0) { |
303 | 401 | Task* consTask = taskman->Alloc(); |
304 | 402 | uintptr_t stackTop; |
@@ -313,4 +411,41 @@ | ||
313 | 411 | } |
314 | 412 | } |
315 | 413 | |
414 | +void ShowCursor(Valiables* o) | |
415 | +{ | |
416 | + int end = o->cons.endLine; | |
417 | + if (end >= o->cons.height) { | |
418 | + end = o->cons.height - 1; | |
419 | + } | |
420 | + Point pos; | |
421 | + if (o->cons.xPos > 0) { | |
422 | + pos = Point(4 + o->cons.xPos * fontHankaku->GetWidth(), 25 + 4 + end * fontHankaku->GetHeight()); | |
423 | + } else { | |
424 | + pos = Point(4 + o->cons.width * fontHankaku->GetWidth(), 25 + 4 + (end - 1) * fontHankaku->GetHeight()); | |
425 | + } | |
426 | + o->sht->DrawRectangleFill( | |
427 | + o->cons.textColor, | |
428 | + pos, | |
429 | + pos + Point(0, fontHankaku->GetHeight() - 1)); | |
316 | 430 | } |
431 | + | |
432 | +void EraseCursor(Valiables* o) | |
433 | +{ | |
434 | + int end = o->cons.endLine; | |
435 | + if (end >= o->cons.height) { | |
436 | + end = o->cons.height - 1; | |
437 | + } | |
438 | + Point pos; | |
439 | + if (o->cons.xPos > 0) { | |
440 | + pos = Point(4 + o->cons.xPos * fontHankaku->GetWidth(), 25 + 4 + end * fontHankaku->GetHeight()); | |
441 | + } else { | |
442 | + pos = Point(4 + o->cons.width * fontHankaku->GetWidth(), 25 + 4 + (end - 1) * fontHankaku->GetHeight()); | |
443 | + } | |
444 | + o->sht->DrawRectangleFill( | |
445 | + o->cons.backColor, | |
446 | + pos, | |
447 | + pos + Point(1, fontHankaku->GetHeight() - 1)); | |
448 | +} | |
449 | + | |
450 | + | |
451 | +} |