home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
488.lha
/
Timer
/
README
< prev
next >
Wrap
Text File
|
1991-02-08
|
4KB
|
97 lines
WAITING ON THE AMIGA
© Copyright 1990 Timm Martin
INTRODUCTION
This archive contains a few functions to allow you to wait inside your C
programs. Included are 6 files:
README ...... what you are reading now
article ..... article discussing the technical details
timer.c ..... all of the timer device functions
timer.h ..... header file for programs using these functions
test.c ...... test program showing you how to use these functions
test ........ executable form of the test program
These functions allow you to wait inside your program for a specified amount
of time either synchronously or asynchronously. A "synchronous" wait means
your program "sleeps" until the desired amount of time has expired. An
"asynchronous" wait means your program can continue executing, and the timer
device will notify you when the specified amount of time has expired.
Using the timer device instead of a simple for-loop to wait inside a program
has a few important advantages:
1) You can be guaranteed of the exact amount of time you will wait with the
timer device. With a for-loop, the amount of time you wait is dependent
on the speed of the machine and how busy it is.
2) With the timer device, you can wait asycnhronously. The for-loop wait is
strictly synchronous.
3) Waiting inside a for-loop is a busy-wait, which is taboo in a
multitasking system. It will cause other system operations to drag.
A synchronous wait using the timer device will put your program to
sleep, allowing the rest of the system to function unimpeded.
LEGAL JUNK
The text is copyrighted, but all of the source is public domain. You may use
it in any program, commercial or non-commercial, without acknowledgement of
or compensation to the author.
All of the source was written to conform to ANSI C standards and compiles
cleanly using Manx C v5.0b (and compiler options -pas -wadpru).
GETTING STARTED...QUICKLY!
-- Place the timer.h header file in the current directory and add the
following line to the beginning of your source file:
#include "timer.h"
-- In your program startup function, call the timer_open() function,
checking its return value. If FALSE, you should end the program.
-- In your program cleanup function, call the timer_close() function.
-- To wait synchronously, use the timer_wait() function, sending it the
number of microseconds you want to wait.
-- To wait asynchronously, use the timer_start() function, sending it the
number of microseconds in which you want to be notified. Then wait for a
signal from the timer device:
Wait( 1L<<timer_port->mp_SigBit );
This can be combined with other signals to allow you to wait for more
than one input. For example, to wait for the timer device and for window
input:
struct Window *window;
Wait( 1L<<window->UserPort->mp_SigBit | 1L<<timer_port->mp_SigBit );
To test whether the specified time has elapsed, use the timer_test()
function. If it has not elapsed, be sure to call the timer_abort()
function before issuing another request. For example:
if (timer_test())
/* the specified time has elapsed */
else
timer_abort();
-- Compile the timer.c source file. Be sure to link this file with your main
program, for example (with the test.c program and Manx C):
ln test timer -lc
For more details, read the accompanying article and the source to the test
program.
/*--- END OF TEXT ---*/