-
Notifications
You must be signed in to change notification settings - Fork 0
/
thdmp.c
166 lines (131 loc) · 3.71 KB
/
thdmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*******************************************************************
* Torture Half-Duplex on Microsoft Platforms
*
* This program is designed to drive the 150 known combinations of
* input method, output method, and execution subsystem supported
* on DOS/Windows. It is intendend to cause problems for anyone
* attempting a IO::Pty::HalfDuplex port.
*
* Subsystem is a compiler option, and must also be communicated:
* -DREALMODE Raw DOS, 8088 style
* -DDPMI_16 16-bit DOS extenders running in a DOS box
* -DDPMI_32 ditto
* -DWIN16 Windows 3.x compatibility mode
* -DWIN32
* -DWIN64
*
* Input and output modes are specified on the command line, and
* can be:
*
* hardware: direct port banging
* bios: ROM interrupt calls
* dos: DOS calls
* unistd: POSIX calls (read/write)
* stdio: C calls (getchar/putchar)
* winfile: NT KERNEL32, WriteFile/ReadFile
* consolea: NT console, WriteConsoleA/ReadConsoleA
* consolew: NT console, WriteConsoleW/ReadConsoleW
*/
#include <stdio.h>
#if (defined(REALMODE) || defined(DPMI_16) || defined(DPMI_32)) \
&& defined(__WATCOMC__)
/* have I mentioned recently how awful the AT keyboard controller
interface is? */
static int hw_setup_in(void) {
}
static void hw_teardown_in(void) {
}
static int hw_getc(void) {
}
static int curx, cury;
static int hw_setup_out(void) {
/* fetch cursor position from VGA registers */
}
static void hw_teardown_out(void) {
}
static char[80][2] far *framebuffer;
static void hw_putc(int ch) {
}
/**/
#else
#define hw_setup_in 0
#define hw_setup_out 0
#define hw_teardown_in 0
#define hw_teardown_out 0
#define hw_getc 0
#define hw_putc 0
#define bios_getc 0
#define bios_putc 0
#define dos_getc 0
#define dos_putc 0
#endif
static void stdio_putc(int ch) {
putchar(ch);
fflush(stdout);
}
static int stdio_getc() {
return getchar();
}
static void unistd_putc(int ch) {
char ch2 = ch;
write(1, &ch2, 1);
}
static int unistd_getc() {
char buf;
read(0, &buf, 1);
return buf;
}
#if defined(WIN16) || defined(WIN32) || defined(WIN64)
#endif
struct method {
const char *name;
int (*setup_in)(void);
void (*teardown_in)(void);
int (*setup_out)(void);
void (*teardown_out)(void);
int (*getc)(void);
void (*putc)(int);
} methods[] = {
{ "hardware", hw_setup_in, hw_teardown_in, hw_setup_out,
hw_teardown_out, hw_getc, hw_putc },
{ "bios", 0, 0, 0, 0, bios_getc, bios_putc },
{ "dos", 0, 0, 0, 0, dos_getc, dos_putc },
{ "unistd", 0, 0, 0, 0, unistd_getc, unistd_putc },
{ "stdio", 0, 0, 0, 0, stdio_getc, stdio_putc },
{ "winfile", 0, 0, 0, 0, winfile_getc, winfile_putc },
{ "ntcona", 0, 0, 0, 0, ntcona_getc, ntcona_putc },
{ "ntconw", 0, 0, 0, 0, ntconw_getc, ntconw_putc },
{ 0, 0, 0, 0, 0, 0, 0 }
};
struct method *lookmethod(char *name) {
struct method *p;
for (p = methods; p->name; p++) {
if (stricmp(name, p->name))
continue;
if (! p->getc) {
printf("'%s' doesn't work on this platform.\n", p->name);
exit(1);
}
return p;
}
printf("'%s' is unrecognized.\n", name);
exit(1);
}
void foomain(char *in, char *out) {
struct method *min = lookmethod(in);
struct method *mout = lookmethod(out);
if (min->setup_in && !(min->setup_in)()) {
printf("'%s' (input) doesn't seem to be supported here.\n",
min->name);
exit(1);
}
if (mout->setup_out && !(mout->setup_out)()) {
min->teardown_in();
printf("'%s' (output) doesn't seem to be supported here.\n",
mout->name);
exit(1);
}
/* do something here */
(min->teardown_in)();
(min->teardown_out)();
}