system.pp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. AllFilesMask: string [3];
  48. {$ifndef RTLLITE}
  49. { System info }
  50. LFNSupport : boolean;
  51. {$ELSE RTLLITE}
  52. const
  53. LFNSupport = false;
  54. {$endif RTLLITE}
  55. procedure DebugWrite(const S: string);
  56. procedure DebugWriteLn(const S: string);
  57. implementation
  58. const
  59. fCarry = 1;
  60. {$I registers.inc}
  61. procedure Intr(IntNo: Byte; var Regs: Registers); external name 'FPC_INTR';
  62. procedure MsDos(var Regs: Registers); external name 'FPC_MSDOS';
  63. { invokes int 21h with the carry flag set on entry; used for the LFN functions
  64. to ensure that the carry flag is set on exit on older DOS versions which don't
  65. support them }
  66. procedure MsDos_Carry(var Regs: Registers); external name 'FPC_MSDOS_CARRY';
  67. {$I system.inc}
  68. procedure DebugWrite(const S: string);
  69. begin
  70. asm
  71. mov si, S
  72. lodsb
  73. mov cl, al
  74. xor ch, ch
  75. mov ah, 2
  76. @@1:
  77. lodsb
  78. mov dl, al
  79. int 21h
  80. loop @@1
  81. end ['ax','bx','cx','dx','si','di'];
  82. end;
  83. procedure DebugWriteLn(const S: string);
  84. begin
  85. DebugWrite(S);
  86. DebugWrite(#13#10);
  87. end;
  88. {*****************************************************************************
  89. ParamStr/Randomize
  90. *****************************************************************************}
  91. function paramcount : longint;
  92. begin
  93. paramcount := 0;
  94. end;
  95. function paramstr(l : longint) : string;
  96. begin
  97. paramstr := '';
  98. end;
  99. procedure randomize;
  100. begin
  101. end;
  102. {*****************************************************************************
  103. System Dependent Exit code
  104. *****************************************************************************}
  105. procedure system_exit;
  106. begin
  107. asm
  108. mov al, byte [exitcode]
  109. mov ah, 4Ch
  110. int 21h
  111. end;
  112. end;
  113. {*****************************************************************************
  114. SystemUnit Initialization
  115. *****************************************************************************}
  116. function CheckLFN:boolean;
  117. var
  118. regs : Registers;
  119. RootName : pchar;
  120. buf : array [0..31] of char;
  121. begin
  122. { Check LFN API on drive c:\ }
  123. RootName:='C:\';
  124. { Call 'Get Volume Information' ($71A0) }
  125. regs.AX:=$71a0;
  126. regs.ES:=DSeg;
  127. regs.DI:=Word(@buf);
  128. regs.CX:=32;
  129. regs.DS:=DSeg;
  130. regs.DX:=Word(RootName);
  131. MsDos_Carry(regs);
  132. { If carryflag=0 and LFN API bit in ebx is set then use Long file names }
  133. CheckLFN:=(regs.Flags and fCarry=0) and (regs.BX and $4000=$4000);
  134. end;
  135. procedure SysInitStdIO;
  136. begin
  137. OpenStdIO(Input,fmInput,StdInputHandle);
  138. OpenStdIO(Output,fmOutput,StdOutputHandle);
  139. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  140. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  141. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  142. end;
  143. function GetProcessID: SizeUInt;
  144. begin
  145. GetProcessID := dos_psp;
  146. end;
  147. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  148. begin
  149. result := stklen;
  150. end;
  151. begin
  152. StackLength := CheckInitialStkLen(InitialStkLen);
  153. StackBottom := __stkbottom;
  154. { To be set if this is a GUI or console application }
  155. IsConsole := TRUE;
  156. { To be set if this is a library and not a program }
  157. IsLibrary := FALSE;
  158. SysInitExceptions;
  159. initunicodestringmanager;
  160. { Setup stdin, stdout and stderr }
  161. SysInitStdIO;
  162. { Use LFNSupport LFN }
  163. LFNSupport:=CheckLFN;
  164. if LFNSupport then
  165. begin
  166. FileNameCasePreserving:=true;
  167. AllFilesMask := '*';
  168. end
  169. else
  170. AllFilesMask := '*.*';
  171. { Reset IO Error }
  172. InOutRes:=0;
  173. end.