+# 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
+
%.o: %.c
- cc65 -t c128 $<
- ca65 -t c128 $$(basename $< .c).s
+ cp /tmp/cc65/lib/c128* .
+ ${CC} -t c128 $<
+ ${CA} -t c128 $$(basename $< .c).s
all: config.o kasse.o general.o credit_manager.o time.o
- cl65 -t c128 *.o -o kasse
+ # See above, please just kill the PATH-definition
+ PATH=${PATH}:~/customSoftware/cc65-2.11.0/src/ld65:/tmp/cc65/lib ${CL} -t c128 *.o -o kasse
package: all
c1541 -attach kasse.d64 -delete state || exit 0
c1541 -attach kasse.d64 -write items || exit 0
test: config.o test.o general.o
- cl65 -t c128 config.o test.o general.o -o test
+ ${CL} -t c128 config.o test.o general.o -o test
test-package: test
c1541 -attach test.d64 -delete state || exit 0
+#define _IS_CONFIG_C
+
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "config.h"
unsigned long int money = 0;
-unsigned long int num_items = 0;
-BYTE num_credit_items = 0;
unsigned long int items_sold = 0;
BYTE printer_port = 4;
-struct status_t status[MAX_ITEMS+1];
-struct credits_t credits[MAX_CREDIT_ITEMS+1];
static bool files_existing = false;
-
+struct status_array_t status;
+struct credits_array_t credits;
+
+/*
+ * Checks if items/credits-files are existing to avoid having to recover
+ * the error state of the drive (we'd have to if we would just access the
+ * files directly)
+ *
+ */
bool lookup_needed_files() {
BYTE lfn = 8;
BYTE files_existing = 0;
strcasecmp(dirent->name, "credits") == 0)
files_existing++;
cbm_closedir(lfn);
- return (files_existing == 2);
+ return (files_existing >= 2);
}
void load_items() {
- BYTE rc;
- char *nn;
- cprintf("load_items()\r\n");
- if (files_existing) {
- rc = cbm_load("items", (BYTE)8, status);
- cprintf("rc = %d\r\n", rc);
- nn = get_input();
- }
-// cbm_load("items", (BYTE)8, NULL);
-}
-
-void save_items() {
- cbm_save("items", (BYTE)8, status, sizeof(struct status_t) * MAX_ITEMS);
- files_existing = true;
+ if (files_existing)
+ cbm_load("items", (BYTE)8, &status);
}
void load_credits() {
if (files_existing)
- cbm_load("credits", (BYTE)8, credits);
+ cbm_load("credits", (BYTE)8, &credits);
}
-void save_credits() {
- cbm_save("credits", (BYTE)8, credits, sizeof(struct credits_t) * MAX_CREDIT_ITEMS);
+void save_items() {
+ cbm_save("items", (BYTE)8, &status, sizeof(struct status_array_t));
files_existing = true;
}
-
-/*
-void dump_state(){
- FILE * f;
- char buf[128];
- int i, len;
- memset(buf, 0, 128);
- f = fopen("state", "r");
- len = fread(buf, 1, 128, f);
- cprintf("read %d bytes from state\n", len);
- fclose(f);
- for (i=0;i<len;i++)
- printf("%x ", buf[i]);
- cprintf("\n");
-
+void save_credits() {
+ cbm_save("credits", (BYTE)8, &credits, sizeof(struct credits_array_t));
+ files_existing = true;
}
-*/
+
void load_config() {
files_existing = lookup_needed_files();
}
#ifndef CONFIG_H_
#define CONFIG_H_
+#define MAX_ITEMS 15
+#define MAX_CREDIT_ITEMS 75
+
/* Eingenommes Geld in Cent */
extern unsigned long int money;
-extern unsigned long int num_items;
-extern unsigned char num_credit_items;
extern unsigned long int items_sold;
extern BYTE printer_port;
unsigned int times_sold;
};
-#define MAX_ITEMS 15
-extern struct status_t status[MAX_ITEMS+1];
+struct status_array_t {
+ BYTE num_items;
+ struct status_t status[MAX_ITEMS];
+};
/* Datenstruktur für die Guthaben */
struct credits_t {
unsigned int credit;
};
-#define MAX_CREDIT_ITEMS 75
-extern struct credits_t credits[MAX_CREDIT_ITEMS+1];
+struct credits_array_t {
+ BYTE num_items;
+ struct credits_t credits[MAX_CREDIT_ITEMS];
+};
+
+#ifndef _IS_CONFIG_C
+extern struct status_array_t status;
+extern struct credits_array_t credits;
+#endif
/* Lädt Dinge wie die Druckeradresse */
void load_config();
BYTE i = 0;
clrscr();
cprintf("C128-Kassenprogramm: Credit Manager\r\n\r\n");
- for (; i < num_credit_items; ++i)
- if (filter == NULL || strncmp(credits[i].nickname, filter, filter_len) == 0)
- cprintf("Guthaben %s: %d Cents\r\n", credits[i].nickname, credits[i].credit);
+ 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");
}
}
credits_int = atoi(credits_input) * negative;
if (credits_int > 0) {
- strcpy(credits[num_credit_items].nickname, nickname);
- credits[num_credit_items].credit = credits_int;
- ++num_credit_items;
+ strcpy(credits.credits[credits.num_items].nickname, nickname);
+ credits.credits[credits.num_items].credit = credits_int;
+ ++credits.num_items;
}
if (negative == -1)
--credits_input;
clrscr();
cprintf("C128-Kassenprogramm\r\n\r\nUhrzeit: %s (wird nicht aktualisiert)\r\nEingenommen: %ld Cents, Verkauft: %ld Flaschen, Drucken: %s\r\n\r\n", time, money, items_sold, (printing == 1 ? "ein" : "aus"));
free(time);
- for (; i < num_items; ++i)
- cprintf("Eintrag %x: %s (%d Cents, %d mal verkauft)\r\n", i, status[i].item_name, status[i].price, status[i].times_sold);
+ for (; i < status.num_items; ++i)
+ cprintf("Eintrag %x: %s (%d Cents, %d mal verkauft)\r\n",
+ i, status.status[i].item_name, status.status[i].price, status.status[i].times_sold);
cprintf("\r\nBefehle: s) Daten sichern d) Drucken umschalten\r\ng) Guthabenverwaltung z) Zeit setzen\r\nn) Neues Getraenk\r\n");
}
BYTE c, nickname_len, single_match;
int einheiten;
char *nickname;
- if (status[n].item_name == NULL)
+ if (status.status[n].item_name == NULL)
cprintf("FEHLER: Diese Einheit existiert nicht.\r\n");
else {
- cprintf("Wieviel Einheiten \"%s\"?\r\n", status[n].item_name);
+ cprintf("Wieviel Einheiten \"%s\"?\r\n", status.status[n].item_name);
while (1) {
c = getchar();
if (c == 13)
nickname_len = strlen(nickname);
/* go through credits and remove the amount of money or set nickname
* to NULL if no such credit could be found */
- for (c = 0; c < num_credit_items; ++c)
- if (strncmp(nickname, credits[c].nickname, nickname_len) == 0) {
+ for (c = 0; c < credits.num_items; ++c)
+ if (strncmp(nickname, credits.credits[c].nickname, nickname_len) == 0) {
if (++matches == 2)
break;
else single_match = c;
}
if (matches == 1) {
- if (credits[single_match].credit < (status[n].price * einheiten)) {
+ if (credits.credits[single_match].credit < (status.status[n].price * einheiten)) {
cprintf("Sorry, %s hat nicht genug Geld :-(\r\n", nickname);
free(nickname);
return;
} else {
/* Geld abziehen */
- credits[single_match].credit -= (status[n].price * einheiten);
- cprintf("\r\nVerbleibendes Guthaben fuer %s: %d Cents. Druecke ANYKEY...\r\n", nickname, credits[single_match].credit);
+ credits.credits[single_match].credit -= (status.status[n].price * einheiten);
+ cprintf("\r\nVerbleibendes Guthaben fuer %s: %d Cents. Druecke ANYKEY...\r\n",
+ nickname, credits.credits[single_match].credit);
getchar();
}
} else if (matches == 0) {
nickname = NULL;
}
}
- status[n].times_sold += einheiten;
- money += status[n].price * einheiten;
+ status.status[n].times_sold += einheiten;
+ money += status.status[n].price * einheiten;
items_sold += einheiten;
if (printing == 1)
print_log(n, einheiten, nickname);
/* Zeit setzen */
set_time_interactive();
} else if (c == 'n') {
- strcpy(status[num_items].item_name, "mate");
- status[num_items].price = 23;
- status[num_items].times_sold = 5;
- num_items++;
+ strcpy(status.status[status.num_items].item_name, "mate");
+ status.status[status.num_items].price = 23;
+ status.status[status.num_items].times_sold = 5;
+ status.num_items++;
} else if (c == 'q')
break;
}