time.c time routines for ST

time.c time routines for ST

Post by RDROY.. » Tue, 02 Jan 1990 12:14:00



/* time.c module to give the ST something a little more standard in
 * the way of time calls.  Add your own calls to get special time
 * arguments, or compile and make calls to time() to get the complete
 * time string.
 * Author:   Some by Robert Royar
 * Date:     Fri Jan 30 12:02:42 EST 1987 (that's the way a time string looks)
 * Compiled: Alcyon v 4.14 (the other compilers give you this free don't they?)

 */
#include <stdio.h>
#include <osbind.h>

static int _day[2][12] = {
                        {0,31,59,90,120,151,181,212,243,273,304,334},
                        {0,31,60,91,121,152,182,213,244,274,305,335}

Quote:};

static char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static char *wdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
int __date, __time;
char *tzone = "EST";

typedef struct TIME {
        int     t_sec;          /* second */
        int     t_min;          /* minute */
        int     t_hr;           /* hour   */
        int     t_md;           /* day of month */
        int     t_mnt;          /* month */
        int     t_year;         /* year */
        int     t_wday;         /* day of week */
        int     t_yd;           /* day of year */

Quote:} TIME;

extern char *time();
extern TIME *ctime();

/* from the _C Programming Language_ by Kernighan and Ritchie */

year_day(day, month, year)
register int day, month, year;
{
        register int leap;

        leap = year%4 == 0 && year%100 != 0 || year%400 == 0;
        return(day+_day[leap][month]);

Quote:}

/* given a year and the day of the year (returned above) return an index to
 * the correct day of the week
 */
week_day(year,day)
register int year, day;
{
        /* this array covers 1980-2000. Each number indexes into the
         * days array for the first day of the year */
        static int firstdays[] = {2, 4, 5, 6, 0, 2, 3, 4, 5, 0, 1, 2, 3, 5,
                                  6, 0, 1, 3, 4, 5, 6};
        register int begdat;

        if (year < 1980)
                return(NULL);   /* everyday is sunday before 1980 */
        year -= 1980;
        begdat = firstdays[year];
        day = (begdat+day)-1;
        if (day < 7)
                return(day);
        else
                return(day%7);

Quote:}

/* return a pointer to a structure of type TIME after filling the structure
 * with the proper values.
 */
TIME *
ctime()
{
        static TIME tm;

        __date = Tgetdate();
        __time = Tgettime();

        tm.t_sec = (__time&31)*2;
        tm.t_min = (__time>>5)&63;
        tm.t_hr  = (__time>>11)&31;
        tm.t_md  = (__date&31);
        tm.t_mnt = ((__date>>5)&15)-1;
        tm.t_year = ((__date>>9)&31)+1980;
        tm.t_yd  = year_day(tm.t_md,tm.t_mnt,tm.t_year);
        tm.t_wday = week_day(tm.t_year,tm.t_yd);
        return(&tm);

Quote:}

/* create an ASCII fixed length string and copy it into timeline.  Caller
 * should make sure timeline has 30 characters space.
 */
char *
time(timeline)
char timeline[];
{
        extern TIME *ctime();
        extern char *getenv();
        register TIME *tm;

        /* write your own getenv(), but the ST env section is
         * a total farce with only 128 bytes for storage
         */
        tzone = getenv("timezone");
        tm = ctime();
        sprintf(timeline,"%s %s %02d %d:%02d:%02d %s %d\n",
        wdays[tm->t_wday],months[tm->t_mnt],tm->t_md,tm->t_hr,tm->t_min,
        tm->t_sec,tzone,tm->t_year);
        return(&timeline);

Quote:}

 
 
 

1. timing-routine / IRQ

Dear folks;
I'm trying to set an IRQ-routine that's to be fired by a timer-A interrupt.
I didn't succeed. Does anybody have a little piece of code (Metacomco-Asm
preferred) that shows how to initialize the timer and how to implement an
interrupt-routine (btw., I need a ms-timing signal) ???
thanx, Klaus.

-- Klaus Hahn.

Department of Psychology
Gutenbergstr. 18
University of MARBURG

Disclaimer: the opinions stated above are not even my own.

2. Mime

3. Need real time clock routine for midi sequencer

4. Color SW 2500 - Monitoring ink left?

5. Printing in GNU Emacs (19.29) for OS/2.

6. timing routines revisited

7. ScanMaker x6 with Windows 2000

8. Mega ST Real Time Clocks

9. Real Time Clock for ST's

10. Mega ST real time clock

11. ST ahead of its time?