1 /* Pcsx - Pc Psx Emulator
2 * Copyright (C) 1999-2002 Pcsx Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
23 #include <X11/keysym.h>
28 #include "../libpcsxcore/plugins.h"
29 #include "../libpcsxcore/spu.h"
30 #include "../libpcsxcore/cdriso.h"
34 #define MAX_SLOTS 5 /* ADB TODO Same as Gtk2Gui.c */
38 unsigned long gpuDisp;
45 gchar *state_filename;
51 pMem = (unsigned char *) malloc(128*96*3);
52 if (pMem == NULL) return;
54 state_filename = get_state_filename (StatesC);
56 GPU_freeze(2, (GPUFreeze_t *)&StatesC);
58 f = gzopen(state_filename, "rb");
60 gzseek(f, 32, SEEK_SET); // skip header
61 gzread(f, pMem, 128*96*3);
64 memcpy(pMem, NoPic_Image.pixel_data, 128*96*3);
65 DrawNumBorPic(pMem, StatesC+1);
67 GPU_showScreenPic(pMem);
71 g_free (state_filename);
73 GPU_showScreenPic(NULL);
78 void KeyStateSave(int i) {
79 gchar *state_filename;
81 state_filename = get_state_filename (i);
82 state_save (state_filename);
84 g_free (state_filename);
87 void KeyStateLoad(int i) {
88 gchar *state_filename;
90 state_filename = get_state_filename (i);
91 state_load (state_filename);
93 g_free (state_filename);
95 // HACKHACK: prevent crash when using recompiler due to execution not
96 // returned from compiled code. This WILL cause memory leak, however a
97 // large amount of refactor is needed for a proper fix.
98 if (Config.Cpu == CPU_DYNAREC) psxCpu->Execute();
101 static short modctrl = 0, modalt = 0;
103 /* Handle keyboard keystrokes */
104 void PADhandleKey(int key) {
105 char Text[MAXPATHLEN];
106 gchar *state_filename;
108 short rel = 0; //released key flag
113 if ((key >> 30) & 1) //specific to dfinput (padJoy)
117 switch (key & ~0x40000000) {
141 if (modalt && modctrl)
143 if (modalt) KeyStateLoad(10);
147 if (modalt && modctrl)
149 if (modalt) KeyStateLoad(0);
150 if (modctrl) KeyStateSave(0);
153 if (modalt && modctrl)
155 if (modalt) KeyStateLoad(1);
156 if (modctrl) KeyStateSave(1);
159 if (modalt && modctrl)
161 if (modalt) KeyStateLoad(2);
162 if (modctrl) KeyStateSave(2);
165 if (modalt && modctrl)
167 if (modalt) KeyStateLoad(3);
168 if (modctrl) KeyStateSave(3);
171 if (modalt && modctrl)
173 if (modalt) KeyStateLoad(4);
174 if (modctrl) KeyStateSave(4);
178 GPU_freeze(2, (GPUFreeze_t *)&StatesC);
179 state_filename = get_state_filename (StatesC);
180 state_save (state_filename);
182 g_free (state_filename);
184 if (ShowPic) { ShowPic = 0; gpuShowPic(); }
188 if (StatesC < (MAX_SLOTS - 1)) StatesC++;
190 GPU_freeze(2, (GPUFreeze_t *)&StatesC);
191 if (ShowPic) { ShowPic = 0; gpuShowPic(); }
194 state_filename = get_state_filename (StatesC);
195 state_load (state_filename);
197 g_free (state_filename);
199 // HACKHACK: prevent crash when using recompiler due to execution not
200 // returned from compiled code. This WILL cause memory leak, however a
201 // large amount of refactor is needed for a proper fix.
202 if (Config.Cpu == CPU_DYNAREC) psxCpu->Execute();
211 sprintf(Text, _("SIO IRQ Always Enabled"));
212 else sprintf(Text, _("SIO IRQ Not Always Enabled"));
213 GPU_displayText(Text);
218 sprintf(Text, _("Black & White Mdecs Only Enabled"));
219 else sprintf(Text, _("Black & White Mdecs Only Disabled"));
220 GPU_displayText(Text);
225 sprintf (Text, _("XA Enabled"));
226 else sprintf (Text, _("XA Disabled"));
227 GPU_displayText(Text);
233 SetCdOpenCaseTime(-1);
236 SetCdOpenCaseTime(0);
240 // the architecture is too broken to actually restart the GUI
241 // because SysUpdate is called from deep within the actual
242 // execution of the emulation code
243 // Fixing this would probably require a complete reworking of
244 // all functions, so that they return 0 or 1 for success
245 // that way, execution wouldn't continue
246 if (CdromId[0] != '\0')
250 if (!UseGui) OnFile_Exit();
253 case XK_Return: //0xff0d
254 if (modalt) //alt-return
255 //I just made this up: a special sym for fullscreen because the current interface can't handle key mods
256 //though it can be used in the future as a convention...eg bit 29 for alt, bit 28 for cntl, etc.
257 GPU_keypressed( (1<<29) | 0xFF0D );
261 if (Config.UseNet) NET_keypressed(key);
267 void SignalExit(int sig) {
272 #define PARSEPATH(dst, src) \
273 ptr = src + strlen(src); \
274 while (*ptr != '\\' && ptr != src) ptr--; \
276 strcpy(dst, ptr+1); \
282 signal(SIGINT, SignalExit);
283 signal(SIGPIPE, SignalExit);
285 GPU_clearDynarec(clearDynarec);
288 if (ret < 0) { SysMessage(_("Error opening CD-ROM plugin!")); return -1; }
290 if (ret < 0) { SysMessage(_("Error opening SPU plugin!")); return -1; }
291 SPU_registerCallback(SPUirq);
292 ret = GPU_open(&gpuDisp, "PCSX", NULL);
293 if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
294 ret = PAD1_open(&gpuDisp);
295 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
296 ret = PAD2_open(&gpuDisp);
297 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
299 if (Config.UseNet && !NetOpened) {
301 char path[MAXPATHLEN];
302 char dotdir[MAXPATHLEN];
304 strncpy(dotdir, getenv("HOME"), MAXPATHLEN-100);
305 strcat(dotdir, "/.pcsx/plugins/");
307 strcpy(info.EmuName, "PCSX " PACKAGE_VERSION);
308 strncpy(info.CdromID, CdromId, 9);
309 strncpy(info.CdromLabel, CdromLabel, 9);
311 info.GPU_showScreenPic = GPU_showScreenPic;
312 info.GPU_displayText = GPU_displayText;
313 info.GPU_showScreenPic = GPU_showScreenPic;
314 info.PAD_setSensitive = PAD1_setSensitive;
315 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
316 strcpy(info.BIOSpath, path);
317 strcpy(info.MCD1path, Config.Mcd1);
318 strcpy(info.MCD2path, Config.Mcd2);
319 sprintf(path, "%s%s", dotdir, Config.Gpu);
320 strcpy(info.GPUpath, path);
321 sprintf(path, "%s%s", dotdir, Config.Spu);
322 strcpy(info.SPUpath, path);
323 sprintf(path, "%s%s", dotdir, Config.Cdr);
324 strcpy(info.CDRpath, path);
327 ret = NET_open(&gpuDisp);
330 // -2 is returned when something in the info
331 // changed and needs to be synced
334 PARSEPATH(Config.Bios, info.BIOSpath);
335 PARSEPATH(Config.Gpu, info.GPUpath);
336 PARSEPATH(Config.Spu, info.SPUpath);
337 PARSEPATH(Config.Cdr, info.CDRpath);
339 strcpy(Config.Mcd1, info.MCD1path);
340 strcpy(Config.Mcd2, info.MCD2path);
343 Config.UseNet = FALSE;
346 if (NET_queryPlayer() == 1) {
347 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
349 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
353 } else if (Config.UseNet) {
363 while ((ret = _OpenPlugins()) == -2) {
365 LoadMcds(Config.Mcd1, Config.Mcd2);
366 if (LoadPlugins() == -1) return -1;
371 void ClosePlugins() {
374 signal(SIGINT, SIG_DFL);
375 signal(SIGPIPE, SIG_DFL);
377 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
379 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
381 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
383 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
385 if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }