Example #1
0
static int picviewer_get_key ()
{
	int key;

	/* clear key queue */
	while (keypress ()) { get_key (); }

	_D (_D_WARN "waiting...");
	while (42) {
		poll_timer ();
		key = do_poll_keyboard ();
		if (key) break;
	}

	return key;
}
Example #2
0
int wait_any_key ()
{
	int key;

	/* clear key queue */
	while (keypress ()) { get_key (); }

	_D (_D_WARN "waiting...");
	while (42) {
		poll_timer ();		/* msdos driver -> does nothing */
		key = do_poll_keyboard ();
		if (!console_keyhandler (key) && key)
				break;
		console_cycle ();
	}
	return key;
}
Example #3
0
int wait_key ()
{
	int key;

	/* clear key queue */
	while (keypress ()) { get_key (); }

	_D (_D_WARN "waiting...");
	while (42) {
		poll_timer ();		/* msdos driver -> does nothing */
		key = do_poll_keyboard ();
		if (!console_keyhandler (key)) {
			if (key == KEY_ENTER || key == KEY_ESCAPE
#ifdef USE_MOUSE
				|| key == BUTTON_LEFT
#endif
				)
				break;
		}
		console_cycle ();
	}
	return key;
}
Example #4
0
static int select_slot (char *path)
{
	int i, key, active = 0;
	int rc = -1;
	int hm = 2, vm = 3;			/* box margins */
	char desc[NUM_SLOTS][40];

	for (i = 0; i < NUM_SLOTS; i++) {
		char name[MAX_PATH];
		FILE *f;
		char sig[8];
		sprintf (name, "%s/%08d.sav", path, i);
		f = fopen (name, "rb");
		if (f == NULL) {
			strcpy (desc[i], "          (empty slot)");
		} else {
			read_bytes (f, sig, 8);
			if (strncmp (sig, strSig, 8)) {
				strcpy (desc[i], "(corrupt file)");
			} else {
				read_string (f, desc[i]);
			}
			fclose(f);
		}
	}

	while (42) {
		char dstr[64];
		for (i = 0; i < NUM_SLOTS; i++) {
			sprintf (dstr, "[%-32.32s]", desc[i]);
			print_text (dstr, 0, hm + 1, vm + 4 + i,
				(40 - 2 * hm) - 1,
				i == active ? MSG_BOX_COLOUR : MSG_BOX_TEXT,
				i == active ? MSG_BOX_TEXT : MSG_BOX_COLOUR);

		}

		poll_timer ();		/* msdos driver -> does nothing */
		key = do_poll_keyboard ();
		if (!console_keyhandler (key)) {
			switch (key) {
			case KEY_ENTER:
				rc = active;
				strncpy (game.strings[MAX_STRINGS],
					desc[i], MAX_STRINGLEN);
				goto press;
			case KEY_ESCAPE:
				rc = -1;
				goto getout;
#ifdef USE_MOUSE
			case BUTTON_LEFT:
				break;
#endif
			case KEY_DOWN:
				active++;
				active %= NUM_SLOTS;
				break;
			case KEY_UP:
				active--;
				if (active < 0)
					active = NUM_SLOTS - 1;
				break;
			}
		}
		console_cycle ();
	}

press:
	_D (_D_WARN "Button pressed: %d", rc);

getout:
	close_window();
	return rc;
}
Example #5
0
/* If main_cycle returns false, don't process more events! */
int main_cycle() {
	unsigned int key, kascii;
	struct vt_entry *v = &game.view_table[0];

	poll_timer();		/* msdos driver -> does nothing */
	update_timer();

	if (game.ver == 0) {
		_text->message_box("Warning: game CRC not listed, assuming AGI version 2.917.");
		game.ver = -1;
	}

	key = do_poll_keyboard();

	/* In AGI Mouse emulation mode we must update the mouse-related
	 * vars in every interpreter cycle.
	 */
	if (opt.agimouse) {
		game.vars[28] = mouse.x / 2;
		game.vars[29] = mouse.y;
	}

	if (key == KEY_PRIORITY) {
		_sprites->erase_both();
		debug_.priority = !debug_.priority;
		show_pic();
		_sprites->blit_both();
		_sprites->commit_both();
		key = 0;
	}

	if (key == KEY_STATUSLN) {
		debug_.statusline = !debug_.statusline;
		_text->write_status();
		key = 0;
	}

	/* Click-to-walk mouse interface */
	if (game.player_control && v->flags & ADJ_EGO_XY) {
		v->direction = get_direction(v->x_pos, v->y_pos, v->parm1, v->parm2, v->step_size);

		if (v->direction == 0)
			in_destination(v);
	}

	kascii = KEY_ASCII(key);

	if (kascii)
		setvar(V_key, kascii);
	process_key:
	switch (game.input_mode) {
	case INPUT_NORMAL:
		if (!handle_controller(key)) {
			if (key == 0 || !game.input_enabled)
				break;
			handle_keys(key);

			/* if ESC pressed, activate menu before
			 * accept.input from the interpreter cycle
			 * sets the input mode to normal again
			 * (closes: #540856)
			 */
			if (key == KEY_ESCAPE) {
				key = 0;
				goto process_key;
			}

			/* commented out to close bug #438872
			 * if (key) game.keypress = key;
			 */
		}
		break;
	case INPUT_GETSTRING:
		handle_controller(key);
		handle_getstring(key);
		setvar(V_key, 0);	/* clear ENTER key */
		break;
	case INPUT_MENU:
		menu->keyhandler(key);
		do_update();
		return false;
	case INPUT_NONE:
		handle_controller(key);
		if (key)
			game.keypress = key;
		break;
	}

	do_update();

	if (game.msg_box_ticks > 0)
		game.msg_box_ticks--;

	return true;
}
Example #6
0
/**
 * Execute a logic script
 * @param n  Number of the logic resource to execute
 */
