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

#include <math.h>

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

#include "helper.h"
#include "and4.h"

int and4_initlog(void *arguments, void *logic)
{
	struct and4_args *args = (struct and4_args *)arguments;
	struct and4_logic *log = (struct and4_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.out_out,&log->out,&log->out_bit_mask))
		return -1;


	return 0;
}

void and4(void *arguments, void *logic)
{
	struct and4_logic *log = (struct and4_logic *)logic;
	u8 i;

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

	check_and_set_mask(i>=4,log->out,log->out_bit_mask);
}
