Пример #1
0
bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
	DEBUG_ENTER_FUNC();
	assert(_isDirectory);

	//TODO: honor the hidden flag

	bool ret = true;

	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
		PSP_DEBUG_PRINT_FUNC("Suspended\n");	// Make sure to block in case of suspend

	PSP_DEBUG_PRINT_FUNC("Current path[%s]\n", _path.c_str());

	int dfd  = sceIoDopen(_path.c_str());
	if (dfd > 0) {
		SceIoDirent dir;
		memset(&dir, 0, sizeof(dir));

		while (sceIoDread(dfd, &dir) > 0) {
			// Skip 'invisible files
			if (dir.d_name[0] == '.')
				continue;

			PSPFilesystemNode entry;

			entry._isValid = true;
			entry._displayName = dir.d_name;

			Common::String newPath(_path);
			if (newPath.lastChar() != '/')
				newPath += '/';
			newPath += dir.d_name;

			entry._path = newPath;
			entry._isDirectory = dir.d_stat.st_attr & FIO_SO_IFDIR;

			PSP_DEBUG_PRINT_FUNC("Child[%s], %s\n", entry._path.c_str(), entry._isDirectory ? "dir" : "file");

			// Honor the chosen mode
			if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) ||
			        (mode == Common::FSNode::kListDirectoriesOnly && !entry._isDirectory))
				continue;

			myList.push_back(new PSPFilesystemNode(entry));
		}

		sceIoDclose(dfd);
		ret = true;
	} else { // dfd <= 0
		ret = false;
	}

	PowerMan.endCriticalSection();

	return ret;
}
Пример #2
0
bool PSPFilesystemNode::exists() const {
	DEBUG_ENTER_FUNC();
	int ret = 0;

	if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
		PSP_DEBUG_PRINT_FUNC("Suspended\n");	// Make sure to block in case of suspend

	PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());

	ret = access(_path.c_str(), F_OK);
	PowerMan.endCriticalSection();

	return (ret == 0);
}
Пример #3
0
/* Function to open the file pointed to by the path.
 *
 */
