コード例 #1
0
ファイル: text.cpp プロジェクト: iPodLinux-Community/iScummVM
int TextMan::print(const char *p, int lin, int col, int len) {
	if (p == NULL)
		return 0;

	debugC(4, kDebugLevelText, "lin = %d, col = %d, len = %d", lin, col, len);

	if (col == 0 && lin == 0 && len == 0)
		lin = col = -1;

	if (len == 0)
		len = 30;

	blit_textbox(p, lin, col, len);

	if (getflag(F_output_mode)) {
		/* non-blocking window */
		setflag(F_output_mode, false);
		return 1;
	}

	/* blocking */

	if (game.vars[V_window_reset] == 0) {
		int k;
		setvar(V_key, 0);
		k = wait_key();
		close_window();
		return k;
	}

	/* timed window */

	debugC(3, kDebugLevelText, "f15==0, v21==%d => timed", getvar(21));
	game.msg_box_ticks = getvar(V_window_reset) * 10;
	setvar(V_key, 0);

	do {
		main_cycle();
		if (game.keypress == KEY_ENTER) {
			debugC(4, kDebugLevelText, "KEY_ENTER");
			setvar(V_window_reset, 0);
			game.keypress = 0;
			break;
		}
	} while (game.msg_box_ticks > 0);

	setvar(V_window_reset, 0);

	close_window();

	return 0;
}
コード例 #2
0
ファイル: agi.cpp プロジェクト: iPodLinux-Community/iScummVM
int AgiEngine::go() {
	CursorMan.showMouse(true);

	report(" \nAGI engine " VERSION " is ready.\n");
	if (game.state < STATE_LOADED) {
		do {
			main_cycle();
		} while (game.state < STATE_RUNNING);
		if (game.ver < 0)
			game.ver = 0;	/* Enable conf file warning */
	}

	run_game();

	return 0;
}
コード例 #3
0
static uint8 test_keypressed() {
	int x = game.keypress;

	game.keypress = 0;
	if (!x) {
		int mode = game.input_mode;
		game.input_mode = INPUT_NONE;
		main_cycle();
		game.input_mode = mode;
	}

	if (x)
		debugC(5, kDebugLevelScripts | kDebugLevelInput, "keypress = %02x", x);

	return x;
}
コード例 #4
0
ファイル: op_test.c プロジェクト: SimonKagstrom/sarien-j2me
static UINT8 test_keypressed ()
{
    int x = game.keypress;

    game.keypress = 0;
    if (!x) {
        int mode = game.input_mode;
        game.input_mode = INPUT_NONE;
        main_cycle ();
        game.input_mode = mode;
    }

    if (x) _D (_D_WARN "keypress = %02x", x);

    return x;
}
コード例 #5
0
ファイル: snake.c プロジェクト: ga2arch/Snake
int main(void)
{
	ps.lose = 0;
	ps.points = 0;
	srand(time(NULL));
	if (screen_init(&ps))
		return 1;
	grid_init(&ps);
	while (!ps.lose) {
		if (!main_cycle(&ps))
			break;
	}
	freelist(ps.s);
	screen_end(&ps);
	return 0;
}
コード例 #6
0
ファイル: savegame.c プロジェクト: UIKit0/sarien
int savegame_dialog ()
{
	char home[MAX_PATH], path[MAX_PATH];
	char *desc;
	char *buttons[] = { "Do as I say!", "I regret", NULL }; 
	char dstr[200];
	int rc, slot = 0;
	int hm, vm, hp, vp;			/* box margins */
	int w;

	hm = 2; vm = 3;
	hp = hm * CHAR_COLS; vp = vm * CHAR_LINES;
	w = (40 - 2 * hm) - 1;

	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Couldn't save game.");
		return err_BadFileOpen;
	}
	/* DATADIR conflicts with ObjIdl.h in win32 SDK, renamed to DATA_DIR */
	sprintf (path, "%s/" DATA_DIR "/", home);
	MKDIR (path, 0755);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
	MKDIR (path, 0711);

	erase_both ();

	draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
	print_text ("Select a slot in which you wish to save the game:",
		0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	print_text ("Press ENTER to select, ESC cancels",
		0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);

	slot = select_slot (path);
	if (slot < 0)	/* ESC pressed */
		return err_OK;

	/* Get savegame description */
	draw_window (hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp,
		GFX_HEIGHT - vp - 9 * CHAR_LINES);
	print_text ("Enter a description for this game:",
		0, hm + 1, vm + 6, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	draw_rectangle (3 * CHAR_COLS, 11 * CHAR_LINES - 1,
		37 * CHAR_COLS, 12 * CHAR_LINES, MSG_BOX_TEXT);
	flush_block (3 * CHAR_COLS, 11 * CHAR_LINES - 1,
		37 * CHAR_COLS, 12 * CHAR_LINES);

	get_string (2, 11, 33, MAX_STRINGS);
	print_character (3, 11, game.cursor_char, MSG_BOX_COLOUR, MSG_BOX_TEXT);
        do { main_cycle (); } while (game.input_mode == INPUT_GETSTRING);
	close_window ();

 	desc = game.strings[MAX_STRINGS];

	sprintf (dstr, "Are you sure you want to save the game "
		"described as:\n\n%s\n\nin slot %d?\n\n\n",
		desc, slot);

	rc = selection_box (dstr, buttons);

	if (rc != 0) {
		message_box ("Game NOT saved.");
		return err_OK;
	}

	sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, slot);
	_D (_D_WARN "file is [%s]", path);
	
	save_game (path, desc);

	message_box ("Game saved.");

	return err_OK;
}
コード例 #7
0
ファイル: savegame.c プロジェクト: SimonKagstrom/sarien-j2me
int savegame_dialog ()
{
#ifndef PALMOS /* FIXME */
	char home[MAX_PATH], path[MAX_PATH];
	char *desc;
	char *buttons[] = { "Do as I say!", "I regret", NULL }; 
	char dstr[200];
	int rc, slot = 0;
	int hm, vm, hp, vp;			/* box margins */
	int w;

	hm = 2; vm = 3;
	hp = hm * CHAR_COLS; vp = vm * CHAR_LINES;
	w = (40 - 2 * hm) - 1;

#ifdef DREAMCAST
	uint8 addr, port, unit;

	addr = maple_first_vmu();
	if(addr) {
		maple_create_port(addr, &port, &unit);
		sprintf(g_vmu_port, "%c%d", port + 'a', unit);
	} else {
		message_box("No VMU found.");
		return err_OK;
	}
#else
	if (get_app_dir (home, MAX_PATH) < 0) {
		message_box ("Couldn't save game.");
		return err_BadFileOpen;
	}
# ifdef CIBYL
	sprintf (path, "recordstore://%05X.%s:",
		game.crc, game.id);
# else
	/* DATADIR conflicts with ObjIdl.h in win32 SDK, renamed to DATA_DIR */
	sprintf (path, "%s/" DATA_DIR "/", home);
	MKDIR (path, 0755);
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id);
	MKDIR (path, 0711);
