527d4a6a18
libc/mem/:
• Split bank_io.c into bank_io_w3.c (existing W3 helpers, base 0xC000,
port 0xE2) and bank_io_w1.c (new mirror through W1, base 0x4000,
port 0xA2). Two .rel files so DCE picks only the needed group:
a W3-only user pulls ~70 bytes instead of all 134. W1 variants are
`--memory tiny`-only (any other mode runs code from W1 or uses W1
for the banked-code segment, swapping it crashes).
• mem_alloc.c: add CF=err checks for mem_free_block and mem_get_page
(were silently ignored), per-function docstrings on alloc/free/
get_page/info, drop the confused "wait wrong order" comment in
mem_info. Header sprinter_mem.h gets matching per-function doc.
libc/stdio/:
• Add hex_print.c (hex8/hex16/hex32, ~26 bytes) and dec_print.c
(dec8/dec16/dec32, ~170 bytes) ported from solid-c STDLIB.ASM.
Replaces the printf("%u"/"%X") wrappers in solid_helpers.c that
dragged in the 3-5 KB printf machinery.
- hex* use the classic cp 10 / sbc 0x69 / daa nibble→ASCII trick;
hex8 self-calls for the high nibble, hex16/hex32 tail-call hex8.
- dec32 is the master routine; dec8/dec16 jump into shared entry
points (__dec_entry3 / __dec_entry5). 32-bit subtract-power-of-10
keeps the high 16 bits in HL alt (shadow set).
- DISCOVERY: ESTEX PUTCHAR ($5B) on our Sprinter build preserves
the main register set + IX but CLOBBERS the shadow set
(BC'/DE'/HL'). solid-c's original code assumed otherwise and
garbled output for values ≥ 6 digits. Fix: save/restore HL alt
around the RST 10 in _dec_emit_or_skip. Documented in
memory/estex_putchar_abi.md.
• file.c: drop stdaux/stdprn (no Sprinter printer API), change
stdin/stdout/stderr fd markers to 0/-1/-2 (positive fds clash with
ESTEX OPEN return values), add TODO header pointing at v2 buffered
FILE rewrite (see docs/TODO.md for the Solid-C reference struct).
bin/sprinter-cc:
• --memory big and --memory huge now always use crt0_banked.s (was:
only with --bank flags), matching docs/memory_modes_implemented.md.
When the user has no --bank flags, generate a tiny stub with
`const uint8_t n_banks = 0;` and assemble bank.s for _bank_pages.
Without this fix, openenv with --memory big could not see the
estex_file_handle symbol exported by crt0_banked.
examples/openenv:
• Add usage of estex_file_handle to confirm the crt0_banked startup-
info is reachable. Local extern decl — keeps the symbol out of
sprinter.h since it only exists in big/huge builds.
examples/dec_test:
• New regression test covering hex8/16/32 and dec8/16/32 across the
interesting boundary values.
.gitignore: add .kilo/ (editor session cache).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
83 lines
2.9 KiB
Makefile
83 lines
2.9 KiB
Makefile
# Build lib/libsprinter.lib — the Sprinter target libc archive.
|
|
#
|
|
# Includes all libc/*.c modules plus the runtime helpers that get
|
|
# auto-pulled by SDCC's codegen (heap for malloc, bank trampolines for
|
|
# __banked). The crt0 family is NOT in the lib — they are always
|
|
# explicitly linked, never DCE-eligible.
|
|
#
|
|
# Each .c file becomes its own .rel inside the archive. The linker
|
|
# pulls only those .rel files whose exported symbols are referenced,
|
|
# giving free dead-code elimination at module granularity.
|
|
|
|
PROJ_ROOT := $(abspath $(CURDIR)/..)
|
|
SDCC_BIN := $(PROJ_ROOT)/third_party/sdcc/bin
|
|
SDCC := $(SDCC_BIN)/sdcc
|
|
SDAR := $(SDCC_BIN)/sdar
|
|
SDASZ80 := $(SDCC_BIN)/sdasz80
|
|
|
|
INC := -I$(PROJ_ROOT)/libc/include
|
|
CC_FLAGS := -mz80 --no-std-crt0 --std-c99 --opt-code-size $(INC)
|
|
|
|
BUILD := $(PROJ_ROOT)/lib/build
|
|
|
|
# All libc C modules.
|
|
LIBC_C := \
|
|
libc/io/atexit.c libc/io/conio.c libc/io/cprintf.c libc/io/dir.c \
|
|
libc/io/videomode_raw.c \
|
|
libc/io/_errno_set.c \
|
|
libc/io/env.c libc/io/errno.c libc/io/fsdir.c \
|
|
libc/io/lseek.c libc/io/mouse.c libc/io/open.c \
|
|
libc/io/read.c libc/io/sleep.c \
|
|
libc/io/time.c libc/io/posix_time.c libc/io/unlink.c \
|
|
libc/io/stat.c \
|
|
libc/mem/bank_io_w3.c libc/mem/bank_io_w1.c libc/mem/mem_alloc.c \
|
|
libc/gfx/gfx_core.c libc/gfx/gfx_raw_common.c \
|
|
libc/gfx/gfx_raw_256.c libc/gfx/gfx_raw_16.c \
|
|
libc/gfx/gfx_256.c libc/gfx/gfx_16.c \
|
|
libc/gfx/gfx_font.c libc/gfx/gfx_text_256.c \
|
|
libc/gfx/gfx_text_16.c \
|
|
libc/stdio/getchar.c libc/stdio/print_hex.c \
|
|
libc/stdio/putchar.c libc/stdio/puts.c libc/stdio/file.c \
|
|
libc/stdio/hex_print.c libc/stdio/dec_print.c \
|
|
libc/stdio/solid_helpers.c \
|
|
libc/io/solid_compat.c
|
|
|
|
# Runtime modules to bundle (pulled by symbol references from libc-using code).
|
|
# NOTE: runtime/bank.s is NOT bundled — its trampoline depends on the banking
|
|
# window (W1 for BIG, W3 for HUGE) which is decided per-build by sprinter-cc.
|
|
# That tool assembles bank.s on each banked build with the right BANK_W1 flag.
|
|
RUNTIME_S := runtime/heap.s
|
|
|
|
LIBC_RELS := $(patsubst libc/%.c,$(BUILD)/%.rel,$(LIBC_C))
|
|
RUNTIME_RELS := $(patsubst runtime/%.s,$(BUILD)/%.rel,$(RUNTIME_S))
|
|
|
|
ALL_RELS := $(LIBC_RELS) $(RUNTIME_RELS)
|
|
|
|
LIB := sprinter.lib
|
|
|
|
all: $(LIB)
|
|
|
|
# Pattern rule for C modules — preserves the libc/io|mem|stdio path
|
|
# so .rel members keep their natural names inside the archive.
|
|
$(BUILD)/%.rel: $(PROJ_ROOT)/libc/%.c
|
|
@mkdir -p $(dir $@)
|
|
$(SDCC) $(CC_FLAGS) -c -o $@ $<
|
|
|
|
# Runtime .s → .rel
|
|
$(BUILD)/%.rel: $(PROJ_ROOT)/runtime/%.s
|
|
@mkdir -p $(dir $@)
|
|
$(SDASZ80) -o $@ $<
|
|
|
|
# Archive — sdar with `rcs` = replace/create/symtab.
|
|
$(LIB): $(ALL_RELS)
|
|
rm -f $@
|
|
$(SDAR) -rcs $@ $(ALL_RELS)
|
|
@echo
|
|
@echo " Built $@ with $(words $(ALL_RELS)) modules:"
|
|
@$(SDAR) -t $@ | sed 's/^/ /'
|
|
|
|
clean:
|
|
rm -rf $(BUILD) $(LIB)
|
|
|
|
.PHONY: all clean
|