]> git.sesse.net Git - pistorm/commitdiff
Add PiStorm interaction autoconf device
authorbeeanyew <beeanyew@gmail.com>
Thu, 22 Apr 2021 23:55:05 +0000 (01:55 +0200)
committerbeeanyew <beeanyew@gmail.com>
Thu, 22 Apr 2021 23:55:05 +0000 (01:55 +0200)
Makefile
platforms/amiga/amiga-autoconf.c
platforms/amiga/amiga-autoconf.h
platforms/amiga/amiga-platform.c
platforms/amiga/pistorm-dev/pistorm-dev-enums.h [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm-dev.c [new file with mode: 0644]
platforms/amiga/pistorm-dev/pistorm-dev.h [new file with mode: 0644]

index ca69756e3f39d64601ad500143d50556546b52ec..5e193202ec5917371da2b7bd0bd1f5b2abc7cf8a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,7 @@ MAINFILES        = emulator.c \
        platforms/amiga/rtg/rtg-output.c \
        platforms/amiga/rtg/rtg-gfx.c \
        platforms/amiga/piscsi/piscsi.c \
+       platforms/amiga/pistorm-dev/pistorm-dev.c \
        platforms/amiga/net/pi-net.c \
        platforms/shared/rtc.c
 
index ed958ea951968a54019085c29160ef779c83732d..2ace7f8211d2f4c5251248c6ad9a146fb3ef6a7c 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: MIT
 
 #include "platforms/platforms.h"
+#include "pistorm-dev/pistorm-dev-enums.h"
 #include "amiga-autoconf.h"
 #include <stdio.h>
 #include <stdlib.h>
 #define Z2_FAST    0x2
 #define Z2_BOOTROM 0x1
 
+// PiStorm Zorro II AutoConfig Fast RAM ROM
 static unsigned char ac_fast_ram_rom[] = {
     Z2_Z2 | Z2_FAST, AC_MEM_SIZE_8MB,       // 00/02, link into memory free list, 8 MB
     0x6, 0x9,                               // 06/09, product id
     0x8, 0x0,                               // 08/0a, preference to 8 MB space
     0x0, 0x0,                               // 0c/0e, reserved
-    0x0, 0x7, 0xD, 0xB,                     // 10/12/14/16, mfg id
+    PISTORM_AC_MANUF_ID,                    // Manufacturer ID
     0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x0, // 18/.../26, serial
     0x0, 0x0, 0x0, 0x0,                     // Optional BOOT ROM vector
 };
 
+// PiSCSI AutoConfig Device ROM
 unsigned char ac_piscsi_rom[] = {
     Z2_Z2 | Z2_BOOTROM, AC_MEM_SIZE_64KB,   // 00/01, Z2, bootrom, 64 KB
     0x6, 0xA,                               // 06/0A, product id
     0x0, 0x0,                               // 00/0a, any space where it fits
     0x0, 0x0,                               // 0c/0e, reserved
-    0x0, 0x7, 0xD, 0xB,                     // 10/12/14/16, mfg id
+    PISTORM_AC_MANUF_ID,                    // Manufacturer ID
     0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x1, // 18/.../26, serial
     0x4, 0x0, 0x0, 0x0,                     // Optional BOOT ROM vector
 };
 
+// PiStorm Device Interaction ROM
+unsigned char ac_pistorm_rom[] = {
+    Z2_Z2, AC_MEM_SIZE_64KB,                // 00/01, Z2, bootrom, 64 KB
+    0x6, 0xB,                               // 06/0A, product id
+    0x0, 0x0,                               // 00/0a, any space where it fits
+    0x0, 0x0,                               // 0c/0e, reserved
+    PISTORM_AC_MANUF_ID,                    // Manufacturer ID
+    0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x2, // 18/.../26, serial
+    0x4, 0x0, 0x0, 0x0,                     // Optional BOOT ROM vector
+};
+
+// A314 Emulation ROM (currently unused)
 static unsigned char ac_a314_rom[] = {
     0xc, AC_MEM_SIZE_64KB,                  // 00/02, 64 kB
     0xa, 0x3,                               // 04/06, product id
@@ -53,7 +68,7 @@ int ac_z3_done = 0;
 int ac_z3_type[AC_PIC_LIMIT];
 int ac_z3_index[AC_PIC_LIMIT];
 
-uint32_t piscsi_base = 0;
+uint32_t piscsi_base = 0, pistorm_dev_base = 0;
 extern uint8_t *piscsi_rom_ptr;
 
 unsigned char get_autoconf_size(int size) {
@@ -201,7 +216,7 @@ 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 [B]\n", ac_base[ac_z3_current_pic]);
+    printf("[AUTOCONF] 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]);
@@ -233,7 +248,7 @@ void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int add
   }
 
   if (done) {
-    printf("Address of Z3 autoconf RAM assigned to $%.8x [W]\n", ac_base[ac_z3_current_pic]);
+    printf("[AUTOCONF] 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]);
@@ -247,6 +262,40 @@ void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int add
   return;
 }
 
+void add_z2_pic(uint8_t type, uint8_t index) {
+  if (ac_z2_pic_count < AC_PIC_LIMIT) {
+    ac_z2_type[ac_z2_pic_count] = type;
+    ac_z2_index[ac_z2_pic_count] = index;
+    ac_z2_pic_count++;
+    return;
+  }
+  printf("[AUTOCONF] Failed to add Z2 PIC of type %d, limit exceeded.\n", type);
+}
+
+void remove_z2_pic(uint8_t type, uint8_t index) {
+  uint8_t pic_found = 0;
+  if (index) {}
+
+  for (uint32_t i = 0; i < ac_z2_pic_count; i++) {
+    if (ac_z2_type[i] == type && !pic_found) {
+      pic_found = 1;
+    }
+    if (pic_found && i < AC_PIC_LIMIT - 1) {
+      ac_z2_type[i] = ac_z2_type[i + 1];
+      ac_z2_index[i] = ac_z2_index[ i + 1];
+    }
+  }
+
+  if (pic_found) {
+    ac_z2_type[AC_PIC_LIMIT - 1] = ACTYPE_NONE;
+    ac_z2_index[AC_PIC_LIMIT - 1] = 0;
+    ac_z2_pic_count--;
+  }
+  else {
+    printf("[AUTOCONF] Tried to remove Z2 PIC of type %d, but it wasn't found.\n", type);
+  }
+}
+
 unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address) {
   unsigned char *rom = NULL;
   unsigned char val = 0;
@@ -261,6 +310,9 @@ unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int
     case ACTYPE_PISCSI:
       rom = ac_piscsi_rom;
       break;
+    case ACTYPE_PISTORM_DEV:
+      rom = ac_pistorm_rom;
+      break;
     default:
       return 0;
       break;
@@ -300,6 +352,9 @@ void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address
     case ACTYPE_PISCSI:
       base = &piscsi_base;
       break;
+    case ACTYPE_PISTORM_DEV:
+      base = &pistorm_dev_base;
+      break;
     default:
       break;
   }
@@ -330,14 +385,17 @@ void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address
       case ACTYPE_MAPFAST_Z2:
         cfg->map_offset[index] = ac_base[ac_z2_current_pic];
         cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
-        printf("Address of Z2 autoconf RAM assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
+        printf("[AUTOCONF] Address of Z2 autoconf RAM assigned to $%.8X\n", ac_base[ac_z2_current_pic]);
         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);
+        printf("[AUTOCONF] 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);
         break;
       case ACTYPE_PISCSI:
-        printf("PiSCSI Z2 device assigned to $%.8x\n", piscsi_base);
+        printf("[AUTOCONF] PiSCSI Z2 device assigned to $%.8X\n", piscsi_base);
         //m68k_add_rom_range(piscsi_base + (16 * SIZE_KILO), piscsi_base + (32 * SIZE_KILO), piscsi_rom_ptr);
         break;
+      case ACTYPE_PISTORM_DEV:
+        printf("[AUTOCONF] PiStorm Interaction Z2 Device assigned to $%.8X\n", pistorm_dev_base);
+        break;
       default:
         break;
     }
index 0ca3db54ccc89210675eea5423a688569270a284..22eebbfb2df416611ec7ae2fb59b4add4417f15d 100644 (file)
@@ -5,7 +5,7 @@
 #define AC_Z2_BASE 0xE80000
 #define AC_Z3_BASE 0xFF000000
 #define AC_SIZE (64 * 1024)
-#define AC_PIC_LIMIT 8
+#define AC_PIC_LIMIT 16
 
 #define AC_MEM_SIZE_8MB 0
 #define AC_MEM_SIZE_64KB 1
 #define AC_MEM_SIZE_EXT_RES 7
 
 enum autoconf_types {
+    ACTYPE_NONE,
     ACTYPE_MAPFAST_Z2,
     ACTYPE_MAPFAST_Z3,
     ACTYPE_A314,
     ACTYPE_PISCSI,
+    ACTYPE_PISTORM_DEV,
     ACTYPE_NUM,
 };
 
@@ -89,3 +91,6 @@ void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address
 unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned int address);
 void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int address, unsigned int value);
 void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int address, unsigned int value);
