From nobody Sat Apr 11 13:59:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1775848844; cv=none; d=zohomail.com; s=zohoarc; b=FK2ASfNPZwiN+Y7vf0z7UnwkEVzCPlMTRbGWLqMAfxJ9sQoWHxRsqKf3EVZkpW/C6eX9LVPpm795skyJsJ8r3NNvD0hwNbr47LFWF8PZZOE2e68Ej6zqheYnZ8ZuvnvmJPVOfL9XWBXeQ+hdrGdpHtNtJd9LZDU2Ety5Fm469jg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775848844; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=L+3nHPs9xR2D8mkEMq5b7qsnC0hTkTfJrxig+fdBYlo=; b=h776ovQOyDbM9bj4r8TAguez/w04kgukPXrH1a8IIRC2ObWUnTZ4bCwMEwjfN4I2+McujU36jsPkrrMfIeWv4l67YI/fXZsFIxz6Liy5X7ZDPF9yicFAUqLw0sU373oDx2pEozzVaxcwrUFai7OaRuag9vssjL2T9vUpzOfn7n0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775848843920275.69654697125384; Fri, 10 Apr 2026 12:20:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wBHOx-0004hy-Lk; Fri, 10 Apr 2026 15:20:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBHOv-0004g1-QR for qemu-devel@nongnu.org; Fri, 10 Apr 2026 15:20:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wBHOs-000170-Vc for qemu-devel@nongnu.org; Fri, 10 Apr 2026 15:20:21 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-jtfE0P7fOAig-na2HDDHVQ-1; Fri, 10 Apr 2026 15:20:15 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0A7FA19560BB; Fri, 10 Apr 2026 19:20:14 +0000 (UTC) Received: from localhost (unknown [10.44.22.4]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 42DDF1801ACE; Fri, 10 Apr 2026 19:20:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775848818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L+3nHPs9xR2D8mkEMq5b7qsnC0hTkTfJrxig+fdBYlo=; b=gIBEn14NZQO7mcnfrXktjhAoxNAW0KldkUyOVebIBw66qTuUi8MKH6mOhwyATWtU6oR7x0 H7aCpW7UTQspkF5YGwbjS68f0BilNLro39xVH+mk1Q40hHQXmaRi9nGg3QEg+pfdbEAXFc E7uWD+WxnKL3WWid7paPTpS8r8oLoDQ= X-MC-Unique: jtfE0P7fOAig-na2HDDHVQ-1 X-Mimecast-MFC-AGG-ID: jtfE0P7fOAig-na2HDDHVQ_1775848814 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 10 Apr 2026 23:18:35 +0400 Subject: [PATCH v2 13/67] ui/console-vc: introduce QemuVT100 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260410-qemu-vnc-v2-13-231416f76dc3@redhat.com> References: <20260410-qemu-vnc-v2-0-231416f76dc3@redhat.com> In-Reply-To: <20260410-qemu-vnc-v2-0-231416f76dc3@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Developer-Signature: v=1; a=openpgp-sha256; l=28456; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=5qFx7O1tTryueCgr78HCGFQy8xKJFAZYAw5dmxbXGno=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBp2U0Usn9NDLkDIVGcTE5NIt0lyX6IA841K3Ff4 rKXL/HWk6GJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCadlNFAAKCRDa6OEJdZac 5aMsD/4yLqeuuM7moJpAaPsfIkXQ+DUt+b0lN0Z7tqn9RiE/9BOxYn+J5qCZk1t1G4V5HxQs3Y1 oWrH2OJkPMevI6kV8rnlfafM0+ZiGlpCMENcwEK5dS2WBCTwRGVwNaKYzCKETRyKfGQEfYifIW3 BkFcOpkxYuorm2ghvDt/Ol0KK3nex8To/9SkP1N3RjtDb8FPUP/63yOCRDucRQIMeYJ+qoIQ3yb EqXY9OL29OuwxdEIemiPsoR0k0W9EVxqOcbLN03EjqQ4XxgoD4CRa+QWLJuwXtcirmcVHfggt60 7tMoI/GNGwTA0Jbfv7rn6+FGULetRnT/Dr4GxDq7bJpx5+1tBPiOKKpI8su+5fmwowNt85ZAyE8 2uc+nGGLpRyVBVmcdQpqxGciIJrQprDxcmdr1CeNTQYaPeh38bt7WcgxgiD+GoMoizlhMtXa5lK wmsiGVJDDSKwgVUQ5UfJ6UMIsMayar/sDH+ABnOsmz4gJwH4qXOFE9iAc8yVRfPbnD5CxYmzFHS vkwVPI/bvdvpl5+pw9R/eCTh7cpAKN6OgnPrxAXYMFYH8IPCAAN/VlypK8cHwxtdrALaHwtQjOT 3le8jHQxQeDU99X1w/FWTQFGEWOAuCfdWBuwiZ3wK3uXOFUIT2xBUUXzbVDAwW6BI7azNjbYbLi tQreR9yYq3pqBmg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 7 X-Spam_score: 0.7 X-Spam_bar: / X-Spam_report: (0.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1775848845040158500 Start moving VT100 emulation specific code in a different structure. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Marc-Andr=C3=A9 Lureau --- ui/console-vc.c | 399 +++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 210 insertions(+), 189 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index 7b9acf1adb1..cc061dff769 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -48,9 +48,7 @@ enum TTYState { TTY_STATE_OSC, }; =20 -typedef struct QemuTextConsole { - QemuConsole parent; - +typedef struct QemuVT100 { int width; int height; int total_height; @@ -66,7 +64,12 @@ typedef struct QemuTextConsole { int update_y0; int update_x1; int update_y1; +} QemuVT100; =20 +typedef struct QemuTextConsole { + QemuConsole parent; + + QemuVT100 vt; Chardev *chr; /* fifo for key pressed */ Fifo8 out_fifo; @@ -183,37 +186,40 @@ static void vga_putcharxy(QemuConsole *s, int x, int = y, int ch, =20 static void invalidate_xy(QemuTextConsole *s, int x, int y) { + QemuVT100 *vt =3D &s->vt; + if (!qemu_console_is_visible(QEMU_CONSOLE(s))) { return; } - if (s->update_x0 > x * FONT_WIDTH) - s->update_x0 =3D x * FONT_WIDTH; - if (s->update_y0 > y * FONT_HEIGHT) - s->update_y0 =3D y * FONT_HEIGHT; - if (s->update_x1 < (x + 1) * FONT_WIDTH) - s->update_x1 =3D (x + 1) * FONT_WIDTH; - if (s->update_y1 < (y + 1) * FONT_HEIGHT) - s->update_y1 =3D (y + 1) * FONT_HEIGHT; + if (vt->update_x0 > x * FONT_WIDTH) + vt->update_x0 =3D x * FONT_WIDTH; + if (vt->update_y0 > y * FONT_HEIGHT) + vt->update_y0 =3D y * FONT_HEIGHT; + if (vt->update_x1 < (x + 1) * FONT_WIDTH) + vt->update_x1 =3D (x + 1) * FONT_WIDTH; + if (vt->update_y1 < (y + 1) * FONT_HEIGHT) + vt->update_y1 =3D (y + 1) * FONT_HEIGHT; } =20 static void console_show_cursor(QemuTextConsole *s, int show) { + QemuVT100 *vt =3D &s->vt; TextCell *c; int y, y1; - int x =3D s->x; + int x =3D vt->x; =20 - s->cursor_invalidate =3D 1; + vt->cursor_invalidate =3D 1; =20 - if (x >=3D s->width) { - x =3D s->width - 1; + if (x >=3D vt->width) { + x =3D vt->width - 1; } - y1 =3D (s->y_base + s->y) % s->total_height; - y =3D y1 - s->y_displayed; + y1 =3D (vt->y_base + vt->y) % vt->total_height; + y =3D y1 - vt->y_displayed; if (y < 0) { - y +=3D s->total_height; + y +=3D vt->total_height; } - if (y < s->height) { - c =3D &s->cells[y1 * s->width + x]; + if (y < vt->height) { + c =3D &vt->cells[y1 * vt->width + x]; if (show && cursor_visible_phase) { TextAttributes t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; t_attrib.invers =3D !(t_attrib.invers); /* invert fg and bg */ @@ -228,27 +234,28 @@ static void console_show_cursor(QemuTextConsole *s, i= nt show) static void console_refresh(QemuTextConsole *s) { DisplaySurface *surface =3D qemu_console_surface(QEMU_CONSOLE(s)); + QemuVT100 *vt =3D &s->vt; TextCell *c; int x, y, y1; =20 assert(surface); - s->text_x[0] =3D 0; - s->text_y[0] =3D 0; - s->text_x[1] =3D s->width - 1; - s->text_y[1] =3D s->height - 1; - s->cursor_invalidate =3D 1; + vt->text_x[0] =3D 0; + vt->text_y[0] =3D 0; + vt->text_x[1] =3D vt->width - 1; + vt->text_y[1] =3D vt->height - 1; + vt->cursor_invalidate =3D 1; =20 qemu_console_fill_rect(QEMU_CONSOLE(s), 0, 0, surface_width(surface), = surface_height(surface), color_table_rgb[0][QEMU_COLOR_BLACK]); - y1 =3D s->y_displayed; - for (y =3D 0; y < s->height; y++) { - c =3D s->cells + y1 * s->width; - for (x =3D 0; x < s->width; x++) { + y1 =3D vt->y_displayed; + for (y =3D 0; y < vt->height; y++) { + c =3D vt->cells + y1 * vt->width; + for (x =3D 0; x < vt->width; x++) { vga_putcharxy(QEMU_CONSOLE(s), x, y, c->ch, &(c->t_attrib)); c++; } - if (++y1 =3D=3D s->total_height) { + if (++y1 =3D=3D vt->total_height) { y1 =3D 0; } } @@ -259,28 +266,29 @@ static void console_refresh(QemuTextConsole *s) =20 static void console_scroll(QemuTextConsole *s, int ydelta) { + QemuVT100 *vt =3D &s->vt; int i, y1; =20 if (ydelta > 0) { for(i =3D 0; i < ydelta; i++) { - if (s->y_displayed =3D=3D s->y_base) + if (vt->y_displayed =3D=3D vt->y_base) break; - if (++s->y_displayed =3D=3D s->total_height) - s->y_displayed =3D 0; + if (++vt->y_displayed =3D=3D vt->total_height) + vt->y_displayed =3D 0; } } else { ydelta =3D -ydelta; - i =3D s->backscroll_height; - if (i > s->total_height - s->height) - i =3D s->total_height - s->height; - y1 =3D s->y_base - i; + i =3D vt->backscroll_height; + if (i > vt->total_height - vt->height) + i =3D vt->total_height - vt->height; + y1 =3D vt->y_base - i; if (y1 < 0) - y1 +=3D s->total_height; + y1 +=3D vt->total_height; for(i =3D 0; i < ydelta; i++) { - if (s->y_displayed =3D=3D y1) + if (vt->y_displayed =3D=3D y1) break; - if (--s->y_displayed < 0) - s->y_displayed =3D s->total_height - 1; + if (--vt->y_displayed < 0) + vt->y_displayed =3D vt->total_height - 1; } } console_refresh(s); @@ -306,6 +314,7 @@ static void kbd_send_chars(QemuTextConsole *s) /* called when an ascii key is pressed */ void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym) { + QemuVT100 *vt =3D &s->vt; uint8_t buf[16], *q; int c; uint32_t num_free; @@ -338,13 +347,13 @@ void qemu_text_console_handle_keysym(QemuTextConsole = *s, int keysym) *q++ =3D '\033'; *q++ =3D '['; *q++ =3D keysym & 0xff; - } else if (s->echo && (keysym =3D=3D '\r' || keysym =3D=3D '\n')) { + } else if (vt->echo && (keysym =3D=3D '\r' || keysym =3D=3D '\n'))= { qemu_chr_write(s->chr, (uint8_t *)"\r", 1, true); *q++ =3D '\n'; } else { *q++ =3D keysym; } - if (s->echo) { + if (vt->echo) { qemu_chr_write(s->chr, buf, q - buf, true); } num_free =3D fifo8_num_free(&s->out_fifo); @@ -357,29 +366,30 @@ void qemu_text_console_handle_keysym(QemuTextConsole = *s, int keysym) static void text_console_update(void *opaque, console_ch_t *chardata) { QemuTextConsole *s =3D QEMU_TEXT_CONSOLE(opaque); + QemuVT100 *vt =3D &s->vt; int i, j, src; =20 - if (s->text_x[0] <=3D s->text_x[1]) { - src =3D (s->y_base + s->text_y[0]) * s->width; - chardata +=3D s->text_y[0] * s->width; - for (i =3D s->text_y[0]; i <=3D s->text_y[1]; i ++) - for (j =3D 0; j < s->width; j++, src++) { + if (vt->text_x[0] <=3D vt->text_x[1]) { + src =3D (vt->y_base + vt->text_y[0]) * vt->width; + chardata +=3D vt->text_y[0] * vt->width; + for (i =3D vt->text_y[0]; i <=3D vt->text_y[1]; i ++) + for (j =3D 0; j < vt->width; j++, src++) { console_write_ch(chardata ++, - ATTR2CHTYPE(s->cells[src].ch, - s->cells[src].t_attrib.fgcol, - s->cells[src].t_attrib.bgcol, - s->cells[src].t_attrib.bold)); + ATTR2CHTYPE(vt->cells[src].ch, + vt->cells[src].t_attrib.fgcol, + vt->cells[src].t_attrib.bgcol, + vt->cells[src].t_attrib.bold)= ); } - dpy_text_update(QEMU_CONSOLE(s), s->text_x[0], s->text_y[0], - s->text_x[1] - s->text_x[0], i - s->text_y[0]); - s->text_x[0] =3D s->width; - s->text_y[0] =3D s->height; - s->text_x[1] =3D 0; - s->text_y[1] =3D 0; + dpy_text_update(QEMU_CONSOLE(s), vt->text_x[0], vt->text_y[0], + vt->text_x[1] - vt->text_x[0], i - vt->text_y[0]); + vt->text_x[0] =3D vt->width; + vt->text_y[0] =3D vt->height; + vt->text_x[1] =3D 0; + vt->text_y[1] =3D 0; } - if (s->cursor_invalidate) { - dpy_text_cursor(QEMU_CONSOLE(s), s->x, s->y); - s->cursor_invalidate =3D 0; + if (vt->cursor_invalidate) { + dpy_text_cursor(QEMU_CONSOLE(s), vt->x, vt->y); + vt->cursor_invalidate =3D 0; } } =20 @@ -393,76 +403,77 @@ static void text_console_resize(QemuTextConsole *t) =20 w =3D surface_width(s->surface) / FONT_WIDTH; h =3D surface_height(s->surface) / FONT_HEIGHT; - if (w =3D=3D t->width && h =3D=3D t->height) { + if (w =3D=3D t->vt.width && h =3D=3D t->vt.height) { return; } =20 - last_width =3D t->width; - t->width =3D w; - t->height =3D h; + last_width =3D t->vt.width; + t->vt.width =3D w; + t->vt.height =3D h; =20 - w1 =3D MIN(t->width, last_width); + w1 =3D MIN(t->vt.width, last_width); =20 - cells =3D g_new(TextCell, t->width * t->total_height + 1); - for (y =3D 0; y < t->total_height; y++) { - c =3D &cells[y * t->width]; + cells =3D g_new(TextCell, t->vt.width * t->vt.total_height + 1); + for (y =3D 0; y < t->vt.total_height; y++) { + c =3D &cells[y * t->vt.width]; if (w1 > 0) { - c1 =3D &t->cells[y * last_width]; + c1 =3D &t->vt.cells[y * last_width]; for (x =3D 0; x < w1; x++) { *c++ =3D *c1++; } } - for (x =3D w1; x < t->width; x++) { + for (x =3D w1; x < t->vt.width; x++) { c->ch =3D ' '; c->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; c++; } } - g_free(t->cells); - t->cells =3D cells; + g_free(t->vt.cells); + t->vt.cells =3D cells; } =20 static void vc_put_lf(VCChardev *vc) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; TextCell *c; int x, y1; =20 - s->y++; - if (s->y >=3D s->height) { - s->y =3D s->height - 1; + vt->y++; + if (vt->y >=3D vt->height) { + vt->y =3D vt->height - 1; =20 - if (s->y_displayed =3D=3D s->y_base) { - if (++s->y_displayed =3D=3D s->total_height) - s->y_displayed =3D 0; + if (vt->y_displayed =3D=3D vt->y_base) { + if (++vt->y_displayed =3D=3D vt->total_height) + vt->y_displayed =3D 0; } - if (++s->y_base =3D=3D s->total_height) - s->y_base =3D 0; - if (s->backscroll_height < s->total_height) - s->backscroll_height++; - y1 =3D (s->y_base + s->height - 1) % s->total_height; - c =3D &s->cells[y1 * s->width]; - for(x =3D 0; x < s->width; x++) { + if (++vt->y_base =3D=3D vt->total_height) + vt->y_base =3D 0; + if (vt->backscroll_height < vt->total_height) + vt->backscroll_height++; + y1 =3D (vt->y_base + vt->height - 1) % vt->total_height; + c =3D &vt->cells[y1 * vt->width]; + for(x =3D 0; x < vt->width; x++) { c->ch =3D ' '; c->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; c++; } - if (s->y_displayed =3D=3D s->y_base) { - s->text_x[0] =3D 0; - s->text_y[0] =3D 0; - s->text_x[1] =3D s->width - 1; - s->text_y[1] =3D s->height - 1; + if (vt->y_displayed =3D=3D vt->y_base) { + vt->text_x[0] =3D 0; + vt->text_y[0] =3D 0; + vt->text_x[1] =3D vt->width - 1; + vt->text_y[1] =3D vt->height - 1; =20 qemu_console_bitblt(QEMU_CONSOLE(s), 0, FONT_HEIGHT, 0, 0, - s->width * FONT_WIDTH, - (s->height - 1) * FONT_HEIGHT); - qemu_console_fill_rect(QEMU_CONSOLE(s), 0, (s->height - 1) * F= ONT_HEIGHT, - s->width * FONT_WIDTH, FONT_HEIGHT, + vt->width * FONT_WIDTH, + (vt->height - 1) * FONT_HEIGHT); + qemu_console_fill_rect(QEMU_CONSOLE(s), 0, (vt->height - 1) * = FONT_HEIGHT, + vt->width * FONT_WIDTH, FONT_HEIGHT, color_table_rgb[0][TEXT_ATTRIBUTES_DEFA= ULT.bgcol]); - s->update_x0 =3D 0; - s->update_y0 =3D 0; - s->update_x1 =3D s->width * FONT_WIDTH; - s->update_y1 =3D s->height * FONT_HEIGHT; + vt->update_x0 =3D 0; + vt->update_y0 =3D 0; + vt->update_x1 =3D vt->width * FONT_WIDTH; + vt->update_y1 =3D vt->height * FONT_HEIGHT; } } } @@ -567,24 +578,25 @@ static void vc_handle_escape(VCChardev *vc) static void vc_update_xy(VCChardev *vc, int x, int y) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; TextCell *c; int y1, y2; =20 - s->text_x[0] =3D MIN(s->text_x[0], x); - s->text_x[1] =3D MAX(s->text_x[1], x); - s->text_y[0] =3D MIN(s->text_y[0], y); - s->text_y[1] =3D MAX(s->text_y[1], y); + vt->text_x[0] =3D MIN(vt->text_x[0], x); + vt->text_x[1] =3D MAX(vt->text_x[1], x); + vt->text_y[0] =3D MIN(vt->text_y[0], y); + vt->text_y[1] =3D MAX(vt->text_y[1], y); =20 - y1 =3D (s->y_base + y) % s->total_height; - y2 =3D y1 - s->y_displayed; + y1 =3D (vt->y_base + y) % vt->total_height; + y2 =3D y1 - vt->y_displayed; if (y2 < 0) { - y2 +=3D s->total_height; + y2 +=3D vt->total_height; } - if (y2 < s->height) { - if (x >=3D s->width) { - x =3D s->width - 1; + if (y2 < vt->height) { + if (x >=3D vt->width) { + x =3D vt->width - 1; } - c =3D &s->cells[y1 * s->width + x]; + c =3D &vt->cells[y1 * vt->width + x]; vga_putcharxy(QEMU_CONSOLE(s), x, y2, c->ch, &(c->t_attrib)); invalidate_xy(s, x, y2); @@ -594,11 +606,12 @@ static void vc_update_xy(VCChardev *vc, int x, int y) static void vc_clear_xy(VCChardev *vc, int x, int y) { QemuTextConsole *s =3D vc->console; - int y1 =3D (s->y_base + y) % s->total_height; - if (x >=3D s->width) { - x =3D s->width - 1; + QemuVT100 *vt =3D &s->vt; + int y1 =3D (vt->y_base + y) % vt->total_height; + if (x >=3D vt->width) { + x =3D vt->width - 1; } - TextCell *c =3D &s->cells[y1 * s->width + x]; + TextCell *c =3D &vt->cells[y1 * vt->width + x]; c->ch =3D ' '; c->t_attrib =3D TEXT_ATTRIBUTES_DEFAULT; vc_update_xy(vc, x, y); @@ -647,19 +660,20 @@ static uint32_t bh_utf8_decode(uint32_t *state, uint3= 2_t *codep, uint32_t byte) static void vc_put_one(VCChardev *vc, int ch) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; TextCell *c; int y1; - if (s->x >=3D s->width) { + if (vt->x >=3D vt->width) { /* line wrap */ - s->x =3D 0; + vt->x =3D 0; vc_put_lf(vc); } - y1 =3D (s->y_base + s->y) % s->total_height; - c =3D &s->cells[y1 * s->width + s->x]; + y1 =3D (vt->y_base + vt->y) % vt->total_height; + c =3D &vt->cells[y1 * vt->width + vt->x]; c->ch =3D ch; c->t_attrib =3D vc->t_attrib; - vc_update_xy(vc, s->x, s->y); - s->x++; + vc_update_xy(vc, vt->x, vt->y); + vt->x++; } =20 static void vc_respond_str(VCChardev *vc, const char *buf) @@ -673,6 +687,7 @@ static void vc_respond_str(VCChardev *vc, const char *b= uf) static void vc_set_cursor(VCChardev *vc, int x, int y) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; =20 if (x < 0) { x =3D 0; @@ -680,15 +695,15 @@ static void vc_set_cursor(VCChardev *vc, int x, int y) if (y < 0) { y =3D 0; } - if (y >=3D s->height) { - y =3D s->height - 1; + if (y >=3D vt->height) { + y =3D vt->height - 1; } - if (x >=3D s->width) { - x =3D s->width - 1; + if (x >=3D vt->width) { + x =3D vt->width - 1; } =20 - s->x =3D x; - s->y =3D y; + vt->x =3D x; + vt->y =3D y; } =20 /** @@ -700,6 +715,7 @@ static void vc_set_cursor(VCChardev *vc, int x, int y) static void vc_csi_P(struct VCChardev *vc, unsigned int nr) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; TextCell *c1, *c2; unsigned int x1, x2, y; unsigned int end, len; @@ -707,28 +723,28 @@ static void vc_csi_P(struct VCChardev *vc, unsigned i= nt nr) if (!nr) { nr =3D 1; } - if (nr > s->width - s->x) { - nr =3D s->width - s->x; + if (nr > vt->width - vt->x) { + nr =3D vt->width - vt->x; if (!nr) { return; } } =20 - x1 =3D s->x; - x2 =3D s->x + nr; - len =3D s->width - x2; + x1 =3D vt->x; + x2 =3D vt->x + nr; + len =3D vt->width - x2; if (len) { - y =3D (s->y_base + s->y) % s->total_height; - c1 =3D &s->cells[y * s->width + x1]; - c2 =3D &s->cells[y * s->width + x2]; + y =3D (vt->y_base + vt->y) % vt->total_height; + c1 =3D &vt->cells[y * vt->width + x1]; + c2 =3D &vt->cells[y * vt->width + x2]; memmove(c1, c2, len * sizeof(*c1)); for (end =3D x1 + len; x1 < end; x1++) { - vc_update_xy(vc, x1, s->y); + vc_update_xy(vc, x1, vt->y); } } /* Clear the rest */ - for (; x1 < s->width; x1++) { - vc_clear_xy(vc, x1, s->y); + for (; x1 < vt->width; x1++) { + vc_clear_xy(vc, x1, vt->y); } } =20 @@ -741,6 +757,7 @@ static void vc_csi_P(struct VCChardev *vc, unsigned int= nr) static void vc_csi_at(struct VCChardev *vc, unsigned int nr) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; TextCell *c1, *c2; unsigned int x1, x2, y; unsigned int end, len; @@ -748,28 +765,28 @@ static void vc_csi_at(struct VCChardev *vc, unsigned = int nr) if (!nr) { nr =3D 1; } - if (nr > s->width - s->x) { - nr =3D s->width - s->x; + if (nr > vt->width - vt->x) { + nr =3D vt->width - vt->x; if (!nr) { return; } } =20 - x1 =3D s->x + nr; - x2 =3D s->x; - len =3D s->width - x1; + x1 =3D vt->x + nr; + x2 =3D vt->x; + len =3D vt->width - x1; if (len) { - y =3D (s->y_base + s->y) % s->total_height; - c1 =3D &s->cells[y * s->width + x1]; - c2 =3D &s->cells[y * s->width + x2]; + y =3D (vt->y_base + vt->y) % vt->total_height; + c1 =3D &vt->cells[y * vt->width + x1]; + c2 =3D &vt->cells[y * vt->width + x2]; memmove(c1, c2, len * sizeof(*c1)); for (end =3D x1 + len; x1 < end; x1++) { - vc_update_xy(vc, x1, s->y); + vc_update_xy(vc, x1, vt->y); } } /* Insert blanks */ - for (x1 =3D s->x; x1 < s->x + nr; x1++) { - vc_clear_xy(vc, x1, s->y); + for (x1 =3D vt->x; x1 < vt->x + nr; x1++) { + vc_clear_xy(vc, x1, vt->y); } } =20 @@ -779,9 +796,10 @@ static void vc_csi_at(struct VCChardev *vc, unsigned i= nt nr) static void vc_save_cursor(VCChardev *vc) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; =20 - vc->x_saved =3D s->x; - vc->y_saved =3D s->y; + vc->x_saved =3D vt->x; + vc->y_saved =3D vt->y; vc->t_attrib_saved =3D vc->t_attrib; } =20 @@ -792,15 +810,17 @@ static void vc_save_cursor(VCChardev *vc) static void vc_restore_cursor(VCChardev *vc) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; =20 - s->x =3D vc->x_saved; - s->y =3D vc->y_saved; + vt->x =3D vc->x_saved; + vt->y =3D vc->y_saved; vc->t_attrib =3D vc->t_attrib_saved; } =20 static void vc_putchar(VCChardev *vc, int ch) { QemuTextConsole *s =3D vc->console; + QemuVT100 *vt =3D &s->vt; int i; int x, y; g_autofree char *response =3D NULL; @@ -827,21 +847,21 @@ static void vc_putchar(VCChardev *vc, int ch) vc->utf8_state =3D BH_UTF8_ACCEPT; switch(ch) { case '\r': /* carriage return */ - s->x =3D 0; + vt->x =3D 0; break; case '\n': /* newline */ vc_put_lf(vc); break; case '\b': /* backspace */ - if (s->x > 0) - s->x--; + if (vt->x > 0) + vt->x--; break; case '\t': /* tabspace */ - if (s->x + (8 - (s->x % 8)) > s->width) { - s->x =3D 0; + if (vt->x + (8 - (vt->x % 8)) > vt->width) { + vt->x =3D 0; vc_put_lf(vc); } else { - s->x =3D s->x + (8 - (s->x % 8)); + vt->x =3D vt->x + (8 - (vt->x % 8)); } break; case '\a': /* alert aka. bell */ @@ -909,32 +929,32 @@ static void vc_putchar(VCChardev *vc, int ch) if (vc->esc_params[0] =3D=3D 0) { vc->esc_params[0] =3D 1; } - vc_set_cursor(vc, s->x, s->y - vc->esc_params[0]); + vc_set_cursor(vc, vt->x, vt->y - vc->esc_params[0]); break; case 'B': /* move cursor down */ if (vc->esc_params[0] =3D=3D 0) { vc->esc_params[0] =3D 1; } - vc_set_cursor(vc, s->x, s->y + vc->esc_params[0]); + vc_set_cursor(vc, vt->x, vt->y + vc->esc_params[0]); break; case 'C': /* move cursor right */ if (vc->esc_params[0] =3D=3D 0) { vc->esc_params[0] =3D 1; } - vc_set_cursor(vc, s->x + vc->esc_params[0], s->y); + vc_set_cursor(vc, vt->x + vc->esc_params[0], vt->y); break; case 'D': /* move cursor left */ if (vc->esc_params[0] =3D=3D 0) { vc->esc_params[0] =3D 1; } - vc_set_cursor(vc, s->x - vc->esc_params[0], s->y); + vc_set_cursor(vc, vt->x - vc->esc_params[0], vt->y); break; case 'G': /* move cursor to column */ - vc_set_cursor(vc, vc->esc_params[0] - 1, s->y); + vc_set_cursor(vc, vc->esc_params[0] - 1, vt->y); break; case 'f': case 'H': @@ -945,9 +965,9 @@ static void vc_putchar(VCChardev *vc, int ch) switch (vc->esc_params[0]) { case 0: /* clear to end of screen */ - for (y =3D s->y; y < s->height; y++) { - for (x =3D 0; x < s->width; x++) { - if (y =3D=3D s->y && x < s->x) { + for (y =3D vt->y; y < vt->height; y++) { + for (x =3D 0; x < vt->width; x++) { + if (y =3D=3D vt->y && x < vt->x) { continue; } vc_clear_xy(vc, x, y); @@ -956,9 +976,9 @@ static void vc_putchar(VCChardev *vc, int ch) break; case 1: /* clear from beginning of screen */ - for (y =3D 0; y <=3D s->y; y++) { - for (x =3D 0; x < s->width; x++) { - if (y =3D=3D s->y && x > s->x) { + for (y =3D 0; y <=3D vt->y; y++) { + for (x =3D 0; x < vt->width; x++) { + if (y =3D=3D vt->y && x > vt->x) { break; } vc_clear_xy(vc, x, y); @@ -967,8 +987,8 @@ static void vc_putchar(VCChardev *vc, int ch) break; case 2: /* clear entire screen */ - for (y =3D 0; y < s->height; y++) { - for (x =3D 0; x < s->width; x++) { + for (y =3D 0; y < vt->height; y++) { + for (x =3D 0; x < vt->width; x++) { vc_clear_xy(vc, x, y); } } @@ -979,20 +999,20 @@ static void vc_putchar(VCChardev *vc, int ch) switch (vc->esc_params[0]) { case 0: /* clear to eol */ - for(x =3D s->x; x < s->width; x++) { - vc_clear_xy(vc, x, s->y); + for(x =3D vt->x; x < vt->width; x++) { + vc_clear_xy(vc, x, vt->y); } break; case 1: /* clear from beginning of line */ - for (x =3D 0; x <=3D s->x && x < s->width; x++) { - vc_clear_xy(vc, x, s->y); + for (x =3D 0; x <=3D vt->x && x < vt->width; x++) { + vc_clear_xy(vc, x, vt->y); } break; case 2: /* clear entire line */ - for(x =3D 0; x < s->width; x++) { - vc_clear_xy(vc, x, s->y); + for(x =3D 0; x < vt->width; x++) { + vc_clear_xy(vc, x, vt->y); } break; } @@ -1012,7 +1032,7 @@ static void vc_putchar(VCChardev *vc, int ch) case 6: /* report cursor position */ response =3D g_strdup_printf("\033[%d;%dR", - s->y + 1, s->x + 1); + vt->y + 1, vt->x + 1); vc_respond_str(vc, response); break; } @@ -1063,21 +1083,22 @@ static int vc_chr_write(Chardev *chr, const uint8_t= *buf, int len) { VCChardev *drv =3D VC_CHARDEV(chr); QemuTextConsole *s =3D drv->console; + QemuVT100 *vt =3D &s->vt; int i; =20 - s->update_x0 =3D s->width * FONT_WIDTH; - s->update_y0 =3D s->height * FONT_HEIGHT; - s->update_x1 =3D 0; - s->update_y1 =3D 0; + vt->update_x0 =3D vt->width * FONT_WIDTH; + vt->update_y0 =3D vt->height * FONT_HEIGHT; + vt->update_x1 =3D 0; + vt->update_y1 =3D 0; console_show_cursor(s, 0); for(i =3D 0; i < len; i++) { vc_putchar(drv, buf[i]); } console_show_cursor(s, 1); - if (s->update_x0 < s->update_x1) { - dpy_gfx_update(QEMU_CONSOLE(s), s->update_x0, s->update_y0, - s->update_x1 - s->update_x0, - s->update_y1 - s->update_y0); + if (vt->update_x0 < vt->update_x1) { + dpy_gfx_update(QEMU_CONSOLE(s), vt->update_x0, vt->update_y0, + vt->update_x1 - vt->update_x0, + vt->update_y1 - vt->update_y0); } return len; } @@ -1136,7 +1157,7 @@ qemu_text_console_init(Object *obj) QemuTextConsole *c =3D QEMU_TEXT_CONSOLE(obj); =20 fifo8_create(&c->out_fifo, 16); - c->total_height =3D DEFAULT_BACKSCROLL; + c->vt.total_height =3D DEFAULT_BACKSCROLL; QEMU_CONSOLE(c)->hw_ops =3D &text_console_ops; QEMU_CONSOLE(c)->hw =3D c; } @@ -1167,12 +1188,12 @@ static void vc_chr_set_echo(Chardev *chr, bool echo) { VCChardev *drv =3D VC_CHARDEV(chr); =20 - drv->console->echo =3D echo; + drv->console->vt.echo =3D echo; } =20 void qemu_text_console_update_size(QemuTextConsole *c) { - dpy_text_resize(QEMU_CONSOLE(c), c->width, c->height); + dpy_text_resize(QEMU_CONSOLE(c), c->vt.width, c->vt.height); } =20 static bool vc_chr_open(Chardev *chr, ChardevBackend *backend, Error **err= p) --=20 2.53.0