#ifndef _LPrimEx_

   #define _LPrimEx_

   #include "PrimEx.h"


   // Logic state mask.

   #define LSTATE 3

   // States.

   #define LOW    0
   #define XSTAT1 1
   #define XSTAT2 2
   #define HIGH   3

   // Logic power mask.

   #define LPOWER 0xC

   // Power values.

   #define ZIMP   0x0 
   #define XPWR1  0x4
   #define XPWR2  0x8
   #define DRV    0xC

   // Power values and states.

   #define OUT_L DRV + LOW
   #define OUT_D XPWR1 + XSTAT1
   #define OUT_X DRV + XSTAT1
   #define OUT_Z ZIMP + XSTAT1
   #define OUT_U XPWR1 + XSTAT2
   #define OUT_H DRV + HIGH

   // State triggering.

   #define CHANGE (LSTATE << 8 | LSTATE)
   #define RISE   (LOW << 8 | HIGH)
   #define FALL   (HIGH << 8 | LOW)

   // State negation.

   #define NOT(st)  (st^LSTATE)
   #define NOT2(st) (st^CHANGE)


   ////////////////////////////////////////////////////////////////////////////
   //
   // DLL Interface.
   //
   ////////////////////////////////////////////////////////////////////////////

   typedef DWORD (CALLBACK* PEEKPROCEX)(int iPort, int iNumber, int iCommand);
   typedef void  (CALLBACK* POKEPROCEX)(int iPort, int iNumber, int iCommand, DWORD dwState, float fRiseDelay, float fFallDelay);

   extern PEEKPROCEX pPeekEx;
   extern POKEPROCEX pPokeEx;


   ////////////////////////////////////////////////////////////////////////////
   //
   //  Macros for all cases of use callback functions PEEK, POKE, SETUP:
   //  parameters:
   //    iPort   - input/output start number.
   //    iNumber - number of inputs/outputs for word functions [1-32].
   //    dwState - logic state bit or word of up to 32 logic state bits.
   //    dr      - rise delay value (float).
   //    df      - fall delay value (float).
   //
   ////////////////////////////////////////////////////////////////////////////

   #define KILL_ALARM()	                                   (*pPokeEx)(0, 0, 0xFFFF, 0, 0, 0)
   #define PEEK(iPort) 	                                   (*pPeekEx)(iPort, 0, 0)
   #define PEEK_AND(iPort, iNumber)	                       (*pPeekEx)(iPort, iNumber, 4)
   #define PEEK_AND_CHANGE(iPort, iNumber)                 (*pPeekEx)(iPort, iNumber, 5)
   #define PEEK_AND_EDGE(iPort, iNumber)                   (*pPeekEx)(iPort, iNumber, 6)
   #define PEEK_CHANGE(iPort)	                             (*pPeekEx)(iPort, 0, 1)
   #define PEEK_DWORD(iPort, iNumber)	                    (*pPeekEx)(iPort, iNumber, 12)
   #define PEEK_EDGE(iPort)	                             (*pPeekEx)(iPort, 0, 2)
   #define PEEK_OR(iPort, iNumber)	                       (*pPeekEx)(iPort, iNumber, 8)
   #define PEEK_OR_CHANGE(iPort, iNumber)                  (*pPeekEx)(iPort, iNumber, 9)
   #define PEEK_OR_EDGE(iPort, iNumber)                    (*pPeekEx)(iPort, iNumber, 10)
   #define PEEK_WORD_CHANGE(iPort, iNumber)                (*pPeekEx)(iPort, iNumber, 13)
   #define POKE_ALARM(d)	                                (*pPokeEx)(0, 0, 0xFFFF, 1, d, d)
   #define POKE_DRV(iPort, dwState, dr, df)	              (*pPokeEx)(iPort, 1, 2, dwState, dr, df)
   #define POKE_OC(iPort, dwState, dr, df)	              (*pPokeEx)(iPort, 1, 1, dwState, dr, df)
   #define POKE_WORD_DRV(iPort, iNumber, dwState, dr, df)  (*pPokeEx)(iPort, iNumber, 2, dwState, dr, df)
   #define POKE_WORD_OC(iPort, iNumber, dwState, dr, df)   (*pPokeEx)(iPort, iNumber, 1, dwState, dr, df)
   #define POKE_WORD_XPWR(iPort, iNumber, dwState, dr, df) (*pPokeEx)(iPort, iNumber, 3, dwState, dr, df)
   #define POKE_WORD_ZIMP(iPort, iNumber, dr, df)          (*pPokeEx)(iPort, iNumber, 0, 0, dr, df)
   #define POKE_XPWR(iPort, dwState, dr, df)	              (*pPokeEx)(iPort, 1, 3, dwState, dr, df)
   #define POKE_ZIMP(iPort, dr, df)	                       (*pPokeEx)(iPort, 1, 0, 0, dr, df)
   #define SETUP_DRV(iPort, dwState)	                    POKE_DRV(iPort, dwState, 0, 0)
   #define SETUP_OC(iPort, dwState)	                       POKE_OC(iPort, dwState, 0, 0)
   #define SETUP_WORD_DRV(iPort, iNumber, dwState)         POKE_WORD_DRV(iPort, iNumber, dwState, 0, 0)
   #define SETUP_WORD_OC(iPort, iNumber, dwState)          POKE_WORD_OC(iPort, iNumber, dwState, 0, 0)
   #define SETUP_WORD_ZIMP(iPort, iNumber)                 POKE_WORD_ZIMP(iPort, iNumber, 0, 0)
   #define SETUP_ZIMP(iPort)	                             POKE_ZIMP(iPort, 0, 0)

#endif
