;(*---------------------------------------------------------------------------
;    :Program.     Dump.asm
;    :Contents.	   Create 1 line with HexDump and ASCII
;    :Author.      Bernd Preusing
;    :Address.	   Gerhardstr. 16  D-2200 Elmshorn
;    :Phone.	   04121/22486
;    :Copyright.   Public Domain
;    :Language.	   68000 Assembler
;    :Translator.  Profimat (würg!)
;    :History.	   1.0 08-Mar-89 Bernd Preusing
;    :Bugs.	   none
;---------------------------------------------------------------------------*)
;
	CODE
	DC.L 1	; Kennung: .obj-File
	DC.W 1	; mod
	DC.B 'Dump'
	DS.B 28,0
	DC.W $0FF5,$0400,$0A55

; CodeSize
	DC.L	ENDE-Prog
; VarSize
	DC.L	12
; ConstSize
	DC.L	Jumps-Consts
; Jumps
	DC.L	2
; Modules
	DC.L	0

Consts:

Jumps:
	DC.W	$4EF9,0,Dump-60
	DC.W	$4EF9,0,Proc000-60

dataPtr	EQUR Prog-4

BLength		EQUR	-4
ByteCount	EQUR	-6
AddrLen		EQUR	-8
Offset		EQUR	-12

Prog:
Proc000:
	BRA	L000018



; d7 = ' '
; a3=stringptr Pos
; a2 = dataptr Start
; d1 = i (loop)
; d2 = byte (zähler spaces)
; -4(a5) = schein
; d4 = const $90 für phex
; d5 = const $40 für phex
;
Dump:
	MOVE.L	A4,-(A7)
	MOVEA.L	dataPtr(PC),A4
	LINK	A5,#-4
	MOVEA.L	16(A5),A3
	MOVE.L	12(A5),a2

	moveq	#0,d2 ; zähler zwischenspaces
	moveq	#-112,d4 ; gibt d4.b=$90 trick hex-wandlung
	moveq	#$40,d5 ; dito
	MOVEQ	#' ',D7

	MOVE.L	a2,D0
	ADD.L	Offset(A4),D0
	move.l	d0,-4(a5)
	moveq	#0,d0		; rest d0.w auf 0 wg. hex
	CMPI.W	#$0006,AddrLen(A4)
	BLS.s	L000011
	MOVE.B	-4(A5),d0
	BSR.s	PHex
L000011:
	CMPI.W	#$0004,AddrLen(A4)
	BLS.s	L000012
	MOVE.B	-3(A5),d0
	BSR.s	PHex
L000012:
	MOVE.B	-2(A5),d0
	BSR.s	PHex
	MOVE.B	-1(A5),d0
	BSR.s	PHex
	move.b	d7,(a3)+

	MOVE.W	ByteCount(A4),D1 ; count
	move.w	BLength(A4),d3 ; zusammen 1,2,4
	bra.s	HexNext
HexLoop:
	TST.w	d2
	BNE.s	NoSpace
	MOVE.b	d7,(a3)+
NoSpace:
	ADDQ.w	#1,D2
	cmp.w	d3,D2
	blo.s	NoOvflw
	moveq	#0,d2
NoOvflw:
	MOVE.B	(A2)+,d0
	BSR.s	PHex
HexNext:
	dbra	d1,HexLoop

	MOVE.b	d7,(a3)+
	MOVE.b	d7,(a3)+

	MOVE.L	12(A5),a2
	MOVE.W	ByteCount(A4),D1
	bra.s	AsciiNext
AsciiLoop:
	MOVE.B	(A2)+,D0
	CMP.B	d7,D0
	BCS.s	PutDot
	CMPI.B	#$80,D0
	BCS.s	NoDot
	CMPI.B	#$A0,D0
	BCC.s	NoDot
PutDot:
	MOVEQ	#'.',D0
NoDot:
	MOVE.B	D0,(a3)+
AsciiNext:
	dbra	d1,AsciiLoop

	clr.b	(a3)

	UNLK	A5
	MOVEA.L	(A7)+,A4
	MOVEA.L	(A7)+,A0
	LEA	12(A7),A7
	JMP	(A0)

; print d0.b hex nach (a3)+
; ändert d0.b, d6.b d0.l muß 0 sein!!
; hat consts in d4 ($90) und d5 ($40)
PHex:
	MOVE.B	d0,D6
	LSR.B	#4,D6
	addq.w	#1,d0		; X-Flag löschen 4 Takte
	Abcd.B	d4,D6		; 6 zyklen
	Abcd.B	d5,D6		; 6
	MOVE.B	D6,(a3)+

	subq.w	#1,d0		; X-Flag löschen und d0 wieder
	ANDI.B	#$0F,D0
	Abcd.B	d4,D0
	Abcd.B	d5,D0
	MOVE.B	D0,(a3)+
	rts

L000018:
	MOVE.L	A4,-(A7)
	MOVEA.L	dataPtr(PC),A4
	BSET	#0,-2(A4)
	BNE.s	L000019
	MOVE.W	#$0002,BLength(A4)
	MOVE.W	#$0010,ByteCount(A4)
	MOVE.W	#$0006,AddrLen(A4)
	CLR.L	Offset(A4)
L000019:
	MOVEA.L	(A7)+,A4
	RTS
ENDE:
	END