# endif
#endif

	erase_both ();

	draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp);
	print_text ("Select a slot in which you wish to save the game:",
		0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	print_text ("Press ENTER to select, ESC cancels",
		0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);

	slot = select_slot (path);
	if (slot < 0)	/* ESC pressed */
		return err_OK;

	/* Get savegame description */
	draw_window (hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp,
		GFX_HEIGHT - vp - 9 * CHAR_LINES);
	print_text ("Enter a description for this game:",
		0, hm + 1, vm + 6, w, MSG_BOX_TEXT, MSG_BOX_COLOUR);
	draw_rectangle (3 * CHAR_COLS, 11 * CHAR_LINES - 1,
		37 * CHAR_COLS, 12 * CHAR_LINES, MSG_BOX_TEXT);
	flush_block (3 * CHAR_COLS, 11 * CHAR_LINES - 1,
		37 * CHAR_COLS, 12 * CHAR_LINES);

	get_string (2, 11, 33, MAX_STRINGS);
	print_character (3, 11, game.cursor_char, MSG_BOX_COLOUR, MSG_BOX_TEXT);
        do { main_cycle (); } while (game.input_mode == INPUT_GETSTRING);
	close_window ();

 	desc = game.strings[MAX_STRINGS];

	sprintf (dstr, "Are you sure you want to save the game "
		"described as:\n\n%s\n\nin slot %d?\n\n\n",
		desc, slot);

	rc = selection_box (dstr, buttons);

	if (rc != 0) {
		message_box ("Game NOT saved.");
		return err_OK;
	}

#ifdef DREAMCAST
	sprintf(path, VMU_PATH, g_vmu_port, game.id, slot);
	fs_unlink(path);
#elif CIBYL
	sprintf (path, "recordstore://%05X.%s:%d",
		game.crc, game.id, slot+1);
        printf("path: %s\n", path);
#else
	sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav",
		home, game.crc, game.id, slot);
