/* * setdatetime — запись RTC через ESTEX SETTIME ($22). * * $22 SETTIME D=day E=month IX=year H=hour L=min B=sec → CF=err / A=errcode * * Читает прямо из *dt — без статического скретча. IX используется как * указатель на структуру (перед RST перезагружается годом — так ждёт * SETTIME). Возврат: 0 или -1 + errno. */ #include #include 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; }