;RAM DEFINE
;;============== page0 =========================
Temp1_PAGE	Textequ	<Page0>
Temp2_PAGE	Textequ	<Page0>
Temp6_PAGE	Textequ	<Page4>
V_STATE_page	Textequ	<Page0>		
;=============== 4bit RAM DEFINE ===============
p3state_page	Textequ		<PAGE0>
VolValue_Page0_PAGE	Textequ		<PAGE0>
Rand0_PAGE	Textequ		<PAGE2>
Rand1_PAGE	Textequ		<PAGE2>
Rand2_PAGE	Textequ		<PAGE2>
p3_go1_PAGE	Textequ		<PAGE2>
P3S_STATE_page	Textequ		<PAGE1>
p_delay1_PAGE	Textequ		<PAGE2>
S_delay1_PAGE	Textequ		<PAGE1>
Delay_Flag_PAGE	Textequ		<PAGE1>
delay8m_PAGE	Textequ		<PAGE1>

M0_Page		Textequ	<Page3>
M1_Page		Textequ	<Page3>
M2_Page		Textequ	<Page3>
M3_Page		Textequ	<Page3>
M4_Page		Textequ	<Page3>
M5_Page		Textequ	<Page3>
M6_Page		Textequ	<Page3>
M7_Page		Textequ	<Page3>
M8_Page		Textequ	<Page3>
M9_Page		Textequ	<Page3>
M10_Page	Textequ	<Page3>
M11_Page	Textequ	<Page3>
M12_Page	Textequ	<Page3>
M13_Page	Textequ	<Page3>
M14_Page	Textequ	<Page3>
M15_Page	Textequ	<Page3>
IRout_ON_OFF_3_0_page Textequ	<Page4>
TRIGGER_FLAG_3_1_page Textequ	<Page4>
IRin_ON_OFF_3_2_page  Textequ	<Page4>
IR_TX_P33_ON_OFF_3_3_page  Textequ	<Page4> 
TRANS_L_PAGE	Textequ	<Page4>
TRANS_H_PAGE	Textequ	<Page4>
EZIO_flag_PAGE	Textequ	<Page4>
EZ_IOH_PAGE	Textequ	<Page4>
EZ_IOL_PAGE	Textequ	<Page4>
EZ_Mark_PAGE	Textequ	<Page4>
Next_flag_page	Textequ	<Page4>
EZIO_FG_page	Textequ	<Page0>
Bit0		equ		#0001b
Bit1		equ		#0010b
Bit2		equ		#0100b
Bit3		equ		#1000b
;=============== 8bit RAM DEFINE ===============
X0_Page		Textequ	<Page3>
X1_Page		Textequ	<Page3>
X2_Page		Textequ	<Page3>
X3_Page		Textequ	<Page3>
X4_Page		Textequ	<Page3>
X5_Page		Textequ	<Page3>
X6_Page		Textequ	<Page3>
X7_Page		Textequ	<Page3>

X0_Low		Textequ	<m0>
X0_High		Textequ	<m1>
X1_Low		Textequ	<m2>
X1_High		Textequ	<m3>
X2_Low		Textequ	<m4>
X2_High		Textequ	<m5>
X3_Low		Textequ	<m6>
X3_High		Textequ	<m7>
X4_Low		Textequ	<m8>
X4_High		Textequ	<m9>
X5_Low		Textequ	<m10>
X5_High		Textequ	<m11>
X6_Low		Textequ	<m12>
X6_High		Textequ	<m13>
X7_Low		Textequ	<m14>
X7_High		Textequ	<m15>

Bit0_Low	equ	#0001b
Bit0_High	equ	#0000b
Bit1_Low	equ	#0010b
Bit1_High	equ	#0000b
Bit2_Low	equ	#0100b
Bit2_High	equ	#0000b
Bit3_Low	equ	#1000b
Bit3_High	equ	#0000b
Bit4_Low	equ	#0000b
Bit4_High	equ	#0001b
Bit5_Low	equ	#0000b
Bit5_High	equ	#0010b
Bit6_Low	equ	#0000b
Bit6_High	equ	#0100b
Bit7_Low	equ	#0000b
Bit7_High	equ	#1000b
;=============== I/O DEFINE ===============
P1_Page		Textequ	<page2>
P2_Page		Textequ	<page2>
P3_Page		Textequ	<page2>
P2_Low		Textequ	<p2_go1>
P2_High		Textequ	<p2_go2>
P3_Low		Textequ	<p3_go1>
P3_High		Textequ	<p3_go2>
P1_Low		Textequ	<p1_go1>
P1_High		Textequ	<p1_go2>
;================== 4 BIT COMMAND ============================
DisableEZIO_@@	MACRO
ifdef 	@@_EZ_IO_@@
	mov	a	#0
	EZ_Mark_&PAGE
	mov	EZIO_flag	a
	mov	EZIO_timerH		a
	mov	EZIO_timerL		a
	mov	EZ_Mark	a
endif
	endm
	
Clr_EZIO_MARK	MACRO
ifdef 	@@_EZ_IO_@@
	EZ_Mark_&PAGE
	mov	a	#0
	mov	EZ_Mark	a
endif	
	endm
;=============================  FG XXX.eio (no wave playing EZIO) ============================================		
EIO_Name	MACRO	EIO_Name
        EZIO_flag_&PAGE
        mov	a	EZIO_flag
        caje	#0000b	@f
        caje	#0101b	@f
        caje	#0111b	@f
	stop
@@:
	DisableEZIO_@@
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0111b
	EZIO_FG_&page
	mov	a	#0010b
	or	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call1 	@@EZIO_Item
	EZIO_FG_&page
	mov	a	#1101b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0001b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL1	@@SCANKEY1
	ENDM
;============================= FG XXX.eio_WV ((wave playing EZIO)) ============================================		
EIO_Name_WV	MACRO	EIO_Name
	DisableEZIO_@@
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#0010b
	or	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call1 	@@EZIO_Item
	PLAY	EIO_Name.wav
	EZIO_FG_&page
	mov	a	#1101b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0001b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL1	@@SCANKEY1
	ENDM

;============================= FG XXX.eio_X ((wave playing EZIO)+Guarentee resolution/size X) ============================================		
EIO_Name_X	MACRO	EIO_Name X
	DisableEZIO_@@
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#0010b
	or	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call1 	@@EZIO_Item
	PLAY	EIO_Name.wav_&X
	EZIO_FG_&page
	mov	a	#1101b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0001b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL1	@@SCANKEY1
	ENDM
;===============================FG XXX.eio_S_WV (wave playing EZIO <special combination of wave with eio file>)=======================================================
EIO_Name_S_WV	MACRO	WAV_Name,EIO_Name
	DisableEZIO_@@
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#0010b
	or	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call1 	@@EZIO_Item
	PLAY	WAV_Name.wav
	EZIO_FG_&page
	mov	a	#1101b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0001b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL1	@@SCANKEY1
	ENDM

;=========FG XXX.eio_S_X (wave playing EZIO <special combination of wave with eio file>+Guarentee resolution/size X)=============
EIO_Name_S_X	MACRO	WAV_Name,EIO_Name,X
	DisableEZIO_@@
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#0010b
	or	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call1 	@@EZIO_Item
	PLAY	WAV_Name.wav_&X
	EZIO_FG_&page
	mov	a	#1101b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0001b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL1	@@SCANKEY1
	ENDM
;========================= BG XXX.eio (no wave playing EZIO)===========================		
EIO_Name_P	MACRO	EIO_Name
        EZIO_flag_&PAGE
        mov	a	EZIO_flag
        caje	#0000b	@f
        caje	#0101b	@f
        caje	#0111b	@f
	stop
@@:
	DisableEZIO_@@
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0111b		; EZIO_flag bit2=1 ==> no wave playing ezio
	EZIO_FG_&page
	mov	a	#1101b
	and	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call2 	@@EZIO_Item
	EZIO_FG_&page
	mov	a	#0111b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0100b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL2	@@SCANKEY1
	ENDM
;========================= BG XXX.eio_WV (4 bit)===========================
EIO_Name_WV_P	MACRO	EIO_Name
	DisableEZIO_@@
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#1101b
	and	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call2 	@@EZIO_Item
	PLAY	EIO_Name.wav
	EZIO_FG_&page
	mov	a	#0111b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0100b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL2	@@SCANKEY1
	ENDM

