objinc.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 Go32V2
  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. {---------------------------------------------------------------------------}
  15. { FileClose -> Platforms DOS - Not checked }
  16. {---------------------------------------------------------------------------}
  17. FUNCTION FileClose (Handle: THandle): Word;
  18. var
  19. regs : trealregs;
  20. begin
  21. regs.realebx:=handle;
  22. regs.realeax:=$3e00;
  23. sysrealintr($21,regs);
  24. FileClose := 0;
  25. end;
  26. {---------------------------------------------------------------------------}
  27. { FileOpen -> Platforms DOS - Checked 05May1998 CEC }
  28. { Returns 0 on failure }
  29. {---------------------------------------------------------------------------}
  30. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  31. Var
  32. regs : trealregs;
  33. BEGIN
  34. DosStreamError:=0;
  35. syscopytodos(longint(@FileName),256);
  36. { get linear address from system unit }
  37. regs.realedx:=tb mod 16;
  38. regs.realds:=tb div 16;
  39. if LFNSupport then
  40. begin
  41. if (mode = stCreate) then
  42. begin
  43. regs.realeax := $716C;
  44. regs.realesi:=tb mod 16;
  45. regs.realebx:=$2002;
  46. regs.realecx:=$20;
  47. regs.realedi:=0;
  48. regs.realedx:=$12;
  49. end
  50. else if (mode = stOpenRead) then
  51. begin
  52. regs.realeax := $716C;
  53. regs.realesi:=tb mod 16;
  54. regs.realebx:=$2000;
  55. regs.realecx:=$20;
  56. regs.realedi:=0;
  57. regs.realedx:=$1;
  58. end
  59. else if (mode = stOpenWrite) then
  60. begin
  61. regs.realeax := $716C;
  62. regs.realesi:=tb mod 16;
  63. regs.realebx:=$2001;
  64. regs.realecx:=$20;
  65. regs.realedi:=0;
  66. regs.realedx:=$11;
  67. end
  68. else if (mode = stOpen) then
  69. begin
  70. regs.realeax := $716C;
  71. regs.realesi:=tb mod 16;
  72. regs.realebx:=$2002;
  73. regs.realecx:=$20;
  74. regs.realedi:=0;
  75. regs.realedx:=$11;
  76. end
  77. else
  78. regs.realeax := Mode;
  79. end
  80. else
  81. regs.realeax := Mode;
  82. regs.realecx:=0;
  83. sysrealintr($21,regs);
  84. if (regs.realflags and 1) <> 0 then
  85. begin
  86. InOutRes:=lo(regs.realeax);
  87. FileOpen:=$0;
  88. exit;
  89. end
  90. else
  91. { word handle (under DOS) }
  92. FileOpen:=regs.realeax and $ffff;
  93. END;
  94. {---------------------------------------------------------------------------}
  95. { SetFilePos -> Platforms DOS - Checked 05May1998 CEC }
  96. {---------------------------------------------------------------------------}
  97. {
  98. Calls the operating system to move the file denoted by the handle to
  99. to the requested position. The move method can be: 0 = absolute offset;
  100. 1 = offset from present location; 2 = offset from end of file;
  101. Any error is held in DosErrorStream and returned from the call.
  102. If the return is zero (ie no error) NewPos contains the new absolute
  103. file position.
  104. }
  105. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;Var Actual: LongInt): Word;
  106. Var
  107. regs: Trealregs;
  108. const
  109. CarryFlag = $001;
  110. BEGIN
  111. regs.realeax := ($42 shl 8) + Byte(MoveType);
  112. regs.realedx := pos and $ffff; { keep low word }
  113. regs.realecx := pos shr 16;
  114. regs.realebx := longint(Handle);
  115. sysrealintr($21,regs);
  116. if (regs.RealFlags and CarryFlag = 0) then { no error }
  117. Actual:=(regs.realeax and $ffff) + ((regs.realedx and $ffff) shl 16)
  118. else
  119. DosStreamError:=word(regs.realeax);
  120. SetFilePos := DosStreamError; { Return any error }
  121. END;
  122. {---------------------------------------------------------------------------}
  123. { FileRead -> Platforms DOS - Checked 05May1998 CEC }
  124. {---------------------------------------------------------------------------}
  125. FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word;
  126. Var Actual: Sw_Word): Word;
  127. BEGIN
  128. Actual:=system.do_read(longint(Handle),longint(@Buf),Count);
  129. FileRead:=InOutRes;
  130. End;
  131. {---------------------------------------------------------------------------}
  132. { FileWrite -> Platforms DOS - Checked 05May1998 CEC }
  133. {---------------------------------------------------------------------------}
  134. FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word): Word;
  135. BEGIN
  136. system.do_write(longint(Handle),longint(@Buf),Count);
  137. Actual:=Count;
  138. FileWrite:=InOutRes;
  139. End;
  140. {---------------------------------------------------------------------------}
  141. { SetFileSize -> Platforms DOS - Not Checked }
  142. {---------------------------------------------------------------------------}
  143. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  144. VAR Actual: LongInt;
  145. regs : trealregs;
  146. const
  147. CarryFlag = $001;
  148. BEGIN
  149. SetFilePos(Handle,FileSize,0,Actual);
  150. If (Actual = FileSize) Then
  151. Begin
  152. regs.realecx:=0;
  153. regs.realedx:=tb mod 16;
  154. regs.realds:=tb div 16;
  155. regs.realebx:=handle;
  156. regs.realeax:=$4000;
  157. sysrealintr($21,regs);
  158. if (regs.RealFlags and CarryFlag = 0) then { no error }
  159. SetFileSize := 0
  160. Else
  161. SetFileSize := 103; { File truncate error }
  162. End
  163. Else
  164. SetFileSize := 103; { File truncate error }
  165. END;
  166. {
  167. $Log$
  168. Revision 1.2 2000-07-13 11:33:40 michael
  169. + removed logs
  170. }