/packages/libndsfpc/src/nds/system.inc

https://github.com/slibre/freepascal · Pascal · 305 lines · 212 code · 66 blank · 27 comment · 0 complexity · 02bb1faf775b5eeb3379eb7b498994a7 MD5 · raw file

  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 systemValueHandler(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. //void setSDcallback(void(*callback)(int));
  66. procedure setSDcallback(callback: pointer); cdecl; external; // ??
  67. // Helper functions for heap size
  68. //! returns current start of heap space
  69. function getHeapStart(): pcuint8; cdecl; external;
  70. //! returns current end of heap space
  71. function getHeapEnd(): pcuint8; cdecl; external;
  72. //! returns current heap limit
  73. function getHeapLimit(): pcuint8; cdecl; external;
  74. {$endif ARM9}
  75. {$ifdef ARM7}
  76. type
  77. ARM7_power = cint;
  78. const
  79. POWER_SOUND : ARM7_power = (1 shl 0);
  80. PM_CONTROL_REG : ARM7_power = 0;
  81. PM_BATTERY_REG : ARM7_power = 1;
  82. PM_AMPLIFIER_REG : ARM7_power = 2;
  83. PM_READ_REGISTER : ARM7_power = (1 shl 7);
  84. PM_AMP_OFFSET : ARM7_power = 2;
  85. PM_GAIN_OFFSET : ARM7_power = 3;
  86. PM_BACKLIGHT_LEVEL : ARM7_power = 4;
  87. PM_GAIN_20 : ARM7_power = 0;
  88. PM_GAIN_40 : ARM7_power = 1;
  89. PM_GAIN_80 : ARM7_power = 2;
  90. PM_GAIN_160 : ARM7_power = 3;
  91. PM_AMP_ON : ARM7_power = 1;
  92. PM_AMP_OFF : ARM7_power = 0;
  93. function PM_LED_CONTROL(m: cint): cint; inline;
  94. procedure installSystemFIFO(); cdecl; external;
  95. procedure systemSleep(); cdecl; external;
  96. function sleepEnabled(): cint; cdecl; external;
  97. function writePowerManagement(reg, command: cint): cint; cdecl; external;
  98. function readPowerManagement(reg: cint): cint; inline;
  99. procedure powerOn(bits: cint); inline;
  100. procedure powerOff(bits: cint); inline;
  101. procedure readUserSettings(); cdecl; external;
  102. procedure systemShutDown(); cdecl; external;
  103. {$endif ARM7}
  104. type
  105. BACKLIGHT_LEVELS = cint;
  106. const
  107. BACKLIGHT_LOW : BACKLIGHT_LEVELS = 0;
  108. BACKLIGHT_MED : BACKLIGHT_LEVELS = 1;
  109. BACKLIGHT_HIGH : BACKLIGHT_LEVELS = 2;
  110. BACKLIGHT_MAX : BACKLIGHT_LEVELS = 3;
  111. type
  112. tPERSONAL_DATA = bitpacked record
  113. RESERVED0: array [0..1] of cuint8;
  114. theme: cuint8;
  115. birthMonth: cuint8;
  116. birthDay: cuint8;
  117. RESERVED1: array [0..0] of cuint8;
  118. name: array [0..9] of cint16;
  119. nameLen: cuint16;
  120. message: array [0..25] of cint16;
  121. messageLen: cuint16;
  122. alarmHour: cuint8;
  123. alarmMinute: cuint8;
  124. RESERVED2: array [0..3] of cuint8;
  125. calX1: cuint16;
  126. calY1: cuint16;
  127. calX1px: cuint8;
  128. calY1px: cuint8;
  129. calX2: cuint16;
  130. calY2: cuint16;
  131. calX2px: cuint8;
  132. calY2px: cuint8;
  133. _user_data: packed record
  134. language: 0..3;
  135. gbaScreen: 0..1;
  136. defaultBrightness: 0..2;
  137. autoMode: 0..1;
  138. RESERVED5: 0..2;
  139. settingsLost: 0..1;
  140. RESERVED6: 0..6;
  141. end;
  142. RESERVED3: cuint16;
  143. rtcOffset: cuint32;
  144. RESERVED4: cuint32;
  145. end;
  146. PERSONAL_DATA = tPERSONAL_DATA;
  147. PPERSONAL_DATA = ^tPERSONAL_DATA;
  148. const
  149. PersonalData : PPERSONAL_DATA = pointer($2FFFC80);
  150. type
  151. RTCtime = packed record
  152. year: cuint8; // add 2000 to get 4 digit year
  153. month: cuint8; // 1 to 12
  154. day: cuint8; // 1 to (days in month)
  155. weekday: cuint8; // day of week
  156. hours: cuint8; // 0 to 11 for AM, 52 to 63 for PM
  157. minutes: cuint8; // 0 to 59
  158. seconds: cuint8; // 0 to 59
  159. // padding: cuint8;
  160. end;
  161. const
  162. ARGV_MAGIC = $5f617267;
  163. type
  164. ppcchar = ^pcchar;
  165. __argv = record
  166. argvMagic: cint; // argv magic number, set to 0x5f617267 ('_arg') if valid
  167. commandLine: pcchar; // base address of command line, set of null terminated strings
  168. length: cint; // total length of command line
  169. argc: integer;
  170. argv: ppcchar;
  171. dummy: cint; // internal use
  172. host: cuint32; // internal use, host ip for dslink
  173. end;
  174. Targv = __argv;
  175. Pargv = ^Targv;
  176. const
  177. __system_argv: Pargv = pointer($02FFFE70);
  178. const
  179. BOOTSIG = $62757473746F6F62; // ULL?
  180. type
  181. __bootstub = packed record // packed ?
  182. bootsig: cuint64;
  183. arm9reboot: VoidFn;
  184. arm7reboot: VoidFn;
  185. bootsize: cuint32;
  186. end;
  187. {$ifdef ARM9}
  188. //procedure memCached(address: pointer); cdecl; external;
  189. function memCached(address: pointer): pointer; cdecl; external;
  190. //procedure memUncached(address: pointer); cdecl; external;
  191. function memUncached(address: pointer): pointer; cdecl; external;
  192. procedure resetARM7(address: cuint32); cdecl; external;
  193. {$endif ARM9}
  194. {$ifdef ARM7}
  195. procedure resetARM9(address: cuint32); cdecl; external;
  196. {$endif ARM7}
  197. {$endif NDS_INTERFACE}
  198. {$ifdef NDS_IMPLEMENTATION}
  199. procedure SetYtrigger(Yvalue: cint); inline;
  200. begin
  201. REG_DISPSTAT^ := (REG_DISPSTAT^ and $007F ) or (Yvalue shl 8) or (( Yvalue and $100 ) shr 1);
  202. end;
  203. {$ifdef ARM9}
  204. procedure lcdSwap(); inline;
  205. begin
  206. REG_POWERCNT^ := REG_POWERCNT^ xor POWER_SWAP_LCDS;
  207. end;
  208. procedure lcdMainOnTop(); inline;
  209. begin
  210. REG_POWERCNT^ := REG_POWERCNT^ or cint(POWER_SWAP_LCDS);
  211. end;
  212. procedure lcdMainOnBottom(); inline;
  213. begin
  214. REG_POWERCNT^ := REG_POWERCNT^ and (not cint(POWER_SWAP_LCDS));
  215. end;
  216. procedure systemShutDown(); inline;
  217. begin
  218. powerOn(PM_SYSTEM_PWR);
  219. end;
  220. {$endif ARM9}
  221. {$ifdef ARM7}
  222. function PM_LED_CONTROL(m: cint): cint; inline;
  223. begin
  224. result := (m) shl 4;
  225. end;
  226. function readPowerManagement(reg: cint): cint; inline;
  227. begin
  228. result := writePowerManagement(reg or PM_READ_REGISTER, 0);
  229. end;
  230. procedure powerOn(bits: cint); inline;
  231. begin
  232. REG_POWERCNT^ := REG_POWERCNT^ or bits;
  233. end;
  234. procedure powerOff(bits: cint); inline;
  235. begin
  236. REG_POWERCNT^ := REG_POWERCNT^ and not bits;
  237. end;
  238. {$endif ARM7}
  239. {$endif NDS_IMPLEMENTATION}