; -----------------------------------------------
; --- extern declared SFRs
; -----------------------------------------------
	extern _STATUS
	extern _FSR0
	extern _INDF0
	extern _PCLATH
	extern _PCL0
	extern _FSR1

C	EQU	0
DC	EQU	1
Z	EQU	2
	
; -----------------------------------------------
; --- generic pointer access helpers
; -----------------------------------------------

GPTRTAG_DATA	EQU	0x00
GPTRTAG_CODE	EQU	0x80

; setup FSR to point to (STK00:STK01)
setup_fsr	macro
	movr	STK01, 0
	movar	_FSR0
	; select indirectly addressed bank
	;bclr	_STATUS, IRP
	;jbts0	STK00, 0
	;bclr	_STATUS, IRP
	endm

; increment FSR, update IRP on bank crossings
; FIXME: update IRP if FSR is reset to 0...
inc_fsr		macro
	incr	_FSR0, 1
	endm

; dispatch according to gptr type
select_routine	macro	dataptr, codeptr
	; __data pointer tag: 0x00
	xoria	GPTRTAG_DATA
	jbts0	_STATUS, Z
	goto	dataptr
	; __code pointer tag: 0x80
	xoria	(GPTRTAG_DATA ^ GPTRTAG_CODE)
	jbts0	_STATUS, Z
	goto	codeptr
	endm

check_data	macro	dataptr
	; __data pointer tag: 0x00
	xoria	GPTRTAG_DATA
	jbts0	_STATUS, Z
	goto	dataptr
	endm

