ソースコードの整理
@@ -15,9 +15,8 @@ | ||
15 | 15 | #include <bitnos/memory.h> |
16 | 16 | #include <bitnos/timer.h> |
17 | 17 | #include <bitnos/specialtask.h> |
18 | +#include <bitnos/pit.h> | |
18 | 19 | |
19 | -#define REFRESH_METHOD 0 | |
20 | - | |
21 | 20 | namespace TaskConsole |
22 | 21 | { |
23 | 22 |
@@ -142,53 +141,86 @@ | ||
142 | 141 | void ShowCursor(Valiables* o); |
143 | 142 | void EraseCursor(Valiables* o); |
144 | 143 | |
145 | -void WriteBuffer(Valiables* o, int x, int y, char ch); | |
146 | -char ReadBuffer(Valiables* o, int x, int y); | |
144 | +void ConsoleMakeBorderLine(Image* img); | |
147 | 145 | |
146 | +/* | |
147 | + * コンソールコマンド関数 | |
148 | + */ | |
149 | +class ConsoleCommands | |
150 | +{ | |
151 | +public: | |
152 | + static void mem(Valiables* o, const char* arg); | |
153 | + static void opencons(Valiables* o, const char* arg); | |
154 | + static void echo(Valiables* o, const char* arg); | |
155 | + static void beep(Valiables* o, const char* arg); | |
156 | + static void eco(Valiables* o, const char* arg); | |
157 | + static void cat(Valiables* o, const char* arg); | |
158 | +}; | |
159 | + | |
160 | +const uint32_t TIMERDATA_CURSOR = 1; | |
161 | +const uint32_t TIMERDATA_BEEP = 2; | |
162 | + | |
148 | 163 | void Init(void* obj) |
149 | 164 | { |
165 | + static int initialPosX = 110, initialPosY = 50; | |
166 | + | |
150 | 167 | Valiables* o = (Valiables*)obj; |
151 | 168 | |
152 | 169 | Task* task = taskman->GetCurrentTask(); |
153 | 170 | |
154 | - Debug::WriteLine("Console Init"); | |
155 | 171 | |
156 | - //o->cons.height = 10; | |
172 | + // コンソールの大きさ設定 | |
157 | 173 | o->cons.height = 12; |
158 | - // o->cons.width = 29; | |
159 | 174 | o->cons.width = 34; |
160 | - //o->cons.bufHeight = 40; | |
161 | - //o->cons.bufWidth = 29; | |
162 | - o->cons.bufWidth = o->cons.width; | |
163 | - o->cons.buf = new char[o->cons.bufHeight * o->cons.bufWidth]; | |
164 | - o->cons.startLine = o->cons.endLine = 0; | |
165 | - o->cons.xPos = 0; | |
166 | - o->cons.printYPos = 0; | |
175 | + | |
176 | + // コンソールの色設定 | |
167 | 177 | o->cons.backColor = ConvRGB16(0, 0, 0); |
168 | - o->cons.textColor = ConvRGB16(255, 255, 255); | |
178 | + o->cons.textColor = ConvRGB16(0xD0, 0xD0, 0xD0); | |
179 | + | |
180 | + // 各種初期化 | |
169 | 181 | o->cmdlineBegin = 0; |
170 | 182 | o->cursor = false; |
183 | + | |
184 | + // コンソール画面がアクティブかどうか | |
171 | 185 | o->active = SpecialTask::Get(SpecialTask::Active) == task; |
172 | 186 | |
187 | + // 文字列バッファの準備 | |
173 | 188 | o->cons.sbuf.Init(o->cons.width, 20); |
189 | + | |
190 | + // バッファ内の書き込み位置 | |
174 | 191 | o->cons.wPos = Point(0, 0); |
192 | + | |
193 | + // 画面内の表示位置 | |
175 | 194 | o->cons.pPos = Point(0, 0); |
176 | 195 | |
196 | + // 画面のバッファ | |
177 | 197 | o->img = new Image( |
178 | 198 | 8 + fontHankaku->GetWidth() * o->cons.width, |
179 | 199 | 25 + 8 + fontHankaku->GetHeight() * o->cons.height); |
180 | 200 | Window::Make(o->img); |
181 | 201 | o->img->DrawRectangleFill( |
182 | - o->cons.backColor, Point(0, 25), Point(o->img->width - 1, o->img->height - 1)); | |
202 | + o->cons.backColor, Point(0, 25), Point(o->img->GetWidth() - 1, o->img->GetHeight() - 1)); | |
203 | + ConsoleMakeBorderLine(o->img); | |
204 | + | |
183 | 205 | o->sht = shtman->Alloc(); |
184 | - o->sht->Init(o->img, Sheet::NoInvColor, Point(200, 50)); | |
206 | + o->sht->Init(o->img, Sheet::NoInvColor, Point(initialPosX, initialPosY)); | |
185 | 207 | o->sht->SetParentTask(task); |
186 | 208 | shtman->SetHeight(o->sht, 0, Sheet::Normal); |
187 | 209 | |
188 | - o->tim = timman->Alloc(task, 1); | |
210 | + // コンソールを開くごとに位置が変わるようにした。 | |
211 | + if (initialPosX < o->img->GetWidth() - 50 && initialPosY < o->img->GetHeight() - 50) { | |
212 | + initialPosX += 20; | |
213 | + initialPosY += 20; | |
214 | + } else { | |
215 | + initialPosX = 110; | |
216 | + initialPosY = 50; | |
217 | + } | |
218 | + | |
219 | + | |
220 | + o->tim = timman->Alloc(task, TIMERDATA_CURSOR); | |
189 | 221 | o->tim->SetTime(80); |
190 | 222 | |
191 | - o->timBeep = timman->Alloc(task, 2); | |
223 | + o->timBeep = timman->Alloc(task, TIMERDATA_BEEP); | |
192 | 224 | |
193 | 225 | PutChar0(o, '>'); |
194 | 226 | } |
@@ -208,7 +240,7 @@ | ||
208 | 240 | } |
209 | 241 | } |
210 | 242 | } else if (msg->from == Message::From::Timer) { |
211 | - if (msg->arg1 == 1) { | |
243 | + if (msg->arg1 == TIMERDATA_CURSOR) { | |
212 | 244 | if (o->active) { |
213 | 245 | o->tim->SetTime(70); |
214 | 246 | if (o->cursor) { |
@@ -219,12 +251,8 @@ | ||
219 | 251 | o->cursor = true; |
220 | 252 | } |
221 | 253 | } |
222 | - } else if (msg->arg1 == 2) { | |
223 | - uint8_t reg = io_in8(0x0061); | |
224 | - //reg |= 0x03; | |
225 | - //reg &= 0x0f; | |
226 | - reg &= 0x0d; | |
227 | - io_out8(0x0061, reg); | |
254 | + } else if (msg->arg1 == TIMERDATA_BEEP) { | |
255 | + PIT::BeepOff(); | |
228 | 256 | } |
229 | 257 | } else if (msg->from == Message::From::System) { |
230 | 258 | if (msg->arg1 == Message::System::WindowActivated) { |
@@ -246,119 +274,17 @@ | ||
246 | 274 | o->cons.sbuf.Scroll(1); |
247 | 275 | o->cons.sbuf.Write(Point(0, o->cons.sbuf.GetHeight() - 1), '\0'); |
248 | 276 | o->cmdlineBegin--; |
249 | - | |
250 | - | |
251 | 277 | } |
252 | 278 | o->cons.wPos.X = 0; |
253 | 279 | o->cons.pPos.X = 0; |
254 | 280 | if (o->cons.pPos.Y < o->cons.height - 1) { |
255 | 281 | o->cons.pPos.Y++; |
256 | - } else { | |
257 | -#if REFRESH_METHOD == 1 | |
258 | - Point posTo(4, 25 + 4); | |
259 | - Point posFrom(4, 25 + 4 + fontHankaku->GetHeight()); | |
260 | - uint16_t* ptrTo; | |
261 | - uint16_t* ptrFrom; | |
262 | - //uint32_t* ptrTo; | |
263 | - //uint32_t* ptrFrom; | |
264 | - for (int y = 4; y < o->img->GetHeight() - 25 - fontHankaku->GetHeight(); y++) { | |
265 | - ptrTo = o->img->buf + posTo.Y * o->img->GetWidth() + 4; | |
266 | - ptrFrom = o->img->buf + posFrom.Y * o->img->GetWidth() + 4; | |
267 | - //ptrTo = (uint32_t*)(o->img->buf + posTo.Y * o->img->GetWidth() + 4); | |
268 | - //ptrFrom = (uint32_t*)(o->img->buf + posFrom.Y * o->img->GetWidth() + 4); | |
269 | - | |
270 | - //for (posFrom.X = 4, posTo.X = 4; posFrom.X < o->img->width - 4; posFrom.X++, posTo.X++) { | |
271 | - for (posFrom.X = 4; posFrom.X < o->img->width - 4; posFrom.X++) { | |
272 | - //o->img->DrawPoint(o->img->GetPoint(posFrom), posTo); | |
273 | - *ptrTo++ = *ptrFrom++; | |
274 | - } | |
275 | - posTo.Y++; | |
276 | - posFrom.Y++; | |
277 | - | |
278 | - } | |
279 | - posTo.X = 0; | |
280 | - o->img->DrawRectangleFill( | |
281 | - o->cons.backColor, posTo, Point(o->img->GetWidth() - 1, o->img->GetHeight() - 1)); | |
282 | - | |
283 | - o->sht->Refresh(); | |
284 | -#endif | |
285 | 282 | } |
286 | 283 | } |
287 | 284 | |
288 | 285 | void PutChar0(Valiables* o, char ch) |
289 | 286 | { |
290 | -#if 0 | |
291 | - // バッファに格納 | |
292 | 287 | if (0x20 <= ch && ch < 0x80) { |
293 | - //o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = ch; | |
294 | - WriteBuffer(o, o->cons.xPos, o->cons.endLine, ch); | |
295 | - o->cons.xPos++; | |
296 | - } | |
297 | - if (ch == '\b') { | |
298 | - if (o->cons.endLine != o->cmdlineBegin) { | |
299 | - o->cons.xPos--; | |
300 | - if (o->cons.xPos < 0) { | |
301 | - o->cons.xPos = o->cons.bufWidth - 1; | |
302 | - o->cons.endLine--; | |
303 | - if (o->cons.endLine < 0) { | |
304 | - o->cons.endLine = o->cons.height - 1; | |
305 | - } | |
306 | - if (o->cons.printYPos > 0) { | |
307 | - o->cons.printYPos--; | |
308 | - } | |
309 | - } | |
310 | - } else if (o->cons.endLine == o->cmdlineBegin && o->cons.xPos > 1) { | |
311 | - o->cons.xPos--; | |
312 | - } | |
313 | - //o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '\0'; | |
314 | - WriteBuffer(o, o->cons.xPos, o->cons.endLine, '\0'); | |
315 | - // 1文字だけ消去する | |
316 | - o->sht->DrawRectangleFill( | |
317 | - o->cons.backColor, | |
318 | - Point( | |
319 | - 4 + fontHankaku->GetWidth() * o->cons.xPos, | |
320 | - 25 + 4 + fontHankaku->GetHeight() * o->cons.printYPos), | |
321 | - Point( | |
322 | - 4 + fontHankaku->GetWidth() * (o->cons.xPos + 1) - 1, | |
323 | - 25 + 4 + fontHankaku->GetHeight() * (o->cons.printYPos + 1) - 1) | |
324 | - ); | |
325 | - } else if (o->cons.bufWidth <= o->cons.xPos || ch == '\n') { | |
326 | - // バッファの右端まで行った、またはエンターキーが押されたから改行 | |
327 | - if (o->cons.xPos < o->cons.bufWidth - 1) { | |
328 | - //o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '\0';] | |
329 | - WriteBuffer(o, o->cons.xPos, o->cons.endLine, '\0'); | |
330 | - } | |
331 | - if (o->cons.printYPos < o->cons.height - 1) { | |
332 | - o->cons.printYPos++; | |
333 | - } | |
334 | - o->cons.xPos = 0; | |
335 | - o->cons.endLine++; | |
336 | - if (o->cons.endLine == o->cons.bufHeight) { | |
337 | - o->cons.endLine = 0; | |
338 | - } | |
339 | - if (o->cons.endLine == o->cons.startLine) { | |
340 | - memset(o->cons.buf + o->cons.endLine * o->cons.bufWidth, '\0', o->cons.bufWidth); | |
341 | - o->cons.startLine++; | |
342 | - if (o->cons.startLine == o->cons.bufHeight) { | |
343 | - o->cons.startLine = 0; | |
344 | - } | |
345 | - } | |
346 | - Debug::WriteLine("start=%d,end=%d", o->cons.startLine, o->cons.endLine); | |
347 | - // 画面全体を描画しなおす | |
348 | - ConsoleRefreshScreen(o, o->cons.endLine - o->cons.height + 1); | |
349 | - } else { | |
350 | - // 改行しなかった | |
351 | - // 1文字だけ描画する | |
352 | - o->sht->DrawChar( | |
353 | - o->cons.textColor, | |
354 | - ch, | |
355 | - Point( | |
356 | - 4 + fontHankaku->GetWidth() * (o->cons.xPos - 1), | |
357 | - 25 + 4 + fontHankaku->GetHeight() * o->cons.printYPos), | |
358 | - fontHankaku); | |
359 | - } | |
360 | -#endif | |
361 | - if (0x20 <= ch && ch < 0x80) { | |
362 | 288 | o->cons.sbuf.Write(o->cons.wPos, ch); |
363 | 289 | o->cons.wPos.X++; |
364 | 290 | if (o->cons.pPos.X < o->cons.width - 1) { |
@@ -394,11 +320,9 @@ | ||
394 | 320 | int pposy = o->cons.pPos.Y; |
395 | 321 | NewLine(o); |
396 | 322 | |
397 | -#if REFRESH_METHOD == 0 | |
398 | 323 | if (pposy == o->cons.pPos.Y) { |
399 | 324 | ConsoleRefreshScreen(o, -1); |
400 | 325 | } |
401 | -#endif | |
402 | 326 | |
403 | 327 | } else { |
404 | 328 | o->sht->DrawChar( |
@@ -413,105 +337,10 @@ | ||
413 | 337 | |
414 | 338 | void PutChar(Valiables* o, char ch) |
415 | 339 | { |
416 | -#if 0 | |
417 | - // バッファに格納 | |
418 | - if (0x20 <= ch && ch < 0x80) { | |
419 | - o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = ch; | |
420 | - o->cons.xPos++; | |
421 | - } | |
422 | - if (ch == '\b') { | |
423 | - if (o->cons.xPos > 0) { | |
424 | - o->cons.xPos--; | |
425 | - } | |
426 | - o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '\0'; | |
427 | - // 1文字だけ消去する | |
428 | - int end = o->cons.endLine; | |
429 | - if (end >= o->cons.height) { | |
430 | - end = o->cons.height - 1; | |
431 | - } | |
432 | - o->sht->DrawRectangleFill( | |
433 | - o->cons.backColor, | |
434 | - Point( | |
435 | - 4 + fontHankaku->GetWidth() * o->cons.xPos, | |
436 | - 25 + 4 + fontHankaku->GetHeight() * end), | |
437 | - Point( | |
438 | - 4 + fontHankaku->GetWidth() * (o->cons.xPos + 1) - 1, | |
439 | - 25 + 4 + fontHankaku->GetHeight() * (end + 1) - 1) | |
440 | - ); | |
441 | - } else if (o->cons.bufWidth <= o->cons.xPos || ch == '\n') { | |
442 | - // バッファの右端まで行った、またはエンターキーが押されたから改行 | |
443 | - if (o->cons.xPos < o->cons.bufWidth - 1) { | |
444 | - o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '\0'; | |
445 | - } | |
446 | - o->cons.xPos = 0; | |
447 | - o->cons.endLine++; | |
448 | - if (o->cons.endLine == o->cons.startLine) { | |
449 | - o->cons.startLine++; | |
450 | - } | |
451 | - if (ch == '\n') { | |
452 | - // コマンドラインを取得 | |
453 | - int i = 0; | |
454 | - char c; | |
455 | - for (int line = o->cmdlineBegin, x = 1; line != o->cons.endLine; line++) { | |
456 | - if (line == o->cons.bufHeight) { | |
457 | - line = 0; | |
458 | - } | |
459 | - for (; x < o->cons.bufWidth && (c = o->cons.buf[o->cons.bufWidth * line + x]) != '\0'; x++) { | |
460 | - o->cmdline[i++] = c; | |
461 | - } | |
462 | - x = 0; | |
463 | - } | |
464 | - o->cmdline[i] = '\0'; | |
465 | - o->cmdlineBegin = o->cons.endLine; | |
466 | - RunCommand(o); | |
467 | - o->cons.buf[o->cons.bufWidth * o->cons.endLine + o->cons.xPos] = '>'; | |
468 | - o->cons.xPos++; | |
469 | - } | |
470 | - // 画面全体を描画しなおす | |
471 | - ConsoleRefreshScreen(o, o->cons.endLine - o->cons.height + 1); | |
472 | - } else { | |
473 | - // 改行しなかった | |
474 | - int end = o->cons.endLine; | |
475 | - if (end >= o->cons.height) { | |
476 | - end = o->cons.height - 1; | |
477 | - } | |
478 | - // 1文字だけ描画する | |
479 | - o->sht->DrawChar( | |
480 | - o->cons.textColor, | |
481 | - ch, | |
482 | - Point( | |
483 | - 4 + fontHankaku->GetWidth() * (o->cons.xPos - 1), | |
484 | - 25 + 4 + fontHankaku->GetHeight() * end), | |
485 | - fontHankaku); | |
486 | - } | |
487 | -#endif | |
488 | 340 | PutChar0(o, ch); |
489 | -#if 0 | |
490 | 341 | if (ch == '\n') { |
491 | - // コマンドラインを取得 | |
492 | 342 | int i = 0; |
493 | 343 | char c; |
494 | - for (int line = o->cmdlineBegin, x = 1; line != o->cons.endLine; line++) { | |
495 | - if (line == o->cons.bufHeight) { | |
496 | - line = 0; | |
497 | - } | |
498 | - for (; x < o->cons.bufWidth && (c = o->cons.buf[o->cons.bufWidth * line + x]) != '\0'; x++) { | |
499 | - o->cmdline[i++] = c; | |
500 | - } | |
501 | - x = 0; | |
502 | - } | |
503 | - o->cmdline[i] = '\0'; | |
504 | - | |
505 | - //Debug::WriteLine(o->cmdline); | |
506 | - RunCommand(o); | |
507 | - | |
508 | - o->cmdlineBegin = o->cons.endLine; | |
509 | - PutChar0(o, '>'); | |
510 | - } | |
511 | -#endif | |
512 | - if (ch == '\n') { | |
513 | - int i = 0; | |
514 | - char c; | |
515 | 344 | for (int line = o->cmdlineBegin, x = 1; line <= o->cons.wPos.Y; line++) { |
516 | 345 | for (; (c = o->cons.sbuf.Read(Point(x, line))) != '\0'; x++) { |
517 | 346 | o->cmdline[i++] = c; |
@@ -544,61 +373,8 @@ | ||
544 | 373 | |
545 | 374 | void ConsoleRefreshScreen(Valiables* o, int begin) |
546 | 375 | { |
547 | -#if 0 | |
548 | - int lines = o->cons.height; | |
549 | 376 | if (begin < 0) { |
550 | 377 | // 自動計算モード |
551 | - lines = o->cons.endLine - o->cons.startLine + 1; | |
552 | - if (lines <= 0) { | |
553 | - /* | |
554 | - * bufの状態が | |
555 | - * ... | |
556 | - * endLine | |
557 | - * ... | |
558 | - * startLine | |
559 | - * ... | |
560 | - * のようになっているとき | |
561 | - */ | |
562 | - lines += o->cons.bufHeight; | |
563 | - } | |
564 | - if (lines <= o->cons.height) { | |
565 | - begin = o->cons.startLine; | |
566 | - } else { | |
567 | - lines = o->cons.height; | |
568 | - begin = o->cons.endLine - o->cons.height + 1; | |
569 | - if (begin < 0) { | |
570 | - begin += o->cons.bufHeight; | |
571 | - } | |
572 | - } | |
573 | - } | |
574 | - o->img->DrawRectangleFill( | |
575 | - o->cons.backColor, Point(0, 25), Point(o->img->width - 1, o->img->height - 1)); | |
576 | - int line = begin; | |
577 | - Debug::WriteLine("refreshing l=%d,ls=%d", line, lines); | |
578 | - for (int y = 0; y < lines; y++) { | |
579 | - for (int x = 0; x < o->cons.width; x++) { | |
580 | - //char ch = o->cons.buf[line * o->cons.bufWidth + x]; | |
581 | - char ch = ReadBuffer(o, x, line); | |
582 | - if (ch == '\0') { | |
583 | - break; | |
584 | - } | |
585 | - o->img->DrawChar( | |
586 | - o->cons.textColor, | |
587 | - ch, | |
588 | - Point(4 + x * fontHankaku->GetWidth(), 25 + 4 + y * fontHankaku->GetHeight()), | |
589 | - fontHankaku); | |
590 | - } | |
591 | - line++; | |
592 | - if (line == o->cons.bufHeight) { | |
593 | - line = 0; | |
594 | - } | |
595 | - if (line == o->cons.startLine) { | |
596 | - break; | |
597 | - } | |
598 | - } | |
599 | - o->sht->Refresh(); | |
600 | -#endif | |
601 | - if (begin < 0) { | |
602 | 378 | begin = o->cons.wPos.Y - o->cons.height + 1; |
603 | 379 | if (begin < 0) { |
604 | 380 | begin = 0; |
@@ -605,27 +381,11 @@ | ||
605 | 381 | } |
606 | 382 | } |
607 | 383 | |
608 | - /* | |
609 | - int beginOld = begin - 1; | |
610 | - if (beginOld < 0) { | |
611 | - beginOld = 0; | |
612 | - } | |
613 | - */ | |
614 | - | |
384 | + // 画面全消去 | |
615 | 385 | o->img->DrawRectangleFill( |
616 | 386 | o->cons.backColor, Point(4, 25 + 4), Point(o->img->GetWidth() - 1 - 4, o->img->GetHeight() - 1 - 4)); |
617 | 387 | |
618 | -/* | |
619 | - for (int lines = 0; beginOld + lines <= o->cons.sbuf.GetHeight() && lines < o->cons.height; lines++) { | |
620 | - o->img->DrawString( | |
621 | - ConvRGB16(127, 127, 127), | |
622 | - o->cons.sbuf.GetPointer(Point(0, beginOld + lines)), | |
623 | - Point(4, 25 + 4 + lines * fontHankaku->GetHeight()), | |
624 | - fontHankaku); | |
625 | - } | |
626 | - */ | |
627 | - | |
628 | - | |
388 | + // 文字列描画 | |
629 | 389 | for (int lines = 0; begin + lines <= o->cons.sbuf.GetHeight() && lines < o->cons.height; lines++) { |
630 | 390 | o->img->DrawString( |
631 | 391 | o->cons.textColor, |
@@ -638,7 +398,6 @@ | ||
638 | 398 | |
639 | 399 | void RunCommand(Valiables* o) |
640 | 400 | { |
641 | - char s[256]; | |
642 | 401 | char* command = o->cmdline; |
643 | 402 | char* args; |
644 | 403 | int i = 0; |
@@ -654,79 +413,17 @@ | ||
654 | 413 | } |
655 | 414 | args = command + i; |
656 | 415 | if (strncmp(command, "mem", 4) == 0) { |
657 | - PutString0(o, "mem : "); | |
658 | - sprintf(s, "%10d", physicalMemorySize); | |
659 | - if ((physicalMemorySize >> 30) != 0) { | |
660 | - PutString0(o, s + 0, 1); | |
661 | - PutChar0(o, ','); | |
662 | - } | |
663 | - if ((physicalMemorySize >> 20) != 0) { | |
664 | - PutString0(o, s + 1, 3); | |
665 | - PutChar0(o, ','); | |
666 | - } | |
667 | - if ((physicalMemorySize >> 10) != 0) { | |
668 | - PutString0(o, s + 4, 3); | |
669 | - PutChar0(o, ','); | |
670 | - } | |
671 | - PutString0(o, s + 7, 3); | |
672 | - PutString0(o, " B\n"); | |
673 | - | |
674 | - uint32_t freeSize = memman.GetFreeSize(); | |
675 | - PutString0(o, "free : "); | |
676 | - sprintf(s, "%10d", freeSize); | |
677 | - if ((freeSize >> 30) != 0) { | |
678 | - PutString0(o, s + 0, 1); | |
679 | - PutChar0(o, ','); | |
680 | - } | |
681 | - if ((freeSize >> 20) != 0) { | |
682 | - PutString0(o, s + 1, 3); | |
683 | - PutChar0(o, ','); | |
684 | - } | |
685 | - if ((freeSize >> 10) != 0) { | |
686 | - PutString0(o, s + 4, 3); | |
687 | - PutChar0(o, ','); | |
688 | - } | |
689 | - PutString0(o, s + 7, 3); | |
690 | - PutString0(o, " B\n"); | |
416 | + ConsoleCommands::mem(o, args); | |
691 | 417 | } else if (strncmp(command, "opencons", 9) == 0) { |
692 | - Task* consTask = taskman->Alloc(); | |
693 | - uintptr_t stackTop; | |
694 | - uint32_t stackSize; | |
695 | - stackTop = (uintptr_t)(new uint8_t[stackSize = 1024*4]); | |
696 | - consTask->SetFuncs(stackTop, stackSize, | |
697 | - TaskConsole::Init, DummyFunc, TaskConsole::Proc); | |
698 | - consTask->InitQueue(128); | |
699 | - taskman->Run(consTask, 1, 2); | |
418 | + ConsoleCommands::opencons(o, args); | |
700 | 419 | } else if (strncmp(command, "echo", 5) == 0) { |
701 | - PutString0(o, args); | |
702 | - PutChar0(o, '\n'); | |
420 | + ConsoleCommands::echo(o, args); | |
703 | 421 | } else if (strncmp(command, "beep", 5) == 0) { |
704 | - int cnt = 2712; | |
705 | - int freq = 1193180; | |
706 | - if (args[0] != '\0') { | |
707 | - cnt = ((freq << 10) / strtol(args, 0, 0) + 512) >> 10; | |
708 | - } | |
709 | - // freq = 1.19318MHz / cnt | |
710 | - io_out8(0x0043, 0xb6); | |
711 | - io_out8(0x0042, (cnt & 0x00ff)); | |
712 | - io_out8(0x0042, ((cnt >> 8) & 0x00ff)); | |
713 | - uint8_t reg = io_in8(0x0061); | |
714 | - reg |= 0x03; | |
715 | - reg &= 0x0f; | |
716 | - io_out8(0x0061, reg); | |
717 | - o->timBeep->SetTime(100); | |
422 | + ConsoleCommands::beep(o, args); | |
718 | 423 | } else if (strncmp(command, "eco", 4) == 0) { |
719 | - PutString0(o, " tree \n"); | |
720 | - PutString0(o, " tree tree \n"); | |
721 | - PutString0(o, "tree tree tree\n"); | |
424 | + ConsoleCommands::eco(o, args); | |
722 | 425 | } else if (strncmp(command, "cat", 4) == 0) { |
723 | - PutString0(o, " _ ___ _.--.\n"); | |
724 | - PutString0(o, " \\`.|\\..----...-'` `-._.-'_.-'`\n"); | |
725 | - PutString0(o, " / ' ` , __.--'\n"); | |
726 | - PutString0(o, " )/' _/ \\ `-_, /\n"); | |
727 | - PutString0(o, " `-'\" `\"\\_ ,_.-;_.-\\_ ',\n"); | |
728 | - PutString0(o, " _.-'_./ {_.' ; /\n"); | |
729 | - PutString0(o, " {_.-``-' {_/\n"); | |
426 | + ConsoleCommands::cat(o, args); | |
730 | 427 | } else { |
731 | 428 | if (strlen(command) > 0) { |
732 | 429 | PutString0(o, "unknown command\n"); |
@@ -754,26 +451,125 @@ | ||
754 | 451 | pos + Point(0, fontHankaku->GetHeight() - 1)); |
755 | 452 | } |
756 | 453 | |
757 | -void WriteBuffer(Valiables* o, int x, int y, char ch) | |
454 | +void ConsoleMakeBorderLine(Image* img) | |
758 | 455 | { |
759 | - if (x < 0 || o->cons.bufWidth <= x) { | |
760 | - Debug::WriteLine("write : x is wrong."); | |
456 | + Point pos0(1, 25); | |
457 | + Point pos1(img->GetWidth() - 2, 25); | |
458 | + Point pos2(1, img->GetHeight() - 2); | |
459 | + Point pos3(img->GetWidth() - 2, img->GetHeight() - 2); | |
460 | + img->DrawLine( | |
461 | + ConvRGB16(0xc0, 0xc0, 0xc0), | |
462 | + pos0, pos2); | |
463 | + img->DrawLine( | |
464 | + ConvRGB16(0xc0, 0xc0, 0xc0), | |
465 | + pos1, pos3); | |
466 | + img->DrawLine( | |
467 | + ConvRGB16(0xc0, 0xc0, 0xc0), | |
468 | + pos2 + Point(1, 0), pos3 + Point(-1, 0)); | |
469 | + img->DrawLine( | |
470 | + ConvRGB16(0x80, 0x80, 0x80), | |
471 | + pos0 + Point(1, 0), pos2 + Point(1, -2)); | |
472 | + img->DrawLine( | |
473 | + ConvRGB16(0x80, 0x80, 0x80), | |
474 | + pos0 + Point(2, 0), pos1 + Point(-1, 0)); | |
475 | + img->DrawLine( | |
476 | + ConvRGB16(0xf0, 0xf0, 0xf0), | |
477 | + pos1 + Point(-1, 1), pos3 + Point(-1, -1)); | |
478 | + img->DrawLine( | |
479 | + ConvRGB16(0xf0, 0xf0, 0xf0), | |
480 | + pos2 + Point(1, -1), pos3 + Point(-2, -1)); | |
481 | +} | |
482 | + | |
483 | +void ConsoleCommands::mem(Valiables* o, const char* arg) | |
484 | +{ | |
485 | + char s[256]; | |
486 | + PutString0(o, "mem : "); | |
487 | + sprintf(s, "%10d", physicalMemorySize); | |
488 | + if ((physicalMemorySize >> 30) != 0) { | |
489 | + PutString0(o, s + 0, 1); | |
490 | + PutChar0(o, ','); | |
761 | 491 | } |
762 | - if (y < 0 || o->cons.bufHeight <= y) { | |
763 | - Debug::WriteLine("write : y is wrong."); | |
492 | + if ((physicalMemorySize >> 20) != 0) { | |
493 | + PutString0(o, s + 1, 3); | |
494 | + PutChar0(o, ','); | |
764 | 495 | } |
765 | - o->cons.buf[y * o->cons.bufWidth + x] = ch; | |
496 | + if ((physicalMemorySize >> 10) != 0) { | |
497 | + PutString0(o, s + 4, 3); | |
498 | + PutChar0(o, ','); | |
499 | + } | |
500 | + PutString0(o, s + 7, 3); | |
501 | + PutString0(o, " B\n"); | |
502 | + | |
503 | + uint32_t freeSize = memman.GetFreeSize(); | |
504 | + PutString0(o, "free : "); | |
505 | + sprintf(s, "%10d", freeSize); | |
506 | + if ((freeSize >> 30) != 0) { | |
507 | + PutString0(o, s + 0, 1); | |
508 | + PutChar0(o, ','); | |
509 | + } | |
510 | + if ((freeSize >> 20) != 0) { | |
511 | + PutString0(o, s + 1, 3); | |
512 | + PutChar0(o, ','); | |
513 | + } | |
514 | + if ((freeSize >> 10) != 0) { | |
515 | + PutString0(o, s + 4, 3); | |
516 | + PutChar0(o, ','); | |
517 | + } | |
518 | + PutString0(o, s + 7, 3); | |
519 | + PutString0(o, " B\n"); | |
766 | 520 | } |
767 | -char ReadBuffer(Valiables* o, int x, int y) | |
521 | + | |
522 | +void ConsoleCommands::opencons(Valiables* o, const char* arg) | |
768 | 523 | { |
769 | - if (x < 0 || o->cons.bufWidth <= x) { | |
770 | - Debug::WriteLine("read : x is wrong."); | |
524 | + Task* consTask = taskman->Alloc(); | |
525 | + uintptr_t stackTop; | |
526 | + uint32_t stackSize; | |
527 | + stackTop = (uintptr_t)(new uint8_t[stackSize = 1024*4]); | |
528 | + consTask->SetFuncs(stackTop, stackSize, | |
529 | + TaskConsole::Init, DummyFunc, TaskConsole::Proc); | |
530 | + consTask->InitQueue(128); | |
531 | + taskman->Run(consTask, 1, 2); | |
532 | +} | |
533 | + | |
534 | +void ConsoleCommands::echo(Valiables* o, const char* arg) | |
535 | +{ | |
536 | + PutString0(o, arg); | |
537 | + PutChar0(o, '\n'); | |
538 | +} | |
539 | + | |
540 | +void ConsoleCommands::beep(Valiables* o, const char* arg) | |
541 | +{ | |
542 | + int cnt = 2712; | |
543 | + const int freq = 1193180; | |
544 | + if (arg[0] != '\0') { | |
545 | + cnt = ((freq << 10) / strtol(arg, 0, 0) + 512) >> 10; | |
771 | 546 | } |
772 | - if (y < 0 || o->cons.bufHeight <= y) { | |
773 | - Debug::WriteLine("read : y is wrong."); | |
774 | - } | |
775 | - return o->cons.buf[y * o->cons.bufWidth + x]; | |
547 | + | |
548 | + // freq = 1.19318MHz / cnt | |
549 | + PIT::BeetSetCounter(cnt); | |
550 | + PIT::BeepOn(); | |
551 | + | |
552 | + // カウンタ2、スピーカイネーブル | |
553 | + | |
554 | + o->timBeep->SetTime(100); | |
776 | 555 | } |
777 | 556 | |
557 | +void ConsoleCommands::eco(Valiables* o, const char* arg) | |
558 | +{ | |
559 | + PutString0(o, " tree \n"); | |
560 | + PutString0(o, " tree tree \n"); | |
561 | + PutString0(o, "tree tree tree\n"); | |
562 | +} | |
778 | 563 | |
564 | +void ConsoleCommands::cat(Valiables* o, const char* arg) | |
565 | +{ | |
566 | + PutString0(o, " _ ___ _.--.\n"); | |
567 | + PutString0(o, " \\`.|\\..----...-'` `-._.-'_.-'`\n"); | |
568 | + PutString0(o, " / ' ` , __.--'\n"); | |
569 | + PutString0(o, " )/' _/ \\ `-_, /\n"); | |
570 | + PutString0(o, " `-'\" `\"\\_ ,_.-;_.-\\_ ',\n"); | |
571 | + PutString0(o, " _.-'_./ {_.' ; /\n"); | |
572 | + PutString0(o, " {_.-``-' {_/\n"); | |
779 | 573 | } |
574 | + | |
575 | +} |
@@ -56,14 +56,14 @@ | ||
56 | 56 | { |
57 | 57 | int width; // 横の文字数 |
58 | 58 | int height; // 縦の文字数 |
59 | - int bufWidth; // バッファの横の文字数 | |
60 | - int bufHeight; // バッファの縦の文字数 | |
61 | - char* buf; // バッファ | |
59 | + //int bufWidth; // バッファの横の文字数 | |
60 | + //int bufHeight; // バッファの縦の文字数 | |
61 | + //char* buf; // バッファ | |
62 | 62 | |
63 | - int startLine; // バッファの開始行 | |
64 | - int endLine; // バッファの終了行(書き込み行) | |
65 | - int xPos; // 書き込みの横位置 | |
66 | - int printYPos; // 表示の縦位置 | |
63 | + //int startLine; // バッファの開始行 | |
64 | + //int endLine; // バッファの終了行(書き込み行) | |
65 | + //int xPos; // 書き込みの横位置 | |
66 | + //int printYPos; // 表示の縦位置 | |
67 | 67 | |
68 | 68 | uint16_t backColor; // 背景色 |
69 | 69 | uint16_t textColor; // 前景色 |