]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/rtg/rtg.c
Remove some duplicate RTG debug output
[pistorm] / platforms / amiga / rtg / rtg.c
index 86aa550f760cd2cb596cafe91bff29fa16ab4310..8ef6a017aeed1ef9304353520c2f4e71f073b804 100644 (file)
@@ -1,19 +1,21 @@
+// SPDX-License-Identifier: MIT
+
 #include <stdint.h>
 #include <endian.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include "config_file/config_file.h"
 #include "rtg.h"
-#include "../../../config_file/config_file.h"
 
-static uint8_t rtg_u8[4];
-static uint16_t rtg_x[8], rtg_y[8];
-static uint16_t rtg_user[8];
-static uint16_t rtg_format;
-static uint32_t rtg_address[2];
-static uint32_t rtg_address_adj[2];
-static uint32_t rtg_rgb[2];
+uint8_t rtg_u8[4];
+uint16_t rtg_x[8], rtg_y[8];
+uint16_t rtg_user[8];
+uint16_t rtg_format;
+uint32_t rtg_address[8];
+uint32_t rtg_address_adj[8];
+uint32_t rtg_rgb[8];
 
 static uint8_t display_enabled = 0xFF;
 
@@ -28,8 +30,14 @@ uint32_t framebuffer_addr = 0;
 uint32_t framebuffer_addr_adj = 0;
 
 static void handle_rtg_command(uint32_t cmd);
-static struct timespec f1, f2;
+//static struct timespec f1, f2;
+
+uint8_t realtime_graphics_debug = 0;
+extern int cpu_emulation_running;
+extern struct emulator_config *cfg;
+extern uint8_t rtg_on;
 
+/*
 static const char *op_type_names[OP_TYPE_NUM] = {
     "BYTE",
     "WORD",
@@ -43,24 +51,44 @@ static const char *rtg_format_names[RTGFMT_NUM] = {
     "32BPP RGB (RGBA)",
     "15BPP RGB (555)",
 };
-
-int init_rtg_data() {
-    rtg_mem = calloc(1, 32 * SIZE_MEGA);
+*/
+int init_rtg_data(struct emulator_config *cfg_) {
+    rtg_mem = calloc(1, 40 * SIZE_MEGA);
     if (!rtg_mem) {
         printf("Failed to allocate RTG video memory.\n");
         return 0;
     }
 
+    m68k_add_ram_range(PIGFX_RTG_BASE + PIGFX_REG_SIZE, 40 * SIZE_MEGA - PIGFX_REG_SIZE, rtg_mem);
+    add_mapping(cfg_, MAPTYPE_RAM_NOALLOC, PIGFX_RTG_BASE + PIGFX_REG_SIZE, 40 * SIZE_MEGA - PIGFX_REG_SIZE, -1, (char *)rtg_mem, "rtg_mem");
     return 1;
 }
 
