From 5bc71a3cfe4bb5dbe09887f36454d01045bd3391 Mon Sep 17 00:00:00 2001 From: nino-porcino Date: Sun, 16 Oct 2022 16:51:25 +0200 Subject: [PATCH] fix 24 hours wrap bug --- demos/viatimer/viaclock.c | 16 ++++++++++++---- lib/interrupt.h | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/demos/viatimer/viaclock.c b/demos/viatimer/viaclock.c index 5fda38f..88aeb76 100644 --- a/demos/viatimer/viaclock.c +++ b/demos/viatimer/viaclock.c @@ -133,10 +133,18 @@ void main() { woz_puts("\rWHAT TIME IS IT ?\r"); - woz_puts("\r(HOURS ) "); apple1_input_line_prompt(KEYBUF, 2); - _hours = (byte) atoi(KEYBUF); - woz_puts("\r(MINUTES) "); apple1_input_line_prompt(KEYBUF, 2); - _minutes = (byte) atoi(KEYBUF); + do { + woz_puts("\r(HOURS ) "); + apple1_input_line_prompt(KEYBUF, 2); + _hours = (byte) atoi(KEYBUF); + } while(_hours > 23); + + do { + woz_puts("\r(MINUTES) "); + apple1_input_line_prompt(KEYBUF, 2); + _minutes = (byte) atoi(KEYBUF); + } while(_minutes > 59); + _seconds = 0; enable_timer_interrupt(); diff --git a/lib/interrupt.h b/lib/interrupt.h index 4365458..1b02749 100644 --- a/lib/interrupt.h +++ b/lib/interrupt.h @@ -35,7 +35,7 @@ EXPORT __interrupt(hardware_all) void time_interrupt_handler() { _seconds = 0; if(++_minutes == 60) { _minutes = 0; - _hours++; + if(++_hours == 24) _hours = 0; } } }