1 {
2     Copyright (c) 2016 by Free Pascal development team
3 
4     GEMDOS interface unit for Atari TOS
5 
6     See the file COPYING.FPC, included in this distribution,
7     for details about the copyright.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13  **********************************************************************}
14 
15 unit gemdos;
16 
17 interface
18 
19 { The API description of this file is based on the information available
20   online at: http://toshyp.atari.org }
21 
22 const
23     E_OK        = 0;       // OK. No error has arisen
numbernull24     EINVFN      = -32;     // Unknown function number
25     EFILNF      = -33;     // File not found
26     EPTHNF      = -34;     // Directory (folder) not found
27     ENHNDL      = -35;     // No more handles available
28     EACCDN      = -36;     // Access denied
29     EIHNDL      = -37;     // Invalid file handle
30     ENSMEM      = -39;     // Insufficient memory
31     EIMBA       = -40;     // Invalid memory block address
32     EDRIVE      = -46;     // Invalid drive specification
33     ECWD        = -47;     // Current directory cannot be deleted
34     ENSAME      = -48;     // Files on different logical drives
35     ENMFIL      = -49;     // No more files can be opened
36     ELOCKED     = -58;     // Segment of a file is protected (network)
37     ENSLOCK     = -59;     // Invalid lock removal request
38     ERANGE      = -64;     // File pointer in invalid segment (see also FreeMiNT message -88)
39     EINTRN      = -65;     // Internal error of GEMDOS
40     EPLFMT      = -66;     // Invalid program load format
41     EGSBF       = -67;     // Allocated memory block could not be enlarged
42     EBREAK      = -68;     // Program termination by Control-C
43     EXCPT       = -69;     // 68000 exception (bombs)
44     EPTHOV      = -70;     // Path overflow
45     ELOOP       = -80;     // Endless loop with symbolic links
46     EPIPE       = -81;     // Write to broken pipe.
47 
48 // as used by fseek
49 const
50     SEEK_FROM_START   = 0;
51     SEEK_FROM_CURRENT = 1;
52     SEEK_FROM_END     = 2;
53 
54 // as used by fcreate and fattrib
55 const
56     ATTRIB_WRITE_PROT   = ( 1 shl 0 );
57     ATTRIB_HIDDEN       = ( 1 shl 1 );
58     ATTRIB_SYSTEM       = ( 1 shl 2 );
59     ATTRIB_VOLUME_LABEL = ( 1 shl 3 );
60     ATTRIB_DIRECTORY    = ( 1 shl 4 );
61     ATTRIB_ARCHIVE      = ( 1 shl 5 );
62 
63 // as used by fopen
64 const
65     OPEN_READ_ONLY      = ( 1 shl 0 );
66     OPEN_WRITE_ONLY     = ( 1 shl 1 );
67     OPEN_READ_WRITE     = ( 1 shl 2 );
68 
69 // as used by fattrib
70 const
71     FLAG_GET            = 0;
72     FLAG_SET            = 1;
73 
74 // as used by mxalloc
75 const
76     MXALLOC_ST          = 0;
77     MXALLOC_ALT         = 1;
78     MXALLOC_PREFER_ST   = 2;
79     MXALLOC_PREFER_ALT  = 3;
80 
81     MXALLOC_PROT_DEFAULT     = (0 shl 4);
82     MXALLOC_PROT_PRIVATE     = (1 shl 4);
83     MXALLOC_PROT_GLOBAL      = (2 shl 4);
84     MXALLOC_PROT_SUPER_ONLY  = (3 shl 4);
85     MXALLOC_PROT_WORLD_READ  = (4 shl 4);
86 
87     MXALLOC_NO_FREE          = (1 shl 14);
88 
89 type
90     PDTA = ^TDTA;
91     TDTA = packed record
92         d_reserved: array[0..20] of shortint; {* Reserved for GEMDOS *}
93         d_attrib: byte;                       {* File attributes     *}
94         d_time: word;                         {* Time                *}
95         d_date: word;                         {* Date                *}
96         d_length: dword;                      {* File length         *}
97         d_fname: array[0..13] of char;        {* Filename            *}
98     end;
99 
100 type
101     PDISKINFO = ^TDISKINFO;
102     TDISKINFO = record
103         b_free: dword;        {* Number of free clusters  *}
104         b_total: dword;       {* Total number of clusters *}
105         b_secsiz: dword;      {* Bytes per sector         *}
106         b_clsiz: dword;       {* Sector per cluster       *}
107     end;
108 
109 type
110     PDOSTIME = ^TDOSTIME;
111     TDOSTIME = record
112         time: word;           {* Time like Tgettime *}
113         date: word;           {* Date like Tgetdate *}
114     end;
115 
116 type
117   PPD = ^TPD;
118   TPD = record
119       p_lowtpa: pointer;      {* Start address of the TPA            *}
120       p_hitpa: pointer;       {* First byte after the end of the TPA *}
121       p_tbase: pointer;       {* Start address of the program code   *}
122       p_tlen: longint;        {* Length of the program code          *}
123       p_dbase: pointer;       {* Start address of the DATA segment   *}
124       p_dlen: longint;        {* Length of the DATA section          *}
125       p_bbase: pointer;       {* Start address of the BSS segment    *}
126       p_blen: longint;        {* Length of the BSS section           *}
127       p_dta: PDTA;            {* Pointer to the default DTA          *}
128                               {* Warning: Points first to the        *}
129                               {* command line !                      *}
130       p_parent: PPD;          {* Pointer to the basepage of the      *}
131                               {* calling processes                   *}
132       p_resrvd0: longint;     {* Reserved                            *}
133       p_env: pchar;           {* Address of the environment string   *}
134       p_resrvd1: array[0..79] of char;   {* Reserved                            *}
135       p_cmdlin: array[0..127] of char;   {* Command line                        *}
136   end;
137   TBASEPAGE = TPD; {* alias types... *}
138   PBASEPAGE = ^TBASEPAGE;
139 
140 type
141   PLINE = ^TLINE;
142   TLINE = record
143       maxlen: byte;        {* Maximum line length *}
144       actuallen: byte;     {* Current line length *}
145       buffer: array[0..254] of byte;   {* Line buffer         *}
146   end;
147 
148 
149 procedure gemdos_pterm0; syscall 1 0;
gemdos_cconinnull150 function gemdos_cconin: longint; syscall 1 1;
gemdos_cconoutnull151 function gemdos_cconout(c: smallint): longint; syscall 1 2;
gemdos_cauxinnull152 function gemdos_cauxin: longint; syscall 1 3;
gemdos_cauxoutnull153 function gemdos_cauxout(c: smallint): longint; syscall 1 4;
gemdos_cprnoutnull154 function gemdos_cprnout(c: smallint): longint; syscall 1 5;
gemdos_crawionull155 function gemdos_crawio(c: smallint): longint; syscall 1 6;
gemdos_crawinnull156 function gemdos_crawin: longint; syscall 1 7;
gemdos_cnecinnull157 function gemdos_cnecin: longint; syscall 1 8;
158 procedure gemdos_cconws(p: pchar); syscall 1 9;
gemdos_cconrsnull159 function gemdos_cconrs(buf: PLINE): longint; syscall 1 10;
gemdos_cconisnull160 function gemdos_cconis: longint; syscall 1 11;
161 
gemdos_dsetdrvnull162 function gemdos_dsetdrv(drv: smallint): longint; syscall 1 14;
163 
gemdos_cconosnull164 function gemdos_cconos: smallint; syscall 1 16;
gemdos_cprnosnull165 function gemdos_cprnos: smallint; syscall 1 17;
gemdos_cauxisnull166 function gemdos_cauxis: smallint; syscall 1 18;
gemdos_cauxosnull167 function gemdos_cauxos: smallint; syscall 1 19;
gemdos_maddaltnull168 function gemdos_maddalt(start: pointer; size: longint): longint; syscall 1 20;
gemdos_sreallocnull169 function gemdos_srealloc(len: longint): longint; syscall 1 21;
170 
gemdos_dgetdrvnull171 function gemdos_dgetdrv: smallint; syscall 1 25;
172 procedure gemdos_setdta(buf: PDTA); syscall 1 26;
173 
gemdos_supernull174 function gemdos_super(stack: pointer): longint; syscall 1 32;
175 
gemdos_tgetdatenull176 function gemdos_tgetdate: longint; syscall 1 42;
gemdos_tsetdatenull177 function gemdos_tsetdate(date: word): smallint; syscall 1 43;
gemdos_tgettimenull178 function gemdos_tgettime: longint; syscall 1 44;
gemdos_tsettimenull179 function gemdos_tsettime(time: word): smallint; syscall 1 45;
180 
gemdos_getdtanull181 function gemdos_getdta: PDTA; syscall 1 47;
gemdos_sversionnull182 function gemdos_sversion: smallint; syscall 1 48;
183 
gemdos_dfreenull184 function gemdos_dfree(buf: PDISKINFO; driveno: smallint): smallint; syscall 1 54;
185 
gemdos_dcreatenull186 function gemdos_dcreate(const path: pchar): longint; syscall 1 57;
gemdos_ddeletenull187 function gemdos_ddelete(const path: pchar): longint; syscall 1 58;
gemdos_dsetpathnull188 function gemdos_dsetpath(path: pchar): smallint; syscall 1 59;
gemdos_fcreatenull189 function gemdos_fcreate(fname: pchar; attr: smallint): smallint; syscall 1 60;
gemdos_fopennull190 function gemdos_fopen(fname: pchar; mode: smallint): longint; syscall 1 61;
gemdos_fclosenull191 function gemdos_fclose(handle: smallint): smallint; syscall 1 62;
gemdos_freadnull192 function gemdos_fread(handle: smallint; count: longint; buf: pointer): longint; syscall 1 63;
gemdos_fwritenull193 function gemdos_fwrite(handle: smallint; count: longint; buf: pointer): longint; syscall 1 64;
gemdos_fdeletenull194 function gemdos_fdelete(fname: pchar): smallint; syscall 1 65;
gemdos_fseeknull195 function gemdos_fseek(offset: longint; handle: smallint; seekmode: smallint): longint; syscall 1 66;
gemdos_fattribnull196 function gemdos_fattrib(filename: pchar; wflag: smallint; attrib: smallint): smallint; syscall 1 67;
gemdos_mxallocnull197 function gemdos_mxalloc(amount: longint; mode: smallint): pointer; syscall 1 68;
gemdos_fdupnull198 function gemdos_fdup(handle: smallint): smallint; syscall 1 69;
gemdos_fforcenull199 function gemdos_fforce(stdh: smallint; nonstdh: smallint): smallint; syscall 1 70;
gemdos_dgetpathnull200 function gemdos_dgetpath(path: pchar; driveno: smallint): smallint; syscall 1 71;
gemdos_mallocnull201 function gemdos_malloc(number: dword): pointer; syscall 1 72;
gemdos_freenull202 function gemdos_free(block: pointer): dword; syscall 1 73;
gemdos_mshrinknull203 function gemdos_mshrink(zero: word; block: pointer; newsiz: longint): longint; syscall 1 74;
gemdos_pexecnull204 function gemdos_pexec(mode: word; name: pchar; cmdline: pchar; env: pchar): longint; syscall 1 75;
205 procedure gemdos_pterm(returncode: smallint); syscall 1 76;
206 
gemdos_fsfirstnull207 function gemdos_fsfirst(filename: pchar; attr: smallint): longint; syscall 1 78;
gemdos_fsnextnull208 function gemdos_fsnext: smallint; syscall 1 79;
209 
gemdos_frenamenull210 function gemdos_frename(zero: word; oldname: pchar; newname: pchar): longint; syscall 1 86;
211 procedure gemdos_fdatime(timeptr: PDOSTIME; handle: smallint; wflag: smallint); syscall 1 87;
212 
213 implementation
214 
215 end.
216