system.pp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. begin
  110. asm
  111. mov al, byte [exitcode]
  112. mov ah, 4Ch
  113. int 21h
  114. end;
  115. end;
  116. {*****************************************************************************
  117. SystemUnit Initialization
  118. *****************************************************************************}
  119. procedure InitNearHeap;
  120. begin
  121. SetMemoryManager(NearHeapMemoryManager);
  122. RegisterNearHeapBlock(__nearheap_start, ptruint(__nearheap_end) - ptruint(__nearheap_start));
  123. end;
  124. function CheckLFN:boolean;
  125. var
  126. regs : Registers;
  127. RootName : pchar;
  128. buf : array [0..31] of char;
  129. begin
  130. { Check LFN API on drive c:\ }
  131. RootName:='C:\';
  132. { Call 'Get Volume Information' ($71A0) }
  133. regs.AX:=$71a0;
  134. regs.ES:=Seg(buf);
  135. regs.DI:=Ofs(buf);
  136. regs.CX:=32;
  137. regs.DS:=Seg(RootName^);
  138. regs.DX:=Ofs(RootName^);
  139. MsDos_Carry(regs);
  140. { If carryflag=0 and LFN API bit in ebx is set then use Long file names }
  141. CheckLFN:=(regs.Flags and fCarry=0) and (regs.BX and $4000=$4000);
  142. end;
  143. procedure SysInitStdIO;
  144. begin
  145. OpenStdIO(Input,fmInput,StdInputHandle);
  146. OpenStdIO(Output,fmOutput,StdOutputHandle);
  147. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  148. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  149. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  150. end;
  151. function GetProcessID: SizeUInt;
  152. begin
  153. GetProcessID := dos_psp;
  154. end;
  155. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  156. begin
  157. result := stklen;
  158. end;
  159. begin
  160. StackLength := CheckInitialStkLen(InitialStkLen);
  161. StackBottom := __stkbottom;
  162. { To be set if this is a GUI or console application }
  163. IsConsole := TRUE;
  164. { To be set if this is a library and not a program }
  165. IsLibrary := FALSE;
  166. { Setup heap }
  167. InitNearHeap;
  168. SysInitExceptions;
  169. initunicodestringmanager;
  170. { Setup stdin, stdout and stderr }
  171. SysInitStdIO;
  172. { Use LFNSupport LFN }
  173. LFNSupport:=CheckLFN;
  174. if LFNSupport then
  175. begin
  176. FileNameCasePreserving:=true;
  177. AllFilesMask := '*';
  178. end
  179. else
  180. AllFilesMask := '*.*';
  181. { Reset IO Error }
  182. InOutRes:=0;
  183. initvariantmanager;
  184. end.