]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/dos/testdpmi.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / dos / testdpmi.c
1 /* testdpmi.c
2  *
3  * Test program: DPMI entry/exit functions
4  * (C) 2009-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  */
10
11 #include <stdlib.h>
12 #include <string.h>
13 #include <stdint.h>
14 #include <assert.h>
15 #include <stdlib.h>
16 #include <stdarg.h>
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <conio.h>
20 #include <fcntl.h>
21 #include <dos.h>
22
23 #include <hw/cpu/cpu.h>
24 #include <hw/dos/dos.h>
25 #include <hw/dos/dosbox.h>
26 #include <hw/dos/doswin.h>
27
28 #ifdef TARGET_WINDOWS
29 #error wrong target
30 #endif
31
32 int main(int argc,char **argv) {
33         unsigned char want = DPMI_ENTER_AUTO;
34
35         if (argc > 1) {
36                 want = atoi(argv[1]);
37                 if (want < 16 || want > 32) return 1;
38         }
39
40         probe_dos();
41         printf("DOS version %x.%02u\n",dos_version>>8,dos_version&0xFF);
42         printf("    Method: '%s'\n",dos_version_method);
43         if (detect_windows()) {
44                 printf("I am running under Windows.\n");
45                 printf("    Mode: %s\n",windows_mode_str(windows_mode));
46                 printf("    Ver:  %x.%02u\n",windows_version>>8,windows_version&0xFF);
47                 printf("    Method: '%s'\n",windows_version_method);
48         }
49         else {
50                 printf("Not running under Windows or OS/2\n");
51         }
52
53         probe_dpmi();
54         if (!dpmi_present) {
55                 printf("This test requires DPMI\n");
56                 return 1;
57         }
58
59         printf("DPMI present:\n");
60 #if dpmi_no_0301h != 0
61         if (dpmi_no_0301h > 0) printf(" - DPMI function 0301H: Call real-mode far routine NOT AVAILABLE\n");
62 #endif
63         printf(" - Flags: 0x%04x\n",dpmi_flags);
64         printf(" - Entry: %04x:%04x (real mode)\n",(unsigned int)(dpmi_entry_point>>16UL),(unsigned int)(dpmi_entry_point & 0xFFFFUL));
65         printf(" - Processor type: %02x\n",dpmi_processor_type);
66         printf(" - Version: %u.%u\n",dpmi_version>>8,dpmi_version&0xFF);
67         printf(" - Private data length: %u paras\n",dpmi_private_data_length_paragraphs);
68
69         /* enter DPMI. the routine will briefly run in protected mode before finding it's way
70          * back to real mode where it can return back to this function */
71         if (!dpmi_enter(want)) {
72                 printf("Unable to enter DPMI server\n");
73                 return 1;
74         }
75         printf("Allocated DPMI private segment: 0x%04x\n",dpmi_private_data_segment);
76         printf("DPMI entered as %u-bit.\n",dpmi_entered);
77         printf(" - PM CS:%04x DS:%04x ES:%04x SS:%04x\n",dpmi_pm_cs,dpmi_pm_ds,dpmi_pm_es,dpmi_pm_ss);
78         printf(" - Real to protected entry: %04x:%04x [rmode]\n",
79                 (unsigned int)(dpmi_pm_entry>>16UL),(unsigned int)(dpmi_pm_entry&0xFFFFUL));
80         if (dpmi_entered == 32)
81                 printf(" - Protected to real entry: %04x:%08lx [pmode]\n",
82                         (unsigned int)((dpmi_rm_entry>>32ULL)&0xFFFFUL),(unsigned long)(dpmi_rm_entry&0xFFFFFFFFUL));
83         else
84                 printf(" - Protected to real entry: %04x:%04x [pmode]\n",
85                         (unsigned int)(dpmi_rm_entry>>16UL),(unsigned int)(dpmi_rm_entry&0xFFFFUL));
86
87         return 0;
88 }
89