home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / iffconverter / iffstartup.a.bak < prev    next >
Text File  |  1997-01-07  |  3KB  |  138 lines

  1. ****
  2.         INCLUDE    exec_lib.i
  3.         INCLUDE    dos_lib.i
  4.         INCLUDE    exec/macros.i
  5.         INCLUDE    exec/execbase.i
  6.         INCLUDE    dos/dos.i
  7.         INCLUDE    dos/dosextens.i
  8.         INCLUDE    workbench/startup.i
  9.  
  10. IFF_LIB_VERSION    equ    0
  11.         
  12. ;-- Defining Macros -------------------------------------------------
  13.  
  14. *--------------------------------------------------------------------
  15. *
  16. *  To call a library function use LIBCALL. If A6 is correct, just
  17. *  use LIBCALL with the functionname only. If A6 isn't correct,
  18. *  than use LIBCALL with the functionname AND the library offset.
  19. *
  20. *--------------------------------------------------------------------
  21.  
  22. LIBCALL        MACRO
  23.         IFGT    NARG-2        More Then Two Arguments?
  24.         FAIL            Too many Arguments!!!
  25.         ENDC
  26.         IFEQ    NARG-2        Two Arguments exactly.
  27.         move.l    (\2),a6
  28.         ENDC
  29.         jsr    (_LVO\1,a6)
  30.         ENDM
  31.         
  32. ;-- Defining Constants ----------------------------------------------
  33.  
  34. SysBase        equ    4
  35.  
  36.  
  37.         XDEF    _exit
  38.  
  39. ;-- Start of Program ------------------------------------------------
  40.         
  41.         SECTION    Startup,code
  42.  
  43.         XREF    _main
  44.                 
  45.         movem.l    d1-d6/a0-a6,-(SP)
  46.  
  47.         lea    (__BSSSection),a0
  48.         move.w    #__BSSLength/4,d0
  49.         CLEAR    D1
  50.         bra.s    ZeroLength
  51. ClearBSSsection        
  52.         move.l    d1,(a0)+
  53. ZeroLength
  54.         dbf    d0,ClearBSSsection
  55.  
  56.         move.l    SP,(__StoredStack)    Save Stack pointer.
  57.         
  58.         lea    (DosName,PC),a1
  59.         moveq    #IFF_LIB_VERSION,d0
  60.         LIBCALL    OpenLibrary,SysBase.W
  61.         move.l    d0,(DosBase)
  62.         beq    NoDosLib
  63.         
  64.         CLEARA    A1
  65.         LIBCALL    FindTask            Get our own task.
  66.         move.l    d0,a4
  67.         
  68.         tst.l    (pr_CLI,a4)        Are we called from Workbench?
  69.         bne.s    FromCLI            No, it was CLI.
  70.         
  71. *---- So we were called from Workbench.
  72. *---- This means a message is waiting for us and we have to answer it!
  73.         move.l    (pr_CurrentDir,a4),d1
  74.         LIBCALL    CurrentDir,DosBase
  75.         
  76.         lea    (pr_MsgPort,a4),a0
  77.         LIBCALL    WaitPort,SysBase.W
  78.         lea    (pr_MsgPort,a4),a0
  79.         LIBCALL    GetMsg
  80.         move.l    d0,(__WBMessage)
  81.  
  82.         move.l    d0,(_argv)
  83.         clr.l    (_argc)
  84.         
  85.         move.l    d0,a0
  86.         move.l    (sm_ArgList,a0),a0
  87.         move.l    (wa_Lock,a0),d1
  88.         LIBCALL    CurrentDir,DosBase
  89.         
  90.         bra.s    DoMain
  91.         
  92. FromCLI
  93.         move.l    #1,_argc
  94. DoMain
  95.         jsr    (_main,PC)
  96.         moveq    #0,d0
  97.         
  98. _exit
  99.         move.l    d0,-(SP)            Save Return Code
  100.  
  101.         tst    (__WBMessage)
  102.         beq.s    NoWBMessage
  103.         
  104.         LIBCALL    Forbid,SysBase.W
  105.         
  106.         move.l    (__WBMessage),a1
  107.         LIBCALL    ReplyMsg
  108. NoWBMessage        
  109.         move.l    (DosBase),a1
  110.         LIBCALL    CloseLibrary,SysBase.W
  111.         move.l    (SP),d0            Retrive Return Code
  112. Quit
  113.         move.l    (__StoredStack),SP    Restore Stack Pointer to its original state
  114.         movem.l    (SP)+,d1-d6/a0-a6
  115.         rts
  116.  
  117. NoDosLib
  118.         bra.s    Quit
  119.         
  120. DosName        DOSNAME
  121. DosBase        dc.l    0
  122.  
  123.         SECTION    __MERGED,data
  124.         XDEF    _argc,_argv
  125. _argc        dc.l    0
  126. _argv        dc.l    0
  127.  
  128. ;-- Start of BSS Section --------------------------------------------
  129.  
  130.         SECTION    bss,bss
  131. __BSSSection
  132.  
  133. __StoredStack    ds.l    1
  134. __WBMessage    ds.l    1
  135.         CNOP    0,4
  136.  
  137. __BSSLength    equ    *-__BSSSection    Length of BSS Section.
  138.