Exemple #1
0
uint *Glulxe::grab_temp_i_array(uint addr, uint len, int passin) {
	arrayref_t *arref = nullptr;
	uint *arr = nullptr;
	uint ix, addr2;

	if (len) {
		arr = (uint *)glulx_malloc(len * sizeof(uint));
		arref = (arrayref_t *)glulx_malloc(sizeof(arrayref_t));
		if (!arr || !arref)
			error("Unable to allocate space for array argument to Glk call.");

		arref->array = arr;
		arref->addr = addr;
		arref->elemsize = 4;
		arref->retained = false;
		arref->len = len;
		arref->next = arrays;
		arrays = arref;

		if (passin) {
			for (ix = 0, addr2 = addr; ix < len; ix++, addr2 += 4) {
				arr[ix] = Mem4(addr2);
			}
		}
	}

	return arr;
}
Exemple #2
0
uint Glulxe::ReadStructField(uint addr, uint fieldnum) {
	if (addr == 0xffffffff) {
		stackptr -= 4;
		return Stk4(stackptr);
	} else {
		return Mem4(addr + (fieldnum * 4));
	}
}
Exemple #3
0
uint Glulxe::ReadMemory(uint addr) {
	if (addr == 0xffffffff) {
		stackptr -= 4;
		return Stk4(stackptr);
	} else {
		return Mem4(addr);
	}
}
Exemple #4
0
/* Look up a property entry. */
static glui32 get_prop(glui32 obj, glui32 id)
{
    glui32 cla = 0;
    glui32 prop;
    glui32 call_argv[2];

    if (id & 0xFFFF0000) {
        cla = Mem4(classes_table+((id & 0xFFFF) * 4));
        ARG(call_argv, 2, 0) = obj;
        ARG(call_argv, 2, 1) = cla;
        if (func_5_oc__cl(2, call_argv) == 0)
            return 0;

        id >>= 16;
        obj = cla;
    }
Exemple #5
0
/* linked_search():
   The structures may be anywhere in memory, in any order. They are
   linked by a four-byte address field, which is found in each struct
   at position nextoffset. If this field contains zero, it indicates
   the end of the linked list.

   The KeyIndirect and ZeroKeyTerminates options may be used.
*/
glui32 linked_search(glui32 key, glui32 keysize, 
  glui32 start, glui32 keyoffset, glui32 nextoffset, glui32 options)
{
  unsigned char keybuf[4];
  int ix;
  glui32 val;
  int zeroterm = ((options & serop_ZeroKeyTerminates) != 0);

  fetchkey(keybuf, key, keysize, options);

  while (start != 0) {
    int match = TRUE;
    if (keysize <= 4) {
      for (ix=0; match && ix<keysize; ix++) {
        if (Mem1(start + keyoffset + ix) != keybuf[ix])
          match = FALSE;
      }
    }
    else {
      for (ix=0; match && ix<keysize; ix++) {
        if (Mem1(start + keyoffset + ix) != Mem1(key + ix))
          match = FALSE;
      }
    }

    if (match) {
      return start;
    }

    if (zeroterm) {
      match = TRUE;
      for (ix=0; match && ix<keysize; ix++) {
        if (Mem1(start + keyoffset + ix) != 0)
          match = FALSE;
      }
      if (match) {
        break;
      }
    }
    
    val = start + nextoffset;
    start = Mem4(val);
  }

  return 0;
}
Exemple #6
0
static int obj_in_class(glui32 obj)
{
    /* This checks whether obj is contained in Class, not whether
       it is a member of Class. */
    return (Mem4(obj + 13 + num_attr_bytes) == class_metaclass);
}