// @(#) $Header: /home/abrown/public_html/first/first2003chs/software/simulator/RCS/pb.h,v 2.10 2006/12/14 19:40:16 abrown Exp $

/***********************************************************************
  * Copyright (C) 2002, 2003  Allen Brown
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  * 
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the
  *   Free Software Foundation, Inc.
  *   59 Temple Place, Suite 330
  *   Boston, MA  02111-1307  USA
  * 
  * To contact the author of this software:
  *   Allen Brown
  *   PO Box J
  *   Corvallis, OR
  * 
  *   http://brown.armoredpenguin.com/~abrown/contact.html
  ***********************************************************************/

#define DEBUG 1
#define BASEFORMAT 10

/* pbasic allows a base variable to be declared as word, byte, nibble.
 * Each such variable may be broken into smaller fields: a word can be
 * broken into two bytes, etc.  Each of these smaller fields may be
 * referred to by a new variable name.  They may also be broken into
 * still smaller fields.
 *   nw VAR WORD
 *   nb0 VAR nw.byte0
 *   nb1 VAR nw.byte1
 * In this example, nw is 16 bits and holds the concatenation of
 * nb1 with nb0, each of which is 8 bits.  Inside of nw, nb1 is shifted
 * 8 bits to the left of nb0.  If we now assign
 *   nb0=17  (or 0x11) and
 *   nb1=5
 * then we now have the case where nw==(5<<8)+17 or 1297 (0x511).
 * We could have gotten the same result into nw by:
 *   nw=1297
 */

// --------------------------------------------------------------
// typedef unsigned int pbvalue;
typedef int pbvalue;
typedef int pbvaluesig;
typedef short pbi;
struct pbnumber {
  pbvalue *vpoint;
  pbvalue value;
  pbi size;
  pbi index;
  char *name;
};

// --------------------------------------------------------------
// Function Declarations from pb_io.c:
void pbhigh(struct pbnumber numbera);
void pbinput(struct pbnumber numbera);
void pblow(struct pbnumber numbera);
void pboutput(struct pbnumber numbera);
int pbserin(
	    struct pbnumber s1,
	    struct pbnumber s2,
	    struct pbnumber s3,
	    struct pbnumber s4,
	    struct pbnumber s5,
	    struct pbnumber s6,
	    struct pbnumber s7,
	    struct pbnumber s8,
	    struct pbnumber s9,
	    struct pbnumber s10,
	    struct pbnumber s11,
	    struct pbnumber s12,
	    struct pbnumber s13,
	    struct pbnumber s14,
	    struct pbnumber s15,
	    struct pbnumber s16,
	    struct pbnumber s17,
	    struct pbnumber s18,
	    struct pbnumber s19,
	    struct pbnumber s20,
	    struct pbnumber s21,
	    struct pbnumber s22,
	    struct pbnumber s23,
	    struct pbnumber s24,
	    struct pbnumber s25,
	    struct pbnumber s26,
	    struct pbnumber s27,
	    struct pbnumber s28,
	    struct pbnumber s29,
	    struct pbnumber s30,
	    struct pbnumber s31,
	    struct pbnumber s32
	    );
void pbserout(
    struct pbnumber dummy1,
    struct pbnumber dummy2,
    struct pbnumber pwm1,
    struct pbnumber relayA,
    struct pbnumber pwm2,
    struct pbnumber relayB,
    struct pbnumber pwm3,
    struct pbnumber pwm4,
    struct pbnumber pwm5,
    struct pbnumber pwm6,
    struct pbnumber pwm7,
    struct pbnumber pwm8,
    struct pbnumber pwm9,
    struct pbnumber pwm10,
    struct pbnumber pwm11,
    struct pbnumber pwm12,
    struct pbnumber pwm13,
    struct pbnumber pwm14,
    struct pbnumber pwm15,
    struct pbnumber pwm16,
    struct pbnumber dummy17,
    struct pbnumber dummy18
    );
void pbshiftout(
		struct pbnumber b1,
		struct pbnumber b2,
		struct pbnumber b3,
		struct pbnumber b4,
		struct pbnumber b5
		);
void pbstop();
void pbtoggle(struct pbnumber numbera);
void pbrun(struct pbnumber numbera);

// --------------------------------------------------------------
// Function Declarations from pb_math.c:
void pblet(struct pbnumber numbera, struct pbnumber numberb, char *linenum);
struct pbnumber pbabs(struct pbnumber numbera);
struct pbnumber pbbnot(struct pbnumber valuea);
struct pbnumber pbadd(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbsub(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbmul(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbdiv(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbmin(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbmax(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbshl(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbshr(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbband(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbbor(struct pbnumber valuea, struct pbnumber valueb);
struct pbnumber pbbxor(struct pbnumber valuea, struct pbnumber valueb);
void pbget(struct pbnumber numbera, struct pbnumber numberb);
void pbput(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbeq(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pblt(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pble(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbgt(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbge(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbne(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pblor(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pbland(struct pbnumber numbera, struct pbnumber numberb);
struct pbnumber pblxor(struct pbnumber numbera, struct pbnumber numberb);

// --------------------------------------------------------------
// Function Declarations from pb_support.c:
int pbtokencmp(char *pbtoken1, char *pbtoken2);
void printnumber(char *stringa, struct pbnumber numbera, char *stringb);
pbvalue makemask( int fieldinvert, pbi fieldsize, pbi fieldindex );
struct pbnumber makepbnumber(
		      pbvalue *vpoint,
		      pbvalue initvalue,
		      pbi size,
		      pbi index,
		      char *name
		      );
struct pbnumber makepbconst(
		      pbvalue value,
		      pbi size,
		      char *name
		      );
pbvalue pbstrip(struct pbnumber numbera);
int assertpbnumber(struct pbnumber numbera, struct pbnumber numberb, char *comment);

// --------------------------------------------------------------
//   makepbnumber(&(value),(pbi)(size),(pbi)(index),name)
/* pbnumber holds the information needed to reconstruct this.
 * pbnumber.vpoint is a C pointer to the variable value.
 * pbnumber.value is an int that can be used to hold the value.
 * pbnumber.size is the size of the field in bits.
 * pbnumber.index tells how many bits to shift this value to
 *   the left when storing.
 */

