• How to use a linked library:
    The best way how to use linked libraries is to define it's functions in a module. To be more simple for programmer is better to add in to the module line containing:
      OPT LINK='linklibrary'
    

    where linklibrary is your linked library name if it is in 'd:lib' drawer, if not, add '*' before the linklibrary with full path (eg: 'hd5:lib/mylib.lib'). This will add the link library into the list of the link objects and after compilation everything will be linked. This module should be in 'dmodules:lib' drawer.

  • Function definition:
    PowerD makes it possible to use different types of functions. First function type is normal linked library function which allows LIST using. All used arguments are loaded into the stack in inverse order and then the function is called:
      LPROC procname(args)(results)
    

    LPROC is mostly used by C compilers, it parses arguments inverted from its definition: x(a,b,c) this moves to stack c then, b and then a, if You use a list as a last argument, all list items will be inserted to stack in same order:
        LPROC x(u,v,w:LIST OF LONG)
        x(a,b,c,d,e,f)
    

    this moves to stack f, e, d, c, b and a. This is quite dull when you want use something like this:
        LPROC x(a,b,c,d)
        n:=0
        x(n++,n++,n++,n++)
    

    this will copy 3 to a, 2 to b, 1 to c and 0 to d. Second is PowerD procedure compatible stack loading. It loads arguments in right order but don't (currently) allows the LISTs. These are also used for external procedures:
      EPROC procname(args)(results)
    

    This is quite more intelligent, but it doesn't allow inline lists as a last argument, you can of course use normal lists (closed in: []).
        EPROC x(a,b,c,d)
        n:=0
        x(n++,n++,n++,n++)
    

    works correctly, moves 0 to a, 1 to b, 2 to c and 3 to d. Last one is best suited for assembler routines, which doesn't use stack (it is slower than registers). Here is the limitation gave by count of registers on the cpu (MC68k allows 8 data, 5 address registers (don't use a6 and a7) and 8 float registers. PPC allows about 8 data/address registers and 13 float registers.):
      RPROC procname(args with registers)(results)[='asm']
    

    As you can see, it is possible to add an assembler source after RPROC definition, this way you can generate inlined functions. Be careful about the assembler source you must adhere right syntax:
      - each line starts with tabulator '\t' or some spaces or a label
      - each line must be ended with linefeed '\n'
      - you must use right instruction set
      - it is absolutely not affected by PowerD, it will be only copied instead of the
        function call
      - it is normal string, so you can use multi line strings
      - the total size of the string must be shorter than 320 characters, if You need more, use
        the APROC.
    


  • How to build linked library:
    First you have to generate object files, each object file should contain only one function. This may be done with OPT OBJECT in PowerD case. If you want to create an assembler routines, use export keyword (usually xdef). Copy all these objects into a single drawer, open shell, set there the drawer and enter 'join #?.o as xxx.lib', where xxx is your library name. Then copy this file into 'd:lib' drawer. Finaly you should write a module for this lib. This way is possible to generate linked libraries from PowerD, Assembler, C etc. objects, just select right function definition (LPROC/EPROC/RPROC).

  • Examples:
      LPROC printf(fmt:PTR TO CHAR,args:LIST)
    
      EPROC PrintF(fmt:PTR TO CHAR,args:PTR)
    
      RPROC PrintF(a0:PTR TO CHAR,a1:LIST)