Example #1
0
void Run_5MS_Task()
{

	if((GPIOC_PDIR & ((0x1<<8))) == 0)
	{
		if(Global_Flight_Mode != NO_CONNECTION)
		{
			debug_console("MSG,Flight Off Pressed\r\n");
			Global_Flight_Mode = RF_LINK_CONNECTED;
		}
	}
	Handle_Button_Presses();





}
Example #2
0
int test_if_code(int lognum) {
	int ec = true;
	int retval = true;
	uint8 op = 0;
	uint8 not_test = false;
	uint8 or_test = false;
	uint16 last_ip = ip;
	uint8 p[16] = { 0 };

	while (retval && !game.quit_prog_now) {
		if (debug_.enabled && (debug_.logic0 || lognum))
			debug_console(lognum, lTEST_MODE, NULL);

		last_ip = ip;
		op = *(code + ip++);
		memmove(p, (code + ip), 16);

		switch (op) {
		case 0xFF:	/* END IF, TEST true */
			goto end_test;
		case 0xFD:
			not_test = !not_test;
			continue;
		case 0xFC:	/* OR */
			/* if or_test is ON and we hit 0xFC, end of OR, then
			 * or is STILL false so break.
			 */
			if (or_test) {
				ec = false;
				retval = false;
				goto end_test;
			}

			or_test = true;
			continue;

		case 0x00:
			/* return true? */
			goto end_test;
		case 0x01:
			ec = test_equal(p[0], p[1]);
			if (p[0] == 11)
				timer_hack++;
			break;
		case 0x02:
			ec = test_equal(p[0], getvar(p[1]));
			if (p[0] == 11 || p[1] == 11)
				timer_hack++;
			break;
		case 0x03:
			ec = test_less(p[0], p[1]);
			if (p[0] == 11)
				timer_hack++;
			break;
		case 0x04:
			ec = test_less(p[0], getvar(p[1]));
			if (p[0] == 11 || p[1] == 11)
				timer_hack++;
			break;
		case 0x05:
			ec = test_greater(p[0], p[1]);
			if (p[0] == 11)
				timer_hack++;
			break;
		case 0x06:
			ec = test_greater(p[0], getvar(p[1]));
			if (p[0] == 11 || p[1] == 11)
				timer_hack++;
			break;
		case 0x07:
			ec = test_isset(p[0]);
			break;
		case 0x08:
			ec = test_isset(getvar(p[0]));
			break;
		case 0x09:
			ec = test_has(p[0]);
			break;
		case 0x0A:
			ec = test_obj_in_room(p[0], p[1]);
			break;
		case 0x0B:
			ec = test_posn(p[0], p[1], p[2], p[3], p[4]);
			break;
		case 0x0C:
			ec = test_controller(p[0]);
			break;
		case 0x0D:
			ec = test_keypressed();
			break;
		case 0x0E:
			ec = test_said(p[0], (uint8 *) code + (ip + 1));
			ip = last_ip;
			ip++;	/* skip opcode */
			ip += p[0] * 2;	/* skip num_words * 2 */
			ip++;	/* skip num_words opcode */
			break;
		case 0x0F:
			debugC(7, kDebugLevelScripts, "comparing [%s], [%s]", game.strings[p[0]], game.strings[p[1]]);
			ec = test_compare_strings(p[0], p[1]);
			break;
		case 0x10:
			ec = test_obj_in_box(p[0], p[1], p[2], p[3], p[4]);
			break;
		case 0x11:
			ec = test_obj_centre(p[0], p[1], p[2], p[3], p[4]);
			break;
		case 0x12:
			ec = test_obj_right(p[0], p[1], p[2], p[3], p[4]);
			break;
		default:
			ec = false;
			goto end_test;
		}

		if (op <= 0x12)
			ip += logic_names_test[op].num_args;

		/* exchange ec value */
		if (not_test)
			ec = !ec;

		/* not is only enabled for 1 test command */
		not_test = false;

		if (or_test && ec) {
			/* a true inside an OR statement passes
			 * ENTIRE statement scan for end of OR
			 */

			/* CM: test for opcode < 0xfc changed from 'op' to
			 *     '*(code+ip)', to avoid problem with the 0xfd (NOT)
			 *     opcode byte. Changed a bad ip += ... ip++ construct.
			 *     This should fix the crash with Larry's logic.0 code:
			 *
			 *     if ((isset(4) ||
			 *          !isset(2) ||
			 *          v30 == 2 ||
			 *          v30 == 1)) {
			 *       goto Label1;
			 *     }
			 *
			 *     The bytecode is: 
			 *     ff fc 07 04 fd 07 02 01 1e 02 01 1e 01 fc ff
			 */

			/* find end of OR */
			while (*(code + ip) != 0xFC) {
				if (*(code + ip) == 0x0E) {	/* said */
					ip++;
					/* cover count + ^words */
					ip += 1 + ((*(code + ip)) * 2);
					continue;
				}

				if (*(code + ip) < 0xFC)
					ip += logic_names_test[*(code + ip)].num_args;
				ip++;
			}
			ip++;

			or_test = false;
			retval = true;
		} else {
			retval = or_test ? retval || ec : retval && ec;
		}
	}
      end_test:

	/* if false, scan for end of IP? */
	if (retval)
		ip += 2;
	else {
		ip = last_ip;
		while (*(code + ip) != 0xff) {
			if (*(code + ip) == 0x0e) {
				ip++;
				ip += (*(code + ip)) * 2 + 1;
			} else if (*(code + ip) < 0xfc) {
				ip += logic_names_test[*(code + ip)].num_args;
				ip++;
			} else {
				ip++;
			}
		}
		ip++;		/* skip over 0xFF */
		ip += READ_LE_UINT16(code + ip) + 2;
	}

	if (debug_.enabled && (debug_.logic0 || lognum))
		debug_console(lognum, 0xFF, retval ? "=true" : "=false");

	return retval;
}
Example #3
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 #4
0
/*
 * ------------------------------------------------------------
 * receive_char ()
 *
 * This routine deals with inputs from any lines.
 * ------------------------------------------------------------
 */
