objinc.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998-2000 by the Free Pascal development team.
  5. Includefile for objects.pp implementing OS-dependent file routines
  6. for Go32V1
  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. begin
  19. asm
  20. xor %bx,%bx
  21. movw handle,%bx
  22. movb $0x3e,%ah
  23. pushl %ebp
  24. int $0x21
  25. popl %ebp
  26. end;
  27. FileClose := 0;
  28. end;
  29. {---------------------------------------------------------------------------}
  30. { FileOpen -> Platforms DOS - Checked 05May1998 CEC }
  31. { Returns 0 on failure }
  32. {---------------------------------------------------------------------------}
  33. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  34. var
  35. AMode: word;
  36. begin
  37. if Mode=stCreate then
  38. Begin
  39. AMode:=$8302;
  40. end
  41. else
  42. Begin
  43. Case (Mode and 3) of
  44. 0 : AMode:=$8001;
  45. 1 : AMode:=$8404;
  46. 2 : AMode:=$8404;
  47. end;
  48. end;
  49. asm
  50. xorl %eax, %eax
  51. movw %ax, DosStreamError
  52. movl FileName, %ebx
  53. movw $0xff02, %ax
  54. movw AMode, %cx
  55. pushl %ebp
  56. int $0x21
  57. popl %ebp
  58. jnc .Lexit1
  59. movw %ax, DosStreamError { Hold Error }
  60. xorl %eax, %eax { Open Failed }
  61. .Lexit1:
  62. movw %ax, __RESULT
  63. END;
  64. end;
  65. {***************************************************************************}
  66. { DosSetFilePtr -> Platforms DOS - Checked 05May1998 CEC }
  67. {***************************************************************************}
  68. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  69. Var Actual: LongInt): Word;
  70. Var
  71. val : longint;
  72. BEGIN
  73. asm
  74. movw MoveType, %ax; { Load move type }
  75. movb $0x42, %ah;
  76. movl pos, %edx; { Load file position }
  77. andl $0xffff,%edx { Only keep low word }
  78. movl pos, %ecx
  79. shrl $16,%ecx;
  80. movw Handle, %bx; { Load file handle }
  81. pushl %ebp;
  82. int $0x21; { Position the file }
  83. popl %ebp;
  84. jc .Lexit4
  85. shll $16,%edx
  86. movzwl %ax,%eax
  87. orl %edx,%eax
  88. movl %eax,val { Update new position }
  89. xorl %eax, %eax;
  90. .Lexit4:
  91. movw %ax, DosStreamError { DOS error returned }
  92. .Lend:
  93. END;
  94. Actual := val;
  95. SetFilePos := DosStreamError; { Return any error }
  96. END;
  97. {---------------------------------------------------------------------------}
  98. { FileRead -> Platforms DOS - Checked 05May1998 CEC }
  99. {---------------------------------------------------------------------------}
  100. FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word;
  101. Var Actual: Sw_Word): Word;
  102. BEGIN
  103. asm
  104. movl count,%ecx
  105. movl buf,%edx
  106. xorl %ebx,%ebx
  107. movw handle,%bx
  108. movb $0x3f,%ah
  109. int $0x21
  110. jnc .LDOSREAD1
  111. movw %ax,DosStreamError
  112. xorl %eax,%eax
  113. .LDOSREAD1:
  114. end;
  115. Actual:=Count;
  116. FileRead:=DosStreamError;
  117. end;
  118. {---------------------------------------------------------------------------}
  119. { FileWrite -> Platforms DOS - Checked 05May1998 CEC }
  120. {---------------------------------------------------------------------------}
  121. FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word): Word;
  122. BEGIN
  123. Actual:=0;
  124. asm
  125. movl Count,%ecx
  126. movl buf,%edx
  127. xorl %ebx,%ebx
  128. movw Handle,%bx
  129. movb $0x40,%ah
  130. pushl %ebp
  131. int $0x21
  132. pop %ebp
  133. jnc .LDOSWRITE1
  134. movw %ax,DosStreamError
  135. .LDOSWRITE1:
  136. end;
  137. Actual:=Count;
  138. FileWrite:=DosStreamError;
  139. end;
  140. {---------------------------------------------------------------------------}
  141. { SetFileSize -> Platforms DOS - Not Checked }
  142. {---------------------------------------------------------------------------}
  143. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  144. VAR Actual, Buf: LongInt;
  145. BEGIN
  146. SetFilePos(Handle,FileSize,0,Actual);
  147. If (Actual = FileSize) Then
  148. Begin
  149. Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
  150. If (Actual <> -1) Then
  151. SetFileSize := 0
  152. Else
  153. SetFileSize := 103; { File truncate error }
  154. End
  155. Else
  156. SetFileSize := 103; { File truncate error }
  157. END;
  158. {
  159. $Log$
  160. Revision 1.3 2000-01-07 16:32:23 daniel
  161. * copyright 2000 added
  162. Revision 1.2 1999/06/01 13:23:10 peter
  163. * fixes to work with the new makefile
  164. * os2 compiles now correct under linux
  165. Revision 1.1 1998/12/21 13:07:02 peter
  166. * use -FE
  167. Revision 1.4 1998/07/06 12:26:19 carl
  168. * Glurbl.... now work perfectly! Do not change :)
  169. Revision 1.3 1998/07/02 12:25:27 carl
  170. * NOTHING would work, FileOpen is now correct!!
  171. Revision 1.2 1998/05/31 14:18:18 peter
  172. * force att or direct assembling
  173. * cleanup of some files
  174. }