]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/rtg/rtg-gfx.c
Add mask handling to all RTG ops, add real time disassembly output
[pistorm] / platforms / amiga / rtg / rtg-gfx.c
index 058a8b1b60dd3969e20b342b29b798c2222bc4ab..558816b40ef50329045b2e9581ed9a16faee81a9 100644 (file)
@@ -17,8 +17,7 @@ extern uint16_t rtg_x[8], rtg_y[8];
 
 extern uint8_t realtime_graphics_debug;
 
-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) {}
+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) {
     uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
     switch(format) {
         case RTGFMT_8BIT: {
@@ -50,6 +49,16 @@ void rtg_fillrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color
     }
 }
 
+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) {
+    uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
+
+    for (int ys = 1; ys < h; ys++) {
+        for (int xs = 0; xs < w; xs++) {
+            SET_RTG_PIXEL_MASK(&dptr[xs], (color & 0xFF), format);
+        }
+    }
+}
+
 void rtg_invertrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t pitch, uint16_t format, uint8_t mask) {
     if (mask) {}
     uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (x << format) + (y * pitch)];
@@ -57,7 +66,7 @@ void rtg_invertrect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t pit
         switch(format) {
             case RTGFMT_8BIT: {
                 for (int xs = 0; xs < w; xs++) {
-                    dptr[xs] = ~dptr[xs];
+                    dptr[xs] ^= mask;
                 }
                 break;
             }
@@ -94,6 +103,37 @@ void rtg_blitrect(uint16_t x, uint16_t y, uint16_t dx, uint16_t dy, uint16_t w,
         xdir = 0;
     }
 
+    for (int ys = 0; ys < h; ys++) {
+        if (xdir) {
+            for (int xs = 0; xs < w; xs++) {
+                SET_RTG_PIXEL_MASK(&dptr[xs], sptr[xs], format);
+            }
+        }
+        else {
+            for (int xs = w - 1; xs >= x; xs--) {
+                SET_RTG_PIXEL_MASK(&dptr[xs], sptr[xs], format);
+            }
+        }
+        sptr += pitchstep;
+        dptr += pitchstep;
+    }
+}
+
+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) {
+    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);
@@ -110,6 +150,8 @@ void rtg_blitrect_nomask_complete(uint16_t sx, uint16_t sy, uint16_t dx, uint16_
     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;
+    uint8_t draw_mode = minterm;
+    uint32_t mask = 0xFF;
 
     if (src_addr == dst_addr) {
         if (sy < dy) {
@@ -123,13 +165,56 @@ void rtg_blitrect_nomask_complete(uint16_t sx, uint16_t sy, uint16_t dx, uint16_
         }
     }
 
-    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;
+    if (format == RTGFMT_RBG565)
+        mask = 0xFFFF;
+    if (format == RTGFMT_RGB32)
+        mask = 0xFFFFFFFF;
+
+    if (minterm == MINTERM_SRC) {
+        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;
+        }
+    }
+    else {
+        for (int ys = 0; ys < h; ys++) {
+            if (xdir) {
+                for (int xs = 0; xs < w; xs++) {
+                    switch (format) {
+                        case RTGFMT_8BIT:
+                            HANDLE_MINTERM_PIXEL(sptr[xs], dptr[xs], format);
+                            break;
+                        case RTGFMT_RBG565:
+                            HANDLE_MINTERM_PIXEL(((uint16_t *)sptr)[xs], ((uint16_t *)dptr)[xs], format);
+                            break;
+                        case RTGFMT_RGB32:
+                            HANDLE_MINTERM_PIXEL(((uint32_t *)sptr)[xs], ((uint32_t *)dptr)[xs], format);
+                            break;
+                    }
+                }
+            }
+            else {
+                for (int xs = w - 1; xs >= sx; xs--) {
+                    switch (format) {
+                        case RTGFMT_8BIT:
+                            HANDLE_MINTERM_PIXEL(sptr[xs], dptr[xs], format);
+                            break;
+                        case RTGFMT_RBG565:
+                            HANDLE_MINTERM_PIXEL(((uint16_t *)sptr)[xs], ((uint16_t *)dptr)[xs], format);
+                            break;
+                        case RTGFMT_RGB32:
+                            HANDLE_MINTERM_PIXEL(((uint32_t *)sptr)[xs], ((uint32_t *)dptr)[xs], format);
+                            break;
+                    }
+                }
+            }
+            sptr += src_pitchstep;
+            dptr += src_pitchstep;
+        }
     }
 }
 