static inline void dz_receive_chars(struct dz_port *dport)
{
	struct tty_struct *tty = NULL;
	struct uart_icount *icount;
	int ignore = 0;
	unsigned short status, tmp;
	unsigned char ch, flag;

	/* this code is going to be a problem...
	   the call to tty_flip_buffer is going to need
	   to be rethought...
	 */
	do {
		status = dz_in(dport, DZ_RBUF);

		/* punt so we don't get duplicate characters */
		if (!(status & DZ_DVAL))
			goto ignore_char;


		ch = UCHAR(status);	/* grab the char */
		flag = TTY_NORMAL;

#if 0
		if (info->is_console) {
			if (ch == 0)
				return;		/* it's a break ... */
		}
#endif

		tty = dport->port.info->tty;/* now tty points to the proper dev */
		icount = &dport->port.icount;

		if (!tty)
			break;
		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
			break;

		icount->rx++;

		/* keep track of the statistics */
		if (status & (DZ_OERR | DZ_FERR | DZ_PERR)) {
			if (status & DZ_PERR)	/* parity error */
				icount->parity++;
			else if (status & DZ_FERR)	/* frame error */
				icount->frame++;
			if (status & DZ_OERR)	/* overrun error */
				icount->overrun++;

			/*  check to see if we should ignore the character
			   and mask off conditions that should be ignored
			 */

			if (status & dport->port.ignore_status_mask) {
				if (++ignore > 100)
					break;
				goto ignore_char;
			}
			/* mask off the error conditions we want to ignore */
			tmp = status & dport->port.read_status_mask;

			if (tmp & DZ_PERR) {
				flag = TTY_PARITY;
#ifdef DEBUG_DZ
				debug_console("PERR\n", 5);
#endif
			} else if (tmp & DZ_FERR) {
				flag = TTY_FRAME;
#ifdef DEBUG_DZ
				debug_console("FERR\n", 5);
#endif
			}
			if (tmp & DZ_OERR) {
#ifdef DEBUG_DZ
				debug_console("OERR\n", 5);
#endif
				tty_insert_flip_char(tty, ch, flag);
				ch = 0;
				flag = TTY_OVERRUN;
			}
		}
		tty_insert_flip_char(tty, ch, flag);
	      ignore_char:
	} while (status & DZ_DVAL);

	if (tty)
		tty_flip_buffer_push(tty);
}

/*
 * ------------------------------------------------------------
 * transmit_char ()
 *
 * This routine deals with outputs to any lines.
 * ------------------------------------------------------------
 */
static inline void dz_transmit_chars(struct dz_port *dport)
{
	struct circ_buf *xmit = &dport->port.info->xmit;
	unsigned char tmp;

	if (dport->port.x_char) {	/* XON/XOFF chars */
		dz_out(dport, DZ_TDR, dport->port.x_char);
		dport->port.icount.tx++;
		dport->port.x_char = 0;
		return;
	}
	/* if nothing to do or stopped or hardware stopped */
	if (uart_circ_empty(xmit) || uart_tx_stopped(&dport->port)) {
		dz_stop_tx(&dport->port, 0);
		return;
	}

	/*
	 * if something to do ... (rember the dz has no output fifo so we go
	 * one char at a time :-<
	 */
	tmp = xmit->buf[xmit->tail];
	xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1);
	dz_out(dport, DZ_TDR, tmp);
	dport->port.icount.tx++;

	if (uart_circ_chars_pending(xmit) < DZ_WAKEUP_CHARS)
		uart_write_wakeup(&dport->port);

	/* Are we done */
	if (uart_circ_empty(xmit))
		dz_stop_tx(&dport->port, 0);
}

