diff options
| author | Robert Göffringmann | 2008-03-03 00:41:59 +0000 |
|---|---|---|
| committer | Robert Göffringmann | 2008-03-03 00:41:59 +0000 |
| commit | 3b27b9fa438611c3a05fcf2d07a3dfde6be192fa (patch) | |
| tree | 8605c47d67b779fb33ce4dda3a64a7d3caecdb4d /backends/platform/ps2/systemps2.cpp | |
| parent | fc91de07dfdfe6bd29edadf739f324f30f5624d0 (diff) | |
| download | scummvm-rg350-3b27b9fa438611c3a05fcf2d07a3dfde6be192fa.tar.gz scummvm-rg350-3b27b9fa438611c3a05fcf2d07a3dfde6be192fa.tar.bz2 scummvm-rg350-3b27b9fa438611c3a05fcf2d07a3dfde6be192fa.zip | |
the ps2 changes from the 0.11.1 release, plus some bugfixes and cleanup.
svn-id: r31034
Diffstat (limited to 'backends/platform/ps2/systemps2.cpp')
| -rw-r--r-- | backends/platform/ps2/systemps2.cpp | 316 |
1 files changed, 144 insertions, 172 deletions
diff --git a/backends/platform/ps2/systemps2.cpp b/backends/platform/ps2/systemps2.cpp index 384ec1f935..b2818ebfc0 100644 --- a/backends/platform/ps2/systemps2.cpp +++ b/backends/platform/ps2/systemps2.cpp @@ -34,7 +34,6 @@ #include <iopcontrol.h> #include <iopheap.h> #include "common/scummsys.h" -#include "../intern.h" #include "engines/engine.h" #include "backends/platform/ps2/systemps2.h" #include "backends/platform/ps2/Gs2dScreen.h" @@ -42,19 +41,22 @@ #include "backends/platform/ps2/irxboot.h" #include <sjpcm.h> #include <libhdd.h> -#include "backends/platform/ps2/savefile.h" +#include "backends/platform/ps2/savefilemgr.h" #include "common/file.h" #include "backends/platform/ps2/sysdefs.h" +#include "backends/platform/ps2/fileio.h" #include <libmc.h> #include <libpad.h> #include "backends/platform/ps2/cd.h" -#include <sio.h> #include <fileXio_rpc.h> #include "backends/platform/ps2/asyncfio.h" #include "eecodyvdfs.h" #include "graphics/surface.h" #include "graphics/font.h" - +#include "backends/timer/default/default-timer.h" +#include "sound/mixer.h" +#include "common/events.h" +#include "backends/platform/ps2/ps2debug.h" // asm("mfc0 %0, $9\n" : "=r"(tickStart)); extern void *_gp; @@ -82,17 +84,6 @@ namespace Graphics { extern AsyncFio fio; -void sioprintf(const char *zFormat, ...) { - va_list ap; - char resStr[2048]; - - va_start(ap,zFormat); - vsnprintf(resStr, 2048, zFormat, ap); - va_end(ap); - - sio_puts(resStr); -} - extern "C" int scummvm_main(int argc, char *argv[]); extern "C" int main(int argc, char *argv[]) { @@ -110,16 +101,24 @@ extern "C" int main(int argc, char *argv[]) { Don't know about NapLink, etc. The priority doesn't matter too much, but we need to be at least at prio 3, so we can have the timer thread run at prio 2 and the sound thread at prio 1 */ - sioprintf("Changing thread priority"); + sioprintf("Changing thread priority\n"); int res = ChangeThreadPriority(tid, 20); - sioprintf("Result = %d", res); + sioprintf("Result = %d\n", res); } - sioprintf("Creating system"); + sioprintf("Creating system\n"); g_system = g_systemPs2 = new OSystem_PS2(argv[0]); - sioprintf("init done. starting ScummVM."); - return scummvm_main(argc, argv); + g_systemPs2->init(); + + sioprintf("init done. starting ScummVM.\n"); + int res = scummvm_main(argc, argv); + sioprintf("scummvm_main terminated: %d\n", res); + + g_systemPs2->quit(); + + // control never gets here + return res; } s32 timerInterruptHandler(s32 cause) { @@ -158,14 +157,6 @@ 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; @@ -174,7 +165,7 @@ void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) { 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); + sioprintf("Module \"%s\": %d\n", modules[i].path, res); if (res < 0) { msgPrintf(FOREVER, "\"%s\"\nnot found: %d", modules[i].path, res); delayMillis(5000); @@ -183,7 +174,7 @@ void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) { } 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); + sioprintf("Module \"%s\": EE=%d, IOP=%d\n", modules[i].path, res, rv); if ((res >= 0) && (rv >= 0)) { switch (modules[i].fileRef->purpose) { case MASS_DRIVER: @@ -203,8 +194,8 @@ void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) { } } } else - sioprintf("Module \"%s\" wasn't found: %d", modules[i].path, modules[i].errorCode); - + sioprintf("Module \"%s\" wasn't found: %d\n", 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) @@ -215,36 +206,31 @@ void OSystem_PS2::startIrxModules(int numModules, IrxReference *modules) { quit(); } } - - if (modules[i].buffer); + + 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); + sioprintf("module %d of %d damaged, loc %d, path %s\n", 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 "); + sioprintf("done\n"); + sioprintf("UsbMass: %sloaded\n", _usbMassLoaded ? "" : "not "); + sioprintf("Mouse: %sloaded\n", _useMouse ? "" : "not "); + sioprintf("Kbd: %sloaded\n", _useKbd ? "" : "not "); + sioprintf("Hdd: %sloaded\n", _useHdd ? "" : "not "); } OSystem_PS2::OSystem_PS2(const char *elfPath) { _soundStack = _timerStack = NULL; - _scummTimerProc = NULL; - _scummSoundProc = NULL; - _scummSoundParam = NULL; _printY = 0; _msgClearTime = 0; _systemQuit = false; - _usbMassConnected = false; _screen = new Gs2dScreen(320, 200, TV_DONT_CARE); - sioprintf("Initializing system..."); - initTimer(); + sioprintf("Initializing system...\n"); _screen->wantAnim(true); @@ -255,7 +241,7 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) { int numModules = loadIrxModules(_bootDevice, irxPath, &modules); if (_bootDevice != HOST) { - sio_puts("Resetting IOP."); + sioprintf("Resetting IOP.\n"); cdvdInit(CDVD_EXIT); cdvdExit(); SifExitIopHeap(); @@ -264,7 +250,7 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) { SifIopReset("rom0:UDNL rom0:EELOADCNF", 0); while (!SifIopSync()) ; - sio_puts("IOP synced."); + sioprintf("IOP synced.\n"); SifInitRpc(0); SifLoadFileInit(); cdvdInit(CDVD_INIT_WAIT); @@ -291,54 +277,54 @@ OSystem_PS2::OSystem_PS2(const char *elfPath) { if ((hddCheckPresent() < 0) || (hddCheckFormatted() < 0)) _useHdd = false; + dbg_printf("romeo : hddCheckPresent done : %d\n", _useHdd); + hddPreparePoweroff(); + //poweroffInit(); + dbg_printf("romeo : hddPreparePoweroff done\n"); + hddSetUserPoweroffCallback(gluePowerOffCallback, this); + //poweroffSetCallback(gluePowerOffCallback, this); + dbg_printf("romeo : hddSetUserPoweroffCallback done\n"); } fileXioSetBlockMode(FXIO_NOWAIT); _mouseVisible = false; - sioprintf("reading RTC"); + sioprintf("reading RTC\n"); readRtcTime(); if (_useHdd) { + printf("romeo : trying to mount...\n"); if (fio.mount("pfs0:", "hdd0:+ScummVM", 0) >= 0) printf("Successfully mounted!\n"); else _useHdd = false; } - sioprintf("Starting SavefileManager"); + initMutexes(); +} + +void OSystem_PS2::init(void) { + sioprintf("Timer...\n"); + _scummTimerManager = new DefaultTimerManager(); + _scummMixer = new Audio::Mixer(); + initTimer(); + + sioprintf("Starting SavefileManager\n"); _saveManager = new Ps2SaveFileManager(this, _screen); - sioprintf("Initializing ps2Input"); + sioprintf("Initializing ps2Input\n"); _input = new Ps2Input(this, _useMouse, _useKbd); - ee_sema_t newSema; - newSema.init_count = 1; - newSema.max_count = 1; - _mutexSema = CreateSema(&newSema); - for (int i = 0; i < MAX_MUTEXES; i++) { - _mutex[i].sema = -1; - _mutex[i].count = _mutex[i].owner = 0; - } - _screen->wantAnim(false); - clearScreen(); -} + _screen->clearScreen(); -OSystem_PS2::~OSystem_PS2(void) { + // OSystem::initBackend(); // romeo } -void OSystem_PS2::initBackend() { - // FIXME: Should probably move lots of stuff from the constructor to here - _mixer = new Audio::Mixer(); - _timer = new DefaultTimerManager(); - setSoundCallback(Audio::Mixer::mixCallback, _mixer); - setTimerCallback(&timer_handler, 10); - - OSystem::initBackend(); +OSystem_PS2::~OSystem_PS2(void) { } void OSystem_PS2::initTimer(void) { @@ -394,28 +380,17 @@ 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) { while (!_systemQuit) { WaitSema(g_TimerThreadSema); - if (_scummTimerProc) - _scummTimerProc(0); + _scummTimerManager->handler(); } ExitThread(); } void OSystem_PS2::soundThread(void) { - ee_sema_t soundSema; - soundSema.init_count = 1; - 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; @@ -431,55 +406,51 @@ void OSystem_PS2::soundThread(void) { bufferedSamples -= 480; cycles++; - WaitSema(_soundSema); - if (_scummSoundProc) { - 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)); - - // demux data into 2 buffers, L and R - __asm__ ( - "move $t2, %1\n\t" // dest buffer right - "move $t3, %0\n\t" // dest buffer left - "lui $t8, 0x7000\n\t" // muxed buffer, fixed at 0x70000000 - "addiu $t9, $0, 100\n\t" // number of loops - "mtsab $0, 2\n\t" // set qword shift = 2 byte - - "loop:\n\t" - " lq $t4, 0($t8)\n\t" // load 8 muxed samples - " lq $t5, 16($t8)\n\t" // load 8 more muxed samples - - " qfsrv $t6, $0, $t4\n\t" // shift right for second - " qfsrv $t7, $0, $t5\n\t" // packing step (right channel) - - " ppach $t4, $t5, $t4\n\t" // combine left channel data - " ppach $t6, $t7, $t6\n\t" // right channel data - - " sq $t4, 0($t3)\n\t" // write back - " sq $t6, 0($t2)\n\t" // - - " addiu $t9, -1\n\t" // decrement loop counter - " addiu $t2, 16\n\t" // increment pointers - " addiu $t3, 16\n\t" - " addiu $t8, 32\n\t" - " bnez $t9, loop\n\t" // loop - : // outputs - : "r"(soundBufL), "r"(soundBufR) // inputs - // : "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", "$t9" // destroyed - : "$10", "$11", "$12", "$13", "$14", "$15", "$24", "$25" // destroyed - ); - // and feed it into the SPU - // non-blocking call, the function will return before the buffer's content - // was transferred. - SjPCM_Enqueue((short int*)soundBufL, (short int*)soundBufR, SMP_PER_BLOCK, 0); - bufferedSamples += 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)); + Audio::Mixer::mixCallback(_scummMixer, (byte*)0x70000000, SMP_PER_BLOCK * 2 * sizeof(int16)); + + // demux data into 2 buffers, L and R + __asm__ ( + "move $t2, %1\n\t" // dest buffer right + "move $t3, %0\n\t" // dest buffer left + "lui $t8, 0x7000\n\t" // muxed buffer, fixed at 0x70000000 + "addiu $t9, $0, 100\n\t" // number of loops + "mtsab $0, 2\n\t" // set qword shift = 2 byte + + "loop:\n\t" + " lq $t4, 0($t8)\n\t" // load 8 muxed samples + " lq $t5, 16($t8)\n\t" // load 8 more muxed samples + + " qfsrv $t6, $0, $t4\n\t" // shift right for second + " qfsrv $t7, $0, $t5\n\t" // packing step (right channel) + + " ppach $t4, $t5, $t4\n\t" // combine left channel data + " ppach $t6, $t7, $t6\n\t" // right channel data + + " sq $t4, 0($t3)\n\t" // write back + " sq $t6, 0($t2)\n\t" // + + " addiu $t9, -1\n\t" // decrement loop counter + " addiu $t2, 16\n\t" // increment pointers + " addiu $t3, 16\n\t" + " addiu $t8, 32\n\t" + " bnez $t9, loop\n\t" // loop + : // outputs + : "r"(soundBufL), "r"(soundBufR) // inputs + // : "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", "$t9" // destroyed + : "$10", "$11", "$12", "$13", "$14", "$15", "$24", "$25" // destroyed + ); + // and feed it into the SPU + // non-blocking call, the function will return before the buffer's content + // was transferred. + SjPCM_Enqueue((short int*)soundBufL, (short int*)soundBufR, SMP_PER_BLOCK, 0); + bufferedSamples += SMP_PER_BLOCK; } - SignalSema(_soundSema); } free(soundBufL); - DeleteSema(_soundSema); ExitThread(); } @@ -487,12 +458,16 @@ bool OSystem_PS2::hddPresent(void) { return _useHdd; } -void OSystem_PS2::setUsbMassConnected(bool stat) { - _usbMassConnected = stat; -} - bool OSystem_PS2::usbMassPresent(void) { - return _usbMassConnected; + + if (_usbMassLoaded) { + int testFd = fio.dopen("mass:/"); + if (testFd >= 0) + fio.dclose(testFd); + if (testFd != -ENODEV) + return true; + } + return false; } void OSystem_PS2::initSize(uint width, uint height) { @@ -519,12 +494,9 @@ void OSystem_PS2::copyRectToScreen(const byte *buf, int pitch, int x, int y, int _screen->copyScreenRect((const uint8*)buf, pitch, x, y, w, h); } -Graphics::Surface *OSystem_PS2::lockScreen() { - return _screen->lockScreen(); -} - -void OSystem_PS2::unlockScreen() { - _screen->unlockScreen(); +bool OSystem_PS2::grabRawScreen(Graphics::Surface *surf) { + _screen->grabScreen(surf); + return true; } void OSystem_PS2::updateScreen(void) { @@ -545,7 +517,7 @@ void OSystem_PS2::delayMillis(uint msecs) { int tid = GetThreadId(); if (tid == _soundTid) { - sioprintf("ERROR: delayMillis() from sound thread!"); + dbg_printf("ERROR: delayMillis() from sound thread!\n"); return; } @@ -558,31 +530,16 @@ void OSystem_PS2::delayMillis(uint msecs) { } } -void OSystem_PS2::setTimerCallback(OSystem::TimerProc callback, int interval) { - if (callback && (interval != 10)) - sioprintf("unhandled timer interval: %d\n", interval); - _scummTimerProc = callback; +Common::TimerManager *OSystem_PS2::getTimerManager() { + return _scummTimerManager; } int OSystem_PS2::getOutputSampleRate(void) const { return 48000; } -bool OSystem_PS2::setSoundCallback(SoundProc proc, void *param) { - assert(proc != NULL); - - WaitSema(_soundSema); - _scummSoundProc = proc; - _scummSoundParam = param; - SignalSema(_soundSema); - return true; -} - -void OSystem_PS2::clearSoundCallback(void) { - WaitSema(_soundSema); - _scummSoundProc = NULL; - _scummSoundParam = NULL; - SignalSema(_soundSema); +Audio::Mixer *OSystem_PS2::getMixer() { + return _scummMixer; } Common::SaveFileManager *OSystem_PS2::getSavefileManager(void) { @@ -646,6 +603,14 @@ void OSystem_PS2::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, i _screen->copyOverlayRect((uint16*)buf, (uint16)pitch, (uint16)x, (uint16)y, (uint16)w, (uint16)h); } +Graphics::Surface *OSystem_PS2::lockScreen() { + return _screen->lockScreen(); +} + +void OSystem_PS2::unlockScreen() { + _screen->unlockScreen(); +} + const OSystem::GraphicsMode OSystem_PS2::_graphicsMode = { NULL, NULL, 0 }; const OSystem::GraphicsMode *OSystem_PS2::getSupportedGraphicsModes(void) const { @@ -710,7 +675,7 @@ void OSystem_PS2::msgPrintf(int millis, char *format, ...) { while ((*lnEnd) && (*lnEnd != '\n')) lnEnd++; *lnEnd = '\0'; - + Common::String str(lnSta); int width = Graphics::g_sysfont.getStringWidth(str); if (width > maxWidth) @@ -739,41 +704,45 @@ void OSystem_PS2::msgPrintf(int millis, char *format, ...) { } void OSystem_PS2::powerOffCallback(void) { - sioprintf("powerOffCallback"); + sioprintf("powerOffCallback\n"); _saveManager->quit(); if (_useHdd) { - sioprintf("umount"); + sioprintf("umount\n"); fio.umount("pfs0:"); } - sioprintf("fxio"); + sioprintf("fxio\n"); // enable blocking FXIO so libhdd will correctly close drive, etc. fileXioSetBlockMode(FXIO_WAIT); - sioprintf("done"); + sioprintf("done\n"); } void OSystem_PS2::quit(void) { + sioprintf("OSystem_PS2::quit called\n"); if (_bootDevice == HOST) { - printf("OSystem_PS2::quit\n"); + sioprintf("OSystem_PS2::quit (HOST)\n"); SleepThread(); } else { - sioprintf("OSystem_PS2::quit"); + sioprintf("OSystem_PS2::quit (bootdev=%d)\n", _bootDevice); if (_useHdd) { driveStandby(); fio.umount("pfs0:"); } - clearSoundCallback(); - setTimerCallback(NULL, 0); + //clearSoundCallback(); + //setTimerCallback(NULL, 0); _screen->wantAnim(false); _systemQuit = true; ee_thread_t statSound, statTimer; + sioprintf("Waiting for timer and sound thread to end\n"); do { // wait until both threads called ExitThread() ReferThreadStatus(_timerTid, &statTimer); ReferThreadStatus(_soundTid, &statSound); } while ((statSound.status != 0x10) || (statTimer.status != 0x10)); + sioprintf("Done\n"); DeleteThread(_timerTid); DeleteThread(_soundTid); free(_timerStack); free(_soundStack); + sioprintf("Stopping timer\n"); DisableIntc(INT_TIMER0); RemoveIntcHandler(INT_TIMER0, _intrId); @@ -782,7 +751,7 @@ void OSystem_PS2::quit(void) { padEnd(); // stop pad library cdvdInit(CDVD_EXIT); - sioprintf("resetting iop"); + sioprintf("resetting iop\n"); SifIopReset(NULL, 0); SifExitRpc(); while (!SifIopSync()); @@ -791,7 +760,7 @@ void OSystem_PS2::quit(void) { SifExitRpc(); FlushCache(0); SifLoadFileExit(); - sioprintf("Restarting ScummVM"); + sioprintf("Restarting ScummVM\n"); LoadExecPS2("cdrom0:\\SCUMMVM.ELF", 0, NULL); // resets the console and executes the ELF } } @@ -800,7 +769,7 @@ void OSystem_PS2::makeConfigPath(char *dest) { FILE *handle; strcpy(dest, "cdfs:/ScummVM.ini"); handle = ps2_fopen(dest, "r"); - if (_usbMassConnected && !handle) { + if (usbMassPresent() && !handle) { strcpy(dest, "mass:/ScummVM.ini"); handle = ps2_fopen(dest, "r"); } @@ -810,4 +779,7 @@ void OSystem_PS2::makeConfigPath(char *dest) { strcpy(dest, "mc0:ScummVM/scummvm.ini"); } +bool OSystem_PS2::runningFromHost(void) { + return (_bootDevice == HOST); +} |
