Skip to contentSkip to conversation

Artist cursor fix final patches

GIT PULL Applied Helge Deller 2 participants 9 messages May 18, 2022

lore
Share & tools
lore
#0 lore raw

The following changes since commit 178bacb66d98d9ee7a702b9f2a4dfcd88b72a9ab:

Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2022-05-09 11:07:04 -0700)

are available in the Git repository at:

https://github.com/hdeller/qemu-hppa.git tags/artist-cursor-fix-final-pull-request

for you to fetch changes up to 9ef2c6b4ab9a430ee230ee305b6994d7eae86fe7:

artist: Fix X cursor position calculation in X11 (2022-05-16 16:46:25 +0200)

----------------------------------------------------------------
hppa: Artist graphics driver fixes for HP-UX and keyboard fix in firmware boot console

This series updates the SeaBIOS-hppa firmware to version 5, in which additional HP fonts were added to the firmware and the firmware boot console was fixed to accept input from the emulated PS/2 keyboard when running in graphical mode (serial console was working before already). To test use the "-boot menu=on" qemu option.

The artist graphics card driver got various fixes when running the X11-Windows on HP-UX:
- fixes the horizontal and vertical postioning of the X11 cursor with HP-UX
- allows X11 to blank the screen (e.g. screensaver)
- allows the X11 driver to turn the X11 cursor on/off

--
Changes compared to version 2 of this series:
- Fixed style issues in the X-cursor positioning patch (noticed by Mark Cave-Ayland)

Changes compared to version 1 of this series:
- Added some Acked-by's from Mark Cave-Ayland <[email protected]>
- SeaBIOS-hppa v5 instead of v4 (PS/2 keyboard now works in boot console)
- integrated artist X11 X-cusor positioning fix (which was sent serperately before)

--
This series should apply cleanly on git head and can be pulled for testing
from: https://github.com/hdeller/qemu-hppa.git artist-cursor-fix-final

----------------------------------------------------------------

Helge Deller (7):
seabios-hppa: Update SeaBIOS-hppa to VERSION 5
artist: Introduce constant for max cursor size
artist: Use human-readable variable names instead of reg_xxx
artist: Fix vertical X11 cursor position in HP-UX
artist: Allow to turn cursor on or off
artist: Emulate screen blanking
artist: Fix X cursor position calculation in X11

 hw/display/artist.c       | 168 ++++++++++++++++++++++++++++----------
 pc-bios/hppa-firmware.img | Bin 701964 -> 719040 bytes
 roms/seabios-hppa         |   2 +-
 3 files changed, 126 insertions(+), 44 deletions(-)

--
2.35.3

#1 lore raw

[PULL 5/7] artist: Allow to turn cursor on or off

Bit 0x80 in the cursor_cntrl register specifies if the cursor should be visible. Prevent rendering the cursor if it's invisible.

---
 hw/display/artist.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
hw/display/artist.c +14 -0
index 780cb15026..b8930b7c5a 100644
@@ -353,10 +353,20 @@ static void artist_get_cursor_pos(ARTISTState *s, int *x, int *y)
     }
 }
 
+static inline bool cursor_visible(ARTISTState *s)
+{
+    /* cursor is visible if bit 0x80 is set in cursor_cntrl */
+    return s->cursor_cntrl & 0x80;
+}
+
 static void artist_invalidate_cursor(ARTISTState *s)
 {
     int x, y;
 
+    if (!cursor_visible(s)) {
+        return;
+    }
+
     artist_get_cursor_pos(s, &x, &y);
     artist_invalidate_lines(&s->vram_buffer[ARTIST_BUFFER_AP],
                             y, s->cursor_height);
@@ -1218,6 +1228,10 @@ static void artist_draw_cursor(ARTISTState *s)
     struct vram_buffer *cursor0, *cursor1 , *buf;
     int cx, cy, cursor_pos_x, cursor_pos_y;
 
+    if (!cursor_visible(s)) {
+        return;
+    }
+
     cursor0 = &s->vram_buffer[ARTIST_BUFFER_CURSOR1];
     cursor1 = &s->vram_buffer[ARTIST_BUFFER_CURSOR2];
     buf = &s->vram_buffer[ARTIST_BUFFER_AP];

--
2.35.3

#2 lore raw

[PULL 6/7] artist: Emulate screen blanking

In reply to Helge Deller

The misc_video and misc_ctrl registers control the visibility of the screen. Start with the screen turned on, and hide or show the screen based on the control registers.

---
 hw/display/artist.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
hw/display/artist.c +30 -0
index b8930b7c5a..49dad2b824 100644
@@ -201,6 +201,8 @@ static const char *artist_reg_name(uint64_t addr)
 }
 #undef REG_NAME
 
