]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/pistorm-dev/pistorm-dev.c
Some RTG bug fixes, (inactive for now) P2C iRTG implementation
[pistorm] / platforms / amiga / pistorm-dev / pistorm-dev.c
index 99c8236a128d5b67406e6b96b5aadcb73f77293e..9668daffdfeb9e1a3476c892311418d0b651cc8f 100644 (file)
@@ -21,8 +21,6 @@
 #ifdef DEBUG_PISTORM_DEVICE
 #define DEBUG printf
 
-#define PIDEV_SWREV 0x0105
-
 static const char *op_type_names[4] = {
     "BYTE",
     "WORD",
@@ -33,6 +31,8 @@ static const char *op_type_names[4] = {
 #define DEBUG(...)
 #endif
 
+#define PIDEV_SWREV 0x0105
+
 extern uint32_t pistorm_dev_base;
 extern uint32_t do_reset;
 
@@ -61,7 +61,7 @@ int32_t grab_amiga_string(uint32_t addr, uint8_t *dest, uint32_t str_max_len) {
     if (r == -1) {
         DEBUG("[GRAB_AMIGA_STRING] No mapped range found for address $%.8X. Grabbing string data over the bus.\n", addr);
         do {
-            dest[index] = read8(addr + index);
+            dest[index] = (unsigned char)m68k_read_memory_8(addr + index);
             index++;
         } while (dest[index - 1] != 0x00 && index < str_max_len);
     }
@@ -98,7 +98,7 @@ int32_t amiga_transfer_file(uint32_t addr, char *filename) {
 
         for (uint32_t i = 0; i < filesize; i++) {
             tmp_read = (uint8_t)fgetc(in);
-            write8(addr + i, tmp_read);
+            m68k_write_memory_8(addr + i, tmp_read);
         }
     } else {
         uint8_t *dst = cfg->map_data[r] + (addr - cfg->map_offset[r]);
@@ -191,25 +191,56 @@ 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) {
-                    //printf("doing super memcpy\n");
                     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])];
                     memcpy(dst_ptr, src_ptr, val);
                 } else {
-                    printf("!!! doing manual memcpy\n");
                     uint8_t tmp = 0;
+                    uint16_t tmps = 0;
                     for (uint32_t i = 0; i < val; i++) {
-                        if (src == -1) tmp = read8(pi_ptr[0] + i);
+                        while (i + 2 < val) {
+                            if (src == -1) tmps = (uint16_t)m68k_read_memory_16(pi_ptr[0] + i);
+                            else memcpy(&tmps, &cfg->map_data[src][pi_ptr[0] - cfg->map_offset[src] + i], 2);
+
+                            if (dst == -1) m68k_write_memory_16(pi_ptr[1] + i, tmps);
+                            else memcpy(&cfg->map_data[dst][pi_ptr[1] - cfg->map_offset[dst] + i], &tmps, 2);
+                            i += 2;
+                        }
+                        if (src == -1) tmp = (uint8_t)m68k_read_memory_8(pi_ptr[0] + i);
                         else tmp = cfg->map_data[src][pi_ptr[0] - cfg->map_offset[src] + i];
                         
-                        if (dst == -1) write8(pi_ptr[1] + i, tmp);
+                        if (dst == -1) m68k_write_memory_8(pi_ptr[1] + i, tmp);
                         else cfg->map_data[dst][pi_ptr[1] - cfg->map_offset[dst] + i] = tmp;
                     }
                 }
                 //DEBUG("[PISTORM-DEV] Copied %d bytes from $%.8X to $%.8X\n", val, pi_ptr[0], pi_ptr[1]);
             }
             break;
+        case PI_CMD_MEMSET:
+            //DEBUG("[PISTORM-DEV} Write to MEMSET: %d (%.8X)\n", val, val);
+            if (pi_ptr[0] == 0) {
+                printf("[PISTORM-DEV] MEMSET with null pointer not allowed. Aborting.\n");
+                pi_cmd_result = PI_RES_INVALIDVALUE;
+            } else if (val == 0) {
+                printf("[PISTORM-DEV] MEMSET called with size 0. Aborting.\n");
+                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);
+                } else {
+                    for (uint32_t i = 0; i < val; i++) {
+                        m68k_write_memory_8(pi_ptr[0] + i, pi_byte[0]);
+                    }
+                }
+            }
+            break;
         case PI_CMD_COPYRECT:
         case PI_CMD_COPYRECT_EX:
             if (pi_ptr[0] == 0 || pi_ptr[1] == 0) {
@@ -222,6 +253,11 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
                 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 (addr != PI_CMD_COPYRECT_EX) {
+                    // Clear out the src/dst coordinates in case something else set them previously.
+                    pi_word[4] = pi_word[5] = pi_word[6] = pi_word[7] = 0;
+                }
+
                 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])];
@@ -239,13 +275,6 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
                         dst_ptr += pi_word[1];
                     }
                 } else {
-                    printf("!!! doing manual copyrect\n");
-
-                    if (addr != PI_CMD_COPYRECT_EX) {
-                        // Clear out the src/dst coordinates in case something else set them previously.
-                        pi_word[4] = pi_word[5] = pi_word[6] = pi_word[7] = 0;
-                    }
-
                     uint32_t src_offset = 0, dst_offset = 0;
                     uint8_t tmp = 0;
 
@@ -256,10 +285,10 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
 
                     for (uint32_t y = 0; y < pi_word[3]; y++) {
                         for (uint32_t x = 0; x < pi_word[2]; x++) {
-                            if (src == -1) tmp = read8(pi_ptr[0] + src_offset + x);
+                            if (src == -1) tmp = (unsigned char)m68k_read_memory_8(pi_ptr[0] + src_offset + x);
                             else tmp = cfg->map_data[src][(pi_ptr[0] + src_offset + x) - cfg->map_offset[src]];
                             
-                            if (dst == -1) write8(pi_ptr[1] + dst_offset + x, tmp);
+                            if (dst == -1) m68k_write_memory_8(pi_ptr[1] + dst_offset + x, tmp);
                             else cfg->map_data[dst][(pi_ptr[1] + dst_offset + x) - cfg->map_offset[dst]] = tmp;
                         }
                         src_offset += pi_word[0];
@@ -269,6 +298,8 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
             }
             break;
 
+        case PI_CMD_SHOWFPS: rtg_show_fps((uint8_t)val); break;
+        case PI_CMD_PALETTEDEBUG: rtg_palette_debug((uint8_t)val); break;
         case PI_CMD_RTGSTATUS:
             DEBUG("[PISTORM-DEV] Write to RTGSTATUS: %d\n", val);
             if (val == 1 && !rtg_enabled) {
@@ -397,7 +428,7 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
                         free(cfg->map_id[index]);
                         cfg->map_type[index] = MAPTYPE_NONE;
                         // Dirty hack, I am sleepy and lazy.
-                        add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "kickstart");
+                        add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "kickstart", 0);
                         pi_cmd_result = PI_RES_OK;
                         do_reset = 1;
                     } else {
@@ -427,7 +458,7 @@ void handle_pistorm_dev_write(uint32_t addr_, uint32_t val, uint8_t type) {
                         free(cfg->map_id[index]);
                         cfg->map_type[index] = MAPTYPE_NONE;
                         // Dirty hack, I am tired and lazy.
-                        add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "extended");
+                        add_mapping(cfg, MAPTYPE_ROM, cfg->map_offset[index], cfg->map_size[index], 0, tmp_string, "extended", 0);
                         pi_cmd_result = PI_RES_OK;
                         do_reset = 1;
                     } else {