예제 #1
0
pdynlib::pdynlib(const pstring libname)
: m_isLoaded(false), m_lib(nullptr)
{
#ifdef _WIN32
	//fprintf(stderr, "win: loading <%s>\n", libname.cstr());
	if (libname != "")
		m_lib = LoadLibrary(libname.cstr());
	else
		m_lib = GetModuleHandle(nullptr);
	if (m_lib != nullptr)
		m_isLoaded = true;
	//else
	//	fprintf(stderr, "win: library <%s> not found!\n", libname.cstr());
#else
	//printf("loading <%s>\n", libname.cstr());
	if (libname != "")
		m_lib = dlopen(libname.cstr(), RTLD_LAZY);
	else
		m_lib = dlopen(nullptr, RTLD_LAZY);
	if (m_lib != nullptr)
		m_isLoaded = true;
	//else
	//	printf("library <%s> not found!\n", libname.cstr());
#endif
	}
예제 #2
0
파일: nl_base.c 프로젝트: vorlenko/mame
ATTR_COLD nl_double netlist_param_model_t::model_value(const pstring &entity, const nl_double defval) const
{
	pstring tmp = this->Value();
	// .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon)
	int p = tmp.ucase().find(entity.ucase() + "=");
	if (p>=0)
	{
		int pblank = tmp.find(" ", p);
		if (pblank < 0) pblank = tmp.len() + 1;
		tmp = tmp.substr(p, pblank - p);
		int pequal = tmp.find("=", 0);
		if (pequal < 0)
			netlist().error("parameter %s misformat in model %s temp %s\n", entity.cstr(), Value().cstr(), tmp.cstr());
		tmp = tmp.substr(pequal+1);
		nl_double factor = NL_FCONST(1.0);
		switch (*(tmp.right(1).cstr()))
		{
			case 'm': factor = 1e-3; break;
			case 'u': factor = 1e-6; break;
			case 'n': factor = 1e-9; break;
			case 'p': factor = 1e-12; break;
			case 'f': factor = 1e-15; break;
			case 'a': factor = 1e-18; break;

		}
		if (factor != NL_FCONST(1.0))
			tmp = tmp.left(tmp.len() - 1);
		return (nl_double) atof(tmp.cstr()) * factor;
	}
	else
	{
		netlist().log("Entity %s not found in model %s\n", entity.cstr(), tmp.cstr());
		return defval;
	}
}
예제 #3
0
파일: nl_parser.c 프로젝트: j26w/mame
ATTR_COLD void parser_t::verror(pstring msg, int line_num, pstring line)
{
	m_setup.netlist().error("line %d: error: %s\n\t\t%s\n", line_num,
			msg.cstr(), line.cstr());

	//throw error;
}
예제 #4
0
파일: nltool.c 프로젝트: matthewbauer/mame
	input_t(netlist::netlist_t *netlist, const pstring &line)
	{
		char buf[400];
		double t;
		int e = sscanf(line.cstr(), "%lf,%[^,],%lf", &t, buf, &m_value);
		if ( e!= 3)
			throw netlist::fatalerror_e("error %d scanning line %s\n", e, line.cstr());
		m_time = netlist::netlist_time::from_double(t);
		m_param = netlist->setup().find_param(buf, true);
	}
예제 #5
0
파일: nlwav.c 프로젝트: matthewbauer/mame
	wav_t(const pstring &fn, unsigned sr)
	{
		m_f = std::fopen(fn.cstr(),"w");
		if (m_f==NULL)
			throw netlist::fatalerror_e("Error opening output file: %s", fn.cstr());
		initialize(sr);
		std::fwrite(&m_fh, sizeof(m_fh), 1, m_f);
		std::fwrite(&m_fmt, sizeof(m_fmt), 1, m_f);
		std::fwrite(&m_data, sizeof(m_data), 1, m_f);
	}
