;[]-------------------------------------------------------------------------[]
;|	Program name: 3_1_1.ASM                                              |
;|	Image   file: 3_1_1.COM                                              |
;|	Note        : A frame for TSR in chapter 3.                          |
;[]-------------------------------------------------------------------------[]


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

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

old_int13	dd	?
old_int60	dd	?
old_int61	dd	?

;------- Include area ------------------

DEBUG	EQU	1
include	register.inc
include	interrup.inc
include	debug.inc

;------- INT 13H -----------------------

new_int13	proc	far

	sti

;
; Pre-processing program can be inserted here.
;

	cli
	pushf
	call	cs:old_int13		; Execute Old INT 13H ISR
	sti

;
; Doing more job in this area.
;

	iret

new_int13	endp

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

new_int60	proc	far

	assume	cs:cseg,ds:nothing	; Override segment

	sti
	pushr	<ax,dx,ds>

	set_int	13H,<word ptr old_int13>,<word ptr old_int13[2]>
	set_int	60H,<word ptr old_int60>,<word ptr old_int60[2]>
	set_int	61H,<word ptr old_int61>,<word ptr old_int61[2]>

	popr	<ds,dx,ax>
	iret

new_int60	endp

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

initialize:

	assume	cs:cseg,ds:cseg

	get_int	13H,old_int13
	set_int	13H,<offset new_int13>
	get_int	60H,old_int60
	set_int	60H,<offset new_int60>
	get_int	61H,old_int61
	set_int	61H,<offset new_int61>

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

cseg	ends
	end	start
