Annotation of uae/amiga/source/timehack.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * synchronize system time with the host's time
        !             3:  *
        !             4:  * Compile with DCC (or SAS/C)
        !             5:  *
        !             6:  * Copyright 1997, 1999 Bernd Schmidt
        !             7:  * Copyright 1999 Patrick Ohly
        !             8:  */
        !             9: 
        !            10: #include <stdio.h>
        !            11: 
        !            12: #include <exec/devices.h>
        !            13: #include <exec/interrupts.h>
        !            14: #include <exec/nodes.h>
        !            15: #include <exec/io.h>
        !            16: #include <exec/memory.h>
        !            17: #include <intuition/intuitionbase.h>
        !            18: #include <intuition/preferences.h>
        !            19: #include <devices/input.h>
        !            20: #include <devices/inputevent.h>
        !            21: #include <devices/timer.h>
        !            22: #include <hardware/intbits.h>
        !            23: #include <clib/alib_protos.h>
        !            24: #include <clib/exec_protos.h>
        !            25: 
        !            26: #ifdef _DCC
        !            27: int (*calltrap)(__d0 int, __a0 struct timeval *) = 0xF0FFA0;
        !            28: #else
        !            29: /* SAS */
        !            30: __asm int (*calltrap)(register __d0 int, register __a0 struct timeval *) = (APTR)0xF0FFA0;
        !            31: #endif
        !            32: 
        !            33: int main (int argc, char **argv)
        !            34: {
        !            35:     struct timerequest *timereq = 0;
        !            36:     struct MsgPort *timeport;
        !            37:     int result = calltrap (0, 0);
        !            38: 
        !            39:     if (result == 1)
        !            40:        fprintf (stderr, "timehack already running.\n");
        !            41:     else if (result == 2)
        !            42:        fprintf (stderr, "timehack not supported with this version of UAE.\n");
        !            43:     if (result != 0)
        !            44:        exit (5);
        !            45: 
        !            46:     timeport = CreatePort (0, 0);
        !            47:     if (timeport)
        !            48:        timereq = CreateStdIO(timeport);
        !            49: 
        !            50:     if (timereq == 0)
        !            51:        goto fail;
        !            52: 
        !            53:     if (OpenDevice ("timer.device", UNIT_VBLANK, timereq, 0) != 0)
        !            54:        goto fail;
        !            55: 
        !            56:     SetTaskPri (FindTask (NULL), 20); /* same as input.device */
        !            57:     for (;;) {
        !            58:         struct timeval cur_sys_time;
        !            59: 
        !            60:         timereq->tr_node.io_Command = TR_GETSYSTIME;
        !            61:         DoIO(timereq);
        !            62:         cur_sys_time = timereq->tr_time;
        !            63:         calltrap (1, &timereq->tr_time);
        !            64:         if (timereq->tr_time.tv_secs > cur_sys_time.tv_secs
        !            65:            || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs
        !            66:                && timereq->tr_time.tv_micro > cur_sys_time.tv_micro))
        !            67:        {
        !            68:             timereq->tr_node.io_Command = TR_SETSYSTIME;
        !            69:             DoIO(timereq);
        !            70:         }
        !            71: 
        !            72:         timereq->tr_time.tv_secs = 1;
        !            73:        timereq->tr_time.tv_micro = 0;
        !            74:         timereq->tr_node.io_Command = TR_ADDREQUEST;
        !            75:        DoIO(timereq);
        !            76:     }
        !            77:     fail:
        !            78:     fprintf (stderr, "Couldn't start timehack (that's bad!)\n");
        !            79:     exit (5);
        !            80: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.