home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
dev
/
c
/
rkrm
/
workbench
/
startup2.0
/
startup.asm
< prev
Wrap
Assembly Source File
|
1992-09-03
|
28KB
|
831 lines
*
* Copyright (c) 1990 Commodore-Amiga, Inc.
*
* This example is provided in electronic form by Commodore-Amiga, Inc. for
* use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition,
* published by Addison-Wesley (ISBN 0-201-56775-X).
*
* The "Amiga ROM Kernel Reference Manual: Devices" contains additional
* information on the correct usage of the techniques and operating system
* functions presented in these examples. The source and executable code
* of these examples may only be distributed in free electronic form, via
* bulletin board or as part of a fully non-commercial and freely
* redistributable diskette. Both the source and executable code (including
* comments) must be included, without modification, in any copy. This
* example may not be published in printed form or distributed with any
* commercial product. However, the programming techniques and support
* routines set forth in these examples may be used in the development
* of original executable software products for Commodore Amiga computers.
*
* All other rights reserved.
*
* This example is provided "as-is" and is subject to change; no
* warranties are made. All use is at your own risk. No liability or
* responsibility is assumed.
*
**********************************************************************
*
*------ 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 startu