]> git.sesse.net Git - pistorm/blobdiff - platforms/amiga/amiga-platform.c
tidy up headers, remove extraneous duplicate decls
[pistorm] / platforms / amiga / amiga-platform.c
index c4bcf0041f2a37e28e0eeef21885d15d6e8ec191..5668bb8bdc2bfe016a5318002c5fe4aaebb2ec9b 100644 (file)
@@ -2,25 +2,28 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include "../platforms.h"
 #include "amiga-autoconf.h"
 #include "amiga-registers.h"
-#include "../shared/rtc.h"
-#include "piscsi/piscsi.h"
-#include "piscsi/piscsi-enums.h"
-#include "net/pi-net.h"
+#include "hunk-reloc.h"
 #include "net/pi-net-enums.h"
+#include "net/pi-net.h"
+#include "piscsi/piscsi-enums.h"
+#include "piscsi/piscsi.h"
+#include "platforms/platforms.h"
+#include "platforms/shared/rtc.h"
 #include "rtg/rtg.h"
 
 int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
 int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type);
 int init_rtg_data();
 
+extern int ac_z2_current_pic;
 extern int ac_z2_done;
 extern int ac_z2_pic_count;
 extern int ac_z2_type[AC_PIC_LIMIT];
 extern int ac_z2_index[AC_PIC_LIMIT];
 
+extern int ac_z3_current_pic;
 extern int ac_z3_pic_count;
 extern int ac_z3_done;
 extern int ac_z3_type[AC_PIC_LIMIT];
@@ -42,6 +45,10 @@ extern unsigned char cdtv_sram[32 * SIZE_KILO];
 
 static uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0;
 
+extern uint32_t piscsi_base;
+
+extern void stop_cpu_emulation(uint8_t disasm_cur);
+
 inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
     if (!ac_z2_done && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
         if (ac_z2_pic_count == 0) {
@@ -70,6 +77,13 @@ inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, uns
         }
     }
 
+    if (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);
+        return 1;
+    }
+
     return -1;
 }
 
@@ -108,6 +122,12 @@ inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, un
         }
     }
 
+    if (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;
+    }
+
     return -1;
 }
 
@@ -118,10 +138,6 @@ void adjust_ranges_amiga(struct emulator_config *cfg) {
     cfg->custom_low = 0;
 
     // Set up the min/max ranges for mapped reads/writes
-    if (gayle_emulation_enabled) {
-        cfg->mapped_low = GAYLEBASE;
-        cfg->mapped_high = GAYLEBASE + GAYLESIZE;
-    }
     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
         if (cfg->map_type[i] != MAPTYPE_NONE) {
             if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
@@ -158,6 +174,9 @@ void adjust_ranges_amiga(struct emulator_config *cfg) {
         else
             cfg->custom_low = min(cfg->custom_low, PISCSI_OFFSET);
         cfg->custom_high = max(cfg->custom_high, PISCSI_UPPER);
+        if (piscsi_base != 0) {
+            cfg->custom_low = min(cfg->custom_low, piscsi_base);
+        }
     }
     if (pinet_enabled) {
         if (cfg->custom_low == 0)
@@ -230,7 +249,7 @@ int setup_platform_amiga(struct emulator_config *cfg) {
     index = get_named_mapped_item(cfg, z2_autoconf_id);
     if (index != -1)
         goto more_z2_fast;
-    
+
     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
         // Restore any "zapped" autoconf items so they can be reinitialized if needed.
         if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
@@ -273,7 +292,7 @@ int setup_platform_amiga(struct emulator_config *cfg) {
             fclose(in);
         }
     }
-    
+
     return 0;
 }
 
@@ -319,6 +338,8 @@ 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++;
         adjust_ranges_amiga(cfg);
     }
     if (piscsi_enabled) {
@@ -371,6 +392,11 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) {
 void handle_reset_amiga(struct emulator_config *cfg) {
     ac_z3_done = 0;
     ac_z2_done = 0;
+    ac_z2_current_pic = 0;
+    ac_z3_current_pic = 0;
+
+    if (piscsi_enabled)
+        piscsi_refresh_drives();
 
     adjust_ranges_amiga(cfg);
 }