qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 03/16] vga: mask addresses in non-VESA modes to 256k
Date: Thu, 18 Jan 2024 13:24:03 +0100	[thread overview]
Message-ID: <20240118122416.9209-4-pbonzini@redhat.com> (raw)
In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com>

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 <pbonzini@redhat.com>
---
 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 = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
     width >>= 3;
     for(x = 0; x < width; x++) {
-        data = vga_read_dword_le(vga, addr);
+        data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1));
         data &= plane_mask;
         v = expand2[GET_PLANE(data, 0)];
         v |= expand2[GET_PLANE(data, 2)] << 2;
@@ -144,7 +144,7 @@ static void vga_draw_line2d2(VGACommonState *vga, uint8_t *d,
     plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
     width >>= 3;
     for(x = 0; x < width; x++) {
-        data = vga_read_dword_le(vga, addr);
+        data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1));
         data &= plane_mask;
         v = expand2[GET_PLANE(data, 0)];
         v |= expand2[GET_PLANE(data, 2)] << 2;
@@ -177,7 +177,7 @@ static void vga_draw_line4(VGACommonState *vga, uint8_t *d,
     plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
     width >>= 3;
     for(x = 0; x < width; x++) {
-        data = vga_read_dword_le(vga, addr);
+        data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1));
         data &= plane_mask;
         v = expand4[GET_PLANE(data, 0)];
         v |= expand4[GET_PLANE(data, 1)] << 1;
@@ -209,7 +209,7 @@ static void vga_draw_line4d2(VGACommonState *vga, uint8_t *d,
     plane_mask = mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf];
     width >>= 3;
     for(x = 0; x < width; x++) {
-        data = vga_read_dword_le(vga, addr);
+        data = vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1));
         data &= plane_mask;
         v = expand4[GET_PLANE(data, 0)];
         v |= expand4[GET_PLANE(data, 1)] << 1;
@@ -242,6 +242,7 @@ static void vga_draw_line8d2(VGACommonState *vga, uint8_t *d,
     palette = vga->last_palette;
     width >>= 3;
     for(x = 0; x < width; x++) {
+        addr &= 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 fea26f91232..5bf4d14f342 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -47,6 +47,9 @@ bool have_vga = true;
 /* 16 state changes per vertical frame @60 Hz */
 #define VGA_TEXT_CURSOR_PERIOD_MS       (1000 * 2 * 16 / 60)
 
+/* Address mask for non-VESA modes.  */
+#define VGA_VRAM_SIZE                   (256 * KiB)
+
 /*
  * Video Graphics Array (VGA)
  *
-- 
2.43.0



  parent reply	other threads:[~2024-01-18 12:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18 12:24 [PULL 00/16] VGA, x86 TCG, misc changes for 2024-01-18 Paolo Bonzini
2024-01-18 12:24 ` [PULL 01/16] vga: use common endian swap macros Paolo Bonzini
2024-01-18 12:24 ` [PULL 02/16] vga: introduce VGADisplayParams Paolo Bonzini
2024-01-18 12:24 ` Paolo Bonzini [this message]
2024-01-18 12:24 ` [PULL 04/16] vga: implement horizontal pel panning in graphics modes Paolo Bonzini
2024-01-18 12:24 ` [PULL 05/16] vga: optimize horizontal pel panning in 256-color modes Paolo Bonzini
2024-01-18 12:24 ` [PULL 06/16] vga: reindent memory access code Paolo Bonzini
2024-01-18 12:24 ` [PULL 07/16] vga: use latches in odd/even mode too Paolo Bonzini
2024-01-18 12:24 ` [PULL 08/16] vga: sort-of implement word and double-word access modes Paolo Bonzini
2024-01-18 12:24 ` [PULL 09/16] Add class property to configure KVM device node to use Paolo Bonzini
2024-01-18 12:24 ` [PULL 10/16] io_uring: move LuringState typedef to block/aio.h Paolo Bonzini
2024-01-18 12:24 ` [PULL 11/16] target/i386: Do not re-compute new pc with CF_PCREL Paolo Bonzini
2024-01-18 12:24 ` [PULL 12/16] target/i386: fix incorrect EIP in PC-relative translation blocks Paolo Bonzini
2024-01-18 12:24 ` [PULL 13/16] target/i386: pcrel: store low bits of physical address in data[0] Paolo Bonzini
2024-01-18 12:24 ` [PULL 14/16] remove unnecessary casts from uintptr_t Paolo Bonzini
2024-01-18 12:24 ` [PULL 15/16] qemu/osdep: Add huge page aligned support on LoongArch platform Paolo Bonzini
2024-01-18 12:24 ` [PULL 16/16] tests/tcg: Don't #include <inttypes.h> in aarch64/system/vtimer.c Paolo Bonzini
2024-01-19 16:41 ` [PULL 00/16] VGA, x86 TCG, misc changes for 2024-01-18 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240118122416.9209-4-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).