]> git.sesse.net Git - pistorm/commitdiff
Some RTG bug fixes, (inactive for now) P2C iRTG implementation
authorbeeanyew <beeanyew@gmail.com>
Thu, 3 Jun 2021 20:16:12 +0000 (22:16 +0200)
committerbeeanyew <beeanyew@gmail.com>
Thu, 3 Jun 2021 20:16:12 +0000 (22:16 +0200)
Fix P2C/P2D behavior when swiching between color depths.
Add P2C iRTG implementation. This is currently too slow to be used due to the massive amount of single ps_read_8s, needs something to copy all the data similar to the RTG driver code.

platforms/amiga/pistorm-dev/pistorm-dev.c
platforms/amiga/rtg/irtg_structs.h
platforms/amiga/rtg/rtg-gfx.c
platforms/amiga/rtg/rtg.c
platforms/amiga/rtg/rtg_driver_amiga/pigfx-2.c

index 95943ab93a33743a6ac098125ec92ce5d04342a9..9668daffdfeb9e1a3476c892311418d0b651cc8f 100644 (file)
@@ -191,6 +191,8 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
             } else {
                 int32_t src = get_mapped_item_by_address(cfg, pi_ptr[0]);
                 int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[1]);
+                if (cfg->map_type[dst] == MAPTYPE_ROM)
+                    break;
                 if (dst != -1 && src != -1) {
                     uint8_t *src_ptr = &cfg->map_data[src][(pi_ptr[0] - cfg->map_offset[src])];
                     uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[1] - cfg->map_offset[dst])];