@@ -217,13 +302,23 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s
 
                 for (int xs = 0; xs < w; xs++) {
                     if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format);
+                        if (mask == 0xFF || format != RTGFMT_8BIT) {
+                            SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format);
+                        }
+                        else {
+                            SET_RTG_PIXELS_MASK(&dptr[xs], fg_color[format], format);
+                        }
                         xs += 7;
                     }
                     else {
                         while (cur_bit > 0 && xs < w) {
                             if (cur_byte & cur_bit) {
-                                SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
+                                if (mask == 0xFF || format != RTGFMT_8BIT) {
+                                    SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
+                                }
+                                else {
+                                    SET_RTG_PIXEL_MASK(&dptr[xs], fg_color[format], format);
+                                }
                             }
                             xs++;
                             cur_bit >>= 1;
@@ -242,16 +337,22 @@ void rtg_blittemplate(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t s
 
                 for (int xs = 0; xs < w; xs++) {
                     if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format);
+                        if (mask == 0xFF || format != RTGFMT_8BIT) {
+                            SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format);
+                        }
+                        else {
+                            SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
+                        }
+                        
                         xs += 7;
                     }
                     else {
                         while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
+                            if (mask == 0xFF || format != RTGFMT_8BIT) {
+                                SET_RTG_PIXEL(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
                             }
                             else {
-                                SET_RTG_PIXEL(&dptr[xs << format], bg_color[format], format);
+                                SET_RTG_PIXEL_MASK(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
                             }
                             xs++;
                             cur_bit >>= 1;
@@ -341,13 +442,23 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr
 
                 for (int xs = 0; xs < w; xs++) {
                     if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format);
+                        if (mask == 0xFF || format != RTGFMT_8BIT) {
+                            SET_RTG_PIXELS(&dptr[xs << format], fg_color[format], format);
+                        }
+                        else {
+                            SET_RTG_PIXELS_MASK(&dptr[xs], fg_color[format], format);
+                        }
                         xs += 7;
                     }
                     else {
                         while (cur_bit > 0 && xs < w) {
                             if (cur_byte & cur_bit) {
-                                SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
+                                if (mask == 0xFF || format != RTGFMT_8BIT) {
+                                    SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
+                                }
+                                else {
+                                    SET_RTG_PIXEL_MASK(&dptr[xs], fg_color[format], format);
+                                }
                             }
                             xs++;
                             cur_bit >>= 1;
@@ -366,16 +477,22 @@ void rtg_blitpattern(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t sr
 
                 for (int xs = 0; xs < w; xs++) {
                     if (w >= 8 && cur_bit == 0x80 && xs < w - 8) {
-                        SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format);
+                        if (mask == 0xFF || format != RTGFMT_8BIT) {
+                            SET_RTG_PIXELS2_COND(&dptr[xs << format], fg_color[format], bg_color[format], format);
+                        }
+                        else {
+                            SET_RTG_PIXELS2_COND_MASK(&dptr[xs << format], fg_color[format], bg_color[format], format);
+                        }
+                        
                         xs += 7;
                     }
                     else {
                         while (cur_bit > 0 && xs < w) {
-                            if (cur_byte & cur_bit) {
-                                SET_RTG_PIXEL(&dptr[xs << format], fg_color[format], format);
+                            if (mask == 0xFF || format != RTGFMT_8BIT) {
+                                SET_RTG_PIXEL(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
                             }
                             else {
-                                SET_RTG_PIXEL(&dptr[xs << format], bg_color[format], format);
+                                SET_RTG_PIXEL_MASK(&dptr[xs << format], (cur_byte & cur_bit) ? fg_color[format] : bg_color[format], format);
                             }
                             xs++;
                             cur_bit >>= 1;
@@ -499,7 +616,7 @@ void rtg_drawline (int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint16_t
        int16_t x1 = x1_, y1 = y1_;
        int16_t x2 = x1_ + x2_, y2 = y1 + y2_;
     uint16_t cur_bit = 0x8000;
-    uint32_t color_mask = 0xFFFF0000;
+    //uint32_t color_mask = 0xFFFF0000;
     uint8_t invert = 0;
 
     uint32_t fg_color[3] = {
@@ -569,77 +686,13 @@ void rtg_drawline (int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint16_t
        }
 }
 
-#define HANDLE_MINTERM_PIXEL_8(s, d, f) \
-      switch(draw_mode) {\
-            case MINTERM_NOR: \
-                  s &= ~(d); \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_ONLYDST: \
-                  d = d & ~(s); break; \
-            case MINTERM_NOTSRC: \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_ONLYSRC: \
-                  s &= (d ^ 0xFF); \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_INVERT: \
-                  d ^= 0xFF; break; \
-            case MINTERM_EOR: \
-                  d ^= s; break; \
-            case MINTERM_NAND: \
-                  s = ~(d & ~(s)) & mask; \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_AND: \
-                  s &= d; \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_NEOR: \
-                  d ^= (s & mask); break; \
-            case MINTERM_DST: /* This one does nothing. */ \
-                  return; break; \
-            case MINTERM_NOTONLYSRC: \
-                  d |= (s & mask); break; \
-            case MINTERM_SRC: \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_NOTONLYDST: \
-                  s = ~(d & s) & mask; \
-            SET_RTG_PIXEL_MASK(&d, s, f); break; \
-            case MINTERM_OR: \
-                  d |= (s & mask); break; \
-      }
-
-
-#define DECODE_PLANAR_PIXEL(a) \
-       switch (planes) { \
-               case 8: if (layer_mask & 0x80 && bmp_data[(plane_size * 7) + cur_byte] & cur_bit) a |= 0x80; \
-               case 7: if (layer_mask & 0x40 && bmp_data[(plane_size * 6) + cur_byte] & cur_bit) a |= 0x40; \
-               case 6: if (layer_mask & 0x20 && bmp_data[(plane_size * 5) + cur_byte] & cur_bit) a |= 0x20; \
-               case 5: if (layer_mask & 0x10 && bmp_data[(plane_size * 4) + cur_byte] & cur_bit) a |= 0x10; \
-               case 4: if (layer_mask & 0x08 && bmp_data[(plane_size * 3) + cur_byte] & cur_bit) a |= 0x08; \
-               case 3: if (layer_mask & 0x04 && bmp_data[(plane_size * 2) + cur_byte] & cur_bit) a |= 0x04; \
-               case 2: if (layer_mask & 0x02 && bmp_data[plane_size + cur_byte] & cur_bit) a |= 0x02; \
-               case 1: if (layer_mask & 0x01 && bmp_data[cur_byte] & cur_bit) a |= 0x01; \
-                       break; \
-       }
-
-#define DECODE_INVERTED_PLANAR_PIXEL(a) \
-       switch (planes) { \
-               case 8: if (layer_mask & 0x80 && (bmp_data[(plane_size * 7) + cur_byte] ^ 0xFF) & cur_bit) a |= 0x80; \
-               case 7: if (layer_mask & 0x40 && (bmp_data[(plane_size * 6) + cur_byte] ^ 0xFF) & cur_bit) a |= 0x40; \
-               case 6: if (layer_mask & 0x20 && (bmp_data[(plane_size * 5) + cur_byte] ^ 0xFF) & cur_bit) a |= 0x20; \
-               case 5: if (layer_mask & 0x10 && (bmp_data[(plane_size * 4) + cur_byte] ^ 0xFF) & cur_bit) a |= 0x10; \
-               case 4: if (layer_mask & 0x08 && (bmp_data[(plane_size * 3) + cur_byte] ^ 0xFF) & cur_bit) a |= 0x08; \
-               case 3: if (layer_mask & 0x04 && (bmp_data[(plane_size * 2) + cur_byte] ^ 0xFF) & cur_bit) a |= 0x04; \
-               case 2: if (layer_mask & 0x02 && (bmp_data[plane_size + cur_byte] ^ 0xFF) & cur_bit) a |= 0x02; \
-               case 1: if (layer_mask & 0x01 && (bmp_data[cur_byte] ^ 0xFF) & cur_bit) a |= 0x01; \
-                       break; \
-       }
-
 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) {
     uint16_t pitch = rtg_x[3];
     uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
 
        uint8_t cur_bit, base_bit, base_byte;
        uint16_t cur_byte = 0, u8_fg = 0;
-    uint32_t color_mask = 0xFFFFFFFF;
+    //uint32_t color_mask = 0xFFFFFFFF;
 
        uint32_t plane_size = src_line_pitch * h;
        uint8_t *bmp_data = bmp_data_src;
@@ -684,8 +737,7 @@ void rtg_p2c (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t
                                goto skip;
                        }
 
-                       //HANDLE_MINTERM_PIXEL_8(u8_fg, ((uint8_t *)dptr)[x]);
-            HANDLE_MINTERM_PIXEL_8(u8_fg, dptr[x], rtg_display_format);
+            HANDLE_MINTERM_PIXEL(u8_fg, dptr[x], rtg_display_format);
 
                        skip:;
                        if ((cur_bit >>= 1) == 0) {
@@ -704,96 +756,3 @@ void rtg_p2c (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t
                cur_byte = base_byte;
        }
 }
-
-//void rtg_p2c_broken(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t pitch, uint8_t mask, uint8_t minterm, uint8_t depth, uint16_t planemask_) {
-    /*uint8_t *planeptr_src = &rtg_mem[rtg_address_adj[1]];
-    uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
-
-       uint8_t cur_bit, base_bit, base_byte;
-       uint16_t cur_byte = 0;//, color = 0;
-    uint16_t srcpitch = rtg_user[1];
-    uint32_t plane_size = srcpitch * rtg_y[3];
-    uint32_t color_mask = 0x00FFFFFF;
-    uint8_t color = 0;
-
-    uint8_t planemask = planemask_ & 0xFF;
-    uint8_t planemask_0 = (planemask_ >> 8);
-
-       cur_bit = base_bit = (0x80 >> (sx % 8));
-       cur_byte = base_byte = ((sx / 8) % srcpitch);
-
-    planeptr_src += (srcpitch * sy);
-
-    if (realtime_graphics_debug) {
-        uint8_t *sptr = NULL;
-
-        printf("P2C: %d,%d - %d,%d (%dx%d) %d, %.4X\n", sx, sy, dx, dy, w, h, depth, planemask_);
-        printf("Mask: %.2X Minterm: %.2X\n", mask, minterm);
-        printf("Pitch: %d Src Pitch: %d (!!!: %d)\n", pitch, srcpitch, rtg_user[1]);
-        printf("Curbyte: %d Curbit: %d\n", cur_byte, cur_bit);
-        printf("Plane size: %d Total size: %d (%X)\n", plane_size, plane_size * depth, plane_size * depth);
-        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("Origin: %.8X\n", rtg_address[2]);
-        printf("Grabbing data from RTG memory.\nData:\n");
-        for (int i = 0; i < h; i++) {
-            for (int k = 0; k < depth; k++) {
-                for (int j = 0; j < srcpitch; j++) {
-                    printf("%.2X", planeptr_src[j + (i * srcpitch) + (plane_size * k)]);
-                }
-                printf("  ");
-            }
-            printf("\n");
-        }
-#ifndef FAKESTORM
-        printf("Data available at origin:\n");
-        for (int i = 0; i < h; i++) {
-            for (int k = 0; k < depth; k++) {
-                for (int j = 0; j < srcpitch; j++) {
-                    printf("%.2X", read8(rtg_address[2] + j + (i * srcpitch) + (plane_size * k)));
-                }
-                printf("  ");
-            }
-            printf("\n");
-        }
-#endif
-    }
-
-       for (int16_t line_y = 0; line_y < h; line_y++) {
-               for (int16_t xs = dx; xs < dx + w; xs++) {
-                       color = 0;
-                       if (minterm & 0x01) {
-                //printf("Decode inverted planar pixel.\n");
-                               DECODE_INVERTED_PLANAR_PIXEL(color, planeptr_src);
-            }
-                       else {
-                //printf("Decode planar pixel.\n");
-                               DECODE_PLANAR_PIXEL(color, planeptr_src);
-            }
-                       
-                       if (mask == 0xFF && (minterm == MINTERM_SRC || minterm == MINTERM_NOTSRC)) {
-                               dptr[xs << rtg_display_format] = color;
-                               goto skip;
-                       }
-
-            //printf("Place pixel.\n");
-                       HANDLE_MINTERM_PIXEL_8(color, dptr[xs << rtg_display_format], rtg_display_format);
-
-                       skip:;
-                       if ((cur_bit >>= 1) == 0) {
-                               cur_bit = 0x80;
-                               cur_byte++;
-                               cur_byte %= srcpitch;
-                       }
-               }
-               dptr += pitch;
-        //if (line_y + sy + 1 == rtg_y[3])
-            //planeptr_src = &rtg_mem[rtg_address_adj[1]];// + (srcpitch * sy);
-        //else
-               planeptr_src += srcpitch;
-               cur_bit = base_bit;
-               cur_byte = base_byte;
-       }*/
-//}