;========================= BG XXX.eio_X (4 bit)+Guarentee resolution/size X===========================
EIO_Name_X_P	MACRO	EIO_Name X
	DisableEZIO_@@
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#1101b
	and	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	call2 	@@EZIO_Item
	PLAY	EIO_Name.wav_&X
	EZIO_FG_&page
	mov	a	#0111b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0100b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL2	@@SCANKEY1
	ENDM
;========================= BG XXX.eio_S_WV (4 bit)===========================
EIO_Name_S_WV_P	MACRO	WAV_Name,EIO_Name
	DisableEZIO_@@
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#1101b
	and	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	CALL2 	@@EZIO_Item
	PLAY	WAV_Name.wav
	EZIO_FG_&page
	mov	a	#0111b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0100b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL2	@@SCANKEY1
	ENDM

;========================= BG XXX.eio_S_X (4 bit)+Guarentee resolution/size X===========================
EIO_Name_S_X_P	MACRO	WAV_Name,EIO_Name,X
	DisableEZIO_@@
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	EZIO_flag_&PAGE
	mov	EZIO_flag	#0011b
	EZIO_FG_&page
	mov	a	#1101b
	and	a	EZIO_FG
	mov	EZIO_FG	a
	playm	EIO_Name.eio
	CALL2 	@@EZIO_Item
	PLAY	WAV_Name.wav_&X
	EZIO_FG_&page
	mov	a	#0111b
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#0100b
	or	a	ret_flag
	mov	ret_flag	a
	rstcf
	CALL2	@@SCANKEY1
	ENDM
;==================================================================================

;Mi=data
Mi_Data	MACRO	Mi,Value
	Mi&_PAGE
	mov	Mi	#Value
	ENDM

;Mi=Mj
Mi_Mj	MACRO	Mi,Mj
	Mi&_PAGE
	mov	a	Mj
	mov	Mi	a
	ENDM
	
;Mi(n)	i=0~15,n=0~3
Mi@n_0	MACRO	Mi,Bit
	Temp2&_PAGE
	mov	temp2	#1111b
	mov	a	Bit
	xor	a	temp2
	Mi&_PAGE
	and	a	Mi
	mov	Mi	a
	ENDM

Mi@n_1	MACRO	Mi,Bit
	Mi&_PAGE
	mov	a	Bit
	or	a	Mi
	mov	Mi	a
	ENDM	

;Mi=Mj.and.data
Mi_Mj_AND_Data	MACRO	Mi,Mj,Value
	Mj&_PAGE
	mov	a	#Value	!& 0xf
	and	a	Mj
	mov	Mi	a
	ENDM

;Mi=Mj.and.Mk
Mi_Mj_AND_Mk	MACRO	Mi,Mj,Mk
	Mj&_PAGE
	mov	a	Mk
	and	a	Mj
	mov	Mi	a
	ENDM

;Mi=Mj.or.data
Mi_Mj_OR_Data	MACRO	Mi,Mj,Value
	Mj&_PAGE
	mov	a	#Value	!& 0xf
	or	a	Mj
	mov	Mi	a
	ENDM

;Mi=Mj.or.Mk
Mi_Mj_OR_Mk	MACRO	Mi,Mj,Mk
	Mj&_PAGE
	mov	a	Mk
	or	a	Mj
	mov	Mi	a
	ENDM

;Mi=Mj.xor.data
Mi_Mj_XOR_Data	MACRO	Mi,Mj,Value
	Mj&_PAGE
	mov	a	#Value	!& 0xf
	xor	a	Mj
	mov	Mi	a
	ENDM

;Mi=Mj.xor.Mk
Mi_Mj_XOR_Mk	MACRO	Mi,Mj,Mk
	Mj&_PAGE
	mov	a	Mk
	xor	a	Mj
	mov	Mi	a
	ENDM

;.inv.Mi
_INV_Mi	MACRO	Mi
	Mi&_PAGE
	mov	a	#1111b
	xor	a	Mi
	mov	Mi	a
	ENDM


;.inv.Mi(n)	n=0~3
_INV_Mi@n	MACRO	Mi,Bit
	Mi&_PAGE
	mov	a	Bit
	xor	a	Mi
	mov	Mi	a
	ENDM

;Trn?H:Pathname
Trn?H_LABEL	MACRO	Port,N,LABEL
	mov	a	Port
;	Temp1&_PAGE
	page4
	mov	temp6	N !& 0xF
	and	a	temp6	
	caje	N !& 0xF	LABEL
	ENDM
	
Trn?H_LABEL_S	MACRO	PortA,PortB,N,M,LABEL
	mov	a	n
	page4
	mov	PortB	a
	nop
	nop
	mov	a	PortA
	mov	temp6	m
	and	a	temp6	
	caje	M !& 0xF	LABEL
	ENDM			
	
;Trn?L:Pathname
Trn?L_LABEL	MACRO	Port,N,LABEL
	mov	a	Port
;	Temp1&_PAGE
	page4
	mov	temp6	N !& 0xF
	and	a	temp6
	caje	#0000b	LABEL
	ENDM
	
Trn?L_LABEL_S	MACRO	PortA,PortB,N,LABEL
	mov	a	n
;	Temp1&_PAGE
	page4
	mov	PortB	a
	mov	a	PortA
	and	a	temp6	
	caje	#0000b	LABEL
	ENDM	
		
;Mi?data:PathName
Mi?Data_LABEL	MACRO	Mi,Value,LABEL
	Mi&_PAGE
	mov	a	Mi
	caje	#Value !& 0xF	LABEL
	ENDM

;Mi?Mj:PathName
Mi?Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a	Mi
	caje	Mj	LABEL
	ENDM
	
;Mi:[path0 path1 path2....pathn]
Switch_Mi  MACRO   Mi,lab:VARARG
local	@@scankey1 
        temp = 0
        FOR ll, <lab>
        	Mi&_PAGE
                mov    a	Mi
     
	   IFDIFI <ll>,<X>			
                caje # (temp !!!& 0xF), !&ll
           ENDIF
                temp = temp + 1
	ENDM 
@@scankey1:	
      ENDM

;Mi(n)?0:PathName
Mi@n_0_LABEL	MACRO	Mi,Bit,LABEL
	Mi&_PAGE
	mov	a	Bit
	and	a	Mi
	caje	#0	LABEL
	ENDM

;Mi(n)?1:PathName
Mi@n_1_LABEL	MACRO	Mi,Bit,LABEL
	Mi&_PAGE
	mov	a	Bit
	and	a	Mi
	caje	Bit	LABEL
	ENDM

;Randn?data:PathName
Rand?Data_LABEL	MACRO	Rand,Value,LABEL
	Rand&_PAGE
	mov	a	Rand
	caje	#Value !& 0xF	LABEL
	ENDM

;Randn?Mi:PathName
Rand?Mi_LABEL	MACRO	Rand,Mi,LABEL
	Rand&_PAGE
	mov	a	Rand
	Mi&_PAGE
	caje	Mi	LABEL
	ENDM

;Randn:[Path0 Path1 ...Pathn]
Switch_Rand  MACRO   Rand,lab:VARARG
local	@@scankey1
        temp = 0
        FOR ll, <lab>
        	Rand&_PAGE
                mov    a	Rand
           
	   IFDIFI <ll>,<X>			
                caje # (temp !!!& 0xF), !&ll
           ENDIF
                temp = temp + 1
     	ENDM 
@@scankey1:     	
      ENDM

;Pn?[01x0]:PathName
;Pn?[xdxd]:[Path0 Path1 .... Pathn]

;Pn_Data_LABEL	MACRO	Pn,Value,LABEL
;	mov	a	Pn
;	caje	Value	LABEL
;	ENDM

;Mi=Pn
Mi_Pn	MACRO	Mi,Pn
	Mi&_PAGE
	mov	a	Pn
	mov	Mi	a
	ENDM
/*	
;Mi=Mj-data
Mi_Mj-data	MACRO	Sum,A1,Value
local	@@dec_ok

	A1&_page
	mov	a	A1
	page0
	mov	temp1	a
	mov	temp2	#Value !& 0XF
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	temp2
	caje	#0	@@dec_ok
@@:
	mov	a	temp1
	inca
	mov	temp1	a
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	#1111b
	xor	a	temp2
	mov	temp2	a
	caje	#0	@F
	jmp	@B
@@:	
@@dec_ok:
	mov	a	temp1
	Sum&_page
	mov	Sum	a
	endm
*/	
;Pn=Mi
Pn_Mi	MACRO	Pn,Mi
	Mi&_PAGE
	mov	a	Mi
	Pn&_PAGE
	mov	Pn&_GO1 a
	mov	Pn&_GO2 #0000B
	ENDM
	