@@ -227,6 +229,8 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
                 pi_cmd_result = PI_RES_INVALIDVALUE;
             } else {
                 int32_t dst = get_mapped_item_by_address(cfg, pi_ptr[0]);
+                if (cfg->map_type[dst] == MAPTYPE_ROM)
+                    break;
                 if (dst != -1) {
                     uint8_t *dst_ptr = &cfg->map_data[dst][(pi_ptr[0] - cfg->map_offset[dst])];
                     memset(dst_ptr, pi_byte[0], val);
index 4ab09c1c86539bf71451134eff7a3926391de5d4..8ceb2136d74cdfd59398166c1e1100bae97be82f 100644 (file)
@@ -44,6 +44,15 @@ struct Node_placeholder {
     uint32_t _p_ln_Name;
 };
 
+struct BitMap {
+    uint16_t BytesPerRow;
+    uint16_t Rows;
+    uint8_t Flags;
+    uint8_t Depth;
+    uint16_t pad;
+    uint32_t _p_Planes[8];
+};
+
 struct MinList_placeholder {
    uint32_t _p_mlh_Head;
    uint32_t _p_mlh_Tail;
@@ -86,7 +95,7 @@ struct MsgPort_placeholder {
     struct List_placeholder mp_MsgList;
 };
 
-struct Rectangle {
+struct P96Rectangle {
     int16_t MinX,MinY;
     int16_t MaxX,MaxY;
 };
@@ -286,7 +295,7 @@ struct P96BoardInfo{
     uint8_t MouseYOffset;
     uint32_t _p_MouseImage;
     uint8_t MousePens[4];
-    struct Rectangle MouseRect;
+    struct P96Rectangle MouseRect;
     uint32_t _p_MouseChunky;
     uint32_t _p_MouseRendered;
     uint32_t _p_MouseSaveBuffer;
index 7334854d642c8ec5c17032d4b1194e3cdca873ce..0779d94d02f6d14b1fe20c7cb40cc94fc6528838 100644 (file)
@@ -8,14 +8,16 @@
 #ifndef FAKESTORM
 #include "gpio/ps_protocol.h"
 #endif
+#include <endian.h>
+#include "platforms/amiga/rtg/irtg_structs.h"
 #include "rtg.h"
 
 extern uint32_t rtg_address[8];
 extern uint32_t rtg_address_adj[8];
 extern uint8_t *rtg_mem; // FIXME
-extern uint16_t rtg_display_format;
 extern uint16_t rtg_user[8];
 extern uint16_t rtg_x[8], rtg_y[8];
+extern uint16_t rtg_format;
 
 extern uint32_t framebuffer_addr;
 extern uint32_t framebuffer_addr_adj;
@@ -647,6 +649,92 @@ void rtg_drawline (int16_t x1_, int16_t y1_, int16_t x2_, int16_t y2_, uint16_t
        }
 }
 
+// This is slow and somewhat useless, needs a rewrite to ps_read_16 copy the bit plane data
+// similarly to what the code in the RTG driver does. Disabled for now.
+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) {
+    uint16_t pitch = dst_pitch;
+    uint8_t *dptr = &rtg_mem[rtg_address_adj[0] + (dy * pitch)];
+    uint8_t draw_mode = minterm;
+
+       uint8_t cur_bit, base_bit, base_byte;
+       uint16_t cur_byte = 0, u8_fg = 0, u8_tmp = 0;
+
+       cur_bit = base_bit = (0x80 >> (sx % 8));
+       cur_byte = base_byte = ((sx / 8) % src_pitch);
+
+    uint8_t *plane_ptr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+    uint32_t plane_addr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+
+    for (int i = 0; i < bm->Depth; i++) {
+        uint32_t plane_address = be32toh(bm->_p_Planes[i]);
+        if (plane_address != 0 && plane_address != 0xFFFFFFFF) {
+            plane_ptr[i] = get_mapped_data_pointer_by_address(cfg, be32toh(bm->_p_Planes[i]));
+            if (!plane_ptr[i]) {
+                plane_addr[i] = be32toh(bm->_p_Planes[i]);
+                if (plane_addr[i] != 0) plane_addr[i] += (sy * src_pitch);
+            } else {
+                plane_ptr[i] += (sy * src_pitch);
+            }
+        } else {
+            plane_addr[i] = plane_address;
+        }
+    }
+
+       for (int16_t line_y = 0; line_y < h; line_y++) {
+               for (int16_t x = dx; x < dx + w; x++) {
+            u8_fg = 0;
+            if (minterm & 0x01) {
+                for (int i = 0; i < bm->Depth; i++) {
+                    if (plane_ptr[i]) {
+                        if (~plane_ptr[i][cur_byte] & cur_bit) u8_fg |= (1 << i);
+                    } else {
+                        if (plane_addr[i] == 0xFFFFFFFF) u8_fg |= (1 << i);
+                        else if (plane_addr[i] != 0) {
+                            u8_tmp = (uint8_t)ps_read_8(plane_addr[i] + cur_byte);
+                            if (~u8_tmp & cur_bit) u8_fg |= (1 << i);
+                        }
+                    }
+                }
+            } else {
+                for (int i = 0; i < bm->Depth; i++) {
+                    if (plane_ptr[i]) {
+                        if (plane_ptr[i][cur_byte] & cur_bit) u8_fg |= (1 << i);
+                    } else {
+                        if (plane_addr[i] == 0xFFFFFFFF) u8_fg |= (1 << i);
+                        else if (plane_addr[i] != 0) {
+                            u8_tmp = (uint8_t)ps_read_8(plane_addr[i] + cur_byte);
+                            if (u8_tmp & cur_bit) u8_fg |= (1 << i);
+                        }
+                    }
+                }
+            }
+
+                       if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
+                               dptr[x] = u8_fg;
+                               goto skip;
+                       }
+
+            HANDLE_MINTERM_PIXEL(u8_fg, dptr[x], RTGFMT_8BIT);
+
+                       skip:;
+                       if ((cur_bit >>= 1) == 0) {
+                               cur_bit = 0x80;
+                               cur_byte++;
+                               cur_byte %= src_pitch;
+                       }
+               }
+               dptr += pitch;
+        for (int i = 0; i < bm->Depth; i++) {
+            if (plane_ptr[i] && (uint32_t)plane_ptr[i] != 0xFFFFFFFF)
+                plane_ptr[i] += src_pitch;
+            if (plane_addr[i] && plane_addr[i] != 0xFFFFFFFF)
+                plane_addr[i] += src_pitch;
+        }
+               cur_bit = base_bit;
+               cur_byte = base_byte;
+    }
+}
+
 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)];
