;	DDT RELOCATOR PROGRAM, INCLUDED WITH THE MODULE TO PERFORM
;	THE MOVE FROM 200H TO THE DESTINATION ADDRESS
VERSION	EQU	14	;1.4
;
;	COPYRIGHT (C) 1976, 1977, 1978
;	DIGITAL RESEARCH
;	BOX 579 PACIFIC GROVE
;	CALIFORNIA 93950
;
	ORG	100H
STACK	EQU	200H
BDOS	EQU	0005H
PRNT	EQU	9	;BDOS PRINT FUNCTION
MODULE	EQU	200H	;MODULE ADDRESS
;
	LXI	B,0	;ADDRESS FIELD FILLED-IN WHEN MODULE BUILT
	JMP	START
	DB	'COPYRIGHT (C) 1978, DIGITAL RESEARCH      '
SIGNON:	DB	'DDT VERS '
	DB	VERSION/10+'0','.'
	DB	VERSION MOD 10 + '0','$'
START:	LXI	SP,STACK
	PUSH	B
	PUSH	B
	LXI	D,SIGNON
	MVI	C,PRNT
	CALL	BDOS
	POP	B	;RECOVER LENGTH OF MOVE
	LXI	H,BDOS+2;ADDRESS FIELD OF JUMP TO BDOS (TOP MEMORY)
	MOV	A,M	;A HAS HIGH ORDER ADDRESS OF MEMORY TOP
	DCR	A	;PAGE DIRECTLY BELOW BDOS
	SUB	B	;A HAS HIGH ORDER ADDRESS OF RELOC AREA
	MOV	D,A
	MVI	E,0	;D,E ADDRESSES BASE OF RELOC AREA
	PUSH	D	;SAVE FOR RELOCATION BELOW
;
	LXI	H,MODULE;READY FOR THE MOVE
MOVE:	MOV	A,B	;BC=0?
	ORA	C
	JZ	RELOC
	DCX	B	;COUNT MODULE SIZE DOWN TO ZERO
	MOV	A,M	;GET NEXT ABSOLUTE LOCATION
	STAX	D	;PLACE IT INTO THE RELOC AREA
	INX	D
	INX	H
	JMP	MOVE
;
RELOC:	;STORAGE MOVED, READY FOR RELOCATION
;	HL ADDRESSES BEGINNING OF THE BIT MAP FOR RELOCATION
	POP	D	;RECALL BASE OF RELOCATION AREA
	POP	B	;RECALL MODULE LENGTH
	PUSH	H	;SAVE BIT MAP BASE IN STACK
	MOV	H,D	;RELOCATION BIAS IS IN D
;
REL0:	MOV	A,B	;BC=0?
	ORA	C
	JZ	ENDREL
;
;	NOT END OF THE RELOCATION, MAY BE INTO NEXT BYTE OF BIT MAP
	DCX	B	;COUNT LENGTH DOWN
	MOV	A,E
	ANI	111B	;0 CAUSES FETCH OF NEXT BYTE
	JNZ	REL1
;	FETCH BIT MAP FROM STACKED ADDRESS
	XTHL
	MOV	A,M	;NEXT 8 BITS OF MAP
	INX	H
	XTHL		;BASE ADDRESS GOES BACK TO STACK
	MOV	L,A	;L HOLDS THE MAP AS WE PROCESS 8 LOCATIONS
REL1:	MOV	A,L
	RAL		;CY SET TO 1 IF RELOCATION NECESSARY
	MOV	L,A	;BACK TO L FOR NEXT TIME AROUND
	JNC	REL2	;SKIP RELOCATION IF CY=0
;
;	CURRENT ADDRESS REQUIRES RELOCATION
	LDAX	D
	ADD	H	;APPLY BIAS IN H
	STAX	D
REL2:	INX	D	;TO NEXT ADDRESS
	JMP	REL0	;FOR ANOTHER BYTE TO RELOCATE
;
ENDREL:	;END OF RELOCATION
	POP	D	;CLEAR STACKED ADDRESS
	MVI	L,0
	PCHL		;GO TO RELOCATED PROGRAM
	END
