Files
snark13 c71e249a4e Add full compiler toolchain, libc, examples and reference docs
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>
2026-06-03 16:13:21 +03:00

68 lines
1.7 KiB
C

/*
* read / write — bulk transfer through ESTEX file handles.
*
* ESTEX READ ($13) / WRITE ($14):
* A = handle, HL = buffer, DE = byte count
* → DE = bytes actually transferred, CF = err with code in A.
*
* SDCC __sdcccall(1) for 3-arg int functions uses callee-pops for the
* stack-passed argument; this implementation mirrors the pattern used
* by SDCC's own z80.lib _memset.
*
* On error: sets errno, returns -1.
*/
#include <unistd.h>
int read(int fd, void *buf, size_t n) __naked
{
(void)fd; (void)buf; (void)n;
__asm
pop iy ; IY = return address
pop bc ; BC = n (stack arg)
ld a, l ; A = handle
ex de, hl ; HL = buf
ld d, b
ld e, c ; DE = n
push ix
push iy ; preserve return addr across RST
ld c, #0x13 ; ESTEX READ
rst #0x10
pop iy
pop ix
jr c, _read_err
;; DE already holds count read.
jp (iy)
_read_err:
call __errno_set
ld de, #-1
jp (iy)
__endasm;
}
int write(int fd, const void *buf, size_t n) __naked
{
(void)fd; (void)buf; (void)n;
__asm
pop iy
pop bc
ld a, l
ex de, hl
ld d, b
ld e, c
push ix
push iy
ld c, #0x14
rst #0x10
pop iy
pop ix
jr c, _write_err
jp (iy)
_write_err:
call __errno_set
ld de, #-1
jp (iy)
__endasm;
}