system.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. unit system;
  2. {$ASMMODE intel}
  3. interface
  4. {$DEFINE FPC_INCLUDE_SOFTWARE_MUL}
  5. {$DEFINE FPC_INCLUDE_SOFTWARE_MOD_DIV}
  6. {$I systemh.inc}
  7. const
  8. LineEnding = #13#10;
  9. { LFNSupport is a variable here, defined below!!! }
  10. DirectorySeparator = '\';
  11. DriveSeparator = ':';
  12. ExtensionSeparator = '.';
  13. PathSeparator = ';';
  14. AllowDirectorySeparators : set of char = ['\','/'];
  15. AllowDriveSeparators : set of char = [':'];
  16. { FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
  17. maxExitCode = 255;
  18. MaxPathLen = 256;
  19. const
  20. { Default filehandles }
  21. UnusedHandle = -1;
  22. StdInputHandle = 0;
  23. StdOutputHandle = 1;
  24. StdErrorHandle = 2;
  25. FileNameCaseSensitive : boolean = false;
  26. FileNameCasePreserving: boolean = false;
  27. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  28. sLineBreak = LineEnding;
  29. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  30. { Default memory segments (Tp7 compatibility) }
  31. seg0040 = $0040;
  32. segA000 = $A000;
  33. segB000 = $B000;
  34. segB800 = $B800;
  35. var
  36. { Mem[] support }
  37. mem : array[0..$7fff-1] of byte absolute $0:$0;
  38. memw : array[0..($7fff div sizeof(word))-1] of word absolute $0:$0;
  39. meml : array[0..($7fff div sizeof(longint))-1] of longint absolute $0:$0;
  40. { C-compatible arguments and environment }
  41. argc:longint; //!! public name 'operatingsystem_parameter_argc';
  42. argv:PPchar; //!! public name 'operatingsystem_parameter_argv';
  43. envp:PPchar; //!! public name 'operatingsystem_parameter_envp';
  44. dos_argv0 : pchar; //!! public name 'dos_argv0';
  45. dos_psp:Word;public name 'dos_psp';
  46. __stkbottom : pointer;public name '__stkbottom';
  47. __nearheap_start: pointer;public name '__nearheap_start';
  48. __nearheap_end: pointer;public name '__nearheap_end';
  49. AllFilesMask: string [3];
  50. {$ifndef RTLLITE}
  51. { System info }
  52. LFNSupport : boolean;
  53. {$ELSE RTLLITE}
  54. const
  55. LFNSupport = false;
  56. {$endif RTLLITE}
  57. procedure DebugWrite(const S: string);
  58. procedure DebugWriteLn(const S: string);
  59. implementation
  60. const
  61. fCarry = 1;
  62. {$I registers.inc}
  63. procedure Intr(IntNo: Byte; var Regs: Registers); external name 'FPC_INTR';
  64. procedure MsDos(var Regs: Registers); external name 'FPC_MSDOS';
  65. { invokes int 21h with the carry flag set on entry; used for the LFN functions
  66. to ensure that the carry flag is set on exit on older DOS versions which don't
  67. support them }
  68. procedure MsDos_Carry(var Regs: Registers); external name 'FPC_MSDOS_CARRY';
  69. {$I system.inc}
  70. {$I nearheap.inc}
  71. procedure DebugWrite(const S: string);
  72. begin
  73. asm
  74. mov si, S
  75. lodsb
  76. mov cl, al
  77. xor ch, ch
  78. mov ah, 2
  79. @@1:
  80. lodsb
  81. mov dl, al
  82. int 21h
  83. loop @@1
  84. end ['ax','bx','cx','dx','si','di'];
  85. end;
  86. procedure DebugWriteLn(const S: string);
  87. begin
  88. DebugWrite(S);
  89. DebugWrite(#13#10);
  90. end;
  91. {*****************************************************************************
  92. ParamStr/Randomize
  93. *****************************************************************************}
  94. function paramcount : longint;
  95. begin
  96. paramcount := 0;
  97. end;
  98. function paramstr(l : longint) : string;
  99. begin
  100. paramstr := '';
  101. end;
  102. procedure randomize;
  103. begin
  104. end;
  105. {*****************************************************************************
  106. System Dependent Exit code
  107. *****************************************************************************}
  108. procedure system_exit;
  109. var
  110. h : byte;
  111. begin
  112. for h:=0 to max_files-1 do
  113. if openfiles[h] then
  114. begin
  115. {$ifdef SYSTEMDEBUG}
  116. writeln(stderr,'file ',opennames[h],' not closed at exit');
  117. {$endif SYSTEMDEBUG}
  118. if h>=5 then
  119. do_close(h);
  120. end;
  121. asm
  122. mov al, byte [exitcode]
  123. mov ah, 4Ch
  124. int 21h
  125. end;
  126. end;
  127. {*****************************************************************************
  128. SystemUnit Initialization
  129. *****************************************************************************}
  130. procedure InitNearHeap;
  131. begin
  132. SetMemoryManager(NearHeapMemoryManager);
  133. RegisterNearHeapBlock(__nearheap_start, ptruint(__nearheap_end) - ptruint(__nearheap_start));
  134. end;
  135. function CheckLFN:boolean;
  136. var
  137. regs : Registers;
  138. RootName : pchar;
  139. buf : array [0..31] of char;
  140. begin
  141. { Check LFN API on drive c:\ }
  142. RootName:='C:\';
  143. { Call 'Get Volume Information' ($71A0) }
  144. regs.AX:=$71a0;
  145. regs.ES:=Seg(buf);
  146. regs.DI:=Ofs(buf);
  147. regs.CX:=32;
  148. regs.DS:=Seg(RootName^);
  149. regs.DX:=Ofs(RootName^);
  150. MsDos_Carry(regs);
  151. { If carryflag=0 and LFN API bit in ebx is set then use Long file names }
  152. CheckLFN:=(regs.Flags and fCarry=0) and (regs.BX and $4000=$4000);
  153. end;
  154. procedure SysInitStdIO;
  155. begin
  156. OpenStdIO(Input,fmInput,StdInputHandle);
  157. OpenStdIO(Output,fmOutput,StdOutputHandle);
  158. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  159. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  160. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  161. end;
  162. function GetProcessID: SizeUInt;
  163. begin
  164. GetProcessID := dos_psp;
  165. end;
  166. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  167. begin
  168. result := stklen;
  169. end;
  170. begin
  171. StackLength := CheckInitialStkLen(InitialStkLen);
  172. StackBottom := __stkbottom;
  173. { To be set if this is a GUI or console application }
  174. IsConsole := TRUE;
  175. { To be set if this is a library and not a program }
  176. IsLibrary := FALSE;
  177. { Setup heap }
  178. InitNearHeap;
  179. SysInitExceptions;
  180. initunicodestringmanager;
  181. { Setup stdin, stdout and stderr }
  182. SysInitStdIO;
  183. { Use LFNSupport LFN }
  184. LFNSupport:=CheckLFN;
  185. if LFNSupport then
  186. begin
  187. FileNameCasePreserving:=true;
  188. AllFilesMask := '*';
  189. end
  190. else
  191. AllFilesMask := '*.*';
  192. { Reset IO Error }
  193. InOutRes:=0;
  194. initvariantmanager;
  195. end.