From nobody Tue Nov 26 20:26:22 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015651; cv=none; d=zohomail.com; s=zohoarc; b=Q+ypiZLc1z9xxrz82MD0nNbZndyvL4gfqM+zPs1P98huZS9TLc8yQm1ObiBZJuYpF7RtyTZNe0PrOoEg2k3df4+WxYIEcVNcIWjWkNDsL5VI3EO1X8A9xW34R/bNENPRHFWEJRoz1WONVd3d+ZIhJ5WEAJ5M/57l/sm33eK6b9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015651; 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=p3Cfhng1m30gY0FPzL64Bq2Z6lQcD2J+KCqhTI1oPmc=; b=FxoOOSMkcwfzzdeHJK7Zsey6lIj3Gr2gxvJrk5jHhzecwKt7VkSwPqEGcgk+kShT6UGljCpckjZ4ohTlXkbt/WZtGQ2bj0O9nuDRLG+AYkm2CLHuJS3ey4bKmEr12iWZDHTLVqDW7gjxfKz2pnc4GJKK6Swqlbm5y3l3/AfdsyU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015651152878.890333080152; Sun, 31 Dec 2023 01:40:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIT-0003UF-Fy; Sun, 31 Dec 2023 04:39:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIC-0003Lq-O0 for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:46 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsI9-0001Oi-6x for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:35 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-QbV0TZsmMhS9OnEfM7ua-g-1; Sun, 31 Dec 2023 04:39:25 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-40d8687b0caso1551885e9.0 for ; Sun, 31 Dec 2023 01:39:25 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id d13-20020a05600c34cd00b0040d833195cdsm4871234wmq.37.2023.12.31.01.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015572; 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=p3Cfhng1m30gY0FPzL64Bq2Z6lQcD2J+KCqhTI1oPmc=; b=H6y6Fg43H3SZ1/aOPCCz2sfbuqTLfYEn3ldwSWNMHECWZYEjAPI5+bRyUJXfDOUPvDSU57 8KOIeNRotnx9ADl+oclDZhy6MNIaeKZ0X+0Jt6IAsviIWBbVY2LbZAfoGhmgASlRyyixSv 4iNoj7FxRI6vkzLbm8loP8H2r9PnMgU= X-MC-Unique: QbV0TZsmMhS9OnEfM7ua-g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015563; x=1704620363; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p3Cfhng1m30gY0FPzL64Bq2Z6lQcD2J+KCqhTI1oPmc=; b=SLGsxwjrjtfzGg4zV2gvAY2imV6ASHJe64eRO+n+a/tvlEnQlS7AY1AFmnIYZ08JWn v/Q3Zc2rFDYfesEGInSA6npGpj4Sbb4B6kEX1by+2s0VC/l6lpKHRBdzL12OEer4E8SD xz6uZ7izV6sFe6qKXtbiVaXUYjnUBAc/5HhXCI6XAdk/ZrP5AmJPnQMb1TIqzQXqqrXU f2u5+Nvzgdj6O5y1jrY7FIn4mrB3ngdSde4WmYZGDiNWdj4FLvH9v4Q+EvEujDcpR+JM NiVFs8eV11Jp9yHpvpiQeIaTs9yYyA7XWvm+gbB+ueEGXgvK2vbf4fZGdXvNk0fZHF6y 4wvQ== X-Gm-Message-State: AOJu0Yxo8ZxZJmX+6vVeO67SVsnPWmcb2LQjtYsFZsYzG6lHbDQoQGlu ZJ2W6gNIXMsWkgFuENkZ2+WRv54RpjNhJsoPU9HpcMAnLo2+iTb3Pa0R0VO2pOisrvPekjX6Tgt pDoHVrFWIFaBjzbC2Qjh31vy4nKb/cOh2pDotICP3mVh/1kZ0+DeBzNfmqcojMhl0ZhgvSfehj0 0bv8UFrJQ= X-Received: by 2002:a05:600c:1f88:b0:40d:64a8:97b2 with SMTP id je8-20020a05600c1f8800b0040d64a897b2mr2520365wmb.116.1704015563411; Sun, 31 Dec 2023 01:39:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQCobwWFOj1HLFYqzwxAloGl54Z09wVNnzTF8fn4Q5afRgAkn7uu/fGOt3MFJM6CgdpTm7NA== X-Received: by 2002:a05:600c:1f88:b0:40d:64a8:97b2 with SMTP id je8-20020a05600c1f8800b0040d64a897b2mr2520361wmb.116.1704015563178; Sun, 31 Dec 2023 01:39:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 1/8] vga: remove unused macros Date: Sun, 31 Dec 2023 10:39:11 +0100 Message-ID: <20231231093918.239549-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015652601100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: BALATON Zoltan --- hw/display/vga.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index 37557c3442a..18d966ecd3e 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -103,12 +103,6 @@ const uint8_t gr_mask[16] =3D { #define PAT(x) (x) #endif =20 -#if HOST_BIG_ENDIAN -#define BIG 1 -#else -#define BIG 0 -#endif - #if HOST_BIG_ENDIAN #define GET_PLANE(data, p) (((data) >> (24 - (p) * 8)) & 0xff) #else @@ -134,14 +128,6 @@ static const uint32_t mask16[16] =3D { PAT(0xffffffff), }; =20 -#undef PAT - -#if HOST_BIG_ENDIAN -#define PAT(x) (x) -#else -#define PAT(x) cbswap_32(x) -#endif - static uint32_t expand4[256]; static uint16_t expand2[256]; static uint8_t expand4to8[16]; --=20 2.43.0 From nobody Tue Nov 26 20:26:22 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015664; cv=none; d=zohomail.com; s=zohoarc; b=DaSSJBhBKdp/SmZsTpGiHqBu5dRJscYRhq5FBulkyJZe/sNcKQz6nJdpsGS7iGv/WwfEe3IG//AqWM4RgRIK1XUNuC35UyyA75gEomWlZNvUFOrZexZYR6ZIQLxRk2Mvla3UFAL/zW0wthjd5VAlmDSfzTtjiQyJAmP2MXJRHjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015664; 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=Brgk5ll/owavblqQEbRTAQK4Nkc5XOQsQQRZds+K5As=; b=Qxzk0gRc5b4raXcYVDL1jdy7Gqx+Zf3AzMltNd/74ldjFW23j6Th3QsKGBGM2TtDJcesuk2H2ftGN78Ha3z6UkiqEfBkaepmV6Manjppc/qxXahwhcXFrEAx8j38u6R+ROmZxAUN3CI7NeJcf3u6qNJNyDoCT4AlN/1chxADuQ8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015664193654.4043711281828; Sun, 31 Dec 2023 01:41:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIX-0003Xq-Bn; Sun, 31 Dec 2023 04:39:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIL-0003MZ-2m for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIC-0001P2-HQ for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:40 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-sE7lhCfKPsiaBFxJfkSPvg-1; Sun, 31 Dec 2023 04:39:28 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3367c893deeso5711349f8f.2 for ; Sun, 31 Dec 2023 01:39:28 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id dr15-20020a5d5f8f000000b003373ece28efsm803004wrb.29.2023.12.31.01.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015574; 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=Brgk5ll/owavblqQEbRTAQK4Nkc5XOQsQQRZds+K5As=; b=TqVeBuZqDsE88v7gDS5ek6oKxkNgeBGAEGZ49mcBNYwEvPwwouX/reB0Cz7v8zSHsu7MwA xXhZCRS+W//rOrJeMUhy9nHtuukKVvmx8gw3uDNtf21csaBRr1ZPpeYD0uLsAjbe+UGCpM PJZ87GAX2DjbQtqY7zHHh+RIZ7tOJuk= X-MC-Unique: sE7lhCfKPsiaBFxJfkSPvg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015566; x=1704620366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Brgk5ll/owavblqQEbRTAQK4Nkc5XOQsQQRZds+K5As=; b=S9ER5aQPF7xHNb1dCn0unzFj9nK9r/8sc/aPBjPaIB9IydiHi0IkP717iG2MU280lF OHS4pb/uqSYje4Eeh2WT71NLUysDMjBbSvGFKaNAzPHBvhtoUwl3XCLTuldaMuoqdI2l D6OhL4wgBn+470+lj3L7MhunXamSlOfSZAKIvXBcy+7MrMyrobejaLlUl8FWJKQ4ZBad v+8M/AdvvEj9vNPBIieLTAWh+VOpNajup09N+dEXwh+SciAnDa2eXBcneGwDU0dRadcQ f96aR0GRtI7350A89JFQnVeVxflr5iqvh0GF6SeFGBxq7yF5wF+3X8TzVnooqdvZ5un7 Q/+w== X-Gm-Message-State: AOJu0YyPbQqeA1VnuxgKhV3Wa6B3e3xDs0wtiWJjzsqpISL9J6ril3Ou ZUBbK6NCGsaYeF6LuLNbGxd53Ak/QgRUo/HE8s39+FN5iSBKOmECo4lXU3FF1ChUOfw1Q1PiS4s GJVuF+fPHMbn+307oZh4mk4VjtvP6KIED+nqdWcJr73ONdQJUduiXjKuzyFoVdmPE5exbb0b/nY HMUbI68LE= X-Received: by 2002:a5d:438c:0:b0:336:5e98:a231 with SMTP id i12-20020a5d438c000000b003365e98a231mr7183914wrq.52.1704015566317; Sun, 31 Dec 2023 01:39:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgYLeDOrDThecNNJX8bvmdBKCUQaCZkAj9F6GWQvf8TEzKoiODGFWhpAVMvHnVsEVQsX7aiw== X-Received: by 2002:a5d:438c:0:b0:336:5e98:a231 with SMTP id i12-20020a5d438c000000b003365e98a231mr7183908wrq.52.1704015565798; Sun, 31 Dec 2023 01:39:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 2/8] vga: introduce VGADisplayParams Date: Sun, 31 Dec 2023 10:39:12 +0100 Message-ID: <20231231093918.239549-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015664608100007 Content-Type: text/plain; charset="utf-8" The next patches will introduce more parameters that cause a full refresh. Instead of adding arguments to get_offsets and lines to update_basic_params, do everything through a struct. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/display/cirrus_vga.c | 24 +++++------- hw/display/vga.c | 82 +++++++++++++++++------------------------ hw/display/vga_int.h | 15 ++++---- 3 files changed, 52 insertions(+), 69 deletions(-) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index b80f98b6c4c..e6d2581d4eb 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -798,9 +798,9 @@ static int cirrus_bitblt_videotovideo_copy(CirrusVGASta= te * s) if (blit_is_unsafe(s, false)) return 0; =20 - return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr, - s->cirrus_blt_srcaddr - s->vga.start_addr, - s->cirrus_blt_width, s->cirrus_blt_height); + return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.params.start_a= ddr, + s->cirrus_blt_srcaddr - s->vga.params.start_addr, + s->cirrus_blt_width, s->cirrus_blt_height); } =20 /*************************************** @@ -1101,30 +1101,26 @@ static void cirrus_write_bitblt(CirrusVGAState * s,= unsigned reg_value) * ***************************************/ =20 -static void cirrus_get_offsets(VGACommonState *s1, - uint32_t *pline_offset, - uint32_t *pstart_addr, - uint32_t *pline_compare) +static void cirrus_get_params(VGACommonState *s1, + VGADisplayParams *params) { CirrusVGAState * s =3D container_of(s1, CirrusVGAState, vga); - uint32_t start_addr, line_offset, line_compare; + uint32_t line_offset; =20 line_offset =3D s->vga.cr[0x13] | ((s->vga.cr[0x1b] & 0x10) << 4); line_offset <<=3D 3; - *pline_offset =3D line_offset; + params->line_offset =3D line_offset; =20 - start_addr =3D (s->vga.cr[0x0c] << 8) + params->start_addr =3D (s->vga.cr[0x0c] << 8) | s->vga.cr[0x0d] | ((s->vga.cr[0x1b] & 0x01) << 16) | ((s->vga.cr[0x1b] & 0x0c) << 15) | ((s->vga.cr[0x1d] & 0x80) << 12); - *pstart_addr =3D start_addr; =20 - line_compare =3D s->vga.cr[0x18] | + params->line_compare =3D s->vga.cr[0x18] | ((s->vga.cr[0x07] & 0x10) << 4) | ((s->vga.cr[0x09] & 0x40) << 3); - *pline_compare =3D line_compare; } =20 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState * s) @@ -2925,7 +2921,7 @@ void cirrus_init_common(CirrusVGAState *s, Object *ow= ner, s->linear_mmio_mask =3D s->real_vram_size - 256; =20 s->vga.get_bpp =3D cirrus_get_bpp; - s->vga.get_offsets =3D cirrus_get_offsets; + s->vga.get_params =3D cirrus_get_params; s->vga.get_resolution =3D cirrus_get_resolution; s->vga.cursor_invalidate =3D cirrus_cursor_invalidate; s->vga.cursor_draw_line =3D cirrus_cursor_draw_line; diff --git a/hw/display/vga.c b/hw/display/vga.c index 18d966ecd3e..3bd357d72c2 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -1059,52 +1059,40 @@ static int update_palette256(VGACommonState *s) return full_update; } =20 -static void vga_get_offsets(VGACommonState *s, - uint32_t *pline_offset, - uint32_t *pstart_addr, - uint32_t *pline_compare) +static void vga_get_params(VGACommonState *s, + VGADisplayParams *params) { - uint32_t start_addr, line_offset, line_compare; - if (vbe_enabled(s)) { - line_offset =3D s->vbe_line_offset; - start_addr =3D s->vbe_start_addr; - line_compare =3D 65535; + params->line_offset =3D s->vbe_line_offset; + params->start_addr =3D s->vbe_start_addr; + params->line_compare =3D 65535; } else { /* compute line_offset in bytes */ - line_offset =3D s->cr[VGA_CRTC_OFFSET]; - line_offset <<=3D 3; + params->line_offset =3D s->cr[VGA_CRTC_OFFSET] << 3; =20 /* starting address */ - start_addr =3D s->cr[VGA_CRTC_START_LO] | + params->start_addr =3D s->cr[VGA_CRTC_START_LO] | (s->cr[VGA_CRTC_START_HI] << 8); =20 /* line compare */ - line_compare =3D s->cr[VGA_CRTC_LINE_COMPARE] | + params->line_compare =3D s->cr[VGA_CRTC_LINE_COMPARE] | ((s->cr[VGA_CRTC_OVERFLOW] & 0x10) << 4) | ((s->cr[VGA_CRTC_MAX_SCAN] & 0x40) << 3); } - *pline_offset =3D line_offset; - *pstart_addr =3D start_addr; - *pline_compare =3D line_compare; } =20 /* update start_addr and line_offset. Return TRUE if modified */ static int update_basic_params(VGACommonState *s) { int full_update; - uint32_t start_addr, line_offset, line_compare; + VGADisplayParams current; =20 full_update =3D 0; =20 - s->get_offsets(s, &line_offset, &start_addr, &line_compare); + s->get_params(s, ¤t); =20 - if (line_offset !=3D s->line_offset || - start_addr !=3D s->start_addr || - line_compare !=3D s->line_compare) { - s->line_offset =3D line_offset; - s->start_addr =3D start_addr; - s->line_compare =3D line_compare; + if (memcmp(¤t, &s->params, sizeof(current))) { + s->params =3D current; full_update =3D 1; } return full_update; @@ -1205,7 +1193,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) } full_update |=3D update_basic_params(s); =20 - line_offset =3D s->line_offset; + line_offset =3D s->params.line_offset; =20 vga_get_text_resolution(s, &width, &height, &cw, &cheight); if ((height * width) <=3D 1) { @@ -1244,7 +1232,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) } =20 cursor_offset =3D ((s->cr[VGA_CRTC_CURSOR_HI] << 8) | - s->cr[VGA_CRTC_CURSOR_LO]) - s->start_addr; + s->cr[VGA_CRTC_CURSOR_LO]) - s->params.start_addr; if (cursor_offset !=3D s->cursor_offset || s->cr[VGA_CRTC_CURSOR_START] !=3D s->cursor_start || s->cr[VGA_CRTC_CURSOR_END] !=3D s->cursor_end) { @@ -1258,7 +1246,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) s->cursor_start =3D s->cr[VGA_CRTC_CURSOR_START]; s->cursor_end =3D s->cr[VGA_CRTC_CURSOR_END]; } - cursor_ptr =3D s->vram_ptr + (s->start_addr + cursor_offset) * 4; + cursor_ptr =3D s->vram_ptr + (s->params.start_addr + cursor_offset) * = 4; if (now >=3D s->cursor_blink_time) { s->cursor_blink_time =3D now + VGA_TEXT_CURSOR_PERIOD_MS / 2; s->cursor_visible_phase =3D !s->cursor_visible_phase; @@ -1268,7 +1256,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) linesize =3D surface_stride(surface); ch_attr_ptr =3D s->last_ch_attr; line =3D 0; - offset =3D s->start_addr * 4; + offset =3D s->params.start_addr * 4; for(cy =3D 0; cy < height; cy++) { d1 =3D dest; src =3D s->vram_ptr + offset; @@ -1348,7 +1336,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) dest +=3D linesize * cheight; line1 =3D line + cheight; offset +=3D line_offset; - if (line < s->line_compare && line1 >=3D s->line_compare) { + if (line < s->params.line_compare && line1 >=3D s->params.line_com= pare) { offset =3D 0; } line =3D line1; @@ -1478,10 +1466,10 @@ static void vga_draw_graphic(VGACommonState *s, int= full_update) disp_width =3D width; depth =3D s->get_bpp(s); =20 - region_start =3D (s->start_addr * 4); - region_end =3D region_start + (ram_addr_t)s->line_offset * height; + region_start =3D (s->params.start_addr * 4); + region_end =3D region_start + (ram_addr_t)s->params.line_offset * heig= ht; region_end +=3D width * depth / 8; /* scanline length */ - region_end -=3D s->line_offset; + region_end -=3D s->params.line_offset; if (region_end > s->vbe_size || depth =3D=3D 0 || depth =3D=3D 15) { /* * We land here on: @@ -1546,7 +1534,7 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) share_surface =3D false; } =20 - if (s->line_offset !=3D s->last_line_offset || + if (s->params.line_offset !=3D s->last_line_offset || disp_width !=3D s->last_width || height !=3D s->last_height || s->last_depth !=3D depth || @@ -1557,12 +1545,12 @@ static void vga_draw_graphic(VGACommonState *s, int= full_update) s->last_scr_height =3D height; s->last_width =3D disp_width; s->last_height =3D height; - s->last_line_offset =3D s->line_offset; + s->last_line_offset =3D s->params.line_offset; s->last_depth =3D depth; s->last_byteswap =3D byteswap; full_update =3D 1; } - if (surface_data(surface) !=3D s->vram_ptr + (s->start_addr * 4) + if (surface_data(surface) !=3D s->vram_ptr + (s->params.start_addr * 4) && is_buffer_shared(surface)) { /* base address changed (page flip) -> shared display surfaces * must be updated with the new base address */ @@ -1572,8 +1560,8 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) if (full_update) { if (share_surface) { surface =3D qemu_create_displaysurface_from(disp_width, - height, format, s->line_offset, - s->vram_ptr + (s->start_addr * 4)); + height, format, s->params.line_offset, + s->vram_ptr + (s->params.start_addr * 4)); dpy_gfx_replace_surface(s->con, surface); } else { qemu_console_resize(s->con, disp_width, height); @@ -1637,9 +1625,9 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) #if 0 printf("w=3D%d h=3D%d v=3D%d line_offset=3D%d cr[0x09]=3D0x%02x cr[0x1= 7]=3D0x%02x linecmp=3D%d sr[0x01]=3D0x%02x\n", width, height, v, line_offset, s->cr[9], s->cr[VGA_CRTC_MODE], - s->line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); + s->params.line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); #endif - addr1 =3D (s->start_addr * 4); + addr1 =3D (s->params.start_addr * 4); bwidth =3D DIV_ROUND_UP(width * bits, 8); y_start =3D -1; d =3D surface_data(surface); @@ -1647,7 +1635,7 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) y1 =3D 0; =20 if (!full_update) { - if (s->line_compare < height) { + if (s->params.line_compare < height) { /* split screen mode */ region_start =3D 0; } @@ -1703,14 +1691,14 @@ static void vga_draw_graphic(VGACommonState *s, int= full_update) if (!multi_run) { mask =3D (s->cr[VGA_CRTC_MODE] & 3) ^ 3; if ((y1 & mask) =3D=3D mask) - addr1 +=3D s->line_offset; + addr1 +=3D s->params.line_offset; y1++; multi_run =3D multi_scan; } else { multi_run--; } /* line compare acts on the displayed lines */ - if (y =3D=3D s->line_compare) + if (y =3D=3D s->params.line_compare) addr1 =3D 0; d +=3D linesize; } @@ -1827,9 +1815,7 @@ void vga_common_reset(VGACommonState *s) s->graphic_mode =3D -1; /* force full update */ s->shift_control =3D 0; s->double_scan =3D 0; - s->line_offset =3D 0; - s->line_compare =3D 0; - s->start_addr =3D 0; + memset(&s->params, '\0', sizeof(s->params)); s->plane_updated =3D 0; s->last_cw =3D 0; s->last_ch =3D 0; @@ -1951,7 +1937,7 @@ static void vga_update_text(void *opaque, console_ch_= t *chardata) =20 /* Update "hardware" cursor */ cursor_offset =3D ((s->cr[VGA_CRTC_CURSOR_HI] << 8) | - s->cr[VGA_CRTC_CURSOR_LO]) - s->start_addr; + s->cr[VGA_CRTC_CURSOR_LO]) - s->params.start_addr; if (cursor_offset !=3D s->cursor_offset || s->cr[VGA_CRTC_CURSOR_START] !=3D s->cursor_start || s->cr[VGA_CRTC_CURSOR_END] !=3D s->cursor_end || full_update) { @@ -1967,7 +1953,7 @@ static void vga_update_text(void *opaque, console_ch_= t *chardata) s->cursor_end =3D s->cr[VGA_CRTC_CURSOR_END]; } =20 - src =3D (uint32_t *) s->vram_ptr + s->start_addr; + src =3D (uint32_t *) s->vram_ptr + s->params.start_addr; dst =3D chardata; =20 if (full_update) { @@ -2212,7 +2198,7 @@ bool vga_common_init(VGACommonState *s, Object *obj, = Error **errp) xen_register_framebuffer(&s->vram); s->vram_ptr =3D memory_region_get_ram_ptr(&s->vram); s->get_bpp =3D vga_get_bpp; - s->get_offsets =3D vga_get_offsets; + s->get_params =3D vga_get_params; s->get_resolution =3D vga_get_resolution; s->hw_ops =3D &vga_ops; switch (vga_retrace_method) { diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 7cf0d11201a..6be61e04284 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -56,6 +56,12 @@ struct VGACommonState; typedef uint8_t (* vga_retrace_fn)(struct VGACommonState *s); typedef void (* vga_update_retrace_info_fn)(struct VGACommonState *s); =20 +typedef struct VGADisplayParams { + uint32_t line_offset; + uint32_t start_addr; + uint32_t line_compare; +} VGADisplayParams; + typedef struct VGACommonState { MemoryRegion *legacy_address_space; uint8_t *vram_ptr; @@ -90,10 +96,7 @@ typedef struct VGACommonState { uint8_t palette[768]; int32_t bank_offset; int (*get_bpp)(struct VGACommonState *s); - void (*get_offsets)(struct VGACommonState *s, - uint32_t *pline_offset, - uint32_t *pstart_addr, - uint32_t *pline_compare); + void (*get_params)(struct VGACommonState *s, VGADisplayParams *params); void (*get_resolution)(struct VGACommonState *s, int *pwidth, int *pheight); @@ -111,9 +114,7 @@ typedef struct VGACommonState { int graphic_mode; uint8_t shift_control; uint8_t double_scan; - uint32_t line_offset; - uint32_t line_compare; - uint32_t start_addr; + VGADisplayParams params; uint32_t plane_updated; uint32_t last_line_offset; uint8_t last_cw, last_ch; --=20 2.43.0 From nobody Tue Nov 26 20:26:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015609; cv=none; d=zohomail.com; s=zohoarc; b=dKGEdxRqkYgiMyUwD/mFGLEbWzp9RSDEHX8ZUnMMy3M8k23L3fd18l9LanwMei2C7KSvyn++h6jOgBrMkTgmJzy03gkxW6qCpSrJx2CJZFy11AmP20ZrhI9bKMzNiXQjqQpiDBHpF8WHNDxG8bbS0G9lgn14tD0GFoSilziq76g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015609; 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=l0GKZTfjYpI+EqFxN4nTQimzWkUmQb261OTT9Ja7F90=; b=A28yGsmZKalonsXnHKfgs3eSnX/HCn94TmG1UcPX4Pt+NMKUhHId2QX0nKysQJ4G0cnSMPC3YYkdE566JrtYkngZtKYKmmB4YzPwUz4JEnXQb36fIuDEaoZ84vOukGsr+H7jSJTjzQrh+oS+LbRYqVErSYW6TLQi0nGbQUytzmI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015609712250.37986259647732; Sun, 31 Dec 2023 01:40:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIQ-0003NR-2M; Sun, 31 Dec 2023 04:39:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIA-0003Li-En for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:35 -0500 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 1rJsI8-0001Oh-Tb for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:34 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-253-JKG2F1d7OSWO2J6x3EmmNw-1; Sun, 31 Dec 2023 04:39:30 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40d86184891so2718685e9.1 for ; Sun, 31 Dec 2023 01:39:29 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id w11-20020adfcd0b000000b003367e35abd4sm23356938wrm.71.2023.12.31.01.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015572; 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=l0GKZTfjYpI+EqFxN4nTQimzWkUmQb261OTT9Ja7F90=; b=EXK4ahMJ5Zig+HpqDSCIIy4BUb36HyBm7LVC8yMfS0fWCs6qSNtnPxOBHurNotKb29CxNH ISFxO+9E/SSwU8pDSqB9Cx/3zd81dChcWkRoR+YzVyesXX4bgb3k2EMW0ABerVm+ZLAJIW 5//JwFuUgTk5pzKqlecmdK17SJQ/a30= X-MC-Unique: JKG2F1d7OSWO2J6x3EmmNw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015568; x=1704620368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l0GKZTfjYpI+EqFxN4nTQimzWkUmQb261OTT9Ja7F90=; b=W1wxcWPix1OI5mmDWfYhmNxe39jA3zLQkJjpMJQL63HVP20gBwBbneuU/uhl1Yi5JH HW7ShFxFAwVYYNRV3o0UEzvEIzV1eDrl20v65GAZBa+xzDa3e4aQS6gZhHHH+mX1w7lC uLcqKNAMZpGdAeboiHWaHWn6JMAWilDAadd5kgTlQyKaN1Lrtv7T3au1w/Edyznlt5dU L5+FEnILcO4iNTIBmXSoaRP4HnZEgDyQ9TprzsSIBvNwOnAHbK6YrmPZOe75IuSnMQUY 7XoPnLJI2Xv9RK2YCBv5jWFmOjj0FFkDSLC14/BFEBZY4+9BVDbQlSuGCaiTX9XuZZC5 kCqg== X-Gm-Message-State: AOJu0Yz9XvOJ898HHaytQ+RpORmQsULy/Nejb73/x6TdafhCZyADhHsF 4xiWfRxLMqPArzDq/KlBBvFciS98tpNb2KqQ2Hf/xQhYMj0hDhSG9dxv59RDC3YY7JAbjkZUZc8 aViO3KPWE/bOodINho0rthz80YCBnDy8kdoEx1jX0KARZGBGG2tuQKCYLyY+g4hPO07F0aju4Id Qr6RzYWHk= X-Received: by 2002:a05:600c:1f17:b0:40d:8818:579e with SMTP id bd23-20020a05600c1f1700b0040d8818579emr129923wmb.108.1704015568567; Sun, 31 Dec 2023 01:39:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IES6ifd+XykLF5DpBUVkOuveQx8mj93qLIWqmHnGQuS9G0EQr7VZ9sYygqBGclr97XY6VFSCQ== X-Received: by 2002:a05:600c:1f17:b0:40d:8818:579e with SMTP id bd23-20020a05600c1f1700b0040d8818579emr129919wmb.108.1704015568304; Sun, 31 Dec 2023 01:39:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 3/8] vga: mask addresses in non-VESA modes to 256k Date: Sun, 31 Dec 2023 10:39:13 +0100 Message-ID: <20231231093918.239549-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015610573100003 Content-Type: text/plain; charset="utf-8" This allows setting the start address to a high value, and reading the bottom of the screen from the beginning of VRAM. Commander Keen 4 ("Goodbye, Galaxy!") relies on this behavior. Signed-off-by: Paolo Bonzini --- hw/display/vga-helpers.h | 9 +++++---- hw/display/vga.c | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h index 10e9cfd40a0..83b9a15604a 100644 --- a/hw/display/vga-helpers.h +++ b/hw/display/vga-helpers.h @@ -108,7 +108,7 @@ static void vga_draw_line2(VGACommonState *vga, uint8_t= *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand2[GET_PLANE(data, 0)]; v |=3D expand2[GET_PLANE(data, 2)] << 2; @@ -144,7 +144,7 @@ static void vga_draw_line2d2(VGACommonState *vga, uint8= _t *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand2[GET_PLANE(data, 0)]; v |=3D expand2[GET_PLANE(data, 2)] << 2; @@ -177,7 +177,7 @@ static void vga_draw_line4(VGACommonState *vga, uint8_t= *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand4[GET_PLANE(data, 0)]; v |=3D expand4[GET_PLANE(data, 1)] << 1; @@ -209,7 +209,7 @@ static void vga_draw_line4d2(VGACommonState *vga, uint8= _t *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand4[GET_PLANE(data, 0)]; v |=3D expand4[GET_PLANE(data, 1)] << 1; @@ -242,6 +242,7 @@ static void vga_draw_line8d2(VGACommonState *vga, uint8= _t *d, palette =3D vga->last_palette; width >>=3D 3; for(x =3D 0; x < width; x++) { + addr &=3D VGA_VRAM_SIZE - 1; PUT_PIXEL2(d, 0, palette[vga_read_byte(vga, addr + 0)]); PUT_PIXEL2(d, 1, palette[vga_read_byte(vga, addr + 1)]); PUT_PIXEL2(d, 2, palette[vga_read_byte(vga, addr + 2)]); diff --git a/hw/display/vga.c b/hw/display/vga.c index 3bd357d72c2..b1660bdde67 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -47,6 +47,9 @@ bool have_vga =3D true; /* 16 state changes per vertical frame @60 Hz */ #define VGA_TEXT_CURSOR_PERIOD_MS (1000 * 2 * 16 / 60) =20 +/* Address mask for non-VESA modes. */ +#define VGA_VRAM_SIZE 262144 + /* * Video Graphics Array (VGA) * --=20 2.43.0 From nobody Tue Nov 26 20:26:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015695; cv=none; d=zohomail.com; s=zohoarc; b=Tuh6X5qN7UrJiEAwTPBSFMiPadr16SlGAQz0ebf/XJMjYisqFqXd1v/cfswoJyAv5ErC1QmiuN+20ipb0+k7h4mq7LvDRpUanNUqi2WZUAYJgJDhK1e4FKsG31STauhVSk1DY7ng/O/L+QYLu5BkQh1Ro47W9SDceaxtxvGXTxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015695; 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=ikM1+N2ztMYn7pHvETrIsFtkrX6zkzruAQdOnPpGWlw=; b=CFBn6uix0ISq+OK+89iQ7vRayLJn15Kp9+jCMxH8MxLXZvvFEMu4TcJhr6HjlsuZ4kfaG2/Z2TVw2J4uq0R2RIOKZ6tjUTYJ1sW1o/Et6Owq0hlxQr4hJArd8CkSExAfshY5CZm2H3JPa+lbLARBdwA9aMl3EIDkwwAj8avnlyw= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015695792215.99141636389072; Sun, 31 Dec 2023 01:41:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIZ-0003b8-9G; Sun, 31 Dec 2023 04:39:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIL-0003Ma-2m for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIC-0001P6-HD for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:42 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-310-x-Oc4kQFOVSY3yHNoJXowQ-1; Sun, 31 Dec 2023 04:39:33 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-40d86184891so2719255e9.1 for ; Sun, 31 Dec 2023 01:39:32 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id k15-20020adfe3cf000000b003367a51217csm23249471wrm.34.2023.12.31.01.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015575; 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=ikM1+N2ztMYn7pHvETrIsFtkrX6zkzruAQdOnPpGWlw=; b=iM0WJPZcbdPd7hO9ROXThpT3JVE03REhfSE1i5NkvRflx7DNh8HFoSsiCsT1NoTrEN9n7z fxqcqDM/mn1UjlSPKVGA8lrS/RBtr/9FrF8WILHS+/XBqUzfBu1C2GmAUZjj1VDqqn5IzY l/eUKbW4OdupWD8PVI5xue1BZT8MDuw= X-MC-Unique: x-Oc4kQFOVSY3yHNoJXowQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015571; x=1704620371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ikM1+N2ztMYn7pHvETrIsFtkrX6zkzruAQdOnPpGWlw=; b=tkPYBQBKUD/nb6n/1zh2KwIAn2a3SqexfB1nn5yq1F8KzdoAggQ2u21Fbpg46rNkom 91x+Zy4/BCSEnrwvw1gtwRM0fGlGhmVsxU0vovBbgLd32ZX1kJS+UNn3S2DQzYTHxhgf 16hi+iTuVcehgq5hJMNlmOASvswahl05eqB19OJPGK37L46k9WU/gE+GIU+/JGqNixOF lYAY7dr9ABFFbFKnmIRXchtkQ1mPpuJUjil8xkZXn06uBr48c++K9m4zL+JGgyrDQIOB JBqCFpXWhz/G5vdjsRnMwW0ZL1wiWw2mQoAHi3B3I6WioDyCSlUIKcPQrErZocIqReWk Q8xQ== X-Gm-Message-State: AOJu0YwP0QhbyiuSuGXJDXAabNQP2GeV6lDNpq0eyBv2cmKeB/9r1AdA P5VkSCDITQRIyH8nz+out1KcOxgRnoWqMBZ5SIhTWGV3/PH4fgV92guGl7Q9c5/agDe/d5zYFHO lvvI+tln1X4lVjPSaPjI+5C9pDrhXkUJT9xn2djLArz1WTr8i9WTIzV6ee95sNXKVsKviguFbP9 Nu/0uO3pM= X-Received: by 2002:a05:600c:5486:b0:40d:8780:2b04 with SMTP id iv6-20020a05600c548600b0040d87802b04mr264457wmb.79.1704015571118; Sun, 31 Dec 2023 01:39:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IErnKb3Ai9CjcbzASLv6McofplNZJD/j8zdpwBiQV8vCJJEmjxmH76Votjoqi5ORkSOOAFixg== X-Received: by 2002:a05:600c:5486:b0:40d:8780:2b04 with SMTP id iv6-20020a05600c548600b0040d87802b04mr264451wmb.79.1704015570659; Sun, 31 Dec 2023 01:39:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 4/8] vga: implement horizontal pel panning in graphics modes Date: Sun, 31 Dec 2023 10:39:14 +0100 Message-ID: <20231231093918.239549-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015696698100007 Content-Type: text/plain; charset="utf-8" This implements smooth scrolling, as used for example by Commander Keen and Second Reality. Unfortunately, this is not enough to avoid tearing in Commander Keen, because sometimes the wrong start address is used for a frame. On real EGA, the panning register is sampled on every line, while the display start is latched for the next frame at the start of the vertical retrace. On real VGA, the panning register is also latched, but at the end of the vertical retrace. It looks like Keen exploits this by only waiting for horizontal retrace when setting the display start, but implementing it breaks the 256-color Keen games... Signed-off-by: Paolo Bonzini --- hw/display/cirrus_vga.c | 4 ++ hw/display/vga-helpers.h | 100 ++++++++++++++++++++++++++++----------- hw/display/vga.c | 36 ++++++++++++-- hw/display/vga_int.h | 3 ++ 4 files changed, 111 insertions(+), 32 deletions(-) diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index e6d2581d4eb..849eff43898 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -43,6 +43,7 @@ #include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "ui/pixel_ops.h" +#include "vga_regs.h" #include "cirrus_vga_internal.h" #include "qom/object.h" #include "ui/console.h" @@ -1121,6 +1122,9 @@ static void cirrus_get_params(VGACommonState *s1, params->line_compare =3D s->vga.cr[0x18] | ((s->vga.cr[0x07] & 0x10) << 4) | ((s->vga.cr[0x09] & 0x40) << 3); + + params->hpel =3D s->vga.ar[VGA_ATC_PEL]; + params->hpel_split =3D s->vga.ar[VGA_ATC_MODE] & 0x20; } =20 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState * s) diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h index 83b9a15604a..29933562c45 100644 --- a/hw/display/vga-helpers.h +++ b/hw/display/vga-helpers.h @@ -98,14 +98,19 @@ static void vga_draw_glyph9(uint8_t *d, int linesize, /* * 4 color mode */ -static void vga_draw_line2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, *palette, data, v; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -126,6 +131,7 @@ static void vga_draw_line2(VGACommonState *vga, uint8_t= *d, d +=3D 32; addr +=3D 4; } + return hpel ? vga->panning_buf + 4 * hpel : NULL; } =20 #define PUT_PIXEL2(d, n, v) \ @@ -134,14 +140,19 @@ static void vga_draw_line2(VGACommonState *vga, uint8= _t *d, /* * 4 color mode, dup2 horizontal */ -static void vga_draw_line2d2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line2d2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, *palette, data, v; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -162,19 +173,25 @@ static void vga_draw_line2d2(VGACommonState *vga, uin= t8_t *d, d +=3D 64; addr +=3D 4; } + return hpel ? vga->panning_buf + 8 * hpel : NULL; } =20 /* * 16 color mode */ -static void vga_draw_line4(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line4(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, data, v, *palette; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -194,19 +211,25 @@ static void vga_draw_line4(VGACommonState *vga, uint8= _t *d, d +=3D 32; addr +=3D 4; } + return hpel ? vga->panning_buf + 4 * hpel : NULL; } =20 /* * 16 color mode, dup2 horizontal */ -static void vga_draw_line4d2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line4d2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, data, v, *palette; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -226,6 +249,7 @@ static void vga_draw_line4d2(VGACommonState *vga, uint8= _t *d, d +=3D 64; addr +=3D 4; } + return hpel ? vga->panning_buf + 8 * hpel : NULL; } =20 /* @@ -233,13 +257,18 @@ static void vga_draw_line4d2(VGACommonState *vga, uin= t8_t *d, * * XXX: add plane_mask support (never used in standard VGA modes) */ -static void vga_draw_line8d2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line8d2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t *palette; int x; =20 palette =3D vga->last_palette; + hpel =3D (hpel >> 1) & 3; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { addr &=3D VGA_VRAM_SIZE - 1; @@ -250,6 +279,7 @@ static void vga_draw_line8d2(VGACommonState *vga, uint8= _t *d, d +=3D 32; addr +=3D 4; } + return hpel ? vga->panning_buf + 8 * hpel : NULL; } =20 /* @@ -257,13 +287,18 @@ static void vga_draw_line8d2(VGACommonState *vga, uin= t8_t *d, * * XXX: add plane_mask support (never used in standard VGA modes) */ -static void vga_draw_line8(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line8(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t *palette; int x; =20 palette =3D vga->last_palette; + hpel =3D (hpel >> 1) & 3; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { ((uint32_t *)d)[0] =3D palette[vga_read_byte(vga, addr + 0)]; @@ -277,13 +312,14 @@ static void vga_draw_line8(VGACommonState *vga, uint8= _t *d, d +=3D 32; addr +=3D 8; } + return hpel ? vga->panning_buf + 4 * hpel : NULL; } =20 /* * 15 bit color */ -static void vga_draw_line15_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line15_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -298,10 +334,11 @@ static void vga_draw_line15_le(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line15_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line15_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -316,13 +353,14 @@ static void vga_draw_line15_be(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 /* * 16 bit color */ -static void vga_draw_line16_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line16_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -337,10 +375,11 @@ static void vga_draw_line16_le(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line16_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line16_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -355,13 +394,14 @@ static void vga_draw_line16_be(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 /* * 24 bit color */ -static void vga_draw_line24_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line24_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -375,10 +415,11 @@ static void vga_draw_line24_le(VGACommonState *vga, u= int8_t *d, addr +=3D 3; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line24_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line24_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -392,13 +433,14 @@ static void vga_draw_line24_be(VGACommonState *vga, u= int8_t *d, addr +=3D 3; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 /* * 32 bit color */ -static void vga_draw_line32_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line32_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -412,10 +454,11 @@ static void vga_draw_line32_le(VGACommonState *vga, u= int8_t *d, addr +=3D 4; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line32_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line32_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -429,4 +472,5 @@ static void vga_draw_line32_be(VGACommonState *vga, uin= t8_t *d, addr +=3D 4; d +=3D 4; } while (--w !=3D 0); + return NULL; } diff --git a/hw/display/vga.c b/hw/display/vga.c index b1660bdde67..2467f3f6c65 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -50,6 +50,13 @@ bool have_vga =3D true; /* Address mask for non-VESA modes. */ #define VGA_VRAM_SIZE 262144 =20 +/* This value corresponds to a shift of zero pixels + * in 9-dot text mode. In other modes, bit 3 is undefined; + * we just ignore it, so that 8 corresponds to zero pixels + * in all modes. + */ +#define VGA_HPEL_NEUTRAL 8 + /* * Video Graphics Array (VGA) * @@ -1001,8 +1008,8 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) } } =20 -typedef void vga_draw_line_func(VGACommonState *s1, uint8_t *d, - uint32_t srcaddr, int width); +typedef void *vga_draw_line_func(VGACommonState *s1, uint8_t *d, + uint32_t srcaddr, int width, int hpel); =20 #include "vga-access.h" #include "vga-helpers.h" @@ -1069,6 +1076,8 @@ static void vga_get_params(VGACommonState *s, params->line_offset =3D s->vbe_line_offset; params->start_addr =3D s->vbe_start_addr; params->line_compare =3D 65535; + params->hpel =3D VGA_HPEL_NEUTRAL; + params->hpel_split =3D false; } else { /* compute line_offset in bytes */ params->line_offset =3D s->cr[VGA_CRTC_OFFSET] << 3; @@ -1081,6 +1090,9 @@ static void vga_get_params(VGACommonState *s, params->line_compare =3D s->cr[VGA_CRTC_LINE_COMPARE] | ((s->cr[VGA_CRTC_OVERFLOW] & 0x10) << 4) | ((s->cr[VGA_CRTC_MAX_SCAN] & 0x40) << 3); + + params->hpel =3D s->ar[VGA_ATC_PEL]; + params->hpel_split =3D s->ar[VGA_ATC_MODE] & 0x20; } } =20 @@ -1452,6 +1464,7 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) ram_addr_t page0, page1, region_start, region_end; DirtyBitmapSnapshot *snap =3D NULL; int disp_width, multi_scan, multi_run; + int hpel; uint8_t *d; uint32_t v, addr1, addr; vga_draw_line_func *vga_draw_line =3D NULL; @@ -1551,6 +1564,9 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) s->last_line_offset =3D s->params.line_offset; s->last_depth =3D depth; s->last_byteswap =3D byteswap; + /* 16 extra pixels are needed for double-width planar modes. */ + s->panning_buf =3D g_realloc(s->panning_buf, + (disp_width + 16) * sizeof(uint32_t)); full_update =3D 1; } if (surface_data(surface) !=3D s->vram_ptr + (s->params.start_addr * 4) @@ -1630,8 +1646,12 @@ static void vga_draw_graphic(VGACommonState *s, int = full_update) width, height, v, line_offset, s->cr[9], s->cr[VGA_CRTC_MODE], s->params.line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); #endif + hpel =3D bits <=3D 8 ? s->params.hpel : 0; addr1 =3D (s->params.start_addr * 4); bwidth =3D DIV_ROUND_UP(width * bits, 8); + if (hpel) { + bwidth +=3D 4; + } y_start =3D -1; d =3D surface_data(surface); linesize =3D surface_stride(surface); @@ -1679,7 +1699,11 @@ static void vga_draw_graphic(VGACommonState *s, int = full_update) if (y_start < 0) y_start =3D y; if (!(is_buffer_shared(surface))) { - vga_draw_line(s, d, addr, width); + uint8_t *p; + p =3D vga_draw_line(s, d, addr, width, hpel); + if (p) { + memcpy(d, p, disp_width * sizeof(uint32_t)); + } if (s->cursor_draw_line) s->cursor_draw_line(s, d, y); } @@ -1701,8 +1725,12 @@ static void vga_draw_graphic(VGACommonState *s, int = full_update) multi_run--; } /* line compare acts on the displayed lines */ - if (y =3D=3D s->params.line_compare) + if (y =3D=3D s->params.line_compare) { + if (s->params.hpel_split) { + hpel =3D VGA_HPEL_NEUTRAL; + } addr1 =3D 0; + } d +=3D linesize; } if (y_start >=3D 0) { diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 6be61e04284..876a1d3697b 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -60,6 +60,8 @@ typedef struct VGADisplayParams { uint32_t line_offset; uint32_t start_addr; uint32_t line_compare; + uint8_t hpel; + bool hpel_split; } VGADisplayParams; =20 typedef struct VGACommonState { @@ -111,6 +113,7 @@ typedef struct VGACommonState { /* display refresh support */ QemuConsole *con; uint32_t font_offsets[2]; + uint8_t *panning_buf; int graphic_mode; uint8_t shift_control; uint8_t double_scan; --=20 2.43.0 From nobody Tue Nov 26 20:26:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015643; cv=none; d=zohomail.com; s=zohoarc; b=Gdh05FY/RaWV4YX2C/Qods0YeR90XYQUwZkXzJ898cQhWJVx+tmuVWKTM+gGorUmvQAGjn899N1hozMk6NoVMe7zhyvvTnlDnZJOMyk3tqaLMtP0cc7RVqKjgxT0pdLMRRwaMS5cwT40FbgJmeCnKNd1fqAC1DNabw1+XuQP9wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015643; 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=zGuVDWpXyHgDtnpBoCqtCU0iZWlD325c2JY3QKidV/E=; b=Nb7zBk57iQ3VnHjKC7/Y15FAYyI9K3W2AFyxTRGMm36dOUnrLblawT2Df8zGsuSY0YDpCTTzmmLEkpcB5a0l7CxF5joYkp5nPPmjtYdhzU2V2UCYLqdbPk+EMciKGG8wYAdXC9W8+3+S8alZH6cw2n9HpcctBzpSjLPdXuiA1lI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015643121976.1209700953244; Sun, 31 Dec 2023 01:40:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIX-0003Vk-5x; Sun, 31 Dec 2023 04:39:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIO-0003NA-IF for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIK-0001PM-RX for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:48 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-394-J-a3J6KBPoud5swmYfs4aA-1; Sun, 31 Dec 2023 04:39:35 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40d4a423c84so71887975e9.3 for ; Sun, 31 Dec 2023 01:39:35 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id g14-20020a05600c310e00b0040d6eb862a7sm10785056wmo.41.2023.12.31.01.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015580; 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=zGuVDWpXyHgDtnpBoCqtCU0iZWlD325c2JY3QKidV/E=; b=FfJwpW2Bk9CLJrgm9wdKacJhFIVqMATvN8Z/yee/iSrL/eGIMEyGI1UoS2JaNuFL31H3+V RsU9Ifu6vbTHFWTxMTJ5MejQieC9IqNzDkg3/BQfJtA85iS+RSPJp7W7hTj8tI7753298k XDvevv9DmgJMXoZvR+GALJI6ZmOSXA4= X-MC-Unique: J-a3J6KBPoud5swmYfs4aA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015574; x=1704620374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zGuVDWpXyHgDtnpBoCqtCU0iZWlD325c2JY3QKidV/E=; b=S26Z2Xy7LRTvD5KbWxfv/QZ/bQmqJte+74Mdnyok2TQtSHphtfdaj/JM9v49Ec1pCE PoEeCdQ2CmlKDR3jm+eT7QNWiBIJeF/D4IbqJJ3tKdO3veZLRvstaSJU6QFyvTTdYC48 84Jk25C6vl+6u+uXyMleR37hzHt61PQr84JDdoyEVh7ggFVtEpcIHjDInzEdCdvaYGCH pucViR2nddxbcBbFpFOAHCNX7mGif4+TPJMpxUxCiL/oI6YYLb4cBwnyHopFJCuq5NbN b3b/3YG6RACvaTsJs1Q9UTb65epSeYYQVFnBNvENwvw55M9txwOK2iKFvuWodU2UKRVH Xq+w== X-Gm-Message-State: AOJu0Yyvxj7PoTYbaALVxOuCE5LNCHGE8ujQi8jWuWL34JSNkldlvBTA yv8+iS5TrezckQpFuHdqpTZl3JpSYlx+uFNnG9r2ahBPF8N1LgPGUjBWK42PpwRAcuGe2Zhe7mp JU4NpuUgpbPiBDuKrNNuc5kQRjp+FKs+dCzqI7zOYYU2W/j/63+c70JfVOQo1sB5zx42VrhktSf aJjlySafk= X-Received: by 2002:a05:600c:5204:b0:40d:7b30:4f9f with SMTP id fb4-20020a05600c520400b0040d7b304f9fmr1138845wmb.26.1704015574055; Sun, 31 Dec 2023 01:39:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQvi8QqI4heBaLzPOhUxOiDs8qK2I6mTEOKcjO1KnTpZH9JjjR5DyxQzXzmpqH1USxD6h3QA== X-Received: by 2002:a05:600c:5204:b0:40d:7b30:4f9f with SMTP id fb4-20020a05600c520400b0040d7b304f9fmr1138842wmb.26.1704015573745; Sun, 31 Dec 2023 01:39:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 5/8] vga: optimize horizontal pel panning in 256-color modes Date: Sun, 31 Dec 2023 10:39:15 +0100 Message-ID: <20231231093918.239549-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015644558100003 Content-Type: text/plain; charset="utf-8" Do not go through the panning buffer unless the address wraps in the middle of the line. Signed-off-by: Paolo Bonzini --- hw/display/vga-helpers.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h index 29933562c45..60ddb27d946 100644 --- a/hw/display/vga-helpers.h +++ b/hw/display/vga-helpers.h @@ -265,6 +265,18 @@ static void *vga_draw_line8d2(VGACommonState *vga, uin= t8_t *d, =20 palette =3D vga->last_palette; hpel =3D (hpel >> 1) & 3; + + /* For 256 color modes, we can adjust the source address and write dir= ectly + * to the destination, even if horizontal pel panning is active. Howe= ver, + * the loop below assumes that the address does not wrap in the middle= of a + * plane. If that happens... + */ + if (addr + (width >> 3) * 4 < VGA_VRAM_SIZE) { + addr +=3D hpel * 4; + hpel =3D 0; + } + + /* ... use the panning buffer as in planar modes. */ if (hpel) { width +=3D 8; d =3D vga->panning_buf; --=20 2.43.0 From nobody Tue Nov 26 20:26:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015677; cv=none; d=zohomail.com; s=zohoarc; b=DfqIrvIREeAOLCHg2SFM/1lOVOLywDn705QhxZ7qX4pTfnsumP+1/xA4h640sHfdgNt+/xRohozZQbZILJMKDU60D+IHMlCFWUImr6TpzCB8Scgg/MIP4sRi//jAXTGERdQEx7ZqMsxkG1/3O1WEWzMTi7U40dhngXsmma9RBk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015677; 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=F1Clt86qsanfkl/RbaWDlF4YfS1X9zhqhbxAVnCe+VA=; b=esst3VhmBykuH6LPbafuFC4SVP0/XjvnDbo/HpTH/RhP2f3eXdO/GCAZQOiz6v5sCrQFbFBxX6d0JL4IUp5aY9Rh0+sjcMmC3vPVSY9BlZtUrTt2WYz94YlkJZc/ls90ddfISW2vUNVMfmcHNS/hH8Gq0v6Y1J0qZo4c7z0jSsA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015677245560.1266117933287; Sun, 31 Dec 2023 01:41:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIc-0003dt-JW; Sun, 31 Dec 2023 04:40:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIO-0003N5-Hl for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:49 -0500 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 1rJsIK-0001PJ-R8 for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:47 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-395-c3mOKjm9MRO5thSHKTi9yA-1; Sun, 31 Dec 2023 04:39:38 -0500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-33677bbd570so5943695f8f.3 for ; Sun, 31 Dec 2023 01:39:38 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id d17-20020adffbd1000000b0033719111458sm6494110wrs.36.2023.12.31.01.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015580; 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=F1Clt86qsanfkl/RbaWDlF4YfS1X9zhqhbxAVnCe+VA=; b=UBDHNi0lOxkrnMfJn0j9QBqLkrf0GuzZt6/XDhxPZBvCY7Ma0kbGPZ8fCN4CACIFe+CEZt 9RfG9a+sJ8Dw48hXeLtHLyhCNFm4/tITBqzAxr7lIswBoGIB1oSaKp08kXQ/O5JaF8PAjx geyYbYqi/2WmDoFznHEUXOBeiLi/aY0= X-MC-Unique: c3mOKjm9MRO5thSHKTi9yA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015576; x=1704620376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F1Clt86qsanfkl/RbaWDlF4YfS1X9zhqhbxAVnCe+VA=; b=jX3D34lymPb1eVqXGYc8gjc2RpK/7molw8sdzZjze3mxcNXfNEEzgacQyg0jBYWsF5 JyJS+64tkTeON8huokf8DYWWuRUuiTVIpxbYnIw/eeXxwweJNiZ1nQH1aGMzRcfPSW0J jPyIXFmwkt/hXvQUmT1Monh7IVh0w7KOihlP1nkuB+yJ8e+xlVz4u+xnAeP/WNXvrp8m FNSSwbLR2ICudLUT9Ll4w6+4aX6SFdNHWxAqmC7JDK0hZVDCHKrwxh2JeExOChbGQfH6 2vvu3DDtD1kuS9cemYutTfGBVy1/+6kPtokGtYVInPuGjpBxXJGGshWPatNMUqA3hIcV Tzzg== X-Gm-Message-State: AOJu0Yx7s6/VAAOKaceCK0W1fIrTIFKdfyg8CVAvnBEIFgOQ1V1E0emR lU2prlA3ode1/kVfRLza2QBTrtUaoJR1MhMxx4WChS88dPQ41CFAd104JCTP8exT8hghJYnQL0A Bibr7m/u6FMh1ZDcoragEWcB3NeL0D2jtc75X/5vCHUYgH5rN9UL0q34+WbDOHlDto1CkQQUlmY y4KFhJE7k= X-Received: by 2002:a5d:5692:0:b0:336:67e9:ebe8 with SMTP id f18-20020a5d5692000000b0033667e9ebe8mr9281570wrv.90.1704015576581; Sun, 31 Dec 2023 01:39:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2tFK7sUyg7wDGvXjjyi8geMiVbKY9vNMa6uu9CtDl9wZwS9RPXWNPemtQUJjKnvlCqPSEpg== X-Received: by 2002:a5d:5692:0:b0:336:67e9:ebe8 with SMTP id f18-20020a5d5692000000b0033667e9ebe8mr9281565wrv.90.1704015576333; Sun, 31 Dec 2023 01:39:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 6/8] vga: reindent memory access code Date: Sun, 31 Dec 2023 10:39:16 +0100 Message-ID: <20231231093918.239549-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015678613100003 Content-Type: text/plain; charset="utf-8" The next patch will reuse latched memory access in text modes. Start with a patch that moves the latched access code out of the "if". Best reviewed with "git diff -b". Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/display/vga.c | 211 ++++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 101 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index 2467f3f6c65..08ba5bb1118 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -832,37 +832,41 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) } =20 if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { - /* chain 4 mode : simplest access */ + /* chain 4 mode : simplest access (but it should use the same + * algorithms as below; see e.g. vga_mem_writeb's plane mask check= ). + */ assert(addr < s->vram_size); - ret =3D s->vram_ptr[addr]; - } else if (s->gr[VGA_GFX_MODE] & 0x10) { + return s->vram_ptr[addr]; + } + + if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); addr =3D ((addr & ~1) << 1) | plane; if (addr >=3D s->vram_size) { return 0xff; } - ret =3D s->vram_ptr[addr]; - } else { - /* standard VGA latched access */ - if (addr * sizeof(uint32_t) >=3D s->vram_size) { - return 0xff; - } - s->latch =3D ((uint32_t *)s->vram_ptr)[addr]; - - if (!(s->gr[VGA_GFX_MODE] & 0x08)) { - /* read mode 0 */ - plane =3D s->gr[VGA_GFX_PLANE_READ]; - ret =3D GET_PLANE(s->latch, plane); - } else { - /* read mode 1 */ - ret =3D (s->latch ^ mask16[s->gr[VGA_GFX_COMPARE_VALUE]]) & - mask16[s->gr[VGA_GFX_COMPARE_MASK]]; - ret |=3D ret >> 16; - ret |=3D ret >> 8; - ret =3D (~ret) & 0xff; - } + return s->vram_ptr[addr]; } + + /* standard VGA latched access */ + plane =3D s->gr[VGA_GFX_PLANE_READ]; + if (addr * sizeof(uint32_t) >=3D s->vram_size) { + return 0xff; + } + s->latch =3D ((uint32_t *)s->vram_ptr)[addr]; + if (!(s->gr[VGA_GFX_MODE] & 0x08)) { + /* read mode 0 */ + ret =3D GET_PLANE(s->latch, plane); + } else { + /* read mode 1 */ + ret =3D (s->latch ^ mask16[s->gr[VGA_GFX_COMPARE_VALUE]]) & + mask16[s->gr[VGA_GFX_COMPARE_MASK]]; + ret |=3D ret >> 16; + ret |=3D ret >> 8; + ret =3D (~ret) & 0xff; + } + return ret; } =20 @@ -912,7 +916,10 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, ui= nt32_t val) s->plane_updated |=3D mask; /* only used to detect font change= */ memory_region_set_dirty(&s->vram, addr, 1); } - } else if (s->gr[VGA_GFX_MODE] & 0x10) { + return; + } + + if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); mask =3D (1 << plane); @@ -928,84 +935,86 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) s->plane_updated |=3D mask; /* only used to detect font change= */ memory_region_set_dirty(&s->vram, addr, 1); } - } else { - /* standard VGA latched access */ - write_mode =3D s->gr[VGA_GFX_MODE] & 3; - switch(write_mode) { - default: - case 0: - /* rotate */ - b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; - val =3D ((val >> b) | (val << (8 - b))) & 0xff; - val |=3D val << 8; - val |=3D val << 16; - - /* apply set/reset mask */ - set_mask =3D mask16[s->gr[VGA_GFX_SR_ENABLE]]; - val =3D (val & ~set_mask) | - (mask16[s->gr[VGA_GFX_SR_VALUE]] & set_mask); - bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; - break; - case 1: - val =3D s->latch; - goto do_write; - case 2: - val =3D mask16[val & 0x0f]; - bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; - break; - case 3: - /* rotate */ - b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; - val =3D (val >> b) | (val << (8 - b)); - - bit_mask =3D s->gr[VGA_GFX_BIT_MASK] & val; - val =3D mask16[s->gr[VGA_GFX_SR_VALUE]]; - break; - } - - /* apply logical operation */ - func_select =3D s->gr[VGA_GFX_DATA_ROTATE] >> 3; - switch(func_select) { - case 0: - default: - /* nothing to do */ - break; - case 1: - /* and */ - val &=3D s->latch; - break; - case 2: - /* or */ - val |=3D s->latch; - break; - case 3: - /* xor */ - val ^=3D s->latch; - break; - } - - /* apply bit mask */ - bit_mask |=3D bit_mask << 8; - bit_mask |=3D bit_mask << 16; - val =3D (val & bit_mask) | (s->latch & ~bit_mask); - - do_write: - /* mask data according to sr[2] */ - mask =3D sr(s, VGA_SEQ_PLANE_WRITE); - s->plane_updated |=3D mask; /* only used to detect font change */ - write_mask =3D mask16[mask]; - if (addr * sizeof(uint32_t) >=3D s->vram_size) { - return; - } - ((uint32_t *)s->vram_ptr)[addr] =3D - (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | - (val & write_mask); -#ifdef DEBUG_VGA_MEM - printf("vga: latch: [0x" HWADDR_FMT_plx "] mask=3D0x%08x val=3D0x%= 08x\n", - addr * 4, write_mask, val); -#endif - memory_region_set_dirty(&s->vram, addr << 2, sizeof(uint32_t)); + return; } + + mask =3D sr(s, VGA_SEQ_PLANE_WRITE); + + /* standard VGA latched access */ + write_mode =3D s->gr[VGA_GFX_MODE] & 3; + switch(write_mode) { + default: + case 0: + /* rotate */ + b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; + val =3D ((val >> b) | (val << (8 - b))) & 0xff; + val |=3D val << 8; + val |=3D val << 16; + + /* apply set/reset mask */ + set_mask =3D mask16[s->gr[VGA_GFX_SR_ENABLE]]; + val =3D (val & ~set_mask) | + (mask16[s->gr[VGA_GFX_SR_VALUE]] & set_mask); + bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; + break; + case 1: + val =3D s->latch; + goto do_write; + case 2: + val =3D mask16[val & 0x0f]; + bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; + break; + case 3: + /* rotate */ + b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; + val =3D (val >> b) | (val << (8 - b)); + + bit_mask =3D s->gr[VGA_GFX_BIT_MASK] & val; + val =3D mask16[s->gr[VGA_GFX_SR_VALUE]]; + break; + } + + /* apply logical operation */ + func_select =3D s->gr[VGA_GFX_DATA_ROTATE] >> 3; + switch(func_select) { + case 0: + default: + /* nothing to do */ + break; + case 1: + /* and */ + val &=3D s->latch; + break; + case 2: + /* or */ + val |=3D s->latch; + break; + case 3: + /* xor */ + val ^=3D s->latch; + break; + } + + /* apply bit mask */ + bit_mask |=3D bit_mask << 8; + bit_mask |=3D bit_mask << 16; + val =3D (val & bit_mask) | (s->latch & ~bit_mask); + +do_write: + /* mask data according to sr[2] */ + s->plane_updated |=3D mask; /* only used to detect font change */ + write_mask =3D mask16[mask]; + if (addr * sizeof(uint32_t) >=3D s->vram_size) { + return; + } + ((uint32_t *)s->vram_ptr)[addr] =3D + (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | + (val & write_mask); +#ifdef DEBUG_VGA_MEM + printf("vga: latch: [0x" HWADDR_FMT_plx "] mask=3D0x%08x val=3D0x%08x\= n", + addr * 4, write_mask, val); +#endif + memory_region_set_dirty(&s->vram, addr << 2, sizeof(uint32_t)); } =20 typedef void *vga_draw_line_func(VGACommonState *s1, uint8_t *d, --=20 2.43.0 From nobody Tue Nov 26 20:26:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015660; cv=none; d=zohomail.com; s=zohoarc; b=auHi6W9bBP1NTecWydvzNYXTH7LL5pIXTc+CP6SZjZ9WIlKd6U70+lauJyV2QPnw0qjZgoXhQN61FW/nPV4LONJcJPWO2A+8ajHP7lfrO4I/s405i2d+pvx8ojSmzaFIYgFeKJ8euGw+ihe539/2wydJ1Ldc5FlbMC5uMPu+MFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015660; 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=CAhd/qb1pUqhE3rfgOgceUMVTexusP9ZyBq4WF7EC4Q=; b=BWcWuhqKiB938BI7QKNWQCncamhM9MfccP3uZ0lqf2yCy7HJSQctT2ml9h1JmW500AhFdtQTijyQjvMB9YF2tYi5VG/LBq9DMV8fQE8tSIdQIjU9hafBwrq/n1Y33X+hl5qI1CAPD70Rm098HcAPlnR+ECaykYDQkQ3wOFS/c3Y= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015660396173.98964844453405; Sun, 31 Dec 2023 01:41:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsIb-0003cR-Iq; Sun, 31 Dec 2023 04:40:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIO-0003NK-If for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIK-0001PS-RV for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:46 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-458-syPBKVY6PKGFPvXGE2afDA-1; Sun, 31 Dec 2023 04:39:40 -0500 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40d86184891so2719885e9.1 for ; Sun, 31 Dec 2023 01:39:40 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id o20-20020a05600c4fd400b0040b37f1079dsm44531821wmq.29.2023.12.31.01.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015582; 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=CAhd/qb1pUqhE3rfgOgceUMVTexusP9ZyBq4WF7EC4Q=; b=OaG/OYkVmnEwkeNukGHKodqFqAqP07BqS1d26QSO6m4jVO1WjIyf07AMldSQZRhsJMTlN2 vDtrBYsjSOdb1ehORCKtvmg/5SNSAH8m2+PlnT+1ZnYvB8M1b1ZJlFjr05Q2131wUTfWAi 8t2Wu5uVuRVYouDIAou9OLRJs/xjWpo= X-MC-Unique: syPBKVY6PKGFPvXGE2afDA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015578; x=1704620378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CAhd/qb1pUqhE3rfgOgceUMVTexusP9ZyBq4WF7EC4Q=; b=RsRWFPh2gbsD395TAZLyPSE+WQYgQYF3XL5j8ePpaC4SUkQ5Qy7FpxHknTbOXJaRfP G2UfafYc+alZ6O7/qh60UwIWkmgr33ywM9GCxOaSBLuwQR8O2foSF+8Tghjyn+YO9aUh C8LK04sv+eB6fQEEQKK2+41Hq11HUV6YP+vTcReI2T8ZeMu1SS/f1Ux04QjUA9WtFUfw lyXSjQ7VdJa7jRsucf+CAtbJJihmrDnneBjqENafBKG8O4qCzaUmYKnOmKBTbuil/SSS ai+F+fTvtRAgUQjzer6D2tbXQ9skTfjpm6qAEhgADo6ajGVKnlVTJHotxFR6sYy5NlIz 1yNQ== X-Gm-Message-State: AOJu0YxroxCo+1I7AjL4f9BvZBOB+1jqnfFoW49qRVAeTrwRkw83jrSd F29fZBEF6HMgwNRstvih5Zg58DOg9Gxf9Pbro9NzqfyopgJeT6dEGwgTMi7fgTbgwnjQDPIYOF/ uYsuAO997W3EF3Zi3ypr1rVkzt76wdp+R1QBg61uJovSj08S53ogbPN6CQWG6UJFKKYgDIcbwW3 RNILCRnBw= X-Received: by 2002:a05:600c:314c:b0:40d:6f01:c39d with SMTP id h12-20020a05600c314c00b0040d6f01c39dmr2494383wmo.186.1704015578524; Sun, 31 Dec 2023 01:39:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGY/hHQEJlxs7prdCNeDzTH5Ku32v14821jCzoc4w3iY21TODhmLhJK5a/aHDfo0Q6toJtpg== X-Received: by 2002:a05:600c:314c:b0:40d:6f01:c39d with SMTP id h12-20020a05600c314c00b0040d6f01c39dmr2494379wmo.186.1704015578167; Sun, 31 Dec 2023 01:39:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 7/8] vga: use latches in odd/even mode too Date: Sun, 31 Dec 2023 10:39:17 +0100 Message-ID: <20231231093918.239549-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015662644100003 Content-Type: text/plain; charset="utf-8" Jazz Jackrabbit uses odd/even mode with 256-color graphics. This is probably so that it can do very fast blitting with a decent resolution (two pixels, compared to four pixels for "regular" mode X). Accesses still use all planes (reads go to the latches and the game uses read mode 1 so that the CPU always gets 0xFF; writes use the plane mask register because the game sets bit 2 of the sequencer's memory mode register). For this to work, QEMU needs to use the code for latched memory accesses in odd/even mode. The only difference between odd/even mode and "regular" planar mode is how the plane is computed in read mode 0, and how the planes are masked if the aforementioned bit 2 is reset. It is almost enough to fix the game. You also need to honor byte/word mode selection, which is done in the next patch. Signed-off-by: Paolo Bonzini --- hw/display/vga.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index 08ba5bb1118..731501cb7af 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -842,15 +842,12 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); - addr =3D ((addr & ~1) << 1) | plane; - if (addr >=3D s->vram_size) { - return 0xff; - } - return s->vram_ptr[addr]; + addr >>=3D 1; + } else { + /* standard VGA latched access */ + plane =3D s->gr[VGA_GFX_PLANE_READ]; } =20 - /* standard VGA latched access */ - plane =3D s->gr[VGA_GFX_PLANE_READ]; if (addr * sizeof(uint32_t) >=3D s->vram_size) { return 0xff; } @@ -903,11 +900,12 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) break; } =20 + mask =3D sr(s, VGA_SEQ_PLANE_WRITE); if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { /* chain 4 mode : simplest access */ plane =3D addr & 3; - mask =3D (1 << plane); - if (sr(s, VGA_SEQ_PLANE_WRITE) & mask) { + mask &=3D (1 << plane); + if (mask) { assert(addr < s->vram_size); s->vram_ptr[addr] =3D val; #ifdef DEBUG_VGA_MEM @@ -919,26 +917,14 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) return; } =20 - if (s->gr[VGA_GFX_MODE] & 0x10) { - /* odd/even mode (aka text mode mapping) */ - plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); - mask =3D (1 << plane); - if (sr(s, VGA_SEQ_PLANE_WRITE) & mask) { - addr =3D ((addr & ~1) << 1) | plane; - if (addr >=3D s->vram_size) { - return; - } - s->vram_ptr[addr] =3D val; -#ifdef DEBUG_VGA_MEM - printf("vga: odd/even: [0x" HWADDR_FMT_plx "]\n", addr); -#endif - s->plane_updated |=3D mask; /* only used to detect font change= */ - memory_region_set_dirty(&s->vram, addr, 1); - } - return; + if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0) { + mask &=3D (addr & 1) ? 0x0a : 0x05; } =20 - mask =3D sr(s, VGA_SEQ_PLANE_WRITE); + if (s->gr[VGA_GFX_MODE] & 0x10) { + /* odd/even mode (aka text mode mapping) */ + addr >>=3D 1; + } =20 /* standard VGA latched access */ write_mode =3D s->gr[VGA_GFX_MODE] & 3; --=20 2.43.0 From nobody Tue Nov 26 20:26:23 2024 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1704015682; cv=none; d=zohomail.com; s=zohoarc; b=c/i/LJ5jh6ye9NcliJq3I5J9tW2AjQylohatklYKLx/3j5LrOZeQNZsqVzfSECD10bmvqKQ7r3jVF5UX6FP5eNoS0ka2z5JW/LozfZizo7jCIYgm3MD0ji9bxqpzgMVmzn3XXcjj0dJiACUSrE272fFp7JIXiBr1Jn1Ny4JP3fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704015682; 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=S+H3R073HOVUafO2Tm+SJNZpyjNCi5sTplULF4PSBxA=; b=OegL8dSwgUOuDCbn1I/DQwr3kOuNA8Sq7NZw6xe2sSJ+khIUo8YwesWy8BdvEEi/lusnXao97lNXVEPi0+w9HHNWmUW0KyhMTID9oQ90vEBNRlBaKNTRnooz/C5DbHoFi2m1JOo2C90WfaeqbLUNnYmOq7OM3bfREeg2TzHnG4I= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704015682224237.13056001770747; Sun, 31 Dec 2023 01:41:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJsId-0003ed-Bq; Sun, 31 Dec 2023 04:40:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJsIQ-0003RQ-6i for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:51 -0500 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 1rJsIL-0001Pn-W7 for qemu-devel@nongnu.org; Sun, 31 Dec 2023 04:39:48 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-74qD4HYTPHqe8dM67qShHg-1; Sun, 31 Dec 2023 04:39:43 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3368abe10c5so5660171f8f.0 for ; Sun, 31 Dec 2023 01:39:42 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id cg13-20020a5d5ccd000000b00336e6014263sm11854213wrb.98.2023.12.31.01.39.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 01:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704015585; 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=S+H3R073HOVUafO2Tm+SJNZpyjNCi5sTplULF4PSBxA=; b=jD8e2zPVXapj2jqofAub06ifB35M5G+PgQfy0sgUBefA4Y2dszlEgxhP6S8VRNDECYzZVt rnd0xDQW67KlTVw6Li8xG1/hdC4vClxjEzR259hn1QmnMiBFHkBabKkyHDNS4IBQ2XFnDx 0tS4+MdpYXcZI79bD7FMmxd0x0tUDIY= X-MC-Unique: 74qD4HYTPHqe8dM67qShHg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704015581; x=1704620381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S+H3R073HOVUafO2Tm+SJNZpyjNCi5sTplULF4PSBxA=; b=fWx1tLipna/1YvSYcU/dWSISFROqxiVihightF4+qcXBGZO3jRWEFiGZA4yvtM7nq8 0zKgHnfJIyE2RxybslQvz+PVUcUY8+p1LiBTFQfEzZTttB9dSqQbUcCNmroIJpInVcym PpT63snH3A90EXIADUTbVbTjMSooAwmLFeKs3f4pLlI/l6LhDnq4DxQAAWP2P1dg3eN5 EPFHpBZIrWyGE+zsXmhBOYG+0V7hf0uACrKCdyH9xwrfnbaunavXB32bkpKwFXd9+U5n /+zLCZFv4i/NfauhI4KTJL9LFfPc5Vdcz6Y4wjfpE8MZwEJM08KIw6Etg4kCjgFmFXeW KPEw== X-Gm-Message-State: AOJu0YwP69B9hlETtnd8wMmaeAe19UQK02d5sGWFfg2LcqfiA4MMWcIB l19j47IuEhsZBHTudnIWFrXSsX9+d7bQqU+s2XYjpan8tX9lYriIAfyt2pJ+WnYTv2xF847t2yL 1HbOO89OKqE+cgz36cgrjlHgWGkvvkdbGwYEOmfEUxegAYH+1ALRrQpGD1xRkgm28TvdAtMSoQm j0mR3+RCo= X-Received: by 2002:a5d:6ac1:0:b0:336:6720:aafe with SMTP id u1-20020a5d6ac1000000b003366720aafemr4973404wrw.54.1704015581114; Sun, 31 Dec 2023 01:39:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTr3Gcvgr3tcc5Laod/W+xMEjv1xVEkuWz6wu4cSWdIUwfqtZnqzdCxeFbVaX1aoQ8vS/VTQ== X-Received: by 2002:a5d:6ac1:0:b0:336:6720:aafe with SMTP id u1-20020a5d6ac1000000b003366720aafemr4973397wrw.54.1704015580602; Sun, 31 Dec 2023 01:39:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kraxel@redhat.com Subject: [PATCH 8/8] vga: sort-of implement word and double-word access modes Date: Sun, 31 Dec 2023 10:39:18 +0100 Message-ID: <20231231093918.239549-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231231093918.239549-1-pbonzini@redhat.com> References: <20231231093918.239549-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -47 X-Spam_score: -4.8 X-Spam_bar: ---- X-Spam_report: (-4.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.667, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1704015682666100003 Content-Type: text/plain; charset="utf-8" Jazz Jackrabbit has a very unusual VGA setup, where it uses odd/even mode with 256-color graphics. Probably, it wants to use fast VRAM-to-VRAM copies without having to store 4 copies of the sprites as needed in mode X, one for each mod-4 alignment; odd/even mode simplifies the code a lot if it's okay to place on a 160-pixels horizontal grid. At the same time, because it wants to use double buffering (a la "mode X") it uses byte mode, not word mode as is the case in text modes. In order to implement the combination of odd/even mode (plane number comes from bit 0 of the address) and byte mode (use all bytes of VRAM, whereas word mode only uses bytes 0, 2, 4,... on each of the four planes), we need to separate the effect on the plane number from the effect on the address. Implementing the modes properly is a mess in QEMU, because it would change the layout of VRAM and break migration. As an approximation, shift right when the CPU accesses memory instead of shifting left when the CRT controller reads it. A hack is needed in order to write font data properly (see comment in the code), but it works well enough for the game. Because doubleword and chain4 modes are now independent, chain4 does not assert anymore that the address is in range. Instead it just returns all ones and discards writes, like other modes. Signed-off-by: Paolo Bonzini --- hw/display/vga.c | 90 +++++++++++++++++++++++++++++++------------ hw/display/vga_regs.h | 4 ++ 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index 731501cb7af..02b250ec0e6 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -832,25 +832,40 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) } =20 if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { - /* chain 4 mode : simplest access (but it should use the same - * algorithms as below; see e.g. vga_mem_writeb's plane mask check= ). - */ - assert(addr < s->vram_size); - return s->vram_ptr[addr]; - } - - if (s->gr[VGA_GFX_MODE] & 0x10) { + /* chain4 mode */ + plane =3D addr & 3; + addr &=3D ~3; + } else if (s->gr[VGA_GFX_MODE] & VGA_GR05_HOST_ODD_EVEN) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); - addr >>=3D 1; } else { /* standard VGA latched access */ plane =3D s->gr[VGA_GFX_PLANE_READ]; } =20 + if (s->gr[VGA_GFX_MISC] & VGA_GR06_CHAIN_ODD_EVEN) { + addr &=3D ~1; + } + + /* Doubleword/word mode. See comment in vga_mem_writeb */ + if (s->cr[VGA_CRTC_UNDERLINE] & VGA_CR14_DW) { + addr >>=3D 2; + } else if ((s->gr[VGA_GFX_MODE] & VGA_GR05_HOST_ODD_EVEN) && + (s->cr[VGA_CRTC_MODE] & VGA_CR17_WORD_BYTE) =3D=3D 0) { + addr >>=3D 1; + } + if (addr * sizeof(uint32_t) >=3D s->vram_size) { return 0xff; } + + if (s->sr[VGA_SEQ_MEMORY_MODE] & VGA_SR04_CHN_4M) { + /* chain 4 mode: simplified access (but it should use the same + * algorithms as below, see e.g. vga_mem_writeb's plane mask check= ). + */ + return s->vram_ptr[(addr << 2) | plane]; + } + s->latch =3D ((uint32_t *)s->vram_ptr)[addr]; if (!(s->gr[VGA_GFX_MODE] & 0x08)) { /* read mode 0 */ @@ -870,8 +885,9 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) /* called for accesses between 0xa0000 and 0xc0000 */ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val) { - int memory_map_mode, plane, write_mode, b, func_select, mask; + int memory_map_mode, write_mode, b, func_select, mask; uint32_t write_mask, bit_mask, set_mask; + int plane =3D 0; =20 #ifdef DEBUG_VGA_MEM printf("vga: [0x" HWADDR_FMT_plx "] =3D 0x%02x\n", addr, val); @@ -905,9 +921,47 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, ui= nt32_t val) /* chain 4 mode : simplest access */ plane =3D addr & 3; mask &=3D (1 << plane); + addr &=3D ~3; + } else { + if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0) { + mask &=3D (addr & 1) ? 0x0a : 0x05; + } + } + + if (s->gr[VGA_GFX_MISC] & VGA_GR06_CHAIN_ODD_EVEN) { + addr &=3D ~1; + } + + /* Doubleword/word mode. These should be honored when displaying, + * not when reading/writing to memory! For example, chain4 modes + * use double-word mode and, on real hardware, would fetch bytes + * 0,1,2,3, 16,17,18,19, 32,33,34,35, etc. Text modes use word + * mode and, on real hardware, would fetch bytes 0,1, 8,9, etc. + * + * QEMU instead shifted addresses on memory accesses because it + * allows more optimizations (e.g. chain4_alias) and simplifies + * the draw_line handlers. Unfortunately, there is one case where + * the difference shows. When fetching font data, accesses are + * always in consecutive bytes, even if the text/attribute pairs + * are done in word mode. Hence, doing a right shift when operating + * on font data is wrong. So check the odd/even mode bits together wi= th + * word mode bit. The odd/even read bit is 0 when reading font data, + * and the odd/even write bit is 1 when writing it. + */ + if (s->cr[VGA_CRTC_UNDERLINE] & VGA_CR14_DW) { + addr >>=3D 2; + } else if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0 && + (s->cr[VGA_CRTC_MODE] & VGA_CR17_WORD_BYTE) =3D=3D 0) { + addr >>=3D 1; + } + + if (addr * sizeof(uint32_t) >=3D s->vram_size) { + return; + } + + if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { if (mask) { - assert(addr < s->vram_size); - s->vram_ptr[addr] =3D val; + s->vram_ptr[(addr << 2) | plane] =3D val; #ifdef DEBUG_VGA_MEM printf("vga: chain4: [0x" HWADDR_FMT_plx "]\n", addr); #endif @@ -917,15 +971,6 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, ui= nt32_t val) return; } =20 - if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0) { - mask &=3D (addr & 1) ? 0x0a : 0x05; - } - - if (s->gr[VGA_GFX_MODE] & 0x10) { - /* odd/even mode (aka text mode mapping) */ - addr >>=3D 1; - } - /* standard VGA latched access */ write_mode =3D s->gr[VGA_GFX_MODE] & 3; switch(write_mode) { @@ -990,9 +1035,6 @@ do_write: /* mask data according to sr[2] */ s->plane_updated |=3D mask; /* only used to detect font change */ write_mask =3D mask16[mask]; - if (addr * sizeof(uint32_t) >=3D s->vram_size) { - return; - } ((uint32_t *)s->vram_ptr)[addr] =3D (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | (val & write_mask); diff --git a/hw/display/vga_regs.h b/hw/display/vga_regs.h index 7fdba34b9b1..40e673f164d 100644 --- a/hw/display/vga_regs.h +++ b/hw/display/vga_regs.h @@ -100,7 +100,9 @@ =20 /* VGA CRT controller bit masks */ #define VGA_CR11_LOCK_CR0_CR7 0x80 /* lock writes to CR0 - CR7 */ +#define VGA_CR14_DW 0x40 #define VGA_CR17_H_V_SIGNALS_ENABLED 0x80 +#define VGA_CR17_WORD_BYTE 0x40 =20 /* VGA attribute controller register indices */ #define VGA_ATC_PALETTE0 0x00 @@ -154,6 +156,8 @@ #define VGA_GFX_BIT_MASK 0x08 =20 /* VGA graphics controller bit masks */ +#define VGA_GR05_HOST_ODD_EVEN 0x10 #define VGA_GR06_GRAPHICS_MODE 0x01 +#define VGA_GR06_CHAIN_ODD_EVEN 0x02 =20 #endif /* HW_VGA_REGS_H */ --=20 2.43.0