;Обработка : TASM SCREEN.ASM
;	     TLINK /T SCREEN.OBJ	
;
stack_len	equ	25

mux_number	equ	169

cseg segment 'code'

assume cs:cseg    
	
	org 100h

begin: jmp begn1 

	
stack_area	db	stack_len dup (?)	;My stack


promp db 13,10,"Set Border Colour (0..16).",13,10
      db "Hot Key  Alt(left)+Shift(left)+Shift(Right).",13,10,"$" 

alr_inst db "Process is already install.",13,10,"$"

cant_inst db "Process is cannot to install",13,10,"$"

oldint_9 label dword				;Addr Old_9_Int
	ofsint_9 dw ?
	segint_9 dw ?

stack_off dw ?					;My stack offset

old_st_seg dw ?					;Old stack addr
old_st_off dw ?
 
sav_ax dw ?

colour  		db	?


New_Int_2f	label	far

		cmp	ah,Mux_Number
		jne	Foreign_Number

;		or	al,al
;		jnz	Bad_Function

		dec	al		; This handler relies on AL to be zero

		iret

Foreign_Number:
		jmp	dword ptr cs:Old_Int_2f_ptr

Old_Int_2f_ptr	dd	?


;****************************************************************************
;			RESIDENT PART BEGIN
;****************************************************************************
respr proc far

	cli

	mov cs:sav_ax,ax     		;Save old stack
	mov ax,ss
	mov cs:old_st_seg,ax
	mov cs:old_st_off,sp
	
	mov ax,cs			;Set My stack
	mov ss,ax
	mov sp,cs:stack_off

	pushf				;Save Flags and registers
	push bx dx cx di si ds es bp 

	xor ax,ax			;Compare with hot-key
	mov ds,ax
	mov bx,417h
	mov ax,[bx]
	
	and ax,8+3
	cmp ax,8+3
	je doing
;	and ax,4+2
;	cmp ax,4+2

;	jnz doing			;Do

	jmp nodoin			;Do nothing
	
doing:  
;	mov ax,0b800h			;Set (ds=video buffer addr)
;	mov ds,ax

	inc cs:colour
	cmp cs:colour,16
	jne set_bord 
	xor al,al
	mov cs:colour,al
	

set_bord:

;	mov dx,3d9h			;Set border color (Port 3d9h);
;	mov al,cs:colour
;	out dx,al
	
	mov ah,0bh
	mov bh,0
	mov bl,cs:colour
	int 10h
	
;	mov bx,1			
;
;	mov ah,44			;Set screen attributes
;
;	mov cx,25*80
;doscr:					
;	mov byte ptr [bx],ah		;Output this attributes at 
;	inc bx				;video buffer
;	inc bx
;	loop doscr

nodoin:	pop bp es ds si di cx dx bx	;Set old Flags and registers 
	popf
	
	mov ax,cs:old_st_seg		;Set old stack
	mov ss,ax
	mov sp,cs:old_st_off

	mov ax,cs:sav_ax

	sti

	jmp oldint_9 			;Jamp to Old_9_int

respr endp
;**************************************************************************
;                      RESIDENT PAART END
;**************************************************************************

begn1: 	

	mov ax,cs			;Set addr of My stack in cs:stack_off
	mov ss,ax
	mov ax,offset stack_area
	add ax,stack_len
	dec ax
	mov cs:stack_off,ax

	xor al,al
	mov ah,mux_number
	int 2fh

	jc ca_inst
	or al,al
	jz  ok_to_inst
	inc al
	jz al_inst
ca_inst:
	lea dx,cant_inst
	mov ah,9
	int 21h	
	jmp quite
al_inst:
	lea dx,alr_inst
	mov ah,9
	int 21h

	jmp quite

ok_to_inst:

	mov ax,352fh
	int 21h
	mov cs:word ptr old_int_2f_ptr,bx
	mov cs:word ptr Old_Int_2f_ptr+2,es
	



; Set own Mux process into chain
;-------------------------------

	mov ax,cs
	mov ds,ax

	mov	dx,offset New_Int_2f
	mov	ax,252fh
	int	21h




	mov ah,35h			;Get 9_Int_Vector
	mov al,9
	int 21h
	
	mov ax,es			;Save 9_Int_Vector in cs:oldint_9
	mov cs:segint_9,ax
	mov cs:ofsint_9,bx

	mov ax,cs			;Set new addr 9_Int
	mov ds,ax
	mov ax,offset respr
	mov dx,ax

	mov ah,25h			;Change 9_Int_Vector
	mov al,9
	int 21h

	mov ah,9             		;Print (promp > con)
	mov dx,offset promp
	int 21h

	xor ah,ah
	mov cs:colour,ah	

	mov dx,offset begn1             ;Set resident length	

	int 27h		                ;Stage resident and quite	


quite:  int 20h

cseg ends

end begin 