home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / PAL / FILEIO / OPEN.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-20  |  2.0 KB  |  93 lines

  1. ;******************************************************************************
  2. ; Filename: OPEN.ASM
  3. ;   Author: Peter Andersson
  4. ;  Version: 0.0
  5. ;  Created: 1994.06.05
  6. ;  Updated: 1995.04.08
  7. ;******************************************************************************
  8. ; Copyright Peter Andersson, 1994-1995.
  9. ; All rights reserved.
  10. ;******************************************************************************
  11. ; Function: LONG @open(PSZ filename,LONG filemode)
  12. ;  Comment: Opens a file
  13. ;    Input: Eax, filename - pointer to filename
  14. ;           Edx, filemode - O_APPEND, O_CREAT, O_TRUNC, O_EXCL
  15. ;                bits 0 & 1 control file access;
  16. ;                0 = read only
  17. ;                1 = write only
  18. ;                2 = read and write
  19. ;  Returns: file handle or -1 if an error occured
  20. ;******************************************************************************
  21.  
  22.     Include    STDDEF.INC
  23.  
  24.     Codeseg
  25.  
  26. Proc    open ,2
  27.         Test    Dl,O_TRUNC
  28.         Push    Ebx,Eax,Edx
  29.         Jz    @@Next01
  30.         Mov    Eax,Edx
  31.         And    [Byte Esp],Not O_EXCL
  32.         Mov    Edx,[Esp+4]                     ;<- forgot this
  33. @@Next03:    Mov    Ah,3Ch
  34.         Clear    Ecx
  35.         Int    21h
  36.         Jc    @@Error
  37.         Mov    Ebx,Eax
  38.         Mov    Ah,3Eh
  39.         Int    21h
  40.         Jc    @@Error
  41. @@Next01:    Mov    Edx,[Esp+4]
  42.         Mov    Al,[Esp]
  43.                 And     Al,3
  44.         Mov    Ah,3Dh
  45.         Int    21h
  46.         Jnc    @@Next02
  47.         Cmp    Ax,2
  48.         Jne    @@Error
  49.         Test    [Byte Esp],O_CREAT
  50.         Jz    @@Error
  51.         And    [Byte Esp],Not O_EXCL
  52.         Mov    Edx,[Esp+4]
  53.         Jmp    @@Next03
  54.     Align    4
  55. @@Next02:    Test    [Byte Esp],O_CREAT
  56.         Jz    @@Next04
  57.         Test    [Byte Esp],O_EXCL
  58.         Jne    @@ExitErr
  59. @@Next04:    Test    [Byte Esp],O_APPEND
  60.         Jz    @@Next05
  61.         Mov    Ebx,Eax
  62.         Clear    Edx
  63.         Mov    Eax,4202h
  64.         Int    21h
  65.         Mov    Eax,Ebx
  66. @@Next05:    Pop    +8,Ebx
  67.         Ret
  68.     Align    4
  69. @@ExitErr:    Mov    Ebx,Eax
  70.         Mov    Ah,3Eh
  71.         Int    21h
  72.         Mov    Eax,5
  73. @@Error:    Mov    [Word errno],Ax
  74.     IfDef    DEBUG
  75.         Pop    Edx,+,Ebx
  76.         Call    printf,Offset ErrOpenMsg,Edx,Ax
  77.     Else
  78.         Pop    +8,Ebx
  79.     Endif
  80.         Mov    Eax,-1
  81.         Ret
  82. Endp    
  83.  
  84.     Dataseg
  85.  
  86. errno        Dd    0
  87.  
  88.     IfDef    DEBUG
  89. ErrOpenMsg    Db    "Error opening file '%s'! Error: %h",CRLF,0
  90.     Endif
  91.  
  92.     End
  93.