fix(examples): z80-led-chaser-c set the Z80 stack pointer in main

SDCC's z80 crt0 defaults SP to 0x0000; on the z80-cpu chip's memory map
(RAM 0x8000-0xBFFF, MMIO at 0xC000+) the stack would grow into unmapped
high memory and the program crashed on the first CALL (delay), so the LEDs
never moved. Set SP to the top of RAM (0xBFFF) at the start of main, the
same thing the asm Larson example does with "LD SP, 0xBFFF". Verified the
ROM runs and walks the LEDs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
David Montero 2026-06-03 06:09:28 +02:00
parent a77dbcafad
commit bf36487642
1 changed files with 9 additions and 0 deletions

View File

@ -57,6 +57,15 @@ static void delay(unsigned int loops) {
}
void main(void) {
/* Park the stack at the top of the chip's 16 KB RAM (0x8000-0xBFFF).
SDCC's crt0 defaults SP to 0x0000; on this chip's memory map (RAM
0x8000-0xBFFF, MMIO at 0xC000+) that would push the stack onto
unmapped high memory and crash on the first CALL. The asm Larson
example does the same with "LD SP, 0xBFFF". */
__asm
ld sp, #0xBFFF
__endasm;
unsigned char bit = 0x01;
char dir = 1; /* +1 = walking left, -1 = walking right */
while (1) {