1 /* 2 Copyright (c) 2002-2004, Thomas Kurschel 3 4 5 Part of Radeon accelerant 6 7 Palette handling. Though it's very often referred to as 8 being part of the DAC, this is not really true as palette 9 lookup is part of the CRTC unit (else it wouldn't work for 10 digital output like DVI) 11 */ 12 13 14 #include "GlobalData.h" 15 #include "dac_regs.h" 16 #include "CP.h" 17 18 19 // Radeon's DACs share same public registers, this function 20 // selects the DAC you'll talk to 21 #define selectPalette( crtc_idx ) \ 22 WRITE_IB_REG( RADEON_DAC_CNTL2, \ 23 (crtc_idx == 0 ? 0 : RADEON_DAC2_PALETTE_ACC_CTL) | \ 24 (ai->si->dac_cntl2 & ~RADEON_DAC2_PALETTE_ACC_CTL) ); 25 26 27 // set standard colour palette (needed for non-palette modes) 28 void Radeon_InitPalette( 29 accelerator_info *ai, int crtc_idx ) 30 { 31 int i; 32 33 START_IB(); 34 35 selectPalette( crtc_idx ); 36 37 WRITE_IB_REG( RADEON_PALETTE_INDEX, 0 ); 38 39 for( i = 0; i < 256; ++i ) 40 WRITE_IB_REG( RADEON_PALETTE_DATA, (i << 16) | (i << 8) | i ); 41 42 SUBMIT_IB(); 43 } 44 45 static void setPalette( 46 accelerator_info *ai, int crtc_idx, 47 uint count, uint8 first, uint8 *color_data ); 48 49 // public function: set colour palette 50 void SET_INDEXED_COLORS( 51 uint count, uint8 first, uint8 *color_data, uint32 flags ) 52 { 53 virtual_card *vc = ai->vc; 54 55 (void)flags; 56 57 SHOW_FLOW( 3, "first=%d, count=%d", first, count ); 58 59 if( vc->mode.space != B_CMAP8 ) { 60 SHOW_ERROR0( 2, "Tried to set palette in non-palette mode" ); 61 return; 62 } 63 64 if( vc->used_crtc[0] ) 65 setPalette( ai, 0, count, first, color_data ); 66 if( vc->used_crtc[1] ) 67 setPalette( ai, 1, count, first, color_data ); 68 } 69 70 71 // set palette of one DAC 72 static void setPalette( 73 accelerator_info *ai, int crtc_idx, 74 uint count, uint8 first, uint8 *color_data ) 75 { 76 uint i; 77 78 START_IB(); 79 80 selectPalette( crtc_idx ); 81 82 WRITE_IB_REG( RADEON_PALETTE_INDEX, first ); 83 84 for( i = 0; i < count; ++i, color_data += 3 ) 85 WRITE_IB_REG( RADEON_PALETTE_DATA, 86 ((uint32)color_data[0] << 16) | 87 ((uint32)color_data[1] << 8) | 88 color_data[2] ); 89 90 SUBMIT_IB(); 91 } 92