
	;=====================
	; update map location
	;=====================
	; new location is in A
update_map_location:

	; get disk location of old location
	; we do this because the disk load code will over-write WHICH_LOAD

	ldx	MAP_LOCATION
	stx	PREVIOUS_LOCATION
	ldy	location_to_file,X
	sty	WHICH_LOAD

	; save new location

	sta	MAP_LOCATION

	;==============================
	; check if need to switch disk

	tax
	lda	location_to_file,X
	cmp	WHICH_LOAD
	beq	same_disk
new_disk:
	sta	WHICH_LOAD		; point to new file
	lda	#NEW_FROM_DISK		; indicate we need to load
	sta	LEVEL_OVER
	rts

same_disk:
	lda	#NEW_LOCATION
	sta	LEVEL_OVER
	rts


	;=========================
	; Move Map NORTH
	;=========================
move_map_north:
	lda	MAP_LOCATION
	tax
	lda	exits_north,X
	jmp	update_map_location

	;=========================
	; Move Map SOUTH
	;=========================
move_map_south:
	lda	MAP_LOCATION
	tax
	lda	exits_south,X
	jmp	update_map_location

	;=========================
	; Move Map EAST
	;=========================
move_map_east:
	lda	MAP_LOCATION
	tax
	lda	exits_east,X
	jmp	update_map_location

	;=========================
	; Move Map WEST
	;=========================
move_map_west:
	lda	MAP_LOCATION
	tax
	lda	exits_west,X
	jmp	update_map_location

exits_north:
.byte LOCATION_OUTSIDE_NN	; LOCATION_POOR_GARY	=	0
.byte LOCATION_WAVY_TREE	; LOCATION_KERREK_1	=	1
.byte LOCATION_KERREK_2		; LOCATION_OLD_WELL	=	2
.byte LOCATION_OUTSIDE_LADY	; LOCATION_YELLOW_TREE	=	3
.byte LOCATION_BURN_TREES	; LOCATION_WATERFALL	=	4

.byte LOCATION_POOR_GARY	; LOCATION_HAY_BALE	=	5
.byte LOCATION_KERREK_1		; LOCATION_MUD_PUDDLE	=	6
.byte LOCATION_OLD_WELL		; LOCATION_ARCHERY	=	7
.byte LOCATION_YELLOW_TREE	; LOCATION_RIVER_STONE	=	8
.byte LOCATION_WATERFALL	; LOCATION_MOUNTAIN_PASS=	9

.byte LOCATION_HAY_BALE		; LOCATION_JHONKA_CAVE	=	10
.byte LOCATION_MUD_PUDDLE	; LOCATION_YOUR_COTTAGE	=	11
.byte LOCATION_ARCHERY		; LOCATION_LAKE_WEST	=	12
.byte LOCATION_RIVER_STONE	; LOCATION_LAKE_EAST	=	13
.byte LOCATION_MOUNTAIN_PASS	; LOCATION_OUTSIDE_INN	=	14

.byte LOCATION_JHONKA_CAVE	; LOCATION_OUTSIDE_NN	=	15
.byte LOCATION_YOUR_COTTAGE	; LOCATION_WAVY_TREE	=	16
.byte LOCATION_LAKE_WEST	; LOCATION_KERREK_2	=	17
.byte LOCATION_LAKE_EAST	; LOCATION_OUTSIDE_LADY	=	18
.byte LOCATION_OUTSIDE_INN	; LOCATION_BURN_TREES	= 	19

.byte LOCATION_CLIFF_HEIGHTS	; LOCATION_CLIFF_BASE	=	20
.byte LOCATION_EMPTY		; LOCATION_CLIFF_HEIGHTS=	21
.byte LOCATION_EMPTY		; LOCATION_TROGDOR_OUTER=	22
.byte LOCATION_EMPTY		; LOCATION_TROGDOR_LAIR	=	23

