8 #include "config_file/config_file.h"
11 uint16_t rtg_x[8], rtg_y[8];
14 uint32_t rtg_address[8];
15 uint32_t rtg_address_adj[8];
18 static uint8_t display_enabled = 0xFF;
20 uint16_t rtg_display_width, rtg_display_height;
21 uint16_t rtg_display_format;
22 uint16_t rtg_pitch, rtg_total_rows;
23 uint16_t rtg_offset_x, rtg_offset_y;
25 uint8_t *rtg_mem; // FIXME
27 uint32_t framebuffer_addr = 0;
28 uint32_t framebuffer_addr_adj = 0;
30 static void handle_rtg_command(uint32_t cmd);
31 static struct timespec f1, f2;
33 uint8_t realtime_graphics_debug = 0;
34 extern int cpu_emulation_running;
36 static const char *op_type_names[OP_TYPE_NUM] = {
43 static const char *rtg_format_names[RTGFMT_NUM] = {
51 rtg_mem = calloc(1, 40 * SIZE_MEGA);
53 printf("Failed to allocate RTG video memory.\n");
60 extern uint8_t busy, rtg_on;
61 void rtg_update_screen();
63 unsigned int rtg_read(uint32_t address, uint8_t mode) {
64 //printf("%s read from RTG: %.8X\n", op_type_names[mode], address);
65 if (address == RTG_COMMAND) {
68 if (address >= PIGFX_REG_SIZE) {
69 if (rtg_mem && (address - PIGFX_REG_SIZE) < PIGFX_UPPER) {
72 return (rtg_mem[address - PIGFX_REG_SIZE]);
75 return be16toh(*(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])));
77 case OP_TYPE_LONGWORD:
78 return be32toh(*(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])));
89 struct timespec diff(struct timespec start, struct timespec end)
92 if ((end.tv_nsec-start.tv_nsec)<0) {
93 temp.tv_sec = end.tv_sec-start.tv_sec-1;
94 temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
96 temp.tv_sec = end.tv_sec-start.tv_sec;
97 temp.tv_nsec = end.tv_nsec-start.tv_nsec;
102 #define CHKREG(a, b) case a: b = value; break;
104 void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
105 //printf("%s write to RTG: %.8X (%.8X)\n", op_type_names[mode], address, value);
106 if (address >= PIGFX_REG_SIZE) {
107 /*if ((address - PIGFX_REG_SIZE) < framebuffer_addr) {// || (address - PIGFX_REG_SIZE) > framebuffer_addr + ((rtg_display_width << rtg_display_format) * rtg_display_height)) {
108 printf("Write to RTG memory outside frame buffer %.8X (%.8X).\n", (address - PIGFX_REG_SIZE), framebuffer_addr);
110 if (rtg_mem && (address - PIGFX_REG_SIZE) < PIGFX_UPPER) {
113 rtg_mem[address - PIGFX_REG_SIZE] = value;
116 *(( uint16_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe16(value);
118 case OP_TYPE_LONGWORD:
119 *(( uint32_t *) (&rtg_mem[address - PIGFX_REG_SIZE])) = htobe32(value);
130 CHKREG(RTG_U81, rtg_u8[0]);
131 CHKREG(RTG_U82, rtg_u8[1]);
132 CHKREG(RTG_U83, rtg_u8[2]);
133 CHKREG(RTG_U84, rtg_u8[3]);
138 CHKREG(RTG_X1, rtg_x[0]);
139 CHKREG(RTG_X2, rtg_x[1]);
140 CHKREG(RTG_X3, rtg_x[2]);
141 CHKREG(RTG_X4, rtg_x[3]);
142 CHKREG(RTG_X5, rtg_x[4]);
143 CHKREG(RTG_Y1, rtg_y[0]);
144 CHKREG(RTG_Y2, rtg_y[1]);
145 CHKREG(RTG_Y3, rtg_y[2]);
146 CHKREG(RTG_Y4, rtg_y[3]);
147 CHKREG(RTG_Y5, rtg_y[4]);
148 CHKREG(RTG_U1, rtg_user[0]);
149 CHKREG(RTG_U2, rtg_user[1]);
150 CHKREG(RTG_FORMAT, rtg_format);
152 handle_rtg_command(value);
156 case OP_TYPE_LONGWORD:
159 rtg_address[0] = value;
160 rtg_address_adj[0] = value - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
163 rtg_address[1] = value;
164 rtg_address_adj[1] = value - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
166 CHKREG(RTG_ADDR3, rtg_address[2]);
167 CHKREG(RTG_ADDR4, rtg_address[3]);
168 CHKREG(RTG_RGB1, rtg_rgb[0]);
169 CHKREG(RTG_RGB2, rtg_rgb[1]);
178 #define gdebug(a) if (realtime_graphics_debug) { printf(a); m68k_end_timeslice(); cpu_emulation_running = 0; }
180 static void handle_rtg_command(uint32_t cmd) {
181 //printf("Handling RTG command %d (%.8X)\n", cmd, cmd);
184 rtg_display_format = rtg_format;
185 rtg_display_width = rtg_x[0];
186 rtg_display_height = rtg_y[0];
188 //rtg_pitch = rtg_display_width << rtg_format;
189 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
190 rtg_total_rows = rtg_y[1];
193 //rtg_pitch = rtg_display_width << rtg_format;
194 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
195 rtg_total_rows = rtg_y[1];
197 //printf("Set RTG mode:\n");
198 //printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
199 //printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
202 //printf("Command: SetPan.\n");
203 rtg_offset_x = rtg_x[1];
204 rtg_offset_y = rtg_y[1];
205 rtg_pitch = (rtg_x[0] << rtg_display_format);
206 framebuffer_addr = rtg_address[0] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
207 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
208 //printf("Set panning to $%.8X (%.8X)\n", framebuffer_addr, rtg_address[0]);
209 //printf("(Panned: $%.8X)\n", framebuffer_addr_adj);
210 //printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
211 printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
213 case RTGCMD_SETCLUT: {
214 //printf("Command: SetCLUT.\n");
215 //printf("Set palette entry %d to %d, %d, %d\n", rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
216 //printf("Set palette entry %d to 32-bit palette color: %.8X\n", rtg_u8[0], rtg_rgb[0]);
217 rtg_set_clut_entry(rtg_u8[0], rtg_rgb[0]);
220 case RTGCMD_SETDISPLAY:
221 //printf("RTG SetDisplay %s\n", (rtg_u8[1]) ? "enabled" : "disabled");
223 //printf("Command: SetDisplay.\n");
226 case RTGCMD_SETSWITCH:
227 //printf("RTG SetSwitch %s\n", ((rtg_x[0]) & 0x01) ? "enabled" : "disabled");
228 //printf("LAL: %.4X\n", rtg_x[0]);
229 if (display_enabled != ((rtg_x[0]) & 0x01)) {
230 display_enabled = ((rtg_x[0]) & 0x01);
231 if (display_enabled) {
235 rtg_shutdown_display();
238 case RTGCMD_FILLRECT:
239 if (rtg_u8[0] == 0xFF || rtg_format != RTGFMT_8BIT) {
240 rtg_fillrect_solid(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_rgb[0], rtg_x[2], rtg_format);
241 gdebug("FillRect Solid\n");
244 rtg_fillrect(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_rgb[0], rtg_x[2], rtg_format, rtg_u8[0]);
245 gdebug("FillRect Masked\n");
248 case RTGCMD_INVERTRECT:
249 rtg_invertrect(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_format, rtg_u8[0]);
250 gdebug("InvertRect\n");
252 case RTGCMD_BLITRECT:
253 if (rtg_u8[0] == 0xFF || rtg_format != RTGFMT_8BIT) {
254 rtg_blitrect_solid(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[3], rtg_format);
255 gdebug("BlitRect Solid\n");
258 rtg_blitrect(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[3], rtg_format, rtg_u8[0]);
259 gdebug("BlitRect Masked\n");
262 case RTGCMD_BLITRECT_NOMASK_COMPLETE:
263 rtg_blitrect_nomask_complete(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[3], rtg_x[4], rtg_address[0], rtg_address[1], rtg_format, rtg_u8[0]);
264 gdebug("BlitRectNoMaskComplete\n");
266 case RTGCMD_BLITPATTERN:
267 rtg_blitpattern(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_address[0], rtg_rgb[0], rtg_rgb[1], rtg_x[3], rtg_format, rtg_x[2], rtg_y[2], rtg_u8[0], rtg_u8[1], rtg_u8[2]);
268 gdebug("BlitPattern\n");
270 case RTGCMD_BLITTEMPLATE:
271 rtg_blittemplate(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_address[0], rtg_rgb[0], rtg_rgb[1], rtg_x[3], rtg_x[4], rtg_format, rtg_x[2], rtg_u8[0], rtg_u8[1]);
272 gdebug("BlitTemplate\n");
274 case RTGCMD_DRAWLINE:
275 if (rtg_u8[0] == 0xFF && rtg_y[2] == 0xFFFF)
276 rtg_drawline_solid(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_rgb[0], rtg_x[3], rtg_format);
278 rtg_drawline(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[4], rtg_rgb[0], rtg_rgb[1], rtg_x[3], rtg_format, rtg_u8[0], rtg_u8[1]);
279 gdebug("DrawLine\n");
282 rtg_p2c(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_u8[1], rtg_u8[2], rtg_u8[0], (rtg_user[0] >> 0x8), rtg_x[4], (uint8_t *)&rtg_mem[rtg_address_adj[1]]);
283 //rtg_p2c_broken(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_y[2], rtg_x[3], rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_user[0]);
284 gdebug("Planar2Chunky\n");