home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 003.lha / WBC.a < prev   
Text File  |  1986-05-05  |  5KB  |  209 lines

  1.     section    text,CODE
  2. * C initial startup procedure under AmigaDOS
  3. * Requirements:
  4.  
  5.     INCLUDE    "exec/types.i"
  6.     INCLUDE "exec/alerts.i"
  7.     INCLUDE "exec/nodes.i"
  8.     INCLUDE "exec/lists.i"
  9.     INCLUDE "exec/ports.i"
  10.     INCLUDE "exec/libraries.i"
  11.     INCLUDE "exec/tasks.i"
  12.     INCLUDE "libraries/dos.i"
  13.     INCLUDE "libraries/dosextens.i"
  14.  
  15. ; some usefull macros:
  16. xlib    macro
  17.     xref    _LVO\1
  18.     endm
  19.  
  20. callsys    macro
  21.     CALLLIB    _LVO\1
  22.     endm
  23.     
  24.  
  25.     xdef    _XCEXIT            * exit(code) is standard way to leave C.
  26.     xdef    _HandlerInterface
  27.  
  28.     xref    _myhandler
  29.     xref    __main            * Name of C program to start with.
  30.     xref    _AbsExecBase
  31.     xref    _FindTask
  32.     xref    _DOSBase
  33.  
  34.     xlib    Alert
  35.     xlib    FindTask
  36.     xlib    Forbid
  37.     xlib    GetMsg
  38.     xlib    OpenLibrary
  39.     xlib    CloseLibrary
  40.     xlib    ReplyMsg
  41.     xlib    Wait
  42.     xlib    WaitPort
  43.     xlib    Open
  44.     xlib    Close
  45.     xlib    CurrentDir
  46.  
  47. start:
  48.     move.l    d0,dosCmdLen
  49.     move.l    a0,dosCmdBuf
  50.     move.l    a7,d0            ; save old stack ptr
  51.     movem.l    d1-d6/a0-a6,-(a7)
  52.     move.l    d0,a5
  53.     move.l    _AbsExecBase,a6
  54.     move.l    a6,_SysBase
  55.     move.l    a7,__StackPtr        * Save stack ptr
  56.  
  57. ;------ get the address of our task
  58.     suba.l    a1,a1
  59.     callsys    FindTask
  60.     move.l    d0,a4
  61.  
  62. ;------ are we running as a son of Workbench?
  63.     move.l    pr_CurrentDir(A4),_curdir
  64.     tst.l    pr_CLI(A4)
  65.     beq    exit2
  66.  
  67. ;=======================================================================
  68. ;====== CLI Startup Code ===============================================
  69. ;=======================================================================
  70.  
  71. fromCLI:
  72.     move.l    a5,D0        ; get top of stack
  73.     sub.l    4(a5),D0    ; compute bottom 
  74.     move.l    D0,__base    ; save for stack checking
  75. ;------    attempt to open DOS library:
  76.     lea    DOSName,A1
  77.     moveq.l    #0,D0
  78.     callsys OpenLibrary
  79.     move.l    D0,_DOSBase
  80.     beq    noDOS
  81.  
  82. ;------ find command name:
  83.     move.l    #start,a0
  84.     clr.l    -(sp)
  85.     jsr    _FindTask
  86.     addq.l    #4,sp
  87.     move.l    d0,a0
  88.     move.l    pr_CLI(a0),a0
  89.     add.l   a0,a0        ; bcpl pointer conversion
  90.     add.l   a0,a0
  91.     move.l    cli_CommandName(a0),a1
  92.     add.l   a1,a1        ; bcpl pointer conversion
  93.     add.l   a1,a1
  94.  
  95. ;------    collect parameters:
  96.     move.l    dosCmdLen,d0        ; get command line length
  97.     move.l    a1,__ProgramName
  98.     addq.l    #1,d0            ; allow for space after command    
  99.  
  100.     clr.w    -(A7)            ; set null terminator for command line
  101.     addq.l    #1,D0            ; force to even number of bytes
  102.     andi.w    #$fffe,D0        ;(round up)
  103.     sub.l    D0,A7            ; make room on stack for command line
  104.     subq.l    #2,D0
  105.     clr.w    0(A7,D0)
  106.  
  107. ;------ copy command line onto stack
  108.     move.l    dosCmdLen,d0        ; get command line length
  109.     move.l    dosCmdBuf,a0
  110.     move.l    d0,d2
  111.     subq.l    #1,d0
  112.  
  113. copy_line:
  114.     move.b    0(A0,D0.W),0(A7,D2.W)    ; copy command line to stack
  115.     subq.l    #1,d2
  116.     dbf    d0,copy_line
  117.     move.b    #' ',0(a7,d2.w)        ; add space between command and parms
  118.     subq.l    #1,d2
  119.  
  120.     move.l    A7,A1
  121.     move.l    A1,-(A7)        ; push command line address
  122.     jsr    __main                * call C entrypoint
  123.     moveq.l    #0,d0            ; set successful status
  124.     bra.l    exit2
  125.  
  126. _XCEXIT:
  127.     move.l    4(SP),d0    ; extract return code
  128. exit2:
  129.     move.l    d0,-(a7)
  130.     move.l    _SysBase,a6
  131.     move.l    _DOSBase,a1
  132.     callsys    CloseLibrary        ; close Dos library
  133.  
  134. ;------ this rts sends us back to DOS:
  135. exitToDOS:
  136.     MOVE.L    (A7)+,D0
  137.     movea.l  __StackPtr,SP        * restore stack ptr
  138.     movem.l    (a7)+,d1-d6/a0-a6
  139.     rts                * and exit
  140.  
  141. ;-----------------------------------------------------------------------
  142. noDOS:
  143.         ALERT    (AG_OpenLib!AO_DOSLib)
  144.         moveq.l    #100,d0
  145.         bra    exit2
  146.  
  147. *************************************************************************
  148. *   HandlerInterface()
  149. *
  150. *   This code is needed to convert the calling sequence performed by
  151. *   the input.task for the input stream management into something
  152. *   that a C program can understand.
  153. *
  154. *   This routine expects a pointer to an InputEvent in A0, a pointer
  155. *   to a data area in A1.  These values are transferred to the stack
  156. *   in the order that a C program would need to find them.  Since the
  157. *   actual handler is written in C, this works out fine. 
  158. *
  159. *   Author: Rob Peck, 12/1/85
  160. *
  161.  
  162. _HandlerInterface:
  163.     movem.L    A0/A1,-(A7)
  164.     jsr    _myhandler
  165.     addq.L    #8,A7
  166.     rts
  167.  
  168.     section    data,DATA
  169. ;
  170.     XDEF    _NULL,_SysBase,_LoadAddress,_console_dev,_WBenchMsg
  171.     XDEF    _curdir,__mbase,__mnext,__msize,__tsize
  172.     XDEF    __oserr,__OSERR,__FPERR,__SIGFPE,__ONERR,__ONEXIT,__ONBREAK
  173.     XDEF    __SIGINT
  174.     XDEF    _errno,_stdin,_stdout,_stderr
  175.     XDEF    __ProgramName,__StackPtr,__base
  176. ;
  177. _errno        dc.l    0
  178. _stdin        dc.l    0
  179. _stdout        dc.l    0
  180. _stderr        dc.l    0
  181. _NULL        dc.l    0        ;
  182. __base        dc.l    0        ; base of stack
  183. __mbase        dc.l    0        ; base of memory pool
  184. __mnext        dc.l    0        ; next available memory location
  185. __msize        dc.l    0        ; size of memory pool
  186. __tsize        dc.l    0        ; total size?
  187. __oserr        equ    *
  188. __OSERR        dc.l    0
  189. __FPERR        dc.l    0
  190. __SIGFPE    dc.l    0
  191. __SIGINT    dc.l    0
  192. __ONERR        dc.l    0
  193. __ONEXIT    dc.l    0
  194. __ONBREAK    dc.l    0
  195. _curdir        dc.l    0
  196. _console_dev    dc.l    0
  197. _SysBase    dc.l    0
  198. _LoadAddress    dc.l    0            ; program load address
  199. _WBenchMsg    dc.l    0
  200. __StackPtr    dc.l    0
  201. dosCmdLen    dc.l    0
  202. dosCmdBuf    dc.l    0
  203. stdin        dc.l    0
  204. __ProgramName    dc.l    0
  205. DOSName     DOSNAME
  206.  
  207.     END
  208.