woollybah 5 лет назад
Родитель
Сommit
0279c83f98
3 измененных файлов с 52 добавлено и 0 удалено
  1. 8 0
      blitz.mod/blitz.bmx
  2. 32 0
      blitz.mod/blitz_app.c
  3. 12 0
      blitz.mod/blitz_app.h

+ 8 - 0
blitz.mod/blitz.bmx

@@ -386,6 +386,14 @@ A millisecond is one thousandth of a second.
 End Rem
 End Rem
 Function Delay( millis:Int )="bbDelay"
 Function Delay( millis:Int )="bbDelay"
 
 
+Rem
+bbdoc: Wait for a given number of microseconds
+#UDelay suspends program execution for at least @microcseconds.<br>
+<br>
+A microsecond is one millionth of a second.
+End Rem
+Function UDelay( microseconds:Int )="void bbUDelay(int)!"
+
 Rem
 Rem
 bbdoc: Get millisecond counter
 bbdoc: Get millisecond counter
 returns: Milliseconds since computer turned on.
 returns: Milliseconds since computer turned on.

+ 32 - 0
blitz.mod/blitz_app.c

@@ -82,6 +82,15 @@ void bbDelay( int millis ){
 	usleep( millis*1000 );
 	usleep( millis*1000 );
 }
 }
 
 
+#if __STDC_VERSION__ >= 199901L
+extern void bbUDelay( int microseconds );
+#else
+void bbUDelay( int microseconds ) {
+	if (microseconds <0) return
+	usleep( microseconds );
+}
+#endif
+
 int bbMilliSecs(){
 int bbMilliSecs(){
 	static mach_timebase_info_data_t info;
 	static mach_timebase_info_data_t info;
 
 
@@ -120,6 +129,20 @@ int bbMilliSecs(){
 	return timeGetTime();
 	return timeGetTime();
 }
 }
 
 
+void bbUDelay( int microseconds ) {
+	__int64 time1 = 0;
+	__int64 time2 = 0;
+	__int64 freq = 0;
+
+	QueryPerformanceCounter((LARGE_INTEGER *) &time1);
+	QueryPerformanceFrequency(&freq);
+
+	do {
+		Sleep(0);
+		QueryPerformanceCounter((LARGE_INTEGER *) &time2);
+	} while(time2-time1 < microseconds*freq/1000000);
+}
+
 int bbIsMainThread(){
 int bbIsMainThread(){
 	return GetCurrentThreadId()==_mainThread;
 	return GetCurrentThreadId()==_mainThread;
 }
 }
@@ -184,6 +207,15 @@ void bbDelay( int millis ){
 	}
 	}
 }
 }
 
 
+#if __STDC_VERSION__ >= 199901L
+extern void bbUDelay( int microseconds );
+#else
+void bbUDelay( int microseconds ) {
+	if (microseconds <0) return
+	usleep( microseconds );
+}
+#endif
+
 //***** ThreadSafe! *****
 //***** ThreadSafe! *****
 int bbMilliSecs(){
 int bbMilliSecs(){
 	int t;
 	int t;

+ 12 - 0
blitz.mod/blitz_app.h

@@ -32,6 +32,18 @@ void		bbWriteStderr( BBString *t );
 void		bbDelay( int ms );
 void		bbDelay( int ms );
 int		bbMilliSecs();
 int		bbMilliSecs();
 int		bbIsMainThread();
 int		bbIsMainThread();
+#if __STDC_VERSION__ >= 199901L
+#ifndef _WIN32
+inline void bbUDelay( int microseconds ) {
+	if( microseconds<0 ) return;
+	usleep( microseconds );
+}
+#else
+void bbUDelay( int microseconds );
+#endif
+#else
+void bbUDelay( int microseconds );
+#endif
 
 
 void		bbStartup( int argc,char *argv[],void *dummy1,void *dummy2 );
 void		bbStartup( int argc,char *argv[],void *dummy1,void *dummy2 );