Now using xyw_fenster global.
h3rald h3rald@h3rald.com
Mon, 19 Jan 2026 14:23:32 +0100
M
Makefile
→
Makefile
@@ -1,5 +1,10 @@
CC = gcc -CFLAGS = -Wall -Wextra -g +BASE_CFLAGS = -Wall -Wextra -g + +# fenster.h contains function bodies unless FENSTER_HEADER is defined. +# Define it for all translation units except one, so fenster_* is defined once. +CFLAGS = $(BASE_CFLAGS) -DFENSTER_HEADER +FENSTER_IMPL_CFLAGS = $(BASE_CFLAGS) SOURCES = xyw.c xywasm.c xywrun.c devices/console.c devices/clock.c devices/display.c OBJS = xyw.o xywasm.o xywrun.o devices/console.o devices/clock.o devices/display.o@@ -31,7 +36,7 @@ xyw.o: xyw.c xyw.h
$(CC) $(CFLAGS) -c xyw.c -o xyw.o xywrun.o: xywrun.c xyw.h fenster.h - $(CC) $(CFLAGS) -c xywrun.c -o xywrun.o + $(CC) $(FENSTER_IMPL_CFLAGS) -c xywrun.c -o xywrun.o xywasm.o: xywasm.c xyw.h $(CC) $(CFLAGS) -c xywasm.c -o xywasm.o
M
fenster.h
→
fenster.h
@@ -20,9 +20,9 @@ #include <stdlib.h>
struct fenster { - const char *title; - const int width; - const int height; + char *title; + int width; + int height; uint32_t *buf; int keys[256]; /* keys are mostly ASCII, but arrows are 17..20 */ int mod; /* mod is 4 bits mask, ctrl=1, shift=2, alt=4, meta=8 */
M
xyw.h
→
xyw.h
@@ -1,11 +1,16 @@
#ifndef XYW_H #define XYW_H +#include "fenster.h" + #define XYW_MODE_X 0x20 #define XYW_MODE_Y 0x40 #define XYW_MODE_W 0x80 #define XYW_TOTAL_INSTRUCTIONS 0x20 #define XYW_TOTAL_DEVICES 0x10 + +#define XYW_WIDTH 256 +#define XYW_HEIGHT 256 // clang-format off #define XYW_PEEKW(d) (*(d) << 8 | (d)[1])@@ -34,6 +39,7 @@
extern const char xyw_instructions[][4]; extern int xyw_debug; extern int xyw_zoom; +extern struct fenster xyw_fenster; extern xyw_device xyw_devices[XYW_TOTAL_DEVICES]; int xyw_assemble(const char *input, const char *output);
M
xywrun.c
→
xywrun.c
@@ -1,6 +1,5 @@
#include <stdio.h> #include <stdlib.h> -#include "fenster.h" #include "xyw.h" #include "devices/console.h"@@ -15,9 +14,6 @@ #define SYSTEM_MEMORY_START 0xfd00
#define USER_STACK_START 0xfd00 #define SYSTEM_STACK_START 0xfe00 #define DEVICE_AREA_START 0xff00 - -#define WIDTH 256 -#define HEIGHT 256 /* system device */ #define SYSTEM_STATE 0xff00@@ -60,6 +56,9 @@ static xyw_word yw_storage = 0; // 16-bit Y register storage
xyw_word *pc = &pc_storage; xyw_word *xw = &xw_storage; xyw_word *yw = &yw_storage; + +// Global window instance (declared in xyw.h) +struct fenster xyw_fenster; //// Helpers to retrieve device number and address within the device static inline int get_device(xyw_word addr)@@ -362,11 +361,14 @@ process_metadata();
// Set direct page to device page by default xyw_memory[SYSTEM_PAGE] = 0xff; // Initialize fenster - uint32_t buf[WIDTH * HEIGHT * xyw_zoom * xyw_zoom]; - struct fenster f = {.title = title, .width = WIDTH * xyw_zoom, .height = HEIGHT * xyw_zoom, .buf = buf}; - fenster_open(&f); + uint32_t buf[XYW_WIDTH * XYW_HEIGHT * xyw_zoom * xyw_zoom]; + xyw_fenster.title = title; + xyw_fenster.width = XYW_WIDTH * xyw_zoom; + xyw_fenster.height = XYW_HEIGHT * xyw_zoom; + xyw_fenster.buf = buf; + fenster_open(&xyw_fenster); xyw_byte paused = 0; - while (fenster_loop(&f) == 0 && xyw_memory[SYSTEM_STATE] && *pc < SYSTEM_MEMORY_START) + while (fenster_loop(&xyw_fenster) == 0 && xyw_memory[SYSTEM_STATE] && *pc < SYSTEM_MEMORY_START) { if (!paused) {@@ -414,6 +416,6 @@ // At present, JCN, JMP, JSR and RTS set the pc to 1 value less than the actual address
// because we are relying on the fact that pc will be incremented at the end of the loop (*pc)++; } - fenster_close(&f); + fenster_close(&xyw_fenster); return 0; }