system.pp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002 by Olle Raab
  5. FreePascal system unit for MacOS.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit System;
  13. interface
  14. {If MAC_SYS_RUNABLE is defined, this file can be included in a
  15. runnable program, but it then lacks lot of features. If not defined
  16. it tries to be faithful to a real system.pp, but it may not be
  17. able to assemble and link. The switch is only temporary, and only for
  18. use when system.pp is developed.}
  19. {$Y-}
  20. {$ifdef MAC_SYS_RUNABLE}
  21. type
  22. integer = -32768 .. 32767;
  23. byte =0..255;
  24. shortint=-128..127;
  25. word=0..65535;
  26. longint=+(-$7FFFFFFF-1)..$7FFFFFFF;
  27. pchar=^char;
  28. {$else}
  29. {At the moment we do not support threadvars}
  30. {$undef HASTHREADVAR}
  31. {$I systemh.inc}
  32. {$I heaph.inc}
  33. {Platform specific information}
  34. const
  35. LineEnding = #13;
  36. LFNSupport = true;
  37. DirectorySeparator = ':';
  38. DriveSeparator = ':';
  39. PathSeparator = ';';
  40. FileNameCaseSensitive = false;
  41. const
  42. UnusedHandle = -1;
  43. StdInputHandle = 0;
  44. StdOutputHandle = 0;
  45. StdErrorHandle = 0;
  46. sLineBreak : string[1] = LineEnding;
  47. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCR;
  48. var
  49. argc : longint;
  50. argv : ppchar;
  51. envp : ppchar;
  52. {$endif}
  53. implementation
  54. {Some MacOS API routines needed for internal use.
  55. Note, because the System unit is the most low level, it should not
  56. depend on any other units, and in particcular not the MacOS unit.}
  57. function NewPtr(logicalSize: Longint): pointer ;
  58. external 'InterfaceLib';
  59. procedure Debugger;
  60. external 'InterfaceLib';
  61. {$ifdef MAC_SYS_RUNABLE}
  62. procedure do_exit;[public,alias:'FPC_DO_EXIT'];
  63. begin
  64. end;
  65. procedure fpc_initializeunits;[public,alias:'FPC_INITIALIZEUNITS'];
  66. begin
  67. end;
  68. {$else}
  69. {$I system.inc}
  70. {*********************** ??????? *************}
  71. procedure SysInitStdIO;
  72. begin
  73. end;
  74. {*****************************************************************************}
  75. procedure setup_arguments;
  76. begin
  77. end;
  78. procedure setup_environment;
  79. begin
  80. end;
  81. {*****************************************************************************
  82. System Dependent Exit code
  83. *****************************************************************************}
  84. Procedure system_exit;
  85. begin
  86. end;
  87. {*****************************************************************************
  88. ParamStr/Randomize
  89. *****************************************************************************}
  90. { number of args }
  91. function paramcount : longint;
  92. begin
  93. {paramcount := argc - 1;}
  94. paramcount:=0;
  95. end;
  96. { argument number l }
  97. function paramstr(l : longint) : string;
  98. begin
  99. {if (l>=0) and (l+1<=argc) then
  100. paramstr:=strpas(argv[l])
  101. else}
  102. paramstr:='';
  103. end;
  104. { set randseed to a new pseudo random value }
  105. procedure randomize;
  106. begin
  107. {regs.realeax:=$2c00;
  108. sysrealintr($21,regs);
  109. hl:=regs.realedx and $ffff;
  110. randseed:=hl*$10000+ (regs.realecx and $ffff);}
  111. randseed:=0;
  112. end;
  113. {*****************************************************************************
  114. Heap Management
  115. *****************************************************************************}
  116. const
  117. theHeapSize = 300000; //TODO: Use heapsize set by user.
  118. var
  119. { Pointer to a block allocated with the MacOS Memory Manager, which
  120. is used as the FPC heap }
  121. theHeap: pointer;
  122. { first address of heap }
  123. function getheapstart:pointer;
  124. begin
  125. getheapstart:= theHeap;
  126. end;
  127. { current length of heap }
  128. function getheapsize:longint;
  129. begin
  130. getheapsize:= theHeapSize ;
  131. end;
  132. { function to allocate size bytes more for the program }
  133. { must return the first address of new data space or -1 if fail }
  134. function Sbrk(size : longint):longint;
  135. begin
  136. Sbrk:=-1; //TODO: Allow heap increase.
  137. end;
  138. {$I heap.inc}
  139. {****************************************************************************
  140. Low level File Routines
  141. All these functions can set InOutRes on errors
  142. ****************************************************************************}
  143. { close a file from the handle value }
  144. procedure do_close(handle : longint);
  145. begin
  146. InOutRes:=1;
  147. end;
  148. procedure do_erase(p : pchar);
  149. begin
  150. InOutRes:=1;
  151. end;
  152. procedure do_rename(p1,p2 : pchar);
  153. begin
  154. InOutRes:=1;
  155. end;
  156. function do_write(h,addr,len : longint) : longint;
  157. begin
  158. InOutRes:=1;
  159. end;
  160. function do_read(h,addr,len : longint) : longint;
  161. begin
  162. InOutRes:=1;
  163. end;
  164. function do_filepos(handle : longint) : longint;
  165. begin
  166. InOutRes:=1;
  167. end;
  168. procedure do_seek(handle,pos : longint);
  169. begin
  170. InOutRes:=1;
  171. end;
  172. function do_seekend(handle:longint):longint;
  173. begin
  174. InOutRes:=1;
  175. end;
  176. function do_filesize(handle : longint) : longint;
  177. begin
  178. InOutRes:=1;
  179. end;
  180. { truncate at a given position }
  181. procedure do_truncate (handle,pos:longint);
  182. begin
  183. InOutRes:=1;
  184. end;
  185. procedure do_open(var f;p:pchar;flags:longint);
  186. {
  187. filerec and textrec have both handle and mode as the first items so
  188. they could use the same routine for opening/creating.
  189. when (flags and $10) the file will be append
  190. when (flags and $100) the file will be truncate/rewritten
  191. when (flags and $1000) there is no check for close (needed for textfiles)
  192. }
  193. begin
  194. InOutRes:=1;
  195. end;
  196. function do_isdevice(handle:longint):boolean;
  197. begin
  198. do_isdevice:=false;
  199. end;
  200. {*****************************************************************************
  201. UnTyped File Handling
  202. *****************************************************************************}
  203. {$i file.inc}
  204. {*****************************************************************************
  205. Typed File Handling
  206. *****************************************************************************}
  207. {$i typefile.inc}
  208. {*****************************************************************************
  209. Text File Handling
  210. *****************************************************************************}
  211. { should we consider #26 as the end of a file ? }
  212. {?? $DEFINE EOF_CTRLZ}
  213. {$i text.inc}
  214. {*****************************************************************************
  215. Directory Handling
  216. *****************************************************************************}
  217. procedure mkdir(const s : string);[IOCheck];
  218. begin
  219. InOutRes:=1;
  220. end;
  221. procedure rmdir(const s : string);[IOCheck];
  222. begin
  223. InOutRes:=1;
  224. end;
  225. procedure chdir(const s : string);[IOCheck];
  226. begin
  227. InOutRes:=1;
  228. end;
  229. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  230. begin
  231. InOutRes := 1;
  232. end;
  233. {*****************************************************************************
  234. SystemUnit Initialization
  235. *****************************************************************************}
  236. Begin
  237. if false then //To save it from the dead code stripper
  238. Debugger; //Included only to make it available for debugging
  239. { To be set if this is a GUI or console application }
  240. IsConsole := TRUE;
  241. { To be set if this is a library and not a program }
  242. IsLibrary := FALSE;
  243. StackBottom := SPtr - StackLength;
  244. ExitCode := 0;
  245. { Setup heap }
  246. theHeap:= NewPtr(theHeapSize);
  247. InitHeap;
  248. { Setup stdin, stdout and stderr }
  249. OpenStdIO(Input,fmInput,StdInputHandle);
  250. OpenStdIO(Output,fmOutput,StdOutputHandle);
  251. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  252. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  253. { Setup environment and arguments }
  254. Setup_Environment;
  255. Setup_Arguments;
  256. { Reset IO Error }
  257. InOutRes:=0;
  258. {$endif}
  259. End.
  260. {
  261. $Log$
  262. Revision 1.4 2002-11-28 10:58:02 olle
  263. + added support for rudimentary heap
  264. Revision 1.3 2002/10/23 15:29:09 olle
  265. + added switch MAC_SYS_RUNABLE
  266. + added include of system.h etc
  267. + added standard globals
  268. + added dummy hook procedures
  269. Revision 1.2 2002/10/10 19:44:05 florian
  270. * changes from Olle to compile/link a simple program
  271. Revision 1.1 2002/10/02 21:34:31 florian
  272. * first dummy implementation
  273. }