-extern uint8_t busy, rtg_on;
-void rtg_update_screen();
+void shutdown_rtg() {
+    printf("[RTG] Shutting down RTG.\n");
+    if (rtg_on) {
+        rtg_on = 0;
+    }
+    if (rtg_mem) {
+        
+        free(rtg_mem);
+        rtg_mem = NULL;
+    }
+}
+
+//void rtg_update_screen();
+
+unsigned int rtg_get_fb() {
+    return PIGFX_RTG_BASE + PIGFX_REG_SIZE + framebuffer_addr_adj;
+}
 
 unsigned int rtg_read(uint32_t address, uint8_t mode) {
     //printf("%s read from RTG: %.8X\n", op_type_names[mode], address);
+    if (address == RTG_COMMAND) {
+        return 0xFFCF;
+    }
     if (address >= PIGFX_REG_SIZE) {
-        if (rtg_mem) {
+        if (rtg_mem && (address - PIGFX_REG_SIZE) < PIGFX_UPPER) {
             switch (mode) {
                 case OP_TYPE_BYTE:
                     return (rtg_mem[address - PIGFX_REG_SIZE]);
@@ -101,7 +129,7 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
         /*if ((address - PIGFX_REG_SIZE) < framebuffer_addr) {// || (address - PIGFX_REG_SIZE) > framebuffer_addr + ((rtg_display_width << rtg_display_format) * rtg_display_height)) {
             printf("Write to RTG memory outside frame buffer %.8X (%.8X).\n", (address - PIGFX_REG_SIZE), framebuffer_addr);
         }*/
-        if (rtg_mem) {
+        if (rtg_mem && (address - PIGFX_REG_SIZE) < PIGFX_UPPER) {
             switch (mode) {
                 case OP_TYPE_BYTE:
                     rtg_mem[address - PIGFX_REG_SIZE] = value;
@@ -157,6 +185,8 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
                         rtg_address[1] = value;
                         rtg_address_adj[1] = value - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
                         break;
+                    CHKREG(RTG_ADDR3, rtg_address[2]);
+                    CHKREG(RTG_ADDR4, rtg_address[3]);
                     CHKREG(RTG_RGB1, rtg_rgb[0]);
                     CHKREG(RTG_RGB2, rtg_rgb[1]);
                 }
@@ -167,8 +197,10 @@ void rtg_write(uint32_t address, uint32_t value, uint8_t mode) {
     return;
 }
 
+#define gdebug(a) if (realtime_graphics_debug) { printf(a); m68k_end_timeslice(); cpu_emulation_running = 0; }
+
 static void handle_rtg_command(uint32_t cmd) {
-    //printf("Handling RTG command %d (%.8X)\n", cmd, cmd);
+  //printf("Handling RTG command %d (%.8X)\n", cmd, cmd);
     switch (cmd) {
         case RTGCMD_SETGC:
             rtg_display_format = rtg_format;
@@ -184,9 +216,9 @@ static void handle_rtg_command(uint32_t cmd) {
                 framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
                 rtg_total_rows = rtg_y[1];
             }
-            printf("Set RTG mode:\n");
-            printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
-            printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
+            //printf("Set RTG mode:\n");
+            //printf("%dx%d pixels\n", rtg_display_width, rtg_display_height);
+            //printf("Pixel format: %s\n", rtg_format_names[rtg_display_format]);
             break;
         case RTGCMD_SETPAN:
             //printf("Command: SetPan.\n");
@@ -195,10 +227,10 @@ static void handle_rtg_command(uint32_t cmd) {
             rtg_pitch = (rtg_x[0] << rtg_display_format);
             framebuffer_addr = rtg_address[0] - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
             framebuffer_addr_adj = framebuffer_addr + (rtg_offset_x << rtg_display_format) + (rtg_offset_y * rtg_pitch);
-            printf("Set panning to $%.8X (%.8X)\n", framebuffer_addr, rtg_address[0]);
-            printf("(Panned: $%.8X)\n", framebuffer_addr_adj);
-            printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
-            printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
+            //printf("Set panning to $%.8X (%.8X)\n", framebuffer_addr, rtg_address[0]);
+            //printf("(Panned: $%.8X)\n", framebuffer_addr_adj);
+            //printf("Offset X/Y: %d/%d\n", rtg_offset_x, rtg_offset_y);
+            //printf("Pitch: %d (%d bytes)\n", rtg_x[0], rtg_pitch);
             break;
         case RTGCMD_SETCLUT: {
             //printf("Command: SetCLUT.\n");
@@ -226,381 +258,77 @@ static void handle_rtg_command(uint32_t cmd) {
             }
             break;
         case RTGCMD_FILLRECT:
-            rtg_fillrect(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_rgb[0], rtg_x[2], rtg_format, 0xFF);
+            if (rtg_u8[0] == 0xFF || rtg_format != RTGFMT_8BIT) {
+                rtg_fillrect_solid(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_rgb[0], rtg_x[2], rtg_format);
+                gdebug("FillRect Solid\n");
+            }
+            else {
+                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]);
+                gdebug("FillRect Masked\n");
+            }
+            break;
+        case RTGCMD_INVERTRECT:
+            rtg_invertrect(rtg_x[0], rtg_y[0], rtg_x[1], rtg_y[1], rtg_x[2], rtg_format, rtg_u8[0]);
+            gdebug("InvertRect\n");
             break;
         case RTGCMD_BLITRECT:
-            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, 0xFF);
+            if (rtg_u8[0] == 0xFF || rtg_format != RTGFMT_8BIT) {
+                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);
+                gdebug("BlitRect Solid\n");
+            }
+            else {
+                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]);
+                gdebug("BlitRect Masked\n");
+            }
             break;
         case RTGCMD_BLITRECT_NOMASK_COMPLETE:
-            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_display_format, rtg_u8[0]);
+            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]);
+            gdebug("BlitRectNoMaskComplete\n");
             break;
         case RTGCMD_BLITPATTERN:
-            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_display_format, rtg_x[2], rtg_y[2], rtg_u8[0], rtg_u8[1], rtg_u8[2]);
+            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]);
+            gdebug("BlitPattern\n");
             return;
         case RTGCMD_BLITTEMPLATE:
-            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_display_format, rtg_x[2], rtg_u8[0], rtg_u8[1]);
+            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]);
+            gdebug("BlitTemplate\n");
             break;
-    }
-}
-
-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) {
-    if (mask) {}
-    uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
-    //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);
-    //printf("%.8X - %.8X (%p) (%p)\n", framebuffer_addr, rtg_address_adj[0], rtg_mem, dptr);
-    switch(format) {
-        case RTGFMT_8BIT: {
-            //printf("Incoming 8-bit color: %.8X\n", color);
-            for (int xs = 0; xs < w; xs++) {
-                dptr[xs] = color & 0xFF;
-            }
+        case RTGCMD_DRAWLINE:
+            if (rtg_u8[0] == 0xFF && rtg_y[2] == 0xFFFF)
+                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);
+            else
+                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]);
+            gdebug("DrawLine\n");
             break;
-        }
-        case RTGFMT_RBG565: {
-            //printf("Incoming raw 16-bit color: %.8X\n", htobe32(color));
-            color = htobe16((color & 0xFFFF));
-            //printf("Incoming 16-bit color: %.8X\n", color);
-            uint16_t *ptr = (uint16_t *)dptr;
-            for (int xs = 0; xs < w; xs++) {
-                ptr[xs] = color;
-            }
+        case RTGCMD_P2C:
+            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]]);
+            gdebug("Planar2Chunky\n");
             break;
-        }
-        case RTGFMT_RGB32: {
-            color = htobe32(color);
-            //printf("Incoming 32-bit color: %.8X\n", color);
-            uint32_t *ptr = (uint32_t *)dptr;
-            for (int xs = 0; xs < w; xs++) {
-                ptr[xs] = color;
-            }
+        case RTGCMD_P2D:
+            rtg_p2d(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]]);
+            gdebug("Planar2Direct\n");
+            break;
+        case RTGCMD_SETSPRITE:
+            rtg_enable_mouse_cursor();
+            gdebug("SetSprite\n");
+            break;
+        case RTGCMD_SETSPRITECOLOR:
+            rtg_set_cursor_clut_entry(rtg_u8[0], rtg_u8[1], rtg_u8[2], rtg_u8[3]);
+            gdebug("SetSpriteColor\n");
+            break;
+        case RTGCMD_SETSPRITEPOS:
+            rtg_set_mouse_cursor_pos((int16_t)rtg_x[0], (int16_t)rtg_y[0]);
+            gdebug("SetSpritePos\n");
+            break;
+        case RTGCMD_SETSPRITEIMAGE:
+            rtg_set_mouse_cursor_image(&rtg_mem[rtg_address_adj[1]], rtg_u8[0], rtg_u8[1]);
+            gdebug("SetSpriteImage\n");
+            break;
+        case RTGCMD_DEBUGME:
+            printf ("[RTG] DebugMe!\n");
+            break;
+        default:
+            printf("[!!!RTG] Unknown/unhandled RTG command %d ($%.4X)\n", cmd, cmd);
             break;
