PUBLIC	CCLDIR
PUBLIC	CCLDDR

CCLDDR:
; Callable via cclddr(dest,source,count)
; CCLDDR mimics LDDR instruction for 8080, executes LDDR on Z80. 
; However count of zero performs nop.
EXTRN	CCCPU
EXTRN	XXKLG

	MOV	H,B	; Squirrel away BC
	MOV	L,C
	SHLD	XXKLG	

	POP	H	; Return address
	POP	B	; Count
	POP	D	; Source
	XTHL		; Dest->hl, return address to TOS
	XCHG		; srce->HL,dest->DE,count->BC 

	MOV	A,B
	ORA	C
	JZ	CCLDIX

	LDA	CCCPU	; Check CPU type
	ORA	A
	JZ	CCLDD8

CCLDDZ:				; Z80 CPU	*****
	DB	0EDH,0B8H	; Z80 lddr instruction
	JMP	CCLDIX

CCLDD8:				; 8080 CPU	*****
	MOV	A,M
	DCX	H
	STAX	D
	DCX	D
	DCX	B
	MOV	A,B
	ORA	C
	JNZ	CCLDD8
	JMP	CCLDIX

CCLDIR:
; Callable via ccldir(dest,source,count)
; CCLDIR mimics LDIR instruction for 8080, executes LDIR on Z80. 
; However count of zero performs nop.
EXTRN	CCCPU
EXTRN	XXKLG

	MOV	H,B	; Squirrel away BC
	MOV	L,C
	SHLD	XXKLG	

	POP	H	; Return address
	POP	B	; Count
	POP	D	; Source
	XTHL		; Dest->hl, return address to TOS
	XCHG		; srce->HL,dest->DE,count->BC 

	MOV	A,B
	ORA	C
	JZ	CCLDIX

	LDA	CCCPU	; Check CPU type
	ORA	A
	JZ	CCLDI8

CCLDIZ:				; Z80 CPU	*****
	DB	0EDH,0B0H	; Z80 ldir instruction

CCLDIX:	LHLD	XXKLG
	MOV	B,H
	MOV	C,L
	XTHL			; Ret addr -> HL
	PUSH	H		; Adjust SP 
	PUSH	H
	PCHL			; Ret

CCLDI8:				; 8080 CPU	*****
	MOV	A,M
	INX	H
	STAX	D
	INX	D
	DCX	B
	MOV	A,B
	ORA	C
	JNZ	CCLDI8
	JMP	CCLDIX
	END


	LDA	CCCPU	; Check CPU type
	ORA	A
	JZ	CCLDD8

CCLDDZ:				; Z80