+
+void add_z2_pic(uint8_t type, uint8_t index);
+void remove_z2_pic(uint8_t type, uint8_t index);
index e3e1a072726ec8b76bae27e78ff255ce6bea97ea..c63c59134c7b612ca90b35eb43f27a6ca028460a 100644 (file)
@@ -11,6 +11,8 @@
 #include "net/pi-net.h"
 #include "piscsi/piscsi-enums.h"
 #include "piscsi/piscsi.h"
+#include "pistorm-dev/pistorm-dev-enums.h"
+#include "pistorm-dev/pistorm-dev.h"
 #include "platforms/platforms.h"
 #include "platforms/shared/rtc.h"
 #include "rtg/rtg.h"
@@ -54,9 +56,9 @@ extern unsigned char cdtv_sram[32 * SIZE_KILO];
 #define min(a, b) (a < b) ? a : b
 #define max(a, b) (a > b) ? a : b
 
-uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0, kick13_mode = 0;
+uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0, kick13_mode = 0, pistorm_dev_enabled = 1;
 
-extern uint32_t piscsi_base;
+extern uint32_t piscsi_base, pistorm_dev_base;
 
 extern void stop_cpu_emulation(uint8_t disasm_cur);
 
@@ -100,7 +102,12 @@ inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, uns
         return -1;
     }
 
