snes9xgx/source/ngc/gctime.cpp
dborth fb27030208 [Whats Was New 002 - July 21, 2008]
- added: classic and nunchuk support
- added: all controllers can now be configured
- added: GC version (untested)
- changed: mappings are no longer stored in SRAM, but in config file. 
           This means no per-game configurations, but one global 
           config per controller.
- one makefile to make all versions. (thanks to snes9x143 SVN)
2008-10-16 01:49:58 +00:00

52 lines
1.3 KiB
C++

/****************************************************************************
* gctime.cpp
****************************************************************************/
#include "gctime.h"
#define TB_CLOCK 40500000
unsigned long tb_diff_msec(tb_t *end, tb_t *start)
{
unsigned long upper, lower;
upper = end->u - start->u;
if (start->l > end->l)
upper--;
lower = end->l - start->l;
return ((upper*((unsigned long)0x80000000/(TB_CLOCK/2000))) + (lower/(TB_CLOCK/1000)));
}
unsigned long tb_diff_usec(tb_t *end, tb_t *start)
{
unsigned long upper, lower;
upper = end->u - start->u;
if (start->l > end->l)
upper--;
lower = end->l - start->l;
return ((upper*((unsigned long)0x80000000/(TB_CLOCK/2000000))) + (lower/(TB_CLOCK/1000000)));
}
void udelay(unsigned int us)
{
tb_t start, end;
mftb(&start);
while (1)
{
mftb(&end);
if (tb_diff_usec(&end, &start) >= us)
break;
}
}
void mdelay(unsigned int ms)
{
tb_t start, end;
mftb(&start);
while (1)
{
mftb(&end);
if (tb_diff_msec(&end, &start) >= ms)
break;
}
}