Category : Utilities for DOS and Windows Machines
Archive   : EMSFREE.ZIP
Filename : EMSFREE.ASM

 
Output of file : EMSFREE.ASM contained in archive : EMSFREE.ZIP

PAGE 60,132
;******************************************************************************
TITLE EMS Free
;AUTHOR: William Besancenez
;DATE-WRITTEN: 08-09-1989
;COMMENTS: Reports free EMS memory. Uses very well behaved method.
;
; ERRORLEVEL MEANING
; ---------- ------------------
; 0 EMS exists.
; 1 EMS error.
; 9 EMS doesn't exist.
;******************************************************************************
.MODEL SMALL

DOS equ
EMM equ
CR equ 13
LF equ 10

PrtStr MACRO message
mov dx,OFFSET message
mov ah,9 ; PRINT STRING function
DOS
ENDM
;******************************************************************************
.CODE

ASSUME ds:_TEXT
ORG 100h

start:

; Determine if EMM exists.
call emm_exist

jc no_emm

; Determine EMM status.
call emm_status
jc emm_error

; Get number of pages left.
call ems_pages ; BX = free DX = total
jc emm_error

; Report number of EMS bytes free.
PrtStr Msg1

xor dx,dx ; zero DX
mov ax,16 ; 16K pages
mul bx ; DX:AX = Kbytes
mov bx,ax ; convert BX
call binidec ; to decimal.

PrtStr Msg1a
xor al,al ; AL=0 no errors

exit:
mov ah,4Ch ; TERM PROCESS function
int 21h

no_emm:
PrtStr Msg2
mov al,9
jmp exit

emm_error:
PrtStr Msg3
mov al,1
jmp exit



;-----------------------------------------------------------------------------;
; This procedure tests for the exsistance of the Expanded Memory Manager. ;
; ;
; On exit: ;
; CF set if no EMM ;
;-----------------------------------------------------------------------------;
emm_exist proc

push ax
push bx
push cx
push dx

mov ax,3D00h ; OPENZ for input function
mov dx,OFFSET EmmName
DOS
jc @F ; EMM doesn't exist

mov bx,ax
mov ax,4400h ; IOCTL get device info
DOS

push ax ; save code from IOCTL
mov ah,3Eh ; CLOSEZ function
DOS
pop ax ; restore code from IOCTL

rcl dl,1 ; CF = bit 7 of DL
cmc ; flip CF

@@:
pop dx
pop cx
pop bx
pop ax

ret

emm_exist endp



;-----------------------------------------------------------------------------;
; This procedure gets the EMM status. ;
; ;
; On exit: ;
; CF set if EMM not ready ;
;-----------------------------------------------------------------------------;
emm_status proc

push ax

mov ah,40h ; GET STATUS function
EMM
or ah,ah ; error ?
jz @F
stc ; indicate error
@@:
pop ax
ret

emm_status endp



;-----------------------------------------------------------------------------;
; This procedure returns the number of EMS pages. ;
; ;
; On exit: ;
; BX unallocated pages ;
; DX total pages in system ;
; CF set if EMM error ;
;-----------------------------------------------------------------------------;
ems_pages proc

push ax

mov ah,42h ; GET PAGES function
EMM
or ah,ah ; error ?
jz @F
stc ; indicate error
@@:
pop ax
ret

ems_pages endp



;-------------------------------------------------------------;
; Displays decimal number -- converts leading zeros to spaces ;
; ;
; BX binary number to convert (0..32767) ;
;-------------------------------------------------------------;
binidec proc

push ax
push bx
push cx
push dx
push si

xor si,si ; leading zero blanking ON
mov cx,10000
call dec_div
mov cx,1000
call dec_div
mov cx,100
call dec_div
mov cx,10
call dec_div
mov cx,1
mov si,cx ; leading zero blanking OFF
call dec_div

pop si
pop dx
pop cx
pop bx
pop ax
ret

binidec endp
;
dec_div proc

mov ax,bx ; number to AX
xor dx,dx ; zero to DX
div cx
mov bx,dx ; remainder to BX
mov dl,al ; decimal digit to DL
add dl,30h ; convert to ASCII
or si,ax ; update leading zero blanking
jnz dec_div_out ; ok to print digit
mov dl,' ' ; convert 0 to space
dec_div_out:
mov ah,2 ; display function
DOS

ret
dec_div endp



;-----------;
; DATA AREA ;
;-----------;

EmmName db 'EMMXXXX0',0
Msg1 db 'EMS bytes available: $'
Msg1a db 'K',CR,LF,'$'
Msg2 db 'No EMS present.'
db CR,LF,'$'
Msg3 db 'EMS error!'
db CR,LF,'$'
;******************************************************************************
END start