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 >
Assembly Source File  |  1988-12-07  |  13KB  |  313 lines

  1.                    TITLE   CMON
  2. PAGE, 132
  3. COMMENT |
  4.  
  5.        Copyright by John Poindexter  Rockville, MD
  6.        Version 1.0  November 4, 1988
  7.  
  8.        xMONITOR Series
  9.  
  10.        This is part of a family of MONITOR programs designed to work with
  11.        applications running in DESQview windows which are not DESQview
  12.        applications, but for which you want to perform some function related
  13.        to their presence in DESQview.
  14.  
  15.        CMON is a DESQview program to be used with DESQview, CMONITOR and
  16.        communications programs such as RBBS and COM-AND where you want to
  17.        monitor the presence of a carrier signal in order to re-start the
  18.        program upon a loss of carrier.
  19.  
  20.        xMONITORs use the DESQview API.
  21.  
  22.        Usage:  You must first install the CMONITOR programs in DESQview.
  23.        See the instruction for CMONITOR.
  24.  
  25.        CMONITOR works in conjuction with CMON.  While in communciations
  26.        program execute CMON d:\path\CM-PIF.DVP from a DOS shell and
  27.        CMONITOR will be loaded and start monitoring the carrier.  When you
  28.        want the monitoring to stop, execute CMON OFF.  CMON will open and
  29.        close the window with CMONITOR.  For the inter-process
  30.        communications that are needed for this to work both the comm PIF
  31.        and CMONITOR PIF must indicate that they share programs.  You
  32.        indicate this by placing an asterisk in the 'Shared Program
  33.        Pathname' field.
  34.  
  35.        CMON checks for the presence of DESQview and will not load unless
  36.        it is present.  It is designed to work with DESQview version 2.01.
  37.  
  38. |
  39. ;*************************************************************
  40. ;            PROGRAM EQUATES, STRUCTURES AND MACROS
  41. ;*************************************************************
  42.  
  43. include dvapi.inc
  44. cmd_tail           equ     80h
  45. cr                 equ     0dh
  46. lf                 equ     0ah
  47. eol                equ     '$'
  48.  
  49. ;*************************************************************
  50. ;        CODE SEGMENT BEGINS
  51. ;*************************************************************
  52.  
  53. code_seg           segment
  54.                    assume  cs:code_seg
  55.                    org     100h            ;org = 100h to make this into a
  56.                                            ;".com" file
  57. first:             jmp     load_monitor
  58.  
  59. ;*************************************************************
  60. ;        PROGRAM DATA
  61. ;*************************************************************
  62.  
  63.                    db      'CMON.COM'
  64.                    db      'Copyright by John Poindexter'
  65.                    db      'Version 1.0'
  66.                    db      '4NOV88'
  67.  
  68.                    align   2
  69. PSP_seg            dw      ?
  70.  
  71. ;DESQview data
  72. main_handle_msg    db      'MAIN'
  73. lmain_handle_msg   equ     $-main_handle_msg
  74. close_mon_msg      db      'CLOSE'
  75. lclose_mon_msg     equ     $-close_mon_msg
  76. mon_mailbox        db      'CMONITOR'
  77. lmon_mailbox       equ     $-mon_mailbox
  78. monitor            label   dword
  79. monitor_win        dw      2 dup (0)
  80. monitor_mail       dd      0
  81. pif_buffer         db      416 dup (?)
  82.  
  83. dv_error_msg       db  cr,lf
  84.                    db  'ERROR - DESQview is not present.'
  85.                    db  cr,lf,eol
  86. file_error_msg     db  cr,lf
  87.                    db  'ERROR - Unable to open PIF file for CMONITOR program.'
  88.                    db  cr,lf,eol
  89. syntax_error_msg   db  cr,lf
  90.                    db  'ERROR - Syntax is: CMON [d:\path\CM-PIF.DVP|OFF]'
  91.                    db  cr,lf,eol
  92.  
  93. ;********************************************************************
  94. ;             ARGV PROCEDURE to get command line arguments
  95. ;********************************************************************
  96. ;                  Call with:  ES:BX = command line address
  97. ;                              (implicit: ES=PSP segment)
  98. ;                              AX    = argument number (0 based)
  99. ;
  100. ;                  Returns:    ES:BX = argument address
  101. ;                              AX    = argument length
  102. ;                              (0=argument not found)
  103. ;                  Other registers preserved.
  104. ;
  105. ; If called with AX=0 (argv[0]) and running under
  106. ; MS-DOS version 3.0 or later, returns ES:BX pointing
  107. ; to program name in environment block and AX=length,
  108. ; otherwise returns ES:BX unchanged and AX=0.
  109. ;
  110.  
  111. cr      equ     0dh             ; ASCII carriage return
  112. lf      equ     0ah             ; ASCII line feed
  113. tab     equ     09h             ; ASCII tab
  114. blank   equ     20h             ; ASCII space character
  115. eqsign  equ     3dh             ; ASCII equal sign
  116.  
  117. argv    proc    near
  118.         or      ax,ax           ; is it argument 0?
  119.         jz      argv8           ; yes, jump to get program name
  120.  
  121.         xor     ah,ah           ; initialize argument counter
  122.  
  123. argv1:  mov     cx,-1           ; set flag = outside argument
  124.  
  125. argv2:  inc     bx              ; point to next character
  126.         cmp     byte ptr es:[bx],cr
  127.         je      argv7           ; exit if carriage return
  128.         cmp     byte ptr es:[bx],blank
  129.         je      argv1           ; outside argument if ASCII blank
  130.         cmp     byte ptr es:[bx],tab
  131.         je      argv1           ; outside argument if ASCII tab
  132.         cmp     byte ptr es:[bx],eqsign
  133.         je      argv1           ; outside argument if ASCII equal sign
  134.  
  135.                                 ; if not blank, tab or equal sign...
  136.         jcxz    argv2           ; jump if already inside argument
  137.  
  138.         inc     ah              ; else count arguments found
  139.         cmp     ah,al           ; is this the one we're looking for?
  140.         je      argv4           ; yes, go find its length
  141.         not     cx              ; no, set flag = inside argument
  142.         jmp     argv2           ; and look at next character
  143.  
  144. argv4:                          ; found desired argument, now
  145.                                 ; determine its length...
  146.         mov     ax,bx           ; save param. starting address
  147.  
  148. argv5:  inc     bx              ; point to next character
  149.         cmp     byte ptr es:[bx],cr
  150.         je      argv6           ; found end if carriage return
  151.         cmp     byte ptr es:[bx],blank
  152.         je      argv6           ; found end if ASCII blank
  153.         cmp     byte ptr es:[bx],tab
  154.         je      argv6           ; found end if ASCII tab
  155.         cmp     byte ptr es:[bx],eqsign
  156.         jne     argv5           ; found end if ASCII equal sign
  157.  
  158. argv6:  xchg    bx,ax           ; set ES:BX = argument address
  159.         sub     ax,bx           ; and AX = argument length
  160.         jmp     argvx           ; return to caller
  161.  
  162. argv7:  xor     ax,ax           ; set AX = 0, argument not found
  163.         jmp     argvx           ; return to caller
  164.  
  165. argv8:                          ; special handling for argv=0
  166.         mov     ax,3000h        ; check if DOS 3.0 or later
  167.         int     21h             ; (force AL=0 in case DOS 1)
  168.         cmp     al,3
  169.         jb      argv7           ; DOS 1 or 2, return null param.
  170.         mov     es,es:[2ch]     ; get environment segment from PSP
  171.         xor     di,di           ; find the program name by
  172.         xor     al,al           ; first skipping over all the
  173.         mov     cx,-1           ; environment variables...
  174.         cld
  175. argv9:  repne scasb             ; scan for double null (can't use
  176.         scasb                   ; (SCASW since might be odd addr.)
  177.         jne     argv9           ; loop if it was a single null
  178.         add     di,2            ; skip count word in environment
  179.         mov     bx,di           ; save program name address
  180.         mov     cx,-1           ; now find its length...
  181.         repne scasb             ; scan for another null byte
  182.         not     cx              ; convert CX to length
  183.         dec     cx
  184.         mov     ax,cx           ; return length in AX
  185.  
  186. argvx:                          ; common exit point
  187.         ret                     ; return to caller
  188.  
  189. argv    endp
  190.  
  191. ;****************************************************************************
  192. ;             LOAD OR UNLOAD CMONITOR PROCEDURE
  193. ;****************************************************************************
  194.  
  195. load_monitor       proc    near
  196.  
  197.                    assume  cs:code_seg, ds:code_seg, es:nothing
  198.  
  199.                    mov     PSP_seg,es      ;save PSP
  200.  
  201. ;make sure this is a DESQview environment
  202.  
  203. chk_dv:            @call   dvpresent
  204.                    test    ax,ax
  205.                    jnz     install
  206.                    lea     dx,dv_error_msg
  207.                    jmp     failed
  208.  
  209. ;DESQview actions
  210. ;get argument
  211.  
  212. install:           mov     bx,cmd_tail     ;setup to get command line arg
  213.                    mov     es,PSP_seg
  214.                    mov     ax,1            ;get first argument
  215.                    call    argv
  216.                    cmp     ax,3            ;is it OFF or a filespec
  217.                    je      turn_off        ;it's probably an OFF
  218.                    mov     di,ax           ;assume its a filespec
  219.                    mov     byte ptr es:[di+bx],0 ;make filespec ASCIIZ
  220.  
  221. ;setup to open CMONITOR process
  222.  
  223.                    push    ds              ;save DS
  224.                    mov     ax,es           ;point to ASCIIZ filespec
  225.                    mov     ds,ax
  226.                    mov     dx,bx
  227.                    mov     ax,3d00h        ;open file for reading
  228.                    int     21h
  229.                    pop     ds
  230.                    jnc     read_file
  231.                    lea     dx,file_error_msg
  232.                    jmp     failed
  233.  
  234. read_file:         mov     bx,ax           ;get file handle
  235.                    lea     dx,pif_buffer
  236.                    mov     cx,416          ;DV 2.00 PIFs are 416 bytes
  237.                    mov     ah,3fh          ;read file
  238.                    int     21h
  239.                    mov     ah,3eh          ;close file
  240.                    int     21h
  241.  
  242. ;open new process for CMONITOR
  243.  
  244.                    push    ds                 ;point to PIF buffer
  245.                    pop     es
  246.                    lea     di,pif_buffer
  247.                    mov     bx,416             ;DV 2.00 PIFs are 416 bytes long
  248.                    @call   newproc            ;open CMONITOR application in DV
  249.                    mov     monitor_win[2],bx  ;get handle - high order word
  250.  
  251. ;send CMONITOR a short message to provide our handle
  252.  
  253.                    @push   monitor            ;get CMONITOR mailbox handle
  254.                    @send   handle,mailtos
  255.                    @pop    monitor_mail
  256.                    lea     si,main_handle_msg
  257.                    xor     bx,bx
  258.                    mov     ax,lmain_handle_msg
  259.                    @push   dssi
  260.                    @push   bxax
  261.                    @send   write,monitor_mail
  262.  
  263.                    jmp     finished
  264.  
  265. ;close CMONITOR window
  266.  
  267. turn_off:          cmp     byte ptr es:[bx],'O'
  268.                    je      check2
  269.                    cmp     byte ptr es:[bx],'o'
  270.                    jne     syntax
  271. check2:            cmp     byte ptr es:[bx+1],'F'
  272.                    je      check3
  273.                    cmp     byte ptr es:[bx+1],'f'
  274.                    jne     syntax
  275. check3:            cmp     byte ptr es:[bx+2],'F'
  276.                    je      close
  277.                    cmp     byte ptr es:[bx+2],'f'
  278.                    jne     syntax
  279.  
  280. close:
  281.                    push    ds
  282.                    pop     es
  283.                    lea     di,mon_mailbox
  284.                    mov     cx,lmon_mailbox
  285.                    @call   findmail
  286.                    test    bx,bx
  287.                    jz      finished
  288.                    @mov    monitor_mail,dssi
  289.                    lea     di,close_mon_msg
  290.                    xor     dx,dx
  291.                    mov     cx,lclose_mon_msg
  292.                    @push   esdi
  293.                    @push   dxcx
  294.                    @send   write,monitor_mail
  295.                    jmp     finished
  296.  
  297. syntax:            lea     dx,syntax_error_msg
  298.                    jmp     failed
  299.  
  300. finished:          mov     ax,4c00h        ;normal exit
  301.                    int     21h             ;
  302.  
  303. failed:            mov     ah,9            ;if not get back to DOS after
  304.                    int     21h             ;printing error message
  305.                    mov     ax,4c01h        ;and returning errorlevel
  306.                    int     21h             ;
  307.  
  308. load_monitor       endp
  309.  
  310. code_seg           ends
  311.  
  312.                    end     first           ;begin at first
  313.