;Mi=Randn
;Mi_Randn	MACRO	Mi,Rand
;	Rand&_PAGE
;	mov	a	Rand
;	Mi&_PAGE
;	mov	Mi	a
;	ENDM
;Mi=Randn
Mi_Randn	MACRO	Mi,Rand
	Rand&_PAGE
	mov	a	Rand
	Mi&_PAGE
	mov	Mi	a
	ENDM	
	
;Mi>Mj?:PathName
Mi_G_Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a, Mj
@@:
	caje	#0Fh	@F
	inca
	caje	Mi	LABEL
	jmp	@B
@@:	
	ENDM
	
;Mi>=Mj?:PathName
Mi_GE_Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a	Mj
@@:
	caje	Mi	LABEL
	caje	#0Fh	@F
	inca
	jmp	@B
@@:
	ENDM
	
;Mi<Mj?:PathName
Mi_S_Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a	Mi
@@:
	caje	#0Fh	@F
	inca
	caje	Mj	LABEL
	jmp	@B
@@:
	ENDM
	
;Mi<=Mj?:PathName
Mi_SE_Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a	Mi
@@:
	caje	Mj	LABEL
	caje	#0Fh	@F
	inca
	jmp	@B
@@:
	ENDM
	
;Mi>data?:PathName
Mi_G_Data_LABEL		MACRO	Mi,Value,LABEL
	Mi&_PAGE
	mov	a	#Value !& 0xf
@@:
	caje	#0Fh	@F
	inca
	caje	Mi	LABEL
	jmp	@B
@@:
	ENDM	
	
;Mi>=data?:PathName
Mi_GE_Data_LABEL	MACRO	Mi,Value,LABEL
	Mi&_PAGE
	mov	a	#Value !& 0xf
@@:
	caje	Mi	LABEL
	caje	#0Fh	@F
	inca
	jmp	@B
@@:
	ENDM
	
;Mi<data?:PathName
Mi_S_Data_LABEL		MACRO	Mi,Value,LABEL
	Mi&_PAGE
	mov	a	Mi
@@:
	caje	#0Fh	@F
	inca
	caje	#Value !& 0xf	LABEL
	jmp	@B
@@:
	ENDM
;Mi<=data?:PathName
Mi_SE_Data_LABEL	MACRO	Mi,Value,LABEL
	Mi&_PAGE
	mov	a	Mi
@@:
	caje	#Value !& 0xf	LABEL
	caje	#0Fh	@F
	inca
	jmp	@B
@@:
	ENDM
	
;Mi!=Mj?:PathName
Mi_NE_Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a	Mi
	caje	Mj	@F
	jmp	LABEL
@@:
	ENDM
	
;Mi!=data?:PathName
Mi_NE_Data_LABEL	MACRO	Mi,Value,LABEL
	Mi&_PAGE
	mov	a	Mi
	caje	#Value !& 0xf	@F
	jmp	LABEL
@@:
	ENDM

;;------------------------------------------	
;Mi=Mj+Mk
Mi_Mj+Mk	MACRO	Mi,Mj,Mk
	Mj&_PAGE
	mov	a	Mj
	page4
	mov	temp6	a
	Mk&_PAGE
	mov	a	Mk
	Temp2&_PAGE
	mov	temp2	a
@@:
	page4
	mov	a	temp6
	inca
	mov	temp6	a
	Temp2&_PAGE
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	#1111b
	xor	a	temp2
	mov	temp2	a
	caje	#0	@F
	jmp	@B
@@:
	page4
	mov	a	temp6
	Mi&_PAGE
	mov	Mi	a
	ENDM
	

;Mi=Mj+data
Mi_Mj+Data	MACRO	Mi,Mj,Value
	Mj&_PAGE
	mov	a	Mj
	page4
	mov	temp6	a
	Temp2&_PAGE
	mov	temp2	#Value
@@:
	page4
	mov	a	temp6
	inca
	mov	temp6	a
	Temp2&_PAGE
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	#1111b
	xor	a	temp2
	mov	temp2	a
	caje	#0	@F
	jmp	@B
@@:
	page4
	mov	a	temp6
	Mi&_PAGE
	mov	Mi	a
	ENDM	

;;------------------------------------------	
;Mi=Mj-Mk
Mi_Mj-Mk	MACRO	Mi,Mj,Mk
	Mj&_PAGE
	mov	a	Mj
	page4
	mov	temp6	a
	Mk&_PAGE
	mov	a	Mk
	Temp2&_PAGE
	mov	temp2	a
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
@@:
	page4
	mov	a	temp6
	inca
	mov	temp6	a
	Temp2&_PAGE
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	#1111b
	xor	a	temp2
	mov	temp2	a
	caje	#0	@F
	jmp	@B
@@:
	page4
	mov	a	temp6
	Mi&_PAGE
	mov	Mi	a
	ENDM

;Mi=Mj-data
Mi_Mj-data	MACRO	Sum,A1,Value
local	@@dec_ok
	A1&_page
	mov	a	A1
	page4
	mov	temp6	a
	page0
	mov	temp2	#Value !& 0XF
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	temp2
	caje	#0	@@dec_ok
@@:
	page4
	mov	a	temp6
	inca
	mov	temp6	a
	page0
	mov	a	#1111b
	xor	a	temp2
	inca
	mov	temp2	a
	mov	a	#1111b
	xor	a	temp2
	mov	temp2	a
	caje	#0	@F
	jmp	@B
@@:	
@@dec_ok:
	page4
	mov	a	temp6
	Sum&_page
	mov	Sum	a
	endm
;=========== 8 bit command =============
;Xi>Xj?:PathName
Xi_G_Xj_LABEL	MACRO	Xi,Xj,LABEL
local	@@chk_X_L,@@cmpr_ok
	Xi&_PAGE
	mov	a	Xj&_High
	caje	Xi&_High	@@chk_X_L
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	Xi&_High	LABEL
	jmp	@B
@@chk_X_L:
	mov	a	Xj&_Low
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	Xi&_Low	LABEL
	jmp	@B
@@cmpr_ok:
	ENDM



;Xi>=Xj?:PathName
Xi_GE_Xj_LABEL	MACRO	Xi,Xj,LABEL
local	@@chk_X_L,@@cmpr_ok

	Xj&_PAGE
	mov	a	Xj&_High
	caje	Xi&_High	@@chk_X_L
@@:
	caje	Xi&_High	LABEL
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@chk_X_L:
	mov	a	Xj&_Low
@@:
	caje	Xi&_Low	LABEL
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@cmpr_ok:
	ENDM

;Xi>data?:PathName
Xi_G_data_LABEL	MACRO	Xi,Value,LABEL
local	@@chk_X_L,@@cmpr_ok

	Xi&_PAGE
	mov	a	#Value >> 4
	caje	Xi&_High	@@chk_X_L
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	Xi&_High	LABEL
	jmp	@B
@@chk_X_L:
	mov	a	#Value !& 0xf
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	Xi&_Low	LABEL
	jmp	@B
@@cmpr_ok:
	ENDM


;Xi>=data?:PahtName
Xi_GE_data_LABEL	MACRO	Xi,Value,LABEL
local	@@chk_X_L,@@cmpr_ok

	Xi&_PAGE
	mov	a	#Value >> 4
	caje	Xi&_High	@@chk_X_L
@@:
	caje	Xi&_High	LABEL
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@chk_X_L:
	mov	a	#Value !& 0xf
@@:
	caje	Xi&_Low	LABEL
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@cmpr_ok:
	ENDM
 
;Xi=data	;i=0~7,data=0~255
Xi_data	Macro	A1,Value
	A1&_page
	mov	a	#Value >> 4
	mov	A1&_High	a
	mov	a	#Value !& 0xF
	mov	A1&_Low	a
	endm

;Xi.L=data
Xi.L_data	MACRO	A1,Value
	A1&_page
	mov	a	#Value
	mov	A1&_Low	a
	endm

;Xi.H=data
Xi.H_data	MACRO	A1,Value
	A1&_page
	mov	a	#Value
	mov	A1&_High	a
	endm

;Xi(n)=0 or 1;n=0~7
Xi@n_0	MACRO	A1,Bit
	page1
	mov	a	Bit&_High
	mov	temp4	a
	mov	a	Bit&_Low
	mov	temp5	a
	mov	a	#1111b
	xor	a	temp5
	mov	temp5	a
	mov	a	#1111b
	xor	a	temp4
	mov	temp4	a

	mov	a	temp4
	A1&_Page
	and	a	A1&_High
	mov	A1&_High	a
	page1
	mov	a	temp5
	A1&_Page
	and	a	A1&_Low
	mov	A1&_Low	a
	endm

