* HEX-ASCII-Dump


	output .TOS
	
	include "D:\GEMDOS_N.S"

esc	equ	27
buf_len	equ	30

	section text
	
	do_start
	
	pea	titel
	call_gemdos Cconws
	addq.l	#6,sp

	pea	get_ram_end
	call_xbios Supexec
	addq.l	#6,sp

new	pea	t_addr
	call_gemdos Cconws
	addq.l	#6,sp
	move.b	#buf_len-1,buffer
	pea	buffer
	call_gemdos Cconrs
	addq.l	#6,sp
	lea	buffer+1(pc),a0
	moveq.l	#0,d0
	move.b	(a0)+,d0
	add.l	d0,a0
	move.b	#0,(a0)
	lea	buffer+2(pc),a0
atxt	cmp.b	#$20,(a0)+
	beq.s	atxt
	subq.l	#1,a0
	moveq.l	#0,d1			* Hex-Zahl
inhex	moveq.l	#0,d0
	move.b	(a0)+,d0
	bsr.w	upcase
	sub.b	#'0',d0
	bcs.s	inhex2
	cmp.b	#$A,d0
	bcs.s	inhex1
	sub.b	#7,d0
	cmp.b	#$A,d0
	bcs.s	inhex2
	cmp.b	#$F,d0
	bhi.s	inhex2
inhex1	lsl.l	#4,d1
	or.l	d0,d1
	bra.s	inhex
inhex2	move.l	d1,a6
	cmp.l	ram_end,d1
	bcs.s	sh_blk
	pea	t_err
	call_gemdos Cconws
	addq.l	#6,sp
	bra.w	new

sh_blk	bsr.w	clr_ln
	moveq.w	#7,d6			* Zeilen
blk1	move.l	a6,d0
	moveq.l	#6,d1
	bsr.w	outhex
	bsr.w	out_sp
	bsr.w	out_sp
	move.l	a6,a5
	move.w	#15,d5			* Spalten
blk2	cmp.l	ram_end,a6
	bcs.s	blk3
	bsr.w	out_st
	bsr.w	out_st
	bra.s	blk4
blk3	move.l	a6,addr
	bsr.w	read_byte
	moveq.b	#2,d1
	bsr.w	outhex
blk4	bsr.w	out_sp
	addq.l	#1,a6
	dbf.w	d5,blk2
	move.w	#15,d5			* Spalten
blk5	cmp.l	ram_end,a5
	bcs.s	blk6
	bsr.w	out_st
	bra.s	blk8
blk6	move.l	a5,addr
	bsr.w	read_byte
	cmp.b	#$20,d0
	bcc.s	blk7
	move.w	#'.',d0
blk7	move.w	d0,-(sp)
	move.w	#5,-(sp)
	call_bios Bconout
	addq.l	#6,sp
blk8	addq.l	#1,a5
	dbf.w	d5,blk5
	bsr.w	crs_nl
	dbf.w	d6,blk1
	pea	t_loop
	call_gemdos Cconws
	addq.l	#6,sp
tst_key	call_gemdos Cconis
	addq.l	#2,sp
	tst.w	d0
	beq.s	tstkey1
	call_gemdos Crawcin
	addq.l	#2,sp
	bra.s	tst_key
tstkey1	call_gemdos Crawcin
	addq.l	#2,sp
	bsr.w	upcase
	cmp.b	#'A',d0
	beq.w	new
	cmp.b	#'Q',d0
	beq.s	prg_end
	cmp.b	#3,d0
	beq.s	prg_end
	bra.w	sh_blk

prg_end	pea	t_end
	call_gemdos Cconws
	addq.l	#6,sp
	call_gemdos Pterm0


* Auslesen der Speicherzelle "phystop"
get_ram_end
	move.l	phystop,ram_end
	rts


* Byte lesen, a0: Adresse, d0: Byte
read_byte
	pea	get_byte
	call_xbios Supexec
	addq.l	#6,sp
	moveq.l	#0,d0
	move.b	ablage,d0
	rts

get_byte
	move.l	addr,a0
	move.b	(a0),ablage
	rts


* Wandelt Klein- in Grožbuchstaben
upcase	cmp.b	#'a',d0
	bcs.s	upcase1
	cmp.b	#'z',d0
	bhi.s	upcase1
	sub.b	#$20,d0
upcase1	rts


* Ausgabe Hex_Zahl, d0.l: Zahl, d1.w: Anz. Stellen - 0: variabel
outhex	movem.l	d0-d3,-(sp)
	move.l	d0,d3
	move.w	#9,d2
outhex1	subq.w	#1,d2
	rol.l	#4,d3
	cmp.w	d1,d2
	bhi.s	outhex1
	move.w	d3,d0	
	and.l	#$F,d0			* letzte Stelle
	add.w	#'0',d0
	cmp.w	#'9',d0
	bls.s	outhex2
	add.w	#7,d0
outhex2	movem.l	d0-d3,-(sp)
	move.w	d0,-(sp)
	move.w	#5,-(sp)		* RAWCON
	call_bios Bconout
	addq.l	#6,sp
	movem.l	(sp)+,d0-d3
	cmp.w	#1,d2
	bne.s	outhex1
	movem.l	(sp)+,d0-d3
	rts


out_st	move.w	#'*',-(sp)
	bra.s	out_ch
out_sp	move.w	#$20,-(sp)
out_ch	move.w	#5,-(sp)
	call_bios Bconout
	addq.l	#6,sp
	rts

crs_nl	pea	t_crsnl
	bra.s	outstr
clr_ln	pea	t_clrln
outstr	call_gemdos Cconws
	addq.l	#6,sp
	rts


	section data
	
titel	dc.b	esc,'E',esc,'e',esc,'v',13,10
	dc.b	'HEX-ASCII-Dump',13,10,0
t_addr	dc.b	esc,'l',13,10,'address: ',0
t_err	dc.b	13,10,'Zu grož!',13,10,0
t_loop	dc.b	'Address / Go / Quit ? ',0
t_end	dc.b	13,10,10,esc,'f',0
t_crsnl	dc.b	13,10,0
t_clrln	dc.b	esc,'l',0


	section bss

ram_end	ds.l	1
addr	ds.l	1
ablage	ds.b	1
buffer	ds.b	buf_len+2
	even
	ds.l	1000	
mystack	ds.w	1

