


;--------------------= "GO" SUBROUTINE =---------------------
; The "go" routine just does a JMP to where the user says. It 
; doesn't mess with the stack (other than to set SP to the 
; user's stack) the "resume" function does an rts using the 
; stack to get to user's code after an SWI, for example. Use 
; that for breakpoints.
; -----------------------------------------------------------
***
;go_addr_sub: "m_go.asm"
;	Called from the command line. "> go <addr>"
;	Takes the command line arguments:
;			<addr> is the address to start the program at
;	This saves the system stack pointer, restores the user stack pointer,
;	Then jumps to the program address.
;	Reg Input:
;		None
;	Reg Output:
;		None
***

go_addr_sub:
	jsr		parse_address		; returns what we want in X

	ldy		#newline		; loads the new line string
	jsr		print_string		; prints the new line string. see "serial.asm"

*  						* i'm sure this can be replaced

	pshx					
	puly					; put the address in Y		

						; save the monitor's stack. set SP to user's
	sts		SP_save_mon		; stores system stack pointer in SP_save_mon
	lds		SP_save			; loads the user stack pointer from SP_save


	sty		go_addr			; stores the address in memory
	ldd		#0			; clears the registers so they are empty on
	ldy		#0			; executing the program
	ldx		#0

	jmp		go_jmp			; now jump to the place to execute the program

; This system uses 3 bytes of memory. The jmp command cannot be used here since the effective
; address is figured out at runtime. The other uses for the jmp command all use the registers
; which we want to be blank. So, when the monitor starts, it puts a $06 at memory location
; go_jmp. $06 is the opcode for the jump instruction. go_addr is the next two bytes after
; go_jmp so when they are placed in that location, it becomes the effective address. Then we jump
; to the $06 at the memory location go_jmp and it uses the proper effective address. It is weird,
; but it works just fine.



			