From: matze Date: Fri, 26 Oct 2007 21:00:32 +0000 (+0000) Subject: * replaced files_existing with differentiated flags. X-Git-Tag: rgb2rv6~41 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fda51addffa1f3fafbbb24e770f7159273b55824;p=c128-kasse * replaced files_existing with differentiated flags. * obsolete items/state files are not written to the disk image anymore git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@68 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/Makefile b/Makefile index af273ec..c860ac7 100644 --- a/Makefile +++ b/Makefile @@ -35,8 +35,8 @@ package: all c1541 -attach kasse.d64 -delete itemz || exit 0 # c1541 -attach kasse.d64 -write itemz || exit 0 c1541 -attach kasse.d64 -write kasse || exit 0 - c1541 -attach kasse.d64 -write state || exit 0 - c1541 -attach kasse.d64 -write items || exit 0 +# c1541 -attach kasse.d64 -write state || exit 0 +# c1541 -attach kasse.d64 -write items || exit 0 test: src/config.o test/test.o src/general.o ${CL} -t c128 src/config.o test/test.o src/general.o -o test diff --git a/src/config.c b/src/config.c index db80ce3..d881af2 100644 --- a/src/config.c +++ b/src/config.c @@ -20,7 +20,8 @@ unsigned char __fastcall__ _sysremove(const char *name); unsigned long int money = 0; unsigned long int items_sold = 0; BYTE printer_port = 4; -static bool files_existing = false; +static bool items_exists = false; +static bool credits_exists = false; struct status_array_t status; struct credits_array_t credits; @@ -32,45 +33,50 @@ struct credits_array_t credits; */ bool lookup_needed_files() { BYTE lfn = 8; - BYTE files_existing = 0; struct cbm_dirent *dirent; if (cbm_opendir(lfn, (BYTE)8) != 0) { cprintf("could not open directory\r\n"); return false; } - while (cbm_readdir(lfn, dirent) == 0) - if ( strcasecmp(dirent->name, "items") == 0 || - strcasecmp(dirent->name, "credits") == 0) - files_existing++; + while (cbm_readdir(lfn, dirent) == 0) { + if (strcasecmp(dirent->name, "items") == 0) + items_exists = true; + if (strcasecmp(dirent->name, "credits") == 0) + credits_exists = true; + } cbm_closedir(lfn); - return (files_existing >= 2); + return credits_exists || items_exists; } void load_items() { - if (files_existing) + if (items_exists) cbm_load("items", (BYTE)8, &status); + else + memset(&status, 0, sizeof(struct status_array_t)); } void load_credits() { - if (files_existing) + if (credits_exists) cbm_load("credits", (BYTE)8, &credits); + else + memset(&credits, 0, sizeof(struct credits_array_t)); } void save_items() { - if (files_existing) + if (items_exists) _sysremove("items"); cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t)); - files_existing = true; + items_exists = true; } void save_credits() { - if (files_existing) + if (credits_exists) _sysremove("credits"); cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t)); - files_existing = true; + credits_exists = true; } void load_config() { - files_existing = lookup_needed_files(); + lookup_needed_files(); }