diff options
| author | 2013-12-24 07:24:51 +0000 | |
|---|---|---|
| committer | 2013-12-24 07:24:51 +0000 | |
| commit | ca546caa6e2932e504d020fb80b6cc0e8665cea9 (patch) | |
| tree | aa9f12d46b8088c24d1ff5322d0808c0aacce42c /src/tools/nltool.c | |
| parent | efaac9818f3f4511f7ad5201fcfe3bbd22c007a4 (diff) | |
Cleanups and version bumpmame0152
Diffstat (limited to 'src/tools/nltool.c')
| -rw-r--r-- | src/tools/nltool.c | 211 |
1 files changed, 105 insertions, 106 deletions
diff --git a/src/tools/nltool.c b/src/tools/nltool.c index a9ba2b56b07..4ac904bb663 100644 --- a/src/tools/nltool.c +++ b/src/tools/nltool.c @@ -25,43 +25,43 @@ #if 0 void mame_printf_warning(const char *format, ...) { - va_list argptr; + va_list argptr; - /* do the output */ - va_start(argptr, format); - vprintf(format, argptr); - va_end(argptr); + /* do the output */ + va_start(argptr, format); + vprintf(format, argptr); + va_end(argptr); } #endif void *malloc_file_line(size_t size, const char *file, int line) { - // allocate the memory and fail if we can't - void *ret = osd_malloc(size); - memset(ret, 0, size); - return ret; + // allocate the memory and fail if we can't + void *ret = osd_malloc(size); + memset(ret, 0, size); + return ret; } void *malloc_array_file_line(size_t size, const char *file, int line) { - // allocate the memory and fail if we can't - void *ret = osd_malloc_array(size); - memset(ret, 0, size); - return ret; + // allocate the memory and fail if we can't + void *ret = osd_malloc_array(size); + memset(ret, 0, size); + return ret; } void free_file_line( void *memory, const char *file, int line ) { - osd_free( memory ); + osd_free( memory ); } struct options_entry oplist[] = { - { "time_to_run;ttr", "1.0", OPTION_FLOAT, "time to run the emulation (seconds)" }, - { "f", "-", OPTION_STRING, "file to process (default is stdin)" }, - { "help;h", "0", OPTION_BOOLEAN, "display help" }, - { NULL } + { "time_to_run;ttr", "1.0", OPTION_FLOAT, "time to run the emulation (seconds)" }, + { "f", "-", OPTION_STRING, "file to process (default is stdin)" }, + { "help;h", "0", OPTION_BOOLEAN, "display help" }, + { NULL } }; /*************************************************************************** @@ -70,90 +70,89 @@ struct options_entry oplist[] = 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); - fread(buf, fsize, 1, f); - buf[fsize] = 0; - fclose(f); - return buf; - } + 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); + fread(buf, fsize, 1, f); + buf[fsize] = 0; + fclose(f); + return buf; + } } class netlist_tool_t : public netlist_base_t { public: - netlist_tool_t() - : netlist_base_t(), m_setup(NULL) - { - - } + netlist_tool_t() + : netlist_base_t(), m_setup(NULL) + { + } - virtual ~netlist_tool_t() { }; + virtual ~netlist_tool_t() { }; - void read_netlist(const char *buffer) - { - m_setup = new netlist_setup_t(*this); - this->set_clock_freq(NETLIST_CLOCK); + void read_netlist(const char *buffer) + { + m_setup = new netlist_setup_t(*this); + this->set_clock_freq(NETLIST_CLOCK); - // register additional devices - //m_setup->factory().register_device<nld_analog_callback>( "NETDEV_CALLBACK", "nld_analog_callback"); + // register additional devices + //m_setup->factory().register_device<nld_analog_callback>( "NETDEV_CALLBACK", "nld_analog_callback"); - // read the netlist ... - //m_setup_func(*m_setup); + // read the netlist ... + //m_setup_func(*m_setup); - m_setup->parse(buffer); + m_setup->parse(buffer); - // start devices - m_setup->start_devices(); - m_setup->resolve_inputs(); - // reset - this->reset(); - } + // start devices + m_setup->start_devices(); + m_setup->resolve_inputs(); + // reset + this->reset(); + } protected: - void vfatalerror(const char *format, va_list ap) const - { - vprintf(format, ap); - throw; - } + void vfatalerror(const char *format, va_list ap) const + { + vprintf(format, ap); + throw; + } private: - netlist_setup_t *m_setup; + netlist_setup_t *m_setup; }; void usage(core_options &opts) { - astring buffer; - fprintf(stderr, - "Usage:\n" - " nltool -help\n" - " nltool [options]\n" - "\n" - "Where:\n" - ); - fprintf(stderr, "%s\n", opts.output_help(buffer)); + astring buffer; + fprintf(stderr, + "Usage:\n" + " nltool -help\n" + " nltool [options]\n" + "\n" + "Where:\n" + ); + fprintf(stderr, "%s\n", opts.output_help(buffer)); } /*------------------------------------------------- @@ -166,37 +165,37 @@ int main(int argc, char *argv[]) netlist_tool_t nt; core_options opts(oplist); astring aerror(""); - osd_ticks_t t = osd_ticks(); + osd_ticks_t t = osd_ticks(); - fprintf(stderr, "%s", "WARNING: This is Work In Progress! - It may fail anytime\n"); + 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)) { - fprintf(stderr, "%s\n", aerror.cstr()); - usage(opts); - return 1; + fprintf(stderr, "%s\n", aerror.cstr()); + usage(opts); + return 1; } if (opts.bool_value("h")) { - usage(opts); - return 1; + usage(opts); + return 1; + } + + nt.read_netlist(filetobuf(opts.value("f"))); + double ttr = opts.float_value("ttr"); + + INT64 tt = ttr * NETLIST_CLOCK; + + printf("startup time ==> %5.3f\n", (double) (osd_ticks() - t) / (double) osd_ticks_per_second() ); + printf("runnning ...\n"); + t = osd_ticks(); + while (tt>0) + { + INT32 tr = MIN(tt, NETLIST_CLOCK / 10); + tt -= tr; + nt.process_queue(tr); } + double emutime = (double) (osd_ticks() - t) / (double) osd_ticks_per_second(); + printf("%f seconds emulation took %f real time ==> %5.2f%%\n", ttr, emutime, ttr/emutime*100.0); - nt.read_netlist(filetobuf(opts.value("f"))); - double ttr = opts.float_value("ttr"); - - INT64 tt = ttr * NETLIST_CLOCK; - - printf("startup time ==> %5.3f\n", (double) (osd_ticks() - t) / (double) osd_ticks_per_second() ); - printf("runnning ...\n"); - t = osd_ticks(); - while (tt>0) - { - INT32 tr = MIN(tt, NETLIST_CLOCK / 10); - tt -= tr; - nt.process_queue(tr); - } - double emutime = (double) (osd_ticks() - t) / (double) osd_ticks_per_second(); - printf("%f seconds emulation took %f real time ==> %5.2f%%\n", ttr, emutime, ttr/emutime*100.0); - - return 0; + return 0; } |