예제 #6
0
파일: nltool.c 프로젝트: ef1105/mameplus
const char *filetobuf(pstring fname)
{
	static pstring pbuf = "";

	if (fname == "-")
	{
		char lbuf[1024];
		while (!feof(stdin))
		{
			fgets(lbuf, 1024, stdin);
			pbuf += lbuf;
		}
		printf("%d\n",*(pbuf.right(1).cstr()+1));
		return pbuf.cstr();
	}
	else
	{
		FILE *f;
		f = fopen(fname, "rb");
		fseek(f, 0, SEEK_END);
		long fsize = ftell(f);
		fseek(f, 0, SEEK_SET);

		char *buf = (char *) malloc(fsize + 1);
		fread(buf, fsize, 1, f);
		buf[fsize] = 0;
		fclose(f);
		return buf;
	}
}
예제 #7
0
	input_t(netlist::netlist_t *netlist, const pstring &line)
	{
		char buf[400];
		double t;
		int e = sscanf(line.cstr(), "%lf,%[^,],%lf", &t, buf, &m_value);
		if ( e!= 3)
			throw netlist::fatalerror_e(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
		m_time = netlist::netlist_time(t);
		m_param = netlist->setup().find_param(buf, true);
	}
예제 #8
0
double nl_convert_base_t::get_sp_unit(const pstring &unit)
{
	int i = 0;
	while (m_units[i].m_unit != "-")
	{
		if (m_units[i].m_unit == unit)
			return m_units[i].m_mult;
		i++;
	}
	fprintf(stderr, "Unit %s unknown\n", unit.cstr());
	return 0.0;
}
예제 #9
0
파일: pstream.c 프로젝트: kkklatu/mame
pofilestream::pofilestream(const pstring &fname) : postream(0), m_pos(0)
{
	m_file = fopen(fname.cstr(), "wb");
	if (m_file == NULL)
	{
		set_flag(FLAG_ERROR);
		set_flag(FLAG_CLOSED);
	}
	else
	{
		if (ftell((FILE *) m_file) >= 0)
		{
			if (fseek((FILE *) m_file, 0, SEEK_SET) >= 0)
				set_flag(FLAG_SEEKABLE);
		}
	}
}
예제 #10
0
void nl_convert_spice_t::process_line(const pstring &line)
{
	if (line != "")
	{
		pstring_vector_t tt(line, " ", true);
		double val = 0.0;
		switch (tt[0].code_at(0))
		{
			case ';':
				out("// {}\n", line.substr(1).cstr());
				break;
			case '*':
				out("// {}\n", line.substr(1).cstr());
				break;
			case '.':
				if (tt[0].equals(".SUBCKT"))
				{
					out("NETLIST_START({})\n", tt[1].cstr());
					for (std::size_t i=2; i<tt.size(); i++)
						add_ext_alias(tt[i]);
				}
				else if (tt[0].equals(".ENDS"))
				{
					dump_nl();
					out("NETLIST_END()\n");
				}
				else
					out("// {}\n", line.cstr());
				break;
			case 'Q':
			{
				bool cerr = false;
				/* check for fourth terminal ... should be numeric net
				 * including "0" or start with "N" (ltspice)
				 */
				ATTR_UNUSED int nval =tt[4].as_long(&cerr);
				pstring model;
				pstring pins ="CBE";

				if ((!cerr || tt[4].startsWith("N")) && tt.size() > 5)
					model = tt[5];
				else
					model = tt[4];
				pstring_vector_t m(model,"{");
				if (m.size() == 2)
				{
					if (m[1].len() != 4)
						fprintf(stderr, "error with model desc %s\n", model.cstr());
					pins = m[1].left(3);
				}
				add_device("QBJT_EB", tt[0], m[0]);
				add_term(tt[1], tt[0] + "." + pins.code_at(0));
				add_term(tt[2], tt[0] + "." + pins.code_at(1));
				add_term(tt[3], tt[0] + "." + pins.code_at(2));
			}
				break;
			case 'R':
				if (tt[0].startsWith("RV"))
				{
					val = get_sp_val(tt[4]);
					add_device("POT", tt[0], val);
					add_term(tt[1], tt[0] + ".1");
					add_term(tt[2], tt[0] + ".2");
					add_term(tt[3], tt[0] + ".3");
				}
				else
				{
					val = get_sp_val(tt[3]);
					add_device("RES", tt[0], val);
					add_term(tt[1], tt[0] + ".1");
					add_term(tt[2], tt[0] + ".2");
				}
				break;
			case 'C':
				val = get_sp_val(tt[3]);
				add_device("CAP", tt[0], val);
				add_term(tt[1], tt[0] + ".1");
				add_term(tt[2], tt[0] + ".2");
				break;
			case 'V':
				// just simple Voltage sources ....
				if (tt[2].equals("0"))
				{
					val = get_sp_val(tt[3]);
					add_device("ANALOG_INPUT", tt[0], val);
					add_term(tt[1], tt[0] + ".Q");
					//add_term(tt[2], tt[0] + ".2");
				}
				else
					fprintf(stderr, "Voltage Source %s not connected to GND\n", tt[0].cstr());
				break;
			case 'I': // Input pin special notation
				{
					val = get_sp_val(tt[2]);
					add_device("ANALOG_INPUT", tt[0], val);
					add_term(tt[1], tt[0] + ".Q");
				}
				break;
			case 'D':
				add_device("DIODE", tt[0], tt[3]);
				/* FIXME ==> does Kicad use different notation from LTSPICE */
				add_term(tt[1], tt[0] + ".K");
				add_term(tt[2], tt[0] + ".A");
				break;
			case 'U':
			case 'X':
			{
				// FIXME: specific code for KICAD exports
				//        last element is component type
				// FIXME: Parameter

				pstring xname = tt[0].replace(".", "_");
				pstring tname = "TTL_" + tt[tt.size()-1] + "_DIP";
				add_device(tname, xname);
				for (std::size_t i=1; i < tt.size() - 1; i++)
				{
					pstring term = pfmt("{1}.{2}")(xname)(i);
					add_term(tt[i], term);
				}
				break;
			}
			default:
				out("// IGNORED {}: {}\n", tt[0].cstr(), line.cstr());
		}
	}
}
예제 #11
0
파일: pparser.c 프로젝트: richard42/mame
void ppreprocessor::error(const pstring &err)
{
	fprintf(stderr, "PREPRO ERROR: %s\n", err.cstr());
}
예제 #12
0
파일: nltool.cpp 프로젝트: dinoue/mame
	void vlog(const plib::plog_level &l, const pstring &ls) const override
	{
		pout("{}: {}\n", l.name().cstr(), ls.cstr());
		if (l == plib::plog_level::FATAL)
			throw std::exception();
	}
예제 #13
0
pifilestream::pifilestream(const pstring &fname)
: pistream(0), m_pos(0), m_actually_close(true)
{
	init(fopen(fname.cstr(), "rb"));
}