]> git.sur5r.net Git - c128-kasse/blob - src/config.c
db80ce38a36f92540227b92fde0ecf15f76d5013
[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 files_existing = false;
24 struct status_array_t status;
25 struct credits_array_t credits;
26
27 /* 
28  * Checks if items/credits-files are existing to avoid having to recover
29  * the error state of the drive (we'd have to if we would just access the
30  * files directly)
31  *
32  */
33 bool lookup_needed_files() {
34         BYTE lfn = 8;
35         BYTE files_existing = 0;
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                         strcasecmp(dirent->name, "credits") == 0)
45                         files_existing++;
46         cbm_closedir(lfn);
47         return (files_existing >= 2);
48 }
49
50 void load_items() {
51         if (files_existing)
52                 cbm_load("items", (BYTE)8, &status);
53 }
54
55 void load_credits() {
56         if (files_existing)
57                 cbm_load("credits", (BYTE)8, &credits);
58 }
59
60 void save_items() {
61         if (files_existing)
62                 _sysremove("items");
63         cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
64         files_existing = true;
65 }
66
67 void save_credits() {
68         if (files_existing)
69                 _sysremove("credits");
70         cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
71         files_existing = true;
72 }
73
74 void load_config() {
75         files_existing = lookup_needed_files();
76 }