system.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. {$i ndsbiosh.inc}
  15. {$i systemh.inc}
  16. {$define fpc_softfpu_interface}
  17. {$i softfpu.pp}
  18. {$undef fpc_softfpu_interface}
  19. function IsARM9(): boolean;
  20. const
  21. LineEnding = #10;
  22. LFNSupport = true;
  23. CtrlZMarksEOF: boolean = false;
  24. DirectorySeparator = '/';
  25. DriveSeparator = ':';
  26. ExtensionSeparator = '.';
  27. PathSeparator = ';';
  28. AllowDirectorySeparators : set of char = ['\','/'];
  29. AllowDriveSeparators : set of char = [':'];
  30. FileNameCaseSensitive = false;
  31. maxExitCode = 255;
  32. MaxPathLen = 255;
  33. AllFilesMask = '*';
  34. sLineBreak: string[1] = LineEnding;
  35. DefaultTextLineBreakStyle: TTextLineBreakStyle = tlbsCRLF;
  36. UnusedHandle = $ffff;
  37. StdInputHandle = 0;
  38. StdOutputHandle = 1;
  39. StdErrorHandle = $ffff;
  40. var
  41. argc: LongInt = 0;
  42. argv: PPChar;
  43. envp: PPChar;
  44. errno: integer;
  45. fake_heap_end: ^byte; cvar;
  46. implementation
  47. {$define fpc_softfpu_implementation}
  48. {$i softfpu.pp}
  49. {$undef fpc_softfpu_implementation}
  50. { we get these functions and types from the softfpu code }
  51. {$define FPC_SYSTEM_HAS_float64}
  52. {$define FPC_SYSTEM_HAS_float32}
  53. {$define FPC_SYSTEM_HAS_flag}
  54. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  55. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  56. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  57. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  58. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  59. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  60. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  61. {$i system.inc}
  62. {$i ndsbios.inc}
  63. {
  64. NDS CPU detecting function (thanks to 21o6):
  65. --------------------------------------------
  66. "You see, the ARM7 can't write to bank A of VRAM, but it doesn't give any
  67. error ... it just doesn't write there... so it's easily determinable what
  68. CPU is running the code"
  69. ARM946E-S processor can handle dsp extensions extensions, but ARM7TDMI does
  70. not. FPC can't retrieve the CPU target at compiling time, so this small
  71. function takes care to check if the code is running on an ARM9 or on an ARM7
  72. CPU. It works on Nintendo DS only, I guess :)
  73. }
  74. function IsARM9(): boolean;
  75. var
  76. Dummy : pword absolute $06800000;
  77. tmp: word;
  78. begin
  79. tmp := Dummy^;
  80. Dummy^ := $C0DE;
  81. IsARM9 := Dummy^ = $C0DE;
  82. Dummy^ := tmp;
  83. end;
  84. {$ifdef FPC_HAS_FEATURE_PROCESSES}
  85. function GetProcessID: SizeUInt;
  86. begin
  87. GetProcessID := 0;
  88. end;
  89. {$endif}
  90. {*****************************************************************************
  91. Misc. System Dependent Functions
  92. *****************************************************************************}
  93. procedure System_exit;
  94. begin
  95. // Boo!
  96. end;
  97. {*****************************************************************************
  98. ParamStr/Randomize
  99. *****************************************************************************}
  100. { number of args }
  101. function paramcount : longint;
  102. begin
  103. paramcount := 0;
  104. end;
  105. { argument number l }
  106. function paramstr(l : longint) : string;
  107. begin
  108. paramstr := '';
  109. end;
  110. { set randseed to a new pseudo random value }
  111. procedure randomize;
  112. begin
  113. // Boo!
  114. end;
  115. {$ifdef FPC_HAS_FEATURE_TEXTIO}
  116. procedure SysInitStdIO;
  117. begin
  118. OpenStdIO(Input,fmInput,StdInputHandle);
  119. OpenStdIO(Output,fmOutput,StdOutputHandle);
  120. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  121. end;
  122. {$endif}
  123. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  124. begin
  125. result := stklen;
  126. end;
  127. begin
  128. StackLength := CheckInitialStkLen(InitialStkLen);
  129. StackBottom := StackTop - StackLength;
  130. { OS specific startup }
  131. { Set up signals handlers }
  132. if IsARM9 then
  133. fpc_cpucodeinit;
  134. { Setup heap }
  135. InitHeap;
  136. SysInitExceptions;
  137. { Setup stdin, stdout and stderr }
  138. SysInitStdIO;
  139. { Reset IO Error }
  140. InOutRes:=0;
  141. { Arguments }
  142. InitSystemThreads;
  143. initvariantmanager;
  144. end.