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 #if TARGET_MSDOS == 32 && defined(WIN386) /* Watcom Win386 does NOT translate LPARAM for us */
32 void far *win386_alt_winnt_MapAliasToFlat(DWORD farptr) {
33 /* FIXME: This only works by converting a 16:16 pointer directly to 16:32.
34 * It works perfectly fine in QEMU and DOSBox, but I seem to remember something
35 * about the x86 architecture and possible ways you can screw up using 16-bit
36 * data segments with 32-bit code. Are those rumors true? Am I going to someday
37 * load up Windows 3.1/95 on an ancient PC and find out this code crashes
38 * horribly or has random problems?
40 * We need this alternate path for Windows NT/2000/XP/Vista/7 because NTVDM.EXE
41 * grants Watcom386 a limited ~2GB limit for the flat data segment (usually
42 * 0x7B000000 or something like that) instead of the full 4GB limit the 3.x/9x/ME
43 * kernels usually grant. This matters because without the full 4GB limit we can't
44 * count on overflow/rollover to reach below our data segment base. Watcom386's
45 * MapAliasToFlat() unfortunately assumes just that. If we were to blindly rely
46 * on it, then we would work just fine under 3.x/9x/ME but crash under
47 * NT/2000/XP/Vista/7 the minute we need to access below our data segment (such as,
48 * when handling the WM_GETMINMAXINFO message the LPARAM far pointer usually
49 * points somewhere into NTVDM.EXE's DOS memory area when we're usually located
50 * at the 2MB mark or so) */
51 return MK_FP(farptr>>16,farptr&0xFFFF);
54 void far *win386_help_MapAliasToFlat(DWORD farptr) {
55 if (windows_mode == WINDOWS_NT)
56 return win386_alt_winnt_MapAliasToFlat(farptr);
58 return (void far*)MapAliasToFlat(farptr); /* MapAliasToFlat() returns near pointer, convert to far! */