home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
pc
/
sysutil
/
geterror.lzh
/
GETERROR.ASM
next >
Wrap
Assembly Source File
|
1987-08-01
|
6KB
|
174 lines
page 55,132
code segment
assume cs:code,ds:code,es:code
org 100h
;
start: jmp initialize
; data area
signature db 'GETERROR.COM Version 1.00 by Brett Warthen'
length_signature = $ - signature
old_int21 dd ?
old_int20 dd ?
old_int16 dd ?
error_code db 0
;
;-----------------------------------------------------------------------
; The following is our front-end to DOS, from which we will trap error
; codes issued by terminating programs.
;-----------------------------------------------------------------------
;
new_int21:
cmp ah,0 ; change function 0 to
jnz not_terminate_0 ; 4Ch with return code 0
mov ax,4C00h
not_terminate_0:
cmp ah,4Ch ; not what we're lookin'
jnz not_us ; for...
mov cs:error_code,al ; here it is, save it!
jmp do_it_dos
not_us:
cmp ah,31h
jnz do_it_dos
mov cs:error_code,al
do_it_dos:
jmp cs:old_int21 ; back to old handler
;
;-----------------------------------------------------------------------
; The following is our Interrupt 20h handler, we translate it to
; Interrupt 21h, Function 4C, and terminate with return code 0
;-----------------------------------------------------------------------
;
new_int20:
mov ax,4C00h
int 21h
;
;-----------------------------------------------------------------------
; The following is our new Interrupt 16h handler. We use it solely
; for a signature request to make sure that we don't install more
; than one copy of the program.
;-----------------------------------------------------------------------
;
new_int16:
cmp ax,0B0B1h ; sig request function
jz signature_request
NOTSIG:
jmp cs:old_int16
signature_request:
push ds
push es
push si
push di
push cx
push cs
pop ds
mov di,offset signature
mov cx,length_signature
repe cmpsb ; compare signatures
pop cx
pop di
pop si
pop es
pop ds
jne NOTSIG ; not ours
xchg al,ah ; ours -- swap AL & AH
push cs ; return pointer to
pop ds ; resident data seg in DS
iret
;
;-----------------------------------------------------------------------
; The following code is for installation purposes only and does not
; remain resident.
;-----------------------------------------------------------------------
;
initialize:
; check to see if already installed...
mov ax,0B0B1h
mov si,offset signature
int 16h
cmp ax,0B1B0h
jnz not_installed
mov al,error_code ; DS points to resident
xor ah,ah ; data...
push ds ; save that for later
push cs
pop ds ; DS points local
mov dl,100 ; convert code to ASCII
div dl
cmp al,0
jz no_100s
add al,'0'
mov msg_code,al
no_100s:
mov al,ah
xor ah,ah
mov dl,10
div dl
cmp al,0
jz no_10s
add al,'0'
mov msg_code[1],al
no_10s:
add ah,'0'
mov msg_code[2],ah
mov ah,9 ; display message
mov dx,offset error_msg
int 21h
; restore pointer to resident data segment, and return with the same
; error level so as to not effect DOS ERRORLEVEL statements in batch
; files...
pop ds
mov ah,4Ch
mov al,error_code
int 21h ; out of here!
not_installed:
mov ax,3521h ; Get address for old
int 21h ; Int 21h routine
mov word ptr old_int21,bx ; and save it
mov word ptr old_int21[2],es
mov dx,offset new_int21 ; Set Int 21h to point to
mov ax,2521h ; our Int 21h handler
int 21h
mov ax,3520h ; Get address for old
int 21h ; Int 20h routine
mov word ptr old_int20,bx ; and save it
mov word ptr old_int20[2],es
mov dx,offset new_int20 ; Set Int 20h to point to
mov ax,2520h ; our Int 20h handler
int 21h
mov ax,3516h ; Get address for old
int 21h ; Int 16h routine
mov word ptr old_int16,bx ; and save it
mov word ptr old_int16[2],es
mov dx,offset new_int16 ; Set Int 16h to point to
mov ax,2516h ; our Int 16h handler
int 21h
mov ah,9 ; Print installation
mov dx,offset install_msg ; message
int 21h
mov dx,offset initialize ; Terminate but remain
int 27h
install_msg db 13,10,'GETERROR.COM Version 1.00 by Brett Warthen',13,10
db 'has been installed in RAM Memory.',13,10,13,10,'$'
error_msg db 13,10,'GETERROR: Last Program terminated with Error Code '
msg_code db '000',13,10,'$'
code ends
end start