Esempio n. 1
0
/////////////////////////////////////////////////////////////////////////////
//
// hefile emucall handler
//
sint32 EMU_CALL psx_emucall(
  void   *state,
  uint8  *ram_native,
  uint32  ram_size,
  sint32  type,
  sint32  emufd,
  sint32  ofs,
  sint32  arg1,
  sint32  arg2
) {
  if(type == 0) {
    if(PSXSTATE->console_callback) {
      sint32 i;
      for(i = 0; i < arg1; i++) {
        char c = ram_native[ofs & (ram_size-1)]; ofs++;
        if(c == 'H') { PSXSTATE->console_enable = 1; }
        if(PSXSTATE->console_enable) {
          (PSXSTATE->console_callback)(PSXSTATE->console_context, c);
        }
      }
    }
    return arg1;
  }
  if(!(HAVE_VFS)) return -5;
  switch(type) {
  case 3: return vopen (VFSSTATE, ram_native, ram_size, ofs);
  case 4: return vclose(VFSSTATE, emufd);
  case 5: return vread (VFSSTATE, ram_native, ram_size, emufd, ofs, arg1);
  case 6: return -13; // EACCES permission denied
  case 7: return vlseek(VFSSTATE, emufd, arg1, arg2);
  default: return -5;
  }
}
Esempio n. 2
0
/*
  read etc...
*/
void ivread()
{
    previous_obj = FALSE;
    if (here(BOOK))
	object = BOOK;
    if (here(BOOK2))
	addobj(BOOK2);
    if (here(BILLBD))
	addobj(BILLBD);
    if (here(CARVNG))
	addobj(CARVNG);
    if (here(MAGAZINE))
	addobj(MAGAZINE);
    if (here(MESSAGE))
	addobj(MESSAGE);
    if (here(OYSTER))
	addobj(OYSTER);
    if (here(POSTER))
	addobj(POSTER);
    if (here(TABLET))
	addobj(TABLET);

    if (previous_obj || object == 0 || dark())
	needobj();
    else
	vread();
    return;
}
Esempio n. 3
0
/*
 * This function reads the *virtual* memory as seen by the kernel.
 */
