Example #1
0
static void loadSaveDatafromVmu(unsigned int id)
{
	char path[16];
	unsigned char buf[MAX_VM_SIZE];
	int size = MAX_VM_SIZE;
	int res;
	const char *load_title = "Select a VMU to load from";
  
	sprintf(path, "%x", id);
  
	ZeroMemory(buf, sizeof(buf));

	int files = vm_SearchFile(path, &res);

	if (!files) {
		return;
	}

	if (files == 1 && load_from_vmu(res, path, buf, &size)) {

		loadSaveData(id, buf);
    
		checked_vm  = res;
		return;
	}
  
	for (;;) {
    
		if (!vmu_select(&res, load_title))
			return;

		if (!load_from_vmu(res, path, buf, &size)) {

			_debug("Failed!");
		} else {

			loadSaveData(id, buf);

			checked_vm  = res;
			return;
		}
	}
}
Example #2
0
VMFILE *vm_fileopen(const char *fname, const char *mode)
{
	VMFILE *ret;
	int size = 0;
	int cnt = 0;
	int vm = 0;
	int i;

	for (i=0; i<MAX_FILES; i++)
		if(fh[i].used == 0)
			break;
	
	if (i>=MAX_FILES)
		return NULL;

	fh[i].used = 1;
	memset(fh[i]._buffer, 0, MAX_SIZE);
	char *_buffer = fh[i]._buffer;

	if (!strncmp(mode, "rb", 2)) {

		if (!vmfile_search(fname, &vm)) {
#ifndef NOSERIAL
			printf("Can't open %s", fname);
#endif

			goto _exit;
		}
		if (!load_from_vmu(vm, fname, _buffer, &size)) {
#ifndef NOSERIAL
			printf("load failed rb %s", fname);
#endif

			goto _exit;
		}

	} else if (!strncmp(mode, "wb", 2)) {

		if (!vmfile_search(fname, &vm)) {
#ifndef NOSERIAL
			printf("Create %s", fname);
#endif
		}

	} else if (!strncmp(mode, "r+", 2)) {

		if (!vmfile_search(fname, &vm)) {
#ifndef NOSERIAL
			printf("Can't open %s", fname);
#endif

			goto _exit;
		}

		if (!load_from_vmu(vm, fname, _buffer, &size)) {
			goto _exit;
		}
		
		cnt = size;

	} else {
#ifndef NOSERIAL
		fprintf(stderr,"vmu error");
#endif
		goto _exit;
	}

	ret = &fh[i]._iob;

	memset(ret->filename, 0, 32);
	strncpy(ret->filename, fname, 32);

	ret->_fd = i;
	ret->_base = _buffer;
	ret->_ptr = ret->_base;
	ret->_cnt = cnt;
	ret->_vm = vm;

	return ret;
_exit:
	fh[i].used = 0;
	return NULL;
}