From a9e5913d0c02cc1c7555083e3f4079e2204add6b Mon Sep 17 00:00:00 2001 From: Peter Schorn Date: Sun, 26 Apr 2015 09:50:00 +0200 Subject: [PATCH] AltairZ80: Reduced polling for CPU stop on non UNIX platforms --- AltairZ80/altairz80_cpu.c | 22 ++++++++++++++++++++-- AltairZ80/altairz80_cpu_nommu.c | 8 ++++++-- AltairZ80/i86_decode.c | 8 ++++++-- AltairZ80/m68ksim.c | 8 ++++++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/AltairZ80/altairz80_cpu.c b/AltairZ80/altairz80_cpu.c index 80e69aa0..e51bb1a3 100644 --- a/AltairZ80/altairz80_cpu.c +++ b/AltairZ80/altairz80_cpu.c @@ -2047,6 +2047,24 @@ void setClockFrequency(const uint32 Value) { clockHasChanged = TRUE; } + +#if !UNIX_PLATFORM + +/* Poll for CPU stop when user presses sim_int_char. Must be followed by sim_process_event */ + +#define INITIAL_POLL_COUNTER 1000 + +void pollForCPUStop(void) { + static uint32 pollCounter = INITIAL_POLL_COUNTER; + if (--pollCounter <= 0) { + pollCounter = INITIAL_POLL_COUNTER; + sim_poll_kbd(); /* the following sim_process_event will check for stop */ + } +} + +#endif + + static t_stat sim_instr_mmu (void) { extern int32 timerInterrupt; extern int32 timerInterruptHandler; @@ -2099,8 +2117,8 @@ static t_stat sim_instr_mmu (void) { while (switch_cpu_now == TRUE) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - /* poll on platforms without reliable signalling */ - sim_poll_kbd(); /* following sim_process_event will check for stop */ + /* poll on platforms without reliable signalling but not too often */ + pollForCPUStop(); /* following sim_process_event will check for stop */ #endif if ((reason = sim_process_event())) break; diff --git a/AltairZ80/altairz80_cpu_nommu.c b/AltairZ80/altairz80_cpu_nommu.c index b8c68769..d2535a7f 100644 --- a/AltairZ80/altairz80_cpu_nommu.c +++ b/AltairZ80/altairz80_cpu_nommu.c @@ -124,6 +124,10 @@ extern int32 IFF_S; /* Interrupt Flip Flop */ extern int32 IR_S; /* Interrupt (upper) / Refresh (lower) register */ extern int32 chiptype; +#if !UNIX_PLATFORM +extern void pollForCPUStop(void); +#endif + /* the following tables precompute some common subexpressions parityTable[i] 0..255 (number of 1's in i is odd) ? 0 : 4 incTable[i] 0..256! (i & 0xa8) | (((i & 0xff) == 0) << 6) | (((i & 0xf) == 0) << 4) @@ -1016,8 +1020,8 @@ t_stat sim_instr_nommu(void) { while (TRUE) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - /* poll on platforms without reliable signalling */ - sim_poll_kbd(); /* following sim_process_event will check for stop */ + /* poll on platforms without reliable signalling but not too often */ + pollForCPUStop(); /* following sim_process_event will check for stop */ #endif if ((reason = sim_process_event())) break; diff --git a/AltairZ80/i86_decode.c b/AltairZ80/i86_decode.c index fe25c5e7..7684b613 100644 --- a/AltairZ80/i86_decode.c +++ b/AltairZ80/i86_decode.c @@ -44,6 +44,10 @@ extern int32 PCX_S; /* PC register (8086), 20 bit */ extern uint32 PCX; /* external view of PC */ extern UNIT cpu_unit; +#if !UNIX_PLATFORM +extern void pollForCPUStop(void); +#endif + void i86_intr_raise(PC_ENV *m,uint8 intrnum); void cpu8086reset(void); t_stat sim_instr_8086(void); @@ -209,8 +213,8 @@ t_stat sim_instr_8086(void) { while (switch_cpu_now == TRUE) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - /* poll on platforms without reliable signalling */ - sim_poll_kbd(); /* following sim_process_event will check for stop */ + /* poll on platforms without reliable signalling but not too often */ + pollForCPUStop(); /* following sim_process_event will check for stop */ #endif if ( (reason = sim_process_event()) ) break; diff --git a/AltairZ80/m68ksim.c b/AltairZ80/m68ksim.c index 76f1853c..f25cec54 100644 --- a/AltairZ80/m68ksim.c +++ b/AltairZ80/m68ksim.c @@ -158,6 +158,10 @@ static uint32 m68k_fc; /* Current function code fro extern uint32 m68k_registers[M68K_REG_CPU_TYPE + 1]; extern UNIT cpu_unit; +#if !UNIX_PLATFORM +extern void pollForCPUStop(void); +#endif + #define M68K_BOOT_LENGTH (32 * 1024) /* size of bootstrap */ #define M68K_BOOT_PC 0x000400 /* initial PC for boot */ #define M68K_BOOT_SP 0xfe0000 /* initial SP for boot */ @@ -215,8 +219,8 @@ t_stat sim_instr_m68k(void) { while (TRUE) { if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - /* poll on platforms without reliable signalling */ - sim_poll_kbd(); /* following sim_process_event will check for stop */ + /* poll on platforms without reliable signalling but not too often */ + pollForCPUStop(); /* following sim_process_event will check for stop */ #endif if ((reason = sim_process_event())) break;