]> git.sesse.net Git - pistorm/commitdiff
Plug some read/write mappings directly into Musashi
authorbeeanyew <beeanyew@gmail.com>
Thu, 31 Dec 2020 11:15:42 +0000 (12:15 +0100)
committerbeeanyew <beeanyew@gmail.com>
Thu, 31 Dec 2020 11:15:42 +0000 (12:15 +0100)
m68k.h
m68kcpu.c
m68kcpu.h
platforms/amiga/amiga-autoconf.c
platforms/amiga/amiga-platform.c

diff --git a/m68k.h b/m68k.h
index 555b314f04f81f773f232d618b2951cf13f0955b..e005ca92380977253396fcf539df2bb93fe53f5f 100644 (file)
--- a/m68k.h
+++ b/m68k.h
@@ -199,6 +199,10 @@ void m68k_write_memory_8(unsigned int address, unsigned int value);
 void m68k_write_memory_16(unsigned int address, unsigned int value);
 void m68k_write_memory_32(unsigned int address, unsigned int value);
 
+/* PiStorm speed hax */
+void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr);
+void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr);
+
 /* Special call to simulate undocumented 68k behavior when move.l with a
  * predecrement destination mode is executed.
  * To simulate real 68k behavior, first write the high word to
index 1012799450e1c21152a2e2739c5fa7faacaa4ddc..cc549570f68db7ef3d0ee163995c78d9b0a69c19 100644 (file)
--- a/m68kcpu.c
+++ b/m68kcpu.c
@@ -45,6 +45,15 @@ extern unsigned char m68ki_cycles[][0x10000];
 extern void (*m68ki_instruction_jump_table[0x10000])(void); /* opcode handler jump table */
 extern void m68ki_build_opcode_table(void);
 
+static unsigned char read_ranges;
+static unsigned int read_addr[8];
+static unsigned int read_upper[8];
+static unsigned char *read_data[8];
+static unsigned char write_ranges;
+static unsigned int write_addr[8];
+static unsigned int write_upper[8];
+static unsigned char *write_data[8];
+
 #include "m68kops.h"
 #include "m68kcpu.h"
 
@@ -1165,6 +1174,44 @@ void m68k_set_context(void* src)
        if(src) m68ki_cpu = *(m68ki_cpu_core*)src;
 }
 
+void m68k_add_ram_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
+{
+       if (read_ranges + 1 < 8) {
+               read_addr[read_ranges] = addr;
+               read_upper[read_ranges] = upper;
+               read_data[read_ranges] = ptr;
+               read_ranges++;
+               printf("[MUSASHI] Mapped read range %d: %.8X-%.8X (%p)\n", read_ranges, addr, upper, ptr);
+       }
+       else {
+               printf("Can't Musashi map more than eight RAM/ROM read ranges.\n");
+       }
+       if (write_ranges + 1 < 8) {
+               write_addr[write_ranges] = addr;
+               write_upper[write_ranges] = upper;
+               write_data[write_ranges] = ptr;
+               write_ranges++;
+               printf("[MUSASHI] Mapped write range %d: %.8X-%.8X (%p)\n", write_ranges, addr, upper, ptr);
+       }
+       else {
+               printf("Can't Musashi map more than eight RAM write ranges.\n");
+       }
+}
+
+void m68k_add_rom_range(uint32_t addr, uint32_t upper, unsigned char *ptr)
+{
+       if (read_ranges + 1 < 8) {
+               read_addr[read_ranges] = addr;
+               read_upper[read_ranges] = upper;
+               read_data[read_ranges] = ptr;
+               read_ranges++;
+               printf("[MUSASHI] Mapped read range %d: %.8X-%.8X (%p)\n", read_ranges, addr, upper, ptr);
+       }
+       else {
+               printf("Can't Musashi map more than eight RAM/ROM read ranges.\n");
+       }
+}
+
 /* ======================================================================== */
 /* ============================== MAME STUFF ============================== */
 /* ======================================================================== */
index 467169b0e6e8f39716eab0cd732ed645b003a863..0ba7aee5bd668bb714fdf276383528c087028acc 100644 (file)
--- a/m68kcpu.h
+++ b/m68kcpu.h
@@ -40,6 +40,7 @@ extern "C" {
 #include "m68k.h"
 
 #include <limits.h>
+#include <endian.h>
 
 #include <setjmp.h>
 
@@ -1124,6 +1125,16 @@ static inline uint m68ki_read_imm_32(void)
  * These functions will also check for address error and set the function
  * code if they are enabled in m68kconf.h.
  */
+
+static unsigned char read_ranges;
+static unsigned int read_addr[8];
+static unsigned int read_upper[8];
+static unsigned char *read_data[8];
+static unsigned char write_ranges;
+static unsigned int write_addr[8];
+static unsigned int write_upper[8];
+static unsigned char *write_data[8];
+
 static inline uint m68ki_read_8_fc(uint address, uint fc)
 {
        (void)fc;
@@ -1134,6 +1145,12 @@ static inline uint m68ki_read_8_fc(uint address, uint fc)
            address = pmmu_translate_addr(address);
 #endif
 
+       for (int i = 0; i < read_ranges; i++) {
+               if(address >= read_addr[i] && address < read_upper[i]) {
+                       return read_data[i][address];
+               }
+       }
+
        return m68k_read_memory_8(ADDRESS_68K(address));
 }
 static inline uint m68ki_read_16_fc(uint address, uint fc)
@@ -1147,6 +1164,12 @@ static inline uint m68ki_read_16_fc(uint address, uint fc)
            address = pmmu_translate_addr(address);
 #endif
 
+       for (int i = 0; i < read_ranges; i++) {
+               if(address >= read_addr[i] && address < read_upper[i]) {
+                       return be16toh(((unsigned short *)(read_data[i] + (address - read_addr[i])))[0]);
+               }
+       }
+
        return m68k_read_memory_16(ADDRESS_68K(address));
 }
 static inline uint m68ki_read_32_fc(uint address, uint fc)
