14 static int syncrtc
= 1;
16 rcvar_t rtc_exports
[] =
18 RCV_BOOL("syncrtc", &syncrtc
),
23 void rtc_latch(byte b
)
25 if ((rtc
.latch
^ b
) & b
& 1)
31 rtc
.regs
[4] = (rtc
.d
>>9) | (rtc
.stop
<<6) | (rtc
.carry
<<7);
39 void rtc_write(byte b
)
41 /* printf("write %02X: %02X (%d)\n", rtc.sel, b, b); */
42 if (!(rtc
.sel
& 8)) return;
46 rtc
.s
= rtc
.regs
[0] = b
;
47 while (rtc
.s
>= 60) rtc
.s
-= 60;
50 rtc
.m
= rtc
.regs
[1] = b
;
51 while (rtc
.m
>= 60) rtc
.m
-= 60;
54 rtc
.h
= rtc
.regs
[2] = b
;
55 while (rtc
.h
>= 24) rtc
.h
-= 24;
59 rtc
.d
= (rtc
.d
& 0x100) | b
;
63 rtc
.d
= (rtc
.d
& 0xff) | ((b
&1)<<9);
96 void rtc_save_internal(FILE *f
)
98 fprintf(f
, "%d %d %d %02d %02d %02d %02d\n%ld\n",
99 rtc
.carry
, rtc
.stop
, rtc
.d
, rtc
.h
, rtc
.m
, rtc
.s
, rtc
.t
,
103 void rtc_load_internal(FILE *f
)
107 f
, "%d %d %d %02d %02d %02d %02d\n%d\n",
108 &rtc
.carry
, &rtc
.stop
, &rtc
.d
,
109 &rtc
.h
, &rtc
.m
, &rtc
.s
, &rtc
.t
, &rt
);
110 while (rtc
.t
>= 60) rtc
.t
-= 60;
111 while (rtc
.s
>= 60) rtc
.s
-= 60;
112 while (rtc
.m
>= 60) rtc
.m
-= 60;
113 while (rtc
.h
>= 24) rtc
.h
-= 24;
114 while (rtc
.d
>= 365) rtc
.d
-= 365;
117 if (rt
) rt
= (time(0) - rt
) * 60;
118 if (syncrtc
) while (rt
-- > 0) rtc_tick();