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"
21 static void itemz_print_screen(void) {
26 cprintf("itemz (phil_fry, sECuRE, sur5r, mxf) v:" GV "\r\n\r\n");
27 cprintf("Datei: ITEMS\r\n\r\n");
28 for (i = 0; i < max(status.num_items, 15); i++) {
29 if (format_euro(buffer, 10, status.status[i].price) != buffer) {
30 cprintf("Error: Could not format price %d\r\n", status.status[i].price);
33 cprintf("Eintrag %2d: %s (%s, %d mal verkauft)\r\n", i,
34 status.status[i].item_name, buffer, status.status[i].times_sold);
36 cprintf("\r\nn) Neu d) L" oUML "schen s) Speichern m) Credit Modus q) "
37 "Beenden\r\nr) Reset des Verkauft-Z" aUML "hlers\r\n");
40 static void new_item(void) {
41 char name[MAX_ITEM_NAME_LENGTH + 1];
42 int price, times_sold;
44 if (status.num_items == MAX_ITEMS) {
45 cprintf("\rEs ist bereits die maximale Anzahl an Eintr" aUML
46 "gen erreicht, dr" uUML "cke RETURN...\r\n");
51 cprintf("\rName des Eintrags:\r\n");
52 if (cgetn_input(name, sizeof(name)) == 0)
54 cprintf("\r\nPreis in Cents:\r\n");
55 if ((price = cget_number(0)) <= 0)
57 cprintf("\r\nWie oft schon verkauft? [0] \r\n");
58 if ((times_sold = cget_number(0)) < 0)
60 memset(status.status[status.num_items].item_name, '\0',
61 MAX_ITEM_NAME_LENGTH + 1);
62 strncpy(status.status[status.num_items].item_name, name,
63 MAX_ITEM_NAME_LENGTH);
64 status.status[status.num_items].price = price;
65 status.status[status.num_items].times_sold = times_sold;
69 static void _delete_item(BYTE num) {
70 memset(status.status[num].item_name, '\0', MAX_ITEM_NAME_LENGTH);
71 status.status[num].price = 0;
72 status.status[num].times_sold = 0;
75 static void delete_item(void) {
78 cprintf("\r Welcher Eintrag soll geloescht werden?\r\n");
79 if ((num = cget_number(-1)) < 0)
82 if (status.num_items > 1) {
83 /* Swap last item with this one and delete the last one to avoid holes */
84 last = (status.num_items - 1);
85 strncpy(status.status[num].item_name, status.status[last].item_name,
86 MAX_ITEM_NAME_LENGTH);
87 status.status[num].price = status.status[last].price;
88 status.status[num].times_sold = status.status[last].times_sold;
97 static void reset_counters(void) {
100 for (i = 0; i < status.num_items; i++) {
101 status.status[i].times_sold = 0;
105 static void itemz_manager() {
108 itemz_print_screen();
124 return; // switch to credit mode
128 cprintf("Unbekannter Befehl, druecke RETURN...\r\n");
135 videomode(VIDEOMODE_80x25);
137 /* clock CPU at double the speed (a whopping 2 Mhz!) */
140 credits.num_items = 0;
141 status.num_items = 0;
142 cprintf("itemz loading...\n");
144 cprintf("itemz: loading ITEMS...\n");
146 cprintf("itemz: loading CREDITS...\n");