Xi@n_1	MACRO	A1,Bit
	A1&_Page
	mov	a	Bit&_High
	or	a	A1&_High
	mov	A1&_High	a
	mov	a	Bit&_Low
	or	a	A1&_Low
	mov	A1&_Low	a
	endm
;----------------------------------------------
;26;Xi=Xj+Xk
Xi_Xj+Xk	MACRO	Sum,A1,A2
LOCAL	@@ADC_H,@@carry,@@adc_ok
	A1&_Page
	mov	a	A1&_Low
	page4
	mov	temp6	a
	A1&_Page
	mov	a	A1&_High
	page0
	mov	temp2	a
	A2&_Page
	mov	a	A2&_Low
	page4
	mov	temp7	a
	A2&_Page
	mov	a	A2&_High
	page1
	mov	temp4	a
	
	page4
	mov	a	temp7
	caje	#0	@@adc_H
@@:
	mov	a	temp6
	inca
	mov	temp6	a
	mov	a	#1111b
	xor	a	temp7
	inca
	mov	temp7	a
	mov	a	#1111b
	xor	a	temp7
	mov	temp7	a
	mov	a	temp6
	caje	#0	@@carry
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@carry:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page4
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@:	
@@adc_H:
	page1
	mov	a	temp4
	caje	#0	@@adc_ok
@@:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page1
	mov	a	#1111b
	xor	a	temp4
	inca
	mov	temp4	a
	mov	a	#1111b
	xor	a	temp4
	mov	temp4	a
	caje	#0	@F
	jmp	@B
@@:	
@@adc_ok:
	page0
	mov	a	temp2
	Sum&_page
	mov	Sum&_High	a
	page4
	mov	a	temp6
	sum&_page
	mov	Sum&_Low	a
	endm
;----------------------------------------------	
;Xi=Xi+data,use page0:temp6,temp2
Xi_Xj+data	MACRO	Sum,A1,Value
local	@@adc_H,@@carry,@@adc_ok

	A1&_Page
	mov	a	A1&_Low
	page4
	mov	temp6	a
	A1&_Page
	mov	a	A1&_High
	page0
	mov	temp2	a
	page4
	mov	temp7	#Value !& 0xf
	page1
	mov	temp4	#Value >> 4	

	page4
	mov	a	temp7
	caje	#0	@@adc_H
@@:
	mov	a	temp6
	inca
	mov	temp6	a
;	page0
	mov	a	#1111b
	xor	a	temp7
	inca
	mov	temp7	a
	mov	a	#1111b
	xor	a	temp7
	mov	temp7	a
	mov	a	temp6
	caje	#0	@@carry
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@carry:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page4
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@:	
@@adc_H:
	page1
	mov	a	temp4
	caje	#0	@@adc_ok
@@:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page1
	mov	a	#1111b
	xor	a	temp4
	inca
	mov	temp4	a
	mov	a	#1111b
	xor	a	temp4
	mov	temp4	a

	page1
	mov	a	temp4
	caje	#0	@F
	jmp	@B
@@:	
@@adc_ok:
	page0
	mov	a	temp2
	Sum&_page
	mov	Sum&_High	a
	page4
	mov	a	temp6
	Sum&_page
	mov	Sum&_Low	a
	endm
;---------------------------------------
;28;Xi=Xj-Xk
Xi_Xj-Xk	MACRO	Sum,A1,A2
local	@@carry,@@dec_ok,@@temp4_carry

	A1&_Page
	mov	a	A1&_Low
	page4
	mov	temp6	a
	A1&_Page
	mov	a	A1&_High
	page0
	mov	temp2	a
	A2&_Page
	mov	a	A2&_Low
	page4
	mov	temp7	a
	A2&_Page
	mov	a	A2&_High
	page1
	mov	temp4	a
	
	mov	a	#1111b		;transfer to 2's complement
	xor	a	temp4
	mov	temp4	a
	page4
	mov	a	#1111b
	xor	a	temp7
	inca
	mov	temp7	a

	mov	a	temp7
	caje	#0	@@temp4_carry
@@:
	mov	a	temp6
	inca
	mov	temp6	a
	mov	a	#1111b
	xor	a	temp7
	inca
	mov	temp7	a
	mov	a	#1111b
	xor	a	temp7
	mov	temp7	a
	mov	a	temp6
	caje	#0	@@carry
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@carry:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page4
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@temp4_carry:
	page1
	mov	a	temp4
	inca
	mov	temp4	a
	jmp	@F
@@:
	page1
	mov	a	temp4
	caje	#0	@@dec_ok
@@:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page1
	mov	a	#1111b
	xor	a	temp4
	inca
	mov	temp4	a
	mov	a	#1111b
	xor	a	temp4
	mov	temp4	a
	caje	#0	@F
	jmp	@B
@@:	
@@dec_ok:
	page0
	mov	a	temp2
	Sum&_page
	mov	Sum&_High	a
	page4
	mov	a	temp6
	Sum&_page
	mov	Sum&_Low	a
	endm
;---------------------------------------
;29;Xi=Xj-data
Xi_Xj-data	MACRO	Sum,A1,Value
local	@@carry,@@dec_ok,@@temp4_carry

	A1&_Page
	mov	a	A1&_Low
	page4
	mov	temp6	a
	A1&_Page
	mov	a	A1&_High
	page0
	mov	temp2	a
	page4
	mov	temp7	#Value !& 0xf
	page1
	mov	temp4	#Value >> 4

	mov	a	#1111b		;tXansfeX to 2's complement
	xor	a	temp4
	mov	temp4	a
	page4
	mov	a	#1111b
	xor	a	temp7
	inca
	mov	temp7	a
	mov	a	temp7
	caje	#0	@@temp4_carry
@@:
	mov	a	temp6
	inca
	mov	temp6	a
	mov	a	#1111b
	xor	a	temp7
	inca
	mov	temp7	a
	mov	a	#1111b
	xor	a	temp7
	mov	temp7	a
	mov	a	temp6
	caje	#0	@@carry
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@carry:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page4
	mov	a	temp7
	caje	#0	@F
	jmp	@B
@@temp4_carry:
	page1
	mov	a	temp4
	inca
	mov	temp4	a
	jmp	@F
@@:	
	page1
	mov	a	temp4
	caje	#0	@@dec_ok
@@:
	page0
	mov	a	temp2
	inca
	mov	temp2	a
	page1
	mov	a	#1111b
	xor	a	temp4
	inca
	mov	temp4	a
	mov	a	#1111b
	xor	a	temp4
	mov	temp4	a
	caje	#0	@F
	jmp	@B
@@:	
@@dec_ok:
	page0
	mov	a	temp2
	Sum&_page
	mov	Sum&_High	a
	page4
	mov	a	temp6
	Sum&_page
	mov	Sum&_Low	a
	endm

;---------------------------------------------------
;Xi=Xj and data
Xi_Xj_AND_Data	MACRO	Sum,A1,Value
	A1&_page
	mov	a	#Value >> 4
	and	a	A1&_High
	Sum&_page
	mov	Sum&_High	a
	A1&_page
	mov	a	#Value !& 0xf
	and	a	A1&_Low
	Sum&_page
	mov	Sum&_Low	a
	endm
	
;Xi=Xj 
Xi_Xj	MACRO	A1,A2
	A2&_page
	mov	a	A2&_High
	A1&_page
	mov	A1&_High	a
	
	A2&_page
	mov	a	A2&_Low
	A1&_page
	mov	A1&_Low	a
	
	endm	

;Xi=Xj and Xk
Xi_Xj_AND_Xk	MACRO	Sum,A1,A2
	A2&_Page
	mov	a	A2&_High
	A1&_page
	and	a	A1&_High
	Sum&_page
	mov	Sum&_High	a
	A2&_Page
	mov	a	A2&_Low
	A1&_page
	and	a	A1&_Low
	Sum&_page
	mov	Sum&_Low	a
	endm

;Xi=Xi or data
Xi_Xj_OR_Data	MACRO	Sum,A1,Value
	A1&_page
	mov	a	#Value >> 4
	or	a	A1&_High
	Sum&_page
	mov	Sum&_High	a
	A1&_page
	mov	a	#Value !& 0xf
	or	a	A1&_Low
	Sum&_page
	mov	Sum&_Low	a
	endm

