2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: SetClock - set/save the date from/to the BBU clock.
9 /*************************************************************************
15 SetClock {LOAD|SAVE|RESET}
24 SetClock can be used to:
25 o Load the time from the battery backed-up clock,
26 o Save the time to the battery backed-up clock,
27 o Reset the battery backed up clock.
33 will set the system time from the battery backed-up clock.
34 In most systems this will be done automatically during
39 will set the time of the battery backed-up clock from the
40 current system clock time.
44 will reset the battery backed-up to a value of the
45 1st January 1978 00:00:00. This is mostly used if the
46 battery backed-up clock has an error and will not
47 respond to normal load and save commands.
52 *************************************************************************/
54 #include <exec/types.h>
55 #include <dos/dosextens.h>
56 #include <dos/rdargs.h>
57 #include <devices/timer.h>
58 #include <utility/tagitem.h>
60 #include <proto/exec.h>
61 #include <proto/dos.h>
62 #include <proto/battclock.h>
63 #include <proto/timer.h>
65 const char version
[] = "$VER: SetClock 41.1 (21.2.1997)";
66 const char exthelp
[] =
67 "SetClock : Set or save the date from/to the battery backed-up clock\n"
68 "\tLOAD Load the time from the battery-backed-up clock\n"
69 "\tSAVE Save the time to the battery-backed-up clock\n"
70 "\tRESET Reset the battery-backed-up clock\n";
72 #define ARG_TEMPLATE "LOAD/S,SAVE/S,RESET/S"
78 int main(int argc
, char **av
)
80 IPTR args
[TOTAL_ARGS
] = { 0, 0, 0 };
81 struct RDArgs
*rda
, *rd
;
82 APTR BattClockBase
= NULL
;
83 struct Device
*TimerBase
= NULL
;
84 ULONG time
, error
= 0;
85 struct timerequest
*tr
;
89 rda
= AllocDosObject(DOS_RDARGS
, NULL
);
92 rda
->RDA_ExtHelp
= (STRPTR
)exthelp
;
93 rd
= ReadArgs(ARG_TEMPLATE
, args
, rda
);
97 BattClockBase
= OpenResource("battclock.resource");
100 if((mp
= CreateMsgPort()))
102 if((tr
= (struct timerequest
*)
103 CreateIORequest(mp
, sizeof(struct timerequest
))))
105 if(OpenDevice("timer.device", UNIT_VBLANK
,
106 (struct IORequest
*)tr
, 0) == 0)
108 TimerBase
= tr
->tr_node
.io_Device
;
113 time
= ReadBattClock();
115 /* Set timer.device clock */
116 tr
->tr_node
.io_Command
= TR_SETSYSTIME
;
117 tr
->tr_time
.tv_secs
= time
;
118 tr
->tr_time
.tv_micro
= 0;
119 tr
->tr_node
.io_Flags
= IOF_QUICK
;
120 DoIO((struct IORequest
*)tr
);
121 if(tr
->tr_node
.io_Error
!= 0)
123 FPuts(Output(), "Error: Could not set system time!\n");
130 WriteBattClock(t
.tv_secs
);
138 error
= ERROR_REQUIRED_ARG_MISSING
;
142 error
= ERROR_INVALID_RESIDENT_LIBRARY
;
144 DeleteIORequest((struct IORequest
*)tr
);
146 } /* CreateIORequest() */
148 error
= ERROR_NO_FREE_STORE
;
151 } /* CreateMsgPort() */
154 error
= ERROR_NO_FREE_STORE
;
156 } /* OpenResource() */
163 FreeDosObject(DOS_RDARGS
, rda
);
164 } /* AllocDosObject() */
170 PrintFault(error
, "SetClock");