From 8094fb30f6c072ab9f3ffda1079315c5a9c52b2d Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Thu, 11 Jun 2020 01:30:10 +0200 Subject: [PATCH] atirage: add access to internal DAC palette. --- devices/atirage.cpp | 36 +++++++++++++++++++++++++++++++++++- devices/atirage.h | 7 +++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/devices/atirage.cpp b/devices/atirage.cpp index 1747d1e..e85f0e6 100644 --- a/devices/atirage.cpp +++ b/devices/atirage.cpp @@ -170,7 +170,17 @@ uint32_t ATIRage::read_reg(uint32_t offset, uint32_t size) { uint32_t res; switch (offset & ~3) { - case ATI_GP_IO: + case ATI_DAC_REGS: + if (offset == ATI_DAC_DATA) { + this->block_io_regs[ATI_DAC_DATA] = + this->palette[this->block_io_regs[ATI_DAC_R_INDEX]][this->comp_index]; + this->comp_index++; /* move to next color component */ + if (this->comp_index >= 3) { + /* autoincrement reading index - move to next palette entry */ + (this->block_io_regs[ATI_DAC_R_INDEX])++; + this->comp_index = 0; + } + } break; default: LOG_F( @@ -204,6 +214,30 @@ void ATIRage::write_reg(uint32_t offset, uint32_t value, uint32_t size) { this->disp_id->read_monitor_sense(gpio_val, gpio_dir)); } break; + case ATI_DAC_REGS: + switch (offset) { + /* writing to read/write index registers resets color component index */ + case ATI_DAC_W_INDEX: + case ATI_DAC_R_INDEX: + this->comp_index = 0; + break; + case ATI_DAC_DATA: + this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][this->comp_index] = value & 0xFF; + this->comp_index++; /* move to next color component */ + if (this->comp_index >= 3) { + LOG_F( + INFO, + "ATI DAC palette entry #%d set to R=%X, G=%X, B=%X", + this->block_io_regs[ATI_DAC_W_INDEX], + this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][0], + this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][1], + this->palette[this->block_io_regs[ATI_DAC_W_INDEX]][2]); + /* autoincrement writing index - move to next palette entry */ + (this->block_io_regs[ATI_DAC_W_INDEX])++; + this->comp_index = 0; + } + } + break; default: LOG_F( INFO, diff --git a/devices/atirage.h b/devices/atirage.h index f57b7fe..60b6d70 100644 --- a/devices/atirage.h +++ b/devices/atirage.h @@ -80,6 +80,10 @@ enum { ATI_VGA_RP_SEL = 0x00B8, ATI_I2C_CNTL_1 = 0x00BC, ATI_DAC_REGS = 0x00C0, + ATI_DAC_W_INDEX = 0x00C0, + ATI_DAC_DATA = 0x00C1, + ATI_DAC_MASK = 0x00C2, + ATI_DAC_R_INDEX = 0x00C3, ATI_DAC_CNTL = 0x00C4, ATI_GEN_TEST_CNTL = 0x00D0, ATI_CUSTOM_MACRO_CNTL = 0x00D4, @@ -155,5 +159,8 @@ private: uint32_t aperture_base; DisplayID* disp_id; + + uint8_t palette[256][4]; /* internal DAC palette in RGBA format */ + int comp_index; /* color component index for DAC palette access */ }; #endif /* ATI_RAGE_H */