home *** CD-ROM | disk | FTP | other *** search
/ Dave Lowe: Devpac Amiga 1 / Lowe_DevpacAmiga1.adf / include / misc / easystart.i
Encoding:
Text File  |  1987-11-09  |  1.2 KB  |  68 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.  
  7.     IFND    EXEC_EXEC_LIB_I
  8.     include    "exec/exec_lib.i"
  9.     ENDC
  10.     IFND    EXEC_EXEC_I
  11.     include    "exec/exec.i"
  12.     ENDC
  13.     IFND    LIBRARIES_DOSEXTENS_I
  14.     include    "libraries/dosextens.i
  15.     ENDC
  16.  
  17.  
  18.     movem.l    d0/a0,-(sp)        save initial values
  19.     clr.l    returnMsg
  20.  
  21.     sub.l    a1,a1
  22.     CALLEXEC FindTask        find us
  23.     move.l    d0,a4
  24.  
  25.     tst.l    pr_CLI(a4)
  26.     beq.s    fromWorkbench
  27.  
  28. * we were called from the CLI
  29.     movem.l    (sp)+,d0/a0        restore regs
  30.     bra    end_startup        and run the user prog
  31.  
  32. * we were called from the Workbench
  33. fromWorkbench
  34.     lea    pr_MsgPort(a4),a0
  35.     CALLEXEC WaitPort        wait for a message
  36.     lea    pr_MsgPort(a4),a0
  37.     CALLEXEC GetMsg            then get it
  38.     move.l    d0,returnMsg        save it for later reply
  39.  
  40. * do some other stuff here RSN like the command line etc
  41.     nop
  42.  
  43.     movem.l    (sp)+,d0/a0        restore
  44. end_startup
  45.     bsr.s    _main            call our program
  46.  
  47. * returns to here with exit code in d0
  48.     move.l    d0,-(sp)        save it
  49.  
  50.     tst.l    returnMsg
  51.     beq.s    exitToDOS        if I was a CLI
  52.  
  53.     CALLEXEC Forbid
  54.     move.l    returnMsg(pc),a1
  55.     CALLEXEC ReplyMsg
  56.  
  57. exitToDOS
  58.     move.l    (sp)+,d0        exit code
  59.     rts
  60.  
  61. * startup code variable
  62. returnMsg    dc.l    0
  63.  
  64. * the program starts here
  65.     even
  66. _main    
  67.  
  68.