;Xi=Xj or Xk
Xi_Xj_OR_Xk	MACRO	Sum,A1,A2
	A2&_Page
	mov	a	A2&_High
	A1&_page
	or	a	A1&_High
	Sum&_page
	mov	Sum&_High	a
	A2&_Page
	mov	a	A2&_Low
	A1&_page
	or	a	A1&_Low
	Sum&_page
	mov	Sum&_Low	a
	endm

;Xi=Xj xor data
Xi_Xj_XOR_Data	MACRO Sum,A1,Value
	A1&_page
	mov	a	#Value >> 4
	xor	a	A1&_High
	Sum&_page
	mov	Sum&_High	a
	A1&_page
	mov	a	#Value !& 0xf
	xor	a	A1&_Low
	Sum&_page
	mov	Sum&_Low	a
	endm

;Xi=Xj xor Xk
Xi_Xj_XOR_Xk	MACRO	Sum,A1,A2
	A2&_Page
	mov	a	A2&_High
	A1&_page
	xor	a	A1&_High
	Sum&_page
	mov	Sum&_High	a
	A2&_Page
	mov	a	A2&_Low
	A1&_page
	xor	a	A1&_Low
	Sum&_page
	mov	Sum&_Low	a
	endm

;.inv.Xi
_INV_Xi	MACRO	A1
	A1&_page
	mov	a	#1111b
	xor	a	A1&_Low
	mov	A1&_Low	a
	mov	a	#1111b
	xor	a	A1&_High
	mov	A1&_High	a
	endm

;.inv.Xi(n),n=0~7
_INV_Xi@n	MACRO	A1,Bit
	A1&_page
	mov	a	Bit&_Low
	xor	a	A1&_Low
	mov	A1&_Low	a
	mov	a	Bit&_High
	xor	a	A1&_High
	mov	A1&_High	a
	endm


;Xi?data:pathname
Xi?data_Label	MACRO	A1,Value,Label
local	@@check_data_ok
	A1&_page
	mov	a	A1&_High
	caje	#Value >> 4	@F
	jmp	@@check_data_ok
@@:
	mov	a	A1&_Low
	caje	#Value !& 0xf	Label
@@check_data_ok:	
	endm

;Xi?Xj:pathname
Xi?Xj_Label	MACRO	A1,A2,Label
local	@@check_ok
	A1&_page
	mov	a	A1&_High
	A2&_Page
	caje	A2&_High	@F
	jmp	@@check_ok
@@:
	A1&_page
	mov	a	A1&_Low
	A2&_Page
	caje	A2&_Low	Label
@@check_ok:
	endm

;Xi:[path0 path1 path2....pathn]
Switch_Xi  MACRO   Xi,lab:VARARG

LOCAL @@scankey1,@@16,@@32,@@48,@@64,@@80,@@96,@@112,@@128,@@144,@@160,@@176,@@192,@@208,@@224,@@240,@@256
 
        temp = 0
        FOR ll, <lab>
            IF  temp == 0
            	Xi&_PAGE
                mov    a, Xi&_High
                caje    #0, @F
                jmp    @@16
                @@:
                mov    a, Xi&_Low

           ELSEIF temp == 16
                @@16:
                mov    	a	Xi&_High
                caje	#1	@F
 		jmp	@@32
		@@:
               	mov	a	Xi&_Low

           ELSEIF temp == 32 
                @@32:
		mov	a	Xi&_high
		caje	#2	@F
		jmp	@@48
		@@:
               	mov	a	Xi&_Low

           ELSEIF temp == 48 
                @@48:
		mov	a	Xi&_high
		caje	#3	@F
		jmp	@@64
		@@:
               	mov	a	Xi&_Low

	   ELSEIF temp == 64
		@@64:
		mov	a	Xi&_high
		caje	#4	@F
		jmp	@@80
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 80
		@@80:
		mov	a	Xi&_high
		caje	#5	@F
		jmp	@@96
		@@:
		mov	a	Xi&_Low	

	   ELSEIF temp == 96
		@@96:
		mov	a	Xi&_high
		caje	#6	@F
		jmp	@@112
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 112
		@@112:
		mov	a	Xi&_high
		caje	#7	@F
		jmp	@@128
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 128
		@@128:
		mov	a	Xi&_high
		caje	#8	@F
		jmp	@@144
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 144
		@@144:
		mov	a	Xi&_high
		caje	#9	@F
		jmp	@@160
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 160
		@@160:
		mov	a	Xi&_high
		caje	#10	@F
		jmp	@@176
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 176
		@@176:
		mov	a	Xi&_high
		caje	#11	@F
		jmp	@@192
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 192
		@@192:
		mov	a	Xi&_high
		caje	#12	@F
		jmp	@@208
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 208
		@@208:
		mov	a	Xi&_high
		caje	#13	@F
		jmp	@@224
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 224
		@@224:
		mov	a	Xi&_high
		caje	#14	@F
		jmp	@@240
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 240
		@@240:
		mov	a	Xi&_high
		caje	#15	@F
		jmp	@@256
		@@:
		mov	a	Xi&_Low

	   ELSEIF temp == 256
		@@256:
		mov	a	Xi&_Low
           ENDIF

	   IFDIFI <ll>,<X>			
           caje # (temp !!!& 0xF), !&ll
           ENDIF
           temp = temp + 1
      ENDM

	IF	temp <= 16
		@@16:
	ELSEIF	temp <= 32
		@@32:
	ELSEIF	temp <= 48
		@@48:
	ELSEIF	temp <= 64
		@@64:
	ELSEIF	temp <= 80
		@@80:
	ELSEIF	temp <= 96
		@@96:
	ELSEIF	temp <= 112
		@@112:
	ELSEIF	temp <= 128
		@@128:
	ELSEIF	temp <= 144
		@@144:
	ELSEIF	temp <= 160
		@@160:
	ELSEIF	temp <= 176
		@@176:
	ELSEIF	temp <= 192 
		@@192:
	ELSEIF	temp <= 208
		@@208:
	ELSEIF	temp <= 224
		@@224:
	ELSEIF	temp <= 240
		@@240:
	ELSEIF	temp <= 256
		@@256:
	ENDIF
@@scankey1:		
 ENDM




;Xi(n)?0:pathname
Xi@n_0_Label	MACRO	A1,Bit,Label
Local	@@check_ok
	A1&_page
	mov	a	Bit&_High
	caje	#0	@F
	and	a	A1&_High
	caje	#0	Label
	jmp	@@check_ok
@@:
	mov	a	Bit&_Low
	and	a	A1&_Low
	caje	#0	Label
@@check_ok:
	endm

;Xi(n)?1:PathName
Xi@n_1_Label	MACRO	A1,Bit,Label
local	@@check_ok
	A1&_page
	mov	a	Bit&_High
	caje	#0	@F
	and	a	A1&_High
	caje	Bit&_High	Label
	jmp	@@check_ok
@@:
	mov	a	Bit&_Low
	and	a	A1&_Low
	caje	Bit&_Low	Label
@@check_ok:
	endm

;Xi>Xj?:PathName
Xi_B_Xj_Label	MACRO	A1,A2,Label
local	@@chk_X_L,@@cmpr_ok
	A2&_Page
	mov	a	A2&_High
	A1&_page
	caje	A1&_High	@@chk_X_L
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	A1&_High	Label
	jmp	@B
@@chk_X_L:
	A2&_Page
	mov	a	A2&_Low
	A1&_page
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	A1&_Low	Label
	jmp	@B
@@cmpr_ok:
	endm


;Xi>=Xj?:PathName
Xi_BE_Xj_Label	MACRO	A1,A2,Label
local	@@chk_X_L,@@cmpr_ok

	A2&_Page
	mov	a	A2&_High
	A1&_page
	caje	A1&_High	@@chk_X_L
@@:
	caje	A1&_High	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@chk_X_L:
	A2&_Page
	mov	a	A2&_Low
	A1&_Page
@@:
	caje	A1&_Low	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@cmpr_ok:
	endm


;Xi<Xj?:PathName,X0>X1?:lable
Xi_S_Xj_Label	MACRO	A1,A2,Label
local	@@chk_X_L,@@cmpr_ok

	A1&_page
	mov	a	A1&_High
	A2&_Page
	caje	A2&_High	@@chk_X_L
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	A2&_High	Label
	jmp	@B
@@chk_X_L:
	A1&_page
	mov	a	A1&_Low
	A2&_Page
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	A2&_Low	Label
	jmp	@B
