		IFND DEBUG_I
DEBUG_I         SET 1
**
**      $VER: debug.i 2.0 (9.11.97)
**
**      Structures and macros for the debug.library
**      68K version
**
		IFND    EXEC_TYPES_I
		include exec/types.i
		ENDC

* Note: set the extension flags to 0!

*  possible values for DB_DEBUG and DB_IN_COUNTER
DB_ON           =       -1
DB_OFF          =       0

*
*       Symbol Structure
*

	STRUCTURE       DB_SS,0
	APTR            DB_SS_NAME      ; Pointer to symbol name
	APTR            DB_SS_COMMENT   ; Pointer to comment string
	LONG            DB_SS_VALUE     ; Value of the symbol
	UBYTE           DB_SS_GROUP_ID  ; Group ID
	UBYTE           DB_SS_EL_SIZE   ; Element size (only for AddValue)
	UBYTE           DB_SS_EXT       ; Flag for future extensions (BOOL)
	UBYTE           DB_SS_PAD       ; pad byte
	LABEL           DB_SS_SIZE

DB_MASK         =       $7f             ; private!

*       Possible values for DB_MC_SIZE / DB_IV_SIZE
DB_BYTE         =       $01
DB_UBYTE        =       $81
DB_WORD         =       $02
DB_UWORD        =       $82
DB_LONG         =       $04
DB_ULONG        =       $84
DB_FLOAT        =       $08             ;single precision (new vor V1.1)
DB_DOUBLE       =       $10             ;double precision (new vor V1.1)

*** Notes to DB_FLOAT and DB_DOUBLE: The value passed in DB_SS_VALUE/
*** DB_MC_VALUE (Symbol Structure / MemContent Struture) must be a POINTER
*** to the floating point number.

*       Possible values for DB_MC_TYPE / DB_IV_TYPE
DB_HEX          =       0
DB_DEC          =       1

*
*       MemContent Structure
*

	STRUCTURE       DB_MC,0
	APTR            DB_MC_NAME      ; Pointer to symbol name
	APTR            DB_MC_COMMENT   ; Pointer to comment string
	APTR            DB_MC_VALUE     ; Address of the symbol (array location)
	UWORD           DB_MC_COUNT     ; Number of elements to display
	UBYTE           DB_MC_GROUP_ID  ; Group ID
	UBYTE           DB_MC_EL_SIZE   ; Element size
	UBYTE           DB_MC_COLUMN    ; Number of columns to display
	UBYTE           DB_MC_TYPE      ; Display type (i.e. Hex/Dec)
	UBYTE           DB_MC_EXT       ; Flag for future extensions (BOOL)
	UBYTE           DB_MC_PAD       ; pad byte
	LABEL           DB_MC_SIZE

*       Possible values for DB_MD_NOASCII
DB_ASCII        =       0
DB_NOASCII      =       1

*
*       MemDump Structure
*

	STRUCTURE       DB_MD,0
	APTR            DB_MD_NAME      ; Pointer to symbol name
	APTR            DB_MD_COMMENT   ; Pointer to comment string
	APTR            DB_MD_VALUE     ; Address of the symbol (memory location)
	ULONG           DB_MD_MEMSIZE   ; Size of memory area to display
	UBYTE           DB_MD_GROUP_ID  ; Group ID
	UBYTE           DB_MD_NOASCII   ; flag to enable/disable ascii output
	UBYTE           DB_MD_EXT       ; Flag for future extensions (BOOL)
	UBYTE           DB_MD_PAD       ; pad byte
	LABEL           DB_MD_SIZE





*
*       Index Structure
*

	STRUCTURE       DB_IN,0
	APTR            DB_IN_COMMENT   ; Pointer to comment string
	UWORD           DB_IN_STARTINX  ; start index
	UWORD           DB_IN_STOPINX   ; end index
	UBYTE           DB_IN_COUNTER   ; index column enable
	UBYTE           DB_IN_GROUP_ID  ; Group ID
	UBYTE           DB_IN_EXT       ; flag for future extensions (BOOL)
	UBYTE           DB_IN_PAD       ; pad byte
	LABEL           DB_IN_SIZE

*
*       IndexVar Structure
*

	STRUCTURE       DB_IV,0
	APTR            DB_IV_NAME      ; Pointer to symbol name
	APTR            DB_IV_COMMENT   ; Pointer to comment string
	APTR            DB_IV_VALUE     ; symbol value
	ULONG           DB_IV_INDEX_ID  ; index id (returned by InitIndex)
	UBYTE           DB_IV_EL_SIZE   ; Element size
	UBYTE           DB_IV_TYPE      ; Display type (i.e. Hex/Dec)
	UBYTE           DB_IV_EXT       ; Flag for future extensions (BOOL)
	UBYTE           DB_IV_PAD       ; pad byte
	LABEL           DB_IV_SIZE

*
*       RegDump Structure
*

	STRUCTURE       DB_RD,0
	APTR            DB_RD_COMMENT   ; Pointer to comment string
	APTR            DB_RD_REGLIST   ; Pointer to register array
	UBYTE           DB_RD_GROUP_ID  ; Group ID
	UBYTE           DB_RD_EXT       ; Flag for future extensions (BOOL)
	LABEL           DB_RD_SIZE

