1999-10-03 14:16:26 +00:00
|
|
|
/*
|
|
|
|
* timer_beos.cpp - Time Manager emulation, BeOS specific stuff
|
|
|
|
*
|
2008-01-01 09:40:36 +00:00
|
|
|
* Basilisk II (C) 1997-2008 Christian Bauer
|
1999-10-03 14:16:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <KernelKit.h>
|
|
|
|
|
|
|
|
#include "sysdeps.h"
|
2001-07-06 17:36:09 +00:00
|
|
|
#include "macos_util.h"
|
1999-10-03 14:16:26 +00:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
#define DEBUG 0
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
2006-04-30 21:26:21 +00:00
|
|
|
// From main_beos.cpp
|
|
|
|
extern thread_id emul_thread;
|
|
|
|
|
|
|
|
|
1999-10-03 14:16:26 +00:00
|
|
|
/*
|
|
|
|
* Return microseconds since boot (64 bit)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Microseconds(uint32 &hi, uint32 &lo)
|
|
|
|
{
|
|
|
|
D(bug("Microseconds\n"));
|
|
|
|
bigtime_t time = system_time();
|
|
|
|
hi = time >> 32;
|
|
|
|
lo = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return local date/time in Mac format (seconds since 1.1.1904)
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint32 TimerDateTime(void)
|
|
|
|
{
|
2001-07-06 17:36:09 +00:00
|
|
|
return TimeToMacTime(time(NULL));
|
1999-10-03 14:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get current time
|
|
|
|
*/
|
|
|
|
|
|
|
|
void timer_current_time(tm_time_t &t)
|
|
|
|
{
|
|
|
|
t = system_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add times
|
|
|
|
*/
|
|
|
|
|
|
|
|
void timer_add_time(tm_time_t &res, tm_time_t a, tm_time_t b)
|
|
|
|
{
|
|
|
|
res = a + b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Subtract times
|
|
|
|
*/
|
|
|
|
|
|
|
|
void timer_sub_time(tm_time_t &res, tm_time_t a, tm_time_t b)
|
|
|
|
{
|
|
|
|
res = a - b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare times (<0: a < b, =0: a = b, >0: a > b)
|
|
|
|
*/
|
|
|
|
|
|
|
|
int timer_cmp_time(tm_time_t a, tm_time_t b)
|
|
|
|
{
|
|
|
|
tm_time_t r = a - b;
|
|
|
|
return r < 0 ? -1 : (r > 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert Mac time value (>0: microseconds, <0: microseconds) to tm_time_t
|
|
|
|
*/
|
|
|
|
|
|
|
|
void timer_mac2host_time(tm_time_t &res, int32 mactime)
|
|
|
|
{
|
|
|
|
if (mactime > 0)
|
|
|
|
res = mactime * 1000; // Time in milliseconds
|
|
|
|
else
|
|
|
|
res = -mactime; // Time in negative microseconds
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert positive tm_time_t to Mac time value (>0: microseconds, <0: microseconds)
|
|
|
|
* A negative input value for hosttime results in a zero return value
|
|
|
|
* As long as the microseconds value fits in 32 bit, it must not be converted to milliseconds!
|
|
|
|
*/
|
|
|
|
|
|
|
|
int32 timer_host2mac_time(tm_time_t hosttime)
|
|
|
|
{
|
|
|
|
if (hosttime < 0)
|
|
|
|
return 0;
|
|
|
|
else if (hosttime > 0x7fffffff)
|
|
|
|
return hosttime / 1000; // Time in milliseconds
|
|
|
|
else
|
|
|
|
return -hosttime; // Time in negative microseconds
|
|
|
|
}
|
2004-05-15 16:21:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delay by specified number of microseconds (<1 second)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Delay_usec(uint32 usec)
|
|
|
|
{
|
|
|
|
snooze(usec);
|
|
|
|
}
|
2005-06-30 10:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Suspend emulator thread, virtual CPU in idle mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
void idle_wait(void)
|
|
|
|
{
|
2006-04-30 21:26:21 +00:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
FIXME: add a semaphore (counter) to avoid a B_BAD_THREAD_STATE
|
|
|
|
return if we call idle_resume() when thread is not suspended?
|
|
|
|
|
|
|
|
Sorry, I can't test -- gb.
|
|
|
|
*/
|
|
|
|
suspend_thread(emul_thread);
|
|
|
|
#endif
|
2005-06-30 10:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume execution of emulator thread, events just arrived
|
|
|
|
*/
|
|
|
|
|
|
|
|
void idle_resume(void)
|
|
|
|
{
|
2006-04-30 21:26:21 +00:00
|
|
|
#if 0
|
|
|
|
resume_thread(emul_thread);
|
|
|
|
#endif
|
2005-06-30 10:20:18 +00:00
|
|
|
}
|