system.pp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. {$I system.inc}
  97. {$I tinyheap.inc}
  98. {procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS'];compilerproc;
  99. begin
  100. MessageBox(0, 'Hello, world!', 'yo', 0);
  101. end;}
  102. {procedure fpc_do_exit;[public,alias:'FPC_DO_EXIT'];compilerproc;
  103. begin
  104. asm
  105. mov ax, 4c00h
  106. int 21h
  107. end;
  108. end;}
  109. {*****************************************************************************
  110. ParamStr/Randomize
  111. *****************************************************************************}
  112. {function GetProgramName: string;
  113. var
  114. dos_env_seg: Word;
  115. ofs: Word;
  116. Ch, Ch2: Char;
  117. begin
  118. if dos_version < $300 then
  119. begin
  120. GetProgramName := '';
  121. exit;
  122. end;
  123. dos_env_seg := PFarWord(Ptr(PrefixSeg, $2C))^;
  124. ofs := 1;
  125. repeat
  126. Ch := PFarChar(Ptr(dos_env_seg,ofs - 1))^;
  127. Ch2 := PFarChar(Ptr(dos_env_seg,ofs))^;
  128. if (Ch = #0) and (Ch2 = #0) then
  129. begin
  130. Inc(ofs, 3);
  131. GetProgramName := '';
  132. repeat
  133. Ch := PFarChar(Ptr(dos_env_seg,ofs))^;
  134. if Ch <> #0 then
  135. GetProgramName := GetProgramName + Ch;
  136. Inc(ofs);
  137. if ofs = 0 then
  138. begin
  139. GetProgramName := '';
  140. exit;
  141. end;
  142. until Ch = #0;
  143. exit;
  144. end;
  145. Inc(ofs);
  146. if ofs = 0 then
  147. begin
  148. GetProgramName := '';
  149. exit;
  150. end;
  151. until false;
  152. end;}
  153. function GetArg(ArgNo: Integer; out ArgResult: string): Integer;
  154. var
  155. I: Integer;
  156. InArg: Boolean;
  157. begin
  158. ArgResult := '';
  159. I := 0;
  160. InArg := False;
  161. GetArg := 0;
  162. while CmdLine[I]<>#0 do
  163. begin
  164. if not InArg and (CmdLine[I] <> ' ') then
  165. begin
  166. InArg := True;
  167. Inc(GetArg);
  168. end;
  169. if InArg and (CmdLine[I] = ' ') then
  170. InArg := False;
  171. if InArg and (GetArg = ArgNo) then
  172. ArgResult := ArgResult + CmdLine[I];
  173. Inc(I);
  174. end;
  175. end;
  176. function paramcount : longint;
  177. var
  178. tmpstr: string;
  179. begin
  180. paramcount := GetArg(-1, tmpstr);
  181. end;
  182. function paramstr(l : longint) : string;
  183. begin
  184. if l = 0 then
  185. paramstr := ''{GetProgramName}
  186. else
  187. GetArg(l, paramstr);
  188. end;
  189. procedure randomize;
  190. {var
  191. hl : longint;
  192. regs : Registers;}
  193. begin
  194. { regs.AH:=$2C;
  195. MsDos(regs);
  196. hl:=regs.DX;
  197. randseed:=hl*$10000+ regs.CX;}
  198. end;
  199. {*****************************************************************************
  200. System Dependent Exit code
  201. *****************************************************************************}
  202. procedure system_exit;
  203. {var
  204. h : byte;}
  205. begin
  206. (* RestoreInterruptHandlers;
  207. for h:=0 to max_files-1 do
  208. if openfiles[h] then
  209. begin
  210. {$ifdef SYSTEMDEBUG}
  211. writeln(stderr,'file ',opennames[h],' not closed at exit');
  212. {$endif SYSTEMDEBUG}
  213. if h>=5 then
  214. do_close(h);
  215. end;
  216. {$ifndef FPC_MM_TINY}
  217. if not CheckNullArea then
  218. writeln(stderr, 'Nil pointer assignment');
  219. {$endif FPC_MM_TINY}*)
  220. asm
  221. mov al, byte [exitcode]
  222. mov ah, 4Ch
  223. int 21h
  224. end;
  225. end;
  226. {*****************************************************************************
  227. SystemUnit Initialization
  228. *****************************************************************************}
  229. procedure SysInitStdIO;
  230. begin
  231. OpenStdIO(Input,fmInput,StdInputHandle);
  232. OpenStdIO(Output,fmOutput,StdOutputHandle);
  233. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  234. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  235. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  236. end;
  237. function GetProcessID: SizeUInt;
  238. begin
  239. GetProcessID := PrefixSeg;
  240. end;
  241. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  242. begin
  243. result := stklen;
  244. end;
  245. begin
  246. MessageBox(0, 'Hello, world!', 'yo', 0);
  247. end.