summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/emu/netlist/devices/nld_truthtable.c6
-rw-r--r--src/emu/netlist/nl_base.c18
-rw-r--r--src/emu/netlist/nl_base.h13
-rw-r--r--src/emu/netlist/nl_setup.c6
-rw-r--r--src/emu/netlist/plib/palloc.c10
-rw-r--r--src/emu/netlist/plib/palloc.h19
-rw-r--r--src/emu/netlist/plib/pconfig.h1
-rw-r--r--src/emu/netlist/plib/plists.h3
-rw-r--r--src/emu/netlist/plib/pparser.c3
-rw-r--r--src/emu/netlist/plib/pstream.h11
-rw-r--r--src/emu/netlist/plib/pstring.c2
-rw-r--r--src/tools/nltool.c4
-rw-r--r--src/tools/nlwav.c43
13 files changed, 69 insertions, 70 deletions
diff --git a/src/emu/netlist/devices/nld_truthtable.c b/src/emu/netlist/devices/nld_truthtable.c
index b0a75183257..a93435a6af0 100644
--- a/src/emu/netlist/devices/nld_truthtable.c
+++ b/src/emu/netlist/devices/nld_truthtable.c
@@ -135,8 +135,8 @@ void truthtable_desc_t::help(unsigned cur, pstring_list_t list,
{
// cutoff previous inputs and outputs for ignore
if (m_outs[nstate] != ~0U && m_outs[nstate] != val)
- fatalerror_e("Error in truthtable: State %04x already set, %d != %d\n",
- (UINT32) nstate, m_outs[nstate], val);
+ fatalerror_e(pstring::sprintf("Error in truthtable: State %04x already set, %d != %d\n",
+ (UINT32) nstate, m_outs[nstate], val));
m_outs[nstate] = val;
for (unsigned j=0; j<m_NO; j++)
m_timing[nstate * m_NO + j] = timing_index[j];
@@ -231,7 +231,7 @@ void truthtable_desc_t::setup(const pstring_list_t &truthtable, UINT32 disabled_
for (UINT32 i=0; i<m_size; i++)
{
if (m_outs[i] == ~0U)
- fatalerror_e("truthtable: found element not set %04x\n", i);
+ throw fatalerror_e(pstring::sprintf("truthtable: found element not set %04x\n", i));
m_outs[i] |= ((ign[i] & ~disabled_ignore) << m_NO);
}
*m_initialized = true;
diff --git a/src/emu/netlist/nl_base.c b/src/emu/netlist/nl_base.c
index f9887de1349..fca4bf6d089 100644
--- a/src/emu/netlist/nl_base.c
+++ b/src/emu/netlist/nl_base.c
@@ -19,24 +19,6 @@ const netlist::netlist_time netlist::netlist_time::zero = netlist::netlist_time:
namespace netlist
{
-//============================================================
-// Exceptions
-//============================================================
-
-// emu_fatalerror is a generic fatal exception that provides an error string
-fatalerror_e::fatalerror_e(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- m_text = pstring(format).vprintf(ap);
- fprintf(stderr, "%s\n", m_text.cstr());
- va_end(ap);
-}
-
-fatalerror_e::fatalerror_e(const char *format, va_list ap)
-{
- m_text = pstring(format).vprintf(ap);
-}
// ----------------------------------------------------------------------------------------
// logic_family_ttl_t
diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h
index 940c5f54052..58f14bd03e0 100644
--- a/src/emu/netlist/nl_base.h
+++ b/src/emu/netlist/nl_base.h
@@ -254,9 +254,9 @@ virtual logic_family_desc_t *default_logic_family()
#if defined(MAME_DEBUG)
#define nl_assert(x) do { if (!(x)) throw fatalerror_e("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0)
#else
-#define nl_assert(x) do { if (0) if (!(x)) throw fatalerror_e("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0)
+#define nl_assert(x) do { if (0) if (!(x)) throw fatalerror_e(pstring::sprintf("assert: %s:%d: %s", __FILE__, __LINE__, #x)); } while (0)
#endif
-#define nl_assert_always(x, msg) do { if (!(x)) throw fatalerror_e("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0)
+#define nl_assert_always(x, msg) do { if (!(x)) throw fatalerror_e(pstring::sprintf("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x)); } while (0)
// -----------------------------------------------------------------------------
@@ -284,16 +284,11 @@ namespace netlist
// Exceptions
//============================================================
- class fatalerror_e : public std::exception
+ class fatalerror_e : public pexception
{
public:
- fatalerror_e(const char *format, ...) ATTR_PRINTF(2,3);
- fatalerror_e(const char *format, va_list ap);
+ fatalerror_e(const pstring &text) : pexception(text) { }
virtual ~fatalerror_e() throw() {}
-
- const pstring &text() { return m_text; }
- private:
- pstring m_text;
};
class logic_output_t;
diff --git a/src/emu/netlist/nl_setup.c b/src/emu/netlist/nl_setup.c
index 3cb615a2906..22426ac7677 100644
--- a/src/emu/netlist/nl_setup.c
+++ b/src/emu/netlist/nl_setup.c
@@ -243,7 +243,7 @@ void setup_t::register_object(device_t &dev, const pstring &name, object_t &obj)
{
NL_VERBOSE_OUT(("Found parameter ... %s : %s\n", name.cstr(), val.cstr()));
double vald = 0;
- if (std::sscanf(val.cstr(), "%lf", &vald) != 1)
+ if (val.scanf("%lf", &vald) != 1)
netlist().error("Invalid number conversion %s : %s\n", name.cstr(), val.cstr());
dynamic_cast<param_double_t &>(param).initial(vald);
}
@@ -253,7 +253,7 @@ void setup_t::register_object(device_t &dev, const pstring &name, object_t &obj)
{
NL_VERBOSE_OUT(("Found parameter ... %s : %s\n", name.cstr(), val.cstr()));
double vald = 0;
- if (std::sscanf(val.cstr(), "%lf", &vald) != 1)
+ if (val.scanf("%lf", &vald) != 1)
netlist().error("Invalid number conversion %s : %s\n", name.cstr(), val.cstr());
dynamic_cast<param_int_t &>(param).initial((int) vald);
}
@@ -997,7 +997,7 @@ nl_double setup_t::model_value(model_map_t &map, const pstring &entity)
case 'a': factor = 1e-18; break;
default:
if (numfac < '0' || numfac > '9')
- fatalerror_e("Unknown number factor <%c> in: %s", numfac, entity.cstr());
+ fatalerror_e(pstring::sprintf("Unknown number factor <%c> in: %s", numfac, entity.cstr()));
}
if (factor != NL_FCONST(1.0))
tmp = tmp.left(tmp.len() - 1);
diff --git a/src/emu/netlist/plib/palloc.c b/src/emu/netlist/plib/palloc.c
index 2ed54bd0b35..5746264322b 100644
--- a/src/emu/netlist/plib/palloc.c
+++ b/src/emu/netlist/plib/palloc.c
@@ -8,6 +8,16 @@
#include "pconfig.h"
#include "palloc.h"
+//============================================================
+// Exceptions
+//============================================================
+
+pexception::pexception(const pstring &text)
+{
+ m_text = text;
+ fprintf(stderr, "%s\n", m_text.cstr());
+}
+
#if (PSTANDALONE)
#include <stdlib.h>
#include <xmmintrin.h>
diff --git a/src/emu/netlist/plib/palloc.h b/src/emu/netlist/plib/palloc.h
index badbc681486..26f76255e76 100644
--- a/src/emu/netlist/plib/palloc.h
+++ b/src/emu/netlist/plib/palloc.h
@@ -8,9 +8,26 @@
#ifndef PALLOC_H_
#define PALLOC_H_
-#include <cstdio>
+#include <exception>
#include "pconfig.h"
+#include "pstring.h"
+
+//============================================================
+// exception base
+//============================================================
+
+class pexception : public std::exception
+{
+public:
+ pexception(const pstring &text);
+ virtual ~pexception() throw() {}
+
+ const pstring &text() { return m_text; }
+
+private:
+ pstring m_text;
+};
//============================================================
// Memory allocation
diff --git a/src/emu/netlist/plib/pconfig.h b/src/emu/netlist/plib/pconfig.h
index c06fe3e3d2f..434a59e2df1 100644
--- a/src/emu/netlist/plib/pconfig.h
+++ b/src/emu/netlist/plib/pconfig.h
@@ -45,7 +45,6 @@
_name(const _name &); \
_name &operator=(const _name &);
-
//============================================================
// Compiling standalone
//============================================================
diff --git a/src/emu/netlist/plib/plists.h b/src/emu/netlist/plib/plists.h
index bbb553eb12a..96f2d41f42e 100644
--- a/src/emu/netlist/plib/plists.h
+++ b/src/emu/netlist/plib/plists.h
@@ -499,8 +499,7 @@ public:
}
p = p->m_next;
}
- //FXIME: throw a standard exception
- //nl_assert_always(false, "element not found");
+ throw pexception("element not found");
}
}
diff --git a/src/emu/netlist/plib/pparser.c b/src/emu/netlist/plib/pparser.c
index d501ba03c6c..d80c3f83327 100644
--- a/src/emu/netlist/plib/pparser.c
+++ b/src/emu/netlist/plib/pparser.c
@@ -5,7 +5,6 @@
*
*/
-#include <cstdio>
#include <cstdarg>
#include "pparser.h"
@@ -287,7 +286,7 @@ ppreprocessor::ppreprocessor()
void ppreprocessor::error(const pstring &err)
{
- fprintf(stderr, "PREPRO ERROR: %s\n", err.cstr());
+ throw pexception("PREPRO ERROR: " + err);
}
diff --git a/src/emu/netlist/plib/pstream.h b/src/emu/netlist/plib/pstream.h
index 45e5d400500..e82141b0371 100644
--- a/src/emu/netlist/plib/pstream.h
+++ b/src/emu/netlist/plib/pstream.h
@@ -13,6 +13,7 @@
#include "pconfig.h"
#include "pstring.h"
+#include "palloc.h"
// -----------------------------------------------------------------------------
// pstream: things common to all streams
@@ -71,13 +72,13 @@ protected:
void check_not_eof() const
{
if (m_flags & FLAG_EOF)
- throw std::runtime_error("unexpected eof");
+ throw pexception("unexpected eof");
}
void check_seekable() const
{
- if (m_flags & FLAG_SEEKABLE)
- throw std::runtime_error("stream is not seekable");
+ if (!(m_flags & FLAG_SEEKABLE))
+ throw pexception("stream is not seekable");
}
unsigned flags() const { return m_flags; }
@@ -153,7 +154,7 @@ public:
void writeline(const pstring &line)
{
write(line.cstr(), line.len());
- putc(10);
+ write(10);
}
void write(const pstring &text)
@@ -161,7 +162,7 @@ public:
write(text.cstr(), text.len());
}
- void putc(const char c)
+ void write(const char c)
{
write(&c, 1);
}
diff --git a/src/emu/netlist/plib/pstring.c b/src/emu/netlist/plib/pstring.c
index 8d75e019716..3533a26f922 100644
--- a/src/emu/netlist/plib/pstring.c
+++ b/src/emu/netlist/plib/pstring.c
@@ -5,11 +5,11 @@
*
*/
-#include <cstdio>
#include <cstring>
//FIXME:: pstring should be locale free
#include <cctype>
#include <cstdlib>
+#include <cstdio>
#include <algorithm>
#include "pstring.h"
diff --git a/src/tools/nltool.c b/src/tools/nltool.c
index 0153653ba25..a13d7dd183c 100644
--- a/src/tools/nltool.c
+++ b/src/tools/nltool.c
@@ -280,7 +280,7 @@ struct input_t
double t;
int e = line.scanf("%lf,%[^,],%lf", &t, buf, &m_value);
if ( e!= 3)
- throw netlist::fatalerror_e("error %d scanning line %s\n", e, line.cstr());
+ throw netlist::fatalerror_e(pstring::sprintf("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);
}
@@ -291,7 +291,7 @@ struct input_t
{
case netlist::param_t::MODEL:
case netlist::param_t::STRING:
- throw netlist::fatalerror_e("param %s is not numeric\n", m_param->name().cstr());
+ throw netlist::fatalerror_e(pstring::sprintf("param %s is not numeric\n", m_param->name().cstr()));
case netlist::param_t::DOUBLE:
static_cast<netlist::param_double_t*>(m_param)->setTo(m_value);
break;
diff --git a/src/tools/nlwav.c b/src/tools/nlwav.c
index d2bc2268a3e..862888b2eed 100644
--- a/src/tools/nlwav.c
+++ b/src/tools/nlwav.c
@@ -47,15 +47,13 @@ public:
class wav_t
{
public:
- wav_t(const pstring &fn, unsigned sr)
+ wav_t(postream &strm, unsigned sr) : m_f(strm)
{
- m_f = std::fopen(fn.cstr(),"w");
- if (m_f==NULL)
- throw netlist::fatalerror_e("Error opening output file: %s", fn.cstr());
+// m_f = strm;
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);
+ m_f.write(&m_fh, sizeof(m_fh));
+ m_f.write(&m_fmt, sizeof(m_fmt));
+ m_f.write(&m_data, sizeof(m_data));
}
~wav_t()
{
@@ -69,24 +67,17 @@ public:
{
m_data.len += m_fmt.block_align;
short ps = sample; /* 16 bit sample, FIXME: powerpc? */
- std::fwrite(&ps, sizeof(ps), 1, m_f);
+ m_f.write(&ps, sizeof(ps));
}
void close()
{
- if (m_f != NULL)
- {
- std::fseek(m_f, 0, SEEK_SET);
- std::fwrite(&m_fh, sizeof(m_fh), 1, m_f);
- std::fwrite(&m_fmt, sizeof(m_fmt), 1, m_f);
-
- //data.len = fmt.block_align * n;
- std::fwrite(&m_data, sizeof(m_data), 1, m_f);
-
+ m_f.seek(0);
+ m_f.write(&m_fh, sizeof(m_fh));
+ m_f.write(&m_fmt, sizeof(m_fmt));
- std::fclose(m_f);
- m_f = NULL;
- }
+ //data.len = fmt.block_align * n;
+ m_f.write(&m_data, sizeof(m_data));
}
private:
struct riff_chunk_t
@@ -139,17 +130,22 @@ private:
riff_format_t m_fmt;
riff_data_t m_data;
- FILE *m_f;
+ postream &m_f;
};
void convert(nlwav_options_t &opts)
{
- wav_t wo(opts.opt_out(), 48000);
+ pofilestream fo(opts.opt_out());
+ if (fo.bad())
+ {
+ throw netlist::fatalerror_e("Error opening output file: " + opts.opt_out());
+ }
+ wav_t wo(fo, 48000);
pifilestream fin(opts.opt_inp());
if (fin.bad())
- throw netlist::fatalerror_e("Error opening input file: %s", opts.opt_inp().cstr());
+ throw netlist::fatalerror_e("Error opening input file: " + opts.opt_inp());
double dt = 1.0 / (double) wo.sample_rate();
double ct = dt;
@@ -222,6 +218,7 @@ void convert(nlwav_options_t &opts)
printf("Amp + %f\n", 32000.0 / (maxsam- mean));
printf("Amp - %f\n", -32000.0 / (minsam- mean));
wo.close();
+ fo.close();
fin.close();
}