From e721d3c0f752daad0098ee043e90ab56f0de36cb Mon Sep 17 00:00:00 2001 From: beeanyew Date: Sat, 10 Apr 2021 04:58:22 +0200 Subject: [PATCH 1/3] 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(); From e900d9251120c0c58f0b0b3108e6fd690f9bce8b Mon Sep 17 00:00:00 2001 From: beeanyew Date: Sat, 10 Apr 2021 05:01:05 +0200 Subject: [PATCH 2/3] Minor project readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbd63a9..8cc3b4d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # Join us on Discord or on Freenode IRC #PiStorm -* There's a Discord server dedicated to the PiStorm, which you can join through this handy invite link: https://discord.com/invite/j6rPtzxaNW +* There's a Discord server dedicated to PiStorm discussion and development, which you can join through this handy invite link: https://discord.com/invite/j6rPtzxaNW * There's also an IRC channel on the Freenode IRC network, `#PiStorm`, which is bridged with the `#general` channel on Discord. # Project information @@ -25,7 +25,7 @@ Since much of the initial work and testing for the PiStorm was done on Amiga com * Kickstart ROM mapping: 1.3, 2.0, 3.1, anything you might own and have dumped in a byteswapped format. Extended ROM mapping as well for instance with the CDTV extended BIOS. * An A1200 3.1+ Kickstart ROM is currently recommended, as this one has the most dynamic automatic configuration on boot. * Fast RAM: Z2, Z3 and CPU local Fast can be mapped for high performance memory available to the CPU only on the PiStorm side of things. -* Virtual SCSI: PiSCSI, a high performance virtual SCSI interface for mapping raw RDB disk images for physical connected to the Pi for use on the Amiga. +* Virtual SCSI: PiSCSI, a high performance virtual SCSI interface for mapping raw RDB disk images or physical storage devices connected to the Pi for use on the Amiga. * RTG: PiGFX, a virtual RTG board with almost all P96-supported functionality supported and accelerated. * Some other things: Most likely I forgot something while writing this, but someone will probably tell me about it. From b8d10ab70788a854da91a6231263ee3b3ece7ab9 Mon Sep 17 00:00:00 2001 From: beeanyew Date: Sat, 10 Apr 2021 05:06:24 +0200 Subject: [PATCH 3/3] Update default.cfg with some more information --- default.cfg | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/default.cfg b/default.cfg index 0cea4a0..56b55a9 100644 --- a/default.cfg +++ b/default.cfg @@ -5,11 +5,12 @@ map type=rom address=0xF80000 size=0x80000 file=kick.rom ovl=0 # Want to map an extended ROM, such as CDTV or CD32? #map type=rom address=0xF00000 size=0x80000 file=cdtv.rom -# Map 128MB of Fast RAM at 0x8000000. -map type=ram address=0x08000000 size=128M id=cpu_slot_ram +# Map 128MB of Fast RAM at 0x8000000, also known as 32-bit Fast RAM or CPU local Fast RAM. +# Only supported properly on select Kickstarts, such as 3.1+ for Amiga 1200, 3000 and 4000. +#map type=ram address=0x08000000 size=128M id=cpu_slot_ram # Map 128MB of Z3 Fast. Note that the address here is not actually used, as it gets auto-assigned by Kickstart itself. -# Enabling Z3 fast requires a Kickstart that actually supports Zorro III, for instance from an A3000 or A4000. -#map type=ram address=0x10000000 size=128M id=z3_autoconf_fast +# Enabling Z3 fast requires at least Kickstart 2.0. +map type=ram address=0x10000000 size=128M id=z3_autoconf_fast # Max 8MB of Z2 Fast can be mapped due to addressing space limitations, but for instance 2+4MB can be chained to leave 2MB for something else. #map type=ram address=0x200000 size=8M id=z2_autoconf_fast #map type=ram address=0x200000 size=2M id=z2_autoconf_fast