home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 001-099 / ff050.lzh / Asm / asmfiles / sstartup.s < prev   
Text File  |  1987-01-17  |  3KB  |  183 lines

  1. ;    This is a Public Domain Assembly language startup file
  2. ;    Based on code described in the Amiga ROM Kernel Manuals
  3. ;
  4. ;    This code sets up the necessary items for programs to
  5. ;    run from either CLI or Workbench.
  6. ;
  7. ;    Written By: Douglas J Leavitt
  8. ;    Release:    1.1
  9.  
  10. ;    Internal Macros
  11.  
  12. XLIB    macro
  13.     xref    _LVO\1
  14.     endm
  15.  
  16. LINKLIB    macro
  17.     jsr    _LVO\1(a6)
  18.     endm
  19.  
  20. ;    Externally defined global variables
  21.  
  22.     xref    _AbsExecBase, _Input, _Output
  23.     xref    _main
  24.  
  25. ;    Internal global variables
  26.  
  27.     xdef    _SysBase, _errno
  28.     xdef    _exit
  29.     XLIB    FindTask
  30.  
  31. ;    Internal Defines
  32.     TC_SIZE = 92
  33.     MP_SIZE = 34
  34.     pr_CLI = TC_SIZE+MP_SIZE+46
  35.     cli_CmdName = 4
  36.  
  37. ;    Entry Point is called startup for Backwards compatibility
  38. ;    reasons.
  39.  
  40.     text
  41. startup:
  42.     move.l    sp,startSP        ; Save passed registers
  43.     move.l    d0,CLlen
  44.     move.l    a0,CLbuf
  45.  
  46.     move.l    _AbsExecBase,a6        ; Get the only known ref point
  47.     move.l    a6,_SysBase
  48.  
  49.     sub.l    a1,a1
  50.     LINKLIB    FindTask
  51.     move.l    d0,a4
  52.  
  53.     tst.l    pr_CLI(a4)
  54.     jeq    fromWB
  55.  
  56. ;;;;;;;;;;
  57. ;
  58. ;    Started from CLI
  59. ;
  60. ;;;;;;;;;;
  61.  
  62. fromCLI:
  63.  
  64. ;    Find command line
  65.     move.l    pr_CLI(a4),a0
  66.     add.l    a0,a0            ; Get BCPL pointer ???
  67.     add.l    a0,a0
  68.     move.l    cli_CmdName(a0),a0
  69.     add.l    a0,a0            ; Get BCPL pointer ???
  70.     add.l    a0,a0
  71.  
  72. ;    Fetch and Copy Buffer
  73.     movem.l    d2|a2|a3,-(sp)
  74.     lea    ArgvBuf,a2        ; Char array for command line
  75.     lea    ArgvArray,a3        ; Actual argv array
  76.     moveq    #1,d2
  77.  
  78. ;    Setup Argv[0] (command name)
  79.     moveq    #0,d0
  80.     move.b    (a0)+,d0        ; Get command name size
  81.     move.l    a2,(a3)+        ; Get pointer to command name
  82.     bra.s    av1
  83. av2:
  84.     move.b    (a0)+,(a2)+        ; Copy name
  85. av1:
  86.     dbf    d0,av2
  87.     clr.b    (a2)+
  88.  
  89. ;    Get the remaining parameters
  90.     move.l    CLlen,d0
  91.     move.l    CLbuf,a0
  92. ws1:
  93.     move.b    (a0)+,d1        ; Get next char
  94.     subq.l    #1,d0
  95.     jle    pExit
  96.     cmp.b    #0x20,d0        ; Skip Blanks
  97.     ble.s    ws1
  98.     addq.l    #1,d2            ; Incr argc
  99.     move.l    a2,(a3)+        ; Save next argv
  100.     bra.s    sv1
  101. sv2:
  102.     move.b    (a0)+,d1        ; Get next char
  103.     subq.l    #1,d0
  104.     ble.s    pExit
  105.     cmp.b    #0x20,d0        ; End of Arg?
  106.     ble.s    eParm
  107. sv1:
  108.     move.b    d1,(a2)+        ; Save a char
  109.     bra.s    sv2
  110. eParm:
  111.     clr.b    (a2)+            ; Terminate string
  112.     bra.s    ws1
  113. pExit:
  114.     clr.b    (a2)+
  115.     clr.l    (a3)+
  116.     move.l    d2,d0
  117.     movem.l    (sp)+,d2|a2|a3
  118.  
  119. ;    Prepare stack to Go
  120.     pea    ArgvArray
  121.     move.l    d0,-(sp)
  122.  
  123. ;    GO!!!!
  124.  
  125. go:    jsr    _main
  126.     clr.l    d0
  127.     bra.s    exit2            ; Falling off the end is a exit(0)
  128. _exit:
  129.     move.l    4(sp),d0        ; Get the exit argument
  130. exit2:
  131.     move.l    startSP,sp
  132.     rts
  133.  
  134. ;;;;;;;;;;
  135. ;
  136. ;    Started From WorkBench
  137. ;
  138. ;;;;;;;;;;
  139.  
  140. fromWB:
  141.  
  142. ;    When Starting from WB set argc, and argv to be 0
  143. ;    This is like the lattice compiler (a way to detect where
  144. ;    you came from.
  145.  
  146.     move.l    ArgvArray,a0
  147.     clr.l    (a0)
  148.     move.l    a0,-(sp)
  149.     clr.l    -(sp)
  150.     jra    go
  151.  
  152. ;;;;;;;;;;
  153. ;
  154. ;    DATA section
  155. ;
  156. ;;;;;;;;;;
  157.  
  158.     data
  159.  
  160. _SysBase:
  161.     dc.l    0
  162.  
  163. _errno:
  164.     dc.l    0
  165.  
  166. startSP:
  167.     dc.l    0
  168. CLlen:
  169.     dc.l    0
  170. CLbuf:
  171.     dc.l    0
  172.  
  173. ArgvArray:
  174.     ds.l    64
  175. ArgvBuf:
  176.     ds.b    512
  177.  
  178. DOSName:
  179.     dc.b    'd', 'o', 's', '.'
  180.     dc.b    'l', 'i', 'b', 'r'
  181.     dc.b    'a', 'r', 'y'
  182.     dc.b    0
  183.