X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=fth%2Fmisc2.fth;fp=fth%2Fmisc2.fth;h=b1ae8eae96309eb67d84f01b256af6d38c4d12b9;hb=36a42cf251672481da028bb30eea1b16779b5f05;hp=f5f9f345574fc2e118b0dd46d59718b2818328c9;hpb=e1fe6a3e5393fc9a90c8b2ad40b4c2092d551d57;p=debian%2Fpforth diff --git a/fth/misc2.fth b/fth/misc2.fth index f5f9f34..b1ae8ea 100644 --- a/fth/misc2.fth +++ b/fth/misc2.fth @@ -49,16 +49,39 @@ variable if-debug ; decimal -create msec-delay 10000 , ( default for SUN ) -: (MSEC) ( #msecs -- ) +create MSEC-DELAY 100000 , \ calibrate this for your system +: (MSEC.SPIN) ( #msecs -- , busy wait, not accurate ) + 0 max \ avoid endless loop 0 - do msec-delay @ 0 + ?do msec-delay @ 0 do loop loop ; +: (MSEC) ( millis -- ) + dup (sleep) \ call system sleep in kernel + IF + ." (SLEEP) failed or not implemented! Using (MSEC.SPIN)" CR + (msec.spin) + ELSE + drop + THEN +; + defer msec -' (msec) is msec + +\ (SLEEP) uses system sleep functions to actually sleep. +\ Use (MSEC.SPIN) on embedded systems that do not support Win32 Sleep() posix usleep(). +1 (SLEEP) [IF] + ." (SLEEP) failed or not implemented! Use (MSEC.SPIN) for MSEC" CR + ' (msec.spin) is msec +[ELSE] + ' (msec) is msec +[THEN] + +: MS ( msec -- , sleep, ANS standard ) + msec +; : SHIFT ( val n -- val<