Posts: 556 from 2003/2/24
From: finland, the l...
TEXT DosName = "dos.library";
REG_D0 = 0;
REG_A0 = (ULONG) DosName;
REG_A6 = SysBase;
ULONG res = (*MyEmulHandle->EmulCallDirectOS)(-552);
ULONG res1 = REG_A0;
ULONG res2 = REG_D0;
kprintf("aaa %x %x %x %x %xn",SysBase,res,res1,res2,DosName);
As noted before the library name needs to be in A1.
The return value is in D0. Generally D1 does not contain any sensible value. 99% of the library functions return value only in D0 only. There are some really rare exceptions to this (utility.library UDivMod32 and SDivMod32 functions return 64-bit value in d0:d1 pair for example... but it makes little sense to call these functions directly I'd say).
If you mean res2 as in "the last dos error", then you need to use dos.library/IoErr() to get that value.
Note that when you set up REG_xx like that, since the registers might be overwritten unless if you're careful. One example of problematic code:
REG_D0 = 0x12345678;
REG_D1 = Output();
Here REG_D0 that is set before would be overwritten by the dos.library Output() call glue logic (and both REG_D0 and REG_D1 would result as current output file handle value).
One solution is to use a variable like this:
BPTR outfh = Output();
REG_D0 = 0x12345678;
REG_D1 = outfh;
Either way, unless if you really must, I'd try to remain using the MorphOS SDK provided ppcinline glue logic instead of custom code like this. However, it does work directly like this as well. The likelihood of silly mistakes is rather high, however. Of course it might be possible to generate the glue functions from the protos/fd files with some tool similar to cvinclude.pl.
Finally, many functions will be rather dangerous to call. Imagine for example intuition/LockIBase or something that obtains a global system lock. Holding this lock will effectively lock all UI operations, and the system will appear "locked up". It's like weaponizing Lua. It's likely that you can't shoot yourself to the foot with Lua normally, but with this functionality you give ample arsenal for it. Maybe there just needs to be a warning to the user deciding to use this functionality: "be careful what you do with this thing"...[ Edited by Piru 04.08.2021 - 19:05 ]