예제 #1
0
파일: cia.cpp 프로젝트: stavrossk/WinUAE
static void do_tod_hack (int dotod)
{
	struct timeval tv;
	static int oldrate;
	uae_u64 t;
	int rate;
	int docount = 0;

	if (tod_hack_enabled == 0)
		return;
	if (!heartbeat_cnt) {
		if (tod_hack_enabled > 0)
			tod_hack_enabled = -1;
		return;
	}
	if (tod_hack_enabled < 0) {
		tod_hack_enabled = TOD_HACK_TIME;
		return;
	}
	if (tod_hack_enabled > 1) {
		tod_hack_enabled--;
		if (tod_hack_enabled == 1) {
			//write_log (_T("TOD HACK enabled\n"));
			tod_hack_reset ();
		}
		return;
	}

	if (currprefs.cs_ciaatod == 0)
		rate = (int)(vblank_hz + 0.5);
	else if (currprefs.cs_ciaatod == 1)
		rate = 50;
	else
		rate = 60;
	if (rate <= 0)
		return;
	if (rate != oldrate || ciaatod != tod_hack_tod_last) {
		//if (ciaatod != 0)
		//	write_log (_T("TOD HACK reset %d,%d %d,%d\n"), rate, oldrate, ciaatod, tod_hack_tod_last);
		tod_hack_reset ();
		oldrate = rate;
		docount = 1;
	}
	if (!dotod && currprefs.cs_ciaatod == 0)
		return;
	gettimeofday (&tv, NULL);
	t = (uae_u64)tv.tv_sec * 1000000 + tv.tv_usec;
	if (t - tod_hack_tv >= 1000000 / rate) {
		tod_hack_tv += 1000000 / rate;
		docount = 1;
	}
	if (docount) {
		ciaatod++;
		ciaatod &= 0x00ffffff;
		tod_hack_tod_last = ciaatod;
		ciaa_checkalarm (0);
	}
}
예제 #2
0
void CIA_vsync_handler ()
{
#ifdef TOD_HACK
    if (currprefs.tod_hack && ciaatodon) {
        struct timeval tv;
	uae_u32 t, nt, rate = currprefs.ntscmode ? 60 : 50;

	if (tod_hack_delay > 0) {
	    tod_hack_delay--;
	    if (tod_hack_delay == 0) {
		tod_hack_reset ();
		tod_hack_delay = 0;
		write_log ("TOD_HACK re-initialized CIATOD=%06.6X\n", ciaatod);
	    }
	}
	if (tod_hack_delay == 0) {
	    gettimeofday (&tv, NULL);
	    t = (uae_u32)(((uae_u64)tv.tv_sec) * rate + tv.tv_usec / (1000000 / rate));
	    nt = t - tod_hack;
	    if ((nt < ciaatod && ciaatod - nt < 10) || nt == ciaatod)
		return; /* try not to count backwards */
	    ciaatod = nt;
	    ciaatod &= 0xffffff;
	    ciaa_checkalarm ();
	    return;
	}
    }
#endif
    if (ciaatodon) {
	ciaatod++;
	ciaatod &= 0xFFFFFF;
	ciaa_checkalarm ();
    }
}