h43315
s 00081/00000/00000
d D 1.1 83/03/22 20:12:40 bog 1 0
c date and time created 83/03/22 20:12:40 by bog
e
u
4
U
t
T
I 1
CBase	Equ	Ds:Word Ptr .00003h; Base of CSeg
DBase	Equ	Ds:Word Ptr .00009h; Base of DSeg
EBase	Equ	Ds:Word Ptr .0000fh; Base of ESeg
SBase	Equ	Ds:Word Ptr .00015h; Base of SSeg
MyBase	Equ	Ds:Word Ptr .0002dh; Base of my CSeg

	CSeg
Prologue:
	Pop	Es		; Destination of move is CSeg
	Sub	Di,Di		;  with offset 0

	Push	Es		; Return to CSeg needs CBase
	Push	Ax		;  and offset of 0

	Push	Ds		; Save pointer to base page seg

	Push	Cs		; Source is my CSeg
	Pop	Ds		;  with
	Mov	Si,Offset Swapper;  offset of first byte to move back

	Mov	Cx,Swap_Length	; Number of bytes to be moved back
	Cld			; Work up in address

    Rep	Movs	Es:Byte Ptr 0[Di],Ds:Byte Ptr 0[Si]; Move stolen code back

	Pop	Ds		; Point Ds back to base page

Relocate_Loop:
	Lods	Cs:Byte Ptr 0[Si]; Get Location|Target byte of relocate list

	Or	Al,Al		; Done with list?
	Jz	Relocate_Done	; Jump if yes

	Mov	Ah,066h		; Two multipliers
	Push	Ax		; Save Location|Target
	And	Ax,0f0f0h	; Ah <- 060h, Al <- Location
	Mul	Ah		; Ax <- Location *6 (*256)
	Xchg	Al,Ah		; * 6 for index into base base
	Mov	Di,Ax		;  into Di

	Lods	Cs:Word Ptr 0[Si]; Get SegOffset from reloc list
	Add	Ax,Ds:Word Ptr (-3)[Di]; Ax <- segbase of item to relocate
	Mov	Es,Ax		; Es <- segbase of item to relocate

	Lods	Cs:Byte Ptr 0[Si]; Get ByteOffset from reloc list
	Mov	Ah,0		; High half zero
	Mov	Bx,Ax		; Bx <- Byte offset of item to relocate

	Pop	Ax		; Location|Target
	And	Ax,00f0fh	; Ah <- 006h, Al <- Target
	Mul	Ah		; *6 for index into base page
	Mov	Di,Ax		;  into Di

	Mov	Ax,Ds:Word Ptr (-3)[Di]; Segbase of Target bucket
	Add	Es:Word Ptr 0[Bx],Ax; Relocate Location by Target segbase

	Jmps	Relocate_Loop	; Loop until done relocating

Relocate_Done:
	Retf			; Invoke .CMD program


Swapper:
	Push	Cs		; Push CBase for Prologue
	Mov	Ax,MyBase	; Get segbase of Prologue
	Push	Ax		;  and push it
	Sub	Ax,Ax		; Start at offset 0
	Push	Ax		; Segbase and offset now on stack
	Retf			; Invoke Prologue with Retf

Reloc	Rb	0

Prologue_Length	Equ	(Offset Swapper)-(Offset Prologue)

Swap_Length	Equ	(Offset Reloc)-(Offset Swapper)

	DSeg
	Dw	Prologue_Length
	Dw	Swap_Length

	End
E 1