@@ -1160,6 +1183,12 @@ static inline uint m68ki_read_32_fc(uint address, uint fc)
            address = pmmu_translate_addr(address);
 #endif
 
+       for (int i = 0; i < read_ranges; i++) {
+               if(address >= read_addr[i] && address < read_upper[i]) {
+                       return be32toh(((unsigned int *)(read_data[i] + (address - read_addr[i])))[0]);
+               }
+       }
+
        return m68k_read_memory_32(ADDRESS_68K(address));
 }
 
@@ -1173,6 +1202,13 @@ static inline void m68ki_write_8_fc(uint address, uint fc, uint value)
            address = pmmu_translate_addr(address);
 #endif
 
+       for (int i = 0; i < write_ranges; i++) {
+               if(address >= write_addr[i] && address < write_upper[i]) {
+                       write_data[i][address] = (unsigned char)value;
+                       return;
+               }
+       }
+
        m68k_write_memory_8(ADDRESS_68K(address), value);
 }
 static inline void m68ki_write_16_fc(uint address, uint fc, uint value)
@@ -1186,6 +1222,13 @@ static inline void m68ki_write_16_fc(uint address, uint fc, uint value)
            address = pmmu_translate_addr(address);
 #endif
 
+       for (int i = 0; i < write_ranges; i++) {
+               if(address >= write_addr[i] && address < write_upper[i]) {
+                       ((short *)(read_data[i] + (address - read_addr[i])))[0] = htobe16(value);
+                       return;
+               }
+       }
+
        m68k_write_memory_16(ADDRESS_68K(address), value);
 }
 static inline void m68ki_write_32_fc(uint address, uint fc, uint value)
@@ -1199,6 +1242,13 @@ static inline void m68ki_write_32_fc(uint address, uint fc, uint value)
            address = pmmu_translate_addr(address);
 #endif
 
+       for (int i = 0; i < write_ranges; i++) {
+               if(address >= write_addr[i] && address < write_upper[i]) {
+                       ((int *)(read_data[i] + (address - read_addr[i])))[0] = htobe32(value);
+                       return;
+               }
+       }
+
        m68k_write_memory_32(ADDRESS_68K(address), value);
 }
 
index b27c0ec67c68f3709e61eb74ada0e4f3690893a3..68f1252469fe9a95c88ef484b21e4e39844eaa00 100644 (file)
@@ -180,9 +180,10 @@ void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int addr
 
   if (done) {
     nib_latch = 0;
-    printf("Address of Z3 autoconf RAM assigned to $%.8x\n", ac_base[ac_z3_current_pic]);
+    printf("Address of Z3 autoconf RAM assigned to $%.8x [B]\n", ac_base[ac_z3_current_pic]);
     cfg->map_offset[index] = ac_base[ac_z3_current_pic];
     cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
+    m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
     ac_z3_current_pic++;
     if (ac_z3_current_pic == ac_z3_pic_count) {
       ac_z3_done = 1;
@@ -201,7 +202,7 @@ void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int add
 
   switch(address & 0xFF) {
     case AC_Z3_REG_WR_ADDR_HI:
-      // This is, as far as I know, the only regiter it should write a 16-bit value to.
+      // This is, as far as I know, the only register it should write a 16-bit value to.
       ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x00000000) | (val << 16);
       done = 1;
       break;
@@ -212,8 +213,10 @@ void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int add
   }
 
   if (done) {
-    printf("Address of Z3 autoconf RAM assigned to $%.8x\n", ac_base[ac_z3_current_pic]);
+    printf("Address of Z3 autoconf RAM assigned to $%.8x [W]\n", ac_base[ac_z3_current_pic]);
     cfg->map_offset[index] = ac_base[ac_z3_current_pic];
+    cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
+    m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
     ac_z3_current_pic++;
     if (ac_z3_current_pic == ac_z3_pic_count)
       ac_z3_done = 1;
@@ -300,6 +303,7 @@ void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address
     printf("Address of Z2 autoconf RAM assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
     cfg->map_offset[index] = ac_base[ac_z2_current_pic];
     cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
+    m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
     printf("Z2 PIC %d at $%.8lX-%.8lX, Size: %d MB\n", ac_z2_current_pic, cfg->map_offset[index], cfg->map_high[index], cfg->map_size[index] / SIZE_MEGA);
     ac_z2_current_pic++;
     if (ac_z2_current_pic == ac_z2_pic_count) {
index c2361e30b91d6f600e7d8049a5b7fb9f66039948..71fd2b5d1c4c1c66bf6584171950c6627adfd8a3 100644 (file)
@@ -138,7 +138,6 @@ void adjust_ranges_amiga(struct emulator_config *cfg) {
 }
 
 int setup_platform_amiga(struct emulator_config *cfg) {
-    if (cfg) {}
     printf("Performing setup for Amiga platform.\n");
     // Look for Z2 autoconf Fast RAM by id
     int index = get_named_mapped_item(cfg, z2_autoconf_id);
@@ -205,6 +204,11 @@ int setup_platform_amiga(struct emulator_config *cfg) {
         }
     }
 
+    index = get_named_mapped_item(cfg, "cpu_slot_ram");
+    if (index != -1) {
+        m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
+    }
+
     adjust_ranges_amiga(cfg);
     
     return 0;