-    if (addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) {
+    if (pistorm_dev_enabled && addr >= pistorm_dev_base && addr < pistorm_dev_base + (64 * SIZE_KILO)) {
+        *val = handle_pistorm_dev_read(addr, type);
+        return 1;
+    }
+
+    if (piscsi_enabled && addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) {
         //printf("[Amiga-Custom] %s read from PISCSI base @$%.8X.\n", op_type_names[type], addr);
         //stop_cpu_emulation(1);
         *val = handle_piscsi_read(addr, type);
@@ -162,7 +169,12 @@ inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, un
         }
     }
 
-    if (addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) {
+    if (pistorm_dev_enabled && addr >= pistorm_dev_base && addr < pistorm_dev_base + (64 * SIZE_KILO)) {
+        handle_pistorm_dev_write(addr, val, type);
+        return 1;
+    }
+
+    if (piscsi_enabled && addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) {
         //printf("[Amiga-Custom] %s write to PISCSI base @$%.8x: %.8X\n", op_type_names[type], addr, val);
         handle_piscsi_write(addr, val, type);
         return 1;
@@ -260,7 +272,7 @@ int setup_platform_amiga(struct emulator_config *cfg) {
         cfg->map_id[index][0] = '^';
         int resize_data = 0;
         if (cfg->map_size[index] > 8 * SIZE_MEGA) {
-            printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizng to 8MB.\n");
+            printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizing to 8MB.\n");
             resize_data = 8 * SIZE_MEGA;
         }
         else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
@@ -279,9 +291,10 @@ int setup_platform_amiga(struct emulator_config *cfg) {
             cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
         }
         printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
-        ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
-        ac_z2_index[ac_z2_pic_count] = index;
-        ac_z2_pic_count++;
+        add_z2_pic(ACTYPE_MAPFAST_Z2, index);
+        //ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
+        //ac_z2_index[ac_z2_pic_count] = index;
+        //ac_z2_pic_count++;
     }
     else
         printf("No Z2 Fast RAM configured.\n");
@@ -333,6 +346,10 @@ int setup_platform_amiga(struct emulator_config *cfg) {
         }
     }
 
+    if (pistorm_dev_enabled) {
+        add_z2_pic(ACTYPE_PISTORM_DEV, 0);
+    }
+
     return 0;
 }
 
