home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Assembler / DVP30_1.DMS / in.adf / Devpac / Examples / misc / easystart.i < prev   
Encoding:
Text File  |  1992-02-26  |  1.2 KB  |  63 lines

  1.  
  2. * some startup code to make a Workbench execute look like the CLI
  3. * based loosely on RKM Vol 1 page 4-36
  4.  
  5. * Include this at the front of your program
  6. * after any other includes
  7. * note that this needs exec/exec_lib.i
  8.  
  9.     IFND    LIBRARIES_DOSEXTENS_I
  10.     include    libraries/dosextens.i
  11.     ENDC
  12.  
  13.  
  14.     movem.l    d0/a0,-(sp)        save initial values
  15.     clr.l    returnMsg
  16.  
  17.     sub.l    a1,a1
  18.     CALLEXEC FindTask        find us
  19.     move.l    d0,a4
  20.  
  21.     tst.l    pr_CLI(a4)
  22.     beq.s    fromWorkbench
  23.  
  24. * we were called from the CLI
  25.     movem.l    (sp)+,d0/a0        restore regs
  26.     bra.s    end_startup        and run the user prog
  27.  
  28. * we were called from the Workbench
  29. fromWorkbench
  30.     lea    pr_MsgPort(a4),a0
  31.     CALLEXEC WaitPort        wait for a message
  32.     lea    pr_MsgPort(a4),a0
  33.     CALLEXEC GetMsg            then get it
  34.     move.l    d0,returnMsg        save it for later reply
  35.  
  36. * do some other stuff here like the command line etc
  37.     nop
  38.  
  39.     movem.l    (sp)+,d0/a0        restore
  40. end_startup
  41.     bsr.s    _main            call our program
  42.  
  43. * returns to here with exit code in d0
  44.     move.l    d0,-(sp)        save it
  45.  
  46.     tst.l    returnMsg
  47.     beq.s    exitToDOS        if I was a CLI
  48.  
  49.     CALLEXEC Forbid
  50.     move.l    returnMsg(pc),a1
  51.     CALLEXEC ReplyMsg
  52.  
  53. exitToDOS
  54.     move.l    (sp)+,d0        exit code
  55.     rts
  56.  
  57. * startup code variable
  58. returnMsg    dc.l    0
  59.  
  60. * the program starts here
  61.     even
  62. _main
  63.