HINTS & TIPS

This month's collection of hints and tips is rounded up by David Spencer.

DESKTOP SCROLLING

By P.D. White

When the RISC OS Desktop is started up, it enables the scroll protect option. This means that if a character is printed in the last column of a line, the cursor is not moved on to the next line until the next character is printed. This prevents the screen scrolling when a character is printed in the very bottom right-hand corner. However, this option is left on when the Desktop is quit, and it survives mode changes. While this will not normally cause problems, it can with some programs. To turn the scroll protect off use:
VDU 23,16|

ALIGN AGAIN

by David Spencer

When Basic's built-in assembler aligns the instruction pointer to a word boundary, either implicitly or using the ALIGN directive, it does not pad the skipped bytes with any data. This means that if you assemble the same source program on two separate occasions, the two object codes will not necessarily be identical. This won't affect execution of the program in any way, but can produce confusing results if a bytewise comparison of two programs is performed.

EXTENDED MOUSE

by Tom Short

The MOUSE statement in the new RISC OS Basic (Version 1.04) has been extended to provide a fourth value. By using the statement:
MOUSE x,y,b,t
x and y will contain the position of the mouse, and b the button state, just as before. The new variable t will contain a value called the monotonic time. This is a counter which starts at zero when the computer is first turned on, and is incremented one hundred times a second. It can only be reset by turning the computer off. The monotonic time can be used to time the delay between mouse clicks to detect double clicks, triple clicks etc.

FINDING FILEINFO

by Ian Taylor

The format of the display produced by *EX and *INFO has been changed in RISC OS. In particular, they no longer give the location on disc of a particular file, and for longer files they give the length as a rough number of kilobytes, rather than an actual value. To find out the full information use the command:
*FILEINFO <filename>
This will print out full file information for the named file, or in the case of a wildcarded name, a group of files. The file length (in hex) is the first value after the date.

DISC DEFECTS

by John Regan

The new 'E' disc format offered by RISC OS allows discs to be used even if they have damaged sectors. When the disc is first formatted, it is verified, and if any sectors are found not to format, the disc is reformatted with those sectors mapped out. The mapped out sectors will appear as free space if the *MAP command is used, and the disc can be used perfectly normally, albeit with a reduced capacity. However, it is not possible to use *BACKUP to backup onto a disc containing defects.

FILE OPENING

by Michael Thornton

Using OPENIN or OPENUP to open a file returns a file handle of zero if the file was not found. This handle must then be checked, and an error given if appropriate. However, if you bypass OPENIN and OPENUP, and instead use the call SYS "OS_Find", you can force an error to be generated if the file is not found. To do this, use:
SYS "OS_Find",&44,name$ TO handle
in place of:
handle = OPENIN name$
and:
SYS "OS_Find",&C4,name$ TO handle
instead of:
handle = OPENUP name$

DIRECTORY VIEWERS

by Graeme Davidson

The RISC OS Filer provides a nice feature to allow you to traverse a directory tree without ending up with countless directory viewers open. Double clicking on a directory in a viewer using the Adjust (right-hand) button, will open the new directory, but also close the current viewer. Similarly, closing a directory viewer with the Adjust button will re-open its parent if it is not already visible. Running an application with a double-click of Adjust will close the viewer before the application is run.

THE SHARED C LIBRARY

by David Spencer

The new release 2 of the Archimedes C compiler supports a shared library facility. This allows several C programs running simultaneously (multi-tasking under RISC OS) to share a common set of library routines, so reducing the length of the individual programs. In order to use this feature, the additional parameter "-l arm.clib.o.stubs" should be added to the command line when the source code is compiled. So, for example:
cc TestProg
would become:
cc TestProg -l arm.clib.o.stubs
The additional parameter tells the linker to include the object file 'stubs', rather than the standard library files.

When linked in this way, the program will only run with the shared library installed (otherwise the error 'SWI &80060 not known' will result). The shared library module has the filename 'Clib' and can be found in the library directory of the C compiler disc, or in the Modules directory within the !System application on RISC OS applications disc number 1.

SYS FLAGS

by Glynn Clements

Most people who have used the SYS statement from Basic will know that the contents of registers can be returned by using the keyword TO followed by a comma-separated list of variable names. It is also possible to read the processor flags returned by the call, by placing a variable name preceded by a semicolon after the returned variables. For example:
SYS "OS_ReadC" TO key ;flags
The flags are in the form of a four-bit number made up of the flags N, Z, C and V. Each flag can be tested individually using AND. For example:
IF (flags AND 2) THEN PRINT "Carry Set"