[comp.sys.amiga.tech] Prototyping a function pointer

AXTBF@ALASKA.BITNET (Tim Friest - programmer at large) (05/10/89)

We are SetFunctioning a library routine (DisplayBeep to be exact). If
our routine fails for some reason (all sound channels are busy, etc.) we
would like to call the real DisplayBeep.  How???  We tried doing this
with C (Lattice 5.02) and an Assembly Language stub, but neither worked
(we meditated on it a while...)

Sample pseudo code follows:

        __fptr OldRoutine;

        OldRoutine = SetFunction(Library, Offset, NewRoutine);

        if (error in new routine)
                OldRoutine(params);

The parameter is a screen pointer which must be passed in A0.

We tried to prototype OldRoutine like a normal function

        extern void __far __asm OldRoutine(register __a0 struct Screen *);

but got an error (unmodifiable lvalue).

We also tried prototyping the variable

        __fptr __far __asm OldRoutine(register __a0 struct Screen *);

but had the same error.

Finally, we tried writing an assembly language stub which

---C---

        extern void __far __asm AsmStub(register __a0 struct Screen *,
                                        register __a1 __fptr);


        AsmStub(Screeen, OldRoutine);

----Assembly---

_AsmStub:
        JSR (A1)
        RTS

------

It compiled and linked fine, but it gurued on execution (the code worked
for a function which we had not setfunctioned, so the stub works).

Any suggestions???

AXTBF@ALASKA.BITNET

It riles them to believe that you percieve the web they weave.
                                                -Moody Blues