From a57951d8549b1375f661bad0cf34b4351c5d873b Mon Sep 17 00:00:00 2001 From: David Montero Date: Wed, 3 Jun 2026 20:23:17 +0200 Subject: [PATCH] fix(examples): z80-led-chaser-c dir must be signed char (SDCC z80) SDCC treats plain `char` as unsigned on Z80, so `dir = -1` read back as 255, `if (dir > 0)` was always true, the "walk right" branch never ran, and the bit just shifted left until it fell off the end and the LEDs went dark after one pass. Use `signed char dir`. Verified in a chip-WASM harness: with plain char the chaser does 8 LED writes then stops; with signed char it walks the bit back and forth continuously (14894 writes). Completes the C example fix together with dropping --code-loc 0x100 in c_compile.py. Co-Authored-By: Claude Opus 4.8 --- frontend/src/data/examples-retro-intel.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/data/examples-retro-intel.ts b/frontend/src/data/examples-retro-intel.ts index 8b38749a..20574eb4 100644 --- a/frontend/src/data/examples-retro-intel.ts +++ b/frontend/src/data/examples-retro-intel.ts @@ -58,7 +58,10 @@ static void delay(unsigned int loops) { void main(void) { unsigned char bit = 0x01; - char dir = 1; /* +1 = walking left, -1 = walking right */ + /* MUST be signed: SDCC treats plain \`char\` as unsigned on Z80, so + dir=-1 would read back as 255, the "walk right" branch would never + run, and the bit would just shift left off the end and stay dark. */ + signed char dir = 1; /* +1 = walking left, -1 = walking right */ while (1) { LED_OUT = bit; delay(5000);