home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mega CD-ROM 1
/
megacd_rom_1.zip
/
megacd_rom_1
/
DESQVIEW
/
CMONITOR.ZIP
/
CMON.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-12-07
|
13KB
|
313 lines
TITLE CMON
PAGE, 132
COMMENT |
Copyright by John Poindexter Rockville, MD
Version 1.0 November 4, 1988
xMONITOR Series
This is part of a family of MONITOR programs designed to work with
applications running in DESQview windows which are not DESQview
applications, but for which you want to perform some function related
to their presence in DESQview.
CMON is a DESQview program to be used with DESQview, CMONITOR and
communications programs such as RBBS and COM-AND where you want to
monitor the presence of a carrier signal in order to re-start the
program upon a loss of carrier.
xMONITORs use the DESQview API.
Usage: You must first install the CMONITOR programs in DESQview.
See the instruction for CMONITOR.
CMONITOR works in conjuction with CMON. While in communciations
program execute CMON d:\path\CM-PIF.DVP from a DOS shell and
CMONITOR will be loaded and start monitoring the carrier. When you
want the monitoring to stop, execute CMON OFF. CMON will open and
close the window with CMONITOR. For the inter-process
communications that are needed for this to work both the comm PIF
and CMONITOR PIF must indicate that they share programs. You
indicate this by placing an asterisk in the 'Shared Program
Pathname' field.
CMON checks for the presence of DESQview and will not load unless
it is present. It is designed to work with DESQview version 2.01.
|
;*************************************************************
; PROGRAM EQUATES, STRUCTURES AND MACROS
;*************************************************************
include dvapi.inc
cmd_tail equ 80h
cr equ 0dh
lf equ 0ah
eol equ '$'
;*************************************************************
; CODE SEGMENT BEGINS
;*************************************************************
code_seg segment
assume cs:code_seg
org 100h ;org = 100h to make this into a
;".com" file
first: jmp load_monitor
;*************************************************************
; PROGRAM DATA
;*************************************************************
db 'CMON.COM'
db 'Copyright by John Poindexter'
db 'Version 1.0'
db '4NOV88'
align 2
PSP_seg dw ?
;DESQview data
main_handle_msg db 'MAIN'
lmain_handle_msg equ $-main_handle_msg
close_mon_msg db 'CLOSE'
lclose_mon_msg equ $-close_mon_msg
mon_mailbox db 'CMONITOR'
lmon_mailbox equ $-mon_mailbox
monitor label dword
monitor_win dw 2 dup (0)
monitor_mail dd 0
pif_buffer db 416 dup (?)
dv_error_msg db cr,lf
db 'ERROR - DESQview is not present.'
db cr,lf,eol
file_error_msg db cr,lf
db 'ERROR - Unable to open PIF file for CMONITOR program.'
db cr,lf,eol
syntax_error_msg db cr,lf
db 'ERROR - Syntax is: CMON [d:\path\CM-PIF.DVP|OFF]'
db cr,lf,eol
;********************************************************************
; ARGV PROCEDURE to get command line arguments
;********************************************************************
; Call with: ES:BX = command line address
; (implicit: ES=PSP segment)
; AX = argument number (0 based)
;
; Returns: ES:BX = argument address
; AX = argument length
; (0=argument not found)
; Other registers preserved.
;
; If called with AX=0 (argv[0]) and running under
; MS-DOS version 3.0 or later, returns ES:BX pointing
; to program name in environment block and AX=length,
; otherwise returns ES:BX unchanged and AX=0.
;
cr equ 0dh ; ASCII carriage return
lf equ 0ah ; ASCII line feed
tab equ 09h ; ASCII tab
blank equ 20h ; ASCII space character
eqsign equ 3dh ; ASCII equal sign
argv proc near
or ax,ax ; is it argument 0?
jz argv8 ; yes, jump to get program name
xor ah,ah ; initialize argument counter
argv1: mov cx,-1 ; set flag = outside argument
argv2: inc bx ; point to next character
cmp byte ptr es:[bx],cr
je argv7 ; exit if carriage return
cmp byte ptr es:[bx],blank
je argv1 ; outside argument if ASCII blank
cmp byte ptr es:[bx],tab
je argv1 ; outside argument if ASCII tab
cmp byte ptr es:[bx],eqsign
je argv1 ; outside argument if ASCII equal sign
; if not blank, tab or equal sign...
jcxz argv2 ; jump if already inside argument
inc ah ; else count arguments found
cmp ah,al ; is this the one we're looking for?
je argv4 ; yes, go find its length
not cx ; no, set flag = inside argument
jmp argv2 ; and look at next character
argv4: ; found desired argument, now
; determine its length...
mov ax,bx ; save param. starting address
argv5: inc bx ; point to next character
cmp byte ptr es:[bx],cr
je argv6 ; found end if carriage return
cmp byte ptr es:[bx],blank
je argv6 ; found end if ASCII blank
cmp byte ptr es:[bx],tab
je argv6 ; found end if ASCII tab
cmp byte ptr es:[bx],eqsign
jne argv5 ; found end if ASCII equal sign
argv6: xchg bx,ax ; set ES:BX = argument address
sub ax,bx ; and AX = argument length
jmp argvx ; return to caller
argv7: xor ax,ax ; set AX = 0, argument not found
jmp argvx ; return to caller
argv8: ; special handling for argv=0
mov ax,3000h ; check if DOS 3.0 or later
int 21h ; (force AL=0 in case DOS 1)
cmp al,3
jb argv7 ; DOS 1 or 2, return null param.
mov es,es:[2ch] ; get environment segment from PSP
xor di,di ; find the program name by
xor al,al ; first skipping over all the
mov cx,-1 ; environment variables...
cld
argv9: repne scasb ; scan for double null (can't use
scasb ; (SCASW since might be odd addr.)
jne argv9 ; loop if it was a single null
add di,2 ; skip count word in environment
mov bx,di ; save program name address
mov cx,-1 ; now find its length...
repne scasb ; scan for another null byte
not cx ; convert CX to length
dec cx
mov ax,cx ; return length in AX
argvx: ; common exit point
ret ; return to caller
argv endp
;****************************************************************************
; LOAD OR UNLOAD CMONITOR PROCEDURE
;****************************************************************************
load_monitor proc near
assume cs:code_seg, ds:code_seg, es:nothing
mov PSP_seg,es ;save PSP
;make sure this is a DESQview environment
chk_dv: @call dvpresent
test ax,ax
jnz install
lea dx,dv_error_msg
jmp failed
;DESQview actions
;get argument
install: mov bx,cmd_tail ;setup to get command line arg
mov es,PSP_seg
mov ax,1 ;get first argument
call argv
cmp ax,3 ;is it OFF or a filespec
je turn_off ;it's probably an OFF
mov di,ax ;assume its a filespec
mov byte ptr es:[di+bx],0 ;make filespec ASCIIZ
;setup to open CMONITOR process
push ds ;save DS
mov ax,es ;point to ASCIIZ filespec
mov ds,ax
mov dx,bx
mov ax,3d00h ;open file for reading
int 21h
pop ds
jnc read_file
lea dx,file_error_msg
jmp failed
read_file: mov bx,ax ;get file handle
lea dx,pif_buffer
mov cx,416 ;DV 2.00 PIFs are 416 bytes
mov ah,3fh ;read file
int 21h
mov ah,3eh ;close file
int 21h
;open new process for CMONITOR
push ds ;point to PIF buffer
pop es
lea di,pif_buffer
mov bx,416 ;DV 2.00 PIFs are 416 bytes long
@call newproc ;open CMONITOR application in DV
mov monitor_win[2],bx ;get handle - high order word
;send CMONITOR a short message to provide our handle
@push monitor ;get CMONITOR mailbox handle
@send handle,mailtos
@pop monitor_mail
lea si,main_handle_msg
xor bx,bx
mov ax,lmain_handle_msg
@push dssi
@push bxax
@send write,monitor_mail
jmp finished
;close CMONITOR window
turn_off: cmp byte ptr es:[bx],'O'
je check2
cmp byte ptr es:[bx],'o'
jne syntax
check2: cmp byte ptr es:[bx+1],'F'
je check3
cmp byte ptr es:[bx+1],'f'
jne syntax
check3: cmp byte ptr es:[bx+2],'F'
je close
cmp byte ptr es:[bx+2],'f'
jne syntax
close:
push ds
pop es
lea di,mon_mailbox
mov cx,lmon_mailbox
@call findmail
test bx,bx
jz finished
@mov monitor_mail,dssi
lea di,close_mon_msg
xor dx,dx
mov cx,lclose_mon_msg
@push esdi
@push dxcx
@send write,monitor_mail
jmp finished
syntax: lea dx,syntax_error_msg
jmp failed
finished: mov ax,4c00h ;normal exit
int 21h ;
failed: mov ah,9 ;if not get back to DOS after
int 21h ;printing error message
mov ax,4c01h ;and returning errorlevel
int 21h ;
load_monitor endp
code_seg ends
end first ;begin at first