diff options
| author | Eugene Sandulenko | 2009-02-15 10:10:23 +0000 | 
|---|---|---|
| committer | Eugene Sandulenko | 2009-02-15 10:10:23 +0000 | 
| commit | c399437479e8489da3d3bd64bcfbd1446ee44a7d (patch) | |
| tree | 69032cb89fea770581a09130e5f0f4018056084f /engines/sci/engine | |
| parent | 3fb25cf100abb955f7dda5a27066af2993039cc9 (diff) | |
| download | scummvm-rg350-c399437479e8489da3d3bd64bcfbd1446ee44a7d.tar.gz scummvm-rg350-c399437479e8489da3d3bd64bcfbd1446ee44a7d.tar.bz2 scummvm-rg350-c399437479e8489da3d3bd64bcfbd1446ee44a7d.zip  | |
- Remove unneeded files
- Make whole thing finally compilable
svn-id: r38214
Diffstat (limited to 'engines/sci/engine')
| -rw-r--r-- | engines/sci/engine/kemu_old.c | 330 | ||||
| -rw-r--r-- | engines/sci/engine/simplesaid.c | 312 | 
2 files changed, 0 insertions, 642 deletions
diff --git a/engines/sci/engine/kemu_old.c b/engines/sci/engine/kemu_old.c deleted file mode 100644 index 4ec6c0a106..0000000000 --- a/engines/sci/engine/kemu_old.c +++ /dev/null @@ -1,330 +0,0 @@ -/*************************************************************************** - kemu_old.c Copyright (C) 2002 Christoph Reichenbach - - - This program may be modified and copied freely according to the terms of - the GNU general public license (GPL), as long as the above copyright - notice and the licensing information contained herein are preserved. - - Please refer to www.gnu.org for licensing details. - - This work is provided AS IS, without warranty of any kind, expressed or - implied, including but not limited to the warranties of merchantibility, - noninfringement, and fitness for a specific purpose. The author will not - be held liable for any damage caused by this work or derivatives of it. - - By using this source code, you agree to the licensing terms as stated - above. - - - Please contact the maintainer for bug reports or inquiries. - - Current Maintainer: - -    Christoph Reichenbach (CR) <jameson@linuxgames.com> - -***************************************************************************/ -/* Emulation code for old kernel functions */ - -#include <engine.h> -#include "kernel_compat.h" -#include "kernel_types.h" -#include "heap.h" - -#define EMU_HEAP_START_ADDR 1000 - -#define EMU_TYPE_VERBATIM 0 /* Arithmetic values */ -#define EMU_TYPE_REGISTERS 1 /* Must re-interpret afterwards. Also used for objects. */ -#define EMU_TYPE_BLOCK 2 /* Bulk data; string or similar. May physically point to stack */ - -static int funct_nr; - -typedef struct { -	heap_ptr start; /* Beginning of the block */ -	reg_t pos; /* Needed for resolving conflicts */ -	int length; /* Number of bytes occupied on the heap */ -	object_t *obj; /* For object types: Pointer to the physical object */ - -	/* Emulation data part */ -	int emudat_type; /* EMU_TYPE_... */ -	heap_ptr emudat_location; /* Only for 1 and 2 */ -	union { -		reg_t *regs; /* registers, for type 1 */ -		byte *block; /* Bulk data location, for type 2 */ -	} emu_data; -	int emudat_size; /* Amount of bytes or number of entries */ -} emu_param_t; - -static inline emu_param_t -identify_value(state_t *s, reg_t reg, heap_ptr firstfree) -{ -	emu_param_t retval; -	int type = determine_reg_type(s, reg); - -	retval.start = firstfree; -	retval.pos = reg; - -	retval.obj = NULL; -	retval.length = 0; -	retval.emudat_type = EMU_TYPE_VERBATIM; /* To allow error aborts */ - -	if (type & KSIG_NULL) -		type &= KSIG_ARITHMETIC; - -	switch (type) { - -	case KSIG_ARITHMETIC: /* trivial */ -		retval.emudat_size = 0; -		break; - -	case KSIG_OBJECT: -		retval.emudat_type = EMU_TYPE_REGISTERS; -		retval.obj = obj_get(s, reg); -		if (!retval.obj) { BREAKPOINT(); } -		retval.length = -SCRIPT_OBJECT_MAGIC_OFFSET -			+ retval.obj->variables_nr * 4 /* values and selectors */ -			+ 2; /* Extra magic selector word (is this really needed?) */ -		retval.emu_data.regs = retval.obj->variables; -		retval.emudat_size = retval.obj->variables_nr; -		retval.emudat_location = retval.start - SCRIPT_OBJECT_MAGIC_OFFSET; -		break; - -	case KSIG_REF: { -		retval.emudat_type = EMU_TYPE_BLOCK; - -		retval.emu_data.block = -			s->seg_manager.dereference(&s->seg_manager, -						   reg, &retval.emudat_size); - -		if (!retval.emu_data.block) { -			SCIkdebug(SCIkERROR, "Cannot handle references into segment type %02x" -				  " (from "PREG") during emulation\n", -				  type, PRINT_REG(reg)); -			retval.emudat_type = EMU_TYPE_VERBATIM; -			retval.length = 0; -		} - -		retval.length = retval.emudat_size; -		retval.emudat_location = retval.start; - -		break; -	} - -	default: -		SCIkdebug(SCIkERROR, "Cannot handle argument type %02x (from "PREG -			  ") during emulation\n", -			  type, PRINT_REG(reg)); -	} - -	return retval; -} - -static inline void -writeout_value(state_t *s, emu_param_t *p) -{ -	if (p->obj) /* First copy object; don't need to read back this part later */ -		memcpy(s->heap + p->start, p->obj->base_obj + SCRIPT_OBJECT_MAGIC_OFFSET, -		       p->length); - -	switch (p->emudat_type) { - -	case EMU_TYPE_VERBATIM: -		SCIkdebug(SCIkEMU, "\tVerbatim/Arithmetic\n"); -		return; - -	case EMU_TYPE_REGISTERS: { -		int i, max = p->emudat_size; - -		SCIkdebug(SCIkEMU, "\tObject, %d selectors\n", max); - -		for (i = 0; i < max; i++) { -			byte *dest = s->heap + p->emudat_location + (i << 1); - -			dest[0] = p->emu_data.regs[i].offset & 0xff; -			dest[1] = (p->emu_data.regs[i].offset >> 8) & 0xff; -			/* Assume they're all numeric values */ -		} -		return; -	} - -	case EMU_TYPE_BLOCK: -		SCIkdebug(SCIkEMU, "\tBulk\n"); -		memcpy(s->heap + p->emudat_location, p->emu_data.block, p->emudat_size); -		return; - -	default: -		BREAKPOINT(); -	} -} - -static inline void -recover_value(state_t *s, emu_param_t *p) -{ /* Writes back the value */ -	switch (p->emudat_type) { - -	case EMU_TYPE_VERBATIM: -		return; - -	case EMU_TYPE_REGISTERS: { -		int i, max = p->emudat_size; -		for (i = 0; i < max; i++) { -			int val = GET_HEAP(p->emudat_location + (i << 1)); -			if (p->emu_data.regs[i].offset != val) { -				SCIkdebug(SCIkEMU, "	Recovering property #%d from %04x: 0:%04x\n", -					  i, p->emudat_location + (i << 1), val); -				p->emu_data.regs[i] = make_reg(0, val); -			} else { -				SCIkdebug(SCIkEMU, "	Property #%d from %04x is unchanged (%04x vs "PREG")\n", -					  i, p->emudat_location + (i << 1), val, PRINT_REG(p->emu_data.regs[i])); -			} -			/* Don't overwrite unless something changed, to preserve pointers */ -		} -		return; -	} - -	case EMU_TYPE_BLOCK: -		memcpy(p->emu_data.block, s->heap + p->emudat_location, p->emudat_size); -		SCIkdebug(SCIkEMU, "    Recovering %d raw bytes from %04x\n", -			  p->emudat_size, p->emudat_location); -		return; - -	default: -		BREAKPOINT(); -	} -} - -static void -_restrict_against(state_t *s, emu_param_t *self, emu_param_t *other) -{ -	if (self->pos.segment != other->pos.segment) -		return; - -	if (self->pos.offset <= other->pos.offset -	    && self->pos.offset + self->emudat_size > other->pos.offset) { -		mem_obj_t *mobj = GET_SEGMENT_ANY(s->seg_manager, self->pos.segment); - -		self->emudat_size = other->pos.offset - self->pos.offset; - -		if (mobj && mobj->type == MEM_OBJ_STACK) -			self->emudat_size *= sizeof(reg_t); /* Accomodate for size differences */ -	} -} - -static void -resolve_conflicts(state_t *s, emu_param_t *params, int count) -{ -	int i, j; -	for (i = 0; i < count; i++) -		for (j = 0; j < count; j++) -			if (i != j) -				_restrict_against(s, params + i, params + j); -} - -reg_t -kFsciEmu(state_t *s, int _funct_nr, int argc, reg_t *argv) -{ -	emu_param_t *shadow_args; -	funct_nr = _funct_nr; - -	if (!s->kfunct_emu_table[funct_nr]) { -		SCIkwarn(SCIkERROR, "Attempt to emulate unknown kernel function %x\n", -			 funct_nr); -		return NULL_REG; -	} else { -		heap_ptr argp = EMU_HEAP_START_ADDR; /* arguments go here */ -		heap_ptr datap = argp + argc * 2; /* copied stuff goes here */ -		int i; - -		shadow_args = sci_malloc(sizeof(emu_param_t) * (argc + 1 -								/* Prevents stupid warning */)); -		memset(shadow_args, 0, sizeof(emu_param_t) * (argc + 1)); - -		SCIkdebug(SCIkEMU, "Emulating kernel call %s[%x] w/ %d arguments at HP:%04x\n", -			  s->kernel_names[funct_nr], funct_nr, argc, argp); - -		for (i = 0; i < argc; i++) { -			int emu_value = argv[i].offset; /* Value we'll pass to the function */ - -			SCIkdebug(SCIkEMU, "   %3d : ["PREG"] ->\n", i, PRINT_REG(argv[i])); - -			shadow_args[i] = identify_value(s, argv[i], datap); - -			switch (shadow_args[i].emudat_type) { - -			case EMU_TYPE_VERBATIM: -				break; - -			case EMU_TYPE_REGISTERS: -			case EMU_TYPE_BLOCK: -				emu_value = shadow_args[i].emudat_location; -				break; - -			default: -				BREAKPOINT(); - -			} - -			SCIkdebug(SCIkEMU, "\t%04x [%d at %04x]\n", -				  emu_value, shadow_args[i].length, shadow_args[i].start); - -			PUT_HEAP(argp, emu_value); -			argp += 2; - -			if (0xffff - shadow_args[i].length < datap) { -				SCIkdebug(SCIkERROR, "Out of heap space while emulating!\n"); -				return NULL_REG; -			} -			datap += shadow_args[i].length; /* Step over last block we wrote */ -		} - -		for (i = 0; i < argc; i++) -			writeout_value(s, shadow_args + i); - -		resolve_conflicts(s, shadow_args, argc); - -		s->kfunct_emu_table[funct_nr](s, funct_nr, argc, EMU_HEAP_START_ADDR); - -		for (i = 0; i < argc; i++) -			recover_value(s, shadow_args + i); -		free(shadow_args); -		return make_reg(0, s->acc); -	} -} - - -int -read_selector16(state_t *s, heap_ptr object, selector_t selector_id, const char *file, int line) -{ -	int slc_count = GET_HEAP(object + SCRIPT_SELECTORCTR_OFFSET); -	int i; -	heap_ptr slc_names = object + slc_count * 2; - -	for (i = 0; i < slc_count; i++) { -		if (GET_HEAP(slc_names + (i<<1)) == selector_id) -			return GET_HEAP(object + (i<<1)); -	} - -	SCIkdebug(SCIkWARNING, "[EMU] Could not read selector %d from HP:%04x (%s, L%d)\n", -		  selector_id, object, file, line); -	return 0; -} - -void -write_selector16(state_t *s, heap_ptr object, selector_t selector_id, -		 int value, const char *fname, int line) -{ -	int slc_count = GET_HEAP(object + SCRIPT_SELECTORCTR_OFFSET); -	int i; -	heap_ptr slc_names = object + slc_count * 2; - -	for (i = 0; i < slc_count; i++) { -		if (GET_HEAP(slc_names + (i<<1)) == selector_id) { -			PUT_HEAP(object + (i<<1), value); -			return; -		} -	} - -	SCIkdebug(SCIkWARNING, "[EMU] Could not write selector %d from HP:%04x (%s, L%d)\n", -		  selector_id, object, fname, line); -} - diff --git a/engines/sci/engine/simplesaid.c b/engines/sci/engine/simplesaid.c deleted file mode 100644 index e74a3aec90..0000000000 --- a/engines/sci/engine/simplesaid.c +++ /dev/null @@ -1,312 +0,0 @@ -/*************************************************************************** - simplesaid.c Copyright (C) 2000 Christoph Reichenbach - - - This program may be modified and copied freely according to the terms of - the GNU general public license (GPL), as long as the above copyright - notice and the licensing information contained herein are preserved. - - Please refer to www.gnu.org for licensing details. - - This work is provided AS IS, without warranty of any kind, expressed or - implied, including but not limited to the warranties of merchantibility, - noninfringement, and fitness for a specific purpose. The author will not - be held liable for any damage caused by this work or derivatives of it. - - By using this source code, you agree to the licensing terms as stated - above. - - - Please contact the maintainer for bug reports or inquiries. - - Current Maintainer: - -    Christoph Reichenbach (CR) <jameson@linuxgames.com> - -***************************************************************************/ - - -#ifdef SCI_SIMPLE_SAID_CODE - -#include <engine.h> -#include <kdebug.h> - -static int current_pword; -static int said_pos; -static int refstart_pos, parse_pos; -static parse_tree_node_t *words; -static int dontclaim; /* Whether the Parse() event should be claimed */ -static int reached_end; - -static state_t *state; -static heap_ptr addr; - -#define WORDP_MODE_STAY 0 -#define WORDP_MODE_NEXT 1 -#define WORDP_MODE_SEEK 2 - -/* hack */ -#define s state - -static inline int /* Returns whether the specified word matches */ -word_p(int mode, int word) -{ -  int oldpp = parse_pos; -  do { -    if (mode) -      ++parse_pos; - -    current_pword = words[parse_pos << 1].content.value; -    /*    SDEBUG("Word at %d = %03x\n", parse_pos, current_pword); */ -    if (current_pword == word) { -      /*      ++matches; */ -      SCIkdebug(SCIkSAID, "wordp(%d, %03x) from %d -> 1\n", mode, word, oldpp); - -      reached_end |= (words[(parse_pos + 1) << 1].type == -1); - -      return 1; -    } - -  } while ((mode == WORDP_MODE_SEEK) && (words[parse_pos <<1].type != -1)); - -  if (words[parse_pos << 1].type == -1) -    --parse_pos; - -  SCIkdebug(SCIkSAID, "wordp(%d, %03x) from %d -> 0\n", mode, word, oldpp); - -  return 0; -} - - - -static inline int /* End of input? */ -end_p() -{ -  int val = (words[(parse_pos + 1) << 1 ].type == -1) || reached_end; - -  SCIkdebug(SCIkSAID, "endp(pp=%d) = %d\n", parse_pos, val); - -  return val; -} - - - -static inline int /* Returns whether the current_word references that specified word */ -reference_p(int referenced_word_index, int word) -{ -  int val = 0; -  int seeker = (refstart_pos << 1) + 2; - -  while (words[seeker].type != -1) { - -    if (words[seeker].content.value == word) -      if (((words[seeker + 1].content.branches[0] > -1) -	   && (words[seeker + 1].content.branches[0] == referenced_word_index)) -	  || ((words[seeker + 1].content.branches[1] > -1) -	      && (words[seeker + 1].content.branches[1] == referenced_word_index))) { -	val = 1; -	reached_end |= (words[seeker + 2].type == -1); -	break; -      } - -    seeker += 2; -  } - -  SCIkdebug(SCIkSAID, "%03x > pos[%d]  = %d  (start at %d)\n", word, referenced_word_index, val, refstart_pos); - -  return val; -} - - -static inline int /* Checks whether the current word has trailing references */ -follows_p(void) -{ -  /*  int val = (words[(parse_pos << 1) + 1].content.branches[1] > (parse_pos << 1)); - -      SDEBUG("follows-p(pp=%d) = %d\n", parse_pos, val);*/ - -  dontclaim = 1; -  return 1; /* appears to work best */ -} - - -static inline int -next_parse_token(int *token_is_op) -{ -  int item = state->heap[addr++]; - -  if (item < 0xf0) { -    item = item << 8 | state->heap[addr++]; -    *token_is_op = 0; -  } else -    *token_is_op = 1; - -  return item; -} - -#define STATE_INITIAL 0 -#define STATE_OR 1 -#define STATE_SEEK 2 -#define STATE_REF 3 - -static int -simplesaid(int minor_state, int terminator) -{ -  int major_state = STATE_INITIAL; -  int refword = parse_pos; /* The word references apply to */ -  int aspiring_refword = -1; /* in "a < b < c", c refers to b, and aspiring_refword will be b. */ -  int truth = 1; -  int token_is_op; -  SCIkdebug(SCIkSAID, "simplesaid(%02x)\n", terminator); - -  while (42) { - -    int token = next_parse_token(&token_is_op); -    SCIkdebug(SCIkSAID, "Got token %03x on truth %d\n", token, truth); - -    if (token_is_op && (token == terminator)) { -      if (terminator == SAID_TERM) -	truth = truth && end_p(); -      SCIkdebug(SCIkSAID, "Terminator; returning %d\n", truth); -      return truth; -    } - -    if (token_is_op) /* operator? */ -      switch (token) { - -      case SAID_COMMA: -	minor_state = STATE_OR; -	break; - -      case SAID_SLASH: -	if (!truth) { -	  while (((token = next_parse_token(&token_is_op)) != terminator) -		 && (token != SAID_TERM)); /* Proceed to end of block */ -	  if (token != terminator) -	    SCIkwarn(SCIkERROR, "Syntax error: Unexpected end of spec"); -	  return 0; -	} - -	major_state = STATE_SEEK; -	minor_state = STATE_INITIAL; -	break; - -      case SAID_PARENC: -	SCIkwarn(SCIkERROR, "')' without matching '('\n"); -        return 0; - -      case SAID_PARENO: -	switch (minor_state) { - -	case STATE_OR: -	  truth |= simplesaid(minor_state, SAID_PARENC); -	  break; - -	case STATE_INITIAL: -	  truth = truth && simplesaid(minor_state, SAID_PARENC); -	  break; - -	default: -	  SCIkwarn(SCIkERROR, "'(' in minor state %d\n", minor_state); -	} -	break; - -      case SAID_BRACKC: -	SCIkwarn(SCIkERROR, "']' without matching '['\n"); -        return 0; - -      case SAID_BRACKO: { -	int parse_pos_old = parse_pos; -	int recurse = simplesaid(minor_state, SAID_BRACKC); -	if (!recurse) -	  parse_pos = parse_pos_old; -	break; -      } - -      case SAID_LT: -	if (aspiring_refword > -1) /* "a < b < c" */ -	  refword = aspiring_refword; /* refword = 'b' (in the case above) */ -	major_state = STATE_REF; -	break; - -      case SAID_GT: -	return truth && follows_p(); - -      case SAID_TERM: -	SCIkwarn(SCIkERROR, "Unexpected end of spec\n"); -        return 0; - -      default: -	SCIkwarn(SCIkERROR, "Syntax error: Unexpected token 0x%02x\n", token); -        return 0; -      } else { -	int tempresult; - -	/*      ++word_tokens_nr; /* Normal word token */ - -	switch(major_state) { - -	case STATE_INITIAL: -	  tempresult = word_p(((minor_state == STATE_OR)? WORDP_MODE_STAY : WORDP_MODE_NEXT), token); -	  refword = parse_pos; -	  break; - -	case STATE_SEEK: -	  tempresult = word_p(WORDP_MODE_SEEK, token); -	  major_state = STATE_INITIAL; -	  refword = parse_pos; -	  break; - -	case STATE_REF: -	  tempresult = reference_p(refword, token); -	  aspiring_refword = parse_pos; -	  break; - -	default: -	  SCIkwarn(SCIkERROR, "Invalid major state!\n"); -          return 0; -	} - -	SCIkdebug(SCIkSAID, "state=(%d,%d), truth = %d * %d\n", major_state, minor_state, truth, tempresult); - -	if (minor_state == STATE_OR) -	  truth |= tempresult; -	else -	  truth = truth && tempresult; - -	minor_state = STATE_INITIAL; -      } -  } -} - -#undef s - -int -vocab_simple_said_test(state_t *s, heap_ptr address) -{ -  int matched; -  current_pword = reached_end = 0; -  dontclaim = 0; -  said_pos = 0; -  if (s->parser_lastmatch_word == SAID_NO_MATCH) -    SCIkdebug(SCIkSAID, "lastmatch_word: none\n"); -  else -    SCIkdebug(SCIkSAID, "lastmatch_word=%d\n", s->parser_lastmatch_word); -  parse_pos = (s->parser_lastmatch_word == SAID_NO_MATCH)? -1 : s->parser_lastmatch_word; -  refstart_pos = parse_pos; -  state = s; -  addr = address; -  words = s->parser_nodes; -  matched = simplesaid(STATE_INITIAL, SAID_TERM); -  SCIkdebug(SCIkSAID, "Result: (matched,dontclaim)=(%d,%d)\n", matched, dontclaim); - -  if (!matched) -    return SAID_NO_MATCH; - -  if (dontclaim) /* partial match */ -    return parse_pos; /* Return lastmatch word */ - -  return SAID_FULL_MATCH; -} - -#endif /* SCI_SIMPLE_SAID_CODE */  | 
