/*
 * or.c
 *
 *  Created on: 29-04-2014
 *      Author: KJ
 */


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

#include "or.h"

int or_initlog(void *arguments, void *logic)
{
	struct or_args *args = (struct or_args *)arguments;
	struct or_logic *log = (struct or_logic *)logic;

	log->out_ptr = log_manager.nets_data + (args->io.out >> 3);
	log->out_bit_mask = 1<<(args->io.out & 0x07);

	log->in1_ptr = log_manager.nets_data + (args->io.in1 >> 3);
	log->in1_bit_mask = 1<<(args->io.in1 & 0x07);

	log->in2_ptr = log_manager.nets_data + (args->io.in2 >> 3);
	log->in2_bit_mask = 1<<(args->io.in2 & 0x07);

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

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

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

	return 0;
}

void or(void *arguments, void *logic)
{
//	struct or_args *args = (struct or_args *)arguments;
	struct or_logic *log = (struct or_logic *)logic;

	if( (*log->in1_ptr & log->in1_bit_mask) ||  (*log->in2_ptr & log->in2_bit_mask) )
		*log->out_ptr|=log->out_bit_mask;
	else
		*log->out_ptr&=~log->out_bit_mask;
}
