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