Wheefun I/O Library  0.0.5
Useful I/O Primitives.
dos.h
Go to the documentation of this file.
1 /* WFIO - the Wheefun IO Library
2  Copyright (C) 2018 Phillip Kilgore
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
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. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 
17  Additionally, you should have recieved a copy of the GNU Classpath
18  exception, which amends the license to generally permit linking against
19  the software provided herein.
20 */
21 
22 #ifndef WFIO_OS_DOS_H
23 #define WFIO_OS_DOS_H
24 
25 #include <wfio/type.h>
26 
43 
44 typedef wfio_sint16_t wfio_dos_sword_t;
45 typedef wfio_uint16_t wfio_dos_uword_t;
46 typedef wfio_sint32_t wfio_dos_sdword_t;
47 typedef wfio_uint32_t wfio_dos_udword_t;
48 
49 typedef enum wfio_dos_opendir_t {
50  WFIO_DOS_OMODE_RD,
51  WFIO_DOS_OMODE_WR,
52  WFIO_DOS_OMODE_RW,
53  WFIO_DOS_OMODE_BAD
54 } wfio_dos_opendir_t;
55 
56 typedef enum wfio_dos_share_t {
57  WFIO_DOS_SMODE_COMPAT,
58  WFIO_DOS_SMODE_RW,
59  WFIO_DOS_SMODE_RDONLY,
60  WFIO_DOS_SMODE_WRONLY,
61  WFIO_DOS_SMODE_FULL
62 } wfio_dos_share_t;
63 
64 typedef enum wfio_dos_fexist_t {
65  WFIO_DOS_FEXIST_ERR,
66  WFIO_DOS_FEXIST_OPEN,
67  WFIO_DOS_FEXIST_TRUNC
68 } wfio_dos_fexist_t;
69 
70 enum {
71  WFIO_DOS_NEXIST_CREAT = 0x10,
72 
73  /* Version Constants */
74 
79 
84 
89 
94 
99 
104 
109 
114 
119 };
120 
124 typedef union wfio_dos_sversion_t {
125 
129  struct {
130  #ifdef WFIO_ENDIAN_HOST_IS_LIL
131  wfio_uint8_t min;
132  wfio_uint8_t maj;
133  #else
134  wfio_uint8_t maj;
135  wfio_uint8_t min;
136  #endif
137 
147  } u8;
148 
152  wfio_dos_uword_t u16;
154 
158 typedef wfio_dos_uword_t wfio_dos_version_t;
159 
163 typedef union wfio_dos_openflags_t {
164  struct {
168  wfio_dos_uword_t mode:3;
169  wfio_dos_uword_t resv0_:1;
170  wfio_dos_uword_t share:3;
171  wfio_dos_uword_t priv:1;
172  wfio_dos_uword_t resv1_:5;
173  wfio_dos_uword_t eret:1;
174  wfio_dos_uword_t acommit:1;
175  wfio_dos_uword_t resv2_:1;
176  } bits;
177  wfio_dos_uword_t raw;
179 
180 typedef union wfio_dos_fileattr_t {
181  struct {
182  wfio_uint8_t rdonly:1;
183  wfio_uint8_t hidden:1;
184  wfio_uint8_t system:1;
185  wfio_uint8_t vlabel:1;
186  wfio_uint8_t subdir:1;
187  wfio_uint8_t archive:1;
188  wfio_uint8_t resv0_:1;
189  } bits;
190  wfio_uint8_t raw;
192 
193 typedef union wfio_dos_creat_t {
194  struct {
195  wfio_dos_uword_t exist:4;
196  wfio_dos_uword_t create:4;
197  } bits;
198  wfio_uint8_t raw;
200 
201 typedef struct wfio_dos_open_t {
202  wfio_dos_openflags_t omode;
203  wfio_dos_fileattr_t fmode;
204  wfio_dos_creat_t cmode;
206 
207 
208 /* DPMI */
209 
210 typedef struct wfio_dos_dpmi_regsd_t {
211  /* Indexing Registers */
212 
216  wfio_dos_udword_t edi;
217 
221  wfio_dos_udword_t esi;
222 
226  wfio_dos_udword_t ebp;
227 
231  wfio_dos_udword_t res;
232 
233  /* General-purpose registers */
234 
238  wfio_dos_udword_t ebx;
239 
243  wfio_dos_uword_t edx;
244 
248  wfio_dos_udword_t ecx;
249 
253  wfio_dos_udword_t eax;
254 
255 
256  /* Flags */
257 
261  wfio_dos_uword_t flags;
262 
266  wfio_dos_uword_t es;
267 
271  wfio_dos_uword_t ds;
272 
276  wfio_dos_uword_t fs;
277 
281  wfio_dos_uword_t gs;
282 
283  /* Other registers */
284 
288  wfio_dos_uword_t ip;
289 
293  wfio_dos_uword_t cs;
294 
298  wfio_dos_uword_t sp;
299 
303  wfio_dos_uword_t ss;
305 
306 typedef struct wfio_dos_dpmi_regsw_t {
307  /* Indexing Registers */
308 
312  wfio_dos_uword_t di;
313 
317  wfio_dos_uword_t diHi;
318 
322  wfio_dos_uword_t si;
323 
327  wfio_dos_uword_t siHi;
328 
332  wfio_dos_uword_t bp;
333 
337  wfio_dos_uword_t bpHi;
338 
342  wfio_dos_udword_t res;
343 
344  /* General-purpose registers */
345 
349  wfio_dos_uword_t bx;
350 
354  wfio_dos_uword_t bxHi;
355 
359  wfio_dos_uword_t dx;
360 
364  wfio_dos_uword_t dxHi;
365 
369  wfio_dos_uword_t cx;
370 
374  wfio_dos_uword_t cxHi;
375 
379  wfio_dos_uword_t ax;
380 
384  wfio_dos_uword_t axHi;
385 
386  /* Flags */
387 
391  wfio_dos_uword_t flags;
392 
393  /* Spare Segment Registers */
394  wfio_dos_uword_t es;
395  wfio_dos_uword_t ds;
396  wfio_dos_uword_t fs;
397  wfio_dos_uword_t gs;
398 
399  /* Other registers */
400  wfio_dos_uword_t ip;
401  wfio_dos_uword_t cs;
402  wfio_dos_uword_t sp;
403  wfio_dos_uword_t ss;
405 
406 typedef struct wfio_dos_dpmi_regsb_t {
407  /* Indexing Registers */
408 
412  wfio_dos_uword_t di;
413 
417  wfio_dos_uword_t diHi;
418 
422  wfio_dos_uword_t si;
423 
427  wfio_dos_uword_t siHi;
428 
432  wfio_dos_uword_t bp;
433 
437  wfio_dos_uword_t bpHi;
438 
442  wfio_dos_udword_t res;
443 
444  /* General-purpose registers */
445 
449  wfio_uint8_t bl;
450 
454  wfio_uint8_t bh;
455 
459  wfio_uint8_t blHi;
460 
464  wfio_uint8_t bhHi;
465 
469  wfio_uint8_t dl;
470 
474  wfio_uint8_t dh;
475 
479  wfio_uint8_t dlHi;
480 
484  wfio_uint8_t dhHi;
485 
489  wfio_uint8_t cl;
490 
494  wfio_uint8_t ch;
495 
499  wfio_uint8_t clHi;
500 
504  wfio_uint8_t chHi;
505 
509  wfio_uint8_t al;
510 
514  wfio_uint8_t ah;
515 
519  wfio_uint8_t alHi;
520 
524  wfio_uint8_t ahHi;
525 
526  /* Flags */
527 
531  wfio_dos_uword_t flags;
532 
533  /* Spare Segment Registers */
534 
538  wfio_dos_uword_t es;
539 
543  wfio_dos_uword_t ds;
544 
548  wfio_dos_uword_t fs;
549 
553  wfio_dos_uword_t gs;
554 
555  /* Other registers */
556 
560  wfio_dos_uword_t ip;
561 
565  wfio_dos_uword_t cs;
566 
570  wfio_dos_uword_t sp;
571 
575  wfio_dos_uword_t ss;
577 
581 typedef union wfio_dos_dpmi_regs_t {
595 
599 typedef struct wfio_dos_farptr_t {
603  wfio_dos_uword_t segment;
607  wfio_dos_uword_t offset;
609 
614  wfio_dos_uword_t segment, wfio_dos_uword_t offset) {
615  register wfio_dos_farptr_t ret = { .segment = segment, .offset=offset };
616  return ret;
617 }
618 
619 #ifdef WFIO_COMPILER_DJGPP
620 #include <dpmi.h>
621 typedef union wfio_dos_dpmi_regs_t wfio_dos_regs_t;
622 
623 /* Call __dpmi_regs directly. */
624 WFIO_ALWAYS_INLINE int wfio_dos_dpmi_int(int vector,
625  wfio_dos_dpmi_regs_t* regs) {
626  return __dpmi_int(vector, (__dpmi_regs*) regs) != -1;
627 }
628 
629 WFIO_ALWAYS_INLINE int wfio_dos_int(int vector, wfio_dos_regs_t* regs) {
630  return __dpmi_int(vector, (__dpmi_regs*) regs) != -1;
631 }
632 
633 #define WFIO_DOS_INT_INLINE_
634 #else
635 
636 typedef union wfio_dos_dpmi_regs_t wfio_dos_regs_t;
637 
638 WFIO_DLL_FASTCALL int wfio_dos_dpmi_int(int vector,
639  wfio_dos_dpmi_regs_t* regs);
640 
641 WFIO_DLL_FASTCALL int wfio_dos_int(int vector, wfio_dos_regs_t* regs);
642 #endif
643 
678 WFIO_ALWAYS_INLINE int wfio_dos_syscall(wfio_dos_regs_t* regs) {
679  return wfio_dos_int(0x21, regs);
680 }
681 
692 
711 WFIO_DLL_FASTCALL int wfio_dos_open3C(const char* path,
712  wfio_dos_fileattr_t attrs, int* error);
713 
731 WFIO_DLL_FASTCALL int wfio_dos_open3D(const char* path,
732  wfio_dos_openflags_t flags, int* error);
733 
751 WFIO_DLL_FASTCALL int wfio_dos_open6C(const char* path,
752  wfio_dos_open_t flags, int* error);
753 
770 WFIO_DLL_FASTCALL int wfio_dos_openEx(const char* path, wfio_dos_open_t flags,
771  wfio_dos_version_t ver, int* error);
772 
787  int* error) {
788  return wfio_dos_openEx(path, flags, 0x0, error);
789 }
790 
791 /* Conversion */
792 
801  wfio_dos_open_t flags);
802 
803 WFIO_DLL_FASTCALL wfio_dos_open_t wfio_dos_wfioToOpen(
804  wfio_openmode_t flags);
805 
807 
808 #endif
wfio_dos_udword_t edi
Synonymous with the 80386&#39;s edi register.
Definition: dos.h:216
Definition: dos.h:210
wfio_dos_uword_t offset
This far pointer&#39;s offset.
Definition: dos.h:607
WFIO_ALWAYS_INLINE wfio_dos_farptr_t wfio_dos_farptr(wfio_dos_uword_t segment, wfio_dos_uword_t offset)
Construct a new far pointer.
Definition: dos.h:613
WFIO_DLL_FASTCALL int wfio_dos_open6C(const char *path, wfio_dos_open_t flags, int *error)
Open a new file handle by invoking DOS system call 0x3C.
wfio_uint8_t dlHi
Synonymous with the the third byte of the edx register.
Definition: dos.h:479
union wfio_dos_sversion_t wfio_dos_sversion_t
A DOS version broken out into its components.
wfio_dos_uword_t bpHi
The upper half of the ebp register.
Definition: dos.h:437
wfio_dos_uword_t axHi
The upper half of the eax register.
Definition: dos.h:384
wfio_uint8_t clHi
Synonymous with the the third byte of the ecx register.
Definition: dos.h:499
#define WFIO_C_BEGIN
Definition: host.h:477
wfio_dos_uword_t diHi
The upper half of the edi register.
Definition: dos.h:417
wfio_dos_udword_t res
Reserved by the system.
Definition: dos.h:231
wfio_dos_udword_t ebx
Synonymous with the 80386&#39;s ebx register.
Definition: dos.h:238
#define WFIO_DLL_FASTCALL
Shorthand for WFIO_DLL WFIO_FASTCALL.
Definition: host.h:425
wfio_uint8_t dh
Synonymous with the 8086&#39;s dh register.
Definition: dos.h:474
Open flags supplied to wfio_dos_open() or wfio_dos_openEx().
Definition: dos.h:163
Definition: dos.h:193
wfio_dos_udword_t ebp
Synonymous with the 80386&#39;s ebp register.
Definition: dos.h:226
wfio_dos_uword_t ds
Synonymous with the 8086&#39;s ds register.
Definition: dos.h:271
wfio_dos_uword_t cx
Synonymous with the 8086&#39;s cx register.
Definition: dos.h:369
wfio_dos_uword_t siHi
The upper half of the esi register.
Definition: dos.h:327
wfio_dos_uword_t di
Synonymous with the 8086&#39;s di register.
Definition: dos.h:412
Definition: dos.h:406
DOS version 1.25.
Definition: dos.h:93
wfio_dos_uword_t gs
Synonymous with the 80286&#39;s gs register.
Definition: dos.h:553
WFIO_DLL_FASTCALL wfio_openmode_t wfio_dos_openToWFIO(wfio_dos_open_t flags)
Convert a DOS open mode to a WFIO open mode.
wfio_dos_uword_t es
Synonymous with the 8086&#39;s es register.
Definition: dos.h:538
wfio_dos_uword_t fs
Synonymous with the 80286&#39;s fs register.
Definition: dos.h:276
DOS version 4.0.
Definition: dos.h:108
A register set corresponding to a DPMI interrupt call.
Definition: dos.h:581
wfio_dos_udword_t res
Reserved by the system.
Definition: dos.h:442
wfio_dos_uword_t fs
Synonymous with the 80286&#39;s fs register.
Definition: dos.h:548
#define WFIO_ALWAYS_INLINE
Mark this symbol to be forced inline.
Definition: host.h:447
wfio_uint8_t ah
Synonymous with the 8086&#39;s ah register.
Definition: dos.h:514
wfio_dos_uword_t cxHi
The upper half of the ecx register.
Definition: dos.h:374
wfio_dos_udword_t res
Reserved by the system.
Definition: dos.h:342
wfio_dos_uword_t flags
Synonymous with the 8086&#39;s flags register.
Definition: dos.h:531
wfio_dos_uword_t bp
Synonymous with the 8086&#39;s bp register.
Definition: dos.h:432
wfio_dos_udword_t eax
Synonymous with the 80386&#39;s ax register.
Definition: dos.h:253
DOS version 5.0.
Definition: dos.h:118
union wfio_dos_dpmi_regs_t wfio_dos_dpmi_regs_t
A register set corresponding to a DPMI interrupt call.
wfio_dos_dpmi_regsw_t w
Treat this register set as 16-bit registers.
Definition: dos.h:589
wfio_uint8_t dl
Synonymous with the 8086&#39;s dl register.
Definition: dos.h:469
wfio_dos_dpmi_regsd_t d
Treat this register set as 32-bit registers.
Definition: dos.h:585
wfio_dos_uword_t segment
This far pointer&#39;s segment.
Definition: dos.h:603
wfio_dos_uword_t siHi
The upper half of the esi register.
Definition: dos.h:427
WFIO_DLL_FASTCALL wfio_dos_version_t wfio_dos_version()
Obtain the current DOS version.
The DOS version of the host.
Definition: dos.h:83
wfio_uint8_t ch
Synonymous with the 8086&#39;s ah register.
Definition: dos.h:494
WFIO_DLL_FASTCALL int wfio_dos_openEx(const char *path, wfio_dos_open_t flags, wfio_dos_version_t ver, int *error)
Open a new file by invoking the appropriate DOS system call and by specifying the version...
wfio_uint8_t bhHi
Synonymous with the the fourth byte of the ebx register.
Definition: dos.h:464
wfio_dos_uword_t edx
Synonymous with the 80386&#39;s edx register.
Definition: dos.h:243
wfio_dos_uword_t ip
Synonymous with the 8086&#39;s ip register.
Definition: dos.h:560
wfio_dos_uword_t sp
Synonymous with the 8086&#39;s cs register.
Definition: dos.h:298
DOS version 2.0.
Definition: dos.h:98
wfio_uint8_t blHi
Synonymous with the the third byte of the ebx register.
Definition: dos.h:459
WFIO_ALWAYS_INLINE int wfio_dos_open(const char *path, wfio_dos_open_t flags, int *error)
Open a new file by invoking the appropriate DOS system call and by specifying the version...
Definition: dos.h:786
wfio_dos_uword_t ds
Synonymous with the 8086&#39;s ds register.
Definition: dos.h:543
Definition: dos.h:306
wfio_dos_udword_t esi
Synonymous with the 80386&#39;s esi register.
Definition: dos.h:221
DOS version 1.0.
Definition: dos.h:88
A DOS version broken out into its components.
Definition: dos.h:124
Definition: dos.h:201
WFIO_ALWAYS_INLINE int wfio_dos_syscall(wfio_dos_regs_t *regs)
Invoke a DOS system call.
Definition: dos.h:678
wfio_dos_uword_t si
Synonymous with the 8086&#39;s si register.
Definition: dos.h:322
wfio_uint8_t alHi
Synonymous with the the third byte of the eax register.
Definition: dos.h:519
#define WFIO_C_END
Definition: host.h:485
struct wfio_dos_sversion_t::@16 u8
The DOS version split into major and minor versions.
wfio_uint8_t ahHi
Synonymous with the the fourth byte of the eax register.
Definition: dos.h:524
wfio_uint8_t al
Synonymous with the 8086&#39;s al register.
Definition: dos.h:509
wfio_dos_uword_t bpHi
The upper half of the ebp register.
Definition: dos.h:337
The DOS version is not known.
Definition: dos.h:78
wfio_dos_uword_t di
Synonymous with the 8086&#39;s di register.
Definition: dos.h:312
wfio_dos_uword_t flags
Synonymous with the 8086&#39;s flags register.
Definition: dos.h:391
wfio_dos_uword_t dx
Synonymous with the 8086&#39;s dx register.
Definition: dos.h:359
wfio_uint8_t dhHi
Synonymous with the the fourth byte of the edx register.
Definition: dos.h:484
wfio_dos_udword_t ecx
Synonymous with the 80386&#39;s ecx register.
Definition: dos.h:248
WFIO_DLL_FASTCALL int wfio_dos_open3D(const char *path, wfio_dos_openflags_t flags, int *error)
Open a new file handle by invoking DOS system call 0x3D.
wfio_dos_uword_t mode
The mode to open the file with.
Definition: dos.h:168
wfio_dos_uword_t u16
The 16-bit word corresponding to the version.
Definition: dos.h:152
wfio_dos_uword_t cs
Synonymous with the 8086&#39;s cs register.
Definition: dos.h:293
wfio_dos_uword_t flags
Synonymous with the 8086&#39;s flags register.
Definition: dos.h:261
A far pointer.
Definition: dos.h:599
wfio_uint8_t bh
Synonymous with the 8086&#39;s bh register.
Definition: dos.h:454
wfio_dos_uword_t gs
Synonymous with the 80286&#39;s gs register.
Definition: dos.h:281
wfio_dos_uword_t ax
Synonymous with the 8086&#39;s ax register.
Definition: dos.h:379
wfio_dos_uword_t ss
Synonymous with the 8086&#39;s ss register.
Definition: dos.h:575
wfio_uint8_t cl
Synonymous with the 8086&#39;s al register.
Definition: dos.h:489
wfio_uint8_t bl
Synonymous with the 8086&#39;s bl register.
Definition: dos.h:449
struct wfio_dos_farptr_t wfio_dos_farptr_t
A far pointer.
wfio_uint8_t chHi
Synonymous with the the fourth byte of the ecx register.
Definition: dos.h:504
Definition: dos.h:180
union wfio_dos_openflags_t wfio_dos_openflags_t
Open flags supplied to wfio_dos_open() or wfio_dos_openEx().
wfio_dos_uword_t ip
Synonymous with the 8086&#39;s ip register.
Definition: dos.h:288
wfio_dos_uword_t bxHi
The upper half of the ebx register.
Definition: dos.h:354
wfio_dos_uword_t es
Synonymous with the 8086&#39;s es register.
Definition: dos.h:266
DOS version 3.0.
Definition: dos.h:103
wfio_dos_uword_t cs
Synonymous with the 8086&#39;s cs register.
Definition: dos.h:565
DOS version 4.0.
Definition: dos.h:113
wfio_dos_uword_t ss
Synonymous with the 8086&#39;s ss register.
Definition: dos.h:303
wfio_dos_uword_t dxHi
The upper half of the edx register.
Definition: dos.h:364
wfio_dos_dpmi_regsb_t b
Treat this register set as 8-bit registers.
Definition: dos.h:593
wfio_dos_uword_t wfio_dos_version_t
The integral type of a dos version.
Definition: dos.h:158
WFIO_DLL_FASTCALL int wfio_dos_open3C(const char *path, wfio_dos_fileattr_t attrs, int *error)
Open a new file handle by invoking DOS system call 0x3C.
wfio_dos_uword_t si
Synonymous with the 8086&#39;s si register.
Definition: dos.h:422
wfio_dos_uword_t diHi
The upper half of the edi register.
Definition: dos.h:317
wfio_dos_uword_t bp
Synonymous with the 8086&#39;s bp register.
Definition: dos.h:332
wfio_dos_uword_t bx
Synonymous with the 8086&#39;s bx register.
Definition: dos.h:349
Shared type definitions.
int wfio_openmode_t
The type corresponding to an openmode.
Definition: iotype.h:103
wfio_dos_uword_t sp
Synonymous with the 8086&#39;s cs register.
Definition: dos.h:570