int run_logic (int n)
{
	UINT8 op = 0;
	UINT8 p[CMD_BSIZE] = { 0 };
	UINT8 *code = NULL;
	int num	= 0;

	/* If logic not loaded, load it */
	if (~game.dir_logic[n].flags & RES_LOADED) {
		_D (_D_WARN "logic %d not loaded!", n);
		agi_load_resource (rLOGIC, n);
	}

	game.lognum = n;
	cur_logic = &game.logics[game.lognum];

	code = cur_logic->data;
	cur_logic->cIP = cur_logic->sIP;

	timer_hack = 0;
	while (ip < game.logics[n].size && !game.quit_prog_now) {
#ifdef USE_CONSOLE
		if (debug.enabled) {
			if (debug.steps > 0) {
				if (debug.logic0 || n) {
					debug_console (n,
						lCOMMAND_MODE, NULL);
					debug.steps--;
				}
			} else {
				blit_both ();
				console_prompt ();
				do {
					main_cycle ();
				} while (!debug.steps && debug.enabled);
				console_lock ();
				erase_both ();
			}
		}
#endif

		switch (op = *(code + ip++)) {
		case 0xff:			/* if (open/close) */
			test_if_code (n);
			break;
		case 0xfe:			/* goto */
			/* +2 covers goto size */
			ip += 2 + ((SINT16)lohi_getword (code + ip));
			/* timer must keep running even in goto loops,
			 * but Sarien can't do that :(
			 */
			if (timer_hack > 20) {
				poll_timer ();
				update_timer ();
				timer_hack = 0;
			}
			break;
		case 0x00:			/* return */
			return 1;
		default:
			num = logic_names_cmd[op].num_args;
			memmove (p, code + ip, num);
			memset (p + num, 0, CMD_BSIZE - num);
			agi_command[op](p);
			ip += num;
		}

		if (game.exit_all_logics)
			break;
	}

	return 0;	/* after executing new.room() */
}
Example #7
0
/**
 * Display a message box with buttons.
 * This function displays the specified message in a text box
 * centered in the screen and waits until a button is pressed.
 * @param p The text to be displayed
 * @param b NULL-terminated list of button labels
 */
int TextMan::selection_box(const char *m, const char **b) {
	int x, y, i, s;
	int key, active = 0;
	int rc = -1;
	int bx[5], by[5];

	_sprites->erase_both();
	blit_textbox(m, -1, -1, -1);

	x = game.window.x1 + 5 * CHAR_COLS / 2;
	y = game.window.y2 - 5 * CHAR_LINES / 2;
	s = game.window.x2 - game.window.x1 + 1 - 5 * CHAR_COLS;
	debugC(3, kDebugLevelText, "s = %d", s);

	/* Automatically position buttons */
	for (i = 0; b[i]; i++) {
		s -= CHAR_COLS * strlen(b[i]);
	}

	if (i > 1) {
		debugC(3, kDebugLevelText, "s / %d = %d", i - 1, s / (i - 1));
		s /= (i - 1);
	} else {
		x += s / 2;
	}

	for (i = 0; b[i]; i++) {
		bx[i] = x;
		by[i] = y;
		x += CHAR_COLS * strlen(b[i]) + s;
	}

	_sprites->blit_both();

	/* clear key queue */
	while (keypress()) {
		get_key();
	}

	debugC(4, kDebugLevelText, "waiting...");
	while (42) {
		for (i = 0; b[i]; i++)
			draw_button(bx[i], by[i], b[i], i == active, 0);

		poll_timer();	/* msdos driver -> does nothing */
		key = do_poll_keyboard();
		switch (key) {
		case KEY_ENTER:
			rc = active;
			goto press;
		case KEY_ESCAPE:
			rc = -1;
			goto getout;
		case BUTTON_LEFT:
			for (i = 0; b[i]; i++) {
				if (test_button(bx[i], by[i], b[i])) {
					rc = active = i;
					goto press;
				}
			}
			break;
		case 0x09:	/* Tab */
			debugC(3, kDebugLevelText, "Focus change");
			active++;
			active %= i;
			break;
		}
		do_update();
	}

      press:
	debugC(4, kDebugLevelText, "Button pressed: %d", rc);

      getout:
	close_window();
	debugC(2, kDebugLevelText, "Result = %d", rc);

	return rc;
}