From cd0e2209005feaa36e1f98877c2d874161d74c9c Mon Sep 17 00:00:00 2001 From: Maik Fischer Date: Thu, 2 Nov 2017 19:15:34 +0100 Subject: [PATCH] speed up interrupt handler by directly writing to VDC RAM --- Makefile | 2 +- include/globals.h | 2 -- src/c128time.c | 21 ++++++++++++--------- src/globals.c | 8 -------- src/kasse.c | 13 +++++++++---- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 5cc4086..90b2af8 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ include/charset_umlauts.h: assets/umlauts.pbm 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 build/bcd2dec.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 build/globals.o +itemz: build/config.o build/itemz.o build/general.o build/credit_manager.o build/c128time.o build/print.o build/globals.o build/bcd2dec.o build/vdc_util.o ${LD} -Ln $@.lbl -t c128 $^ -o $@ cat: build/general.o build/cat.o build/config.o build/print.o build/globals.o diff --git a/include/globals.h b/include/globals.h index c92bda1..ec83854 100644 --- a/include/globals.h +++ b/include/globals.h @@ -11,8 +11,6 @@ #define GLOBAL extern #endif -void init_globals(void); - GLOBAL uint8_t printing; GLOBAL enum kasse_menu kasse_menu; GLOBAL struct daytime_t daytime; diff --git a/src/c128time.c b/src/c128time.c index f631e84..9d05903 100644 --- a/src/c128time.c +++ b/src/c128time.c @@ -1,6 +1,6 @@ /* * RGB2R-C128-Kassenprogramm - * © 2007-2009 phil_fry, sECuRE, sur5r + * © 2007-2017 phil_fry, sECuRE, sur5r, mxf * See LICENSE for license information * */ @@ -15,6 +15,7 @@ #include "bcd2dec.h" #include "general.h" #include "globals.h" +#include "vdc_util.h" /* This file uses the CIA TOD (Complex Interface Adapter, Time of Day) * for timekeeping, see https://www.c64-wiki.com/wiki/CIA and its Links section @@ -23,11 +24,17 @@ /* the Time of Day PM bit is set for hours >= 12 */ #define TOD_PM 0x80 +/* VDC charmap starts at 0x0000; 80 chars per line. + * We want to draw at 72 chars on the 1st line. + */ +#define CLOCK_ADDR 72 + +/* arbitrarly chosen stack size, should be large enough */ #define DAYTIME_IRQ_STACK_SIZE 32 uint8_t daytime_irq_stack[DAYTIME_IRQ_STACK_SIZE]; void update_time(void) { - volatile static uint8_t bcd_hour, hour, min, sec, tenth; + uint8_t bcd_hour, hour, min, sec, dummy; /* Read the hour register first to stop the clock from updating the external * registers from the internal (still ticking!) CIA registers. */ @@ -49,7 +56,7 @@ void update_time(void) { min = bcd2dec(CIA1.tod_min); /* MUST read tod_10 to enable the clock latch again */ - tenth = CIA1.tod_10; + dummy = CIA1.tod_10; /* it's a new day when hour wraps */ if (daytime.hour > hour) { @@ -104,16 +111,12 @@ void set_time(uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) { } uint8_t _daytime_irq(void) { - static char *t; - static uint8_t x, y; + char *t; /* We are called 60 times a second. We only want to draw a clock * when we are a) on the mainscreen and b) the seconds changed */ if (kasse_menu == MENU_MAIN && CIA1.tod_sec != daytime.sec) { t = get_time(); - x = wherex(); - y = wherey(); - cputsxy(70, 3, t); - gotoxy(x, y); + vdc_write_mem(CLOCK_ADDR, t, 8); } /* always call additional handlers */ return (IRQ_NOT_HANDLED); diff --git a/src/globals.c b/src/globals.c index 014b556..0443cbb 100644 --- a/src/globals.c +++ b/src/globals.c @@ -1,10 +1,2 @@ #define IS_GLOBALS_C #include "globals.h" - -void init_globals(void) { - printing = 1; - /* initialize daytime global, start the CIA TOD */ - set_time(0, 0, 0, 0); - kasse_menu = MENU_UNDEFINED; - return; -} diff --git a/src/kasse.c b/src/kasse.c index d2e5560..54521e6 100644 --- a/src/kasse.c +++ b/src/kasse.c @@ -48,9 +48,10 @@ static void print_screen(void) { profit[0] = '\0'; } textcolor(TC_CYAN); - cprintf("C128-Kassenprogramm (phil_fry, sECuRE, sur5r, mxf) " GV "\r\n"); + /* fill whole line with cyan, so color bits are set up for the clock */ + cprintf("%-80s", "C128-Kasse (phil_fry, sECuRE, sur5r, mxf) " GV); textcolor(TC_LIGHT_GRAY); - cprintf("\r\n\r\n" + cprintf("\r\n\r\n\r\n" "Ertrag: %s (%ld Artikel); Drucken: %s\r\n", profit, items_sold, (printing == 1 ? "ein" : "aus")); textcolor(TC_LIGHT_GRAY); @@ -272,7 +273,8 @@ void set_time_interactive(void) { uint8_t day, tp1, tp2, tp3; char *time_input, *time; cprintf("Gib den aktuellen Tag des Events und Uhrzeit ein\r\n" - "(Format DHHMMSS):\r\n"); + "Format DHHMMSS, 0-indexiert, z.B. 0174259 für \"erster Tag um " + "17:42:59\":\r\n"); time_input = get_input(); part[0] = time_input[0]; day = atoi(part); @@ -295,7 +297,10 @@ int main(void) { char *c; char *time; - init_globals(); + printing = 1; + /* initialize daytime global, start the CIA TOD */ + set_time(0, 0, 0, 0); + kasse_menu = MENU_UNDEFINED; videomode(VIDEOMODE_80x25); -- 2.39.5