home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / gifmachine_405.lzh / GIFMachine / Sources / startup.a < prev    next >
Text File  |  1990-11-17  |  4KB  |  245 lines

  1.  INCLUDE "exec/types.i"
  2.  INCLUDE "exec/execbase.i"
  3.  INCLUDE "exec/memory.i"
  4.  INCLUDE "libraries/dosextens.i"
  5.  
  6.  XREF @main
  7.  
  8.  XREF _LVOOpenLibrary
  9.  XREF _LVOOldOpenLibrary
  10.  XREF _LVOCloseLibrary
  11.  XREF _LVOSetSignal
  12.  XREF _LVOForbid
  13.  XREF _LVOWaitPort
  14.  XREF _LVOGetMsg
  15.  XREF _LVOReplyMsg
  16.  XREF _LVOSetIoErr
  17.  XREF _LVOAllocVec
  18.  XREF _LVOFreeVec
  19.  XREF _LVOOutput
  20.  XREF _LVOWrite
  21.  
  22.  XREF _LinkerDB
  23.  XREF __BSSBAS
  24.  XREF __BSSLEN
  25.  XREF _RESLEN
  26.  XREF _RESBASE
  27.  XREF _NEWDATAL
  28.  
  29.  XREF _AbsExecBase
  30.  
  31. LIBCALL    MACRO
  32.     jsr _LVO\1(a6)
  33.     ENDM
  34.  
  35.   SECTION StartCode,CODE
  36.  
  37. init:
  38.     movem.l    d0/a0,-(sp)
  39.  
  40. ; first off we will check for our workbench message, if any.  we will store
  41. ; the pointer to it in d7 temporarily until we actually copy the data
  42. ; segment over.  otherwise we wouldn't be residentiable.
  43.  
  44.     moveq    #0,d7        ; clear out longword
  45.  
  46. ; get address of our task
  47.     move.l    _AbsExecBase.W,a6
  48.     move.l    ThisTask(a6),a3
  49.  
  50. ; clear any pending signals
  51.     moveq    #0,d0
  52.     move.l    #$00003000,d1
  53.     LIBCALL    SetSignal
  54.  
  55. ; check for workbench message
  56.     tst.l    pr_CLI(a3)
  57.     bne.s    FromCLI
  58.  
  59.     lea    pr_MsgPort(a3),a0
  60.     LIBCALL    WaitPort
  61.     lea    pr_MsgPort(a3),a0
  62.     LIBCALL    GetMsg
  63.     move.l    d0,d7
  64.  
  65. FromCLI:
  66.     lea    DOSlib(pc),a1
  67.     moveq    #36,d0
  68.     LIBCALL    OpenLibrary
  69.     tst.l    d0
  70.     bne.s    DoMain
  71.  
  72.     lea    DOSlib(pc),a1
  73.     LIBCALL    OldOpenLibrary
  74.     tst.l    d0
  75.     beq.s    bomb
  76.  
  77.     move.l    d0,a6
  78.     LIBCALL    Output
  79.     move.l    d0,d1
  80.     beq.s    bomb
  81.  
  82.     lea    Msg1(pc),a0
  83.     move.l    a0,d2
  84.     moveq    #Msg1Len,d3
  85.     LIBCALL    Write
  86.  
  87.     move.l    a6,a1
  88.     move.l    _AbsExecBase.W,a6
  89.     LIBCALL    CloseLibrary
  90.  
  91. bomb:    addq.l    #8,sp        ; pop d0/a0 off stack
  92.  
  93.     move.l    d7,d0        ; check if we have a workbench startup
  94.     bsr    ReplyWB        ; message and reply it if so
  95.  
  96.     moveq    #0,d0
  97.     rts
  98.  
  99. DoMain:
  100.     move.l    d0,-(sp)
  101.  
  102.     lea    _LinkerDB,a4
  103.     sub.l    #_RESBASE,a4
  104.  
  105. ; get mem to hold data and bss stuff
  106.     move.l    #_RESLEN,d0
  107.     move.l    #MEMF_PUBLIC+MEMF_CLEAR,d1
  108.     LIBCALL    AllocVec
  109.     tst.l    d0
  110.     bne.s    gotmem
  111.  
  112. ; no mem available so bomb out
  113.     move.l    d7,d0        ; check for wb startup message and reply
  114.     bsr    ReplyWB        ; it if present
  115.  
  116.     move.l    (sp)+,a6    ; get dos base
  117.     addq.l    #8,sp        ; pop d0/a0 off of stack
  118.  
  119.     moveq    #ERROR_NO_FREE_STORE,d1
  120.     LIBCALL    SetIoErr
  121.  
  122.     move.l    a6,a1
  123.     move.l    _AbsExecBase.W,a6
  124.     LIBCALL    CloseLibrary
  125.  
  126.     moveq    #20,d0
  127.     rts
  128.  
  129. ; get ready to copy data over into freshly alloced data area
  130. gotmem:    move.l    d0,a0
  131.     move.l    d0,a2
  132.  
  133.     move.l    d0,a1
  134.     move.l    #_NEWDATAL,d0
  135. cpy:    move.l    (a4)+,(a0)+
  136.     subq.l    #1,d0
  137.     bne.s    cpy
  138.  
  139. ; now do the relocs for resident data
  140.     move.l    (a4)+,d0
  141. reloc:    beq.s    nreloc
  142.     move.l    a1,a0
  143.     add.l    (a4)+,a0
  144.     add.l    (a0),a2
  145.     move.l    a2,(a0)
  146.     move.l    a1,a2
  147.     subq.l    #1,d0
  148.     bra.s    reloc
  149.  
  150. nreloc:    move.l    a1,a4
  151.     add.l    #_RESBASE,a4
  152.  
  153. ; stash some important junk away
  154.     move.l    (sp)+,_DOSBase(a4)
  155.     move.l    d7,_WBenchMsg(a4)
  156.  
  157.     move.l    _AbsExecBase.W,a6
  158.     move.l    a6,_SysBase(a4)
  159.  
  160. ; call our main program.  we call the main routine with the following
  161. ; arguments:
  162. ;
  163. ;   d0 = length of command line
  164. ;   a0 = pointer to command line
  165. ;   a1 = pointer to workbench startup message (or NULL)
  166.  
  167.     movem.l    (sp)+,d0/a0
  168.     movem.l    sp,__StackPtr(a4)
  169.  
  170.     movea.l    d7,a1
  171.     jsr    @main
  172.     moveq    #0,d0
  173.     bra.s    Exit
  174.  
  175.  XDEF _XCEXIT
  176. _XCEXIT:
  177.     move.l    4(sp),d0
  178.  XDEF @XCEXIT
  179. @XCEXIT:
  180.  
  181. Exit:    move.l    d0,d3            ; save return code in safe place
  182.  
  183.     move.l    _WBenchMsg(a4),d0    ; check if we need to reply the
  184.     bsr    ReplyWB            ; workbench startup message
  185.  
  186.     move.l    _DOSBase(a4),a6
  187.     moveq    #0,d1
  188.     LIBCALL    SetIoErr
  189.  
  190.     move.l    a6,a1
  191.     move.l    _AbsExecBase.W,a6
  192.     LIBCALL    CloseLibrary
  193.  
  194.     movea.l    __StackPtr(a4),sp
  195.  
  196.     move.l    a4,a1
  197.     sub.l    #_RESBASE,a1
  198.     LIBCALL    FreeVec
  199.  
  200.     move.l    d3,d0            ; restore return code
  201.     rts
  202.  
  203. ; this subroutine is called when we try to check if we need to reply
  204. ; the workbench message.  This is done because we do this in more than
  205. ; one place.
  206.  
  207. ReplyWB:
  208.     move.l    d0,d2
  209.     beq.s    1$
  210.  
  211.     move.l    _AbsExecBase.W,a6
  212.     LIBCALL    Forbid
  213.     movea.l    d2,a1
  214.     LIBCALL    ReplyMsg
  215.  
  216. 1$    rts
  217.  
  218. ; ---- This is the data we need for the startup module.  we don't put it in
  219. ;      a data segment, though, or it would end up being copied over when we
  220. ;      clone the data hunk and this stuff isn't needed anywhere else...
  221.  
  222. DOSlib    dc.b "dos.library",0
  223.  
  224. Msg1    dc.b "You need KickStart 2.0 or greater.",13
  225. Msg1Len    EQU *-Msg1
  226.     ds.w 0
  227.  
  228. ; ---- This is the BBS segment that holds various startup junk for us.
  229.  
  230.    SECTION __MERGED,BSS
  231.  
  232.  XDEF _DOSBase
  233.  XDEF _SysBase
  234.  XDEF _IntuitionBase
  235.  XDEF _WBenchMsg
  236.  XDEF __StackPtr
  237.  
  238. _DOSBase    ds.b 4
  239. _SysBase    ds.b 4
  240. _IntuitionBase    ds.b 4
  241. _WBenchMsg    ds.b 4
  242. __StackPtr    ds.b 4
  243.  
  244.    END
  245.