http://wiki.amigaos.net/wiki/BattClock_Resource
Code: Select all
#include <exec/types.h>
#include <dos/dos.h>
#include <utility/date.h>
#include <resources/battclock.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/battclock.h>
#include <proto/utility.h>
int main()
{
CONST CONST_STRPTR Days[] ={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
CONST CONST_STRPTR Months[] = {"January","February","March","April","May","June",
"July","August","September","October","November","December"};
STRPTR ampm;
uint32 AmigaTime;
struct ClockData MyClock;
struct Library *BattClockBase = IExec->OpenResource(BATTCLOCKNAME);
struct BattClockIFace *IBattClock = (struct BattClockIFace *)IExec->GetInterface(BattClockBase, "main", 1, NULL);
if (IBattClock != NULL) {
/* Get number of seconds till now */
AmigaTime = IBattClock->ReadBattClock();
/* Convert to a ClockData structure */
IUtility->Amiga2Date(AmigaTime,&MyClock);
IDOS->Printf("\nRobin, tell everyone the BatDate and BatTime");
/* Print the Date */
IDOS->Printf("\n\nOkay Batman, the BatDate is ");
IDOS->Printf("%s, %s %ld, %ld",Days[MyClock.wday],Months[MyClock.month-1], MyClock.mday,MyClock.year);
/* Convert military time to normal time and set AM/PM */
if (MyClock.hour < 12) {
ampm = "AM"; /* hour less than 12, must be morning */
}
else {
ampm = "PM"; /* hour greater than 12,must be night */
MyClock.hour -= 12; /* subtract the extra 12 of military */
};
if (MyClock.hour == 0) {
MyClock.hour = 12; /* don't forget the 12s */
}
/* Print the time */
IDOS->Printf("\n the BatTime is ");
IDOS->Printf("%02ld:%02ld:%02ld %s\n\n", MyClock.hour, MyClock.min, MyClock.sec, ampm);
IExec->DropInterface((struct Interface*)IBattClock);
}
else
IDOS->Printf("Error: Unable to open the %s\n",BATTCLOCKNAME);
return 0;
}