aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/platform/ps2/Makefile.ps275
-rw-r--r--backends/platform/ps2/ps2debug.cpp25
-rw-r--r--backends/platform/ps2/ps2debug.h34
-rw-r--r--backends/platform/ps2/rawsavefile.cpp157
-rw-r--r--backends/platform/ps2/rawsavefile.h71
-rw-r--r--backends/platform/ps2/rpckbd.c178
-rw-r--r--backends/platform/ps2/rpckbd.h28
-rw-r--r--backends/platform/ps2/savefilemgr.cpp572
-rw-r--r--backends/platform/ps2/savefilemgr.h107
-rw-r--r--backends/platform/ps2/sdlkeys.h264
10 files changed, 1511 insertions, 0 deletions
diff --git a/backends/platform/ps2/Makefile.ps2 b/backends/platform/ps2/Makefile.ps2
new file mode 100644
index 0000000000..22cd4eaa1b
--- /dev/null
+++ b/backends/platform/ps2/Makefile.ps2
@@ -0,0 +1,75 @@
+# $Header: Exp $
+include $(PS2SDK)/Defs.make
+
+DISABLE_SCALERS = true
+DISABLE_HQ_SCALERS = true
+# DISABLE_KYRA = true
+HAVE_GCC3 = true
+
+CC = ee-gcc
+CXX = ee-g++
+AS = ee-gcc
+LD = ee-gcc
+AR = ee-ar cru
+RANLIB = ee-ranlib
+STRIP = ee-strip
+MKDIR = mkdir -p
+RM = rm -f
+
+srcdir = ../../..
+VPATH = $(srcdir)
+INCDIR = ../../../
+
+DEFINES = -DUSE_VORBIS -DUSE_TREMOR -DUSE_MAD -DUSE_MPEG2 -DUSE_ZLIB -D_EE -D__PLAYSTATION2__ -O2 -Wall -Wno-multichar
+
+# PS2SDK-Ports from ps2dev.org's SVN repository for libmad, zlib and ucl
+PS2SDK_PORTS = /home/robby/libStuffNew/ps2sdk-ports
+PS2SDK_PORTS_INCS = /ucl /zlib/include /libmad/ee/include
+PS2SDK_PORTS_LIBS = /ucl /zlib/lib /libmad/ee/lib
+
+# we also need SjPcm, Tremor and libmpeg2
+MORE_LIBS_DIR = /home/robby/libStuff
+MORE_LIBS_INCS = /SjPcm/ee/src /mpeg2dec/include /tremor
+MORE_LIBS_LIBS = /SjPcm/ee/lib /mpeg2dec/libmpeg2 /tremor/tremor
+
+INCLUDES = $(addprefix -I$(PS2SDK_PORTS),$(PS2SDK_PORTS_INCS))
+INCLUDES += $(addprefix -I$(MORE_LIBS_DIR),$(MORE_LIBS_INCS))
+INCLUDES += -I $(PS2SDK)/ee/include -I $(PS2SDK)/common/include -I ./common -I . -I $(srcdir) -I $(srcdir)/engines
+
+TARGET = elf/scummvm.elf
+
+OBJS := backends/platform/ps2/DmaPipe.o \
+ backends/platform/ps2/Gs2dScreen.o \
+ backends/platform/ps2/irxboot.o \
+ backends/platform/ps2/ps2input.o \
+ backends/platform/ps2/ps2pad.o \
+ backends/platform/ps2/rawsavefile.o \
+ backends/platform/ps2/savefile.o \
+ backends/platform/ps2/savefilemgr.o \
+ backends/platform/ps2/fileio.o \
+ backends/platform/ps2/icon.o \
+ backends/platform/ps2/asyncfio.o \
+ backends/platform/ps2/cd.o \
+ backends/platform/ps2/eecodyvdfs.o \
+ backends/platform/ps2/rpckbd.o \
+ backends/platform/ps2/systemps2.o \
+ backends/platform/ps2/ps2mutex.o \
+ backends/platform/ps2/ps2time.o \
+ backends/platform/ps2/ps2debug.o
+
+MODULE_DIRS += .
+
+include $(srcdir)/Makefile.common
+
+LDFLAGS += -mno-crt0 $(PS2SDK)/ee/startup/crt0.o -T $(PS2SDK)/ee/startup/linkfile
+LDFLAGS += -L $(PS2SDK)/ee/lib -L .
+LDFLAGS += $(addprefix -L$(MORE_LIBS_DIR),$(MORE_LIBS_LIBS))
+LDFLAGS += $(addprefix -L$(PS2SDK_PORTS),$(PS2SDK_PORTS_LIBS))
+LDFLAGS += -lmc -lpad -lmouse -lhdd -lpoweroff -lsjpcm -lmpeg2 -lmad -ltremor -lz -lucl -lm -lc -lfileXio -lkernel -lstdc++
+# LDFLAGS += -s
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+ $(LD) $^ $(LDFLAGS) -o $@
+
diff --git a/backends/platform/ps2/ps2debug.cpp b/backends/platform/ps2/ps2debug.cpp
new file mode 100644
index 0000000000..272d256232
--- /dev/null
+++ b/backends/platform/ps2/ps2debug.cpp
@@ -0,0 +1,25 @@
+#include "ps2debug.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <sio.h>
+
+void sioprintf(const char *zFormat, ...) {
+ va_list ap;
+ char resStr[2048];
+
+ va_start(ap,zFormat);
+ vsnprintf(resStr, 2048, zFormat, ap);
+ va_end(ap);
+
+ char *pos = resStr;
+ while (*pos) {
+ if (*pos == '\n') {
+ // SIO terminal needs explicit CRLF
+ sio_putc('\r');
+ sio_putc('\n');
+ } else
+ sio_putc(*pos);
+ pos++;
+ }
+}
+
diff --git a/backends/platform/ps2/ps2debug.h b/backends/platform/ps2/ps2debug.h
new file mode 100644
index 0000000000..2b128ec9df
--- /dev/null
+++ b/backends/platform/ps2/ps2debug.h
@@ -0,0 +1,34 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __PS2DEBUG_H__
+#define __PS2DEBUG_H__
+
+#define dbg_printf sioprintf
+
+void sioprintf(const char *zFormat, ...);
+
+#endif // __PS2DEBUG_H__
+
diff --git a/backends/platform/ps2/rawsavefile.cpp b/backends/platform/ps2/rawsavefile.cpp
new file mode 100644
index 0000000000..03270ea9ce
--- /dev/null
+++ b/backends/platform/ps2/rawsavefile.cpp
@@ -0,0 +1,157 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "backends/platform/ps2/rawsavefile.h"
+#include "backends/platform/ps2/savefilemgr.h"
+
+RawReadFile::RawReadFile(McAccess *mcAccess) {
+ _mcAccess = mcAccess;
+ _size = -1;
+ _pos = 0;
+ _buf = NULL;
+}
+
+RawReadFile::~RawReadFile(void) {
+ if (_buf)
+ free(_buf);
+}
+
+bool RawReadFile::bufOpen(const char *path) {
+ int handle = _mcAccess->open(path, O_RDONLY);
+ printf("RawReadFile Open: \"%s\" => %d\n", path, handle);
+ if (handle >= 0) {
+ _size = _mcAccess->size(handle);
+ _buf = (uint8 *)memalign(64, _size);
+ int res = _mcAccess->read(handle, _buf, _size);
+ if (res != _size) {
+ free(_buf);
+ _size = -1;
+ _buf = NULL;
+ }
+ _mcAccess->close(handle);
+ } else {
+ _size = -1;
+ _buf = NULL;
+ }
+ _pos = 0;
+ return (_buf != NULL);
+}
+
+int RawReadFile::bufTell(void) const {
+ return _pos;
+}
+
+int RawReadFile::bufSeek(int ofs, int whence) {
+ switch (whence) {
+ case SEEK_SET:
+ _pos = ofs;
+ break;
+ case SEEK_CUR:
+ _pos += ofs;
+ break;
+ case SEEK_END:
+ _pos = _size + ofs;
+ break;
+ }
+ if (_pos < 0)
+ _pos = 0;
+ else if (_pos > _size)
+ _pos = _size;
+ return _pos;
+}
+
+int RawReadFile::bufRead(void *dest, int size) {
+ if (_pos + size > _size)
+ size = _size - _pos;
+ memcpy(dest, _buf + _pos, size);
+ _pos += size;
+ return size;
+}
+
+int RawReadFile::bufSize(void) const {
+ return _size;
+}
+
+
+
+RawWriteFile::RawWriteFile(McAccess *mcAccess) {
+ _mcAccess = mcAccess;
+ _size = 64 * 1024;
+
+ _buf = (uint8 *)memalign(64, _size);
+ _pos = 0;
+ _handle = -1;
+}
+
+RawWriteFile::~RawWriteFile() {
+ if (_pos != 0) {
+ printf("RawWriteFile d'tor: file wasn't flushed!\n");
+ bufFlush();
+ }
+ free(_buf);
+ if (_handle >= 0)
+ _mcAccess->close(_handle);
+}
+
+bool RawWriteFile::bufOpen(const char *path) {
+ _handle = _mcAccess->open(path, O_WRONLY | O_CREAT);
+ strcpy(_filename, path);
+ return (_handle >= 0);
+}
+
+void RawWriteFile::bufWrite(const void *buf, int len) {
+ while (_pos + len > _size) {
+ _size = _size * 2;
+ _buf = (uint8 *)realloc(_buf, _size);
+ }
+ memcpy(_buf + _pos, buf, len);
+ _pos += len;
+}
+
+bool RawWriteFile::bufFlush(void) {
+ int result = _mcAccess->write(_handle, _buf, _pos);
+ if (_pos != result) {
+ if (result > 0) {
+ memmove(_buf, _buf + result, _pos - result);
+ _pos -= result;
+ }
+ return false;
+ }
+ _pos = 0;
+ return true;
+}
+
+int RawWriteFile::bufTell(void) const {
+ return _pos;
+}
+
+void RawWriteFile::removeFile(void) {
+ if (_handle >= 0)
+ _mcAccess->close(_handle);
+ _handle = -1;
+ _pos = 0;
+
+ _mcAccess->remove(_filename);
+}
diff --git a/backends/platform/ps2/rawsavefile.h b/backends/platform/ps2/rawsavefile.h
new file mode 100644
index 0000000000..b638d106ab
--- /dev/null
+++ b/backends/platform/ps2/rawsavefile.h
@@ -0,0 +1,71 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __RAWSAVEFILE_H__
+#define __RAWSAVEFILE_H__
+
+#include "common/scummsys.h"
+
+class McAccess;
+
+class RawReadFile {
+public:
+ RawReadFile(McAccess *mcAccess);
+ virtual ~RawReadFile();
+
+ bool bufOpen(const char *path);
+ int bufRead(void *dest, int size);
+ int bufTell(void) const;
+ int bufSeek(int ofs, int whence);
+ int bufSize(void) const;
+protected:
+ McAccess *_mcAccess;
+ int _size;
+ uint8 *_buf;
+ int _pos;
+};
+
+class RawWriteFile {
+public:
+ RawWriteFile(McAccess *mcAccess);
+ virtual ~RawWriteFile();
+
+ bool bufOpen(const char *path);
+ void bufWrite(const void *buf, int len);
+ int bufTell(void) const;
+
+ bool bufFlush(void);
+ void removeFile();
+protected:
+ char _filename[128];
+
+ McAccess *_mcAccess;
+ uint8 *_buf;
+ int _size, _pos;
+ int _handle;
+};
+
+#endif // __RAWSAVEFILE_H__
+
diff --git a/backends/platform/ps2/rpckbd.c b/backends/platform/ps2/rpckbd.c
new file mode 100644
index 0000000000..8291df681a
--- /dev/null
+++ b/backends/platform/ps2/rpckbd.c
@@ -0,0 +1,178 @@
+/*
+# _____ ___ ____ ___ ____
+# ____| | ____| | | |____|
+# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
+#-----------------------------------------------------------------------
+# Copyright 2005, ps2dev - http://www.ps2dev.org
+# Licenced under Academic Free License version 2.0
+# Review ps2sdk README & LICENSE files for further details.
+#
+# $Id$
+# USB Keyboard Driver for PS2 using RPC instead of FIO
+*/
+
+#include <tamtypes.h>
+#include <kernel.h>
+#include <sifrpc.h>
+#include <string.h>
+#include "backends/platform/ps2/rpckbd.h"
+
+static int curr_readmode = PS2KBD_READMODE_NORMAL;
+static int kbdRpcSema = -1;
+static int kbdInitialized = 0;
+
+static SifRpcClientData_t cd0;
+static unsigned char rpcBuf[3 * PS2KBD_KEYMAP_SIZE] __attribute__((aligned (16)));
+static unsigned int rpcKey __attribute__((aligned (16)));
+
+int PS2KbdInit(void)
+/* Initialise the keyboard library */
+{
+ int res;
+ ee_sema_t kbdSema;
+
+ while ((res = SifBindRpc(&cd0, PS2KBD_RPC_ID, 0)) < 0)
+ nopdelay();
+
+ memset(rpcBuf, 0, 3 * PS2KBD_KEYMAP_SIZE);
+ rpcKey = 0;
+
+ kbdSema.init_count = 1;
+ kbdSema.max_count = 1;
+
+ kbdRpcSema = CreateSema(&kbdSema);
+ if (kbdRpcSema >= 0) {
+ kbdInitialized = 1;
+ return 0;
+ } else
+ return -1;
+}
+
+static void rpcCompleteIntr(void *param) {
+ iSignalSema(kbdRpcSema);
+}
+
+int PS2KbdRead(char *key)
+/* Reads 1 character from the keyboard */
+{
+ int res;
+ if ((!kbdInitialized) || (curr_readmode != PS2KBD_READMODE_NORMAL))
+ return -1;
+
+ if (PollSema(kbdRpcSema) >= 0) {
+ // last rpc call completed
+ res = (rpcKey != 0);
+ *key = *(char *)UNCACHED_SEG(&rpcKey);
+ SifCallRpc(&cd0, KBD_RPC_READKEY, SIF_RPC_M_NOWAIT, rpcBuf, 0, &rpcKey, 4, rpcCompleteIntr, NULL);
+ return res;
+ } else // rpc still running
+ return 0;
+}
+
+int PS2KbdReadRaw(PS2KbdRawKey *key)
+/* Reads 1 raw character from the keyboard */
+{
+ int res;
+ if ((!kbdInitialized) || (curr_readmode != PS2KBD_READMODE_RAW))
+ return -1;
+
+ if (PollSema(kbdRpcSema) >= 0) {
+ // last rpc call completed
+ res = (rpcKey != 0);
+ *key = *(PS2KbdRawKey *)UNCACHED_SEG(&rpcKey);
+ SifCallRpc(&cd0, KBD_RPC_READRAW, SIF_RPC_M_NOWAIT, rpcBuf, 0, &rpcKey, 4, rpcCompleteIntr, NULL);
+ return res;
+ } else // rpc still running
+ return 0;
+}
+
+int PS2KbdSetReadmode(u32 readmode)
+/* Sets the read mode to normal or raw */
+{
+ if (kbdInitialized) {
+ if (curr_readmode == readmode)
+ return 0;
+ WaitSema(kbdRpcSema);
+ *(unsigned int *)rpcBuf = curr_readmode = readmode;
+ return SifCallRpc(&cd0, KBD_RPC_SETREADMODE, SIF_RPC_M_NOWAIT, rpcBuf, 4, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdSetLeds(u8 leds)
+/* Sets all connected keyboards leds */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ *(unsigned char *)rpcBuf = leds;
+ return SifCallRpc(&cd0, KBD_RPC_SETLEDS, SIF_RPC_M_NOWAIT, rpcBuf, 4, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdSetKeymap(PS2KbdKeyMap *keymaps)
+/* Sets the current keymap */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ memcpy(rpcBuf + 0 * PS2KBD_KEYMAP_SIZE, keymaps->keymap, PS2KBD_KEYMAP_SIZE);
+ memcpy(rpcBuf + 1 * PS2KBD_KEYMAP_SIZE, keymaps->shiftkeymap, PS2KBD_KEYMAP_SIZE);
+ memcpy(rpcBuf + 2 * PS2KBD_KEYMAP_SIZE, keymaps->keycap, PS2KBD_KEYMAP_SIZE);
+ return SifCallRpc(&cd0, KBD_RPC_SETKEYMAP, SIF_RPC_M_NOWAIT, rpcBuf, 3 * PS2KBD_KEYMAP_SIZE, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdSetCtrlmap(u8 *ctrlmap)
+/* Sets the control key mappings */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ memcpy(rpcBuf, ctrlmap, PS2KBD_KEYMAP_SIZE);
+ return SifCallRpc(&cd0, KBD_RPC_SETCTRLMAP, SIF_RPC_M_NOWAIT, rpcBuf, PS2KBD_KEYMAP_SIZE, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdSetAltmap(u8 *altmap)
+/* Sets the alt key mappings */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ memcpy(rpcBuf, altmap, PS2KBD_KEYMAP_SIZE);
+ return SifCallRpc(&cd0, KBD_RPC_SETALTMAP, SIF_RPC_M_NOWAIT, rpcBuf, PS2KBD_KEYMAP_SIZE, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdSetSpecialmap(u8 *special)
+/* Sets the special key mappings */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ memcpy(rpcBuf, special, PS2KBD_KEYMAP_SIZE);
+ return SifCallRpc(&cd0, KBD_RPC_SETSPECIALMAP, SIF_RPC_M_NOWAIT, rpcBuf, PS2KBD_KEYMAP_SIZE, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdFlushBuffer(void)
+/* Flushes the keyboard buffer */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ return SifCallRpc(&cd0, KBD_RPC_FLUSHBUFFER, SIF_RPC_M_NOWAIT, rpcBuf, 0, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
+int PS2KbdResetKeymap(void)
+/* Resets the keymap to the default US mapping */
+{
+ if (kbdInitialized) {
+ WaitSema(kbdRpcSema);
+ return SifCallRpc(&cd0, KBD_RPC_RESETKEYMAP, SIF_RPC_M_NOWAIT, rpcBuf, 0, rpcBuf, 0, rpcCompleteIntr, NULL);
+ } else
+ return -1;
+}
+
diff --git a/backends/platform/ps2/rpckbd.h b/backends/platform/ps2/rpckbd.h
new file mode 100644
index 0000000000..329d95b294
--- /dev/null
+++ b/backends/platform/ps2/rpckbd.h
@@ -0,0 +1,28 @@
+#ifndef __RPCKBD_H__
+#define __RPCKBD_H__
+
+#include "backends/platform/ps2/iop/rpckbd/include/ps2kbd.h"
+
+typedef kbd_rawkey PS2KbdRawKey;
+typedef kbd_keymap PS2KbdKeyMap;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ int PS2KbdInit(void);
+ int PS2KbdRead(char *key);
+ int PS2KbdReadRaw(PS2KbdRawKey *key);
+ int PS2KbdSetReadmode(u32 readmode);
+ int PS2KbdSetLeds(u8 leds);
+ int PS2KbdSetKeymap(PS2KbdKeyMap *keymaps);
+ int PS2KbdSetCtrlmap(u8 *ctrlmap);
+ int PS2KbdSetAltmap(u8 *altmap);
+ int PS2KbdSetSpecialmap(u8 *special);
+ int PS2KbdFlushBuffer(void);
+ int PS2KbdResetKeymap(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/backends/platform/ps2/savefilemgr.cpp b/backends/platform/ps2/savefilemgr.cpp
new file mode 100644
index 0000000000..8fbd98e78a
--- /dev/null
+++ b/backends/platform/ps2/savefilemgr.cpp
@@ -0,0 +1,572 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include <tamtypes.h>
+#include <kernel.h>
+#include <sifrpc.h>
+#include <loadfile.h>
+#include <fileio.h>
+#include <malloc.h>
+#include <ucl/ucl.h>
+#include <libmc.h>
+#include "backends/platform/ps2/savefile.h"
+#include "backends/platform/ps2/Gs2dScreen.h"
+#include "backends/platform/ps2/systemps2.h"
+#include "backends/fs/abstract-fs.h"
+#include "backends/platform/ps2/ps2debug.h"
+
+#include "common/scummsys.h"
+
+#include "backends/platform/ps2/savefilemgr.h"
+#include "backends/platform/ps2/savefile.h"
+
+extern void *_gp;
+
+#define PORT 0
+#define SLOT 0
+// port 0, slot 0: memory card in first slot.
+
+McAccess::McAccess(int port, int slot) {
+ _port = port;
+ _slot = slot;
+ ee_sema_t newSema;
+ newSema.init_count = 1;
+ newSema.max_count = 1;
+ _sema = CreateSema(&newSema);
+
+ assert(mcInit(MC_TYPE_MC) >= 0);
+}
+
+McAccess::~McAccess(void) {
+ DeleteSema(_sema);
+}
+
+int McAccess::open(const char *name, int mode) {
+ int res;
+ WaitSema(_sema);
+ mcOpen(_port, _slot, name, mode);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::close(int fd) {
+ int res;
+ WaitSema(_sema);
+ mcClose(fd);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::size(int fd) {
+ int res, size;
+ WaitSema(_sema);
+ mcSeek(fd, 0, SEEK_END);
+ mcSync(0, NULL, &size);
+ mcSeek(fd, 0, SEEK_SET);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ assert(res == 0);
+ return size;
+}
+
+int McAccess::read(int fd, void *buf, int size) {
+ int res;
+ WaitSema(_sema);
+ mcRead(fd, buf, size);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::write(int fd, const void *buf, int size) {
+ int res;
+ WaitSema(_sema);
+ mcWrite(fd, buf, size);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::mkDir(const char *name) {
+ int res;
+ WaitSema(_sema);
+ mcMkDir(_port, _slot, name);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::remove(const char *name) {
+ int res;
+ WaitSema(_sema);
+ mcDelete(_port, _slot, name);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::getDir(const char *name, unsigned int mode, int max, void *dest) {
+ int res;
+ WaitSema(_sema);
+ mcGetDir(_port, _slot, name, mode, max, (mcTable*)dest);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+int McAccess::getInfo(int *type, int *free, int *format) {
+ int res;
+ WaitSema(_sema);
+ mcGetInfo(_port, _slot, type, free, format);
+ mcSync(0, NULL, &res);
+ SignalSema(_sema);
+ return res;
+}
+
+#define MAX_MC_ENTRIES 16
+
+void runSaveThread(Ps2SaveFileManager *param);
+
+Ps2SaveFileManager::Ps2SaveFileManager(OSystem_PS2 *system, Gs2dScreen *screen) {
+ _system = system;
+ _screen = screen;
+ _mc = new McAccess(PORT, SLOT);
+
+ _mcDirList = (mcTable*)memalign(64, MAX_MC_ENTRIES * sizeof(mcTable));
+ _mcDirName[0] = '\0';
+ _mcCheckTime = 0;
+ _mcNeedsUpdate = true;
+
+ for (int mcCheckCount = 0; mcCheckCount < 3; mcCheckCount++) {
+ /* retry mcGetInfo 3 times. It slows down startup without mc considerably,
+ but cheap 3rd party memory cards apparently fail to get detected once in a while */
+
+ int mcType, mcFree, mcFormat;
+ int res = _mc->getInfo(&mcType, &mcFree, &mcFormat);
+
+ if ((res == 0) || (res == -1)) { // mc okay
+ _mcPresent = true;
+ printf("MC okay, result = %d. Type %d, Free %d, Format %d\n", res, mcType, mcFree, mcFormat);
+ checkMainDirectory();
+ break;
+ } else {
+ _mcPresent = false;
+ printf("MC failed, not present or not formatted, code %d\n", res);
+ }
+ }
+
+ // create save thread
+ ee_sema_t newSema;
+ newSema.init_count = 0;
+ newSema.max_count = 1;
+ _autoSaveSignal = CreateSema(&newSema);
+ _autoSaveBuf = NULL;
+ _autoSaveSize = 0;
+ _systemQuit = false;
+
+ ee_thread_t saveThread, thisThread;
+ ReferThreadStatus(GetThreadId(), &thisThread);
+
+ saveThread.initial_priority = thisThread.current_priority + 1;
+ saveThread.stack_size = 8 * 1024;
+ _autoSaveStack = malloc(saveThread.stack_size);
+ saveThread.stack = _autoSaveStack;
+ saveThread.func = (void *)runSaveThread;
+ saveThread.gp_reg = &_gp;
+
+ _autoSaveTid = CreateThread(&saveThread);
+ assert(_autoSaveTid >= 0);
+ StartThread(_autoSaveTid, this);
+}
+
+Ps2SaveFileManager::~Ps2SaveFileManager(void) {
+}
+
+void Ps2SaveFileManager::checkMainDirectory(void) {
+ // verify that the main directory (scummvm config + icon) exists
+ int ret, fd;
+ _mcNeedsUpdate = true;
+ ret = _mc->getDir("/ScummVM/*", 0, MAX_MC_ENTRIES, _mcDirList);
+ printf("/ScummVM/* res = %d\n", ret);
+ if (ret <= 0) { // assume directory doesn't exist
+ printf("Dir doesn't exist\n");
+ ret = _mc->mkDir("/ScummVM");
+ if (ret >= 0) {
+ fd = _mc->open("/ScummVM/scummvm.icn", O_WRONLY | O_CREAT);
+ if (fd >= 0) {
+ uint16 icoSize;
+ uint16 *icoBuf = decompressIconData(&icoSize);
+ ret = _mc->write(fd, icoBuf, icoSize * 2);
+ _mc->close(fd);
+ free(icoBuf);
+
+ printf(".icn written\n");
+ setupIcon("/ScummVM/icon.sys", "scummvm.icn", "ScummVM", "Configuration");
+ } else
+ printf("Can't create icon file: %d\n", fd);
+ } else
+ printf("can't create scummvm directory: %d\n", ret);
+ }
+}
+
+void Ps2SaveFileManager::splitPath(const char *fileName, char *dir, char *name) {
+ strcpy(dir, fileName);
+ char *ext = strchr(dir, '.');
+ if (ext) {
+ *ext = '\0';
+ ext++;
+ }
+ if (ext && *ext)
+ sprintf(name, "%s.ucl", ext);
+ else
+ strcpy(name, "save.ucl");
+}
+
+bool Ps2SaveFileManager::mcReadyForDir(const char *dir) {
+ if (_mcNeedsUpdate || ((_system->getMillis() - _mcCheckTime) > 2000) || !_mcPresent) {
+ // check if memory card was exchanged/removed in the meantime
+ int mcType, mcFree, mcFormat, mcResult;
+ mcResult = _mc->getInfo(&mcType, &mcFree, &mcFormat);
+ if (mcResult != 0) { // memory card was exchanged
+ _mcNeedsUpdate = true;
+ if (mcResult == -1) { // yes, it was exchanged
+ checkMainDirectory(); // make sure ScummVM dir and icon are there
+ } else { // no memorycard in slot or not formatted or something like that
+ _mcPresent = false;
+ printf("MC not found, error code %d\n", mcResult);
+ return false;
+ }
+ }
+ _mcPresent = true;
+ _mcCheckTime = _system->getMillis();
+ }
+ if (_mcNeedsUpdate || strcmp(_mcDirName, dir)) {
+ strcpy(_mcDirName, dir);
+ char dirStr[256];
+ sprintf(dirStr, "/ScummVM-%s/*", dir);
+ _mcEntries = _mc->getDir(dirStr, 0, MAX_MC_ENTRIES, _mcDirList);
+ _mcNeedsUpdate = false;
+ }
+ return (_mcEntries >= 0);
+}
+
+Common::InSaveFile *Ps2SaveFileManager::openForLoading(const char *filename) {
+ _screen->wantAnim(true);
+
+ char dir[256], name[256];
+ splitPath(filename, dir, name);
+ printf("openForLoading: \"%s\" => \"%s\" + \"%s\"\n", filename, dir, name);
+ if (mcReadyForDir(dir)) {
+ printf("Ready\n");
+ bool fileExists = false;
+ for (int i = 0; i < _mcEntries; i++)
+ if (strcmp(name, (char*)_mcDirList[i].name) == 0)
+ fileExists = true;
+ if (fileExists) {
+ printf("Found!\n");
+ char fullName[256];
+ sprintf(fullName, "/ScummVM-%s/%s", dir, name);
+ UclInSaveFile *file = new UclInSaveFile(fullName, _screen, _mc);
+ if (file) {
+ if (!file->ioFailed())
+ return file;
+ else {
+ printf("IoFailed\n");
+ delete file;
+ }
+ }
+ } else
+ printf("file %s (%s) doesn't exist\n", filename, name);
+ }
+ _screen->wantAnim(false);
+ return NULL;
+}
+
+Common::OutSaveFile *Ps2SaveFileManager::openForSaving(const char *filename) {
+ int res;
+ char dir[256], name[256];
+
+ _screen->wantAnim(true);
+ splitPath(filename, dir, name);
+
+ if (!mcReadyForDir(dir)) {
+ if (_mcPresent) { // directory doesn't seem to exist yet
+ char fullPath[256];
+ sprintf(fullPath, "/ScummVM-%s", dir);
+ res = _mc->mkDir(fullPath);
+
+ char icoSysDest[256], saveDesc[256];
+ sprintf(icoSysDest, "%s/icon.sys", fullPath);
+ strcpy(saveDesc, dir);
+ if ((saveDesc[0] >= 'a') && (saveDesc[0] <= 'z'))
+ saveDesc[0] += 'A' - 'a';
+ setupIcon(icoSysDest, "../ScummVM/scummvm.icn", saveDesc, "Savegames");
+ }
+ }
+
+ if (_mcPresent) {
+ char fullPath[256];
+ sprintf(fullPath, "/ScummVM-%s/%s", dir, name);
+ if (strstr(filename, ".s00") || strstr(filename, ".ASD") || strstr(filename, ".asd")) {
+ // this is an autosave
+ AutoSaveFile *file = new AutoSaveFile(this, fullPath);
+ return file;
+ } else {
+ UclOutSaveFile *file = new UclOutSaveFile(fullPath, _system, _screen, _mc);
+ if (!file->ioFailed()) {
+ // we're creating a file, mc will have to be updated next time
+ _mcNeedsUpdate = true;
+ return file;
+ } else {
+ printf("UCL out create failed!\n");
+ delete file;
+ }
+ }
+ }
+
+ _screen->wantAnim(false);
+ return NULL;
+}
+
+void Ps2SaveFileManager::listSavefiles(const char *prefix, bool *marks, int num) {
+ _screen->wantAnim(true);
+
+ int mcType, mcFree, mcFormat, mcResult;
+ mcResult = _mc->getInfo(&mcType, &mcFree, &mcFormat);
+
+ memset(marks, false, num * sizeof(bool));
+
+ if ((mcResult == 0) || (mcResult == -1)) {
+ // there's a memory card in the slot.
+ if (mcResult == -1)
+ _mcNeedsUpdate = true;
+
+ mcTable *mcEntries = (mcTable*)memalign(64, sizeof(mcTable) * MAX_MC_ENTRIES);
+
+ char dirStr[256], ext[256], mcSearchStr[256];
+ strcpy(dirStr, prefix);
+ char *pos = strchr(dirStr, '.');
+ if (pos) {
+ strcpy(ext, pos + 1);
+ *pos = '\0';
+ } else
+ ext[0] = '\0';
+ sprintf(mcSearchStr, "/ScummVM-%s/%s*", dirStr, ext);
+
+ int numEntries = _mc->getDir(mcSearchStr, 0, MAX_MC_ENTRIES, mcEntries);
+
+ int searchLen = strlen(ext);
+ for (int i = 0; i < numEntries; i++)
+ if ((((char*)mcEntries[i].name)[0] != '.') && stricmp((char*)mcEntries[i].name, "icon.sys")) {
+ char *stopCh;
+ int destNum = (int)strtoul((char*)mcEntries[i].name + searchLen, &stopCh, 10);
+ if ((!stopCh) || strcmp(stopCh, ".ucl"))
+ printf("unexpected end %s in name %s, search %s\n", stopCh, (char*)mcEntries[i].name, prefix);
+ if (destNum < num)
+ marks[destNum] = true;
+ }
+ free(mcEntries);
+ }
+ _screen->wantAnim(false);
+}
+
+Common::StringList Ps2SaveFileManager::listSavefiles(const char *regex) {
+ _screen->wantAnim(true);
+ Common::StringList results;
+ int mcType, mcFree, mcFormat, mcResult;
+
+ printf("listSavefiles -> regex=%s\n", regex);
+
+ mcResult = _mc->getInfo(&mcType, &mcFree, &mcFormat);
+
+ if ((mcResult == 0) || (mcResult == -1)) {
+ // there's a memory card in the slot.
+ if (mcResult == -1)
+ _mcNeedsUpdate = true;
+
+ mcTable *mcEntries = (mcTable*)memalign(64, sizeof(mcTable) * MAX_MC_ENTRIES);
+
+ char temp[256], mcSearchStr[256], *dir, *ext;
+ strcpy(temp, regex);
+ dir = strdup(strtok(temp, "."));
+ ext = strdup(strtok(NULL, "*"));
+
+ printf("dir = %s - ext = %s\n", dir, ext);
+
+ sprintf(mcSearchStr, "/ScummVM-%s/%s*", dir, ext);
+
+ int numEntries = _mc->getDir(mcSearchStr, 0, MAX_MC_ENTRIES, mcEntries);
+ char *name;
+ for (int i = 0; i < numEntries; i++) {
+ name = (char*)mcEntries[i].name;
+
+ if ((name[0] != '.') && stricmp(name, "icon.sys")) {
+ printf(" name = %s\n", (char*)mcEntries[i].name);
+ if (Common::matchString(name, "s*.ucl")) {
+ sprintf(temp, "%s.%s%c%c", dir, ext, name[1], name[2]);
+ results.push_back(temp);
+ printf(" -> match [%s] ;-)\n", temp);
+ }
+ else {
+ results.push_back(name); // ;-)
+ printf(" -> no match :-(\n");
+ }
+ }
+ }
+ free(mcEntries);
+ free(dir);
+ free(ext);
+ }
+
+ _screen->wantAnim(false);
+
+ return results;
+}
+
+bool Ps2SaveFileManager::removeSavefile(const char *filename) {
+
+ char dir[64], name[64], fullPath[128];
+
+ splitPath(filename, dir, name);
+ sprintf(fullPath, "/ScummVM-%s/%s", dir, name);
+
+ int res = _mc->remove(fullPath);
+ return (res == 0);
+}
+
+const char *Ps2SaveFileManager::getSavePath(void) const {
+ return "mc0:";
+}
+
+bool Ps2SaveFileManager::setupIcon(const char *dest, const char *ico, const char *descr1, const char *descr2) {
+ mcIcon icon_sys;
+ memset(&icon_sys, 0, sizeof(mcIcon));
+ memcpy(icon_sys.head, "PS2D", 4);
+ char title[256];
+ if (!stricmp("SAVEGAME", descr1)) { // these are broken sword 1 savegames
+ sprintf(title, "BSword1\n%s", descr2);
+ icon_sys.nlOffset = 8;
+ } else {
+ sprintf(title, "%s\n%s", descr1, descr2);
+ icon_sys.nlOffset = strlen(descr1) + 1;
+ }
+ strcpy_sjis((short*)&(icon_sys.title), title);
+ icon_sys.trans = 0x10;
+ memcpy(icon_sys.bgCol, _bgcolor, sizeof(_bgcolor));
+ memcpy(icon_sys.lightDir, _lightdir, sizeof(_lightdir));
+ memcpy(icon_sys.lightCol, _lightcol, sizeof(_lightcol));
+ memcpy(icon_sys.lightAmbient, _ambient, sizeof(_ambient));
+ strcpy((char*)icon_sys.view, ico);
+ strcpy((char*)icon_sys.copy, ico);
+ strcpy((char*)icon_sys.del, ico);
+
+ int fd, res;
+ fd = _mc->open(dest, O_WRONLY | O_CREAT);
+ if (fd >= 0) {
+ res = _mc->write(fd, &icon_sys, sizeof(icon_sys));
+ _mc->close(fd);
+ return (res == sizeof(icon_sys));
+ } else
+ return false;
+}
+
+uint16 *Ps2SaveFileManager::decompressIconData(uint16 *size) {
+ uint16 inPos = 1;
+ uint16 *rleData = (uint16*)_rleIcoData;
+ uint16 resSize = rleData[0];
+ uint16 *resData = (uint16*)malloc(resSize * sizeof(uint16));
+ uint16 outPos = 0;
+ while (outPos < resSize) {
+ uint16 len = rleData[inPos++];
+ while (len--)
+ resData[outPos++] = 0x7FFF;
+ len = rleData[inPos++];
+ while (len--)
+ resData[outPos++] = rleData[inPos++];
+ }
+ *size = resSize;
+ assert(outPos == resSize);
+ return resData;
+}
+
+void runSaveThread(Ps2SaveFileManager *param) {
+ param->saveThread();
+}
+
+void Ps2SaveFileManager::writeSaveNonblocking(char *name, void *buf, uint32 size) {
+ if (buf && size && !_systemQuit) {
+ strcpy(_autoSaveName, name);
+ assert(!_autoSaveBuf);
+ _autoSaveBuf = (uint8*)malloc(size);
+ memcpy(_autoSaveBuf, buf, size);
+ _autoSaveSize = size;
+ SignalSema(_autoSaveSignal);
+ }
+}
+
+void Ps2SaveFileManager::saveThread(void) {
+ while (!_systemQuit) {
+ WaitSema(_autoSaveSignal);
+ if (_autoSaveBuf && _autoSaveSize) {
+ UclOutSaveFile *outSave = new UclOutSaveFile(_autoSaveName, _system, _screen, _mc);
+ if (!outSave->ioFailed()) {
+ outSave->write(_autoSaveBuf, _autoSaveSize);
+ outSave->flush();
+ }
+ if (outSave->ioFailed())
+ _system->msgPrintf(5000, "Writing autosave to %s failed", _autoSaveName);
+ delete outSave;
+ free(_autoSaveBuf);
+ _autoSaveBuf = NULL;
+ _autoSaveSize = 0;
+ _mcNeedsUpdate = true; // we've created a file, mc will have to be updated
+ _screen->wantAnim(false);
+ }
+ }
+ ExitThread();
+}
+
+void Ps2SaveFileManager::quit(void) {
+ _systemQuit = true;
+ ee_thread_t statSave, statThis;
+ ReferThreadStatus(GetThreadId(), &statThis);
+ ChangeThreadPriority(_autoSaveTid, statThis.current_priority - 1);
+
+ do { // wait until thread called ExitThread()
+ SignalSema(_autoSaveSignal);
+ ReferThreadStatus(_autoSaveTid, &statSave);
+ } while (statSave.status != 0x10);
+
+ DeleteThread(_autoSaveTid);
+ free(_autoSaveStack);
+}
+
+McAccess *Ps2SaveFileManager::getMcAccess(void) {
+ return _mc;
+}
+
+
diff --git a/backends/platform/ps2/savefilemgr.h b/backends/platform/ps2/savefilemgr.h
new file mode 100644
index 0000000000..0164d4551b
--- /dev/null
+++ b/backends/platform/ps2/savefilemgr.h
@@ -0,0 +1,107 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef __SAVEFILEMGR_H__
+#define __SAVEFILEMGR_H__
+
+#include <libmc.h>
+#include "common/savefile.h"
+
+class Gs2dScreen;
+class OSystem_PS2;
+
+
+class McAccess {
+public:
+ McAccess(int port, int slot);
+ ~McAccess(void);
+ int open(const char *name, int mode);
+ int close(int fd);
+ int size(int fd);
+ int read(int fd, void *buf, int size);
+ int write(int fd, const void *buf, int size);
+ int mkDir(const char *name);
+ int getDir(const char *name, unsigned int mode, int max, void *dest);
+ int getInfo(int *type, int *free, int *format);
+ int remove(const char *name);
+
+private:
+ int _sema;
+ int _port, _slot;
+};
+
+class Ps2SaveFileManager : public Common::SaveFileManager {
+public:
+ Ps2SaveFileManager(OSystem_PS2 *system, Gs2dScreen *screen);
+ virtual ~Ps2SaveFileManager();
+
+ virtual Common::InSaveFile *openForLoading(const char *filename);
+ virtual Common::OutSaveFile *openForSaving(const char *filename);
+ virtual void listSavefiles(const char *prefix, bool *marks, int num);
+
+ virtual Common::StringList listSavefiles(const char *regex);
+ virtual bool removeSavefile(const char *filename);
+
+ /** Get the path to the save game directory. */
+ virtual const char *getSavePath() const;
+
+ void writeSaveNonblocking(char *name, void *buf, uint32 size);
+ void saveThread(void);
+ void quit(void);
+
+ McAccess *getMcAccess(void);
+private:
+ bool setupIcon(const char *dest, const char *ico, const char *descr1, const char *descr2);
+
+ bool mcReadyForDir(const char *dir);
+
+ void checkMainDirectory(void);
+ void splitPath(const char *fileName, char *dir, char *name);
+ uint16 *decompressIconData(uint16 *size);
+
+ Gs2dScreen *_screen;
+ OSystem_PS2 *_system;
+ McAccess *_mc;
+
+ int _autoSaveTid;
+ int _autoSaveSignal;
+ void *_autoSaveStack;
+ volatile bool _systemQuit;
+ uint8 *_autoSaveBuf;
+ uint32 _autoSaveSize;
+ char _autoSaveName[256];
+
+ mcTable *_mcDirList;
+ int _mcEntries;
+ char _mcDirName[256];
+ bool _mcNeedsUpdate, _mcPresent;
+ uint32 _mcCheckTime;
+
+ static const uint8 _rleIcoData[14018];
+ static const iconIVECTOR _bgcolor[4];
+ static const iconFVECTOR _lightdir[3], _lightcol[3], _ambient;
+};
+
+#endif // __SAVEFILE_MGR_H__
diff --git a/backends/platform/ps2/sdlkeys.h b/backends/platform/ps2/sdlkeys.h
new file mode 100644
index 0000000000..b2f783cedd
--- /dev/null
+++ b/backends/platform/ps2/sdlkeys.h
@@ -0,0 +1,264 @@
+/* copied from SDK_keysym.h */
+
+#ifndef __SDLKEYS_H__
+#define __SDLKEYS_H__
+
+enum SdlKeyCodes {
+ SDLK_UNKNOWN = 0,
+ SDLK_FIRST = 0,
+ SDLK_BACKSPACE = 8,
+ SDLK_TAB = 9,
+ SDLK_CLEAR = 12,
+ SDLK_RETURN = 13,
+ SDLK_PAUSE = 19,
+ SDLK_ESCAPE = 27,
+ SDLK_SPACE = 32,
+ SDLK_EXCLAIM = 33,
+ SDLK_QUOTEDBL = 34,
+ SDLK_HASH = 35,
+ SDLK_DOLLAR = 36,
+ SDLK_AMPERSAND = 38,
+ SDLK_QUOTE = 39,
+ SDLK_LEFTPAREN = 40,
+ SDLK_RIGHTPAREN = 41,
+ SDLK_ASTERISK = 42,
+ SDLK_PLUS = 43,
+ SDLK_COMMA = 44,
+ SDLK_MINUS = 45,
+ SDLK_PERIOD = 46,
+ SDLK_SLASH = 47,
+ SDLK_0 = 48,
+ SDLK_1 = 49,
+ SDLK_2 = 50,
+ SDLK_3 = 51,
+ SDLK_4 = 52,
+ SDLK_5 = 53,
+ SDLK_6 = 54,
+ SDLK_7 = 55,
+ SDLK_8 = 56,
+ SDLK_9 = 57,
+ SDLK_COLON = 58,
+ SDLK_SEMICOLON = 59,
+ SDLK_LESS = 60,
+ SDLK_EQUALS = 61,
+ SDLK_GREATER = 62,
+ SDLK_QUESTION = 63,
+ SDLK_AT = 64,
+ /*
+ Skip uppercase letters
+ */
+ SDLK_LEFTBRACKET = 91,
+ SDLK_BACKSLASH = 92,
+ SDLK_RIGHTBRACKET = 93,
+ SDLK_CARET = 94,
+ SDLK_UNDERSCORE = 95,
+ SDLK_BACKQUOTE = 96,
+ SDLK_a = 97,
+ SDLK_b = 98,
+ SDLK_c = 99,
+ SDLK_d = 100,
+ SDLK_e = 101,
+ SDLK_f = 102,
+ SDLK_g = 103,
+ SDLK_h = 104,
+ SDLK_i = 105,
+ SDLK_j = 106,
+ SDLK_k = 107,
+ SDLK_l = 108,
+ SDLK_m = 109,
+ SDLK_n = 110,
+ SDLK_o = 111,
+ SDLK_p = 112,
+ SDLK_q = 113,
+ SDLK_r = 114,
+ SDLK_s = 115,
+ SDLK_t = 116,
+ SDLK_u = 117,
+ SDLK_v = 118,
+ SDLK_w = 119,
+ SDLK_x = 120,
+ SDLK_y = 121,
+ SDLK_z = 122,
+ SDLK_DELETE = 127,
+ /* End of ASCII mapped keysyms */
+
+ /* International keyboard syms */
+ SDLK_WORLD_0 = 160, /* 0xA0 */
+ SDLK_WORLD_1 = 161,
+ SDLK_WORLD_2 = 162,
+ SDLK_WORLD_3 = 163,
+ SDLK_WORLD_4 = 164,
+ SDLK_WORLD_5 = 165,
+ SDLK_WORLD_6 = 166,
+ SDLK_WORLD_7 = 167,
+ SDLK_WORLD_8 = 168,
+ SDLK_WORLD_9 = 169,
+ SDLK_WORLD_10 = 170,
+ SDLK_WORLD_11 = 171,
+ SDLK_WORLD_12 = 172,
+ SDLK_WORLD_13 = 173,
+ SDLK_WORLD_14 = 174,
+ SDLK_WORLD_15 = 175,
+ SDLK_WORLD_16 = 176,
+ SDLK_WORLD_17 = 177,
+ SDLK_WORLD_18 = 178,
+ SDLK_WORLD_19 = 179,
+ SDLK_WORLD_20 = 180,
+ SDLK_WORLD_21 = 181,
+ SDLK_WORLD_22 = 182,
+ SDLK_WORLD_23 = 183,
+ SDLK_WORLD_24 = 184,
+ SDLK_WORLD_25 = 185,
+ SDLK_WORLD_26 = 186,
+ SDLK_WORLD_27 = 187,
+ SDLK_WORLD_28 = 188,
+ SDLK_WORLD_29 = 189,
+ SDLK_WORLD_30 = 190,
+ SDLK_WORLD_31 = 191,
+ SDLK_WORLD_32 = 192,
+ SDLK_WORLD_33 = 193,
+ SDLK_WORLD_34 = 194,
+ SDLK_WORLD_35 = 195,
+ SDLK_WORLD_36 = 196,
+ SDLK_WORLD_37 = 197,
+ SDLK_WORLD_38 = 198,
+ SDLK_WORLD_39 = 199,
+ SDLK_WORLD_40 = 200,
+ SDLK_WORLD_41 = 201,
+ SDLK_WORLD_42 = 202,
+ SDLK_WORLD_43 = 203,
+ SDLK_WORLD_44 = 204,
+ SDLK_WORLD_45 = 205,
+ SDLK_WORLD_46 = 206,
+ SDLK_WORLD_47 = 207,
+ SDLK_WORLD_48 = 208,
+ SDLK_WORLD_49 = 209,
+ SDLK_WORLD_50 = 210,
+ SDLK_WORLD_51 = 211,
+ SDLK_WORLD_52 = 212,
+ SDLK_WORLD_53 = 213,
+ SDLK_WORLD_54 = 214,
+ SDLK_WORLD_55 = 215,
+ SDLK_WORLD_56 = 216,
+ SDLK_WORLD_57 = 217,
+ SDLK_WORLD_58 = 218,
+ SDLK_WORLD_59 = 219,
+ SDLK_WORLD_60 = 220,
+ SDLK_WORLD_61 = 221,
+ SDLK_WORLD_62 = 222,
+ SDLK_WORLD_63 = 223,
+ SDLK_WORLD_64 = 224,
+ SDLK_WORLD_65 = 225,
+ SDLK_WORLD_66 = 226,
+ SDLK_WORLD_67 = 227,
+ SDLK_WORLD_68 = 228,
+ SDLK_WORLD_69 = 229,
+ SDLK_WORLD_70 = 230,
+ SDLK_WORLD_71 = 231,
+ SDLK_WORLD_72 = 232,
+ SDLK_WORLD_73 = 233,
+ SDLK_WORLD_74 = 234,
+ SDLK_WORLD_75 = 235,
+ SDLK_WORLD_76 = 236,
+ SDLK_WORLD_77 = 237,
+ SDLK_WORLD_78 = 238,
+ SDLK_WORLD_79 = 239,
+ SDLK_WORLD_80 = 240,
+ SDLK_WORLD_81 = 241,
+ SDLK_WORLD_82 = 242,
+ SDLK_WORLD_83 = 243,
+ SDLK_WORLD_84 = 244,
+ SDLK_WORLD_85 = 245,
+ SDLK_WORLD_86 = 246,
+ SDLK_WORLD_87 = 247,
+ SDLK_WORLD_88 = 248,
+ SDLK_WORLD_89 = 249,
+ SDLK_WORLD_90 = 250,
+ SDLK_WORLD_91 = 251,
+ SDLK_WORLD_92 = 252,
+ SDLK_WORLD_93 = 253,
+ SDLK_WORLD_94 = 254,
+ SDLK_WORLD_95 = 255, /* 0xFF */
+
+ /* Numeric keypad */
+ SDLK_KP0 = 256,
+ SDLK_KP1 = 257,
+ SDLK_KP2 = 258,
+ SDLK_KP3 = 259,
+ SDLK_KP4 = 260,
+ SDLK_KP5 = 261,
+ SDLK_KP6 = 262,
+ SDLK_KP7 = 263,
+ SDLK_KP8 = 264,
+ SDLK_KP9 = 265,
+ SDLK_KP_PERIOD = 266,
+ SDLK_KP_DIVIDE = 267,
+ SDLK_KP_MULTIPLY = 268,
+ SDLK_KP_MINUS = 269,
+ SDLK_KP_PLUS = 270,
+ SDLK_KP_ENTER = 271,
+ SDLK_KP_EQUALS = 272,
+
+ /* Arrows + Home/End pad */
+ SDLK_UP = 273,
+ SDLK_DOWN = 274,
+ SDLK_RIGHT = 275,
+ SDLK_LEFT = 276,
+ SDLK_INSERT = 277,
+ SDLK_HOME = 278,
+ SDLK_END = 279,
+ SDLK_PAGEUP = 280,
+ SDLK_PAGEDOWN = 281,
+
+ /* Function keys */
+ SDLK_F1 = 282,
+ SDLK_F2 = 283,
+ SDLK_F3 = 284,
+ SDLK_F4 = 285,
+ SDLK_F5 = 286,
+ SDLK_F6 = 287,
+ SDLK_F7 = 288,
+ SDLK_F8 = 289,
+ SDLK_F9 = 290,
+ SDLK_F10 = 291,
+ SDLK_F11 = 292,
+ SDLK_F12 = 293,
+ SDLK_F13 = 294,
+ SDLK_F14 = 295,
+ SDLK_F15 = 296,
+
+ /* Key state modifier keys */
+ SDLK_NUMLOCK = 300,
+ SDLK_CAPSLOCK = 301,
+ SDLK_SCROLLOCK = 302,
+ SDLK_RSHIFT = 303,
+ SDLK_LSHIFT = 304,
+ SDLK_RCTRL = 305,
+ SDLK_LCTRL = 306,
+ SDLK_RALT = 307,
+ SDLK_LALT = 308,
+ SDLK_RMETA = 309,
+ SDLK_LMETA = 310,
+ SDLK_LSUPER = 311, /* Left "Windows" key */
+ SDLK_RSUPER = 312, /* Right "Windows" key */
+ SDLK_MODE = 313, /* "Alt Gr" key */
+ SDLK_COMPOSE = 314, /* Multi-key compose key */
+
+ /* Miscellaneous function keys */
+ SDLK_HELP = 315,
+ SDLK_PRINT = 316,
+ SDLK_SYSREQ = 317,
+ SDLK_BREAK = 318,
+ SDLK_MENU = 319,
+ SDLK_POWER = 320, /* Power Macintosh power key */
+ SDLK_EURO = 321, /* Some european keyboards */
+ SDLK_UNDO = 322, /* Atari keyboard has Undo */
+
+ /* Add any other keys here */
+
+ SDLK_LAST
+};
+
+#endif
+
+