2 * RGB2R-C128-Kassenprogramm
3 * © 2007-2009 phil_fry, sECuRE, sur5r
4 * See LICENSE for license information
6 * itemz.c: Verwaltet die ITEMS- und CREDITS-datei
17 #include "credit_manager.h"
19 #include "vdc_patch_charset.h"
22 static void itemz_print_screen(void) {
24 char buffer[EUR_FORMAT_MINLEN];
27 cprintf("itemz (phil_fry, sECuRE, sur5r, mxf) v:" GV "\r\n\r\n");
28 cprintf("Datei: ITEMS\r\n\r\n");
29 for (i = 0; i < max(status.num_items, 15); i++) {
30 if (format_euro(buffer, sizeof(buffer), status.status[i].price) != buffer) {
31 cprintf("Error: Could not format price %d\r\n", status.status[i].price);
34 cprintf("Eintrag %2d: %s (%s, %d mal verkauft)\r\n", i,
35 status.status[i].item_name, buffer, status.status[i].times_sold);
37 cprintf("\r\nn) Neu d) L" oUML "schen s) Speichern m) Credit Modus q) "
38 "Beenden\r\nr) Reset des Verkauft-Z" aUML "hlers\r\n");
41 static void new_item(void) {
42 char name[MAX_ITEM_NAME_LENGTH + 1];
43 int price, times_sold;
45 if (status.num_items == MAX_ITEMS) {
46 cprintf("\rEs ist bereits die maximale Anzahl an Eintr" aUML
47 "gen erreicht, dr" uUML "cke RETURN...\r\n");
52 cprintf("\rName des Eintrags:\r\n");
53 if (cgetn_input(name, sizeof(name)) == 0)
55 cprintf("\r\nPreis in Cents:\r\n");
56 if ((price = cget_number(0)) <= 0)
58 cprintf("\r\nWie oft schon verkauft? [0] \r\n");
59 if ((times_sold = cget_number(0)) < 0)
61 memset(status.status[status.num_items].item_name, '\0',
62 MAX_ITEM_NAME_LENGTH + 1);
63 strncpy(status.status[status.num_items].item_name, name,
64 MAX_ITEM_NAME_LENGTH);
65 status.status[status.num_items].price = price;
66 status.status[status.num_items].times_sold = times_sold;
70 static void _delete_item(BYTE num) {
71 memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH);
72 status.status[num].price = 0;
73 status.status[num].times_sold = 0;
76 static void delete_item(void) {
79 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
81 num = cget_number(-1);
85 if (status.num_items > 1) {
86 /* Swap last item with this one and delete the last one to avoid holes */
87 last = (status.num_items - 1);
88 strncpy(status.status[num].item_name, status.status[last].item_name,
89 MAX_ITEM_NAME_LENGTH);
90 status.status[num].price = status.status[last].price;
91 status.status[num].times_sold = status.status[last].times_sold;
100 static void reset_counters(void) {
103 for (i = 0; i < status.num_items; i++) {
104 status.status[i].times_sold = 0;
108 static void itemz_manager() {
111 itemz_print_screen();
127 return; // switch to credit mode
131 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
138 videomode(VIDEOMODE_80x25);
140 /* clock CPU at double the speed (a whopping 2 Mhz!) */
143 credits.num_items = 0;
144 status.num_items = 0;
145 cprintf("itemz loading...\n");
147 cprintf("itemz: loading ITEMS...\n");
149 cprintf("itemz: loading CREDITS...\n");