]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/dos/tstlp.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / dos / tstlp.c
1 /* tstlp.c
2  *
3  * Test program: DOS memory map awareness library
4  * (C) 2011-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 <stdio.h>
16 #include <conio.h>
17 #include <dos.h>
18
19 #include <hw/cpu/cpu.h>
20 #include <hw/dos/dos.h>
21 #include <hw/dos/dosbox.h>
22 #include <hw/dos/doswin.h>
23
24 #if TARGET_MSDOS == 32
25 uint16_t cpu_read_my_cs() {
26         uint16_t r=0;
27
28         __asm {
29                 push    cs
30                 pop     ax
31                 mov     r,ax
32         }
33
34         return r;
35 }
36 #endif
37
38 int main() {
39 #if TARGET_MSDOS == 32
40         uint16_t sg;
41         int c;
42 #endif
43
44         probe_dos();
45         printf("DOS version %x.%02u\n",dos_version>>8,dos_version&0xFF);
46         if (detect_windows()) {
47                 printf("I am running under Windows.\n");
48                 printf("    Mode: %s\n",windows_mode_str(windows_mode));
49                 printf("    Ver:  %x.%02u\n",windows_version>>8,windows_version&0xFF);
50         }
51         else {
52                 printf("Not running under Windows or OS/2\n");
53         }
54
55         if (detect_dosbox_emu())
56                 printf("I am also running under DOSBox\n");
57
58 #if TARGET_MSDOS == 16
59         /* TODO: Someday the dos_ltp() code will work in 16-bit mode, for environments like EMM386.EXE v86 or from within
60          *       the 16-bit Windows 3.1 world */
61         printf("This program is intended to test memory mapping under 32-bit protected mode and does not apply to 16-bit real mode\n");
62 #else
63         if (!dos_ltp_probe()) {
64                 printf("DOS linear->physical translation probe failed\n");
65                 return 1;
66         }
67
68         sg = cpu_read_my_cs();
69         printf("Results:\n");
70         printf("                Paging: %u   (CPU paging enabled)\n",dos_ltp_info.paging);
71         printf("             DOS remap: %u   (memory below 1MB is remapped, not 1:1)\n",dos_ltp_info.dos_remap);
72         printf("     Should lock pages: %u   (Extender may page to disk or move pages)\n",dos_ltp_info.should_lock_pages);
73         printf("           Can't xlate: %u   (No way to determine physical mem addr)\n",dos_ltp_info.cant_xlate);
74         printf("             Using PAE: %u   (DOS extender is using PAE)\n",dos_ltp_info.using_pae);
75         printf("         DMA DOS xlate: %u   (DMA is translated too, virtualized)\n",dos_ltp_info.dma_dos_xlate);
76         printf("        use VCPI xlate: %u   (VCPI server can provide translation)\n",dos_ltp_info.vcpi_xlate);
77         printf("                   CR0: 0x%08lx\n",dos_ltp_info.cr0);
78         printf("                   CR3: 0x%08lx\n",dos_ltp_info.cr3);
79         printf("                   CR4: 0x%08lx\n",dos_ltp_info.cr4);
80         printf("                    CS: 0x%04x %s CPL=%u\n",(unsigned int)sg,sg & 4 ? "LDT" : "GDT",sg&3);
81
82         while ((c=getch()) != 13) {
83                 if (c == 27) return 1;
84         }
85
86         {
87                 uint32_t l;
88                 uint64_t p;
89                 int line=0;
90
91                 printf("Map test (32MB):\n");
92                 for (l=0;l < (32UL << 20UL);l += 4096) {
93                         printf("0x%08lX: ",l); fflush(stdout);
94                         p = dos_linear_to_phys(l);
95                         if (p == DOS_LTP_FAILED) printf("N/A\n");
96                         else printf("0x%08llX\n",p);
97
98                         if (++line >= 24) {
99                                 line -= 24;
100                                 while ((c=getch()) != 13) {
101                                         if (c == 27) return 1;
102                                 }
103                         }
104                 }
105         }
106 #endif
107
108         return 0;
109 }
110