|
|
1.1 root 1: //
2: // nono
1.1.1.3 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
7: #include "textscreen.h"
8:
9: //
10: // テキストスクリーン
11: //
12:
13: // コンストラクタ
14: TextScreen::TextScreen()
15: {
16: }
17:
18: // コンストラクタ
19: TextScreen::TextScreen(int arg_col, int arg_row)
20: {
21: Init(arg_col, arg_row);
22: }
23:
24: // デストラクタ
25: TextScreen::~TextScreen()
26: {
27: }
28:
29: // 初期化
30: void
31: TextScreen::Init(int arg_col, int arg_row)
32: {
1.1.1.6 ! root 33: assert(arg_col > 0);
! 34: assert(arg_row > 0);
! 35:
1.1 root 36: col = arg_col;
37: row = arg_row;
38:
1.1.1.6 ! root 39: textbuf.resize(col * row);
1.1 root 40: X = 0;
41: Y = 0;
42:
43: Clear();
44: }
45:
46: // クリア
47: void
48: TextScreen::Clear()
49: {
50: for (int i = 0; i < col * row; i++) {
51: textbuf[i] = 0x0020;
52: }
1.1.1.2 root 53:
1.1.1.4 root 54: // ホームポジション
55: Locate(0, 0);
1.1.1.2 root 56: }
57:
1.1.1.6 ! root 58: // 1 行上スクロール
! 59: void
! 60: TextScreen::ScrollUp()
! 61: {
! 62: memmove(&textbuf[0], &textbuf[col],
! 63: (row - 1) * col * sizeof(textbuf[0]));
! 64: for (int i = 0; i < col; i++) {
! 65: textbuf[(row - 1) * col + i] = 0x0020;
! 66: }
! 67: }
! 68:
! 69:
1.1 root 70: // 現在のカーソル位置に1文字出力する。
71: void
72: TextScreen::Putc(uint16 ch)
73: {
1.1.1.6 ! root 74: if (OutOfScreen) {
1.1 root 75: return;
76: }
77:
1.1.1.6 ! root 78: if (ch == '\n') {
! 79: CRLF();
! 80: } else {
! 81: textbuf[(Y * col) + X] = ch;
! 82: Ascend();
! 83: }
! 84: }
! 85:
! 86: // 現在のカーソル位置の文字を取得
! 87: // カーソルは移動する。
! 88: // カーソルが範囲外だったときは 0 を返す。
! 89: uint16
! 90: TextScreen::Getc()
! 91: {
! 92: if (OutOfScreen) {
! 93: return 0;
! 94: }
! 95:
! 96: uint16 ch = textbuf[(Y * col) + X];
! 97: Ascend();
! 98: return ch;
1.1 root 99: }
100:
101: // テキストスクリーンに文字列を出力する。
102: void
103: TextScreen::Puts(const char *str)
104: {
105: while (*str != '\0') {
106: Putc(*str++);
107: }
108: }
109:
110: // テキストスクリーンに文字列を出力する。
111: void
1.1.1.3 root 112: TextScreen::Puts(TA attr, const char *str)
1.1 root 113: {
114: while (*str != '\0') {
1.1.1.3 root 115: Putc(((uint)attr) | *str++);
1.1 root 116: }
117: }
118:
1.1.1.2 root 119: // テキストスクリーンの現在位置から書式付き文字列を出力する。
120: void
121: TextScreen::Print(const char *fmt, ...)
122: {
123: char buf[1024];
124: va_list ap;
125:
126: va_start(ap, fmt);
127: vsnprintf(buf, sizeof(buf), fmt, ap);
128: va_end(ap);
129:
130: Puts(buf);
131: }
132:
1.1 root 133: // テキストスクリーンに座標を指定して書式付き文字列を出力する。
134: void
135: TextScreen::Print(int x, int y, const char *fmt, ...)
136: {
137: char buf[1024];
138: va_list ap;
139:
140: va_start(ap, fmt);
141: vsnprintf(buf, sizeof(buf), fmt, ap);
142: va_end(ap);
143:
1.1.1.2 root 144: Locate(x, y);
1.1 root 145: Puts(buf);
146: }
147:
148: // テキストスクリーンに座標と属性を指定して、書式付き文字列を出力する。
149: void
1.1.1.3 root 150: TextScreen::Print(int x, int y, TA attr, const char *fmt, ...)
1.1 root 151: {
152: char buf[1024];
153: va_list ap;
154:
155: va_start(ap, fmt);
156: vsnprintf(buf, sizeof(buf), fmt, ap);
157: va_end(ap);
158:
1.1.1.2 root 159: Locate(x, y);
1.1 root 160: Puts(attr, buf);
161: }
1.1.1.2 root 162:
1.1.1.6 ! root 163: // 現在位置の属性を取得
! 164: // カーソルが画面外の場合は TA::Normal を返す。
! 165: TA
! 166: TextScreen::GetAttr() const
1.1.1.4 root 167: {
1.1.1.6 ! root 168: if (OutOfScreen) {
! 169: return TA::Normal;
! 170: }
1.1.1.4 root 171:
1.1.1.6 ! root 172: return TA(textbuf[(Y * col) + X] & 0xff00);
1.1.1.4 root 173: }
174:
1.1.1.6 ! root 175: // 現在位置の属性を attr に設定する。
! 176: // カーソルは移動しない。
1.1.1.4 root 177: void
1.1.1.6 ! root 178: TextScreen::SetAttr(TA attr)
1.1.1.4 root 179: {
1.1.1.6 ! root 180: if (OutOfScreen) {
1.1.1.4 root 181: return;
182: }
183:
1.1.1.6 ! root 184: auto& ch = textbuf[(Y * col) + X];
! 185: ch = (ch & 0xff) | (uint)attr;
1.1.1.4 root 186: }
187:
1.1.1.6 ! root 188: //
! 189: // テキストコンソール
! 190: // (行折り返しと行送りがある)
! 191: //
1.1.1.2 root 192:
1.1.1.6 ! root 193: // コンストラクタ
! 194: TextConsole::TextConsole()
! 195: : inherited()
! 196: {
! 197: Mode = Console;
1.1.1.2 root 198: }
1.1.1.5 root 199:
200: //
201: // モニターインタフェース
202: //
203:
204: // デストラクタ
205: IMonitor::~IMonitor()
206: {
207: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.