]> git.sur5r.net Git - c128-kasse/commitdiff
modularized itemz and moved new credit manager stuff into credit_manager.c
authormatze <matze@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Thu, 25 Oct 2007 13:04:44 +0000 (13:04 +0000)
committermatze <matze@af93e077-1a23-4f1e-9cbe-9382a9d578f5>
Thu, 25 Oct 2007 13:04:44 +0000 (13:04 +0000)
itemz now uses the regular credit_manager functions
apart from linking itemz against credit_manager.o I also had to change some other stuff in the Makefile like commenting out custom paths and this cp /tmp/cc65(... . line which makes the build fail.

git-svn-id: https://shell.noname-ev.de/svn/kasse/c128@60 af93e077-1a23-4f1e-9cbe-9382a9d578f5

Makefile
src/credit_manager.c
src/itemz.c

index 881ae84dfb43ef67690d34dd8e333e23d3235164..af273eccc7e05b9bd7a6856c573b126623feea1c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
 # Note: this are my paths to cc65 as there is no gentoo ebuild, sorry for that.
 # Please use the path below if you've installed cc65 system-wide
-CC=~/customSoftware/cc65-2.11.0/src/cc65/cc65 -I ~/customSoftware/cc65-2.11.0/include
-CA=~/customSoftware/cc65-2.11.0/src/ca65/ca65
-CL=~/customSoftware/cc65-2.11.0/src/cl65/cl65
-CC=cc65
-CA=ca65
-CL=cl65
+#CC=~/customSoftware/cc65-2.11.0/src/cc65/cc65 -I ~/customSoftware/cc65-2.11.0/include
+#CA=~/customSoftware/cc65-2.11.0/src/ca65/ca65
+#CL=~/customSoftware/cc65-2.11.0/src/cl65/cl65
+CC=cc65
+CA=ca65
+CL=cl65
 
 src/%.o: src/%.c include/%.h
        ${CC} -O -I include -t c128 $<
@@ -17,20 +17,23 @@ test/%.o: test/%.c
 
 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* .
+       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
+itemz: src/config.o src/itemz.o src/general.o src/credit_manager.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
+       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 src/credit_manager.o -o itemz
 
 all: kasse itemz
 
 package: all
+       cp images/kasse.d64 .
        c1541 -attach kasse.d64 -delete state || exit 0 
        c1541 -attach kasse.d64 -delete items  || exit 0
        c1541 -attach kasse.d64 -delete kasse  || exit 0
+       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
@@ -50,4 +53,4 @@ clean:
        rm -rf src/*.o src/*.s test/*.o test/*.s
        
 dist-clean: clean
-       rm kasse test 
+       rm kasse itemz kasse.d64
index 5986e935dfc704572caf141cb1dccaed6ac6cbf9..6fa39d5b5bb4b534217c36f683dafdd855430a8b 100644 (file)
 static char *filter = NULL;
 static BYTE filter_len;
 
-static void print_credit_screen() {
-       BYTE i = 0;
+static BYTE current_credits_page = 0;
+
+static void credit_print_screen() {
+       BYTE i, pages;
+       char buffer[10];
+
        clrscr();
-       cprintf("C128-Kassenprogramm: Credit Manager\r\n\r\n");
-       for (; i < credits.num_items; ++i)
-               if (filter == NULL || strncmp(credits.credits[i].nickname, filter, filter_len) == 0)
-                       cprintf("Guthaben %s: %d Cents\r\n", credits.credits[i].nickname, credits.credits[i].credit);
-       cprintf("\r\nBefehle: n) Neues Guthaben f) Filtern z) Zurueck\r\n");
+       cprintf("itemz (phil_fry, sECuRE, sur5r)\r\n\r\n");
+       /* 16 entries per page */
+       pages = (credits.num_items / 16);
+       if (current_credits_page > pages)
+               current_credits_page = pages;
+       cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages);
+       for (i = (current_credits_page * 16); i < credits.num_items && i < ((current_credits_page+1) * 16); i++) {
+               if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
+                       cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
+                       exit(1);
+               }
+
+               cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
+       }
+       cprintf("\r\nn) Neu d) Loeschen b) Seite hoch f) Seite runter\r\ne) Aendern s) Speichern z) Zurueck\r\n");
 }
 
