/*
 * or8.c
 *
 *  Created on: 15-02-2017
 *      Author: Krzysztof Jakubczyk
 */

#include <math.h>

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

#include "helper.h"
#include "or8.h"

int or8_initlog(void *arguments, void *logic)
{
	struct or8_args *args = (struct or8_args *)arguments;
	struct or8_logic *log = (struct or8_logic *)logic;

	if(set_bit_ptr_mask(args->io.in1_in,&log->in[0],&log->in_bit_mask[0]))
		return -1;
	if(set_bit_ptr_mask(args->io.in2_in,&log->in[1],&log->in_bit_mask[1]))
		return -1;
	if(set_bit_ptr_mask(args->io.in3_in,&log->in[2],&log->in_bit_mask[2]))
		return -1;
	if(set_bit_ptr_mask(args->io.in4_in,&log->in[3],&log->in_bit_mask[3]))
		return -1;
	if(set_bit_ptr_mask(args->io.in5_in,&log->in[4],&log->in_bit_mask[4]))
		return -1;
	if(set_bit_ptr_mask(args->io.in6_in,&log->in[5],&log->in_bit_mask[5]))
		return -1;
	if(set_bit_ptr_mask(args->io.in7_in,&log->in[6],&log->in_bit_mask[6]))
		return -1;
	if(set_bit_ptr_mask(args->io.in8_in,&log->in[7],&log->in_bit_mask[7]))
		return -1;
	if(set_bit_ptr_mask(args->io.out_out,&log->out,&log->out_bit_mask))
		return -1;


	return 0;
}

void or8(void *arguments, void *logic)
{
	struct or8_logic *log = (struct or8_logic *)logic;
	u8 i;

	for(i=0;i<8;i++)
		if(*log->in[i] & log->in_bit_mask[i])
			break;

	check_and_set_mask(i<8,log->out,log->out_bit_mask);
}
