]> git.sur5r.net Git - c128-kasse/blobdiff - src/config.c
Speicherfehler behoben (Danke Sascha)
[c128-kasse] / src / config.c
index b1e6a5816be8c8ecc89d5ab7289b5f148cf7d7df..34a09a21b863ea7591fbfab9763e626625127cc1 100644 (file)
@@ -1,6 +1,6 @@
 /* 
  * RGB2R-C128-Kassenprogramm
- * (c) 2007 phil_fry, sECuRE, sur5r
+ * (c) 2007-2008 phil_fry, sECuRE, sur5r
  * See LICENSE for license information
  *
  */
 #include <string.h>
 #include <stdio.h>
 #include <stdbool.h>
-#include <unistd.h>
 
 #include "kasse.h"
 #include "general.h"
 #include "config.h"
 
-/* undocumented function which scratches files */
-//unsigned char __fastcall__ _sysremove(const char *name);
+/* NOTE: undocumented function which scratches files
+   We need to use this function because linking unistd.h
+   makes our program break at runtime.
+ */
+unsigned char __fastcall__ _sysremove(const char *name);
 
 unsigned long int money = 0;
 unsigned long int items_sold = 0;
@@ -36,27 +38,32 @@ struct credits_array_t credits;
  */
 static void lookup_needed_files() {
        BYTE lfn = 8;
-       struct cbm_dirent *dirent;
+       struct cbm_dirent dirent;
 
        if (cbm_opendir(lfn, (BYTE)8) != 0) {
                cprintf("could not open directory\r\n");
                return;
        }
-       while (cbm_readdir(lfn, dirent) == 0) {
-               if (strncmp(dirent->name, "log", 3) == 0)
+       while (cbm_readdir(lfn, &dirent) == 0) {
+               if (strncmp(dirent.name, "log", 3) == 0)
                        log_num++;
-               if (strcasecmp(dirent->name, "items") == 0)
+               if (strcasecmp(dirent.name, "items") == 0)
                        items_exists = true;
-               if (strcasecmp(dirent->name, "credits") == 0)
+               if (strcasecmp(dirent.name, "credits") == 0)
                        credits_exists = true;
        }
        cbm_closedir(lfn);
 }
 
 void load_items() {
-       if (items_exists)
+       BYTE c;
+
+       if (items_exists) {
+               items_sold = 0;
                cbm_load("items", (BYTE)8, &status);
-       else
+               for (c = 0; c < status.num_items; c++)
+                       items_sold += status.status[c].times_sold;
+       } else
                memset(&status, 0, sizeof(struct status_array_t));
 }
 
@@ -69,14 +76,14 @@ void load_credits() {
 
 void save_items() {
        if (items_exists)
-               unlink("items");
+               _sysremove("items");
        cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
        items_exists = true;
 }
 
 void save_credits() {
        if (credits_exists)
-               unlink("credits");
+               _sysremove("credits");
        cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
        credits_exists = true;
 }