// file="/home/abrown/public_html/first/first2002chs/software2002/simulator/testprog.c"
// Allen Brown  date="20061214 13:17:09"
// @(#) $Header: /home/abrown/public_html/first/first2002chs/software2002/simulator/RCS/testprog.c,v 1.6 2006/12/14 21:19:03 abrown Exp $

/***********************************************************************
  * Copyright (C) 2002  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
  ***********************************************************************/

#include <stdio.h>
#include "pb.h"

// --------------------------------------------------------------
int pblogcount=0;
int pblog(char command[], int linenum, int expect, int value)
{
  int errorcount;
  printf("%s\t%d value=%d(0x%x), expect=%d(0x%x)",
	 command, linenum, value, value, expect, expect);
  if( expect == value )
    {
      errorcount=0;
      printf("\n");
    } else {
      errorcount=1;
      printf(" ERROR\n");
    }
  if( ++pblogcount != linenum )
    {
      fprintf(stderr,"pblog count mismatch\n");
    }
  return(errorcount);
} // pblog

// --------------------------------------------------------------
main()
{
  int errorcount=0;

  pbword8_t p1_x_w8;				// p1_x var byte
#define p1_x p1_x_w8,pbword8

#define p1_x_b2 p1_x_w8,bit2			// p1_x_b2 var p1_x,bit2

#define p1_x_b7 p1_x_w8,bit7			// p1_x_b7 var p1_x,bit7

  pbword8_t p2_y_w8;				// p2_y var byte
#define p2_y p2_y_w8,pbword8

#define p2_y_b5 p2_y_w8,bit5			// p2_y_b5 var p2_y,bit5

#define c_p1_x pbconst(1)			// c_p1_x con 1

#define coma pbconst(1)				// coma con 1

#define comb pbconst(1)				// comb con 1

  pboutput(comb);				// output comb

  pboutput(coma);				// input coma

  pboutput(pbconst(7));				// output 7

  pblet(&p1_x,pbconst(255),"p1_x","line59");	// p1_x = 255
  errorcount += pblog( "pblet", 1, 0xff, p1_x_w8 );

  pbput(pbconst(1),pbconst(9));			// put 1,9

  pbput(pbconst(2),p1_x);			// put 2,p1_x

  pbget(&p1_x,pbconst(1));			// get 1 p1_x
  errorcount += pblog( "pbget", 2, 0x09, p1_x_w8 );

  pbput(pbconst(3),p1_x);			// put 3,p1_x

  pblet(&p1_x,pbconst(128),"p1_x","71");	// p1_x = 128
  errorcount += pblog( "pblet", 3, 0x080, p1_x_w8 );

  pblet(&p1_x_b2,pbconst(11),"p1_x_b2","74");	// p1_x_b2 = 11
  errorcount += pblog( "pblet", 4, 0x084, p1_x_w8 );

  pblet(&p1_x_b7,pbconst(0),"p1_x_b7","77");	// p1_x_b7 = 0
  errorcount += pblog( "pblet", 5, 0x04, p1_x_w8 );

  pbget(&p1_x,pbconst(3));			// get 3 p1_x
  errorcount += pblog( "pbget", 6, 0x09, p1_x_w8 );

  pbget(&p1_x,pbconst(2));			// get 2 p1_x
  errorcount += pblog( "pbget", 7, 0xff, p1_x_w8 );

  pblet(&p2_y,pbconst(240),"p2_y","86");	// p2_y = 240
  errorcount += pblog( "pblet", 8, 0xf0, p2_y_w8 );

  pblet(&p1_x_b2,p2_y,"p1_x_b2","89");		// p1_x_b2 = p2_y	??
  errorcount += pblog( "pblet", 9, 0xfb, p1_x_w8 );

  pblet(&p2_y,pbconst(254),"p2_y","92");	// p2_y = 254
  errorcount += pblog( "pblet", 10, 0xfe, p2_y_w8 );

  pblet(&p1_x_b7,p2_y,"p1_x_b7","95");		// p1_x_b7 = p2_y	??
  errorcount += pblog( "pblet", 11, 0x7b, p1_x_w8 );

  pblet(&p1_x,p2_y,"p1_x","98");		// p1_x = p2_y
  errorcount += pblog( "pblet", 12, 0xfe, p1_x_w8 );

  pblet(&p2_y,p1_x_b7,"p2_y","101");		// p2_y = p1_x_b7
  errorcount += pblog( "pblet", 13, 0x01, p2_y_w8 );

  pblet(&p2_y_b5,p1_x_b7,"p2_y_b5","104");	// p2_y_b5 = p1_x_b7
  errorcount += pblog( "pblet", 14, 0x21, p2_y_w8 );

  pblet(&p1_x_b7,pbconst(0),"p1_x_b7","107");	// p1_x_b7 = 0
  errorcount += pblog( "pblet", 15, 0x7e, p1_x_w8 );

  pblet(&p2_y_b5,p1_x_b7,"p2_y_b5","110");	// p2_y_b5 = p1_x_b7
  errorcount += pblog( "pblet", 16, 0x01, p2_y_w8 );

  pblet(&p2_y, pbadd(p2_y,p1_x),pbword8,"p2_y","113");	// p2_y = p2_y + p1_x
  errorcount += pblog( "pblet", 17, 0x7f, p2_y_w8 );

  pblet(&p1_x, pbadd(pbconst(2),p2_y_b5),pbword8,"p1_x","116"); // p1_x = 2 + p2_7_b5
  errorcount += pblog( "pblet", 18, 0x03, p1_x_w8 );

  pblet(&p2_y, pbsub(p2_y,p1_x),pbword8,"p2_y","119");	// p2_y = p2_y - p1_x
  errorcount += pblog( "pblet", 19, 0x7c, p2_y_w8 );

  pblet(&p2_y, pbadd(p2_y,p2_y),pbword8,"p2_y","122");	// p2_y = p2_y + p2_y
  errorcount += pblog( "pblet", 20, 0xf8, p2_y_w8 );

  pblet(&p2_y, pbadd(p2_y,pbconst(15)),pbword8,"p2_y","125"); // p2_y = p2_y + 15
  errorcount += pblog( "pblet", 21, 0x07, p2_y_w8 );

  pblet(&p2_y, pbsub(p2_y,pbconst(15)),pbword8,"p2_y","128"); // p2_y = p2_y - 15
  errorcount += pblog( "pblet", 22, 0xf8, p2_y_w8 );

  pblet(&p2_y, pbmin(p2_y,pbconst(249)),pbword8,"p2_y","131"); // p2_y = p2_y min 249
  errorcount += pblog( "pblet", 23, 0xf9, p2_y_w8 );

  pblet(&p2_y, pbmin(p2_y,pbconst(247)),pbword8,"p2_y","134"); // p2_y = p2_y min 247
  errorcount += pblog( "pblet", 24, 0xf9, p2_y_w8 );

  pblet(&p2_y, pbmax(p2_y,pbconst(246)),pbword8,"p2_y","137"); // p2_y = p2_y max 246
  errorcount += pblog( "pblet", 25, 0xf6, p2_y_w8 );

  printf("Exiting with %d errors.\n", errorcount);

  exit(errorcount);
} // main
// --------------------------------------------------------------

