From e721d3c0f752daad0098ee043e90ab56f0de36cb Mon Sep 17 00:00:00 2001 From: beeanyew Date: Sat, 10 Apr 2021 04:58:22 +0200 Subject: [PATCH] Allow Z3 PICs to be configured in Z2 autoconf address space This allows Z3 Fast RAM to be used with Kickstarts that do not explicitly automatically configure Zorro III devices. --- platforms/amiga/amiga-autoconf.c | 20 +++--- platforms/amiga/amiga-autoconf.h | 6 +- platforms/amiga/amiga-platform.c | 105 ++++++++++++++++++++++--------- 3 files changed, 87 insertions(+), 44 deletions(-) diff --git a/platforms/amiga/amiga-autoconf.c b/platforms/amiga/amiga-autoconf.c index 9fb849d..55d46bb 100644 --- a/platforms/amiga/amiga-autoconf.c +++ b/platforms/amiga/amiga-autoconf.c @@ -86,13 +86,13 @@ unsigned char get_autoconf_size_ext(int size) { extern void adjust_ranges_amiga(struct emulator_config *cfg); -unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned int address_) { - int address = address_ - AC_Z3_BASE; +unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned int address) { int index = ac_z3_index[ac_z3_current_pic]; unsigned char val = 0; - if ((address & 0xFF) >= AC_Z3_REG_RES50 && (address & 0xFF) <= AC_Z3_REG_RES7C) + if ((address & 0xFF) >= AC_Z3_REG_RES50 && (address & 0xFF) <= AC_Z3_REG_RES7C) { val = 0; + } else { switch(address & 0xFF) { case AC_Z3_REG_ER_TYPE: @@ -146,6 +146,8 @@ unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned i case AC_Z3_REG_ER_RES0E: case AC_Z3_REG_ER_RES0F: case AC_Z3_REG_ER_Z2_INT: + val = 0; + break; default: val = 0; break; @@ -157,8 +159,7 @@ unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned i int nib_latch = 0; -void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) { - int address = address_ - AC_Z3_BASE; +void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int address, unsigned int value) { int index = ac_z3_index[ac_z3_current_pic]; unsigned char val = (unsigned char)value; int done = 0; @@ -212,8 +213,7 @@ void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int addr return; } -void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int address_, unsigned int value) { - int address = address_ - AC_Z3_BASE; +void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int address, unsigned int value) { int index = ac_z3_index[ac_z3_current_pic]; unsigned short val = (unsigned short)value; int done = 0; @@ -243,9 +243,8 @@ void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int add return; } -unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address_) { +unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address) { unsigned char *rom = NULL; - int address = address_ - AC_Z2_BASE; unsigned char val = 0; switch(ac_z2_type[ac_z2_current_pic]) { @@ -281,8 +280,7 @@ unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int return (unsigned int)val; } -void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) { - int address = address_ - AC_Z2_BASE; +void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address, unsigned int value) { int done = 0; int index = ac_z2_index[ac_z2_current_pic]; diff --git a/platforms/amiga/amiga-autoconf.h b/platforms/amiga/amiga-autoconf.h index 554b6c6..b7484de 100644 --- a/platforms/amiga/amiga-autoconf.h +++ b/platforms/amiga/amiga-autoconf.h @@ -84,6 +84,6 @@ enum autoconfg_z3_regs { unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address); void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address, unsigned int value); -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); +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); diff --git a/platforms/amiga/amiga-platform.c b/platforms/amiga/amiga-platform.c index 5668bb8..1ea192f 100644 --- a/platforms/amiga/amiga-platform.c +++ b/platforms/amiga/amiga-platform.c @@ -13,6 +13,15 @@ #include "platforms/shared/rtc.h" #include "rtg/rtg.h" +//#define DEBUG_AMIGA_PLATFORM + +#ifdef DEBUG_AMIGA_PLATFORM +#define DEBUG printf +#else +#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(); @@ -43,22 +52,36 @@ extern unsigned char cdtv_sram[32 * SIZE_KILO]; #define min(a, b) (a < b) ? a : b #define max(a, b) (a > b) ? a : b -static uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0; +uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0, kick13_mode = 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) { - ac_z2_done = 1; + if (kick13_mode) + ac_z3_done = 1; + + if ((!ac_z2_done || !ac_z3_done) && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) { + if (!ac_z2_done && ac_z2_current_pic < ac_z2_pic_count) { + if (type == OP_TYPE_BYTE) { + *val = autoconfig_read_memory_8(cfg, addr - AC_Z2_BASE); + return 1; + } + printf("Unexpected %s read from Z2 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE); return -1; } - - if (type == OP_TYPE_BYTE) { - *val = autoconfig_read_memory_8(cfg, addr); - return 1; + if (!ac_z3_done && ac_z3_current_pic < ac_z3_pic_count) { + uint32_t addr_ = addr - AC_Z2_BASE; + if (addr_ & 0x02) { + addr_ = (addr_ - 2) + 0x100; + } + if (type == OP_TYPE_BYTE) { + *val = autoconfig_read_memory_z3_8(cfg, addr_ - AC_Z2_BASE); + return 1; + } + printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE); + return -1; } } if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) { @@ -68,13 +91,11 @@ inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, uns } if (type == OP_TYPE_BYTE) { - *val = autoconfig_read_memory_z3_8(cfg, addr); + *val = autoconfig_read_memory_z3_8(cfg, addr - AC_Z3_BASE); return 1; } - else { - printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE); - //stop_emulation(); - } + printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE); + return -1; } if (addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) { @@ -88,16 +109,33 @@ inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, uns } inline int custom_write_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 (type == OP_TYPE_BYTE) { - if (ac_z2_pic_count == 0) { - ac_z2_done = 1; - return -1; - } + if (kick13_mode) + ac_z3_done = 1; - //printf("Write to Z2 autoconf area.\n"); - autoconfig_write_memory_8(cfg, addr, val); - return 1; + if ((!ac_z2_done || !ac_z3_done) && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) { + if (!ac_z2_done && ac_z2_current_pic < ac_z2_pic_count) { + if (type == OP_TYPE_BYTE) { + autoconfig_write_memory_8(cfg, addr - AC_Z2_BASE, val); + return 1; + } + printf("Unexpected %s write to Z2 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE); + return -1; + } + if (!ac_z3_done && ac_z3_current_pic < ac_z3_pic_count) { + uint32_t addr_ = addr - AC_Z2_BASE; + if (addr_ & 0x02) { + addr_ = (addr_ - 2) + 0x100; + } + if (type == OP_TYPE_BYTE) { + autoconfig_write_memory_z3_8(cfg, addr_ - AC_Z2_BASE, val); + return 1; + } + else if (type == OP_TYPE_WORD) { + autoconfig_write_memory_z3_16(cfg, addr_ - AC_Z2_BASE, val); + return 1; + } + printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE); + return -1; } } @@ -109,11 +147,11 @@ inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, un } //printf("Write to autoconf area.\n"); - autoconfig_write_memory_z3_8(cfg, addr, val); + autoconfig_write_memory_z3_8(cfg, addr - AC_Z3_BASE, val); return 1; } else if (type == OP_TYPE_WORD) { - autoconfig_write_memory_z3_16(cfg, addr, val); + autoconfig_write_memory_z3_16(cfg, addr - AC_Z3_BASE, val); return 1; } else { @@ -147,7 +185,7 @@ void adjust_ranges_amiga(struct emulator_config *cfg) { } } - if (ac_z2_pic_count && !ac_z2_done) { + if (ac_z2_pic_count && (!ac_z2_done || !ac_z3_done)) { if (cfg->custom_low == 0) cfg->custom_low = AC_Z2_BASE; else @@ -323,7 +361,7 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) { printf("[AMIGA] CDTV mode enabled.\n"); cdtv_mode = 1; } - if (strcmp(var, "rtg") == 0) { + if (strcmp(var, "rtg") == 0 && !rtg_enabled) { if (init_rtg_data()) { printf("[AMIGA] RTG Enabled.\n"); rtg_enabled = 1; @@ -332,9 +370,13 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) { else printf("[AMIGA} Failed to enable RTG.\n"); } + if (strcmp(var, "kick13") == 0) { + printf("[AMIGA] Kickstart 1.3 mode enabled, Z3 PICs will not be enumerated.\n"); + kick13_mode = 1; + } // PiSCSI stuff - if (strcmp(var, "piscsi") == 0) { + if (strcmp(var, "piscsi") == 0 && !piscsi_enabled) { printf("[AMIGA] PISCSI Interface Enabled.\n"); piscsi_enabled = 1; piscsi_init(); @@ -367,7 +409,7 @@ void setvar_amiga(struct emulator_config *cfg, char *var, char *val) { } // Pi-Net stuff - if (strcmp(var, "pi-net") == 0) { + if (strcmp(var, "pi-net") == 0 && !pinet_enabled) { printf("[AMIGA] PI-NET Interface Enabled.\n"); pinet_enabled = 1; pinet_init(val); @@ -390,11 +432,14 @@ 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_done = (ac_z2_pic_count == 0); + ac_z3_done = (ac_z3_pic_count == 0); ac_z2_current_pic = 0; ac_z3_current_pic = 0; + DEBUG("[AMIGA] Reset handler.\n"); + DEBUG("[AMIGA] AC done - Z2: %d Z3: %d.\n", ac_z2_done, ac_z3_done); + if (piscsi_enabled) piscsi_refresh_drives();