]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/hw/flatreal/test.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / hw / flatreal / test.c
1 /* Test program to demonstrate using the Flat Real Mode library.
2  *
3  * Interesting results:
4  *    - Most modern CPUs do not seem to enforce segment limits in real mode.
5  *      But anything prior to (about) a Pentium II will, especially if made by Intel.
6  *    - Most emulators seem to not enforce real mode segment limits either.
7  *      DOSBox and Virtual Box completely ignore limits. Bochs and Microsoft Virtual
8  *      PC 2007 enforce segment limits.
9  */
10
11 #include <stdlib.h>
12 #include <string.h>
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <conio.h>
16 #include <dos.h>
17
18 #include <hw/cpu/cpu.h>
19 #include <hw/dos/dos.h>
20 #include <hw/dos/doswin.h>
21 #include <hw/flatreal/flatreal.h>
22
23 int main() {
24 #if TARGET_MSDOS == 16
25         cpu_probe();
26         probe_dos();
27         printf("DOS version %x.%02u\n",dos_version>>8,dos_version&0xFF);
28         if (detect_windows()) {
29                 printf("I am running under Windows.\n");
30                 printf("    Mode: %s\n",windows_mode_str(windows_mode));
31                 printf("    Ver:  %x.%02u\n",windows_version>>8,windows_version&0xFF);
32         }
33         else {
34                 printf("Not running under Windows or OS/2\n");
35         }
36
37         if (flatrealmode_setup(FLATREALMODE_4GB)) {
38                 unsigned int i;
39                 unsigned char c;
40                 unsigned long d;
41                 unsigned short w;
42
43                 for (i=0;i < 0x40;i++) {
44                         c = flatrealmode_readb(0xB8000UL + (uint32_t)i);
45                         printf("%02X ",c);
46                 }
47                 printf("\n");
48                 for (i=0;i < 0x40;i++) {
49                         flatrealmode_writeb(0xB8000UL + (uint32_t)i,i);
50                 }
51                 while (getch() != 13);
52                 printf("\n");
53
54                 for (i=0;i < 0x40;i++) {
55                         w = flatrealmode_readw(0xB8000UL + (uint32_t)(i*2));
56                         printf("%04X ",w);
57                 }
58                 printf("\n");
59                 for (i=0;i < 0x40;i++) {
60                         flatrealmode_writew(0xB8000UL + (uint32_t)(i*2),i*0x101);
61                 }
62                 while (getch() != 13);
63                 printf("\n");
64
65                 for (i=0;i < 0x40;i++) {
66                         d = flatrealmode_readd(0xB8000UL + (uint32_t)(i*4));
67                         printf("%08lX ",(unsigned long)d);
68                 }
69                 printf("\n");
70                 for (i=0;i < 0x40;i++) {
71                         flatrealmode_writed(0xB8000UL + (uint32_t)(i*4),i*0x1010101UL);
72                 }
73                 while (getch() != 13);
74
75                 printf("Flat real mode testing: will your CPU GP# fault if I access beyond 64KB?\n");
76
77                 flatrealmode_setup(FLATREALMODE_4GB);  i = flatrealmode_test();
78                 printf("Processor with segment limits @ 4GB,         result: %d (%s)\n",i,i?"yes":"no");
79
80                 flatrealmode_setup(FLATREALMODE_64KB); i = flatrealmode_test();
81                 printf("Processor with segment limits reset to 64KB, result: %d (%s)\n",i,i?"yes":"no");
82
83                 flatrealmode_setup(FLATREALMODE_4GB);  i = flatrealmode_test();
84                 printf("Processor with segment limits @ 4GB,         result: %d (%s)\n",i,i?"yes":"no");
85
86                 flatrealmode_setup(FLATREALMODE_64KB); i = flatrealmode_test();
87                 printf("Processor with segment limits reset to 64KB, result: %d (%s)\n",i,i?"yes":"no");
88         }
89         else {
90                 printf("Unable to set up Flat Real Mode\n");
91         }
92         return 0;
93 #else
94         printf("Flat real mode is specific to the 16-bit real-mode builds of this suite\n");
95         printf("and does not apply to 32-bit protected mode.\n");
96         return 1;
97 #endif
98 }
99