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 // pcsx-rearmed: we handle gpu elsewhere
293 //ret = GPU_open(&gpuDisp, "PCSX", NULL);
294 //if (ret < 0) { SysMessage(_("Error opening GPU plugin!")); return -1; }
295 ret = PAD1_open(&gpuDisp);
296 if (ret < 0) { SysMessage(_("Error opening Controller 1 plugin!")); return -1; }
297 ret = PAD2_open(&gpuDisp);
298 if (ret < 0) { SysMessage(_("Error opening Controller 2 plugin!")); return -1; }
300 if (Config.UseNet && !NetOpened) {
302 char path[MAXPATHLEN];
303 char dotdir[MAXPATHLEN];
305 strncpy(dotdir, getenv("HOME"), MAXPATHLEN-100);
306 strcat(dotdir, "/.pcsx/plugins/");
308 strcpy(info.EmuName, "PCSX " PACKAGE_VERSION);
309 strncpy(info.CdromID, CdromId, 9);
310 strncpy(info.CdromLabel, CdromLabel, 9);
312 info.GPU_showScreenPic = GPU_showScreenPic;
313 info.GPU_displayText = GPU_displayText;
314 info.GPU_showScreenPic = GPU_showScreenPic;
315 info.PAD_setSensitive = PAD1_setSensitive;
316 sprintf(path, "%s%s", Config.BiosDir, Config.Bios);
317 strcpy(info.BIOSpath, path);
318 strcpy(info.MCD1path, Config.Mcd1);
319 strcpy(info.MCD2path, Config.Mcd2);
320 sprintf(path, "%s%s", dotdir, Config.Gpu);
321 strcpy(info.GPUpath, path);
322 sprintf(path, "%s%s", dotdir, Config.Spu);
323 strcpy(info.SPUpath, path);
324 sprintf(path, "%s%s", dotdir, Config.Cdr);
325 strcpy(info.CDRpath, path);
328 ret = NET_open(&gpuDisp);
331 // -2 is returned when something in the info
332 // changed and needs to be synced
335 PARSEPATH(Config.Bios, info.BIOSpath);
336 PARSEPATH(Config.Gpu, info.GPUpath);
337 PARSEPATH(Config.Spu, info.SPUpath);
338 PARSEPATH(Config.Cdr, info.CDRpath);
340 strcpy(Config.Mcd1, info.MCD1path);
341 strcpy(Config.Mcd2, info.MCD2path);
344 Config.UseNet = FALSE;
347 if (NET_queryPlayer() == 1) {
348 if (SendPcsxInfo() == -1) Config.UseNet = FALSE;
350 if (RecvPcsxInfo() == -1) Config.UseNet = FALSE;
354 } else if (Config.UseNet) {
364 while ((ret = _OpenPlugins()) == -2) {
366 LoadMcds(Config.Mcd1, Config.Mcd2);
367 if (LoadPlugins() == -1) return -1;
372 void ClosePlugins() {
375 signal(SIGINT, SIG_DFL);
376 signal(SIGPIPE, SIG_DFL);
378 if (ret < 0) { SysMessage(_("Error closing CD-ROM plugin!")); return; }
380 if (ret < 0) { SysMessage(_("Error closing SPU plugin!")); return; }
382 if (ret < 0) { SysMessage(_("Error closing Controller 1 Plugin!")); return; }
384 if (ret < 0) { SysMessage(_("Error closing Controller 2 plugin!")); return; }
385 // pcsx-rearmed: we handle gpu elsewhere
387 //if (ret < 0) { SysMessage(_("Error closing GPU plugin!")); return; }