]> git.sur5r.net Git - c128-kasse/commitdiff
kasse: allow starting up without a printer
authorMaik Fischer <maikf@qu.cx>
Sat, 28 Oct 2017 10:38:25 +0000 (12:38 +0200)
committerMaik Fischer <maikf@qu.cx>
Mon, 30 Oct 2017 10:10:51 +0000 (11:10 +0100)
Makefile
include/globals.h [new file with mode: 0644]
include/kasse.h
src/globals.c [new file with mode: 0644]
src/itemz.c
src/kasse.c
src/print.c

index 1df105e47f6445f124df0ea960ae096f60f564eb..de3ca5f51ab80c752f0b8f97982bc9c0bd92224c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,10 +23,10 @@ include/version.h:
 include/charset_umlauts.h:
        ./util/mkfont assets/umlauts.pbm chars_umlauts > $@
 
-kasse: build/config.o build/kasse.o build/general.o build/credit_manager.o build/c128time.o build/print.o build/vdc_patch_charset.o build/vdc_util.o
+kasse: build/config.o build/kasse.o build/general.o build/credit_manager.o build/c128time.o build/print.o build/vdc_patch_charset.o build/vdc_util.o build/globals.o
        ${LD} -Ln $@.lbl -t c128 $^ -o $@
 
-itemz: build/config.o build/itemz.o build/general.o build/credit_manager.o build/c128time.o build/print.o
+itemz: build/config.o build/itemz.o build/general.o build/credit_manager.o build/c128time.o build/print.o build/globals.o
        ${LD} -Ln $@.lbl -t c128 $^ -o $@
 
 cat: build/general.o build/cat.o
diff --git a/include/globals.h b/include/globals.h
new file mode 100644 (file)
index 0000000..00fca09
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _GLOBALS_H_
+#define _GLOBALS_H_
+
+#include <stdint.h>
+
+#ifdef _IS_GLOBALS_C
+#define GLOBAL
+#else
+#define GLOBAL extern
+#endif
+
+void init_globals(void);
+
+GLOBAL uint8_t printing;
+
+#endif // _GLOBALS_H_
index 93650f368f7c3ab92a681a01a0e59f2ab402ee8c..43a67dacea3e372a3fd4fc23299c081517ad2279 100644 (file)
@@ -3,7 +3,4 @@
 
 void print_the_buffer(void);
 
-#ifdef _IS_KASSE
-BYTE printing = 1;
-#endif
 #endif
diff --git a/src/globals.c b/src/globals.c
new file mode 100644 (file)
index 0000000..b759fe0
--- /dev/null
@@ -0,0 +1,7 @@
+#define _IS_GLOBALS_C
+#include "globals.h"
+
+void init_globals(void) {
+  printing = 1;
+  return;
+}
index 1606e3d642018db9fdb95c04206063e36798e96e..3f4d74972e6184330321674718ae295c893fbc9d 100644 (file)
@@ -17,6 +17,7 @@
 #include "credit_manager.h"
 #include "version.h"
 #include "vdc_patch_charset.h"
+#include "globals.h"
 
 static void itemz_print_screen(void) {
   BYTE i;
index 91b4268c9cd99b59423c48962d0fbd5597688652..d6ffb486c3ed5931eb46dd3956cb9d9b102b514f 100644 (file)
@@ -4,7 +4,6 @@
  * See LICENSE for license information
  *
  */
-#define _IS_KASSE
 #include <stdio.h>
 #include <conio.h>
 #include <stdlib.h>
@@ -21,6 +20,7 @@
 #include "print.h"
 #include "version.h"
 #include "vdc_patch_charset.h"
+#include "globals.h"
 // drucker 4 oder 5
 // graphic 4,0,10
 
@@ -355,6 +355,8 @@ int main(void) {
   char *c;
   char *time;
 
+  init_globals();
+
   videomode(VIDEOMODE_80x25);
 
   /* clock CPU at double the speed (a whopping 2 Mhz!) */
index 665f99feee090b7d19f34b0dca49eef3f084c92e..dee15994efe06e20309865f0154e96df3ddb49b2 100644 (file)
@@ -12,6 +12,7 @@
 #include "general.h"
 #define _IS_PRINT
 #include "print.h"
+#include "globals.h"
 
 /* NOTE: undocumented function which scratches files
    We need to use this function because linking unistd.h
@@ -36,19 +37,34 @@ void init_log(void) {
 }
 
 void print_the_buffer(void) {
-  BYTE c;
+  BYTE status;
+  char *c;
+
+  if (!printing)
+    return;
+
 RETRY:
-  c = cbm_open((BYTE)4, (BYTE)4, (BYTE)0, NULL);
-  if (c != 0) {
-    c128_perror(c, "cbm_open(printer)");
-    if (retry_or_quit() == 'q')
+  status = cbm_open((BYTE)4, (BYTE)4, (BYTE)0, NULL);
+  if (status != 0) {
+    c128_perror(status, "cbm_open(printer)");
+
+    do {
+      cprintf("\r\nr)etry, c)ontinue or q)uit?\r\n");
+      c = get_input();
+    } while ((*c != 'r') && (*c != 'c') && (*c != 'q'));
+
+    if (*c == 'q')
       exit(1);
+    else if (*c == 'c') {
+      printing = 0;
+      return;
+    }
 
     goto RETRY;
   }
-  c = cbm_write((BYTE)4, print_buffer, strlen(print_buffer));
-  if (c != strlen(print_buffer)) {
-    c128_perror(c, "write(printer)");
+  status = cbm_write((BYTE)4, print_buffer, strlen(print_buffer));
+  if (status != strlen(print_buffer)) {
+    c128_perror(status, "write(printer)");
     if (retry_or_quit() == 'q')
       exit(1);
     goto RETRY;