File:  [UNIX Amiga Emulator] / uae / amiga / source / timehack.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:47:09 2018 UTC (8 years, 3 months ago) by root
Branches: MAIN, BSchmidt
CVS tags: uae089, uae0829, uae0828, uae0827, uae0826, uae0825, uae0824, uae0823, uae0822, uae0821, uae0820, uae0819, uae0818, uae0817, uae0816, uae0815, uae0814, uae0813, uae0812, uae0811, uae0810, HEAD
uae-0.8.9

/*
 * synchronize system time with the host's time
 *
 * Compile with DCC (or SAS/C)
 *
 * Copyright 1997, 1999 Bernd Schmidt
 * Copyright 1999 Patrick Ohly
 */

#include <stdio.h>

#include <exec/devices.h>
#include <exec/interrupts.h>
#include <exec/nodes.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <intuition/intuitionbase.h>
#include <intuition/preferences.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <devices/timer.h>
#include <hardware/intbits.h>
#include <clib/alib_protos.h>
#include <clib/exec_protos.h>

#ifdef _DCC
int (*calltrap)(__d0 int, __a0 struct timeval *) = 0xF0FFA0;
#else
/* SAS */
__asm int (*calltrap)(register __d0 int, register __a0 struct timeval *) = (APTR)0xF0FFA0;
#endif

int main (int argc, char **argv)
{
    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    int result = calltrap (0, 0);

    if (result == 1)
	fprintf (stderr, "timehack already running.\n");
    else if (result == 2)
	fprintf (stderr, "timehack not supported with this version of UAE.\n");
    if (result != 0)
	exit (5);

    timeport = CreatePort (0, 0);
    if (timeport)
	timereq = CreateStdIO(timeport);

    if (timereq == 0)
	goto fail;

    if (OpenDevice ("timer.device", UNIT_VBLANK, timereq, 0) != 0)
	goto fail;

    SetTaskPri (FindTask (NULL), 20); /* same as input.device */
    for (;;) {
        struct timeval cur_sys_time;

        timereq->tr_node.io_Command = TR_GETSYSTIME;
        DoIO(timereq);
        cur_sys_time = timereq->tr_time;
        calltrap (1, &timereq->tr_time);
        if (timereq->tr_time.tv_secs > cur_sys_time.tv_secs
	    || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs
		&& timereq->tr_time.tv_micro > cur_sys_time.tv_micro))
	{
            timereq->tr_node.io_Command = TR_SETSYSTIME;
            DoIO(timereq);
        }

        timereq->tr_time.tv_secs = 1;
	timereq->tr_time.tv_micro = 0;
        timereq->tr_node.io_Command = TR_ADDREQUEST;
	DoIO(timereq);
    }
    fail:
    fprintf (stderr, "Couldn't start timehack (that's bad!)\n");
    exit (5);
}

unix.superglobalmegacorp.com

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