--- nono/lib/textscreen.cpp 2026/04/29 17:04:51 1.1.1.6 +++ nono/lib/textscreen.cpp 2026/04/29 17:05:26 1.1.1.11 @@ -4,12 +4,12 @@ // Licensed under nono-license.txt // -#include "textscreen.h" - // // テキストスクリーン // +#include "textscreen.h" + // コンストラクタ TextScreen::TextScreen() { @@ -28,13 +28,14 @@ TextScreen::~TextScreen() // 初期化 void -TextScreen::Init(int arg_col, int arg_row) +TextScreen::Init(int arg_col, int arg_row, ModeKind mode) { assert(arg_col > 0); assert(arg_row > 0); col = arg_col; row = arg_row; + Mode = mode; textbuf.resize(col * row); X = 0; @@ -71,16 +72,17 @@ TextScreen::ScrollUp() void TextScreen::Putc(uint16 ch) { - if (OutOfScreen) { + if (ch == '\n') { + CRLF(); return; } - if (ch == '\n') { - CRLF(); - } else { - textbuf[(Y * col) + X] = ch; - Ascend(); + if (OutOfScreen) { + return; } + + textbuf[(Y * col) + X] = ch; + Ascend(); } // 現在のカーソル位置の文字を取得 @@ -103,7 +105,8 @@ void TextScreen::Puts(const char *str) { while (*str != '\0') { - Putc(*str++); + uint16 ch = (uint8)*str++; + Putc(ch); } } @@ -185,23 +188,26 @@ TextScreen::SetAttr(TA attr) ch = (ch & 0xff) | (uint)attr; } -// -// テキストコンソール -// (行折り返しと行送りがある) -// - -// コンストラクタ -TextConsole::TextConsole() - : inherited() +// src の src_y 行目から rows 行をこのスクリーンの dst_y 行目以降にコピーする。 +// 双方のカーソルは移動しない。 +// もし row がどちらかではみ出た場合はコピーをそこで終了する。 +// src と dst (この screen) の桁数が違うと assert する。 +void +TextScreen::CopyRowsFrom(int dst_y, int rows, const TextScreen& src, int src_y) { - Mode = Console; -} + assert(GetCol() == src.GetCol()); -// -// モニターインタフェース -// + const auto& srcbuf = src.GetBuf(); -// デストラクタ -IMonitor::~IMonitor() -{ + // rows を小さいほうに揃える。 + if (rows > GetRow() - dst_y) { + rows = GetRow() - dst_y; + } + if (rows > src.GetRow() - src_y) { + rows = src.GetRow() - src_y; + } + + // 内部構造を知っているので一気にコピー。 + memcpy(&textbuf[dst_y * col], &srcbuf[src_y * col], + sizeof(textbuf[0]) * col * rows); }