.byte LOCATION_EMPTY		; LOCATION_HIDDEN_GLEN	=	24
.byte LOCATION_EMPTY		; LOCATION_INSIDE_LADY	= 	25
.byte LOCATION_EMPTY		; LOCATION_INSIDE_NN	=	26
.byte LOCATION_EMPTY		; LOCATION_INSIDE_INN	=	27
.byte LOCATION_EMPTY		; LOCATION_EMPTY	=	28

exits_south:
.byte LOCATION_HAY_BALE		; LOCATION_POOR_GARY	=	0
.byte LOCATION_MUD_PUDDLE	; LOCATION_KERREK_1	=	1
.byte LOCATION_ARCHERY		; LOCATION_OLD_WELL	=	2
.byte LOCATION_RIVER_STONE	; LOCATION_YELLOW_TREE	=	3
.byte LOCATION_MOUNTAIN_PASS	; LOCATION_WATERFALL	=	4

.byte LOCATION_JHONKA_CAVE	; LOCATION_HAY_BALE	=	5
.byte LOCATION_YOUR_COTTAGE	; LOCATION_MUD_PUDDLE	=	6
.byte LOCATION_LAKE_WEST	; LOCATION_ARCHERY	=	7
.byte LOCATION_LAKE_EAST	; LOCATION_RIVER_STONE	=	8
.byte LOCATION_OUTSIDE_INN	; LOCATION_MOUNTAIN_PASS=	9

.byte LOCATION_OUTSIDE_NN	; LOCATION_JHONKA_CAVE	=	10
.byte LOCATION_WAVY_TREE	; LOCATION_YOUR_COTTAGE	=	11
.byte LOCATION_KERREK_2		; LOCATION_LAKE_WEST	=	12
.byte LOCATION_OUTSIDE_LADY	; LOCATION_LAKE_EAST	=	13
.byte LOCATION_BURN_TREES	; LOCATION_OUTSIDE_INN	=	14

.byte LOCATION_POOR_GARY	; LOCATION_OUTSIDE_NN	=	15
.byte LOCATION_KERREK_1		; LOCATION_WAVY_TREE	=	16
.byte LOCATION_OLD_WELL		; LOCATION_KERREK_2	=	17
.byte LOCATION_YELLOW_TREE	; LOCATION_OUTSIDE_LADY	=	18
.byte LOCATION_WATERFALL	; LOCATION_BURN_TREES	= 	19

.byte LOCATION_CLIFF_HEIGHTS	; LOCATION_CLIFF_BASE	=	20
.byte LOCATION_EMPTY		; LOCATION_CLIFF_HEIGHTS=	21
.byte LOCATION_EMPTY		; LOCATION_TROGDOR_OUTER=	22
.byte LOCATION_EMPTY		; LOCATION_TROGDOR_LAIR	=	23

.byte LOCATION_EMPTY		; LOCATION_HIDDEN_GLEN	=	24
.byte LOCATION_OUTSIDE_LADY	; LOCATION_INSIDE_LADY	= 	25
.byte LOCATION_OUTSIDE_NN	; LOCATION_INSIDE_NN	=	26
.byte LOCATION_OUTSIDE_INN	; LOCATION_INSIDE_INN	=	27
.byte LOCATION_EMPTY		; LOCATION_EMPTY	=	28

exits_east:
.byte LOCATION_KERREK_1		; LOCATION_POOR_GARY	=	0
.byte LOCATION_OLD_WELL		; LOCATION_KERREK_1	=	1
.byte LOCATION_YELLOW_TREE	; LOCATION_OLD_WELL	=	2
.byte LOCATION_WATERFALL	; LOCATION_YELLOW_TREE	=	3
.byte LOCATION_EMPTY		; LOCATION_WATERFALL	=	4

