libc: сплит «1 функция = 1 модуль» — вся библиотека, wildcard-сборка

- bios/conio/env/errno/gfx/io/mem/mouse/stdio/stdlib/string/sys/time/
  video разложены по модулям: общие статики и helpers — в internal
  _-модулях (_conio.h/_mouse.h/_gfx.h/_palette.h/_atexit.h/_time.h)
- lib/Makefile: LIBC_C = wildcard libc/*/*.c — гранулярность файлов
  = гранулярность DCE линкера
- эффект _CODE: gfx_text 6986→2568 Б, gfx_mous −1745, gfx_demo/d16
  −542; ранее timedir −3270, ls −3098, stattest −2995
- комментарии оставшихся модулей переведены на русский; puts: убран
  мёртвый pchars; videomode_raw разложен на get/set
- docs/libc-split-asm-cases.md — правила asm-связок между модулями;
  docs/libc-roadmap.md — план этапа
- восстановлен examples/mdview/SAMPLE.MD (нужен make floppy)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-06 16:08:58 +03:00
parent 46553f4e07
commit 4a081501d8
237 changed files with 4830 additions and 3933 deletions
-93
View File
@@ -1,93 +0,0 @@
/*
* 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;
}
+41
View File
@@ -0,0 +1,41 @@
/*
* getenv — значение переменной окружения через ESTEX ENVIRON ($46, subfn 1):
* in: HL = имя (ASCIIZ), DE = выходной буфер
* out: CF=0 + A != 0 → найдена, значение записано в [DE..end-1]
* CF=0 + A == 0 → переменной нет (примечание: это ПРОТИВОПОЛОЖНО
* тому, что пишет DiskSyscalls.txt v1.6 — проверено
* эмпирически и по solid-c IO.ASM:763-766)
* CF=1 → ошибка, A = код
*
* Возвращает указатель в приватный 128-байтный буфер — скопируй до
* следующего вызова getenv(), если значение должно пережить его.
* NULL — нет переменной или ошибка (errno).
*/
#include <stdint.h>
#include <sprinter.h>
static char env_buf[128];
char *getenv(const char *name) __naked
{
(void)name;
__asm
push ix
;; HL = имя на входе; дополнительно 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;
}
+26
View File
@@ -0,0 +1,26 @@
/*
* putenv — установить переменную окружения строкой "NAME=value" (ASCIIZ).
* ESTEX ENVIRON ($46, subfn 2): HL = строка; CF=1 / A = код при ошибке.
* Возвращает 0 или -1 + errno.
*/
#include <stdint.h>
#include <sprinter.h>
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;
}
+28
View File
@@ -0,0 +1,28 @@
/*
* sysenv — снять всё окружение в буфер вызывающего.
* ESTEX ENVIRON ($46, subfn 0): HL = буфер; на выходе буфер заполнен
* ASCIIZ-строками "NAME=value" подряд, конец — дополнительный NUL:
* "PATH=...\0SOLID=H\0\0"
* Буфер должен вмещать всё окружение. Возвращает buf или -1 + errno.
*/
#include <stdint.h>
#include <sprinter.h>
char *sysenv(char *buf) __naked
{
(void)buf;
__asm
push ix
push hl ; спрятать указатель (= возврат)
ld bc, #0x0046 ; ESTEX ENVIRON; subfn 0 = sysenv
rst #0x10
pop de ; DE = указатель буфера
pop ix
ret nc ; успех: DE уже держит buf
;; CF=1 A = код ошибки ESTEX.
call __errno_set
ld de, #-1
ret
__endasm;
}