objinc.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Includefile for objects.pp implementing OS-dependent file routines
  6. for EMX (OS/2 & DOS)
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************
  13. }
  14. {This is the correct way to call external assembler procedures.}
  15. procedure syscall;external name '___SYSCALL';
  16. FUNCTION FileClose(Handle: THandle): word;
  17. begin
  18. asm
  19. xor %bx,%bx
  20. movw handle,%bx
  21. movb $0x3e,%ah
  22. call syscall
  23. end;
  24. FileClose := 0;
  25. end;
  26. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  27. var
  28. AMode: word;
  29. begin
  30. if Mode=stCreate then
  31. Begin
  32. AMode:=$8302;
  33. end
  34. else
  35. Begin
  36. Case (Mode and 3) of
  37. 0 : AMode:=$8001;
  38. 1 : AMode:=$8404;
  39. 2 : AMode:=$8404;
  40. end;
  41. end;
  42. asm
  43. xorl %eax, %eax
  44. movw %ax, DosStreamError
  45. movl FileName, %ebx
  46. movw $0xff02, %ax
  47. movw AMode, %cx
  48. call syscall
  49. jnc .Lexit1
  50. movw %ax, DosStreamError { Hold Error }
  51. xorl %eax, %eax { Open Failed }
  52. .Lexit1:
  53. movw %ax, __RESULT
  54. END;
  55. end;
  56. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  57. Var Actual: LongInt): Word;
  58. Var
  59. val : longint;
  60. BEGIN
  61. asm
  62. movw MoveType, %ax; { Load move type }
  63. movb $0x42, %ah;
  64. movl pos, %edx; { Load file position }
  65. movw Handle, %bx; { Load file handle }
  66. call syscall
  67. jc .Lexit4
  68. movl %eax,val { Update new position }
  69. xorl %eax, %eax;
  70. .Lexit4:
  71. movw %ax, DosStreamError { OS2 error returned }
  72. .Lend:
  73. END;
  74. Actual := val;
  75. SetFilePos := DosStreamError; { Return any error }
  76. END;
  77. FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word;
  78. Var Actual: Sw_Word): Word;
  79. BEGIN
  80. asm
  81. movl count,%ecx
  82. movl buf,%edx
  83. xorl %ebx,%ebx
  84. movw handle,%bx
  85. movb $0x3f,%ah
  86. call syscall
  87. jnc .LDOSREAD1
  88. movw %ax,DosStreamError
  89. xorl %eax,%eax
  90. .LDOSREAD1:
  91. end;
  92. Actual:=Count;
  93. FileRead:=DosStreamError;
  94. end;
  95. FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word): Word;
  96. BEGIN
  97. Actual:=0;
  98. asm
  99. movl Count,%ecx
  100. movl buf,%edx
  101. xorl %ebx,%ebx
  102. movw Handle,%bx
  103. movb $0x40,%ah
  104. call syscall
  105. jnc .LDOSWRITE1
  106. movw %ax,DosStreamError
  107. .LDOSWRITE1:
  108. end;
  109. Actual:=Count;
  110. FileWrite:=DosStreamError;
  111. end;
  112. function SetFileSize (Handle: THandle; FileSize: longint): word; assembler;
  113. asm
  114. movl $0x7F18, %eax
  115. movl Handle, %ebx
  116. movl FileSize,%edx
  117. call syscall
  118. jc .LSetFSize1
  119. movl $0x4202, %eax
  120. movl Handle, %ebx
  121. movl $0, %edx
  122. call syscall
  123. movl $0, %eax
  124. jnc .LSetFSize1
  125. decl %eax
  126. .LSetFSize1:
  127. end;
  128. {
  129. $Log$
  130. Revision 1.8 2000-06-12 17:26:29 hajny
  131. * little mistyping in SetFileSize
  132. Revision 1.7 2000/06/06 17:10:36 hajny
  133. * moving file ptr to the end in SetFileSize
  134. Revision 1.6 2000/06/05 18:55:54 hajny
  135. * another SetFileSize correction
  136. Revision 1.5 2000/06/04 14:17:28 hajny
  137. * SetFileSize fixed
  138. Revision 1.4 2000/02/09 16:59:33 peter
  139. * truncated log
  140. Revision 1.3 2000/01/07 16:41:48 daniel
  141. * copyright 2000
  142. Revision 1.2 2000/01/07 16:32:32 daniel
  143. * copyright 2000 added
  144. }