+ uint32_t plane_size = src_line_pitch * h;
+ uint8_t *bmp_data = bmp_data_src;
+
+ cur_bit = base_bit = (0x80 >> (sx % 8));
+ cur_byte = base_byte = ((sx / 8) % src_line_pitch);
+
+ if (realtime_graphics_debug) {
+ printf("P2D: %d,%d - %d,%d (%dx%d) %d, %.2X\n", sx, sy, dx, dy, w, h, planes, layer_mask);
+ printf("Mask: %.2X Minterm: %.2X\n", mask, draw_mode);
+ printf("Pitch: %d Src Pitch: %d (!!!: %.4X)\n", pitch, src_line_pitch, rtg_user[0]);
+ printf("Curbyte: %d Curbit: %d\n", cur_byte, cur_bit);
+ printf("Plane size: %d Total size: %d (%X)\n", plane_size, plane_size * planes, plane_size * planes);
+ printf("Source: %.8X - %.8X\n", rtg_address[1], rtg_address_adj[1]);
+ printf("Target: %.8X - %.8X\n", rtg_address[0], rtg_address_adj[0]);
+ fflush(stdout);
+
+ printf("Grabbing data from RTG memory.\nData:\n");
+ for (int i = 0; i < h; i++) {
+ for (int k = 0; k < planes; k++) {
+ for (int j = 0; j < src_line_pitch; j++) {
+ printf("%.2X", bmp_data_src[j + (i * src_line_pitch) + (plane_size * k)]);
+ }
+ printf(" ");
+ }
+ printf("\n");
+ }
+ }
+
+ uint32_t *clut = (uint32_t *)bmp_data_src;
+ bmp_data += (256 * 4);
+ bmp_data_src += (256 * 4);
+
+ for (int16_t line_y = 0; line_y < h; line_y++) {
+ for (int16_t x = dx; x < dx + w; x++) {
+ u8_fg = 0;
+ if (draw_mode & 0x01) {
+ DECODE_INVERTED_PLANAR_PIXEL(u8_fg)
+ }
+ else {
+ DECODE_PLANAR_PIXEL(u8_fg)
+ }
+
+ uint32_t fg_color = clut[u8_fg];
+
+ if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
+ switch (rtg_display_format) {
+ case RTGFMT_RBG565:
+ ((uint16_t *)dptr)[x] = (fg_color >> 16);
+ break;
+ case RTGFMT_RGB32:
+ ((uint32_t *)dptr)[x] = fg_color;
+ break;
+ }
+ goto skip;
+ }
+
+ skip:;
+ if ((cur_bit >>= 1) == 0) {
+ cur_bit = 0x80;
+ cur_byte++;
+ cur_byte %= src_line_pitch;
+ }