*       Register array: 16 Longwords containing the registers d0 - a7
REGARRAY_SIZE   =       16*4


*
*       Count Structure
*

	STRUCTURE       DB_CO,0
	APTR            DB_CO_COMMENT   ; Pointer to comment string
	APTR            DB_CO_ADDRESS   ; address of the counter (ULONG*)
	UBYTE           DB_CO_GROUP_ID  ; Group ID
	UBYTE           DB_CO_EXT
	LABEL           DB_CO_SIZE


*
*       Profiler Structure
*

	STRUCTURE       DB_PR,0
	APTR            DB_PR_NAME      ; Pointer to function name
	APTR            DB_PR_COMMENT   ; Pointer to comment string
	APTR            DB_PR_PTR       ; Pointer to internal ProfStruct / 0
	UBYTE           DB_PR_EXT       ; Flag for future extensions (BOOL)
	UBYTE           DB_PR_PAD       ; pad byte
	LABEL           DB_PR_SIZE


*       Possible values for DB_LA_DISPLAY
DB_NONE         =       0
DB_GROUP        =       1
DB_SEQ          =       2
DB_PROF         =       4
DB_ALL          =       DB_GROUP!DB_SEQ!DB_PROF

*
*       Layout Structure
*

	STRUCTURE       DB_LA,0
	APTR            DB_LA_FOLDSTART ; -> GoldEd Fold Marker (Start) or NULL
	APTR            DB_LA_FOLDEND   ; -> GoldEd Fold Marker (End) or NULL
	UBYTE           DB_LA_DISPLAY   ; Display type: standard / sequential
	UBYTE           DB_LA_COLUMN    ; Num of columns for standard output
	UBYTE           DB_LA_SYMPOS    ; Position of the symbol values
	UBYTE           DB_LA_MCPOS     ; Position of the memcont values
	UBYTE           DB_LA_COPOS     ; Position of the count value
	UBYTE           DB_LA_PROPOS    ; Position of the profiler values
	UBYTE           DB_LA_EXT       ; Flag for future extensions (BOOL)
	UBYTE           DB_LA_PAD       ; pad byte
	LABEL           DB_LA_SIZE

****************************   LVO's of the debug.library

_LVOAllocDebug  =       -30
_LVOFreeDebug   =       -36
_LVOAllocGroup  =       -42
_LVOAddSym      =       -48
_LVOAddValue    =       -54
_LVOAddArray    =       -60
_LVOAddDump     =       -66
_LVOAddRegDump  =       -72
_LVOInitIndex   =       -78
_LVOAddInxVar   =       -84
_LVOSetMark     =       -90
_LVOWriteDebug  =       -96
_LVOCount       =       -102
_LVOStartTimer  =       -108
_LVOStopTimer   =       -114

****************************   Macros and default values

DB_DEBUG        set     DB_ON           ;switch on/off the debugging system
DB_GROUPPRI     set     0               ;default group priority
DB_DEFSIZE      set     DB_ULONG        ;default size for AddValue/AddArray
DB_DEFCOUNT     set     1               ;default count for AddArray
DB_DEFCOLUMN    set     4               ;default column for AddArray
DB_DEFTYPE      set     DB_HEX          ;default type for AddArray
DB_DEFMEMSIZE   set     128             ;default memsize for AddDump
DB_STARTINX     set     1               ;default index start
DB_STOPINX      set     65535           ;default index stop
DB_INXFLAG      set     DB_ON           ;default index flag
DB_DISPTYPE     set     DB_ALL          ;default output formatting      
DB_DUMPFLAG     set     DB_ASCII        ;default flag for ascii output (memdump)
DB_DISPCOLUMN   set     60              ;default number of column
DB_DEFSYMPOS    set     36              ;default value pos for symbol output
DB_DEFMCPOS     set     30              ;default value pos for memcont output
DB_DEFCOPOS     set     30              ;default value pos for count output
DB_DEFPROPOS    set     30              ;default value pos for profiler output


*       !!!!!!!!!  Note: Use of the macros modifies the CCR !!!!!!!!!!

;--------------------------------------
*
*  DB_OPENDEBUG
*
*  Opens the debug.library

DB_OPENDEBUG    macro
		IFNE    DB_DEBUG
			movem.l d0/d1/a0/a1/a6,-(sp)
			move.l  $4.w,a6
			moveq   #0,d0
			lea     debugname,a1
			jsr     -552(a6)                ;OpenLibrary
			move.l  d0,_DebugBase
			movem.l (sp)+,d0/d1/a0/a1/a6
			IFND    _DebugBase
			bra.b   end\@

debugname                       dc.b    "debug.library",0
				cnop    0,4
_DebugBase                      dc.l    0
end\@
			ENDC
		ENDC
		endm

;--------------------------------------
*
*  DB_CLOSEDEBUG
*
*  Closes the debug.library

DB_CLOSEDEBUG   macro
		IFNE    DB_DEBUG
			movem.l d0/d1/a0/a1/a6,-(sp)
			move.l  $4.w,a6
			move.l  _DebugBase,d0
			beq.b   .noclose\@
			move.l  d0,a1
			jsr     -414(a6)                        ;CloseLibrary
.noclose\@
			movem.l (sp)+,d0/d1/a0/a1/a6
		ENDC
		endm

