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 <noreply@anthropic.com>
This commit is contained in:
David Montero 2026-06-03 20:23:17 +02:00
parent e79368a04a
commit a57951d854
1 changed files with 4 additions and 1 deletions

View File

@ -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);