.model tiny
.code
jumps
	org	100h
start:	jmp	ini
copyright db	13,10,13,10,'        -= Copyright (c) Evgeny Medvednikov 1992. Antiskop lab. =-',13,10,13,10

int09:	pushf
	push	ax
	push	es
	in	al,60h
	cmp	al,0e0h
	je	extend
	test	al,80h
	jne	reset_done
	mov	byte ptr cs:done,1
	jmp	cont1 	
reset_done:
	mov	byte ptr cs:flag,0
	mov	byte ptr cs:done,0
	mov	byte ptr cs:tik,5
	mov	cs:scan,al
	jmp	extend
cont1:
	push	ax
	mov	ax,40h
	mov	es,ax
	mov	ax,es:[1ch]
	mov	cs:head,ax
	pushf
	call	dword ptr cs:old
	pop	ax
	cmp	cs:scan,al
	mov	cs:scan,al
	jne	no_move

	mov	ax,cs:head
	cmp	ax,es:[1ch]
	mov	ax,es:[1ch]
	mov	cs:head,ax

	je	no_buf
	mov	byte ptr cs:flag,1
	jmp	cont
no_move:
	mov	ax,cs:head
	cmp	ax,es:[1ch]
	mov	ax,es:[1ch]
	mov	cs:head,ax
	je	no_buf
	
	
	mov	byte ptr cs:flag,0
	mov	byte ptr cs:done,1
	mov	byte ptr cs:tik,5
	jmp	cont
no_buf:
	mov	byte ptr cs:flag,0
	mov	byte ptr cs:done,0
cont:
	pop	es
	pop	ax
	popf
	iret
extend:
	pop	es
	pop	ax
	popf
	jmp	dword ptr cs:old	

last_char:
	cli
	push	bx
	mov	bx,es:[1ch]
	add	bx,2
	cmp	bx,es:[1ah]
	je	quit
	sub	bx,2
	cmp	bx,1eh
	jne	norm
	mov	ax,es:[3ch]
	mov	es:[1eh],ax
	mov	word ptr es:[1ch],1eh+2
	jmp	quit
norm:
	mov	ax,es:[bx-2]
	mov	es:[bx],ax
	cmp	bx,3ch
	jne	dal
	mov	bx,1eh-2
dal:
	inc	bx
	inc	bx
	mov	es:[1ch],bx
	mov	cs:head,bx
quit:
	pop	bx
	ret

int08:	pushf
	cmp	byte ptr cs:done,0
	je	exit8
	dec	byte ptr cs:tik
	jnz	cont3
	mov	byte ptr cs:tik,5
	mov	byte ptr cs:flag,1
cont3:
	cmp	byte ptr cs:flag,0
	je	exit8
	cmp	cs:done,0
	je	exit8
	push	ax
	push	es
	mov	ax,40h
	mov	es,ax
	call	last_char
	pop	es
	pop	ax
exit8:	popf
	db	0eah		; jmp far xxxx:xxxx
old8	dw	?,?	

tik	db	5
old	dw	?,?
scan	db	?
head	dw	?
flag	db	?
done	db	?

int16:
	cmp	dx,9854h
	jne	quit16
	cmp	bx,5498h
	jne	quit16
	mov	ax,'IM'
	iret
quit16:	
	db	0eah
old16	dw	?,?

ini:	mov	ax,0f000h
	mov	es,ax
	cmp	byte ptr es:[0fffeh],0fch
	je	at_mashine
	cmp	byte ptr es:[0fffeh],0f8h
	je	at_mashine

	mov	ah,1
	mov	dx,9854h
	mov	bx,5498h
	int	16h
	cmp	ax,'IM'
	je	alr

	mov	dx,offset xt_mess
	mov	ah,9
	int	21h

	cli
	mov	ax,40h
	mov	es,ax
	mov	ax,es:[1ch]
	mov	cs:head,ax


	mov	ax,3509h
	int	21h
	mov	old,bx
	mov	old+2,es
	mov	ax,2509h
	mov	dx,offset int09
	int	21h

	mov	ax,3516h
	int	21h
	mov	old16,bx
	mov	old16+2,es
	mov	ax,2516h
	mov	dx,offset int16
	int	21h

	mov	ax,3508h
	int	21h
	mov	old8,bx
	mov	old8+2,es
	mov	ax,2508h
	mov	dx,offset int08
	int	21h

	mov	dx,offset ini
	int	27h
at_mashine:
	mov	ax,305h
	mov	bx,0
	int	16h
	mov	dx,offset at_mess
	mov	ah,9
	int	21h
	int	20h
alr:
	mov	ah,9
	mov	dx,offset alrm
	int	21h
	int	20h

xt_mess	db	13,10,'FASTKEY for XT or PC mashine installed',13,10,36
at_mess	db	13,10,'FASTKEY for AT or XT-286 mashine is ON',13,10,36
alrm	db	'FASTKEY allready installed$'
end	start
