objinc.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 AmigaOS
  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. Const
  15. _LVOFindTask = -294;
  16. _LVOWaitPort = -384;
  17. _LVOGetMsg = -372;
  18. _LVOOpenLibrary = -552;
  19. _LVOCloseLibrary = -414;
  20. _LVOClose = -36;
  21. _LVOOpen = -30;
  22. _LVOIoErr = -132;
  23. _LVOSeek = -66;
  24. _LVODeleteFile = -72;
  25. _LVORename = -78;
  26. _LVOWrite = -48;
  27. _LVORead = -42;
  28. _LVOCreateDir = -120;
  29. _LVOSetCurrentDirName = -558;
  30. _LVOGetCurrentDirName = -564;
  31. _LVOInput = -54;
  32. _LVOOutput = -60;
  33. _LVOUnLock = -90;
  34. _LVOLock = -84;
  35. _LVOCurrentDir = -126;
  36. _LVONameFromLock = -402;
  37. _LVONameFromFH = -408;
  38. _LVOGetProgramName = -576;
  39. _LVOGetProgramDir = -600;
  40. _LVODupLock = -96;
  41. _LVOExamine = -102;
  42. _LVOParentDir = -210;
  43. _LVOSetFileSize = -456;
  44. {---------------------------------------------------------------------------}
  45. { FileClose -> Platforms AmigaOS - Not checked }
  46. {---------------------------------------------------------------------------}
  47. FUNCTION FileClose(Handle: THandle): word;
  48. begin
  49. asm
  50. move.l handle,d1
  51. move.l a6,d6 { save a6 }
  52. move.l _DOSBase,a6
  53. jsr _LVOClose(a6)
  54. move.l d6,a6 { restore a6 }
  55. end;
  56. FileClose := 0;
  57. end;
  58. {---------------------------------------------------------------------------}
  59. { FileOpen -> Platforms AmigaOS - 08Jul98 CEC }
  60. { Returns 0 on failure }
  61. {---------------------------------------------------------------------------}
  62. FUNCTION FileOpen (Var FileName: AsciiZ; Mode: Word): THandle;
  63. var
  64. oflags : longint;
  65. AHandle : THandle;
  66. begin
  67. AHandle:=0;
  68. { On opening reset error code }
  69. DosStreamError := 0;
  70. if Mode=stCreate then
  71. { read/write file with creation of file }
  72. oflags := 1006
  73. else
  74. { read/write access on existing file }
  75. oflags := 1005;
  76. asm
  77. move.l a6,d6 { save a6 }
  78. move.l FileName,d1
  79. move.l oflags,d2 { MODE_READWRITE }
  80. move.l _DOSBase,a6
  81. jsr _LVOOpen(a6)
  82. tst.l d0
  83. bne @noopenerror { on zero an error occured }
  84. jsr _LVOIoErr(a6)
  85. move.w d0,DosStreamError
  86. bra @openend
  87. @noopenerror:
  88. move.l d6,a6 { restore a6 }
  89. move.l d0,AHandle { we need the base pointer to access this variable }
  90. bra @end
  91. @openend:
  92. move.l d6,a6 { restore a6 }
  93. @end:
  94. end;
  95. FileOpen := AHandle;
  96. end;
  97. {***************************************************************************}
  98. { DosSetFilePtr -> Platforms AmigaOS - 08Jul98 CEC }
  99. {***************************************************************************}
  100. FUNCTION SetFilePos (Handle: THandle; Pos: LongInt; MoveType: Word;
  101. Var Actual: LongInt): Word;
  102. Var
  103. Move_typ : longint;
  104. BEGIN
  105. Move_typ := 0;
  106. { Move from beginning of file }
  107. if MoveType = 0 then
  108. Move_typ := -1;
  109. { Move from current position of file }
  110. If MoveType = 1 then
  111. Move_typ := 0;
  112. { Move from end of file }
  113. If MoveType = 2 then
  114. Move_typ := 1;
  115. { We have to seek TWO times, if we wish to get the actual absolute }
  116. { file position normally. }
  117. asm
  118. move.l a6,d6 { Save base pointer }
  119. move.l handle,d1
  120. move.l d2,-(sp)
  121. move.l d3,-(sp) { save registers }
  122. move.l pos,d2
  123. move.l Move_typ,d3 { Setup correct move type }
  124. move.l _DOSBase,a6
  125. jsr _LVOSeek(a6)
  126. move.l (sp)+,d3 { restore registers }
  127. move.l (sp)+,d2
  128. cmp.l #-1,d0 { is there a file access error? }
  129. bne @noerr_one { no, then seek a second time }
  130. jsr _LVOIoErr(a6) { yes ,get error in d0 and jmp }
  131. bra @err
  132. @noerr_one: { Seek a second time }
  133. move.l d6,a6 { Restore base pointer }
  134. move.l handle,d1
  135. move.l d2,-(sp)
  136. move.l d3,-(sp) { save registers }
  137. move.l pos,d2
  138. move.l Move_typ,d3 { Setup correct move type }
  139. move.l _DOSBase,a6
  140. jsr _LVOSeek(a6)
  141. move.l (sp)+,d3 { restore registers }
  142. move.l (sp)+,d2
  143. cmp.l #-1,d0 { is there a file access error? }
  144. bne @noerr
  145. jsr _LVOIoErr(a6)
  146. @err:
  147. move.w d0,DosStreamError
  148. move.l d6,a6 { restore a6 }
  149. bra @seekend
  150. @noerr:
  151. move.l d6,a6 { restore a6 }
  152. move.l Actual,a0 { Get address of variable }
  153. move.l d0,(a0) { Set value of Actual }
  154. @seekend:
  155. end;
  156. SetFilePos := DosStreamError; { Return any error }
  157. END;
  158. {---------------------------------------------------------------------------}
  159. { FileRead -> Platforms AmigaOS - 08Jul98 CEC }
  160. {---------------------------------------------------------------------------}
  161. FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word;
  162. Var Actual: Sw_Word): Word;
  163. BEGIN
  164. if Count <= 0 then
  165. Begin
  166. FileRead:=1; { Return a non zero error }
  167. exit;
  168. end;
  169. asm
  170. move.l a6,d6
  171. movem.l d2/d3,-(sp)
  172. move.l handle,d1 { we must set up aparamters BEFORE }
  173. move.l buf,d2 { setting up a6 for the OS call }
  174. move.l count,d3
  175. move.l _DOSBase,a6
  176. jsr _LVORead(a6)
  177. movem.l (sp)+,d2/d3
  178. cmp.l #-1,d0
  179. bne @doswrend { if -1 = error }
  180. jsr _LVOIoErr(a6)
  181. move.w d0,DosStreamError
  182. bra @doswrend2
  183. @doswrend:
  184. { to store a result for the function }
  185. { we must of course first get back the}
  186. { base pointer! }
  187. move.l d6,a6
  188. move.l Actual,a0 { Actual is a pointer! }
  189. move.l d0,(a0)
  190. bra @end
  191. @doswrend2:
  192. move.l d6,a6
  193. @end:
  194. end;
  195. FileRead:=DosStreamError;
  196. end;
  197. {---------------------------------------------------------------------------}
  198. { FileWrite -> Platforms AmigAOS - 08Jul98 CEC }
  199. {---------------------------------------------------------------------------}
  200. FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word): Word;
  201. BEGIN
  202. if Count <= 0 then
  203. Begin
  204. FileWrite:=1; { Return a non zero error code }
  205. exit;
  206. end;
  207. asm
  208. move.l a6,d6
  209. movem.l d2/d3,-(sp)
  210. move.l handle,d1 { we must of course set up the }
  211. move.l buf,d2 { parameters BEFORE getting }
  212. move.l count,d3 { _DOSBase }
  213. move.l _DOSBase,a6
  214. jsr _LVOWrite(a6)
  215. movem.l (sp)+,d2/d3
  216. cmp.l #-1,d0
  217. bne @doswrend { if -1 = error }
  218. jsr _LVOIoErr(a6)
  219. move.w d0,DosStreamError
  220. bra @doswrend2
  221. @doswrend:
  222. { we must restore the base pointer before setting the result }
  223. move.l d6,a6
  224. move.l Actual,a0 { Actual is a pointer! }
  225. move.l d0,(a0)
  226. bra @end
  227. @doswrend2:
  228. move.l d6,a6
  229. @end:
  230. end;
  231. Actual:=Count;
  232. FileWrite:=DosStreamError;
  233. end;
  234. {---------------------------------------------------------------------------}
  235. { SetFileSize -> Platforms AmigaOS - 08Jul98 CEC }
  236. {---------------------------------------------------------------------------}
  237. FUNCTION SetFileSize (Handle: THandle; FileSize: LongInt): Word;
  238. BEGIN
  239. { Point to the end of the file }
  240. { with the new size }
  241. asm
  242. @noerr_one: { Seek a second time }
  243. move.l a6,d6 { Save base pointer }
  244. move.l handle,d1
  245. move.l d2,-(sp)
  246. move.l d3,-(sp) { save registers }
  247. move.l FileSize,d2
  248. move.l #-1,d3 { Setup correct move type }
  249. move.l _DOSBase,a6 { from beginning of file }
  250. jsr _LVOSetFileSize(a6)
  251. move.l (sp)+,d3 { restore registers }
  252. move.l (sp)+,d2
  253. cmp.l #-1,d0 { is there a file access error? }
  254. bne @noerr
  255. jsr _LVOIoErr(a6)
  256. move.w d0,DosStreamError
  257. @noerr:
  258. move.l d6,a6 { restore a6 }
  259. end;
  260. SetFileSize:=DosStreamError;
  261. END;
  262. {
  263. $Log$
  264. Revision 1.2 2000-07-13 11:33:37 michael
  265. + removed logs
  266. }