home *** CD-ROM | disk | FTP | other *** search
- <TITLE>swi -- Python library reference</TITLE>
- Next: <A HREF="../d/drawf" TYPE="Next">drawf</A>
- Prev: <A HREF="../r/riscospath" TYPE="Prev">riscospath</A>
- Up: <A HREF="../r/riscos_only" TYPE="Up">RISCOS ONLY</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>13.3. Built-in Module <CODE>swi</CODE></H1>
- This module provides access to the RiscOS SWI interface. It provides
- a function <CODE>swi</CODE> that puts suitable values in the arm registers,
- calls the SWI and extracts values from registers.
- <P>
- As many SWIs manipulate blocks of memory a new object type is provided
- for handling blocks of memory and inserting and extracting values from them.
- <P>
- Errors are reported as exceptions; the usual exceptions are given
- for type, index and value errors, while errors reported by X versions of the
- system calls raise
- <CODE>swi.error</CODE>, described below.
- <P>
- Module <CODE>swi</CODE> defines the following data item:
- <P>
- <DL><DT><B>error</B> -- exception of module swi<DD>
- This exception is raised when an RiscOS X SWI returns a
- RiscOS-related error (e.g., not for illegal argument types). Its
- string value is <CODE>'swi.error'</CODE>. The accompanying value is a
- string returned by the SWI.
- </DL>
- It defines the following functions:
- <P>
- <DL><DT><B>swi</B> (<VAR>name</VAR>,<VAR>descriptor</VAR>,...) -- function of module swi<DD>
- Calls the swi given by <VAR>name</VAR> with registers given by <VAR>descriptor</VAR>.
- <VAR>name</VAR> can either be an integer SWI number, or a string SWI name.
- SWI names are case dependent. To call the X version of the SWI you should
- set the X bit in the number, or preceed the name with X.
- <P>
- <VAR>descriptor</VAR> is a string that determines the registers to be passed
- and returned. Values to pass are taken sequentially from the remaining
- arguments, they are assigned to registers starting from r0. Characters
- of <VAR>descriptor</VAR> indicate how to pass values.
- <P>
- <DL>
- <DT><I>Character</I><DD><I>Meaning</I> --- <I>Argument Type</I>
- <P>
- <DT>`<SAMP>i</SAMP>'<DD>pass an integer --- int
- <DT>`<SAMP>s</SAMP>'<DD>pass a pointer to a string --- string
- <DT>`<SAMP>b</SAMP>'<DD>pass a pointer to the start of a block --- block
- <DT>`<SAMP>e</SAMP>'<DD>pass a pointer after the end of a block --- block
- <DT>`<SAMP>0-9</SAMP>'<DD>insert 0-9 in the register --- -
- <DT>`<SAMP>-</SAMP>'<DD>insert in the register --- -
- <DT>`<SAMP>.</SAMP>'<DD>skip a register --- -
- </DL>
- Note: Strings are read--only. If you want to alter a buffer passed to a SWI you
- must use a block.
- <P>
- If the descriptor contains a semi--colon, characters after this refer
- to values returned by registers. A single value is returned as an
- object. Several values are returned as a tuple.
- <P>
- <DL>
- <DT><I>Character</I><DD><I>Meaning</I> --- <I>Output Type</I>
- <P>
- <DT>`<SAMP>i</SAMP>'<DD>return an integer --- int
- <DT>`<SAMP>s</SAMP>'<DD>return a string --- string
- <DT>`<SAMP>*</SAMP>'<DD>return the carry flag --- int
- <DT>`<SAMP>.</SAMP>'<DD>skip a register --- -
- </DL>
- Example: wimp_initialise
- <P>
- <UL COMPACT><CODE>>>> from swi import *<P>
- >>> msgs=block(2,[0x600c0,0])<P>
- >>> pname="myprog"<P>
- >>> wimpver,taskhand=swi(0x600c0,"iisb;ii",310,0x4b534154,pname,msgs)<P>
- </CODE></UL>
- </DL>
- <DL><DT><B>block</B> (<VAR>size</VAR> [, <VAR>initializer</VAR>]) -- function of module swi<DD>
- Returns a new block of <VAR>size</VAR> words. The initializer must be a string
- or a list of integers. The initializer is truncated to fit the block.
- If it is too short it is padded with zeros. If there is no initializer
- the content of the block is undefined.
- </DL>
- The memory of a block is guaranteed not to move unless the block is deleted
- or resized.
- <P>
- Blocks support index and slice operations as for lists of integers, except
- that the block cannot change size, so assignments are truncated or padded
- as for initialization. Slices beyond the end of the block give index errors.
- <P>
- <DL><DT><B>register</B> (<VAR>size</VAR>,<VAR>address</VAR>) -- function of module swi<DD>
- Registers a prexisting memory block of <VAR>size</VAR> words as a block.
- Returns a new block. The memory supplied will not be freed when the block
- is deleted, or moved when it is resized.
- </DL>
- Block items support the following data items and methods.
- <P>
- <DL><DT><B>length</B> -- data of module swi<DD>
- The length of the block in bytes. Equal to <CODE>4*len(<VAR>block</VAR>)</CODE>.
- </DL>
- <DL><DT><B>start</B> -- data of module swi<DD>
- The start address of the memory block.
- </DL>
- <DL><DT><B>end</B> -- data of module swi<DD>
- The address after the end of the memory block.
- </DL>
- <DL><DT><B>padstring</B> (<VAR>string</VAR>,<VAR>padchar</VAR> [,<VAR>x</VAR>,<VAR>y</VAR>]) -- function of module swi<DD>
- The string is copied into the block between bytes <CODE>x</CODE> and <CODE>y-1</CODE>.
- The string is truncated or padded with <VAR>padchar</VAR> as required.
- <VAR>x</VAR> and <VAR>y</VAR> default to 0 and <CODE>block.length</CODE>.
- </DL>
- <DL><DT><B>tostring</B> ([<VAR>x</VAR>,<VAR>y</VAR>]) -- function of module swi<DD>
- The bytes between <CODE>x</CODE> and <CODE>y-1</CODE> are returned as a string.
- <VAR>x</VAR> and <VAR>y</VAR> default to 0 and <CODE>block.length</CODE>.
- </DL>
- <DL><DT><B>nullstring</B> ([<VAR>x</VAR>,<VAR>y</VAR>]) -- function of module swi<DD>
- The bytes between <CODE>x</CODE> and <CODE>y-1</CODE> are returned as a string, the
- string is terminated before the first null character if any.
- <VAR>x</VAR> and <VAR>y</VAR> default to 0 and <CODE>block.length</CODE>.
- </DL>
- <DL><DT><B>ctrlstring</B> ([<VAR>x</VAR>,<VAR>y</VAR>]) -- function of module swi<DD>
- The bytes between <CODE>x</CODE> and <CODE>y-1</CODE> are returned as a string, the
- string is terminated before the first control character if any.
- <VAR>x</VAR> and <VAR>y</VAR> default to 0 and <CODE>block.length</CODE>.
- </DL>
- <DL><DT><B>bitset</B> (<VAR>i</VAR>,<VAR>x</VAR>,<VAR>y</VAR>) -- function of module swi<DD>
- <CODE>b.bitset(x,y)</CODE> is equivalent to @verb{b[i]=(b[i]&y)^x}.
- </DL>
- <DL><DT><B>resize</B> (<VAR>size</VAR>) -- function of module swi<DD>
- Changes the size of the block. The new size is in words. If the block was
- created using <CODE>register</CODE> this just changes the recorded end of the
- block. Otherwise the block may move, and the data in the block is
- truncated or zero padded as neccesary.
- </DL>
-