-/* Guthabenverwalter */
-void credit_manager() {
-       int negative = 1;
-       char *c, *nickname, *credits_input;
-       /* credits_int is a stupid name, but overlaps with struct credits_t credits; else */
-       int credits_int;
-       while (1) {
-               print_credit_screen();
-               c = get_input();
-               if (c == NULL || *c == '\0')
-                       continue;
-               if (*c == 'n') {
-                       cprintf("\r\nGuthaben eingeben:\r\n");
-                       credits_input = get_input();
 
-                       if (credits_input == NULL || credits_input[0] == '\0')
-                               continue;
-                       else if (credits_input[0] == '-') {
-                               negative = -1;
-                               ++credits_input;
-                       }
-                       credits_int = atoi(credits_input) * negative;
-                       if (credits_int > 0) {
-                               cprintf("Nickname eingeben:\r\n");
-                               nickname = get_input();
-                               if (nickname == NULL || nickname[0] == '\0')
-                                       continue;
-                               strncpy(credits.credits[credits.num_items].nickname, nickname, 9);
-                               credits.credits[credits.num_items].credit = credits_int;
-                               ++credits.num_items;
-                       }
-               } else if (*c == 'f') {
-                       cprintf("Filter eingeben:\r\n");
-                       filter = get_input();
-                       if (filter == NULL || *filter == 32 || (filter_len = strlen(filter)) == 0)
-                               filter = NULL;
-               } else if (*c == 'z' || *c == 'q')
-                       break;
+static void new_credit() {
+       char *input, *name;
+       int credit;
+
+       if (credits.num_items == 75) {
+               cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
+               input = get_input();
+               return;
+       }
+
+       cprintf("\rNickname:\r\n");
+       if ((input = get_input()) == NULL || *input == '\0')
+               return;
+       name = strdup(input);
+       cprintf("\r\nGuthaben in Cents:\r\n");
+       if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
+               return;
+       strcpy(credits.credits[credits.num_items].nickname, name);
+       credits.credits[credits.num_items].credit = credit;
+       credits.num_items++;
+       free(name);
+}
+
+static void _delete_credit(BYTE num) {
+       memset(credits.credits[num].nickname, '\0', 11);
+       credits.credits[num].credit = 0;
+}
+
+static void delete_credit() {
+       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 (credits.num_items > 1) {
+               /* Swap last item with this one and delete the last one to avoid holes */
+               last = (credits.num_items - 1);
+               strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
+               credits.credits[num].credit = credits.credits[last].credit;
+               _delete_credit(last);
+       } else {
+               /* Just delete it */
+               _delete_credit(num);
        }
+       credits.num_items--;
+}
+
+void credit_manager(){
+       char *c;
+       while(1){
+               credit_print_screen();
+               c = get_input();
+               switch (*c) {
+                       case 'n':
+                               new_credit(); break;
+                       case 'd':
+                               delete_credit(); break;
+                       case 's':
+                               save_credits(); break;
+                       case 'f':
+                               if (current_credits_page < (credits.num_items / 16))
+                                               current_credits_page++;
+                               break;
+                       case 'b':
+                               if (current_credits_page > 0)
+                                       current_credits_page--;
+                               break;
+                       case 'z':
+                               return; 
+                       default:
+                               cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
+                               get_input(); 
+               }
+       }       
 }
index e020fa5957aa171c0a2e843829d3e6a3d662d7c4..caf23bf72472175cb530a6191f379a3d90f9dca6 100644 (file)
 
 #include "general.h"
 #include "config.h"
+#include "credit_manager.h"
 
 enum itemz_mode { MODE_ITEMS, MODE_CREDITS };
 
 static enum itemz_mode mode = MODE_ITEMS;
-static BYTE current_credits_page = 0;
 
-static void print_screen() {
+static void itemz_print_screen() {
        BYTE i, pages;
        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("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("\r\nn) Neu d) Loeschen s) Speichern m) Modus\r\n");
-       } else {
-               /* 16 entries per page */
-               pages = (credits.num_items / 16);
-               if (current_credits_page > pages)
-                       current_credits_page = pages;
-               cprintf("Datei: CREDITS (Seite %d von %d)\r\n\r\n", current_credits_page, pages);
-               for (i = (current_credits_page * 16); i < credits.num_items && i < ((current_credits_page+1) * 16); i++) {
-                       if (format_euro(buffer, 10, credits.credits[i].credit) != buffer) {
-                               cprintf("Error: Could not format credit %d\r\n", credits.credits[i].credit);
-                               exit(1);
-                       }
-
-                       cprintf("%d: %s: %s\r\n", i, credits.credits[i].nickname, buffer);
-               }
-               cprintf("\r\nn) Neu d) Loeschen b) Seite hoch f) Seite runter\r\ne) Aendern s) Speichern m) Modus\r\n");
+               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) Neu d) Loeschen s) Speichern m) Credit Modus\r\n");
 }
 
 static void new_item() {
@@ -110,53 +93,25 @@ static void delete_item() {
        status.num_items--;
 }
 
-static void new_credit() {
-       char *input, *name;
-       int credit;
-
-       if (credits.num_items == 75) {
-               cprintf("\rEs ist bereits die maximale Anzahl an Eintraegen erreicht, druecke RETURN...\r\n");
-               input = get_input();
-               return;
-       }
-
-       cprintf("\rNickname:\r\n");
-       if ((input = get_input()) == NULL || *input == '\0')
-               return;
-       name = strdup(input);
-       cprintf("\r\nGuthaben in Cents:\r\n");
-       if ((input = get_input()) == NULL || *input == '\0' || (credit = atoi(input)) == 0)
-               return;
-       strcpy(credits.credits[credits.num_items].nickname, name);
-       credits.credits[credits.num_items].credit = credit;
-       credits.num_items++;
-       free(name);
-}
-
-static void _delete_credit(BYTE num) {
-       memset(credits.credits[num].nickname, '\0', 11);
-       credits.credits[num].credit = 0;
-}
-
-static void delete_credit() {
-       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 (credits.num_items > 1) {
-               /* Swap last item with this one and delete the last one to avoid holes */
-               last = (credits.num_items - 1);
-               strcpy(credits.credits[num].nickname, credits.credits[last].nickname);
-               credits.credits[num].credit = credits.credits[last].credit;
-               _delete_credit(last);
-       } else {
-               /* Just delete it */
-               _delete_credit(num);
+static void itemz_manager(){
+       char *c;
+       while(1){
+               itemz_print_screen();
+               c = get_input();
+               switch (*c) {
+                       case 'n':
+                               new_item(); break;
+                       case 'd':
+                               delete_item(); break;
+                       case 's':
+                               save_items(); break;
+                       case 'm':
+                               return; // switch to credit mode
+                       default:
+                               cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
+                               get_input(); 
+               }
        }
-       credits.num_items--;
 }
 
 int main() {
@@ -171,42 +126,8 @@ int main() {
        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 if (*c == 'm')
-                               mode = MODE_CREDITS;
-                       else {
-                               cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
-                               c = get_input();
-                       }
-               } else {
-                       if (*c == 'm')
-                               mode = MODE_ITEMS;
-                       else if (*c == 'n')
-                               new_credit();
-                       else if (*c == 'd')
-                               delete_credit();
-                       else if (*c == 's')
-                               save_credits();
-                       else if (*c == 'f') {
-                               if (current_credits_page < (credits.num_items / 16))
-                                       current_credits_page++;
-                       } else if (*c == 'b') {
-                               if (current_credits_page > 0)
-                                       current_credits_page--;
-                       }
-                       else {
-                               cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
-                               c = get_input();
-                       }
-               }
+               itemz_manager();
+               credit_manager();
        }
        return 0;
 }