Skip to contentSkip to conversation

sm501: Fix hardware cursor color conversion

PATCH Applied Sebastian Bauer 2 participants 3 messages Jun 18, 2018 – Jun 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sm501: Fix hardware cursor color conversion

According to the sm501 specs the hardware cursor colors are to be given in the rgb565 format, but the code currently interprets them as bgr565.

Therefore, the colors of the hardware cursors are wrong in the QEMU display, e.g., the standard mouse pointer of AmigaOS appears blue instead of red. This change fixes this issue by replacing the existing naive bgr565 => rgb888 conversion with a standard rgb565 => rgb888 one that also scales the color component values properly.

---
 hw/display/sm501.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/sm501.c +3 -3
index 0488ab69d3..6c7f8483f3 100644
@@ -668,9 +668,9 @@ static inline void get_hwc_palette(SM501State *state, int crt, uint8_t *palette)
         } else {
             rgb565 = color_reg & 0xFFFF;
         }
-        palette[i * 3 + 0] = (rgb565 << 3) & 0xf8; /* red */
-        palette[i * 3 + 1] = (rgb565 >> 3) & 0xfc; /* green */
-        palette[i * 3 + 2] = (rgb565 >> 8) & 0xf8; /* blue */
+        palette[i * 3 + 0] = ((rgb565 >> 11) * 527 + 23) >> 6; /* r */
+        palette[i * 3 + 1] = (((rgb565 >> 5) & 0x3f) * 259 + 33) >> 6; /* g */
+        palette[i * 3 + 2] = ((rgb565 & 0x1f) * 527 + 23) >> 6; /* b */
     }
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Sebastian Bauer

According to the sm501 specs the hardware cursor colors are to be given in the rgb565 format, but the code currently interprets them as bgr565.

Can those specs be found online somewhere?

Quoted 29 lines

Therefore, the colors of the hardware cursors are wrong in the QEMU display, e.g., the standard mouse pointer of AmigaOS appears blue instead of red. This change fixes this issue by replacing the existing naive bgr565 => rgb888 conversion with a standard rgb565 => rgb888 one that also scales the color component values properly.

---
 hw/display/sm501.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/sm501.c +3 -3
index 0488ab69d3..6c7f8483f3 100644
@@ -668,9 +668,9 @@ static inline void get_hwc_palette(SM501State *state, int crt, uint8_t *palette)
         } else {
             rgb565 = color_reg & 0xFFFF;
         }
-        palette[i * 3 + 0] = (rgb565 << 3) & 0xf8; /* red */
-        palette[i * 3 + 1] = (rgb565 >> 3) & 0xfc; /* green */
-        palette[i * 3 + 2] = (rgb565 >> 8) & 0xf8; /* blue */
+        palette[i * 3 + 0] = ((rgb565 >> 11) * 527 + 23) >> 6; /* r */
+        palette[i * 3 + 1] = (((rgb565 >> 5) & 0x3f) * 259 + 33) >> 6; /* g */
+        palette[i * 3 + 2] = ((rgb565 & 0x1f) * 527 + 23) >> 6; /* b */
     }
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Applied
#2 lore raw
In reply to Sebastian Bauer
Quoted 10 lines · Sebastian Bauer

According to the sm501 specs the hardware cursor colors are to be given in the rgb565 format, but the code currently interprets them as bgr565.

Therefore, the colors of the hardware cursors are wrong in the QEMU display, e.g., the standard mouse pointer of AmigaOS appears blue instead of red. This change fixes this issue by replacing the existing naive bgr565 => rgb888 conversion with a standard rgb565 => rgb888 one that also scales the color component values properly.

Applied to ppc-for-3.0, thanks.

Quoted 21 lines
---
 hw/display/sm501.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/display/sm501.c +3 -3
index 0488ab69d3..6c7f8483f3 100644
@@ -668,9 +668,9 @@ static inline void get_hwc_palette(SM501State *state, int crt, uint8_t *palette)
         } else {
             rgb565 = color_reg & 0xFFFF;
         }
-        palette[i * 3 + 0] = (rgb565 << 3) & 0xf8; /* red */
-        palette[i * 3 + 1] = (rgb565 >> 3) & 0xfc; /* green */
-        palette[i * 3 + 2] = (rgb565 >> 8) & 0xf8; /* blue */
+        palette[i * 3 + 0] = ((rgb565 >> 11) * 527 + 23) >> 6; /* r */
+        palette[i * 3 + 1] = (((rgb565 >> 5) & 0x3f) * 259 + 33) >> 6; /* g */
+        palette[i * 3 + 2] = ((rgb565 & 0x1f) * 527 + 23) >> 6; /* b */
     }
 }
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson