#include "general.h"
#include "globals.h"
-char *get_time(void) {
- static char buffer[9];
- uint8_t bcd_hour, hour, bcd_min, bcd_sec, tenth;
+void update_time(void) {
+ uint8_t bcd_hour, hour, min, sec, tenth;
/* Read the hour register first to stop the clock from updating the external
* registers from the internal (still ticking!) CIA registers. */
hour = bcd2dec(bcd_hour);
}
- bcd_sec = CIA1.tod_sec;
- bcd_min = CIA1.tod_min;
+ sec = bcd2dec(CIA1.tod_sec);
+ min = bcd2dec(CIA1.tod_min);
/* MUST read tod_10 to enable the clock latch again */
tenth = CIA1.tod_10;
- sprintf(buffer, "%02d:%02x:%02x", hour, bcd_min, bcd_sec);
+ if (daytime.hour > hour) {
+ daytime.day++;
+ }
+
+ daytime.hour = hour;
+ daytime.min = min;
+ daytime.sec = sec;
+}
+
+char *get_time(void) {
+ static char buffer[9];
+ update_time();
+ sprintf(buffer, "%02d:%02d:%02d", daytime.hour, daytime.min, daytime.sec);
return buffer;
}
/* divide by 10; put quotient in high nibble, reminder in low nibble */
uint8_t dec2bcd(uint8_t dec) { return (((dec / 10) << 4) | (dec % 10)); }
-void set_time(uint8_t hour, uint8_t min, uint8_t sec) {
+void set_time(uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) {
uint8_t bcd_hour;
/* CIA TOD will always flip the pm bit
bcd_hour = dec2bcd(hour);
}
+ daytime.day = day;
+ daytime.hour = hour;
+ daytime.min = min;
+ daytime.sec = sec;
+
CIA1.tod_hour = bcd_hour;
CIA1.tod_min = dec2bcd(min);
CIA1.tod_sec = dec2bcd(sec);
}
void set_time_interactive(void) {
- BYTE part[3] = {'0', '0', '\0'};
- BYTE tp1, tp2, tp3;
+ char part[3] = {'\0', '\0', '\0'};
+ uint8_t day, tp1, tp2, tp3;
char *time_input, *time;
- cprintf("Gib die aktuelle Uhrzeit ein (Format HHMMSS):\r\n");
+ cprintf("Gib den aktuellen Tag des Events und Uhrzeit ein\r\n"
+ "(Format DHHMMSS):\r\n");
time_input = get_input();
part[0] = time_input[0];
- part[1] = time_input[1];
+ day = atoi(part);
+ part[0] = time_input[1];
+ part[1] = time_input[2];
tp1 = atoi(part);
- part[0] = time_input[2];
- part[1] = time_input[3];
+ part[0] = time_input[3];
+ part[1] = time_input[4];
tp2 = atoi(part);
- part[0] = time_input[4];
- part[1] = time_input[5];
+ part[0] = time_input[5];
+ part[1] = time_input[6];
tp3 = atoi(part);
- set_time(tp1, tp2, tp3);
+ set_time(day, tp1, tp2, tp3);
time = get_time();
cprintf("\r\nZeit gesetzt: %s\r\n", time);