home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / source / cback.a < prev    next >
Encoding:
Text File  |  1996-12-24  |  24.9 KB  |  751 lines

  1. *
  2. * C initial startup procedure under AmigaDOS
  3.  
  4.         INCLUDE        "exec/types.i"
  5.         INCLUDE        "exec/alerts.i"
  6.         INCLUDE        "exec/nodes.i"
  7.         INCLUDE        "exec/lists.i"
  8.         INCLUDE        "exec/ports.i"
  9.         INCLUDE        "exec/libraries.i"
  10.         INCLUDE        "exec/tasks.i"
  11.         INCLUDE        "exec/memory.i"
  12.         INCLUDE        "exec/execbase.i"
  13.         INCLUDE        "libraries/dos.i"
  14.         INCLUDE        "libraries/dosextens.i"
  15.         INCLUDE        "workbench/startup.i"
  16.         INCLUDE        "exec/funcdef.i"
  17.         INCLUDE        "exec/exec_lib.i"
  18.         INCLUDE        "libraries/dos_lib.i"
  19.  
  20. MEMFLAGS    EQU        MEMF_CLEAR+MEMF_PUBLIC
  21. AbsExecBase EQU 4
  22.  
  23. TINY    EQU     0
  24. callsys macro
  25.         CALLLIB _LVO\1
  26.         endm
  27.         
  28.         xdef        __startup
  29.         xdef        _XCEXIT               ; exit(code) is standard way to leave C.
  30.         xdef         @_XCEXIT
  31.         
  32.         xref        LinkerDB              ; linker defined base value
  33.         xref        _BSSBAS               ; linker defined base of BSS
  34.         xref        _BSSLEN               ; linker defined length of BSS
  35.  
  36.         xref        __main                ; Name of C program to start with.
  37.         xref        __fpinit              * initialize floating point
  38.         xref        __fpterm              * terminate floating point
  39.  
  40. *        library references
  41.  
  42.         csect       _NOMERGE,0,0,0,4
  43.         xref        __savecli
  44.         xref        __freecli
  45.         xref        FindTask
  46.  
  47. __startup:
  48. start:
  49.         movem.l d1-d6/a0-a6,-(a7)
  50. REGSIZE EQU     (6+7)*4
  51.         lea     REGSIZE(a7),A5         * determine old stack pointer
  52.         move.l  a0,a2                  * save command pointer
  53.         move.l  d0,d2                  * and command length
  54.         lea     LinkerDB,a4            * load base register
  55.  
  56.         move.l  AbsExecBase.W,a6
  57.         move.l  a6,SysBase(A4)
  58.  
  59. *------        Clear out our BSS section
  60.         lea     _BSSBAS,a3             * get base of BSS
  61.         moveq   #0,d1
  62.         move.l  #_BSSLEN,d0            * get length of BSS in longwords
  63.         bra.s   clr_lp                 * and clear for length given
  64. clr_bss move.l  d1,(a3)+
  65. clr_lp  dbf     d0,clr_bss
  66.         move.l  a7,_StackPtr(A4)       * Save stack ptr
  67.  
  68. *------ get the address of our task
  69.         move.l        ThisTask(a6),A3
  70.  
  71. *-----  clear any pending signals
  72.         moveq        #0,d0
  73.         move.l       #$00003000,d1
  74.         callsys      SetSignal
  75.  
  76. *------ are we running as a son of Workbench?
  77.         move.l       pr_CurrentDir(A3),__curdir(A4)
  78.         tst.l        pr_CLI(A3)
  79.         beq          fromWorkbench
  80.  
  81. *=======================================================================
  82. *====== CLI Startup Code ===============================================
  83. *=======================================================================
  84.  
  85. fromCLI:
  86. *------        attempt to open DOS library:
  87.         bsr.w        openDOS
  88.  
  89. *------ Duplicate the current directory for the called process
  90.         move.l        __curdir(A4),D1
  91.         move.l        DOSBase(A4),A6
  92.         callsys       DupLock
  93.         move.l        D0,__curdir(A4)
  94.  
  95. *------ Save the current CLI info including path for child to use
  96.         pea            cli
  97.         jsr            __savecli(pc)   
  98.         addq.l         #4,a7
  99.  
  100. *------ find command name:
  101.         move.l        pr_CLI(A3),a0
  102.         add.l         a0,a0                        ; bcpl pointer conversion
  103.         add.l         a0,a0
  104.         move.l        cli_CommandName(a0),a1
  105.         add.l         a1,a1                        ; bcpl pointer conversion
  106.         add.l         a1,a1
  107.  
  108. *------        collect parameters:
  109.         move.l        d2,d0                        ; get command line length
  110.         moveq.l       #0,d1
  111.         move.b        (a1)+,d1
  112.         move.l        A1,D4                        ;save our pointer
  113.         move.l        d1,d3
  114.         add.l         d1,d1                        ; double length since we copy it twice
  115.         add.l         d1,d0                        ; add length of command name
  116.         addq.l        #5,d0                        ; allow for space after command        
  117.         addq.l        #4,d0                        ; As well as for the roundup
  118. *                          ; changed from 5 to 9 for quotes
  119. *                                         
  120. *------        We have the length of the command string to be copied.
  121. *------        Allocate space for it.
  122. *------        Round up to the nearest 4 bytes
  123.         lsl.l         #2,d0
  124.         add.l         memsize(A4),d0
  125.         move.l        d0,memsize(A4)
  126.  
  127. ************************************************************************
  128. ************************************************************************
  129. ******** Allocate and copy over the code to do the magic stuff *********
  130. ************************************************************************
  131. ************************************************************************
  132.  
  133.         lea           memlist(A4),A0
  134.         move.l        AbsExecBase.W,a6
  135.         callsys       AllocEntry                ;get a place to put the code
  136. *        btst.l        #31,d0                     ;did we get the memory we asked for?
  137. *        beq           cliexit                    ;no, can't do anything then
  138.         move.l        D0,A1
  139.         move.l        D0,-(A7)                  ;remember the chunk we allocated
  140.  
  141. *------ Now we copy the code over
  142.         movea.l       ML_SIZE+ME_ADDR(A1),A1   ;locate our allocated block
  143.  
  144. *------        Copy over the command line to the allocated area
  145.         lea           commandbuf-copybeg(A1),A3
  146.  
  147. *------        At this point, we have:
  148. *                A0 - Work pointer
  149. *                A1 - Pointer to Allocated memory block
  150. *                A2 - Pointer to program name
  151. *                A3 - Pointer to target buffer
  152. *                A3 - Pointer to our process structure
  153. *                D0 - Work register
  154. *                D1 - Work register
  155. *                D2 - length of command name
  156. *                D3 - length of program name
  157. *                D4 - Pointer to program name
  158.  
  159.         move.l        d2,argslen                 ; save length of args
  160.         move.l        d3,proglen                 ; save length of prog
  161.         
  162.         movea.l       D4,A0                      ; Load program name
  163.         move.l        D3,D0                      ;      and length
  164.         move.b        #'"',(a3)+
  165.         bra.s         cpy1
  166. cpycmd: move.b        (A0)+,(A3)+                ; copy over the command name
  167. cpy1:   dbf           d0,cpycmd
  168.         move.b        #'"',(a3)+
  169.         move.b        #' ',(A3)+                 ; add the space delimiter
  170.  
  171.         move.l        A2,A0                      ; Load command text
  172.         move.l        D2,D0                      ;      and length
  173.         bra.s         cpy2
  174. cpylin: move.b        (A0)+,(A3)+
  175. cpy2:   dbf           d0,cpylin
  176.         clr.b         (A3)+
  177.  
  178. *------        Now copy over the program name
  179.         move.l        A3,_ProgramName(A4)
  180.         move.l        D4,A0
  181.         move.l        D3,D0
  182.         bra.s         cpy3
  183. cpypgm: move.b        (A0)+,(A3)+
  184. cpy3:   dbf           D0,cpypgm
  185.         clr.b         (A3)                        ;don't forget trailing null on name
  186.  
  187. *------ First we want to put it into our seglist
  188.         lea           segexit-copybeg(A1),A2
  189.         move.l        A2,_XCEXIT+2(A4)            ;patch the jump instruction
  190.         lea           start-4(PC),A2
  191.    
  192. *        Now we have:    A1 to our new fake segment
  193. *                        A2 to the start of the real seglist
  194.         move.l        #(copyend-copybeg)/4,(A1)+
  195.         move.l        A1,D3
  196.         lsr.l         #2,D3                        ;convert it to a bptr to the list
  197.         move.l        (A2),(A1)+                   ;save our next segment pointer
  198.         clr.l         (A2)                         ;and kill it from the chain
  199. *------ We have the seglist
  200.  
  201.         lea           AutoLoader(PC),A2
  202.         move.l        #(copyend-AutoLoader)-1,D0
  203. copyit  move.b        (A2)+,(A1)+
  204.         dbf           d0,copyit
  205.  
  206. *------        See if they want to do some I/O
  207.         tst.l        _BackGroundIO(A4)
  208.         beq          noio
  209.         lea          current_window(A4),A0
  210.         move.l       A0,D1
  211.         move.l       #1005,D2
  212.         move.l       DOSBase(A4),A6
  213.         callsys      Open
  214.         move.l       d0,_Backstdout(A4)
  215. noio:
  216.  
  217. *------ If under 2.0 Flush cache and get ProgramDir
  218.    
  219.         moveq        #36,d0
  220.         cmp.w        $14(a6),d0
  221.         bgt.b        nov36
  222.         
  223.         move.l       DOSBase(A4),A6
  224.         jsr          -$258(a6)                  ;GetProgramDir
  225.         move.l       d0,d1
  226.         callsys       DupLock
  227.         move.l       d0,ProgramDir(a4)
  228.  
  229.         move.l       AbsExecBase.w,A6
  230.         moveq        #-1,d0
  231.         callsys      CacheClearU
  232.  
  233. nov36:
  234.         
  235.         move.l       AbsExecBase.w,A6
  236.  
  237.         callsys        Forbid
  238.  
  239. *------ Attach the task to do the dirty work
  240.         move.l        __procname(A4),D1        ; Name of task to start
  241.         move.l        __priority(A4),D2        ; Priority of background task
  242.         move.l        __stack(A4),D4           ; Stack size of created task
  243.  
  244.         move.l        DOSBase(A4),A6
  245.         callsys       CreateProc
  246.         move.l        A6,A3                    ; restore dosbase to close it
  247.         tst.l         D0
  248.         bne           ok
  249.  
  250. *------ Serious problems.  For some reason the CreateProc failed.
  251. *------ We need to free the AlocEntry memory and go home
  252.         move.l        (A7)+,A2
  253.         movea.l       ML_SIZE+ME_ADDR(A2),A1   ;locate our allocated block
  254. *------ Also must get rid of current directory
  255.         move.l        __curdir(A4),D1
  256.         callsys       UnLock
  257.  
  258.         move.l        A2,A0
  259.         move.l        AbsExecBase.w,A6
  260.         callsys       FreeEntry
  261.         move.l        #104,D0
  262.         bra           cliexit
  263.  
  264. ok:
  265. *------ The task started ok, attach the memory we allocated to
  266. *------        its task control block
  267.         move.l        D0,A2
  268.  
  269.         move.l        (a7)+,A1                ;locate the memory we allocated
  270.         lea           -pr_MsgPort(A2),A2
  271.         lea           TC_MEMENTRY(A2),A0
  272.  
  273.  
  274. *        ADDTAIL
  275.         LEA           LH_TAIL(A0),A0
  276.         MOVE.L        LN_PRED(A0),D0
  277.         MOVE.L        A1,LN_PRED(A0)
  278.         MOVE.L        A0,(A1)
  279.         MOVE.L        D0,LN_PRED(A1)
  280.         MOVE.L        D0,A0
  281.         MOVE.L        A1,(A0)
  282.  
  283.         move.l        #0,D0
  284.  
  285. cliexit:
  286.         move.l        AbsExecBase.w,A6
  287.         callsys       Permit
  288.         move.l        A3,A1
  289.         move.l        AbsExecBase.w,A6
  290.         callsys       CloseLibrary
  291.         movem.l       (a7)+,d1-d6/a0-a6
  292.         rts
  293.  
  294. *=======================================================================
  295. *====== Workbench Startup Code =========================================
  296. *=======================================================================
  297.  
  298. fromWorkbench:
  299.         move.l        a7,d0                         
  300.         sub.l         TC_SPLOWER(a3),d0
  301.  
  302. *------ Set __base for stack checking
  303.         move.l       a7,d1
  304.         sub.l        d0,d1               * get top of stack
  305.         add.l        #128,D1             * allow for parms overflow
  306.         move.l       D1,__base(A4)       * save for stack checking
  307.         
  308.         cmp.l         __stack(a4),d0
  309.         bcc.s        nochange        
  310.  
  311. *-- current stack is not as big as __stack says it needs
  312. *-- to be. Allocate a new one.
  313.         move.l        __stack(a4),d0
  314.         add.l         #128,d0           * extra room
  315.         move.l        d0,newstacksize(a4)
  316.  
  317.         move.l        #MEMFLAGS,d1
  318.         callsys       AllocMem
  319.         tst.l         d0
  320.         beq.w         return
  321.         
  322.         move.l        d0,newstack(a4)
  323.         add.l         #128,d0           * extra room
  324.         move.l        d0,__base(a4)
  325.         
  326.         add.l         __stack(a4),d0
  327.         move.l        d0,d1
  328.         
  329. *-- If we're running under 2.0, call StackSwap to set up
  330. *-- the new stack. Otherwise, just jam the new value into
  331. *-- A7.        
  332.         cmpi.w        #36,$14(a6)
  333.         blt.s         no20
  334.  
  335.         move.l        d0,mystk_Pointer(a4)
  336.         move.l        d1,mystk_Upper(a4)
  337.         sub.l         newstacksize(a4),d1
  338.         lea           mystk_Lower(a4),a0
  339.         move.l        d1,(a0)
  340.         callsys       StackSwap
  341.         bra.s         nochange
  342.            
  343. no20:   move.l        d0,a7
  344.                 
  345. nochange:
  346.  
  347. *------ Save the current stack. We'll reset it to here to
  348. *------ Run the autoterminators.
  349.         move.l        a7,newst_Pointer(a4)
  350.         move.l        a7,newst_Upper(a4)
  351.         lea           newst_Lower(a4),a0
  352.         move.l        __base(a4),(a0)
  353.         cmpi.w        #36,$14(a6)
  354.         blt.s         no20b
  355.         callsys       StackSwap
  356.         
  357. no20b:
  358.  
  359.  
  360. *------ open the DOS library:
  361.         bsr.w         openDOS
  362.  
  363.         
  364. *------ we are now set up.  wait for a message from our starter
  365.         bsr.w         waitmsg
  366.         move.l        d0,_WBenchMsg(A4)
  367.         move.l        d0,-(SP)
  368. *
  369.         move.l        d0,a2                            ; get first argument
  370.         move.l        sm_ArgList(a2),d0
  371.         beq.s         do_cons
  372.         move.l        DOSBase(A4),a6
  373.         move.l        d0,a0
  374.         move.l        wa_Lock(a0),d1
  375.         callsys       DupLock
  376.         move.l        d0,__curdir(A4)
  377.         move.l        d0,d1
  378.         callsys       CurrentDir
  379. do_cons:
  380.         move.l        sm_ToolWindow(a2),d1             ; get the window argument
  381.         beq.s         do_main
  382.         move.l        #MODE_OLDFILE,d2
  383.         callsys       Open
  384.         move.l        d0,stdin(A4)
  385.         beq.s         do_main
  386.         lsl.l         #2,d0
  387.         move.l        d0,a0
  388.         move.l        fh_Type(a0),pr_ConsoleTask(A3)
  389. do_main:
  390.         move.l        _WBenchMsg(A4),a0                ; get address of workbench message
  391.         move.l        a0,-(a7)                         ; push argv
  392.         pea           NULL(A4)                         ; push argc
  393.         move.l        sm_ArgList(a0),a0                ; get address of arguments
  394.         move.l        wa_Name(a0),_ProgramName(A4)     ; get name of program
  395.  
  396.         lea           xcexit(PC),A2
  397.         move.l        A2,_XCEXIT+2(A4)                 ;patch the jump instruction
  398.  
  399.         moveq         #36,d0
  400.         cmp.w         $14(a6),d0
  401.         bgt.b         nov36b
  402.         
  403.         move.l        AbsExecBase.w,A6
  404.         moveq         #-1,d0
  405.         callsys       CacheClearU
  406. nov36b:
  407.  
  408. *------ For startup from workbench, there is no reason to go through
  409. *------ The fancy stuff to make the startup work.  Just run the
  410. *------ Code directly
  411.         jsr           __fpinit(PC)
  412.         tst.l         d0
  413.         bne.w         exit2
  414.         jsr           __main
  415.         moveq.l       #0,d0
  416.         bra.w         exit2
  417.         
  418.  
  419. ************************************************************************
  420. ************************************************************************
  421. *************                                              *************
  422. ************* Start of code that is copied to fake segment *************
  423. *************                                              *************
  424. ************************************************************************
  425. ************************************************************************
  426.  
  427. copybeg:
  428.         DC.L        (copyend-copybeg)/4
  429. next:   DC.L        0
  430. AutoLoader:
  431.         move.l        a7,d0
  432.         movem.l       d1-d6/a0-a6,-(a7)
  433.         move.l        d0,a5
  434.         move.l        AbsExecBase.w,a6
  435.         lea           LinkerDB,A4                ; load base register
  436.         move.l        a7,_StackPtr(A4)
  437.  
  438.         bsr.w         openDOS
  439.         suba.l        a1,a1
  440.  
  441.         suba.l        a1,a1
  442.         callsys       FindTask
  443.         move.l        d0,A3
  444.  
  445.         move.l        TC_SPLOWER(A3),__base(A4)        ; set base of stack
  446.         add.l         #128,__base(A4)          ;allow for parms overflow
  447.  
  448.         move.l        pr_SegList(A3),a0        ;locate the segment list
  449.         add.l         A0,A0
  450.         add.l         A0,A0                    ;and convert to an APTR
  451.         move.l        12(A0),A1                ;so we can access the segments
  452.         add.l         A1,A1
  453.         add.l         A1,A1
  454.  
  455.         move.l        (A1),seglist(A4)        ;save the remainder for later
  456.         move.l        (A1),12(A0)             ;cut off our segment
  457.  
  458.         move.l        __curdir(A4),D1
  459.         move.l        DOSBase(A4),a6
  460.         callsys       CurrentDir
  461.  
  462.         move.l        ProgramDir(a4),d1
  463.         beq.s         noprogramdir
  464.         jsr           -$252(a6)                ;SetProgramDir
  465.  
  466. noprogramdir:
  467.  
  468. *------ Open Nil: and set up it's input buffer so 
  469. *------ ReadArgs will work.
  470.         lea           nil(pc),a0
  471.         move.l        a0,d1
  472.         move.l        #MODE_OLDFILE,d2
  473.         callsys       Open
  474.         move.l        d0,pr_CIS(a3)
  475.         add.l         d0,d0
  476.         add.l         d0,d0
  477.         move.l        d0,a2
  478.         move.l        argslen(pc),d2
  479.         move.l        d2,fh_End(a2)
  480.         move.l        #0,fh_Pos(a2)        
  481.         
  482.         move.l        AbsExecBase.w,a6
  483.         move.l        d2,d0
  484.         moveq.l       #0,d1
  485.         callsys       AllocMem
  486.         tst.l         d0
  487.         beq.b         segexit
  488.  
  489.         move.l        d0,a0
  490.         lea           commandbuf(pc),a1
  491.         adda.l        proglen(pc),a1
  492.         addq.l        #3,a1               * 3 - is for quotes and trailing space
  493.         subq.l        #1,d2
  494.         blt.b         donecpy
  495. cpy:
  496.         move.b        (a1)+,(a0)+
  497.         dbf           d2,cpy        
  498.             
  499. donecpy:
  500.         lsr.l         #2,d0
  501.         move.l        d0,fh_Buf(a2)
  502.         
  503. *------ Use the cli that our creator set up for us.
  504.         move.l        cli(pc),pr_CLI(a3)
  505.  
  506.         jsr           __fpinit
  507.         tst.l         d0
  508.         bne.s         segexit
  509.         pea           commandbuf(PC)
  510.         jsr           __main                        ; call C entrypoint
  511.         addq          #4,A7
  512.  
  513.  
  514. *------ Unlock the directory we set up for them
  515. segexit:
  516.         move.l        DOSBase(A4),a6
  517.         move.l        __curdir(A4),D1
  518.         callsys       UnLock
  519.  
  520.         moveq.l       #0,d0                        ; set successful status
  521. xcexit:
  522. exit2:
  523.  
  524.         tst.l         _WBenchMsg(A4)
  525.         beq.s         swapdone
  526.         
  527. *-- Set the stack to the first NEW stack we allocated
  528. *-- So C++ destructors can run with a large stack if required
  529.         move.l        newst_Lower(a4),__base(a4)        
  530.         move.l        AbsExecBase.W,A6
  531.         cmpi.w        #36,$14(a6)
  532.         blt.s         noswap1
  533.         lea           newst_Lower(a4),a0
  534.         callsys       StackSwap
  535.         bra.b         swapdone
  536. noswap1:
  537.         move.l        newst_Pointer(a4),a7
  538. swapdone:
  539.         move.l        _ONEXIT(A4),d0         ; exit trap function?
  540.         beq.s         exit3
  541.         move.l        d0,a0
  542.         jsr           (a0)
  543.  
  544. exit3:
  545.  
  546. *------ These must not be PC relative calls since this code is copied
  547.         jsr           __fpterm
  548.  
  549. done_1c:
  550.  
  551. *-- Swap back to original stack
  552. *-- If we're running under 2.0, call StackSwap
  553. *-- Otherwise, just jam the new value into a7
  554.         move.l        AbsExecBase.W,A6
  555.         cmpi.w        #36,$14(a6)
  556.         blt.s         noswap
  557.         tst.l         mystk_Lower(a4)
  558.         beq.s         noswap
  559.  
  560.         lea           mystk_Lower(a4),a0
  561.         subq.l        #4,mystk_Pointer(a4)      * make room for the ret code  
  562.         callsys       StackSwap
  563.            
  564. noswap:  
  565.  
  566.         move.l        _StackPtr(a4),a7          * restore stack ptr
  567.  
  568.  
  569. *------ if we ran from CLI, skip workbench cleanup:
  570.         tst.l         _WBenchMsg(A4)
  571.         beq.s         exitToDOS
  572.         move.l        newstacksize(a4),d0
  573.         beq.s         exit4
  574.         move.l        newstack(a4),a1
  575.         move.l        AbsExecBase.W,A6
  576.         callsys       FreeMem
  577. exit4:
  578.         move.l        DOSBase(A4),a6
  579.         move.l        stdin(A4),d1
  580.         beq.s         done_4
  581.         callsys       Close
  582.  
  583. done_4:
  584.         tst.l         ProgramDir(a4)
  585.         beq.s         noprogdir
  586.         moveq.l       #0,d1
  587.         jsr           -$252(a6)                ;SetProgramDir
  588.         move.l        ProgramDir(a4),d1
  589.         callsys       UnLock
  590.  
  591.  
  592. noprogdir:
  593.  
  594. *------ return the startup message to our parent
  595. *        we forbid so workbench can't UnLoadSeg() us
  596. *        before we are done:
  597.         move.l        __curdir(a4),d1
  598.         beq.s         done_5
  599.         callsys       UnLock
  600.  
  601. done_5:
  602.         move.l        AbsExecBase.w,A6
  603.         callsys       Forbid
  604.         move.l        _WBenchMsg(A4),a1
  605.         callsys       ReplyMsg
  606.         move.l        DOSBase(a4),a1
  607.         bra.b         noCIS
  608.  
  609. *------ this rts sends us back to DOS:
  610. exitToDOS:
  611.         jsr           __freecli
  612.         
  613.         move.l        AbsExecBase.W,a6
  614.         sub.l         a1,a1
  615.         callsys       FindTask
  616.         move.l        d0,a0
  617.         
  618.         move.l        pr_CIS(a0),d1      * test for our input file handle
  619.         beq.b         noCIS
  620.  
  621.         clr.l         pr_CIS(a0)
  622.         move.l        d1,d2
  623.         add.l         d1,d1
  624.         add.l         d1,d1
  625.         move.l        d1,a2
  626.         
  627. *------ First free the buffer we allocated
  628.         move.l        fh_Buf(a2),d1
  629.         add.l         d1,d1
  630.         add.l         d1,d1
  631.         move.l        d1,a1
  632.         move.l        argslen(pc),d0
  633.         callsys       FreeMem
  634.  
  635. *------ Restore fields to 0 
  636.         clr.l         fh_Buf(a2)
  637.         clr.l         fh_End(a2)
  638.  
  639. *------ Close Nil:        
  640.         move.l        d2,d1
  641.         move.l        DOSBase(A4),a6
  642.         callsys       Close
  643.  
  644. *------ They are done so unload them
  645.         move.l        seglist(A4),D1
  646.         move.l        DOSBase(A4),a6
  647.         callsys       UnLoadSeg
  648.  
  649.         move.l        a6,a1
  650.  
  651. noCIS:
  652.         move.l        AbsExecBase.w,a6
  653.         callsys       CloseLibrary                ; close Dos library
  654.  
  655. return:
  656.         movem.l       (a7)+,d1-d6/a0-a6
  657.         rts
  658.  
  659. *-----------------------------------------------------------------------
  660. *  Open the DOS library:
  661.  
  662. openDOS
  663.                 lea          DOSName(A4),A1
  664.                 moveq.l      #0,D0
  665.                 callsys      OpenLibrary
  666.                 move.l       D0,DOSBase(A4)
  667.                 beq          noDOS
  668.                 rts
  669. *-----------------------------------------------------------------------
  670. noDOS:
  671.                 moveq.l      #100,d0
  672.                 bra          exit2
  673.  
  674. cli:            dc.l         0
  675. argslen:        dc.l         0
  676. proglen:        dc.l         0
  677. nil:            dc.b         'NIL:',0,0
  678.                 
  679. copyend:
  680. commandbuf:
  681.  
  682. ************************************************************************
  683. ************************************************************************
  684. **************                                            **************
  685. ************** End of code that is copied to fake segment **************
  686. **************                                            **************
  687. ************************************************************************
  688. ************************************************************************
  689.  
  690. *-----------------------------------------------------------------------
  691. * This routine gets the message that workbench will send to us
  692. * called with task id in A3
  693.  
  694. waitmsg:
  695.                 lea        pr_MsgPort(A3),a0          ; our process base
  696.                 callsys    WaitPort
  697.                 lea        pr_MsgPort(A3),a0          ; our process base
  698.                 callsys    GetMsg
  699.                 rts
  700.  
  701.         csect        __MERGED,1,0,0,4
  702.  
  703. *------        These externals control the task that is started
  704.         xref        _BackGroundIO                ; flag to indicate background task
  705. *                                                ; wants to do I/O
  706.         xref        __stack                      ; stack space for created task
  707.         xref        __procname                   ; name of process to be created
  708.         xref        __priority                   ; priority to create process at
  709.  
  710.         xref        MathBase
  711.         xref        MathTransBase
  712. *
  713.         xdef        NULL,SysBase,DOSBase,_Backstdout
  714.  
  715.     xref        _FPERR
  716.         xref        _WBenchMsg
  717.         xref        __curdir
  718.         xref        _OSERR,_SIGFPE,_ONERR,_ONEXIT,_ONBREAK
  719.         xref        _SIGINT
  720.         xref        _ProgramName,_StackPtr,__base
  721. *
  722. memlist        ds.b        LN_SIZE
  723.                dc.w        1
  724.                dc.l        MEMF_PUBLIC
  725. memsize        dc.l        copyend-copybeg
  726.  
  727. _XCEXIT      
  728. @_XCEXIT       dc.w        $4ef9
  729.                dc.l        0
  730. seglist        dc.l        0
  731. NULL           dc.l        0                ;
  732. DOSBase        dc.l        0
  733. SysBase        dc.l        0
  734. dosCmdLen      dc.l        0
  735. dosCmdBuf      dc.l        0
  736. stdin          dc.l        0
  737. _Backstdout    dc.l        0                ;filehandle for I/O
  738. ProgramDir     dc.l        0
  739. DOSName        dc.b        'dos.library',0
  740. current_window dc.b        '*',0
  741. mystk_Lower    dc.l        0
  742. mystk_Upper    dc.l        0
  743. mystk_Pointer  dc.l        0
  744. newst_Lower    dc.l        0
  745. newst_Upper    dc.l        0
  746. newst_Pointer  dc.l        0
  747. newstack       dc.l        0                   * pointer to new stack (if needed)
  748. newstacksize   dc.l        0                   * size of new stack
  749.                END
  750.