2001-04-24 04:23:58 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
|
|
|
|
|
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT)
|
2001-04-26 05:10:55 +02:00
|
|
|
#ident "$Id: udp.cc,v 1.2 2001/04/26 03:10:55 steve Exp $"
|
2001-04-24 04:23:58 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "udp.h"
|
|
|
|
|
#include "symbols.h"
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
|
|
static symbol_table_t udp_table;
|
|
|
|
|
|
|
|
|
|
struct vvp_udp_s *udp_create(char *label)
|
|
|
|
|
{
|
|
|
|
|
if (!udp_table)
|
|
|
|
|
udp_table = new_symbol_table();
|
|
|
|
|
|
|
|
|
|
assert(!udp_find(label));
|
|
|
|
|
|
|
|
|
|
struct vvp_udp_s *u = new struct vvp_udp_s;
|
|
|
|
|
|
|
|
|
|
symbol_value_t v;
|
|
|
|
|
v.ptr = u;
|
|
|
|
|
sym_set_value(udp_table, label, v);
|
|
|
|
|
|
|
|
|
|
u->name = 0x0;
|
|
|
|
|
u->sequ = 0;
|
|
|
|
|
u->nin = 0;
|
|
|
|
|
u->init = 3;
|
|
|
|
|
u->table = 0x0;
|
|
|
|
|
|
|
|
|
|
return u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct vvp_udp_s *udp_find(char *label)
|
|
|
|
|
{
|
|
|
|
|
symbol_value_t v = sym_get_value(udp_table, label);
|
|
|
|
|
return (struct vvp_udp_s *)v.ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned char udp_propagate(vvp_ipoint_t uix)
|
|
|
|
|
{
|
|
|
|
|
functor_t fu = functor_index(uix);
|
|
|
|
|
struct vvp_udp_s *u = fu->udp;
|
|
|
|
|
assert(u);
|
|
|
|
|
assert(u->table);
|
|
|
|
|
|
|
|
|
|
unsigned char ret = 2;
|
|
|
|
|
|
|
|
|
|
for (char **rptr = u->table; *rptr ; rptr++)
|
|
|
|
|
{
|
|
|
|
|
char *row = *rptr;
|
|
|
|
|
|
|
|
|
|
if (u->sequ)
|
|
|
|
|
{
|
2001-04-26 05:10:55 +02:00
|
|
|
char old_out = (fu->oval&3)["01xx"];
|
|
|
|
|
if ( row[0]=='?'
|
|
|
|
|
|| row[0]==old_out
|
|
|
|
|
|| (row[0]=='b' && old_out!='x')
|
|
|
|
|
|| (row[0]=='l' && old_out!='1')
|
|
|
|
|
|| (row[0]=='h' && old_out!='0') )
|
2001-04-24 04:23:58 +02:00
|
|
|
row++;
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 05:10:55 +02:00
|
|
|
int i;
|
2001-04-24 04:23:58 +02:00
|
|
|
|
2001-04-26 05:10:55 +02:00
|
|
|
for (i=0; i < u->nin; i++, row++)
|
2001-04-24 04:23:58 +02:00
|
|
|
{
|
|
|
|
|
assert (*row);
|
|
|
|
|
|
2001-04-26 05:10:55 +02:00
|
|
|
int idx = ipoint_input_index(uix, i);
|
|
|
|
|
int port = ipoint_port(idx);
|
|
|
|
|
functor_t pfun = functor_index(idx);
|
2001-04-24 04:23:58 +02:00
|
|
|
|
|
|
|
|
char new_bit = ((pfun->ival >> (2*port))&3)["01xx"];
|
|
|
|
|
|
2001-04-26 05:10:55 +02:00
|
|
|
if ( *row != new_bit
|
|
|
|
|
&& *row != '?'
|
|
|
|
|
&& (*row != 'b' || new_bit == 'x')
|
|
|
|
|
&& (*row != 'l' || new_bit == '1')
|
|
|
|
|
&& (*row != 'h' || new_bit == '0') )
|
2001-04-24 04:23:58 +02:00
|
|
|
{
|
|
|
|
|
char old_bit = ((pfun->old_ival >> (2*port))&3)["01xx"];
|
|
|
|
|
if (new_bit == old_bit)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch (*row)
|
|
|
|
|
{
|
|
|
|
|
case '*':
|
|
|
|
|
continue;
|
|
|
|
|
case '_':
|
|
|
|
|
if (new_bit == '0')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case '+':
|
|
|
|
|
if (new_bit == '1')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case '%':
|
|
|
|
|
if (new_bit == 'x')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
2001-04-26 05:10:55 +02:00
|
|
|
case 'B':
|
|
|
|
|
if (old_bit == 'x')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
2001-04-24 04:23:58 +02:00
|
|
|
case 'r':
|
|
|
|
|
if (old_bit=='0' && new_bit=='1')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
if (old_bit=='x' && new_bit=='1')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
if (old_bit=='1' && new_bit=='0')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'F':
|
|
|
|
|
if (old_bit=='x' && new_bit=='0')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
|
|
|
|
if (old_bit=='0')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
if (old_bit=='1')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'P':
|
|
|
|
|
if (old_bit=='0' && new_bit=='x')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
case 'N':
|
|
|
|
|
if (old_bit=='1' && new_bit=='x')
|
|
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-04-26 05:10:55 +02:00
|
|
|
}
|
2001-04-24 04:23:58 +02:00
|
|
|
|
2001-04-26 05:10:55 +02:00
|
|
|
if (i == u->nin)
|
2001-04-24 04:23:58 +02:00
|
|
|
{
|
|
|
|
|
assert(*row);
|
|
|
|
|
if (*row == '-')
|
|
|
|
|
ret = fu->oval;
|
|
|
|
|
else
|
|
|
|
|
switch (*row)
|
|
|
|
|
{
|
|
|
|
|
case '0':
|
|
|
|
|
ret = 0;
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
ret = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ret = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-26 05:10:55 +02:00
|
|
|
for (int i=0; i < u->nin; i+=4)
|
2001-04-24 04:23:58 +02:00
|
|
|
{
|
2001-04-26 05:10:55 +02:00
|
|
|
functor_t fu = functor_index(ipoint_input_index(uix, i));
|
2001-04-24 04:23:58 +02:00
|
|
|
fu->old_ival = fu->ival;
|
2001-04-26 05:10:55 +02:00
|
|
|
}
|
2001-04-24 04:23:58 +02:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: udp.cc,v $
|
2001-04-26 05:10:55 +02:00
|
|
|
* Revision 1.2 2001/04/26 03:10:55 steve
|
|
|
|
|
* Redo and simplify UDP behavior.
|
|
|
|
|
*
|
2001-04-24 04:23:58 +02:00
|
|
|
* Revision 1.1 2001/04/24 02:23:59 steve
|
|
|
|
|
* Support for UDP devices in VVP (Stephen Boettcher)
|
|
|
|
|
*
|
|
|
|
|
*/
|