home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
cbm
/
nduk-v37.lha
/
V37
/
startups
/
startup.asm
< prev
next >
Wrap
Assembly Source File
|
1991-11-12
|
27KB
|
800 lines
*------ startup.asm v 36.13
*
* Copyright (c) 1990 Commodore-Amiga, Inc.
*
*
*------
*------ Conditional assembly flags
*------ ASTART: 1=Standard Globals Defined 0=Reentrant Only
*------ WINDOW: 1=AppWindow for WB startup 0=No AppWindow code
*------ XNIL: 1=Remove startup NIL: init 0=Default Nil: WB Output
*------ NARGS: 1=Argv[0] only 0=Normal cmd line arg parse
*------ DEBUG: 1=Set up old statics for Wack 0=No extra statics
*------ QARG: 1=No argv 0=Passes argc,argv
* Include the appropriate startup.i (example rstartup.i) here or in
* your assem line
INCLUDE "allstartup.i"
* Flags for [A]start AWstart Rstart RWstart RXstart QStart
* ASTART 1 1 0 0 0 0
* WINDOW 0 1 0 1 0 0
* XNIL 0 0 0 0 1 1
* NARGS 0 0 0 0 0 0
* DEBUG 0 0 0 0 0 0
* QARG 0 0 0 0 0 1
;------ Flag WB output initialization
NNIL SET (1-XNIL)
WBOUT SET (ASTART!WINDOW!NNIL)
************************************************************************
*
* startup.asm --- Reentrant C Program Startup/Exit (CLI and WB)
* v36.13 011/07/90
*
* Copyright (c) 1988, 1990 Commodore-Amiga, Inc.
*
* Title to this software and all copies thereof remain vested in the
* authors indicated in the above copyright notice. The object version
* of this code may be used in software for Commodore Amiga computers.
* All other rights are reserved.
*
* NO REPRESENTATIONS OR WARRANTIES ARE MADE WITH RESPECT TO THE
* ACCURACY, RELIABILITY, PERFORMANCE OR OPERATION OF THIS SOFTWARE,
* AND ALL SUCH USE IS AT YOUR OWN RISK. NEITHER COMMODORE NOR THE
* AUTHORS ASSUME ANY RESPONSIBILITY OR LIABILITY WHATSOEVER WITH
* RESPECT TO YOUR USE OF THIS SOFTWARE.
*
*
* RSTARTUP.ASM
*
* Changes for 2.0 - since commands may now receive a >256 character command
* line, the argv buffer size is now dynamic, based on DosCmdLen passed in.
* The argv count is also dynamic, based on number of spaces in the command
* line.
*
* This startup dynamically allocates a structure which includes
* the argv buffers. If you use this startup, your code must return
* to this startup when it exits. Use exit(n) or final curly brace
* (rts) to return here. Do not use AmigaDOS Exit( ) function.
* Due to this dynamic allocation and some code consolidation, this
* startup can make executables several hundred bytes smaller.
*
* Because a static initialSP variable can not be used, this
* code depends on the fact that AmigaDOS places the address of
* the top of our stack in SP and proc->pr_ReturnAddr right before
* JSR'ing to us. This code uses pr_ReturnAddr when restoring SP.
*
* Most versions of startup will initialize a Workbench process's
* input and output streams (and stdio globals if present) to NIL:
* if no other form of Workbench output (like WINDOW) is provided.
* This should help prevent crashes if a user puts an icon on a CLI
* program, and will also protect against careless stdio debugging
* or error messages left in a Workbench program. The code for
* initializing Workbench IO streams only be removed by assembling
* startup with ASTART and WINDOW set to 0, and XNIL set to 1.
*
*
* Some startups which can be conditionally assembled:
*
* 1. Standard Astartup for non-reentrant code
* 2. Reentrant Rstartup (no unshareable globals)
* 3. Smaller reentrant-only RXstartup (no NIL: WB init code)
* 4. Standard AWstartup (WB output window) for non-reentrant code
* 5. Reentrant RWstartup (WB output window, no unshareable globals)
* 6. Smallest Qstartup (No argv - argv is ptr to NULL string)
*
*
* Explanation of conditional assembly flags:
*
* ASTART (ASTART SET 1) startups will set up and XDEF the
* global variables _stdin, _stdout, _stderr, _errno and _WBenchMsg.
* These startups can be used as smaller replacements for startups
* like (A)startup.obj and TWstartup.obj. Startups with ASTART
* would generally be used for non-reentrant programs, although the
* startup code itself is still reentrant if the globals are not
* referenced.
* Reentrant (ASTART SET 0) startups will NOT set up or
* XDEF the stdio and WBenchMsg globals. This not only makes the
* startup slightly smaller, but also lets you know if your code
* is referencing these non-reentrant globals (you will get an
* unresolved external reference when you link). Programs
* get their input and output handles from Input( ) and Output( ),
* and the WBenchMsg is passed in argv on Workbench startup.
*
* WINDOW (WINDOW SET 1) startups use an XREF'd CON: string
* named AppWindow, defined in your application, to open a stdio
* console window when your application is started from Workbench.
* For non-reentrant programs, this window can be used for normal
* stdio (printf, getchar, etc). For reentrant programs the window
* is Input( ) and Output( ). WINDOW is useful when adding Workbench
* capability to a stdio application, and also for debugging other
* Workbench applications. To insure that applications requiring
* a window startup are linked with a window startup, the label
* _NeedWStartup can be externed and referenced in the application
* so that a linker error will occur if linked with a standard
* startup.
*
* example: /* Optional safety reference to NeedWStartup */
* extern UBYTE NeedWStartup;
* UBYTE *HaveWStartup = &NeedWStartup;
* /* Required window specification */
* char AppWindow[] = "CON:30/30/200/150/MyProgram";
* ( OR char AppWindow[] = "\0"; for no window )
*
*
* XNIL (XNIL SET 1) allows the creation of a smaller startup
* by removing the code that initializes a Workbench process's
* output streams to NIL:. This flag can only remove the code
* if it is not required for ASTART or WINDOW.
*
* NARGS (NARGS SET 1) removes the code used to parse command line
* arguments. The command name is still passed to _main as argv[0].
* This option can take about 120 bytes off the size of any program that
* does not use command line args.
*
* DEBUG (DEBUG SET 1) will cause the old startup.asm statics
* initialSP, dosCmdLen and dosCmdBuf to be defined and initialized
* by the startup code, for use as debugging symbols when using Wack.
*
* QARG (QARG SET TO 1) will bypass all argument parsing. A CLI
* startup is passed argc == 1, and a Workbench startup is passed
* argc == 0. Argv[0] will be a pointer to a NULL string rather than
* a pointer to the command name. This option creates a very small
* startup with no sVar structure allocation, and therefore must be used
* with XNIL (it is incompatible with default or AWindow output options).
*
*
* RULES FOR REENTRANT CODE
*
* - Make no direct or indirect (printf, etc) references to the
* globals _stdin, _stdout, _stderr, _errno, or _WBenchMsg.
*
* - For stdio use either special versions of printf and getchar
* that use Input( ) and Output( ) rather than _stdin and _stdout,
* or use fprintf and fgetc with Input( ) and Output( ) file handles.
*
* - Workbench applications must get the pointer to the WBenchMsg
* from argv rather than from a global extern WBenchMsg.
*
* - Use no global or static variables within your code. Instead,
* put all former globals in a dynamically allocated structure, and
* pass around a pointer to that structure. The only acceptable
* globals are constants (message strings, etc) and global copies
* of Library Bases to resolve Amiga.lib references. Your code
* must return all OpenLibrary's into non-global variables,
* copy the result to the global library base only if successful,
* and use the non-globals when deciding whether to Close any
*