system.pp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. unit system;
  2. interface
  3. {$DEFINE FPC_NO_DEFAULT_HEAP}
  4. {$DEFINE FPC_INCLUDE_SOFTWARE_MUL}
  5. {$DEFINE FPC_INCLUDE_SOFTWARE_MOD_DIV}
  6. {$DEFINE FPC_USE_SMALL_DEFAULTSTACKSIZE}
  7. { To avoid warnings in thread.inc code,
  8. but value must be really given after
  9. systemh.inc is included otherwise the
  10. $mode switch is not effective }
  11. {$I systemh.inc}
  12. {$I tnyheaph.inc}
  13. const
  14. LineEnding = #13#10;
  15. { LFNSupport is a variable here, defined below!!! }
  16. DirectorySeparator = '\';
  17. DriveSeparator = ':';
  18. ExtensionSeparator = '.';
  19. PathSeparator = ';';
  20. AllowDirectorySeparators : set of char = ['\','/'];
  21. AllowDriveSeparators : set of char = [':'];
  22. { FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
  23. maxExitCode = 255;
  24. MaxPathLen = 256;
  25. const
  26. { Default filehandles }
  27. UnusedHandle = $ffff;{ instead of -1, as it is a word value}
  28. StdInputHandle = 0;
  29. StdOutputHandle = 1;
  30. StdErrorHandle = 2;
  31. FileNameCaseSensitive : boolean = false;
  32. FileNameCasePreserving: boolean = false;
  33. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  34. sLineBreak = LineEnding;
  35. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  36. { Default memory segments (Tp7 compatibility) }
  37. { seg0040: Word = $0040;
  38. segA000: Word = $A000;
  39. segB000: Word = $B000;
  40. segB800: Word = $B800;}
  41. { The value that needs to be added to the segment to move the pointer by
  42. 64K bytes (BP7 compatibility) }
  43. SelectorInc: Word = $1000;
  44. var
  45. { Mem[] support }
  46. mem : array[0..$7fff-1] of byte absolute $0:$0;
  47. memw : array[0..($7fff div sizeof(word))-1] of word absolute $0:$0;
  48. meml : array[0..($7fff div sizeof(longint))-1] of longint absolute $0:$0;
  49. { C-compatible arguments and environment }
  50. argc:longint; //!! public name 'operatingsystem_parameter_argc';
  51. argv:PPchar; //!! public name 'operatingsystem_parameter_argv';
  52. envp:PPchar; //!! public name 'operatingsystem_parameter_envp';
  53. dos_argv0 : pchar; //!! public name 'dos_argv0';
  54. { The DOS Program Segment Prefix segment (TP7 compatibility) }
  55. PrefixSeg:Word;public name '__fpc_PrefixSeg';
  56. { SaveInt00: FarPointer;public name '__SaveInt00';}
  57. AllFilesMask: string [3];
  58. {$ifndef RTLLITE}
  59. { System info }
  60. LFNSupport : boolean;
  61. {$ELSE RTLLITE}
  62. const
  63. LFNSupport = false;
  64. {$endif RTLLITE}
  65. procedure InitTask;external 'KERNEL';
  66. procedure WaitEvent;external 'KERNEL';
  67. procedure InitApp;external 'USER';
  68. procedure MessageBox(hWnd: word; lpText, lpCaption: PChar; uType: word);external 'USER';
  69. implementation
  70. const
  71. fCarry = 1;
  72. { used for an offset fixup for accessing the proc parameters in asm routines
  73. that use nostackframe. We can't use the parameter name directly, because
  74. i8086 doesn't support sp relative addressing. }
  75. {$ifdef FPC_X86_CODE_FAR}
  76. extra_param_offset = 2;
  77. {$else FPC_X86_CODE_FAR}
  78. extra_param_offset = 0;
  79. {$endif FPC_X86_CODE_FAR}
  80. {$if defined(FPC_X86_DATA_FAR) or defined(FPC_X86_DATA_HUGE)}
  81. extra_data_offset = 2;
  82. {$else}
  83. extra_data_offset = 0;
  84. {$endif}
  85. type
  86. PFarByte = ^Byte;far;
  87. PFarChar = ^Char;far;
  88. PFarWord = ^Word;far;
  89. {$I registers.inc}
  90. {$I system.inc}
  91. {$I tinyheap.inc}
  92. {procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS'];compilerproc;
  93. begin
  94. MessageBox(0, 'Hello, world!', 'yo', 0);
  95. end;}
  96. {procedure fpc_do_exit;[public,alias:'FPC_DO_EXIT'];compilerproc;
  97. begin
  98. asm
  99. mov ax, 4c00h
  100. int 21h
  101. end;
  102. end;}
  103. {*****************************************************************************
  104. ParamStr/Randomize
  105. *****************************************************************************}
  106. {function GetProgramName: string;
  107. var
  108. dos_env_seg: Word;
  109. ofs: Word;
  110. Ch, Ch2: Char;
  111. begin
  112. if dos_version < $300 then
  113. begin
  114. GetProgramName := '';
  115. exit;
  116. end;
  117. dos_env_seg := PFarWord(Ptr(PrefixSeg, $2C))^;
  118. ofs := 1;
  119. repeat
  120. Ch := PFarChar(Ptr(dos_env_seg,ofs - 1))^;
  121. Ch2 := PFarChar(Ptr(dos_env_seg,ofs))^;
  122. if (Ch = #0) and (Ch2 = #0) then
  123. begin
  124. Inc(ofs, 3);
  125. GetProgramName := '';
  126. repeat
  127. Ch := PFarChar(Ptr(dos_env_seg,ofs))^;
  128. if Ch <> #0 then
  129. GetProgramName := GetProgramName + Ch;
  130. Inc(ofs);
  131. if ofs = 0 then
  132. begin
  133. GetProgramName := '';
  134. exit;
  135. end;
  136. until Ch = #0;
  137. exit;
  138. end;
  139. Inc(ofs);
  140. if ofs = 0 then
  141. begin
  142. GetProgramName := '';
  143. exit;
  144. end;
  145. until false;
  146. end;}
  147. {function GetCommandLine: string;
  148. var
  149. len, I: Integer;
  150. begin
  151. len := PFarByte(Ptr(PrefixSeg, $80))^;
  152. SetLength(GetCommandLine, len);
  153. for I := 1 to len do
  154. GetCommandLine[I] := PFarChar(Ptr(PrefixSeg, $80 + I))^;
  155. end;}
  156. {function GetArg(ArgNo: Integer; out ArgResult: string): Integer;
  157. var
  158. cmdln: string;
  159. I: Integer;
  160. InArg: Boolean;
  161. begin
  162. cmdln := GetCommandLine;
  163. ArgResult := '';
  164. I := 1;
  165. InArg := False;
  166. GetArg := 0;
  167. for I := 1 to Length(cmdln) do
  168. begin
  169. if not InArg and (cmdln[I] <> ' ') then
  170. begin
  171. InArg := True;
  172. Inc(GetArg);
  173. end;
  174. if InArg and (cmdln[I] = ' ') then
  175. InArg := False;
  176. if InArg and (GetArg = ArgNo) then
  177. ArgResult := ArgResult + cmdln[I];
  178. end;
  179. end;}
  180. function paramcount : longint;
  181. {var
  182. tmpstr: string;}
  183. begin
  184. { paramcount := GetArg(-1, tmpstr);}
  185. paramcount:=0;
  186. end;
  187. function paramstr(l : longint) : string;
  188. begin
  189. { if l = 0 then
  190. paramstr := GetProgramName
  191. else
  192. GetArg(l, paramstr);}
  193. paramstr:='';
  194. end;
  195. procedure randomize;
  196. {var
  197. hl : longint;
  198. regs : Registers;}
  199. begin
  200. { regs.AH:=$2C;
  201. MsDos(regs);
  202. hl:=regs.DX;
  203. randseed:=hl*$10000+ regs.CX;}
  204. end;
  205. {*****************************************************************************
  206. System Dependent Exit code
  207. *****************************************************************************}
  208. procedure system_exit;
  209. {var
  210. h : byte;}
  211. begin
  212. (* RestoreInterruptHandlers;
  213. for h:=0 to max_files-1 do
  214. if openfiles[h] then
  215. begin
  216. {$ifdef SYSTEMDEBUG}
  217. writeln(stderr,'file ',opennames[h],' not closed at exit');
  218. {$endif SYSTEMDEBUG}
  219. if h>=5 then
  220. do_close(h);
  221. end;
  222. {$ifndef FPC_MM_TINY}
  223. if not CheckNullArea then
  224. writeln(stderr, 'Nil pointer assignment');
  225. {$endif FPC_MM_TINY}*)
  226. asm
  227. mov al, byte [exitcode]
  228. mov ah, 4Ch
  229. int 21h
  230. end;
  231. end;
  232. {*****************************************************************************
  233. SystemUnit Initialization
  234. *****************************************************************************}
  235. procedure SysInitStdIO;
  236. begin
  237. OpenStdIO(Input,fmInput,StdInputHandle);
  238. OpenStdIO(Output,fmOutput,StdOutputHandle);
  239. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  240. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  241. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  242. end;
  243. function GetProcessID: SizeUInt;
  244. begin
  245. GetProcessID := PrefixSeg;
  246. end;
  247. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  248. begin
  249. result := stklen;
  250. end;
  251. begin
  252. MessageBox(0, 'Hello, world!', 'yo', 0);
  253. end.