2 * RGB2R-C128-Kassenprogramm
3 * (c) 2007-2008 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
19 /* NOTE: undocumented function which scratches files
20 We need to use this function because linking unistd.h
21 makes our program break at runtime.
23 unsigned char __fastcall__ _sysremove(const char *name);
25 unsigned long int money = 0;
26 unsigned long int items_sold = 0;
27 BYTE printer_port = 4;
28 static bool items_exists = false;
29 static bool credits_exists = false;
30 struct status_array_t status;
31 struct credits_array_t credits;
34 * Checks if items/credits-files are existing to avoid having to recover
35 * the error state of the drive (we'd have to if we would just access the
39 static void lookup_needed_files() {
41 struct cbm_dirent *dirent;
43 if (cbm_opendir(lfn, (BYTE)8) != 0) {
44 cprintf("could not open directory\r\n");
47 while (cbm_readdir(lfn, dirent) == 0) {
48 if (strncmp(dirent->name, "log", 3) == 0)
50 if (strcasecmp(dirent->name, "items") == 0)
52 if (strcasecmp(dirent->name, "credits") == 0)
53 credits_exists = true;
60 cbm_load("items", (BYTE)8, &status);
62 memset(&status, 0, sizeof(struct status_array_t));
67 cbm_load("credits", (BYTE)8, &credits);
69 memset(&credits, 0, sizeof(struct credits_array_t));
75 cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
81 _sysremove("credits");
82 cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
83 credits_exists = true;
87 lookup_needed_files();