home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / workbench / startup2.0 / startup.asm < prev   
Assembly Source File  |  1992-09-03  |  28KB  |  831 lines

  1. *
  2. * Copyright (c) 1990 Commodore-Amiga, Inc.
  3. * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  4. * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  5. * published by Addison-Wesley (ISBN 0-201-56775-X).
  6. * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  7. * information on the correct usage of the techniques and operating system 
  8. * functions presented in these examples.  The source and executable code 
  9. * of these examples may only be distributed in free electronic form, via 
  10. * bulletin board or as part of a fully non-commercial and freely 
  11. * redistributable diskette.  Both the source and executable code (including 
  12. * comments) must be included, without modification, in any copy.  This 
  13. * example may not be published in printed form or distributed with any
  14. * commercial product.  However, the programming techniques and support
  15. * routines set forth in these examples may be used in the development
  16. * of original executable software products for Commodore Amiga computers.
  17. * All other rights reserved.
  18. * This example is provided "as-is" and is subject to change; no
  19. * warranties are made.  All use is at your own risk. No liability or
  20. * responsibility is assumed.
  21. *
  22. **********************************************************************
  23. *
  24. *------ startup.asm  v 36.13
  25. *
  26. **********************************************************************
  27.  
  28.  
  29. *
  30. * Copyright (c) 1990 Commodore-Amiga, Inc.
  31. *
  32. *
  33. *------
  34. *------ Conditional assembly flags
  35. *------ ASTART:   1=Standard Globals Defined    0=Reentrant Only
  36. *------ WINDOW:   1=AppWindow for WB startup    0=No AppWindow code
  37. *------ XNIL:     1=Remove startup NIL: init    0=Default Nil: WB Output
  38. *------ NARGS:    1=Argv[0] only                0=Normal cmd line arg parse
  39. *------ DEBUG:    1=Set up old statics for Wack 0=No extra statics
  40. *------ QARG:     1=No argv                     0=Passes argc,argv
  41.  
  42. * Include the appropriate startup.i (example rstartup.i) here or in
  43. * your assem line
  44.  
  45.         INCLUDE "allstartup.i"
  46.  
  47. * Flags for  [A]start  AWstart  Rstart  RWstart  RXstart  QStart
  48. * ASTART         1        1       0        0        0       0
  49. * WINDOW         0        1       0        1        0       0
  50. * XNIL           0        0       0        0        1       1
  51. * NARGS          0        0       0        0        0       0
  52. * DEBUG          0        0       0        0        0       0
  53. * QARG           0        0       0        0        0       1
  54.  
  55. ;------   Flag WB output initialization
  56. NNIL      SET    (1-XNIL)
  57. WBOUT     SET   (ASTART!WINDOW!NNIL)
  58.  
  59. ************************************************************************
  60. *
  61. *   startup.asm --- Reentrant C Program Startup/Exit (CLI and WB)
  62. *                   v36.13  011/07/90
  63. *
  64. *   Copyright (c) 1988, 1990 Commodore-Amiga, Inc.
  65. *
  66. *   Title to this software and all copies thereof remain vested in the
  67. *   authors indicated in the above copyright notice.  The object version
  68. *   of this code may be used in software for Commodore Amiga computers.
  69. *   All other rights are reserved.
  70. *
  71. *   NO REPRESENTATIONS OR WARRANTIES ARE MADE WITH RESPECT TO THE
  72. *   ACCURACY, RELIABILITY, PERFORMANCE OR OPERATION OF THIS SOFTWARE,
  73. *   AND ALL SUCH USE IS AT YOUR OWN RISK.  NEITHER COMMODORE NOR THE
  74. *   AUTHORS ASSUME ANY RESPONSIBILITY OR LIABILITY WHATSOEVER WITH
  75. *   RESPECT TO YOUR USE OF THIS SOFTWARE.
  76. *
  77. *
  78. *   RSTARTUP.ASM
  79. *
  80. *  Changes for 2.0 - since commands may now receive a >256 character command
  81. *  line, the argv buffer size is now dynamic, based on DosCmdLen passed in.
  82. *  The argv count is also dynamic, based on number of spaces in the command
  83. *  line.
  84. *
  85. *      This startup dynamically allocates a structure which includes
  86. *   the argv buffers.  If you use this startup, your code must return
  87. *   to this startup when it exits.  Use exit(n) or final curly brace
  88. *   (rts) to return here.  Do not use AmigaDOS Exit( ) function.
  89. *   Due to this dynamic allocation and some code consolidation, this
  90. *   startup can make executables several hundred bytes smaller.
  91. *
  92. *       Because a static initialSP variable can not be used, this
  93. *   code depends on the fact that AmigaDOS places the address of
  94. *   the top of our stack in SP and proc->pr_ReturnAddr right before
  95. *   JSR'ing to us.  This code uses pr_ReturnAddr when restoring SP.
  96. *
  97. *       Most versions of startup will initialize a Workbench process's
  98. *   input and output streams (and stdio globals if present) to NIL:
  99. *   if no other form of Workbench output (like WINDOW) is provided.
  100. *   This should help prevent crashes if a user puts an icon on a CLI
  101. *   program, and will also protect against careless stdio debugging
  102. *   or error messages left in a Workbench program.  The code for
  103. *   initializing Workbench IO streams only be removed by assembling
  104. *   startup with ASTART and WINDOW set to 0, and XNIL set to 1.
  105. *
  106. *
  107. *   Some startups which can be conditionally assembled:
  108. *
  109. *      1. Standard Astartup for non-reentrant code
  110. *      2. Reentrant Rstartup (no unshareable globals)
  111. *      3. Smaller reentrant-only RXstartup (no NIL: WB init code)
  112. *      4. Standard AWstartup (WB output window) for non-reentrant code
  113. *      5. Reentrant RWstartup (WB output window, no unshareable globals)
  114. *      6. Smallest Qstartup  (No argv - argv is ptr to NULL string)
  115. *
  116. *
  117. *   Explanation of conditional assembly flags:
  118. *
  119. *      ASTART (ASTART SET 1) startups will set up and XDEF the
  120. *   global variables _stdin, _stdout, _stderr, _errno and  _WBenchMsg.
  121. *   These startups can be used as smaller replacements for startups
  122. *   like (A)startup.obj and TWstartup.obj.  Startups with ASTART
  123. *   would generally be used for non-reentrant programs, although the
  124. *   startup code itself is still reentrant if the globals are not
  125. *   referenced.
  126. *      Reentrant (ASTART SET 0) startups will NOT set up or
  127. *   XDEF the stdio and WBenchMsg globals.  This not only makes the
  128. *   startup slightly smaller, but also lets you know if your code
  129. *   is referencing these non-reentrant globals (you will get an
  130. *   unresolved external reference when you link).  Programs
  131. *   get their input and output handles from Input( ) and Output( ),
  132. *   and the WBenchMsg is passed in argv on Workbench startup.
  133. *
  134. *      WINDOW (WINDOW SET 1) startups use an XREF'd CON: string
  135. *   named AppWindow, defined in your application, to open a stdio
  136. *   console window when your application is started from Workbench.
  137. *   For non-reentrant programs, this window can be used for normal
  138. *   stdio (printf, getchar, etc).  For reentrant programs the window
  139. *   is Input( ) and Output( ).  WINDOW is useful when adding Workbench
  140. *   capability to a stdio application, and also for debugging other
  141. *   Workbench applications.  To insure that applications requiring
  142. *   a window startup are linked with a window startup, the label
  143. *   _NeedWStartup can be externed and referenced in the application
  144. *   so that a linker error will occur if linked with a standard
  145. *   startup.
  146. *
  147. *       example:   /* Optional safety reference to NeedWStartup */
  148. *                    extern UBYTE  NeedWStartup;
  149. *                    UBYTE  *HaveWStartup = &NeedWStartup;
  150. *                  /* Required window specification */
  151. *                    char AppWindow[] = "CON:30/30/200/150/MyProgram";
  152. *                    ( OR  char AppWindow[] = "\0";  for no window )
  153. *
  154. *
  155. *      XNIL (XNIL SET 1) allows the creation of a smaller startup
  156. *   by removing the code that initializes a Workbench process's
  157. *   output streams to NIL:.  This flag can only remove the code
  158. *   if it is not required for ASTART or WINDOW.
  159. *
  160. *      NARGS (NARGS SET 1) removes the code used to parse command line
  161. *   arguments.  The command name is still passed to _main as argv[0].
  162. *   This option can take about 120 bytes off the size of any program that
  163. *   does not use command line args.
  164. *
  165. *      DEBUG (DEBUG SET 1) will cause the old startup.asm statics
  166. *   initialSP, dosCmdLen and dosCmdBuf to be defined and initialized
  167. *   by the startup code, for use as debugging symbols when using Wack.
  168. *
  169. *      QARG (QARG SET TO 1) will bypass all argument parsing.  A CLI
  170. *   startup is passed argc == 1, and a Workbench startu