filectrl.inc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. {
  2. System independent filecontrol interface for tp7
  3. $Id$
  4. }
  5. { no known 16 bit compilers support overriding }
  6. function OpenFileStr(FName: PChar; Flags: Longint): TFileHandle; assembler;
  7. asm
  8. @@Retry:
  9. push ds
  10. lds dx,FName
  11. mov al,byte ptr Flags
  12. mov ah,3dh
  13. int 21h
  14. pop ds
  15. jnc @@1
  16. push ax
  17. mov ax,0
  18. push ax { ErrorCode: Longint }
  19. les dx,FName
  20. push es
  21. push dx { FName as ErrorInfo }
  22. call [ErrorHandler]
  23. cmp ax,errRetry
  24. je @@Retry
  25. mov ax,-1
  26. @@1:
  27. end;
  28. function CreateFileStr(FName: PChar): TFileHandle; assembler;
  29. asm
  30. @@Retry:
  31. push ds
  32. lds dx,FName
  33. mov cl,20h
  34. xor ch,ch
  35. mov ah,3Ch
  36. int 21h
  37. pop ds
  38. jnc @@1
  39. push ax
  40. mov ax,0
  41. push ax
  42. les dx,FName
  43. push es
  44. push dx { FName as errorinfo }
  45. call [ErrorHandler]
  46. cmp ax,errRetry
  47. je @@Retry
  48. mov ax,-1
  49. @@1:
  50. end;
  51. procedure DeleteFileStr(FName: PChar); assembler;
  52. asm
  53. @@Retry:
  54. push ds
  55. lds dx,FName
  56. mov AH,41h
  57. int 21h
  58. pop ds
  59. jnc @@1
  60. push ax
  61. mov ax,0
  62. push ax
  63. les dx,FName
  64. push es
  65. push dx
  66. call [ErrorHandler]
  67. cmp ax,errRetry
  68. je @@Retry
  69. @@1:
  70. end;
  71. procedure CloseFile(Handle: TFileHandle); assembler;
  72. asm
  73. @@Retry:
  74. mov bx,Handle
  75. mov ah,3eh
  76. int 21h
  77. jnc @@1
  78. push ax
  79. mov ax,0
  80. push ax
  81. push ax
  82. push ax
  83. call [ErrorHandler]
  84. cmp ax,errRetry
  85. je @@Retry
  86. @@1:
  87. end;
  88. function SeekFile(Handle: TFileHandle; Pos: TFileInt; SeekType: Word): TFileInt; assembler;
  89. asm
  90. @@Retry:
  91. mov ah,42H
  92. mov bx,Handle
  93. mov dx,word ptr Pos[0]
  94. mov cx,word ptr Pos[2]
  95. mov al,byte ptr SeekType
  96. int 21h
  97. jnc @@1
  98. push ax
  99. mov ax,0
  100. push ax
  101. push ax
  102. push ax
  103. call [ErrorHandler]
  104. cmp ax,errRetry
  105. je @@Retry
  106. mov ax,-1
  107. mov dx,-1
  108. @@1:
  109. end;
  110. function ReadFile(Handle: TFileHandle; var Buff; Count: CPUWord): CPUWord; assembler;
  111. asm
  112. @@Retry:
  113. push ds
  114. lds dx,Buff
  115. mov cx,Count
  116. mov bx,Handle
  117. mov ah,3fh
  118. int 21h
  119. pop ds
  120. jnc @@1
  121. push ax
  122. mov ax,0
  123. push ax
  124. push ax
  125. push ax
  126. call [ErrorHandler]
  127. cmp ax,errRetry
  128. je @@Retry
  129. xor ax,ax
  130. @@1:
  131. end;
  132. function WriteFile(Handle: TFileHandle; var Buff; Count: CPUWord): CPUWord; assembler;
  133. asm
  134. @@Retry:
  135. push ds
  136. lds dx,Buff
  137. mov cx,Count
  138. mov bx,Handle
  139. mov ah,40h
  140. int 21h
  141. pop ds
  142. jnc @@1
  143. push ax
  144. mov ax,0
  145. push ax
  146. push ax
  147. push ax
  148. call [ErrorHandler]
  149. cmp ax,errRetry
  150. je @@Retry
  151. xor ax,ax
  152. @@1:
  153. end;
  154. procedure FlushFile(Handle: TFileHandle); assembler;
  155. asm
  156. @@Retry:
  157. mov bx,Handle
  158. mov ah,68H
  159. int 21h
  160. jnc @@1
  161. push ax
  162. mov ax,0
  163. push ax
  164. push ax
  165. push ax
  166. call [ErrorHandler]
  167. cmp ax,errRetry
  168. je @@Retry
  169. @@1:
  170. end;
  171. procedure TruncateFile(Handle: TFileHandle);
  172. begin
  173. WriteFile(Handle, Handle, 0);
  174. end;
  175. function EndOfFile(Handle: TFileHandle): Boolean; assembler;
  176. asm
  177. @@Retry:
  178. mov ax,4400h
  179. mov bx,Handle
  180. int 21h
  181. jnc @@1
  182. push ax
  183. mov ax,0
  184. push ax
  185. push ax
  186. push ax
  187. call [ErrorHandler]
  188. cmp ax,errRetry
  189. je @@Retry
  190. jmp @@3 { Set result to 1, though an error has happened }
  191. @@1:
  192. test ax,40h
  193. jz @@3
  194. xor al,al
  195. jmp @@2
  196. @@3:
  197. mov al,1
  198. @@2:
  199. end;
  200. function FilePos(Handle: TFileHandle): TFileInt;
  201. begin
  202. FilePos := SeekFile(Handle, 0, skCur);
  203. end;
  204. function FileSize(Handle: TFileHandle): TFileInt;
  205. var
  206. L: Longint;
  207. begin
  208. L := FilePos(Handle);
  209. FileSize := SeekFile(Handle, 0, skEnd);
  210. SeekFile(Handle, L, skBeg);
  211. end;
  212. {
  213. $Log$
  214. Revision 1.2 2000-07-13 11:32:26 michael
  215. + removed logs
  216. }