@@ -698,7 +786,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(u8_fg, dptr[x], rtg_display_format);
+            HANDLE_MINTERM_PIXEL(u8_fg, dptr[x], rtg_format);
 
                        skip:;
                        if ((cur_bit >>= 1) == 0) {
@@ -770,7 +858,7 @@ void rtg_p2d (int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t
             uint32_t fg_color = clut[u8_fg];
 
                        if (mask == 0xFF && (draw_mode == MINTERM_SRC || draw_mode == MINTERM_NOTSRC)) {
-                               switch (rtg_display_format) {
+                               switch (rtg_format) {
                                        case RTGFMT_RBG565:
                                                ((uint16_t *)dptr)[x] = (fg_color >> 16);
                                                break;
index 0d97b28b92aece4ac1e81b59afc0ca2b3919dde0..91e4e772695fbaa88ef9dfd552ae30ee218a0f74 100644 (file)
@@ -6,13 +6,15 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-#include "irtg_structs.h"
 #include "config_file/config_file.h"
 #include "gpio/ps_protocol.h"
+#include "platforms/amiga/rtg/irtg_structs.h"
 #include "rtg.h"
 
 #include "m68k.h"
 
+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);
+
 uint8_t rtg_u8[4];
 uint16_t rtg_x[8], rtg_y[8];
 uint16_t rtg_user[8];
@@ -434,6 +436,43 @@ static void handle_irtg_command(uint32_t cmd) {
             gdebug("iBlitPattern end\n");
             break;
         }
+        case RTGCMD_P2C: {
+            // A0: BoardInfo, A1: BitMap *bm, A2: RenderInfo *r,
+            // D0: SHORT x, D1: SHORT y, D2: SHORT dx, D3: SHORT dy, D4: SHORT w, D5: SHORT h,
+            // D6: UBYTE minterm, D7: UBYTE mask
+            r = (struct P96RenderInfo *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A2));
+            struct BitMap *bm = (struct BitMap *)get_mapped_data_pointer_by_address(cfg, M68KR(M68K_REG_A1));
+            if (!r || !bm)
+                break;
+
+            gdebug("iP2C begin\n");
+
+            if (!bm) {
+                printf ("Help! BitMap not in mapped memory.\n");
+                break;
+            } else {
+                gdebug("Data is available in mapped memory.\n");
+            }
+
+            if (realtime_graphics_debug) {
+                printf("bm: %.8X r: %.8X\n", (uint32_t)bm, (uint32_t)r);
+                if (bm)
+                    printf("bm pitch: %d\n", be16toh(bm->BytesPerRow));
+                if (r)
+                    printf("r pitch: %d\n", be16toh(r->BytesPerRow));
+            }
+
+            uint16_t bmp_pitch = be16toh(bm->BytesPerRow);
+            uint16_t line_pitch = be16toh(r->BytesPerRow);
+            rtg_address_adj[0] = be32toh(r->_p_Memory) - (PIGFX_RTG_BASE + PIGFX_REG_SIZE);
+
+            uint8_t minterm = (uint8_t)M68KR(M68K_REG_D6);
+            cmd_mask = (uint8_t)M68KR(M68K_REG_D7);
+
+            rtg_p2c_ex(M68KR(M68K_REG_D0), M68KR(M68K_REG_D1), M68KR(M68K_REG_D2), M68KR(M68K_REG_D3), M68KR(M68K_REG_D4), M68KR(M68K_REG_D5), minterm, bm, cmd_mask, line_pitch, bmp_pitch);
+            gdebug("iP2C end\n");
+            break;
+        }
         default:
             printf("[!!!IRTG] Unnkonw/unhandled iRTG command %d.\n", cmd);
             break;
index 9af64be2d9a536bb27cb5839aa8ccbca2d2aab86..bf8b79330a10d43abdc051a69f4438d65a17496d 100644 (file)
@@ -661,6 +661,8 @@ void DrawLine (__REGA0(struct BoardInfo *b), __REGA1(struct RenderInfo *r), __RE
 }
 
 void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {
+// iRTG path disabled for now, since it's really slow, see note in rtg-gfx.c.
+//#ifndef IRTG    
     if (!b || !r)
         return;
 
@@ -718,6 +720,9 @@ void BlitPlanar2Chunky (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm)
     WRITEBYTE(RTG_U83, bm->Depth);
 
     WRITESHORT(RTG_COMMAND, RTGCMD_P2C);
+//#else
+//    IWRITECMD(RTGCMD_P2C);
+//#endif
 }
 
 void BlitPlanar2Direct (__REGA0(struct BoardInfo *b), __REGA1(struct BitMap *bm), __REGA2(struct RenderInfo *r), __REGA3(struct ColorIndexMapping *clut), __REGD0(SHORT x), __REGD1(SHORT y), __REGD2(SHORT dx), __REGD3(SHORT dy), __REGD4(SHORT w), __REGD5(SHORT h), __REGD6(UBYTE minterm), __REGD7(UBYTE mask)) {