;--------------------------------------
*
*  DB_ALLOCDEBUG        DebugVar,BufferSize
*
*  Starts a new debug session
*
*  DebugVar  : Variable that is needed by all other macros
*  BufferSize: Size of memory to be allocated

DB_ALLOCDEBUG   macro
		IFNE    DB_DEBUG
			IFNE    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			movem.l d0/d1/a0/a1/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  #\2,d0
			jsr     _LVOAllocDebug(a6)              ;AllocDebug
			move.l  d0,\1
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a6
			bra.b   end\@
\1                      dc.l    0
end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_FREEDEBUG         DebugVar
*
*  Ends the specified debug session
*
*  DebugVar  : Variable returned by AllocDebug

DB_FREEDEBUG    macro
		IFNE    DB_DEBUG
			IFNE    NARG-1
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			movem.l d0/d1/a0/a1/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			jsr     _LVOFreeDebug(a6)               ;FreeDebug
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a6
		ENDC
		endm


;--------------------------------------
*
*  DB_ALLOCGROUP        DebugVar,GroupVar,[GroupName],[Priority]
*
*  Allocates a new debug group
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable needed by other macros
*  GroupName : Name of this group [optional]
*  Priority  : Priority of this group [optional]
*              If Priority is omitted, DB_GROUPPRI is taken for default

DB_ALLOCGROUP   macro
		IFNE    DB_DEBUG
			IFGT    NARG-4
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\2"
				FAIL    "Missing GroupVar"
				mexit
			ENDC

			movem.l d0/d1/a0/a1/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			IFC     "","\4"
				moveq   #DB_GROUPPRI,d0
			ELSEIF
				move.l  #\4,d0
			ENDC
			IFC     "","\3"
				sub.l   a1,a1
			ELSEIF
				lea     name\@,a1
			ENDC
			jsr     _LVOAllocGroup(a6)              ;AllocGroup
			move.b  d0,\2
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a6
			bra.b   end\@

			IFNC    "","\3"
name\@                          dc.b    "\3",0
			ENDC
\2                      dc.b    0
			cnop    0,4
end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDSYM    DebugVar,[GroupVar],Symbolname,[Comment]
*
*  Adds a new symbol to the debug structure
*  In case of absolute symbols, the value of the symbol is added,
*  in case of relative symbols, their address is added
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  Symbolname: name of the symbol to be added to the debug structure
*  Comment   : comment that should be displayed in the output file [optional]

DB_ADDSYM       macro
		IFNE    DB_DEBUG
			IFGT    NARG-4
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing Symbolname"
			mexit
			ENDC

			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_SS_SIZE
			sub     #DB_SS_SIZE,a5
			move.l  a5,a1
			move.l  #.name\@,DB_SS_NAME(a1)
			IFC     "","\4"
				clr.l   DB_SS_COMMENT(a1)
			ELSEIF
				move.l  #.comment\@,DB_SS_COMMENT(a1)
			ENDC
			move.l  #\3,DB_SS_VALUE(a1)
			IFC     "","\2"
				clr.b   DB_SS_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_SS_GROUP_ID(a1)
			ENDC
			clr.b   DB_SS_EXT(a1)
			jsr     _LVOAddSym(a6)                 ;AddSym
			add     #DB_SS_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			bra.b   .end\@

.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDVALUE  DebugVar,[GroupVar],Symbolname,[Comment],[Size]
*
*  Adds a new memory content/register to the debug structure
*  Should never be used with absolute symbols
*  In case of a relative symbol, the content of this symbol is added
*  In case of registers, the content of the register is added
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  Symbolname: name of the symbol to be added to the debug structure
*              only relative symbols and registers should be specified
*  Comment   : comment that should be displayed in the output file [optional]
*  Size      : Size of the memory content (see above at 'Symbol Structure'
*              for possible values) [optional]
*              If the size is omitted, DB_DEFSIZE is taken for default


