2 Copyright 2010, The AROS Development Team. All rights reserved.
6 /**************************************************************************
9 * This file contains helper functions to detect, if J-UAE is running and
10 * to detect, if an executeable is a m68k amigaOS file.
12 * It also gives wanderer.c a function, to forward a Message to
13 * the m68k amigaOS launchd via J-UAE, so that the correct
14 * executeable is started with all wanderer arguments.
16 **************************************************************************/
18 #include <proto/utility.h>
19 #include <utility/tagitem.h>
20 #include <workbench/workbench.h>
24 #include <aros/debug.h>
27 #include "workbench_intern.h"
28 #include "uae_integration.h"
30 /**************************************************************************
33 * return the port, Janus UAE uses to launch applications
34 **************************************************************************/
35 static struct MsgPort
*get_j_uae_port(void)
37 return FindPort((STRPTR
) J_UAE_PORT
);
40 /**************************************************************************
43 * test if Janus UAE is running
44 **************************************************************************/
45 BOOL
j_uae_running(void)
47 if( get_j_uae_port() != NULL
)
49 D(bug("[WBLIB] %s: J-UAE port found\n", __PRETTY_FUNCTION__
));
53 D(bug("[WBLIB] %s: J-UAE port \"%s\" *not* found\n", __PRETTY_FUNCTION__
, J_UAE_PORT
));
57 /**************************************************************************
58 * is_68k(filename with path)
60 * test, if the supplied file is an AmigaOS 68k binary
62 * (Amiga 68k executables start with 0x00 0x00 0x03 0xf3)
63 **************************************************************************/
64 BOOL
is_68k(STRPTR filename
, APTR WorkbenchBase
)
69 fh
=Open(filename
, MODE_OLDFILE
);
73 if(Read(fh
, begin
, 4) == 4)
75 if( (begin
[0] == 0x00) && (begin
[1] == 0x00) && (begin
[2] == 0x03) && (begin
[3] == 0xf3) )
77 D(bug("[WBLIB] %s: Amiga 68k executable found: %s\n", __PRETTY_FUNCTION__
, filename
));
87 /**************************************************************************
88 * tag_list_nr(struct TagItem *tstate)
90 * count number of TagItems
91 **************************************************************************/
92 static ULONG
tag_list_nr(const struct TagItem
*tstate
, APTR WorkbenchBase
)
97 while(NextTagItem((struct TagItem
**)&tstate
))
102 D(bug("[WBLIB] %s: TagList has %d items.\n", __PRETTY_FUNCTION__
, count
));
106 /**************************************************************************
107 * str_dup_vec(char *in)
109 * Allocate a buffer for string in with AllocVecPooled
110 **************************************************************************/
111 static STRPTR
str_dup_vec(void *mempool
, char *in
)
120 result
=AllocVecPooled(mempool
, strlen(in
)+1);
123 return (STRPTR
) result
;
126 #define LOCK_NAME_BUFFER_SIZE 2000
128 /**************************************************************************
129 * tag_list_clone(struct TagItem *in)
131 * clone the TagList in and also clone all strings, in points to
132 **************************************************************************/
133 struct TagItem
*tag_list_clone(void *mempool
, const struct TagItem
*in
, APTR WorkbenchBase
)
138 struct TagItem
*result
;
139 char *name_from_lock
;
142 nr
=tag_list_nr(in
, WorkbenchBase
);
149 /* don't ask me, if all that stuff can work on 64-Bit AROS, sorry */
151 /* local only, no pool required */
152 name_from_lock
=(char *) AllocVec(LOCK_NAME_BUFFER_SIZE
, MEMF_CLEAR
);
155 D(bug("[WBLIB] %s: ERROR: AllocVec failed!\n", __PRETTY_FUNCTION__
));
159 result
=(struct TagItem
*) AllocVecPooled(mempool
, (nr
+1) * sizeof(struct TagItem
));
162 D(bug("[WBLIB] %s: ERROR: AllocVecPooled failed!\n", __PRETTY_FUNCTION__
));
163 FreeVec(name_from_lock
);
168 while( (tag
=NextTagItem((struct TagItem
**)&in
)) )
170 switch(tag
->ti_Tag
) {
172 case WBOPENA_ArgLock
:
173 NameFromLock((BPTR
) tag
->ti_Data
, name_from_lock
, LOCK_NAME_BUFFER_SIZE
);
174 UnLock((BPTR
) tag
->ti_Data
); /* do we have to UnLock it? */
175 result
[t
].ti_Tag
=WBOPENA_ArgLock
;
176 result
[t
].ti_Data
=(STACKIPTR
) str_dup_vec(mempool
, name_from_lock
);
177 D(bug("[WBLIB] %s: WBOPENA_ArgLock: %s\n", __PRETTY_FUNCTION__
, name_from_lock
));
181 case WBOPENA_ArgName
:
182 result
[t
].ti_Tag
=WBOPENA_ArgName
;
183 result
[t
].ti_Data
=(STACKIPTR
) str_dup_vec(mempool
, (char *) tag
->ti_Data
);
184 D(bug("[WBLIB] %s: WBOPENA_ArgName: %s\n", __PRETTY_FUNCTION__
, tag
->ti_Data
));
190 /* terminate. not necessary, but feels better. */
191 result
[t
].ti_Tag
=TAG_DONE
;
192 result
[t
].ti_Data
=TAG_DONE
;
194 FreeVec(name_from_lock
);
199 /**************************************************************************
200 * forward_to_uae(struct TagItem *argsTagList, char *name)
202 * Sends a message to the J-UAE port in order to launch the
203 * according m68k amigaOS executeable.
205 * Errorhandling is completely up to J-UAE!
206 * J-UAE has to free all message resources!
207 **************************************************************************/
208 void forward_to_uae(struct TagItem
*argsTagList
, char *name
, APTR WorkbenchBase
)
211 struct MsgPort
*port
;
212 struct JUAE_Launch_Message
*msg
;
215 D(bug("[WBLIB] %s: j_uae_running and is_68k!\n", __PRETTY_FUNCTION__
));
217 /* We allocate everything in a pool, so we can free it easily afterwards
218 * J-UAE has to free everything
220 pool
=CreatePool(MEMF_CLEAR
|MEMF_PUBLIC
, 2048, 1024);
223 msg
=AllocVecPooled(pool
, sizeof(struct JUAE_Launch_Message
));
227 msg
->tags
=tag_list_clone(pool
, argsTagList
, WorkbenchBase
);
228 msg
->ln_Name
=str_dup_vec(pool
, name
);
230 /* now ensure, that the port stays alive */
232 port
=get_j_uae_port();
235 D(bug("[WBLIB] %s: PutMsg %lx to J-UAE\n", __PRETTY_FUNCTION__
, msg
));
236 PutMsg(port
, (struct Message
*) msg
); /* one way */
239 /* argl. someone closed the port inbetween !? */
240 D(bug("[WBLIB] %s: ERROR: someone closed the port inbetween !? \n", __PRETTY_FUNCTION__
));