home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d543
/
mousexy.lha
/
MouseXY
/
Includes
/
Detach.i
next >
Wrap
Text File
|
1991-09-20
|
5KB
|
169 lines
*»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
*»» Made for Hisoft Devpac 2.12 by Preben Nielsen
*»»
*»» 09-Aug-91: Made this header
*»»
*»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
*»» A few macros to help detach a program from the CLI (Works from
*»» Workbench as well).
*»»
*»» DetachSingle only works with programs consisting of exactly one
*»» segment.
*»»
*»» DetachMulti works with any number of segments.
*»»
*»» None of the macros currently support passing of arguments from
*»» CLI to the program.
*»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
IFND DETACH_DEFINES
DETACH_DEFINES SET 1
include "exec/exec_lib.i"
include "exec/memory.i"
include "libraries/dos_lib.i"
include "libraries/dosextens.i"
DetachSingle MACRO ; DetachSingle <'process name'>,stacksize,processpri
SECTION SingleSplit,CODE
DetachStart move.l 4.W,A6
suba.l A1,A1
jsr _LVOFindTask(A6) ; Find us
move.l D0,A2
tst.l pr_CLI(A2)
bne.S 1$
move.l DetachStart-4(PC),A2
adda.l A2,A2
adda.l A2,A2
jmp 4(A2) ; from WorkBench
1$ moveq #RETURN_FAIL,D7
jsr _LVOForbid(A6) ; From CLI
lea DoSnAme(PC),A1
jsr _LVOOldOpenLibrary(A6)
move.l D0,D5
beq.S 4$
moveq #ML_SIZE+1*ME_SIZE,D0
move.l #MEMF_PUBLIC|MEMF_CLEAR,D1
jsr _LVOAllocMem(A6) ; Allocate Memlist
move.l D0,A2
tst.l D0
beq.S 3$
lea ProcessName(PC),A0
move.l A0,D1
moveq #\3,D2 ; Priority
move.l DetachStart-4(PC),D3
move.l #\2,D4 ; StackSize
move.l D5,A6
jsr _LVOCreateProc(A6)
move.l 4.W,A6
tst.l D0
beq.S 2$
move.l D0,A0
lea -pr_MsgPort(A0),A0 ; Now we have process
not.l pr_CLI(A0) ; All MY programs will now think they were started from the CLI
lsl.l #2,D3
subq.l #4,D3
move.l D3,A1
move.w #1,ML_NUMENTRIES(A2) ; MemList -> ml_NumEntries = 1
move.l A1,ML_ME+ME_ADDR(A2) ; MemList -> ml_me[0].me_Addr = Segment
move.l (A1),ML_ME+ME_LENGTH(A2); MemList -> ml_me[0].me_Length = Length
lea TC_MEMENTRY(A0),A0
move.l A2,A1
jsr _LVOAddTail(A6) ; AddTail(&Process->pr_Task.tc_MemEntry,&MemList->ml_Node);
lea DetachStart-4(PC),A0
clr.l (A0) ; Split the segments
moveq #RETURN_OK,D7
bra.S 3$
2$ move.l A2,A1 ; CreateProc failed. Can't do anything then
moveq #ML_SIZE+1*ME_SIZE,D0
jsr _LVOFreeMem(A6)
3$ move.l D5,A1
jsr _LVOCloseLibrary(A6)
4$ jsr _LVOPermit(A6)
move.l D7,D0 ; Set return code
rts
DoSnAme dc.b 'dos.library',0
ProcessName dc.b \1,0 ; CreateProc makes a copy of this name
SECTION ProcessCode,CODE
ENDM
DetachMulti MACRO ; DetachMulti <'process name'>,stacksize,processpri
SECTION MultiSplit,CODE
DetachStart move.l 4.W,A6
suba.l A1,A1
jsr _LVOFindTask(A6) ; Find us
move.l D0,A2
tst.l pr_CLI(A2)
bne.S 1$
move.l DetachStart-4(PC),A2
adda.l A2,A2
adda.l A2,A2
jmp 4(A2) ; from WorkBench
1$ moveq #RETURN_FAIL,D7
link A4,#-100
jsr _LVOForbid(A6) ; From CLI
lea DoSnAme(PC),A1
jsr _LVOOldOpenLibrary(A6)
move.l D0,D5
beq 7$
move.l DetachStart-4(PC),A1
move.l A1,D3
moveq #0,D6 ; Number of segments
moveq #ML_SIZE,D7 ; Size of memory to allocate
move.l SP,A0
2$ move.l A1,D0 ; Count segments and make MemEntries on the stack
beq.S 3$
adda.l A1,A1
adda.l A1,A1
subq.l #4,A1
move.l A1,(A0)+ ; MemList -> ml_me[0].me_Addr = Segment
move.l (A1),(A0)+ ; MemList -> ml_me[0].me_Length = Length
move.l 4(A1),A1
addq.w #1,D6
addq.w #ME_SIZE,D7
bra.S 2$
3$ move.l D7,D0
move.l #MEMF_PUBLIC|MEMF_CLEAR,D1
jsr _LVOAllocMem(A6) ; Allocate Memlist
move.l D0,A2
tst.l D0
beq.S 6$
move.w D6,ML_NUMENTRIES(A2) ; MemList -> ml_NumEntries = number of segments
move.l SP,A0
lea ML_ME(A2),A1
move.l D7,D0
sub.w #ML_SIZE+1,D0
4$ move.b (A0)+,(A1)+
dbf D0,4$
move.l #ProcessName,D1
moveq #\3,D2 ; Priority
move.l #\2,D4 ; Stacksize
move.l D5,A6
jsr _LVOCreateProc(A6)
move.l 4.W,A6
move.l D0,A0
tst.l D0
beq.S 5$
lea -pr_MsgPort(A0),A0 ; Now we have process
not.l pr_CLI(A0) ; All MY programs will now think they were started from the CLI
lea TC_MEMENTRY(A0),A0
move.l A2,A1
jsr _LVOAddTail(A6) ; AddTail(&Process->pr_Task.tc_MemEntry,&MemList->ml_Node);
lea DetachStart-4(PC),A1
clr.l (A1) ; Split the segments
moveq #RETURN_OK,D7
bra.S 6$
5$ move.l A2,A1 ; CreateProc failed. Can't do anything then
move.l D7,D0
jsr _LVOFreeMem(A6)
6$ move.l D5,A1
jsr _LVOCloseLibrary(A6)
7$ jsr _LVOPermit(A6)
unlk A4
move.l D7,D0 ; Set return code
rts
DoSnAme dc.b 'dos.library',0
ProcessName dc.b \1,0 ; CreateProc makes a copy of this name
SECTION ProcessCode,CODE
ENDM
ENDC