home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / cbm / nduk-v40.lha / V40 / startups / startup.asm < prev    next >
Assembly Source File  |  1991-11-12  |  27KB  |  800 lines

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