.assume ADL=1
;Call.lil MonitorL (ADL mode)
;call.sil MonitorL (z80 mode)
MonitorL:
	call Monitor
	ret.l		;Return (supports both Z80 and ADL)
	

;(Z80)
;ld hl,$0000
;ld bc,32
;call.sil Monitor_MemDumpL
;(adl)
;ld hl,$D10000  ;WARNING - Top byte (D1) replaced with MB
;ld bc,32
;call.lil Monitor_MemDumpL
Monitor_MemDumpL:
	push ix
	push hl
		ld ix,0
		add ix,sp
		ld a,mb			;Address= $MBHHLL
		ld (ix+2),a
	pop hl
	pop ix
	call Monitor_MemDump	
	ret.l		;Return (supports both Z80 and ADL)
	
	
	
ShowHex:	
	push af
		and %11110000
		rrca
		rrca
		rrca
		rrca
		call PrintHexChar
	pop af
	and %00001111
PrintHexChar:
	or a	;Clear Carry Clag
	daa
	add a,$F0
	adc a,$40
	call PrintChar
	ret

Monitor:
	push af
	push bc
	push de
	push hl
	push ix
	push ix
		push bc
			ld b,'A'
			ld c,'F'
			push AF
			pop ix
			call MonitorOne8
			
			;call NewLine
			
			ld b,'B'
			ld c,'C'

		pop ix
		call MonitorOne
		
		ld b,'D'
		ld c,'E'
		push DE
		pop ix
		call MonitorOne
		
		ld b,'H'
		ld c,'L'
		push HL
		pop ix
		call MonitorOne
		
		call NewLine
		
		ld b,'I'
		ld c,'X'
	pop ix
	call MonitorOne
	
	ld b,'I'
	ld c,'Y'
	push iy
	pop ix
	call MonitorOne
	;call NewLine
	
	
	ld b,15
mon1:
	inc sp
	djnz mon1
	
	pop ix
	push ix
	
	ld b,15
mon2:
	dec sp
	djnz mon2

	ld b,'P'
	ld c,'C'
	call MonitorOne
	
	
	ld ix,18
	add ix,sp
	
	ld b,'S'
	ld c,'P'
	call MonitorOne
	
	call NewLine
	
	ld b,'s'
	ld c,'p'
	ld ix,0
	add.sis ix,sp
	call MonitorOne8
	
	ld b,' '
	ld c,'I'
	ld hl,i
	push hl
	pop ix
	call MonitorOne8
	
	ld b,'M'
	ld c,'B'
	ld a,mb
	call MonitorOne8b
	
	call NewLine
	
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	ret
MonitorOne8b:
	push ix
		push af
			call MonitorLabel
			ld a,' '
			call PrintChar
			call PrintChar
			call PrintChar
			call PrintChar
		pop af
		jr MonitorOneC2
		
MonitorOne8:
	push ix
		call MonitorLabel
		ld a,' '
		call PrintChar
		call PrintChar
		jr MonitorOneB

MonitorOneShow24bit:
	push ix	
	jr MonitorOneAlt
MonitorOne:
	push ix
		call MonitorLabel
MonitorOneAlt:
		ld a,(ix+2)
		call ShowHex
MonitorOneB:
		ld a,(ix+1)
		call ShowHex
MonitorOneC:
		ld a,(ix+0)
MonitorOneC2:
		call ShowHex
		ld a,' '
		call PrintChar
	pop ix
	ret
	
MonitorLabel:
	ld a,b
	call PrintChar
	ld a,c
	call PrintChar
	ld a,':'
	call PrintChar
	
	ld ix,3
	add ix,sp
	ret	
	
	
Monitor_MemDump:		
	push bc
		ld b,'>'
		ld c,b
		push hl
		pop ix
		call MonitorOne
	pop bc
		call NewLine
Monitor_MemDumpAgain:
		ld a,c

		;We need to check if there is a full line of data left, and show 
		;less bytes if there is not.

		cp 8				;And 8 on everything else!
		jr c,Monitor_MemDump_lessthan8
		ld a,8
	
				;Show data as HEX
Monitor_MemDump_lessthan8:
		ld b,a
		ld a,c
		sub b
		ld c,a
	push bc
	push hl
Monitor_MemDump_HexAgain:

		ld a,(hl)			;Read in a byte
		call ShowHex			;Show it as hex		

		ld a,' '
		call PrintChar			;Print a space

		inc hl
		dec b
		jr nz,Monitor_MemDump_HexAgain
	pop hl
	pop bc
				;Show data as Letters
Monitor_MemDump_CharAgain:
	ld a,(hl)
	
	cp 32
	jr nc,Monitor_MemDump_CharOK

Monitor_MemDump_CharBad:
	ld a,'.'			;Show a . for unshowable characters

Monitor_MemDump_CharOK:
	call PrintChar
	inc hl
	dec b
	jr nz,Monitor_MemDump_CharAgain
	
	call NewLine			;40 character screens need a newline, others do not!
	ld a,c
	or a
	jr nz,Monitor_MemDumpAgain
	ret