From 750dbde18501efb6f9520d378475e3b58aea9ea4 Mon Sep 17 00:00:00 2001 From: Maik Fischer Date: Sat, 28 Oct 2017 12:38:25 +0200 Subject: [PATCH] kasse: allow starting up without a printer --- Makefile | 4 ++-- include/globals.h | 16 ++++++++++++++++ include/kasse.h | 3 --- src/globals.c | 7 +++++++ src/itemz.c | 1 + src/kasse.c | 4 +++- src/print.c | 32 ++++++++++++++++++++++++-------- 7 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 include/globals.h create mode 100644 src/globals.c diff --git a/Makefile b/Makefile index 1df105e..de3ca5f 100644 --- 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 index 0000000..00fca09 --- /dev/null +++ b/include/globals.h @@ -0,0 +1,16 @@ +#ifndef _GLOBALS_H_ +#define _GLOBALS_H_ + +#include + +#ifdef _IS_GLOBALS_C +#define GLOBAL +#else +#define GLOBAL extern +#endif + +void init_globals(void); + +GLOBAL uint8_t printing; + +#endif // _GLOBALS_H_ diff --git a/include/kasse.h b/include/kasse.h index 93650f3..43a67da 100644 --- a/include/kasse.h +++ b/include/kasse.h @@ -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 index 0000000..b759fe0 --- /dev/null +++ b/src/globals.c @@ -0,0 +1,7 @@ +#define _IS_GLOBALS_C +#include "globals.h" + +void init_globals(void) { + printing = 1; + return; +} diff --git a/src/itemz.c b/src/itemz.c index 1606e3d..3f4d749 100644 --- a/src/itemz.c +++ b/src/itemz.c @@ -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; diff --git a/src/kasse.c b/src/kasse.c index 91b4268..d6ffb48 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -4,7 +4,6 @@ * See LICENSE for license information * */ -#define _IS_KASSE #include #include #include @@ -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!) */ diff --git a/src/print.c b/src/print.c index 665f99f..dee1599 100644 --- a/src/print.c +++ b/src/print.c @@ -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; -- 2.39.5