]> git.sur5r.net Git - c128-kasse/blobdiff - src/kasse.c
use cget_return() to wait for a RETURN key press
[c128-kasse] / src / kasse.c
index 53141dcdd080a6d72c0e540855a5f60f8e912a56..aa112f3706705cf4f1463369fc6219561183060f 100644 (file)
@@ -10,6 +10,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <cbm.h>
+#include <c128.h>
+#include <6502.h>
 
 #include "general.h"
 #include "config.h"
@@ -18,6 +20,7 @@
 #include "c128time.h"
 #include "print.h"
 #include "version.h"
+#include "vdc_patch_charset.h"
 // drucker 4 oder 5
 // graphic 4,0,10
 
@@ -31,7 +34,7 @@ void print_item(BYTE i) {
   textcolor(TC_YELLOW);
   cprintf("%2d", i);
   textcolor(TC_LIGHT_GRAY);
-  cprintf(": %-" xstr(MAX_ITEM_NAME_LENGTH) "s \xDD%s, %3dx ",
+  cprintf(": %-" xstr(MAX_ITEM_NAME_LENGTH) "s \xDD%s,   %3dx ",
           status.status[i].item_name, profit, status.status[i].times_sold);
 }
 
@@ -41,12 +44,12 @@ static void print_screen(void) {
   char *time = get_time();
   char profit[10];
   clrscr();
-  if (format_euro(profit, 10, money) == NULL) {
+  if (format_euro(profit, sizeof(profit), money) == NULL) {
     cprintf("Einnahme %ld konnte nicht umgerechnet werden\r\n", money);
     exit(1);
   }
   textcolor(TC_CYAN);
-  cprintf("C128-Kassenprogramm (phil_fry, sECuRE, sur5r) " GV "\r\n");
+  cprintf("C128-Kassenprogramm (phil_fry, sECuRE, sur5r, mxf) " GV "\r\n");
   textcolor(TC_LIGHT_GRAY);
   cprintf("\r\nUhrzeit:     %s (wird nicht aktualisiert)\r\n"
           "Eingenommen: %s, Verkauft: %ld Dinge, Drucken: %s\r\n",
@@ -123,7 +126,7 @@ static void print_log(char *name, int item_price, int einheiten, char *nickname,
      + 7 leerzeichen
      --> 48 zeichen
      */
-  if (format_euro(price, 10, item_price) == NULL) {
+  if (format_euro(price, sizeof(price), item_price) == NULL) {
     cprintf("Preis %d konnte nicht umgerechnet werden\r\n", item_price);
     exit(1);
   }
@@ -144,12 +147,11 @@ static signed int buy(char *name, unsigned int price) {
   BYTE c, x, y, nickname_len;
   int einheiten;
   char nickname[NICKNAME_MAX_LEN + 1];
-  char rest[11];
+  char rest[10];
   struct credits_t *credit;
 
   memset(nickname, '\0', sizeof(nickname));
-  memset(rest, ' ', sizeof(rest));
-  rest[8] = '\0';
+  memset(rest, '\0', sizeof(rest));
 
   clrscr();
   cprintf("Wieviel Einheiten \"%s\"? [1] \r\n", name);
@@ -157,7 +159,7 @@ static signed int buy(char *name, unsigned int price) {
   y = wherey();
   while (1) {
     /* Buffer-Ende erreicht? */
-    if (i == 4)
+    if (i == (sizeof(entered) - 1))
       break;
 
     c = cgetc();
@@ -173,9 +175,9 @@ static signed int buy(char *name, unsigned int price) {
       gotoxy(x + i, y);
       continue;
     }
-    if (c == 27) {
-      cprintf("Kauf abgebrochen, druecke RETURN...\r\n");
-      get_input();
+    if (c == PETSCII_ESC) {
+      cprintf("Kauf abgebrochen, dr" uUML "cke RETURN...\r\n");
+      cget_return();
       return 1;
     }
     if (c == '-' && i == 0) {
@@ -191,7 +193,7 @@ static signed int buy(char *name, unsigned int price) {
   einheiten = atoi(entered) * negative;
 
   if (einheiten > 100 || einheiten < -100 || einheiten == 0) {
-    cprintf("\r\nEinheit nicht in [-100, 100] oder 0, Abbruch, druecke "
+    cprintf("\r\nEinheit nicht in [-100, 100] oder 0, Abbruch, dr" uUML "cke "
             "RETURN...\r\n");
     cgetc();
     return 1;
@@ -272,14 +274,14 @@ static signed int buy(char *name, unsigned int price) {
     }
   }
 
-  if (*nickname != '\0' && *nickname != 32) {
+  if (*nickname != '\0' && *nickname != PETSCII_SP) {
     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 */
     credit = find_credit(nickname);
     if (credit != NULL) {
       while ((signed int)credit->credit < ((signed int)price * einheiten)) {
-        if (format_euro(rest, 10, credit->credit) == NULL) {
+        if (format_euro(rest, sizeof(rest), credit->credit) == NULL) {
           cprintf("Preis %d konnte nicht umgerechnet werden\r\n",
                   credit->credit);
           exit(1);
@@ -297,23 +299,24 @@ static signed int buy(char *name, unsigned int price) {
       /* substract money */
       credit->credit -= (price * einheiten);
 
-      if (format_euro(rest, 10, credit->credit) == NULL) {
+      if (format_euro(rest, sizeof(rest), credit->credit) == NULL) {
         cprintf("Preis %d konnte nicht umgerechnet werden\r\n", credit->credit);
         exit(1);
       }
 
       textcolor(TC_LIGHT_GREEN);
-      cprintf("\r\nVerbleibendes Guthaben fuer %s: %s. Druecke RETURN...\r\n",
+      cprintf("\r\nVerbleibendes Guthaben f" uUML "r %s: %s. Dr" uUML
+              "cke RETURN...\r\n",
               nickname, rest);
       textcolor(TC_LIGHT_GRAY);
-      get_input();
+      cget_return();
       matches++;
     } else {
       textcolor(TC_LIGHT_RED);
       cprintf("\r\nNickname nicht gefunden in der Guthabenverwaltung! Abbruch, "
-              "druecke RETURN...\r\n");
+              "dr" uUML "cke RETURN...\r\n");
       textcolor(TC_LIGHT_GRAY);
-      get_input();
+      cget_return();
       return 0;
     }
   } else {
@@ -333,7 +336,7 @@ static signed int buy(char *name, unsigned int price) {
 void buy_stock(BYTE n) {
   if (n >= status.num_items || status.status[n].item_name == NULL) {
     cprintf("FEHLER: Diese Einheit existiert nicht.\r\n");
-    get_input();
+    cget_return();
     return;
   }
 
@@ -349,26 +352,26 @@ void buy_custom(void) {
   int price;
 
   clrscr();
-  memset(name, '\0', 20);
+  memset(name, '\0', sizeof(name));
   cprintf("\r\nWas soll gekauft werden?\r\n");
   input = get_input();
-  strncpy(name, input, 20);
+  strncpy(name, input, sizeof(name));
   if (*name == '\0')
     return;
 
   cprintf("\r\nWie teuer ist \"%s\" (in cents)?\r\n", name);
   while (1) {
     c = cgetc();
-    if (c == 13)
+    if (c == PETSCII_CR)
       break;
     cputc(c);
-    if (c == 27) {
-      cprintf("Kauf abgebrochen, druecke RETURN...\r\n");
-      get_input();
+    if (c == PETSCII_ESC) {
+      cprintf("Kauf abgebrochen, dr" uUML "cke RETURN...\r\n");
+      cget_return();
       return;
     } else if (c == '-' && i == 0)
       negative = -1;
-    else if (c > 47 && c < 58)
+    else if (c >= PETSCII_0 && c <= PETSCII_9)
       entered[i++] = c;
   }
   price = atoi(entered) * negative;
@@ -403,12 +406,19 @@ int main(void) {
   char *c;
   char *time;
 
-  if (VIDEOMODE == 40)
-    videomode(80);
+  videomode(VIDEOMODE_80x25);
 
   /* clock CPU at double the speed (a whopping 2 Mhz!) */
   fast();
 
+  /* Manipulate the VDC with IRQs turned off.
+   * KERNALs default IRQ handler will also try to read the VDC status
+   * register, which could interfere with our code trying to read it.
+   */
+  SEI();
+  vdc_patch_charset();
+  CLI();
+
   clrscr();
 
   /* Allocate logging buffer memory */
@@ -447,18 +457,22 @@ int main(void) {
     print_screen();
     c = get_input();
     /* ...display dialogs eventually */
-    if (*c > 47 && *c < 58) {
+    if (*c >= PETSCII_0 && *c <= PETSCII_9) {
       /* if the input starts with a digit, we will interpret it as a number
        * for the item to be sold */
       buy_stock(atoi(c));
     } else if (*c == 'f') {
       buy_custom();
     } else if (*c == 's') {
+      cprintf("\r\nsaving items.. ");
       save_items();
+      cprintf("ok\r\nsaving credits.. ");
       save_credits();
+      cprintf("ok\r\nflushing log.. ");
       log_flush();
-      cprintf("\r\nStatefile/Creditfile/Log gesichert, druecke RETURN...\r\n");
-      get_input();
+      cprintf("ok\r\nStatefile/Creditfile/Log gesichert, dr" uUML
+              "cke RETURN...\r\n");
+      cget_return();
     } else if (*c == 'g') {
       credit_manager();
     } else if (*c == 'z') {