.byte LOCATION_MUD_PUDDLE	; LOCATION_HAY_BALE	=	5
.byte LOCATION_ARCHERY		; LOCATION_MUD_PUDDLE	=	6
.byte LOCATION_RIVER_STONE	; LOCATION_ARCHERY	=	7
.byte LOCATION_MOUNTAIN_PASS	; LOCATION_RIVER_STONE	=	8
.byte LOCATION_CLIFF_BASE	; LOCATION_MOUNTAIN_PASS=	9

.byte LOCATION_YOUR_COTTAGE	; LOCATION_JHONKA_CAVE	=	10
.byte LOCATION_LAKE_WEST	; LOCATION_YOUR_COTTAGE	=	11
.byte LOCATION_LAKE_EAST	; LOCATION_LAKE_WEST	=	12
.byte LOCATION_OUTSIDE_INN	; LOCATION_LAKE_EAST	=	13
.byte LOCATION_EMPTY		; LOCATION_OUTSIDE_INN	=	14

.byte LOCATION_WAVY_TREE	; LOCATION_OUTSIDE_NN	=	15
.byte LOCATION_KERREK_2		; LOCATION_WAVY_TREE	=	16
.byte LOCATION_OUTSIDE_LADY	; LOCATION_KERREK_2	=	17
.byte LOCATION_BURN_TREES	; LOCATION_OUTSIDE_LADY	=	18
.byte LOCATION_EMPTY		; LOCATION_BURN_TREES	= 	19

.byte LOCATION_EMPTY		; LOCATION_CLIFF_BASE	=	20
.byte LOCATION_TROGDOR_OUTER	; LOCATION_CLIFF_HEIGHTS=	21
.byte LOCATION_TROGDOR_LAIR	; LOCATION_TROGDOR_OUTER=	22
.byte LOCATION_EMPTY		; LOCATION_TROGDOR_LAIR	=	23

.byte LOCATION_POOR_GARY	; LOCATION_HIDDEN_GLEN	=	24
.byte LOCATION_EMPTY		; LOCATION_INSIDE_LADY	= 	25
.byte LOCATION_EMPTY		; LOCATION_INSIDE_NN	=	26
.byte LOCATION_EMPTY		; LOCATION_INSIDE_INN	=	27
.byte LOCATION_EMPTY		; LOCATION_EMPTY	=	28

exits_west:
.byte LOCATION_HIDDEN_GLEN	; LOCATION_POOR_GARY	=	0
.byte LOCATION_POOR_GARY	; LOCATION_KERREK_1	=	1
.byte LOCATION_KERREK_1		; LOCATION_OLD_WELL	=	2
.byte LOCATION_OLD_WELL		; LOCATION_YELLOW_TREE	=	3
.byte LOCATION_YELLOW_TREE	; LOCATION_WATERFALL	=	4

.byte LOCATION_EMPTY		; LOCATION_HAY_BALE	=	5
.byte LOCATION_HAY_BALE		; LOCATION_MUD_PUDDLE	=	6
.byte LOCATION_MUD_PUDDLE	; LOCATION_ARCHERY	=	7
.byte LOCATION_ARCHERY		; LOCATION_RIVER_STONE	=	8
.byte LOCATION_RIVER_STONE	; LOCATION_MOUNTAIN_PASS=	9

.byte LOCATION_EMPTY		; LOCATION_JHONKA_CAVE	=	10
.byte LOCATION_JHONKA_CAVE	; LOCATION_YOUR_COTTAGE	=	11
.byte LOCATION_YOUR_COTTAGE	; LOCATION_LAKE_WEST	=	12
.byte LOCATION_LAKE_WEST	; LOCATION_LAKE_EAST	=	13
.byte LOCATION_LAKE_EAST	; LOCATION_OUTSIDE_INN	=	14

