I'm trying to understand Pexec function and I need your help, because it seems the documentation isn't clear to me: https://toshyp.atari.org/en/00500b.html#Pexec
I have a simple application, just Mshrink/Cconws/Cconin/Pterm and it works fine.
Now I'm trying to run it with two methods:
1) Pexec(0)
2) Pexec(3) and then Pexec(4)
In both cases my application crashes. Sometimes it shows the message ("Cconws") sometimes it doesn't, but it never returns back to the desktop, just silently hangs or displays an error message (bombs on the TOS or "Panic" under EmuTOS)
I run it from a floppy (to avoid pexec emulation) under Steem SSE / Hatari with the OS: TOS 1.04 / EmuTOS 1.0 / EmuTOS 1.3
My guess there is something wrong with Environment or CommandLine:
Pexec(0):
Code: Select all
; Process load & execute
pea Environment(pc)
pea CommandLine(pc)
pea FileName(pc)
clr.w -(a7) ; Load and go
move.w #$4B,-(a7) ; Pexec
trap #1 ; Gemdos
lea 16(a7),a7
; Process termination
clr.w -(a7) ; Pterm
trap #1 ; Gemdos
SECTION DATA
FileName:
dc.b 'echo.tos',$0
EVEN
Basepage:
dc.l $0
CommandLine:
dc.l $0
Environment:
dc.l $0
Pexec(3) / Pexec(4):
Code: Select all
; Process load & execute
pea Environment(pc)
pea CommandLine(pc)
pea FileName(pc)
move.w #3,-(a7) ; Load, don't go
move.w #$4B,-(a7) ; Pexec
trap #1 ; Gemdos
lea 16(a7),a7
; D0 - child processes' basepage is returned as a LONG
tst.l D0
bmi Pterm ; Exit on error
move.l D0,Basepage
; Process execute
clr.l -(a7)
move.l Basepage,-(a7) ; Basepage
clr.l -(a7)
move.w #4,-(a7) ; Just go
move.w #$4B,-(a7) ; Pexec
trap #1 ; Gemdos
lea 16(a7),a7
; Process termination
Pterm:
clr.w -(a7) ; Pterm
trap #1 ; Gemdos
SECTION DATA
FileName:
dc.b 'echo.tos',$0
EVEN
Basepage:
dc.l $0
CommandLine:
dc.l $0
Environment:
dc.l $0