;==============================================================================
;===                                                                        ===
;===                        Debug / kleine Hilfe                            ===
;===                                                                        ===
;===            für Assembler - geschrieben von Aliso 1989                  ===
;===                                                                        ===
;==============================================================================

	entry	Debug

CALLSYS MACRO
 XREF	_LVO\1
 move.l	\2,a6
 jsr	_LVO\1(a6)
 ENDM

CALL MACRO
 XREF	_LVO\1
 jsr	_LVO\1(a6)
 ENDM


AbsExecBase equ 4

	section	DebugCode,Code

Debug:
	movem.l	d0-d7/a0-a6,-(sp)		; Register retten
	clr.l	Position			; Anzahl löschen
	move.l	d0,DataStream			; Wert nach DataStream
	lea	FormatString,a0			; 
	lea	DataStream,a1			;
	lea	PutChars,a2			;
	lea	Return,a3			;
	CALLSYS	RawDoFmt,AbsExecBase		; String formatieren
	lea	DosName,a1			; Library öffnen
	CALL	OldOpenLibrary			;
	move.l	d0,-(sp)			; Zeiger auf Stack
	CALLSYS	Output,d0			; Output
	move.l	d0,d1				; Handle nach  D1
	move.l	#String,d2			; Adresse
	move.l	Position,d3			; Anzahl
	CALL	Write				; ausgeben
	move.l	(sp)+,a1			; Zeiger von Stack
	CALLSYS	CloseLibrary,AbsExecBase	; Library schließen
	movem.l	(sp)+,d0-d7/a0-a6		; Register vom Stack
	rts					; und zurück
PutChars:
	movem.l	d1/a0,-(sp)
	move.l	Position,d1
	lea	String,a0
	move.b	d0,0(a0,d1)
	addq.l	#1,Position
	movem.l	(sp)+,d1/a0
Return:
	rts

DosName:
	dc.b	'dos.library',0
	cnop	2
Position:
	dc.l	0
DataStream:
	dc.l	0
FormatString:
	dc.b	'%ld',13,10,0
	cnop	2
String:
	ds.b	20
