From ad3767a2bdb56f9465deab501c243f94ae6a6edd Mon Sep 17 00:00:00 2001 From: Peter Schorn Date: Sat, 25 Apr 2015 08:31:05 +0200 Subject: [PATCH] AltairZ80: Fixed keyboard polling on non UNIX platform and daylight savings time issue with CP/M 3 clock --- AltairZ80/altairz80_cpu.c | 5 ++++- AltairZ80/altairz80_cpu_nommu.c | 7 +++++-- AltairZ80/altairz80_sio.c | 16 +++++++++++----- AltairZ80/i86_decode.c | 5 ++++- AltairZ80/m68ksim.c | 6 ++++-- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/AltairZ80/altairz80_cpu.c b/AltairZ80/altairz80_cpu.c index f26d5f9d..643afd84 100644 --- a/AltairZ80/altairz80_cpu.c +++ b/AltairZ80/altairz80_cpu.c @@ -2099,8 +2099,11 @@ 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 - if ((reason = sim_poll_kbd()) == SCPE_STOP) /* poll on platforms without reliable signalling */ + /* poll on platforms without reliable signalling */ + if ((sim_poll_kbd() == SCPE_OK) && stop_cpu) { + reason = SCPE_STOP; break; + } #endif if ((reason = sim_process_event())) break; diff --git a/AltairZ80/altairz80_cpu_nommu.c b/AltairZ80/altairz80_cpu_nommu.c index 7e5be792..c1198e00 100644 --- a/AltairZ80/altairz80_cpu_nommu.c +++ b/AltairZ80/altairz80_cpu_nommu.c @@ -1016,8 +1016,11 @@ t_stat sim_instr_nommu(void) { while (TRUE) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - if ((reason = sim_poll_kbd()) == SCPE_STOP) - break; /* poll on platforms without reliable signalling */ + /* poll on platforms without reliable signalling */ + if ((sim_poll_kbd() == SCPE_OK) && stop_cpu) { + reason = SCPE_STOP; + break; + } #endif if ((reason = sim_process_event())) break; diff --git a/AltairZ80/altairz80_sio.c b/AltairZ80/altairz80_sio.c index 99edcaed..a72063be 100644 --- a/AltairZ80/altairz80_sio.c +++ b/AltairZ80/altairz80_sio.c @@ -736,12 +736,11 @@ static int32 sio0sCore(const int32 port, const int32 io, const int32 data) { if (sio_unit.u3) /* character available? */ return spi.sio_can_read | spi.sio_can_write; ch = sim_poll_kbd(); /* no, try to get a character */ - if (ch) { /* character available? */ - if (ch == SCPE_STOP) { /* stop CPU in case ^E (default) was typed */ - stop_cpu = TRUE; + if ((ch == SCPE_OK) && stop_cpu) { sim_interval = 0; /* detect stop condition as soon as possible*/ return spi.sio_cannot_read | spi.sio_can_write; /* do not consume stop character */ } + if (ch) { /* character available? */ sio_unit.u3 = TRUE; /* indicate character available */ sio_unit.buf = ch; /* store character in buffer */ return spi.sio_can_read | spi.sio_can_write; @@ -1363,11 +1362,18 @@ static time_t mkCPM3Origin(void) { 3 BCD byte: MM 4 BCD byte: SS */ static void setClockCPM3(void) { - ClockCPM3Delta = mkCPM3Origin() + + struct tm targetDate; + const time_t targetSeconds = mkCPM3Origin() + (GetBYTEWrapper(setClockCPM3Adr) + GetBYTEWrapper(setClockCPM3Adr + 1) * 256) * SECONDS_PER_DAY + fromBCD(GetBYTEWrapper(setClockCPM3Adr + 2)) * SECONDS_PER_HOUR + fromBCD(GetBYTEWrapper(setClockCPM3Adr + 3)) * SECONDS_PER_MINUTE + - fromBCD(GetBYTEWrapper(setClockCPM3Adr + 4)) - time(NULL); + fromBCD(GetBYTEWrapper(setClockCPM3Adr + 4)); + // compute target year, month and day and replace hour, minute and second fields + targetDate = *localtime(&targetSeconds); + targetDate.tm_hour = fromBCD(GetBYTEWrapper(setClockCPM3Adr + 2)); + targetDate.tm_min = fromBCD(GetBYTEWrapper(setClockCPM3Adr + 3)); + targetDate.tm_sec = fromBCD(GetBYTEWrapper(setClockCPM3Adr + 4)); + ClockCPM3Delta = mktime(&targetDate) - time(NULL); } static int32 simh_in(const int32 port) { diff --git a/AltairZ80/i86_decode.c b/AltairZ80/i86_decode.c index 9026fcea..74fb2f5a 100644 --- a/AltairZ80/i86_decode.c +++ b/AltairZ80/i86_decode.c @@ -209,8 +209,11 @@ t_stat sim_instr_8086(void) { while (switch_cpu_now == TRUE) { /* loop until halted */ if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - if ((reason = sim_poll_kbd()) == SCPE_STOP) /* poll on platforms without reliable signalling */ + /* poll on platforms without reliable signalling */ + if ((sim_poll_kbd() == SCPE_OK) && stop_cpu) { + reason = SCPE_STOP; break; + } #endif if ( (reason = sim_process_event()) ) break; diff --git a/AltairZ80/m68ksim.c b/AltairZ80/m68ksim.c index 9db65b2a..37e13ef0 100644 --- a/AltairZ80/m68ksim.c +++ b/AltairZ80/m68ksim.c @@ -215,9 +215,11 @@ t_stat sim_instr_m68k(void) { while (TRUE) { if (sim_interval <= 0) { /* check clock queue */ #if !UNIX_PLATFORM - if ((reason = sim_poll_kbd()) == SCPE_STOP) /* poll on platforms without reliable - signalling */ + /* poll on platforms without reliable signalling */ + if ((sim_poll_kbd() == SCPE_OK) && stop_cpu) { + reason = SCPE_STOP; break; + } #endif if ((reason = sim_process_event())) break;