;------------------------------------------------------------------------------
;  CHIP: for SN8P2XXXX series
;  Purpose: The cycle of some SN8P2XXX instructions are different to S8KD-2 ICE.
;           this FILE provide macro to align the instruction cyle between
;           SN8P2XXX real chip and ICE.
;  Revision History:
;  V1.0  03/08/2004  First issue
;
;  V2.0  03/23/2004  
;                    1. Add IFNDEF __SN8P2X_ICE__ to avoid re-definition error
;                    2. Add @SONiX_Macro_Branch macro
;                       Note: After 1.99K assembler will suport user defined jump forward and
;                              backword directive)
;------------------------------------------------------------------------------

IFNDEF	__SN8P2X_ICE__
	__SN8P2X_ICE__	EQU	1


;************************************************
@xch	macro  m1,m2

	IFDIFI	<A>, <m1>
		ECHO	Error: The first parameter of @XCH macro should be A(accumulator)
		ECHO	Valid example: @XCH A,M
		ECHO
		ERROR
		ENDP
	ENDIF

		    xch  m1,m2        
	
	endm  
	      
;************************************************
@b0xch	macro  m1,m2 

	IFDIFI	<A>, <m1>
		ECHO	Error: The first parameter of @B0XCH macro should be A(accumulator)
		ECHO	Valid example: @B0XCH A,M
		ECHO
		ERROR
		ENDP
	ENDIF             

		b0xch  m1,m2        
	
	endm
	
;************************************************     
; Note: m2 must be A (accumulator)
@adc	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @ADC macro should be A(accumulator)
		ECHO	Valid example: @ADC M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		adc  m1,m2        
	
	endm
	
;************************************************     
; Note: m2 must be A (accumulator)
@add	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @ADD macro should be A(accumulator)
		ECHO	Valid example: @ADD M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		add  m1,m2        
	
	endm
	       
;************************************************ 
; Note: m2 must be A (accumulator)
@b0add	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @B0ADD macro should be A(accumulator)
		ECHO	Valid example: @B0ADD M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		b0add  m1,m2        
	
	endm    

;************************************************     
; Note: m2 must be A (accumulator)
@sbc	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @SBC macro should be A(accumulator)
		ECHO	Valid example: @SBC M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		sbc  m1,m2        
	
	endm

;************************************************     
; Note: m2 must be A (accumulator)
@sub	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @SUB macro should be A(accumulator)
		ECHO	Valid example: @SUB M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		sub  m1,m2        
	
	endm

;************************************************     
; Note: m2 must be A (accumulator)
@and	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @AND macro should be A(accumulator)
		ECHO	Valid example: @AND M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		and  m1,m2        
	
	endm

;************************************************     
; Note: m2 must be A (accumulator)
@or	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @OR macro should be A(accumulator)
		ECHO	Valid example: @OR M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		or  m1,m2        
	
	endm

;************************************************     
; Note: m2 must be A (accumulator)
@xor	macro  m1,m2

	IFDIFI	<A>, <m2>
		ECHO	Error: The second parameter of @XOR macro should be A(accumulator)
		ECHO	Valid example: @XOR M,A
		ECHO
		ERROR
		ENDP
	ENDIF

		xor  m1,m2        
	
	endm

;************************************************     
@swapm	macro  m1	

		swapm  m1
	
	endm

;************************************************    
@rrcm	macro  m1

		rrcm  m1     
	
	endm

;************************************************   
@rlcm	macro  m1

		rlcm  m1     
	
	endm

;************************************************   
@bclr	macro  m1

	_m1Addr = @int(m1)

		bclr  m1
	
	endm

;************************************************   
@bset	macro  m1

	_m1Addr = @int(m1)

		bset  m1
	
	endm
	
;************************************************   
@b0bclr	macro  m1

	_m1Addr = @int(m1)

		b0bclr  m1
	
	endm
	
;************************************************    
@b0bset	macro  m1

	_m1Addr = @int(m1)

		b0bset  m1
	
	endm         
;************************************************
@incms  macro  m1

		incms  m1
	
	endm

;************************************************    
@decms  macro  m1

		decms  m1
	
	endm
        
;************************************************

@SONiX_Macro_Branch	macro

	ECHO ***************************************************************************
	ECHO *              !!!! Waring !!!!
	ECHO * Put an Macro next an Branch instruction maybe cause wrong branch.
	ECHO * @SONiX_Macro_Branch is defined in SN8P2X_ICE.H
	ECHO ***************************************************************************
	jmp    @F.SN8_Macro_Start
	jmp    @F.SN8_Macro_End
	
	endm
	
;************************************************

ENDIF