From: sur5r Date: Sat, 20 Oct 2007 13:08:11 +0000 (+0000) Subject: replace printf and file functions, warning: may be broken, not tested yet X-Git-Tag: rgb2rv6~65 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b759df66c0d98a4c5839b386ec352577a223f998;p=c128-kasse replace printf and file functions, warning: may be broken, not tested yet git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@44 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/config.c b/config.c index 9fc1fee..f173947 100644 --- a/config.c +++ b/config.c @@ -1,6 +1,7 @@ #include -#include +#include #include +#include #include "general.h" #include "config.h" @@ -15,37 +16,48 @@ struct credits_t credits[MAX_CREDIT_ITEMS+1]; void load_config(); void load_items(){ - FILE* f; char line[80]; - char * sep; - BYTE lfn = 219; -// cbm_open(lfn, (BYTE)8, (BYTE)0, "items,r"); - f = fopen("items","r"); - for (num_items=0; num_items < MAX_ITEMS && !feof(f); num_items++) { - fgets(line, 79, f); + char *sep; + BYTE lfn = 8; + BYTE rc; + int count=1; + + rc=cbm_open(lfn, (BYTE)8, (BYTE)0, "items,r"); + if(rc!=0) + { + cprintf("cannot open items\r\n"); + return; + } + for (num_items=0; num_items < MAX_ITEMS && count>0; num_items++) { + count=cbm_read(lfn, line, 79); + //fgets(line, 79, f); sep = strchr(line, '='); strncpy(status[num_items].item_name, line, sep-line); status[num_items].price = atoi(sep+1); status[num_items].times_sold = 0; } - fclose(f); + cbm_close(lfn); } /** * 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){ + char i; + BYTE lfn=8; + BYTE rc; + int count=1; + + rc=cbm_open(lfn, (BYTE)8, (BYTE)0, "state,r"); + if (rc!=0){ cprintf("cannot open state\r\n"); return; } - while (!feof(f)) { - fgets(line, 79, f); + while (count>0) { + count=cbm_read(lfn,line,79); + //fgets(line, 79, f); sep = strchr(line, '='); if (sep==NULL) continue; @@ -57,21 +69,30 @@ void load_state(){ } } } - fclose(f); + cbm_close(lfn); } void save_state(){ - FILE * f; int i; + BYTE lfn=8; + BYTE rc; + int count=1; + int size=1; + char line[81]; - f = fopen("state", "w"); - if (f==NULL){ + rc=cbm_open(lfn, (BYTE)8, (BYTE)0, "state,w"); + if (rc!=0){ c128_perror(23, "cannot open state file"); return; } for (i=0;imaxlen) return NULL; -// sprintf(s, "%d,%dEUR", cent/100, cent%100); + sprintf(s, "%d,%dEUR", cent/100, cent%100); return s; } diff --git a/items b/items index 102a472..fb6548a 100644 --- a/items +++ b/items @@ -1 +1,3 @@ -Mate=100 Bier=120 Cola=100 \ No newline at end of file +mate=100 +bier=120 +cola=100 diff --git a/kasse.c b/kasse.c index 7eb8df9..de72138 100644 --- a/kasse.c +++ b/kasse.c @@ -154,6 +154,7 @@ void set_time_interactive() { int main() { BYTE c; + toggle_videomode(); /* Zeit erstmalig setzen */ set_time_interactive(); POKE(216, 255); diff --git a/kasse.d64 b/kasse.d64 index a592886..b279629 100644 Binary files a/kasse.d64 and b/kasse.d64 differ diff --git a/state b/state index 3b46f9f..1b33b2d 100644 --- a/state +++ b/state @@ -1 +1,3 @@ -Mate=23 Bier=42 Cola=23 \ No newline at end of file +mate=23 +bier=42 +cola=23 diff --git a/test.c b/test.c index 1df0f3d..ea603ed 100644 --- a/test.c +++ b/test.c @@ -14,7 +14,7 @@ int main(){ load_items(); load_state(); for (i=0; i < num_items; ++i) { - printf("%x: %s (%s, %d mal)\n", i, status[i].item_name, format_euro(euro, 9, status[i].price), status[i].times_sold); + cprintf("%x: %s (%s, %d mal)\n", i, status[i].item_name, format_euro(euro, 9, status[i].price), status[i].times_sold); status[i].times_sold+=10; } @@ -22,9 +22,9 @@ int main(){ load_items(); load_state(); for (i=0; i < num_items; ++i) { - printf("%x: %s (%s, %d mal)\n", i, status[i].item_name, format_euro(euro, 9, status[i].price), status[i].times_sold); + cprintf("%x: %s (%s, %d mal)\n", i, status[i].item_name, format_euro(euro, 9, status[i].price), status[i].times_sold); } - printf("strlen(%s)==%d\n", status[1].item_name, strlen(status[1].item_name)); - printf("%d %d %d\n", status[1].item_name[0], '\r', '\n'); -} \ No newline at end of file + cprintf("strlen(%s)==%d\n", status[1].item_name, strlen(status[1].item_name)); + cprintf("%d %d %d\n", status[1].item_name[0], '\r', '\n'); +} diff --git a/time.c b/time.c index 276380b..4552fe0 100644 --- a/time.c +++ b/time.c @@ -18,7 +18,7 @@ char *get_time() { h -= (hrs * 3600); min = (h / 60); h -= (min * 60); -// sprintf(buffer, "%02d:%02d:%02d", hrs, min, (int)h); + sprintf(buffer, "%02d:%02d:%02d", hrs, min, (int)h); return buffer; }