;[]-------------------------------------------------------------------------[]
;|	Program name: 2_6_4.ASM                                              |
;|	Image   file: 2_6_4.COM                                              |
;|	Note        : This is a TSR program.                                 |
;|                    It uses INT 08H to display the contain of CS and IP.   |
;[]-------------------------------------------------------------------------[]


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

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

old_int08	dd	?
old_int60	dd	?
old_int61	dd	?
x		db	?
y		db	?

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

DEBUG	EQU	0			; Disable debug tool
include	register.inc
include	interrup.inc
include	display.inc
include	cursor.inc
include	debug.inc

;------- INT 08H -----------------------

new_int08	proc	far

	pushf				; Execute Old INT 08H ISR
	call	cs:old_int08
	sti

	push	bp			; Save BP
	mov	bp,sp			; Let BP=SP, so
					; [BP+0] is the old value of BP
					; [BP+2] is the IP of return address
					; [BP+4] is the CS of return address
					; [BP+6] is the FLAG at interrupt

	pushr	<ax,bx,cx,dx,ds>	; Save register
	mov	ax,cs			; Adjust DS
	mov	ds,ax

	get_cursor x,y			; Save current cursor position
	set_cursor 70,0			; Set cursor position to (70,0)

	mov	ax,[bp+4]		; Get CS value
	call	dsword			; Display CS
	call	dcolon			; Display ':'
	mov	ax,[bp+2]		; Get IP value
	call	dsword			; Display IP

	set_cursor x,y			; Restore current cursor position

	popr	<ds,dx,cx,bx,ax>	; Restore register
	pop	bp			; Restore BP
	iret

new_int08	endp

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

new_int60	proc	far

	assume	cs:cseg,ds:nothing	; Override segment

	sti
	pushr	<ax,dx,ds>

	set_int	08H,<word ptr old_int08>,<word ptr old_int08[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	08H,old_int08
	set_int	08H,<offset new_int08>
	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