-        }
-    }
-    for (int ys = 1; ys < h; ys++) {
-        dptr += pitch;
-        memcpy(dptr, (void *)(size_t)(dptr - pitch), (w << format));
-    }
-    //printf("FillRect done.\n");
-}
-
-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) {
-    if (mask) {}
-    //printf("BlitRect: %d,%d to %d,%d (%dx%d) p:%d dp: %d\n", x, y, dx, dy, w, h, pitch, rtg_pitch);
-    uint8_t *sptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
-    uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dx << format) + (dy * pitch)];
-
-    uint32_t xdir = 1, pitchstep = pitch;
-
-    if (y < dy) {
-        pitchstep = -pitch;
-        sptr += ((h - 1) * pitch);
-        dptr += ((h - 1) * pitch);
-    }
-    if (x < dx) {
-        xdir = 0;
-    }
-
-    for (int ys = 0; ys < h; ys++) {
-        if (xdir)
-            memcpy(dptr, sptr, w << format);
-        else
-            memmove(dptr, sptr, w << format);
-        sptr += pitchstep;
-        dptr += pitchstep;
-    }
-}
-
-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) {
-    if (minterm) {}
-    //printf("BlitRectNoMaskComplete\n");
-    uint8_t *sptr = &rtg_mem[src_addr - (PIGFX_RTG_BASE + PIGFX_REG_SIZE) + (sx << format) + (sy * srcpitch)];
-    uint8_t *dptr = &rtg_mem[dst_addr - (PIGFX_RTG_BASE + PIGFX_REG_SIZE) + (dx << format) + (dy * dstpitch)];
-
-    uint32_t xdir = 1, src_pitchstep = srcpitch, dst_pitchstep = dstpitch;
-
-    if (src_addr == dst_addr) {
-        if (sy < dy) {
-            src_pitchstep = -srcpitch;
-            sptr += ((h - 1) * srcpitch);
-            dst_pitchstep = -dstpitch;
-            dptr += ((h - 1) * dstpitch);
-        }
-        if (sx < dx) {
-            xdir = 0;
-        }
-    }
-
-    for (int ys = 0; ys < h; ys++) {
-        if (xdir)
-            memcpy(dptr, sptr, w << format);
-        else
-            memmove(dptr, sptr, w << format);
-        sptr += src_pitchstep;
-        dptr += dst_pitchstep;
-    }
-}
-
-extern struct emulator_config *cfg;
-
-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) {
-    if (mask) {}
-    //printf("BlitTemplate: %d,%d (%dx%d) @%.8X p:%d dp: %d DM: %d Format: %d\n", x, y, w, h, src_addr, pitch, t_pitch, draw_mode & 0x03, format);
-    //printf("FBA: %.8x\n", framebuffer_addr);
-
-    uint8_t *dptr = &rtg_mem[rtg_address_adj[1] + (x << format) + (y * pitch)];
-    uint8_t *sptr = NULL;
-    uint8_t cur_bit = 0, base_bit = 0, cur_byte = 0;
-    uint8_t invert = (draw_mode & DRAWMODE_INVERSVID);
-    uint16_t tmpl_x = 0;
-
-    draw_mode &= 0x03;
-
-       tmpl_x = offset_x / 8;
-    cur_bit = base_bit = (0x80 >> (offset_x % 8));
-
-    uint32_t fg_color[3] = {
-        (fgcol & 0xFF),
-        htobe16((fgcol & 0xFFFF)),
-        htobe32(fgcol),
-    };
-    uint32_t bg_color[3] = {
-        (bgcol & 0xFF),
-        htobe16((bgcol & 0xFFFF)),
-        htobe32(bgcol),
-    };
-
-    if (src_addr >= PIGFX_RTG_BASE)
-        sptr = &rtg_mem[src_addr - PIGFX_RTG_BASE];
-    else {
-        int i = get_mapped_item_by_address(cfg, src_addr);
-        if (i != -1) {
-            //printf("Grabbing data from mapped range %d at offset %ld.\n", i, src_addr - cfg->map_offset[i]);
-            sptr = &cfg->map_data[i][src_addr - cfg->map_offset[i]];
-        }
-        else {
-            printf("BlitTemplate: Failed to find mapped range for address %.8X\n", src_addr);
-            return;
-        }
-    }
-
-    switch (draw_mode) {
-        case DRAWMODE_JAM1:
-            for (uint16_t ys = 0; ys < h; ys++) {
-                //printf("JAM1: Get byte from sptr[%d] (%p) <- (%p)...\n", tmpl_x, sptr, cfg->map_data[1]);
-                cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x];
-
-                for (int xs = 0; xs < w; xs++) {
-                    if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS(dptr, xs, format, fg_color);
-                        xs += 7;
-                    }
-                    else {
-                        while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                //printf("JAM1: Write byte to dptr[%d] (%p) <- (%p)...\n", xs, dptr, rtg_mem);
-                                SET_RTG_PIXEL(dptr, xs, format, fg_color);
-                            }
-                            xs++;
-                            cur_bit >>= 1;
-                        }
-                        xs--;
-                        cur_bit = 0x80;
-                    }
-                    TEMPLATE_LOOPX;
-                }
-                TEMPLATE_LOOPY;
-            }
-            return;
-        case DRAWMODE_JAM2:
-            for (uint16_t ys = 0; ys < h; ys++) {
-                //printf("JAM2: Get byte from sptr[%d] (%p) <- (%p)...\n", tmpl_x, sptr, cfg->map_data[1]);
-                cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x];
-
-                for (int xs = 0; xs < w; xs++) {
-                    if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS_COND(dptr, xs, format, fg_color, bg_color);
-                        xs += 7;
-                    }
-                    else {
-                        while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                SET_RTG_PIXEL(dptr, xs, format, fg_color)
-                            }
-                            else {
-                                SET_RTG_PIXEL(dptr, xs, format, bg_color)
-                            }
-                            xs++;
-                            cur_bit >>= 1;
-                        }
-                        xs--;
-                        cur_bit = 0x80;
-                    }
-                    TEMPLATE_LOOPX;
-                }
-                TEMPLATE_LOOPY;
-            }
-            return;
-        case DRAWMODE_COMPLEMENT:
-            for (uint16_t ys = 0; ys < h; ys++) {
-                cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x];
-
-                for (int xs = 0; xs < w; xs++) {
-                    if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS_COND(dptr, xs, format, fg_color, bg_color);
-                        xs += 7;
-                    }
-                    else {
-                        while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                INVERT_RTG_PIXELS(dptr, xs, format)
-                            }
-                            else {
-                                INVERT_RTG_PIXEL(dptr, xs, format)
-                            }
-                            xs++;
-                            cur_bit >>= 1;
-                        }
-                        xs--;
-                        cur_bit = 0x80;
-                    }
-                    TEMPLATE_LOOPX;
-                }
-                TEMPLATE_LOOPY;
-            }
-            return;
-    }
-}
-
-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) {
-    if (mask) {}
-    //printf("BlitPattern: %d,%d (%dx%d) @%.8X p:%d dp: %d DM: %d Format: %d\n", x, y, w, h, src_addr, pitch, 2, draw_mode & 0x03, format);
-    //printf("FBA: %.8x - lr: %d\n", framebuffer_addr, loop_rows);
-
-    uint8_t *dptr = &rtg_mem[rtg_address_adj[1] + (x << format) + (y * pitch)];
-    uint8_t *sptr = NULL, *sptr_base = NULL;
-    uint8_t cur_bit = 0, base_bit = 0, cur_byte = 0;
-    uint8_t invert = (draw_mode & DRAWMODE_INVERSVID);
-    uint16_t tmpl_x = 0;
-
-    draw_mode &= 0x03;
-
-       tmpl_x = (offset_x / 8) % 2;
-    cur_bit = base_bit = (0x80 >> (offset_x % 8));
-
-    uint32_t fg_color[3] = {
-        (fgcol & 0xFF),
-        htobe16((fgcol & 0xFFFF)),
-        htobe32(fgcol),
-    };
-    uint32_t bg_color[3] = {
-        (bgcol & 0xFF),
-        htobe16((bgcol & 0xFFFF)),
-        htobe32(bgcol),
-    };
-
-
-    if (src_addr >= PIGFX_RTG_BASE)
-        sptr = &rtg_mem[src_addr - PIGFX_RTG_BASE];
-    else {
-        int i = get_mapped_item_by_address(cfg, src_addr);
-        if (i != -1) {
-            //printf("BlitPattern: Grabbing data from mapped range %d at offset %ld.\n", i, src_addr - cfg->map_offset[i]);
-            sptr = &cfg->map_data[i][src_addr - cfg->map_offset[i]];
-        }
-        else {
-            printf("BlitPattern: Failed to find mapped range for address %.8X\n", src_addr);
-            return;
-        }
-    }
-
-    sptr_base = sptr;
-    sptr += (offset_y % loop_rows) * 2;
-
-    switch (draw_mode) {
-        case DRAWMODE_JAM1:
-            for (uint16_t ys = 0; ys < h; ys++) {
-                //printf("JAM1: Get byte from sptr[%d] (%p) <- (%p)...\n", tmpl_x, sptr, cfg->map_data[1]);
-                cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x];
-
-                for (int xs = 0; xs < w; xs++) {
-                    if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS(dptr, xs, format, fg_color);
-                        xs += 7;
-                    }
-                    else {
-                        while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                //printf("JAM1: Write byte to dptr[%d] (%p) <- (%p)...\n", xs, dptr, rtg_mem);
-                                SET_RTG_PIXEL(dptr, xs, format, fg_color);
-                            }
-                            xs++;
-                            cur_bit >>= 1;
-                        }
-                        xs--;
-                        cur_bit = 0x80;
-                    }
-                    PATTERN_LOOPX;
-                }
-                PATTERN_LOOPY;
-            }
-            return;
-        case DRAWMODE_JAM2:
-            for (uint16_t ys = 0; ys < h; ys++) {
-                //printf("JAM2: Get byte from sptr[%d] (%p) <- (%p)...\n", tmpl_x, sptr, cfg->map_data[1]);
-                cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x];
-
-                for (int xs = 0; xs < w; xs++) {
-                    //printf("JAM2: Write byte to dptr[%d] (%p) <- (%p)...\n", xs, dptr, rtg_mem);
-                    if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS_COND(dptr, xs, format, fg_color, bg_color);
-                        xs += 7;
-                    }
-                    else {
-                        while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                SET_RTG_PIXEL(dptr, xs, format, fg_color)
-                            }
-                            else {
-                                SET_RTG_PIXEL(dptr, xs, format, bg_color)
-                            }
-                            xs++;
-                            cur_bit >>= 1;
-                        }
-                        xs--;
-                        cur_bit = 0x80;
-                    }
-                    PATTERN_LOOPX;
-                }
-                PATTERN_LOOPY;
-            }
-            return;
-        case DRAWMODE_COMPLEMENT:
-            for (uint16_t ys = 0; ys < h; ys++) {
-                cur_byte = (invert) ? sptr[tmpl_x] ^ 0xFF : sptr[tmpl_x];
-
-                for (int xs = 0; xs < w; xs++) {
-                    if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS_COND(dptr, xs, format, fg_color, bg_color);
-                        xs += 7;
-                    }
-                    else {
-                        while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                INVERT_RTG_PIXELS(dptr, xs, format)
-                            }
-                            else {
-                                INVERT_RTG_PIXEL(dptr, xs, format)
-                            }
-                            xs++;
-                            cur_bit >>= 1;
-                        }
-                        xs--;
-                        cur_bit = 0x80;
-                    }
-                    PATTERN_LOOPX;
-                }
-                PATTERN_LOOPY;
-            }
-            return;
     }
 }