home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / cexpress / files / seekfile.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.1 KB  |  47 lines

  1. ;unsigned short  seek_file(path);
  2. ;  char  *path;
  3.  
  4.     EXTRN  _memory_model:byte
  5.  
  6. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  7.     ASSUME CS:_TEXT
  8.     PUBLIC _seek_file
  9. _seek_file proc near
  10.     push bp            ;
  11.     mov  bp,sp        ;
  12.     push si            ;
  13.     cmp  _memory_model,0    ;near or far?
  14.     jle  begin        ;jump if near
  15.     inc  bp            ;else add 2 to BP
  16.     inc  bp            ;
  17. begin:    push ds            ;save Turbo's DS
  18.     cmp  _memory_model,2    ;data near or far?
  19.     jb   L0            ;jump if near
  20.     lds  si,dword ptr[bp+4] ;get string address
  21.     jmp  short L00        ;
  22. L0:    mov  si,[bp+4]        ;
  23. L00:    mov  dx,si        ;pt DX to string too
  24.     cmp  byte ptr[si],0    ;test for null string
  25.     je   L1            ;
  26.     mov  ah,3dh        ;function to open file
  27.     mov  al,0        ;subfunction to read file
  28.     int  21h        ;open the file
  29.     jc   L2            ;jump if error, return code in AX
  30.     mov  bx,ax        ;shift handle to BX
  31.     mov  ah,3eh        ;func to close file
  32.     int  21h        ;close the file
  33.     sub  ax,ax        ;return 0 if file found
  34.     jmp  short L2        ;
  35. L1:    mov  ax,2        ;null string return code
  36. L2:    pop  ds            ;
  37.     pop  si            ;
  38.     pop  bp            ;
  39.     cld            ;
  40.     cmp  _memory_model,0    ;quit
  41.     jle  quit        ;
  42.     db   0CBh        ;RET far
  43. quit:    ret            ;RET near
  44. _seek_file endp
  45. _TEXT    ENDS
  46.     END
  47.