8 #include "../../../config_file/config_file.h"
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 display_enabled = 0xFF;
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 uint8_t *rtg_mem; // FIXME
25 uint32_t framebuffer_addr;
26 uint32_t framebuffer_addr_adj;
28 static void handle_rtg_command(uint32_t cmd);
29 static struct timespec f1, f2;
31 static const char *op_type_names[OP_TYPE_NUM] = {
38 static const char *rtg_format_names[RTGFMT_NUM] = {
46 rtg_mem = calloc(1, 32 * SIZE_MEGA);
48 printf("Failed to allocate RTG video memory.\n");
55 extern uint8_t busy, rtg_on;
56 void rtg_update_screen();
58 unsigned int rtg_read(uint32_t address, uint8_t mode) {
59 //printf("%s read from RTG: %.8X\n", op_type_names[mode], address);
60 if (address >= PIGFX_REG_SIZE) {
64 return (rtg_mem[address - PIGFX_REG_SIZE]);
67 return be16toh(*(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])));
69 case OP_TYPE_LONGWORD:
70 return be32toh(*(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])));
81 struct timespec diff(struct timespec start, struct timespec end)
84 if ((end.tv_nsec-start.tv_nsec)<0) {
85 temp.tv_sec = end.tv_sec-start.tv_sec-1;
86 temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
88 temp.tv_sec = end.tv_sec-start.tv_sec;
89 temp.tv_nsec = end.tv_nsec-start.tv_nsec;
94 void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
95 //printf("%s write to RTG: %.8X (%.8X)\n", op_type_names[mode], address, value);
96 if (address >= PIGFX_REG_SIZE) {
100 rtg_mem[address - PIGFX_REG_SIZE] = value;
103 *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe16(value);
105 case OP_TYPE_LONGWORD:
106 *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe32(value);
155 handle_rtg_command(value);
159 case OP_TYPE_LONGWORD:
162 rtg_address[0] = value;
165 rtg_address[1] = value;
181 static void handle_rtg_command(uint32_t cmd) {
182 //printf("Handling RTG command %d (%.8X)\n", cmd, cmd);
185 rtg_display_format = rtg_format;
186 rtg_display_width = rtg_x[0];
187 rtg_display_height = rtg_y[0];
189 //rtg_pitch = rtg_display_width << rtg_format;
190 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
191 rtg_total_rows = rtg_y[1];
194 //rtg_pitch = rtg_display_width << rtg_format;
195 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
196 rtg_total_rows = rtg_y[1];
198 printf("Set RTG mode:\n");
199 printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
200 printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
203 //printf("Command: SetPan.\n");
204 rtg_offset_x = rtg_x[1];
205 rtg_offset_y = rtg_y[1];
206 rtg_pitch = (rtg_x[0] << rtg_display_format);
207 framebuffer_addr = rtg_address[0] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
208 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
209 printf("Set panning to $%.8X (%.8X)\n", framebuffer_addr, rtg_address[0]);
210 printf("(Panned: $%.8X)\n", framebuffer_addr_adj);
211 printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
212 printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
214 case RTGCMD_SETCLUT: {
215 //printf("Command: SetCLUT.\n");
216 //printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
217 //printf("Set palette entry %d to 32-bit palette color: %.8X\n", rtg_u8[0], rtg_rgb[0]);
218 rtg_set_clut_entry(rtg_u8[0], rtg_rgb[0]);
221 case RTGCMD_SETDISPLAY:
222 //printf("RTG SetDisplay %s\n", (rtg_u8[1]) ? "enabled" : "disabled");
224 //printf("Command: SetDisplay.\n");
227 case RTGCMD_SETSWITCH:
228 printf("RTG SetSwitch %s\n", ((rtg_x[0]) & 0x01) ? "enabled" : "disabled");
229 printf("LAL: %.4X\n", rtg_x[0]);
230 if (display_enabled != ((rtg_x[0]) & 0x01)) {
231 display_enabled = ((rtg_x[0]) & 0x01);
232 if (display_enabled) {
236 rtg_shutdown_display();
239 case RTGCMD_FILLRECT:
240 rtg_fillrect(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_rgb[0], rtg_x[2], rtg_format, 0xFF);
245 void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color, uint16_t pitch, uint16_t format, uint8_t mask) {
246 if (mask || pitch) {}
247 uint8_t *dptr = &rtg_mem[framebuffer_addr + (x << format) + (y * rtg_pitch)];
248 //printf("FillRect: %d,%d to %d,%d C%.8X, p:%d dp: %d m:%.2X\n", x, y, x+w, y+h, color, pitch, rtg_pitch, mask);
251 //printf("Incoming 8-bit color: %.8X\n", color);
252 for (int xs = 0; xs < w; xs++) {
253 dptr[xs] = color & 0xFF;
257 case RTGFMT_RBG565: {
258 //printf("Incoming raw 16-bit color: %.8X\n", htobe32(color));
259 color = htobe16((color & 0xFFFF));
260 //printf("Incoming 16-bit color: %.8X\n", color);
261 uint16_t *ptr = (uint16_t *)dptr;
262 for (int xs = 0; xs < w; xs++) {
268 color = htobe32(color);
269 //printf("Incoming 32-bit color: %.8X\n", color);
270 uint32_t *ptr = (uint32_t *)dptr;
271 for (int xs = 0; xs < w; xs++) {
277 for (int ys = 1; ys < h; ys++) {
279 memcpy(dptr, (void *)(size_t)(dptr - rtg_pitch), (w << format));