コード例 #1
0
ファイル: timer.c プロジェクト: Sunoo/nonamemame
void mame_timer_adjust(mame_timer *which, mame_time duration, int param, mame_time period)
{
	mame_time time = get_current_time();

	/* error if this is an inactive timer */
	if (which->tag == -1)
	{
		printf("mame_timer_adjust: adjusting an inactive timer!\n");
		logerror("mame_timer_adjust: adjusting an inactive timer!\n");
		return;
	}

	/* if this is the callback timer, mark it modified */
	if (which == callback_timer)
		callback_timer_modified = 1;

	/* compute the time of the next firing and insert into the list */
	which->callback_param = param;
	which->enabled = 1;

	/* set the start and expire times */
	which->start = time;
	which->expire = add_mame_times(time, duration);
	which->period = period;

	/* remove and re-insert the timer in its new order */
	timer_list_remove(which);
	timer_list_insert(which);

	/* if this was inserted as the head, abort the current timeslice and resync */
	LOG(("timer_adjust %s:%d to expire @ %.9f\n", which->file, which->line, mame_time_to_double(which->expire)));
	if (which == timer_head && cpu_getexecutingcpu() >= 0)
		activecpu_abort_timeslice();
}
コード例 #2
0
ファイル: timer.c プロジェクト: Sunoo/nonamemame
void mame_timer_set_global_time(mame_time newbase)
{
	mame_timer *timer;

	/* set the new global offset */
	global_basetime = newbase;

	LOG(("mame_timer_set_global_time: new=%.9f head->expire=%.9f\n", mame_time_to_double(newbase), mame_time_to_double(timer_head->expire)));

	/* now process any timers that are overdue */
	while (compare_mame_times(timer_head->expire, global_basetime) <= 0)
	{
		int was_enabled = timer_head->enabled;

		/* if this is a one-shot timer, disable it now */
		timer = timer_head;
		if (compare_mame_times(timer->period, time_zero) == 0 || compare_mame_times(timer->period, time_never) == 0)
			timer->enabled = 0;

		/* set the global state of which callback we're in */
		callback_timer_modified = 0;
		callback_timer = timer;
		callback_timer_expire_time = timer->expire;

		/* call the callback */
		if (was_enabled && timer->callback)
		{
			LOG(("Timer %s:%d fired (expire=%.9f)\n", timer->file, timer->line, mame_time_to_double(timer->expire)));
			profiler_mark(PROFILER_TIMER_CALLBACK);
			(*timer->callback)(timer->callback_param);
			profiler_mark(PROFILER_END);
		}

		/* clear the callback timer global */
		callback_timer = NULL;

		/* reset or remove the timer, but only if it wasn't modified during the callback */
		if (!callback_timer_modified)
		{
			/* if the timer is temporary, remove it now */
			if (timer->temporary)
				timer_remove(timer);

			/* otherwise, reschedule it */
			else
			{
				timer->start = timer->expire;
				timer->expire = add_mame_times(timer->expire, timer->period);

				timer_list_remove(timer);
				timer_list_insert(timer);
			}
		}
	}
}
コード例 #3
0
ファイル: hitme.c プロジェクト: broftkd/mess-cvs
static WRITE8_HANDLER( output_port_0_w )
{
	/*
        Note: We compute the timeout time on a write here. Unfortunately, the situation is
        kind of weird, because the discrete sound system is also affected by this timeout.
        In fact, it is very important that our timing calculation timeout AFTER the sound
        system's equivalent computation, or else we will hang notes.
    */
	UINT8 raw_game_speed = readinputport(6);
	double resistance = raw_game_speed * 25000 / 100;
	mame_time duration = make_mame_time(0, MAX_SUBSECONDS * 0.45 * 6.8e-6 * resistance * (data+1));
	timeout_time = add_mame_times(mame_timer_get_time(), duration);

	discrete_sound_w(HITME_DOWNCOUNT_VAL, data);
	discrete_sound_w(HITME_OUT0, 1);
}