home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / SYSUTL / TSRWRK32.ZIP / FMARK.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-06  |  7.3 KB  |  242 lines

  1. ;=======================================================================
  2. ;FMARK.ASM - mark a position in memory,
  3. ;30-May-1989 above which TSRs will later be cleared by UnMark.COM
  4. ;03:10       this version leaves a minimal size MARK in memory,
  5. ;           storing the rest on disk
  6. ;         requires a single command line parameter naming
  7. ;           the file where the mark will be stored
  8. ;
  9. ; Syntax:  FMARK [d:][path]filename
  10. ;=======================================================================
  11. ; written for MASM (version 4 or later) or TASM
  12. ; by Kim Kokkonen, TurboPower Software
  13. ; telephone: 408-438-8608, Compuserve 72457,2131
  14. ;=======================================================================
  15. ; VERSION 2.0  6/17/86
  16. ;   start at a version number compatible with other TSR utilities
  17. ; VERSION 2.1  7/18/86
  18. ;   keep consistent with RELEASE
  19. ; VERSION 2.2  3/4/87
  20. ;   add save area for BIOS data areas
  21. ;     40:A8 (8 bytes for EGA)
  22. ;     40:F0 (16 bytes for interapplications communications)
  23. ; VERSION 2.3  5/2/87
  24. ;   convert to MASM
  25. ; VERSION 2.4  5/17/87
  26. ;   for consistency with RELEASE
  27. ; VERSION 2.5  6/2/87
  28. ;   fix bug in memory allocated when command line is 15 bytes long
  29. ;   add version checking for consistency between FMARK and RELEASE
  30. ; VERSION 3.1  5/30/89 for use with UnMark and ReMark 3.1
  31. ;   by Tom Gilbert's Heart & Mind includes TurboPower 2.8
  32. ;   fix problem occurring when command processor is an EXE file,
  33. ;     by storing parent's PSP segment as part of MARK save area
  34. ;     (thanks to Tom Rawson for this code)
  35. ; VERSION 3.2, 6 Jun 90
  36. ; Toad Hall Tweak
  37. ; Had a bug where its "didit" string isn't terminated!  Prints LOTS of
  38. ; garbage!  Fixed.
  39. ;=======================================================================
  40.  
  41. CSEG    segment    public para
  42.     ASSUME    CS:CSEG, DS:CSEG, ES:CSEG
  43.  
  44.     org    016H        ;access to parent's PSP
  45. parpsp  label    word
  46.  
  47.     org    02CH
  48. envseg  label    word        ;access to environment segment
  49.  
  50.     org    80H
  51. cmdlen  label    byte        ;command line length
  52.     org    81H
  53. cmdlin  label    byte        ;first character of command line
  54.  
  55.     org    100H
  56. fmark    proc    near
  57.  
  58. ComEntry:            ;parse  command line for file name
  59.     mov    si,offset cmdlin ;point to command line
  60.     mov    di,offset filnm    ;point to filename storage string
  61.     cld
  62.     mov    bx,'za'        ;BL='a', BH='z' (handy constants)    v3.2
  63.     mov    dx,0920H    ;DL=32, DH=9                v3.2
  64.     mov    ah,0DFH        ;handy constant for uppercasing        v3.2
  65.  
  66. get1:    lodsb            ;get first non-blank
  67.     cmp    al,dl    ;32        ;skip space
  68.     je    get1
  69.     cmp    al,dh    ;9        ;skip tab
  70.     je    get1
  71.     cmp    al,13        ;check for end of input
  72.     jne    get2        ;got a non-blank, now get the parameter
  73.     jmp    error        ;no parameter --> error
  74.  
  75. get2:    cmp    al,bl    ;'a'    ;                    v3.2
  76.     jb    sto1
  77.     cmp    al,bh    ;'z'    ;                    v3.2
  78.     ja    sto1
  79.      and    al,ah    ;0DFH    ;uppercase                v3.2
  80. sto1:    stosb            ;store the non-blank character
  81.     lodsb            ;get next character
  82.     cmp    al,dl    ;32    ;terminate with blank, tab, or <cr>    v3.2
  83.     je    gotit
  84.     cmp    al,dh    ;9    ;                    v3.2
  85.     je    gotit
  86.     cmp    al,13
  87.     je    gotit
  88.     jmp    short get2
  89.  
  90. gotit:
  91. ;v1.1    xor    al,al        ;create the specified file        v3.2
  92. ;v1.1    stosb            ;terminate ASCIIZ pathname
  93.     mov    ax,'$' SHL 8
  94.     stosw
  95.     mov    dx,offset filnm
  96.     xor    cx,cx        ;normal attribute
  97.     mov    ah,3CH        ;DOS CREAT
  98.     int    21H
  99. ;v3.2    jae    store
  100.     jnb    store        ;v3.2
  101.      mov    dx,offset badfil ;'Could not open file for writing'
  102.      jmp    MsgErr        ;display error, terminate        v3.2
  103.  
  104. store:    mov    bx,ax        ;keep file handle in bx
  105.     push    DS        ;save DS
  106.     mov    cx,400H        ;1024 bytes to store
  107.     xor    ax,ax
  108.     mov    DS,ax        ;segment 0
  109.     ASSUME    DS:NOTHING
  110.  
  111.     mov    dx,ax        ;offset 0
  112.     mov    ah,40H        ;write the interrupt
  113.     int    21H        ;vector table block to file
  114.     pop    DS        ;get DS back
  115.     ASSUME    DS:CSEG        ;If Write Fails
  116.     jc    FwErr        ;Then Error Exit
  117.  
  118. egasav:    push    DS        ;Else save DS
  119.     mov    cx,0008H    ;8 bytes to store
  120.     mov    ax,0040H
  121.     mov    DS,ax        ;BIOS data segment
  122.     ASSUME    DS:NOTHING
  123.     mov    dx,00A8H    ;EGA save table pointer
  124.     mov    ah,40H        ;store the EGA data area
  125.     int    21H        ;write block to file
  126.     pop    DS        ;get DS back
  127.  
  128.     ASSUME    DS:CSEG        ;If Write Fails
  129.     jc    FwErr        ;Then Error Exit
  130. intcom:    push    DS        ;Else save DS
  131.     mov    cx,0010H    ;16 bytes to store
  132.     mov    ax,0040H
  133.     mov    DS,ax        ;BIOS data segment
  134.     ASSUME    DS:NOTHING    ;store the interapplications
  135.     mov    dx,00F0H    ;communication area
  136.     mov    ah,40H
  137.     int    21H        ;write block to file
  138.     pop    DS        ;get DS back
  139.     ASSUME    DS:CSEG        ;If Write Fails
  140.     jc    FwErr        ;Then Error Exit
  141.  
  142. parent:    mov    cx,2        ;Else store the parent's psp
  143.     mov    dx,offset parpsp
  144.     mov    ah,40H
  145.     int    21H        ;If write block to file fails
  146.     jc    FwErr        ;Then Error Exit
  147.                 ;Else determine whether EMS is present
  148. ems:    push    bx        ;temporarily store the file handle
  149.     xor    bx,bx        ;zero the EMS handle count in case
  150.     mov    dx,offset emsnm ;EMS not present
  151.     mov    ax,3D00H
  152.     int    21H
  153.     jb    sthand        ;EMS driver not installed
  154.  
  155.     mov    bx,ax        ;EMS handle into bx
  156.     mov    ah,3EH        ;close the
  157.     int    21H        ;open "handle"
  158.  
  159.     mov    ah,4DH        ;get the current EMS page map
  160.     mov    di,offset emsmap ;ES=CS already
  161.     xor    bx,bx        ;required by some versions of EMM
  162.     cld            ;required by some versions of EMM
  163.     int    67H
  164.     or    ah,ah
  165.     jz    sthand        ;result ok
  166.      xor    bx,bx        ;error, return zero EMS handles
  167. sthand:    mov    emscnt,bx    ;store count of active handles
  168.     shl    bx,1
  169.     shl    bx,1        ;4 bytes per handle
  170.     inc    bx
  171.     inc    bx        ;2 more bytes for the handle count
  172.     mov    cx,bx        ;number of bytes to write
  173.     pop    bx        ;get file handle back
  174.     mov    dx,offset emscnt ;what we're writing
  175.     mov    ah,40H
  176.     int    21H        ;write out the table
  177.     jae    closfl        ;ok,continue
  178.  
  179. FwErr:    mov    dx,offset nowrit    ;'Error while writing'
  180.     jmp    short MsgErr    ;display, terminate            v3.2
  181.  
  182. closfl:    mov    ah,3EH        ;close up the table file
  183.     int    21H        ;close handle
  184.     jnb    idstr        ;ok, continue                v3.2
  185.      mov    dx,offset badcls    ;'Error closing table files'
  186.      jmp    short MsgErr    ;display, terminate            v3.2
  187.  
  188. ;put a standard ID string into the PSP for RELEASE to check
  189. idstr:    mov    si,offset id
  190.     mov    di,60H        ;unused area of the PSP
  191.     mov    cx,IDLEN    ;characters in ID string
  192.     cld
  193.     rep    movsb        ;copy string
  194.  
  195. ;deallocate environment block of this mark
  196. deall:    mov    ax,envseg    ;environment segment
  197.     mov    ES,ax        ;  into es
  198.     mov    ah,49H        ;deallocate
  199.     int    21H        ;no reason for an error to occur
  200. gores:    mov    dx,offset didit ;print message and TSR
  201.     mov    ah,9        ;write success message
  202.     int    21H        ;including filename
  203.     mov    dx,offset crlf  ;and newline
  204.     mov    ah,9
  205.     int    21H
  206.     xor    dx,dx        ;get number of paragraphs to keep
  207.     mov    dl,cmdlen    ;length of command line
  208.     add    dx,0090H    ;rest of PSP plus paragraph margin
  209.     mov    cl,4
  210.     shr    dx,cl        ;convert to paragraphs
  211.     mov    ax,3100H
  212.     int    21H        ;terminate and stay resident
  213.  
  214. ;v3.2    Enter here if you have a message before 'syntax error'
  215. MsgErr:    mov    ah,9        ;v3.2
  216.     int    21H
  217. ;error output - show syntax line
  218. error:    mov    dx,offset syntax
  219.     mov    ah,9
  220.     int    21H
  221.     mov    ax,4C01H    ;exit with error
  222.     int    21H
  223. fmark    endp
  224.  
  225. emsnm    db  'EMMXXXX0',0    ;file name for testing EMS presence
  226. id    db  'FM3.2 TSR'        ;id string for UnMark/ReMark check
  227. IDLEN    equ $-id
  228. ;messages
  229. badfil    db    13,10,'Could not open file for writing$'
  230. nowrit    db    13,10,'Error while writing$'
  231. badcls    db    13,10,'Error closing table file$'
  232. syntax    db    13,10,'Syntax:  FMARK [d:][path]filename'
  233. crlf    db    13,10,'$'
  234. didit    db    13,10,'FMARK 3.2 - Marked current memory position in '
  235. ;data storage area
  236. filnm    db    44H dup ('?')    ;mark file name
  237. emscnt    dw    0    ;holds number of active pages in map that follows
  238. emsmap    db    0    ;holds EMS page map if installed
  239.         ;(note may extend 1K bytes past end of file in memory)
  240. CSEG    ends
  241.     end    ComEntry
  242.