Article View: comp.sys.amiga.tech
Article #13765Re: Setting the Amiga system date and time
From: Michael van Elst
Date: Sun, 18 Feb 1990 10:30
Date: Sun, 18 Feb 1990 10:30
95 lines
3692 bytes
3692 bytes
In article <1113@mindlink.UUCP> a218@mindlink.UUCP (Charlie Gibbs) writes:
>In article <77.25d0c638@intersil.uucp> hamilton@intersil.uucp
>(Fred Hamilton) writes:
>>I can read the Amiga system time with DateStamp().
>>But how do I SET it?
>>Thanks. (I'm installing a battery backed up clock in my 1000.)
>
> I couldn't figure it out either, so I cheated - I just built
>an appropriate DATE command and Execute()d it. Working in assembly
>language I got my program down to 400 bytes.
I tried to mail to the orignal poster but did not succeed. Here comes
the letter.
> By the way, I re-mapped my clock to $980000 and it works great. I still
> haven't figured out how to set the Amiga system time from within a C
> program (I'm new to C and all these structures, DoIO calls, and lousy
> documentation are really making my brain hurt), but I can set my clock
> to the Amiga system time and dump it to verify that it works.
Hello, you should get the new manuals (the complete set is the stores
for about 4 weeks). It's not easy for a C novice but the examples will
say you much about C and Amiga programming.
Now, for your question. The system clock is managed by the timer.device.
You should open the device for unit UNIT_VBLANK. Then use the
TR_SETSYSTIME command to set the date and time. You'll need to convert
date/time into system time which is seconds and microseconds since
1.january 1978 0:00. (Is the year correct ? Hmm)
Example:
#include <devices/timer.h>
struct timerequest *treq;
struct MsgPort *port;
/* create an IO reply port */
port = CreatePort(0,0);
if (port == NULL)
cleanup("can't get io reply port");
/* create the IO message */
treq = (struct timerequest *)CreateExtIO(port,sizeof(struct timerequest))
if (treq == NULL)
cleanup("can't get timer request");
/* get access to the timers */
if (OpenDevice(TIMERNAME, UNIT_VBLANK, treq, 0))
cleanup("can't open timer.device");
/* and now set the system time, seconds and micros should be the
time you want to set */
treq.tr_node.io_Command = TR_SETSYSTIME;
treq.tr_time.tv_secs = seconds;
treq.tr_time.tv_micro = micros;
DoIO(treq);
/* and free all resources */
CloseDevice(treq);
DeleteExtIO(treq);
DeletePort(port);
---------------------
Most of the code is needed only once in a real program, you may
use the same timerequest over and over again. Oh, and cleanup()
doesn't exist. I use one routine that frees all the resources I've
claimed throughout the whole program, it something like:
cleanup(message)
char *message;
{
if (treq != NULL && treq->tr_node.io_Device != -1) CloseDevice(treq);
if (treq != NULL) DeleteExtIO(treq);
if (port != NULL) DeletePort(port);
if (s != NULL) fprintf(stderr,"cleanup: %s\n",message);
}
If you want to read the current system time then use instead:
treq.tr_node.io_Command = TR_GETSYSTIME;
DoIO(treq);
seconds = treq.tr_time.tv_secs;
micros = treq.tr_time.tv_micro;
----------------------
And I recommend it a second time, all the information is in the Rom Kernal
Manuals.
--
Michael van Elst
E-Mail: uunet!unido!mpirbn!p554mve
Internet: p554mve@mpirbn.UUCP
Technical Details
Message-ID:
<559@mpirbn.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!uwm.edu!zaphod.mps.ohio-state.edu!think!mintaka!bloom-beacon!eru!luth!sunic!mcsun!unido!mpirbn!p554mveReferences:
<1113@mindlink.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!uwm.edu!zaphod.mps.ohio-state.edu!think!mintaka!bloom-beacon!eru!luth!sunic!mcsun!unido!mpirbn!p554mve From: p554mve@mpirbn.UUCP (Michael van Elst) Newsgroups: comp.sys.amiga.tech Subject: Re: Setting the Amiga system date and time Message-ID: <559@mpirbn.UUCP> Date: 18 Feb 90 10:30:20 GMT References: <1113@mindlink.UUCP> Reply-To: p554mve@mpirbn.UUCP (Michael van Elst) Organization: Max-Planck-Institut fuer Radioastronomie, Bonn Lines: 95