#endif
	_D (_D_WARN "file is [%s]", path);
	
	save_game (path, desc);

	message_box ("Game saved.");
#endif /* PALMOS */

	return err_OK;
}
コード例 #8
0
static int play_game() {
	int ec = err_OK;

	debugC(2, kDebugLevelMain, "initializing...");
	debugC(2, kDebugLevelMain, "game.ver = 0x%x", game.ver);

	stop_sound();
	clear_screen(0);

	game.horizon = HORIZON;
	game.player_control = false;

	setflag(F_logic_zero_firsttime, true);	/* not in 2.917 */
	setflag(F_new_room_exec, true);	/* needed for MUMG and SQ2! */
	setflag(F_sound_on, true);	/* enable sound */
	setvar(V_time_delay, 2);	/* "normal" speed */

	game.gfx_mode = true;
	game.quit_prog_now = false;
	game.clock_enabled = true;
	game.line_user_input = 22;

	if (opt.agimouse)
		report("Using AGI Mouse 1.0 protocol\n");

	report("Running AGI script.\n");

	setflag(F_entered_cli, false);
	setflag(F_said_accepted_input, false);
	game.vars[V_word_not_found] = 0;
	game.vars[V_key] = 0;

	debugC(2, kDebugLevelMain, "Entering main loop");
	do {

		if (!main_cycle())
			continue;

		if (getvar(V_time_delay) == 0 ||
		    (1 + clock_count) % getvar(V_time_delay) == 0) {
			if (!game.has_prompt && game.input_mode == INPUT_NORMAL) {
				_text->write_prompt();
				game.has_prompt = 1;
			} else
			    if (game.has_prompt && game.input_mode == INPUT_NONE) {
				_text->write_prompt();
				game.has_prompt = 0;
			}

			interpret_cycle();

			setflag(F_entered_cli, false);
			setflag(F_said_accepted_input, false);
			game.vars[V_word_not_found] = 0;
			game.vars[V_key] = 0;
		}

		if (game.quit_prog_now == 0xff)
			ec = err_RestartGame;

	} while (game.quit_prog_now == 0);

	stop_sound();

	return ec;
}
コード例 #9
0
ファイル: op_cmd.c プロジェクト: UIKit0/sarien
/**
 * 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() */
}
コード例 #10
0
ファイル: main.c プロジェクト: SimonKagstrom/sarien-j2me
int main (int argc, char *argv[])
{
	int ec;

	MaxApplZone ();

	game.clock_enabled = FALSE;
	game.state = STATE_INIT;

	init_machine (argc, argv);

	game.color_fg = 15;
	game.color_bg = 0;

	if ((game.sbuf = calloc (_WIDTH, _HEIGHT)) == NULL) {
		ec = err_NotEnoughMemory;
		goto bail_out;
	}
#ifdef USE_HIRES
	if ((game.hires = calloc (_WIDTH * 2, _HEIGHT)) == NULL) {
		ec = err_NotEnoughMemory;
		goto bail_out_2;
	};
	opt.hires = 1;
#endif

	if (init_sprites () != err_OK) {
		ec = err_NotEnoughMemory;
		goto bail_out_3;
	}

	if (init_video () != err_OK) {
		ec = err_Unk;
		goto bail_out_4;
	}

	console_init ();
	report ("--- Starting console ---\n\n");

	_D ("Init sound");
	init_sound ();

	game.ver = -1;		/* Disable conf file warning */

	report (" \nSarien " VERSION " is ready.\n");
	if (game.state < STATE_LOADED) {
       		console_prompt ();
		do { main_cycle (); } while (game.state < STATE_RUNNING);
		if (game.ver < 0)
			game.ver = 0;	/* Enable conf file warning */
	}

	ec = run_game ();

	deinit_sound ();
	deinit_video ();

bail_out_4:
	deinit_sprites ();
bail_out_3:
#ifdef USE_HIRES
	free (game.hires);
#endif
bail_out_2:
	free (game.sbuf);
bail_out:
	if (ec == err_OK || ec == err_DoNothing) {
		deinit_machine ();
		exit (ec);
	}

	deinit_machine ();

	return ec;
}