]> git.sur5r.net Git - c128-kasse/blob - src/config.c
Use unlink() instead of _sysremove(), cleanup makefile
[c128-kasse] / src / config.c
1 /* 
2  * RGB2R-C128-Kassenprogramm
3  * (c) 2007 phil_fry, sECuRE, sur5r
4  * See LICENSE for license information
5  *
6  */
7 #define _IS_CONFIG_C
8
9 #include <stdlib.h>
10 #include <conio.h>
11 #include <string.h>
12 #include <stdio.h>
13 #include <stdbool.h>
14 #include <unistd.h>
15
16 #include "kasse.h"
17 #include "general.h"
18 #include "config.h"
19
20 /* undocumented function which scratches files */
21 //unsigned char __fastcall__ _sysremove(const char *name);
22
23 unsigned long int money = 0;
24 unsigned long int items_sold = 0;
25 BYTE printer_port = 4;
26 static bool items_exists = false;
27 static bool credits_exists = false;
28 struct status_array_t status;
29 struct credits_array_t credits;
30
31 /* 
32  * Checks if items/credits-files are existing to avoid having to recover
33  * the error state of the drive (we'd have to if we would just access the
34  * files directly)
35  *
36  */
37 static void lookup_needed_files() {
38         BYTE lfn = 8;
39         struct cbm_dirent *dirent;
40
41         if (cbm_opendir(lfn, (BYTE)8) != 0) {
42                 cprintf("could not open directory\r\n");
43                 return;
44         }
45         while (cbm_readdir(lfn, dirent) == 0) {
46                 if (strncmp(dirent->name, "log", 3) == 0)
47                         log_num++;
48                 if (strcasecmp(dirent->name, "items") == 0)
49                         items_exists = true;
50                 if (strcasecmp(dirent->name, "credits") == 0)
51                         credits_exists = true;
52         }
53         cbm_closedir(lfn);
54 }
55
56 void load_items() {
57         if (items_exists)
58                 cbm_load("items", (BYTE)8, &status);
59         else
60                 memset(&status, 0, sizeof(struct status_array_t));
61 }
62
63 void load_credits() {
64         if (credits_exists)
65                 cbm_load("credits", (BYTE)8, &credits);
66         else
67                 memset(&credits, 0, sizeof(struct credits_array_t));
68 }
69
70 void save_items() {
71         if (items_exists)
72                 unlink("items");
73         cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
74         items_exists = true;
75 }
76
77 void save_credits() {
78         if (credits_exists)
79                 unlink("credits");
80         cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
81         credits_exists = true;
82 }
83
84 void load_config() {
85         lookup_needed_files();
86 }