]> git.sur5r.net Git - c128-kasse/blob - src/config.c
* replaced files_existing with differentiated flags.
[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 "general.h"
15 #include "config.h"
16
17 /* undocumented function which scratches files */
18 unsigned char __fastcall__ _sysremove(const char *name);
19
20 unsigned long int money = 0;
21 unsigned long int items_sold = 0;
22 BYTE printer_port = 4;
23 static bool items_exists = false;
24 static bool credits_exists = false;
25 struct status_array_t status;
26 struct credits_array_t credits;
27
28 /* 
29  * Checks if items/credits-files are existing to avoid having to recover
30  * the error state of the drive (we'd have to if we would just access the
31  * files directly)
32  *
33  */
34 bool lookup_needed_files() {
35         BYTE lfn = 8;
36         struct cbm_dirent *dirent;
37
38         if (cbm_opendir(lfn, (BYTE)8) != 0) {
39                 cprintf("could not open directory\r\n");
40                 return false;
41         }
42         while (cbm_readdir(lfn, dirent) == 0) {
43                 if (strcasecmp(dirent->name, "items") == 0)
44                         items_exists = true;
45                 if (strcasecmp(dirent->name, "credits") == 0)
46                         credits_exists = true;
47         }
48         cbm_closedir(lfn);
49         return credits_exists || items_exists;
50 }
51
52 void load_items() {
53         if (items_exists)
54                 cbm_load("items", (BYTE)8, &status);
55         else
56                 memset(&status, 0, sizeof(struct status_array_t));
57 }
58
59 void load_credits() {
60         if (credits_exists)
61                 cbm_load("credits", (BYTE)8, &credits);
62         else
63                 memset(&credits, 0, sizeof(struct credits_array_t));
64 }
65
66 void save_items() {
67         if (items_exists)
68                 _sysremove("items");
69         cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
70         items_exists = true;
71 }
72
73 void save_credits() {
74         if (credits_exists)
75                 _sysremove("credits");
76         cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
77         credits_exists = true;
78 }
79
80 void load_config() {
81         lookup_needed_files();
82 }