Skip to content

Commit

Permalink
fgetc patch from Peter Monta.
Browse files Browse the repository at this point in the history
  • Loading branch information
steve committed Mar 22, 2001
1 parent 2b8d9ab commit b24011b
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 8 deletions.
120 changes: 117 additions & 3 deletions vpi/sys_display.c
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: sys_display.c,v 1.23 2001/03/18 00:31:32 steve Exp $"
#ident "$Id: sys_display.c,v 1.24 2001/03/22 02:23:40 steve Exp $"
#endif

# include "vpi_user.h"
Expand Down Expand Up @@ -420,11 +420,13 @@ static int sys_monitor_calltf(char*name)
*/
static int sys_fopen_calltf(char *name)
{
s_vpi_value val, value;
s_vpi_value val, value, modevalue;
unsigned char *mode_string;

vpiHandle call_handle = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, call_handle);
vpiHandle item = vpi_scan(argv);
vpiHandle mode = vpi_scan(argv);

if (item == 0) {
vpi_printf("%s: file name parameter missing.\n", name);
Expand All @@ -443,11 +445,30 @@ static int sys_fopen_calltf(char *name)
return 0;
}

if (mode == 0) {
mode_string = "w";
} else {
if (vpi_get(vpiType, mode) != vpiConstant) {
vpi_printf("ERROR: %s parameter must be a constant\n", name);
vpi_free_object(argv);
return 0;
}

if (vpi_get(vpiConstType, mode) != vpiStringConst) {
vpi_printf("ERROR: %s parameter must be a string.\n", name);
vpi_free_object(argv);
return 0;
}
modevalue.format = vpiStringVal;
vpi_get_value(mode, &modevalue);
mode_string = modevalue.value.str;
}

value.format = vpiStringVal;
vpi_get_value(item, &value);

val.format = vpiIntVal;
val.value.integer = vpi_mcd_open( value.value.str );
val.value.integer = vpi_mcd_open_x( value.value.str, mode_string );

vpi_put_value(call_handle, &val, 0, vpiNoDelay);

Expand Down Expand Up @@ -533,6 +554,80 @@ static int sys_fclose_calltf(char *name)
return 0;
}

static int sys_fputc_calltf(char *name)
{
unsigned int mcd;
int type;
unsigned char x;
s_vpi_value value, xvalue;
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, sys);
vpiHandle item = vpi_scan(argv);

if (item == 0) {
vpi_printf("%s: mcd parameter missing.\n", name);
return 0;
}

type = vpi_get(vpiType, item);
if (type != vpiReg && type != vpiRealVal) {
vpi_printf("ERROR: %s mcd parameter must be of integral, got vpiType=%d\n",
name, type);
vpi_free_object(argv);
return 0;
}

value.format = vpiIntVal;
vpi_get_value(item, &value);
mcd = value.value.integer;

item = vpi_scan(argv);

xvalue.format = vpiIntVal;
vpi_get_value(item, &xvalue);
x = xvalue.value.integer;

return vpi_mcd_fputc( mcd, x );
}

static int sys_fgetc_calltf(char *name)
{
unsigned int mcd;
int type;
s_vpi_value value, rval;
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, sys);
vpiHandle item = vpi_scan(argv);

if (item == 0) {
vpi_printf("%s: mcd parameter missing.\n", name);
return 0;
}

type = vpi_get(vpiType, item);
if (type != vpiReg && type != vpiRealVal) {
vpi_printf("ERROR: %s mcd parameter must be of integral, got vpiType=%d\n",
name, type);
vpi_free_object(argv);
return 0;
}

value.format = vpiIntVal;
vpi_get_value(item, &value);
mcd = value.value.integer;

rval.format = vpiIntVal;
rval.value.integer = vpi_mcd_fgetc( mcd );

vpi_put_value(sys, &rval, 0, vpiNoDelay);

return 0;
}

static int sys_fgetc_sizetf(char*x)
{
return 32;
}

void sys_display_register()
{
Expand Down Expand Up @@ -601,11 +696,30 @@ void sys_display_register()
tf_data.sizetf = 0;
tf_data.user_data = "$fwrite";
vpi_register_systf(&tf_data);

tf_data.type = vpiSysTask;
tf_data.tfname = "$fputc";
tf_data.calltf = sys_fputc_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = 0;
tf_data.user_data = "$fputc";
vpi_register_systf(&tf_data);

tf_data.type = vpiSysFunc;
tf_data.tfname = "$fgetc";
tf_data.calltf = sys_fgetc_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = sys_fgetc_sizetf;
tf_data.user_data = "$fgetc";
vpi_register_systf(&tf_data);
}


