aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorRobert Göffringmann2006-06-07 06:07:05 +0000
committerRobert Göffringmann2006-06-07 06:07:05 +0000
commita01d5c139357217c2c3b7a8c485b99de4055fe2b (patch)
treec81bdaf431ebe50d3f5f6aee304b56a549e6919b /backends
parent6aaafb47ebc10fcc88d9d140bcc5c70eab417160 (diff)
downloadscummvm-rg350-a01d5c139357217c2c3b7a8c485b99de4055fe2b.tar.gz
scummvm-rg350-a01d5c139357217c2c3b7a8c485b99de4055fe2b.tar.bz2
scummvm-rg350-a01d5c139357217c2c3b7a8c485b99de4055fe2b.zip
various PS2 changes
svn-id: r22969
Diffstat (limited to 'backends')
-rw-r--r--backends/ps2/Gs2dScreen.cpp18
-rw-r--r--backends/ps2/GsDefs.h2
-rw-r--r--backends/ps2/READ_PS2.TXT72
-rw-r--r--backends/ps2/asyncfio.cpp22
-rw-r--r--backends/ps2/asyncfio.h2
-rw-r--r--backends/ps2/fileio.cpp77
-rw-r--r--backends/ps2/savefile.cpp89
-rw-r--r--backends/ps2/systemps2.cpp501
-rw-r--r--backends/ps2/systemps2.h34
9 files changed, 476 insertions, 341 deletions
diff --git a/backends/ps2/Gs2dScreen.cpp b/backends/ps2/Gs2dScreen.cpp
index 0c706e6ea3..7cf82ae5a0 100644
--- a/backends/ps2/Gs2dScreen.cpp
+++ b/backends/ps2/Gs2dScreen.cpp
@@ -31,6 +31,8 @@
#include "GsDefs.h"
#include "graphics/surface.h"
+extern void *_gp;
+
enum Buffers {
SCREEN = 0,
MOUSE,
@@ -61,7 +63,7 @@ static bool g_RunAnim = false;
static GsVertex kFullScreen[2];
static TexVertex kMouseTex[2] = {
{ SCALE(1), SCALE(1) },
- { SCALE(M_SIZE), SCALE(M_SIZE) }
+ { SCALE(M_SIZE - 1), SCALE(M_SIZE - 1) }
};
static TexVertex kPrintTex[2] = {
{ SCALE(1), SCALE(1) },
@@ -137,17 +139,17 @@ Gs2dScreen::Gs2dScreen(uint16 width, uint16 height, TVMode tvMode) {
if (tvMode == TV_DONT_CARE) {
if (PAL_NTSC_FLAG == 'E')
- _videoMode = TV_NTSC;
- else
_videoMode = TV_PAL;
+ else
+ _videoMode = TV_NTSC;
} else
_videoMode = tvMode;
printf("Setting up %s mode\n", (_videoMode == TV_PAL) ? "PAL" : "NTSC");
-
+
// set screen size, 640x544 for pal, 640x448 for ntsc
_tvWidth = 640;
- _tvHeight = ((_videoMode == TV_PAL) ? 544 : 448); // PAL => 512?
+ _tvHeight = ((_videoMode == TV_PAL) ? 544 : 448);
kFullScreen[0].z = kFullScreen[1].z = 0;
kFullScreen[0].x = ORIGIN_X;
kFullScreen[0].y = ORIGIN_Y;
@@ -226,10 +228,10 @@ Gs2dScreen::Gs2dScreen(uint16 width, uint16 height, TVMode tvMode) {
_animStack = malloc(ANIM_STACK_SIZE);
animThread.initial_priority = thisThread.current_priority - 3;
- animThread.stack = _animStack;
+ animThread.stack = _animStack;
animThread.stack_size = ANIM_STACK_SIZE;
- animThread.func = (void *)runAnimThread;
- asm("move %0, $gp\n": "=r"(animThread.gp_reg));
+ animThread.func = (void *)runAnimThread;
+ animThread.gp_reg = &_gp;
_animTid = CreateThread(&animThread);
assert(_animTid >= 0);
diff --git a/backends/ps2/GsDefs.h b/backends/ps2/GsDefs.h
index 3cc016d6dc..65dec5e2a6 100644
--- a/backends/ps2/GsDefs.h
+++ b/backends/ps2/GsDefs.h
@@ -27,7 +27,7 @@
// Gs2dScreen defines:
-#define PAL_NTSC_FLAG (*((uint8*)0x1FC80000))
+#define PAL_NTSC_FLAG (*(volatile uint8*)0x1FC7FF52)
#define GS_PMODE *((volatile uint64*)0x12000000)
#define GS_CSR *((volatile uint64*)0x12001000)
diff --git a/backends/ps2/READ_PS2.TXT b/backends/ps2/READ_PS2.TXT
index 29a53e5ba9..59ba25ce38 100644
--- a/backends/ps2/READ_PS2.TXT
+++ b/backends/ps2/READ_PS2.TXT
@@ -1,53 +1,62 @@
-ScummVM-PS2 Readme
-==================
+ScummVM-PS2 0.8.2 Readme
+========================
-You need a Playstation2 with a modchip of your choice in order to run ScummVM.
+You need a PlayStation 2 with a modchip of your choice in order to run ScummVM.
-ScummVM expects the game data on the CD-R, other devices like USB sticks
- and HDD are currently unsupported.
+ScummVM expects the game data on CD-R/DVD-R, on the Harddisk or on a USB mass
+ storage device.
-In order to use a USB Mouse and USB Keyboard, you need Sony's USB driver,
- the USBD.IRX. Copy it from a PS2 game that supports USB devices, like
- Eye Toy or Singstar.
-The demo disc that came with my PS2 also had it.
- Put it into the directory in which you extracted the .zip file.
-You can also use ScummVM without the USB driver but you can only use the
- Gamepad in that case.
+ It tries to mount the HDD partition hdd0:+ScummVM on startup and basically
+ treats it in the same way as the DVD drive.
+ Creating the partition and putting the datafiles there is up to you.
+
+ Not all USB mass storage devices are supported, but the most common ones should
+ work. If you attach a device and it gets recognized, it will show up together
+ with the CD/DVD drive and HDD in the "Add Game" dialog.
+
+ Most USB Mice and Keyboards should work, too. I have a Logitech MX500 mouse that
+ doesn't work, all the other devices I tried worked fine.
Creating a CD-R using CD-Tool
=============================
+
Copy any games you want on the CD over into the directory where you extracted
the ZIP file. Don't copy any files directly into the directory of the
ScummVM.ELF, those files are ignored. Instead, have each game in its own
directory.
-File- and directorynames should be DOS 8+3, if they aren't, they'll get
- renamed.
-If you run windows, just double click the make_iso.bat.
-Wait while it creates the ISO image and burn it with Nero
-or any other CD writing software.
+ File- and directorynames should be DOS 8+3, if they aren't, they'll get
+ renamed.
+
+ If you run windows, just double click the make_iso.bat.
+ Wait while it creates the ISO image and burn it with Nero
+ or any other CD writing software.
-For Linux or Mac OS X binaries check http://www.nobis-crew.org/cd-tool/
+ For Linux or Mac OS X binaries check http://www.nobis-crew.org/cd-tool/
-Unfortunately, writing DVD images with cd-tool is currently broken and will
- crash when it reaches the 2GB limit. This problem will probably be fixed in
- the nearer future.
+ Unfortunately, writing DVD images with cd-tool is currently broken.
+ This problem will probably be fixed in the nearer future.
+
+
+If you want to create a CD/DVD without CD-Tool, make sure to put the ELF,
+ the SYSTEM.CNF and all the IRXs into the CD/DVD's root directory.
Notes
=====
-- CD swapping doesn't work, unfortunately. So you should have all games
- on the CD you booted from.
-- Curse of Monkey Island is unsupported. iMuse digital crashes often,
- especially during Sea battles.
-- Zlib is unsupported, so compressed SAN files won't work.
+- The Curse of Monkey Island only works correctly from HDD.
+ Playing it from CD/DVD will initially seem to work, but you will
+ experience random crashes.
+- Compressed SAN files need a lot of CPU power, probably because of zlib,
+ and are constantly out of sync. Uncompressed SANs play fine though, so
+ compress_san is NOT recommended.
- The cd/dvd drive is a bottleneck, that's why you should compress the games
- with MP3 or Ogg/Vorbis using compress_scumm_sou / compress_scumm_bun /
- compress_sword1 / compress_sword2 etc, but *not* compress_san as it
- requires zlib. Besides, uncompressed SAN files play fine.
+ with MP3 using compress_scumm_sou / compress_scumm_bun / compress_sword1 /
+ compress_sword2 etc, but NOT compress_san.
- I haven't had time to implement a virtual keyboard. If you don't have a USB
keyboard, you can only enter '1's using the Select button.
+ (for copy protection screens as well as savegame names)
- When you see '1's and '0's flying across your screen, it means ScummVM is
accessing the Memory Card. Don't switch off or reset the console in that
case, and don't remove the Memory Card either :P
@@ -66,3 +75,8 @@ Cross - Left mouse button
Circle - Right mouse button
Left analog stick - Mouse. Disabled when USB mouse is detected.
+
+
+Changes since 0.8.0 RC3
+=======================
+- USB Mass support was added
diff --git a/backends/ps2/asyncfio.cpp b/backends/ps2/asyncfio.cpp
index 4ffd19fa47..45cadbafa9 100644
--- a/backends/ps2/asyncfio.cpp
+++ b/backends/ps2/asyncfio.cpp
@@ -52,8 +52,6 @@ int AsyncFio::open(const char *name, int ioMode) {
fileXioOpen(name, ioMode, DEFAULT_MODE);
fileXioWaitAsync(FXIO_WAIT, &res);
SignalSema(_ioSema);
- if (res < -2)
- printf("File %s error: %d (mode %d)\n", name, res, ioMode);
return res;
}
@@ -144,6 +142,26 @@ void AsyncFio::dclose(int fd) {
SignalSema(_ioSema);
}
+int AsyncFio::mount(const char *mountpoint, const char *mountstring, int flag) {
+ int res;
+ WaitSema(_ioSema);
+ checkSync();
+ fileXioMount(mountpoint, mountstring, flag);
+ fileXioWaitAsync(FXIO_WAIT, &res);
+ SignalSema(_ioSema);
+ return res;
+}
+
+int AsyncFio::umount(const char *mountpoint) {
+ int res;
+ WaitSema(_ioSema);
+ checkSync();
+ fileXioUmount(mountpoint);
+ fileXioWaitAsync(FXIO_WAIT, &res);
+ SignalSema(_ioSema);
+ return res;
+}
+
int AsyncFio::sync(int fd) {
WaitSema(_ioSema);
if (_runningOp == _ioSlots + fd)
diff --git a/backends/ps2/asyncfio.h b/backends/ps2/asyncfio.h
index a9cb5607b9..ce5145dea2 100644
--- a/backends/ps2/asyncfio.h
+++ b/backends/ps2/asyncfio.h
@@ -36,6 +36,8 @@ public:
int dopen(const char *name);
int dread(int fd, iox_dirent_t *dest);
void dclose(int fd);
+ int mount(const char *mountpoint, const char *mountstring, int flag);
+ int umount(const char *mountpoint);
int sync(int fd);
bool poll(int fd);
bool fioAvail(void);
diff --git a/backends/ps2/fileio.cpp b/backends/ps2/fileio.cpp
index 61d43b355a..3b21e0796f 100644
--- a/backends/ps2/fileio.cpp
+++ b/backends/ps2/fileio.cpp
@@ -27,10 +27,11 @@
#include <fileio.h>
#include <assert.h>
#include <string.h>
-#include <cdvd_rpc.h>
#include "backends/ps2/asyncfio.h"
#include "base/engine.h"
#include "common/file.h"
+#include "eecodyvdfs.h"
+#include "common/config-manager.h"
#define CACHE_SIZE (2048 * 32)
#define MAX_READ_STEP (2048 * 16)
@@ -396,7 +397,7 @@ private:
uint8 _rootLen;
};
-TocManager tocManager;
+static TocManager tocManager;
struct FioHandleCache {
Ps2File *file;
@@ -409,6 +410,8 @@ static int cacheListLen = 0;
static int openFileCount = 0;
static int cacheListSema = -1;
+static bool checkedPath = false;
+
Ps2File *findInCache(int64 id);
FILE *ps2_fopen(const char *fname, const char *mode) {
@@ -419,9 +422,19 @@ FILE *ps2_fopen(const char *fname, const char *mode) {
cacheListSema = CreateSema(&newSema);
assert(cacheListSema >= 0);
}
- if (!tocManager.haveEntries() && g_engine) // read the TOC the first time the engine opens a file
- // FIXME: Dear porter, you probably want to use ConfMan.get("path") here to get the data path
- tocManager.readEntries(g_engine->getGameDataPath());
+
+ printf("ps2_fopen: %s, %s\n", fname, mode);
+
+ if (!checkedPath && g_engine) {
+ // are we playing from cd/dvd?
+ const char *gameDataPath = ConfMan.get("path").c_str();
+ printf("Read TOC dir: %s\n", gameDataPath);
+ if (strncmp(gameDataPath, "cdfs:", 5) != 0)
+ driveStop(); // no, we aren't. stop the drive. it's noisy.
+ // now cache the dir tree
+ tocManager.readEntries(gameDataPath);
+ checkedPath = true;
+ }
if (((mode[0] != 'r') && (mode[0] != 'w')) || ((mode[1] != '\0') && (mode[1] != 'b'))) {
printf("unsupported mode \"%s\" for file \"%s\"\n", mode, fname);
@@ -623,7 +636,6 @@ TocManager::TocManager(void) {
}
TocManager::~TocManager(void) {
- // todo: write this...
}
bool TocManager::haveEntries(void) {
@@ -633,38 +645,41 @@ bool TocManager::haveEntries(void) {
void TocManager::readEntries(const char *root) {
_rootLen = strlen(root);
strcpy(_root, root);
- if (_root[_rootLen - 1] == '/') {
+ while (_root[_rootLen - 1] == '/') {
_rootLen--;
_root[_rootLen] = '\0';
}
- readDir(_root, &_rootNode, 0);
+ char readPath[256];
+ sprintf(readPath, "%s/", _root);
+ printf("readDir: %s\n", readPath);
+ readDir(readPath, &_rootNode, 0);
}
-#define MAX_DIR_ENTRIES 512
-
void TocManager::readDir(const char *path, TocNode **node, int level) {
if (level <= 2) { // we don't scan deeper than that
- struct TocEntry tocEntries[MAX_DIR_ENTRIES];
- int files = CDVD_GetDir(path + 5, NULL, CDVD_GET_FILES_AND_DIRS, tocEntries, MAX_DIR_ENTRIES, NULL);
-
- for (int cnt = 0; cnt < files; cnt++) {
- if (tocEntries[cnt].filename[0] != '.') { // skip '.' and '..'
- *node = new TocNode;
- (*node)->sub = (*node)->next = NULL;
-
- (*node)->nameLen = strlen(tocEntries[cnt].filename);
- memcpy((*node)->name, tocEntries[cnt].filename, (*node)->nameLen + 1);
-
- if (tocEntries[cnt].fileProperties & 2) { // directory
- (*node)->isDir = true;
- char nextPath[256];
- sprintf(nextPath, "%s/%s", path, tocEntries[cnt].filename);
- readDir(nextPath, &((*node)->sub), level + 1);
- } else
- (*node)->isDir = false;
- node = &((*node)->next);
- }
- }
+ iox_dirent_t dirent;
+ int fd = fio.dopen(path);
+ if (fd >= 0) {
+ while (fio.dread(fd, &dirent) > 0)
+ if (dirent.name[0] != '.') { // skip '.' and '..'
+ *node = new TocNode;
+ (*node)->sub = (*node)->next = NULL;
+
+ (*node)->nameLen = strlen(dirent.name);
+ memcpy((*node)->name, dirent.name, (*node)->nameLen + 1);
+
+ if (dirent.stat.mode & FIO_S_IFDIR) { // directory
+ (*node)->isDir = true;
+ char nextPath[256];
+ sprintf(nextPath, "%s%s/", path, dirent.name);
+ readDir(nextPath, &((*node)->sub), level + 1);
+ } else
+ (*node)->isDir = false;
+ node = &((*node)->next);
+ }
+ fio.dclose(fd);
+ } else
+ printf("Can't open path: %s\n", path);
}
}
diff --git a/backends/ps2/savefile.cpp b/backends/ps2/savefile.cpp
index e2254d9210..495fc556b3 100644
--- a/backends/ps2/savefile.cpp
+++ b/backends/ps2/savefile.cpp
@@ -33,6 +33,8 @@
#include "backends/ps2/systemps2.h"
#include "common/scummsys.h"
+extern void *_gp;
+
#define UCL_MAGIC 0x314C4355
#define PORT 0
@@ -53,6 +55,7 @@ public:
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;
@@ -130,6 +133,15 @@ int McAccess::mkDir(const char *name) {
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);
@@ -154,7 +166,7 @@ public:
virtual ~UclOutSaveFile(void);
virtual uint32 write(const void *ptr, uint32 size);
virtual void flush(void);
- virtual bool ioFailed(void);
+ virtual bool ioFailed(void) const;
virtual void clearIOFailed(void);
private:
OSystem_PS2 *_system;
@@ -164,6 +176,7 @@ private:
uint8 *_buf;
uint32 _bufSize, _bufPos;
bool _ioFailed, _wasFlushed;
+ char _fileName[128];
};
class UclInSaveFile : public Common::InSaveFile {
@@ -172,9 +185,13 @@ public:
virtual ~UclInSaveFile(void);
virtual bool eos(void) const;
virtual uint32 read(void *ptr, uint32 size);
- virtual bool ioFailed(void);
+ virtual bool ioFailed(void) const;
virtual void clearIOFailed(void);
virtual void skip(uint32 offset);
+
+ virtual uint32 pos(void) const;
+ virtual uint32 size(void) const;
+ virtual void seek(int pos, int whence = SEEK_SET);
private:
Gs2dScreen *_screen;
McAccess *_mc;
@@ -271,9 +288,9 @@ Ps2SaveFileManager::Ps2SaveFileManager(OSystem_PS2 *system, Gs2dScreen *screen)
saveThread.initial_priority = thisThread.current_priority + 1;
saveThread.stack_size = 8 * 1024;
_autoSaveStack = malloc(saveThread.stack_size);
- saveThread.stack = _autoSaveStack;
- saveThread.func = (void *)runSaveThread;
- asm("move %0, $gp\n": "=r"(saveThread.gp_reg));
+ saveThread.stack = _autoSaveStack;
+ saveThread.func = (void *)runSaveThread;
+ saveThread.gp_reg = &_gp;
_autoSaveTid = CreateThread(&saveThread);
assert(_autoSaveTid >= 0);
@@ -560,14 +577,13 @@ void Ps2SaveFileManager::quit(void) {
_systemQuit = true;
ee_thread_t statSave, statThis;
ReferThreadStatus(GetThreadId(), &statThis);
- int res = ChangeThreadPriority(_autoSaveTid, statThis.current_priority - 1);
- sioprintf("SaveThread prio res: %d", res);
+ ChangeThreadPriority(_autoSaveTid, statThis.current_priority - 1);
do { // wait until thread called ExitThread()
SignalSema(_autoSaveSignal);
ReferThreadStatus(_autoSaveTid, &statSave);
} while (statSave.status != 0x10);
- sioprintf("wait done");
+
DeleteThread(_autoSaveTid);
free(_autoSaveStack);
}
@@ -613,7 +629,7 @@ UclInSaveFile::~UclInSaveFile(void) {
_screen->wantAnim(false);
}
-bool UclInSaveFile::ioFailed(void) {
+bool UclInSaveFile::ioFailed(void) const {
return _ioFailed;
}
@@ -625,6 +641,33 @@ bool UclInSaveFile::eos(void) const {
return _bufPos == _bufSize;
}
+uint32 UclInSaveFile::pos(void) const {
+ return _bufPos;
+}
+
+uint32 UclInSaveFile::size(void) const {
+ return _bufSize;
+}
+
+void UclInSaveFile::seek(int pos, int whence) {
+ int destPos;
+ switch (whence) {
+ case SEEK_SET:
+ destPos = pos;
+ break;
+ case SEEK_CUR:
+ destPos = _bufPos + pos;
+ break;
+ case SEEK_END:
+ destPos = _bufSize + pos;
+ break;
+ default:
+ return;
+ }
+ if ((destPos >= 0) && (destPos <= (int)_bufSize))
+ _bufPos = (uint32)destPos;
+}
+
uint32 UclInSaveFile::read(void *ptr, uint32 size) {
if (_buf) {
uint32 bytesRemain = _bufSize - _bufPos;
@@ -660,6 +703,7 @@ UclOutSaveFile::UclOutSaveFile(const char *filename, OSystem_PS2 *system, Gs2dSc
_bufSize = 65536;
_buf = (uint8*)malloc(_bufSize);
_ioFailed = false;
+ strcpy(_fileName, filename);
} else {
_ioFailed = true;
_bufSize = 0;
@@ -686,7 +730,7 @@ UclOutSaveFile::~UclOutSaveFile(void) {
_screen->wantAnim(false);
}
-bool UclOutSaveFile::ioFailed(void) {
+bool UclOutSaveFile::ioFailed(void) const {
return _ioFailed;
}
@@ -695,7 +739,7 @@ void UclOutSaveFile::clearIOFailed(void) {
}
void UclOutSaveFile::flush(void) {
- int res = 0;
+ int res;
if (_bufPos) {
if (_wasFlushed) {
@@ -712,17 +756,30 @@ void UclOutSaveFile::flush(void) {
res = ucl_nrv2e_99_compress(_buf, _bufPos, compBuf + 8, &compSize, NULL, 10, NULL, NULL);
if (res >= 0) {
res = _mc->write(_fd, compBuf, compSize + 8);
- if (res != (int)compSize + 8)
+ if (res != (int)compSize + 8) {
+ printf("flush: write failed, %d != %d\n", res, compSize + 8);
res = -1;
+ }
} else
printf("Unable to compress %d bytes of savedata, errorcode %d\n", _bufPos, res);
free(compBuf);
_bufPos = 0;
}
- }
- if (res < 0) {
- _ioFailed = true;
- printf("UclOutSaveFile::flush failed!\n");
+
+ if (res < 0) {
+ _ioFailed = true;
+ printf("UclOutSaveFile::flush failed!\n");
+ if (_fd >= 0) {
+ // the file is broken; delete it
+ _mc->close(_fd);
+ res = _mc->remove(_fileName);
+ if (res == 0)
+ printf("File %s: remove ok\n", _fileName);
+ else
+ printf("File %s: remove error %d\n", _fileName, res);
+ _fd = -1;
+ }
+ }
}
}
diff --git a/backends/ps2/systemps2.cpp b/backends/ps2/systemps2.cpp
index 3f8ee9c969..5437e5b324 100644
--- a/backends/ps2/systemps2.cpp
+++ b/backends/ps2/systemps2.cpp
@@ -31,16 +31,15 @@
#include <assert.h>
#include <iopcontrol.h>
#include <iopheap.h>
-#include <osd_config.h>
#include "common/scummsys.h"
#include "../intern.h"
#include "base/engine.h"
-#include "base/main.h"
#include "backends/ps2/systemps2.h"
#include "backends/ps2/Gs2dScreen.h"
#include "backends/ps2/ps2input.h"
+#include "backends/ps2/irxboot.h"
#include <sjpcm.h>
-#include <cdvd_rpc.h>
+#include <libhdd.h>
#include "backends/ps2/savefile.h"
#include "common/file.h"
#include "backends/ps2/sysdefs.h"
@@ -49,28 +48,27 @@
#include "backends/ps2/cd.h"
#include <sio.h>
#include <fileXio_rpc.h>
+#include "backends/ps2/asyncfio.h"
+#include "eecodyvdfs.h"
#include "graphics/surface.h"
#include "graphics/font.h"
+// asm("mfc0 %0, $9\n" : "=r"(tickStart));
+
+extern void *_gp;
+
#define TIMER_STACK_SIZE (1024 * 32)
#define SOUND_STACK_SIZE (1024 * 32)
#define SMP_PER_BLOCK 800
-#define FROM_BCD(a) ((a >> 4) * 10 + (a & 0xF))
#define BUS_CLOCK 147456000 // bus clock, a little less than 150 mhz
#define CLK_DIVIS 5760 // the timer IRQ handler gets called (BUS_CLOCK / 256) / CLK_DIVIS times per second (100 times)
-#ifdef USE_PS2LINK
-#define IRX_PREFIX "host:"
-#define IRX_SUFFIX
-#else
-#define IRX_PREFIX "cdrom0:\\"
-#define IRX_SUFFIX ";1"
-#endif
-
static int g_TimerThreadSema = -1, g_SoundThreadSema = -1;
static int g_MainWaitSema = -1, g_TimerWaitSema = -1;
static volatile int32 g_MainWakeUp = 0, g_TimerWakeUp = 0;
-static volatile uint32 msecCount = 0;
+volatile uint32 msecCount = 0;
+
+OSystem_PS2 *g_systemPs2;
int gBitFormat = 555;
@@ -80,6 +78,8 @@ namespace Graphics {
extern const NewFont g_sysfont;
};
+extern AsyncFio fio;
+
void sioprintf(const char *zFormat, ...) {
va_list ap;
char resStr[2048];
@@ -91,23 +91,10 @@ void sioprintf(const char *zFormat, ...) {
sio_puts(resStr);
}
+extern "C" int scummvm_main(int argc, char *argv[]);
+
extern "C" int main(int argc, char *argv[]) {
SifInitRpc(0);
-#ifndef USE_PS2LINK // reset the IOP if this is a CD build
- cdvdInit(CDVD_EXIT);
- cdvdExit();
- SifExitIopHeap();
- SifLoadFileExit();
- SifExitRpc();
- sio_puts("Resetting IOP.");
- SifIopReset("rom0:UDNL rom0:EELOADCNF",0);
- while (!SifIopSync())
- ;
- sio_puts("IOP synced.");
- SifInitRpc(0);
- SifLoadFileInit();
- cdvdInit(CDVD_INIT_NOWAIT);
-#endif
ee_thread_t thisThread;
int tid = GetThreadId();
@@ -127,15 +114,10 @@ extern "C" int main(int argc, char *argv[]) {
}
sioprintf("Creating system");
- /* The OSystem has to be created before we enter ScummVM's main.
- It sets up the memory card, etc. */
- g_system = new OSystem_PS2();
- assert(g_system);
+ g_system = g_systemPs2 = new OSystem_PS2(argv[0]);
sioprintf("init done. starting ScummVM.");
- int res = scummvm_main(argc, argv);
- g_system->quit(); // TODO: Consider removing / replacing this!
- return res;
+ return scummvm_main(argc, argv);
}
s32 timerInterruptHandler(s32 cause) {
@@ -170,7 +152,84 @@ void systemSoundThread(OSystem_PS2 *system) {
system->soundThread();
}
-OSystem_PS2::OSystem_PS2(void) {
+void gluePowerOffCallback(void *system) {
+ ((OSystem_PS2*)system)->powerOffCallback();
+}
+
+void mass_connect_cb(void *pkt, void *system) {
+ ((OSystem_PS2*)system)->setUsbMassConnected(true);
+}
+
+void mass_disconnect_cb(void *pkt, void *system) {
+ ((OSystem_PS2*)system)->setUsbMassConnected(false);
+}
+
+void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) {
+
+ _usbMassLoaded = _useMouse = _useKbd = _useHdd = false;
+
+ int res = 0, rv = 0;
+ for (int i = 0; i < numModules; i++) {
+ if (modules[i].loc == IRX_FILE) {
+ res = SifLoadModule(modules[i].path, modules[i].argSize, modules[i].args);
+ sioprintf("Module \"%s\": %d", modules[i].path, res);
+ if (res < 0) {
+ msgPrintf(FOREVER, "\"%s\"\nnot found: %d", modules[i].path, res);
+ delayMillis(5000);
+ quit();
+ }
+ } else if (modules[i].loc == IRX_BUFFER) {
+ if (modules[i].errorCode == 0) {
+ res = SifExecModuleBuffer(modules[i].buffer, modules[i].size, modules[i].argSize, modules[i].args, &rv);
+ sioprintf("Module \"%s\": EE=%d, IOP=%d", modules[i].path, res, rv);
+ if ((res >= 0) && (rv >= 0)) {
+ switch (modules[i].fileRef->purpose) {
+ case MASS_DRIVER:
+ _usbMassLoaded = true;
+ break;
+ case MOUSE_DRIVER:
+ _useMouse = true;
+ break;
+ case KBD_DRIVER:
+ _useKbd = true;
+ break;
+ case HDD_DRIVER:
+ _useHdd = true;
+ break;
+ default:
+ break;
+ }
+ }
+ } else
+ sioprintf("Module \"%s\" wasn't found: %d", modules[i].path, modules[i].errorCode);
+
+ if ((modules[i].errorCode < 0) || (res < 0) || (rv < 0)) {
+ if (!(modules[i].fileRef->flags & OPTIONAL)) {
+ if (modules[i].errorCode < 0)
+ msgPrintf(FOREVER, "\"%s\"\nnot found: %d", modules[i].path, modules[i].errorCode);
+ else
+ msgPrintf(FOREVER, "Couldn't start\n\"%s\"\nEE=%d IOP=%d", modules[i].path, res, rv);
+ delayMillis(5000);
+ quit();
+ }
+ }
+
+ if (modules[i].buffer);
+ free(modules[i].buffer);
+ } else {
+ sioprintf("module %d of %d damaged, loc %d, path %s", i, numModules, modules[i].loc, modules[i].path);
+ }
+ free(modules[i].path);
+ }
+ free(modules);
+ sioprintf("done");
+ sioprintf("UsbMass: %sloaded", _usbMassLoaded ? "" : "not ");
+ sioprintf("Mouse: %sloaded", _useMouse ? "" : "not ");
+ sioprintf("Kbd: %sloaded", _useKbd ? "" : "not ");
+ sioprintf("Hdd: %sloaded", _useHdd ? "" : "not ");
+}
+
+OSystem_PS2::OSystem_PS2(const char *elfPath) {
_soundStack = _timerStack = NULL;
_scummTimerProc = NULL;
_scummSoundProc = NULL;
@@ -178,6 +237,7 @@ OSystem_PS2::OSystem_PS2(void) {
_printY = 0;
_msgClearTime = 0;
_systemQuit = false;
+ _usbMassConnected = false;
_screen = new Gs2dScreen(320, 200, TV_DONT_CARE);
@@ -186,24 +246,53 @@ OSystem_PS2::OSystem_PS2(void) {
_screen->wantAnim(true);
- sioprintf("Loading IOP modules...");
- loadModules();
+ char irxPath[256];
+ _bootDevice = detectBootPath(elfPath, irxPath);
+
+ IrxReference *modules;
+ int numModules = loadIrxModules(_bootDevice, irxPath, &modules);
+
+ if (_bootDevice != HOST) {
+ sio_puts("Resetting IOP.");
+ cdvdInit(CDVD_EXIT);
+ cdvdExit();
+ SifExitIopHeap();
+ SifLoadFileExit();
+ SifExitRpc();
+ SifIopReset("rom0:UDNL rom0:EELOADCNF", 0);
+ while (!SifIopSync())
+ ;
+ sio_puts("IOP synced.");
+ SifInitRpc(0);
+ SifLoadFileInit();
+ cdvdInit(CDVD_INIT_WAIT);
+ }
+ startIrxModules(numModules, modules);
int res;
- if ((res = SjPCM_Init(0)) < 0) {
- msgPrintf(FOREVER, "SjPCM Bind failed: %d", res);
+ if ((res = fileXioInit()) < 0) {
+ msgPrintf(FOREVER, "FXIO Init failed: %d", res);
quit();
}
- if ((res = CDVD_Init()) != 0) {
- msgPrintf(FOREVER, "CDVD Init failed: %d", res);
+ if ((res = initCdvdFs()) < 0) {
+ msgPrintf(FOREVER, "CoDyVDfs bind failed: %d", res);
quit();
}
-
- if ((res = fileXioInit()) < 0) {
- msgPrintf(FOREVER, "FXIO Init failed: %d", res);
+
+ if ((res = SjPCM_Init(0)) < 0) {
+ msgPrintf(FOREVER, "SjPCM Bind failed: %d\n", res);
quit();
}
+
+ if (_useHdd) {
+ if ((hddCheckPresent() < 0) || (hddCheckFormatted() < 0))
+ _useHdd = false;
+
+ hddPreparePoweroff();
+ hddSetUserPoweroffCallback(gluePowerOffCallback, this);
+ }
+
fileXioSetBlockMode(FXIO_NOWAIT);
_mouseVisible = false;
@@ -211,15 +300,19 @@ OSystem_PS2::OSystem_PS2(void) {
sioprintf("reading RTC");
readRtcTime();
+ if (_useHdd) {
+ if (fio.mount("pfs0:", "hdd0:+ScummVM", 0) >= 0)
+ printf("Successfully mounted!\n");
+ else
+ _useHdd = false;
+ }
+
sioprintf("Starting SavefileManager");
_saveManager = new Ps2SaveFileManager(this, _screen);
sioprintf("Initializing ps2Input");
_input = new Ps2Input(this, _useMouse, _useKbd);
-#ifdef _REC_MUTEX_
- _mutex = new Ps2Mutex[MAX_MUTEXES];
-
ee_sema_t newSema;
newSema.init_count = 1;
newSema.max_count = 1;
@@ -228,7 +321,7 @@ OSystem_PS2::OSystem_PS2(void) {
_mutex[i].sema = -1;
_mutex[i].count = _mutex[i].owner = 0;
}
-#endif
+
_screen->wantAnim(false);
_screen->clearScreen();
}
@@ -257,15 +350,14 @@ void OSystem_PS2::initTimer(void) {
timerThread.stack = _timerStack;
timerThread.stack_size = TIMER_STACK_SIZE;
timerThread.func = (void *)systemTimerThread;
- //timerThread.gp_reg = _gp; // _gp is always NULL.. broken linkfile?
- asm("move %0, $gp\n": "=r"(timerThread.gp_reg));
+ timerThread.gp_reg = &_gp;
// soundthread's priority is higher than main- and timerthread
soundThread.initial_priority = thisThread.current_priority - 2;
soundThread.stack = _soundStack;
soundThread.stack_size = SOUND_STACK_SIZE;
soundThread.func = (void *)systemSoundThread;
- asm("move %0, $gp\n": "=r"(soundThread.gp_reg));
+ soundThread.gp_reg = &_gp;
_timerTid = CreateThread(&timerThread);
_soundTid = CreateThread(&soundThread);
@@ -290,6 +382,11 @@ void OSystem_PS2::initTimer(void) {
T0_COUNT = 0;
T0_COMP = CLK_DIVIS; // (BUS_CLOCK / 256) / CLK_DIVIS = 100
T0_MODE = TIMER_MODE( 2, 0, 0, 0, 1, 1, 1, 0, 1, 1);
+
+ DI();
+ SifAddCmdHandler(0x12, mass_connect_cb, this);
+ SifAddCmdHandler(0x13, mass_disconnect_cb, this);
+ EI();
}
void OSystem_PS2::timerThread(void) {
@@ -307,12 +404,12 @@ void OSystem_PS2::soundThread(void) {
soundSema.max_count = 1;
_soundSema = CreateSema(&soundSema);
assert(_soundSema >= 0);
-
int16 *soundBufL = (int16*)memalign(64, SMP_PER_BLOCK * sizeof(int16) * 2);
int16 *soundBufR = soundBufL + SMP_PER_BLOCK;
int bufferedSamples = 0;
int cycles = 0;
+
while (!_systemQuit) {
WaitSema(g_SoundThreadSema);
@@ -324,7 +421,7 @@ void OSystem_PS2::soundThread(void) {
WaitSema(_soundSema);
if (_scummSoundProc) {
- if (bufferedSamples <= 4 * SMP_PER_BLOCK) {
+ if (bufferedSamples <= 8 * SMP_PER_BLOCK) {
// we have to produce more samples, call sound mixer
// the scratchpad at 0x70000000 is used as temporary soundbuffer
_scummSoundProc(_scummSoundParam, (uint8*)0x70000000, SMP_PER_BLOCK * 2 * sizeof(int16));
@@ -366,7 +463,7 @@ void OSystem_PS2::soundThread(void) {
SjPCM_Enqueue((short int*)soundBufL, (short int*)soundBufR, SMP_PER_BLOCK, 0);
bufferedSamples += SMP_PER_BLOCK;
}
- }
+ }
SignalSema(_soundSema);
}
free(soundBufL);
@@ -374,7 +471,7 @@ void OSystem_PS2::soundThread(void) {
ExitThread();
}
-const char *irxModules[] = {
+/*const char *irxModules[] = {
"rom0:SIO2MAN",
"rom0:MCMAN",
"rom0:MCSERV",
@@ -384,14 +481,16 @@ const char *irxModules[] = {
IRX_PREFIX "IOMANX.IRX" IRX_SUFFIX,
#endif
IRX_PREFIX "FILEXIO.IRX" IRX_SUFFIX,
- IRX_PREFIX "CDVD.IRX" IRX_SUFFIX,
- IRX_PREFIX "SJPCM.IRX" IRX_SUFFIX
-};
+ IRX_PREFIX "CODYVDFS.IRX" IRX_SUFFIX,
+ IRX_PREFIX "SJPCM.IRX" IRX_SUFFIX,
+};*/
void OSystem_PS2::loadModules(void) {
- _useMouse = _useKbd = false;
-
+ //_usbMassConnected = _usbMassLoaded = _useMouse = _useKbd = _useHdd = false;
+ //static char hddarg[] = "-o" "\0" "4" "\0" "-n" "\0" "20";
+ //static char pfsarg[] = "-m" "\0" "2" "\0" "-o" "\0" "16" "\0" "-n" "\0" "40" /*"\0" "-debug"*/;
+#if 0
int res;
for (int i = 0; i < ARRAYSIZE(irxModules); i++) {
if ((res = SifLoadModule(irxModules[i], 0, NULL)) < 0) {
@@ -412,8 +511,46 @@ void OSystem_PS2::loadModules(void) {
sioprintf("Cannot load module: RPCKBD.IRX (%d)", res);
else
_useKbd = true;
+ if ((res = SifLoadModule(IRX_PREFIX "USB_MASS.IRX" IRX_SUFFIX, 0, NULL)) < 0)
+ sioprintf("Cannot load module: USB_MASS.IRX (%d)", res);
+ else
+ _usbMassLoaded = true;
+ }
+
+ if ((res = fileXioInit()) < 0) {
+ msgPrintf(FOREVER, "FXIO Init failed: %d", res);
+ quit();
}
- sioprintf("Modules: UsbMouse %sloaded, UsbKbd %sloaded.", _useMouse ? "" : "not ", _useKbd ? "" : "not ");
+
+ if ((res = SifLoadModule(IRX_PREFIX "PS2DEV9.IRX" IRX_SUFFIX, 0, NULL)) < 0)
+ sioprintf("Cannot load module: PS2DEV9.IRX (%d)", res);
+ else if ((res = SifLoadModule(IRX_PREFIX "PS2ATAD.IRX" IRX_SUFFIX, 0, NULL)) < 0)
+ sioprintf("Cannot load module: PS2ATAD.IRX (%d)", res);
+ else if ((res = SifLoadModule(IRX_PREFIX "PS2HDD.IRX" IRX_SUFFIX, sizeof(hddarg), hddarg)) < 0)
+ sioprintf("Cannot load module: PS2HDD.IRX (%d)", res);
+ else if ((res = SifLoadModule(IRX_PREFIX "PS2FS.IRX" IRX_SUFFIX, sizeof(pfsarg), pfsarg)) < 0)
+ sioprintf("Cannot load module: PS2FS.IRX (%d)", res);
+ else {
+ if ((res = SifLoadModule(IRX_PREFIX "POWEROFF.IRX" IRX_SUFFIX, 0, NULL)) < 0)
+ sioprintf("Cannot load module: POWEROFF.IRX (%d)", res);
+ if ((hddCheckPresent() >= 0) && (hddCheckFormatted() >= 0))
+ _useHdd = true;
+ }
+
+ sioprintf("Modules: UsbMouse %sloaded, UsbKbd %sloaded, UsbMass %sloaded, HDD %sloaded.", _useMouse ? "" : "not ", _useKbd ? "" : "not ", _usbMassLoaded ? "" : "not ", _useHdd ? "" : "not ");
+#endif
+}
+
+bool OSystem_PS2::hddPresent(void) {
+ return _useHdd;
+}
+
+void OSystem_PS2::setUsbMassConnected(bool stat) {
+ _usbMassConnected = stat;
+}
+
+bool OSystem_PS2::usbMassPresent(void) {
+ return _usbMassConnected;
}
void OSystem_PS2::initSize(uint width, uint height) {
@@ -492,7 +629,6 @@ bool OSystem_PS2::setSoundCallback(SoundProc proc, void *param) {
WaitSema(_soundSema);
_scummSoundProc = proc;
_scummSoundParam = param;
- SjPCM_Play();
SignalSema(_soundSema);
return true;
}
@@ -501,7 +637,6 @@ void OSystem_PS2::clearSoundCallback(void) {
WaitSema(_soundSema);
_scummSoundProc = NULL;
_scummSoundParam = NULL;
- SjPCM_Pause();
SignalSema(_soundSema);
}
@@ -509,91 +644,6 @@ Common::SaveFileManager *OSystem_PS2::getSavefileManager(void) {
return _saveManager;
}
-#ifndef _REC_MUTEX_
-OSystem::MutexRef OSystem_PS2::createMutex(void) {
- ee_sema_t newSema;
- newSema.init_count = 1;
- newSema.max_count = 1;
- int resSema = CreateSema(&newSema);
- if (resSema < 0)
- printf("createMutex: unable to create Semaphore.\n");
- return (MutexRef)resSema;
-}
-
-void OSystem_PS2::lockMutex(MutexRef mutex) {
- WaitSema((int)mutex);
-}
-
-void OSystem_PS2::unlockMutex(MutexRef mutex) {
- SignalSema((int)mutex);
-}
-
-void OSystem_PS2::deleteMutex(MutexRef mutex) {
- DeleteSema((int)mutex);
-}
-#else
-OSystem::MutexRef OSystem_PS2::createMutex(void) {
- WaitSema(_mutexSema);
- Ps2Mutex *mutex = NULL;
- for (int i = 0; i < MAX_MUTEXES; i++)
- if (_mutex[i].sema < 0) {
- mutex = _mutex + i;
- break;
- }
- if (mutex) {
- ee_sema_t newSema;
- newSema.init_count = 1;
- newSema.max_count = 1;
- mutex->sema = CreateSema(&newSema);
- mutex->owner = mutex->count = 0;
- } else
- printf("OSystem_PS2::createMutex: ran out of Mutex slots!\n");
- SignalSema(_mutexSema);
- return (OSystem::MutexRef)mutex;
-}
-
-void OSystem_PS2::lockMutex(MutexRef mutex) {
- WaitSema(_mutexSema);
- Ps2Mutex *sysMutex = (Ps2Mutex*)mutex;
- int tid = GetThreadId();
- assert(tid != 0);
- if (sysMutex->owner && (sysMutex->owner == tid))
- sysMutex->count++;
- else {
- SignalSema(_mutexSema);
- WaitSema(sysMutex->sema);
- WaitSema(_mutexSema);
- sysMutex->owner = tid;
- sysMutex->count = 0;
- }
- SignalSema(_mutexSema);
-}
-
-void OSystem_PS2::unlockMutex(MutexRef mutex) {
- WaitSema(_mutexSema);
- Ps2Mutex *sysMutex = (Ps2Mutex*)mutex;
- int tid = GetThreadId();
- if (sysMutex->owner && sysMutex->count && (sysMutex->owner == tid))
- sysMutex->count--;
- else {
- assert(sysMutex->count == 0);
- SignalSema(sysMutex->sema);
- sysMutex->owner = 0;
- }
- SignalSema(_mutexSema);
-}
-
-void OSystem_PS2::deleteMutex(MutexRef mutex) {
- WaitSema(_mutexSema);
- Ps2Mutex *sysMutex = (Ps2Mutex*)mutex;
- if (sysMutex->owner || sysMutex->count)
- printf("WARNING: Deleting LOCKED mutex!\n");
- DeleteSema(sysMutex->sema);
- sysMutex->sema = -1;
- SignalSema(_mutexSema);
-}
-#endif
-
void OSystem_PS2::setShakePos(int shakeOffset) {
_screen->setShakePos(shakeOffset);
}
@@ -614,6 +664,23 @@ void OSystem_PS2::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x,
_screen->setMouseOverlay(buf, w, h, hotspot_x, hotspot_y, keycolor);
}
+bool OSystem_PS2::openCD(int drive) {
+ return false;
+}
+
+bool OSystem_PS2::pollCD(void) {
+ return false;
+}
+
+void OSystem_PS2::playCD(int track, int num_loops, int start_frame, int duration) {
+}
+
+void OSystem_PS2::stopCD(void) {
+}
+
+void OSystem_PS2::updateCD(void) {
+}
+
void OSystem_PS2::showOverlay(void) {
_screen->showOverlay();
}
@@ -726,8 +793,29 @@ void OSystem_PS2::msgPrintf(int millis, char *format, ...) {
_msgClearTime = millis + getMillis();
}
+void OSystem_PS2::powerOffCallback(void) {
+ sioprintf("powerOffCallback");
+ _saveManager->quit();
+ if (_useHdd) {
+ sioprintf("umount");
+ fio.umount("pfs0:");
+ }
+ sioprintf("fxio");
+ // enable blocking FXIO so libhdd will correctly close drive, etc.
+ fileXioSetBlockMode(FXIO_WAIT);
+ sioprintf("done");
+}
+
void OSystem_PS2::quit(void) {
+#ifdef USE_PS2LINK
+ printf("OSystem_PS2::quit\n");
+ SleepThread();
+#endif
sioprintf("OSystem_PS2::quit");
+ if (_useHdd) {
+ driveStandby();
+ fio.umount("pfs0:");
+ }
clearSoundCallback();
setTimerCallback(NULL, 0);
_screen->wantAnim(false);
@@ -749,108 +837,31 @@ void OSystem_PS2::quit(void) {
padEnd(); // stop pad library
cdvdInit(CDVD_EXIT);
+ sioprintf("resetting iop");
+ SifIopReset(NULL, 0);
+ SifExitRpc();
+ while (!SifIopSync());
+ SifInitRpc(0);
cdvdExit();
- SifExitIopHeap();
- SifLoadFileExit();
SifExitRpc();
+ FlushCache(0);
+ SifLoadFileExit();
+ sioprintf("Restarting ScummVM");
LoadExecPS2("cdrom0:\\SCUMMVM.ELF", 0, NULL); // resets the console and executes the ELF
}
-static uint32 g_timeSecs;
-static int g_day, g_month, g_year;
-static uint32 g_lastTimeCheck;
-
-void buildNewDate(int dayDiff) {
- static int daysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (((g_year % 4) == 0) && (((g_year % 100) != 0) || ((g_year % 1000) == 0)))
- daysPerMonth[1] = 29;
- else
- daysPerMonth[1] = 28;
-
- if (dayDiff == -1) {
- g_day--;
- if (g_day == 0) {
- g_month--;
- if (g_month == 0) {
- g_year--;
- g_month = 12;
- }
- g_day = daysPerMonth[g_month - 1];
- }
- } else if (dayDiff == 1) {
- g_day++;
- if (g_day > daysPerMonth[g_month - 1]) {
- g_day = 1;
- g_month++;
- if (g_month > 12) {
- g_month = 1;
- g_year++;
- }
- }
- }
-}
-
-#define SECONDS_PER_DAY (24 * 60 * 60)
-
-void OSystem_PS2::readRtcTime(void) {
- struct CdClock cdClock;
- CDVD_ReadClock(&cdClock);
- g_lastTimeCheck = msecCount;
-
- if (cdClock.stat) {
- msgPrintf(5000, "Unable to read RTC time, EC: %d\n", cdClock.stat);
- g_day = g_month = 1;
- g_year = 0;
- g_timeSecs = 0;
- } else {
- int gmtOfs = configGetTimezone();
- if (configIsDaylightSavingEnabled())
- gmtOfs += 60;
-
- int timeSecs = (FROM_BCD(cdClock.hour) * 60 + FROM_BCD(cdClock.minute)) * 60 + FROM_BCD(cdClock.second);
- timeSecs -= 9 * 60 * 60; // minus 9 hours, JST -> GMT conversion
- timeSecs += gmtOfs * 60; // GMT -> timezone the user selected
-
- g_day = FROM_BCD(cdClock.day);
- g_month = FROM_BCD(cdClock.month);
- g_year = FROM_BCD(cdClock.year);
-
- if (timeSecs < 0) {
- buildNewDate(-1);
- timeSecs += SECONDS_PER_DAY;
- } else if (timeSecs >= SECONDS_PER_DAY) {
- buildNewDate(+1);
- timeSecs -= SECONDS_PER_DAY;
- }
- g_timeSecs = (uint32)timeSecs;
+void OSystem_PS2::makeConfigPath(char *dest) {
+ FILE *handle;
+ strcpy(dest, "cdfs:/ScummVM.ini");
+ handle = ps2_fopen(dest, "r");
+ if (_usbMassConnected && !handle) {
+ strcpy(dest, "mass:/ScummVM.ini");
+ handle = ps2_fopen(dest, "r");
}
-
- sioprintf("Time: %d:%02d:%02d - %d.%d.%4d", g_timeSecs / (60 * 60), (g_timeSecs / 60) % 60, g_timeSecs % 60,
- g_day, g_month, g_year + 2000);
-}
-
-extern time_t time(time_t *p) {
- return (time_t)g_timeSecs;
+ if (handle)
+ ps2_fclose(handle);
+ else
+ strcpy(dest, "mc0:ScummVM/scummvm.ini");
}
-extern struct tm *localtime(const time_t *p) {
- uint32 currentSecs = g_timeSecs + (msecCount - g_lastTimeCheck) / 1000;
- if (currentSecs >= SECONDS_PER_DAY) {
- buildNewDate(+1);
- g_lastTimeCheck += SECONDS_PER_DAY * 1000;
- currentSecs = g_timeSecs + (msecCount - g_lastTimeCheck) / 1000;
- }
-
- static struct tm retStruct;
- memset(&retStruct, 0, sizeof(retStruct));
-
- retStruct.tm_hour = currentSecs / (60 * 60);
- retStruct.tm_min = (currentSecs / 60) % 60;
- retStruct.tm_sec = currentSecs % 60;
- retStruct.tm_year = g_year + 100;
- retStruct.tm_mday = g_day;
- retStruct.tm_mon = g_month - 1;
- // tm_wday, tm_yday and tm_isdst are zero for now
- return &retStruct;
-}
diff --git a/backends/ps2/systemps2.h b/backends/ps2/systemps2.h
index e3de3e1a4e..acfefa3483 100644
--- a/backends/ps2/systemps2.h
+++ b/backends/ps2/systemps2.h
@@ -29,21 +29,21 @@
class Gs2dScreen;
class Ps2Input;
class Ps2SaveFileManager;
+struct IrxReference;
-#define _REC_MUTEX_
+extern void sioprintf(const char *zFormat, ...);
+
+#define MAX_MUTEXES 16
-#ifdef _REC_MUTEX_
-#define MAX_MUTEXES 32
struct Ps2Mutex {
int sema;
int owner;
int count;
};
-#endif
class OSystem_PS2 : public OSystem {
public:
- OSystem_PS2(void);
+ OSystem_PS2(const char *elfPath);
virtual ~OSystem_PS2(void);
virtual void initSize(uint width, uint height);
@@ -76,6 +76,12 @@ public:
virtual void clearSoundCallback();
virtual int getOutputSampleRate(void) const;
+ virtual bool openCD(int drive);
+ virtual bool pollCD();
+ virtual void playCD(int track, int num_loops, int start_frame, int duration);
+ virtual void stopCD();
+ virtual void updateCD();
+
virtual MutexRef createMutex(void);
virtual void lockMutex(MutexRef mutex);
virtual void unlockMutex(MutexRef mutex);
@@ -97,8 +103,16 @@ public:
void timerThread(void);
void soundThread(void);
void msgPrintf(int millis, char *format, ...);
+ void makeConfigPath(char *dest);
+
+ void powerOffCallback(void);
+ bool hddPresent(void);
+ bool usbMassPresent(void);
+ void setUsbMassConnected(bool stat);
private:
+ void startIrxModules(int numModules, IrxReference *modules);
+
volatile OSystem::TimerProc _scummTimerProc;
volatile OSystem::SoundProc _scummSoundProc;
void *_scummSoundParam;
@@ -109,7 +123,7 @@ private:
void loadModules(void);
bool _mouseVisible;
- bool _useMouse, _useKbd;
+ bool _useMouse, _useKbd, _useHdd, _usbMassLoaded, _usbMassConnected;
Ps2SaveFileManager *_saveManager;
@@ -118,15 +132,17 @@ private:
uint16 _oldMouseX, _oldMouseY;
uint32 _msgClearTime;
uint16 _printY;
-#ifdef _REC_MUTEX_
+
int _mutexSema;
- Ps2Mutex *_mutex;
-#endif
+ Ps2Mutex _mutex[MAX_MUTEXES];
+
uint8 *_timerStack, *_soundStack;
int _timerTid, _soundTid;
int _intrId;
volatile bool _systemQuit;
static const GraphicsMode _graphicsMode;
+
+ int _bootDevice;
};
#endif // SYSTEMPS2_H