From 9c87dda0e4592b59cfd3129bea463dcd79bd290e Mon Sep 17 00:00:00 2001 From: angelosa Date: Fri, 11 Aug 2023 04:09:39 +0200 Subject: video/pc_vga_matrox.cpp: implement cursor color --- src/devices/video/pc_vga_matrox.cpp | 76 +++++++++++++++++++++++++++++++++++-- src/devices/video/pc_vga_matrox.h | 13 +++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/devices/video/pc_vga_matrox.cpp b/src/devices/video/pc_vga_matrox.cpp index 6756ab79a0b..2ade6ec2006 100644 --- a/src/devices/video/pc_vga_matrox.cpp +++ b/src/devices/video/pc_vga_matrox.cpp @@ -25,6 +25,16 @@ device_memory_interface::space_config_vector matrox_vga_device::memory_space_con return r; } +void matrox_vga_device::device_start() +{ + svga_device::device_start(); + + save_item(NAME(m_cursor_read_index)); + save_item(NAME(m_cursor_write_index)); + save_item(NAME(m_cursor_index_state)); + save_pointer(NAME(m_cursor_color), 12); +} + void matrox_vga_device::device_reset() { svga_device::device_reset(); @@ -36,6 +46,8 @@ void matrox_vga_device::device_reset() m_mgamode = false; m_interlace_mode = false; + + m_cursor_read_index = m_cursor_write_index = m_cursor_index_state = 0; m_truecolor_ctrl = 0x80; m_multiplex_ctrl = 0x98; } @@ -209,9 +221,9 @@ void matrox_vga_device::ramdac_ext_map(address_map &map) map(0x03, 0x03).lr8( NAME([this] (offs_t offset) { return vga.dac.read_index; }) ).w(FUNC(matrox_vga_device::ramdac_read_index_w)); -// map(0x04, 0x04) Cursor/Overscan Color Write Index -// map(0x05, 0x05) Cursor/Overscan Color data -// map(0x07, 0x07) Cursor/Overscan Color Read Index + map(0x04, 0x04).rw(FUNC(matrox_vga_device::cursor_write_index_r), FUNC(matrox_vga_device::cursor_write_index_w)); + map(0x05, 0x05).rw(FUNC(matrox_vga_device::cursor_data_r), FUNC(matrox_vga_device::cursor_data_w)); + map(0x07, 0x07).rw(FUNC(matrox_vga_device::cursor_read_index_r), FUNC(matrox_vga_device::cursor_read_index_w)); // map(0x09, 0x09) Direct Cursor control map(0x0a, 0x0a).rw(FUNC(matrox_vga_device::ramdac_ext_indexed_r), FUNC(matrox_vga_device::ramdac_ext_indexed_w)); // map(0x0b, 0x0b) Cursor RAM data @@ -224,7 +236,6 @@ u8 matrox_vga_device::ramdac_ext_indexed_r() // Unclear from the docs, according to usage seems to be the write index with no autoincrement logerror("RAMDAC ext read [%02x]\n", vga.dac.write_index); return space(EXT_REG + 1).read_byte(vga.dac.write_index); -; } void matrox_vga_device::ramdac_ext_indexed_w(offs_t offset, u8 data) @@ -233,6 +244,63 @@ void matrox_vga_device::ramdac_ext_indexed_w(offs_t offset, u8 data) space(EXT_REG + 1).write_byte(vga.dac.write_index, data); } +u8 matrox_vga_device::cursor_write_index_r() +{ + return m_cursor_write_index; +} + +void matrox_vga_device::cursor_write_index_w(offs_t offset, u8 data) +{ + m_cursor_write_index = data & 3; + m_cursor_index_state = 0; + if (data & 0xfc) + logerror("RAMDAC cursor write index > 3"); +} + +u8 matrox_vga_device::cursor_read_index_r() +{ + return m_cursor_read_index; +} + +void matrox_vga_device::cursor_read_index_w(offs_t offset, u8 data) +{ + m_cursor_read_index = data & 3; + m_cursor_index_state = 0; + if (data & 0xfc) + logerror("RAMDAC cursor read index > 3"); +} + +u8 matrox_vga_device::cursor_data_r() +{ + const u8 res = m_cursor_color[(m_cursor_read_index * 3) + m_cursor_index_state]; + if (!machine().side_effects_disabled()) + { + m_cursor_index_state ++; + if (m_cursor_index_state > 2) + { + m_cursor_index_state = 0; + m_cursor_read_index ++; + m_cursor_read_index &= 3; + } + } + return res; +} + +void matrox_vga_device::cursor_data_w(offs_t offset, u8 data) +{ + m_cursor_color[(m_cursor_write_index * 3) + m_cursor_index_state] = data; + if (!machine().side_effects_disabled()) + { + m_cursor_index_state ++; + if (m_cursor_write_index > 2) + { + m_cursor_index_state = 0; + m_cursor_write_index ++; + m_cursor_write_index &= 3; + } + } +} + void matrox_vga_device::ramdac_indexed_map(address_map &map) { // silicon revision diff --git a/src/devices/video/pc_vga_matrox.h b/src/devices/video/pc_vga_matrox.h index c12847b342f..cac6f324521 100644 --- a/src/devices/video/pc_vga_matrox.h +++ b/src/devices/video/pc_vga_matrox.h @@ -27,6 +27,7 @@ public: protected: virtual void io_3bx_3dx_map(address_map &map) override; + virtual void device_start() override; virtual void device_reset() override; virtual uint16_t offset() override; @@ -65,6 +66,18 @@ private: u8 ramdac_ext_indexed_r(); void ramdac_ext_indexed_w(offs_t offset, u8 data); + u8 cursor_write_index_r(); + void cursor_write_index_w(offs_t offset, u8 data); + u8 cursor_data_r(); + void cursor_data_w(offs_t offset, u8 data); + u8 cursor_read_index_r(); + void cursor_read_index_w(offs_t offset, u8 data); + + u8 m_cursor_write_index = 0; + u8 m_cursor_read_index = 0; + u8 m_cursor_index_state = 0; + u8 m_cursor_color[12]{}; + u8 truecolor_ctrl_r(); void truecolor_ctrl_w(offs_t offset, u8 data); u8 multiplex_ctrl_r(); -- cgit v1.2.3