From 5b46b348c19f4d94827a61eb26957bbab3d113f2 Mon Sep 17 00:00:00 2001 From: Jens Staal Date: Sun, 14 Jun 2020 07:14:36 +0200 Subject: [PATCH] attempt at providing usleep() and round() for Plan9 --- sources/fisher.c | 10 +++++++++- sources/miketron.c | 10 +++++++++- sources/muncher.c | 10 +++++++++- sources/sudoku.c | 17 +++++++++++++++-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/sources/fisher.c b/sources/fisher.c index f39a37b..795c30b 100644 --- a/sources/fisher.c +++ b/sources/fisher.c @@ -16,7 +16,15 @@ #define HWID WID/2 #ifdef Plan9 -#define usleep(x) sleep(x/1000000) +int usleep(long usec) { + int seconds = usec/1000000; + long nano = usec*1000 - seconds*1000000; + struct timespec sleepy = {0}; + sleepy.ts_sec = second; + sleepy.ts_nsec = nano; + nanosleep(&sleepy, (struct timespec *) NULL); + return 0; +} #endif typedef signed char byte; diff --git a/sources/miketron.c b/sources/miketron.c index 096ffeb..fcd9146 100644 --- a/sources/miketron.c +++ b/sources/miketron.c @@ -28,7 +28,15 @@ compile with -lncurses #ifdef Plan9 #define len 10 #define wid 40 -#define usleep(x) sleep(x/1000000) +int usleep(long usec) { + int seconds = usec/1000000; + long nano = usec*1000 - seconds*1000000; + struct timespec sleepy = {0}; + sleepy.ts_sec = second; + sleepy.ts_nsec = nano; + nanosleep(&sleepy, (struct timespec *) NULL); + return 0; +} #endif typedef signed char byte; diff --git a/sources/muncher.c b/sources/muncher.c index eaae2fc..2c2a35f 100644 --- a/sources/muncher.c +++ b/sources/muncher.c @@ -26,7 +26,15 @@ compile with -lncurses #ifdef Plan9 #define len 10 #define wid 40 -#define usleep(x) sleep(x/1000000) +int usleep(long usec) { + int seconds = usec/1000000; + long nano = usec*1000 - seconds*1000000; + struct timespec sleepy = {0}; + sleepy.ts_sec = second; + sleepy.ts_nsec = nano; + nanosleep(&sleepy, (struct timespec *) NULL); + return 0; +} #endif typedef signed char byte; diff --git a/sources/sudoku.c b/sources/sudoku.c index 104d07d..b2c2196 100644 --- a/sources/sudoku.c +++ b/sources/sudoku.c @@ -22,6 +22,21 @@ NOTE: This program is only made for entertainment porpuses. The puzzles are gene #if defined Plan9 #define size 3 #define s 9 +/* I hope this is approximately right */ +int round(float x) +{ + int y=(int) x; + if x>0 + if x-y >0.5 + return (int)(x + 0.5); + else + return y; + if x<0 + if x-y <-0.5 + return int(x -0.5); + else + return y; +} #endif typedef signed char byte; @@ -247,9 +262,7 @@ void mouseinput(int sy, int sx){ getmouse(&m); #endif if( m.y < (3+1+size+s)-sy && m.x<(2*s+1)-sx ){//it's a shame to include math.h only for round() but it was the only moral way to make gcc shut up -#ifndef Plan9 py= round( (float)(size*(m.y-4-sy))/(size+1) );//these are derived from the formulas in draw() by simple algebra -#endif px=(m.x-1-sx)/2; } else