+// SPDX-License-Identifier: MIT
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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"
#define DEBUG(...)
#endif
-
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;
#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);
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);
}
}
- 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;
}
}
- if (ac_z2_pic_count && (!ac_z2_done || !ac_z3_done)) {
+ if ((ac_z2_pic_count || ac_z3_pic_count) && (!ac_z2_done || !ac_z3_done)) {
if (cfg->custom_low == 0)
cfg->custom_low = AC_Z2_BASE;
else
cfg->custom_low = min(cfg->custom_low, AC_Z2_BASE);
cfg->custom_high = max(cfg->custom_high, AC_Z2_BASE + AC_SIZE);
}
- if (ac_z3_pic_count && !ac_z3_done) {
+ /*if (ac_z3_pic_count && !ac_z3_done) {
if (cfg->custom_low == 0)
cfg->custom_low = AC_Z3_BASE;
else
cfg->custom_low = min(cfg->custom_low, AC_Z3_BASE);
cfg->custom_high = max(cfg->custom_high, AC_Z3_BASE + AC_SIZE);
- }
+ }*/
if (rtg_enabled) {
if (cfg->custom_low == 0)
cfg->custom_low = PIGFX_RTG_BASE;
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) {
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");
}
}
+ if (pistorm_dev_enabled) {
+ add_z2_pic(ACTYPE_PISTORM_DEV, 0);
+ }
+
return 0;
}
cdtv_mode = 1;
}
if (strcmp(var, "rtg") == 0 && !rtg_enabled) {
- if (init_rtg_data()) {
+ if (init_rtg_data(cfg)) {
printf("[AMIGA] RTG Enabled.\n");
rtg_enabled = 1;
adjust_ranges_amiga(cfg);
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) {
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) {
printf("Failed to write CDTV SRAM to disk.\n");
}
}
+ if (cfg->platform->subsys) {
+ free(cfg->platform->subsys);
+ }
+ if (piscsi_enabled) {
+ piscsi_shutdown();
+ piscsi_enabled = 0;
+ }
+ if (rtg_enabled) {
+ shutdown_rtg();
+ rtg_enabled = 0;
+ }
+ if (pinet_enabled) {
+ pinet_enabled = 0;
+ }
+
+ cdtv_mode = 0;
+
+ autoconfig_reset_all();
+ printf("[AMIGA] Platform shutdown completed.\n");
}
void create_platform_amiga(struct platform_config *cfg, char *subsys) {
if (subsys) {
cfg->subsys = malloc(strlen(subsys) + 1);
strcpy(cfg->subsys, subsys);
- for (int i = 0; i < strlen(cfg->subsys); i++) {
+ for (unsigned int i = 0; i < strlen(cfg->subsys); i++) {
cfg->subsys[i] = tolower(cfg->subsys[i]);
}
}