void *PspIoStream::open() {
	DEBUG_ENTER_FUNC();

	if (PowerMan.beginCriticalSection()) {
		// No need to open? Just return the _handle resume() already opened
		PSP_DEBUG_PRINT_FUNC("suspended\n");
	}

	_handle = sceIoOpen(_path.c_str(), _writeMode ? PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC : PSP_O_RDONLY, 0777);
	if (!_handle) {
		_error = true;
		_handle = NULL;
	}

	// Get the file size. This way is much faster than going to the end of the file and back
	SceIoStat stat;
	sceIoGetstat(_path.c_str(), &stat);
	_fileSize = *((uint32 *)(void *)&stat.st_size);	// 4GB file (32 bits) is big enough for us

	PSP_DEBUG_PRINT("%s filesize[%d]\n", _path.c_str(), _fileSize);

	PowerMan.registerForSuspend(this);	 // Register with the powermanager to be suspended

	PowerMan.endCriticalSection();

	return (void *)_handle;
}
Пример #4
0
bool PspIoStream::seek(int32 offs, int whence) {
	DEBUG_ENTER_FUNC();
	PSP_DEBUG_PRINT_FUNC("offset[0x%x], whence[%d], _pos[0x%x], _physPos[0x%x]\n", offs, whence, _pos, _physicalPos);
	_eos = false;

	int32 posToSearchFor = 0;
	switch (whence) {
	case SEEK_CUR:
		posToSearchFor = _pos;
		break;
	case SEEK_END:
		posToSearchFor = _fileSize;
		break;
	}
	posToSearchFor += offs;

	// Check for bad values
	if (posToSearchFor < 0) {
		_error = true;
		return false;
	} else if (posToSearchFor > _fileSize) {
		_error = true;
		_eos = true;
		return false;
	}

	_pos = posToSearchFor;

	return true;
}
Пример #5
0
// The real thread function
void PspAudio::threadFunction() {
	assert(_callback);
	PSP_DEBUG_PRINT_FUNC("audio thread started\n");

	while (_init) {		// Keep looping so long as we haven't been told to stop
		if (_paused)
			PSP_DEBUG_PRINT("audio thread paused\n");
		while (_paused) {	// delay until we stop pausing
			PspThread::delayMicros(100000);	// 100ms
			if (!_paused)
				PSP_DEBUG_PRINT("audio thread unpaused\n");
		}

		PSP_DEBUG_PRINT("remaining samples[%d]\n", _remainingSamples);

		PSP_DEBUG_PRINT("filling buffer[%d]\n", _bufferToFill);
		_callback(_userData, _buffers[_bufferToFill], _bufferSize); // ask mixer to fill in data
		nextBuffer(_bufferToFill);

		PSP_DEBUG_PRINT("playing buffer[%d].\n", _bufferToPlay);
		playBuffer();
		nextBuffer(_bufferToPlay);
	} // while _init

	// destroy everything
	free(_buffers[0]);
	sceAudioChRelease(_pspChannel);
	PSP_DEBUG_PRINT("audio thread exiting. ****************************\n");
}
Пример #6
0
PSPFilesystemNode::PSPFilesystemNode(const Common::String &p, bool verify) {
	DEBUG_ENTER_FUNC();
	assert(p.size() > 0);

	_path = p;
	_displayName = lastPathComponent(_path, '/');
	_isValid = true;
	_isDirectory = true;

	PSP_DEBUG_PRINT_FUNC("path [%s]\n", _path.c_str());

	if (verify) {
		struct stat st;
		if (PowerMan.beginCriticalSection() == PowerManager::Blocked)
			PSP_DEBUG_PRINT_FUNC("Suspended\n");
		_isValid = (0 == stat(_path.c_str(), &st));
		PowerMan.endCriticalSection();
		_isDirectory = S_ISDIR(st.st_mode);
	}
}
Пример #7
0
PspIoStream::~PspIoStream() {
	DEBUG_ENTER_FUNC();

	if (PowerMan.beginCriticalSection())
		PSP_DEBUG_PRINT_FUNC("suspended\n");

	PowerMan.unregisterForSuspend(this); 			// Unregister with powermanager to be suspended
													// Must do this before fclose() or resume() will reopen.
	sceIoClose(_handle);

	PowerMan.endCriticalSection();
}
Пример #8
0
uint32 PspIoStream::read(void *ptr, uint32 len) {
	DEBUG_ENTER_FUNC();
	PSP_DEBUG_PRINT_FUNC("filename[%s], len[0x%x], ptr[%p], _pos[%x], _physPos[%x]\n", _path.c_str(), len, ptr, _pos, _physicalPos);

	if (_error || _eos || len <= 0)
		return 0;

	uint32 lenRemainingInFile = _fileSize - _pos;

	// check for getting EOS
	if (len > lenRemainingInFile) {
		len = lenRemainingInFile;
		_eos = true;
	}

	if (PowerMan.beginCriticalSection())
		PSP_DEBUG_PRINT_FUNC("suspended\n");

	// check if we need to seek
	if (_pos != _physicalPos)
		PSP_DEBUG_PRINT("seeking from %x to %x\n", _physicalPos, _pos);
		if (!physicalSeekFromCur(_pos - _physicalPos)) {
			_error = true;
			return 0;
		}

	int ret = sceIoRead(_handle, ptr, len);

	PowerMan.endCriticalSection();

	_physicalPos += ret;	// Update position
	_pos = _physicalPos;

	if (ret != (int)len) {	// error
		PSP_ERROR("sceIoRead returned [0x%x] instead of len[0x%x]\n", ret, len);
		_error = true;
		_errorSource = 4;
	}
	return ret;
}
Пример #9
0
AbstractFSNode *PSPFilesystemNode::getParent() const {
	DEBUG_ENTER_FUNC();
	if (_path == ROOT_PATH)
		return 0;

	PSP_DEBUG_PRINT_FUNC("current[%s]\n", _path.c_str());

	const char *start = _path.c_str();
	const char *end = lastPathComponent(_path, '/');

	AbstractFSNode *node = new PSPFilesystemNode(Common::String(start, end - start), false);

	return node;
}
Пример #10
0
uint32 PspIoStream::write(const void *ptr, uint32 len) {
	DEBUG_ENTER_FUNC();
	PSP_DEBUG_PRINT_FUNC("filename[%s], len[0x%x], ptr[%p], _pos[%x], _physPos[%x]\n", _path.c_str(), len, ptr, _pos, _physicalPos);

	if (!len || _error)		// we actually get some calls with len == 0!
		return 0;

	_eos = false;			// we can't have eos with write

	if (PowerMan.beginCriticalSection())
		PSP_DEBUG_PRINT_FUNC("suspended\n");

	// check if we need to seek
	if (_pos != _physicalPos)
		if (!physicalSeekFromCur(_pos - _physicalPos)) {
			_error = true;
			return 0;
		}

	int ret = sceIoWrite(_handle, ptr, len);

	PowerMan.endCriticalSection();

	if (ret != (int)len) {
		_error = true;
		_errorSource = 5;
		PSP_ERROR("sceIoWrite returned[0x%x] instead of len[0x%x]\n", ret, len);
	}

	_physicalPos += ret;
	_pos = _physicalPos;

	if (_pos > _fileSize)
		_fileSize = _pos;

	return ret;
}
Пример #11
0
AbstractFSNode *PSPFilesystemNode::getChild(const Common::String &n) const {
	DEBUG_ENTER_FUNC();
	// FIXME: Pretty lame implementation! We do no error checking to speak
	// of, do not check if this is a special node, etc.
	assert(_isDirectory);

	Common::String newPath(_path);
	if (_path.lastChar() != '/')
		newPath += '/';
	newPath += n;

	PSP_DEBUG_PRINT_FUNC("child [%s]\n", newPath.c_str());

	AbstractFSNode *node = new PSPFilesystemNode(newPath, true);

	return node;
}