@@cmpr_ok:
	endm

;Xi<=Xj?:PathName
Xi_SE_Xj_Label	MACRO	A1,A2,Label
local	@@chk_X_L,@@cmpr_ok

	A1&_page
	mov	a	A1&_High
	A2&_Page
	caje	A2&_High	@@chk_X_L
@@:
	caje	A2&_High	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@chk_X_L:
	A1&_page
	mov	a	A1&_Low
	A2&_Page
@@:
	caje	A2&_Low	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@cmpr_ok:
	endm

;Xi>data?:PathName
Xi_B_data_Label	MACRO	A1,Value,Label
local	@@chk_X_L,@@cmpr_ok
	A1&_page
	mov	a	#Value >> 4
	caje	A1&_High	@@chk_X_L
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	A1&_High	Label
	jmp	@B
@@chk_X_L:
	mov	a	#Value !& 0xf
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	A1&_Low	Label
	jmp	@B
@@cmpr_ok:
	endm


;Xi>=data?:PahtName
Xi_BE_data_Label	MACRO	A1,Value,Label
local	@@chk_X_L,@@cmpr_ok

	A1&_page
	mov	a	#Value >> 4
	caje	A1&_High	@@chk_X_L
@@:
	caje	A1&_High	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@chk_X_L:
	mov	a	#Value !& 0xf
@@:
	caje	A1&_Low	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@cmpr_ok:
	endm

;Xi<data?:PathName,data=00101101b
Xi_S_data_Label	MACRO	A1,Value,Label
local	@@chk_X_L,@@cmpr_ok

	A1&_page
	mov	a	A1&_High
	caje	#Value >> 4	@@chk_X_L
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	#Value >> 4	Label
	jmp	@B
@@chk_X_L:
	mov	a	A1&_Low
@@:
	caje	#0Fh	@@cmpr_ok
	inca
	caje	#Value !& 0xf	Label
	jmp	@B
@@cmpr_ok:
	endm


;Xi<=data?:PathName,data=00101101b
Xi_SE_data_Label	MACRO	A1,Value,Label
local	@@chk_X_L,@@cmpr_ok
		
	A1&_page
	mov	a	A1&_High
	caje	#Value >> 4	@@chk_X_L
@@:
	caje	#Value >> 4	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@chk_X_L:
	mov	a	A1&_Low
@@:
	caje	#Value !& 0xf	Label
	caje	#0Fh	@@cmpr_ok
	inca
	jmp	@B
@@cmpr_ok:
	endm

;Xi!=Xj?:PathName
Xi_NE_Xj_Label	MACRO	A1,A2,Label

	A2&_Page
	mov	a	A2&_High
	A1&_page
	caje	A1&_High	@F
	jmp	Label
@@:
	A2&_Page
	mov	a	A2&_Low
	A1&_page
	caje	A1&_Low	@F
	jmp	Label
@@:
	endm

;Xi!=data?:PathName
Xi_NE_data_Label	MACRO	A1,Value,Label

	A1&_page
	mov	a	A1&_High
	caje	#Value >> 4	@F
	jmp	Label
@@:
	mov	a	A1&_Low
	caje	#Value !& 0xf	@F
	jmp	Label
@@:
	endm

;------------------------------------------------------
;P2+P3=Xi,m=2,3;n=2,3;i=0~31
Pm+Pn_Xi	MACRO	Pm,Pn,A1
	A1&_page
	mov	a	A1&_Low
	Pn&_Page
	mov	Pn&_Low	a
	mov	Pn&_High	#0000b
	A1&_page
	mov	a	A1&_High
	Pm&_Page
	mov	Pm&_Low	a
	mov	Pm&_High	#0000b
	endm
Pm+Pn_data	MACRO	Pm,Pn,Value
	Pn&_Page
	mov	Pn&_Low	#Value !& 0xf
	mov	Pn&_High	#0000b
	Pm&_Page
	mov	Pm&_Low	#Value >> 4
	mov	Pm&_High	#0000b
	endm

; VOL=Mi
SetVol_M	macro	Mi
;P2+P3=data,m=2,3;n=2,3;data=0~255
	page3
		mov	a,Mi
	TEMP6&_PAGE
	; Mark bit 3 of data
	mov	temp6,a
	mov	a,#0111b
	and	a,temp6
	mov	temp6,a
	
	; Volvalue = {VolValue[3],temp6[2:0]}
	mov	a,#1000b
	VolValue_Page0&_PAGE
	and	a,VolValue_Page0
	TEMP6&_PAGE
	or	a,temp6
	VolValue_Page0&_PAGE
	mov	VolValue_Page0,a
	mov	mode,a

	endm

; VOL=data
SetVol_D	macro	data
	TEMP6&_PAGE
	; Mark bit 3 of data
	mov	temp6,#data
	mov	a,#0111b
	and	a,temp6
	mov	temp6,a
	
	; Volvalue = {VolValue[3],temp6[2:0]}
	mov	a,#1000b
	VolValue_Page0&_PAGE
	and	a,VolValue_Page0
	TEMP6&_PAGE
	or	a,temp6
	VolValue_Page0&_PAGE
	mov	VolValue_Page0,a
	mov	mode,a
	endm

; VOL++
IncVol	macro
local	IncVol_OK
	page0
	mov	a,VolValue_Page0
	caje	#0111b,IncVol_OK
	caje	#1111b,IncVol_OK
	mov	a,VolValue_Page0
	inca
	mov	VolValue_Page0,a	
	mov	mode,a

IncVol_OK:
	endm

; VOL--
DecVol	MACRO
local	DecVol_OK
	page0

	;Data put into "A" first.
	mov	a,VolValue_Page0
	; a = a -1
	TEMP6&_PAGE	
	mov	temp6,#1111b	
	xor	a,temp6
	inca
	xor	a,temp6
	
	;Check if a less then 0	
	caje	#0FH,DecVol_OK		; no setting IR mode
	caje	#07H,DecVol_OK		; setting IR mode
	page0	
	mov	VolValue_Page0,a
	mov	mode,a
DecVol_OK:
	endm


; Nop delay time = (10*data + 3)*4us
Nop_us	MACRO	data
local	LoopCnt
local	LoopCntOK
	mov	a,#0
	
LoopCnt:	
	inca
	nop
	nop
	nop	
	nop
	nop
	nop
	nop
	nop
	nop
	NOP
	NOP
	NOP
	NOP
	
	caje	#data,LoopCntOK
	jmp	LoopCnt		;2005/11/30 03:15¤U¤È
LoopCntOK:	
	rstc			;2005/11/30 03:15¤U¤È
	endm

VolDown	MACRO
local	DecVolOK
local	DecVolNotOK
	page0
	mov	a,VolValue_Page0
	TEMP6&_PAGE
	mov	temp6,a
	;check if volume less than 0.
	caje	#0FH,DecVolOK		; no setting IR mode
	caje	#07H,DecVolOK		; setting IR mode
DecVolNotOK:
	;;1
	; Temp6 = Temp6 -1
	;Data put into "A" first.
	TEMP6&_PAGE	
	mov	a,temp6
	mov	temp6,#1111b
	xor	a,temp6
	inca
	xor	a,temp6
	mov	temp6,a

	;check if volume less than 0.
	caje	#0FH,DecVolOK		; no setting IR mode
	caje	#07H,DecVolOK		; setting IR mode
	mov 	a,temp6
	mov	mode,a
	Nop_us	15			; Nearly 64us*15 + 14 cycle
	
	
	;;2
	TEMP6&_PAGE
	mov	a,temp6
	mov	temp6,#1111b
	xor	a,temp6
	inca
	xor	a,temp6
	mov	temp6,a

	;check if volume less than 0.
	caje	#0FH,DecVolOK		; no setting IR mode
	caje	#07H,DecVolOK		; setting IR mode
	mov 	a,temp6
	mov	mode,a
	Nop_us	15			; Nearly 64us*15 + 14 cycle
	
	;;3
	mov	a,temp6
	mov	temp6,#1111b
	xor	a,temp6
	inca
	xor	a,temp6
	mov	temp6,a

	;check if volume less than 0.
	caje	#0FH,DecVolOK		; no setting IR mode
	caje	#07H,DecVolOK		; setting IR mode
	mov 	a,temp6
	mov	mode,a
	Nop_us	15			; Nearly 64us*15 + 14 cycle
	
	;;4
	mov	a,temp6
	mov	temp6,#1111b
	xor	a,temp6
	inca
	xor	a,temp6
	mov	temp6,a

	;check if volume less than 0.
	caje	#0FH,DecVolOK		; no setting IR mode
	caje	#07H,DecVolOK		; setting IR mode
	mov 	a,temp6
	mov	mode,a
	Nop_us	15			; Nearly 64us*15 + 14 cycle
	
	;jmp	DecVolNotOK
