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:
+21
-84
@@ -1,93 +1,30 @@
|
||||
/*
|
||||
* time.c — getdatetime / setdatetime via ESTEX SYSTIME ($21) / SETTIME ($22).
|
||||
* time — текущие секунды Unix-эпохи из RTC (getdatetime / ESTEX
|
||||
* SYSTIME $21).
|
||||
*
|
||||
* $21 SYSTIME → D=day E=month IX=year H=hour L=min B=sec C=dow
|
||||
* $22 SETTIME D=day E=month IX=year H=hour L=min B=sec → CF=err / A=errcode
|
||||
* SDCC-шная z80.lib кладёт time/localtime/mktime И _RtcRead в один
|
||||
* модуль time.rel, так что _RtcRead нельзя переопределить из
|
||||
* отдельного объектника — будет "multiple definition". Обходим это,
|
||||
* реализуя весь POSIX time API сами; тогда линкер никогда не тянет
|
||||
* SDCC-шный time.rel.
|
||||
*
|
||||
* Struct layout (datetime_t, 8 bytes):
|
||||
* +0 day, +1 month, +2..3 year, +4 hour, +5 min, +6 sec, +7 dow
|
||||
*
|
||||
* Both routines write/read *dt directly — no static scratch. The key
|
||||
* trick in getdatetime is `ex (sp), hl` after RST: HL holds hour:min,
|
||||
* stack TOS holds dt — one byte swaps them, then we walk the struct
|
||||
* via HL. setdatetime uses IX as the struct pointer (re-loaded with
|
||||
* year just before RST since that's what SETTIME expects).
|
||||
* Эпоха — Unix (1970-01-01 00:00:00). Без таймзон и DST.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include "_time.h"
|
||||
|
||||
void getdatetime(datetime_t *dt) __naked
|
||||
time_t time(time_t *t)
|
||||
{
|
||||
(void)dt;
|
||||
__asm
|
||||
push ix ; save caller IX (BIOS clobbers it)
|
||||
push hl ; stash dt across RST (clobbers HL)
|
||||
ld c, #0x21 ; ESTEX SYSTIME
|
||||
rst #0x10
|
||||
;; Returns: D=day E=month IX=year H=hour L=min B=sec C=dow
|
||||
|
||||
;; ex (sp), hl: TOS<->HL. Now HL = dt, TOS = hour:min stash.
|
||||
ex (sp), hl
|
||||
ld (hl), d ; +0 day
|
||||
inc hl
|
||||
ld (hl), e ; +1 month
|
||||
inc hl
|
||||
push ix ; year → stack
|
||||
pop de ; DE = year
|
||||
ld (hl), e ; +2 year low
|
||||
inc hl
|
||||
ld (hl), d ; +3 year high
|
||||
inc hl
|
||||
pop de ; D = hour, E = min (from earlier ex(sp))
|
||||
ld (hl), d ; +4 hour
|
||||
inc hl
|
||||
ld (hl), e ; +5 min
|
||||
inc hl
|
||||
ld (hl), b ; +6 sec
|
||||
inc hl
|
||||
ld (hl), c ; +7 dow
|
||||
pop ix ; restore caller IX
|
||||
ret
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int setdatetime(const datetime_t *dt) __naked
|
||||
{
|
||||
(void)dt;
|
||||
__asm
|
||||
push ix ; save caller IX
|
||||
push hl
|
||||
pop ix ; IX = dt
|
||||
|
||||
ld d, (hl) ; +0 D = day
|
||||
inc hl
|
||||
ld e, (hl) ; +1 E = month
|
||||
inc hl
|
||||
ld c, (hl) ; +2 year low
|
||||
inc hl
|
||||
ld b, (hl) ; +3 year high (BC->IX)
|
||||
inc hl
|
||||
push bc
|
||||
ld b, (hl) ; +4 H = hour
|
||||
inc hl
|
||||
ld c, (hl) ; +5 L = min (BC->HL)
|
||||
inc hl
|
||||
push bc
|
||||
ld b, (hl) ; +6 B = sec
|
||||
pop hl
|
||||
pop ix
|
||||
ld c, #0x22 ; ESTEX SETTIME
|
||||
rst #0x10
|
||||
pop ix ; restore caller IX
|
||||
jr c, _st_err2
|
||||
ld de, #0
|
||||
ret
|
||||
_st_err2:
|
||||
call __errno_set
|
||||
ld de, #-1
|
||||
ret
|
||||
__endasm;
|
||||
datetime_t dt;
|
||||
getdatetime(&dt);
|
||||
unsigned long days = _tm_year_days(dt.year)
|
||||
+ _tm_month_days(dt.year, dt.month)
|
||||
+ (dt.day - 1);
|
||||
time_t epoch = days * 86400UL
|
||||
+ (unsigned long)dt.hour * 3600UL
|
||||
+ (unsigned long)dt.minute * 60UL
|
||||
+ dt.second;
|
||||
if (t) *t = epoch;
|
||||
return epoch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user