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