system.inc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. {$ifdef NDS_INTERFACE}
  2. const
  3. REG_DISPSTAT : pcuint16 = pointer($04000004);
  4. type
  5. DISP_BITS = cint;
  6. const
  7. DISP_IN_VBLANK : DISP_BITS = (1 shl 0);
  8. DISP_IN_HBLANK : DISP_BITS = (1 shl 1);
  9. DISP_YTRIGGERED : DISP_BITS = (1 shl 2);
  10. DISP_VBLANK_IRQ : DISP_BITS = (1 shl 3);
  11. DISP_HBLANK_IRQ : DISP_BITS = (1 shl 4);
  12. DISP_YTRIGGER_IRQ : DISP_BITS = (1 shl 5);
  13. REG_VCOUNT : pcuint16 = pointer($04000006);
  14. HALT_CR : pcuint16 = pointer($04000300);
  15. REG_POWERCNT : pcuint16 = pointer($04000304);
  16. REG_DSIMODE : pcuint32 = pointer($04004000);
  17. procedure SetYtrigger(Yvalue: cint); inline;
  18. const
  19. PM_ARM9_DIRECT = (1 shl 16);
  20. type
  21. PM_Bits = cint;
  22. const
  23. PM_SOUND_AMP : PM_Bits = (1 shl 0);
  24. PM_SOUND_MUTE : PM_Bits = (1 shl 1);
  25. PM_BACKLIGHT_BOTTOM : PM_Bits = (1 shl 2);
  26. PM_BACKLIGHT_TOP : PM_Bits = (1 shl 3);
  27. PM_SYSTEM_PWR : PM_Bits = (1 shl 6);
  28. POWER_LCD : PM_Bits = PM_ARM9_DIRECT or (1 shl 0);
  29. POWER_2D_A : PM_Bits = PM_ARM9_DIRECT or (1 shl 1);
  30. POWER_MATRIX : PM_Bits = PM_ARM9_DIRECT or (1 shl 2);
  31. POWER_3D_CORE : PM_Bits = PM_ARM9_DIRECT or (1 shl 3);
  32. POWER_2D_B : PM_Bits = PM_ARM9_DIRECT or (1 shl 9);
  33. POWER_SWAP_LCDS: PM_Bits = PM_ARM9_DIRECT or (1 shl 15);
  34. // POWER_ALL_2D : PM_Bits = PM_ARM9_DIRECT or POWER_LCD or POWER_2D_A or POWER_2D_B;
  35. POWER_ALL_2D : PM_Bits = (1 shl 16) or (1 shl 0) or (1 shl 1) or (1 shl 9);
  36. // POWER_ALL : PM_Bits = PM_ARM9_DIRECT or POWER_ALL_2D or POWER_3D_CORE or POWER_MATRIX;
  37. POWER_ALL : PM_Bits = (1 shl 16) or (1 shl 0) or (1 shl 1) or (1 shl 9) or (1 shl 3) or (1 shl 2);
  38. //procedure SystemSleep(); cdecl; external;
  39. procedure ledBlink(bm: cint); cdecl; external;
  40. {$ifdef ARM9}
  41. procedure SystemSleep(); cdecl; external;
  42. procedure powerOn(bits: cint); cdecl; external;
  43. procedure powerOff(bits: cint); cdecl; external;
  44. procedure systemMsgHandler(bytes: cint; user_data: pointer); cdecl; external;
  45. procedure powerValueHandler(value: cuint32; data: pointer); cdecl; external;
  46. procedure lcdSwap(); inline;
  47. procedure lcdMainOnTop(); inline;
  48. procedure lcdMainOnBottom(); inline;
  49. procedure systemShutDown(); inline;
  50. function getBatteryLevel(): cuint32; cdecl; external;
  51. procedure setVectorBase(highVector: cint); cdecl; external;
  52. type
  53. sysVectors_t = packed record
  54. reset: cuint32;
  55. undefined: cuint32;
  56. swi: cuint32;
  57. prefetch_abort: cuint32;
  58. data_abort: cuint32;
  59. fiq: cuint32;
  60. end;
  61. sysVectors = sysVectors_t;
  62. PsysVectors = ^sysVectors;
  63. var
  64. SystemVectors: sysVectors; cvar; external;
  65. // Helper functions for heap size
  66. //! returns current start of heap space
  67. function getHeapStart(): pcuint8; cdecl; external;
  68. //! returns current end of heap space
  69. function getHeapEnd(): pcuint8; cdecl; external;
  70. //! returns current heap limit
  71. function getHeapLimit(): pcuint8; cdecl; external;
  72. {$endif ARM9}
  73. {$ifdef ARM7}
  74. type
  75. ARM7_power = cint;
  76. const
  77. POWER_SOUND : ARM7_power = (1 shl 0);
  78. PM_CONTROL_REG : ARM7_power = 0;
  79. PM_BATTERY_REG : ARM7_power = 1;
  80. PM_AMPLIFIER_REG : ARM7_power = 2;
  81. PM_READ_REGISTER : ARM7_power = (1 shl 7);
  82. PM_AMP_OFFSET : ARM7_power = 2;
  83. PM_GAIN_OFFSET : ARM7_power = 3;
  84. PM_BACKLIGHT_LEVEL : ARM7_power = 4;
  85. PM_GAIN_20 : ARM7_power = 0;
  86. PM_GAIN_40 : ARM7_power = 1;
  87. PM_GAIN_80 : ARM7_power = 2;
  88. PM_GAIN_160 : ARM7_power = 3;
  89. PM_AMP_ON : ARM7_power = 1;
  90. PM_AMP_OFF : ARM7_power = 0;
  91. function PM_LED_CONTROL(m: cint): cint; inline;
  92. procedure installSystemFIFO(); cdecl; external;
  93. procedure systemSleep(); cdecl; external;
  94. function sleepEnabled(): cint; cdecl; external;
  95. function writePowerManagement(reg, command: cint): cint; cdecl; external;
  96. function readPowerManagement(reg: cint): cint; inline;
  97. procedure powerOn(bits: cint); inline;
  98. procedure powerOff(bits: cint); inline;
  99. procedure readUserSettings(); cdecl; external;
  100. procedure systemShutDown(); cdecl; external;
  101. {$endif ARM7}
  102. type
  103. BACKLIGHT_LEVELS = cint;
  104. const
  105. BACKLIGHT_LOW : BACKLIGHT_LEVELS = 0;
  106. BACKLIGHT_MED : BACKLIGHT_LEVELS = 1;
  107. BACKLIGHT_HIGH : BACKLIGHT_LEVELS = 2;
  108. BACKLIGHT_MAX : BACKLIGHT_LEVELS = 3;
  109. type
  110. tPERSONAL_DATA = bitpacked record
  111. RESERVED0: array [0..1] of cuint8;
  112. theme: cuint8;
  113. birthMonth: cuint8;
  114. birthDay: cuint8;
  115. RESERVED1: array [0..0] of cuint8;
  116. name: array [0..9] of cint16;
  117. nameLen: cuint16;
  118. message: array [0..25] of cint16;
  119. messageLen: cuint16;
  120. alarmHour: cuint8;
  121. alarmMinute: cuint8;
  122. RESERVED2: array [0..3] of cuint8;
  123. calX1: cuint16;
  124. calY1: cuint16;
  125. calX1px: cuint8;
  126. calY1px: cuint8;
  127. calX2: cuint16;
  128. calY2: cuint16;
  129. calX2px: cuint8;
  130. calY2px: cuint8;
  131. _user_data: packed record
  132. language: 0..3;
  133. gbaScreen: 0..1;
  134. defaultBrightness: 0..2;
  135. autoMode: 0..1;
  136. RESERVED5: 0..2;
  137. settingsLost: 0..1;
  138. RESERVED6: 0..6;
  139. end;
  140. RESERVED3: cuint16;
  141. rtcOffset: cuint32;
  142. RESERVED4: cuint32;
  143. end;
  144. PERSONAL_DATA = tPERSONAL_DATA;
  145. PPERSONAL_DATA = ^tPERSONAL_DATA;
  146. const
  147. PersonalData : PPERSONAL_DATA = pointer($2FFFC80);
  148. type
  149. RTCtime = packed record
  150. year: cuint8; // add 2000 to get 4 digit year
  151. month: cuint8; // 1 to 12
  152. day: cuint8; // 1 to (days in month)
  153. weekday: cuint8; // day of week
  154. hours: cuint8; // 0 to 11 for AM, 52 to 63 for PM
  155. minutes: cuint8; // 0 to 59
  156. seconds: cuint8; // 0 to 59
  157. // padding: cuint8;
  158. end;
  159. const
  160. ARGV_MAGIC = $5f617267;
  161. type
  162. ppcchar = ^pcchar;
  163. __argv = record
  164. argvMagic: cint; // argv magic number, set to 0x5f617267 ('_arg') if valid
  165. commandLine: pcchar; // base address of command line, set of null terminated strings
  166. length: cint; // total length of command line
  167. argc: integer;
  168. argv: ppcchar;
  169. dummy: cint; // internal use
  170. host: cuint32; // internal use, host ip for dslink
  171. end;
  172. Targv = __argv;
  173. Pargv = ^Targv;
  174. const
  175. __system_argv: Pargv = pointer($02FFFE70);
  176. const
  177. BOOTSIG = $62757473746F6F62; // ULL?
  178. type
  179. __bootstub = packed record // packed ?
  180. bootsig: cuint64;
  181. arm9reboot: VoidFn;
  182. arm7reboot: VoidFn;
  183. bootsize: cuint32;
  184. end;
  185. {$ifdef ARM9}
  186. //procedure memCached(address: pointer); cdecl; external;
  187. function memCached(address: pointer): pointer; cdecl; external;
  188. //procedure memUncached(address: pointer); cdecl; external;
  189. function memUncached(address: pointer): pointer; cdecl; external;
  190. procedure resetARM7(address: cuint32); cdecl; external;
  191. {$endif ARM9}
  192. {$ifdef ARM7}
  193. procedure resetARM9(address: cuint32); cdecl; external;
  194. {$endif ARM7}
  195. {$endif NDS_INTERFACE}
  196. {$ifdef NDS_IMPLEMENTATION}
  197. procedure SetYtrigger(Yvalue: cint); inline;
  198. begin
  199. REG_DISPSTAT^ := (REG_DISPSTAT^ and $007F ) or (Yvalue shl 8) or (( Yvalue and $100 ) shr 1);
  200. end;
  201. {$ifdef ARM9}
  202. procedure lcdSwap(); inline;
  203. begin
  204. REG_POWERCNT^ := REG_POWERCNT^ xor POWER_SWAP_LCDS;
  205. end;
  206. procedure lcdMainOnTop(); inline;
  207. begin
  208. REG_POWERCNT^ := REG_POWERCNT^ or cint(POWER_SWAP_LCDS);
  209. end;
  210. procedure lcdMainOnBottom(); inline;
  211. begin
  212. REG_POWERCNT^ := REG_POWERCNT^ and (not cint(POWER_SWAP_LCDS));
  213. end;
  214. procedure systemShutDown(); inline;
  215. begin
  216. powerOn(PM_SYSTEM_PWR);
  217. end;
  218. {$endif ARM9}
  219. {$ifdef ARM7}
  220. function PM_LED_CONTROL(m: cint): cint; inline;
  221. begin
  222. result := (m) shl 4;
  223. end;
  224. function readPowerManagement(reg: cint): cint; inline;
  225. begin
  226. result := writePowerManagement(reg or PM_READ_REGISTER, 0);
  227. end;
  228. procedure powerOn(bits: cint); inline;
  229. begin
  230. REG_POWERCNT^ := REG_POWERCNT^ or bits;
  231. end;
  232. procedure powerOff(bits: cint); inline;
  233. begin
  234. REG_POWERCNT^ := REG_POWERCNT^ and not bits;
  235. end;
  236. {$endif ARM7}
  237. {$endif NDS_IMPLEMENTATION}