libch.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {
  2. This file is part of the Free Component Library (FCL)
  3. Copyright (c) 1999-2002 by the Free Pascal development team
  4. BIOS functions unit for Nintendo DS
  5. Copyright (c) 2006 by Francesco Lombardi
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *****************************************************************************}
  12. type
  13. time_t = longint;
  14. ptime_t = ^time_t;
  15. Ptm = ^tm;
  16. tm = record
  17. tm_sec: longint;
  18. tm_min: longint;
  19. tm_hour: longint;
  20. tm_mday: longint;
  21. tm_mon: longint;
  22. tm_year: longint;
  23. tm_wday: longint;
  24. tm_yday: longint;
  25. tm_isdst: longint;
  26. end;
  27. (* Some libc functions *)
  28. //function printf(format: Pchar; args: array of const): longint; cdecl; external;
  29. function printf(format: Pchar): longint; cdecl; varargs; external;
  30. //function sprintf(s: Pchar; format: Pchar; args: array of const): longint; cdecl; external;
  31. function sprintf(s: Pchar; format: Pchar): longint; varargs; cdecl; external;
  32. //function iprintf(format: Pchar; args: array of const): longint; cdecl; external;
  33. function iprintf(format: Pchar): longint; varargs; cdecl; external;
  34. //function scanf(format: Pchar; args: array of const): longint; cdecl; external;
  35. function scanf(format: Pchar): longint; cdecl; varargs; external;
  36. //function sscanf(s: Pchar; format: Pchar; args: array of const): longint; cdecl; external;
  37. function sscanf(s: Pchar; format: Pchar): longint; cdecl; varargs; external;
  38. function strcmp(s1: Pchar; s2: Pchar): longint; cdecl; external;
  39. function malloc(size: integer): pointer; cdecl; external;
  40. function realloc(ptr: pointer; size: integer): pointer; cdecl; external;
  41. procedure free(ptr: pointer); cdecl; external;
  42. function memcpy(dest: pointer; src: pointer; n: integer): pointer; cdecl; external;
  43. function gmtime(timer: ptime_t): ptm; cdecl; external;
  44. function time(timer: ptime_t): time_t; cdecl; external;
  45. type
  46. TSort = function (const a, b: pointer): integer;
  47. procedure qsort(__base: pointer; __nmemb: integer; __size: integer; __compar: TSort); cdecl; external;
  48. function __errno: plongint; cdecl; export;
  49. type
  50. _FILE = record
  51. firstCluster: longword;
  52. length: longword;
  53. curPos: longword;
  54. curClus: longword; // Current cluster to read from
  55. curSect: integer; // Current sector within cluster
  56. curByte: integer; // Current byte within sector
  57. readBuffer: array [0..511] of byte; // Buffer used for unaligned reads
  58. appClus: longword; // Cluster to append to
  59. appSect: integer; // Sector within cluster for appending
  60. appByte: integer; // Byte within sector for appending
  61. read: boolean; // Can read from file
  62. write: boolean; // Can write to file
  63. append: boolean; // Can append to file
  64. inUse: boolean; // This file is open
  65. dirEntSector: longword; // The sector where the directory entry is stored
  66. dirEntOffset: integer; // The offset within the directory sector
  67. end;
  68. P_FILE = ^_FILE;
  69. const
  70. SEEK_SET = 0;
  71. SEEK_CUR = 1;
  72. SEEK_END = 2;
  73. (*
  74. ------------------------------------------------------------------------------
  75. Directory iterator for mantaining state between dir* calls
  76. ------------------------------------------------------------------------------
  77. *)
  78. type
  79. DIR_ITER = record
  80. device: longint;
  81. dirStruct: pointer;
  82. end;
  83. PDIR_ITER = ^DIR_ITER;
  84. stat = packed record
  85. st_dev: longint;
  86. st_ino: longword;
  87. st_mode : longword;
  88. st_nlink : word;
  89. st_uid : word;
  90. st_gid : word;
  91. st_rdev : longint;
  92. st_size : longint;
  93. st_atime : longint;
  94. st_spare1: longint;
  95. st_mtime: longint;
  96. st_spare2: longint;
  97. st_ctime: longint;
  98. st_spare3: longint;
  99. st_blksize: longint;
  100. st_blocks: longint;
  101. st_spare4: array [0..1] of longint;
  102. end;
  103. TStat = stat;
  104. PStat = ^stat;
  105. const
  106. _IFMT = 0170000; // type of file
  107. _IFDIR = 0040000; // directory
  108. _IFCHR = 0020000; // character special
  109. _IFBLK = 0060000; // block special
  110. _IFREG = 0100000; // regular
  111. _IFLNK = 0120000; // symbolic link
  112. _IFSOCK = 0140000; // socket
  113. _IFIFO = 0010000; // fifo
  114. S_BLKSIZE = 1024; // size of a block
  115. S_ISUID = 0004000; // set user id on execution
  116. S_ISGID = 0002000; // set group id on execution
  117. NAME_MAX = 767;
  118. function S_ISBLK(m: longint): boolean; inline;
  119. function S_ISCHR(m: longint): boolean; inline;
  120. function S_ISDIR(m: longint): boolean; inline;
  121. function S_ISFIFO(m: longint): boolean; inline;
  122. function S_ISREG(m: longint): boolean; inline;
  123. function S_ISLNK(m: longint): boolean; inline;
  124. function S_ISSOCK(m: longint): boolean; inline;
  125. type
  126. dirent = record
  127. d_ino: longint;
  128. d_name: array [0..NAME_MAX] of char;
  129. end;
  130. PDirent = ^dirent;
  131. PPDirent = ^PDirent;
  132. DIR = record
  133. position: longint;
  134. dirData: PDIR_ITER;
  135. fileData: dirent;
  136. end;
  137. PDIR = ^DIR;
  138. (* DIR handling *)
  139. function closedir(dirp: PDIR): longint; cdecl; external;
  140. function opendir(const dirname: pchar): PDIR; cdecl; external;
  141. function readdir(dirp: PDIR): PDirent; cdecl; external;
  142. function readdir_r(dirp: PDIR; entry: PDirent; result: PPDirent): longint; cdecl; external;
  143. procedure rewinddir(dirp: PDIR); cdecl; external;
  144. procedure seekdir(dirp: PDIR; loc: longint); cdecl; external;
  145. function telldir(dirp: PDIR): longint; cdecl; external;
  146. function diropen(const path: pchar): PDIR_ITER; cdecl; external;
  147. function dirreset(dirState: PDIR_ITER): longint; cdecl; external;
  148. function dirnext(dirState: PDIR_ITER; filename: pchar; filestat: Pstat): longint; cdecl; external;
  149. function dirclose(dirState: PDIR_ITER): longint; cdecl; external;
  150. (* File handling *)
  151. function fopen(filename: Pchar; modes: Pchar): P_FILE; cdecl; external;
  152. function fread(ptr: pointer; size: longint; n: longint; stream: P_FILE): longint; cdecl; external;
  153. function fread(var ptr; size: longint; n: longint; var stream: _FILE): longint; cdecl; external;
  154. function fwrite(ptr: pointer; size: longint; n: longint; s: P_FILE): longint; cdecl; external;
  155. function fwrite(var ptr; size: longint; n: longint; var s: _FILE): longint; cdecl; external;
  156. function ftell(stream: P_FILE): longint; cdecl; external;
  157. function ftell(var stream: _FILE): longint; cdecl; external;
  158. function fseek(stream: P_FILE; off: longint; whence: longint): longint; cdecl; external;
  159. function fseek(var stream: _FILE; off: longint; whence: longint): longint; cdecl; external;
  160. function fclose(stream: P_FILE): longint; cdecl; external;
  161. function fclose(var stream: _FILE): longint; cdecl; external;
  162. function isatty(fildes: longint): longint; cdecl; external;
  163. function fileno(para1: P_FILE): longint; cdecl; external;
  164. function fileno(var para1: _FILE): longint; cdecl; external;
  165. function fstat(fildes: longint; buf: PStat): longint; cdecl; external;
  166. function fstat(fildes: longint; var buf: TStat): longint; cdecl; external;
  167. function _stat(__file:Pchar; var __buf:Tstat):longint; cdecl; external name 'stat';
  168. function ftruncate(fildes: longint; len: longint): longint; cdecl; external;
  169. function unlink(path: Pchar): longint; cdecl; external;
  170. function rename(para1: Pchar; para2: Pchar): longint; cdecl; external;