diff --git a/src/dev/gr2/hq2.rs b/src/dev/gr2/hq2.rs index 496ec0ca9..804997075 100644 --- a/src/dev/gr2/hq2.rs +++ b/src/dev/gr2/hq2.rs @@ -1515,7 +1515,8 @@ impl Hq2Engine { match cmd { PUC_INIT => self.init(out), PUC_COLOR => { - out.reg(re3::REG_R, (a[0] & 0xfff) << 11); + // The pixel is one byte; OpenBSD repeats the index in all four (rasops). + out.reg(re3::REG_R, (a[0] & 0xff) << 11); out.reg(re3::REG_G, 0); out.reg(re3::REG_B, 0); } diff --git a/src/dev/gr2/hq2_tests.rs b/src/dev/gr2/hq2_tests.rs index c3540290d..83bbfc814 100644 --- a/src/dev/gr2/hq2_tests.rs +++ b/src/dev/gr2/hq2_tests.rs @@ -76,6 +76,20 @@ fn textport_clear_and_rect() { assert_eq!(pixel(g, 10, 22), 0); } +/// OpenBSD passes rasops' 8-bit colour, the index repeated in all four bytes. +#[test] +fn textport_color_uses_the_low_byte_as_the_pixel() { + let g = &live_gr2(Gr2Variant::Xz); + tp_init(g); + cmd(g, hq2::PUC_COLOR, 0x0707_0707); + cmd(g, hq2::PUC_RECTI2D, 10); + data(g, 20); + data(g, 12); + data(g, 21); + g.wait_idle(); + assert_eq!(pixel(g, 10, 20), 7); +} + #[test] fn textport_drawchar_places_glyph_bottom_row_first() { let g = &live_gr2(Gr2Variant::Xz);