home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm32 / disk.doc < prev    next >
Text File  |  1994-01-15  |  23KB  |  862 lines

  1.  
  2. ***************************** DISK & FILE *******************************
  3.  
  4. ASM32 disk & file subroutines Copyright (C) 1993 Douglas Herr
  5. All rights reserved
  6.  
  7. The DOS file attribute byte tells you whether a file is read-only,
  8. system, a subdirectory, or may provide other information.  File attribute
  9. bits may be combined.  Each bit of the file attribute means:
  10.  
  11.         0 = normal files
  12.         1 = read-only
  13.         2 = hidden files
  14.         4 = system files
  15.         8 = volume label (only one per disk)
  16.        16 = subdirectories
  17.        32 = archive bit set
  18.  
  19.    Thus a file with an attribute of 18 is a hidden subdirectory (16 OR 2)
  20.  
  21.  
  22.  
  23.                       ASM32 buffered file I/O system
  24.  
  25.     Several ASM32 subroutines are available for buffered file Input or
  26.     Output.  Files to be managed by the buffered I/O system must be opened
  27.     by FOPEN or FCREATE, and must be closed by FCLOSE.  Buffered file I/O
  28.     will be much faster than unbuffered.  ASM32's default buffer size is
  29.     4096 bytes; this can be changed by altering FBUFFER_SIZE in FOPEN.ASM
  30.     and re-assembling.  Up to 20 files can be managed by FOPEN; this can
  31.     be changed by altering NUMBER_OF_FILES in $handle.asm and reassembling.
  32.  
  33.     Subroutines: FOPEN        open file & initialize buffer
  34.                  FCREATE      create file & initialize buffer
  35.                  FCLOSE       flush & close output buffer; close file
  36.                  FSEEK        move file pointer & update buffer
  37.                  FGETSTR      read a string from buffer
  38.                  FGETCHR      read a character from buffer
  39.                  FGET         read specified number of bytes from buffer
  40.                  FPUTSTR      write string to buffer
  41.                  FPUTCRLF     write CR+LF to buffer
  42.                  FPUTCHR      write character to buffer
  43.                  FPUT         write specified number of bytes to buffer
  44.  
  45.  
  46. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  47.  
  48. DISKSIZE:    determines total and free disk space
  49. Source:      disksize.asm
  50.  
  51. Call with:   DL = drive number (drive A: = 0, default drive = -1)
  52. Returns:     if CF = 0, EAX = total disk space
  53.                         EDX = free disk space
  54.              if CF = 1, AX = DOS error code
  55.               DiskSize does not trap "drive not ready" errors
  56. Uses:        EAX, EDX, flags
  57. Supports:    all DOS drives
  58. Example:
  59.  
  60. public  example_code
  61. extrn    disksize:near
  62.  
  63. include codeseg.inc
  64.  
  65. ; code
  66. example_code    proc near
  67.         mov    dl,0
  68.         call    disksize
  69.         jc      disk_error
  70.  
  71.  
  72. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  73.  
  74. diskwp:      determines if a floppy disk is write-protected
  75. Source:      diskwp.asm
  76.  
  77. Call with:   DL = floppy disk number (drive A: = 0)
  78. Returns:     AL = BIOS error code
  79.                 0 = no error
  80.                 1 = invalid disk number
  81.                 3 = disk is write-protected or wrong media
  82.               128 = drive not ready
  83. Uses:        EAX, flags
  84. Supports:    physical drives A: and B:
  85. Example:
  86.  
  87. public  check_disk
  88. extrn   diskwp:near
  89.  
  90. include codeseg.inc
  91.  
  92. ; code
  93. check_disk      proc near
  94.         .
  95.         .
  96.         .
  97.         mov     dl,1              ; drive B:
  98.         call    diskwp            ; can I write to this disk?
  99.         jnc     short no_problem
  100.  
  101.  
  102. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  103.  
  104. DOTBAK:      changes the file extension of an existing file to .BAK
  105. Source:      dotbak.asm (strrchr.asm)
  106.  
  107. Call with:   ESI = address of a valid ASCIIZ filename in low memory
  108.              dotbak deletes a previous .BAK file of this name and
  109.              renames the input filename.ext to filename.bak.
  110. Returns:     if CF = 0, no error
  111.              if CF = 1, AL = DOS error code.  If AL = 5, the previous
  112.              .BAK filename is probably read-only.  All other errors refer
  113.              to the name change operation.
  114. Uses:        AX, flags
  115. Example:
  116.  
  117. extrn   dotbak:near
  118.  
  119. include dataseg.inc
  120.  
  121. ; data
  122.  
  123. disk_doc  db 'DISK.DOC',0
  124.  
  125. @curseg    ends
  126.  
  127. include codeseg.inc
  128.  
  129. ; code
  130.              .
  131.              .
  132.              .
  133.              mov   esi,offset disk_doc
  134.              call  dotbak
  135.  
  136.  
  137. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  138.  
  139. FCLOSE:      close a file managed by ASM32's buffered file I/O system
  140. Source:      fopen.asm ($handle.asm)
  141.  
  142. Call with:   BX = file handle
  143.              The file must have been opened by FOPEN or FCREATE;  If the
  144.              file is not read-only, the output buffer will be written to
  145.              the disk file before closing the file.
  146. Returns:     if CF = 0, no error
  147.              if CF = 1, AX = error code
  148. Uses:        AX, flags
  149. Example:     see FOPEN
  150.  
  151.  
  152.  
  153.  
  154. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  155.  
  156. FCOPY:       copy a file
  157. Source:      fcopy.asm
  158.  
  159. Call with:   ESI = address of source filename
  160.              EDI = address of destination filename
  161.              Both filenames must be ASCIIZ strings.  Drive and path need
  162.              not be fully specified; filenames may not include * or ?
  163.              wildcards.
  164. Returns:     if CF = 0, no problem
  165.              if CF = 1, AX = DOS error code
  166. Uses:        EAX, CF
  167. Example:
  168.  
  169. extrn   fcopy:near
  170.  
  171. include dataseg.inc
  172.  
  173. ; data
  174.         db 'b:'
  175. source  db 'asm32cw.lib',0         ; copy the library to b:
  176.  
  177. @curseg    ends
  178.  
  179. include codeseg.inc
  180.  
  181. ; code
  182.         .
  183.         .
  184.         lea     esi,source
  185.         mov     edi,esi               ; EDI also points to source
  186.         sub     edi,2                 ; back the pointer to the 'B:'
  187.         call    fcopy
  188.         jc      oops
  189.  
  190.  
  191.  
  192. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  193.  
  194. FCOUNT:      counts the number of files matching an ASCIIZ filespec string.
  195.              The filespec string may include the '*' and '?' wildcards.
  196. Source:      fcount.asm
  197.  
  198. Call with:   EDX pointing to filespec string
  199.              CX = file attributes
  200. Returns:     EAX = number of files matching the filespec string
  201. Uses:        EAX
  202. Example:
  203.  
  204. extrn   fcount:near
  205.  
  206. include dataseg.inc
  207.  
  208. ; data
  209. filespec  db '*.asm',0
  210.  
  211. @curseg    ends
  212.  
  213. include codeseg.inc
  214.  
  215. ; code
  216.         .
  217.         .
  218.         .
  219.         lea    edx,filespec     ; address of filespec string
  220.         xor    cx,cx            ; normal files only
  221.         call   fcount
  222.  
  223.  
  224. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  225.  
  226. FCREATE:     create new file and initialize output buffer
  227. Source:      fcreate.asm ($handle.asm)
  228.  
  229. Call with:   EDX pointing to ASCIIZ filename
  230.              The file is created with write-only access.  If a file with
  231.              the same name already exists, it is truncated to zero
  232.              length by FCREATE.
  233. Returns:     if CF = 0, AX = file handle
  234.              if CF = 1, AX = error code
  235. Uses:        AX, flags
  236. Example:
  237.  
  238. public   myprog
  239. extrn    fcreate:near
  240.  
  241. include  dataseg.inc
  242.  
  243. ; data
  244. file_name   db 'ANYNEW.FIL',0
  245. file_handle dw 0
  246.  
  247. @curseg    ends
  248.  
  249. include codeseg.inc
  250.  
  251. ; code
  252. myprog   proc  near
  253.          .
  254.          .
  255.          .
  256.          lea   edx,file_name
  257.          call  fcreate
  258.          jc    something_went_wrong      ; go to error control code
  259.          mov   file_handle,ax            ; save the handle
  260.          .
  261.          .
  262.          .
  263.  
  264.  
  265. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  266.  
  267. FEXIST:      determines if a file exists and can be opened with read access
  268. Source:      fexist.asm
  269.  
  270. Call with:   EDX pointing to ASCIIZ filename in low memory
  271. Returns:     if CF = 0, file exists
  272.              if CF = 1, AX = DOS error code
  273. Uses:        AX, CF; all other flags and registers are saved
  274. Example:
  275.  
  276. extrn    fexist:near
  277.  
  278. include  dataseg.inc
  279.  
  280. ; data
  281. filename db 'asm32.doc',0
  282.  
  283. @curseg    ends
  284.  
  285. include  codeseg.inc
  286.  
  287. ; code
  288.          .
  289.          .
  290.          .
  291.          lea   edx,filename
  292.          call  fexist
  293.          jnc   got_the_file      ; if CF = 0, go on
  294.          jmp   doserror          ; else go to error handling code
  295.  
  296.  
  297.  
  298. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  299.  
  300. FFLUSH:      flushes the ASM32 and DOS output buffers for specified handle
  301. Source:      fflush.asm (fseek.asm)
  302.  
  303. Call with:   BX = file handle
  304.              flushing the buffers guards against data loss in case of system
  305.              failure, such as power loss
  306. Returns:     if CF = 0, no error; function successful
  307.              if CF = 1, AX = DOS error code
  308. Uses:        AX, flags
  309. Example:
  310.  
  311. include codeseg.inc
  312.  
  313. extrn   fflush:near
  314.  
  315. ; code
  316. ; program opens file & writes to file
  317.       .
  318.       .
  319.       .
  320. ; flush the buffers to disk
  321.       mov    bx,handle
  322.       call   fflush
  323.  
  324.  
  325.  
  326. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  327.  
  328. FGET:        read specified number of bytes from file buffer
  329. Source:      fget.asm ($handle.asm, $fget.asm)
  330.  
  331. Call with:   BX = file handle
  332.              ECX = number of bytes requested (up to 4096 bytes)
  333. Returns:     if CF = 0, EAX = number of bytes read
  334.                         EBX points to data in buffer
  335.              if CF = 1, AX = DOS error code
  336. Uses:        EAX, EBX, flags
  337. Example:
  338.  
  339. extrn   fopen:near, fget:near
  340.  
  341. include dataseg.inc
  342.  
  343. ; data
  344. file_name   db 'asm32.doc',0
  345. file_handle dw 0
  346.  
  347. @curseg    ends
  348.  
  349. include codeseg.inc
  350.  
  351. ; code
  352.           .
  353.           .
  354.           .
  355.           lea   edx,file_name
  356.           call  fopen
  357.           jc    fopen_problem
  358.           mov   file_handle,ax  ; save for later
  359.  
  360.           mov   bx,ax           ; file handle
  361.           mov   ecx,8           ; I want 8 bytes
  362.           call  fget            ;  returned at [EBX]
  363.           jc    read_problem    ; uh oh, trouble ...
  364.           cmp   eax,ecx         ; did I get what I wanted?
  365.           jne   not_enough
  366.           .
  367.           .
  368.  
  369.  
  370.  
  371.  
  372. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  373.  
  374. FGETCHR:     read a character from a file buffer
  375. Source:      fgetchr.asm ($handle.asm)
  376.  
  377. Call with:   BX = file handle
  378. Returns:     if CF = 0, AL = next character from file buffer
  379.              if CF = 1, AX = DOS error code
  380.                         AX = 0 if at end of file
  381. Uses:        AX, flags
  382. Example:
  383.  
  384. extrn   fopen:near, fgetchr:near
  385.  
  386. include dataseg.inc
  387.  
  388. ; data
  389. file_name   db 'asm32.doc',0
  390. file_handle dw 0
  391.  
  392. @curseg    ends
  393.  
  394. include codeseg.inc
  395.  
  396. ; code
  397.           .
  398.           .
  399.           .
  400.           lea   edx,file_name
  401.           call  fopen
  402.           jc    fopen_problem
  403.           mov   file_handle,ax  ; save for later
  404.  
  405.           mov   bx,ax           ; file handle
  406.           call  fgetchr         ; character in AL
  407.           jc    read_problem
  408.  
  409.           .
  410.           .
  411.  
  412.  
  413.  
  414. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  415.  
  416. FGETSTR:     read an ASCII string from a file buffer
  417. Source:      fgetstr.asm ($handle.asm, $fget.asm)
  418.  
  419. Call with:   BX = file handle
  420.              ASCII strings may be terminated with either 0Dh or 0Dh+0Ah.
  421.              After reading each string, FGetStr positions the buffer pointer
  422.              to read the next string.  String length should be less than
  423.              the buffer size.  See FOPEN.
  424.              NOTE THAT THE STRING IN THE BUFFER IS NOT ZERO-TERMINATED.
  425. Returns:     if CF = 0, EBX points to string in buffer
  426.                         ECX = length of ASCII string
  427.                      if ECX = byte length of buffer, string >= size of buffer
  428.              if CF = 1, AX = DOS error code
  429.                         AX = 0 if end of file
  430. Uses:        EBX, EAX, ECX, flags
  431. Example:
  432.  
  433. extrn   fopen:near, fgetstr:near
  434.  
  435. include dataseg.inc
  436.  
  437. ; data
  438. file_name   db 'asm32.doc',0
  439. file_handle dw 0
  440.  
  441. @curseg    ends
  442.  
  443. include codeseg.inc
  444.  
  445. ; code
  446.         .
  447.         .
  448.         .
  449.         lea   edx,file_name
  450.         call  fopen
  451.         mov   al,0            ; read-only access
  452.         jc    fopen_problem
  453.         mov   file_handle,ax  ; save for later
  454.  
  455.         mov   bx,ax           ; file handle
  456.         call  fgetstr
  457.         jc    read_problem
  458.  
  459.         call  strndup         ; make a copy for later
  460.         .
  461.         .
  462.         .
  463.  
  464.  
  465.  
  466. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  467.  
  468. filelist:    creates a list of file names matching a filespec mask
  469. Source:      filelist.asm (fcount.asm)
  470.  
  471. Call with:   ESI pointing to filespec mask
  472.              CX = file attribute mask
  473. Returns:     if CF = 0:
  474.                EDI = address of list buffer in low memory
  475.                EAX = number of filenames in list
  476.                ECX = list field width
  477.              if CF = 1, AX = DOS error code
  478.              You should use ASM32's HFREE to release the file list
  479.              buffer when you're done with it.
  480. Uses:        EAX, ECX, EDI, flags
  481. Example:
  482.  
  483. public  myproc
  484. extrn   filelist:near
  485.  
  486. include dataseg.inc
  487.  
  488. ; data
  489. filespec db '*.*',0
  490.  
  491. @curseg    ends
  492.  
  493. include codeseg.inc
  494.  
  495. ; code
  496.         .
  497.         .
  498.         .
  499.         lea    esi,filespec
  500.         mov    cx,16            ; normal files and subdirectories
  501.         call   filelist
  502.         jc     cant_do_it       ; oops
  503.  
  504.  
  505.  
  506. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  507.  
  508. FOPEN:       opens existing file and initializes ASM32 buffered I/O
  509. Source:      fopen.asm ($handle.asm)
  510.  
  511. Call with:   EDX pointing to name of file to be opened
  512.              AL = access mode
  513.               0 = read-only access
  514.               1 = write-only access
  515.               2 = read-write access NOT SUPPORTED YET
  516. Returns:     if CF = 0, AX = file handle
  517.              if CF = 1, AX = ASM32 or DOS error code; file not opened
  518.                 if AX = 0, insufficient memory available
  519.                 if AX = 0FFFFh, no handles available in ASM32 I/O array;
  520.                    change NUMBER_OF_HANDLES in $handle.asm and re-assemble
  521.                    (default = 20 handles)
  522. Uses:        AX, flags
  523. Example:
  524.  
  525. public   myprog
  526. extrn    fopen:near, fclose:near
  527.  
  528. include  dataseg.inc
  529.  
  530. ; data
  531. file_name   db 'ASM32.DOC',0
  532. file_handle dw 0
  533.  
  534. @curseg    ends
  535.  
  536. include  codeseg.inc
  537.  
  538. ; code
  539. myprog   proc  near
  540.          .
  541.          .
  542.          .
  543.          lea   edx,file_name
  544.          xor   al,al          ; read-only access
  545.          call  fopen
  546.          jc    something_went_wrong
  547.          mov   file_handle,ax ; save the handle
  548.          .
  549.          .
  550.          .
  551.  
  552. ; all done with this file
  553.          mov   bx,file_handle
  554.          call  fclose
  555.  
  556.  
  557.  
  558. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  559.  
  560. FPUT:        write specified number of bytes to output file buffer
  561. Source:      fput.asm ($handle.asm)
  562.  
  563. Call with:   BX = file handle
  564.              EDI pointing to data to write
  565.              ECX = number of bytes to write
  566. Returns:     if CF = 0, no error
  567.              if CF = 1, AX = error code
  568. Uses:        EAX, flags
  569. Example:
  570.  
  571. public  myproc
  572. extrn   fput:near
  573. extrn   fputchr:near
  574. extrn   fputcrlf:near
  575.  
  576. include dataseg.inc
  577.  
  578. ; data
  579. data1    db 'several bytes may be written at once'
  580. data_len equ $-data1
  581.  
  582. @curseg    ends
  583.  
  584. include codeseg.inc
  585.  
  586. ; code
  587.          .
  588.          .
  589.          .
  590.          mov   bx,output_handle
  591.          lea   edi,data1              ; EDI -> data1
  592.          mov   ecx,data_len           ; bytes to write
  593.          call  fput
  594.          call  fputcrlf               ; write CR+LF for new line
  595.                                       ; in ASCII text file
  596.          mov   al,26                  ; End-of-File byte (optional)
  597.          call  fputchr
  598.  
  599.  
  600. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  601.  
  602. FPUTCHR:     write one character to output file buffer
  603. Source:      fputchr.asm (fput.asm)
  604.  
  605. Call with:   BX = output file handle
  606.              AL = character to write
  607. Returns:     if CF = 1, AX = DOS error code
  608.              if CF = 0, no error
  609. Uses:        AX, flags
  610. Example:     see FPUT
  611.  
  612. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  613.  
  614. FPUTCRLF:    write CR+LF pair to output file buffer
  615. Source:      fputcrlf.asm (fput.asm)
  616.  
  617. Call with:   BX = output file handle; file must have been opened by
  618.              FOPEN or FCREATE
  619. Returns:     if CF = 0, no error
  620.              if CF = 1, AX = DOS error code
  621. Uses:        AX, flags
  622. Example:     see FPUT
  623.  
  624.  
  625.  
  626. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  627.  
  628. FPUTSTR:     write an ASCIIZ string to output buffer
  629. Source:      fputstr.asm (strlen.asm, fput.asm)
  630.  
  631. Call with:   BX = file handle
  632.              EDI pointing to ASCIIZ string
  633. Returns:     if CF = 0, EAX = bytes written
  634.              if CF = 1, AX = DOS error code
  635. Uses:        EAX, flags
  636. Example:
  637.  
  638. public  myproc
  639. extrn   fputstr:near
  640. extrn   fputcrlf:near
  641.  
  642. include dataseg.inc
  643.  
  644. ; data
  645. strptr   dd 0                         ; pointer to string, assigned by program
  646.  
  647. @curseg    ends
  648.  
  649. include codeseg.inc
  650.  
  651. ; code
  652.          .
  653.          .
  654.          .
  655.          mov   bx,output_handle
  656.          mov   edi,strptr             ; EDI -> string
  657.          call  fputstr
  658.          call  fputcrlf               ; write CR+LF for new line
  659.                                       ; in ASCII text file
  660.  
  661.  
  662.  
  663. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  664.  
  665. FSEEK:       move file pointer for a file opened by FOPEN
  666. Source:      fseek.asm ($handle.asm)
  667.  
  668. Call with:   BX = file handle
  669.              AL = method code: 0 = absolute offset from start of file
  670.                                1 = signed offset from current file pointer
  671.                                2 = signed offset from end of file
  672.              EDX = dword offset
  673. Returns:     if CF = 1, AX = DOS error code
  674.              if CF = 0, EAX = new location of file pointer
  675. Uses:        EAX, flags
  676.  
  677. Example:
  678.  
  679. public  whoknows
  680. extrn fopen:near, fseek:near
  681.  
  682. include dataseg.inc
  683.  
  684. ; data
  685. file0   db 'file0.dat',0
  686.  
  687. @curseg    ends
  688.  
  689. include codeseg.inc
  690.  
  691. ; code
  692. whoknows  proc near
  693.         .
  694.         .
  695.         .
  696.         mov     edx,offset file0
  697.         mov     al,1              ; write only
  698.         call    fopen
  699.         jc      error
  700.         xor     edx,edx           ; zero offset
  701.         mov     al,2              ; relative to end of file
  702.         call    fseek             ; move pointer to end of file
  703.  
  704.  
  705.  
  706.  
  707.  
  708. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  709.  
  710. FSIZE:       determines a file's size
  711. Source:      fsize.asm
  712.  
  713. Call with:   BX = valid file handle
  714. Returns:     if CF = 0, EAX = file size
  715.              if CF = 1, AX = DOS error code
  716. Uses:        EAX, CF
  717. Example:
  718.  
  719.  
  720. extrn   fsize:near
  721.  
  722. include dataseg.inc
  723.  
  724. ; data
  725.  
  726. filenam db 'ASM32.DOC',0      ; ASCIIZ filename
  727.  
  728. @curseg    ends
  729.  
  730. include codeseg.inc
  731.  
  732. ; code
  733.         .
  734.         .
  735.         .
  736.         lea     edx,filenam    ; point to filename in low memory
  737.         mov     al,0           ;  read-only access (not required by FSIZE)
  738.         call    fopen          ;  open the file
  739.         jc      oops           ; jump to error control
  740.                                ;  else no problem - continue
  741.         mov     bx,ax          ; file handle in BX
  742.         call    fsize          ; returns file size in EAX
  743.  
  744.  
  745. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  746.  
  747. MLOAD:       read a file into far memory, allocating new selector
  748. Source:      mload.asm (fsize.asm)
  749.  
  750. Call with:   [EDX] pointing to ASCIIZ filename
  751. Returns:     if CF = 0, BX = selector of memory block
  752.                         EAX = bytes loaded from disk
  753.              if CF = 1, AX = DOS error code
  754. Uses:        EAX, BX, CF
  755. Example:
  756.  
  757. include model.inc
  758.  
  759. public  test_mload
  760.  
  761. extrn   mload:near
  762.  
  763. include dataseg.inc
  764. filesel         dw 0
  765. fname           db 'filename.txt',0
  766. file_size       dd 0
  767.  
  768. include codeseg.inc
  769.  
  770. test_mload      proc near
  771.         .
  772.         .
  773.  
  774.         lea     edx,fname
  775.         call    mload           ; read file into DOS memory
  776.         jc      short no_good   ;  jump if there was a problem
  777.  
  778.         mov     filesel,bx      ; save new selector of memory block
  779.         mov     file_size,eax   ; save file size
  780.  
  781. no_good:                        ; return with CF = 1 if error
  782.         ret                     ; CF = 0 if no error
  783. test_mload      endp
  784.         end
  785.  
  786.  
  787.  
  788. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  789.  
  790. MSAVE:       write memory block to file
  791. Source:      msave.asm
  792.  
  793. Call with:   [EDX] pointing to ASCIIZ filename
  794.              ES:[EBX] -> first byte to write
  795.              EAX = number of bytes to write
  796. Returns:     if CF = 0, no error
  797.              if CF = 1, AX = DOS error code
  798. Uses:        EAX, flags
  799. Example:
  800.  
  801. include model.inc
  802.  
  803. public  test_msave
  804.  
  805. extrn   msave:near
  806.  
  807. include dataseg.inc
  808. filesel         dw 0
  809. fname           db 'filename.txt',0
  810. file_size       dd 0
  811.  
  812. include codeseg.inc
  813.  
  814. test_msave      proc near
  815.         .
  816.         .
  817.  
  818.         lea     edx,fname
  819.         mov     eax,file_size
  820.         mov     es,filesel      ; selector of memory block
  821.         xor     ebx,ebx         ; start at beginning of memory block
  822.         call    mload           ; read file into DOS memory
  823.                                 ; return with CF = 1 if error
  824.         ret                     ; CF = 0 if no error
  825. test_msave      endp
  826.         end
  827.  
  828.  
  829.  
  830. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  831.  
  832. QFNAME:      qualifies a filename
  833. Source:      qfname.asm
  834.  
  835. Call with:   EBX pointing to a filename; the filename may contain
  836.              drive specification and/or complete or partial path name.
  837.              Drive specification and path name not required.
  838. Returns:     ESI pointing to the full DRIVESPEC:\PATH\FILENAME
  839.              ECX = length of full filename
  840.              Note that ESI points to QFName's buffer space; the next
  841.              call to QFName will return a new filename at the same address.
  842. Uses:        ESI, ECX, flags
  843. Example:
  844.  
  845. include dataseg.inc
  846.  
  847. ; data
  848. docs    db '*.doc',0         ; search for .DOC files in current directory
  849.  
  850. @curseg    ends
  851.  
  852. include codeseg.inc
  853.  
  854. ; code
  855.         .
  856.         .
  857.         .
  858.         lea    ebx,docs
  859.         call   qfname        ; returns 'drive:\path\*.doc'
  860.  
  861.  
  862.