1 // SPDX-License-Identifier: MIT
7 #include "config_file/config_file.h"
9 #include "gpio/ps_protocol.h"
12 #include "platforms/amiga/rtg/irtg_structs.h"
15 extern uint32_t rtg_address[8];
16 extern uint32_t rtg_address_adj[8];
17 extern uint8_t *rtg_mem; // FIXME
18 extern uint16_t rtg_user[8];
19 extern uint16_t rtg_x[8], rtg_y[8];
20 extern uint16_t rtg_format;
22 extern uint32_t framebuffer_addr;
23 extern uint32_t framebuffer_addr_adj;
25 extern uint8_t realtime_graphics_debug;
27 void rtg_fillrect_solid(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color, uint16_t pitch, uint16_t format) {
28 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
31 for (int xs = 0; xs < w; xs++) {
32 dptr[xs] = color & 0xFF;
37 color = htobe16((color & 0xFFFF));
38 uint16_t *ptr = (uint16_t *)dptr;
39 for (int xs = 0; xs < w; xs++) {
45 color = htobe32(color);
46 uint32_t *ptr = (uint32_t *)dptr;
47 for (int xs = 0; xs < w; xs++) {
53 for (int ys = 1; ys < h; ys++) {
55 memcpy(dptr, (void *)(size_t)(dptr - pitch), (w << format));
59 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) {
60 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
62 for (int ys = 0; ys < h; ys++) {
63 for (int xs = 0; xs < w; xs++) {
64 SET_RTG_PIXEL_MASK(&dptr[xs << format], (color & 0xFF), format);
70 void rtg_invertrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t pitch, uint16_t format, uint8_t mask) {
72 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
73 for (int ys = 0; ys < h; ys++) {
76 for (int xs = 0; xs < w; xs++) {
82 for (int xs = 0; xs < w; xs++) {
83 ((uint16_t *)dptr)[xs] = ~((uint16_t *)dptr)[xs];
88 for (int xs = 0; xs < w; xs++) {
89 ((uint32_t *)dptr)[xs] = ~((uint32_t *)dptr)[xs];
98 void rtg_blitrect(uint16_t x, uint16_t y, uint16_t dx, uint16_t dy, uint16_t w, uint16_t h, uint16_t pitch, uint16_t format, uint8_t mask) {
100 uint8_t *sptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
101 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dx << format) + (dy * pitch)];
103 uint32_t xdir = 1, pitchstep = pitch;
107 sptr += ((h - 1) * pitch);
108 dptr += ((h - 1) * pitch);
114 for (int ys = 0; ys < h; ys++) {
116 for (int xs = 0; xs < w; xs++) {
117 SET_RTG_PIXEL_MASK(&dptr[xs], sptr[xs], format);
121 for (int xs = w - 1; xs >= x; xs--) {
122 SET_RTG_PIXEL_MASK(&dptr[xs], sptr[xs], format);
130 void rtg_blitrect_solid(uint16_t x, uint16_t y, uint16_t dx, uint16_t dy, uint16_t w, uint16_t h, uint16_t pitch, uint16_t format) {
131 uint8_t *sptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
132 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dx << format) + (dy * pitch)];
134 uint32_t xdir = 1, pitchstep = pitch;
138 sptr += ((h - 1) * pitch);
139 dptr += ((h - 1) * pitch);
145 for (int ys = 0; ys < h; ys++) {
147 memcpy(dptr, sptr, w << format);
149 memmove(dptr, sptr, w << format);
155 void rtg_blitrect_nomask_complete(uint16_t sx, uint16_t sy, uint16_t dx, uint16_t dy, uint16_t w, uint16_t h, uint16_t srcpitch, uint16_t dstpitch, uint32_t src_addr, uint32_t dst_addr, uint16_t format, uint8_t minterm) {
157 uint8_t *sptr = &rtg_mem[src_addr - (PIGFX_RTG_BASE + PIGFX_REG_SIZE) + (sx << format) + (sy * srcpitch)];
158 uint8_t *dptr = &rtg_mem[dst_addr - (PIGFX_RTG_BASE + PIGFX_REG_SIZE) + (dx << format) + (dy * dstpitch)];
160 uint32_t xdir = 1, src_pitchstep = srcpitch, dst_pitchstep = dstpitch;
161 uint8_t draw_mode = minterm;
162 uint32_t mask = 0xFF;
164 if (src_addr == dst_addr) {
166 src_pitchstep = -srcpitch;
167 sptr += ((h - 1) * srcpitch);
168 dst_pitchstep = -dstpitch;
169 dptr += ((h - 1) * dstpitch);
176 if (format == RTGFMT_RBG565)
178 if (format == RTGFMT_RGB32)
181 if (minterm == MINTERM_SRC) {
182 for (int ys = 0; ys < h; ys++) {
184 memcpy(dptr, sptr, w << format);
186 memmove(dptr, sptr, w << format);
187 sptr += src_pitchstep;
188 dptr += dst_pitchstep;
192 for (int ys = 0; ys < h; ys++) {
194 for (int xs = 0; xs < w; xs++) {
197 HANDLE_MINTERM_PIXEL(sptr[xs], dptr[xs], format);
200 HANDLE_MINTERM_PIXEL(((uint16_t *)sptr)[xs], ((uint16_t *)dptr)[xs], format);
203 HANDLE_MINTERM_PIXEL(((uint32_t *)sptr)[xs], ((uint32_t *)dptr)[xs], format);
209 for (int xs = w - 1; xs >= sx; xs--) {
212 HANDLE_MINTERM_PIXEL(sptr[xs], dptr[xs], format);
215 HANDLE_MINTERM_PIXEL(((uint16_t *)sptr)[xs], ((uint16_t *)dptr)[xs], format);
218 HANDLE_MINTERM_PIXEL(((uint32_t *)sptr)[xs], ((uint32_t *)dptr)[xs], format);
223 sptr += src_pitchstep;
224 dptr += src_pitchstep;
229 extern struct emulator_config *cfg;
231 void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t src_addr, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t t_pitch, uint16_t format, uint16_t offset_x, uint8_t mask, uint8_t draw_mode) {
232 uint8_t *dptr = &rtg_mem[rtg_address_adj[1] + (x << format) + (y * pitch)];
233 uint8_t *sptr = NULL;
234 uint8_t cur_bit = 0, base_bit = 0, cur_byte = 0;
235 uint8_t invert = (draw_mode & DRAWMODE_INVERSVID);
240 tmpl_x = offset_x / 8;
241 cur_bit = base_bit = (0x80 >> (offset_x % 8));
243 if (realtime_graphics_debug) {
244 printf("DEBUG: BlitTemplate - %d, %d (%dx%d)\n", x, y, w, h);
245 printf("Src: %.8X\n", src_addr);
246 printf("Dest: %.8X (%.8X)\n", rtg_address[1], rtg_address_adj[1]);
247 printf("pitch: %d t_pitch: %d format: %d\n", pitch, t_pitch, format);
248 printf("offset_x: %d mask: %.2X draw_mode: %d\n", offset_x, mask, draw_mode);
251 uint32_t fg_color[3] = {
253 htobe16((fgcol & 0xFFFF)),
256 uint32_t bg_color[3] = {
258 htobe16((bgcol & 0xFFFF)),
262 sptr = get_mapped_data_pointer_by_address(cfg, src_addr);
264 if (realtime_graphics_debug) {
265 printf("BlitTemplate data NOT available in mapped range, source address: $%.8X\n", src_addr);
268 if (realtime_graphics_debug) {
269 printf("BlitTemplate data available in mapped range at $%.8X\n", src_addr);
275 for (uint16_t ys = 0; ys < h; ys++) {
276 for (int xs = 0; xs < w; xs++) {
278 if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
279 if (mask == 0xFF || format != RTGFMT_8BIT) {
280 SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format);
283 SET_RTG_PIXELS_MASK(&dptr[xs], fg_color[format], format);
288 while (cur_bit > 0 && xs < w) {
289 if (cur_byte & cur_bit) {
290 if (mask == 0xFF || format != RTGFMT_8BIT) {
291 SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
294 SET_RTG_PIXEL_MASK(&dptr[xs], fg_color[format], format);
308 for (uint16_t ys = 0; ys < h; ys++) {
309 for (int xs = 0; xs < w; xs++) {
311 if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
312 if (mask == 0xFF || format != RTGFMT_8BIT) {
313 SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format);
316 SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
322 while (cur_bit > 0 && xs < w) {
323 if (mask == 0xFF || format != RTGFMT_8BIT) {
324 SET_RTG_PIXEL(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
327 SET_RTG_PIXEL_MASK(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
339 case DRAWMODE_COMPLEMENT:
340 for (uint16_t ys = 0; ys < h; ys++) {
341 for (int xs = 0; xs < w; xs++) {
343 if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
344 INVERT_RTG_PIXELS(&dptr[xs << format], format)
348 while (cur_bit > 0 && xs < w) {
349 if (cur_byte & cur_bit) {
350 INVERT_RTG_PIXEL(&dptr[xs << format], format)
365 void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t src_addr_, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t format, uint16_t offset_x, uint16_t offset_y, uint8_t mask, uint8_t draw_mode, uint8_t loop_rows) {
368 uint8_t *dptr = &rtg_mem[rtg_address_adj[1] + (x << format) + (y * pitch)];
369 uint8_t *sptr = NULL, *sptr_base = NULL;
370 uint8_t cur_bit = 0, base_bit = 0, cur_byte = 0;
371 uint8_t invert = (draw_mode & DRAWMODE_INVERSVID);
373 uint32_t src_addr = src_addr_;
374 uint32_t src_addr_base = src_addr;
378 tmpl_x = (offset_x / 8) % 2;
379 cur_bit = base_bit = (0x80 >> (offset_x % 8));
381 uint32_t fg_color[3] = {
383 htobe16((fgcol & 0xFFFF)),
386 uint32_t bg_color[3] = {
388 htobe16((bgcol & 0xFFFF)),
393 sptr = get_mapped_data_pointer_by_address(cfg, src_addr);
395 if (realtime_graphics_debug) {
396 printf("BlitPattern data NOT available in mapped range, source address: $%.8X\n", src_addr);
397 src_addr += (offset_y % loop_rows) * 2;
400 if (realtime_graphics_debug) {
401 printf("BlitPattern data available in mapped range at $%.8X\n", src_addr);
404 sptr += (offset_y % loop_rows) * 2;
409 for (uint16_t ys = 0; ys < h; ys++) {
410 for (int xs = 0; xs < w; xs++) {
412 if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
413 if (mask == 0xFF || format != RTGFMT_8BIT) {
414 SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format);
417 SET_RTG_PIXELS_MASK(&dptr[xs], fg_color[format], format);
422 while (cur_bit > 0 && xs < w) {
423 if (cur_byte & cur_bit) {
424 if (mask == 0xFF || format != RTGFMT_8BIT) {
425 SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
428 SET_RTG_PIXEL_MASK(&dptr[xs], fg_color[format], format);
442 for (uint16_t ys = 0; ys < h; ys++) {
443 for (int xs = 0; xs < w; xs++) {
445 if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
446 if (mask == 0xFF || format != RTGFMT_8BIT) {
447 SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format);
450 SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
456 while (cur_bit > 0 && xs < w) {
457 if (mask == 0xFF || format != RTGFMT_8BIT) {
458 SET_RTG_PIXEL(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
461 SET_RTG_PIXEL_MASK(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
473 case DRAWMODE_COMPLEMENT:
474 for (uint16_t ys = 0; ys < h; ys++) {
475 for (int xs = 0; xs < w; xs++) {
477 if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
478 INVERT_RTG_PIXELS(&dptr[xs << format], format)
482 while (cur_bit > 0 && xs < w) {
483 if (cur_byte & cur_bit) {
484 INVERT_RTG_PIXEL(&dptr[xs << format], format)
499 void rtg_drawline_solid(int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint16_t len, uint32_t fgcol, uint16_t pitch, uint16_t format) {
500 int16_t x1 = x1_, y1 = y1_;
501 int16_t x2 = x1_ + x2_, y2 = y1 + y2_;
503 uint32_t fg_color[3] = {
505 htobe16((fgcol & 0xFFFF)),
509 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (y1 * pitch)];
511 int32_t line_step = pitch;
514 int16_t dx, dy, dx_abs, dy_abs, ix, iy, x = x1;
528 SET_RTG_PIXEL(&dptr[x << format], fg_color[format], format);
530 if (dx_abs >= dy_abs) {
531 if (!len) len = dx_abs;
532 for (uint16_t i = 0; i < len; i++) {
540 SET_RTG_PIXEL(&dptr[x << format], fg_color[format], format);
544 if (!len) len = dy_abs;
545 for (uint16_t i = 0; i < len; i++) {
553 SET_RTG_PIXEL(&dptr[x << format], fg_color[format], format);
558 #define DRAW_LINE_PIXEL \
559 if (pattern & cur_bit) { \
560 if (invert) { INVERT_RTG_PIXEL(&dptr[x << format], format) } \
562 if (mask == 0xFF || format != RTGFMT_8BIT) { SET_RTG_PIXEL(&dptr[x << format], fg_color[format], format); } \
563 else { SET_RTG_PIXEL_MASK(&dptr[x << format], fg_color[format], format); } \
566 else if (draw_mode == DRAWMODE_JAM2) { \
567 if (invert) { INVERT_RTG_PIXEL(&dptr[x << format], format) } \
569 if (mask == 0xFF || format != RTGFMT_8BIT) { SET_RTG_PIXEL(&dptr[x << format], bg_color[format], format); } \
570 else { SET_RTG_PIXEL_MASK(&dptr[x << format], bg_color[format], format); } \
573 if ((cur_bit >>= 1) == 0) \
576 void rtg_drawline (int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint16_t len, uint16_t pattern, uint16_t pattern_offset, uint32_t fgcol, uint32_t bgcol, uint16_t pitch, uint16_t format, uint8_t mask, uint8_t draw_mode) {
577 if (pattern_offset) {}
579 int16_t x1 = x1_, y1 = y1_;
580 int16_t x2 = x1_ + x2_, y2 = y1 + y2_;
581 uint16_t cur_bit = 0x8000;
582 //uint32_t color_mask = 0xFFFF0000;
585 uint32_t fg_color[3] = {
587 htobe16((fgcol & 0xFFFF)),
590 uint32_t bg_color[3] = {
592 htobe16((bgcol & 0xFFFF)),
596 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (y1 * pitch)];
598 int32_t line_step = pitch;
601 int16_t dx, dy, dx_abs, dy_abs, ix, iy, x = x1;
615 if (draw_mode & DRAWMODE_INVERSVID)
617 if (draw_mode & DRAWMODE_COMPLEMENT) {
624 if (dx_abs >= dy_abs) {
625 if (!len) len = dx_abs;
626 for (uint16_t i = 0; i < len; i++) {
638 if (!len) len = dy_abs;
639 for (uint16_t i = 0; i < len; i++) {
652 // This is slow and somewhat useless, needs a rewrite to ps_read_16 copy the bit plane data
653 // similarly to what the code in the RTG driver does. Disabled for now.
654 void rtg_p2c_ex(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t minterm, struct BitMap *bm, uint8_t mask, uint16_t dst_pitch, uint16_t src_pitch) {
655 uint16_t pitch = dst_pitch;
656 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
657 uint8_t draw_mode = minterm;
659 uint8_t cur_bit, base_bit, base_byte;
660 uint16_t cur_byte = 0, u8_fg = 0, u8_tmp = 0;
662 cur_bit = base_bit = (0x80 >> (sx % 8));
663 cur_byte = base_byte = ((sx / 8) % src_pitch);
665 uint8_t *plane_ptr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
666 uint32_t plane_addr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
668 for (int i = 0; i < bm->Depth; i++) {
669 uint32_t plane_address = be32toh(bm->_p_Planes[i]);
670 if (plane_address != 0 && plane_address != 0xFFFFFFFF) {
671 plane_ptr[i] = get_mapped_data_pointer_by_address(cfg, be32toh(bm->_p_Planes[i]));
673 plane_addr[i] = be32toh(bm->_p_Planes[i]);
674 if (plane_addr[i] != 0) plane_addr[i] += (sy * src_pitch);
676 plane_ptr[i] += (sy * src_pitch);
679 plane_addr[i] = plane_address;
683 for (int16_t line_y = 0; line_y < h; line_y++) {
684 for (int16_t x = dx; x < dx + w; x++) {
686 if (minterm & 0x01) {
687 for (int i = 0; i < bm->Depth; i++) {
689 if (~plane_ptr[i][cur_byte] & cur_bit) u8_fg |= (1 << i);
691 if (plane_addr[i] == 0xFFFFFFFF) u8_fg |= (1 << i);
692 else if (plane_addr[i] != 0) {
693 u8_tmp = (uint8_t)ps_read_8(plane_addr[i] + cur_byte);
694 if (~u8_tmp & cur_bit) u8_fg |= (1 << i);
699 for (int i = 0; i < bm->Depth; i++) {
701 if (plane_ptr[i][cur_byte] & cur_bit) u8_fg |= (1 << i);
703 if (plane_addr[i] == 0xFFFFFFFF) u8_fg |= (1 << i);
704 else if (plane_addr[i] != 0) {
705 u8_tmp = (uint8_t)ps_read_8(plane_addr[i] + cur_byte);
706 if (u8_tmp & cur_bit) u8_fg |= (1 << i);
712 if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
717 HANDLE_MINTERM_PIXEL(u8_fg, dptr[x], RTGFMT_8BIT);
720 if ((cur_bit >>= 1) == 0) {
723 cur_byte %= src_pitch;
727 for (int i = 0; i < bm->Depth; i++) {
728 if (plane_ptr[i] && (uint32_t)plane_ptr[i] != 0xFFFFFFFF)
729 plane_ptr[i] += src_pitch;
730 if (plane_addr[i] && plane_addr[i] != 0xFFFFFFFF)
731 plane_addr[i] += src_pitch;
734 cur_byte = base_byte;
738 void rtg_p2c (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src) {
739 uint16_t pitch = rtg_x[3];
740 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
742 uint8_t cur_bit, base_bit, base_byte;
743 uint16_t cur_byte = 0, u8_fg = 0;
744 //uint32_t color_mask = 0xFFFFFFFF;
746 uint32_t plane_size = src_line_pitch * h;
747 uint8_t *bmp_data = bmp_data_src;
749 cur_bit = base_bit = (0x80 >> (sx % 8));
750 cur_byte = base_byte = ((sx / 8) % src_line_pitch);
752 if (realtime_graphics_debug) {
753 printf("P2C: %d,%d - %d,%d (%dx%d) %d, %.2X\n", sx, sy, dx, dy, w, h, planes, layer_mask);
754 printf("Mask: %.2X Minterm: %.2X\n", mask, draw_mode);
755 printf("Pitch: %d Src Pitch: %d (!!!: %.4X)\n", pitch, src_line_pitch, rtg_user[0]);
756 printf("Curbyte: %d Curbit: %d\n", cur_byte, cur_bit);
757 printf("Plane size: %d Total size: %d (%X)\n", plane_size, plane_size * planes, plane_size * planes);
758 printf("Source: %.8X - %.8X\n", rtg_address[1], rtg_address_adj[1]);
759 printf("Target: %.8X - %.8X\n", rtg_address[0], rtg_address_adj[0]);
762 printf("Grabbing data from RTG memory.\nData:\n");
763 for (int i = 0; i < h; i++) {
764 for (int k = 0; k < planes; k++) {
765 for (int j = 0; j < src_line_pitch; j++) {
766 printf("%.2X", bmp_data_src[j + (i * src_line_pitch) + (plane_size * k)]);
774 for (int16_t line_y = 0; line_y < h; line_y++) {
775 for (int16_t x = dx; x < dx + w; x++) {
777 if (draw_mode & 0x01) {
778 DECODE_INVERTED_PLANAR_PIXEL(u8_fg)
781 DECODE_PLANAR_PIXEL(u8_fg)
784 if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
789 HANDLE_MINTERM_PIXEL(u8_fg, dptr[x], rtg_format);
792 if ((cur_bit >>= 1) == 0) {
795 cur_byte %= src_line_pitch;
799 if ((line_y + sy + 1) % h)
800 bmp_data += src_line_pitch;
802 bmp_data = bmp_data_src;
804 cur_byte = base_byte;
808 void rtg_p2d (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src) {
809 uint16_t pitch = rtg_x[3];
810 uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
812 uint8_t cur_bit, base_bit, base_byte;
813 uint16_t cur_byte = 0, u8_fg = 0;
814 //uint32_t color_mask = 0xFFFFFFFF;
816 uint32_t plane_size = src_line_pitch * h;
817 uint8_t *bmp_data = bmp_data_src;
819 cur_bit = base_bit = (0x80 >> (sx % 8));
820 cur_byte = base_byte = ((sx / 8) % src_line_pitch);
822 if (realtime_graphics_debug) {
823 printf("P2D: %d,%d - %d,%d (%dx%d) %d, %.2X\n", sx, sy, dx, dy, w, h, planes, layer_mask);
824 printf("Mask: %.2X Minterm: %.2X\n", mask, draw_mode);
825 printf("Pitch: %d Src Pitch: %d (!!!: %.4X)\n", pitch, src_line_pitch, rtg_user[0]);
826 printf("Curbyte: %d Curbit: %d\n", cur_byte, cur_bit);
827 printf("Plane size: %d Total size: %d (%X)\n", plane_size, plane_size * planes, plane_size * planes);
828 printf("Source: %.8X - %.8X\n", rtg_address[1], rtg_address_adj[1]);
829 printf("Target: %.8X - %.8X\n", rtg_address[0], rtg_address_adj[0]);
832 printf("Grabbing data from RTG memory.\nData:\n");
833 for (int i = 0; i < h; i++) {
834 for (int k = 0; k < planes; k++) {
835 for (int j = 0; j < src_line_pitch; j++) {
836 printf("%.2X", bmp_data_src[j + (i * src_line_pitch) + (plane_size * k)]);
844 uint32_t *clut = (uint32_t *)bmp_data_src;
845 bmp_data += (256 * 4);
846 bmp_data_src += (256 * 4);
848 for (int16_t line_y = 0; line_y < h; line_y++) {
849 for (int16_t x = dx; x < dx + w; x++) {
851 if (draw_mode & 0x01) {
852 DECODE_INVERTED_PLANAR_PIXEL(u8_fg)
855 DECODE_PLANAR_PIXEL(u8_fg)
858 uint32_t fg_color = clut[u8_fg];
860 if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
861 switch (rtg_format) {
863 ((uint16_t *)dptr)[x] = (fg_color >> 16);
866 ((uint32_t *)dptr)[x] = fg_color;
873 if ((cur_bit >>= 1) == 0) {
876 cur_byte %= src_line_pitch;
880 if ((line_y + sy + 1) % h)
881 bmp_data += src_line_pitch;
883 bmp_data = bmp_data_src;
885 cur_byte = base_byte;