]> git.sur5r.net Git - c128-kasse/commitdiff
implement itemz.c which manages ITEMS (works)/CREDITS (TODO) files
authorsECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Tue, 23 Oct 2007 14:37:50 +0000 (14:37 +0000)
committersECuRE <sECuRE@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Tue, 23 Oct 2007 14:37:50 +0000 (14:37 +0000)
git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@54 af93e077-1a23-4f1e-9cbe-9382a9d578f5

Makefile
include/itemz.h [new file with mode: 0644]
src/itemz.c [new file with mode: 0644]
src/kasse.c

index 6b8844124a1f30cd31e6d15d3ae62673fcb1c3e1..881ae84dfb43ef67690d34dd8e333e23d3235164 100644 (file)
--- 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 (file)
index 0000000..e69de29
diff --git a/src/itemz.c b/src/itemz.c
new file mode 100644 (file)
index 0000000..41f2fd5
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * RGB2R-C128-Kassenprogramm
+ * (c) 2007 phil_fry, sECuRE, sur5r
+ *
+ * itemz.c: Verwaltet die ITEMS- und CREDITS-datei
+ *
+ */
+#include <c128.h>
+#include <conio.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#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;
+}
index b000ed45b6a2d9fd8814c328370c999e23925ae9..06453790ce0ecc0d59ae23509c43e39099d05d34 100644 (file)
@@ -1,3 +1,8 @@
+/*
+ * RGB2R-C128-Kassenprogramm
+ * (c) 2007 phil_fry, sECuRE, sur5r
+ *
+ */
 #include <stdio.h>
 #include <conio.h>
 #include <stdlib.h>