Mercurial > hg > Members > kono > nitros9-code
view docs/ccguide/os9.refentry @ 1331:0a3500c747de
Fixed ANOTHER bug
author | boisy |
---|---|
date | Sun, 07 Sep 2003 00:53:51 +0000 |
parents | 42b2c775f05f |
children |
line wrap: on
line source
<refentry id="os9"> <refnamediv> <refname>_os9</refname> <refpurpose>system call interface from C programs</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> #include <os9.h> </funcsynopsisinfo> <funcprototype> <funcdef><function>_os9</function></funcdef> <paramdef>char <parameter>code</parameter></paramdef> <paramdef>struct registers *<parameter>reg</parameter></paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1><title>Description</title> <para> _os9 enables a programmer to access virtually any OS-9 system call directly from a C program without having to resort to assembly language routines. </para> <para> <varname>Code</varname> is one of the codes that are defines in os9.h. os9.h contains codes for the F$ and I$ function/service requests, and it also contains getstt, setstt, and error codes. </para> <para> The input registers(reg) for the system calls are accessed by the following structure that is defined in os9.h: <programlisting> struct registers { char rg_cc,rg_a,rg_b,rg_dp; unsigned rg_x,rg_y,rg_u; }; </programlisting> An example program that uses _os9 is presented on the following page. </para> </refsect1> <refsect1><title>Diagnostics</title> <para> -1 is returned is the OS-9 call failed. 0 is returned on success. </para> </refsect1> <refsect1><title>Program Example</title> <programlisting> #include <os9.h> #include <modes.h> /* this program does an I$GETSTT call to get file size */ main(argc,argv) int argc; char **argv; { struct registers reg; int path; /* tell linker we need longs */ pflinit(); /* low level open(file name is first command line param */ path=open(*++argv,S_IREAD); /* set up regs for call to OS-9 */ reg.rg_a=path; reg.rg_b=SS_SIZE; if(_os9(I_GETSTT,&reg) == 0) printf("filesize = %lx\n", /* success */ (long) (reg.rg_x << 16)+reg.rg_u); else printf("OS9 error #%d\n",reg.rg_b & 0xff); /*failed*/ dumpregs(&reg); /* take a look at the registers */ } dumpregs(r) register struct registers *r; { printf("cc=%02x\n",r->rg_cc & 0xff); printf(" a=%02x\n",r->rg_a & 0xff); printf(" b=%02x\n",r->rg_b & 0xff); printf("dp=%02x\n",r->rg_dp & 0xff); printf(" x=%02x\n",r->rg_x); printf(" y=%02x\n",r->rg_u); printf(" u=%02x\n",r->rg_y); } </programlisting> </refsect1> </refentry>