home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 122.lha / Arp_v1.1 / Libraries / Lattice_SRC / arpc.s < prev    next >
Encoding:
Text File  |  1986-11-20  |  6.5 KB  |  277 lines

  1. ;
  2. ; Lattice 4.0 C startup under ARP
  3. ;
  4. ; Copyright (c) 1988, Scott Ballantyne
  5. ; May be freely used by users/supporters of ARP.
  6. ;
  7. ; Use at your own risk, of course.
  8. ;
  9. ; This code provides an arp 'wrapper' for Lattice, which opens arp,
  10. ; does some arp stuff, and calls an arp specific _main routine which does
  11. ; CLI processing using GADS() and WBench processing as usual for lattice.
  12. ; SDB
  13. ;
  14.         INCLUDE "exec/types.i"
  15.         INCLUDE "exec/alerts.i"
  16.         INCLUDE "exec/nodes.i"
  17.         INCLUDE "exec/lists.i"
  18.         INCLUDE "exec/ports.i"
  19.         INCLUDE "exec/libraries.i"
  20.         INCLUDE "exec/tasks.i"
  21.     INCLUDE    "exec/ables.i"
  22.         INCLUDE "libraries/dos.i"
  23.         INCLUDE "libraries/dosextens.i"
  24.     INCLUDE    "libraries/arpbase.i"
  25.         INCLUDE "workbench/startup.i"
  26.         INCLUDE "exec/exec_lib.i"
  27.         INCLUDE "libraries/dos_lib.i"
  28.  
  29. AbsExecBase    EQU    4
  30.  
  31.     xdef    _XCEXIT        ; exit(code)
  32.     xref    _LinkerDB    ; a4 bias
  33.     xref    __BSSBAS    ; start of BSS
  34.     xref    __BSSLEN    ; length of BSS
  35.  
  36.     csect    text,0,0,1,2    ; xref's now are 16-bit relocatable
  37.  
  38.     xref    __main
  39.     xref    _MemCleanup
  40.  
  41. start:    move.l    sp,a5        ; save old stack pointer
  42.     movem.l    d1-d6/a0-a6,-(sp) ; Seems lattice depends on this?
  43.     move.l    a0,a2        ; command
  44.     move.l    d0,d2        ; length
  45.     lea.l    _LinkerDB,a4    ; this is base register.
  46.     lea.l    __BSSBAS,a1    ; this is start of BSS
  47.     moveq.l    #0,d1
  48.     move.l    #__BSSLEN,d0    ; this is in long words
  49.     bne.s    start2
  50.     bra.s    cont
  51. start1:    move.l    d1,(a1)+    ; clear BSS
  52. start2:    dbra    d0,start1
  53. cont:    
  54.     move.l    sp,__StackPtr(a4)    ; save altered stack pointer    
  55.     move.l    4,a6
  56.     move.l    a6,_SysBase(a4)        ; save exec base
  57.     clr.l    _WBenchMsg(a4)
  58.     lea    ARPNAME(pc),a1        ; get name of arp.library
  59.     moveq.l    #ArpVersion,d0
  60.     SYSCALL    OpenLibrary        ; open it
  61.     move.l    d0,_ArpBase(a4)        ; set up arp library pointer
  62.     move.l    d0,_DOSBase(a4)        ; also as DOS pointer
  63.     beq    AhOhNoARP
  64.     move.l    d0,a0
  65.     move.l    GfxBase(a0),_GfxBase(a4)    ; give free graphics.library
  66.     move.l    IntuiBase(a0),_IntuitionBase(a4) ; and free intuition.library
  67.     
  68.     move.l    ThisTask(a6),a3        ; get task in A3
  69.     move.l    pr_CurrentDir(A3),_curdir(A4)
  70.     tst.l    pr_CLI(a3)
  71.     beq    fromWorkbench
  72. *******************
  73. * CLI startup
  74. *    d0 = a0 = arpbase.
  75. *    d2/a2  = length/command
  76. *    a3 = *Process
  77. *    a5 = initial SP
  78. *    
  79. *******************
  80.     move.l    a5,d0        ; stack top
  81.     sub.l    4(a5),d0    ; bottom
  82.     add.l    #128,d0        ; parms overflow
  83.     move.l    d0,__base(a4)    ; save for stack checking
  84.     move.l    pr_CLI(a3),a0
  85.     add.l    a0,a0
  86.     add.l    a0,a0
  87.     move.l    cli_CommandName(a0),a1
  88.     add.l    a1,a1
  89.     add.l    a1,a1
  90.  
  91. *------- build arg list
  92. *------- lattice wants "name arg1 arg2 arg3" etc.
  93.     move.l    d2,d0
  94.     moveq.l    #0,d1
  95.     move.b    (a1)+,d1    ; length of program name
  96.     add.l    d1,d0        ; add it to command name
  97.     addq.l    #1,d0        ; and allow for space
  98.     clr.w    -(sp)        ; slop
  99.     addq.l    #1,d0        ; force even # bytes
  100.     and.w    #-2,d0        ; round up
  101.     sub.l    d0,a7        ; make space
  102.     clr.w    -2(a7,d0.w)
  103. *--------------
  104. *    copy command to stack
  105. *--------------
  106.     move.l    d2,d0
  107.     add.l    d1,d2
  108.     bra.s    fixnul            ; fix lattice NOCMD bug
  109. fixnul1:
  110.     move.b    0(a2,d0.w),0(sp,d2.w)
  111.     subq.l    #1,d2
  112. fixnul:    dbra    d0,fixnul1
  113.     move.b    #' ',0(sp,d2.w)
  114.     subq.l    #1,d2
  115. copy_cmd:
  116.     move.b    0(a1,d2.w),0(sp,d2.w)
  117.     dbra    d2,copy_cmd
  118.     move.l    sp,-(sp)
  119.     bra    main
  120. *=========================
  121. * Workbench version
  122. *=========================
  123.  
  124. fromWorkbench:
  125.     move.l    TC_SPLOWER(a3),__base(a4)    ; base for workbench
  126.     add.l    #128,__base(a4)            ; parms overflow
  127.     lea.l    pr_MsgPort(a3),a0
  128.     SYSCALL    WaitPort            ; wait for startup message
  129.     lea    pr_MsgPort(a3),a0
  130.     SYSCALL    GetMsg
  131.     move.l    _ArpBase(a4),a6        ; nuther lattice bug fix
  132.     move.l    d0,_WBenchMsg(a4)
  133.     move.l    d0,a2            ; get first argument
  134.     move.l    sm_ArgList(a2),d0
  135.     beq.s    do_cons
  136.     move.l    d0,a0
  137.     move.l    wa_Lock(a0),d1
  138.     move.l    d1,_curdir(A4)
  139.     SYSCALL    CurrentDir
  140. do_cons:
  141.     move.l    sm_ToolWindow(a2),d1    ; get the window argument
  142.     beq.s    do_main
  143.     move.l    #MODE_OLDFILE,d2
  144.     SYSCALL    Open
  145.     move.l    d0,_stdin(a4)
  146.     beq.s    do_main
  147.     lsl.l    #2,d0
  148.     move.l    d0,a0
  149.     move.l    fh_Type(a0),pr_ConsoleTask(a3)
  150. do_main:
  151.     move.l    _WBenchMsg(a4),a0
  152.     pea    _NULL(a4)        ; argument to _main
  153.     move.l    sm_ArgList(a0),a0
  154.     move.l    wa_Name(a0),__ProgramName(a4)
  155. main:    jsr    __main(pc)
  156.     moveq.l    #0,d0
  157.     bra.s    exit2
  158.  
  159. _XCEXIT:
  160.     move.l    4(sp),d0    ; this is program rc
  161. exit2:
  162.     move.l    d0,-(sp)
  163.     move.l    __ONEXIT(a4),d0    ; somebody set a trap?
  164.     beq.s    exit21
  165.     move.l    d0,a0
  166.     jsr    (a0)            ; call user def
  167. exit21:    jsr    _MemCleanup(pc)        ; lattice function
  168.     move.l    4,a6
  169.     move.l    _MathBase(a4),d0
  170.     beq.s    exit22
  171.     move.l    d0,a1
  172.     SYSCALL    CloseLibrary
  173. exit22:
  174.     move.l    _MathTransBase(a4),d0
  175.     beq.s    exit23
  176.     move.l    d0,a1
  177.     SYSCALL    CloseLibrary
  178. exit23:    move.l    _MathIeeeDoubBasBase(a4),d0
  179.     beq.s    wbp
  180.     move.l    d0,a1
  181.     SYSCALL    CloseLibrary
  182. wbp:    tst.l    _WBenchMsg(a4)
  183.     beq.s    shellrts
  184.     move.l    _ArpBase(a4),a6
  185.     move.l    _console_dev(a4),d1
  186.     beq.s    wbp1
  187.     SYSCALL    Close
  188. wbp1:    move.l    _stdin(a4),d1
  189.     beq.s    wbp2
  190.     SYSCALL    Close
  191. wbp2:    move.l    4,a6
  192.     FORBID
  193.     move.l    _WBenchMsg(a4),a1
  194.     SYSCALL    ReplyMsg
  195. shellrts:
  196.     move.l    _ArpBase(a4),a1
  197.     SYSCALL    CloseLibrary    ; free ARP resources
  198.     move.l    (sp)+,d0    ; get exit code
  199.     move.l    __StackPtr(a4),sp
  200.     movem.l    (sp)+,d1-d6/a0-a6
  201.     rts
  202.  
  203. ************************
  204. * Called if no ARP
  205. ************************
  206. AhOhNoARP:
  207.     lea.l    dosname(pc),a1
  208.     SYSCALL    OpenLibrary
  209.     tst.l    d0
  210.     beq.s    noarp1
  211.     move.l    d0,a6
  212.     SYSCALL    Output
  213.     move.l    d0,d1
  214.     beq.s    noarp1
  215.     lea.l    alibmsg(pc),a0
  216.     move.l    a0,d2
  217. *    move.l    #alibmsg,d2    ; appears lattice asm can't handle this.
  218. *    move.l    #aliblng,d3    ; or this either.
  219.     move.l    #28,d3
  220.     SYSCALL    Write
  221. noarp1:    move.l    a5,sp
  222.     rts
  223.  
  224. dosname:    dc.b    'dos.library',0
  225. alibmsg:    dc.b    'you need '
  226. ARPNAME:    ArpName
  227.     dc.b    ' V34+',10
  228. aliblng    EQU    *-alibmsg
  229.  
  230.     csect    __MERGED,1,,2,2
  231.  
  232.     xref    _DOSBase
  233.     xref    _MathBase
  234.     xref    _MathTransBase
  235.     
  236.     xdef    _GfxBase
  237.     xdef    _IntuitionBase
  238.  
  239.     xdef    _NULL,_SysBase,_LoadAddress,_console_dev,_WBenchMsg
  240.     xdef    _curdir,__mbase,__mnext,__msize,__tsize
  241.     xdef    __oserr,__OSERR,__FPERR,__SIGFPE,__ONERR,__ONEXIT,__ONBREAK
  242.     xdef    __SIGINT,__ECS
  243.     xdef    __ProgramName,__StackPtr,__base
  244.     xdef    _MathIeeeDoubBasBase
  245.     xdef    _ArpBase
  246. *
  247. _NULL        dc.l    0
  248. __base:        dc.l    0    ; base of stack
  249. __mbase:    dc.l    0    ; base of memory pool
  250. __mnext:    dc.l    0    ; next available memory location
  251. __msize:    dc.l    0    ; size of memory pool
  252. __tsize:    dc.l    0    ; total size
  253. __oserr:    equ    *
  254. __OSERR:    dc.l    0
  255. __FPERR:    dc.l    0
  256. __SIGFPE:    dc.l    0
  257. __SIGINT:    dc.l    0
  258. __ONERR:    dc.l    0
  259. __ONEXIT:    dc.l    0
  260. __ONBREAK:    dc.l    0
  261. __ECS:        dc.l    0    * extended character set flag
  262. _curdir:    dc.l    0
  263. _console_dev:    dc.l    0
  264. _SysBase:    dc.l    0
  265. _ArpBase:    dc.l    0    ; ARP library base pointer
  266. _GfxBase:    dc.l    0    ; Graphics library base pointer
  267. _IntuitionBase:    dc.l    0    ; Intuition library base pointer
  268. _LoadAddress:    dc.l    0    * program load address
  269. _WBenchMsg:    dc.l    0
  270. __StackPtr:    dc.l    0
  271. _stdin:        dc.l    0
  272. __ProgramName:    dc.l    0
  273. _MathIeeeDoubBasBase:    dc.l    0
  274.  
  275.     END
  276.  
  277.