static ssize_t read_kmem(struct file *file, char *buf, 
			 size_t count, loff_t *ppos)
{
	unsigned long p = *ppos;
	ssize_t read = 0;
	ssize_t virtr = 0;
	char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
		
	if (p < (unsigned long) high_memory) {
		read = count;
		if (count > (unsigned long) high_memory - p)
			read = (unsigned long) high_memory - p;

#if defined(__sparc__) || defined(__mc68000__)
		/* we don't have page 0 mapped on sparc and m68k.. */
		if (p < PAGE_SIZE && read > 0) {
			size_t tmp = PAGE_SIZE - p;
			if (tmp > read) tmp = read;
			if (clear_user(buf, tmp))
				return -EFAULT;
			buf += tmp;
			p += tmp;
			read -= tmp;
			count -= tmp;
		}
#endif
		if (copy_to_user(buf, (char *)p, read))
			return -EFAULT;
		p += read;
		buf += read;
		count -= read;
	}

	if (count > 0) {
		kbuf = (char *)__get_free_page(GFP_KERNEL);
		if (!kbuf)
			return -ENOMEM;
		while (count > 0) {
			int len = count;

			if (len > PAGE_SIZE)
				len = PAGE_SIZE;
			len = vread(kbuf, (char *)p, len);
			if (!len)
				break;
			if (copy_to_user(buf, kbuf, len)) {
				free_page((unsigned long)kbuf);
				return -EFAULT;
			}
			count -= len;
			buf += len;
			virtr += len;
			p += len;
		}
		free_page((unsigned long)kbuf);
	}
 	*ppos = p;
 	return virtr + read;
}
Esempio n. 4
0
static int read_kmem(struct inode *inode, struct file *file, char *buf, int count)
{
	int read1, read2;

	read1 = read_mem(inode, file, buf, count);
	if (read1 < 0)
		return read1;
	read2 = vread(buf + read1, (char *) file->f_pos, count - read1);
	if (read2 < 0)
		return read2;
	file->f_pos += read2;
	return read1 + read2;
}
Esempio n. 5
0
corona::Image* load_image_from_packfile(const char* filename)
{
	VFILE* vf = vopen(filename);
	if (!vf)
	{
		err("loadimage: couldn't load image %s; couldnt find a file or a vfile", filename);
	}
	int l = filesize(vf);
	std::auto_ptr<char> buffer(new char[l]);
	vread(buffer.get(), l, vf);
	vclose(vf);
	std::auto_ptr<corona::File> memfile(corona::CreateMemoryFile(buffer.get(), l));
	return corona::OpenImage(memfile.get(), corona::FF_AUTODETECT, corona::PF_DONTCARE);
}
Esempio n. 6
0
/****************************** code ******************************/
Layer::Layer(VFILE *f)
{
	lucent = 0; width = height = 0;
	vread(layername, 256, f);
	vread(&parallax_x, 8, f);
	vread(&parallax_y, 8, f);
	vread(&width, 2, f);
	vread(&height, 2, f);
	vread(&lucent, 1, f);

	tiledata = new word[width*height];
	cvread(tiledata, width*height*2, f);
    x_offset = y_offset = 0; // no offset until parallax has changed
}
Esempio n. 7
0
void read_exif_header(FILE *fp, unsigned char *buffer, bool *is_valid, bool *is_little_endian)
{
  //  SOI
  vread(buffer, 2, fp, is_valid);
  vcmp(SOI, buffer, 2, is_valid);

  //  APP1 Marker
  vread(buffer, 2, fp, is_valid);
  vcmp(APP1_MARKER, buffer, 2, is_valid);

  //  EXIF Identifier Code
  vseek(fp, 2, SEEK_CUR, is_valid);   //  Skip (APP1 Length)
  vread(buffer, 6, fp, is_valid);
  vcmp(EXIF_IDENT_CODE, buffer, 6, is_valid);

  //  Byte Order
  vread(buffer, 2, fp, is_valid);

  if(*is_valid && memcmp(TIFF_LITTLE_ENDIAN, buffer, 2) == 0)
    *is_little_endian = true;
  else if(*is_valid && memcmp(TIFF_BIG_ENDIAN, buffer, 2) == 0)
    *is_little_endian = false;
  else
    *is_valid = false;

  //  EXIF Fixed Code
  vread(buffer, 2, fp, is_valid);
  vrev(buffer, 2, is_valid, is_little_endian);
  vcmp(EXIF_FIXED_CODE, buffer, 2, is_valid);

  //  0th IFD Offset
  vread(buffer, 4, fp, is_valid);
  vrev(buffer, 4, is_valid, is_little_endian);

  //  0th IFD
  vseek(fp, todecimal(buffer, 4) - 8, SEEK_CUR, is_valid);

  //  0th IFD Entry Count
  vread(buffer, 2, fp, is_valid);
  vrev(buffer, 2, is_valid, is_little_endian);
}
Esempio n. 8
0
size_t Garlick_vf_read(void *ptr, size_t elemsize, size_t amt, void *handle) { return vread((char *)ptr, elemsize*amt,(VFILE*)handle); }
Esempio n. 9
0
/*
	Routine to process a transitive verb
*/
trverb()
{
	switch(verb){
	case CALM:
	case WALK:
	case QUIT:
	case SCORE:
	case FOO:
	case BRIEF:
	case SUSPEND:
	case HOURS:
	case LOG:
		actspk(verb);
		break;
	case TAKE:
		vtake();
		break;
	case DROP:
		vdrop();
		break;
	case OPEN:
	case LOCK:
		vopen();
		break;
	case SAY:
		vsay();
		break;
	case NOTHING:
		rspeak(54);
		break;
	case ON:
		von();
		break;
	case OFF:
		voff();
		break;
	case WAVE:
		vwave();
		break;
	case KILL:
		vkill();
		break;
	case POUR:
		vpour();
		break;
	case EAT:
		veat();
		break;
	case DRINK:
		vdrink();
		break;
	case RUB:
		if (object != LAMP)
			rspeak(76);
		else
			actspk(RUB);
		break;
	case THROW:
		vthrow();
		break;
	case FEED:
		vfeed();
		break;
	case FIND:
	case INVENTORY:
		vfind();
		break;
	case FILL:
		vfill();
		break;
	case READ:
		vread();
		break;
	case BLAST:
		vblast();
		break;
	case BREAK:
		vbreak();
		break;
	case WAKE:
		vwake();
		break;
	default:
		printf("This verb is not implemented yet.\n");
	}
}
Esempio n. 10
0
void VSP::LoadVSP(VFILE *f)
{
	int signature;
	vread(&signature, 4, f);
	if (signature != VSP_SIGNATURE)
		err("VSP::LoadVSP() - Invalid VSP signature!");

	int version;
	vread(&version, 4, f);
	if (version != VSP_VERSION)
		err("VSP::LoadVSP() - Invalid version (%d)", version);

	int tilesize;
	vread(&tilesize, 4, f);
	if (tilesize != 16)
		err("VSP::LoadVSP() - bzzzzzzzzttt. Try a 16x16 vsp! %d",tilesize);

	int format;
	vread(&format, 4, f);
	vread(&numtiles, 4, f);

	int compression;
	vread(&compression, 4, f);
	if (compression != VSP_ZLIB) err("huhhruhoeijfaoijrf..fdpok no compression? tell vecna!!!");
	byte *tiledatabuf = new byte[16*16*3*numtiles];
	cvread(tiledatabuf, 16*16*3*numtiles, f);

	container = new image(16, 16);
	container->delete_data();

	vspdata = ImageFrom24bpp(tiledatabuf, 16, 16*numtiles);
	delete[] tiledatabuf;

	vread(&numanims, 4, f);
	anims = new vspanim_r[numanims];
	for(int i = 0; i < numanims; i++)
	{
		vread(anims[i].name, 256, f);
		vread(&anims[i].start, 4, f);
		vread(&anims[i].finish, 4, f);
		vread(&anims[i].delay, 4, f);
		vread(&anims[i].mode, 4, f);
	}

	ValidateAnimations();

	vread(&numobs, 4, f);
	obs = new char[numobs*256];
	cvread(obs, numobs*256, f);

	// initialize tile anim stuff
	tileidx = new int[numtiles];
	flipped = new int[numtiles];
	vadelay = new int[numanims];

	int i;
	for (i=0; i<numanims; i++)
		vadelay[i]=0;
	for (i=0; i<numtiles; i++)
	{
		flipped[i] = 0;
		tileidx[i] = i;
	}
	mytimer = systemtime;

	// Overkill (2006-07-20): And added back in.
	SetHandleImage(2, vspdata);
}
Esempio n. 11
0
// Overkill (2006-07-20): Saver functions!
void MAP::save(FILE *f)
{
	int i;
	char tempfn[16] = "$$v3map.tmp";
	FILE *out = fopen(tempfn, "wb");
	if (!out) err("Unable to open %s for writing!", tempfn);
	// Map signature.
	char signature[8];
	strcpy(signature, maptag);
	fwrite(&signature, 1, 6, f);

	// Version
	int version = MAP_VERSION;
	fwrite(&version, 1, 4, f);

	// USE OUTPUT BUFFER FROM THIS POINT ON.
	fwrite(mapname, 1, 256, out);
	//log("mapname: %s", mapname);
	// savevspname, not vspname because it's what the vsp file WILL be,
	// not necessarily what it IS at that moment.
	// So, you can set it then FileSaveVSP() down the line.
	fwrite(savevspname, 1, 256, out);
	//log("savevspname: %s", savevspname);
	fwrite(musicname, 1, 256, out);
	//log("musicname: %s", musicname);
	fwrite(renderstring, 1, 256, out);
	//log("renderstring: %s", renderstring);
	fwrite(startupscript, 1, 256, out);
	//log("startupscript: %s", startupscript);
	fwrite(&startx, 1, 2, out);
	fwrite(&starty, 1, 2, out);

	fwrite(&numlayers, 1, 4, out);
	for (i = 0; i < numlayers; i++)
	{
		layers[i]->save(out);
	}

	// Obs.
	cfwrite(obslayer, 1, mapwidth*mapheight, out);
	// Zones
	cfwrite(zonelayer, 1, mapwidth*mapheight*2, out);

	fwrite(&numzones, 1, 4, out);
	for (i=0; i<numzones; i++)
	{
		fwrite(zones[i]->name, 1, 256, out);
		fwrite(zones[i]->script, 1, 256, out);
		fwrite(&zones[i]->percent, 1, 1, out);
		fwrite(&zones[i]->delay, 1, 1, out);
		fwrite(&zones[i]->method, 1, 1, out);
	}

	// ENTITIES! <3.
	fwrite(&entities, 1, 4, out);
	for (i=0; i<entities; i++)
	{
		//log("ENT %d of %d", i, entities);
		// Tile coords.
		int x = entity[i]->x / 16;
		int y = entity[i]->y / 16;
		fwrite(&x, 1, 2, out);
		fwrite(&y, 1, 2, out);
		fwrite(&entity[i]->face, 1, 1, out);
		fwrite(&entity[i]->obstructable, 1, 1, out);
		fwrite(&entity[i]->obstruction, 1, 1, out);
		fwrite(&entity[i]->autoface, 1, 1, out);
		fwrite(&entity[i]->speed, 1, 2, out);
		//log("HERE?");
		// FIXME: ACTIVATION MODE
		int activationMode = 0;
		fwrite(&activationMode, 1, 1, out);
		// Movecode and wandering.
		fwrite(&entity[i]->movecode, 1, 1, out);
		fwrite(&entity[i]->wx1, 1, 2, out);
		fwrite(&entity[i]->wy1, 1, 2, out);
		fwrite(&entity[i]->wx2, 1, 2, out);
		fwrite(&entity[i]->wy2, 1, 2, out);
		fwrite(&entity[i]->wdelay, 1, 2, out);
		//log("YAR?");
		// Expand! whatever, man.
		int expand = 0;
		fwrite(&expand, 1, 4, out);

		// h8 u STD::string.
		char tempchar[256];

		//log("movestr: %s", entity[i]->movestr);
		fwrite(entity[i]->movestr, 1, 256, out);
		strcpy(tempchar, entity[i]->chr->name.c_str());
		fwrite(tempchar, 1, 256, out);
		strcpy(tempchar, entity[i]->description.c_str());
		fwrite(tempchar, 1, 256, out); // description
		strcpy(tempchar, entity[i]->script.c_str());
		fwrite(tempchar, 1, 256, out); // The actual script position.
	}
	// NO LONGER NEED TO USE THE OUTPUT BUFFER
	fclose(out);
	
	// Why vopen instead? I... don't know!
	// Now that we've finished the buffer though, we can
	// use this to fill in the unknown map information.
	
	VFILE *tmp = vopen(tempfn);
	if (!tmp) err("Could not open %s for reading!", tempfn);
	int bufferlength = filesize(tmp);
	byte* buf = new byte[bufferlength];
	vread(buf, bufferlength, tmp);
	vclose(tmp);
	// Delete the temporary buffer, we've gotten what we wanted.
	remove(tempfn);

	// Alright... finally, all this to get the offset for the VC stuffs.
	int vcofs = 14 + bufferlength;
	fwrite(&vcofs, 1, 4, f);
	// Write the buffer into the map now.
	fwrite(buf, 1, bufferlength, f);
	// VC funcs are waaay down here.
	int vcfuncs = 0; // number compiled should be none.
	//log("VCOFS: %d CURRENT POS: %d", vcofs, ftell(f));
	fwrite(&vcfuncs, 1, 4, f);
}
Esempio n. 12
0
MAP::MAP(char *fname)
{
	VFILE *f = vopen(fname);
	if (!f)
		err("MAP::MAP() - could not load map %s", fname);

	strcpy(mapfname, fname);
	strlwr(mapfname);

	char signature[8];
	vread(signature, 6, f);
	if (strcmp(signature, maptag))
		err("MAP::MAP() - %s is not a valid mapfile!", fname);

	int version;
	vread(&version, 4, f);
	if (version != MAP_VERSION)
		err("MAP::MAP() - %s is not the correct MAP format version!", fname);
	vread(&version, 4, f); // skip vc offset

	vread(mapname, 256, f);
	vread(vspname, 256, f);
	strcpy(savevspname, vspname); // Overkill 2006-05-21
	vread(musicname, 256, f);
	vread(renderstring, 256, f);
	vread(startupscript, 256, f);

	PlayMusic(musicname);

	startx = starty = 0;
	vread(&startx, 2, f);
	vread(&starty, 2, f);

	std::string s = std::string(fname);
	int offs = s.rfind('\\');
	if (offs >= 0)
	{
		s.replace(offs+1,strlen(fname),vspname);
		tileset = new VSP((char *)s.c_str());
	}
	else
	{
		offs = s.rfind('/');
		if (offs >= 0)
		{
			s.replace(offs+1,strlen(fname),vspname);
			tileset = new VSP((char *)s.c_str());
		}
		else
			tileset = new VSP(vspname);
	}

	vread(&numlayers, 4, f);

	//layers = new Layer*[numlayers];
	layers.resize(numlayers);
	int i;
	for (i=0; i<numlayers; i++)
		layers[i] = new Layer(f);

	mapwidth = layers[0]->width;
	mapheight = layers[0]->height;

	obslayer = new byte[mapwidth*mapheight];
	zonelayer = new word[mapwidth*mapheight];
	cvread(obslayer, mapwidth*mapheight, f);
	cvread(zonelayer, mapwidth*mapheight*2, f);

	vread(&numzones, 4, f);
	zones.resize(numzones);
	for (i=0; i<numzones; i++)
	{
		zones[i] = new Zone;
		zones[i]->percent = zones[i]->method = zones[i]->delay = 0;
		vread(zones[i]->name, 256, f);
		vread(zones[i]->script, 256, f);
		vread(&zones[i]->percent, 1, f);
		vread(&zones[i]->delay, 1, f);
		vread(&zones[i]->method, 1, f);
	}

	vread(&mapentities, 4, f);

	for (i=0; i<mapentities; i++)
	{
		int t=0, x1=0, y1=0, x2=0, y2=0;
		char movescript[256], chrname[256], script[256], description[256];

		vread(&x1, 2, f);
		vread(&y1, 2, f);
		int o1 = vtell(f);
		vseek(f, 22, 1);
		vread(movescript, 256, f);
		vread(chrname, 256, f);
		vread(description, 256, f); // this is actually the description which we dont care about
		vread(script, 256, f); // this is the actual script
		vseek(f, o1, 0);

		int i = AllocateEntity(x1*16, y1*16, chrname);

		entity[i]->description = description;
		entity[i]->script = script;
		vread(&t, 1, f);
		if (!t) t = SOUTH;
		entity[i]->setface(t); t=0;
		vread(&t, 1, f);
		entity[i]->obstructable = t ? true : false; t=0;
		vread(&t, 1, f);
		entity[i]->obstruction = t ? true : false; t=0;
		vread(&t, 1, f);
		entity[i]->autoface = (t!=0); t=0;
		vread(&t, 2, f);
		entity[i]->setspeed(t); t=0;
		vread(&t, 1, f);
		// activation mode FIXME
		vread(&t, 1, f);

		vread(&x1, 2, f);
		vread(&y1, 2, f);
		vread(&x2, 2, f);
		vread(&y2, 2, f);
		switch(t)
		{
			case 0: entity[i]->SetMotionless(); break;
			case 1: entity[i]->SetWanderZone(); break;
			case 2: entity[i]->SetWanderBox(x1, y1, x2, y2); break; //FIXME
			case 3: entity[i]->SetMoveScript(movescript); break;
		}
		t=0; vread(&t, 2, f);
		entity[i]->SetWanderDelay(t);
		vread(&t, 4, f);
		vseek(f, 1024, 1);
		/*
		vread(&tlen, 4, f);
		vread(ename, tlen+1, f);
		// chr filename
		vread(&tlen, 4, f);
		vread(chrfn, tlen+1, f);
		// script
		vread(&tlen, 4, f);
		vread(escript, tlen+1, f);
		// movescript
		vread(&tlen, 4, f);
		vread(emovescript, tlen+1, f);

		vread(&tlen, 4, f);
		vread(&tlen, 4, f);
		int eface, speed, tx, ty;
		vread(&eface, 4, f);
		vread(&speed, 4, f);
		vread(&tx, 4, f);
		vread(&ty, 4, f);

		vread(&x1, 4, f);
		vread(&y1, 4, f);
		vread(&x2, 4, f);
		vread(&y2, 4, f);

		int idx = AllocateEntity(tx*16, ty*16, chrfn);
		entity[idx]->setface(eface);
		entity[idx]->setspeed(speed);
		entity[idx]->script = escript;
		entity[idx]->autoface = (eflags & ENT_AUTOFACE) ? true : false;
		entity[idx]->obstructable = (eflags & ENT_OBSTRUCTED) ? true : false;
		entity[idx]->obstruction = (eflags & ENT_OBSTRUCTS) ? true : false;

		if (method == ENT_MOVESCRIPT) entity[idx]->SetMoveScript(emovescript);
		if (method == ENT_WANDERZONE) entity[idx]->SetWanderZone();
		if (method == ENT_WANDERBOX) entity[idx]->SetWanderBox(x1, y1, x2, y2);*/
	}
	current_map = this;
	se->LoadMapScript(f, mapfname);
	vclose(f);
	se->ExecuteFunctionString(startupscript);
}