Showing changes from revision #1 to #2:
Added | Removed | Changed
RISC OS provide numerous SWIs that perform many different operations. Most SWIs functions are specified by their name. e.g. OS_RemoveCursors removes cursors. However, there are two SWIs that perform a wide variety of different operations. They are OS_Byte and OS_Word.
This document provides information on OS_Byte.
The OS_Byte SWI uses at most three registers. The registers upon entry are detailed below:
Register | Use |
---|---|
R0 | Reason code. Used to specify the operation to be performed. (0 – 255) |
R1 | Parameter 2. Dependant on reason code (0 – 255) |
R2 | Parameter 3. Dependant on reason code (0 – 255) |
The name OS_Byte originates from the use of one byte per parameter (values of 0 to 255). It is important to note that the register actually passes the value as 32-bit parameters, and mask out the top 24-bits.
Any routine written to implement or decode OS_Byte calls, must preserve the top 24-bits, at least in R0. This can be achieved by masking the parameters into temporary registers instead of back into the passed parameters.
Some operations of OS_Byte result in returned values too large to fit into a single byte, and should be treated as whole words.
The value passed by R0 specifies the operation to be performed. The reason code must be a value from 0 to 255. Although a large number of different operations are available, the reason codes are grouped by parameter usage.
Where the reason code is between 0 and 127 (inclusive), only R1 is used to pass information to the SWI routine. However, R2 is sometimes used as a temporary register that is corrupted during the SWI routine.
Where the reason code is between 128 and 165 (inclusive), both R1 and R2 are used to pass values to the SWI routine. They may also be used to return values upon exit.
They are often used to return information, rather than perform a particular action.
Where the reason code is between 166 and 255 (inclusive), both R1 and R2 are used to pass values to the SWI routine. In addition, R0 is also used as an index pointer into the RAM which holds the status variables, which are held in consecutive memory locations. i.e. When R0 = 166, points to the first status variable, R1 = 167 points to the second status variable, and so on.
The contents of R1 and R2 determines what happens to the status variable. The formula below shows how the new value of the status variable is calculated:
New_Value = (Old_Value AND R2) EOR R1
On exit:
To read a value without being altered, the following Register values should be used:
To write a specific value, the following Register values should be used:
To alter specific bits, the following Register values should be used:
e.g. If bits 5,6 & 7 are to be changed, to the binary pattern 101, then the following binary values should be used:
OS_Byte is a vectored SWI, but before its vector is called, interrupts are disabled. Most OS_Byte routines are so short that there is no need to re-enable interrupts, and instead rely on RISC OS to do this when control is returned to the program that issued the SWI.
Because the interrupts are not re-enabled, the routines are also used by interrupt handling routines.
If you wish to replace an OS_Byte routine, you must ensure that the replacement routine:
Because the OS_Byte is a vectored SWI, it is possible to add your own OS_Byte calls by installing a routine on the software vector that OS_Byte uses.
For more information, read the Software Vectors section.
Because OS_Byte performs a lot of very useful functions, RISC OS provides a *Command to call the routine directly. The command is *FX.
Because *FX cannot display any return values, it is not possible to use the command to read the values of status variables.