|
<--- Turn the page
   
(contents page)
   
Turn the page ---> Detecting the ANSI screen driver |
|
|
The third technique is another small .COM file which sends an ANSI cursor report command to the driver and checks to see if ANSI returns a response. When executed from batch file, it will return the same errorlevel setting as with the second technique descussed before: ;----------------------------------------------;
; Utility to detect if ANSI.SYS is already ;
; installed on the system. ;
; ;
; Sends ANSI cursor report character to screen.;
; If there is a response (ANSI returns actual ;
; cursor report) then ANSI is installed. ;
; ;
; - use nbasm to assemble this source ;
; ;
; Support batch file: ;
; Returns errorlevel 0 if not detected. ;
; Returns errorlevel 1 if detected ;
; ;
; by Hendry Lee ;
;----------------------------------------------;
.model tiny
.code
org 100h
; clear keyboard buffer
call FlushBuf
; test for ANSI
mov dx,offset Ansi_Test
call Disp
mov ah,0Bh ; get STDIN status
int 21h
call ClrSc
call Goto_Top_Left
cmp al,0FFh ; = char returned
jz short Detected
Not_Detected: ; display not installed
mov dx,offset Not_Inst_Msg
call Disp
xor al,al
jmp short Exit ; exit to DOS
; clear keyboard buffer
Detected: call FlushBuf
mov dx,offset Inst_Msg ; installed
call Disp
mov al,1
Exit: mov ah,4Ch ; exit to DOS
int 21h
Disp proc near uses ax
mov ah,09h ; display string
int 21h
ret
Disp endp
FlushBuf proc near uses ax
loophere: mov ah,06h ; direct console input
mov dl,0FFh
int 21h
or al,al ; any input?
jnz loophere ; yes, get next
ret
FlushBuf endp
ClrSc proc near uses ax bx cx dx
mov ah,06h ; scroll up window
xor al,al ; entire screen
mov bh,7h ; normal attribute
xor cx,cx ; upper left (0,0)
mov dh,24 ; lower right row
mov dl,79 ; lower right column
int 10h
ret
ClrSc endp
Goto_Top_Left proc near uses ax bx dx
mov ah,02h ; set cursor position
mov bh,0h ; at this page
mov dh,00h ; row at 0
mov dl,00h ; column at 0
int 10h
ret
Goto_Top_Left endp
;ANSI cursor report command
Ansi_Test db 1Bh,'[6n','$'
Inst_Msg db 'ANSI.SYS installed.','$'
Not_Inst_Msg db 'ANSI.SYS not installed.','$'
.end
The Pros and Cons of each: The first technique is all batch script. No need for an assembler or the time to debug it in DEBUG if you need to modify it. However, it does print extra line feeds to the screen. The second and third technique are very small, 82 bytes and 156 bytes respectively. If you want to use either one in a batch file with out the print to screen, you could delete even more bytes. However, if you are an optimize freak (and who isn't), you could have them return 0FFh instead of 01h and save a few more bytes, but let is leave optimization for a different issue. ¥ |
<--- Turn the page
   
(contents page)
   
Turn the page ---> Page 14