DecVolOK:
	page0
	endm
	
;;-------------------------------------------	
;Mi=data
Mi_Data	MACRO	Mi,Value
	Mi&_PAGE
	mov	Mi	#Value
	ENDM
;;------------------------------------------	
;;IRin_on
IRin_on macro
	IRin_ON_OFF_3_2&_page
	MOV	A, #0100B
	OR	A, IRin_ON_OFF_3_2
	MOV	IRin_ON_OFF_3_2, A
	endm
;;------------------------------------------
;;IRin_Off
IRin_Off macro
	IRin_ON_OFF_3_2&_page
	MOV	A, #1011B
	and	A, IRin_ON_OFF_3_2
	MOV	IRin_ON_OFF_3_2, A
	endm
;;-----------------------------------------	
;;IRout	
IRout macro Value
	IRout_ON_OFF_3_0&_page
	MOV	A, #0001B
	AND	A, IRout_ON_OFF_3_0
	CAJE	#0001B, @F
	MOV	A, #0001B
	OR	A, IRout_ON_OFF_3_0
	MOV	IRout_ON_OFF_3_0, A

	MOV	TRANS_H, #Value >> 4
	MOV	TRANS_L, #VALUE !& 0XF
@@:	
	endm
;;------------------------------------------	
;IRoutH mi
IRoutH macro mi
	IRout_ON_OFF_3_0&_page
	MOV	A, #0001B
	AND	A, IRout_ON_OFF_3_0
	CAJE	#0001B, @F
	Mi&_PAGE
	MOV	A, Mi
	TRANS_H&_PAGE
	MOV	TRANS_H, A
@@:
	endm
;;------------------------------------------
;IRoutL mi
IRoutL macro mi	
	IRout_ON_OFF_3_0&_page
	MOV	A, #0001B
	AND	A, IRout_ON_OFF_3_0
	CAJE	#0001B, @F
	MOV	A, #0001B
	OR	A, IRout_ON_OFF_3_0
	MOV	IRout_ON_OFF_3_0, A
	
	Mi&_PAGE
	MOV	A, Mi
	TRANS_L&_PAGE
	MOV	TRANS_L, A
@@:	
	endm

;;----------------------------------------	
;Mi>=Mj?:PathName
Mi_GE_Mj_LABEL	MACRO	Mi,Mj,LABEL
	Mi&_PAGE
	mov	a	Mj
@@:
	caje	Mi	LABEL
	caje	#0Fh	@F
	inca
	jmp	@B
@@:
	ENDM	
;;----------------------------------------
;.inv.Mi
_INV_Mi	MACRO	Mi
	Mi&_PAGE
	mov	a	#1111b
	xor	a	Mi
	mov	Mi	a
	ENDM	
;;-----------------------------------------	
;PWMIO1	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM1H	a
;	mov	a	#duty !& 0xf
;	mov	PWM1L	a	
;	endm

;PWMIO2	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM2H	a
;	mov	a	#duty !& 0xf
;	mov	PWM2L	a	
;	endm	
	
;PWMIO3	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM3H	a
;	mov	a	#duty !& 0xf
;	mov	PWM3L	a	
;	endm	

;PWMIO4	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM4H	a
;	mov	a	#duty !& 0xf
;	mov	PWM4L	a	
;	endm	

;PWMIO5	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM5H	a
;	mov	a	#duty !& 0xf
;	mov	PWM5L	a	
;	endm	

;PWMIO6	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM6H	a
;	mov	a	#duty !& 0xf
;	mov	PWM6L	a	
;	endm	

;PWMIO7	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM7H	a
;	mov	a	#duty !& 0xf
;	mov	PWM7H	a	
;	endm	

;PWMIO8	MACRO	duty
;	mov	a	#duty >> 4
;	mov	PWM8H	a
;	mov	a	#duty !& 0xf
;	mov	PWM8H	a	
;	endm	
;;------------------------------------------------	
;PWMIO_EN1	MACRO
;	page4
;	mov	a	#0001b
;	or	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	
;	
;	p3state&_page
;	mov	a	#0001b
;	or	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	
;	P3S_STATE&_page
;	mov	a	#1110b
;	and	a	P3S_STATE
;	mov	P3S_STATE	a
;	mov	p3s	a
;	
;		
;	endm

;PWMIO_EN2	macro
;	page4
;	mov	a	#0010b
;	or	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	
;	p3state&_page
;	mov	a	#0010b
;	or	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	
;	P3S_STATE&_page
;	mov	a	#1101b
;	and	a	P3S_STATE
;	mov	P3S_STATE	a
;	mov	p3s	a
;	endm
		

;PWMIO_EN3	macro
;	page4
;	mov	a	#0100b
;	or	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	
;	p3state&_page
;	mov	a	#0100b
;	or	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	P3S_STATE&_page
;	mov	a	#1011b
;	and	a	P3S_STATE
;	mov	P3S_STATE	a
;	mov	p3s	a
;	endm
	
;PWMIO_EN4	macro
;	page4
;	mov	a	#1000b
;	or	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	
;	p3state&_page
;	mov	a	#1000b
;	or	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	P3S_STATE&_page
;	mov	a	#0111b
;	and	a	P3S_STATE
;	mov	P3S_STATE	a
;	mov	p3s	a
;	endm
	
	
	
;PWMIO_OFF1	macro
;	p3state&_page
;	mov	a	#1110b
;	and	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	
;	page4
;	mov	a	#1110b
;	and	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	endm		

;PWMIO_OFF2	macro
;
;	p3state&_page
;	mov	a	#1101b
;	and	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	page4
;	mov	a	#1101b
;	and	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	endm
	

;PWMIO_OFF3	macro
;	p3state&_page
;	mov	a	#1011b
;	and	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	
;	page4
;	mov	a	#1011b
;	and	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	
;	
;	endm				
	
;PWMIO_OFF4	macro
;	p3state&_page
;	mov	a	#0111b
;	and	a	p3state
;	mov	p3state	a
;	mov	p3	a
;	page4
;	mov	a	#0111b
;	and	a	PWMIOEN1
;	mov	PWMIOEN1	a
;	mov	mode2	a
;	
;	
;	endm		
	

;-----------------------------	
;PWMIO_cycle_1	macro data	
;	mov	a	#data	
;	mov	mode4	a
;	endm

;PWMIO_cycle_2	macro data	
;	mov	a	#data	
;	mov	mode5	a
;	endm	

@_@Repeat	MACRO	Voicename
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	mov	a	#0001B
	mov	NEXT	A
	NEXT	Voicename
	PLAY	Voicename
	CALL1	@@SCANKEY1
	ENDM
@_@Repeat_p	MACRO	Voicename	
	V_STATE_&page
	MOV	A #0100B
	OR	A V_STATE
	MOV	V_STATE A
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	mov	a	#0001B
	mov	NEXT	A
	NEXT	Voicename
	PLAY	Voicename
	CALL2	@@SCANKEY1
	ENDM
		
STOP_R	MACRO
	page4
	mov	a	#0
	mov	Next_flag a
	mov	next	a
	mov	nxtply	a
	endm	
;;---------------------------------

;PWMIO1_X  macro A1	
;	A1&_page
;	mov	a	A1&_High
;	mov	PWM1H	a
;	mov	a	A1&_Low
;	mov	PWM1L	a		
;	endm
	
;PWMIO2_X  macro A1	
;	A1&_page
;	mov	a	A1&_High
;	mov	PWM2H	a
;	mov	a	A1&_Low
;	mov	PWM2L	a		
;	endm
	
;PWMIO3_X  macro A1	
;	A1&_page
;	mov	a	A1&_High
;	mov	PWM3H	a
;	mov	a	A1&_Low
;	mov	PWM3L	a		
;	endm	
	
;PWMIO4_X  macro A1	
;	A1&_page
;	mov	a	A1&_High
;	mov	PWM4H	a
;	mov	a	A1&_Low
;	mov	PWM4L	a		
;	endm	
	
