diff --git a/vpi/sys_display.c b/vpi/sys_display.c index fdc411808..6b5eec6d3 100644 --- a/vpi/sys_display.c +++ b/vpi/sys_display.c @@ -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" @@ -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); @@ -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); @@ -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() { @@ -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. * diff --git a/vpi_user.h b/vpi_user.h index 3a4e1e227..33120b1c5 100644 --- a/vpi_user.h +++ b/vpi_user.h @@ -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 @@ -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. @@ -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. * diff --git a/vpip/vpi_mcd.c b/vpip/vpi_mcd.c index be7162fbc..999f8cd12 100644 --- a/vpip/vpi_mcd.c +++ b/vpip/vpi_mcd.c @@ -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" @@ -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++) { @@ -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); @@ -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; +} diff --git a/vvp/vpi_mcd.cc b/vvp/vpi_mcd.cc index 5b4b40d89..0a6997dc0 100644 --- a/vvp/vpi_mcd.cc +++ b/vvp/vpi_mcd.cc @@ -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" @@ -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++) { @@ -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); @@ -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; +}