From 0d886ab1aa0a50966dab9a9ff08f504892b2644d Mon Sep 17 00:00:00 2001 From: sECuRE Date: Sat, 28 Jul 2007 21:31:18 +0000 Subject: [PATCH] printing implemented git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@28 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- config.c | 31 +++++-------------------------- config.h | 3 +++ credit_manager.c | 6 +++--- general.c | 8 ++++++-- general.h | 5 +++-- kasse.c | 31 +++++++++++++++++++++++-------- kasse.h | 2 +- 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/config.c b/config.c index 5dbd328..6a76e6a 100644 --- a/config.c +++ b/config.c @@ -6,15 +6,15 @@ unsigned long int money = 0; unsigned long int num_items = 0; -uc num_credit_items = 0; +BYTE num_credit_items = 0; unsigned long int items_sold = 0; +BYTE printer_port = 4; struct status_t status[MAX_ITEMS+1]; struct credits_t credits[MAX_CREDIT_ITEMS+1]; #ifdef REAL_DATA void load_config(); - void load_items(){ FILE* f; char line[80]; @@ -30,30 +30,9 @@ void load_items(){ } -/** - * must be called after load_items() - */ void load_state(){ - FILE* f; - char line[80]; - char * sep; - char i, j; - f = fopen("state", "r"); - if (f==NULL){ - printf("cannot open state\n"); - return; - } - while (!feof(f)) { - fgets(line, 79, f); - sep = strchr(line, '='); - *(line + (sep-line)) = 0; - for (i=0; i< MAX_ITEMS; i++) { - if (strcmp(line, status[i].item_name)==0) { - status[i].times_sold = atoi(sep+1); - break; - } - } - } + status[0].times_sold=23; + status[1].times_sold=42; } void save_state(){} @@ -66,7 +45,7 @@ void load_config() { } void load_items() { - uc c; + BYTE c; num_items=2; strcpy(status[0].item_name, "cola"); status[0].price = 230; diff --git a/config.h b/config.h index 01cdd80..d3d1c24 100644 --- a/config.h +++ b/config.h @@ -1,3 +1,5 @@ +#include "general.h" + #ifndef CONFIG_H_ #define CONFIG_H_ @@ -6,6 +8,7 @@ extern unsigned long int money; extern unsigned long int num_items; extern unsigned char num_credit_items; extern unsigned long int items_sold; +extern BYTE printer_port; /* Datenstruktur der verkauften Einträge */ diff --git a/credit_manager.c b/credit_manager.c index 65a5293..64ee6a3 100644 --- a/credit_manager.c +++ b/credit_manager.c @@ -7,10 +7,10 @@ #include "general.h" char *filter = NULL; -uc filter_len; +BYTE filter_len; void print_credit_screen() { - uc i = 0; + BYTE i = 0; clrscr(); printf("C128-Kassenprogramm: Credit Manager\n\n"); for (; i < num_credit_items; ++i) @@ -22,7 +22,7 @@ void print_credit_screen() { /* Guthabenverwalter */ void credit_manager() { int negative = 1; - uc c; + BYTE c; char *nickname, *credits_input; /* credits_int is a stupid name, but overlaps with struct credits_t credits; else */ int credits_int; diff --git a/general.c b/general.c index ab64528..1b99373 100644 --- a/general.c +++ b/general.c @@ -10,9 +10,9 @@ * */ char *get_input() { - uc i = 0; + BYTE i = 0; char *output = malloc(32 * sizeof(char)); - uc c; + BYTE c; if (output == NULL) { perror("malloc()"); exit(1); @@ -28,3 +28,7 @@ char *get_input() { } return output; } + +void c128_perror(BYTE c, char *msg) { + printf("\nError (Code %d) while: %s\nOS Error = %s\n", c, msg, _oserror); +} diff --git a/general.h b/general.h index f8aa25b..81afdf4 100644 --- a/general.h +++ b/general.h @@ -1,6 +1,7 @@ #ifndef GENERAL_H_ #define GENERAL_H_ -#define uc unsigned char -#define NULL 0 +typedef unsigned char BYTE; char *get_input(); +void c128_perror(BYTE, char*); +extern BYTE _oserror; #endif /*GENERAL_H_*/ diff --git a/kasse.c b/kasse.c index 684af72..28a4c8c 100644 --- a/kasse.c +++ b/kasse.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "general.h" #include "config.h" @@ -10,11 +11,11 @@ // drucker 4 oder 5 // graphic 4,0,10 - +char print_buffer[81]; /* Hauptbildschirm ausgeben */ void print_screen() { - uc i = 0; + BYTE i = 0; clrscr(); printf("C128-Kassenprogramm\n\n"); printf("Eingenommen: %ld Cents, Verkauft: %ld Flaschen, Drucken: %s\n\n", money, items_sold, (printing == 1 ? "ein" : "aus")); @@ -24,7 +25,8 @@ void print_screen() { } /* Druckt eine entsprechende Zeile aus */ -void print_log(uc n, int einheiten, char *nickname) { +void print_log(BYTE n, int einheiten, char *nickname) { + BYTE c; /* Format: Transaction-ID (Anzahl verkaufter Einträge, inklusive des zu druckenden!) Uhrzeit (TODO) @@ -33,15 +35,28 @@ void print_log(uc n, int einheiten, char *nickname) { Anzahl Nickname (falls es vom Guthaben abgezogen wird) */ - printf("[%d] UHRZEIT - %s - %d - %d - an %s\n", items_sold, status[n].item_name, status[n].price, einheiten, (nickname != NULL ? nickname : "Unbekannt")); + sprintf(print_buffer, "[%d] UHRZEIT - %s - %d - %d - an %s\r\n", items_sold, status[n].item_name, status[n].price, einheiten, (nickname != NULL ? nickname : "Unbekannt")); + c = cbm_open(4, 4, 0, NULL); + if (c != 0) { + c128_perror(c, "cbm_open(printer)"); + save_state(); + exit(1); + } + c = cbm_write(4, print_buffer, strlen(print_buffer)); + if (c != strlen(print_buffer)) { + c128_perror(c, "write(printer)"); + save_state(); + exit(1); + } + cbm_close(4); } /* Dialog, der einen durch's Abrechnen der Einträge führt */ -void buy(uc n) { +void buy(BYTE n) { int negative = 1; char entered[5] = {'1', 0, 0, 0, 0}; - uc i = 0, matches = 0; - uc c, nickname_len, single_match; + BYTE i = 0, matches = 0; + BYTE c, nickname_len, single_match; int einheiten; char *nickname; if (status[n].item_name == NULL) @@ -100,7 +115,7 @@ void buy(uc n) { } int main() { - static uc c; + static BYTE c; /* Konfigurationsdatei laden */ load_config(); /* Einträge (=Getränke) laden */ diff --git a/kasse.h b/kasse.h index 8f6aca7..8323994 100644 --- a/kasse.h +++ b/kasse.h @@ -1 +1 @@ -uc printing = 1; +BYTE printing = 1; -- 2.39.5