.byte LOCATION_EMPTY		; LOCATION_OUTSIDE_NN	=	15
.byte LOCATION_OUTSIDE_NN	; LOCATION_WAVY_TREE	=	16
.byte LOCATION_WAVY_TREE	; LOCATION_KERREK_2	=	17
.byte LOCATION_KERREK_2		; LOCATION_OUTSIDE_LADY	=	18
.byte LOCATION_OUTSIDE_LADY	; LOCATION_BURN_TREES	= 	19

.byte LOCATION_EMPTY		; LOCATION_CLIFF_BASE	=	20
.byte LOCATION_EMPTY		; LOCATION_CLIFF_HEIGHTS=	21
.byte LOCATION_CLIFF_HEIGHTS	; LOCATION_TROGDOR_OUTER=	22
.byte LOCATION_EMPTY		; LOCATION_TROGDOR_LAIR	=	23

.byte LOCATION_EMPTY		; LOCATION_HIDDEN_GLEN	=	24
.byte LOCATION_EMPTY		; LOCATION_INSIDE_LADY	= 	25
.byte LOCATION_EMPTY		; LOCATION_INSIDE_NN	=	26
.byte LOCATION_EMPTY		; LOCATION_INSIDE_INN	=	27
.byte LOCATION_EMPTY		; LOCATION_EMPTY	=	28

location_to_file:
.byte LOAD_PEASANT1		; LOCATION_POOR_GARY	=	0
.byte LOAD_PEASANT1		; LOCATION_KERREK_1	=	1
.byte LOAD_PEASANT1		; LOCATION_OLD_WELL	=	2
.byte LOAD_PEASANT1		; LOCATION_YELLOW_TREE	=	3
.byte LOAD_PEASANT1		; LOCATION_WATERFALL	=	4

.byte LOAD_PEASANT2		; LOCATION_HAY_BALE	=	5
.byte LOAD_PEASANT2		; LOCATION_MUD_PUDDLE	=	6
.byte LOAD_PEASANT2		; LOCATION_ARCHERY	=	7
.byte LOAD_PEASANT2		; LOCATION_RIVER_STONE	=	8
.byte LOAD_PEASANT2		; LOCATION_MOUNTAIN_PASS=	9

.byte LOAD_PEASANT3		; LOCATION_JHONKA_CAVE	=	10
.byte LOAD_PEASANT3		; LOCATION_YOUR_COTTAGE	=	11
.byte LOAD_PEASANT3		; LOCATION_LAKE_WEST	=	12
.byte LOAD_PEASANT3		; LOCATION_LAKE_EAST	=	13
.byte LOAD_PEASANT3		; LOCATION_OUTSIDE_INN	=	14

.byte LOAD_PEASANT4		; LOCATION_OUTSIDE_NN	=	15
.byte LOAD_PEASANT4		; LOCATION_WAVY_TREE	=	16
.byte LOAD_PEASANT4		; LOCATION_KERREK_2	=	17
.byte LOAD_PEASANT4		; LOCATION_OUTSIDE_LADY	=	18
.byte LOAD_PEASANT4		; LOCATION_BURN_TREES	= 	19

.byte LOAD_CLIFF		; LOCATION_CLIFF_BASE	=	20
.byte LOAD_CLIFF		; LOCATION_CLIFF_HEIGHTS=	21
.byte LOAD_CLIFF		; LOCATION_TROGDOR_OUTER=	22
.byte LOAD_TROGDOR		; LOCATION_TROGDOR_LAIR	=	23

.byte LOAD_INSIDE		; LOCATION_HIDDEN_GLEN	=	24
.byte LOAD_INSIDE		; LOCATION_INSIDE_LADY	= 	25
.byte LOAD_INSIDE		; LOCATION_INSIDE_NN	=	26
.byte LOAD_INN			; LOCATION_INSIDE_INN	=	27

.byte LOAD_ARCHERY		; LOCATION_ARCHERY_GAME	=	28
.byte LOAD_MAP			; LOCATION_MAP		=	29

.byte LOCATION_EMPTY		; LOCATION_EMPTY	=	30