@@ -382,8 +399,9 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) {
         printf("[AMIGA] PISCSI Interface Enabled.\n");
         piscsi_enabled = 1;
         piscsi_init();
-        ac_z2_type[ac_z2_pic_count] = ACTYPE_PISCSI;
-        ac_z2_pic_count++;
+        add_z2_pic(ACTYPE_PISCSI, 0);
+        //ac_z2_type[ac_z2_pic_count] = ACTYPE_PISCSI;
+        //ac_z2_pic_count++;
         adjust_ranges_amiga(cfg);
     }
     if (piscsi_enabled) {
@@ -418,6 +436,11 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) {
         adjust_ranges_amiga(cfg);
     }
 
+    if (strcmp(var, "no-pistorm-dev") == 0) {
+        pistorm_dev_enabled = 0;
+        printf("[AMIGA] Disabling PiStorm interaction device.\n");
+    }
+
     // RTC stuff
     if (strcmp(var, "rtc_type") == 0) {
         if (val && strlen(val) != 0) {
diff --git a/platforms/amiga/pistorm-dev/pistorm-dev-enums.h b/platforms/amiga/pistorm-dev/pistorm-dev-enums.h
new file mode 100644 (file)
index 0000000..7c69e49
--- /dev/null
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: MIT
+
+// Currently "2011" / 0x07DB - Defined as "Reserved for Hackers Only" in old Commodore documentation
+#define PISTORM_AC_MANUF_ID 0x0, 0x7, 0xD, 0xB
+
+// [R], [W] and [RW] indicate read, write or both access modes for register
+// Any failure or result code from a write command should be put in PI_CMDRESULT
+enum pistorm_dev_cmds {
+    PI_CMD_RESET        = 0x00, // [W] Reset the host system.
+    PI_CMD_SWITCHCONFIG = 0x02, // [W] Switch config file to string at PI_STR1, if it exists.
+                                //     This will reset the Amiga if the config loads successfully.
+    PI_CMD_PISCSI_CTRL  = 0x04, // [W] Control a PiSCSI device. The command written here uses values
+                                //     From various data registers around $2000.
+    PI_CMD_RTGSTATUS    = 0x06, // [RW] Read: Check RTG status Write: Set RTG status (enabled/disabled)
+    PI_CMD_NETSTATUS    = 0x08, // [RW] Read: Check ETH status Write: Set ETH status (enabled/disabled)
+    PI_CMD_KICKROM      = 0x0A, // [W] Map a different Kickstart ROM to the standard address using
+                                //     the string at PI_STR1, if the file exists. Requires some config
+                                //     file names to be set in order to find it.
+    PI_CMD_EXTROM       = 0x0E, // [W] Same as above, but the extended ROM.
+
+    PI_CMD_HWREV        = 0x10, // [R] Check the PiStorm hardware version/revision
+    PI_CMD_SWREV        = 0x12, // [R] Check the PiStorm software version/revision
+
+    PI_CMD_QBASIC       = 0xFC, // QBasic
+    PI_CMD_NIBBLES      = 0xFE, // Nibbles
+
+    PI_DBG_MSG          = 0x1000, // [W] Trigger debug message output to avoid slow serial kprintf.
+    PI_DBG_VAL1         = 0x1010, // [RW]
+    PI_DBG_VAL2         = 0x1014, // [RW]
+    PI_DBG_VAL3         = 0x1018, // [RW]
+    PI_DBG_VAL4         = 0x101C, // [RW]
+    PI_DBG_VAL5         = 0x1020, // [RW]
+    PI_DBG_VAL6         = 0x1024, // [RW]
+    PI_DBG_VAL7         = 0x1028, // [RW]
+    PI_DBG_VAL8         = 0x102C, // [RW]
+    PI_DBG_STR1         = 0x1030, // [RW] Pointers to debug strings (typically in "Amiga RAM")
+    PI_DBG_STR2         = 0x1034, // [RW]
+    PI_DBG_STR3         = 0x1038, // [RW]
+    PI_DBG_STR4         = 0x103C, // [RW]
+
+    PI_BYTE1            = 0x2000, // [RW] // Bytes, words and longwords used as extended arguments.
+    PI_BYTE2            = 0x2001, // [RW] // for PiStorm interaction device commands.
+    PI_BYTE3            = 0x2002, // [RW]
+    PI_BYTE4            = 0x2003, // [RW]
+    PI_BYTE5            = 0x2004, // [RW]
+    PI_BYTE6            = 0x2005, // [RW]
+    PI_BYTE7            = 0x2006, // [RW]
+    PI_BYTE8            = 0x2007, // [RW]
+    PI_WORD1            = 0x2008, // [RW]
+    PI_WORD2            = 0x200A, // [RW]
+    PI_WORD3            = 0x200C, // [RW]
+    PI_WORD4            = 0x200E, // [RW]
+    PI_LONGWORD1        = 0x2010, // [RW]
+    PI_LONGWORD2        = 0x2014, // [RW]
+    PI_LONGWORD3        = 0x2018, // [RW]
+    PI_LONGWORD4        = 0x201C, // [RW]
+    PI_STR1             = 0x2020, // [RW] Pointers to strings (typically in "Amiga RAM")
+    PI_STR2             = 0x2024, // [RW]
+    PI_STR3             = 0x2028, // [RW]
+    PI_STR4             = 0x202C, // [RW]
+
+    PI_CMDRESULT        = 0x2100, // [R] Check the result of any command that provides a "return value".
+};
diff --git a/platforms/amiga/pistorm-dev/pistorm-dev.c b/platforms/amiga/pistorm-dev/pistorm-dev.c
new file mode 100644 (file)
index 0000000..566790d
--- /dev/null
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: MIT
+
+#include "pistorm-dev.h"
+#include "pistorm-dev-enums.h"
+#include <stdio.h>
+
+#define DEBUG_PISTORM_DEVICE
+
+#ifdef DEBUG_PISTORM_DEVICE
+#define DEBUG printf
+
+static const char *op_type_names[4] = {
+    "BYTE",
+    "WORD",
+    "LONGWORD",
+    "MEM",
+};
+#else
+#define DEBUG(...)
+#endif
+
+extern uint32_t pistorm_dev_base;
+extern uint32_t do_reset;
+
+void handle_pistorm_dev_write(uint32_t addr, uint32_t val, uint8_t type) {
+    switch((addr & 0xFFFF)) {
+        case PI_CMD_RESET:
+            DEBUG("[PISTORM-DEV] System reset called through PiStorm interaction device, code %.4X\n", (val & 0xFFFF));
+            do_reset = 1;
+            break;
+        default:
+            DEBUG("[PISTORM-DEV] WARN: Unhandled %s register write to %.4X: %d\n", op_type_names[type], addr - pistorm_dev_base, val);
+            break;
+    }
+}
+uint32_t handle_pistorm_dev_read(uint32_t addr, uint8_t type) {
+    switch((addr & 0xFFFF)) {
+
+        default:
+            DEBUG("[PISTORM-DEV] WARN: Unhandled %s register read from %.4X\n", op_type_names[type], addr - pistorm_dev_base);
+            break;
+    }
+    return 0;
+}
diff --git a/platforms/amiga/pistorm-dev/pistorm-dev.h b/platforms/amiga/pistorm-dev/pistorm-dev.h
new file mode 100644 (file)
index 0000000..20b8de1
--- /dev/null
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: MIT
+
+#include <stdint.h>
+
+void handle_pistorm_dev_write(uint32_t addr, uint32_t val, uint8_t type);
+uint32_t handle_pistorm_dev_read(uint32_t addr, uint8_t type);