From: sECuRE Date: Tue, 23 Oct 2007 14:37:50 +0000 (+0000) Subject: implement itemz.c which manages ITEMS (works)/CREDITS (TODO) files X-Git-Tag: rgb2rv6~55 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=27d643897880482cf745f73a477ee2a882a8e0a1;p=c128-kasse implement itemz.c which manages ITEMS (works)/CREDITS (TODO) files git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@54 af93e077-1a23-4f1e-9cbe-9382a9d578f5 --- diff --git a/Makefile b/Makefile index 6b88441..881ae84 100644 --- a/Makefile +++ b/Makefile @@ -15,11 +15,18 @@ test/%.o: test/%.c ${CC} -O -I include -t c128 $< ${CA} -I include -t c128 test/$$(basename $< .c).s -all: src/config.o src/kasse.o src/general.o src/credit_manager.o src/c128time.o +kasse: src/config.o src/kasse.o src/general.o src/credit_manager.o src/c128time.o # See above, please just kill the PATH-definition cp /tmp/cc65/lib/c128* . PATH=${PATH}:~/customSoftware/cc65-2.11.0/src/ld65:/tmp/cc65/lib ${CL} -t c128 src/*.o -o kasse +itemz: src/config.o src/itemz.o src/general.o + # See above, please just kill the PATH-definition + cp /tmp/cc65/lib/c128* . + PATH=${PATH}:~/customSoftware/cc65-2.11.0/src/ld65:/tmp/cc65/lib ${CL} -t c128 src/config.o src/itemz.o src/general.o -o itemz + +all: kasse itemz + package: all c1541 -attach kasse.d64 -delete state || exit 0 c1541 -attach kasse.d64 -delete items || exit 0 diff --git a/include/itemz.h b/include/itemz.h new file mode 100644 index 0000000..e69de29 diff --git a/src/itemz.c b/src/itemz.c new file mode 100644 index 0000000..41f2fd5 --- /dev/null +++ b/src/itemz.c @@ -0,0 +1,122 @@ +/* + * RGB2R-C128-Kassenprogramm + * (c) 2007 phil_fry, sECuRE, sur5r + * + * itemz.c: Verwaltet die ITEMS- und CREDITS-datei + * + */ +#include +#include +#include +#include +#include + +#include "general.h" +#include "config.h" + +enum itemz_mode { MODE_ITEMS, MODE_CREDITS }; + +static enum itemz_mode mode = MODE_ITEMS; + +static void print_screen() { + BYTE i; + char buffer[10]; + + clrscr(); + cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n"); + if (mode == MODE_ITEMS) { + cprintf("Datei: ITEMS\r\n\r\n"); + for (i = 0; i < status.num_items; i++) { + if (format_euro(buffer, 10, status.status[i].price) != buffer) { + cprintf("Error: Could not format price %d\r\n", status.status[i].price); + exit(1); + } + cprintf("Eintrag %x: %s (%s, %d mal verkauft)\r\n", + i, status.status[i].item_name, buffer, status.status[i].times_sold); + } + cprintf("\r\nn) Neuer Eintrag d) Eintrag loeschen s) Datei speichern\r\n"); + } else { + cprintf("Datei: CREDITS\r\n\r\n"); + /* TODO: display credits */ + } +} + +static void new_item() { + char *input, *name; + int price; + + cprintf("\rName des Eintrags:\r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; + name = strdup(input); + cprintf("\r\nPreis in Cents:\r\n"); + if ((input = get_input()) == NULL || *input == '\0' || (price = atoi(input)) == 0) + return; + cprintf("\r\nWie oft schon verkauft? [0] \r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; + strcpy(status.status[status.num_items].item_name, name); + status.status[status.num_items].price = price; + status.status[status.num_items].times_sold = atoi(input); + status.num_items++; +} + +static void _delete_item(BYTE num) { + memset(status.status[num].item_name, '\0', 10); + status.status[num].price = 0; + status.status[num].times_sold = 0; +} + +static void delete_item() { + char *input; + BYTE num, last; + + cprintf("\r Welcher Eintrag soll geloescht werden?\r\n"); + if ((input = get_input()) == NULL || *input == '\0') + return; + num = atoi(input); + if (status.num_items > 1) { + /* Swap last item with this one and delete the last one to avoid holes */ + last = (status.num_items - 1); + strcpy(status.status[num].item_name, status.status[last].item_name); + status.status[num].price = status.status[last].price; + status.status[num].times_sold = status.status[last].times_sold; + _delete_item(last); + } else { + /* Just delete it */ + _delete_item(num); + } + status.num_items--; +} + +int main() { + char *c; + toggle_videomode(); + credits.num_items = 0; + status.num_items = 0; + cprintf("itemz loading...\n"); + load_config(); + cprintf("itemz: loading ITEMS...\n"); + load_items(); + cprintf("itemz: loading CREDITS...\n"); + load_credits(); + while (1) { + print_screen(); + c = get_input(); + if (mode == MODE_ITEMS) { + if (*c == 'n') + new_item(); + else if (*c == 'd') + delete_item(); + else if (*c == 's') + save_items(); + else { + cprintf("Unbekannter Befehl, druecke RETURN...\r\n"); + c = get_input(); + } + } else { + /* TODO: code */ + } + } + return 0; +} diff --git a/src/kasse.c b/src/kasse.c index b000ed4..0645379 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -1,3 +1,8 @@ +/* + * RGB2R-C128-Kassenprogramm + * (c) 2007 phil_fry, sECuRE, sur5r + * + */ #include #include #include