.model small
.stack 500h
.code
resi_timer: ;resident code for timer interrupt
cmp cs:flag,1 ;cheacking if screen contents are saved
je timer_2
dec cs:count ;cheacking for the completion of waiting period i.e the time after which the screen saver will be activated
jnz timer_quit
push cx
push ax
push dx
push es
push di
push si
push ds
mov cx,0b800h ;initializing data segment to the starting of screen memory
mov ds,cx
mov si,00
mov cx,cs ;initializing extra segment
mov es,cx ;to the starting of code segment
lea di,buf ;for accessing buffer
cld
mov cx,2000 ;80*25=2000 characters, 2 bytes per char:ascii code & attribute
rep movsw ;saving the screen contents to the buffer
mov cs:flag,1
mov cx,0b800h ;initializing extra segment to the starting of screen memory
mov es,cx
mov di,00
mov cx,2000
mov ax,0720h ;load the ascii code for blank space & background in ax regi.
cld
rep stosw ;filling the entire screen with the spaces
pop ds
pop si
pop di
pop es
pop dx
pop ax
pop cx
timer_quit:
jmp dword ptr cs:old_ip_timer ;indirect jumo to the timer ISR routine
timer_2:
dec cs:spd
jnz timer_2_quit
mov cs:spd,2
push cx
push ax
push dx
push es
push di
push si
push ds
mov cx,0b800h
mov es,cx
mov di,cs:pos
mov ax,0720h
cld
stosw
inc cs:pos
inc cs:pos
cmp cs:pos,4000
jb t4
mov cs:pos,0
t4:
mov di,cs:pos
mov cx,cs
mov ds,cx
mov cx,5
lea si,string
mov ah,07
t8:
lodsb
stosw
loop t8
pop ds
pop si
pop di
pop es
pop dx
pop ax
pop cx
timer_2_quit:jmp dword ptr cs:old_ip_timer
resi_kbd:
mov cs:count,150 ;setting count for waiting period to activate screen
cmp cs:flag,0 ;checking if the screen contents are saved
je kbd_quit
push cx
push ax
push dx
push es
push di
push si
push ds
mov cx,0b800h
mov es,cx
mov di,00
mov cx,cs
mov ds,cx
lea si,buf
cld
mov cx,2000
rep movsw
mov cs:flag,0
pop ds
pop si
pop di
pop es
pop dx
pop ax
pop cx
kbd_quit:
jmp dword ptr cs:old_ip_kbd ;indirect jump to the keyboard ISR routine
old_ip_timer dw ?
old_cs_timer dw ?
old_ip_kbd dw ?
old_cs_kbd dw ?
flag db 0
count dw 182
buf db 4000 dup(0)
pos dw 0
spd db 2
string db 'HELLO'
init: ;Initialization routine
mov ax,cs
mov ds,ax
mov ah,35h ;saving the original IVT contents
mov al,8 ;get the address of INT 08h in ES:BX
int 21h
mov word ptr old_ip_timer,bx
mov word ptr old_cs_timer,es
cli
mov ah,25h ;set the address of INT 08 in ES:BX
mov al,8
lea dx,resi_timer ;replacing IVT entries for the timer interrupt by the addresses and offsets of resident codes
int 21h
mov ah,35h ;get the address of INT 09h in ES:BX
mov al,9
int 21h
mov word ptr old_ip_kbd,bx
mov word ptr old_cs_kbd,es
mov ah,25h ;set the address of INT 09 in ES:BX
mov al,9
lea dx,resi_kbd ;replacing IVT entries for the keyboard interrupt by the addresses and offsets of resident codes
int 21h
;lea dx,init
add dx,100h
mov cl,4
shr dx,cl
inc dx
mov ah,31h ; requests stay resident
lea dx,init ; set the size of resident portion
mov al,00
int 21h
end init
end