

.equ z_HL  z_Regs
.equ z_L   z_Regs
.equ z_H   z_Regs+1
.equ z_HLU  z_Regs+2

.equ z_BC  z_Regs+3
.equ z_C   z_Regs+3
.equ z_B   z_Regs+4
.equ z_BCU   z_Regs+5

.equ z_DE  z_Regs+6
.equ z_E   z_Regs+6
.equ z_D   z_Regs+7
.equ z_DEU  z_Regs+8

.equ z_As  z_Regs+9
.equ z_Hs  z_Regs+10
.equ z_ix  z_Regs+11
.equ z_ixl  z_Regs+11
.equ z_ixh  z_Regs+12


.equ z_iy   z_Regs+13
.equ z_iyl  z_Regs+13
.equ z_iyh  z_Regs+14


.equ z_spec  z_Regs+15 ; Used for A during Z80 emu routines


.equ t_SP     	 z_Regs+16
.equ t_RetAddr 	 z_Regs+17
.equ t_RetAddrL 	 z_Regs+17
.equ t_RetAddrH 	 z_Regs+18
.equ t_A     	 z_Regs+19
.equ t_X     	 z_Regs+20
.equ t_Y     	 z_Regs+21

.equ t_MemdumpL     	 z_Regs+22
.equ t_MemdumpH     	 z_Regs+23
.equ t_MemdumpU     	 z_Regs+24

.equ t_MemdumpBL     	 z_Regs+25
.equ t_MemdumpBH     	 z_Regs+26
.equ t_MemdumpBU     	 z_Regs+27

;z_BCs  z_Regs+18
;z_Cs   z_Regs+19
;z_Bs   z_Regs+20

.equ Bit0 	LookupBits+0
.equ Bit1 	LookupBits+1
.equ Bit2 	LookupBits+2
.equ Bit3 	LookupBits+3
.equ Bit4 	LookupBits+4
.equ Bit5 	LookupBits+5
.equ Bit6 	LookupBits+6
.equ Bit7 	LookupBits+7
.macro Mode65816 			
	clc	;16 bit mode (65816 Native)
	xce
.endm

.macro Mode16bit 			
	 	;  --MX---- M=Accumulator X=XY
	REP  #%00110000	;16 bit XY+Accumulator
	.ACCU 16 ;assume M:0		;Accumulator 16 bit
	.INDEX 16;assume X:0		;XY 16 bit	
.endm
.macro Mode16bitAX
	 	;  --MX---- M=Accumulator X=XY
	REP  #%00110000	;16 bit XY+Accumulator
	.ACCU 16 ;assume M:0		;Accumulator 16 bit
	.INDEX 16;assume X:0		;XY 16 bit	
.endm
.macro Mode16bitA
	    ;  --MX---- M=Accumulator X=XY
	REP  #%00100000	
	SEP  #%00010000	
	.ACCU 16		;Accumulator 16 bit
	.INDEX 8		;XY 16 bit	
.endm
.macro Mode16bitX
	    ;  --MX---- M=Accumulator X=XY
	REP  #%00010000	
	SEP  #%00100000
	.ACCU 8 ;assume M:0		;Accumulator 16 bit
	.INDEX 16;assume X:0		;XY 16 bit	
.endm

.macro Mode8bit	;This will set top byte of XY to 0 / AB (C) unaffected
	;6502 mode implies this anyway:
		;  --MX---- M=Accumulator X=XY
	SEP  #%00110000	;8 bit XY+Accumulator 
	
	.ACCU 8		;Accumulator 8 bit
	.INDEX 8	;XY 8 bit
.endm


.macro Mode6502	;This will set top byte of XY to 0 / AB (C) unaffected
	sec	;8 bit mode (6502 Emulation)
	xce	
	
	;6502 mode implies this anyway:
		;  --MX---- M=Accumulator X=XY
	SEP  #%00110000	;8 bit XY+Accumulator 
	
	.ACCU 8		;Accumulator 8 bit
	.INDEX 8	;XY 8 bit
.endm

.macro Mode8bitAX;This will set top byte of XY to 0 / AB (C) unaffected
	SEP  #%00110000	;8 bit XY+Accumulator
	.ACCU 8 ;assume M:1		;Accumulator 8 bit
	.INDEX 8;assume X:1		;XY 8 bit
.endm

.macro rlca	
		clc
		adc #$80
		rol
.endm
.macro rrca	
		pha
			ror
		pla
		ror
.endm
.macro PushAll	
		pha
		
		txa
		pha
		
		tya 
		pha
.endm
.macro PullAll
		pla 
		tay
		
		pla
		tax
		
		pla
.endm

.macro PushPair			;Push a pair onto the stack (eg PushPair z_HL)
		lda \1			
		pha				;Push lower Zpage entry
		lda \1+1
		pha
.endm					;Push higher Zpage entry
	
.macro PullPair			;Pull a pair onto the stack (eg PullPair z_HL)
		pla
		sta \1+1		;Pull lower Zpage entry
		pla
		sta \1			;Pull higher Zpage entry
		stz \1+2
.endm
.macro PushTriple			;Push a pair onto the stack (eg PushPair z_HL)
		lda \1			
		pha				;Push lower Zpage entry
		lda \1+1
		pha
		lda \1+2
		pha
.endm					;Push higher Zpage entry
	
.macro PullTriple			;Pull a pair onto the stack (eg PullPair z_HL)
		pla
		sta \1+2		;Pull lower Zpage entry
		pla
		sta \1+1		;Pull lower Zpage entry
		pla
		sta \1			;Pull higher Zpage entry
		
.endm

.macro PushPairSafe		;Push a pair onto the stack (eg PushPair z_HL)
		sta z_spec
		lda \1			
		pha				;Push lower Zpage entry
		lda \1+1
		pha
		lda z_spec
.endm				;Push higher Zpage entry
	
.macro PullPairSafe		;Pull a pair onto the stack (eg PullPair z_HL)
		sta z_spec
		pla
		sta \1+1		;Pull lower Zpage entry
		pla
		sta \1			;Pull higher Zpage entry
		stz \1+2
		lda z_spec
.endm
.macro LoadPair	
		lda #<\2
		sta \1
		lda #>\2
		sta \1+1
		stz \1+2
.endm


.macro LoadTriple
		lda #<\2
		sta \1		;L
		
		lda #>\2
		sta \1+1	;H
		
		lda #\2>>16
		sta \1+2	;U
.endm


.macro LoadOne
		lda \2
		sta \1
.endm
.macro AddTriple
		clc
		lda \1
		adc #<\2	;L
		sta \1
		
		lda #>\2
		adc \1+1	;H
		sta \1+1
	
		lda #\2>>16
		adc \1+2	;U
		sta \1+2
.endm
.macro AddPair	
		clc
		lda \1
		adc #<\2
		sta \1
		lda #>\2
		adc \1+1
		sta \1+1
.endm
.macro add
		clc
		adc \1
.endm
.macro sub	
		sec
		sbc \1
.endm