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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
#define Unknown win_Unknown
#include <windows.h>
#undef Unknown
#include "dat.h"
#include "fns.h"
#include "error.h"
#include "keyboard.h"
#include "cursor.h"
#include "ieplugin.h"
/*
* image channel descriptors - copied from draw.h as it clashes with windows.h on many things
*/
enum {
CRed = 0,
CGreen,
CBlue,
CGrey,
CAlpha,
CMap,
CIgnore,
NChan,
};
#define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
#define CHAN1(a,b) __DC(a,b)
#define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
#define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
#define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
#define NBITS(c) ((c)&15)
#define TYPE(c) (((c)>>4)&15)
enum {
GREY1 = CHAN1(CGrey, 1),
GREY2 = CHAN1(CGrey, 2),
GREY4 = CHAN1(CGrey, 4),
GREY8 = CHAN1(CGrey, 8),
CMAP8 = CHAN1(CMap, 8),
RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */
XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
};
extern ulong displaychan;
extern void drawend(void);
extern int chantodepth(ulong);
extern int main(int argc, char **argv);
static void dprint(char*, ...);
static DWORD WINAPI winproc(LPVOID);
static HINSTANCE inst;
static HINSTANCE previnst;
static int attached;
static ulong *data;
extern DWORD PlatformId;
char* gkscanid = "emu_win32vk";
extern int cflag;
Plugin *plugin = NULL;
DWORD WINAPI
pluginproc(LPVOID p)
{
int x, y, b;
for (;;) {
WaitForSingleObject(plugin->dopop, INFINITE);
switch (POP.op) {
case Pgfxkey:
if(gkbdq != nil)
gkbdputc(gkbdq, POP.u.key);
break;
case Pmouse:
x = POP.u.m.x;
y = POP.u.m.y;
b = POP.u.m.b;
mousetrack(b, x, y, 0);
break;
}
SetEvent(plugin->popdone);
}
}
int WINAPI
WinMain(HINSTANCE winst, HINSTANCE wprevinst, LPSTR cmdline, int wcmdshow)
{
HANDLE sharedmem;
uint pid = _getpid();
char iname[16];
inst = winst;
previnst = wprevinst;
sprint(iname, "%uX", pid);
sharedmem = OpenFileMapping(FILE_MAP_WRITE, FALSE, iname);
if (sharedmem != NULL)
plugin = MapViewOfFile(sharedmem, FILE_MAP_WRITE, 0, 0, 0);
if (plugin != NULL) {
DWORD tid;
int i;
Xsize = plugin->Xsize;
Ysize = plugin->Ysize;
displaychan = plugin->cdesc;
cflag = plugin->cflag;
for (i = 0; i < PI_NCLOSE; i++)
CloseHandle(plugin->closehandles[i]);
CreateThread(0, 0, pluginproc, 0, 0, &tid);
/* cmdline passed into WinMain does not contain name of executable.
* The globals __argc and __argv to include this info - like UNIX
*/
main(__argc, __argv);
UnmapViewOfFile(plugin);
plugin = NULL;
}
if (sharedmem != NULL)
CloseHandle(sharedmem);
return 0;
}
static Lock ioplock;
void
newiop()
{
lock(&ioplock);
}
int
sendiop()
{
int val;
SetEvent(plugin->doiop);
WaitForSingleObject(plugin->iopdone, INFINITE);
val = plugin->iop.val;
unlock(&ioplock);
return val;
}
void
dprint(char *fmt, ...)
{
va_list arg;
char buf[128];
va_start(arg, fmt);
vseprint(buf, buf+sizeof(buf), fmt, (LPSTR)arg);
va_end(arg);
OutputDebugString("inferno: ");
OutputDebugString(buf);
}
uchar*
attachscreen(IRectangle *r, ulong *chan, int *d, int *width, int *softscreen)
{
int k;
if (!attached) {
newiop();
IOP.op = Iattachscr;
if (sendiop() != 0)
return nil;
data = plugin->screen;
attached = 1;
}
r->min.x = 0;
r->min.y = 0;
r->max.x = Xsize;
r->max.y = Ysize;
if(displaychan == 0)
displaychan = CMAP8;
*chan = displaychan;
k = chantodepth(displaychan);
*d = k;
*width = (Xsize/4)*(k/8);
*softscreen = 1;
return (uchar*)data;
}
void
flushmemscreen(IRectangle r)
{
if(r.max.x<=r.min.x || r.max.y<=r.min.y)
return;
newiop();
IOP.op = Iflushscr;
IOP.u.r = r;
sendiop();
}
void
setpointer(int x, int y)
{
USED(x); USED(y);
// TODO
}
void
drawcursor(Drawcursor* c)
{
USED(c);
// TODO
}
char*
clipread(void)
{
return nil;
}
void
clipwrite(char *p)
{
USED(p);
{
|