Exemplo n.º 1
0
/** polling method. Call every frame. */
int readPads() {
	int i;
	oldpaddata = paddata;
	paddata = 0;
	
	// in ms.
	u32 newtime = cpu_ticks() / CLOCKS_PER_MILISEC;
	time_since_last = newtime - curtime;
	curtime = newtime;
	
	int rslt = 0;
	
	for (i = 0; i < pad_count; ++i) {
		rslt |= readPad(&pad_data[i]);
	}
	
	for (i = 0; i < 16; ++i) {
		if (getKeyPressed(i + 1))
			delaycnt[i] -= time_since_last;
		else
			delaycnt[i] = getKeyDelay(i + 1, 0);
	}
	
	return rslt;
}
Exemplo n.º 2
0
static void
cpu_tick_calibrate(int reset)
{
	static uint64_t c_last;
	uint64_t c_this, c_delta;
	static struct bintime  t_last;
	struct bintime t_this, t_delta;
	uint32_t divi;

	if (reset) {
		/* The clock was stepped, abort & reset */
		t_last.sec = 0;
		return;
	}

	/* we don't calibrate fixed rate cputicks */
	if (!cpu_tick_variable)
		return;

	getbinuptime(&t_this);
	c_this = cpu_ticks();
	if (t_last.sec != 0) {
		c_delta = c_this - c_last;
		t_delta = t_this;
		bintime_sub(&t_delta, &t_last);
		/*
		 * Headroom:
		 * 	2^(64-20) / 16[s] =
		 * 	2^(44) / 16[s] =
		 * 	17.592.186.044.416 / 16 =
		 * 	1.099.511.627.776 [Hz]
		 */
		divi = t_delta.sec << 20;
		divi |= t_delta.frac >> (64 - 20);
		c_delta <<= 20;
		c_delta /= divi;
		if (c_delta > cpu_tick_frequency) {
			if (0 && bootverbose)
				printf("cpu_tick increased to %ju Hz\n",
				    c_delta);
			cpu_tick_frequency = c_delta;
		}
	}