Esempio n. 1
0
void z_read( zmachine *zm ) {
  zbyte max = read_byte( zm, zm->zargs[0] );
  zbyte size = read_byte( zm, zm->zargs[0] + 1 );

  VALUE line;

  int i;

  if( h_version(zm) < 5 ) {
    max -= 1;
    size = 0;
  }

  line = rb_funcall( keyboard(zm), id_read_line, 1, UINT2NUM(max - size) );

  for( i = 0; i < RSTRING_LEN(line); i++ ) {
    zchar c = *(RSTRING_PTR(line) + i);

    write_byte( zm, zm->zargs[0] + text_buffer_offset(zm) + size + i, 
      translate_to_zscii( zm->m, c ) );
  }

  if( h_version(zm) < 5 ) {
    write_byte( zm, zm->zargs[0] + text_buffer_offset(zm) + size + i, 0 );
  }

  if( h_version(zm) > 4 ) {
    write_byte( zm, zm->zargs[0] + 1, i );
  }

  /* write the parse table */

  if( zm->zargs[1] != 0 ) {
    write_parse_table( zm, line, zm->zargs[1], h_dictionary(zm), 0 );
  }

  /* echo the input back to the output */

  print_cstr( zm, "> " );
  print_rstr( zm, line );
  print_cstr( zm, "\n" );

  /* store the terminating character (if required) */

  if( h_version(zm) > 4 ) {
    p_store( zm, translate_to_zscii( zm->m, 10 ) );
  }
}
Esempio n. 2
0
void Processor::encode_text(int padding) {
	static const zchar again[] = { 'a', 'g', 'a', 'i', 'n', 0, 0, 0, 0 };
	static const zchar examine[] = { 'e', 'x', 'a', 'm', 'i', 'n', 'e', 0, 0 };
	static const zchar wait[] = { 'w', 'a', 'i', 't', 0, 0, 0, 0, 0 };

	zbyte *zchars;
	const zchar *ptr;
	zchar c;
	int i = 0;

	if (_resolution == 0) find_resolution();

	zchars = new byte[3 * (_resolution + 1)];
	ptr = _decoded;

	// Expand abbreviations that some old Infocom games lack
	if (_expand_abbreviations && (h_version <= V8)) {
		if (padding == 0x05 && _decoded[1] == 0) {
			switch (_decoded[0]) {
			case 'g': ptr = again; break;
			case 'x': ptr = examine; break;
			case 'z': ptr = wait; break;
			default: break;
			}
		}
	}

	// Translate string to a sequence of Z-characters
	while (i < 3 * _resolution) {
		if ((c = *ptr++) != 0) {
			int index, set;
			zbyte c2;

			if (c == ' ') {
				zchars[i++] = 0;
				continue;
			}

			// Search character in the alphabet
			for (set = 0; set < 3; set++)
				for (index = 0; index < 26; index++)
					if (c == alphabet (set, index))
						goto letter_found;

			// Character not found, store its ZSCII value
			c2 = translate_to_zscii(c);

			zchars[i++] = 5;
			zchars[i++] = 6;
			zchars[i++] = c2 >> 5;
			zchars[i++] = c2 & 0x1f;
			continue;

	letter_found:
			// Character found, store its index
			if (set != 0)
				zchars[i++] = ((h_version <= V2) ? 1 : 3) + set;

			zchars[i++] = index + 6;
		} else {
Esempio n. 3
0
void Processor::record_char(zchar c) {
	if (c != ZC_RETURN) {
		if (c < ZC_HKEY_MIN || c > ZC_HKEY_MAX) {
			record_code(translate_to_zscii(c), false);
			if (c == ZC_SINGLE_CLICK || c == ZC_DOUBLE_CLICK) {
				record_code(mouse_x, true);
				record_code(mouse_y, true);
			}
		} else {
			record_code(1000 + c - ZC_HKEY_MIN, true);
		}
	}
}
Esempio n. 4
0
static void record_char (zchar c)
{

    if (c != ZC_RETURN) {
	if (c < ZC_HKEY_MIN || c > ZC_HKEY_MAX) {
	    record_code (translate_to_zscii (c), FALSE);
	    if (c == ZC_SINGLE_CLICK || c == ZC_DOUBLE_CLICK) {
		record_code (mouse_x, TRUE);
		record_code (mouse_y, TRUE);
	    }
	} else record_code (1000 + c - ZC_HKEY_MIN, TRUE);
    }

}/* record_char */
Esempio n. 5
0
void Processor::z_read_char() {
	zchar key;

	// Supply default arguments
	if (zargc < 2)
		zargs[1] = 0;

	// Read input from the current input stream
	key = stream_read_key(
		zargs[1],	// timeout value
		zargs[2],	// timeout routine
		false  		// enable hot keys
	);

	if (key == ZC_BAD)
		return;

	// Store key
	store(translate_to_zscii(key));
}
Esempio n. 6
0
void memory_word (const zword *s)
{
    zword size;
    zword addr;
    zword c;

    if (h_version == V6) {

	int width = os_string_width (s);

	if (redirect[depth].xsize != 0xffff)

	    if (redirect[depth].width + width > redirect[depth].xsize) {

		if (*s == ' ' || *s == ZC_INDENT || *s == ZC_GAP)
		    width = os_string_width (++s);

		memory_new_line ();

	    }

	redirect[depth].width += width;

    }

    addr = redirect[depth].table;

    LOW_WORD (addr, size)
    addr += 2;

    while ((c = *s++) != 0)
	storeb ((zword) (addr + (size++)), translate_to_zscii (c));

    storew (redirect[depth].table, size);

}/* memory_word */
Esempio n. 7
0
void z_read_char( zmachine *zm ) {
  zchar c = NUM2UINT(rb_funcall( keyboard(zm), id_read_char, 0 ));
  p_store( zm, translate_to_zscii( zm->m, c ) );
}
Esempio n. 8
0
void Processor::z_read() {
	zchar buffer[INPUT_BUFFER_SIZE];
	zword addr;
	zchar key;
	zbyte max, size;
	zbyte c;
	int i;

	// Supply default arguments
	if (zargc < 3)
		zargs[2] = 0;

	// Get maximum input size
	addr = zargs[0];

	LOW_BYTE(addr, max);

	if (h_version <= V4)
		max--;

	if (max >= INPUT_BUFFER_SIZE)
		max = INPUT_BUFFER_SIZE - 1;

	// Get initial input size
	if (h_version >= V5) {
		addr++;
		LOW_BYTE(addr, size);
	} else {
		size = 0;
	}

	// Copy initial input to local buffer
	for (i = 0; i < size; i++) {
		addr++;
		LOW_BYTE(addr, c);
		buffer[i] = translate_from_zscii(c);
	}
	buffer[i] = 0;

	// Draw status line for V1 to V3 games
	if (h_version <= V3)
		z_show_status();

	// Read input from current input stream
	key = stream_read_input(
		max, buffer,		// buffer and size
		zargs[2],			// timeout value
		zargs[3],			// timeout routine
		false,				// enable hot keys
		h_version == V6		// no script in V6
	);

	if (key == ZC_BAD)
		return;

	// Perform save_undo for V1 to V4 games
	if (h_version <= V4)
		save_undo();

	// Copy local buffer back to dynamic memory
	for (i = 0; buffer[i] != 0; i++) {
		if (key == ZC_RETURN) {
			buffer[i] = unicode_tolower (buffer[i]);
		}

		storeb((zword)(zargs[0] + ((h_version <= V4) ? 1 : 2) + i), translate_to_zscii(buffer[i]));
	}

	// Add null character (V1-V4) or write input length into 2nd byte
	if (h_version <= V4)
		storeb((zword)(zargs[0] + 1 + i), 0);
	else
		storeb((zword)(zargs[0] + 1), i);

	// Tokenise line if a token buffer is present
	if (key == ZC_RETURN && zargs[1] != 0)
		tokenise_line (zargs[0], zargs[1], 0, false);

	// Store key
	if (h_version >= V5)
		store(translate_to_zscii(key));
}