		IFND DEBUGPPC_I
DEBUGPPC_I         SET 1
**
**      $VER: debug.i 2.0 (9.11.97)
**
**      Structures and macros for the debug.library
**      PowerPC version
**

		IFND    EXEC_TYPES_I
		include exec/types.i
		ENDC

		IFND    POWERPC_PPCMACROS_I
		include powerpc/ppcmacros.i
		ENDC

		IFND    POWERPC_POWERPC_I
		include powerpc/powerpc.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_PAD1
	UBYTE           DB_RD_PAD2
	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_PAD1
	UBYTE           DB_CO_PAD2
	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_PAD1
	UBYTE           DB_PR_PAD2
	UBYTE           DB_PR_PAD3      ; 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)
	APTR            DB_LA_FOLDEND   ; -> GoldEd Fold Marker (End)
	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 exec.library

_LVO_OpenLibrary       =       -552
_LVO_CloseLibrary      =       -414

****************************   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_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
DB_DUMPFLAG     set     DB_ASCII        ;default flag for ascii output (memdump)


*       !!!!!!!!!  Note: Use of the macros modifies the LR and the CR  !!!!!!!!!!

;--------------------------------------
*
*  DB_OPENDEBUG
*
*  Opens the debug.library
*
*  This macro requires the base of the exec.library to be defined under the
*  name _SysBase

DB_OPENDEBUG    macro
		IFNE    DB_DEBUG
			pushctr
			pushgpr r3-r10
			lw      r3,_SysBase
			li      r3,0
			la      r6,debugname
			RUN68K  _SysBase,_OpenLibrary
			sw      r3,_DebugBasePPC
			popgpr
			popctr
			IFND    _DebugBasePPC
			save
			section "debug.library",data
debugname                       dc.b    "debug.library",0
				cnop    0,4
_DebugBasePPC                   dc.l    0
			restore
			ENDC
		ENDC
		endm

;--------------------------------------
*
*  DB_CLOSEDEBUG
*
*  Closes the debug.library
*
*  This macro requires the base of the exec.library to be defined under the
*  name _SysBase

DB_CLOSEDEBUG   macro
		IFNE    DB_DEBUG
			pushctr
			pushgpr r3-r10
			lw      r6,_DebugBasePPC
			tstw    r6
			beq     .noclose\@
			RUN68K  _SysBase,_CloseLibrary
.noclose\@
			popgpr
			popctr
		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
			pushctr
			pushgpr r3-r10
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			liw     r3,\2
			RUN68K  _DebugBasePPC,AllocDebug
			sw      r3,_\1
.nodebug\@
			popgpr
			popctr
			save
			section "debug.library",data
_\1                     dc.l    0
			restore
		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
			pushctr
			pushgpr r3-r10
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lw      r5,_\1
			RUN68K  _DebugBasePPC,FreeDebug
.nodebug\@
			popgpr
			popctr
		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
			pushctr
			pushgpr r3-r10
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lw      r5,_\1
			IFC     "","\4"
				liw     r3,DB_GROUPPRI
			ELSEIF
				liw     r3,\4
			ENDC
			IFC     "","\3"
				clrw    r6
			ELSEIF
				la      r6,name\@
			ENDC
			RUN68K  _DebugBasePPC,AllocGroup
			sb      r3,_\2
.nodebug\@
			popgpr
			popctr
			save
			section "debug.library",data
			IFNC    "","\3"
name\@                          dc.b    "\3",0
			ENDC
_\2                     dc.b    0
			cnop    0,4
			restore
		ENDC
		endm

;--------------------------------------
*
*  DB_ADDSYM    DebugVar,[GroupVar],Symbolname,[Comment]
*
*  Adds a new symbol to the debug structure; the value of the symbol 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
*              if Symbolname is a relative symbol, an & must be preceeded
*  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
			pushctr
			pushgpr r3-r10/r31
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_SS_SIZE
			subi    r6,r31,DB_SS_SIZE
			la      r3,.name\@
			stw     r3,DB_SS_NAME(r6)
			IFC     "","\4"
				clrw    r3
			ELSEIF
				la      r3,.comment\@
			ENDC
			stw     r3,DB_SS_COMMENT(r6)
			IFNC    "&","\*LEFT(\3,1)"
				liw     r3,\3
			ELSEIF
				la      r3,\*RIGHT(\3,\*STRLEN(\3)-1)
			ENDC
			stw     r3,DB_SS_VALUE(r6)
			IFC     "","\2"
				clrw    r3
			ELSEIF
				lb      r3,_\2
			ENDC
			stb     r3,DB_SS_GROUP_ID(r6)
			clrw    r3
			stb     r3,DB_SS_EXT(r6)
			RUN68K  _DebugBasePPC,AddSym
			ulnk    r31
