system.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by Francesco Lombardi.
  4. System unit for Nintendo DS
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit System;
  12. interface
  13. {$define FPC_IS_SYSTEM}
  14. {$define FPC_HAS_FEATURE_THREADING}
  15. {$define FPC_HAS_FEATURE_CONSOLEIO}
  16. {$define FPC_HAS_FEATURE_COMMANDARGS}
  17. {$define FPC_HAS_FEATURE_TEXTIO}
  18. {$define FPC_HAS_FEATURE_FILEIO}
  19. {$i systemh.inc}
  20. {$i ndsbiosh.inc}
  21. {$i ndsh.inc}
  22. {$i libch.inc}
  23. {$define fpc_softfpu_interface}
  24. {$i softfpu.pp}
  25. {$undef fpc_softfpu_interface}
  26. const
  27. LineEnding = #10;
  28. LFNSupport = true;
  29. CtrlZMarksEOF: boolean = false;
  30. DirectorySeparator = '/';
  31. DriveSeparator = ':';
  32. ExtensionSeparator = '.';
  33. PathSeparator = ';';
  34. AllowDirectorySeparators : set of char = ['\','/'];
  35. AllowDriveSeparators : set of char = [':'];
  36. FileNameCaseSensitive = false;
  37. maxExitCode = 255;
  38. MaxPathLen = 255;
  39. AllFilesMask = '*';
  40. sLineBreak: string[1] = LineEnding;
  41. DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
  42. UnusedHandle = $ffff;
  43. StdInputHandle = 0;
  44. StdOutputHandle = 1;
  45. StdErrorHandle = $ffff;
  46. var
  47. argc: LongInt = 0;
  48. argv: PPChar;
  49. envp: PPChar;
  50. // errno: integer;
  51. fake_heap_end: ^byte; cvar; external;
  52. irq_vector: integer; external name '__irq_vector';
  53. //procedure AssignDevice(FIOD: Pointer);
  54. implementation
  55. {$define fpc_softfpu_implementation}
  56. {$i softfpu.pp}
  57. {$undef fpc_softfpu_implementation}
  58. { we get these functions and types from the softfpu code }
  59. {$define FPC_SYSTEM_HAS_float64}
  60. {$define FPC_SYSTEM_HAS_float32}
  61. {$define FPC_SYSTEM_HAS_flag}
  62. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  63. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  64. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  65. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  66. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  67. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  68. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  69. {$i system.inc}
  70. {$i ndsbios.inc}
  71. {$i nds.inc}
  72. {$i libc.inc}
  73. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  74. function GetProcessID: SizeUInt;
  75. begin
  76. GetProcessID := 0;
  77. end;
  78. {$endif}
  79. {*****************************************************************************
  80. Misc. System Dependent Functions
  81. *****************************************************************************}
  82. procedure System_exit;
  83. begin
  84. // Boo!
  85. end;
  86. {*****************************************************************************
  87. ParamStr/Randomize
  88. *****************************************************************************}
  89. const
  90. QRAN_SHIFT = 15;
  91. QRAN_MASK = ((1 shl QRAN_SHIFT) - 1);
  92. QRAN_MAX = QRAN_MASK;
  93. QRAN_A = 1664525;
  94. QRAN_C = 1013904223;
  95. { set randseed to a new pseudo random value }
  96. procedure randomize;
  97. var
  98. IPC_Timer: array [0..2] of byte absolute $27FF01B;
  99. begin
  100. RandSeed := (IPC_Timer[0] * 3600) + (IPC_Timer[1] * 60) + IPC_Timer[2];
  101. end;
  102. function random(): integer;
  103. begin
  104. RandSeed := QRAN_A * RandSeed + QRAN_C;
  105. random := (RandSeed shr 16) and QRAN_MAX;
  106. end;
  107. function random(value: integer): integer;
  108. var
  109. a: integer;
  110. begin
  111. RandSeed := QRAN_A * RandSeed + QRAN_C;
  112. a := (RandSeed shr 16) and QRAN_MAX;
  113. random := (a * value) shr 15;
  114. end;
  115. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  116. { number of args }
  117. function paramcount : longint;
  118. begin
  119. paramcount := 0;
  120. end;
  121. { argument number l }
  122. function paramstr(l : longint) : string;
  123. begin
  124. paramstr := '';
  125. end;
  126. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  127. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  128. procedure SysInitStdIO;
  129. begin
  130. OpenStdIO(Input,fmInput,StdInputHandle);
  131. OpenStdIO(Output,fmOutput,StdOutputHandle);
  132. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  133. end;
  134. {$endif}
  135. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  136. begin
  137. result := stklen;
  138. end;
  139. begin
  140. StackLength := CheckInitialStkLen(InitialStkLen);
  141. StackBottom := StackTop - StackLength;
  142. { OS specific startup }
  143. { Set up signals handlers }
  144. fpc_cpucodeinit;
  145. { Setup heap }
  146. InitHeap;
  147. SysInitExceptions;
  148. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  149. { Setup stdin, stdout and stderr }
  150. SysInitStdIO;
  151. { Reset IO Error }
  152. InOutRes:=0;
  153. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  154. { Arguments }
  155. {$ifdef FPC_HAS_FEATURE_THREADING}
  156. { threading }
  157. InitSystemThreads;
  158. {$endif FPC_HAS_FEATURE_THREADING}
  159. initvariantmanager;
  160. end.