gemdos.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. {
  2. Copyright (c) 2016 by Free Pascal development team
  3. GEMDOS interface unit for Atari TOS
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$PACKRECORDS 2}
  11. {$MODESWITCH OUT+}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit gemdos;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. { The API description of this file is based on the information available
  17. online at: https://freemint.github.io/tos.hyp/en/index.html }
  18. const
  19. E_OK = 0; // OK. No error has arisen
  20. EINVFN = -32; // Unknown function number
  21. EFILNF = -33; // File not found
  22. EPTHNF = -34; // Directory (folder) not found
  23. ENHNDL = -35; // No more handles available
  24. EACCDN = -36; // Access denied
  25. EIHNDL = -37; // Invalid file handle
  26. ENSMEM = -39; // Insufficient memory
  27. EIMBA = -40; // Invalid memory block address
  28. EDRIVE = -46; // Invalid drive specification
  29. ECWD = -47; // Current directory cannot be deleted
  30. ENSAME = -48; // Files on different logical drives
  31. ENMFIL = -49; // No more files can be opened
  32. ELOCKED = -58; // Segment of a file is protected (network)
  33. ENSLOCK = -59; // Invalid lock removal request
  34. ERANGE = -64; // File pointer in invalid segment (see also FreeMiNT message -88)
  35. EINTRN = -65; // Internal error of GEMDOS
  36. EPLFMT = -66; // Invalid program load format
  37. EGSBF = -67; // Allocated memory block could not be enlarged
  38. EBREAK = -68; // Program termination by Control-C
  39. EXCPT = -69; // 68000 exception (bombs)
  40. EPTHOV = -70; // Path overflow
  41. ELOOP = -80; // Endless loop with symbolic links
  42. EPIPE = -81; // Write to broken pipe.
  43. // as used by fseek
  44. const
  45. SEEK_FROM_START = 0;
  46. SEEK_FROM_CURRENT = 1;
  47. SEEK_FROM_END = 2;
  48. // as used by fcreate and fattrib
  49. const
  50. ATTRIB_WRITE_PROT = ( 1 shl 0 );
  51. ATTRIB_HIDDEN = ( 1 shl 1 );
  52. ATTRIB_SYSTEM = ( 1 shl 2 );
  53. ATTRIB_VOLUME_LABEL = ( 1 shl 3 );
  54. ATTRIB_DIRECTORY = ( 1 shl 4 );
  55. ATTRIB_ARCHIVE = ( 1 shl 5 );
  56. // as used by fopen
  57. const
  58. OPEN_READ_ONLY = ( 1 shl 0 );
  59. OPEN_WRITE_ONLY = ( 1 shl 1 );
  60. OPEN_READ_WRITE = ( 1 shl 2 );
  61. // as used by fattrib
  62. const
  63. FLAG_GET = 0;
  64. FLAG_SET = 1;
  65. // as used by mxalloc
  66. const
  67. MXALLOC_ST = 0;
  68. MXALLOC_ALT = 1;
  69. MXALLOC_PREFER_ST = 2;
  70. MXALLOC_PREFER_ALT = 3;
  71. MXALLOC_PROT_DEFAULT = (0 shl 4);
  72. MXALLOC_PROT_PRIVATE = (1 shl 4);
  73. MXALLOC_PROT_GLOBAL = (2 shl 4);
  74. MXALLOC_PROT_SUPER_ONLY = (3 shl 4);
  75. MXALLOC_PROT_WORLD_READ = (4 shl 4);
  76. MXALLOC_NO_FREE = (1 shl 14);
  77. // as used by pexec
  78. const
  79. PE_LOADGO = 0; {* load & go *}
  80. PE_LOAD = 3; {* just load *}
  81. PE_GO = 4; {* just go *}
  82. PE_CBASEPAGE = 5; {* just create basepage *}
  83. PE_GO_FREE = 6; {* just go, then free *}
  84. PE_CBASEPAGE_FLAGS = 7; {* create basepage defining the program flags *}
  85. {* MiNT/MagiC *}
  86. PE_ASYNC_LOADGO = 100; {* load and asynchronously go *}
  87. PE_INIT = 101; {* Inherits path- and file-handles (MagiC) *}
  88. PE_TERM = 102; {* The process will be deleted (MagiC) *}
  89. PE_ASYNC_GO = 104; {* asynchronously go *}
  90. PE_ASYNC_GO_FREE = 106; {* asynchronously go and free *}
  91. PE_XBASE = 107; {* As Mode 7, but in place of a command line the process name will be passed. (MagiC) *}
  92. PE_EXACC = 108; {* Used internally by MagiC for starting an ACC *}
  93. PE_OVERLAY = 200; {* load and overlay *}
  94. PE_OVERLAY_GO = 204; {* overlay and go *}
  95. PE_OVERLAY_GO_FREE = 206; {* overlay, go and free *}
  96. PE_PTRACE = $8000; {* activate tracing *}
  97. // Sconfig - Modes
  98. SC_GETCONF = 0; {* KAOS 1.2 *}
  99. SC_SETCONF = 1; {* KAOS 1.2 *}
  100. SC_DOSVARS = 2; {* KAOS 1.4 *}
  101. SC_MOWNER = 3; {* MagiC 3.00 *}
  102. SC_WBACK = 4; {* MagiC 4.01 *}
  103. SC_INTMAVAIL = 5; {* MagiC 4.01 *}
  104. SC_INTGARBC = 6; {* MagiC 4.01 *}
  105. // Sconfig Bits
  106. SCB_PTHCK = $001; {* KAOS 1.2 *}
  107. SCB_DSKCH = $002; {* KAOS 1.2 *}
  108. SCB_BREAK = $004; {* KAOS 1.2 *}
  109. SCB_NCTLC = $008; {* KAOS 1.2 *}
  110. SCB_NFAST = $010; {* KAOS 1.2 *}
  111. SCB_CMPTB = $020; {* KAOS 1.4 *}
  112. SCB_NSMRT = $040; {* KAOS 1.4 *}
  113. SCB_NGRSH = $080; {* KAOS 1.4 *}
  114. SCB_NHALT = $100; {* KAOS 1.4 *}
  115. SCB_RESVD = $200; {* KAOS 1.4 *}
  116. SCB_PULLM = $400; {* KAOS 1.4 *}
  117. SCB_FLPAR = $800; {* MagiC 3.0 *}
  118. type
  119. PDTA = ^TDTA;
  120. TDTA = packed record
  121. d_reserved: array[0..20] of shortint; {* Reserved for GEMDOS *}
  122. d_attrib: byte; {* File attributes *}
  123. d_time: word; {* Time *}
  124. d_date: word; {* Date *}
  125. d_length: dword; {* File length *}
  126. d_fname: array[0..13] of AnsiChar; {* Filename *}
  127. end;
  128. type
  129. PDISKINFO = ^TDISKINFO;
  130. TDISKINFO = record
  131. b_free: dword; {* Number of free clusters *}
  132. b_total: dword; {* Total number of clusters *}
  133. b_secsiz: dword; {* Bytes per sector *}
  134. b_clsiz: dword; {* Sector per cluster *}
  135. end;
  136. type
  137. PDOSTIME = ^TDOSTIME;
  138. TDOSTIME = record
  139. time: word; {* Time like Tgettime *}
  140. date: word; {* Date like Tgetdate *}
  141. end;
  142. type
  143. PPD = ^TPD;
  144. TPD = record
  145. p_lowtpa: pointer; {* Start address of the TPA *}
  146. p_hitpa: pointer; {* First byte after the end of the TPA *}
  147. p_tbase: pointer; {* Start address of the program code *}
  148. p_tlen: longint; {* Length of the program code *}
  149. p_dbase: pointer; {* Start address of the DATA segment *}
  150. p_dlen: longint; {* Length of the DATA section *}
  151. p_bbase: pointer; {* Start address of the BSS segment *}
  152. p_blen: longint; {* Length of the BSS section *}
  153. p_dta: PDTA; {* Pointer to the default DTA *}
  154. {* Warning: Points first to the *}
  155. {* command line ! *}
  156. p_parent: PPD; {* Pointer to the basepage of the *}
  157. {* calling processes *}
  158. p_resrvd0: longint; {* Reserved *}
  159. p_env: PAnsiChar; {* Address of the environment string *}
  160. p_resrvd1: array[0..79] of AnsiChar; {* Reserved *}
  161. p_cmdlin: array[0..127] of AnsiChar; {* Command line *}
  162. end;
  163. TBASEPAGE = TPD; {* alias types... *}
  164. PBASEPAGE = ^TBASEPAGE;
  165. type
  166. PLINE = ^TLINE;
  167. TLINE = record
  168. maxlen: byte; {* Maximum line length *}
  169. actuallen: byte; {* Current line length *}
  170. buffer: array[0..254] of byte; {* Line buffer *}
  171. end;
  172. procedure gemdos_pterm0; syscall 1 0;
  173. function gemdos_cconin: longint; syscall 1 1;
  174. function gemdos_cconout(c: smallint): longint; syscall 1 2;
  175. function gemdos_cauxin: longint; syscall 1 3;
  176. function gemdos_cauxout(c: smallint): longint; syscall 1 4;
  177. function gemdos_cprnout(c: smallint): longint; syscall 1 5;
  178. function gemdos_crawio(c: smallint): longint; syscall 1 6;
  179. function gemdos_crawin: longint; syscall 1 7;
  180. function gemdos_cnecin: longint; syscall 1 8;
  181. procedure gemdos_cconws(p: PAnsiChar); syscall 1 9;
  182. function gemdos_cconrs(buf: PLINE): longint; syscall 1 10;
  183. function gemdos_cconis: longint; syscall 1 11;
  184. function gemdos_dsetdrv(drv: smallint): longint; syscall 1 14;
  185. function gemdos_cconos: smallint; syscall 1 16;
  186. function gemdos_cprnos: smallint; syscall 1 17;
  187. function gemdos_cauxis: smallint; syscall 1 18;
  188. function gemdos_cauxos: smallint; syscall 1 19;
  189. function gemdos_maddalt(start: pointer; size: longint): longint; syscall 1 20;
  190. function gemdos_srealloc(len: longint): longint; syscall 1 21;
  191. function gemdos_dgetdrv: smallint; syscall 1 25;
  192. procedure gemdos_fsetdta(buf: PDTA); syscall 1 26;
  193. function gemdos_super(stack: pointer): longint; syscall 1 32;
  194. function gemdos_tgetdate: word; syscall 1 42;
  195. function gemdos_tsetdate(date: word): word; syscall 1 43;
  196. function gemdos_tgettime: word; syscall 1 44;
  197. function gemdos_tsettime(time: word): word; syscall 1 45;
  198. function gemdos_fgetdta: PDTA; syscall 1 47;
  199. function gemdos_sversion: smallint; syscall 1 48;
  200. procedure gemdos_ptermres(keepcnt: longint; returncode: smallint); syscall 1 49;
  201. function gemdos_sconfig(mode: smallint; flags: longint): longint; syscall 1 51;
  202. function gemdos_dfree(var buf: TDISKINFO; driveno: smallint): smallint; syscall 1 54;
  203. function gemdos_dcreate(const path: PAnsiChar): longint; syscall 1 57;
  204. function gemdos_ddelete(const path: PAnsiChar): longint; syscall 1 58;
  205. function gemdos_dsetpath(const path: PAnsiChar): smallint; syscall 1 59;
  206. function gemdos_fcreate(const fname: PAnsiChar; attr: smallint): smallint; syscall 1 60;
  207. function gemdos_fopen(const fname: PAnsiChar; mode: smallint): longint; syscall 1 61;
  208. function gemdos_fclose(handle: smallint): smallint; syscall 1 62;
  209. function gemdos_fread(handle: smallint; count: longint; buf: pointer): longint; syscall 1 63;
  210. function gemdos_fwrite(handle: smallint; count: longint; buf: pointer): longint; syscall 1 64;
  211. function gemdos_fdelete(const fname: PAnsiChar): smallint; syscall 1 65;
  212. function gemdos_fseek(offset: longint; handle: smallint; seekmode: smallint): longint; syscall 1 66;
  213. function gemdos_fattrib(const filename: PAnsiChar; wflag: smallint; attrib: smallint): smallint; syscall 1 67;
  214. function gemdos_mxalloc(amount: longint; mode: smallint): pointer; syscall 1 68;
  215. function gemdos_fdup(handle: smallint): smallint; syscall 1 69;
  216. function gemdos_fforce(stdh: smallint; nonstdh: smallint): smallint; syscall 1 70;
  217. function gemdos_dgetpath(path: PAnsiChar; driveno: smallint): smallint; syscall 1 71;
  218. function gemdos_malloc(number: dword): pointer; syscall 1 72;
  219. function gemdos_mfree(block: pointer): dword; syscall 1 73;
  220. function gemdos_mshrink(zero: word; block: pointer; newsiz: longint): longint; syscall 1 74;
  221. function gemdos_pexec(mode: word; name: PAnsiChar; cmdline: PAnsiChar; env: PAnsiChar): longint; syscall 1 75;
  222. procedure gemdos_pterm(returncode: smallint); syscall 1 76;
  223. function gemdos_fsfirst(const filename: PAnsiChar; attr: smallint): longint; syscall 1 78;
  224. function gemdos_fsnext: smallint; syscall 1 79;
  225. function gemdos_frename(zero: word; const oldname: PAnsiChar; const newname: PAnsiChar): longint; syscall 1 86;
  226. procedure gemdos_fdatime(timeptr: PDOSTIME; handle: smallint; wflag: smallint); syscall 1 87;
  227. function gemdos_Flock(handle, mode: smallint; start, length: LongInt): LongInt; syscall 1 92;
  228. { MiNT extensions }
  229. type
  230. PMSGTYPE = ^TMSGTYPE;
  231. TMSGTYPE = record
  232. msg1: LongInt;
  233. msg2: LongInt;
  234. pid: SmallInt;
  235. end;
  236. PXATTR = ^TXATTR;
  237. TXATTR = record
  238. mode: Word;
  239. index: LongInt;
  240. dev: Word;
  241. rdev: Word;
  242. nlink: Word;
  243. uid: Word;
  244. gid: Word;
  245. size: LongInt;
  246. blksize: LongInt;
  247. nblocks: LongInt;
  248. mtime: Word;
  249. mdate: Word;
  250. atime: Word;
  251. adate: Word;
  252. ctime: Word;
  253. cdate: Word;
  254. attr: Word;
  255. reserved2: Word;
  256. reserved3: Array[0..1] of LongInt;
  257. end;
  258. PSIGACTION = ^TSIGACTION;
  259. TSIGACTION = record
  260. sa_handler: Pointer;
  261. sa_mask: LongInt;
  262. sa_flags: Integer;
  263. end;
  264. function gemdos_Syield: smallint; syscall 1 255;
  265. function gemdos_Fpipe(var usrh: ARRAY of smallint): smallint; syscall 1 256;
  266. function gemdos_Ffchown(fd, uid, gid: smallint): longint; syscall 1 257;
  267. function gemdos_Ffchmod(fd: smallint; mode: word): longint; syscall 1 258;
  268. function gemdos_Fsync(fd: smallint): longint; syscall 1 259;
  269. function gemdos_Fcntl(f: smallint; arg: LongInt; cmd: smallint): smallint; syscall 1 260;
  270. function gemdos_Finstat(f: smallint): LongInt; syscall 1 261;
  271. function gemdos_Foutstat(f: smallint): LongInt; syscall 1 262;
  272. function gemdos_Fgetchar(f, mode: smallint): LongInt; syscall 1 263;
  273. function gemdos_Fputchar(f: smallint; c: LongInt; mode: smallint): LongInt; syscall 1 264;
  274. function gemdos_Pwait: LongInt; syscall 1 265;
  275. function gemdos_Pnice(delta : smallint): smallint; syscall 1 266;
  276. function gemdos_Pgetpid: smallint; syscall 1 267;
  277. function gemdos_Pgetppid: smallint; syscall 1 268;
  278. function gemdos_Pgetpgrp: smallint; syscall 1 269;
  279. function gemdos_Psetpgrp(pid, newgrp: smallint): smallint; syscall 1 270;
  280. function gemdos_Pgetuid: smallint; syscall 1 271;
  281. function gemdos_Psetuid(id: smallint): smallint; syscall 1 272;
  282. function gemdos_Pkill(pid, sig: smallint): smallint; syscall 1 273;
  283. function gemdos_Psignal(sig: smallint; handler: Pointer): Pointer; syscall 1 274;
  284. function gemdos_Pvfork: smallint; syscall 1 275;
  285. function gemdos_Pgetgid: smallint; syscall 1 276;
  286. function gemdos_Psetgid(id : smallint): smallint; syscall 1 277;
  287. function gemdos_Psigblock(mask: LongInt): LongInt; syscall 1 278;
  288. function gemdos_Psigsetmask(mask: LongInt): LongInt; syscall 1 279;
  289. function gemdos_Pusrval(arg: LongInt): LongInt; syscall 1 280;
  290. function gemdos_Pdomain(newdom: smallint): smallint; syscall 1 281;
  291. procedure gemdos_Psigreturn; syscall 1 282;
  292. function gemdos_Pfork: smallint; syscall 1 283;
  293. function gemdos_Pwait3(flag: smallint; var rusage: ARRAY of LongInt): LongInt; syscall 1 284;
  294. function gemdos_Fselect(timeout: Word; var rfds, wfds, xfds: LongInt): smallint; syscall 1 285;
  295. function gemdos_Prusage(var r: ARRAY of LongInt): LongInt; syscall 1 286;
  296. function gemdos_Psetlimit(lim: smallint; value: LongInt): LongInt; syscall 1 287;
  297. function gemdos_Talarm(secs: LongInt): LongInt; syscall 1 288;
  298. procedure gemdos_Pause; syscall 1 289;
  299. function gemdos_Sysconf(n: smallint): LongInt; syscall 1 290;
  300. function gemdos_Psigpending: LongInt; syscall 1 291;
  301. function gemdos_Dpathconf(const name: PAnsiChar; n: smallint): LongInt; syscall 1 292;
  302. function gemdos_Pmsg(mode: smallint; mbox: LongInt; var msg: TMSGTYPE): LongInt; syscall 1 293;
  303. function gemdos_Fmidipipe(pid, inp, outp: smallint): LongInt; syscall 1 294;
  304. function gemdos_Prenice(pid, delta: smallint): smallint; syscall 1 295;
  305. function gemdos_Dopendir(const name: PAnsiChar; flag: smallint): LongInt; syscall 1 296;
  306. function gemdos_Dreaddir(buflen: smallint; dir: LongInt; buf: PAnsiChar): LongInt; syscall 1 297;
  307. function gemdos_Drewinddir(dir: LongInt): LongInt; syscall 1 298;
  308. function gemdos_Dclosedir(dir: LongInt): LongInt; syscall 1 299;
  309. function gemdos_Fxattr(flag: smallint; const name: PAnsiChar; var buf: TXATTR): LongInt; syscall 1 300;
  310. function gemdos_Flink(const oldname: PAnsiChar; const newname: PAnsiChar): LongInt; syscall 1 301;
  311. function gemdos_Fsymlink(const oldname: PAnsiChar; const newname: PAnsiChar): LongInt; syscall 1 302;
  312. function gemdos_Freadlink(size: smallint; buf: PAnsiChar; const name: PAnsiChar): LongInt; syscall 1 303;
  313. function gemdos_Dcntl(cmd: smallint; const name: PAnsiChar; arg: LongInt): LongInt; syscall 1 304;
  314. function gemdos_Fchown(const name: PAnsiChar; uid, gid: smallint): LongInt; syscall 1 305;
  315. function gemdos_Fchmod(const name: PAnsiChar; mode: smallint): LongInt; syscall 1 306;
  316. function gemdos_Pumask(mode: Word): LongInt; syscall 1 307;
  317. function gemdos_Psemaphore(mode: smallint; id, timeout: LongInt): LongInt; syscall 1 308;
  318. function gemdos_Dlock(mode, drive: smallint): LongInt; syscall 1 309;
  319. procedure gemdos_Psigpause(mask: LongInt); syscall 1 310;
  320. function gemdos_Psigaction(sig: smallint; act, oact: PSIGACTION): LongInt; syscall 1 311;
  321. function gemdos_Pgeteuid: smallint; syscall 1 312;
  322. function gemdos_Pgetegid: smallint; syscall 1 313;
  323. function gemdos_Pwaitpid(pid, flag: smallint; var rusage: ARRAY of LongInt): LongInt; syscall 1 314;
  324. function gemdos_Dgetcwd(path: PAnsiChar; drv, size: smallint): LongInt; syscall 1 315;
  325. procedure gemdos_Salert(str: PAnsiChar); syscall 1 316;
  326. function gemdos_Tmalarm(time: longint): LongInt; syscall 1 317;
  327. { function gemdos_Psigintr(vec, sig: smallint): LongInt; syscall 1 318; }
  328. function gemdos_Suptime(var uptime: longint; var loadaverage: longint): LongInt; syscall 1 319;
  329. implementation
  330. end.