
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;								;;
	;; Prot200 Copyright (C) 2000 Pixel (Pap︻ Martin)		;;
	;;	A program to handle the problem with Intel CPUs and the	;;
	;;	Borland Pascal 7.0 CRT library bug causing "Runtime	;;
	;;	error 200 at xxxx:xxxx" messages			;;
	;;								;;
	;; Download at: http://karol.adlerka.schools.sk/~pixel		;;
	;;		http://fornax.sk/~pixel				;;
	;;								;;
	;; Reporting bugs, suggestions, questions, donations, ideas, or	;;
	;; for any other unlisted reason you can contact me at this	;;
	;; e-mail address: pixel@karol.adlerka.schools.sk		;;
	;;								;;
	;; About source code distribution see prot200.txt		;;
	;;								;;
	;; Rezident made by REZIDER v2					;;
	;; compile with: tasm dprot.asm /m				;;
	;;		 tlink dprot.obj /t				;;
	;;								;;
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


model tiny
.code
.386
	org	100h
start:
	jmp	get_rezident
;--------------------------------------------------------------------------
INT_00	proc	far

	pushf
	pusha
	mov	bp,sp
	push	ds es

	add	bp,12h
	lds	bx,ss:[bp]
	cmp	word ptr ds:[bx],0F1F7h
	jne	__dont_activate
	cmp	word ptr ds:[bx-2],00037h
	jne	__dont_activate
	add	word ptr ss:[bp],2
	mov	word ptr ss:[bp-12h+2],0FFFFh
	mov	word ptr ss:[bp-12h+6],0FFFFh
	pop	es ds
	popa
	xor	dx,dx
	mov	ax,0FFFFh
	popf
	iret
__dont_activate:
	pop	es ds
	popa
	popf

	db	0EAh	;far jump to original interrupt vector

ofs_00	dw	?
seg_00	dw	?

INT_00	endp
;--------------------------------------------------------------------------
INT_21	proc	far

	cmp	ax,2500h
	je	change_00
	cmp	ax,3500h
	je	read_00

back:

	db	0EAh	;far jump to original interrupt vector
ofs_21	dw	?
seg_21	dw	?

change_00:
	cmp	bx,0FEEDh
	jne	not_myself1
	cmp	cx,0DEAFh
	je	back
not_myself1:
	cli
	mov	cs:ofs_00,dx
	mov	cs:seg_00,ds
	sti
	retf	2
read_00:
	cmp	bx,0FEEDh
	jne	not_myself2
	cmp	cx,0DEAFh
	je	back
not_myself2:
	mov	bx,cs:ofs_00
	mov	es,cs:seg_00
	retf	2

INT_21	endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
get_rezident:
	mov	ah,9
	mov	dx,offset intro_text
	int	21h
	mov	bx,0FEEDh
	mov	cx,0DEAFh
	mov	ax,3500h
	int	21h	; Get original vector of INT 00
	mov	seg_00,es
 	cmp	bx,offset INT_00
 	jne	not_yet
 	mov	al,ds:[bx]
 	cmp	al,es:[bx]
 	je	uninstall
not_yet:
	mov	ofs_00,bx
	mov	bx,0FEEDh
	mov	cx,0DEAFh
	mov	ax,2500h
	mov	dx,offset INT_00
	int	21h
	mov	ax,3521h
	int	21h	; Get original vector of INT 21
	mov	seg_21,es
	mov	ofs_21,bx
	mov	ax,2521h
	mov	dx,offset INT_21
	int	21h
	mov	ah,9
	mov	dx,offset install_text
	int	21h
	mov	dx,offset get_rezident
	int	27h		; Terminate but stay resident
uninstall:
	mov	ax,2521h
	lds	dx,dword ptr es:ofs_21
	int	21h

	mov	ax,2500h
	lds	dx,dword ptr es:ofs_00
	int	21h

	mov	ah,49h		; release program memory
	int	21h
	mov	es,es:[2Ch]	; release environment
	mov	ah,49h
	int	21h
	push	cs
	pop	ds
	mov	ah,9
	mov	dx,offset uninstall_text
	int	21h
	int	20h
intro_text	db	'prot200 v1.00 Copyright (C) 2000 Pixel (Pap︻ Martin)',0Dh,0Ah,'$'
install_text	db	'insatlled$'
uninstall_text	db	'uninsatlled$'
end	start