.nodebug\@
			popgpr
			popctr
			save
			section "debug.library",data
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
			restore
		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

			pushctr
			pushgpr r3-r10/r31
			IFGPR   \3
				mr      r3,\3
			ELSEIF
				IFNC    "","\5"
					IFEQ    (\5&DB_MASK)-DB_BYTE
						lb      r3,\3
					ENDC
					IFEQ    (\5&DB_MASK)-DB_WORD
						lh      r3,\3
					ENDC
					IFEQ    (\5&DB_MASK)-DB_LONG
						lw      r3,\3
					ENDC
					IFEQ    (\5&DB_MASK)-DB_FLOAT
					    pushf   f0
					    la      r3,.double\@
					    IFFPR   \3
						frsp    f0,\3
						sf      f0,.double\@
					    ELSEIF
						ls      f0,\3
						sf      f0,.double\@
					    ENDC
					ENDC
					IFEQ    (\5&DB_MASK)-DB_DOUBLE
					    pushf   f0
					    la      r3,.double\@
					    IFFPR   \3
						sf      \3,.double\@
					    ELSEIF
						lf      f0,\3
						sf      f0,.double\@
					    ENDC
					ENDC
				ELSEIF
					lw      r3,\3
				ENDC
			ENDC
			lw      r4,_DebugBasePPC
			tstw    r4
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_SS_SIZE
			subi    r6,r31,DB_SS_SIZE
			la      r4,.name\@
			stw     r4,DB_SS_NAME(r6)
			IFC     "","\4"
				clrw    r4
			ELSEIF
				la      r4,.comment\@
			ENDC
			stw     r4,DB_SS_COMMENT(r6)
			IFC     "","\2"
				clrw    r4
			ELSEIF
				lb      r4,_\2
			ENDC
			stb     r4,DB_SS_GROUP_ID(r6)
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_BYTE
					stb     r3,DB_SS_VALUE+3(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_WORD
					sth     r3,DB_SS_VALUE+2(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_LONG
					stw     r3,DB_SS_VALUE(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					stw     r3,DB_SS_VALUE(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					stw     r3,DB_SS_VALUE(r6)
				ENDC
			ELSEIF
				stw     r3,DB_SS_VALUE(r6)
			ENDC
			IFC     "","\5"
				li      r4,DB_DEFSIZE
			ELSEIF
				li      r4,\5
			ENDC
			stb     r4,DB_SS_EL_SIZE(r6)
			clrw    r4
			stb     r4,DB_SS_EXT(r6)
			RUN68K  _DebugBasePPC,AddValue
			ulnk    r31
.nodebug\@
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					popf    f0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					popf    f0
				ENDC
			ENDC
			popgpr
			popctr
			save
			section "debug.library",data
.double\@               dc.d    0
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
			restore
		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
			pushctr
			pushgpr r3-r10/r31
			lw      r4,_DebugBasePPC
			tstw    r4
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_MC_SIZE
			subi    r6,r31,DB_MC_SIZE
			la      r3,.name\@
			stw     r3,DB_MC_NAME(r6)
			IFC     "","\4"
				clrw    r3
			ELSEIF
				la      r3,.comment\@
			ENDC
			stw     r3,DB_MC_COMMENT(r6)
			la      r3,\3
			stw     r3,DB_MC_VALUE(r6)
			IFC     "","\2"
				clrw    r3
			ELSEIF
				lb      r3,_\2
			ENDC
			stb     r3,DB_MC_GROUP_ID(r6)
			IFC     "","\5"
				li      r3,DB_DEFSIZE
			ELSEIF
				li      r3,\5
			ENDC
			stb     r3,DB_MC_EL_SIZE(r6)
			IFC     "","\6"
				li      r3,DB_DEFCOUNT
			ELSEIF
				li      r3,\6
			ENDC
			sth     r3,DB_MC_COUNT(r6)
			IFC     "","\7"
				li      r3,DB_DEFCOLUMN
			ELSEIF
				li      r3,\7
			ENDC
			stb     r3,DB_MC_COLUMN(r6)
			IFC     "","\8"
				li      r3,DB_DEFTYPE
			ELSEIF
				li      r3,\8
			ENDC
			stb     r3,DB_MC_TYPE(r6)
			clrw    r3
			stb     r3,DB_MC_EXT(r6)
			RUN68K  _DebugBasePPC,AddArray
			ulnk    r31
.nodebug\@
			popgpr
			popctr
			save
			section "debug.library",data
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
			restore
		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)
*              if Symbolname is a relative symbol, an & must be preceeded
*  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
			pushctr
			pushgpr r3-r10/r31
			IFNC    "&","\*LEFT(\3,1)"
				liw     r3,\3
			ELSEIF
				la      r3,\*RIGHT(\3,\*STRLEN(\3)-1)
			ENDC
			lw      r4,_DebugBasePPC
			tstw    r4
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_MD_SIZE
			subi    r6,r31,DB_MD_SIZE
			la      r4,.name\@
			stw     r4,DB_MD_NAME(r6)
			IFC     "","\4"
				clrw    r4
				stw     r4,DB_MD_COMMENT(r6)
			ELSEIF
				la      r4,.comment\@
				stw     r4,DB_MD_COMMENT(r6)
			ENDC
			stw     r3,DB_MC_VALUE(r6)
			IFC     "","\2"
				clrw    r4
			ELSEIF
				lb      r4,_\2
			ENDC
			stb     r4,DB_MD_GROUP_ID(r6)
			IFC     "","\5"
				liw     r4,DB_DEFMEMSIZE
			ELSEIF
				liw     r4,\5
			ENDC
			stw     r4,DB_MD_MEMSIZE(r6)
			IFC     "","\6"
				liw     r4,DB_DUMPFLAG
			ELSEIF
				liw     r4,\6
			ENDC
			stw     r4,DB_MD_NOASCII(r6)
			clrw    r4
			stb     r4,DB_MD_EXT(r6)
			RUN68K  _DebugBasePPC,AddDump
			ulnk    r31
.nodebug\@
			popgpr
			popctr
			save
			section "debug.library",data
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
			restore
		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
		push    r3
		lw      r3,_\3
		tstw    r3
		bne     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
			pushctr
			pushgpr r4-r10/r31
			lw      r4,_DebugBasePPC
			tstw    r4
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_IN_SIZE
			subi    r6,r31,DB_IN_SIZE
			IFC     "","\4"
				clrw    r4
			ELSEIF
				la      r4,comment\@
			ENDC
			stw     r4,DB_IN_COMMENT(r6)
			IFC     "","\5"
				li      r4,DB_STARTINX
			ELSEIF
				li      r4,\5
			ENDC
			sth     r4,DB_IN_STARTINX(r6)
			IFC     "","\6"
				li      r4,DB_STOPINX
			ELSEIF
				li      r4,\6
			ENDC
			sth     r4,DB_IN_STOPINX(r6)
			IFC     "","\7"
				li      r4,DB_INXFLAG
			ELSEIF
				li      r4,\7
			ENDC
			stb     r4,DB_IN_COUNTER(r6)
			IFC     "","\2"
				clrw    r4
			ELSEIF
				lb      r4,_\2
			ENDC
			stb     r4,DB_IN_GROUP_ID(r6)
			clrw    r4
			stb     r4,DB_IN_EXT(r6)
			RUN68K  _DebugBasePPC,InitIndex
			sw      r3,_\3
			ulnk    r31
.nodebug\@
			popgpr
			popctr
			save
			section "debug.library",data
			IFNC    "","\4"
comment\@                       dc.b    "\4",0
			ENDC
			cnop    0,4
_\3                     dc.l    0
			restore
end\@
		pop     r3
		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

			pushctr
			pushgpr r3-r10/r31
			IFGPR   \3
				mr      r3,\3
			ELSEIF
				IFNC    "","\5"
					IFEQ    (\5&DB_MASK)-DB_BYTE
						lb      r3,\3
					ENDC
					IFEQ    (\5&DB_MASK)-DB_WORD
						lh      r3,\3
					ENDC
					IFEQ    (\5&DB_MASK)-DB_LONG
						lw      r3,\3
					ENDC
					IFEQ    (\5&DB_MASK)-DB_FLOAT
					    pushf   f0
					    la      r3,.double\@
					    IFFPR   \3
						frsp    f0,\3
						sf      f0,.double\@
					    ELSEIF
						ls      f0,\3
						sf      f0,.double\@
					    ENDC
					ENDC
					IFEQ    (\5&DB_MASK)-DB_DOUBLE
					    pushf   f0
					    la      r3,.double\@
					    IFFPR   \3
						sf      \3,.double\@
					    ELSEIF
						lf      f0,\3
						sf      f0,.double\@
					    ENDC
					ENDC
				ELSEIF
					lw      r3,\3
				ENDC
			ENDC
			lw      r4,_DebugBasePPC
			tstw    r4
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_IV_SIZE
			subi    r6,r31,DB_IV_SIZE
			la      r4,.name\@
			stw     r4,DB_IV_NAME(r6)
			IFC     "","\4"
				clrw    r4
			ELSEIF
				la      r4,.comment\@
			ENDC
			stw     r4,DB_IV_COMMENT(r6)
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_BYTE
					stb     r3,DB_IV_VALUE+3(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_WORD
					sth     r3,DB_IV_VALUE+2(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_LONG
					stw     r3,DB_IV_VALUE(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					stw     r3,DB_SS_VALUE(r6)
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					stw     r3,DB_SS_VALUE(r6)
				ENDC
			ELSEIF
				stw     r3,DB_IV_VALUE(r6)
			ENDC
			lw      r4,_\2
			stw     r4,DB_IV_INDEX_ID(r6)
			IFC     "","\5"
				li      r4,DB_DEFSIZE
			ELSEIF
				li      r4,\5
			ENDC
			stb     r4,DB_IV_EL_SIZE(r6)
			IFC     "","\6"
				li      r4,DB_DEFTYPE
			ELSEIF
				li      r4,\6
			ENDC
			stb     r4,DB_IV_TYPE(r6)
			clrw    r4
			stb     r4,DB_IV_EXT(r6)
			RUN68K  _DebugBasePPC,AddInxVar
			ulnk    r31
.nodebug\@
			IFNC    "","\5"
				IFEQ    (\5&DB_MASK)-DB_FLOAT
					popf    f0
				ENDC
				IFEQ    (\5&DB_MASK)-DB_DOUBLE
					popf    f0
				ENDC
			ENDC
			popgpr
			popctr

			save
			section "debug.library",data
.double\@               dc.d    0
.name\@                 dc.b    "\3",0
			IFNC    "","\4"
.comment\@                      dc.b    "\4",0
			ENDC
			cnop    0,4
			restore
		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
			pushctr
			pushgpr r3-r10
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lw      r5,_\1
			IFC     "","\2"
				clrw    r6
			ELSEIF
				la      r6,.name\@
			ENDC
			RUN68K  _DebugBasePPC,SetMark
.nodebug\@
			popgpr
			popctr

			save
			section "debug.library",data
			IFNC    "","\2"
.name\@                         dc.b    "\2",0
			ENDC
			cnop    0,4
			restore
		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
			pushctr
			pushgpr r3-r10/r31
			lw      r3,.count\@
			tstw    r3
			bne     .nodebug\@
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lw      r5,_\1
			lnk     r31,-DB_CO_SIZE
			subi    r6,r31,DB_CO_SIZE
			la      r4,.comment\@
			stw     r4,DB_CO_COMMENT(r6)
			la      r4,.count\@
			stw     r4,DB_CO_ADDRESS(r6)
			IFC     "","\2"
				clrw    r4
			ELSEIF
				lb      r4,_\2
			ENDC
			stb     r4,DB_CO_GROUP_ID(r6)
			clrw    r4
			stb     r4,DB_CO_EXT(r6)
			RUN68K  _DebugBasePPC,Count
			ulnk    r31
.nodebug\@
			lw      r3,.count\@
			addi    r3,r3,1
			sw      r3,.count\@
			popgpr
			popctr

			save
			section "debug.library",data
.count\@                dc.l    0
.comment\@              dc.b    "\3",0
			cnop    0,4
			restore
		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. If omitted an indirect call (blrl)
*                is performed [optional]
*  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
*                (in this way macros can be measured, for example
*                 68K calls)
*
*  Note: One paramater of 'Destination' or 'Comment' MUST be specified

DB_CALL         macro
		IFNE    DB_DEBUG
		    IFND    __PROFGROUP\4
__PROFGROUP\4               set     DB_ON
		    ENDC
		    IFEQ        __PROFGROUP\4-DB_ON
			IFGT    NARG-4
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-1
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\2"
				IFC     "","\3"
					FAIL    "Missing Destination/Comment"
				mexit
				ENDC
			ENDC
			pushctr
			pushgpr r3-r10/r31
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lb      r3,.profcounter\@
			tstw    r3
			bne     .inc\@
			lw      r5,_\1
			lnk     r31,-DB_PR_SIZE
			subi    r6,r31,DB_PR_SIZE
			IFC     "","\2"
				clrw    r4
			ELSEIF
				la      r4,.destination\@
			ENDC
			stw     r4,DB_PR_NAME(r6)
			IFC     "","\3"
				clrw    r4
			ELSEIF
				la      r4,.comment\@
			ENDC
			stw     r4,DB_PR_COMMENT(r6)
			lw      r4,.profptr\@
			stw     r4,DB_PR_PTR(r6)
			clrw    r4
			stb     r4,DB_PR_EXT(r6)
			RUN68K  _DebugBasePPC,StartTimer
			sw      r3,.profptr\@
			ulnk    r31
.inc\@
			lb      r5,.profcounter\@
			addi    r5,r5,1
			sb      r5,.profcounter\@
.nodebug\@
			popgpr
			popctr
		    ENDC
		ENDC
		IFC     "","\5"
			IFC     "","\2"
				blrl
			ELSEIF
				bl      \2
			ENDC
		ELSEIF
			\2      \3
		ENDC

		IFNE    DB_DEBUG
		    IFEQ        __PROFGROUP\4-DB_ON
			pushctr
			pushgpr r3-r10
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug2\@
			lb      r3,.profcounter\@
			subic.  r3,r3,1
			sb      r3,.profcounter\@
			bne     .nodebug2\@
			lw      r6,.profptr\@
			RUN68K  _DebugBasePPC,StopTimer
.nodebug2\@
			popgpr
			popctr

			save
			section "debug.library",data
			IFNC    "","\2"
.destination\@                  dc.b    "\2",0
			ENDC
			IFNC    "","\3"
.comment\@                      dc.b    "\3",0
			ENDC
.profcounter\@          dc.b    0
			cnop    0,4
.profptr\@              dc.l    0
			restore

.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
*
*  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-4
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFLT    NARG-1
				FAIL    "Wrong number of arguments"
				mexit
			ENDC
			IFC     "","\1"
				FAIL    "Missing DebugVar"
				mexit
			ENDC
			IFC     "","\2"
				IFC     "","\3"
					FAIL    "Missing Destination/Comment"
				mexit
				ENDC
			ENDC
			pushlr
			pushctr
			pushgpr r3-r10/r31
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lb      r3,.profcounter\@
			tstw    r3
			bne     .inc\@
			lw      r5,_\1
			lnk     r31,-DB_PR_SIZE
			subi    r6,r31,DB_PR_SIZE
			IFC     "","\2"
				clrw    r4
			ELSEIF
				la      r4,.destination\@
			ENDC
			stw     r4,DB_PR_NAME(r6)
			IFC     "","\3"
				clrw    r4
			ELSEIF
				la      r4,.comment\@
			ENDC
			stw     r4,DB_PR_COMMENT(r6)
			lw      r4,.profptr\@
			stw     r4,DB_PR_PTR(r6)
			clrw    r4
			stb     r4,DB_PR_EXT(r6)
			RUN68K  _DebugBasePPC,StartTimer
			sw      r3,.profptr\@
			ulnk    r31
.inc\@
			lb      r5,.profcounter\@
			addi    r5,r5,1
			sb      r5,.profcounter\@
.nodebug\@
			popgpr
			bl      .end\@
			pushgpr r3-r10
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug2\@
			lb      r3,.profcounter\@
			subic.  r3,r3,1
			sb      r3,.profcounter\@
			bne     .nodebug2\@
			lw      r6,.profptr\@
			RUN68K  _DebugBasePPC,StopTimer
.nodebug2\@
			popgpr
			popctr
			poplr
			blr
			save
			section "debug.library",data
			IFNC    "","\2"
.destination\@                  dc.b    "\2",0
			ENDC
			IFNC    "","\3"
.comment\@                      dc.b    "\3",0
			ENDC
.profcounter\@          dc.b    0
			cnop    0,4
.profptr\@              dc.l    0
			restore

.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
			pushctr
			pushgpr r3-r10/r28/r31
			lw      r3,_DebugBasePPC
			tstw    r3
			beq     .nodebug\@
			lw      r5,_\1
			IFC     "","\2"
				clrw    r28
			ELSEIF
				la      r28,.filename\@
			ENDC
			lnk     r31,-DB_LA_SIZE
			subi    r6,r31,DB_LA_SIZE
			IFNC    "","\3"
				la      r4,.foldstart\@
			ELSEIF
				clrw    r4
			ENDC
			stw     r4,DB_LA_FOLDSTART(r6)
			IFNC    "","\4"
				la      r4,.foldend\@
			ELSEIF
				clrw    r4
			ENDC
			stw     r4,DB_LA_FOLDEND(r6)
			IFC     "","\5"
				li      r4,DB_DISPTYPE
			ELSEIF
				li      r4,\5
			ENDC
			stb     r4,DB_LA_DISPLAY(r6)
			stbi    DB_DISPCOLUMN,DB_LA_COLUMN(r6)
			stbi    DB_DEFSYMPOS,DB_LA_SYMPOS(r6)
			stbi    DB_DEFMCPOS,DB_LA_MCPOS(r6)
			stbi    DB_DEFCOPOS,DB_LA_COPOS(r6)
			stbi    DB_DEFPROPOS,DB_LA_PROPOS(r6)
			clrw    r4
			stb     r4,DB_LA_EXT(r6)
			RUN68K_XL  _DebugBasePPC,WriteDebug
			ulnk    r31
.nodebug\@
			popgpr
			popctr

			save
			section "debug.library",data
			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
			restore
		ENDC
		endm

;--------------------------------------
*
*  DB_XREF
*
*  Imports the base of the debug.library.
*  It the base is imported from a 68K module and smalldata is activated,
*  DB_XREFPPC must be used.

DB_XREF         macro
		IFNE    DB_DEBUG
			XREF    _DebugBasePPC
		ENDC
		endm

;--------------------------------------
*
*  DB_XDEF
*
*  Exports the base of the debug.library.

DB_XDEF         macro
		IFNE    DB_DEBUG
			XDEF    _DebugBasePPC
		ENDC
		endm


;--------------------------------------
*
*  DB_XREFPPC
*
*  Imports the base of the debug.library when a PPC module wants to use
*  the debug.library opened in a 68K module.
*
*  Note: this command must be executed by the CPU BEFORE any other DB
*  command is used!!

DB_XREFPPC      macro
		IFNE    DB_DEBUG
			IFND    _DebugBasePPC
			XREF    _DebugBase

				save
				section "debug.library",data
__DebugBase                     dc.l    _DebugBase
_DebugBasePPC                   dc.l    0
				restore

				push    r3
				lw      r3,__DebugBase
				lwz     r3,0(r3)
				sw      r3,_DebugBasePPC
				pop     r3
			ENDC
		ENDC
		endm

;--------------------------------------
*
*  XREFPPC  Variable
*
*  imports a debug variable created by DB_ALLOCDEBUG,DB_ALLOCGROUP or
*  DB_INITINX when a PPC module wants to access these variables which were
*  defined in a 68K module
*
*  Note: this command must be executed by the CPU BEFORE any other DB
*  command accesses this variable!!
*
*  Variable : any debugging variable created by one of the functions
*             mentioned above

XREFPPC         macro
		IFNE    DB_DEBUG
			IFND    _\1
			XREF    \1

				save
				section "debug.library",data
__\1                            dc.l    \1
_\1                             dc.l    0
				restore

				push    r3
				lw      r3,__\1
				lwz     r3,0(r3)
				sw      r3,_\1
				pop     r3
			ENDC
		ENDC
		endm

	ENDC    ;DEBUG_I
