5 static uint8_t frombcd(uint8_t v
)
13 uint32_t posix_time(void)
15 /* Days from March 1 for a specific month, starting in March */
16 static const unsigned int yday
[12] =
17 { 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337 };
18 com32sys_t ir
, d0
, d1
, t0
;
19 unsigned int c
, y
, mo
, d
, h
, m
, s
;
22 memset(&ir
, 0, sizeof ir
);
25 __intcall(0x1A, &ir
, &d0
);
28 __intcall(0x1A, &ir
, &t0
);
31 __intcall(0x1A, &ir
, &d1
);
33 if (t0
.ecx
.b
[1] < 0x12)
36 c
= frombcd(d0
.ecx
.b
[1]);
37 y
= frombcd(d0
.ecx
.b
[0]);
38 mo
= frombcd(d0
.edx
.b
[1]);
39 d
= frombcd(d0
.edx
.b
[0]);
41 h
= frombcd(t0
.ecx
.b
[1]);
42 m
= frombcd(t0
.ecx
.b
[0]);
43 s
= frombcd(t0
.edx
.b
[1]);
45 /* We of course have no idea about the timezone, so ignore it */
48 * Look for impossible dates... this code was written in 2010, so
49 * assume any century less than 20 is just broken.
55 /* Consider Jan and Feb as the last months of the previous year */
62 * Just in case: if the month is nonsense, don't read off the end
68 t
= y
*365 + y
/4 - y
/100 + y
/400 + yday
[mo
-3] + d
- 719469;