/*
 * ------------------------------------------------------------
 * check_modem_status ()
 *
 * Only valid for the MODEM line duh !
 * ------------------------------------------------------------
 */
static inline void check_modem_status(struct dz_port *dport)
{
	unsigned short status;

	/* if not ne modem line just return */
	if (dport->port.line != DZ_MODEM)
		return;

	status = dz_in(dport, DZ_MSR);

	/* it's easy, since DSR2 is the only bit in the register */
	if (status)
		dport->port.icount.dsr++;
}
Example #5
0
/*
 * ------------------------------------------------------------
 * receive_char ()
 *
 * This routine deals with inputs from any lines.
 * ------------------------------------------------------------
 */
static inline void receive_chars(struct dz_serial *info_in)
{

	struct dz_serial *info;
	struct tty_struct *tty = 0;
	struct async_icount *icount;
	int ignore = 0;
	unsigned short status, tmp;
	unsigned char ch;

	/* this code is going to be a problem...
	   the call to tty_flip_buffer is going to need
	   to be rethought...
	 */
	do {
		status = dz_in(info_in, DZ_RBUF);
		info = lines[LINE(status)];

		/* punt so we don't get duplicate characters */
		if (!(status & DZ_DVAL))
			goto ignore_char;

		ch = UCHAR(status);	/* grab the char */

#if 0
		if (info->is_console) {
			if (ch == 0)
				return;	/* it's a break ... */
		}
#endif

		tty = info->tty;	/* now tty points to the proper dev */
		icount = &info->icount;

		if (!tty)
			break;
		if (tty->flip.count >= TTY_FLIPBUF_SIZE)
			break;

		*tty->flip.char_buf_ptr = ch;
		*tty->flip.flag_buf_ptr = 0;
		icount->rx++;

		/* keep track of the statistics */
		if (status & (DZ_OERR | DZ_FERR | DZ_PERR)) {
			if (status & DZ_PERR)	/* parity error */
				icount->parity++;
			else if (status & DZ_FERR)	/* frame error */
				icount->frame++;
			if (status & DZ_OERR)	/* overrun error */
				icount->overrun++;

			/*  check to see if we should ignore the character
			   and mask off conditions that should be ignored
			 */

			if (status & info->ignore_status_mask) {
				if (++ignore > 100)
					break;
				goto ignore_char;
			}
			/* mask off the error conditions we want to ignore */
			tmp = status & info->read_status_mask;

			if (tmp & DZ_PERR) {
				*tty->flip.flag_buf_ptr = TTY_PARITY;
#ifdef DEBUG_DZ
				debug_console("PERR\n", 5);
#endif
			} else if (tmp & DZ_FERR) {
				*tty->flip.flag_buf_ptr = TTY_FRAME;
#ifdef DEBUG_DZ
				debug_console("FERR\n", 5);
#endif
			}
			if (tmp & DZ_OERR) {
#ifdef DEBUG_DZ
				debug_console("OERR\n", 5);
#endif
				if (tty->flip.count < TTY_FLIPBUF_SIZE) {
					tty->flip.count++;
					tty->flip.flag_buf_ptr++;
					tty->flip.char_buf_ptr++;
					*tty->flip.flag_buf_ptr = TTY_OVERRUN;
				}
			}
		}
		tty->flip.flag_buf_ptr++;
		tty->flip.char_buf_ptr++;
		tty->flip.count++;
	      ignore_char:
	} while (status & DZ_DVAL);

	if (tty)
		tty_flip_buffer_push(tty);
}

/*
 * ------------------------------------------------------------
 * transmit_char ()
 *
 * This routine deals with outputs to any lines.
 * ------------------------------------------------------------
 */
static inline void transmit_chars(struct dz_serial *info)
{
	unsigned char tmp;



	if (info->x_char) {	/* XON/XOFF chars */
		dz_out(info, DZ_TDR, info->x_char);
		info->icount.tx++;
		info->x_char = 0;
		return;
	}
	/* if nothing to do or stopped or hardware stopped */
	if ((info->xmit_cnt <= 0) || info->tty->stopped || info->tty->hw_stopped) {
		dz_stop(info->tty);
		return;
	}
	/*
	 * if something to do ... (rember the dz has no output fifo so we go
	 * one char at a time :-<
	 */
	tmp = (unsigned short) info->xmit_buf[info->xmit_tail++];
	dz_out(info, DZ_TDR, tmp);
	info->xmit_tail = info->xmit_tail & (DZ_XMIT_SIZE - 1);
	info->icount.tx++;

	if (--info->xmit_cnt < WAKEUP_CHARS)
		dz_sched_event(info, DZ_EVENT_WRITE_WAKEUP);


	/* Are we done */
	if (info->xmit_cnt <= 0)
		dz_stop(info->tty);
}