@_@Repeatall  MACRO   voicename,lab:VARARG
local	@@_repeat_speech
		mov	a	#0000B
		mov	NEXT	A
		
		CALL1	@@CHK_VOC1
		CALL1	@@CLEAR_ENTER_B1
		Next_flag_&PAGE
		mov	Next_flag	#1
		mov	a	#0001B
		mov	NEXT	A
		PLAY	Voicename
@@_repeat_speech:        
        temp= 0
        FOR ll, <lab>
             
	   IFDIFI <ll>,<X>			
                NEXT	!&ll	;Voicename
                mov	a	#0
                mov	nxtply	a
                
		CALL1	@@SCANKEY1
           ENDIF
                temp = temp + 1
	ENDM 
		NEXT	Voicename
		mov	a	#0
                mov	nxtply	a
                CALL1	@@SCANKEY1
                jmp	@@_repeat_speech
      ENDM
      
@_@Repeatall_p  MACRO   voicename,lab:VARARG
local	@@_repeat_speech
		mov	a	#0000B
		mov	NEXT	A
		
		
		V_STATE_&page
		MOV	A #0100B
		OR	A V_STATE
		MOV	V_STATE A
		CALL2	@@CHK_VOC_P1
		CALL2	@@CLEAR_ENTER_P1
		Next_flag_&PAGE
		mov	Next_flag	#2
		mov	a	#0001B
		mov	NEXT	A
		PLAY	Voicename
@@_repeat_speech:        
        temp= 0
        FOR ll, <lab>
             
	   IFDIFI <ll>,<X>			
                NEXT	!&ll	;Voicename
                mov	a	#0
                mov	nxtply	a
                
		CALL2	@@SCANKEY1
           ENDIF
                temp = temp + 1
	ENDM 
		NEXT	Voicename
		mov	a	#0
                mov	nxtply	a
                CALL2	@@SCANKEY1
                jmp	@@_repeat_speech
      ENDM
      
;;@@PWMIO_PS macro data
;;	mov	a	#data
;;	mov	PIO_PS	a
;;	endm      
	
Pn_Data	MACRO	Pn,GO1,GO2
	Pn&_PAGE
	mov	Pn&_GO1	GO1
	mov	Pn&_GO2	GO2
	ENDM	

Pn_Data_LABEL	MACRO	Pn,Value,anddata,LABEL
	mov	a	anddata
	TEMP6&_PAGE
	mov	temp6	a
	mov	a	Pn
	and	a	temp6
	caje	Value	LABEL
	ENDM		
	
;PnFV_Data	
PnFV_Data  macro Pn,GO1,GO2,FV1
	
	Pn&_PAGE
	mov	Pn&_GO1 GO1
	mov	Pn&_GO2 GO2
	mov	Pn&_Fv1 FV1	
	ENDM	
/*
Pn_Data	MACRO	Pn,GO1,GO2
	Pn&_PAGE
	mov	Pn&_GO1	GO1
	mov	Pn&_GO2	GO2
	ENDM		
*/	
Play?_Label macro label
	v_state&_page
	mov	a #0001b
	and	a v_state
	caje	#0001b label
	endm
FREQ macro H,L	
	MOV	A	H
	MOV	RH	A
	MOV	A	#0000B
	MOV	RL	A
	MOV	A	H
	MOV	RH	A
	MOV	A	L
	MOV	RL	A
	endm
Tail	macro
	CALL1	@@TAILXO
	endm
Vol_M	macro	Mi

	Mi&_PAGE
	mov	a,Mi
	temp6&_PAGE
	; Mark bit 3 of data
	mov	temp6,a
	mov	a,#0111b
	and	a,temp6
	mov	temp6,a
	
	; Volvalue = {VolValue[3],temp6[2:0]}
	mov	a,#1000b
	VolValue_Page0&_Page
	and	a,VolValue_Page0
	temp6&_PAGE
	or	a,temp6
	VolValue_Page0&_Page
	mov	VolValue_Page0,a
	mov	mode,a

	endm	
; VOL=data
Vol_D	macro	data
	temp6&_PAGE
	; Mark bit 3 of data
	mov	temp6,#data
	mov	a,#0111b
	and	a,temp6
	mov	temp6,a
	
	; Volvalue = {VolValue[3],temp6[2:0]}
	mov	a,#1000b
	VolValue_Page0&_Page
	and	a,VolValue_Page0
	temp6&_PAGE
	or	a,temp6
	VolValue_Page0&_Page
	mov	VolValue_Page0,a
	mov	mode,a
	endm	
STOP_P	macro	
	CALL2 	@@STOP_PB
	endm
STOP_O	macro
	CALL3	@@STOP_O1
	endm
STOP_V	macro	
	CALL1	@@STOP_V		
	endm
STOP_all macro
	CALL1	@@STOP
	endm
DELAY	MACRO  v1,v2,v3
	Delay_Flag&_PAGE
	MOV	A	#1110B
	AND	A	Delay_Flag
	MOV	Delay_Flag	A
	delay8m&_PAGE
	MOV	DELAY8M	v1
	MOV	DELAY01	v2
	MOV	DELAY1S	v3
	v_state&_page
;	mov	a	#1101b
	mov	a	#1110b
	and	a	ret_flag
	mov	ret_flag	a
	MOV	A	#0010B   
	OR	A	RET_FLAG 
	MOV	RET_FLAG	A		
	delay8m&_PAGE
	CALL1	@@SCANKEY1
	endm

P_DELAY	macro  v1,v2,v3
	Delay_Flag&_PAGE
	MOV	A	#1110B
	AND	A	Delay_Flag
	MOV	Delay_Flag	A
	p_delay1&_PAGE
	MOV	p_delay1	v1
	MOV	p_delay2	v2
	MOV	p_delay3	v3
	v_state&_page
;	mov	a	#0111b
	mov	a	#1011b	
	and	a	ret_flag
	mov	ret_flag	a
	mov	a	#1000b
	or	a	ret_flag
	mov	ret_flag	a	
	p_delay1&_PAGE
	CALL2	@@SCANKEY1
	endm	

S_DELAY	macro  v1,v2,v3
	Delay_Flag&_PAGE
	MOV	A	#1110B
	AND	A	Delay_Flag
	MOV	Delay_Flag	A
	S_delay1&_PAGE
	MOV	S_delay1	v1
	MOV	S_delay2	v2
	MOV	S_delay3	v3
	CALL3	@@SCANKEY1
	endm		
	
IRoutX	MACRO A1	
	IRout_ON_OFF_3_0&_page
	MOV	A, #0001B
	AND	A, IRout_ON_OFF_3_0
	CAJE	#0001B, @F
	MOV	A, #0001B
	OR	A, IRout_ON_OFF_3_0
	MOV	IRout_ON_OFF_3_0, A
	A1&_Page
	mov	a	A1&_Low
	TRANS_H&_page
	MOV	TRANS_H, a
	A1&_Page
	mov	a	A1&_High
	TRANS_L&_page
	MOV	TRANS_L, a 
@@:	
	endm		

VoiceName	MACRO	VoiceName
	CALL1	@@CHK_VOC1
	CALL1	@@CLEAR_ENTER_B1
	PLAY	VoiceName
	v_state&_page
;	mov	a	#0010b
	mov	a	#0011b
	or	a	ret_flag
	mov	ret_flag	a
	CALL1	@@SCANKEY1
	endm

VoiceName_P	MACRO	VoiceName
	V_STATE_&page
	MOV	A #0100B
	OR	A V_STATE
	MOV	V_STATE A
	CALL2	@@CHK_VOC_P1
	CALL2	@@CLEAR_ENTER_P1
	
	PLAY	Voicename
	v_state&_page
;	mov	a	#1000b
	mov	a	#1100b
	or	a	ret_flag
	mov	ret_flag	a
	CALL2	@@SCANKEY1
	endm	

ASM_RET	macro	dd
local	@@_RET1,@@_RET2
;	TEMP1&_PAGE	
	page4
	MOV	A	TEMP6	
	CAJE	#0001B	@@_RET1	
	CAJE	#0010B	@@_RET2	
	RET3
@@_RET1:	
	RET1
@@_RET2:	
	RET2
	endm


ASM 	macro	aa,bb
local	@@call1,@@call2,@@exit_macro	
;	TEMP1&_PAGE
	page4
	mov	a	bb	
	MOV	TEMP6	a
	caje	#0001b	@@call1
	caje	#0010b	@@call2
	call3	aa
	jmp	@@exit_macro
@@call1:
	call1	aa
	jmp	@@exit_macro
@@call2:
	call2	aa	
@@exit_macro:	
	endm		