*       Call68KLib.p
*
*       Part of the Storm-PowerASM tutorial
*
*       A small PPC program which calls some functions of
*       68K shared libraries.
*
*       © 1997 HAAGE&PARTNER Computer GmbH

                include powerpc/powerpc.i

                include exec_lib.i
                include dos_lib.i
                include intuition_lib.i

                XREF    _SysBase                ;import _SysBase
                XREF    _DOSBase                ;import _DOSBase
                XREF    _PowerPCBase            ;import _PowerPCBase

                executable                      ;generate executable

start
                prolog                          ;build stackframe
                push    r22                     ;save r22
                la      r6,Int_Name             ;a1 -> library name
                li      r3,0                    ;d0 = library version
                RUN68K  _SysBase,OpenLibrary    ;open intuition library
                sw      r3,_IntuitionBase       ;save _IntuitionBase
                tstw    r3                      ;library successfully opened?
                beq     .exit                   ;no -> exit
                li      r5,0                    ;a0 = NULL
                RUN68K  _IntuitionBase,DisplayBeep ;call DisplayBeep
                lw      r4,_IntuitionBase       ;load _Intuitionbase into r4
                RUN68K  _SysBase,CloseLibrary   ;close Intuition-Library
                la      r3,CPUName              ;Address of the CPU name to r3
                sw      r3,Args                 ;store stringpointer to 'Args'
                la      r4,text                 ;Address of 'text' to r4 (d1)
                la      r22,Args                ;Address of 'Args' to r22 (d2)
                RUN68K_XL       _DOSBase,VPrintf ;print some text
.exit
                pop     r22                     ;restore r22
                epilog                          ;remove stackframe


                section data
Int_Name        INTNAME
text            dc.b    "DisplayBeep successfully called by %s\n",0
CPUName         dc.b    "PPC",0


                section bss
_IntuitionBase  ds.l    1
Args            ds.l    1
