home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / assembler / thesource / volume1 / source / startupcode / wbstartup.lha / wb_startup.i
Encoding:
Text File  |  1992-12-31  |  1.8 KB  |  88 lines

  1. * some startup code to make a Workbench execute look like the CLI
  2. * based loosely on RKM Vol 1 page 4-36
  3. *
  4. * Include this at the front of your program after any other includes.
  5. *
  6. * This code originally came from the DevPac 2.08 disk.  It has been
  7. * heavily modified, though, by the Dancing Fool of Epsilon.
  8.  
  9.         incdir    'df0:include/'
  10.  
  11.         IFND    EXEC_EXEC_I
  12.         include    'exec/exec.i'
  13.         ENDIF
  14.  
  15.         IFND    LIBRARIES_DOSEXTENS_I
  16.         include    'libraries/dosextens.i'
  17.         ENDIF
  18.  
  19.  IFND    CALLEXEC
  20. CALLEXEC    MACRO
  21.         movea.l    4.w,a6
  22.         jsr    _LVO\1(a6)
  23.         ENDM
  24.  ENDIF
  25.  
  26.  IFND    _LVOFindTask
  27. _LVOFindTask    EQU    -$126
  28.  ENDIF
  29.  
  30.  IFND _LVOWaitPort
  31. _LVOWaitPort    EQU    -$180
  32.  ENDIF
  33.  
  34.  IFND _LVOGetMsg
  35. _LVOGetMsg    EQU    -$174
  36.  ENDIF
  37.  
  38.  IFND _LVOReplyMsg
  39. _LVOReplyMsg    EQU    -$17a
  40.  ENDIF
  41.  
  42.  IFND _LVOForbid
  43. _LVOForbid    EQU    -$84
  44.  ENDIF
  45.  
  46.  
  47. WBStartUp:    movem.l    d0/a0,-(sp)        ; save initial values
  48.         suba.l    a3,a3
  49.  
  50.         suba.l    a1,a1            ; clear out
  51.         CALLEXEC FindTask        ; find us
  52.         move.l    d0,a4            ; save our pointer in a4
  53.  
  54.         tst.l    pr_CLI(a4)        ; are we from the cli?
  55.         beq.b    .fromWorkbench        ; nope, do other stuff...
  56.  
  57.     ; we were called from the CLI
  58.         movem.l    (sp)+,d0/a0        ; restore regs
  59.         bra.b    .end_startup        ; and run the user prog
  60.  
  61.     ; we were called from the Workbench
  62. .fromWorkbench:    lea    pr_MsgPort(a4),a0    ; our port
  63.         CALLEXEC WaitPort        ; wait for a message
  64.         lea    pr_MsgPort(a4),a0    ; our port
  65.         CALLEXEC GetMsg            ; then get it
  66.         move.l    d0,a3            ; save it for later reply
  67.         movem.l    (sp)+,d0/a0        ; restore
  68. .end_startup:    move.l    a3,-(sp)
  69.         bsr.b    .main            ; start the main program
  70.  
  71.     ; returns to here with exit code in d0
  72.         move.l    d0,-(sp)        ; save it
  73.  
  74.         tst.l    4(sp)
  75.         beq.b    .exitToDOS        ; if I was a CLI
  76.  
  77.         CALLEXEC Forbid
  78.         move.l    4(sp),a1
  79.         CALLEXEC ReplyMsg
  80.  
  81. .exitToDOS:    move.l    (sp)+,d0        ; exit code
  82.         addq.l    #4,sp
  83.         rts
  84.  
  85.     ; the program starts here
  86.         cnop    0,4            ; long word align
  87. .main:
  88.