+static void artist_invalidate(void *opaque);
+
 /* artist has a fixed line length of 2048 bytes. */
 #define ADDR_TO_Y(addr) extract32(addr, 11, 11)
 #define ADDR_TO_X(addr) extract32(addr, 0, 11)
@@ -903,6 +905,7 @@ static void artist_reg_write(void *opaque, hwaddr addr, uint64_t val,
 {
     ARTISTState *s = opaque;
     int width, height;
+    uint64_t oldval;
 
     trace_artist_reg_write(size, addr, artist_reg_name(addr & ~3ULL), val);
 
@@ -1061,7 +1064,18 @@ static void artist_reg_write(void *opaque, hwaddr addr, uint64_t val,
         break;
 
     case MISC_VIDEO:
+        oldval = s->misc_video;
         combine_write_reg(addr, val, size, &s->misc_video);
+        /* Invalidate and hide screen if graphics signal is turned off. */
+        if (((oldval & 0x0A000000) == 0x0A000000) &&
+            ((val & 0x0A000000) != 0x0A000000)) {
+            artist_invalidate(s);
+        }
+        /* Invalidate and redraw screen if graphics signal is turned back on. */
+        if (((oldval & 0x0A000000) != 0x0A000000) &&
+            ((val & 0x0A000000) == 0x0A000000)) {
+            artist_invalidate(s);
+        }
         break;
 
     case MISC_CTRL:
@@ -1263,6 +1277,12 @@ static void artist_draw_cursor(ARTISTState *s)
     }
 }
 
+static bool artist_screen_enabled(ARTISTState *s)
+{
+    /*  We could check for (s->misc_ctrl & 0x00800000) too... */
+    return ((s->misc_video & 0x0A000000) == 0x0A000000);
+}
+
 static void artist_draw_line(void *opaque, uint8_t *d, const uint8_t *src,
                              int width, int pitch)
 {
@@ -1270,6 +1290,12 @@ static void artist_draw_line(void *opaque, uint8_t *d, const uint8_t *src,
     uint32_t *cmap, *data = (uint32_t *)d;
     int x;
 
+    if (!artist_screen_enabled(s)) {
+        /* clear screen */
+        memset(data, 0, s->width * sizeof(uint32_t));
+        return;
+    }
+
     cmap = (uint32_t *)(s->vram_buffer[ARTIST_BUFFER_CMAP].data + 0x400);
 
     for (x = 0; x < s->width; x++) {
@@ -1384,6 +1410,10 @@ static void artist_realizefn(DeviceState *dev, Error **errp)
     s->image_bitmap_op = 0x23000300;
     s->plane_mask = 0xff;
 
+    /* enable screen */
+    s->misc_video |= 0x0A000000;
+    s->misc_ctrl  |= 0x00800000;
+
     s->con = graphic_console_init(dev, 0, &artist_ops, s);
     qemu_console_resize(s->con, s->width, s->height);
 }

--
2.35.3

#3 lore raw

[PULL 3/7] artist: Use human-readable variable names instead of reg_xxx

In reply to Helge Deller

Convert the variable names of some registers to human-readable and understandable names.

---
 hw/display/artist.c | 72 ++++++++++++++++++++++++++++++---------------
 1 file changed, 49 insertions(+), 23 deletions(-)
hw/display/artist.c +49 -23
index 6333ee41db..c8b261a52e 100644
@@ -81,9 +81,10 @@ struct ARTISTState {
     uint32_t plane_mask;
 
     uint32_t reg_100080;
-    uint32_t reg_300200;
-    uint32_t reg_300208;
-    uint32_t reg_300218;
+    uint32_t horiz_backporch;
+    uint32_t active_lines_low;
+    uint32_t misc_video;
+    uint32_t misc_ctrl;
 
     uint32_t dst_bm_access;
     uint32_t src_bm_access;
@@ -138,8 +139,14 @@ typedef enum {
     BG_COLOR = 0x118014,
     PLANE_MASK = 0x118018,
     IMAGE_BITMAP_OP = 0x11801c,
-    CURSOR_POS = 0x300100,
-    CURSOR_CTRL = 0x300104,
+    CURSOR_POS = 0x300100,      /* reg17 */
+    CURSOR_CTRL = 0x300104,     /* reg18 */
+    MISC_VIDEO = 0x300218,      /* reg21 */
+    MISC_CTRL = 0x300308,       /* reg27 */
+    HORIZ_BACKPORCH = 0x300200, /* reg19 */
+    ACTIVE_LINES_LOW = 0x300208,/* reg20 */
+    FIFO1 = 0x300008,           /* reg34 */
+    FIFO2 = 0x380008,
 } artist_reg_t;
 
 typedef enum {
@@ -177,12 +184,18 @@ static const char *artist_reg_name(uint64_t addr)
     REG_NAME(SRC_BM_ACCESS);
     REG_NAME(CURSOR_POS);
     REG_NAME(CURSOR_CTRL);
+    REG_NAME(HORIZ_BACKPORCH);
+    REG_NAME(ACTIVE_LINES_LOW);
+    REG_NAME(MISC_VIDEO);
+    REG_NAME(MISC_CTRL);
     REG_NAME(LINE_XY);
     REG_NAME(PATTERN_LINE_START);
     REG_NAME(LINE_SIZE);
     REG_NAME(LINE_END);
     REG_NAME(FONT_WRITE_INCR_Y);
     REG_NAME(FONT_WRITE_START);
+    REG_NAME(FIFO1);
+    REG_NAME(FIFO2);
     }
     return "";
 }
@@ -1028,16 +1041,20 @@ static void artist_reg_write(void *opaque, hwaddr addr, uint64_t val,
         combine_write_reg(addr, val, size, &s->transfer_data);
         break;
 
-    case 0x300200:
-        combine_write_reg(addr, val, size, &s->reg_300200);
+    case HORIZ_BACKPORCH:
+        combine_write_reg(addr, val, size, &s->horiz_backporch);
         break;
 
-    case 0x300208:
-        combine_write_reg(addr, val, size, &s->reg_300208);
+    case ACTIVE_LINES_LOW:
+        combine_write_reg(addr, val, size, &s->active_lines_low);
         break;
 
-    case 0x300218:
-        combine_write_reg(addr, val, size, &s->reg_300218);
+    case MISC_VIDEO:
+        combine_write_reg(addr, val, size, &s->misc_video);
+        break;
+
+    case MISC_CTRL:
+        combine_write_reg(addr, val, size, &s->misc_ctrl);
         break;
 
     case CURSOR_POS:
@@ -1122,12 +1139,11 @@ static uint64_t artist_reg_read(void *opaque, hwaddr addr, unsigned size)
     case 0x100000:
     case 0x300000:
     case 0x300004:
-    case 0x300308:
     case 0x380000:
         break;
 
-    case 0x300008:
-    case 0x380008:
+    case FIFO1:
+    case FIFO2:
         /*
          * FIFO ready flag. we're not emulating the FIFOs
          * so we're always ready
@@ -1135,16 +1151,25 @@ static uint64_t artist_reg_read(void *opaque, hwaddr addr, unsigned size)
         val = 0x10;
         break;
 
-    case 0x300200:
-        val = s->reg_300200;
+    case HORIZ_BACKPORCH:
+        val = s->horiz_backporch;
+        break;
+
+    case ACTIVE_LINES_LOW:
+        val = s->active_lines_low;
+        /* activeLinesLo for cursor is in reg20.b.b0 */
+        val |= ((s->height - 1) & 0xff);
         break;
 
-    case 0x300208:
-        val = s->reg_300208;
+    case MISC_VIDEO:
+        /* emulate V-blank */
+        val = s->misc_video ^ 0x00040000;
+        /* activeLinesHi for cursor is in reg21.b.b2 */
+        val |= ((s->height - 1) & 0xff00);
         break;
 
-    case 0x300218:
-        val = s->reg_300218;
+    case MISC_CTRL:
+        val = s->misc_ctrl;
         break;
 
     case 0x30023c:
@@ -1379,9 +1404,10 @@ static const VMStateDescription vmstate_artist = {
         VMSTATE_UINT32(cursor_width, ARTISTState),
         VMSTATE_UINT32(plane_mask, ARTISTState),
         VMSTATE_UINT32(reg_100080, ARTISTState),
-        VMSTATE_UINT32(reg_300200, ARTISTState),
-        VMSTATE_UINT32(reg_300208, ARTISTState),
-        VMSTATE_UINT32(reg_300218, ARTISTState),
+        VMSTATE_UINT32(horiz_backporch, ARTISTState),
+        VMSTATE_UINT32(active_lines_low, ARTISTState),
+        VMSTATE_UINT32(misc_video, ARTISTState),
+        VMSTATE_UINT32(misc_ctrl, ARTISTState),
         VMSTATE_UINT32(dst_bm_access, ARTISTState),
         VMSTATE_UINT32(src_bm_access, ARTISTState),
         VMSTATE_UINT32(control_plane, ARTISTState),

--
2.35.3

#4 lore raw

[PULL 7/7] artist: Fix X cursor position calculation in X11

In reply to Helge Deller

The X cursor postion can be calculated based on the backporch and interleave values. In the emulation we ignore the HP-UX settings for backporch and use instead twice the size of the emulated cursor. With those changes the X-position of the graphics cursor is now finally working correctly on HP-UX 10 and HP-UX 11.

Based on coding in Xorg X11R6.6

---
 hw/display/artist.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)
hw/display/artist.c +22 -16
index 49dad2b824..eadaef0d46 100644
@@ -1,7 +1,8 @@
 /*
  * QEMU HP Artist Emulation
  *
- * Copyright (c) 2019 Sven Schnelle <[email protected]>
+ * Copyright (c) 2019-2022 Sven Schnelle <[email protected]>
+ * Copyright (c) 2022 Helge Deller <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  */
@@ -313,19 +314,15 @@ static void artist_rop8(ARTISTState *s, struct vram_buffer *buf,
 static void artist_get_cursor_pos(ARTISTState *s, int *x, int *y)
 {
     /*
-     * Don't know whether these magic offset values are configurable via
-     * some register. They seem to be the same for all resolutions.
-     * The cursor values provided in the registers are:
-     * X-value: -295 (for HP-UX 11) and 338 (for HP-UX 10.20) up to 2265
-     * Y-value: 1146 down to 0
      * The emulated Artist graphic is like a CRX graphic, and as such
      * it's usually fixed at 1280x1024 pixels.
-     * Because of the maximum Y-value of 1146 you can not choose a higher
-     * vertical resolution on HP-UX (unless you disable the mouse).
+     * Other resolutions may work, but no guarantee.
      */
 
-    static int offset = 338;
-    int lx;
+    unsigned int hbp_times_vi, horizBackPorch;
+    int16_t xHi, xLo;
+    const int videoInterleave = 4;
+    const int pipelineDelay = 4;
 
     /* ignore if uninitialized */
     if (s->cursor_pos == 0) {
@@ -333,16 +330,23 @@ static void artist_get_cursor_pos(ARTISTState *s, int *x, int *y)
         return;
     }
 
-    lx = artist_get_x(s->cursor_pos);
-    if (lx < offset) {
-        offset = lx;
-    }
-    *x = (lx - offset) / 2;
+    /*
+     * Calculate X position based on backporch and interleave values.
+     * Based on code from Xorg X11R6.6
+     */
+    horizBackPorch = ((s->horiz_backporch & 0xff0000) >> 16) +
+                     ((s->horiz_backporch & 0xff00) >> 8) + 2;
+    hbp_times_vi = horizBackPorch * videoInterleave;
+    xHi = s->cursor_pos >> 19;
+    *x = ((xHi + pipelineDelay) * videoInterleave) - hbp_times_vi;
+
+    xLo = (s->cursor_pos >> 16) & 0x07;
+    *x += ((xLo - hbp_times_vi) & (videoInterleave - 1)) + 8 - 1;
 
     /* subtract cursor offset from cursor control register */
     *x -= (s->cursor_cntrl & 0xf0) >> 4;
 
-    /* height minus nOffscreenScanlines is stored in cursor control register */
+    /* Calculate Y position */
     *y = s->height - artist_get_y(s->cursor_pos);
     *y -= (s->cursor_cntrl & 0x0f);
 
@@ -1056,6 +1060,8 @@ static void artist_reg_write(void *opaque, hwaddr addr, uint64_t val,
         break;
 
     case HORIZ_BACKPORCH:
+        /* overwrite HP-UX settings to fix X cursor position. */
+        val = (NGLE_MAX_SPRITE_SIZE << 16) + (NGLE_MAX_SPRITE_SIZE << 8);
         combine_write_reg(addr, val, size, &s->horiz_backporch);
         break;
 

--
2.35.3

#5 lore raw

[PULL 2/7] artist: Introduce constant for max cursor size

In reply to Helge Deller

Add the constant NGLE_MAX_SPRITE_SIZE which defines the currently maximum supported cursor size.

---
 hw/display/artist.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/display/artist.c +6 -4
index 39fc0c4ca5..6333ee41db 100644
@@ -98,6 +98,9 @@ struct ARTISTState {
     int draw_line_pattern;
 };
 
+/* hardware allows up to 64x64, but we emulate 32x32 only. */
+#define NGLE_MAX_SPRITE_SIZE    32
+
 typedef enum {
     ARTIST_BUFFER_AP = 1,
     ARTIST_BUFFER_OVERLAY = 2,
@@ -1325,11 +1328,10 @@ static void artist_realizefn(DeviceState *dev, Error **errp)
     framebuffer_update_memory_section(&s->fbsection, &buf->mr, 0,
                                       buf->width, buf->height);
     /*
-     * no idea whether the cursor is fixed size or not, so assume 32x32 which
-     * seems sufficient for HP-UX X11.
+     * Artist cursor max size
      */
-    s->cursor_height = 32;
-    s->cursor_width = 32;
+    s->cursor_height = NGLE_MAX_SPRITE_SIZE;
+    s->cursor_width = NGLE_MAX_SPRITE_SIZE;
 
     /*
      * These two registers are not initialized by seabios's STI implementation.

--
2.35.3

#6 lore raw

[PULL 4/7] artist: Fix vertical X11 cursor position in HP-UX

In reply to Helge Deller

Drop the hard-coded value of 1146 lines which seems to work with HP-UX 11, but not with HP-UX 10. Instead encode the screen height in byte 0 of active_lines_low and byte 3 of misc_video as it's expected by the Xorg X11 graphics driver.

This potentially allows for higher vertical screen resolutions than 1280x1024 with X11.

---
 hw/display/artist.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
hw/display/artist.c +9 -5
index c8b261a52e..780cb15026 100644
@@ -337,10 +337,11 @@ static void artist_get_cursor_pos(ARTISTState *s, int *x, int *y)
     }
     *x = (lx - offset) / 2;
 
-    *y = 1146 - artist_get_y(s->cursor_pos);
-
     /* subtract cursor offset from cursor control register */
     *x -= (s->cursor_cntrl & 0xf0) >> 4;
+
+    /* height minus nOffscreenScanlines is stored in cursor control register */
+    *y = s->height - artist_get_y(s->cursor_pos);
     *y -= (s->cursor_cntrl & 0x0f);
 
     if (*x > s->width) {
@@ -1158,14 +1159,17 @@ static uint64_t artist_reg_read(void *opaque, hwaddr addr, unsigned size)
     case ACTIVE_LINES_LOW:
         val = s->active_lines_low;
         /* activeLinesLo for cursor is in reg20.b.b0 */
-        val |= ((s->height - 1) & 0xff);
+        val &= ~(0xff << 24);
+        val |= (s->height & 0xff) << 24;
         break;
 
     case MISC_VIDEO:
         /* emulate V-blank */
-        val = s->misc_video ^ 0x00040000;
+        s->misc_video ^= 0x00040000;
         /* activeLinesHi for cursor is in reg21.b.b2 */
-        val |= ((s->height - 1) & 0xff00);
+        val = s->misc_video;
+        val &= ~0xff00UL;
+        val |= (s->height & 0xff00);
         break;
 
     case MISC_CTRL:

--
2.35.3

#7 lore raw

[PULL 1/7] seabios-hppa: Update SeaBIOS-hppa to VERSION 5

In reply to Helge Deller

New features and fixes in SeaBIOS for hppa/parisc:

* STI firmware now contains additional fonts built-in, which can be selected with qemu command-line options:

        -fw_cfg opt/font,string=1       - a HP 8x16 font
        -fw_cfg opt/font,string=2       - a HP 6x13 font
        -fw_cfg opt/font,string=3       - a HP 10x20 font
        -fw_cfg opt/font,string=4       - a Linux 16x32 font

* Fixed PS/2 keyboard emulation when running in graphical mode. This allows to type boot commands in the firmware boot menu if qemu was started with "-boot menu=on" (and no linux kernel was given on the qemu command line).

* Fix firmware rendenzvous code to clear all pending external intrrupts before entering the waiting loop.

---
 pc-bios/hppa-firmware.img | Bin 701964 -> 719040 bytes
 roms/seabios-hppa         |   2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
pc-bios/hppa-firmware.img binary +0 -0
index 0ec2d96b8f48a46dc9c0fabd50d14d5a2212a071..392bce072bad607b1baaff0136f35844fa5d439e 100644
GIT binary patch
roms/seabios-hppa +1 -1
index bf3404006f..17ca7a9998 160000
@@ -1 +1 @@
-Subproject commit bf3404006fd2c832857eb57e6f853862f97dacea
+Subproject commit 17ca7a9998c1755d42321cfc0afb5f480f5a58ff

--
2.35.3

#8 lore raw
In reply to Helge Deller
Quoted 21 lines · Helge Deller

The following changes since commit 178bacb66d98d9ee7a702b9f2a4dfcd88b72a9ab:

   Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2022-05-09 11:07:04 -0700)

are available in the Git repository at:

https://github.com/hdeller/qemu-hppa.git tags/artist-cursor-fix-final-pull-request

for you to fetch changes up to 9ef2c6b4ab9a430ee230ee305b6994d7eae86fe7:

artist: Fix X cursor position calculation in X11 (2022-05-16 16:46:25 +0200)

----------------------------------------------------------------
hppa: Artist graphics driver fixes for HP-UX and keyboard fix in firmware boot console

This series updates the SeaBIOS-hppa firmware to version 5, in which additional HP fonts were added to the firmware and the firmware boot console was fixed to accept input from the emulated PS/2 keyboard when running in graphical mode (serial console was working before already). To test use the "-boot menu=on" qemu option.

Quoted 5 lines

The artist graphics card driver got various fixes when running the X11-Windows on HP-UX:
- fixes the horizontal and vertical postioning of the X11 cursor with HP-UX
- allows X11 to blank the screen (e.g. screensaver)
- allows the X11 driver to turn the X11 cursor on/off

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.

r~