Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!rutgers!cbmvax!ken From: ken@cbmvax.commodore.com (Ken Farinsky - CATS) Newsgroups: comp.sys.amiga.programmer Subject: Re: Help! (AmigaDOS CreateProc/LoadSeg) Message-ID: <19578@cbmvax.commodore.com> Date: 6 Mar 91 21:02:29 GMT References: <63329@eerie.acsu.Buffalo.EDU> Reply-To: ken@cbmvax.commodore.com (Ken Farinsky - CATS) Organization: Commodore, West Chester, PA Lines: 63 In article <63329@eerie.acsu.Buffalo.EDU> gbbrooks@acsu.buffalo.edu (george b brooks) writes: > Segment := LoadSeg("df1:HelloWorld"); > ID := CreateProc(ADR("NewProcess"),0D,Segment,10000D); > (Where HelloWorld is a compiled M-2 program on disk) > > Segment := LoadSeg(ADR(HelloWorldProcedure)); > ID := CreateProc(ADR("NewProcess"),0D,Segment,10000D); > (Where HelloWorldProcedure is a M-2 procedure in the same code) > > Or what DOES LoadSeg do? Or, rather, I'd like to find out how to >create a new process executing concurrently with my original process from >either a procedure or a compiled (and linked :-) ) file.... the above two >do NOT work. The first one does NOT make an error, yet no second process >is started. The second one gurus the system with error 4 (address?) Its been a while since I've worked with these calls, so these answers may be a bit off. LoadSeg() takes a file name and returns a BPTR to a seg list: BPTR LoadSeg( UBYTE *name ); CreateProc() takes the BPTR returned by LoadSeg(), or any other BPTR to a seg list: struct MsgPort *CreateProc( UBYTE *name, long pri, BPTR segList, long stackSize ); Note that CreateProc() does not return a pointer to the process structure, it returns a pointer to the message port in the process structure. Remember that, in general, code started from disk is compiled with standard startups. When you use LoadSeg(), the code thinks its started from workbench, so you have to send the process a startup message, and hang around for the reply and unload the code when done... The code in the first example is waiting for something to send it a WBStartup message. The second case is incorrect. LoadSeg() needs a BPTR to a seg list, which can be faked like: /* From Mike Sinz AmigaMail example */ struct CodeHdr { ULONG SegSize; /* sizeof(struct CodeHdr) */ ULONG NextSeg; /* Must be NULL */ UWORD JumpInstr; /* set to 0x4EF9 (a jump instruction) */ APTR Function; /* a pointer to the function */ } CreateProc() takes a BPTR to the NextSeg field of this structure. If you are really interested in this, I would recommend purchasing the AmigaMail Volume I notebook from CATS: CATS Orders 1200 Wilson Drive West Chester, PA 19380 (215) 431-9180 The sample code is in the DOS section, it is titled "Creating Multiple Processes With Re-entrant Code." -- -- Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines uucp: ken@cbmvax.commodore.com or ...{uunet,rutgers}!cbmvax!ken bix: kfarinsky