DB_ADDVALUE     macro
		IFNE    DB_DEBUG
			IFGT    NARG-5
				FAIL    "Wrong number of arguments"
			mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing Value"
				mexit
			ENDC
			IFNC    "","\5"
				IFNE    (\5&DB_MASK)-DB_BYTE
				    IFNE    (\5&DB_MASK)-DB_WORD
					IFNE    (\5&DB_MASK)-DB_LONG
					    IFNE    (\5&DB_MASK)-DB_FLOAT
						IFNE    (\5&DB_MASK)-DB_DOUBLE
							FAIL    "Illegal Size"
						ENDC
					    ENDC
					ENDC
				    ENDC
				ENDC
			ENDC

			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					fmovem.x        fp0,-(sp)
					fmove.s \3,fp0
					fmove.d fp0,.double\@
					move.l  #.double\@,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					fmovem.x        fp0,-(sp)
					fmove.d \3,fp0
					fmove.d fp0,.double\@
					move.l  #.double\@,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_BYTE
					move.b  \3,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_WORD
					move    \3,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_LONG
					move.l  \3,d0
				ENDC
			ELSEIF
				move.l  \3,d0
			ENDC
			move.l  _DebugBase,d1
			beq.b   .nodebug\@
			move.l  d1,a6
			move.l  \1,a0
			link    a5,#-DB_SS_SIZE
			sub     #DB_SS_SIZE,a5
			move.l  a5,a1
			move.l  #.name\@,DB_SS_NAME(a1)
			IFC     "","\4"
				clr.l   DB_SS_COMMENT(a1)
			ELSEIF
				move.l  #.comment\@,DB_SS_COMMENT(a1)
			ENDC
			IFC     "","\2"
				clr.b   DB_SS_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_SS_GROUP_ID(a1)
			ENDC
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_BYTE
					move.b  d0,DB_SS_VALUE+3(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_WORD
					move    d0,DB_SS_VALUE+2(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_LONG
					move.l  d0,DB_SS_VALUE(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					move.l  d0,DB_SS_VALUE(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					move.l  d0,DB_SS_VALUE(a1)
				ENDC
			ELSEIF
				move.l  d0,DB_SS_VALUE(a1)
			ENDC
			IFC     "","\5"
				move.b  #DB_DEFSIZE,DB_SS_EL_SIZE(a1)
			ELSEIF
				move.b  #\5,DB_SS_EL_SIZE(a1)
			ENDC
			clr.b   DB_SS_EXT(a1)
			jsr     _LVOAddValue(a6)                 ;AddValue
			add     #DB_SS_SIZE,a5
			unlk    a5
.nodebug\@
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					fmovem.x        (sp)+,fp0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					fmovem.x        (sp)+,fp0
				ENDC
			ENDC
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			bra.b   .end\@
.double\@               dc.l    2,0
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDARRAY  DebugVar,[GroupVar],Symbolname,[Comment],[Size],[Count]
*               [Columns],[Type]
*
*  Adds a new array definition to the debug structure
*  'Count' elements of the size 'Size' at the symbol 'Symbolname' are
*  displayed in 'column' Columns.
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  Symbolname: name of the symbol to be added to the debug structure
*              only relative symbols should be used (registers don't work)
*  Comment   : comment that should be displayed in the output file [optional]
*  Size      : Size of an element (see above at 'Symbol Structure'
*              for possible values) [optional]
*              If the size is omitted, DB_DEFSIZE is taken for default
*  Count     : Number of elements [optional]
*            : If the count is omitted, count is set to DB_DEFCOUNT by default
*  Columns   : Number of columns for the array output [optional]
*            : If Columns is omitted, Columns is set to DB_DEFCOLUMN by default
*  Type      : Displays the values either in hex or in decimal notation
*              (see above at 'MemContent Struture' for possible values)
*              [optional]
*              If Type is omitted, DB_DEFTYPE is taken for default

DB_ADDARRAY     macro
		IFNE    DB_DEBUG
			IFGT    NARG-8
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing Symbolname"
				mexit
			ENDC
			IFNC    "","\5"
				IFNE    (\5&DB_MASK)-DB_BYTE
				    IFNE    (\5&DB_MASK)-DB_WORD
					IFNE    (\5&DB_MASK)-DB_LONG
					    IFNE    (\5&DB_MASK)-DB_FLOAT
						IFNE    (\5&DB_MASK)-DB_DOUBLE
							FAIL    "Illegal Size"
						ENDC
					    ENDC
					ENDC
				    ENDC
				ENDC
			ENDC

			movem.l d0/d1/a0-a2/a5/a6,-(sp)
			lea     \3,a2
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_MC_SIZE
			sub     #DB_MC_SIZE,a5
			move.l  a5,a1
			move.l  #.name\@,DB_MC_NAME(a1)
			IFC     "","\4"
				clr.l   DB_MC_COMMENT(a1)
			ELSEIF
				move.l  #.comment\@,DB_MC_COMMENT(a1)
			ENDC
			move.l  a2,DB_MC_VALUE(a1)
			IFC     "","\2"
				clr.b   DB_MC_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_MC_GROUP_ID(a1)
			ENDC
			IFC     "","\5"
				move.b  #DB_DEFSIZE,DB_MC_EL_SIZE(a1)
			ELSEIF
				move.b  #\5,DB_MC_EL_SIZE(a1)
			ENDC
			IFC     "","\6"
				move    #DB_DEFCOUNT,DB_MC_COUNT(a1)
			ELSEIF
				move    #\6,DB_MC_COUNT(a1)
			ENDC
			IFC     "","\7"
				move.b  #DB_DEFCOLUMN,DB_MC_COLUMN(a1)
			ELSEIF
				move.b  #\7,DB_MC_COLUMN(a1)
			ENDC
			IFC     "","\8"
				move.b  #DB_DEFTYPE,DB_MC_TYPE(a1)
			ELSEIF
				move.b  #\8,DB_MC_TYPE(a1)
			ENDC
			clr.b   DB_MC_EXT(a1)
			jsr     _LVOAddArray(a6)                 ;AddArray
			add     #DB_MC_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0-a2/a5/a6
			bra.b   .end\@

.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDDUMP   DebugVar,[GroupVar],Symbolname,[Comment],[MemSize],[ASCIIFlag]
*
*  Adds a new memdump definition to the debug structure
*  MemSize bytes from the position at Symbolname are displayed in the
*  output file
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  Symbolname: name of the symbol to be added to the debug structure
*              only relative symbols should be used (registers don't work)
*  Comment   : comment that should be displayed in the output file [optional]
*  MemSize   : Size of the memory to be printed to the output file [optional]
*              If Memsize is omitted, a size of DB_DEFMEMSIZE bytes is taken
*              for default
*  ASCIIFlag : flag to enable/disable ASCII output [optional]. If omitted,
*              DB_DUMPFLAG is taken for default

DB_ADDDUMP      macro
		IFNE    DB_DEBUG
			IFGT    NARG-6
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing Symbolname"
				mexit
			ENDC

			movem.l d0/d1/a0-a2/a5/a6,-(sp)
			lea     \3,a2
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_MD_SIZE
			sub     #DB_MD_SIZE,a5
			move.l  a5,a1
			move.l  #.name\@,DB_MD_NAME(a1)
			IFC     "","\4"
				clr.l   DB_MD_COMMENT(a1)
			ELSEIF
				move.l  #.comment\@,DB_MD_COMMENT(a1)
			ENDC
			move.l  a2,DB_MC_VALUE(a1)
			IFC     "","\2"
				clr.b   DB_MD_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_MD_GROUP_ID(a1)
			ENDC
			IFC     "","\5"
				move.l  #DB_DEFMEMSIZE,DB_MD_MEMSIZE(a1)
			ELSEIF
				move.l  #\5,DB_MD_MEMSIZE(a1)
			ENDC
			IFC     "","\6"
				move.b  #DB_DUMPFLAG,DB_MD_NOASCII(a1)
			ELSEIF
				move.b  #\6,DB_MD_NOASCII(a1)
			ENDC
			clr.b   DB_MD_EXT(a1)
			jsr     _LVOAddDump(a6)                 ;AddDump
			add     #DB_MD_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0-a2/a5/a6
			bra.b   .end\@

.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDREGDUMP        DebugVar,[GroupVar],[Comment]
*
*  Adds a new register dump definition to the debug structure
*  All 16 register contents are stored into the debug
*  structure
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  Comment   : comment that should be displayed in the output file [optional]

DB_ADDREGDUMP   macro
		IFNE    DB_DEBUG
			IFGT    NARG-3
				FAIL    "Wrong number of arguments"
			mexit
			ENDC
			IFLT    NARG-1
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC

			lea     -REGARRAY_SIZE(sp),sp
			movem.l d0-a7,(sp)
			add.l   #REGARRAY_SIZE,60(sp)
			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  sp,d0
			add.l   #6*4,d0
			move.l  _DebugBase,d1
			beq.b   .nodebug\@
			move.l  d1,a6
			move.l  \1,a0
			link    a5,#-DB_RD_SIZE
			sub     #DB_RD_SIZE,a5
			move.l  a5,a1
			IFC     "","\3"
				clr.l   DB_RD_COMMENT(a1)
			ELSEIF
				move.l  #.comment\@,DB_RD_COMMENT(a1)
			ENDC
			move.l  d0,DB_RD_REGLIST(a1)
			IFC     "","\2"
				clr.b   DB_RD_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_RD_GROUP_ID(a1)
			ENDC
			clr.b   DB_RD_EXT(a1)
			jsr     _LVOAddRegDump(a6)                 ;AddRegDump
			add     #DB_RD_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			lea     REGARRAY_SIZE(sp),sp
			bra.b   .end\@

			IFNC    "","\3"
.comment\@                      dc.b    "\3",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_INITINX   DebugVar,[GroupVar],InxVar,[Comment],[StartInx],[StopInx]
*               [Inxflag]
*
*  initializes a new index debugging action
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  InxVar    : Variable that is needed by DB_ADDINXVAR
*  Comment   : comment that should be displayed in the output file [optional]
*  StartInx  : start index for debugging output [optional]
*              if StartInx is omitted, DB_STARTINX is taken for default
*  StopInx   : stop index for debugging output [optional]
*              if StopInx is omitted, DB_STOPINX is taken for default
*  Inxflag   : bool flag: if set, an additional column with the index' is
*              printed in the output file [optional]
*              if Inxflag is omitted, DB_INXFLAG is taken for default

DB_INITINX      macro
		IFNE    DB_DEBUG
		tst.l   \3
		bne.b   end\@
			IFGT    NARG-7
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing InxVar"
				mexit
			ENDC
			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_IN_SIZE
			sub     #DB_IN_SIZE,a5
			move.l  a5,a1
			IFC     "","\4"
				clr.l   DB_IN_COMMENT(a1)
			ELSEIF
				move.l  #comment\@,DB_IN_COMMENT(a1)
			ENDC
			IFC     "","\5"
				move    #DB_STARTINX,DB_IN_STARTINX(a1)
			ELSEIF
				move    #\5,DB_IN_STARTINX(a1)
			ENDC
			IFC     "","\6"
				move    #DB_STOPINX,DB_IN_STOPINX(a1)
			ELSEIF
				move    #\6,DB_IN_STOPINX(a1)
			ENDC
			IFC     "","\7"
				move.b  #DB_INXFLAG,DB_IN_COUNTER(a1)
			ELSEIF
				move.b  #\7,DB_IN_COUNTER(a1)
			ENDC
			IFC     "","\2"
				clr.b   DB_IN_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_IN_GROUP_ID(a1)
			ENDC
			clr.b   DB_IN_EXT(a1)
			jsr     _LVOInitIndex(a6)             ;InitIndex
			move.l  d0,\3
			add     #DB_IN_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			bra.b   end\@

			IFNC    "","\4"
comment\@                       dc.b    "\4",0
			ENDC
			cnop    0,4
\3                      dc.l    0
end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDINXVAR   DebugVar,InxVar,Symbolname,[Comment],[Size],[Type]
*
*  if the specified symbol was not added to the index list yet, it's
*  added now. Additionally a value is added to the index list.
*
*  DebugVar  : Variable returned by AllocDebug
*  InxVar    : Variable returned by InitInx
*  Symbolname: name of the symbol to be added to the index structure
*              only relative symbols and registers should be specified
*  Comment   : comment that should be displayed in the output file [optional]
*  Size      : Size of an element (see above at 'Symbol Structure'
*              for possible values) [optional]
*              If the size is omitted, DB_DEFSIZE is taken for default
*  Type      : Displays the values either in hex or in decimal notation
*              (see above at 'MemContent Struture' for possible values)
*              [optional]
*              If Type is omitted, DB_DEFTYPE is taken for default

DB_ADDINXVAR    macro
		IFNE    DB_DEBUG
			IFGT    NARG-7
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-3
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\2"
				FAIL    "Missing InxVar"
				mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing Symbolname"
				mexit
			ENDC
			IFNC    "","\5"
				IFNE    (\5&DB_MASK)-DB_BYTE
				    IFNE    (\5&DB_MASK)-DB_WORD
					IFNE    (\5&DB_MASK)-DB_LONG
					    IFNE    (\5&DB_MASK)-DB_FLOAT
						IFNE    (\5&DB_MASK)-DB_DOUBLE
							FAIL    "Illegal Size"
						ENDC
					    ENDC
					ENDC
				    ENDC
				ENDC
			ENDC

			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					fmovem.x        fp0,-(sp)
					fmove.s \3,fp0
					fmove.d fp0,.double\@
					move.l  #.double\@,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					fmovem.x        fp0,-(sp)
					fmove.d \3,fp0
					fmove.d fp0,.double\@
					move.l  #.double\@,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_BYTE
					move.b  \3,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_WORD
					move    \3,d0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_LONG
					move.l  \3,d0
				ENDC
			ELSEIF
				move.l  \3,d0
			ENDC
			move.l  _DebugBase,d1
			beq.b   .nodebug\@
			move.l  d1,a6
			move.l  \1,a0
			link    a5,#-DB_IV_SIZE
			sub     #DB_IV_SIZE,a5
			move.l  a5,a1
			move.l  #.name\@,DB_IV_NAME(a1)
			IFC     "","\4"
				clr.l   DB_IV_COMMENT(a1)
			ELSEIF
				move.l  #.comment\@,DB_IV_COMMENT(a1)
			ENDC
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_BYTE
					move.b  d0,DB_IV_VALUE+3(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_WORD
					move    d0,DB_IV_VALUE+2(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_LONG
					move.l  d0,DB_IV_VALUE(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					move.l  d0,DB_SS_VALUE(a1)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					move.l  d0,DB_SS_VALUE(a1)
				ENDC
			ELSEIF
				move.l  d0,DB_IV_VALUE(a1)
			ENDC
			move.l  \2,DB_IV_INDEX_ID(a1)
			IFC     "","\5"
				move.b  #DB_DEFSIZE,DB_IV_EL_SIZE(a1)
			ELSEIF
				move.b  #\5,DB_IV_EL_SIZE(a1)
			ENDC
			IFC     "","\6"
				move.b  #DB_DEFTYPE,DB_IV_TYPE(a1)
			ELSEIF
				move.b  #\6,DB_IV_TYPE(a1)
			ENDC
			clr.b   DB_IV_EXT(a1)
			jsr     _LVOAddInxVar(a6)                 ;AddInxVar
			add     #DB_IV_SIZE,a5
			unlk    a5
.nodebug\@
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					fmovem.x        (sp)+,fp0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					fmovem.x        (sp)+,fp0
				ENDC
			ENDC
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			bra.b   .end\@
.double\@               dc.l    2,0
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_SETMARK     DebugVar,[Markname]
*
*  adds a mark to the sequential output
*
*  DebugVar  : Variable returned by AllocDebug
*  Markname  : Name of the mark [optional]

DB_SETMARK      macro
		IFNE    DB_DEBUG

			IFGT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-1
				FAIL    "Wrong number of arguments"
			mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC

			movem.l d0/d1/a0/a1/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0

			IFC     "","\2"
				sub.l   a1,a1
			ELSEIF
				move.l  #.name\@,a1
			ENDC
			jsr     _LVOSetMark(a6)                 ;SetMark
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a6
			bra.b   .end\@

			IFNC    "","\2"
.name\@                         dc.b    "\2",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_COUNT     DebugVar,[GroupVar],Comment
*
*  every time this macro is called, a counter is incremented. The final
*  value of the counter is printed out on the output file
*
*  DebugVar  : Variable returned by AllocDebug
*  GroupVar  : Variable returned by AllocGroup [optional]
*              If GroupVar is omitted, the symbol is put into the default
*              group
*  Comment   : comment that should be displayed in the output file

DB_COUNT        macro
		IFNE    DB_DEBUG
			IFGT    NARG-3
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
			mexit
			ENDC
			IFC     "","\3"
				FAIL    "Missing Comment"
				mexit
			ENDC
			tst.l   .count\@
			bne.b   .cont\@
			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_CO_SIZE
			sub     #DB_CO_SIZE,a5
			move.l  a5,a1
			move.l  #.comment\@,DB_CO_COMMENT(a1)
			move.l  #.count\@,DB_CO_ADDRESS(a1)
			IFC     "","\2"
				clr.b   DB_CO_GROUP_ID(a1)
			ELSEIF
				move.b  \2,DB_CO_GROUP_ID(a1)
			ENDC
			clr.b   DB_CO_EXT(a1)
			jsr     _LVOCount(a6)                 ;Count
			add     #DB_CO_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
.cont\@
			addq.l  #1,.count\@
			bra.b   .end\@

.count\@                dc.l    0
.comment\@              dc.b    "\3",0
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_CALL  DebugVar,Destination,[Comment],[ProfGroup],[Flag]
*
*  calls the subroutine 'Destination' and measures the time the routine has
*  to complete. Displays the result in the profiler output.
*
*  DebugVar    : Variable returned by AllocDebug
*  Destination : soubroutine to be called
*  Comment     : comment that should be displayed in the output file
*                [optional]
*  ProfGroup   : numberic value to identify a group of profiler calls
*                it allows to disable a group by DB_DISABLE [optional]
*  Flag        : If 'Flag' is omitted then 'Destination' is called
*                by an 'jsr' command. If 'Flag' is specified
*                then 'Destination' is interpreted as an command and
*                'Comment' is interpreted as operands. (in this way macros
*                can be measured, for example PPC calls) [optional]

DB_CALL         macro
		IFNE    DB_DEBUG
		    IFND    __PROFGROUP\4
__PROFGROUP\4               set     DB_ON
		    ENDC
		    IFEQ        __PROFGROUP\4-DB_ON
			IFGT    NARG-5
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\2"
				FAIL    "Missing Destination"
				mexit
			ENDC

			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			tst.b   .profcounter\@
			bne.b   .inc\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_PR_SIZE
			sub     #DB_PR_SIZE,a5
			move.l  a5,a1
			move.l  #.destination\@,DB_PR_NAME(a1)

			IFNC    "","\3"
			       move.l  #.comment\@,DB_PR_COMMENT(a1)
			ELSEIF
			       clr.l   DB_PR_COMMENT(a1)
			ENDC
			move.l  .profptr\@,DB_PR_PTR(a1)
			clr.b   DB_PR_EXT(a1)
			jsr     _LVOStartTimer(a6)                 ;StartTimer
			move.l  d0,.profptr\@
			add     #DB_PR_SIZE,a5
			unlk    a5
.inc\@
			addq.b  #1,.profcounter\@
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
		    ENDC
		ENDC
		IFC     "","\5"
			jsr     \2
		ELSEIF
			\2      \3
		ENDC

		IFNE    DB_DEBUG
		    IFEQ        __PROFGROUP\4-DB_ON
			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug2\@
			subq.b  #1,.profcounter\@
			bne.b   .nodebug2\@
			move.l  d0,a6
			move.l  .profptr\@,a1
			jsr     _LVOStopTimer(a6)                 ;StopTimer
.nodebug2\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			bra.b   .end\@

.destination\@          dc.b    "\2",0
			IFNC    "","\3"
.comment\@                      dc.b    "\3",0
			ENDC
.profcounter\@          dc.b    0
			cnop    0,4
.profptr\@              dc.l    0

.end\@
		    ENDC
		ENDC
		endm

;--------------------------------------
*
*  DB_MEASURE  DebugVar,Symbolname,[Comment],[ProfGroup]
*
*  measures the time a subroutine has to complete. In opposition to DB_CALL
*  this command has to be placed at the beginning of a subroutine, directly
*  after the label
*  This command MUST NOT be used when parameters are transferred on stack
*
*  DebugVar    : Variable returned by AllocDebug
*  Symbolname  : a symbolname that should always be the subroutine name
*  Comment     : comment that should be displayed in the output file
*                [optional]
*  ProfGroup   : numberic value to identify a group of profiler calls
*                it allows to disable a group by DB_DISABLE [optional]

DB_MEASURE      macro
		IFNE    DB_DEBUG
		    IFND    __PROFGROUP\4
__PROFGROUP\4               set     DB_ON
		    ENDC
		    IFEQ        __PROFGROUP\4-DB_ON
			IFGT    NARG-5
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-2
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\2"
				FAIL    "Missing Destination"
				mexit
			ENDC

			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			tst.b   .profcounter\@
			bne.b   .inc\@
			move.l  d0,a6
			move.l  \1,a0
			link    a5,#-DB_PR_SIZE
			sub     #DB_PR_SIZE,a5
			move.l  a5,a1
			move.l  #.destination\@,DB_PR_NAME(a1)

			IFNC    "","\3"
			       move.l  #.comment\@,DB_PR_COMMENT(a1)
			ELSEIF
			       clr.l   DB_PR_COMMENT(a1)
			ENDC
			move.l  .profptr\@,DB_PR_PTR(a1)
			clr.b   DB_PR_EXT(a1)
			jsr     _LVOStartTimer(a6)                 ;StartTimer
			move.l  d0,.profptr\@
			add     #DB_PR_SIZE,a5
			unlk    a5
.inc\@
			addq.b  #1,.profcounter\@
.nodebug\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			jsr     .end\@
			movem.l d0/d1/a0/a1/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug2\@
			subq.b  #1,.profcounter\@
			bne.b   .nodebug2\@
			move.l  d0,a6
			move.l  .profptr\@,a1
			jsr     _LVOStopTimer(a6)                 ;StopTimer
.nodebug2\@
			movem.l (sp)+,d0/d1/a0/a1/a5/a6
			rts

.destination\@          dc.b    "\2",0
			IFNC    "","\3"
.comment\@                      dc.b    "\3",0
			ENDC
.profcounter\@          dc.b    0
			cnop    0,4
.profptr\@              dc.l    0

.end\@
		    ENDC
		ENDC
		endm

;--------------------------------------
*
*  DB_DISABLE    ProfGroup
*
*  disables the profiler action for the specified profiler group. Every
*  profiler action (DB_CALL, DB_MEASURE) can be put into a profiler group.
*  profiler actions must be disabled BEFORE the DB_CALL and DB_MEASURE
*  commands that should be disabled
*
*  ProfGroup   : numberic value to identify a group of profiler calls.
*                if omitted, all profiler actions (DB_CALL/DB_MEASURE) with
*                omitted 'ProfGroup'-field are disabled [optional]

DB_DISABLE      macro
		IFNE    DB_DEBUG
			IFGT    NARG-1
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
__PROFGROUP\1                   set     DB_OFF
		ENDC
		endm

;--------------------------------------
*
*  DB_WRITEDEBUG  DebugVar,[Filename],[FoldStart],[FoldEnd],[DispType]
*
*  the current debug session is printed out to an output file
*
*  DebugVar  : Variable returned by AllocDebug
*  Filename  : name of the debug output file. If omitted, the debugging
*              information is printed out on stdout [optional]
*  FoldStart : GoldEd Fold Marker Start [optional]
*  FoldEnd   : GoldEd Fold Marker End (must be different than the
*              Start Marker). If one of these two values is omitted the
*              debugging output will be formatted standard. [optional]
*  DispType  : display type (see above at 'Layout Structure'
*              for possible values) [optional]
*              If the size is omitted, DB_DISPTYPE is taken for default

DB_WRITEDEBUG   macro
		IFNE    DB_DEBUG

			IFGT    NARG-10
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-1
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC

			movem.l d0/d1/a0-a2/a5/a6,-(sp)
			move.l  _DebugBase,d0
			beq.b   .nodebug\@
			move.l  d0,a6
			move.l  \1,a0
			IFC     "","\2"
				sub.l   a2,a2
			ELSEIF
				lea     .filename\@,a2
			ENDC
			link    a5,#-DB_LA_SIZE
			sub     #DB_LA_SIZE,a5
			move.l  a5,a1
			IFNC    "","\3"
			       move.l  #.foldstart\@,DB_LA_FOLDSTART(a1)
			ELSEIF
			       clr.l   DB_LA_FOLDSTART(a1)
			ENDC
			IFNC    "","\4"
			       move.l  #.foldend\@,DB_LA_FOLDEND(a1)
			ELSEIF
			       clr.l   DB_LA_FOLDEND(a1)
			ENDC
			IFC     "","\5"
				move.b  #DB_DISPTYPE,DB_LA_DISPLAY(a1)
			ELSEIF
				move.b  #\5,DB_LA_DISPLAY(a1)
			ENDC
			move.b  #DB_DISPCOLUMN,DB_LA_COLUMN(a1)
			move.b  #DB_DEFSYMPOS,DB_LA_SYMPOS(a1)
			move.b  #DB_DEFMCPOS,DB_LA_MCPOS(a1)
			move.b  #DB_DEFCOPOS,DB_LA_COPOS(a1)
			move.b  #DB_DEFPROPOS,DB_LA_PROPOS(a1)
			clr.b   DB_LA_EXT(a1)
			jsr     _LVOWriteDebug(a6)                 ;WriteDebug
			add     #DB_LA_SIZE,a5
			unlk    a5
.nodebug\@
			movem.l (sp)+,d0/d1/a0-a2/a5/a6
			bra.b   .end\@

			IFNC    "","\2"
.filename\@                     dc.b    "\2",0
			ENDC
			IFNC    "","\3"
.foldstart\@                    dc.b    "\3",0
			ENDC
			IFNC    "","\4"
.foldend\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
.end\@
		ENDC
		endm

;--------------------------------------
*
*  DB_XREF
*
*  Imports the base of the debug.library. It is needed when DB_ALLOCGROUP
*  is called from another module

DB_XREF         macro
		IFNE    DB_DEBUG
			XREF    _DebugBase
		ENDC
		endm

;--------------------------------------
*
*  DB_XDEF
*
*  Exports the base of the debug.library. It is needed when other modules want
*  to use the debug.library

DB_XDEF         macro
		IFNE    DB_DEBUG
			XDEF    _DebugBase
		ENDC
		endm





	ENDC    ;DEBUG_I
