-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.cpp
314 lines (210 loc) · 5.92 KB
/
main.cpp
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include "z64.h"
#include "Gfx #1.3.h"
extern const int screen_width = 1024, screen_height = 768;
LPDIRECTDRAW7 lpdd = 0;
LPDIRECTDRAWSURFACE7 lpddsprimary;
LPDIRECTDRAWSURFACE7 lpddsback;
DDSURFACEDESC2 ddsd;
HRESULT res;
RECT dst, src;
INT32 pitchindwords;
FILE* zeldainfo = 0;
int ProcessDListShown = 0;
extern int SaveLoaded;
extern UINT32 command_counter;
extern GFX_INFO gfx;
int rdp_init();
int rdp_close();
int rdp_update();
void rdp_process_list(void);
extern INLINE void popmessage(const char* err, ...);
extern INLINE void fatalerror(const char* err, ...);
EXPORT void CALL CaptureScreen ( char * Directory )
{
}
EXPORT void CALL ChangeWindow (void)
{
}
EXPORT void CALL CloseDLL (void)
{
}
EXPORT void CALL DllAbout ( HWND hParent )
{
popmessage("angrylion's RDP, unpublished beta. MESS source code used.");
}
EXPORT void CALL DllConfig ( HWND hParent )
{
popmessage("Nothing to configure");
}
EXPORT void CALL DllTest ( HWND hParent )
{
}
EXPORT void CALL ReadScreen(void **dest, long *width, long *height)
{
}
EXPORT void CALL DrawScreen (void)
{
}
EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo )
{
PluginInfo->Version = 0x0103;
PluginInfo->Type = PLUGIN_TYPE_GFX;
sprintf (PluginInfo->Name, "My little plugin");
PluginInfo->NormalMemory = TRUE;
PluginInfo->MemoryBswaped = TRUE;
}
GFX_INFO gfx;
EXPORT BOOL CALL InitiateGFX (GFX_INFO Gfx_Info)
{
gfx = Gfx_Info;
return TRUE;
}
EXPORT void CALL MoveScreen (int xpos, int ypos)
{
RECT statusrect;
POINT p;
p.x = p.y = 0;
GetClientRect(gfx.hWnd, &dst);
ClientToScreen(gfx.hWnd, &p);
OffsetRect(&dst, p.x, p.y);
GetClientRect(gfx.hStatusBar, &statusrect);
dst.bottom -= statusrect.bottom;
}
EXPORT void CALL ProcessDList(void)
{
if (!ProcessDListShown)
{
popmessage("ProcessDList");
ProcessDListShown = 1;
}
}
EXPORT void CALL ProcessRDPList(void)
{
rdp_process_list();
return;
}
EXPORT void CALL RomClosed (void)
{
rdp_close();
if (lpddsback)
{
IDirectDrawSurface_Release(lpddsback);
lpddsback = 0;
}
if (lpddsprimary)
{
IDirectDrawSurface_Release(lpddsprimary);
lpddsprimary = 0;
}
if (lpdd)
{
IDirectDraw_Release(lpdd);
lpdd = 0;
}
SaveLoaded = 1;
command_counter = 0;
}
EXPORT void CALL RomOpen (void)
{
RECT bigrect, smallrect, statusrect;
GetWindowRect(gfx.hWnd,&bigrect);
GetClientRect(gfx.hWnd,&smallrect);
int rightdiff = screen_width - smallrect.right;
int bottomdiff = screen_height - smallrect.bottom;
if (gfx.hStatusBar)
{
GetClientRect(gfx.hStatusBar, &statusrect);
bottomdiff += statusrect.bottom;
}
MoveWindow(gfx.hWnd, bigrect.left, bigrect.top, bigrect.right - bigrect.left + rightdiff, bigrect.bottom - bigrect.top + bottomdiff, TRUE);
DDPIXELFORMAT ftpixel;
LPDIRECTDRAWCLIPPER lpddcl;
res = DirectDrawCreateEx(0, (LPVOID*)&lpdd, IID_IDirectDraw7, 0);
if(res != DD_OK)
fatalerror("Couldn't create a DirectDraw object");
res = IDirectDraw_SetCooperativeLevel(lpdd, gfx.hWnd, DDSCL_NORMAL);
if(res != DD_OK)
fatalerror("Couldn't set a cooperative level. Error code %x", res);
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsprimary, 0);
if(res != DD_OK)
fatalerror("CreateSurface for a primary surface failed. Error code %x", res);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = PRESCALE_WIDTH;
ddsd.dwHeight = PRESCALE_HEIGHT;
memset(&ftpixel, 0, sizeof(ftpixel));
ftpixel.dwSize = sizeof(ftpixel);
ftpixel.dwFlags = DDPF_RGB;
ftpixel.dwRGBBitCount = 32;
ftpixel.dwRBitMask = 0xff0000;
ftpixel.dwGBitMask = 0xff00;
ftpixel.dwBBitMask = 0xff;
ddsd.ddpfPixelFormat = ftpixel;
res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsback, 0);
if (res == DDERR_INVALIDPIXELFORMAT)
fatalerror("ARGB8888 is not supported. You can try changing desktop color depth to 32-bit, but most likely that won't help.");
else if(res != DD_OK)
fatalerror("CreateSurface for a secondary surface failed. Error code %x", res);
res = IDirectDrawSurface_GetSurfaceDesc(lpddsback, &ddsd);
if (res != DD_OK)
fatalerror("GetSurfaceDesc failed.");
if ((ddsd.lPitch & 3) || ddsd.lPitch < (PRESCALE_WIDTH << 2))
fatalerror("Pitch of a secondary surface is either not 32 bit aligned or two small.");
pitchindwords = ddsd.lPitch >> 2;
res = IDirectDraw_CreateClipper(lpdd, 0, &lpddcl, 0);
if (res != DD_OK)
fatalerror("Couldn't create a clipper.");
res = IDirectDrawClipper_SetHWnd(lpddcl, 0, gfx.hWnd);
if (res != DD_OK)
fatalerror("Couldn't register a windows handle as a clipper.");
res = IDirectDrawSurface_SetClipper(lpddsprimary, lpddcl);
if (res != DD_OK)
fatalerror("Couldn't attach a clipper to a surface.");
src.top = src.left = 0;
src.bottom = 0;
src.right = PRESCALE_WIDTH;
POINT p;
p.x = p.y = 0;
GetClientRect(gfx.hWnd, &dst);
ClientToScreen(gfx.hWnd, &p);
OffsetRect(&dst, p.x, p.y);
GetClientRect(gfx.hStatusBar, &statusrect);
dst.bottom -= statusrect.bottom;
DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(DDBLTFX);
ddbltfx.dwFillColor = 0;
res = IDirectDrawSurface_Blt(lpddsprimary, &dst, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
src.bottom = PRESCALE_HEIGHT;
res = IDirectDrawSurface_Blt(lpddsback, &src, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
rdp_init();
}
EXPORT void CALL ShowCFB (void)
{
rdp_update();
}
EXPORT void CALL UpdateScreen (void)
{
rdp_update();
}
EXPORT void CALL ViStatusChanged (void)
{
}
EXPORT void CALL ViWidthChanged (void)
{
}
EXPORT void CALL FBWrite(DWORD, DWORD)
{
}
EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, DWORD size)
{
}
EXPORT void CALL FBRead(DWORD addr)
{
}
EXPORT void CALL FBGetFrameBufferInfo(void *pinfo)
{
}