home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n20.zip / UMBFILES.ZIP / UMBFILES.ASM < prev    next >
Assembly Source File  |  1991-08-23  |  9KB  |  299 lines

  1. ;****************************************************************************
  2. ; UMBFILES extends the System File Table (SFT) that DOS uses to track
  3. ; the state of open files by creating an extension of the SFT in upper
  4. ; memory.  The syntax is
  5. ;
  6. ;    UMBFILES[=]nn
  7. ;
  8. ; where "nn" is the number of entries to be created in the SFT extension.
  9. ; For best results, boot your system with the statement FILES=8 in CONFIG.-
  10. ; SYS, and then allocate room for additional FILES with UMBFILES.  For exam-
  11. ; ple, if you now boot with the statement FILES=40, change it to FILES=8 and
  12. ; add the statement UMBFILES=32 to your CONFIG.SYS file.  The sum total of
  13. ; FILES and UMBFILES cannot exceed 255.
  14. ;
  15. ; Note: UMBFILES can only be used on 386 and 486 PCs that are running DOS
  16. ; 5.0 and are configured for loading TSRs and drivers in upper memory.  To
  17. ; accomplish this, you must ensure that, at a minimum:
  18. ;
  19. ;    1) HIMEM.SYS is loaded
  20. ;    2) EMM386.EXE is loaded with a RAM or NOEMS parameter
  21. ;    3) CONFIG.SYS contains a DOS=UMB (or DOS=HIGH,UMB) statement
  22. ;    4) Your PC contains at least 384K of extended memory
  23. ;****************************************************************************
  24.  
  25. code        segment
  26.         assume    cs:code,ds:code
  27.         org    100h
  28. begin:        jmp    main
  29.  
  30. copyright    db    "UMBFILES 1.0 Copyright (c) 1991 Jeff Prosise",13,10
  31.         db    "First published in PC Magazine, November 26, 1991"
  32.         db    13,10,13,10
  33. msg        db    "System File Table extended",13,10,"$"
  34.  
  35. helpmsg        db    "Builds an extension to the System File Table in "
  36.         db    "upper memory.",13,10,13,10
  37.         db    "UMBFILES[=]nn",13,10,13,10
  38.         db    "  nn    Number of new SFT entries to create."
  39.         db    13,10,13,10
  40.         db    "UMBFILES requires DOS 5.0 and a 386 or 486 PC "
  41.         db    "configured for loading",13,10
  42.         db    "programs and drivers in upper memory.  The sum "
  43.         db    "of FILES and UMBFILES",13,10
  44.         db    "may not exceed 255.",13,10,"$"
  45.  
  46. errmsg1        db    "Requires DOS 5.x",13,10,"$"
  47. errmsg2        db    "Syntax: UMBFILES[=]nn",13,10,"$"
  48. errmsg3        db    "Invalid parameter or parameter out of range",13,10
  49. errmsg4        db    "FILES plus UMBFILES cannot exceed 255",13,10,"$"
  50. errmsg5        db    "Invalid parameter (cannot be 0)",13,10,"$"
  51. errmsg6        db    "Upper Memory Area not available",13,10,"$"
  52. errmsg7        db    "Insufficient memory",13,10,"$"
  53.  
  54. umbfiles    dw    0            ;Number of UMBFILES
  55. strategy    dw    ?            ;Memory allocation strategy
  56. linkstat    dw    0            ;Upper memory link status
  57. last_offset    dw    ?            ;Offset of final SFT header
  58. last_segment    dw    ?            ;Segment of final SFT header
  59. sftlen        dw    ?            ;Length of SFT extension
  60.  
  61. ;****************************************************************************
  62. ; Procedure MAIN
  63. ;****************************************************************************
  64.  
  65. main        proc    near
  66.         cld                ;Clear direction flag
  67.         mov    si,81h            ;Point SI to command line
  68.         call    scanhelp        ;Scan for "/?" switch
  69.         jnc    main1            ;Branch if not found
  70.  
  71.         mov    ah,09h            ;Display help text and exit
  72.         mov    dx,offset helpmsg    ;  with ERRORLEVEL=0
  73.         int    21h
  74.         mov    ax,4C00h
  75.         int    21h
  76. ;
  77. ; Check the DOS version and abort if it's not 5.x.
  78. ;
  79. main1:        mov    ah,30h            ;Get DOS version
  80.         int    21h
  81.         cmp    al,5            ;Branch if the major version
  82.         mov    dx,offset errmsg1    ;  number is 5, abort if
  83.         je    main2            ;  it's not
  84.  
  85. error:        mov    ah,9            ;Display error message
  86.         int    21h
  87.         mov    ax,4C01h        ;Exit with ERRORLEVEL=1
  88.         int    21h
  89. ;
  90. ; Parse the command line to determine how many SFT entries to create.
  91. ;
  92. main2:        call    findchar        ;Advance to next character
  93.         mov    dx,offset errmsg2    ;Error if EOL encountered
  94.         jc    error
  95.  
  96.         call    asc2bin            ;Convert ASCII to binary
  97.         mov    dx,offset errmsg3    ;Error if carry is set on
  98.         jc    error            ;  return
  99.         mov    dx,offset errmsg5    ;Error if number was 0
  100.         or    al,al
  101.         jz    error
  102.         mov    byte ptr umbfiles,al    ;Save UMBFILES number
  103. ;
  104. ; Walk the chain of SFT headers to determine how many FILES already exist.
  105. ;
  106.         xor    cx,cx            ;Zero SFT entry count
  107.         mov    ah,52h            ;Get address of DOS's List
  108.         int    21h            ;  of Lists
  109.         mov    di,es:[bx+4]        ;Place address of first SFT
  110.         mov    es,es:[bx+6]        ;  header in ES:DI
  111.  
  112. main3:        mov    last_offset,di        ;Save the address of this
  113.         mov    last_segment,es        ;  header
  114.         add    cx,es:[di+4]        ;Add number of SFT entries
  115.                         ;  in this block
  116.         mov    bx,es:[di]        ;Place address of next SFT
  117.         mov    es,es:[di+2]        ;  header in ES:DI and loop
  118.         mov    di,bx            ;  if the offset address
  119.         cmp    di,0FFFFh        ;  isn't equal to FFFFh
  120.         jne    main3
  121.  
  122.         add    cx,umbfiles        ;Verify that FILES plus
  123.         mov    dx,offset errmsg4    ;  UMBFILES is less than
  124.         cmp    cx,255            ;  255 and abort if it's
  125.         ja    error            ;  not
  126. ;
  127. ; Allocate an upper memory block to hold the SFT extension.
  128. ;
  129.         mov    ax,5802h        ;Get the current UMB link
  130.         int    21h            ;  status and save it
  131.         mov    byte ptr linkstat,al
  132.  
  133.         mov    ax,5803h        ;Set UMB link
  134.         mov    bx,1
  135.         int    21h
  136.         mov    dx,offset errmsg6    ;Error if carry returns set
  137.         jc    error
  138.  
  139.         mov    ax,5800h        ;Get the current memory
  140.         int    21h            ;  allocation strategy
  141.         mov    strategy,ax        ;  code and save it
  142.  
  143.         mov    ax,5801h        ;Change to high-only, best-
  144.         mov    bx,41h            ;  fit allocation strategy
  145.         int    21h
  146.         mov    dx,offset errmsg6    ;Error if carry returns set
  147.         jnc    main4
  148.  
  149. error1:        jmp    error
  150.  
  151. main4:        mov    al,59            ;Compute the number of
  152.         mul    byte ptr umbfiles    ;  paragraphs of memory
  153.         mov    sftlen,ax        ;  required for the SFT
  154.         add    ax,21            ;  extension
  155.         mov    cl,4
  156.         shr    ax,cl
  157.         mov    bx,ax
  158.         mov    ah,48h            ;Request the memory through
  159.         int    21h            ;  DOS function 48h
  160.         mov    dx,offset errmsg7    ;Error if allocation request
  161.         jc    error1            ;  is denied
  162.  
  163.         dec    ax            ;Point ES to MCB preceding
  164.         mov    es,ax            ;  the memory block
  165.         mov    word ptr es:[01h],08h    ;Change owner ID to 08h
  166.         inc    ax            ;Point ES back to the block
  167.         mov    es,ax            ;  itself
  168.  
  169.         mov    ax,5801h        ;Restore original memory
  170.         mov    bx,strategy        ;  allocation strategy
  171.         int    21h
  172.  
  173.         mov    ax,5803h        ;Restore original UMB
  174.         mov    bx,linkstat        ;  link status
  175.         xor    bh,bh
  176.         int    21h
  177. ;
  178. ; Initialize the new SFT block and link it into the chain.
  179. ;
  180.         mov    word ptr es:[00h],0FFFFh    ;Initialize the
  181.         mov    word ptr es:[02h],0000h        ;  SFT header
  182.         mov    ax,umbfiles
  183.         mov    word ptr es:[04h],ax
  184.  
  185.         mov    cx,sftlen        ;Load CX with SFT length
  186.         xor    al,al            ;Fill the new SFT with
  187.         mov    di,06h            ;  zeroes from start to
  188.         rep    stosb            ;  finish
  189.  
  190.         mov    ax,es            ;Place the address of the
  191.         mov    di,last_offset        ;  new SFT header in the
  192.         mov    es,last_segment        ;  header of the last
  193.         mov    word ptr es:[di],00h    ;  one
  194.         mov    word ptr es:[di+2],ax
  195. ;
  196. ; Display message verifying that the operation is completed, and then exit.
  197. ;
  198.         mov    ah,09h            ;Display message
  199.         mov    dx,offset copyright
  200.         int    21h
  201.         mov    ax,4C00h        ;Exit with ERRORLEVEL=0
  202.         int    21h
  203. main        endp
  204.  
  205. ;****************************************************************************
  206. ; SCANHELP scans the command line for a /? switch.  If found, carry returns
  207. ; set and SI contains its offset.  If not found, carry returns clear.
  208. ;****************************************************************************
  209.  
  210. scanhelp    proc    near
  211.         push    si            ;Save SI
  212. scanloop:    lodsb                ;Get a character
  213.         cmp    al,0Dh            ;Exit if end of line
  214.         je    scan_exit
  215.         cmp    al,"?"            ;Loop if not "?"
  216.         jne    scanloop
  217.         cmp    byte ptr [si-2],"/"    ;Loop if not "/"
  218.         jne    scanloop
  219.  
  220.         add    sp,2            ;Clear the stack
  221.         sub    si,2            ;Adjust SI
  222.         stc                ;Set carry and exit
  223.         ret
  224.  
  225. scan_exit:    pop    si            ;Restore SI
  226.         clc                ;Clear carry and exit
  227.         ret
  228. scanhelp    endp
  229.  
  230. ;****************************************************************************
  231. ; FINDCHAR advances SI to the next non-white space character.  On return,
  232. ; carry set indicates EOL was encountered; carry clear indicates it was not.
  233. ;****************************************************************************
  234.  
  235. findchar    proc    near
  236.         lodsb                ;Get the next character
  237.         cmp    al,09h            ;Loop if tab
  238.         je    findchar
  239.         cmp    al,20h            ;Loop if space
  240.         je    findchar
  241.         cmp    al,2Ch            ;Loop if comma
  242.         je    findchar
  243.         cmp    al,3Dh            ;Loop if equal sign
  244.         je    findchar
  245.         dec    si            ;Point SI to the character
  246.         cmp    al,0Dh            ;Exit with carry set if end
  247.         je    eol            ;  of line is reached
  248.  
  249.         clc                ;Clear carry and exit
  250.         ret
  251.  
  252. eol:        stc                ;Set carry and exit
  253.         ret
  254. findchar    endp
  255.  
  256. ;****************************************************************************
  257. ; ASC2BIN converts a decimal number entered in ASCII form into a binary
  258. ; value in AL.  Carry set on return indicates that an error occurred in
  259. ; the conversion.
  260. ;****************************************************************************
  261.  
  262. asc2bin        proc    near
  263.         sub    ax,ax            ;Initialize registers
  264.         sub    bh,bh
  265.         mov    dl,10
  266.  
  267. a2b_loop:    mov    bl,[si]            ;Get a character
  268.         inc    si
  269.         cmp    bl,20h            ;Exit if space
  270.         je    a2b_exit
  271.         cmp    bl,2Ch            ;Exit if comma
  272.         je    a2b_exit
  273.         cmp    bl,0Dh            ;Exit if carriage return
  274.         je    a2b_exit
  275.  
  276.         cmp    bl,"0"            ;Error if character is not
  277.         jb    a2b_error        ;  a number
  278.         cmp    bl,"9"
  279.         ja    a2b_error
  280.  
  281.         mul    dl            ;Multiply the value in AL by
  282.         jc    a2b_error        ;  10 and exit on overflow
  283.         sub    bl,30h            ;ASCII => binary
  284.         add    ax,bx            ;Add latest value to AX
  285.         cmp    ax,255            ;Error if sum > 255
  286.         jna    a2b_loop        ;Loop back for more
  287.  
  288. a2b_error:    dec    si            ;Set carry and exit
  289.         stc
  290.         ret
  291.  
  292. a2b_exit:    dec    si            ;Clear carry and exit
  293.         clc
  294.         ret
  295. asc2bin        endp
  296.  
  297. code        ends
  298.         end    begin
  299.