home *** CD-ROM | disk | FTP | other *** search
- ;=======================================================================
- ;FMARK.ASM - mark a position in memory,
- ;30-May-1989 above which TSRs will later be cleared by UnMark.COM
- ;03:10 this version leaves a minimal size MARK in memory,
- ; storing the rest on disk
- ; requires a single command line parameter naming
- ; the file where the mark will be stored
- ;
- ; Syntax: FMARK [d:][path]filename
- ;=======================================================================
- ; written for MASM (version 4 or later) or TASM
- ; by Kim Kokkonen, TurboPower Software
- ; telephone: 408-438-8608, Compuserve 72457,2131
- ;=======================================================================
- ; VERSION 2.0 6/17/86
- ; start at a version number compatible with other TSR utilities
- ; VERSION 2.1 7/18/86
- ; keep consistent with RELEASE
- ; VERSION 2.2 3/4/87
- ; add save area for BIOS data areas
- ; 40:A8 (8 bytes for EGA)
- ; 40:F0 (16 bytes for interapplications communications)
- ; VERSION 2.3 5/2/87
- ; convert to MASM
- ; VERSION 2.4 5/17/87
- ; for consistency with RELEASE
- ; VERSION 2.5 6/2/87
- ; fix bug in memory allocated when command line is 15 bytes long
- ; add version checking for consistency between FMARK and RELEASE
- ; VERSION 3.1 5/30/89 for use with UnMark and ReMark 3.1
- ; by Tom Gilbert's Heart & Mind includes TurboPower 2.8
- ; fix problem occurring when command processor is an EXE file,
- ; by storing parent's PSP segment as part of MARK save area
- ; (thanks to Tom Rawson for this code)
- ; VERSION 3.2, 6 Jun 90
- ; Toad Hall Tweak
- ; Had a bug where its "didit" string isn't terminated! Prints LOTS of
- ; garbage! Fixed.
- ;=======================================================================
-
- CSEG segment public para
- ASSUME CS:CSEG, DS:CSEG, ES:CSEG
-
- org 016H ;access to parent's PSP
- parpsp label word
-
- org 02CH
- envseg label word ;access to environment segment
-
- org 80H
- cmdlen label byte ;command line length
- org 81H
- cmdlin label byte ;first character of command line
-
- org 100H
- fmark proc near
-
- ComEntry: ;parse command line for file name
- mov si,offset cmdlin ;point to command line
- mov di,offset filnm ;point to filename storage string
- cld
- mov bx,'za' ;BL='a', BH='z' (handy constants) v3.2
- mov dx,0920H ;DL=32, DH=9 v3.2
- mov ah,0DFH ;handy constant for uppercasing v3.2
-
- get1: lodsb ;get first non-blank
- cmp al,dl ;32 ;skip space
- je get1
- cmp al,dh ;9 ;skip tab
- je get1
- cmp al,13 ;check for end of input
- jne get2 ;got a non-blank, now get the parameter
- jmp error ;no parameter --> error
-
- get2: cmp al,bl ;'a' ; v3.2
- jb sto1
- cmp al,bh ;'z' ; v3.2
- ja sto1
- and al,ah ;0DFH ;uppercase v3.2
- sto1: stosb ;store the non-blank character
- lodsb ;get next character
- cmp al,dl ;32 ;terminate with blank, tab, or <cr> v3.2
- je gotit
- cmp al,dh ;9 ; v3.2
- je gotit
- cmp al,13
- je gotit
- jmp short get2
-
- gotit:
- ;v1.1 xor al,al ;create the specified file v3.2
- ;v1.1 stosb ;terminate ASCIIZ pathname
- mov ax,'$' SHL 8
- stosw
- mov dx,offset filnm
- xor cx,cx ;normal attribute
- mov ah,3CH ;DOS CREAT
- int 21H
- ;v3.2 jae store
- jnb store ;v3.2
- mov dx,offset badfil ;'Could not open file for writing'
- jmp MsgErr ;display error, terminate v3.2
-
- store: mov bx,ax ;keep file handle in bx
- push DS ;save DS
- mov cx,400H ;1024 bytes to store
- xor ax,ax
- mov DS,ax ;segment 0
- ASSUME DS:NOTHING
-
- mov dx,ax ;offset 0
- mov ah,40H ;write the interrupt
- int 21H ;vector table block to file
- pop DS ;get DS back
- ASSUME DS:CSEG ;If Write Fails
- jc FwErr ;Then Error Exit
-
- egasav: push DS ;Else save DS
- mov cx,0008H ;8 bytes to store
- mov ax,0040H
- mov DS,ax ;BIOS data segment
- ASSUME DS:NOTHING
- mov dx,00A8H ;EGA save table pointer
- mov ah,40H ;store the EGA data area
- int 21H ;write block to file
- pop DS ;get DS back
-
- ASSUME DS:CSEG ;If Write Fails
- jc FwErr ;Then Error Exit
- intcom: push DS ;Else save DS
- mov cx,0010H ;16 bytes to store
- mov ax,0040H
- mov DS,ax ;BIOS data segment
- ASSUME DS:NOTHING ;store the interapplications
- mov dx,00F0H ;communication area
- mov ah,40H
- int 21H ;write block to file
- pop DS ;get DS back
- ASSUME DS:CSEG ;If Write Fails
- jc FwErr ;Then Error Exit
-
- parent: mov cx,2 ;Else store the parent's psp
- mov dx,offset parpsp
- mov ah,40H
- int 21H ;If write block to file fails
- jc FwErr ;Then Error Exit
- ;Else determine whether EMS is present
- ems: push bx ;temporarily store the file handle
- xor bx,bx ;zero the EMS handle count in case
- mov dx,offset emsnm ;EMS not present
- mov ax,3D00H
- int 21H
- jb sthand ;EMS driver not installed
-
- mov bx,ax ;EMS handle into bx
- mov ah,3EH ;close the
- int 21H ;open "handle"
-
- mov ah,4DH ;get the current EMS page map
- mov di,offset emsmap ;ES=CS already
- xor bx,bx ;required by some versions of EMM
- cld ;required by some versions of EMM
- int 67H
- or ah,ah
- jz sthand ;result ok
- xor bx,bx ;error, return zero EMS handles
- sthand: mov emscnt,bx ;store count of active handles
- shl bx,1
- shl bx,1 ;4 bytes per handle
- inc bx
- inc bx ;2 more bytes for the handle count
- mov cx,bx ;number of bytes to write
- pop bx ;get file handle back
- mov dx,offset emscnt ;what we're writing
- mov ah,40H
- int 21H ;write out the table
- jae closfl ;ok,continue
-
- FwErr: mov dx,offset nowrit ;'Error while writing'
- jmp short MsgErr ;display, terminate v3.2
-
- closfl: mov ah,3EH ;close up the table file
- int 21H ;close handle
- jnb idstr ;ok, continue v3.2
- mov dx,offset badcls ;'Error closing table files'
- jmp short MsgErr ;display, terminate v3.2
-
- ;put a standard ID string into the PSP for RELEASE to check
- idstr: mov si,offset id
- mov di,60H ;unused area of the PSP
- mov cx,IDLEN ;characters in ID string
- cld
- rep movsb ;copy string
-
- ;deallocate environment block of this mark
- deall: mov ax,envseg ;environment segment
- mov ES,ax ; into es
- mov ah,49H ;deallocate
- int 21H ;no reason for an error to occur
- gores: mov dx,offset didit ;print message and TSR
- mov ah,9 ;write success message
- int 21H ;including filename
- mov dx,offset crlf ;and newline
- mov ah,9
- int 21H
- xor dx,dx ;get number of paragraphs to keep
- mov dl,cmdlen ;length of command line
- add dx,0090H ;rest of PSP plus paragraph margin
- mov cl,4
- shr dx,cl ;convert to paragraphs
- mov ax,3100H
- int 21H ;terminate and stay resident
-
- ;v3.2 Enter here if you have a message before 'syntax error'
- MsgErr: mov ah,9 ;v3.2
- int 21H
- ;error output - show syntax line
- error: mov dx,offset syntax
- mov ah,9
- int 21H
- mov ax,4C01H ;exit with error
- int 21H
- fmark endp
-
- emsnm db 'EMMXXXX0',0 ;file name for testing EMS presence
- id db 'FM3.2 TSR' ;id string for UnMark/ReMark check
- IDLEN equ $-id
- ;messages
- badfil db 13,10,'Could not open file for writing$'
- nowrit db 13,10,'Error while writing$'
- badcls db 13,10,'Error closing table file$'
- syntax db 13,10,'Syntax: FMARK [d:][path]filename'
- crlf db 13,10,'$'
- didit db 13,10,'FMARK 3.2 - Marked current memory position in '
- ;data storage area
- filnm db 44H dup ('?') ;mark file name
- emscnt dw 0 ;holds number of active pages in map that follows
- emsmap db 0 ;holds EMS page map if installed
- ;(note may extend 1K bytes past end of file in memory)
- CSEG ends
- end ComEntry