/*
 *
 * Copyright © 1996 Norlinvest Ltd. All rights reserved.
 * EDComX, EDSpice, EDWin, EE Designer, CompCAD, CAD 1000,
 * CAD ABC and Visionics are trade marks of Norlinvest Ltd.
 * Copyright © 1983 - 2003.
 *
 */

#include "cm.h"
#include "dlldef.h"

extern double CurrTime;

// ANDs

void fnVhdlAnd2(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE) *CurrOutput = ONE;
   else                               *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd3(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE) *CurrOutput = ONE;
   else                                                *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd4(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t *CurrOutput,Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE &&
      Input3 == ONE && Input4 == ONE)    *CurrOutput = ONE;
   else                                  *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd5(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd6(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd7(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd8(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd9(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd10(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd11(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd12(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd13(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd14(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13, Digital_State_t Input14,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE && Input14 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd15(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE && Input14 == ONE && Input15 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlAnd16(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
                Digital_State_t Input16,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE && Input14 == ONE && Input15 == ONE &&
      Input16 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// NANDs

void fnVhdlNand2(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t *CurrOutput,
                 Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand3(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand4(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE && Input4 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand5(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t *CurrOutput,
                 Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand6(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand7(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand8(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand9(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand10(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand11(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10, Digital_State_t Input11,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand12(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand13(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                 Digital_State_t Input13,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand14(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                 Digital_State_t Input13, Digital_State_t Input14,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE && Input14 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand15(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                 Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE && Input14 == ONE && Input15 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNand16(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                 Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                 Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                 Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
                 Digital_State_t Input16,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL)
{
   if(Input1 == ONE && Input2 == ONE && Input3 == ONE &&
      Input4 == ONE && Input5 == ONE && Input6 == ONE &&
      Input7 == ONE && Input8 == ONE && Input9 == ONE &&
      Input10 == ONE && Input11 == ONE && Input12 == ONE &&
      Input13 == ONE && Input14 == ONE && Input15 == ONE &&
      Input16 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// ORs

void fnVhdlOr2(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t *CurrOutput,
               Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr3(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr4(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE || Input4 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr5(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t *CurrOutput,
               Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr6(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr7(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr8(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr9(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr10(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr11(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10, Digital_State_t Input11,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr12(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr13(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
               Digital_State_t Input13,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr14(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
               Digital_State_t Input13, Digital_State_t Input14,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE || Input14 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr15(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
               Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE || Input14 == ONE || Input15 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlOr16(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
               Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
               Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
               Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
               Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
               Digital_State_t Input16,
               Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input9 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE || Input14 == ONE || Input15 == ONE ||
      Input16 == ONE)
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// NORs

void fnVhdlNor2(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor3(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor4(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE || Input4 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor5(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor6(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor7(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor8(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor9(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor10(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor11(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor12(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor13(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor14(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13, Digital_State_t Input14,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE || Input14 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor15(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE || Input14 == ONE || Input15 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlNor16(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t Input6,
                Digital_State_t Input7, Digital_State_t Input8, Digital_State_t Input9,
                Digital_State_t Input10, Digital_State_t Input11, Digital_State_t Input12,
                Digital_State_t Input13, Digital_State_t Input14, Digital_State_t Input15,
                Digital_State_t Input16,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL)
{
   if(Input1 == ONE || Input2 == ONE || Input3 == ONE ||
      Input4 == ONE || Input5 == ONE || Input6 == ONE ||
      Input7 == ONE || Input8 == ONE || Input9 == ONE ||
      Input10 == ONE || Input11 == ONE || Input12 == ONE ||
      Input13 == ONE || Input14 == ONE || Input15 == ONE ||
      Input16 == ONE)
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// XORs

void fnVhdlXor2(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE) || (Input1 == ZERO && Input2 == ZERO))
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlXor3(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE && Input3 == ONE) ||
      (Input1 == ZERO && Input2 == ZERO && Input3 == ZERO))
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlXor4(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE && Input3 == ONE && Input4 == ONE) ||
      (Input1 == ZERO && Input2 == ZERO && Input3 == ZERO && Input4 == ZERO))
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlXor5(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                Digital_State_t Input4, Digital_State_t Input5, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE && Input3 == ONE && Input4 == ONE && Input5 == ONE) ||
      (Input1 == ZERO && Input2 == ZERO && Input3 == ZERO && Input4 == ZERO && Input5 == ZERO))
      *CurrOutput = ZERO;
   else
      *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// XNORs

void fnVhdlXnor2(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t *CurrOutput,
                 Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE) || (Input1 == ZERO && Input2 == ZERO))
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlXnor3(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE && Input3 == ONE) ||
      (Input1 == ZERO && Input2 == ZERO && Input3 == ZERO))
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlXnor4(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t *CurrOutput,
                 Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE && Input3 == ONE && Input4 == ONE) ||
      (Input1 == ZERO && Input2 == ZERO && Input3 == ZERO && Input4 == ZERO))
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlXnor5(Digital_State_t Input1, Digital_State_t Input2, Digital_State_t Input3,
                 Digital_State_t Input4, Digital_State_t Input5, Digital_State_t *CurrOutput,
                 Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if((Input1 == ONE && Input2 == ONE && Input3 == ONE && Input4 == ONE && Input5 == ONE) ||
      (Input1 == ZERO && Input2 == ZERO && Input3 == ZERO && Input4 == ZERO && Input5 == ZERO))
      *CurrOutput = ONE;
   else
      *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// Tristate

void fnVhdlTristate(Digital_State_t Input, Digital_State_t CurrControl, Digital_State_t PrevControl,
                    Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL,
                    double tLZ, double tHZ, double tZL, double tZH)
{
   if(CurrControl == ONE)  *CurrOutput = Input;
   else                    *CurrOutput = UNKNOWN;
   
   if(*CurrOutput != *PrevOutput)
   {
      if(CurrControl != PrevControl)
      {
         if(CurrControl == ONE)
         {
            if(*CurrOutput == ONE) cm_event_queue(CurrTime + tZH);
            else                   cm_event_queue(CurrTime + tZL);
         }
         else
         {
            if(*PrevOutput == ONE) cm_event_queue(CurrTime + tHZ);
            else                   cm_event_queue(CurrTime + tLZ);
         }
      }
      else
      {
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);
      }
   }
}

// Inverter

void fnVhdlInverter(Digital_State_t Input, Digital_State_t *CurrOutput,
                    Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(Input == ONE) *CurrOutput = ZERO;
   else             *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// Latche

void fnVhdlLd(Digital_State_t Input, Digital_State_t CurrGate, Digital_State_t PrevGate,
              Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
              double tLH, double tHL, double gLH, double gHL)
{
   if(CurrGate == ONE) *CurrOutput = Input;
   else                *CurrOutput = *PrevOutput;

   if(*CurrOutput != *PrevOutput)
      if(CurrGate != PrevGate)
      {
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + gLH);
         else                   cm_event_queue(CurrTime + gHL);
      }
      else
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);

}

// Buffer

void fnVhdlBuffer(Digital_State_t Input, Digital_State_t *CurrOutput,
                  Digital_State_t *PrevOutput, double tLH, double tHL)
{
   *CurrOutput = Input;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

// Flip-Flops

void fnVhdlFd(Digital_State_t Input, Digital_State_t CurrClock, Digital_State_t PrevClock,
              Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH, double tHL)
{
   if(CurrClock != PrevClock && CurrClock == ONE)
      *CurrOutput = Input;

   if(*CurrOutput != *PrevOutput)
      if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
      else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlFdc(Digital_State_t Input, Digital_State_t CurrClock, Digital_State_t PrevClock,
               Digital_State_t Clear, Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL, double clrHL)
{
   if(Clear == ONE) *CurrOutput = ZERO;
   else
      if(CurrClock != PrevClock && CurrClock == ONE)
         *CurrOutput = Input;

   if(*CurrOutput != *PrevOutput)
      if(Clear == ONE)          cm_event_queue(CurrTime + clrHL);
      else
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlFdp(Digital_State_t Input, Digital_State_t CurrClock, Digital_State_t PrevClock,
               Digital_State_t Preset, Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
               double tLH, double tHL, double preLH)
{
   if(Preset == ONE) *CurrOutput = ONE;
   else
      if(CurrClock != PrevClock && CurrClock == ONE)
         *CurrOutput = Input;

   if(*CurrOutput != *PrevOutput)
      if(Preset == ONE)          cm_event_queue(CurrTime + preLH);
      else
         if(*CurrOutput == ONE)  cm_event_queue(CurrTime + tLH);
         else                    cm_event_queue(CurrTime + tHL);
}

void fnVhdlFdcp(Digital_State_t Input, Digital_State_t CurrClock, Digital_State_t PrevClock,
                Digital_State_t Clear, Digital_State_t Preset, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL, double clrHL, double preLH)
{
   if(Clear == ONE && Preset == ZERO)
   {
      *CurrOutput = ZERO;
   }
   else
      if(Clear == ZERO && Preset == ONE)
      {
         *CurrOutput = ONE;
      }
      else
         if(Clear == ONE && Preset == ONE)
         {
            *CurrOutput = ONE;
         }
         else
            if(CurrClock != PrevClock && CurrClock == ONE)
               *CurrOutput = Input;

   if(*CurrOutput != *PrevOutput)
      if(Clear == ONE && Preset == ONE) cm_event_queue(CurrTime + 1e-9);
      else
         if(Clear == ONE)               cm_event_queue(CurrTime + clrHL);
         else
            if(Preset == ONE)           cm_event_queue(CurrTime + preLH);
            else
               if(*CurrOutput == ONE)   cm_event_queue(CurrTime + tLH);
               else                     cm_event_queue(CurrTime + tHL);
}

// Multiplexers

void fnVhdlMux2(Digital_State_t Input0, Digital_State_t Input1, Digital_State_t CurrSelect,
                Digital_State_t PrevSelect, Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL, double selLH, double selHL)
{
   if(CurrSelect == ZERO) *CurrOutput = Input0;
   else                   *CurrOutput = Input1;

   if(*CurrOutput != *PrevOutput)
      if(CurrSelect != PrevSelect)
      {
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + selLH);
         else                   cm_event_queue(CurrTime + selHL);
      }
      else
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);
}

#define defInput(n) *CurrOutput = Input##n

void fnVhdlMux4(Digital_State_t Input0, Digital_State_t Input1, Digital_State_t Input2,
                Digital_State_t Input3, Digital_State_t CurrSelect0, Digital_State_t PrevSelect0,
                Digital_State_t CurrSelect1, Digital_State_t PrevSelect1,
                Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                double tLH, double tHL, double selLH, double selHL)
{
   int iSelect  = (CurrSelect0 == ONE ? 1 : 0) |
                  (CurrSelect1 == ONE ? 2 : 0);

   int iInput   = 1 << iSelect;

   if(iInput & 1) defInput(0);
   else
      if((iInput >> 1) & 1) defInput(1);
      else
         if((iInput >> 2) & 1) defInput(2);
         else
            defInput(3);

   if(*CurrOutput != *PrevOutput)
      if(CurrSelect0 != PrevSelect0 || CurrSelect1 != PrevSelect1)
      {
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + selLH);
         else                   cm_event_queue(CurrTime + selHL);
      }
      else
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlMux8(Digital_State_t Input0, Digital_State_t Input1, Digital_State_t Input2,
                Digital_State_t Input3, Digital_State_t Input4, Digital_State_t Input5,
                Digital_State_t Input6, Digital_State_t Input7, Digital_State_t CurrSelect0,
                Digital_State_t PrevSelect0, Digital_State_t CurrSelect1,
                Digital_State_t PrevSelect1, Digital_State_t CurrSelect2,
                Digital_State_t PrevSelect2, Digital_State_t *CurrOutput,
                Digital_State_t *PrevOutput, double tLH, double tHL, double selLH, double selHL)
{
   int iSelect  = (CurrSelect0 == ONE ? 1 : 0) |
                  (CurrSelect1 == ONE ? 2 : 0) |
                  (CurrSelect2 == ONE ? 4 : 0);

   int iInput   = 1 << iSelect;

   if(iInput & 1) defInput(0);
   else
      if((iInput >> 1) & 1) defInput(1);
      else
         if((iInput >> 2) & 1) defInput(2);
         else
            if((iInput >> 3) & 1) defInput(3);
            else
               if((iInput >> 4) & 1) defInput(4);
               else
                  if((iInput >> 5) & 1) defInput(5);
                  else
                     if((iInput >> 6) & 1) defInput(6);
                     else
                        defInput(7);

   if(*CurrOutput != *PrevOutput)
      if(CurrSelect0 != PrevSelect0 || CurrSelect1 != PrevSelect1 || CurrSelect2 != PrevSelect2)
      {
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + selLH);
         else                   cm_event_queue(CurrTime + selHL);
      }
      else
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);
}

void fnVhdlMux16(Digital_State_t Input0,  Digital_State_t Input1,  Digital_State_t Input2,
                 Digital_State_t Input3,  Digital_State_t Input4,  Digital_State_t Input5,
                 Digital_State_t Input6,  Digital_State_t Input7,  Digital_State_t Input8,
                 Digital_State_t Input9,  Digital_State_t Input10, Digital_State_t Input11,
                 Digital_State_t Input12, Digital_State_t Input13, Digital_State_t Input14,
                 Digital_State_t Input15, Digital_State_t CurrSelect0, Digital_State_t PrevSelect0,
                 Digital_State_t CurrSelect1, Digital_State_t PrevSelect1, Digital_State_t CurrSelect2,
                 Digital_State_t PrevSelect2, Digital_State_t CurrSelect3, Digital_State_t PrevSelect3,
                 Digital_State_t *CurrOutput, Digital_State_t *PrevOutput,
                 double tLH, double tHL, double selLH, double selHL)
{
   int iSelect  = (CurrSelect0 == ONE ? 1 : 0) |
                  (CurrSelect1 == ONE ? 2 : 0) |
                  (CurrSelect2 == ONE ? 4 : 0) |
                  (CurrSelect3 == ONE ? 8 : 0);

   int iInput   = 1 << iSelect;

   if(iInput & 1) defInput(0);
   else
      if((iInput >> 1) & 1) defInput(1);
      else
         if((iInput >> 2) & 1) defInput(2);
         else
            if((iInput >> 3) & 1) defInput(3);
            else
               if((iInput >> 4) & 1) defInput(4);
               else
                  if((iInput >> 5) & 1) defInput(5);
                  else
                     if((iInput >> 6) & 1) defInput(6);
                     else
                        if((iInput >> 7) & 1) defInput(7);
                        else
                           if((iInput >> 8) & 1) defInput(8);
                           else
                              if((iInput >> 9) & 1) defInput(9);
                              else
                                 if((iInput >> 10) & 1) defInput(10);
                                 else
                                    if((iInput >> 11) & 1) defInput(11);
                                    else
                                       if((iInput >> 12) & 1) defInput(12);
                                       else
                                          if((iInput >> 13) & 1) defInput(13);
                                          else
                                             if((iInput >> 14) & 1) defInput(14);
                                             else
                                                defInput(15);


   if(*CurrOutput != *PrevOutput)
      if(CurrSelect0 != PrevSelect0 || CurrSelect1 != PrevSelect1 || 
         CurrSelect2 != PrevSelect2 || CurrSelect3 != PrevSelect3)
      {
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + selLH);
         else                   cm_event_queue(CurrTime + selHL);
      }
      else
         if(*CurrOutput == ONE) cm_event_queue(CurrTime + tLH);
         else                   cm_event_queue(CurrTime + tHL);
}

// Decoders

void fnVhdlDec1(Digital_State_t CurrAddress, Digital_State_t PrevAddress,
                Digital_State_t *Output0, Digital_State_t *Output1,
                double tLH, double tHL)
{
   if(CurrAddress == ZERO)
   {
      *Output0 = ONE;
      *Output1 = ZERO;
   }
   else
   {
      *Output0 = ZERO;
      *Output1 = ONE;
   }

   if(CurrAddress != PrevAddress)
   {
      cm_event_queue(CurrTime + tLH);
      cm_event_queue(CurrTime + tHL);
   }
}

#define defOutput(n, v) *Output##n = v

void fnVhdlDec2(Digital_State_t CurrAddress0, Digital_State_t PrevAddress0,
                Digital_State_t CurrAddress1, Digital_State_t PrevAddress1,
                Digital_State_t *Output0, Digital_State_t *Output1,
                Digital_State_t *Output2, Digital_State_t *Output3, double tLH, double tHL)
{
   int iAddress = (CurrAddress0 == ONE ? 1 : 0) |
                  (CurrAddress1 == ONE ? 2 : 0);

   int iOutputs = 1 << iAddress;

   defOutput(0,  ( iOutputs        & 1) ? ONE : ZERO);
   defOutput(1,  ((iOutputs >> 1)  & 1) ? ONE : ZERO);
   defOutput(2,  ((iOutputs >> 2)  & 1) ? ONE : ZERO);
   defOutput(3,  ((iOutputs >> 3)  & 1) ? ONE : ZERO);

   if(CurrAddress0 != PrevAddress0 || CurrAddress1 != PrevAddress1)
   {
      cm_event_queue(CurrTime + tLH);
      cm_event_queue(CurrTime + tHL);
   }
}

void fnVhdlDec3(Digital_State_t CurrAddress0, Digital_State_t PrevAddress0, Digital_State_t CurrAddress1,
                Digital_State_t PrevAddress1, Digital_State_t CurrAddress2, Digital_State_t PrevAddress2,
                Digital_State_t *Output0, Digital_State_t *Output1, Digital_State_t *Output2,
                Digital_State_t *Output3, Digital_State_t *Output4, Digital_State_t *Output5,
                Digital_State_t *Output6, Digital_State_t *Output7, double tLH, double tHL)
{
   int iAddress = (CurrAddress0 == ONE ? 1 : 0) |
                  (CurrAddress1 == ONE ? 2 : 0) |
                  (CurrAddress2 == ONE ? 4 : 0);

   int iOutputs = 1 << iAddress;

   defOutput(0,  ( iOutputs        & 1) ? ONE : ZERO);
   defOutput(1,  ((iOutputs >> 1)  & 1) ? ONE : ZERO);
   defOutput(2,  ((iOutputs >> 2)  & 1) ? ONE : ZERO);
   defOutput(3,  ((iOutputs >> 3)  & 1) ? ONE : ZERO);
   defOutput(4,  ((iOutputs >> 4)  & 1) ? ONE : ZERO);
   defOutput(5,  ((iOutputs >> 5)  & 1) ? ONE : ZERO);
   defOutput(6,  ((iOutputs >> 6)  & 1) ? ONE : ZERO);
   defOutput(7,  ((iOutputs >> 7)  & 1) ? ONE : ZERO);

   if(CurrAddress0 != PrevAddress0 || CurrAddress1 != PrevAddress1 || CurrAddress2 != PrevAddress2)
   {
      cm_event_queue(CurrTime + tLH);
      cm_event_queue(CurrTime + tHL);
   }
}

void fnVhdlDec4(Digital_State_t CurrAddress0, Digital_State_t PrevAddress0, Digital_State_t CurrAddress1,
                Digital_State_t PrevAddress1, Digital_State_t CurrAddress2, Digital_State_t PrevAddress2,
                Digital_State_t CurrAddress3, Digital_State_t PrevAddress3, Digital_State_t *Output0,
                Digital_State_t *Output1, Digital_State_t *Output2, Digital_State_t *Output3,
                Digital_State_t *Output4,  Digital_State_t *Output5, Digital_State_t *Output6,
                Digital_State_t *Output7, Digital_State_t *Output8, Digital_State_t *Output9,
                Digital_State_t *Output10, Digital_State_t *Output11, Digital_State_t *Output12,
                Digital_State_t *Output13,  Digital_State_t *Output14, Digital_State_t *Output15, 
                double tLH, double tHL)
{
   int iAddress = (CurrAddress0 == ONE ? 1 : 0) |
                  (CurrAddress1 == ONE ? 2 : 0) |
                  (CurrAddress2 == ONE ? 4 : 0) |
                  (CurrAddress3 == ONE ? 8 : 0);

   int iOutputs = 1 << iAddress;

   defOutput(0,  ( iOutputs        & 1) ? ONE : ZERO);
   defOutput(1,  ((iOutputs >> 1)  & 1) ? ONE : ZERO);
   defOutput(2,  ((iOutputs >> 2)  & 1) ? ONE : ZERO);
   defOutput(3,  ((iOutputs >> 3)  & 1) ? ONE : ZERO);
   defOutput(4,  ((iOutputs >> 4)  & 1) ? ONE : ZERO);
   defOutput(5,  ((iOutputs >> 5)  & 1) ? ONE : ZERO);
   defOutput(6,  ((iOutputs >> 6)  & 1) ? ONE : ZERO);
   defOutput(7,  ((iOutputs >> 7)  & 1) ? ONE : ZERO);
   defOutput(8,  ((iOutputs >> 8)  & 1) ? ONE : ZERO);
   defOutput(9,  ((iOutputs >> 9)  & 1) ? ONE : ZERO);
   defOutput(10, ((iOutputs >> 10) & 1) ? ONE : ZERO);
   defOutput(11, ((iOutputs >> 11) & 1) ? ONE : ZERO);
   defOutput(12, ((iOutputs >> 12) & 1) ? ONE : ZERO);
   defOutput(13, ((iOutputs >> 13) & 1) ? ONE : ZERO);
   defOutput(14, ((iOutputs >> 14) & 1) ? ONE : ZERO);
   defOutput(15, ((iOutputs >> 15) & 1) ? ONE : ZERO);

   if(CurrAddress0 != PrevAddress0 || CurrAddress1 != PrevAddress1 ||
      CurrAddress2 != PrevAddress2 || CurrAddress3 != PrevAddress3)
   {
      cm_event_queue(CurrTime + tLH);
      cm_event_queue(CurrTime + tHL);
   }
}

void fnVhdlDff(Digital_State_t Input, Digital_State_t CurrClock, Digital_State_t PrevClock,
               Digital_State_t Clear, Digital_State_t Preset, Digital_State_t *CurrOutput,
               Digital_State_t *PrevOutput, double tLH, double tHL, double clrHL, double preLH)
{
   if(Clear == ZERO && Preset == ONE)
   {
      *CurrOutput = ZERO;
   }
   else
      if(Clear == ONE && Preset == ZERO)
      {
         *CurrOutput = ONE;
      }
      else
         if(Clear == ZERO && Preset == ZERO)
         {
            *CurrOutput = ONE;
         }
         else
            if(CurrClock != PrevClock && CurrClock == ONE)
               *CurrOutput = Input;

   if(*CurrOutput != *PrevOutput)
      if(Clear == ZERO && Preset == ZERO) cm_event_queue(CurrTime + 1e-9);
      else
         if(Clear == ZERO)               cm_event_queue(CurrTime + clrHL);
         else
            if(Preset == ZERO)           cm_event_queue(CurrTime + preLH);
            else
               if(*CurrOutput == ONE)   cm_event_queue(CurrTime + tLH);
               else                     cm_event_queue(CurrTime + tHL);
}

void fnVhdlGnd(Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tHL)
{
   *CurrOutput = ZERO;

   if(*CurrOutput != *PrevOutput) cm_event_queue(CurrTime + tHL);
}

void fnVhdlVcc(Digital_State_t *CurrOutput, Digital_State_t *PrevOutput, double tLH)
{
   *CurrOutput = ONE;

   if(*CurrOutput != *PrevOutput) cm_event_queue(CurrTime + tLH);
}