/*
* $Log: sys_display.c,v $
* Revision 1.24 2001/03/22 02:23:40 steve
* fgetc patch from Peter Monta.
*
* Revision 1.23 2001/03/18 00:31:32 steve
* $display can take 0 arguments.
*
Expand Down
8 changes: 7 additions & 1 deletion vpi_user.h
Expand Up @@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vpi_user.h,v 1.1 2001/03/19 01:21:45 steve Exp $"
#ident "$Id: vpi_user.h,v 1.2 2001/03/22 02:23:17 steve Exp $"
#endif


Expand Down Expand Up @@ -177,7 +177,10 @@ extern void vpi_printf(const char*fmt, ...);
extern unsigned int vpi_mcd_close(unsigned int mcd);
extern char *vpi_mcd_name(unsigned int mcd);
extern unsigned int vpi_mcd_open(char *name);
extern unsigned int vpi_mcd_open_x(char *name, char *mode);
extern int vpi_mcd_printf(unsigned int mcd, const char*fmt, ...);
extern int vpi_mcd_fputc(unsigned int mcd, unsigned char x);
extern int vpi_mcd_fgetc(unsigned int mcd);

/*
* support for VPI callback functions.
Expand Down Expand Up @@ -266,6 +269,9 @@ extern DLLEXPORT void (*vlog_startup_routines[])();

/*
* $Log: vpi_user.h,v $
* Revision 1.2 2001/03/22 02:23:17 steve
* fgetc patch from Peter Monta.
*
* Revision 1.1 2001/03/19 01:21:45 steve
* vpi_user header file is a root header.
*
Expand Down
32 changes: 30 additions & 2 deletions vpip/vpi_mcd.c
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vpi_mcd.c,v 1.1 2001/03/14 19:27:44 steve Exp $"
#ident "$Id: vpi_mcd.c,v 1.2 2001/03/22 02:23:45 steve Exp $"
#endif

# include "vpi_priv.h"
Expand Down Expand Up @@ -80,6 +80,11 @@ char *vpi_mcd_name(unsigned int mcd)
}

unsigned int vpi_mcd_open(char *name)
{
return vpi_mcd_open_x(name, "w");
}

unsigned int vpi_mcd_open_x(char *name, char *mode)
{
int i;
for(i = 0; i < 31; i++) {
Expand All @@ -89,7 +94,7 @@ unsigned int vpi_mcd_open(char *name)
return 0; /* too many open mcd's */

got_entry:
mcd_table[i].fp = fopen(name, "w");
mcd_table[i].fp = fopen(name, mode);
if(mcd_table[i].fp == NULL)
return 0;
mcd_table[i].filename = strdup(name);
Expand Down Expand Up @@ -121,3 +126,26 @@ int vpi_mcd_printf(unsigned int mcd, const char*fmt, ...)
return len;
}

int vpi_mcd_fputc(unsigned int mcd, unsigned char x)
{
int i;

for(i = 0; i < 31; i++) {
if( (mcd>>i) & 1) {
return fputc(x, mcd_table[i].fp);
}
}
return 0;
}

int vpi_mcd_fgetc(unsigned int mcd)
{
int i;

for(i = 0; i < 31; i++) {
if( (mcd>>i) & 1) {
return fgetc(mcd_table[i].fp);
}
}
return 0;
}
32 changes: 30 additions & 2 deletions vvp/vpi_mcd.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vpi_mcd.cc,v 1.1 2001/03/16 01:44:34 steve Exp $"
#ident "$Id: vpi_mcd.cc,v 1.2 2001/03/22 02:24:05 steve Exp $"
#endif

# include "vpi_priv.h"
Expand Down Expand Up @@ -80,6 +80,11 @@ char *vpi_mcd_name(unsigned int mcd)
}

unsigned int vpi_mcd_open(char *name)
{
return vpi_mcd_open_x(name,"w");
}

unsigned int vpi_mcd_open_x(char *name, char *mode)
{
int i;
for(i = 0; i < 31; i++) {
Expand All @@ -89,7 +94,7 @@ unsigned int vpi_mcd_open(char *name)
return 0; /* too many open mcd's */

got_entry:
mcd_table[i].fp = fopen(name, "w");
mcd_table[i].fp = fopen(name, mode);
if(mcd_table[i].fp == NULL)
return 0;
mcd_table[i].filename = strdup(name);
Expand Down Expand Up @@ -121,3 +126,26 @@ int vpi_mcd_printf(unsigned int mcd, const char*fmt, ...)
return len;
}

int vpi_mcd_fputc(unsigned int mcd, unsigned char x)
{
int i;

for(i = 0; i < 31; i++) {
if( (mcd>>i) & 1) {
return fputc(x, mcd_table[i].fp);
}
}
return 0;
}

int vpi_mcd_fgetc(unsigned int mcd)
{
int i;

for(i = 0; i < 31; i++) {
if( (mcd>>i) & 1) {
return fgetc(mcd_table[i].fp);
}
}
return 0;
}

0 comments on commit b24011b

Please sign in to comment.