c71e249a4e
First substantive commit: the entire Sprinter C compiler tree on top of
the bare README+gitignore initial commit.
What's in here:
bin/sprinter-cc — driver script invoking SDCC + linker + mkexe
libc/ — Sprinter-specific libc layer over ESTEX/BIOS
(conio, gfx, io, mem, stdio + headers)
runtime/ — crt0 variants (default/small/banked/minimal)
+ heap + bank trampolines
toolchain/ — mkexe (SprintEXE packer, C + tests)
examples/ — 30 demo programs (gfx, file I/O, env, time, …)
lib/Makefile — builds the libc archive (sprinter.lib)
docs/ — converted Sprinter manuals + asm reference samples
third_party/ — solid-c reference compiler dump + sdcc setup script
release_docs/ — packaging / release notes
gitignore overhaul:
• Drop dangerous blanket patterns: *.asm (would hide docs/samples/*.asm)
and *.exe (case-insensitive match was hiding third_party/solid-c/*.EXE
on macOS APFS). Replaced with examples/*/*.{asm,exe,…} and lib/*.lib.
• Restore tracking of toolchain/mkexe/tests/{one,big}.bin — those are
INPUT fixtures, not build outputs.
• Collapse the duplicated SDCC/C/Sdcc sections into one section per
concern (build outputs / vendored / OS-junk).
• Add .sprinter-cc-*/, build/ (catches lib/build/ too), .claude/.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
94 lines
2.7 KiB
C
94 lines
2.7 KiB
C
/*
|
|
* getenv / putenv via ESTEX ENVIRON ($46).
|
|
*
|
|
* ESTEX $46 subfn 1 (getenv):
|
|
* in: HL = name (ASCIIZ), DE = output buffer (caller-owned)
|
|
* out: CF=0 + A != 0 → variable found, value written into [DE..end-1]
|
|
* CF=0 + A == 0 → variable not present (note: this is the
|
|
* opposite of what DiskSyscalls.txt v1.6 docs
|
|
* claim — verified empirically and against
|
|
* solid-c's IO.ASM:763-766 implementation)
|
|
* CF=1 → error, A = code
|
|
* DE on exit points at one past the last byte written
|
|
*
|
|
* ESTEX $46 subfn 2 (putenv):
|
|
* in: HL = "NAME=value" (NUL-terminated)
|
|
* out: CF=1 / A = error code on failure
|
|
*
|
|
* We hand back a pointer into a private 128-byte buffer for getenv().
|
|
* Caller must copy the bytes before the next getenv() call if they
|
|
* need to outlive it.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <sprinter.h>
|
|
|
|
static char env_buf[128];
|
|
|
|
char *getenv(const char *name) __naked
|
|
{
|
|
(void)name;
|
|
__asm
|
|
push ix
|
|
;; HL = name on entry; we need to also load DE = env_buf.
|
|
ld de, #_env_buf
|
|
ld bc, #0x0146 ; ESTEX ENVIRON; subfn: getenv
|
|
rst #0x10
|
|
pop ix
|
|
jr c, _getenv_err
|
|
or a, a
|
|
jr Z, _getenv_miss
|
|
ld de, #_env_buf
|
|
ret
|
|
_getenv_err:
|
|
call __errno_set
|
|
_getenv_miss:
|
|
ld de, #0
|
|
ret
|
|
__endasm;
|
|
}
|
|
|
|
int putenv(const char *namevalue) __naked
|
|
{
|
|
(void)namevalue;
|
|
__asm
|
|
push ix
|
|
ld bc, #0x0246 ; ESTEX ENVIRON; subfn: setenv
|
|
rst #0x10
|
|
pop ix
|
|
jr c, _putenv_err
|
|
ld de, #0
|
|
ret
|
|
_putenv_err:
|
|
call __errno_set
|
|
ld de, #-1
|
|
ret
|
|
__endasm;
|
|
}
|
|
|
|
/* ESTEX $46 subfn 0 (sysenv):
|
|
* in: HL = caller-owned buffer
|
|
* out: caller's buffer is filled with one NUL-terminated "NAME=value"
|
|
* per env var, then a trailing extra NUL marks the end:
|
|
* "PATH=...\0SOLID=H\0\0"
|
|
* return: buf on success, -1 on error (errno set).
|
|
* Buffer must be large enough for the whole environment.
|
|
*/
|
|
char *sysenv(char *buf) __naked
|
|
{
|
|
(void)buf;
|
|
__asm
|
|
push ix
|
|
push hl ; stash buffer pointer (= return value)
|
|
ld bc, #0x0046 ; ESTEX ENVIRON; subfn 0 = sysenv
|
|
rst #0x10
|
|
pop de ; DE = buffer pointer
|
|
pop ix
|
|
ret nc ; success: DE already has buf
|
|
;; CF=1 → A = ESTEX error code.
|
|
call __errno_set
|
|
ld de, #-1
|
|
ret
|
|
__endasm;
|
|
}
|