View Single Post
Old 30 December 2013, 10:30   #21
thellier
Registered User
 
Join Date: Sep 2011
Location: Paris/France
Posts: 148
>Alternatively, you could write a mixed-binary 68k library that runs 68K if the .dll is not found or if not running on a .dll capable system.
This is the way Wazp3D works
Wazp3D.library use my soft3d.library as renderer
the soft3d.library contain native calls to the soft3d.dll but also the full 68k functions if the .dll cant be opened

On the PC side the soft3d side contain both the glue functions and the pure x86 function
SOFT3D_CreateTextureUAE() called from UAE
SOFT3D_CreateTexture() can be called from a windows apps (useless here but present)

>int library = uni_load_library("hello_world_library");
>int function = uni_get_function(library, "hello_world");

Would be more simple to have a standard UAE backdoor that will do an "OpenLibraryNative" and just return a library header (version) and full jumps table
Not very difficult Here it is the code I used in Wazp3D/soft3d (more in Wazp3d sources)
There is only something that MUST be changed = no more open the external library with his full name (soft3d.dll) but the name (soft3d) so allowing to have the same 68k code that will open soft3d.so soft3d.elf

Alain Thellier

Code:
/*==========================================================================*/
void winuae_getnativeaddrall( ULONG dllbase, APTR *funcnames, ULONG *funcptrs,ULONG nb )
{
register ULONG D0 __asm("d0")=GETNATIVEADRESSE;
register ULONG D1 __asm("d1")=dllbase;
register ULONG A0 __asm("a0");

register ULONG D2	__asm("d2");
	
	for(D2=0;D2<nb;D2++)
	{
	D0=GETNATIVEADRESSE;
	D1=dllbase;
	A0=(ULONG)funcnames[0];
	asm volatile ("jsr 0xf0ffc0");
	D0++;					/* only to avoid d0 to be otimized away */
	funcptrs[0]= D0-1;		/* only to avoid d0 to be otimized away like that: funcptrs[0]=GETNATIVEADRESSE */
	funcnames++;
	funcptrs++;
	}
}
/*==========================================================================*/
ULONG winuae_opendll( APTR dllname )
{
	WINUAENATIVE(OPENDLL,0,(ULONG)dllname);
}
/*==========================================================================*/
ULONG  winuae_closedll( ULONG dllbase )
{
	WINUAENATIVE(CLOSEDLL,dllbase,0);
}
/*==========================================================================*/
#define SOFT3D_ClearImageBufferUAE 0
#define SOFT3D_ClearZBufferUAE 1
#define SOFT3D_CreateTextureUAE 2
#define SOFT3D_DoUpdateUAE 3
#define SOFT3D_DrawPrimitiveUAE 4
#define SOFT3D_EndUAE 5
#define SOFT3D_FreeTextureUAE 6
#define SOFT3D_ReadZSpanUAE 7
#define SOFT3D_AllocImageBufferUAE 8
#define SOFT3D_SetBitmapUAE 9
#define SOFT3D_SetClippingUAE 10
#define SOFT3D_SetDrawStateUAE 11
#define SOFT3D_AllocZbufferUAE 12
#define SOFT3D_StartUAE 13
#define SOFT3D_WriteZSpanUAE 14
#define SOFT3D_FlushUAE 15
#define SOFT3D_UpdateTextureUAE 16
#define SOFT3D_DebugUAE 17

UBYTE name0 [] = {"_SOFT3D_ClearImageBufferUAE"};
UBYTE name1 [] = {"_SOFT3D_ClearZBufferUAE"};
UBYTE name2 [] = {"_SOFT3D_CreateTextureUAE"};
UBYTE name3 [] = {"_SOFT3D_DoUpdateUAE"};
UBYTE name4 [] = {"_SOFT3D_DrawPrimitiveUAE"};
UBYTE name5 [] = {"_SOFT3D_EndUAE"};
UBYTE name6 [] = {"_SOFT3D_FreeTextureUAE"};
UBYTE name7 [] = {"_SOFT3D_ReadZSpanUAE"};
UBYTE name8 [] = {"_SOFT3D_AllocImageBufferUAE"};
UBYTE name9 [] = {"_SOFT3D_SetBitmapUAE"};
UBYTE name10[] = {"_SOFT3D_SetClippingUAE"};
UBYTE name11[] = {"_SOFT3D_SetDrawStateUAE"};
UBYTE name12[] = {"_SOFT3D_AllocZbufferUAE"};
UBYTE name13[] = {"_SOFT3D_StartUAE"};
UBYTE name14[] = {"_SOFT3D_WriteZSpanUAE"};
UBYTE name15[] = {"_SOFT3D_FlushUAE"};
UBYTE name16[] = {"_SOFT3D_UpdateTextureUAE"};
UBYTE name17[] = {"_SOFT3D_Debug"};

#define FUNCNB 18
APTR funcnames[FUNCNB]={name0,name1,name2,name3,name4,name5,name6,name7,name8,name9,name10,name11,name12,name13,name14,name15,name16,name17};
ULONG funcptrs[FUNCNB];
ULONG dllbase=0;

#define NLOOP(nbre) for(n=0;n<nbre;n++)
void Libprintf(UBYTE *string, ...);
extern BOOL LibDebug;
/*==================================================================================*/
void OpenSoft3DDLL()
{
BOOL DebugState=LibDebug;
int n;

LibDebug=TRUE;
	Libprintf("OpenSoft3DDLL\n");
	dllbase = winuae_opendll("soft3d.dll");
	if(dllbase == 0)
		{LibDebug=TRUE;LibAlert("Cant open WinUAE/soft3d.dll !"); LibDebug=DebugState; return;} 

	Libprintf("The DLL soft3d.dll is opened :-) (dllbase %ld)\n",dllbase);

	winuae_getnativeaddrall(dllbase,funcnames,funcptrs,FUNCNB);

	NLOOP(FUNCNB)
		if(funcptrs[n]!=0)
		{Libprintf("DLL's function%ld: %ld (from dllbase %ld)\n",n,funcptrs[n],funcptrs[n]-dllbase); }
		else
		{Libprintf("DLL's function%ld: not found ! \n",n); dllbase=0; } 

	if(dllbase!=0)
		{ Libprintf("DLL functions are here :-) \n"); }
	else
		{ Libprintf("DLL fail :-( \n"); dllbase=0; }

}
/*==================================================================================*/
void CloseSoft3DDLL()
{
	Libprintf("CloseSoft3DDLL\n");
	if(dllbase == 0) return;

	winuae_closedll(dllbase);
	Libprintf("The DLL soft3d.dll is closed\n");
}
/*==================================================================================*/

Last edited by Toni Wilen; 30 December 2013 at 10:54. Reason: Code in code tags.
thellier is offline  
AdSense AdSense  
 
Page generated in 0.08898 seconds with 9 queries