From a3e8a3227f76d7d725e8489ab099024bba0fde6a Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sat, 14 Dec 2024 06:56:00 +0100 Subject: [PATCH 1/5] cleanup sim.h options and checks Guard FAST_BLOCK by !EXCLUDE_Z80. Remove unneeded checks from simdefs.h (already guarded in sim.h) --- altairsim/srcsim/sim.h | 4 +++- cpmsim/srcsim/sim.h | 4 +++- cromemcosim/srcsim/sim.h | 4 +++- imsaisim/srcsim/sim.h | 4 +++- intelmdssim/srcsim/sim.h | 4 +++- mosteksim/srcsim/sim.h | 6 ++++-- picosim/srcsim/sim.h | 4 +++- z80core/simdefs.h | 25 ------------------------- z80sim/srcsim/sim.h.debug | 4 +++- z80sim/srcsim/sim.h.fast | 4 +++- 10 files changed, 28 insertions(+), 35 deletions(-) diff --git a/altairsim/srcsim/sim.h b/altairsim/srcsim/sim.h index 88de8601..d5f472b2 100644 --- a/altairsim/srcsim/sim.h +++ b/altairsim/srcsim/sim.h @@ -38,8 +38,10 @@ #define CPU_SPEED 2 /* default CPU speed */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ +#endif /*#define WANT_ICE*/ /* attach ICE to headless machine */ #ifdef WANT_ICE diff --git a/cpmsim/srcsim/sim.h b/cpmsim/srcsim/sim.h index 20e122a4..2cf62769 100644 --- a/cpmsim/srcsim/sim.h +++ b/cpmsim/srcsim/sim.h @@ -15,8 +15,10 @@ #define CPU_SPEED 0 /* default CPU speed 0=unlimited */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 #define FAST_BLOCK /* much faster but not accurate Z80 block instr. */ +#endif /*#define WANT_ICE*/ /* attach ICE to machine */ #ifdef WANT_ICE diff --git a/cromemcosim/srcsim/sim.h b/cromemcosim/srcsim/sim.h index 68e22a0e..24ee5c16 100644 --- a/cromemcosim/srcsim/sim.h +++ b/cromemcosim/srcsim/sim.h @@ -39,8 +39,10 @@ #define CPU_SPEED 4 /* default CPU speed */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ +#endif /*#define WANT_ICE*/ /* attach ICE to headless machine */ #ifdef WANT_ICE diff --git a/imsaisim/srcsim/sim.h b/imsaisim/srcsim/sim.h index 97e33bfb..b721c334 100644 --- a/imsaisim/srcsim/sim.h +++ b/imsaisim/srcsim/sim.h @@ -39,8 +39,10 @@ #define CPU_SPEED 2 /* default CPU speed */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ +#endif /*#define WANT_ICE*/ /* attach ICE to headless machine */ #ifdef WANT_ICE diff --git a/intelmdssim/srcsim/sim.h b/intelmdssim/srcsim/sim.h index 730374e2..d5ba18f4 100644 --- a/intelmdssim/srcsim/sim.h +++ b/intelmdssim/srcsim/sim.h @@ -23,8 +23,10 @@ #define EXCLUDE_Z80 /* Intel Intellec MDS-800 was an 8080 machine */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ +#endif /*#define WANT_ICE*/ /* attach ICE to headless machine */ #ifdef WANT_ICE diff --git a/mosteksim/srcsim/sim.h b/mosteksim/srcsim/sim.h index 66f2f91b..0e1cbaf0 100644 --- a/mosteksim/srcsim/sim.h +++ b/mosteksim/srcsim/sim.h @@ -22,11 +22,13 @@ */ #define DEF_CPU Z80 /* default CPU (Z80 or I8080) */ #define CPU_SPEED 0 /* default CPU speed 0=unlimited */ +#define EXCLUDE_I8080 /* this was a Z80 machine */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ -#define EXCLUDE_I8080 /* this was a Z80 machine */ +#endif #define WANT_ICE /* attach ICE to headless machine */ #ifdef WANT_ICE diff --git a/picosim/srcsim/sim.h b/picosim/srcsim/sim.h index 018bdaec..f3f0f96d 100644 --- a/picosim/srcsim/sim.h +++ b/picosim/srcsim/sim.h @@ -14,8 +14,10 @@ #define CPU_SPEED 4 /* CPU speed 0=unlimited */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ +#endif #define BAREMETAL /* set up the simulator core for bare metal use */ /*#define WANT_ICE*/ /* attach ICE to headless machine */ diff --git a/z80core/simdefs.h b/z80core/simdefs.h index 7ba37acd..e931bb31 100644 --- a/z80core/simdefs.h +++ b/z80core/simdefs.h @@ -34,33 +34,8 @@ #if defined(EXCLUDE_Z80) && DEF_CPU != I8080 #error "DEF_CPU=Z80 and no Z80 simulation included" #endif -#if defined(EXCLUDE_Z80) && defined(FAST_BLOCK) -#error "FAST_BLOCK makes only sense without EXCLUDE_Z80" -#endif #if (defined(ALT_I8080) || defined(ALT_Z80)) && !defined(UNDOC_INST) #error "UNDOC_INST required for alternate simulators" -#endif -#ifdef HISIZE -#ifndef WANT_ICE -#error "WANT_ICE required for HISIZE" -#endif -#if HISIZE < 1 || HISIZE > 1000 -#error "HISIZE must be between 1 and 1000" -#endif -#endif /* HISIZE */ -#ifdef SBSIZE -#ifndef WANT_ICE -#error "WANT_ICE required for SBSIZE" -#endif -#if SBSIZE < 1 || SBSIZE > 10 -#error "SBSIZE must be between 1 and 10" -#endif -#endif /* SBSIZE */ -#if defined(WANT_TIM) && !defined(WANT_ICE) -#error "WANT_ICE required for WANT_TIM" -#endif -#if defined(WANT_HB) && !defined(WANT_ICE) -#error "WANT_ICE required for WANT_HB" #endif /* bit definitions of CPU flags */ diff --git a/z80sim/srcsim/sim.h.debug b/z80sim/srcsim/sim.h.debug index 590c2389..5acb4317 100644 --- a/z80sim/srcsim/sim.h.debug +++ b/z80sim/srcsim/sim.h.debug @@ -17,8 +17,10 @@ #define CPU_SPEED 0 /* default CPU speed 0=unlimited */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -/*#define UNDOC_INST*/ /* compile undocumented instructions */ +/*#define UNDOC_INST*/ /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 /*#define FAST_BLOCK*/ /* much faster but not accurate Z80 block instr. */ +#endif #define WANT_ICE /* attach ICE to headless machine */ #ifdef WANT_ICE diff --git a/z80sim/srcsim/sim.h.fast b/z80sim/srcsim/sim.h.fast index 21b9843e..73d1d813 100644 --- a/z80sim/srcsim/sim.h.fast +++ b/z80sim/srcsim/sim.h.fast @@ -18,8 +18,10 @@ #define CPU_SPEED 0 /* default CPU speed 0=unlimited */ /*#define ALT_I8080*/ /* use alt. 8080 sim. primarily optimized for size */ /*#define ALT_Z80*/ /* use alt. Z80 sim. primarily optimized for size */ -#define UNDOC_INST /* compile undocumented instructions */ +#define UNDOC_INST /* compile undocumented instrs. (required by ALT_*) */ +#ifndef EXCLUDE_Z80 #define FAST_BLOCK /* much faster but not accurate Z80 block instr. */ +#endif #define WANT_ICE /* attach ICE to headless machine */ #ifdef WANT_ICE From c3e054f2149647210a90486bd22a190909784892 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sat, 14 Dec 2024 07:09:32 +0100 Subject: [PATCH 2/5] simice: clean-up optional features messages --- z80core/simice.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/z80core/simice.c b/z80core/simice.c index 6287bdd5..9cf5b508 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -864,21 +864,20 @@ static void print_reg(void) */ static void do_break(char *s) { -#if !defined(SBSIZE) && !defined(WANT_HB) - UNUSED(s); - - puts("Sorry, no breakpoints available"); - puts("Please recompile with SBSIZE and/or WANT_HB defined in sim.h"); -#else /* SBSIZE || WANT_HB */ +#if defined(SBSIZE) || defined(WANT_HB) WORD a; int n; #ifdef SBSIZE register int i; int hdr_flag; +#endif #endif -#ifdef WANT_HB if (*s == 'h') { +#ifndef WANT_HB + puts("Sorry, no hardware breakpoint available"); + puts("Please recompile with WANT_HB defined in sim.h"); +#else /* WANT_HB */ s++; if (*s == '\n') { if (hb_flag) { @@ -947,10 +946,13 @@ static void do_break(char *s) hb_addr = a; hb_mode = n; hb_flag = 1; +#endif /* WANT_HB */ return; } -#endif /* WANT_HB */ -#ifdef SBSIZE +#ifndef SBSIZE + puts("Sorry, no software breakpoints available"); + puts("Please recompile with SBSIZE defined in sim.h"); +#else /* SBSIZE */ if (*s == '\n') { hdr_flag = 0; for (i = 0; i < SBSIZE; i++) @@ -1042,7 +1044,6 @@ static void do_break(char *s) soft[i].sb_passcount = 0; } #endif /* SBSIZE */ -#endif /* SBSIZE || WANT_HB */ } /* @@ -1259,7 +1260,7 @@ static void do_show(void) #else i = 0; #endif - printf("T-State counting %spossible\n", i ? "" : "im"); + printf("T-State counting %spossible\n", i ? "" : "not "); } /* From 55da80b44bdcbc1ae2ee8611f689a6177351266f Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sat, 14 Dec 2024 07:26:25 +0100 Subject: [PATCH 3/5] sync with RP2xxx-GEEK-80 order --- z80sim/srcsim/simmem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/z80sim/srcsim/simmem.h b/z80sim/srcsim/simmem.h index a23ee569..3ce5eca6 100644 --- a/z80sim/srcsim/simmem.h +++ b/z80sim/srcsim/simmem.h @@ -60,8 +60,8 @@ static inline BYTE memrdr(WORD addr) data = memory[addr]; #ifdef BUS_8080 - cpu_bus |= CPU_WO | CPU_MEMR; cpu_bus &= ~CPU_M1; + cpu_bus |= CPU_WO | CPU_MEMR; #endif return data; From 800779e0e89bdceb252e970c28691ac0d3a87f98 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sat, 14 Dec 2024 07:52:27 +0100 Subject: [PATCH 4/5] add hardware breakpoint support to picosim So we can test performance impact. --- picosim/srcsim/sim.h | 1 + picosim/srcsim/simmem.h | 40 ++++++++++++++++++++++++++++++++++++++-- z80sim/srcsim/simmem.h | 4 ++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/picosim/srcsim/sim.h b/picosim/srcsim/sim.h index f3f0f96d..7d5e6192 100644 --- a/picosim/srcsim/sim.h +++ b/picosim/srcsim/sim.h @@ -25,6 +25,7 @@ #define WANT_TIM /* count t-states */ #define HISIZE 100 /* number of entries in history */ #define SBSIZE 4 /* number of software breakpoints */ +#define WANT_HB /* hardware breakpoint */ #endif #if PICO_RP2040 diff --git a/picosim/srcsim/simmem.h b/picosim/srcsim/simmem.h index d00f14c4..7e9714ce 100644 --- a/picosim/srcsim/simmem.h +++ b/picosim/srcsim/simmem.h @@ -15,6 +15,13 @@ #include "sim.h" #include "simdefs.h" +#ifdef WANT_ICE +#include "simice.h" +#endif + +#ifdef BUS_8080 +#include "simglb.h" +#endif extern BYTE bnk0[65536], bnk1[49152]; extern BYTE selbnk; @@ -30,6 +37,15 @@ extern void init_memory(void), reset_memory(void); */ static inline void memwrt(WORD addr, BYTE data) { +#ifdef BUS_8080 + cpu_bus &= ~(CPU_M1 | CPU_WO | CPU_MEMR); +#endif + +#ifdef WANT_HB + if (hb_flag && hb_addr == addr && (hb_mode & HB_WRITE)) + hb_trig = HB_WRITE; +#endif + if ((selbnk == 0) || (addr >= 0xc000)) { if (addr < 0xff00) bnk0[addr] = data; @@ -40,10 +56,30 @@ static inline void memwrt(WORD addr, BYTE data) static inline BYTE memrdr(WORD addr) { + register BYTE data; + +#ifdef WANT_HB + if (hb_flag && hb_addr == addr) { + if (cpu_bus & CPU_M1) { + if (hb_mode & HB_EXEC) + hb_trig = HB_EXEC; + } else { + if (hb_mode & HB_READ) + hb_trig = HB_READ; + } + } +#endif if ((selbnk == 0) || (addr >= 0xc000)) - return bnk0[addr]; + data = bnk0[addr]; else - return bnk1[addr]; + data = bnk1[addr]; + +#ifdef BUS_8080 + cpu_bus &= ~CPU_M1; + cpu_bus |= CPU_WO | CPU_MEMR; +#endif + + return data; } /* diff --git a/z80sim/srcsim/simmem.h b/z80sim/srcsim/simmem.h index 3ce5eca6..08db58ce 100644 --- a/z80sim/srcsim/simmem.h +++ b/z80sim/srcsim/simmem.h @@ -21,6 +21,10 @@ #include "simice.h" #endif +#ifdef BUS_8080 +#include "simglb.h" +#endif + extern BYTE memory[65536]; extern void init_memory(void); From da0f20527ff1c2e0faf547ad2f89512240fd171d Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sat, 14 Dec 2024 08:22:43 +0100 Subject: [PATCH 5/5] simice: fixes for picosim Also check for '\0' for 'b' and 'bh'. Don't mix f* stdio calls with non-f*. --- z80core/simice.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/z80core/simice.c b/z80core/simice.c index 9cf5b508..d2ebac9c 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -369,7 +369,7 @@ static int handle_break(void) fputs("write", stdout); else fputs("execute", stdout); - printf(" access to %04x\n", hb_addr); + fprintf(stdout, " access to %04x\n", hb_addr); hb_trig = 0; cpu_error = NONE; return 0; @@ -879,7 +879,7 @@ static void do_break(char *s) puts("Please recompile with WANT_HB defined in sim.h"); #else /* WANT_HB */ s++; - if (*s == '\n') { + if (*s == '\n' || *s == '\0') { if (hb_flag) { fputs("Hardware breakpoint set with ", stdout); n = 0; @@ -889,16 +889,17 @@ static void do_break(char *s) } if (hb_mode & HB_WRITE) { if (n) - putchar('/'); + fputc('/', stdout); fputs("write", stdout); n = 1; } if (hb_mode & HB_EXEC) { if (n) - putchar('/'); + fputc('/', stdout); fputs("execute", stdout); } - printf(" access trigger to %04x\n", hb_addr); + fprintf(stdout, " access trigger to %04x\n", + hb_addr); } else puts("No hardware breakpoint set"); return; @@ -953,7 +954,7 @@ static void do_break(char *s) puts("Sorry, no software breakpoints available"); puts("Please recompile with SBSIZE defined in sim.h"); #else /* SBSIZE */ - if (*s == '\n') { + if (*s == '\n' || *s == '\0') { hdr_flag = 0; for (i = 0; i < SBSIZE; i++) if (soft[i].sb_pass) {