116e ; NEWBELL Resident Bell (Ctrl-G) killer ; .MODEL TINY .386 .CODE ORG 100h start: jmp main ;**************************** Resident data org_int10 dd ? ;***************** NewInt10 -- (Write char int Teletype mode) newint10 PROC FAR cmp ax, 0e07h ; Check if Bell character jnz no_bell iret ; Yes, do nothing no_bell: jmp cs:org_int10 ; jump to old Int 10 routine newint10 ENDP ;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Transient Section ;**************************** Transient data header db 'NEWBELL Custom Bell (Ctrl-G) routine',13, 10, '$' uninstalled db 13, 10, 'Un' installed db 'Installed Successfully',13,10,'$' syntax db 'Syntax: NEWBELL [/U]',13,10,'$' nomemory db 'Out of memory',13,10,'$' alreadyin db 'Already installed',13,10,'$' notfound db 'Resident copy not found',13,10,'$' cantunload db 'Can''t uninstall',13,10,'$' resname db 'NewBell ' resseg dw 0 ;**************************** Main -- Main procedure main PROC mov ah,9 ;Print install message mov dx, offset header int 21h call findres ;Find resident copy mov al,'/' ;Search for slash xor cx, cx ;in command line mov cl, byte ptr cs:[80h] mov di, 81h repne scasb jne nounload ;No slash, don't unload mov dx, offset syntax ;DX = 'Syntax:' string cmp byte ptr[di], 'U' ;/U or /u, unload je unload cmp byte ptr[di], 'u' je unload cmp byte ptr[di], '?' ;/?, print syntax je error nounload: mov dx, offset alreadyin ;Point DX to error string cmp resseg, 0 ;Already installed? jne error cld ;Clear direction flag mov ax, offset lastbyte ;AX = last byte + 256 inc ah cmp ax, sp ;Check for too little memory jbe memOK mov dx, offset nomemory ;Print 'Out of memory' string error: mov ah, 9 int 21h mov ax, 4C01h ;Exit with error int 21h memOK: mov sp, ax ;Shrink stack jmp load ;Jump to Load procedure main ENDP ;**************************** Load -- TSR loader procedure load PROC mov ah,49h ;Free environment segment mov es, cs:[2Ch] int 21h mov ax, 3510h ;Get and store old INT9 address int 21h mov word ptr[org_int10], bx mov word ptr[org_int10+2], es mov ax, 2510h ;Set new INT16 handler mov dx, offset newint10 int 21h mov ax, cs ;ES = MCB segment (CS - 1) dec ax mov es, ax mov si, offset resname ;Change resident name mov di, 8 mov cx, di rep movsb mov ah, 9 ;Print 'Installed' string mov dx, offset installed int 21h mov dx, offset header ;Last byte of program lastbyte: int 27h ;DOS TSR service load ENDP ;**************************** Unload -- Uninstall procedure unload PROC mov cx, resseg ;CX = resident segment mov dx, offset notfound ;Point DX to error string test cx, cx ;Make sure it's in memory je error mov dx, offset cantunload ;Point DX to error string mov ax, 3510h ;Check to make sure that the int 21h ;interrupts still point to cmp bx, offset newint10 ;the resident copy... jne error mov es, resseg ;ES = resident segment mov ax, 2510h ;Reset INT9 vector mov dx, word ptr es:[org_int10] mov ds, word ptr es:[org_int10+2] int 21h mov ah, 49h ;Release memory segment int 21h push cs ;DS = CS pop ds mov byte ptr[installed], 'i' ;Fix 'Uninstalled' string mov ah,9 ;Print 'Uninstalled' string mov dx, offset uninstalled int 21h mov ax, 4C00h ;Quit program int 21h unload ENDP ;**************************** FindRes -- Find resident copy findres PROC pusha ;Save registers push es mov ax,5802h ;Save UMB link status int 21h push ax mov ax, 5803h ;Link UMBs mov bx, 1 int 21h mov ah, 52h ;Get Internal Config Table int 21h sub bx, 2 ;BX = first MCB mov bx, es:[bx] fr_lp: mov es, bx ;ES = MCB segment cmp dword ptr es:[8], 4277654eh ;Check for signature je fr_found add bx, es:[3] ;Step to next one inc bx cmp byte ptr es:[0],'Z' ;Last one in chain? jne fr_lp ;Loop back mov bx,-1 ;Return 0 (-1 + 1 = 0) fr_found: inc bx mov resseg, bx ;Return resident segment mov ax, 5803h ;Restore UMB link status pop bx int 21h pop es popa ret findres ENDP END start . 0