objinc.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 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. {This is the correct way to call external assembler procedures.}
  15. procedure syscall;external name '___SYSCALL';
  16. {---------------------------------------------------------------------------}
  17. { FileClose -> Platforms OS2 - Not checked }
  18. {---------------------------------------------------------------------------}
  19. FUNCTION FileClose(Handle: THandle): word;
  20. begin
  21. asm
  22. xor %bx,%bx
  23. movw handle,%bx
  24. movb $0x3e,%ah
  25. call syscall
  26. end;
  27. FileClose := 0;
  28. end;
  29. {---------------------------------------------------------------------------}
  30. { FileOpen -> Platforms OS2 - 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. call syscall
  56. jnc .Lexit1
  57. movw %ax, DosStreamError { Hold Error }
  58. xorl %eax, %eax { Open Failed }
  59. .Lexit1:
  60. movw %ax, __RESULT
  61. END;
  62. end;
  63. {***************************************************************************}
  64. { DosSetFilePtr -> Platforms OS2 - Checked 05May1998 CEC }
  65. {***************************************************************************}
  66. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  67. Var Actual: LongInt): Word;
  68. Var
  69. val : longint;
  70. BEGIN
  71. asm
  72. movw MoveType, %ax; { Load move type }
  73. movb $0x42, %ah;
  74. movl pos, %edx; { Load file position }
  75. movw Handle, %bx; { Load file handle }
  76. call syscall
  77. jc .Lexit4
  78. movl %eax,val { Update new position }
  79. xorl %eax, %eax;
  80. .Lexit4:
  81. movw %ax, DosStreamError { OS2 error returned }
  82. .Lend:
  83. END;
  84. Actual := val;
  85. SetFilePos := DosStreamError; { Return any error }
  86. END;
  87. {---------------------------------------------------------------------------}
  88. { FileRead -> Platforms OS2 - Checked 05May1998 CEC }
  89. {---------------------------------------------------------------------------}
  90. FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word;
  91. Var Actual: Sw_Word): Word;
  92. BEGIN
  93. asm
  94. movl count,%ecx
  95. movl buf,%edx
  96. xorl %ebx,%ebx
  97. movw handle,%bx
  98. movb $0x3f,%ah
  99. call syscall
  100. jnc .LDOSREAD1
  101. movw %ax,DosStreamError
  102. xorl %eax,%eax
  103. .LDOSREAD1:
  104. end;
  105. Actual:=Count;
  106. FileRead:=DosStreamError;
  107. end;
  108. {---------------------------------------------------------------------------}
  109. { FileWrite -> Platforms OS2 - Checked 05May1998 CEC }
  110. {---------------------------------------------------------------------------}
  111. FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word): Word;
  112. BEGIN
  113. Actual:=0;
  114. asm
  115. movl Count,%ecx
  116. movl buf,%edx
  117. xorl %ebx,%ebx
  118. movw Handle,%bx
  119. movb $0x40,%ah
  120. call syscall
  121. jnc .LDOSWRITE1
  122. movw %ax,DosStreamError
  123. .LDOSWRITE1:
  124. end;
  125. Actual:=Count;
  126. FileWrite:=DosStreamError;
  127. end;
  128. {---------------------------------------------------------------------------}
  129. { SetFileSize -> Platforms OS2 - Not Checked }
  130. {---------------------------------------------------------------------------}
  131. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  132. VAR Actual, Buf: LongInt;
  133. BEGIN
  134. SetFilePos(Handle,FileSize,0,Actual);
  135. If (Actual = FileSize) Then
  136. Begin
  137. Actual := FileWrite(Handle, Pointer(@Buf), 0,Actual); { Truncate the file }
  138. If (Actual <> -1) Then
  139. SetFileSize := 0
  140. Else
  141. SetFileSize := 103; { File truncate error }
  142. End
  143. Else
  144. SetFileSize := 103; { File truncate error }
  145. END;
  146. {
  147. $Log$
  148. Revision 1.4 2000-02-09 16:59:33 peter
  149. * truncated log
  150. Revision 1.3 2000/01/07 16:41:48 daniel
  151. * copyright 2000
  152. Revision 1.2 2000/01/07 16:32:32 daniel
  153. * copyright 2000 added
  154. }