#: 17755 S12/OS9/68000 (OSK)
18-Mar-93 16:27:10
Sb: #17744-#Subroutine modules
Fm: Graham Trott 100115,1075
To: Bob van der Poel 76510,2203 (X)
Bob --
I've used subroutine modules in CD-I, to extend the functionality of a standard
high-level package (kinda like HyperCard's XCMD). I attach below an example
(to compute the size of a rectangle across the diagonal without using sqrt).
As far as I know it's difficult to have static storage; I use a mixture of
getting the caller to pass the addresses of variables, combined with
self-modifying code (purists may groan but it's OK in CD-I). You might
alternatively employ a shared data module.
First, a special cstart module:
* Radial.a
use oskdefs.d
psect XCMD,(Sbrtn<<8)+Objct,(ReEnt<<8),1,0,Start
org -32768
_attop do.l 1
_mtop: do.l 1
_stbot: do.l 1
errno: do.l 1
_totmem: do.l 1
_sbsize: do.l 1
_fcbs: do.l 1
environ: do.l 1
_pathcnt: do.w 1
_sysglob: do.l 1
Start: dc.l Function-Start Offset to the C main program
Params dz.l 3 This is the self-modifying storage area
* This function returns the address of an item of storage,
* organized as an array of pointers to data (see the C code).
Parameter: lea Params(pc),a0
asl.l #2,d0
move.l (a0,d0),d0
rts
ends
Next, the C part of the subroutine module:
/* Radial.c */
extern long *Parameter(); /* returns the address of a parameter */
void Function() /* the main entry point */
{
long width, height, square, n;
width=*(Parameter(0)); /* get the data from the first variable */
height=*(Parameter(1)); /* ditto the second */
square=width*width+height*height;
for (n=2; n*n
|