From: sECuRE Date: Sun, 29 Jul 2007 11:12:04 +0000 (+0000) Subject: set_time and get_time implemented X-Git-Tag: rgb2rv6~72 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=be7d062ab73679886ad4d758c842d733255f068e;p=c128-kasse set_time and get_time implemented git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@37 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/Makefile b/Makefile index d697ffd..c7efcd3 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ cc65 -t c128 $< ca65 -t c128 $$(basename $< .c).s -all: config.o kasse.o general.o credit_manager.o +all: config.o kasse.o general.o credit_manager.o time.o cl65 -t c128 *.o -o kasse package: all diff --git a/general.h b/general.h index 6d55870..7fb1338 100644 --- a/general.h +++ b/general.h @@ -5,4 +5,8 @@ char *get_input(); char * format_euro(char * s, int maxlen, int cent); void c128_perror(BYTE, char*); extern BYTE _oserror; +#define POKE(addr,val) (*(unsigned char*) (addr) = (val)) +#define POKEW(addr,val) (*(unsigned*) (addr) = (val)) +#define PEEK(addr) (*(unsigned char*) (addr)) +#define PEEKW(addr) (*(unsigned*) (addr)) #endif /*GENERAL_H_*/ diff --git a/kasse.c b/kasse.c index 28a4c8c..6b551ca 100644 --- a/kasse.c +++ b/kasse.c @@ -8,6 +8,7 @@ #include "config.h" #include "kasse.h" #include "credit_manager.h" +#include "time.h" // drucker 4 oder 5 // graphic 4,0,10 @@ -16,12 +17,13 @@ char print_buffer[81]; /* Hauptbildschirm ausgeben */ void print_screen() { BYTE i = 0; + char *time = get_time(); clrscr(); - printf("C128-Kassenprogramm\n\n"); - printf("Eingenommen: %ld Cents, Verkauft: %ld Flaschen, Drucken: %s\n\n", money, items_sold, (printing == 1 ? "ein" : "aus")); + printf("C128-Kassenprogramm\n\nUhrzeit: %s (wird nicht aktualisiert\nEingenommen: %ld Cents, Verkauft: %ld Flaschen, Drucken: %s\n\n", time, money, items_sold, (printing == 1 ? "ein" : "aus")); + free(time); for (; i < num_items; ++i) printf("Eintrag %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold); - printf("\nBefehle: s) Daten sichern d) Drucken umschalten g) Guthabenverwaltung\n"); + printf("\nBefehle: s) Daten sichern d) Drucken umschalten\ng) Guthabenverwaltung z) Zeit setzen\n"); } /* Druckt eine entsprechende Zeile aus */ @@ -114,8 +116,33 @@ void buy(BYTE n) { } } +void set_time_interactive() { + BYTE part[3] = {'0', '0', '\0'}; + BYTE tp1, tp2, tp3; + char *time_input, *time; + printf("Gib die aktuelle Uhrzeit ein (Format HHMMSS):\n"); + time_input = get_input(); + part[0] = time_input[0]; + part[1] = time_input[1]; + tp1 = atoi(part); + part[0] = time_input[2]; + part[1] = time_input[3]; + tp2 = atoi(part); + part[0] = time_input[4]; + part[1] = time_input[5]; + tp3 = atoi(part); + set_time(tp1, tp2, tp3); + + time = get_time(); + printf("Zeit gesetzt: %s\n", time); + free(time); +} + int main() { - static BYTE c; + BYTE c; + /* Zeit erstmalig setzen */ + set_time_interactive(); + POKE(216, 255); /* Konfigurationsdatei laden */ load_config(); /* Einträge (=Getränke) laden */ @@ -123,7 +150,7 @@ int main() { /* Zustand laden */ load_state(); /* Guthaben laden */ - load_credits(); +// load_credits(); while (1) { /* Bildschirm anzeigen */ print_screen(); @@ -135,7 +162,7 @@ int main() { else if (c == 's') { /* Zustandsdatei schreiben */ save_state(); - save_credits(); +// save_credits(); printf("Statefile/Creditfile gesichert, druecke ANYKEY...\n"); getchar(); } else if (c == 'd') { @@ -146,6 +173,9 @@ int main() { } else if (c == 'g') { /* Guthabenverwalter aufrufen */ credit_manager(); + } else if (c == 'z') { + /* Zeit setzen */ + set_time_interactive(); } else if (c == 'q') break; } diff --git a/time.c b/time.c new file mode 100644 index 0000000..4552fe0 --- /dev/null +++ b/time.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include "general.h" + +char *get_time() { + long int h = PEEK(0x00A0) * 65536, + m = PEEK(0x00A1) * 256, + s = PEEK(0x00A2); + char *buffer = malloc(9 * sizeof(char)); + BYTE hrs, min; + if (buffer == NULL) { + perror("malloc()"); + exit(1); + } + h = (h + m + s) / 60; + hrs = (h / 3600); + h -= (hrs * 3600); + min = (h / 60); + h -= (min * 60); + sprintf(buffer, "%02d:%02d:%02d", hrs, min, (int)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); +} diff --git a/time.h b/time.h new file mode 100644 index 0000000..adc6ffb --- /dev/null +++ b/time.h @@ -0,0 +1,5 @@ +#ifndef TIME_H_ +#define TIME_H_ +void set_time(); +char *get_time(); +#endif