home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / assembler / thesource / volume4 / source / startupcode / wb_startup.i < prev   
Encoding:
Text File  |  1993-03-22  |  2.4 KB  |  115 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 after any other includes.
  6. *
  7. * This code originally came from the DevPac 2.08 disk.  It has been
  8. * heavily modified, though, by the Dancing Fool of Epsilon.
  9. *
  10. * Revision history:
  11. * 1.1:
  12. *    Added the CALL macro for some optimization.
  13. *
  14. * 1.0:
  15. *    Original release.
  16. *
  17. ***********************************************************
  18.  
  19.         incdir    'include/'
  20.  
  21.         IFND    EXEC_EXEC_I
  22.         include    'exec/exec.i'
  23.         ENDIF
  24.  
  25.         IFND    LIBRARIES_DOSEXTENS_I
  26.         include    'libraries/dosextens.i'
  27.         ENDIF
  28.  
  29.         incdir    ''
  30.  
  31. ***********************************************************
  32. * Other Macros
  33. ***********************************************************
  34.  
  35.  IFND    CALLEXEC
  36. CALLEXEC    MACRO
  37.         movea.l    4.w,a6
  38.         jsr    _LVO\1(a6)
  39.         ENDM
  40.  ENDIF
  41.  
  42.  IFND    CALL
  43. CALL        MACRO
  44.         jsr    _LVO\1(a6)
  45.         ENDM
  46.  ENDIF
  47.  
  48. ***********************************************************
  49. * Other Equates
  50. ***********************************************************
  51.  
  52.  IFND    _LVOFindTask
  53. _LVOFindTask    EQU    -$126
  54.  ENDIF
  55.  
  56.  IFND _LVOWaitPort
  57. _LVOWaitPort    EQU    -$180
  58.  ENDIF
  59.  
  60.  IFND _LVOGetMsg
  61. _LVOGetMsg    EQU    -$174
  62.  ENDIF
  63.  
  64.  IFND _LVOReplyMsg
  65. _LVOReplyMsg    EQU    -$17a
  66.  ENDIF
  67.  
  68.  IFND _LVOForbid
  69. _LVOForbid    EQU    -$84
  70.  ENDIF
  71.  
  72. ***********************************************************
  73.  
  74. WBStartUp:    movem.l    d0/a0,-(sp)        ; save initial values
  75.         suba.l    a3,a3
  76.  
  77.         suba.l    a1,a1            ; clear out
  78.         CALLEXEC FindTask        ; find us
  79.         move.l    d0,a4            ; save our pointer in a4
  80.  
  81.         tst.l    pr_CLI(a4)        ; are we from the cli?
  82.         beq.b    .fromWorkbench        ; nope, do other stuff...
  83.  
  84.     ; we were called from the CLI
  85.         movem.l    (sp)+,d0/a0        ; restore regs
  86.         bra.b    .end_startup        ; and run the user prog
  87.  
  88.     ; we were called from the Workbench
  89. .fromWorkbench:    lea    pr_MsgPort(a4),a0    ; our port
  90.         CALL     WaitPort        ; wait for a message
  91.         lea    pr_MsgPort(a4),a0    ; our port
  92.         CALL    GetMsg            ; then get it
  93.         move.l    d0,a3            ; save it for later reply
  94.         movem.l    (sp)+,d0/a0        ; restore
  95. .end_startup:    move.l    a3,-(sp)
  96.         bsr.b    .main            ; start the main program
  97.  
  98.     ; returns to here with exit code in d0
  99.         move.l    d0,-(sp)        ; save it
  100.  
  101.         tst.l    4(sp)
  102.         beq.b    .exitToDOS        ; if I was a CLI
  103.  
  104.         CALLEXEC Forbid
  105.         movea.l    4(sp),a1
  106.         CALL     ReplyMsg
  107.  
  108. .exitToDOS:    move.l    (sp)+,d0        ; exit code
  109.         addq.w    #4,sp
  110.         rts
  111.  
  112.     ; the program starts here
  113.         cnop    0,4            ; long word align
  114. .main:
  115.