


; --------------= Register View Subroutine =---------------
; this subroutine displays the registers stored on the 
; user's stack after (for example) an SWI.
; ---------------------------------------------------------
reglist	dc.b	'cbaxyp'
rl_size	dc.b	0,0,0,1,1,1

***
;reg_view_sub: "m_rv.asm"
;	Called from the command line: "> rv"
;	Takes no command line arguments. Must be used AFTER a breakpoint is hit, or
;	It won't work.
;	Reg Input:
;		None
;	Reg Output
;		none
***


reg_view_sub:

	ldy		#newline		; loads a new line string
	jsr		print_string		; prints the new line string. see "serial.asm"

	ldy		SP_save			; load Y with the user's SP
	ldx		#reglist		; load X with the stuff we need to use
	ldaa		#6			; loads A with 6
rv_loop1:
	ldab		6,x			; load B with the size of the register to be printed
	cmpb		#$00			; 
	bgt		rv_double		; if its a '1' its a double!
rv_single:
	psha					; stores A
	ldaa		0,x			; loads the name of the register
	jsr		put_char		; prints the name of the register
	ldaa		#'-'			; loads the '-' character
	jsr		put_char		; prints that character
	ldaa		0,y			; loads the value in the registers position(from the stack)
	jsr		print_number		; prints that value
	pula					; restores A, which is the counter
	iny					; increments y to the next spot in the stack
	inx					; increments x to the next register (character)
	bra		rv_loop_end		; goes to the loop ending part
rv_double:
	psha					; stores A
	ldaa		0,x			; loads the register name
	jsr		put_char		; prints the register name
	ldaa		#'-'			; loads the '-' character
	jsr		put_char		; prints that character
	pula					; restores A
	pshx					; stores X
	ldx		0,y			; loads X from the stack
	jsr		print_address		; prints the value in X
	pulx					; restores X
	iny					; increments stack to the next 2 byte register in stack
	iny
	inx					; increments x to point to the name of the next register
						; then goes to the loop ending part
rv_loop_end:					
	psha					; stores A
	ldaa		#32			; loads a space character
	jsr		put_char		; prints the space character
	pula					; restores A
	deca					; decrements A
	beq		rv_done			; if A is now zero, end the routine
	bra		rv_loop1		; otherwise, keep looping
rv_done:
	rts					; returns
