

; -----------------= EDIT MEMORY SUBROUTINE =------------------
; should be called memory modify. changes memory at addr by
; putting <val> in there.
; cmd: mm <addr> <val>
; -------------------------------------------------------------
edit_mem_sub:
	
	pshy 					; these are just to save the regs from modification
	pshx					; stores state
	pshd					; stores state
	
	jsr		parse_address		; returns address in X
	cmpb		#$ff			; error?
	beq		em_done			; if yes, done
     
	ldaa		0,x			; get the old value
	psha					; save for later use	

	jsr		parse_byte		; returns byte in A
	cmpb		#$ff			; error?
	beq		em_done_up		; yes, quit

	psha					; print_string doesn't preserve A it would seem!
	ldy		#newline		; loads a new line string
	jsr		print_string		; prints the new line. see "serial.asm"
	ldy		#em_2			; "Old value: "
	jsr		print_string		; prints the string
	pula					; restore A

*						* this section seems retarded. see if it can be removed

	pulb					; pull the old value from the stack
	psha					; push the new value

*						* can be replaced probably
	pshb					; push the old value
	pula					; pull the old value into a

	jsr		print_number		; print the old value	

	pula					; pull the new value

	staa		0,x			; put the new number into
						; that memory location
	bra		em_done			; finish up

em_done_up:
	pula					; we need to pull A because it was put on

em_done:
	puld					; restore the registers
	pulx
	puly 

	rts					; returns

