system.pp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 ndsbiosh.inc}
  20. {$i systemh.inc}
  21. {$define fpc_softfpu_interface}
  22. {$i softfpu.pp}
  23. {$undef fpc_softfpu_interface}
  24. function IsARM9(): boolean;
  25. const
  26. LineEnding = #10;
  27. LFNSupport = true;
  28. CtrlZMarksEOF: boolean = false;
  29. DirectorySeparator = '/';
  30. DriveSeparator = ':';
  31. ExtensionSeparator = '.';
  32. PathSeparator = ';';
  33. AllowDirectorySeparators : set of char = ['\','/'];
  34. AllowDriveSeparators : set of char = [':'];
  35. FileNameCaseSensitive = false;
  36. maxExitCode = 255;
  37. MaxPathLen = 255;
  38. AllFilesMask = '*';
  39. sLineBreak: string[1] = LineEnding;
  40. DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
  41. UnusedHandle = $ffff;
  42. StdInputHandle = 0;
  43. StdOutputHandle = 1;
  44. StdErrorHandle = $ffff;
  45. var
  46. argc: LongInt = 0;
  47. argv: PPChar;
  48. envp: PPChar;
  49. errno: integer;
  50. fake_heap_end: ^byte; cvar; external;
  51. irq_vector: integer; external name '__irq_vector';
  52. implementation
  53. {$define fpc_softfpu_implementation}
  54. {$i softfpu.pp}
  55. {$undef fpc_softfpu_implementation}
  56. { we get these functions and types from the softfpu code }
  57. {$define FPC_SYSTEM_HAS_float64}
  58. {$define FPC_SYSTEM_HAS_float32}
  59. {$define FPC_SYSTEM_HAS_flag}
  60. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  61. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  62. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  63. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  64. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  65. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  66. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  67. {$i system.inc}
  68. {$i ndsbios.inc}
  69. {
  70. NDS CPU detecting function
  71. --------------------------
  72. ARM946E-S processor can handle dsp extensions, but ARM7TDMI does not. FPC can
  73. detect dsp by catching a SIGILL that fires when ARM7 cpu tries to use a dsp
  74. command. Unfortunately, NDS' rtl does not have any error catching mechanism.
  75. This function takes care to check if the code is running on an ARM9 or on an
  76. ARM7 CPU, by checking the IRQ vector address ($0B003FFC for ARM9, 0380fff8
  77. for ARM7), declared in the linker script. This function is cleaner than the
  78. older one, because does not raise any memory writing error.
  79. It works on Nintendo DS only, I guess :)
  80. }
  81. function IsARM9(): boolean;
  82. begin
  83. IsARM9 := integer(@irq_vector) = $0B003FFC;
  84. end;
  85. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  86. function GetProcessID: SizeUInt;
  87. begin
  88. GetProcessID := 0;
  89. end;
  90. {$endif}
  91. {*****************************************************************************
  92. Misc. System Dependent Functions
  93. *****************************************************************************}
  94. procedure System_exit;
  95. begin
  96. // Boo!
  97. end;
  98. {*****************************************************************************
  99. ParamStr/Randomize
  100. *****************************************************************************}
  101. const
  102. QRAN_SHIFT = 15;
  103. QRAN_MASK = ((1 shl QRAN_SHIFT) - 1);
  104. QRAN_MAX = QRAN_MASK;
  105. QRAN_A = 1664525;
  106. QRAN_C = 1013904223;
  107. { set randseed to a new pseudo random value }
  108. procedure randomize;
  109. var
  110. IPC_Timer: array [0..2] of byte absolute $27FF01B;
  111. begin
  112. RandSeed := (IPC_Timer[0] * 3600) + (IPC_Timer[1] * 60) + IPC_Timer[2];
  113. end;
  114. function random(): integer;
  115. begin
  116. RandSeed := QRAN_A * RandSeed + QRAN_C;
  117. random := (RandSeed shr 16) and QRAN_MAX;
  118. end;
  119. function random(value: integer): integer;
  120. var
  121. a: integer;
  122. begin
  123. RandSeed := QRAN_A * RandSeed + QRAN_C;
  124. a := (RandSeed shr 16) and QRAN_MAX;
  125. random := (a * value) shr 15;
  126. end;
  127. {$ifdef FPC_HAS_FEATURE_COMMANDARGS}
  128. { number of args }
  129. function paramcount : longint;
  130. begin
  131. paramcount := 0;
  132. end;
  133. { argument number l }
  134. function paramstr(l : longint) : string;
  135. begin
  136. paramstr := '';
  137. end;
  138. {$endif FPC_HAS_FEATURE_COMMANDARGS}
  139. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  140. procedure SysInitStdIO;
  141. begin
  142. OpenStdIO(Input,fmInput,StdInputHandle);
  143. OpenStdIO(Output,fmOutput,StdOutputHandle);
  144. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  145. end;
  146. {$endif}
  147. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  148. begin
  149. result := stklen;
  150. end;
  151. begin
  152. StackLength := CheckInitialStkLen(InitialStkLen);
  153. StackBottom := StackTop - StackLength;
  154. { OS specific startup }
  155. { Set up signals handlers }
  156. if IsARM9 then
  157. fpc_cpucodeinit;
  158. { Setup heap }
  159. InitHeap;
  160. SysInitExceptions;
  161. {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
  162. { Setup stdin, stdout and stderr }
  163. SysInitStdIO;
  164. { Reset IO Error }
  165. InOutRes:=0;
  166. {$endif FPC_HAS_FEATURE_CONSOLEIO}
  167. { Arguments }
  168. {$ifdef FPC_HAS_FEATURE_THREADING}
  169. { threading }
  170. InitSystemThreads;
  171. {$endif FPC_HAS_FEATURE_THREADING}
  172. initvariantmanager;
  173. end.