home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / climax_429.lzh / CLImax / bud.a < prev    next >
Text File  |  1991-01-10  |  5KB  |  212 lines

  1. ; This here code is for a process started up by CLImax which has the job of
  2. ; actually carrying out the creation of the new CLI process and then waiting
  3. ; for it to finish and then closing the screen it used.
  4. ;
  5. ; Written for the Manx assembler, hopefully
  6. ; portable.  Use the -n flag for one-pass assembly.  Link with the +a flag.
  7. ;
  8. ; This code is incorporated into the program CLImax, which then copies it into
  9. ; an allocated block of public memory.  It copies everything found between
  10. ; the two symbols _beginning and _ending.  The new process adds this area of
  11. ; memory into its tc_MemEntry list for automatic cleanup.
  12.  
  13.  
  14.         xdef        _beginning
  15.         xdef        _ending
  16.         xdef        _StuffOffs
  17.         xdef        _CommandOffs
  18.         xdef        _CloseStuff
  19.         xdef        _NameOffs
  20.         xdef        _FakeOffs
  21.  
  22.         nolist
  23.           include     "exec/types.i"      ; nobody pulls this in!
  24.           include     "exec/memory.i"
  25.           include     "exec/tasks.i"
  26.           include     "exec/execbase.i"
  27.           include     "intuition/screens.i"
  28.           include    "libraries/dosextens.i"
  29.           include    "libraries/dos_lib.i"
  30.         list
  31.  
  32.         STRUCTURE    stufff,0
  33.           CPTR        ibase
  34.           CPTR        gbase
  35.           CPTR        dosbase
  36.           CPTR        fawnt
  37.           CPTR        scr
  38.           CPTR        win
  39.           BPTR        wandle
  40.           BPTR        ceedee
  41.         LABEL        stuffsize
  42.  
  43.  
  44. stuf        equr        a5        ; the stuff struct
  45. clap        equr        a4        ; our struct CLI
  46. me        equr        a3        ; FindTask(null)
  47. mist        equr        a2        ; tc_MemEntry addition
  48. pathlist    equr        d7        ; the command path bptr-list
  49.  
  50. memlistsize    equ        ML_SIZE+ME_SIZE        ; size of MemList
  51.                             ;   with one MemEntry
  52. codesize    equ        8+_ending-_beginning    ; size of our "seglist"
  53.  
  54.  
  55. ; I'm getting my _LVO symbol definitions from Manx c.lib; I don't know where
  56. ; you get yours.
  57. ;;;; AAAAAAGH!  As of Aztec 5.0d1, all of a sudden c.lib has INCORRECT VALUES
  58. ;;;; for the _LVO symbols for dos.library!  They're POSITIVE!!  So, we get the
  59. ;;;; correct values from libraries/dos_lib.i and check here:
  60.  
  61. lcall:      macro                ; call whatever library is in a6
  62.         ifd        _LVO\1
  63.         else
  64.           xref        _LVO\1      ; (few dublications)
  65.         endc
  66.         jsr        _LVO\1(a6)
  67.         endm
  68.  
  69.  
  70. xcall:      macro            ; make an exec library call
  71.         move.l         4,a6
  72.         lcall        \1
  73.         endm
  74.  
  75.         cseg
  76.         cnop        0,4    ; USE LN'S +A OPTION to make this work
  77.  
  78.  
  79. ; ============================ The first word copied is also the entry point:
  80.  
  81. _beginning:    lea        stuff(pc),stuf
  82.         sub.l        a1,a1
  83.         xcall        FindTask
  84.         move.l        d0,me
  85.         move.l      #MEMF_PUBLIC|MEMF_CLEAR,d1
  86.         move.l      #memlistsize,d0
  87.         xcall        AllocMem    ; make a MemList with one entry
  88.         move.l      d0,mist
  89.         tst.l        d0
  90.         beq        DOit(pc)    ; low ram? then we'll lose more!
  91.                         ; (this code won't deallocate)
  92.           move.l      #codesize,ML_ME+ME_LENGTH(mist)
  93.           lea        _beginning(pc),a0
  94.           moveq        #8,d0
  95.           sub.l        d0,a0
  96.           move.l      a0,ML_ME+ME_ADDR(mist)
  97.           move.w      #1,ML_NUMENTRIES(mist)  ; the memlist points
  98.           lea        TC_MEMENTRY(me),a0    ;   to our code
  99.           move.l      mist,a1
  100.           lcall        AddTail     ; plug in where RemTask looks.
  101.  
  102. DOit:        move.l        wandle(stuf),d0
  103.         asl.l        #2,d0
  104.         move.l        d0,a0
  105.         move.l        fh_Type(a0),pr_ConsoleTask(me)
  106.         move.l        win(stuf),pr_WindowPtr(me)
  107.         move.l        ceedee(stuf),pr_CurrentDir(me)
  108.         lea        fakli(pc),a0
  109.         move.l        a0,d0
  110.         asr.l        #2,d0
  111.         move.l        d0,pr_CLI(me)
  112.  
  113.         move.l        dosbase(stuf),a6
  114.         moveq        #0,d3
  115.         move.l        wandle(stuf),d2
  116.         lea        command(pc),a0
  117.         move.l        a0,d1
  118.         lcall        Execute                ; TA DA!
  119.  
  120.         move.l        wandle(stuf),d1
  121.         lcall        Close
  122.  
  123.         clr.l        pr_CLI(me)
  124.         lea        fakli(pc),clap
  125.         move.l        pr_CurrentDir(me),d1
  126.         beq        nounlock(pc)
  127.           lcall        UnLock
  128.           clr.l        pr_CurrentDir(me)
  129. nounlock:    move.l        cli_CommandDir(clap),pathlist
  130.         asl.l        #2,pathlist
  131.         beq        die(pc)
  132.  
  133. getapode:      move.l    pathlist,a2
  134.           move.l    (a2),pathlist        ; bptr to next
  135.           move.l    4(a2),d1        ; lock
  136.           beq        nounlick(pc)
  137.             move.l    dosbase(stuf),a6
  138.             lcall    UnLock
  139. nounlick:      move.l    a2,a1
  140.           moveq        #8,d0
  141.           xcall        FreeMem
  142.           asl.l        #2,pathlist
  143.           bne        getapode(pc)
  144.  
  145. die:        move.l        stuf,-(sp)        ; C style parm
  146.         bsr        _CloseStuff
  147.         addq        #4,sp
  148.         moveq        #0,d1
  149.         move.l        dosbase(stuf),a6
  150.         lcall        Exit            ; bye bye
  151.  
  152.  
  153. ; this routine can be called both from the main program and from the bud
  154. ; process.  In the former case the copy of stuff that we need to use is not
  155. ; the one we can find at stuff(pc).  So we pass the stuff pointer as a C arg.
  156.  
  157. _CloseStuff:    move.l        4(sp),stuf
  158.         tst.l        wandle(stuf)
  159.         bne        nocloseW(pc)
  160.           tst.l        win(stuf)
  161.           beq        nocloseW(pc)
  162.             move.l    ibase(stuf),a6
  163.             move.l    win(stuf),a0
  164.             lcall    CloseWindow
  165. ; call CloseWindow only if wandle has NEVER been nonzero
  166.  
  167. nocloseW:    tst.l        scr(stuf)
  168.         beq        nocloseS(pc)
  169.           xcall        Forbid            ; fuck the macro
  170. wait:            move.l    scr(stuf),a0
  171.             tst.l    sc_FirstWindow(a0)
  172.             beq        closeS(pc)
  173.               move.l    dosbase(stuf),a6
  174.               moveq    #50,d1
  175.               lcall    Delay
  176.               bra    wait(pc)
  177. closeS:          move.l    ibase(stuf),a6
  178.           lcall        CloseScreen    ; stuff->scr already in a0
  179.           xcall        Permit
  180.  
  181. nocloseS:    tst.l        fawnt(stuf)
  182.         beq        nocloseF(pc)
  183.           move.l    fawnt(stuf),a1
  184.           move.l    gbase(stuf),a6
  185.           lcall        CloseFont
  186. nocloseF:    move.l      ibase(stuf),a1
  187.         xcall        CloseLibrary
  188.         move.l        gbase(stuf),a1
  189.         lcall        CloseLibrary
  190.         rts
  191.  
  192.  
  193. command:    ds.b        88
  194. _CommandOffs:    dc.w        command-_beginning
  195. stuff:        ds.b        stuffsize
  196. _StuffOffs:    dc.w        stuff-_beginning
  197. procname:    dc.b        "CLImax",0
  198. _NameOffs:    dc.w        procname-_beginning
  199.  
  200.         cnop        0,4
  201. fakli:        ds.b        cli_SIZEOF
  202. prompt:        dc.b        4,"%N> ",0,0,0
  203.         ds.b        56
  204. setname:    dc.b        4,"SYS:",0,0,0
  205.         ds.b        80
  206. _FakeOffs:    dc.w        fakli-_beginning
  207.  
  208.         cnop        0,4
  209. _ending:    dc.l        0        ; safety pad
  210.  
  211.         end
  212.