Title: COUNTERVAR Author: Nicholas Clark Version: 0.02 Title From: Documentation Author From: Documentation Version From: Documentation Supplier: Nicholas Clark Date: 05/03/97 Keywords: Utility programs Shareware: No Machine: Archimedes Operating system: RISCOS Memory requirements: Peripherals needed: Other s/ware needed: Directory: micros/arch/riscos/e194 Date mounted/updated: 15/03/97 File names: countervar.zip Unarchived files: 4 Unarchived size: 6 kbytes Omissions: See also: SETTIMER (e050) ------------------------------------------------------------------------------- Acquiring the package: Download the archive file(s) and extract using SparkPlug 2 (see the "tools_help" file in micros/arch/riscos/tools for further info). Description: CounterVar is a short (140 bytes) utility to create an OS variable which acts as a counter. Every time this variable is read, its value is automatically incremented. It is designed to be replace parts of code that currently read, increment and write a conventional environment variable (eg the UnixLib pipe counter) The utility is able to create any number of counter variables - call it once for each counter to create. The name of the variable to create is supplied as the first parameter, the optional second parameter is the initial value (defaults to zero) CounterHex counts in hexadecimal rather than decimal (and always generates exactly 8 character output.) The counter variable is implemented as a code variable - the advantages of this method over reading, modifying and writing a conventional variable from inside your code are: 0: The code variable method is almost certainly more compact. 1: This method will be faster - only one SWI call to read the variable, none to write it back 2: [As long as you aren't trying to read the counter under interrupts] you can't accidentally read the same value twice. Using a conventional variable, two programs running in task windows can, if one is unlucky enough to read the value just after a second program has read it, but just before the second program writes back the incremented value. Hopefully the source serves as an example of how to write a transient utility, and how to write a code variable.