From 5da6b87ec843d7cc0e36a0797379a6be80a6686e Mon Sep 17 00:00:00 2001 From: sECuRE Date: Tue, 30 Oct 2007 23:46:56 +0000 Subject: [PATCH] fix bugs in setting/reading time, this one affected the other bug (loading/saving items did not work, showed 0x2F entries) because it overwrote memory git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@75 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- src/c128time.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/c128time.c b/src/c128time.c index d9d680b..3678392 100644 --- a/src/c128time.c +++ b/src/c128time.c @@ -8,25 +8,32 @@ #include #include #include "general.h" +#include char *get_time() { - long int h = PEEK(0x00A0) * 65536, + uint32_t h = PEEK(0x00A0) * 65536, m = PEEK(0x00A1) * 256, s = PEEK(0x00A2); static char buffer[9]; BYTE hrs, min; + h = (h + m + s) / 60; hrs = (h / 3600); - h -= (hrs * 3600); + h -= ((uint32_t)hrs * (uint32_t)3600); min = (h / 60); h -= (min * 60); - sprintf(buffer, "%02d:%02d:%02d", hrs, min, (int)h); + + sprintf(buffer, "%02d:%02d:%02d", hrs, min, (BYTE)h); return buffer; } void set_time(BYTE hrs, min, sec) { - long int added = ((long int)sec + ((long int)min * (long int)60) + ((long int)hrs * (long int)3600)) * (long int)60; - POKE(0x00A0, (BYTE)(added / 65536)); - POKE(0x00A1, (BYTE)(added / 256)); - POKE(0x00A2, (BYTE)added); + uint32_t added = ((uint32_t)sec + ((uint32_t)min * (uint32_t)60) + ((uint32_t)hrs * (uint32_t)3600)) * (uint32_t)60; + uint32_t lowbit = (added & 0xFF); + uint32_t middlebit = (added >> 8) & 0xFF; + uint32_t highbit = (added >> 16) & 0xFF; + + POKE(0x00A0, (BYTE)highbit); + POKE(0x00A1, (BYTE)middlebit); + POKE(0x00A2, (BYTE)lowbit); } -- 2.39.5