]> git.sur5r.net Git - c128-kasse/commitdiff
replace printf and file functions, warning: may be broken, not tested yet
authorsur5r <sur5r@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 20 Oct 2007 13:08:11 +0000 (13:08 +0000)
committersur5r <sur5r@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Sat, 20 Oct 2007 13:08:11 +0000 (13:08 +0000)
git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@44 af93e077-1a23-4f1e-9cbe-9382a9d578f5

config.c
general.c
items
kasse.c
kasse.d64
state
test.c
time.c

index 9fc1feed019fa1a03e6ff1d609a87f949a581997..f173947d2ac233751844ba425d7e3f73c2b1f981 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1,6 +1,7 @@
 #include <stdlib.h>
-#include <stdio.h>
+#include <conio.h>
 #include <string.h>
+#include <stdio.h>
 #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;i<num_items;i++)
-       fprintf(f, "%s=%d\n",status[i].item_name, status[i].times_sold);
-    fclose(f);
+       {
+               memset(line,0, 81);
+               size=sprintf(line, "%s=%d\n", status[i].item_name, status[i].times_sold);
+               cbm_write(lfn, line, size);
+       //fprintf(f, "%s=%d\n",status[i].item_name, status[i].times_sold);
+       }
+       cbm_close(lfn);
 }
 /*
 void dump_state(){
@@ -81,11 +102,11 @@ void dump_state(){
        memset(buf, 0, 128);
        f = fopen("state", "r");
        len = fread(buf, 1, 128, f);
-       printf("read %d bytes from state\n", len);
+       cprintf("read %d bytes from state\n", len);
        fclose(f);
        for (i=0;i<len;i++)
                printf("%x ", buf[i]);
-       printf("\n");
+       cprintf("\n");
        
 }
 */
index d806c0af9760223cfa8640cfcff815c4572e6e7c..e7f037d6adaec190e4fe69a51f87afea6325f395 100644 (file)
--- a/general.c
+++ b/general.c
@@ -36,7 +36,7 @@ char * format_euro(char * s, int maxlen, int cent){
                len++;
        if (len>maxlen)
                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 102a4725520cc1a1045d63f52ddda04ccd3f340e..fb6548a87faee466a481c84b3670749a34f032fd 100644 (file)
--- a/items
+++ b/items
@@ -1 +1,3 @@
-Mate=100\rBier=120\rCola=100
\ No newline at end of file
+mate=100\r
+bier=120\r
+cola=100\r
diff --git a/kasse.c b/kasse.c
index 7eb8df9542de8f44ecead7414a2e1f7adf1112d0..de72138004db4c78d15e9354fa4180634d125e95 100644 (file)
--- 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);
index a5928860c6c0bc97711e739258148db95d1e4cd8..b2796296e9a3903e75188f9b4ab694cda6b1dd5f 100644 (file)
Binary files a/kasse.d64 and b/kasse.d64 differ
diff --git a/state b/state
index 3b46f9fe51c52a0390f0f2fe7bada7fed249da79..1b33b2de3acfc3828e4af8339f6f40aca36a85fa 100644 (file)
--- a/state
+++ b/state
@@ -1 +1,3 @@
-Mate=23\rBier=42\rCola=23
\ No newline at end of file
+mate=23\r
+bier=42\r
+cola=23\r
diff --git a/test.c b/test.c
index 1df0f3d179f9e55c6f93acc9b4026f91d410b2ad..ea603ed86a0027387cce322d7ac0c2f2b8717237 100644 (file)
--- 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 276380b28eac67db7b4677edecff3dd1d3eab4a1..4552fe02f171117e9bdbde37c158000cbc0d7047 100644 (file)
--- 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;
 }