*       MixedBin.s
*
*       Part of the Storm-PowerASM tutorial
*
*       A small PPC program which demonstrates how to call
*       a PPC function
*
*       © 1997 HAAGE&PARTNER Computer GmbH

                XREF    PPCMain                 ;import address of PPC function
                XREF    _LinkerDB               ;import pointer to smalldata base

                XDEF    Func68K                 ;export subroutine address
                XDEF    _PowerPCBase            ;export _PowerPCBase
                XDEF    _main                   ;export _main

                include powerpc/powerpc.i

                include exec_lib.i
                include dos_lib.i

                section "",code

_main
                movem.l d1-a6,-(sp)
                move.l  $4.w,_SysBase           ;evaluate _SysBase
                lea     _LinkerDB,a4            ;get pointer to Smalldata base
                OPENPOWERPC                     ;open powerpc.library
                tst.l   _PowerPCBase            ;success?
                beq.b   .exit                   ;no -> exit
                lea     dos_name,a1             ;a1 -> "dos.library"
                moveq   #0,d0                   ;d0 = minimum version
                CALLEXEC        OpenLibrary     ;open dos.library
                tst.l   d0                      ;success?
                beq.b   .exit                   ;no -> exit
                move.l  d0,_DOSBase             ;store DosBase
                move.l  #12,d0                  ;parameter for PPC function
                RUNPOWERPC      PPCMain         ;call PPC function
                move.l  d0,Args                 ;store result
                move.l  #result_text,d1         ;pointer to text
                move.l  #Args,d2                ;pointer to arguments
                CALLDOS         VPrintf         ;print out result
                move.l  _DOSBase,a1             ;get DosBase to a1
                CALLEXEC        CloseLibrary    ;close dos.library
.exit
                CLOSEPOWERPC                    ;close powerpc.library
                movem.l (sp)+,d1-a6
                moveq   #0,d0
                rts


Func68K
                movem.l d1-a6,-(sp)
                muls    d1,d0                   ;multiply both parameters
                movem.l (sp)+,d1-a6
                rts

                section "",data

                POWERDATA
dos_name        dc.b    "dos.library",0
result_text     dc.b    "The PPCMain function returned %ld\n",0


                section "",bss
_SysBase        ds.l    1
_DOSBase        ds.l    1
Args            ds.l    1

