4 #include "rockmacros.h"
13 void rtc_latch(byte b
)
15 if ((rtc
.latch
^ b
) & b
& 1)
21 rtc
.regs
[4] = (rtc
.d
>>9) | (rtc
.stop
<<6) | (rtc
.carry
<<7);
29 void rtc_write(byte b
)
31 /* printf("write %02X: %02X (%d)\n", rtc.sel, b, b); */
32 if (!(rtc
.sel
& 8)) return;
36 rtc
.s
= rtc
.regs
[0] = b
;
37 while (rtc
.s
>= 60) rtc
.s
-= 60;
40 rtc
.m
= rtc
.regs
[1] = b
;
41 while (rtc
.m
>= 60) rtc
.m
-= 60;
44 rtc
.h
= rtc
.regs
[2] = b
;
45 while (rtc
.h
>= 24) rtc
.h
-= 24;
49 rtc
.d
= (rtc
.d
& 0x100) | b
;
53 rtc
.d
= (rtc
.d
& 0xff) | ((b
&1)<<9);
86 void rtc_save_internal(int fd
)
91 rt
= rb
->mktime(rb
->get_time());
93 fdprintf(fd
, "%d %d %d %d %d %d %d %d\n", rtc
.carry
, rtc
.stop
, rtc
.d
, rtc
.h
,
94 rtc
.m
, rtc
.s
, rtc
.t
, rt
);
97 void rtc_load_internal(int fd
)
102 rb
->read_line(fd
, buf
, sizeof(buf
));
103 sscanf(buf
, "%d %d %d %d %d %d %d %d\n", &rtc
.carry
, &rtc
.stop
, &rtc
.d
,
104 &rtc
.h
, &rtc
.m
, &rtc
.s
, &rtc
.t
, &rt
);
106 while (rtc
.t
>= 60) rtc
.t
-= 60;
107 while (rtc
.s
>= 60) rtc
.s
-= 60;
108 while (rtc
.m
>= 60) rtc
.m
-= 60;
109 while (rtc
.h
>= 24) rtc
.h
-= 24;
110 while (rtc
.d
>= 365) rtc
.d
-= 365;
115 if (rt
) rt
= (rb
->mktime(rb
->get_time()) - rt
) * 60;
117 while (rt
-- > 0) rtc_tick();