3 * Code to detect the surrounding DOS/Windows environment and support routines to work with it
4 * (C) 2009-2012 Jonathan Campbell.
5 * Hackipedia DOS library.
7 * This code is licensed under the LGPL.
8 * <insert LGPL legal text here>
16 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
26 #include <hw/cpu/cpu.h>
27 #include <hw/dos/dos.h>
28 #include <hw/dos/doswin.h>
29 #include <hw/dos/dosntvdm.h>
31 /* TODO: Windows 3.1/95/98/ME have a DPMI server underneath.
32 * It would be neato at some point if these functions were
33 * available for use from Windows 3.1 Win16/Win32, and
34 * Windows 95/98/ME Win32 */
35 #if TARGET_MSDOS == 32 && !defined(TARGET_WINDOWS) && !defined(TARGET_OS2)
36 void dpmi_free_descriptor(uint16_t d) {
37 union REGS regs = {0};
38 regs.w.ax = 0x0001; /* DPMI free descriptor */
40 int386(0x31,®s,®s);
43 uint16_t dpmi_alloc_descriptors(uint16_t c) {
44 union REGS regs = {0};
45 regs.w.ax = 0x0000; /* allocate descriptor */
46 regs.w.cx = 1; /* just one */
47 int386(0x31,®s,®s);
48 if (regs.w.cflag & 1) return 0;
52 unsigned int dpmi_set_segment_base(uint16_t sel,uint32_t base) {
53 union REGS regs = {0};
54 regs.w.ax = 0x0007; /* set segment base */
56 regs.w.cx = base >> 16UL;
58 int386(0x31,®s,®s);
59 if (regs.w.cflag & 1) return 0;
63 unsigned int dpmi_set_segment_limit(uint16_t sel,uint32_t limit) {
64 union REGS regs = {0};
65 regs.w.ax = 0x0008; /* set segment limit */
67 regs.w.cx = limit >> 16UL;
69 int386(0x31,®s,®s);
70 if (regs.w.cflag & 1) return 0;
74 unsigned int dpmi_set_segment_access(uint16_t sel,uint16_t access) {
75 union REGS regs = {0};
78 /* the DPL/CPL value we give to the DPMI function below must match our privilege level, so
79 * get that value from our own selector */
88 regs.w.ax = 0x0009; /* set segment access rights */
90 regs.w.cx = (access & 0xFF9F) | (c << 5); /* readable, code, CPL=same, present=1, 16-bit byte granular */
91 int386(0x31,®s,®s);
92 if (regs.w.cflag & 1) return 0;