Ejemplo n.º 1
0
// loads the line from the current file
bool Tline::load()
{
  Tmap_item::load();
  // reads first and second ends
  v1 = rdlong();
  v2 = rdlong();

  // reads all the walls
  int n = rdlong();
  if (n==0) return false;
#ifndef EDITOR
  walls = (Twall **)malloc( n*sizeof(Twall*) );
#else
  walls = (Twall **)malloc( sizeof(Twall*) );
#endif
  if (!walls) return false;
  Twall **w;
  int i;
  for (i=0,w=walls;i<n;i++,NEXTWALL(w)) {
    byte kind = rdchar();
    // create the walls
    switch (kind) {
      case wtWALL:
        (*w) = new Twall();
        break;
      case wtHOLE:
        (*w) = new Thole();
        break;
      case wtPORTAL:
        (*w) = new Tportal();
        break;
    }
    if (!(*w)->load()) {
#ifndef EDITOR
      for (;w>=walls;w--)
        delete *w;
#else
      Twall *w0,*n;
      for (w0=*walls;w0;w0=n) {
        n=w0->next;
        delete w0;
      }
#endif      
      free(walls);
      return false;
    }
  }
  wallsnum=n;
  return true;
}
Ejemplo n.º 2
0
static s32 get_fixup (s32 reloc, s32 code_end)
{
	s32 old_bufpos;
	s32 next;
	static s32 reloc_pos;

	old_bufpos = buf_pos;
	if (reloc == 0) {
		buf_pos = code_end;
		reloc = rdlong (buf_pos);
		buf_pos += 4;
		reloc_pos = buf_pos;
		buf_pos = old_bufpos;
		if (reloc == 0) return 0;
		else return reloc+0x1c+LOAD_BASE;
	} else {
		buf_pos = reloc_pos;
again:
		next = (u8)rdbyte (buf_pos);
		buf_pos++;
		if (next == 0) {
			buf_pos = old_bufpos;
			return 0;
		} else if (next == 1) {
			reloc += 254;
			goto again;
		}
		else reloc += next;
		reloc_pos = buf_pos;
		buf_pos = old_bufpos;
		return reloc;
	}
}
Ejemplo n.º 3
0
// loads the cluster from the current file
bool Tcluster::load()
{
  Tmap_item::load();
  int n = rdlong();
  if (n) {
    CONSTRUCT_AND_LOAD_ARRAY( sectors, Tsector, n );
  }
  sectorsnum=n;
  return true;
}
Ejemplo n.º 4
0
void load_binfile (const char *bin_filename)
{
	s32 reloc, next, pos, code_end, len, i = 0;
	FILE *f;

	if ((f = fopen (bin_filename, "r")) == NULL) {
		fprintf (stderr, "Error opening 68k-binary '%s'\n", bin_filename);
		//SDL_Quit ();
		exit (-2);
	}
	fseek (f, 0, SEEK_END);
	len = ftell (f);
	fseek (f, 0, SEEK_SET);
	assert (len+LOAD_BASE < MEM_SIZE);
	fread (m68kram+LOAD_BASE, 1, len, f);
	fclose (f);
	
	buf_pos = LOAD_BASE + 2;
	code_end = LOAD_BASE + 0x1c + rdlong (buf_pos);
	i=0;
	reloc = get_fixup (0, code_end);
	while (reloc) {
		i++;
		pos = buf_pos;
		/* address to be modified */
		buf_pos = reloc;
		next = rdlong (buf_pos);
		next += LOAD_BASE;
		wrlong (buf_pos, next);
		if (next > code_end) {
			fprintf (stderr, "Reloc 0x%x (0x%x) out of range..\n", next, reloc+LOAD_BASE);
		}
		buf_pos = pos;
		reloc = get_fixup (reloc, code_end);
	}
	fprintf (stderr, "%s: 0x%x bytes (code end 0x%x), %d fixups; loaded at 0x%x.\n", bin_filename, len, code_end, i, LOAD_BASE);
}