/*
 * event.c
 *
 *  Created on: 21-05-2014
 *      Author: KJ
 */


#include "tdefs.h"
#include "misc.h"

#include "event.h"
#include "events_reg.h"

int event_initlog(void *arguments, void *logic)
{
	struct event_args *args = (struct event_args *)arguments;
	struct event_logic *log = (struct event_logic *)logic;

	log->in_ptr = log_manager.nets_data + (args->io.in >> 3);
	log->in_bit_no = args->io.in & 0x07;

	if(log->in_ptr >= (log_manager.nets_data+sizeof(log_manager.nets_data)))
		return -1;

	if(args->params.fun==0)
		log->prev_state = (saved_events[(args->params.inf&0x7F)>>3] & (1<<(args->params.inf%8)))? 1 : 0;
	else
		log->prev_state = (*log->in_ptr & (1<<log->in_bit_no)) ? 1 : 0;

	return 0;
}

