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
+10
View File
@@ -0,0 +1,10 @@
/*
* _pal_args — скретчи аргументов BIOS $A4 (только данные, см. _palette.h).
*/
#include "_palette.h"
uint8_t _pal_num;
uint8_t _pal_start;
uint8_t _pal_count;
uint16_t _pal_data;
+23
View File
@@ -0,0 +1,23 @@
/*
* _palette.h — внутренности палитровых модулей (НЕ публичный заголовок).
*
* Палитра Sprinter: BIOS $A4 PIC_SET_PAL / PIC_GET_PAL, $A6 SET_PAL_INIT.
* Направление в $A4 выбирает бит 7 регистра A:
* A = pal_num — запись из RAM в VRAM
* A = 0x80 | pal_num — чтение из VRAM в RAM
* pal_num 0..3 — графика, 4..7 — четыре текстовых плана.
*/
#ifndef _PALETTE_INTERNAL_H
#define _PALETTE_INTERNAL_H
#include <palette.h>
/* Скретчи для передачи аргументов в inline asm — SDCC __sdcccall(1)
* даёт только HL, остальное через память (данные в _pal_args.c;
* пишут pal_load и pal_get). */
extern uint8_t _pal_num;
extern uint8_t _pal_start;
extern uint8_t _pal_count;
extern uint16_t _pal_data;
#endif
+20
View File
@@ -0,0 +1,20 @@
/*
* _videomode_raw_get — текущий видеорежим (ESTEX GETVMOD $51),
* БЕЗ валидации класса режима. Используется и conio (публичный
* gettextmode), и gfx (gfx_init) — свой модуль, чтобы чисто
* графическая программа не тянула conio ради номера режима.
*/
#include <stdint.h>
uint8_t _videomode_raw_get(void) __naked
{
__asm
push ix
ld c, #0x51 ; ESTEX GETVMOD
rst #0x10
pop ix
;; uint8_t возвращается в A ESTEX уже положил режим туда.
ret
__endasm;
}
+30
View File
@@ -0,0 +1,30 @@
/*
* _videomode_raw_set — установить видеорежим (ESTEX SETVMOD $50),
* БЕЗ валидации класса режима. Публичный settextmode (conio)
* оборачивает его text-only проверкой; gfx_init/gfx_done зовут
* напрямую, чтобы входить В графические режимы.
* Возврат: 0 или -1 (errno из кода ESTEX).
*/
#include <stdint.h>
#include <errno.h>
int _videomode_raw_set(uint8_t mode) __naked
{
(void)mode;
__asm
;; SDCC __sdcccall(1): единственный uint8_t уже в A.
push ix
ld bc, #0x0050 ; ESTEX SETVMOD (B=0 (страница), C=0x50)
rst #0x10
jr c, _vmr_err
ld de, #0
pop ix
ret
_vmr_err:
call __errno_set
ld de, #-1
pop ix
ret
__endasm;
}
+28
View File
@@ -0,0 +1,28 @@
/*
* pal_get — прочитать блок палитровых записей из VRAM (BIOS $A4;
* тот же id функции, бит 7 регистра A переключает в чтение).
*/
#include "_palette.h"
void pal_get(uint8_t pal_num, uint8_t start, uint8_t count, uint8_t *bgr0)
{
_pal_num = (uint8_t)(pal_num | 0x80); /* бит 7 = чтение */
_pal_start = start;
_pal_count = count;
_pal_data = (uint16_t)(uintptr_t)bgr0;
__asm
push ix
ld a, (__pal_start)
ld e, a ; E = start
ld a, (__pal_count)
ld d, a ; D = count (0 = 256)
ld hl, (__pal_data) ; HL = буфер
ld b, #0xFF ; B = маска
ld a, (__pal_num) ; A = 0x80 | pal_num чтение
ld c, #0xA4 ; BIOS PIC_GET_PAL (= $A4)
rst #0x08
pop ix
__endasm;
}
+16
View File
@@ -0,0 +1,16 @@
/*
* pal_get_color — прочитать одну палитровую запись в R/G/B
* (любой указатель может быть NULL).
*/
#include "_palette.h"
void pal_get_color(uint8_t pal_num, uint8_t slot,
uint8_t *r, uint8_t *g, uint8_t *b)
{
uint8_t entry[4];
pal_get(pal_num, slot, 1, entry);
if (b) *b = entry[0];
if (g) *g = entry[1];
if (r) *r = entry[2];
}
+30
View File
@@ -0,0 +1,30 @@
/*
* pal_load — записать блок палитровых записей в VRAM
* (BIOS $A4 PIC_SET_PAL): pal_num 0..7, start — первый слот,
* count слотов (0 = 256), bgr0 — записи по 4 байта (B, G, R, 0).
*/
#include "_palette.h"
void pal_load(uint8_t pal_num, uint8_t start, uint8_t count,
const uint8_t *bgr0)
{
_pal_num = pal_num;
_pal_start = start;
_pal_count = count;
_pal_data = (uint16_t)(uintptr_t)bgr0;
__asm
push ix
ld a, (__pal_start)
ld e, a ; E = start
ld a, (__pal_count)
ld d, a ; D = count (0 = 256)
ld hl, (__pal_data) ; HL = данные
ld b, #0xFF ; B = маска (без AND)
ld a, (__pal_num) ; A = номер палитры (бит 7 = 0: запись)
ld c, #0xA4 ; BIOS PIC_SET_PAL
rst #0x08
pop ix
__endasm;
}
+14
View File
@@ -0,0 +1,14 @@
/*
* pal_reset — восстановить палитру по умолчанию типа `type` во всех
* четырёх текстовых палитровых страницах (4..7).
*/
#include "_palette.h"
void pal_reset(uint8_t type)
{
pal_reset_at(type, 4, 0);
pal_reset_at(type, 5, 0);
pal_reset_at(type, 6, 0);
pal_reset_at(type, 7, 0);
}
+30
View File
@@ -0,0 +1,30 @@
/*
* pal_reset_at — восстановить встроенную палитру по умолчанию
* (BIOS $A6 SET_PAL_INIT): A = pal_page, E = графическая палитра
* (0..3), B = тип — PAL_GRAPH (1) / PAL_SINCLAIR (2) / PAL_CGA (3).
*/
#include "_palette.h"
static uint8_t reset_page_;
static uint8_t reset_graph_;
static uint8_t reset_type_;
void pal_reset_at(uint8_t type, uint8_t pal_page, uint8_t graph_pal)
{
reset_type_ = type;
reset_page_ = pal_page;
reset_graph_ = graph_pal;
__asm
push ix
ld a, (_reset_graph_)
ld e, a ; E = индекс графической палитры (0..3)
ld a, (_reset_type_)
ld b, a ; B = тип (1=GRAPH, 2=SINCLAIR, 3=CGA)
ld a, (_reset_page_) ; A = палитровая страница (последним A занят)
ld c, #0xA6 ; BIOS SET_PAL_INIT
rst #0x08
pop ix
__endasm;
}
+17
View File
@@ -0,0 +1,17 @@
/*
* pal_set_color — одна палитровая запись из RGB: собирает четвёрку
* (B, G, R, 0) и зовёт pal_load(pal_num, slot, 1, ...).
*/
#include "_palette.h"
void pal_set_color(uint8_t pal_num, uint8_t slot,
uint8_t r, uint8_t g, uint8_t b)
{
uint8_t entry[4];
entry[0] = b;
entry[1] = g;
entry[2] = r;
entry[3] = 0;
pal_load(pal_num, slot, 1, entry);
}
-131
View File
@@ -1,131 +0,0 @@
/*
* palette.c — Sprinter palette (BIOS $A4 PIC_SET_PAL / PIC_GET_PAL,
* BIOS $A6 SET_PAL_INIT).
*
* Direction in $A4 is selected by bit 7 of A:
* A = pal_num → write entries from RAM to VRAM
* A = 0x80 | pal_num → read entries from VRAM into RAM
*
* Lives under libc/video/ because palette control is shared between
* graphics (mode 0x81/0x82) and text (mode 0x03) — pal_num 0..3 for
* graphics, 4..7 for the four text-mode planes. The conio and gfx
* subsystems each ship thin domain-specific wrappers on top.
*/
#include <stdint.h>
#include <palette.h>
/* Statics used to pass parameters to the inline asm — SDCC __sdcccall(1)
* gives us only HL natively, so the rest go through memory. */
static uint8_t pal_num_;
static uint8_t pal_start_;
static uint8_t pal_count_;
static uint16_t pal_data_;
/* ---- $A4 PIC_SET_PAL — write entries to VRAM --------------------- */
void pal_load(uint8_t pal_num, uint8_t start, uint8_t count,
const uint8_t *bgr0)
{
pal_num_ = pal_num;
pal_start_ = start;
pal_count_ = count;
pal_data_ = (uint16_t)(uintptr_t)bgr0;
__asm
push ix
ld a, (_pal_start_)
ld e, a ; E = start
ld a, (_pal_count_)
ld d, a ; D = count (0 256)
ld hl, (_pal_data_) ; HL = data
ld b, #0xFF ; B = mask (no AND)
ld a, (_pal_num_) ; A = palette number (bit7 = 0 write)
ld c, #0xA4 ; BIOS PIC_SET_PAL
rst #0x08
pop ix
__endasm;
}
/* ---- $A4 PIC_GET_PAL — read entries from VRAM -------------------- *
* Same function id; bit 7 of A flips it to read mode. */
void pal_get(uint8_t pal_num, uint8_t start, uint8_t count, uint8_t *bgr0)
{
pal_num_ = (uint8_t)(pal_num | 0x80); /* bit 7 = read */
pal_start_ = start;
pal_count_ = count;
pal_data_ = (uint16_t)(uintptr_t)bgr0;
__asm
push ix
ld a, (_pal_start_)
ld e, a ; E = start
ld a, (_pal_count_)
ld d, a ; D = count (0 256)
ld hl, (_pal_data_) ; HL = buffer
ld b, #0xFF ; B = mask
ld a, (_pal_num_) ; A = 0x80 | pal_num read
ld c, #0xA4 ; BIOS PIC_GET_PAL (= $A4)
rst #0x08
pop ix
__endasm;
}
/* ---- one-colour helpers ------------------------------------------ */
void pal_set_color(uint8_t pal_num, uint8_t slot,
uint8_t r, uint8_t g, uint8_t b)
{
uint8_t entry[4];
entry[0] = b;
entry[1] = g;
entry[2] = r;
entry[3] = 0;
pal_load(pal_num, slot, 1, entry);
}
void pal_get_color(uint8_t pal_num, uint8_t slot,
uint8_t *r, uint8_t *g, uint8_t *b)
{
uint8_t entry[4];
pal_get(pal_num, slot, 1, entry);
if (b) *b = entry[0];
if (g) *g = entry[1];
if (r) *r = entry[2];
}
/* ---- $A6 SET_PAL_INIT — restore a built-in default palette ------- *
* Signature: A = pal_page, E = graphics palette index (0..3), B = type.
* Type is one of PAL_GRAPH (1) / PAL_SINCLAIR (2) / PAL_CGA (3). */
static uint8_t reset_page_;
static uint8_t reset_graph_;
static uint8_t reset_type_;
void pal_reset_at(uint8_t type, uint8_t pal_page, uint8_t graph_pal)
{
reset_type_ = type;
reset_page_ = pal_page;
reset_graph_ = graph_pal;
__asm
push ix
ld a, (_reset_graph_)
ld e, a ; E = graphics palette index (0..3)
ld a, (_reset_type_)
ld b, a ; B = type (1=GRAPH, 2=SINCLAIR, 3=CGA)
ld a, (_reset_page_) ; A = palette page (last A is needed)
ld c, #0xA6 ; BIOS SET_PAL_INIT
rst #0x08
pop ix
__endasm;
}
void pal_reset(uint8_t type)
{
pal_reset_at(type, 4, 0);
pal_reset_at(type, 5, 0);
pal_reset_at(type, 6, 0);
pal_reset_at(type, 7, 0);
}
-46
View File
@@ -1,46 +0,0 @@
/*
* videomode_raw.c — low-level ESTEX SETVMOD / GETVMOD ($50 / $51).
*
* Plain getters/setters with NO mode-class validation. Used by both
* conio (text-validated public API) and gfx (graphics modes). Lives
* in its own .c so a pure graphics program does not pull in the entire
* conio module to switch modes.
*
* Public conio functions in conio.c wrap these with a text-mode check;
* gfx_init / gfx_done in gfx_core.c call them directly.
*/
#include <stdint.h>
#include <errno.h>
uint8_t _videomode_raw_get(void) __naked
{
__asm
push ix
ld c, #0x51 ; ESTEX GETVMOD
rst #0x10
pop ix
;; uint8_t returns in A ESTEX already put mode there.
ret
__endasm;
}
int _videomode_raw_set(uint8_t mode) __naked
{
(void)mode;
__asm
;; SDCC __sdcccall(1) passes uint8_t in A leave it there.
push ix
ld bc, #0x0050 ; ESTEX SETVMOD (B=0 (page), C=0x50)
rst #0x10
jr c, _vmr_err
ld de, #0
pop ix
ret
_vmr_err:
call __errno_set
ld de, #-1
pop ix
ret
__endasm;
}