5 #include "../../../config_file/config_file.h"
7 static uint16_t palette[256];
8 static uint8_t rtg_mem[64 * SIZE_MEGA]; // FIXME
10 static uint8_t rtg_u8[4];
11 static uint16_t rtg_x[3], rtg_y[3];
12 static uint16_t rtg_format;
13 static uint32_t rtg_address[2];
14 static uint32_t rtg_rgb[2];
16 static uint8_t rtg_enabled;
18 uint16_t rtg_display_width, rtg_display_height;
19 uint16_t rtg_display_format;
20 uint16_t rtg_pitch, rtg_total_rows;
21 uint16_t rtg_offset_x, rtg_offset_y;
23 uint32_t framebuffer_addr;
25 static void handle_rtg_command(uint32_t cmd);
27 static const char *op_type_names[OP_TYPE_NUM] = {
34 static const char *rtg_format_names[RTGFMT_NUM] = {
41 unsigned int rtg_read(uint32_t address, uint8_t mode) {
42 //printf("%s read from RTG: %.8X\n", op_type_names[mode], address);
43 if (address >= PIGFX_REG_SIZE) {
47 return (rtg_mem[address - PIGFX_REG_SIZE]);
50 return *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE]));
52 case OP_TYPE_LONGWORD:
53 return *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE]));
64 void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
65 //printf("%s write to RTG: %.8X (%.8X)\n", op_type_names[mode], address, value);
66 if (address >= PIGFX_REG_SIZE) {
70 rtg_mem[address - PIGFX_REG_SIZE] = value;
73 *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = value;
75 case OP_TYPE_LONGWORD:
76 *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = value;
91 rtg_u8[address - RTG_U81] = value;
118 handle_rtg_command(value);
122 case OP_TYPE_LONGWORD:
125 rtg_address[0] = value;
128 rtg_address[1] = value;
144 static void handle_rtg_command(uint32_t cmd) {
145 //printf("Handling RTG command %d (%.8X)\n", cmd, cmd);
148 rtg_display_format = rtg_format;
149 rtg_display_width = rtg_x[0];
150 rtg_display_height = rtg_y[0];
152 rtg_pitch = rtg_x[1];
153 rtg_total_rows = rtg_y[1];
156 rtg_pitch = rtg_x[1];
157 rtg_total_rows = rtg_y[1];
159 //printf("Set RTG mode:\n");
160 //printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
161 //printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
164 //printf("Command: SetPan.\n");
165 framebuffer_addr = rtg_address[0];
166 rtg_offset_x = rtg_x[1];
167 rtg_offset_y = rtg_y[1];
168 rtg_pitch = (rtg_x[0] << rtg_display_format);
169 //printf("Set panning to $%.8X\n", framebuffer_addr);
170 //printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
171 //printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
173 case RTGCMD_SETCLUT: {
174 //printf("Command: SetCLUT.\n");
175 //printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
176 int r = (int)((float)rtg_u8[1] / 255.0f * 31.0f);
177 int g = (int)((float)rtg_u8[2] / 255.0f * 63.0f);
178 int b = (int)((float)rtg_u8[3] / 255.0f * 31.0f);
179 palette[rtg_u8[0]] = ((r & 0x1F) << 11) | ((g & 0x3F) << 6) | ((b & 0x1F) << 6);
182 case RTGCMD_SETDISPLAY:
183 //printf("Command: SetDisplay.\n");
184 if (rtg_enabled != rtg_u8[1]) {
185 //printf("RTG Display %s\n", (rtg_u8[1]) ? "enabled" : "disabled");
186 rtg_enabled = rtg_u8[1];
188 //printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
192 case RTGCMD_SETSWITCH:
193 // Implementing this command only matters if the Pi is to pass through the analog (or digital)
194 // native video, otherwise this does nothing.