summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/nltool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/nltool.c')
-rw-r--r--src/tools/nltool.c141
1 files changed, 89 insertions, 52 deletions
diff --git a/src/tools/nltool.c b/src/tools/nltool.c
index 4f627f413b6..a2e70ced243 100644
--- a/src/tools/nltool.c
+++ b/src/tools/nltool.c
@@ -8,23 +8,41 @@
****************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <sstream>
-#include <assert.h>
-#include "corefile.h"
-#include "corestr.h"
-#include "sha1.h"
-#include "netlist/nl_base.h"
+#include <cstdio>
+
+#ifdef PSTANDALONE
+#if (PSTANDALONE)
+#define PSTANDALONE_PROVIDED
+#endif
+#endif
+
+#ifdef PSTANDALONE_PROVIDED
+
+#include <ctime>
+
+#include "poptions.h"
+#include "pstring.h"
+#include "plists.h"
+#include "nl_setup.h"
+#include "nl_factory.h"
+#include "nl_parser.h"
+#include "devices/net_lib.h"
+
+#define osd_ticks_t clock_t
+
+inline osd_ticks_t osd_ticks_per_second() { return CLOCKS_PER_SEC; }
+
+osd_ticks_t osd_ticks(void) { return clock(); }
+#else
+
+#include "netlist/poptions.h"
+#include "netlist/pstring.h"
+#include "netlist/plists.h"
#include "netlist/nl_setup.h"
-#include "netlist/nl_parser.h"
#include "netlist/nl_factory.h"
-#include "netlist/nl_util.h"
+#include "netlist/nl_parser.h"
#include "netlist/devices/net_lib.h"
-#include "options.h"
-
+#endif
/***************************************************************************
* MAME COMPATIBILITY ...
*
@@ -79,17 +97,30 @@ void report_bad_cast(const std::type_info &src_type, const std::type_info &dst_t
}
#endif
-struct options_entry oplist[] =
+class tool_options_t : public poptions
{
- { "time_to_run;t", "1.0", OPTION_FLOAT, "time to run the emulation (seconds)" },
- { "logs;l", "", OPTION_STRING, "colon separated list of terminals to log" },
- { "file;f", "-", OPTION_STRING, "file to process (default is stdin)" },
- { "cmd;c", "run", OPTION_STRING, "run|convert|listdevices" },
- { "verbose;v", "0", OPTION_BOOLEAN, "be verbose - this produces lots of output" },
- { "help;h", "0", OPTION_BOOLEAN, "display help" },
- { NULL, NULL, 0, NULL }
+public:
+ tool_options_t() :
+ poptions(),
+ opt_ttr ("t", "time_to_run", 1.0, "time to run the emulation (seconds)", this),
+ opt_logs("l", "logs", "", "colon separated list of terminals to log", this),
+ opt_file("f", "file", "-", "file to process (default is stdin)", this),
+ opt_cmd ("c", "cmd", "run", "run|convert|listdevices", this),
+ opt_verb("v", "verbose", "be verbose - this produces lots of output", this),
+ opt_help("h", "help", "display help", this)
+ {}
+
+ poption_double opt_ttr;
+ poption_str opt_logs;
+ poption_str opt_file;
+ poption_str opt_cmd;
+ poption_bool opt_verb;
+ poption_bool opt_help;
};
+//Alternative
+//static poption *optlist[] = { &opt_ttr, &opt_logs, &opt_file, &opt_cmd, &opt_verb, &opt_help, NULL };
+
NETLIST_START(dummy)
/* Standard stuff */
@@ -148,7 +179,7 @@ public:
void init()
{
- m_setup = nl_alloc(netlist_setup_t, *this);
+ m_setup = palloc(netlist_setup_t, *this);
this->init_object(*this, "netlist");
m_setup->init();
}
@@ -216,9 +247,8 @@ private:
};
-void usage(core_options &opts)
+void usage(tool_options_t &opts)
{
- std::string buffer;
fprintf(stderr,
"Usage:\n"
" nltool -help\n"
@@ -226,19 +256,19 @@ void usage(core_options &opts)
"\n"
"Where:\n"
);
- fprintf(stderr, "%s\n", opts.output_help(buffer));
+ fprintf(stderr, "%s\n", opts.help().cstr());
}
-static void run(core_options &opts)
+static void run(tool_options_t &opts)
{
netlist_tool_t nt;
osd_ticks_t t = osd_ticks();
nt.init();
- nt.m_logs = opts.value("l");
- nt.m_verbose = opts.bool_value("v");
- nt.read_netlist(filetobuf(opts.value("f")));
- double ttr = opts.float_value("t");
+ nt.m_logs = opts.opt_logs();
+ nt.m_verbose = opts.opt_verb();
+ nt.read_netlist(filetobuf(opts.opt_file()));
+ double ttr = opts.opt_ttr();
printf("startup time ==> %5.3f\n", (double) (osd_ticks() - t) / (double) osd_ticks_per_second() );
printf("runnning ...\n");
@@ -316,13 +346,14 @@ static void listdevices()
class convert_t
{
public:
- void convert(pstring contents)
+
+ void convert(const pstring &contents)
{
nl_util::pstring_list spnl = nl_util::split(contents, "\n");
// Add gnd net
- nets.add(nl_alloc(sp_net_t, "0"), false);
+ nets.add(palloc(sp_net_t, "0"), false);
nets[0]->terminals().add("GND");
pstring line = "";
@@ -364,15 +395,15 @@ protected:
struct sp_dev_t
{
public:
- sp_dev_t(const pstring atype, const pstring aname, const pstring amodel)
+ sp_dev_t(const pstring &atype, const pstring &aname, const pstring &amodel)
: m_type(atype), m_name(aname), m_model(amodel), m_val(0), m_has_val(false)
{}
- sp_dev_t(const pstring atype, const pstring aname, double aval)
+ sp_dev_t(const pstring &atype, const pstring &aname, double aval)
: m_type(atype), m_name(aname), m_model(""), m_val(aval), m_has_val(true)
{}
- sp_dev_t(const pstring atype, const pstring aname)
+ sp_dev_t(const pstring &atype, const pstring &aname)
: m_type(atype), m_name(aname), m_model(""), m_val(0.0), m_has_val(false)
{}
@@ -404,7 +435,7 @@ protected:
sp_net_t * net = nets.find(netname);
if (net == NULL)
{
- net = nl_alloc(sp_net_t, netname);
+ net = palloc(sp_net_t, netname);
nets.add(net, false);
}
net->terminals().add(termname);
@@ -497,6 +528,7 @@ protected:
if (line != "")
{
nl_util::pstring_list tt = nl_util::split(line, " ", true);
+ double val = 0.0;
switch (tt[0].cstr()[0])
{
case ';':
@@ -529,21 +561,23 @@ protected:
// FIXME: we need a is_long method ..
ATTR_UNUSED int nval =tt[4].as_long(&cerr);
if ((!cerr || tt[4].startsWith("N")) && tt.count() > 5)
- devs.add(nl_alloc(sp_dev_t, "QBJT", tt[0], tt[5]), false);
+ devs.add(palloc(sp_dev_t, "QBJT", tt[0], tt[5]), false);
else
- devs.add(nl_alloc(sp_dev_t, "QBJT", tt[0], tt[4]), false);
+ devs.add(palloc(sp_dev_t, "QBJT", tt[0], tt[4]), false);
add_term(tt[1], tt[0] + ".C");
add_term(tt[2], tt[0] + ".B");
add_term(tt[3], tt[0] + ".E");
}
break;
case 'R':
- devs.add(nl_alloc(sp_dev_t, "RES", tt[0], get_sp_val(tt[3])), false);
+ val = get_sp_val(tt[3]);
+ devs.add(palloc(sp_dev_t, "RES", tt[0], val), false);
add_term(tt[1], tt[0] + ".1");
add_term(tt[2], tt[0] + ".2");
break;
case 'C':
- devs.add(nl_alloc(sp_dev_t, "CAP", tt[0], get_sp_val(tt[3])), false);
+ val = get_sp_val(tt[3]);
+ devs.add(palloc(sp_dev_t, "CAP", tt[0], val), false);
add_term(tt[1], tt[0] + ".1");
add_term(tt[2], tt[0] + ".2");
break;
@@ -551,7 +585,8 @@ protected:
// just simple Voltage sources ....
if (tt[2].equals("0"))
{
- devs.add(nl_alloc(sp_dev_t, "ANALOG_INPUT", tt[0], get_sp_val(tt[3])), false);
+ val = get_sp_val(tt[3]);
+ devs.add(palloc(sp_dev_t, "ANALOG_INPUT", tt[0], val), false);
add_term(tt[1], tt[0] + ".Q");
//add_term(tt[2], tt[0] + ".2");
}
@@ -560,20 +595,23 @@ protected:
break;
case 'D':
// FIXME: Rewrite resistor value
- devs.add(nl_alloc(sp_dev_t, "DIODE", tt[0], tt[3]), false);
+ devs.add(palloc(sp_dev_t, "DIODE", tt[0], tt[3]), false);
add_term(tt[1], tt[0] + ".A");
add_term(tt[2], tt[0] + ".K");
break;
case 'X':
+ {
// FIXME: specific code for KICAD exports
// last element is component type
- devs.add(nl_alloc(sp_dev_t, "TTL_" + tt[tt.count()-1] + "_DIP", tt[0]), false);
+ pstring tname = "TTL_" + tt[tt.count()-1] + "_DIP";
+ devs.add(palloc(sp_dev_t, tname, tt[0]), false);
for (int i=1; i < tt.count() - 1; i++)
{
pstring term = pstring::sprintf("%s.%d", tt[0].cstr(), i);
add_term(tt[i], term);
}
break;
+ }
default:
printf("// IGNORED %s: %s\n", tt[0].cstr(), line.cstr());
}
@@ -614,32 +652,31 @@ convert_t::sp_unit convert_t::m_sp_units[] = {
int main(int argc, char *argv[])
{
- //int result;
- core_options opts(oplist);
- std::string aerror("");
+ tool_options_t opts;
+ int ret;
fprintf(stderr, "%s", "WARNING: This is Work In Progress! - It may fail anytime\n");
- if (!opts.parse_command_line(argc, argv, OPTION_PRIORITY_DEFAULT, aerror))
+ if ((ret = opts.parse(argc, argv)) != argc)
{
- fprintf(stderr, "%s\n", aerror.c_str());
+ fprintf(stderr, "Error parsing %s\n", argv[ret]);
usage(opts);
return 1;
}
- if (opts.bool_value("h"))
+ if (opts.opt_help())
{
usage(opts);
return 1;
}
- pstring cmd = opts.value("c");
+ pstring cmd = opts.opt_cmd();
if (cmd == "listdevices")
listdevices();
else if (cmd == "run")
run(opts);
else if (cmd == "convert")
{
- pstring contents = filetobuf(opts.value("f"));
+ pstring contents = filetobuf(opts.opt_file());
convert_t converter;
converter.convert(contents);
}