;[]-------------------------------------------------------------------------[]
;|	Program name: 2_5_1.ASM                                              |
;|	Image   file: 2_5_1.COM                                              |
;|	Note        : It is modified from 2_4_1.ASM.                         |
;|                    There are some bugs in this TSR program.               |
;[]-------------------------------------------------------------------------[]


cseg	segment
	assume	cs:cseg,ds:cseg
	org	100H
start:
	jmp	initialize

;------- Data area ---------------------

old_int05	dd	?
old_int60	dd	?
msg		db	'Hello world!',0DH,0AH,'$'

;------- INT 05H -----------------------

new_int05	proc	far

	sti

	push	ax			; Save the register value
	push	dx
	push	ds

	mov	ax,cs			; Display 'Hello world!'
	mov	ds,ax
	mov	dx,offset msg
	mov	ah,09H
	int	21H

	pop	ds			; Restore the register value
	pop	dx
	pop	ax

	iret

new_int05	endp

;------- INT 60H -----------------------

new_int60	proc	far

	sti

	push	ax
	push	dx
	push	ds

	mov	dx,cs:word ptr old_int05	; restore INT 05H
	mov	ds,cs:word ptr old_int05[2]
	mov	ax,2505H
	int	21H

	mov	dx,cs:word ptr old_int60	; restore INT 60H
	mov	ds,cs:word ptr old_int60[2]
	mov	ax,2560H
	int	21H

	pop	ds
	pop	dx
	pop	ax

	iret

new_int60	endp

;------- Main program ------------------

initialize:

	mov	al,05H			; Get the INT 05H interrupt vector
	mov	ah,35H
	int	21H
	mov	word ptr old_int05,bx	; Save the vector in old_int05
	mov	word ptr old_int05[2],es

	mov	al,60H			; Get the INT 60H interrupt vector
	mov	ah,35H
	int	21H
	mov	word ptr old_int60,bx	; Save the vector in old_int60
	mov	word ptr old_int60[2],es

	mov	dx,offset new_int05	; Set the INT 05H interrupt vector
	mov	al,05H
	mov	ah,25H
	int	21H

	mov	dx,offset new_int60	; Set the INT 60H interrupt vector
	mov	al,60H
	mov	ah,25H
	int	21H

	mov	dx,offset initialize	; Terminate and stay resident
	int	27H

cseg	ends
	end	start
