From c26b5dadc48ad48d8a8cbbad082cb951dfca08e1 Mon Sep 17 00:00:00 2001 From: Robbbert Date: Sun, 24 May 2015 13:58:21 +1000 Subject: (MESS) camplynx: added TAP cassette format. --- scripts/src/lib.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'scripts/src') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index d4738644375..54540f0f630 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -168,6 +168,8 @@ project "formats" MAME_DIR .. "src/lib/formats/c4040_dsk.h", MAME_DIR .. "src/lib/formats/c8280_dsk.c", MAME_DIR .. "src/lib/formats/c8280_dsk.h", + MAME_DIR .. "src/lib/formats/camplynx_cas.c", + MAME_DIR .. "src/lib/formats/camplynx_cas.h", MAME_DIR .. "src/lib/formats/cbm_crt.c", MAME_DIR .. "src/lib/formats/cbm_crt.h", MAME_DIR .. "src/lib/formats/cbm_tap.c", -- cgit v1.2.3 From fede658aa6a2b78b1309e9b53f3bdc1094605912 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 24 May 2015 13:00:35 +0200 Subject: Cleaned up includes in header files and reworked memory allocation. (nw) --- scripts/src/netlist.lua | 5 +- src/emu/netlist/analog/nld_ms_direct.h | 26 ++---- src/emu/netlist/analog/nld_ms_jakobi.h | 2 - src/emu/netlist/analog/nld_ms_sor.h | 2 - src/emu/netlist/analog/nld_ms_sor_mat.h | 16 ++-- src/emu/netlist/analog/nld_solver.c | 17 ++-- src/emu/netlist/analog/nld_twoterm.c | 6 +- src/emu/netlist/devices/nld_log.c | 8 +- src/emu/netlist/devices/nld_log.h | 2 +- src/emu/netlist/nl_base.c | 43 ++++++++-- src/emu/netlist/nl_base.h | 32 ++++++- src/emu/netlist/nl_config.h | 143 +------------------------------- src/emu/netlist/nl_dice_compat.h | 2 +- src/emu/netlist/nl_factory.c | 6 +- src/emu/netlist/nl_factory.h | 5 +- src/emu/netlist/nl_lists.h | 3 +- src/emu/netlist/nl_setup.c | 19 +++-- src/emu/netlist/nl_setup.h | 3 - src/emu/netlist/palloc.c | 22 +++++ src/emu/netlist/palloc.h | 93 +++++++++++++++++++++ src/emu/netlist/pconfig.h | 79 ++++++++++++++++++ src/emu/netlist/plists.h | 32 +++---- src/emu/netlist/pstate.c | 5 +- src/emu/netlist/pstate.h | 2 - src/emu/netlist/pstring.c | 76 +++++++++++++---- src/emu/netlist/pstring.h | 45 ++++------ src/tools/nltool.c | 39 +++++---- 27 files changed, 431 insertions(+), 302 deletions(-) create mode 100644 src/emu/netlist/palloc.c create mode 100644 src/emu/netlist/palloc.h create mode 100644 src/emu/netlist/pconfig.h (limited to 'scripts/src') diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 6c79eb1b463..96d81688fc3 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -7,7 +7,6 @@ files { MAME_DIR .. "src/emu/netlist/nl_lists.h", MAME_DIR .. "src/emu/netlist/nl_time.h", MAME_DIR .. "src/emu/netlist/nl_util.h", - MAME_DIR .. "src/emu/netlist/plists.h", MAME_DIR .. "src/emu/netlist/nl_base.c", MAME_DIR .. "src/emu/netlist/nl_base.h", MAME_DIR .. "src/emu/netlist/nl_parser.c", @@ -16,8 +15,12 @@ files { MAME_DIR .. "src/emu/netlist/nl_setup.h", MAME_DIR .. "src/emu/netlist/nl_factory.c", MAME_DIR .. "src/emu/netlist/nl_factory.h", + MAME_DIR .. "src/emu/netlist/pconfig.h", + MAME_DIR .. "src/emu/netlist/palloc.c", + MAME_DIR .. "src/emu/netlist/palloc.h", MAME_DIR .. "src/emu/netlist/pstring.c", MAME_DIR .. "src/emu/netlist/pstring.h", + MAME_DIR .. "src/emu/netlist/plists.h", MAME_DIR .. "src/emu/netlist/pstate.c", MAME_DIR .. "src/emu/netlist/pstate.h", MAME_DIR .. "src/emu/netlist/analog/nld_bjt.c", diff --git a/src/emu/netlist/analog/nld_ms_direct.h b/src/emu/netlist/analog/nld_ms_direct.h index a57dcfc0869..44dbc027699 100644 --- a/src/emu/netlist/analog/nld_ms_direct.h +++ b/src/emu/netlist/analog/nld_ms_direct.h @@ -67,20 +67,12 @@ private: template netlist_matrix_solver_direct_t::~netlist_matrix_solver_direct_t() { - for (int k=0; k<_storage_N; k++) - { - //delete[] m_A[k]; - } for (int k = 0; k < N(); k++) { - nl_free(m_terms[k]); + pfree(m_terms[k]); } - //delete[] m_last_RHS; - //delete[] m_RHS; - nl_free_array(m_terms); - nl_free_array(m_rails_temp); - //delete[] m_row_ops; - + pfree_array(m_terms); + pfree_array(m_rails_temp); } template @@ -431,12 +423,12 @@ netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t( , m_dim(size) , m_lp_fact(0) { - m_terms = nl_alloc_array(terms_t *, N()); - m_rails_temp = nl_alloc_array(terms_t, N()); + m_terms = palloc_array(terms_t *, N()); + m_rails_temp = palloc_array(terms_t, N()); for (int k = 0; k < N(); k++) { - m_terms[k] = nl_alloc(terms_t); + m_terms[k] = palloc(terms_t); } } @@ -446,12 +438,12 @@ netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t( , m_dim(size) , m_lp_fact(0) { - m_terms = nl_alloc_array(terms_t *, N()); - m_rails_temp = nl_alloc_array(terms_t, N()); + m_terms = palloc_array(terms_t *, N()); + m_rails_temp = palloc_array(terms_t, N()); for (int k = 0; k < N(); k++) { - m_terms[k] = nl_alloc(terms_t); + m_terms[k] = palloc(terms_t); } } diff --git a/src/emu/netlist/analog/nld_ms_jakobi.h b/src/emu/netlist/analog/nld_ms_jakobi.h index e64e28f6f41..367656b7fb1 100644 --- a/src/emu/netlist/analog/nld_ms_jakobi.h +++ b/src/emu/netlist/analog/nld_ms_jakobi.h @@ -8,8 +8,6 @@ #ifndef NLD_MS_GAUSS_SEIDEL_H_ #define NLD_MS_GAUSS_SEIDEL_H_ -#include - #include "nld_solver.h" #include "nld_ms_direct.h" diff --git a/src/emu/netlist/analog/nld_ms_sor.h b/src/emu/netlist/analog/nld_ms_sor.h index fe9ee0366a6..3e9348d8cd6 100644 --- a/src/emu/netlist/analog/nld_ms_sor.h +++ b/src/emu/netlist/analog/nld_ms_sor.h @@ -12,8 +12,6 @@ #ifndef NLD_MS_SOR_H_ #define NLD_MS_SOR_H_ -#include - #include "nld_solver.h" #include "nld_ms_direct.h" diff --git a/src/emu/netlist/analog/nld_ms_sor_mat.h b/src/emu/netlist/analog/nld_ms_sor_mat.h index 52bbe8e5743..911137984f0 100644 --- a/src/emu/netlist/analog/nld_ms_sor_mat.h +++ b/src/emu/netlist/analog/nld_ms_sor_mat.h @@ -12,8 +12,6 @@ #ifndef NLD_MS_SOR_MAT_H_ #define NLD_MS_SOR_MAT_H_ -#include - #include "nld_solver.h" #include "nld_ms_direct.h" @@ -64,13 +62,13 @@ void netlist_matrix_solver_SOR_mat_t::log_stats() { if (this->m_stat_calculations != 0 && m_log_stats) { - printf("==============================================\n"); - printf("Solver %s\n", this->name().cstr()); - printf(" ==> %d nets\n", this->N()); //, (*(*groups[i].first())->m_core_terms.first())->name().cstr()); - printf(" has %s elements\n", this->is_dynamic() ? "dynamic" : "no dynamic"); - printf(" has %s elements\n", this->is_timestep() ? "timestep" : "no timestep"); - printf(" %6.3f average newton raphson loops\n", (double) this->m_stat_newton_raphson / (double) this->m_stat_vsolver_calls); - printf(" %10d invocations (%6d Hz) %10d gs fails (%6.2f%%) %6.3f average\n", + this->netlist().log("==============================================\n"); + this->netlist().log("Solver %s\n", this->name().cstr()); + this->netlist().log(" ==> %d nets\n", this->N()); //, (*(*groups[i].first())->m_core_terms.first())->name().cstr()); + this->netlist().log(" has %s elements\n", this->is_dynamic() ? "dynamic" : "no dynamic"); + this->netlist().log(" has %s elements\n", this->is_timestep() ? "timestep" : "no timestep"); + this->netlist().log(" %6.3f average newton raphson loops\n", (double) this->m_stat_newton_raphson / (double) this->m_stat_vsolver_calls); + this->netlist().log(" %10d invocations (%6d Hz) %10d gs fails (%6.2f%%) %6.3f average\n", this->m_stat_calculations, this->m_stat_calculations * 10 / (int) (this->netlist().time().as_double() * 10.0), this->m_gs_fail, diff --git a/src/emu/netlist/analog/nld_solver.c b/src/emu/netlist/analog/nld_solver.c index 4b734f30fa8..3b0bf32149a 100644 --- a/src/emu/netlist/analog/nld_solver.c +++ b/src/emu/netlist/analog/nld_solver.c @@ -79,8 +79,7 @@ ATTR_COLD netlist_matrix_solver_t::netlist_matrix_solver_t(const eSolverType typ ATTR_COLD netlist_matrix_solver_t::~netlist_matrix_solver_t() { - for (int i = 0; i < m_inps.count(); i++) - global_free(m_inps[i]); + m_inps.clear_and_free(); } ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets) @@ -144,7 +143,7 @@ ATTR_COLD void netlist_matrix_solver_t::setup(netlist_analog_net_t::list_t &nets if (net_proxy_output == NULL) { - net_proxy_output = nl_alloc(netlist_analog_output_t); + net_proxy_output = palloc(netlist_analog_output_t); net_proxy_output->init_object(*this, this->name() + "." + pstring::sprintf("m%d", m_inps.count())); m_inps.add(net_proxy_output); net_proxy_output->m_proxied_net = &p->net().as_analog(); @@ -352,7 +351,7 @@ NETLIB_NAME(solver)::~NETLIB_NAME(solver)() while (e != NULL) { netlist_matrix_solver_t * const *en = m_mat_solvers.next(e); - global_free(*e); + pfree(*e); e = en; } @@ -410,9 +409,9 @@ template netlist_matrix_solver_t * NETLIB_NAME(solver)::create_solver(int size, const int gs_threshold, const bool use_specific) { if (use_specific && m_N == 1) - return nl_alloc(netlist_matrix_solver_direct1_t, m_params); + return palloc(netlist_matrix_solver_direct1_t, m_params); else if (use_specific && m_N == 2) - return nl_alloc(netlist_matrix_solver_direct2_t, m_params); + return palloc(netlist_matrix_solver_direct2_t, m_params); else { if (size >= gs_threshold) @@ -420,18 +419,18 @@ netlist_matrix_solver_t * NETLIB_NAME(solver)::create_solver(int size, const int if (USE_MATRIX_GS) { typedef netlist_matrix_solver_SOR_mat_t solver_mat; - return nl_alloc(solver_mat, m_params, size); + return palloc(solver_mat, m_params, size); } else { typedef netlist_matrix_solver_SOR_t solver_GS; - return nl_alloc(solver_GS, m_params, size); + return palloc(solver_GS, m_params, size); } } else { typedef netlist_matrix_solver_direct_t solver_D; - return nl_alloc(solver_D, m_params, size); + return palloc(solver_D, m_params, size); } } } diff --git a/src/emu/netlist/analog/nld_twoterm.c b/src/emu/netlist/analog/nld_twoterm.c index 6e92bc9d8c9..02ec7fa9c29 100644 --- a/src/emu/netlist/analog/nld_twoterm.c +++ b/src/emu/netlist/analog/nld_twoterm.c @@ -171,8 +171,8 @@ NETLIB_UPDATE_PARAM(POT) m_R1.update_dev(); m_R2.update_dev(); - m_R1.set_R(MAX(m_R.Value() * v, netlist().gmin())); - m_R2.set_R(MAX(m_R.Value() * (1.0 - v), netlist().gmin())); + m_R1.set_R(std::max(m_R.Value() * v, netlist().gmin())); + m_R2.set_R(std::max(m_R.Value() * (1.0 - v), netlist().gmin())); } @@ -218,7 +218,7 @@ NETLIB_UPDATE_PARAM(POT2) m_R1.update_dev(); - m_R1.set_R(MAX(m_R.Value() * v, netlist().gmin())); + m_R1.set_R(std::max(m_R.Value() * v, netlist().gmin())); } // ---------------------------------------------------------------------------------------- diff --git a/src/emu/netlist/devices/nld_log.c b/src/emu/netlist/devices/nld_log.c index 51bbad790ab..a57301df744 100644 --- a/src/emu/netlist/devices/nld_log.c +++ b/src/emu/netlist/devices/nld_log.c @@ -5,6 +5,8 @@ * */ +#include + #include "nld_log.h" //#include "sound/wavwrite.h" @@ -24,12 +26,12 @@ NETLIB_RESET(log) NETLIB_UPDATE(log) { - fprintf(m_file, "%20.9e %e\n", netlist().time().as_double(), (nl_double) INPANALOG(m_I)); + std::fprintf(static_cast(m_file), "%20.9e %e\n", netlist().time().as_double(), (nl_double) INPANALOG(m_I)); } NETLIB_NAME(log)::~NETLIB_NAME(log)() { - fclose(m_file); + std::fclose(static_cast(m_file)); } NETLIB_START(logD) @@ -44,7 +46,7 @@ NETLIB_RESET(logD) NETLIB_UPDATE(logD) { - fprintf(m_file, "%e %e\n", netlist().time().as_double(), (nl_double) (INPANALOG(m_I) - INPANALOG(m_I2))); + std::fprintf(static_cast(m_file), "%e %e\n", netlist().time().as_double(), (nl_double) (INPANALOG(m_I) - INPANALOG(m_I2))); } // FIXME: Implement wav later, this must be clock triggered device where the input to be written diff --git a/src/emu/netlist/devices/nld_log.h b/src/emu/netlist/devices/nld_log.h index bf0bbe31a0d..99fd9541602 100644 --- a/src/emu/netlist/devices/nld_log.h +++ b/src/emu/netlist/devices/nld_log.h @@ -28,7 +28,7 @@ NETLIB_DEVICE(log, ~NETLIB_NAME(log)(); netlist_analog_input_t m_I; protected: - FILE * m_file; + void * m_file; ); #define LOGD(_name, _I, _I2) \ diff --git a/src/emu/netlist/nl_base.c b/src/emu/netlist/nl_base.c index e61cb65a09c..090dc901210 100644 --- a/src/emu/netlist/nl_base.c +++ b/src/emu/netlist/nl_base.c @@ -5,6 +5,10 @@ * */ +#include + +#include "palloc.h" + #include "nl_base.h" #include "devices/nld_system.h" #include "analog/nld_solver.h" @@ -13,6 +17,28 @@ const netlist_time netlist_time::zero = netlist_time::from_raw(0); +//============================================================ +// Exceptions +//============================================================ + +// emu_fatalerror is a generic fatal exception that provides an error string +nl_fatalerror::nl_fatalerror(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + m_text = pstring(format).vprintf(ap); + va_end(ap); +} + +nl_fatalerror::nl_fatalerror(const char *format, va_list ap) +{ + m_text = pstring(format).vprintf(ap); +} + +// ---------------------------------------------------------------------------------------- +// netlist_logic_family_ttl_t +// ---------------------------------------------------------------------------------------- + class netlist_logic_family_ttl_t : public netlist_logic_family_desc_t { public: @@ -28,7 +54,7 @@ public: } virtual nld_base_d_to_a_proxy *create_d_a_proxy(netlist_logic_output_t &proxied) const { - return nl_alloc(nld_d_to_a_proxy , proxied); + return palloc(nld_d_to_a_proxy , proxied); } }; @@ -48,7 +74,7 @@ public: } virtual nld_base_d_to_a_proxy *create_d_a_proxy(netlist_logic_output_t &proxied) const { - return nl_alloc(nld_d_to_a_proxy , proxied); + return palloc(nld_d_to_a_proxy , proxied); } }; @@ -84,9 +110,10 @@ void netlist_queue_t::on_pre_save() for (int i = 0; i < m_qsize; i++ ) { m_times[i] = this->listptr()[i].exec_time().as_raw(); - const char *p = this->listptr()[i].object()->name().cstr(); - int n = MIN(63, strlen(p)); - strncpy(&(m_name[i][0]), p, n); + pstring p = this->listptr()[i].object()->name(); + int n = p.len(); + n = std::min(63, n); + std::strncpy(&(m_name[i][0]), p, n); m_name[i][n] = 0; } } @@ -117,7 +144,7 @@ ATTR_COLD netlist_object_t::netlist_object_t(const type_t atype, const family_t ATTR_COLD netlist_object_t::~netlist_object_t() { - //delete m_name; + } ATTR_COLD void netlist_object_t::init_object(netlist_base_t &nl, const pstring &aname) @@ -161,10 +188,10 @@ netlist_base_t::netlist_base_t() m_stop(netlist_time::zero), m_time(netlist_time::zero), m_queue(*this), - m_use_deactivate(0), m_mainclock(NULL), m_solver(NULL), m_gnd(NULL), + m_use_deactivate(0), m_setup(NULL) { } @@ -175,7 +202,7 @@ netlist_base_t::~netlist_base_t() { if (!m_nets[i]->isRailNet()) { - global_free(m_nets[i]); + pfree(m_nets[i]); } } diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h index a5f471f5f5a..bb2eef986c7 100644 --- a/src/emu/netlist/nl_base.h +++ b/src/emu/netlist/nl_base.h @@ -254,6 +254,32 @@ ATTR_COLD virtual const netlist_logic_family_desc_t *default_logic_family() return &netlist_family_ ## _fam; \ } +//============================================================ +// Exceptions +//============================================================ + +class nl_fatalerror : public std::exception +{ +public: + nl_fatalerror(const char *format, ...) ATTR_PRINTF(2,3); + nl_fatalerror(const char *format, va_list ap); + virtual ~nl_fatalerror() throw() {} + + inline const pstring &text() { return m_text; } +private: + pstring m_text; +}; + +//============================================================ +// Asserts +//============================================================ + +#ifdef MAME_DEBUG +#define nl_assert(x) do { if (!(x)) throw nl_fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0) +#else +#define nl_assert(x) do { if (0) if (!(x)) throw nl_fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0) +#endif +#define nl_assert_always(x, msg) do { if (!(x)) throw nl_fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0) // ----------------------------------------------------------------------------- @@ -619,8 +645,6 @@ protected: } }; -//#define INPVAL(_x) (_x).Q() - // ----------------------------------------------------------------------------- // net_net_t // ----------------------------------------------------------------------------- @@ -1246,12 +1270,12 @@ private: netlist_time m_time; netlist_queue_t m_queue; - bool m_use_deactivate; - NETLIB_NAME(mainclock) * m_mainclock; NETLIB_NAME(solver) * m_solver; NETLIB_NAME(gnd) * m_gnd; + bool m_use_deactivate; + NETLIB_NAME(netlistparams) *m_params; netlist_setup_t *m_setup; }; diff --git a/src/emu/netlist/nl_config.h b/src/emu/netlist/nl_config.h index 5baf097d352..b4c08feafcb 100644 --- a/src/emu/netlist/nl_config.h +++ b/src/emu/netlist/nl_config.h @@ -8,14 +8,7 @@ #ifndef NLCONFIG_H_ #define NLCONFIG_H_ -/* FIXME: at some time, make it compile on its own */ - -#include "osdcore.h" -#include "corealloc.h" -#include "eminline.h" -#include -#include -#include +#include "pconfig.h" //============================================================ // SETUP @@ -102,8 +95,6 @@ // DEBUGGING //============================================================ -//#define fatalerror xxbreakme - #define NL_VERBOSE (0) #define NL_KEEP_STATISTICS (0) @@ -129,16 +120,6 @@ _name(const _name &); \ _name &operator=(const _name &); -#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) -#if !defined(__ppc__) && !defined (__PPC__) && !defined(__ppc64__) && !defined(__PPC64__) -#define ATTR_ALIGN __attribute__ ((aligned(64))) -#else -#define ATTR_ALIGN -#endif -#else -#define ATTR_ALIGN -#endif - //============================================================ // Performance tracking //============================================================ @@ -158,128 +139,6 @@ // this macro passes an item followed by a string version of itself as two consecutive parameters #define NLNAME(x) x, #x -//============================================================ -// Exceptions -//============================================================ - -// emu_fatalerror is a generic fatal exception that provides an error string -class nl_fatalerror : public std::exception -{ -public: - nl_fatalerror(const char *format, ...) ATTR_PRINTF(2,3) - { - char text[1024]; - va_list ap; - va_start(ap, format); - vsprintf(text, format, ap); - va_end(ap); - osd_printf_error("%s\n", text); - } - nl_fatalerror(const char *format, va_list ap) - { - char text[1024]; - vsprintf(text, format, ap); - osd_printf_error("%s\n", text); - } -}; - -//============================================================ -// Memory allocation -//============================================================ - -#define nl_alloc(T, ...) global_alloc(T(__VA_ARGS__)) -#define nl_alloc_array(T, N) global_alloc_array(T, N) - -#define nl_free(_ptr) global_free(_ptr) -#define nl_free_array(_ptr) global_free_array(_ptr) - - -//============================================================ -// Asserts -//============================================================ - -#ifdef MAME_DEBUG -#define nl_assert(x) do { if (!(x)) throw nl_fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0) -#else -#define nl_assert(x) do { if (0) if (!(x)) throw nl_fatalerror("assert: %s:%d: %s", __FILE__, __LINE__, #x); } while (0) -//#define assert_always(x, msg) do { if (!(x)) throw emu_fatalerror("Fatal error: %s (%s:%d)", msg, __FILE__, __LINE__); } while (0) -#endif -#define nl_assert_always(x, msg) do { if (!(x)) throw nl_fatalerror("Fatal error: %s\nCaused by assert: %s:%d: %s", msg, __FILE__, __LINE__, #x); } while (0) - -//============================================================ -// Compiling standalone -//============================================================ - -// Compiling without mame ? - -#ifndef ATTR_HOT -#warning ATTR_HOT not defined - -// standard C includes -#include -#include -#include -#include -#include - -// standard C++ includes -#include -#include -#include - -#define ATTR_HOT -#define ATTR_COLD -#define ATTR_PRINTF(n1,n2) -#define RESTRICT -#define EXPECTED -#define UNEXPECTED -#define ATTR_UNUSED __attribute__((__unused__)) - -/* 8-bit values */ -typedef unsigned char UINT8; -typedef signed char INT8; - -/* 16-bit values */ -typedef unsigned short UINT16; -typedef signed short INT16; - -/* 32-bit values */ -#ifndef _WINDOWS_H -typedef unsigned int UINT32; -typedef signed int INT32; -#endif - -/* 64-bit values */ -#ifndef _WINDOWS_H -#ifdef _MSC_VER -typedef signed __int64 INT64; -typedef unsigned __int64 UINT64; -#else -__extension__ typedef unsigned long long UINT64; -__extension__ typedef signed long long INT64; -#endif -#endif - -/* U64 and S64 are used to wrap long integer constants. */ -#if defined(__GNUC__) || defined(_MSC_VER) -#define U64(val) val##ULL -#define S64(val) val##LL -#else -#define U64(val) val -#define S64(val) val -#endif - -/* Standard MIN/MAX macros */ -#ifndef MIN -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -#endif -#ifndef MAX -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#endif - - -#endif - //============================================================ // WARNINGS //============================================================ diff --git a/src/emu/netlist/nl_dice_compat.h b/src/emu/netlist/nl_dice_compat.h index 45a20f1b533..f67a7895658 100644 --- a/src/emu/netlist/nl_dice_compat.h +++ b/src/emu/netlist/nl_dice_compat.h @@ -41,7 +41,7 @@ sed -e 's/#define \(.*\)"\(.*\)"[ \t]*,[ \t]*\(.*\)/NET_ALIAS(\1,\2.\3)/' src/ma #ifndef NL_CONVERT_CPP #ifdef NETLIST_DEVELOPMENT -#define CHIP(_n, _t) setup.register_dev( nl_alloc(nld_ ## _t ## _dip), _n); +#define CHIP(_n, _t) setup.register_dev( palloc(nld_ ## _t ## _dip), _n); #else #define CHIP(_n, _t) setup.register_dev(NETLIB_NAME_STR(_t ## _dip), _n); #endif diff --git a/src/emu/netlist/nl_factory.c b/src/emu/netlist/nl_factory.c index 7c6f38dcac4..f79cfc81155 100644 --- a/src/emu/netlist/nl_factory.c +++ b/src/emu/netlist/nl_factory.c @@ -80,7 +80,7 @@ netlist_factory_t::~netlist_factory_t() for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e)) { net_device_t_base_factory *p = *e; - global_free(p); + pfree(p); } m_list.clear(); } @@ -90,7 +90,7 @@ netlist_device_t *netlist_factory_t::new_device_by_classname(const pstring &clas for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e)) { net_device_t_base_factory *p = *e; - if (strcmp(p->classname(), classname) == 0) + if (p->classname() == classname) { netlist_device_t *ret = p->Create(); return ret; @@ -111,7 +111,7 @@ net_device_t_base_factory * netlist_factory_t::factory_by_name(const pstring &na for (net_device_t_base_factory * const *e = m_list.first(); e != NULL; e = m_list.next(e)) { net_device_t_base_factory *p = *e; - if (strcmp(p->name(), name) == 0) + if (p->name() == name) { return p; } diff --git a/src/emu/netlist/nl_factory.h b/src/emu/netlist/nl_factory.h index 421bdfefdad..1998dbd07d2 100644 --- a/src/emu/netlist/nl_factory.h +++ b/src/emu/netlist/nl_factory.h @@ -10,6 +10,7 @@ #define NLFACTORY_H_ #include "nl_config.h" +#include "palloc.h" #include "plists.h" #include "nl_base.h" #include "pstring.h" @@ -54,7 +55,7 @@ public: ATTR_COLD netlist_device_t *Create() const { - netlist_device_t *r = nl_alloc(C); + netlist_device_t *r = palloc(C); //r->init(setup, name); return r; } @@ -72,7 +73,7 @@ public: ATTR_COLD void register_device(const pstring &name, const pstring &classname, const pstring &def_param) { - m_list.add(nl_alloc(net_device_t_factory< _C >, name, classname, def_param)); + m_list.add(palloc(net_device_t_factory< _C >, name, classname, def_param)); } ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname) const; diff --git a/src/emu/netlist/nl_lists.h b/src/emu/netlist/nl_lists.h index b0bfdd9b517..4f410e55cb9 100644 --- a/src/emu/netlist/nl_lists.h +++ b/src/emu/netlist/nl_lists.h @@ -45,7 +45,6 @@ public: netlist_timed_queue() { - //m_list = global_alloc_array(entry_t, SIZE); clear(); } @@ -64,7 +63,7 @@ public: } *i = e; inc_stat(m_prof_sort); - nl_assert(m_end - m_list < _Size); + //nl_assert(m_end - m_list < _Size); } ATTR_HOT inline const entry_t *pop() diff --git a/src/emu/netlist/nl_setup.c b/src/emu/netlist/nl_setup.c index ba69d6bd47c..bab76e657cd 100644 --- a/src/emu/netlist/nl_setup.c +++ b/src/emu/netlist/nl_setup.c @@ -5,6 +5,9 @@ * */ +#include + +#include "palloc.h" #include "nl_base.h" #include "nl_setup.h" #include "nl_parser.h" @@ -36,7 +39,7 @@ netlist_setup_t::netlist_setup_t(netlist_base_t &netlist) , m_proxy_cnt(0) { netlist.set_setup(this); - m_factory = nl_alloc(netlist_factory_t); + m_factory = palloc(netlist_factory_t); } void netlist_setup_t::init() @@ -55,7 +58,7 @@ netlist_setup_t::~netlist_setup_t() m_params_temp.clear(); netlist().set_setup(NULL); - nl_free(m_factory); + pfree(m_factory); pstring::resetmem(); } @@ -221,7 +224,7 @@ void netlist_setup_t::register_object(netlist_device_t &dev, const pstring &name { NL_VERBOSE_OUT(("Found parameter ... %s : %s\n", name.cstr(), val.cstr())); double vald = 0; - if (sscanf(val.cstr(), "%lf", &vald) != 1) + if (std::sscanf(val.cstr(), "%lf", &vald) != 1) netlist().error("Invalid number conversion %s : %s\n", name.cstr(), val.cstr()); dynamic_cast(param).initial(vald); } @@ -231,7 +234,7 @@ void netlist_setup_t::register_object(netlist_device_t &dev, const pstring &name { NL_VERBOSE_OUT(("Found parameter ... %s : %s\n", name.cstr(), val.cstr())); double vald = 0; - if (sscanf(val.cstr(), "%lf", &vald) != 1) + if (std::sscanf(val.cstr(), "%lf", &vald) != 1) netlist().error("Invalid number conversion %s : %s\n", name.cstr(), val.cstr()); dynamic_cast(param).initial((int) vald); } @@ -436,7 +439,7 @@ void netlist_setup_t::connect_input_output(netlist_core_terminal_t &in, netlist_ if (out.isFamily(netlist_terminal_t::ANALOG) && in.isFamily(netlist_terminal_t::LOGIC)) { netlist_logic_input_t &incast = dynamic_cast(in); - nld_a_to_d_proxy *proxy = nl_alloc(nld_a_to_d_proxy, incast); + nld_a_to_d_proxy *proxy = palloc(nld_a_to_d_proxy, incast); incast.set_proxy(proxy); pstring x = pstring::sprintf("proxy_ad_%s_%d", in.name().cstr(), m_proxy_cnt); m_proxy_cnt++; @@ -475,7 +478,7 @@ void netlist_setup_t::connect_terminal_input(netlist_terminal_t &term, netlist_c { netlist_logic_input_t &incast = dynamic_cast(inp); NL_VERBOSE_OUT(("connect_terminal_input: connecting proxy\n")); - nld_a_to_d_proxy *proxy = nl_alloc(nld_a_to_d_proxy, incast); + nld_a_to_d_proxy *proxy = palloc(nld_a_to_d_proxy, incast); incast.set_proxy(proxy); pstring x = pstring::sprintf("proxy_ad_%s_%d", inp.name().cstr(), m_proxy_cnt); m_proxy_cnt++; @@ -544,7 +547,7 @@ void netlist_setup_t::connect_terminals(netlist_core_terminal_t &t1, netlist_cor else { NL_VERBOSE_OUT(("adding net ...\n")); - netlist_analog_net_t *anet = nl_alloc(netlist_analog_net_t); + netlist_analog_net_t *anet = palloc(netlist_analog_net_t); t1.set_net(*anet); //m_netlist.solver()->m_nets.add(anet); // FIXME: Nets should have a unique name @@ -721,7 +724,7 @@ void netlist_setup_t::resolve_inputs() netlist().log("Deleting net %s ...", todelete[i]->name().cstr()); netlist().m_nets.remove(todelete[i]); if (!todelete[i]->isRailNet()) - delete todelete[i]; + pfree(todelete[i]); } pstring errstr(""); diff --git a/src/emu/netlist/nl_setup.h b/src/emu/netlist/nl_setup.h index d58893ca6af..311ca0bfa63 100644 --- a/src/emu/netlist/nl_setup.h +++ b/src/emu/netlist/nl_setup.h @@ -9,7 +9,6 @@ #define NLSETUP_H_ #include "nl_base.h" -//#include "nl_factory.h" //============================================================ // MACROS / inline netlist definitions @@ -23,8 +22,6 @@ #define ALIAS(_alias, _name) \ setup.register_alias(# _alias, # _name); -//#define NET_NEW(_type) setup.factory().new_device_by_classname(NETLIB_NAME_STR(_type), setup) - #define NET_REGISTER_DEV(_type, _name) \ setup.register_dev(NETLIB_NAME_STR(_type), # _name); diff --git a/src/emu/netlist/palloc.c b/src/emu/netlist/palloc.c new file mode 100644 index 00000000000..37b6a1ab58f --- /dev/null +++ b/src/emu/netlist/palloc.c @@ -0,0 +1,22 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * palloc.c + * + */ + +#include +#include + +void *palloc_raw(const size_t size) +{ + //size_t asize = ((size + 63) / 64) * 64; + //return aligned_alloc(64, asize); + return _mm_malloc(size, 64); +} + +void pfree_raw(void *p) +{ + //free(p); + _mm_free(p); +} diff --git a/src/emu/netlist/palloc.h b/src/emu/netlist/palloc.h new file mode 100644 index 00000000000..cf0039327c7 --- /dev/null +++ b/src/emu/netlist/palloc.h @@ -0,0 +1,93 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * palloc.h + * + */ + +#ifndef PALLOC_H_ +#define PALLOC_H_ + +#include "pconfig.h" + +//============================================================ +// Memory allocation +//============================================================ + +#if (PSTANDALONE) +#include +#include + +void *palloc_raw(const size_t size); +void pfree_raw(void *p); + +template +inline T *palloc_t() +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(); +} + +template +inline T *palloc_t(P1 &p1) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1); +} + +template +inline T *palloc_t(P1 &p1, P2 &p2) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1, p2); +} + +template +inline T *palloc_t(P1 &p1, P2 &p2, P3 &p3) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1, p2, p3); +} + +template +inline T *palloc_t(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, P7 &p7) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1, p2, p3, p4, p5, p6, p7); +} + +template +inline void pfree_t(T *p) +{ + p->~T(); + pfree_raw(p); + //delete p; +} + +template +inline T *palloc_array_t(size_t N) +{ + return new T[N]; +} + +template +inline void pfree_array_t(T *p) +{ + delete[] p; +} + +#define palloc(T, ...) palloc_t(__VA_ARGS__) +#define pfree(_ptr) pfree_t(_ptr) + +#define palloc_array(T, N) palloc_array_t(N) +#define pfree_array(_ptr) pfree_array_t(_ptr) + +#else +#include "corealloc.h" +#define palloc(T, ...) global_alloc(T(__VA_ARGS__)) +#define pfree(_ptr) global_free(_ptr) +#define palloc_array(T, N) global_alloc_array(T, N) +#define pfree_array(_ptr) global_free_array(_ptr) +#endif + +#endif /* NLCONFIG_H_ */ diff --git a/src/emu/netlist/pconfig.h b/src/emu/netlist/pconfig.h new file mode 100644 index 00000000000..5ab1f8493b0 --- /dev/null +++ b/src/emu/netlist/pconfig.h @@ -0,0 +1,79 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pconfig.h + * + */ + +#ifndef PCONFIG_H_ +#define PCONFIG_H_ + +#ifndef PSTANDALONE + #define PSTANDALONE (0) +#endif + +#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) +#if !defined(__ppc__) && !defined (__PPC__) && !defined(__ppc64__) && !defined(__PPC64__) +#define ATTR_ALIGN __attribute__ ((aligned(64))) +#else +#define ATTR_ALIGN +#endif +#else +#define ATTR_ALIGN +#endif + +//============================================================ +// Compiling standalone +//============================================================ + +// Compiling without mame ? + +#if !(PSTANDALONE) +#include "osdcore.h" +#else +#define ATTR_HOT +#define ATTR_COLD + +#define RESTRICT +#define EXPECTED(x) (x) +#define UNEXPECTED(x) (x) +#define ATTR_PRINTF(n1,n2) +#define ATTR_UNUSED __attribute__((__unused__)) + +/* 8-bit values */ +typedef unsigned char UINT8; +typedef signed char INT8; + +/* 16-bit values */ +typedef unsigned short UINT16; +typedef signed short INT16; + +/* 32-bit values */ +#ifndef _WINDOWS_H +typedef unsigned int UINT32; +typedef signed int INT32; +#endif + +/* 64-bit values */ +#ifndef _WINDOWS_H +#ifdef _MSC_VER +typedef signed __int64 INT64; +typedef unsigned __int64 UINT64; +#else +__extension__ typedef unsigned long long UINT64; +__extension__ typedef signed long long INT64; +#endif +#endif + +/* U64 and S64 are used to wrap long integer constants. */ +#if defined(__GNUC__) || defined(_MSC_VER) +#define U64(val) val##ULL +#define S64(val) val##LL +#else +#define U64(val) val +#define S64(val) val +#endif + +#endif + +#endif /* PCONFIG_H_ */ diff --git a/src/emu/netlist/plists.h b/src/emu/netlist/plists.h index c9c54f5d54f..86ecac61422 100644 --- a/src/emu/netlist/plists.h +++ b/src/emu/netlist/plists.h @@ -11,6 +11,7 @@ #define PLISTS_H_ #include "nl_config.h" +#include "palloc.h" #include "pstring.h" // ---------------------------------------------------------------------------------------- @@ -47,7 +48,7 @@ public: ATTR_COLD ~parray_t() { if (m_list != NULL) - nl_free_array(m_list); + pfree_array(m_list); m_list = NULL; } @@ -70,9 +71,9 @@ protected: ATTR_COLD void set_capacity(const int new_capacity) { if (m_list != NULL) - nl_free_array(m_list); + pfree_array(m_list); if (new_capacity > 0) - m_list = nl_alloc_array(_ListClass, new_capacity); + m_list = palloc_array(_ListClass, new_capacity); else m_list = NULL; m_capacity = new_capacity; @@ -98,7 +99,7 @@ public: if (m_capacity == 0) m_list = NULL; else - m_list = nl_alloc_array(_ListClass, m_capacity); + m_list = palloc_array(_ListClass, m_capacity); m_count = 0; } @@ -108,7 +109,7 @@ public: if (m_capacity == 0) m_list = NULL; else - m_list = nl_alloc_array(_ListClass, m_capacity); + m_list = palloc_array(_ListClass, m_capacity); m_count = 0; for (int i=0; i=0) && (pos=0) && (pos=0) && (pos1=0) && (pos2=0) && (pos1=0) && (pos2 0) { - _ListClass *m_new = nl_alloc_array(_ListClass, new_capacity); + _ListClass *m_new = palloc_array(_ListClass, new_capacity); _ListClass *pd = m_new; if (cnt > new_capacity) @@ -246,14 +247,14 @@ private: for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++) *pd = *ps; if (m_list != NULL) - nl_free_array(m_list); + pfree_array(m_list); m_list = m_new; m_count = cnt; } else { if (m_list != NULL) - nl_free_array(m_list); + pfree_array(m_list); m_list = NULL; m_count = 0; } @@ -402,7 +403,8 @@ public: } p = p->m_next; } - nl_assert_always(false, "element not found"); + //FXIME: throw a standard exception + //nl_assert_always(false, "element not found"); } } @@ -428,7 +430,7 @@ public: _ListClass **p = &m_head; while (*p != &elem) { - nl_assert(*p != NULL); + //nl_assert(*p != NULL); p = &((*p)->m_next); } (*p) = elem.m_next; diff --git a/src/emu/netlist/pstate.c b/src/emu/netlist/pstate.c index 15cc27561be..ee2c17d1ae9 100644 --- a/src/emu/netlist/pstate.c +++ b/src/emu/netlist/pstate.c @@ -30,7 +30,7 @@ ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pst }; NL_VERBOSE_OUT(("SAVE: <%s> %s(%d) %p\n", fullname.cstr(), ts[dt].cstr(), size, ptr)); - pstate_entry_t *p = nl_alloc(pstate_entry_t, stname, dt, owner, size, count, ptr, is_ptr); + pstate_entry_t *p = palloc(pstate_entry_t, stname, dt, owner, size, count, ptr, is_ptr); m_save.add(p); } @@ -67,7 +67,8 @@ ATTR_COLD void pstate_manager_t::post_load() template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname) { //save_state_ptr(stname, DT_CUSTOM, 0, 1, &state); - pstate_entry_t *p = nl_alloc(pstate_entry_t, stname, owner, &state); + pstate_callback_t *state_p = &state; + pstate_entry_t *p = palloc(pstate_entry_t, stname, owner, state_p); m_save.add(p); state.register_state(*this, stname); } diff --git a/src/emu/netlist/pstate.h b/src/emu/netlist/pstate.h index 3e8cbcd3a15..7b1fa287c6a 100644 --- a/src/emu/netlist/pstate.h +++ b/src/emu/netlist/pstate.h @@ -8,8 +8,6 @@ #ifndef PSTATE_H_ #define PSTATE_H_ -//#include "nl_config.h" -//#include "nl_time.h" #include "plists.h" #include "pstring.h" diff --git a/src/emu/netlist/pstring.c b/src/emu/netlist/pstring.c index de44e1571d9..6ca031039ab 100644 --- a/src/emu/netlist/pstring.c +++ b/src/emu/netlist/pstring.c @@ -5,10 +5,13 @@ * */ -#include "pstring.h" +#include #include -#include +#include +//FIXME:: pstring should be locale free +#include +#include "pstring.h" // The following will work on linux, however not on Windows .... @@ -51,9 +54,9 @@ void pstring::pcat(const char *s) int slen = strlen(s); str_t *n = salloc(m_ptr->len() + slen); if (m_ptr->len() > 0) - memcpy(n->str(), m_ptr->str(), m_ptr->len()); + std::memcpy(n->str(), m_ptr->str(), m_ptr->len()); if (slen > 0) - memcpy(n->str() + m_ptr->len(), s, slen); + std::memcpy(n->str() + m_ptr->len(), s, slen); *(n->str() + n->len()) = 0; sfree(m_ptr); m_ptr = n; @@ -63,7 +66,7 @@ void pstring::pcopy(const char *from, int size) { str_t *n = salloc(size); if (size > 0) - memcpy(n->str(), from, size); + std::memcpy(n->str(), from, size); *(n->str() + size) = 0; sfree(m_ptr); m_ptr = n; @@ -118,7 +121,7 @@ int pstring::find_last_not_of(const pstring no) const return -1; } -pstring pstring::replace(const pstring &search, const pstring &replace) +pstring pstring::replace(const pstring &search, const pstring &replace) const { pstring ret = ""; @@ -158,6 +161,11 @@ pstring pstring::rtrim(const pstring ws) const return ""; } +void pstring::pcopy(const char *from) +{ + pcopy(from, strlen(from)); +} + //------------------------------------------------- // pcmpi - compare a character array to an nstring //------------------------------------------------- @@ -167,20 +175,20 @@ int pstring::pcmpi(const char *lhs, const char *rhs, int count) const // loop while equal until we hit the end of strings int index; for (index = 0; index < count; index++) - if (lhs[index] == 0 || tolower(lhs[index]) != tolower(rhs[index])) + if (lhs[index] == 0 || std::tolower(lhs[index]) != std::tolower(rhs[index])) break; // determine the final result if (index < count) - return tolower(lhs[index]) - tolower(rhs[index]); + return std::tolower(lhs[index]) - std::tolower(rhs[index]); if (lhs[index] == 0) return 0; return 1; } -nl_double pstring::as_double(bool *error) const +double pstring::as_double(bool *error) const { - nl_double ret; + double ret; char *e = NULL; if (error != NULL) @@ -194,7 +202,7 @@ nl_double pstring::as_double(bool *error) const long pstring::as_long(bool *error) const { - nl_double ret; + long ret; char *e = NULL; if (error != NULL) @@ -213,7 +221,7 @@ pstring pstring::vprintf(va_list args) const { // sprintf into the temporary buffer char tempbuf[4096]; - vsprintf(tempbuf, cstr(), args); + std::vsprintf(tempbuf, cstr(), args); return pstring(tempbuf); } @@ -235,6 +243,17 @@ pstring::str_t *pstring::salloc(int n) return ret; } +void pstring::resetmem() +{ + // Release the 0 string + m_pool.m_shutdown = true; + m_pool.resetmem(); +} + +// ---------------------------------------------------------------------------------------- +// pstring ... +// ---------------------------------------------------------------------------------------- + pstring pstring::sprintf(const char *format, ...) { va_list ap; @@ -245,11 +264,31 @@ pstring pstring::sprintf(const char *format, ...) } -void pstring::resetmem() +int pstring::find(const char *search, int start) const { - // Release the 0 string - m_pool.m_shutdown = true; - m_pool.resetmem(); + int alen = len(); + const char *result = std::strstr(cstr() + std::min(start, alen), search); + return (result != NULL) ? (result - cstr()) : -1; +} + +int pstring::find(const char search, int start) const +{ + int alen = len(); + const char *result = std::strchr(cstr() + std::min(start, alen), search); + return (result != NULL) ? (result - cstr()) : -1; +} + +bool pstring::startsWith(const char *arg) const +{ + return (pcmp(cstr(), arg, std::strlen(arg)) == 0); +} + +int pstring::pcmp(const char *left, const char *right, int count) const +{ + if (count < 0) + return std::strcmp(left, right); + else + return std::strncmp(left, right, count); } // ---------------------------------------------------------------------------------------- @@ -276,8 +315,8 @@ void *pblockpool::alloc(const std::size_t n) return (char *) malloc(n); else { - int memsize = ((n + m_align - 1) / m_align) * m_align; - int min_alloc = MAX(m_blocksize, memsize+sizeof(memblock)-MINDATASIZE); + std::size_t memsize = ((n + m_align - 1) / m_align) * m_align; + std::size_t min_alloc = std::max(m_blocksize, memsize+sizeof(memblock)-MINDATASIZE); char *ret = NULL; //std::printf("m_first %p\n", m_first); for (memblock *p = m_first; p != NULL && ret == NULL; p = p->next) @@ -374,3 +413,4 @@ void pblockpool::resetmem() std::printf("Freed %d out of total %d blocks\n", freedblocks, totalblocks); } } + diff --git a/src/emu/netlist/pstring.h b/src/emu/netlist/pstring.h index 2bf3a0f9877..13e00e93365 100644 --- a/src/emu/netlist/pstring.h +++ b/src/emu/netlist/pstring.h @@ -7,16 +7,18 @@ #ifndef _PSTRING_H_ #define _PSTRING_H_ -#include "nl_config.h" -#include -#include +#include +#include + +#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y))) +#define ATTR_UNUSED __attribute__((__unused__)) // ---------------------------------------------------------------------------------------- // pblockbool: allocate small memory more efficiently at the expense of some overhead // ---------------------------------------------------------------------------------------- struct pblockpool { - NETLIST_PREVENT_COPYING(pblockpool) + public: static const int MINDATASIZE = 8; @@ -48,7 +50,7 @@ private: }; memblock *m_first; - int m_blocksize; + std::size_t m_blocksize; int m_align; }; @@ -128,26 +130,16 @@ public: inline int cmp(const pstring &string) const { return pcmp(string.cstr()); } inline int cmpi(const pstring &string) const { return pcmpi(cstr(), string.cstr()); } - inline int find(const char *search, int start = 0) const - { - int alen = len(); - const char *result = strstr(cstr() + MIN(start, alen), search); - return (result != NULL) ? (result - cstr()) : -1; - } + int find(const char *search, int start = 0) const; - inline int find(const char search, int start = 0) const - { - int alen = len(); - const char *result = strchr(cstr() + MIN(start, alen), search); - return (result != NULL) ? (result - cstr()) : -1; - } + int find(const char search, int start = 0) const; // various inline bool startsWith(const pstring &arg) const { return (pcmp(cstr(), arg.cstr(), arg.len()) == 0); } - inline bool startsWith(const char *arg) const { return (pcmp(cstr(), arg, strlen(arg)) == 0); } + bool startsWith(const char *arg) const; - pstring replace(const pstring &search, const pstring &replace); + pstring replace(const pstring &search, const pstring &replace) const; // these return nstring ... inline pstring cat(const pstring &s) const { return *this + s; } @@ -171,7 +163,7 @@ public: // conversions - nl_double as_double(bool *error = NULL) const; + double as_double(bool *error = NULL) const; long as_long(bool *error = NULL) const; @@ -214,22 +206,13 @@ private: return pcmp(m_ptr->str(), right); } - inline int pcmp(const char *left, const char *right, int count = -1) const - { - if (count < 0) - return strcmp(left, right); - else - return strncmp(left, right, count); - } + int pcmp(const char *left, const char *right, int count = -1) const; int pcmpi(const char *lhs, const char *rhs, int count = -1) const; void pcopy(const char *from, int size); - inline void pcopy(const char *from) - { - pcopy(from, strlen(from)); - } + void pcopy(const char *from); inline void pcopy(const pstring &from) { diff --git a/src/tools/nltool.c b/src/tools/nltool.c index 4f627f413b6..e1d6a3d9e8d 100644 --- a/src/tools/nltool.c +++ b/src/tools/nltool.c @@ -148,7 +148,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(); } @@ -313,16 +313,20 @@ static void listdevices() convert - convert a spice netlist -------------------------------------------------*/ +static const char *PSTR_RES = "RES"; +static const char *PSTR_CAP = "CAP"; + 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 +368,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 +408,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 +501,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 +534,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 +558,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 +568,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()); } -- cgit v1.2.3 From b3b2768cc9efdfaa682bbf25492d641be94fd8ad Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Sun, 24 May 2015 18:11:48 +0200 Subject: cgenie: Rewrote driver and removed lots of cruft. - Remove custom 6845 emulation and use our standard core - Use the slot system for the parallel interface, fix and implement the joystick as a slot device and create a printer slot device - Add support for the RS-232 port - Add support for the Break key (causes NMI) --- scripts/src/bus.lua | 30 +- scripts/target/mame/mess.lua | 3 +- src/emu/bus/cgenie/carts.c | 13 - src/emu/bus/cgenie/carts.h | 20 - src/emu/bus/cgenie/expansion.c | 108 ---- src/emu/bus/cgenie/expansion.h | 128 ----- src/emu/bus/cgenie/expansion/carts.c | 13 + src/emu/bus/cgenie/expansion/carts.h | 20 + src/emu/bus/cgenie/expansion/expansion.c | 108 ++++ src/emu/bus/cgenie/expansion/expansion.h | 128 +++++ src/emu/bus/cgenie/expansion/floppy.c | 230 ++++++++ src/emu/bus/cgenie/expansion/floppy.h | 75 +++ src/emu/bus/cgenie/floppy.c | 193 ------- src/emu/bus/cgenie/floppy.h | 59 -- src/emu/bus/cgenie/parallel/carts.c | 14 + src/emu/bus/cgenie/parallel/carts.h | 21 + src/emu/bus/cgenie/parallel/joystick.c | 153 ++++++ src/emu/bus/cgenie/parallel/joystick.h | 48 ++ src/emu/bus/cgenie/parallel/parallel.c | 115 ++++ src/emu/bus/cgenie/parallel/parallel.h | 94 ++++ src/emu/bus/cgenie/parallel/printer.c | 132 +++++ src/emu/bus/cgenie/parallel/printer.h | 58 ++ src/mess/drivers/cgenie.c | 908 +++++++++++++++---------------- src/mess/includes/cgenie.h | 139 ----- src/mess/machine/cgenie.c | 432 --------------- src/mess/video/cgenie.c | 412 -------------- 26 files changed, 1672 insertions(+), 1982 deletions(-) delete mode 100644 src/emu/bus/cgenie/carts.c delete mode 100644 src/emu/bus/cgenie/carts.h delete mode 100644 src/emu/bus/cgenie/expansion.c delete mode 100644 src/emu/bus/cgenie/expansion.h create mode 100644 src/emu/bus/cgenie/expansion/carts.c create mode 100644 src/emu/bus/cgenie/expansion/carts.h create mode 100644 src/emu/bus/cgenie/expansion/expansion.c create mode 100644 src/emu/bus/cgenie/expansion/expansion.h create mode 100644 src/emu/bus/cgenie/expansion/floppy.c create mode 100644 src/emu/bus/cgenie/expansion/floppy.h delete mode 100644 src/emu/bus/cgenie/floppy.c delete mode 100644 src/emu/bus/cgenie/floppy.h create mode 100644 src/emu/bus/cgenie/parallel/carts.c create mode 100644 src/emu/bus/cgenie/parallel/carts.h create mode 100644 src/emu/bus/cgenie/parallel/joystick.c create mode 100644 src/emu/bus/cgenie/parallel/joystick.h create mode 100644 src/emu/bus/cgenie/parallel/parallel.c create mode 100644 src/emu/bus/cgenie/parallel/parallel.h create mode 100644 src/emu/bus/cgenie/parallel/printer.c create mode 100644 src/emu/bus/cgenie/parallel/printer.h delete mode 100644 src/mess/includes/cgenie.h delete mode 100644 src/mess/machine/cgenie.c delete mode 100644 src/mess/video/cgenie.c (limited to 'scripts/src') diff --git a/scripts/src/bus.lua b/scripts/src/bus.lua index d499aabbef4..74ee8ac027e 100644 --- a/scripts/src/bus.lua +++ b/scripts/src/bus.lua @@ -2440,11 +2440,29 @@ end if (BUSES["CGENIE_EXPANSION"]~=null) then files { - MAME_DIR .. "src/emu/bus/cgenie/expansion.c", - MAME_DIR .. "src/emu/bus/cgenie/expansion.h", - MAME_DIR .. "src/emu/bus/cgenie/carts.c", - MAME_DIR .. "src/emu/bus/cgenie/carts.h", - MAME_DIR .. "src/emu/bus/cgenie/floppy.c", - MAME_DIR .. "src/emu/bus/cgenie/floppy.h", + MAME_DIR .. "src/emu/bus/cgenie/expansion/expansion.c", + MAME_DIR .. "src/emu/bus/cgenie/expansion/expansion.h", + MAME_DIR .. "src/emu/bus/cgenie/expansion/carts.c", + MAME_DIR .. "src/emu/bus/cgenie/expansion/carts.h", + MAME_DIR .. "src/emu/bus/cgenie/expansion/floppy.c", + MAME_DIR .. "src/emu/bus/cgenie/expansion/floppy.h", + } +end + +--------------------------------------------------- +-- +--@src/emu/bus/cgenie/parallel.h,BUSES += CGENIE_PARALLEL +--------------------------------------------------- + +if (BUSES["CGENIE_PARALLEL"]~=null) then + files { + MAME_DIR .. "src/emu/bus/cgenie/parallel/parallel.c", + MAME_DIR .. "src/emu/bus/cgenie/parallel/parallel.h", + MAME_DIR .. "src/emu/bus/cgenie/parallel/carts.c", + MAME_DIR .. "src/emu/bus/cgenie/parallel/carts.h", + MAME_DIR .. "src/emu/bus/cgenie/parallel/joystick.c", + MAME_DIR .. "src/emu/bus/cgenie/parallel/joystick.h", + MAME_DIR .. "src/emu/bus/cgenie/parallel/printer.c", + MAME_DIR .. "src/emu/bus/cgenie/parallel/printer.h", } end diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua index 867fb0fcdb1..2d027f05677 100644 --- a/scripts/target/mame/mess.lua +++ b/scripts/target/mame/mess.lua @@ -580,6 +580,7 @@ BUSES["CBM2"] = true BUSES["CBMIEC"] = true BUSES["CENTRONICS"] = true BUSES["CGENIE_EXPANSION"] = true +BUSES["CGENIE_PARALLEL"] = true BUSES["CHANNELF"] = true BUSES["COCO"] = true BUSES["COLECO"] = true @@ -1405,8 +1406,6 @@ files { createMESSProjects(_target, _subtarget, "eaca") files { MAME_DIR .. "src/mess/drivers/cgenie.c", - MAME_DIR .. "src/mess/machine/cgenie.c", - MAME_DIR .. "src/mess/video/cgenie.c", } createMESSProjects(_target, _subtarget, "einis") diff --git a/src/emu/bus/cgenie/carts.c b/src/emu/bus/cgenie/carts.c deleted file mode 100644 index f4b23a5cf9d..00000000000 --- a/src/emu/bus/cgenie/carts.c +++ /dev/null @@ -1,13 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Dirk Best -/*************************************************************************** - - EACA Colour Genie Expansion Carts - -***************************************************************************/ - -#include "carts.h" - -SLOT_INTERFACE_START( expansion_slot_carts ) - SLOT_INTERFACE("floppy", CGENIE_FDC) -SLOT_INTERFACE_END diff --git a/src/emu/bus/cgenie/carts.h b/src/emu/bus/cgenie/carts.h deleted file mode 100644 index 5dd3b67e172..00000000000 --- a/src/emu/bus/cgenie/carts.h +++ /dev/null @@ -1,20 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Dirk Best -/*************************************************************************** - - EACA Colour Genie Expansion Carts - -***************************************************************************/ - -#pragma once - -#ifndef __CGENIE_CARTS_H__ -#define __CGENIE_CARTS_H__ - -#include "emu.h" - -#include "floppy.h" - -SLOT_INTERFACE_EXTERN( expansion_slot_carts ); - -#endif // __CGENIE_CARTS_H__ diff --git a/src/emu/bus/cgenie/expansion.c b/src/emu/bus/cgenie/expansion.c deleted file mode 100644 index 88a89a32cce..00000000000 --- a/src/emu/bus/cgenie/expansion.c +++ /dev/null @@ -1,108 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Dirk Best -/*************************************************************************** - - EACA Colour Genie Expansion Slot - - 50-pin slot - -***************************************************************************/ - -#include "expansion.h" - - -//************************************************************************** -// DEVICE DEFINITIONS -//************************************************************************** - -const device_type EXPANSION_SLOT = &device_creator; - - -//************************************************************************** -// SLOT DEVICE -//************************************************************************** - -//------------------------------------------------- -// expansion_slot_device - constructor -//------------------------------------------------- - -expansion_slot_device::expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : - device_t(mconfig, EXPANSION_SLOT, "Expansion Slot", tag, owner, clock, "expansion_slot", __FILE__), - device_slot_interface(mconfig, *this), - m_program(NULL), - m_io(NULL), - m_cart(NULL), - m_int_handler(*this), - m_nmi_handler(*this), - m_reset_handler(*this) -{ -} - -//------------------------------------------------- -// expansion_slot_device - destructor -//------------------------------------------------- - -expansion_slot_device::~expansion_slot_device() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void expansion_slot_device::device_start() -{ - // resolve callbacks - m_int_handler.resolve_safe(); - m_nmi_handler.resolve_safe(); - m_reset_handler.resolve_safe(); -} - -//------------------------------------------------- -// device_reset - device-specific reset -//------------------------------------------------- - -void expansion_slot_device::device_reset() -{ -} - -//------------------------------------------------- -// set_program_space - set address space we are attached to -//------------------------------------------------- - -void expansion_slot_device::set_program_space(address_space *program) -{ - m_program = program; -} - -//------------------------------------------------- -// set_io_space - set address space we are attached to -//------------------------------------------------- - -void expansion_slot_device::set_io_space(address_space *io) -{ - m_io = io; -} - - -//************************************************************************** -// CARTRIDGE INTERFACE -//************************************************************************** - -//------------------------------------------------- -// device_expansion_interface - constructor -//------------------------------------------------- - -device_expansion_interface::device_expansion_interface(const machine_config &mconfig, device_t &device) : - device_slot_card_interface(mconfig, device) -{ - m_slot = dynamic_cast(device.owner()); -} - -//------------------------------------------------- -// ~device_expansion_interface - destructor -//------------------------------------------------- - -device_expansion_interface::~device_expansion_interface() -{ -} diff --git a/src/emu/bus/cgenie/expansion.h b/src/emu/bus/cgenie/expansion.h deleted file mode 100644 index 79cbc1430b5..00000000000 --- a/src/emu/bus/cgenie/expansion.h +++ /dev/null @@ -1,128 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Dirk Best -/*************************************************************************** - - EACA Colour Genie Expansion Slot - - 50-pin slot - - 1 GND 26 /MREQ - 2 A8 27 /WR - 3 A7 28 /C4 - 4 A6 29 (not used) - 5 A9 30 /C1 - 6 A5 31 BD3 - 7 A4 32 /C3 - 8 A3 33 (not used) - 9 A10 34 /C2 - 10 A2 35 DB6 - 11 A11 36 /RD - 12 A1 37 BD4 - 13 A0 38 (not used) - 14 A12 39 BD7 - 15 A14 40 (not used) - 16 A13 41 BD5 - 17 /RFSH 42 (not useD) - 18 A15 43 BD0 - 19 /INT 44 (not used) - 20 /BUSRQ 45 BD2 - 21 /NMI 46 /RESET - 22 /WAIT 47 /M1 - 23 /HALT 48 /IORQ - 24 /BUSAK 49 BD1 - 25 /ROMDIS 50 +5V - -***************************************************************************/ - -#pragma once - -#ifndef __CGENIE_EXPANSION_H__ -#define __CGENIE_EXPANSION_H__ - -#include "emu.h" - - -//************************************************************************** -// INTERFACE CONFIGURATION MACROS -//************************************************************************** - -#define MCFG_EXPANSION_SLOT_ADD(_tag) \ - MCFG_DEVICE_ADD(_tag, EXPANSION_SLOT, 0) \ - MCFG_DEVICE_SLOT_INTERFACE(expansion_slot_carts, NULL, false) - -#define MCFG_EXPANSION_SLOT_INT_HANDLER(_devcb) \ - devcb = &expansion_slot_device::set_int_handler(*device, DEVCB_##_devcb); - -#define MCFG_EXPANSION_SLOT_NMI_HANDLER(_devcb) \ - devcb = &expansion_slot_device::set_nmi_handler(*device, DEVCB_##_devcb); - -#define MCFG_EXPANSION_SLOT_RESET_HANDLER(_devcb) \ - devcb = &expansion_slot_device::set_reset_handler(*device, DEVCB_##_devcb); - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -class device_expansion_interface; - -class expansion_slot_device : public device_t, public device_slot_interface -{ -public: - // construction/destruction - expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - virtual ~expansion_slot_device(); - - void set_program_space(address_space *program); - void set_io_space(address_space *io); - - // callbacks - template static devcb_base &set_int_handler(device_t &device, _Object object) - { return downcast(device).m_int_handler.set_callback(object); } - - template static devcb_base &set_nmi_handler(device_t &device, _Object object) - { return downcast(device).m_nmi_handler.set_callback(object); } - - template static devcb_base &set_reset_handler(device_t &device, _Object object) - { return downcast(device).m_reset_handler.set_callback(object); } - - // called from cart device - DECLARE_WRITE_LINE_MEMBER( int_w ) { m_int_handler(state); } - DECLARE_WRITE_LINE_MEMBER( nmi_w ) { m_nmi_handler(state); } - DECLARE_WRITE_LINE_MEMBER( reset_w ) { m_reset_handler(state); } - - address_space *m_program; - address_space *m_io; - -protected: - // device-level overrides - virtual void device_start(); - virtual void device_reset(); - - device_expansion_interface *m_cart; - -private: - devcb_write_line m_int_handler; - devcb_write_line m_nmi_handler; - devcb_write_line m_reset_handler; -}; - -// class representing interface-specific live expansion device -class device_expansion_interface : public device_slot_card_interface -{ -public: - // construction/destruction - device_expansion_interface(const machine_config &mconfig, device_t &device); - virtual ~device_expansion_interface(); - -protected: - expansion_slot_device *m_slot; -}; - -// device type definition -extern const device_type EXPANSION_SLOT; - -// include here so drivers don't need to -#include "carts.h" - -#endif // __CGENIE_EXPANSION_H__ diff --git a/src/emu/bus/cgenie/expansion/carts.c b/src/emu/bus/cgenie/expansion/carts.c new file mode 100644 index 00000000000..f4b23a5cf9d --- /dev/null +++ b/src/emu/bus/cgenie/expansion/carts.c @@ -0,0 +1,13 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Expansion Carts + +***************************************************************************/ + +#include "carts.h" + +SLOT_INTERFACE_START( expansion_slot_carts ) + SLOT_INTERFACE("floppy", CGENIE_FDC) +SLOT_INTERFACE_END diff --git a/src/emu/bus/cgenie/expansion/carts.h b/src/emu/bus/cgenie/expansion/carts.h new file mode 100644 index 00000000000..45bf66a4c90 --- /dev/null +++ b/src/emu/bus/cgenie/expansion/carts.h @@ -0,0 +1,20 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Expansion Carts + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_EXPANSION_CARTS_H__ +#define __CGENIE_EXPANSION_CARTS_H__ + +#include "emu.h" + +#include "floppy.h" + +SLOT_INTERFACE_EXTERN( expansion_slot_carts ); + +#endif // __CGENIE_EXPANSION_CARTS_H__ diff --git a/src/emu/bus/cgenie/expansion/expansion.c b/src/emu/bus/cgenie/expansion/expansion.c new file mode 100644 index 00000000000..88a89a32cce --- /dev/null +++ b/src/emu/bus/cgenie/expansion/expansion.c @@ -0,0 +1,108 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Expansion Slot + + 50-pin slot + +***************************************************************************/ + +#include "expansion.h" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type EXPANSION_SLOT = &device_creator; + + +//************************************************************************** +// SLOT DEVICE +//************************************************************************** + +//------------------------------------------------- +// expansion_slot_device - constructor +//------------------------------------------------- + +expansion_slot_device::expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, EXPANSION_SLOT, "Expansion Slot", tag, owner, clock, "expansion_slot", __FILE__), + device_slot_interface(mconfig, *this), + m_program(NULL), + m_io(NULL), + m_cart(NULL), + m_int_handler(*this), + m_nmi_handler(*this), + m_reset_handler(*this) +{ +} + +//------------------------------------------------- +// expansion_slot_device - destructor +//------------------------------------------------- + +expansion_slot_device::~expansion_slot_device() +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void expansion_slot_device::device_start() +{ + // resolve callbacks + m_int_handler.resolve_safe(); + m_nmi_handler.resolve_safe(); + m_reset_handler.resolve_safe(); +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void expansion_slot_device::device_reset() +{ +} + +//------------------------------------------------- +// set_program_space - set address space we are attached to +//------------------------------------------------- + +void expansion_slot_device::set_program_space(address_space *program) +{ + m_program = program; +} + +//------------------------------------------------- +// set_io_space - set address space we are attached to +//------------------------------------------------- + +void expansion_slot_device::set_io_space(address_space *io) +{ + m_io = io; +} + + +//************************************************************************** +// CARTRIDGE INTERFACE +//************************************************************************** + +//------------------------------------------------- +// device_expansion_interface - constructor +//------------------------------------------------- + +device_expansion_interface::device_expansion_interface(const machine_config &mconfig, device_t &device) : + device_slot_card_interface(mconfig, device) +{ + m_slot = dynamic_cast(device.owner()); +} + +//------------------------------------------------- +// ~device_expansion_interface - destructor +//------------------------------------------------- + +device_expansion_interface::~device_expansion_interface() +{ +} diff --git a/src/emu/bus/cgenie/expansion/expansion.h b/src/emu/bus/cgenie/expansion/expansion.h new file mode 100644 index 00000000000..79cbc1430b5 --- /dev/null +++ b/src/emu/bus/cgenie/expansion/expansion.h @@ -0,0 +1,128 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Expansion Slot + + 50-pin slot + + 1 GND 26 /MREQ + 2 A8 27 /WR + 3 A7 28 /C4 + 4 A6 29 (not used) + 5 A9 30 /C1 + 6 A5 31 BD3 + 7 A4 32 /C3 + 8 A3 33 (not used) + 9 A10 34 /C2 + 10 A2 35 DB6 + 11 A11 36 /RD + 12 A1 37 BD4 + 13 A0 38 (not used) + 14 A12 39 BD7 + 15 A14 40 (not used) + 16 A13 41 BD5 + 17 /RFSH 42 (not useD) + 18 A15 43 BD0 + 19 /INT 44 (not used) + 20 /BUSRQ 45 BD2 + 21 /NMI 46 /RESET + 22 /WAIT 47 /M1 + 23 /HALT 48 /IORQ + 24 /BUSAK 49 BD1 + 25 /ROMDIS 50 +5V + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_EXPANSION_H__ +#define __CGENIE_EXPANSION_H__ + +#include "emu.h" + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_EXPANSION_SLOT_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, EXPANSION_SLOT, 0) \ + MCFG_DEVICE_SLOT_INTERFACE(expansion_slot_carts, NULL, false) + +#define MCFG_EXPANSION_SLOT_INT_HANDLER(_devcb) \ + devcb = &expansion_slot_device::set_int_handler(*device, DEVCB_##_devcb); + +#define MCFG_EXPANSION_SLOT_NMI_HANDLER(_devcb) \ + devcb = &expansion_slot_device::set_nmi_handler(*device, DEVCB_##_devcb); + +#define MCFG_EXPANSION_SLOT_RESET_HANDLER(_devcb) \ + devcb = &expansion_slot_device::set_reset_handler(*device, DEVCB_##_devcb); + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +class device_expansion_interface; + +class expansion_slot_device : public device_t, public device_slot_interface +{ +public: + // construction/destruction + expansion_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + virtual ~expansion_slot_device(); + + void set_program_space(address_space *program); + void set_io_space(address_space *io); + + // callbacks + template static devcb_base &set_int_handler(device_t &device, _Object object) + { return downcast(device).m_int_handler.set_callback(object); } + + template static devcb_base &set_nmi_handler(device_t &device, _Object object) + { return downcast(device).m_nmi_handler.set_callback(object); } + + template static devcb_base &set_reset_handler(device_t &device, _Object object) + { return downcast(device).m_reset_handler.set_callback(object); } + + // called from cart device + DECLARE_WRITE_LINE_MEMBER( int_w ) { m_int_handler(state); } + DECLARE_WRITE_LINE_MEMBER( nmi_w ) { m_nmi_handler(state); } + DECLARE_WRITE_LINE_MEMBER( reset_w ) { m_reset_handler(state); } + + address_space *m_program; + address_space *m_io; + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + + device_expansion_interface *m_cart; + +private: + devcb_write_line m_int_handler; + devcb_write_line m_nmi_handler; + devcb_write_line m_reset_handler; +}; + +// class representing interface-specific live expansion device +class device_expansion_interface : public device_slot_card_interface +{ +public: + // construction/destruction + device_expansion_interface(const machine_config &mconfig, device_t &device); + virtual ~device_expansion_interface(); + +protected: + expansion_slot_device *m_slot; +}; + +// device type definition +extern const device_type EXPANSION_SLOT; + +// include here so drivers don't need to +#include "carts.h" + +#endif // __CGENIE_EXPANSION_H__ diff --git a/src/emu/bus/cgenie/expansion/floppy.c b/src/emu/bus/cgenie/expansion/floppy.c new file mode 100644 index 00000000000..6773afa895c --- /dev/null +++ b/src/emu/bus/cgenie/expansion/floppy.c @@ -0,0 +1,230 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Floppy Disc Controller + + TODO: + - Only native MESS .mfi files load + - What's the exact FD1793 model? + - How does it turn off the motor? + - How does it switch between FM/MFM? + - What's the source of the timer and the exact timings? + +***************************************************************************/ + +#include "floppy.h" +#include "formats/cgenie_dsk.h" +#include "bus/generic/carts.h" + + +//************************************************************************** +// CONSTANTS/MACROS +//************************************************************************** + +#define VERBOSE 0 + +// set to 1 to test fm disk formats +#define FM_MODE 0 + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type CGENIE_FDC = &device_creator; + +FLOPPY_FORMATS_MEMBER( cgenie_fdc_device::floppy_formats ) + FLOPPY_CGENIE_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( cgenie_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) + SLOT_INTERFACE("sd", FLOPPY_525_SD) + SLOT_INTERFACE("ssdd", FLOPPY_525_SSDD) + SLOT_INTERFACE("dd", FLOPPY_525_DD) + SLOT_INTERFACE("ssqd", FLOPPY_525_SSQD) + SLOT_INTERFACE("qd", FLOPPY_525_QD) +SLOT_INTERFACE_END + +//------------------------------------------------- +// rom_region - device-specific ROM region +//------------------------------------------------- + +ROM_START( cgenie_fdc ) + ROM_REGION(0x3000, "software", 0) + ROM_LOAD("cgdos.rom", 0x0000, 0x2000, CRC(2a96cf74) SHA1(6dcac110f87897e1ee7521aefbb3d77a14815893)) +ROM_END + +const rom_entry *cgenie_fdc_device::device_rom_region() const +{ + return ROM_NAME( cgenie_fdc ); +} + +//------------------------------------------------- +// machine_config_additions - device-specific +// machine configurations +//------------------------------------------------- + +static MACHINE_CONFIG_FRAGMENT( cgenie_fdc ) + MCFG_TIMER_DRIVER_ADD_PERIODIC("timer", cgenie_fdc_device, timer_callback, attotime::from_msec(25)) + + MCFG_FD1793x_ADD("fd1793", XTAL_1MHz) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(cgenie_fdc_device, intrq_w)) + + MCFG_FLOPPY_DRIVE_ADD("fd1793:0", cgenie_floppies, "ssdd", cgenie_fdc_device::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("fd1793:1", cgenie_floppies, "ssdd", cgenie_fdc_device::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("fd1793:2", cgenie_floppies, NULL, cgenie_fdc_device::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("fd1793:3", cgenie_floppies, NULL, cgenie_fdc_device::floppy_formats) + +// MCFG_SOFTWARE_LIST_ADD("floppy_list", "cgenie_flop") + + MCFG_GENERIC_SOCKET_ADD("socket", generic_plain_slot, "cgenie_socket") + MCFG_GENERIC_EXTENSIONS("bin,rom") + MCFG_GENERIC_LOAD(cgenie_fdc_device, socket_load) + + MCFG_SOFTWARE_LIST_ADD("cart_list", "cgenie_cart") +MACHINE_CONFIG_END + +machine_config_constructor cgenie_fdc_device::device_mconfig_additions() const +{ + return MACHINE_CONFIG_NAME( cgenie_fdc ); +} + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// cgenie_fdc_device - constructor +//------------------------------------------------- + +cgenie_fdc_device::cgenie_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, CGENIE_FDC, "Floppy Disc Controller", tag, owner, clock, "cgenie_fdc", __FILE__), + device_expansion_interface(mconfig, *this), + m_fdc(*this, "fd1793"), + m_floppy0(*this, "fd1793:0"), + m_floppy1(*this, "fd1793:1"), + m_floppy2(*this, "fd1793:2"), + m_floppy3(*this, "fd1793:3"), + m_socket(*this, "socket"), + m_floppy(NULL), + m_timer_irq_off(NULL), + m_irq_status(0) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void cgenie_fdc_device::device_start() +{ + m_timer_irq_off = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(cgenie_fdc_device::irq_off_callback), this)); +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void cgenie_fdc_device::device_reset() +{ + // dos rom + m_slot->m_program->install_rom(0xc000, 0xdfff, memregion("software")->base()); + + // memory mapped i/o + m_slot->m_program->install_read_handler(0xffe0, 0xffe3, 0, 0x10, read8_delegate(FUNC(cgenie_fdc_device::irq_r), this)); + m_slot->m_program->install_write_handler(0xffe0, 0xffe3, 0, 0x10, write8_delegate(FUNC(cgenie_fdc_device::select_w), this)); + m_slot->m_program->install_read_handler(0xffec, 0xffef, 0, 0x10, read8_delegate(FUNC(fd1793_t::read), m_fdc.target())); + m_slot->m_program->install_write_handler(0xffec, 0xffef, 0, 0x10, write8_delegate(FUNC(fd1793_t::write), m_fdc.target())); + + // map extra socket + if (m_socket->exists()) + { + m_slot->m_program->install_read_handler(0xe000, 0xefff, read8_delegate(FUNC(generic_slot_device::read_rom), (generic_slot_device *) m_socket)); + } +} + + +//************************************************************************** +// IMPLEMENTATION +//************************************************************************** + +READ8_MEMBER( cgenie_fdc_device::irq_r ) +{ + return m_irq_status; +} + +void cgenie_fdc_device::update_irq() +{ + m_slot->int_w(m_irq_status ? 1 : 0); +} + +TIMER_DEVICE_CALLBACK_MEMBER( cgenie_fdc_device::timer_callback ) +{ + m_irq_status |= IRQ_TIMER; + update_irq(); + + // timer to turn it off again + m_timer_irq_off->adjust(attotime::from_usec(250)); +} + +TIMER_CALLBACK_MEMBER( cgenie_fdc_device::irq_off_callback ) +{ + m_irq_status &= ~IRQ_TIMER; + update_irq(); +} + +DEVICE_IMAGE_LOAD_MEMBER( cgenie_fdc_device, socket_load ) +{ + UINT32 size = m_socket->common_get_size("rom"); + + if (size > 0x1000) + { + image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported ROM size"); + return IMAGE_INIT_FAIL; + } + + m_socket->rom_alloc(0x1000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE); + m_socket->common_load_rom(m_socket->get_rom_base(), size, "rom"); + + return IMAGE_INIT_PASS; +} + +WRITE_LINE_MEMBER( cgenie_fdc_device::intrq_w ) +{ + if (VERBOSE) + logerror("cgenie_fdc_device::intrq_w: %d\n", state); + + if (state) + m_irq_status |= IRQ_WDC; + else + m_irq_status &= ~IRQ_WDC; + + update_irq(); +} + +WRITE8_MEMBER( cgenie_fdc_device::select_w ) +{ + if (VERBOSE) + logerror("cgenie_fdc_device::motor_w: 0x%02x\n", data); + + if (FM_MODE) + m_fdc->dden_w(1); + + m_floppy = NULL; + + if (BIT(data, 0)) m_floppy = m_floppy0->get_device(); + if (BIT(data, 1)) m_floppy = m_floppy1->get_device(); + if (BIT(data, 2)) m_floppy = m_floppy2->get_device(); + if (BIT(data, 3)) m_floppy = m_floppy3->get_device(); + + m_fdc->set_floppy(m_floppy); + + if (m_floppy) + { + m_floppy->ss_w(BIT(data, 4)); + m_floppy->mon_w(0); + } +} diff --git a/src/emu/bus/cgenie/expansion/floppy.h b/src/emu/bus/cgenie/expansion/floppy.h new file mode 100644 index 00000000000..254b4c54d71 --- /dev/null +++ b/src/emu/bus/cgenie/expansion/floppy.h @@ -0,0 +1,75 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Floppy Controller Cartridge + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_EXPANSION_FLOPPY_H__ +#define __CGENIE_EXPANSION_FLOPPY_H__ + +#include "emu.h" +#include "expansion.h" +#include "machine/wd_fdc.h" +#include "bus/generic/slot.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> floppy_controller_device + +class cgenie_fdc_device : public device_t, public device_expansion_interface +{ +public: + // construction/destruction + cgenie_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + TIMER_DEVICE_CALLBACK_MEMBER(timer_callback); + TIMER_CALLBACK_MEMBER( irq_off_callback ); + + DECLARE_DEVICE_IMAGE_LOAD_MEMBER(socket_load); + + DECLARE_WRITE_LINE_MEMBER(intrq_w); + DECLARE_READ8_MEMBER(irq_r); + DECLARE_WRITE8_MEMBER(select_w); + + DECLARE_FLOPPY_FORMATS(floppy_formats); + + +protected: + virtual const rom_entry *device_rom_region() const; + virtual machine_config_constructor device_mconfig_additions() const; + virtual void device_start(); + virtual void device_reset(); + +private: + void update_irq(); + + required_device m_fdc; + required_device m_floppy0; + required_device m_floppy1; + required_device m_floppy2; + required_device m_floppy3; + required_device m_socket; + + enum + { + IRQ_WDC = 0x40, + IRQ_TIMER = 0x80 + }; + + floppy_image_device *m_floppy; + + emu_timer *m_timer_irq_off; + UINT8 m_irq_status; +}; + +// device type definition +extern const device_type CGENIE_FDC; + +#endif // __CGENIE_EXPANSION_FLOPPY_H__ diff --git a/src/emu/bus/cgenie/floppy.c b/src/emu/bus/cgenie/floppy.c deleted file mode 100644 index efb53807774..00000000000 --- a/src/emu/bus/cgenie/floppy.c +++ /dev/null @@ -1,193 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Dirk Best -/*************************************************************************** - - EACA Colour Genie Floppy Disc Controller - - TODO: - - What's the exact FD1793 model? - - How does it turn off the motor? - - How does it switch between FM/MFM? - -***************************************************************************/ - -#include "floppy.h" -#include "formats/cgenie_dsk.h" -#include "bus/generic/carts.h" - - -//************************************************************************** -// CONSTANTS/MACROS -//************************************************************************** - -#define VERBOSE 0 - -// set to 1 to test fm disk formats -#define FM_MODE 0 - - -//************************************************************************** -// DEVICE DEFINITIONS -//************************************************************************** - -const device_type CGENIE_FDC = &device_creator; - -FLOPPY_FORMATS_MEMBER( cgenie_fdc_device::floppy_formats ) - FLOPPY_CGENIE_FORMAT -FLOPPY_FORMATS_END - -static SLOT_INTERFACE_START( cgenie_floppies ) - SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) - SLOT_INTERFACE("sd", FLOPPY_525_SD) - SLOT_INTERFACE("ssdd", FLOPPY_525_SSDD) - SLOT_INTERFACE("dd", FLOPPY_525_DD) - SLOT_INTERFACE("ssqd", FLOPPY_525_SSQD) - SLOT_INTERFACE("qd", FLOPPY_525_QD) -SLOT_INTERFACE_END - -//------------------------------------------------- -// rom_region - device-specific ROM region -//------------------------------------------------- - -ROM_START( cgenie_fdc ) - ROM_REGION(0x3000, "software", 0) - ROM_LOAD("cgdos.rom", 0x0000, 0x2000, CRC(2a96cf74) SHA1(6dcac110f87897e1ee7521aefbb3d77a14815893)) -ROM_END - -const rom_entry *cgenie_fdc_device::device_rom_region() const -{ - return ROM_NAME( cgenie_fdc ); -} - -//------------------------------------------------- -// machine_config_additions - device-specific -// machine configurations -//------------------------------------------------- - -static MACHINE_CONFIG_FRAGMENT( cgenie_fdc ) - MCFG_FD1793x_ADD("fd1793", XTAL_16MHz / 4 / 4) - MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(cgenie_fdc_device, intrq_w)) - - MCFG_FLOPPY_DRIVE_ADD("fd1793:0", cgenie_floppies, "ssdd", cgenie_fdc_device::floppy_formats) - MCFG_FLOPPY_DRIVE_ADD("fd1793:1", cgenie_floppies, "ssdd", cgenie_fdc_device::floppy_formats) - MCFG_FLOPPY_DRIVE_ADD("fd1793:2", cgenie_floppies, NULL, cgenie_fdc_device::floppy_formats) - MCFG_FLOPPY_DRIVE_ADD("fd1793:3", cgenie_floppies, NULL, cgenie_fdc_device::floppy_formats) - -// MCFG_SOFTWARE_LIST_ADD("floppy_list", "cgenie_flop") - - MCFG_GENERIC_SOCKET_ADD("socket", generic_plain_slot, "cgenie_socket") - MCFG_GENERIC_EXTENSIONS("bin,rom") - MCFG_GENERIC_LOAD(cgenie_fdc_device, socket_load) - - MCFG_SOFTWARE_LIST_ADD("cart_list", "cgenie_cart") -MACHINE_CONFIG_END - -machine_config_constructor cgenie_fdc_device::device_mconfig_additions() const -{ - return MACHINE_CONFIG_NAME( cgenie_fdc ); -} - - -//************************************************************************** -// LIVE DEVICE -//************************************************************************** - -//------------------------------------------------- -// cgenie_fdc_device - constructor -//------------------------------------------------- - -cgenie_fdc_device::cgenie_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : - device_t(mconfig, CGENIE_FDC, "Colour Genie Floppy Disc Controller", tag, owner, clock, "cgenie_fdc", __FILE__), - device_expansion_interface(mconfig, *this), - m_fdc(*this, "fd1793"), - m_floppy0(*this, "fd1793:0"), - m_floppy1(*this, "fd1793:1"), - m_floppy2(*this, "fd1793:2"), - m_floppy3(*this, "fd1793:3"), - m_socket(*this, "socket"), - m_floppy(NULL) -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void cgenie_fdc_device::device_start() -{ -} - -//------------------------------------------------- -// device_reset - device-specific reset -//------------------------------------------------- - -void cgenie_fdc_device::device_reset() -{ - // dos rom - m_slot->m_program->install_rom(0xc000, 0xdfff, memregion("software")->base()); - - // memory mapped i/o - m_slot->m_program->install_write_handler(0xffe0, 0xffe3, 0, 0x10, write8_delegate(FUNC(cgenie_fdc_device::select_w), this)); - m_slot->m_program->install_read_handler( 0xffec, 0xffef, 0, 0x10, read8_delegate(FUNC(fd1793_t::read), m_fdc.target())); - m_slot->m_program->install_write_handler(0xffec, 0xffef, 0, 0x10, write8_delegate(FUNC(fd1793_t::write), m_fdc.target())); - - // map extra socket - if (m_socket->exists()) - { - m_slot->m_program->install_read_handler(0xe000, 0xefff, read8_delegate(FUNC(generic_slot_device::read_rom), (generic_slot_device *) m_socket)); - } -} - - -//************************************************************************** -// IMPLEMENTATION -//************************************************************************** - -DEVICE_IMAGE_LOAD_MEMBER( cgenie_fdc_device, socket_load ) -{ - UINT32 size = m_socket->common_get_size("rom"); - - if (size > 0x1000) - { - image.seterror(IMAGE_ERROR_UNSPECIFIED, "Unsupported ROM size"); - return IMAGE_INIT_FAIL; - } - - m_socket->rom_alloc(0x1000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE); - m_socket->common_load_rom(m_socket->get_rom_base(), size, "rom"); - - return IMAGE_INIT_PASS; -} - -WRITE_LINE_MEMBER( cgenie_fdc_device::intrq_w ) -{ - if (VERBOSE) - logerror("cgenie_fdc_device::intrq_w: %d\n", state); - - // forward to host - m_slot->int_w(state); -} - -WRITE8_MEMBER( cgenie_fdc_device::select_w ) -{ - if (VERBOSE) - logerror("cgenie_fdc_device::motor_w: 0x%02x\n", data); - - if (FM_MODE) - m_fdc->dden_w(1); - - m_floppy = NULL; - - if (BIT(data, 0)) m_floppy = m_floppy0->get_device(); - if (BIT(data, 1)) m_floppy = m_floppy1->get_device(); - if (BIT(data, 2)) m_floppy = m_floppy2->get_device(); - if (BIT(data, 3)) m_floppy = m_floppy3->get_device(); - - m_fdc->set_floppy(m_floppy); - - if (m_floppy) - { - m_floppy->ss_w(BIT(data, 4)); - m_floppy->mon_w(0); - } -} diff --git a/src/emu/bus/cgenie/floppy.h b/src/emu/bus/cgenie/floppy.h deleted file mode 100644 index 6911358763d..00000000000 --- a/src/emu/bus/cgenie/floppy.h +++ /dev/null @@ -1,59 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Dirk Best -/*************************************************************************** - - EACA Colour Genie Floppy Controller Cartridge - -***************************************************************************/ - -#pragma once - -#ifndef __CGENIE_EXPANSION_FLOPPY_H__ -#define __CGENIE_EXPANSION_FLOPPY_H__ - -#include "emu.h" -#include "expansion.h" -#include "machine/wd_fdc.h" -#include "bus/generic/slot.h" - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// ======================> floppy_controller_device - -class cgenie_fdc_device : public device_t, public device_expansion_interface -{ -public: - // construction/destruction - cgenie_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - - DECLARE_WRITE_LINE_MEMBER(intrq_w); - DECLARE_WRITE8_MEMBER(select_w); - - DECLARE_FLOPPY_FORMATS(floppy_formats); - - DECLARE_DEVICE_IMAGE_LOAD_MEMBER(socket_load); - -protected: - virtual const rom_entry *device_rom_region() const; - virtual machine_config_constructor device_mconfig_additions() const; - virtual void device_start(); - virtual void device_reset(); - -private: - required_device m_fdc; - required_device m_floppy0; - required_device m_floppy1; - required_device m_floppy2; - required_device m_floppy3; - required_device m_socket; - - floppy_image_device *m_floppy; -}; - -// device type definition -extern const device_type CGENIE_FDC; - -#endif // __CGENIE_EXPANSION_FLOPPY_H__ diff --git a/src/emu/bus/cgenie/parallel/carts.c b/src/emu/bus/cgenie/parallel/carts.c new file mode 100644 index 00000000000..61a6380117f --- /dev/null +++ b/src/emu/bus/cgenie/parallel/carts.c @@ -0,0 +1,14 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Parallel Carts + +***************************************************************************/ + +#include "carts.h" + +SLOT_INTERFACE_START( parallel_slot_carts ) + SLOT_INTERFACE("joystick", CGENIE_JOYSTICK) + SLOT_INTERFACE("printer", CGENIE_PRINTER) +SLOT_INTERFACE_END diff --git a/src/emu/bus/cgenie/parallel/carts.h b/src/emu/bus/cgenie/parallel/carts.h new file mode 100644 index 00000000000..29c092b9d0a --- /dev/null +++ b/src/emu/bus/cgenie/parallel/carts.h @@ -0,0 +1,21 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Parallel Carts + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_PARALLEL_CARTS_H__ +#define __CGENIE_PARALLEL_CARTS_H__ + +#include "emu.h" + +#include "joystick.h" +#include "printer.h" + +SLOT_INTERFACE_EXTERN( parallel_slot_carts ); + +#endif // __CGENIE_PARALLEL_CARTS_H__ diff --git a/src/emu/bus/cgenie/parallel/joystick.c b/src/emu/bus/cgenie/parallel/joystick.c new file mode 100644 index 00000000000..de520ba0669 --- /dev/null +++ b/src/emu/bus/cgenie/parallel/joystick.c @@ -0,0 +1,153 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Joystick Interface EG2013 + + Keypads are organized as 3x4 matrix. + +***************************************************************************/ + +#include "joystick.h" + + +//************************************************************************** +// CONSTANTS/MACROS +//************************************************************************** + +#define VERBOSE 0 + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type CGENIE_JOYSTICK = &device_creator; + +//------------------------------------------------- +// input_ports - device-specific input ports +//------------------------------------------------- + +static INPUT_PORTS_START( cgenie_joystick ) + PORT_START("JOY.0") + PORT_BIT(0x3f, 0x00, IPT_AD_STICK_X) PORT_SENSITIVITY(100) PORT_PLAYER(1) + + PORT_START("JOY.1") + PORT_BIT(0x3f, 0x00, IPT_AD_STICK_Y) PORT_SENSITIVITY(100) PORT_PLAYER(1) PORT_REVERSE + + PORT_START("JOY.2") + PORT_BIT(0x3f, 0x00, IPT_AD_STICK_X) PORT_SENSITIVITY(100) PORT_PLAYER(2) + + PORT_START("JOY.3") + PORT_BIT(0x3f, 0x00, IPT_AD_STICK_Y) PORT_SENSITIVITY(100) PORT_PLAYER(2) PORT_REVERSE + + PORT_START("KEYPAD.0") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("Keypad 1 Button 3") PORT_PLAYER(1) PORT_CODE(KEYCODE_3_PAD) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_NAME("Keypad 1 Button 6") PORT_PLAYER(1) PORT_CODE(KEYCODE_6_PAD) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON3) PORT_NAME("Keypad 1 Button 9") PORT_PLAYER(1) PORT_CODE(KEYCODE_9_PAD) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON4) PORT_NAME("Keypad 1 Button #") PORT_PLAYER(1) PORT_CODE(KEYCODE_SLASH_PAD) + + PORT_START("KEYPAD.1") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("Keypad 1 Button 2") PORT_PLAYER(1) PORT_CODE(KEYCODE_2_PAD) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON6) PORT_NAME("Keypad 1 Button 5") PORT_PLAYER(1) PORT_CODE(KEYCODE_5_PAD) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON7) PORT_NAME("Keypad 1 Button 8") PORT_PLAYER(1) PORT_CODE(KEYCODE_8_PAD) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON8) PORT_NAME("Keypad 1 Button 0") PORT_PLAYER(1) PORT_CODE(KEYCODE_0_PAD) + + PORT_START("KEYPAD.2") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON9) PORT_NAME("Keypad 1 Button 1") PORT_PLAYER(1) PORT_CODE(KEYCODE_1_PAD) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON10) PORT_NAME("Keypad 1 Button 4") PORT_PLAYER(1) PORT_CODE(KEYCODE_4_PAD) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON11) PORT_NAME("Keypad 1 Button 7") PORT_PLAYER(1) PORT_CODE(KEYCODE_7_PAD) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON12) PORT_NAME("Keypad 1 Button *") PORT_PLAYER(1) PORT_CODE(KEYCODE_ASTERISK) + + PORT_START("KEYPAD.3") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("Keypad 2 Button 3") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON2) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_NAME("Keypad 2 Button 6") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON5) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON3) PORT_NAME("Keypad 2 Button 9") PORT_PLAYER(2) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON4) PORT_NAME("Keypad 2 Button #") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON1) + + PORT_START("KEYPAD.4") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON5) PORT_NAME("Keypad 2 Button 2") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON2) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON6) PORT_NAME("Keypad 2 Button 5") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON5) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON7) PORT_NAME("Keypad 2 Button 8") PORT_PLAYER(2) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON8) PORT_NAME("Keypad 2 Button 0") PORT_PLAYER(2) + + PORT_START("KEYPAD.5") + PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON9) PORT_NAME("Keypad 2 Button 1") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON1) + PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_BUTTON10) PORT_NAME("Keypad 2 Button 4") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON4) + PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_BUTTON11) PORT_NAME("Keypad 2 Button 7") PORT_PLAYER(2) + PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_BUTTON12) PORT_NAME("Keypad 2 Button *") PORT_PLAYER(2) PORT_CODE(JOYCODE_BUTTON1) +INPUT_PORTS_END + +ioport_constructor cgenie_joystick_device::device_input_ports() const +{ + return INPUT_PORTS_NAME( cgenie_joystick ); +} + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// cgenie_joystick_device - constructor +//------------------------------------------------- + +cgenie_joystick_device::cgenie_joystick_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, CGENIE_JOYSTICK, "Joystick Interface EG2013", tag, owner, clock, "cgenie_joystick", __FILE__), + device_parallel_interface(mconfig, *this), + m_joy(*this, "JOY"), + m_keypad(*this, "KEYPAD"), + m_select(0) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void cgenie_joystick_device::device_start() +{ +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void cgenie_joystick_device::device_reset() +{ +} + + +//************************************************************************** +// IMPLEMENTATION +//************************************************************************** + +void cgenie_joystick_device::pa_w(UINT8 data) +{ + if (VERBOSE) + logerror("%s: pa_w %02x\n", tag(), data); + + // d0 to d5 connected + m_select = data & 0x3f; +} + +UINT8 cgenie_joystick_device::pb_r() +{ + UINT8 data = 0x0f; + + // read button state + for (int i = 0; i < 4; i++) + if (!BIT(m_select, i)) + data &= m_keypad[i]->read(); + + // and joystick state + data |= m_joy[3]->read() > m_select ? 0x10 : 0x00; + data |= m_joy[2]->read() > m_select ? 0x20 : 0x00; + data |= m_joy[1]->read() > m_select ? 0x40 : 0x00; + data |= m_joy[0]->read() > m_select ? 0x80 : 0x00; + + if (VERBOSE) + logerror("%s: pb_r %02x\n", tag(), data); + + return data; +} diff --git a/src/emu/bus/cgenie/parallel/joystick.h b/src/emu/bus/cgenie/parallel/joystick.h new file mode 100644 index 00000000000..28be43b00e6 --- /dev/null +++ b/src/emu/bus/cgenie/parallel/joystick.h @@ -0,0 +1,48 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Joystick Interface EG2013 + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_PARALLEL_JOYSTICK_H__ +#define __CGENIE_PARALLEL_JOYSTICK_H__ + +#include "emu.h" +#include "parallel.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> cgenie_joystick_device + +class cgenie_joystick_device : public device_t, public device_parallel_interface +{ +public: + // construction/destruction + cgenie_joystick_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + +protected: + virtual void device_start(); + virtual void device_reset(); + virtual ioport_constructor device_input_ports() const; + + virtual void pa_w(UINT8 data); + virtual UINT8 pb_r(); + +private: + required_ioport_array<4> m_joy; + required_ioport_array<6> m_keypad; + + UINT8 m_select; +}; + +// device type definition +extern const device_type CGENIE_JOYSTICK; + +#endif // __CGENIE_PARALLEL_JOYSTICK_H__ diff --git a/src/emu/bus/cgenie/parallel/parallel.c b/src/emu/bus/cgenie/parallel/parallel.c new file mode 100644 index 00000000000..e948af9c00a --- /dev/null +++ b/src/emu/bus/cgenie/parallel/parallel.c @@ -0,0 +1,115 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Parallel Slot + + 20-pin slot + +***************************************************************************/ + +#include "parallel.h" + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type PARALLEL_SLOT = &device_creator; + + +//************************************************************************** +// SLOT DEVICE +//************************************************************************** + +//------------------------------------------------- +// parallel_slot_device - constructor +//------------------------------------------------- + +parallel_slot_device::parallel_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, PARALLEL_SLOT, "Parallel Slot", tag, owner, clock, "parallel_slot", __FILE__), + device_slot_interface(mconfig, *this), + m_cart(NULL) +{ +} + +//------------------------------------------------- +// parallel_slot_device - destructor +//------------------------------------------------- + +parallel_slot_device::~parallel_slot_device() +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void parallel_slot_device::device_start() +{ + m_cart = dynamic_cast(get_card_device()); +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void parallel_slot_device::device_reset() +{ +} + + +//************************************************************************** +// I/O PORTS +//************************************************************************** + +READ8_MEMBER( parallel_slot_device::pa_r ) +{ + if (m_cart) + return m_cart->pa_r(); + else + return 0xff; +} + +WRITE8_MEMBER( parallel_slot_device::pa_w ) +{ + if (m_cart) + m_cart->pa_w(data); +} + +READ8_MEMBER( parallel_slot_device::pb_r ) +{ + if (m_cart) + return m_cart->pb_r(); + else + return 0xff; +} + +WRITE8_MEMBER( parallel_slot_device::pb_w ) +{ + if (m_cart) + m_cart->pb_w(data); +} + + +//************************************************************************** +// CARTRIDGE INTERFACE +//************************************************************************** + +//------------------------------------------------- +// device_parallel_interface - constructor +//------------------------------------------------- + +device_parallel_interface::device_parallel_interface(const machine_config &mconfig, device_t &device) : + device_slot_card_interface(mconfig, device) +{ + m_slot = dynamic_cast(device.owner()); +} + +//------------------------------------------------- +// ~device_parallel_interface - destructor +//------------------------------------------------- + +device_parallel_interface::~device_parallel_interface() +{ +} diff --git a/src/emu/bus/cgenie/parallel/parallel.h b/src/emu/bus/cgenie/parallel/parallel.h new file mode 100644 index 00000000000..a7f5c8bbb77 --- /dev/null +++ b/src/emu/bus/cgenie/parallel/parallel.h @@ -0,0 +1,94 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Parallel Slot + + 20-pin slot + + 1 GND 11 IOB2 + 2 +12V 12 IOB1 + 3 IOA3 13 IOB0 + 4 IOA4 14 IOB3 + 5 IOA0 15 IOB4 + 6 IOA5 16 IOB5 + 7 IOA1 17 IOB7 + 8 IOA2 18 IOB6 + 9 IOA7 19 +5V + 10 IOA6 20 -12V + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_PARALLEL_H__ +#define __CGENIE_PARALLEL_H__ + +#include "emu.h" + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_PARALLEL_SLOT_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, PARALLEL_SLOT, 0) \ + MCFG_DEVICE_SLOT_INTERFACE(parallel_slot_carts, NULL, false) + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +class device_parallel_interface; + +class parallel_slot_device : public device_t, public device_slot_interface +{ +public: + // construction/destruction + parallel_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + virtual ~parallel_slot_device(); + + // IOA + DECLARE_READ8_MEMBER(pa_r); + DECLARE_WRITE8_MEMBER(pa_w); + + // IOB + DECLARE_READ8_MEMBER(pb_r); + DECLARE_WRITE8_MEMBER(pb_w); + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + + device_parallel_interface *m_cart; + +private: +}; + +// class representing interface-specific live parallel device +class device_parallel_interface : public device_slot_card_interface +{ +public: + // construction/destruction + device_parallel_interface(const machine_config &mconfig, device_t &device); + virtual ~device_parallel_interface(); + + virtual UINT8 pa_r() { return 0xff; }; + virtual void pa_w(UINT8 data) {}; + + virtual UINT8 pb_r() { return 0xff; }; + virtual void pb_w(UINT8 data) {}; + +protected: + parallel_slot_device *m_slot; +}; + +// device type definition +extern const device_type PARALLEL_SLOT; + +// include here so drivers don't need to +#include "carts.h" + +#endif // __CGENIE_PARALLEL_H__ diff --git a/src/emu/bus/cgenie/parallel/printer.c b/src/emu/bus/cgenie/parallel/printer.c new file mode 100644 index 00000000000..f9963844dd5 --- /dev/null +++ b/src/emu/bus/cgenie/parallel/printer.c @@ -0,0 +1,132 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Printer Interface EG2012 + +***************************************************************************/ + +#include "printer.h" + + +//************************************************************************** +// CONSTANTS/MACROS +//************************************************************************** + +#define VERBOSE 0 + + +//************************************************************************** +// DEVICE DEFINITIONS +//************************************************************************** + +const device_type CGENIE_PRINTER = &device_creator; + +//------------------------------------------------- +// machine_config_additions - device-specific +// machine configurations +//------------------------------------------------- + +static MACHINE_CONFIG_FRAGMENT( cgenie_printer ) + MCFG_CENTRONICS_ADD("centronics", centronics_devices, "printer") + MCFG_CENTRONICS_BUSY_HANDLER(WRITELINE(cgenie_printer_device, busy_w)) + MCFG_CENTRONICS_PERROR_HANDLER(WRITELINE(cgenie_printer_device, perror_w)) + MCFG_CENTRONICS_SELECT_HANDLER(WRITELINE(cgenie_printer_device, select_w)) + MCFG_CENTRONICS_FAULT_HANDLER(WRITELINE(cgenie_printer_device, fault_w)) + MCFG_CENTRONICS_OUTPUT_LATCH_ADD("latch", "centronics") +MACHINE_CONFIG_END + +machine_config_constructor cgenie_printer_device::device_mconfig_additions() const +{ + return MACHINE_CONFIG_NAME( cgenie_printer ); +} + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// cgenie_printer_device - constructor +//------------------------------------------------- + +cgenie_printer_device::cgenie_printer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, CGENIE_PRINTER, "Printer Interface EG2012", tag, owner, clock, "cgenie_printer", __FILE__), + device_parallel_interface(mconfig, *this), + m_centronics(*this, "centronics"), + m_latch(*this, "latch"), + m_centronics_busy(0), + m_centronics_out_of_paper(0), + m_centronics_unit_sel(1), + m_centronics_ready(1) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void cgenie_printer_device::device_start() +{ +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void cgenie_printer_device::device_reset() +{ +} + + +//************************************************************************** +// IMPLEMENTATION +//************************************************************************** + +WRITE_LINE_MEMBER( cgenie_printer_device::busy_w ) +{ + m_centronics_busy = state; +} + +WRITE_LINE_MEMBER( cgenie_printer_device::perror_w ) +{ + m_centronics_out_of_paper = state; +} + +WRITE_LINE_MEMBER( cgenie_printer_device::select_w ) +{ + m_centronics_unit_sel = state; +} + +WRITE_LINE_MEMBER( cgenie_printer_device::fault_w ) +{ + m_centronics_ready = state; +} + +void cgenie_printer_device::pa_w(UINT8 data) +{ + if (VERBOSE) + logerror("%s: pa_w %02x\n", tag(), data); + + m_latch->write(data); +} + +UINT8 cgenie_printer_device::pb_r() +{ + UINT8 data = 0x0f; + + data |= m_centronics_ready << 4; + data |= m_centronics_unit_sel << 5; + data |= m_centronics_out_of_paper << 6; + data |= m_centronics_busy << 7; + + return data; +} + +void cgenie_printer_device::pb_w(UINT8 data) +{ + if (VERBOSE) + logerror("%s: pa_w %02x\n", tag(), data); + + m_centronics->write_strobe(BIT(data, 0)); +} diff --git a/src/emu/bus/cgenie/parallel/printer.h b/src/emu/bus/cgenie/parallel/printer.h new file mode 100644 index 00000000000..52479c73d5c --- /dev/null +++ b/src/emu/bus/cgenie/parallel/printer.h @@ -0,0 +1,58 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + EACA Colour Genie Printer Interface EG2012 + +***************************************************************************/ + +#pragma once + +#ifndef __CGENIE_PARALLEL_PRINTER_H__ +#define __CGENIE_PARALLEL_PRINTER_H__ + +#include "emu.h" +#include "parallel.h" +#include "bus/centronics/ctronics.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> cgenie_printer_device + +class cgenie_printer_device : public device_t, public device_parallel_interface +{ +public: + // construction/destruction + cgenie_printer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + DECLARE_WRITE_LINE_MEMBER(busy_w); + DECLARE_WRITE_LINE_MEMBER(perror_w); + DECLARE_WRITE_LINE_MEMBER(select_w); + DECLARE_WRITE_LINE_MEMBER(fault_w); + +protected: + virtual machine_config_constructor device_mconfig_additions() const; + virtual void device_start(); + virtual void device_reset(); + + virtual void pa_w(UINT8 data); + virtual UINT8 pb_r(); + virtual void pb_w(UINT8 data); + +private: + required_device m_centronics; + required_device m_latch; + + int m_centronics_busy; + int m_centronics_out_of_paper; + int m_centronics_unit_sel; + int m_centronics_ready; +}; + +// device type definition +extern const device_type CGENIE_PRINTER; + +#endif // __CGENIE_PARALLEL_PRINTER_H__ diff --git a/src/mess/drivers/cgenie.c b/src/mess/drivers/cgenie.c index 23f62221c77..9771f744502 100644 --- a/src/mess/drivers/cgenie.c +++ b/src/mess/drivers/cgenie.c @@ -1,505 +1,480 @@ -// license:BSD-3-Clause -// copyright-holders:Nathan Woods +// license:GPL-2.0+ +// copyright-holders:Dirk Best /*************************************************************************** -HAD to change the PORT_ANALOG defs in this file... please check ;-) - -Colour Genie memory map - -CPU #1: -0000-3fff ROM basic & bios R D0-D7 - -4000-bfff RAM -c000-dfff ROM dos R D0-D7 -e000-efff ROM extra R D0-D7 -f000-f3ff color ram W/R D0-D3 -f400-f7ff font ram W/R D0-D7 -f800-f8ff keyboard matrix R D0-D7 -ffe0-ffe3 floppy motor W D0-D2 - floppy head select W D3 -ffec-ffef FDC WD179x R/W D0-D7 - ffec command W - ffec status R - ffed track R/W - ffee sector R/W - ffef data R/W - -Interrupts: -IRQ mode 1 -NMI + + EACA Colour Genie EG2000 + + TODO: + - System is too fast, there should be one wait cycle every five cycles? + - What's the exact MC6845 type? It can't be H46505 + - Adjust visible area so that the borders aren't that large (needs + MC6845 changes) + - Verify BASIC and character set versions + ***************************************************************************/ #include "emu.h" #include "cpu/z80/z80.h" -#include "includes/cgenie.h" -#include "imagedev/flopdrv.h" -#include "formats/basicdsk.h" -#include "imagedev/cassette.h" +#include "machine/ram.h" +#include "video/mc6845.h" #include "sound/ay8910.h" -#include "sound/dac.h" +#include "imagedev/cassette.h" #include "formats/cgen_cas.h" -#include "machine/ram.h" -#include "bus/cgenie/expansion.h" +#include "bus/rs232/rs232.h" +#include "bus/cgenie/expansion/expansion.h" +#include "bus/cgenie/parallel/parallel.h" + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +class cgenie_state : public driver_device +{ +public: + cgenie_state(const machine_config &mconfig, device_type type, const char *tag) + : driver_device(mconfig, type, tag), + m_maincpu(*this, "maincpu"), + m_cassette(*this, "cassette"), + m_ram(*this, RAM_TAG), + m_crtc(*this, "crtc"), + m_rs232(*this, "rs232"), + m_exp(*this, "exp"), + m_char_rom(*this, "gfx1"), + m_color_ram(*this, "colorram"), + m_font_ram(*this, "fontram"), + m_keyboard(*this, "KEY"), + m_palette(NULL), + m_control(0xff), + m_rs232_rx(1), + m_rs232_dcd(1) + {} + + DECLARE_DRIVER_INIT(cgenie_eu); + DECLARE_DRIVER_INIT(cgenie_nz); + + MC6845_BEGIN_UPDATE(crtc_begin_update); + MC6845_UPDATE_ROW(crtc_update_row); + + // 4-bit color ram + DECLARE_READ8_MEMBER(colorram_r); + DECLARE_WRITE8_MEMBER(colorram_w); + + // control port + DECLARE_WRITE8_MEMBER(control_w); + DECLARE_READ8_MEMBER(control_r); + + DECLARE_READ8_MEMBER(keyboard_r); + DECLARE_INPUT_CHANGED_MEMBER(rst_callback); + + DECLARE_WRITE_LINE_MEMBER(rs232_rx_w); + DECLARE_WRITE_LINE_MEMBER(rs232_dcd_w); + +protected: + virtual void machine_start(); + +private: + required_device m_maincpu; + required_device m_cassette; + required_device m_ram; + required_device m_crtc; + required_device m_rs232; + required_device m_exp; + required_memory_region m_char_rom; + required_shared_ptr m_color_ram; + required_shared_ptr m_font_ram; + required_ioport_array<8> m_keyboard; + + static const rgb_t m_palette_bg[]; + static const rgb_t m_palette_eu[]; + static const rgb_t m_palette_nz[]; + + const rgb_t *m_palette; + rgb_t m_background_color; + + UINT8 m_control; + + int m_rs232_rx; + int m_rs232_dcd; +}; + + +//************************************************************************** +// ADDRESS MAPS +//************************************************************************** static ADDRESS_MAP_START( cgenie_mem, AS_PROGRAM, 8, cgenie_state ) ADDRESS_MAP_UNMAP_HIGH AM_RANGE(0x0000, 0x3fff) AM_ROM -// AM_RANGE(0x4000, 0xbfff) AM_RAM // set up in MACHINE_START - AM_RANGE(0xf000, 0xf3ff) AM_READWRITE(cgenie_colorram_r, cgenie_colorram_w ) AM_SHARE("colorram") - AM_RANGE(0xf400, 0xf7ff) AM_READWRITE(cgenie_fontram_r, cgenie_fontram_w) AM_SHARE("fontram") - AM_RANGE(0xf800, 0xf8ff) AM_READ(cgenie_keyboard_r ) - AM_RANGE(0xffe0, 0xffe3) AM_READ(cgenie_irq_status_r) +// AM_RANGE(0x4000, 0xbfff) AM_RAM // set up in machine_start + AM_RANGE(0xc000, 0xefff) AM_NOP // cartridge space + AM_RANGE(0xf000, 0xf3ff) AM_READWRITE(colorram_r, colorram_w ) AM_SHARE("colorram") + AM_RANGE(0xf400, 0xf7ff) AM_RAM AM_SHARE("fontram") + AM_RANGE(0xf800, 0xf8ff) AM_MIRROR(0x300) AM_READ(keyboard_r) + AM_RANGE(0xfc00, 0xffff) AM_NOP // cartridge space ADDRESS_MAP_END static ADDRESS_MAP_START( cgenie_io, AS_IO, 8, cgenie_state ) ADDRESS_MAP_GLOBAL_MASK(0xff) - AM_RANGE(0xf8, 0xf8) AM_READWRITE(cgenie_sh_control_port_r, cgenie_sh_control_port_w ) + AM_RANGE(0xf8, 0xf8) AM_DEVWRITE("ay8910", ay8910_device, address_w) AM_RANGE(0xf9, 0xf9) AM_DEVREADWRITE("ay8910", ay8910_device, data_r, data_w) - AM_RANGE(0xfa, 0xfa) AM_READWRITE(cgenie_index_r, cgenie_index_w ) - AM_RANGE(0xfb, 0xfb) AM_READWRITE(cgenie_register_r, cgenie_register_w ) - AM_RANGE(0xff, 0xff) AM_READWRITE(cgenie_port_ff_r, cgenie_port_ff_w ) + AM_RANGE(0xfa, 0xfa) AM_DEVWRITE("crtc", mc6845_1_device, address_w) + AM_RANGE(0xfb, 0xfb) AM_DEVREADWRITE("crtc", mc6845_1_device, register_r, register_w) + AM_RANGE(0xff, 0xff) AM_READWRITE(control_r, control_w) ADDRESS_MAP_END -static INPUT_PORTS_START( cgenie ) - PORT_START("DSW0") - PORT_DIPNAME( 0x10, 0x10, "Video Display accuracy") PORT_CODE(KEYCODE_F5) PORT_TOGGLE - PORT_DIPSETTING( 0x10, "TV set" ) - PORT_DIPSETTING( 0x00, "RGB monitor" ) - PORT_BIT(0xef, 0xef, IPT_UNUSED) - -/************************************************************************** - +-------------------------------+ +-------------------------------+ - | 0 1 2 3 4 5 6 7 | | 0 1 2 3 4 5 6 7 | -+--+---+---+---+---+---+---+---+---+ +--+---+---+---+---+---+---+---+---+ -|0 | @ | A | B | C | D | E | F | G | |0 | ` | a | b | c | d | e | f | g | -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|1 | H | I | J | K | L | M | N | O | |1 | h | i | j | k | l | m | n | o | -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|2 | P | Q | R | S | T | U | V | W | |2 | p | q | r | s | t | u | v | w | -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|3 | X | Y | Z | [ |F-1|F-2|F-3|F-4| |3 | x | y | z | { |F-5|F-6|F-7|F-8| -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|4 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |4 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|5 | 8 | 9 | : | ; | , | - | . | / | |5 | 8 | 9 | * | + | < | = | > | ? | -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|6 |ENT|CLR|BRK|UP |DN |LFT|RGT|SPC| |6 |ENT|CLR|BRK|UP |DN |LFT|RGT|SPC| -| +---+---+---+---+---+---+---+---+ | +---+---+---+---+---+---+---+---+ -|7 |SHF|ALT|PUP|PDN|INS|DEL|CTL|END| |7 |SHF|ALT|PUP|PDN|INS|DEL|CTL|END| -+--+---+---+---+---+---+---+---+---+ +--+---+---+---+---+---+---+---+---+ -***************************************************************************/ - PORT_START("ROW0") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('@') PORT_CHAR('`') - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A') - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B') - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C') - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D') - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E') - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F') - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G') - - PORT_START("ROW1") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H') - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I') - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J') - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K') - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L') - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M') - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N') - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O') - - PORT_START("ROW2") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P') - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q') - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R') - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S') - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T') - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U') - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V') - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W') - - PORT_START("ROW3") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X') - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y') - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z') - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("[ { (Not Connected)") PORT_CHAR('[') PORT_CHAR('{') - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1)) PORT_CHAR(UCHAR_MAMEKEY(F5)) - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2)) PORT_CHAR(UCHAR_MAMEKEY(F6)) - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3)) PORT_CHAR(UCHAR_MAMEKEY(F7)) - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4)) PORT_CHAR(UCHAR_MAMEKEY(F8)) - - PORT_START("ROW4") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!') - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"') - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#') - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$') - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%') - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&') - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'') - - PORT_START("ROW5") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(') - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')') - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS) PORT_CHAR(':') PORT_CHAR('*') - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR('+') - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<') - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('-') PORT_CHAR('=') - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>') - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?') - - PORT_START("ROW6") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Clear") PORT_CODE(KEYCODE_EQUALS) PORT_CHAR(UCHAR_MAMEKEY(F10)) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Break") PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(UCHAR_MAMEKEY(ESC)) - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_UP) PORT_CHAR(UCHAR_MAMEKEY(UP)) - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT)) - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ') - - /* 2008-05 FP: Below we still miss a 'Lock' key, two 'Rst' keys (used in pair, they should restart the - system) and, I guess, two unused inputs (according to the user manual, there are no other keys on the - keyboard) */ - PORT_START("ROW7") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_LSHIFT) PORT_CHAR(UCHAR_SHIFT_1) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Mod Sel") PORT_CODE(KEYCODE_LALT) PORT_CHAR(UCHAR_MAMEKEY(F9)) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Unknown 1") - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Rpt") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(F11)) - PORT_BIT(0x10, 0x00, IPT_KEYBOARD) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_MAMEKEY(F12)) - PORT_BIT(0x20, 0x00, IPT_KEYBOARD) PORT_NAME("Unknown 2") - PORT_BIT(0x40, 0x00, IPT_KEYBOARD) PORT_NAME("Unknown 3") - PORT_BIT(0x80, 0x00, IPT_KEYBOARD) PORT_NAME("Unknown 4") - - PORT_START("JOY0") - PORT_BIT( 0xff, 0x60, IPT_AD_STICK_X) PORT_SENSITIVITY(40) PORT_KEYDELTA(0) PORT_MINMAX(0x00,0xcf ) PORT_PLAYER(1) - - PORT_START("JOY1") - PORT_BIT( 0xff, 0x60, IPT_AD_STICK_Y) PORT_SENSITIVITY(40) PORT_KEYDELTA(0) PORT_MINMAX(0x00,0xcf ) PORT_PLAYER(1) PORT_REVERSE - - PORT_START("JOY2") - PORT_BIT( 0xff, 0x60, IPT_AD_STICK_X) PORT_SENSITIVITY(40) PORT_KEYDELTA(0) PORT_MINMAX(0x00,0xcf ) PORT_PLAYER(2) - - PORT_START("JOY3") - PORT_BIT( 0xff, 0x60, IPT_AD_STICK_Y) PORT_SENSITIVITY(40) PORT_KEYDELTA(0) PORT_MINMAX(0x00,0xcf ) PORT_PLAYER(2) PORT_REVERSE - - /* Joystick Keypad */ - /* keypads were organized a 3 x 4 matrix and it looked */ - /* exactly like a our northern telephone numerical pads */ - /* The addressing was done with a single clear bit 0..6 */ - /* on i/o port A, while all other bits were set. */ - /* (e.g. 0xFE addresses keypad1 row 0, 0xEF keypad2 row 1) */ - - /* bit 0 1 2 3 */ - /* FE/F7 0 [3] [6] [9] [#] */ - /* FD/EF 1 [2] [5] [8] [0] */ - /* FB/DF 2 [1] [4] [7] [*] */ - - /* 2008-05 FP: temporarily I mapped these as follows: - - Joy 1 at Keypad - - Joy 2 at a Joystick buttons - A better mapping would be needed... - */ - - PORT_START("KP0") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [3]") PORT_CODE(KEYCODE_3_PAD) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [6]") PORT_CODE(KEYCODE_6_PAD) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [9]") PORT_CODE(KEYCODE_9_PAD) - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [#]") PORT_CODE(KEYCODE_SLASH_PAD) - - PORT_START("KP1") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [2]") PORT_CODE(KEYCODE_2_PAD) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [5]") PORT_CODE(KEYCODE_5_PAD) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [8]") PORT_CODE(KEYCODE_8_PAD) - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [0]") PORT_CODE(KEYCODE_0_PAD) - - PORT_START("KP2") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [1]") PORT_CODE(KEYCODE_1_PAD) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [4]") PORT_CODE(KEYCODE_4_PAD) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [7]") PORT_CODE(KEYCODE_7_PAD) - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 1 [*]") PORT_CODE(KEYCODE_ASTERISK) - - PORT_START("KP3") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [3]") PORT_CODE(JOYCODE_BUTTON2) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [6]") PORT_CODE(JOYCODE_BUTTON5) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [9]") - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [#]") PORT_CODE(JOYCODE_BUTTON1) - - PORT_START("KP4") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [2]") PORT_CODE(JOYCODE_BUTTON2) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [5]") PORT_CODE(JOYCODE_BUTTON5) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [8]") - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [0]") - - PORT_START("KP5") - PORT_BIT(0x01, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [1]") PORT_CODE(JOYCODE_BUTTON1) - PORT_BIT(0x02, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [4]") PORT_CODE(JOYCODE_BUTTON4) - PORT_BIT(0x04, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [7]") - PORT_BIT(0x08, 0x00, IPT_KEYBOARD) PORT_NAME("Joy 2 [*]") PORT_CODE(JOYCODE_BUTTON1) +//************************************************************************** +// INPUTS +//************************************************************************** + +static INPUT_PORTS_START( cgenie ) + PORT_START("KEY.0") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('@') PORT_CHAR('`') + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A') + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B') + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C') + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D') + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E') + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F') + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G') + + PORT_START("KEY.1") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H') + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I') + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J') + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K') + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L') + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M') + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N') + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O') + + PORT_START("KEY.2") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P') + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q') + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R') + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S') + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T') + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U') + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V') + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W') + + PORT_START("KEY.3") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X') + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y') + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z') + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_UNUSED) // produces [ and { when pressed, not on keyboard + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F1) PORT_CHAR(UCHAR_MAMEKEY(F1)) PORT_CHAR(UCHAR_MAMEKEY(F5)) + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F2) PORT_CHAR(UCHAR_MAMEKEY(F2)) PORT_CHAR(UCHAR_MAMEKEY(F6)) + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F3) PORT_CHAR(UCHAR_MAMEKEY(F3)) PORT_CHAR(UCHAR_MAMEKEY(F7)) + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_F4) PORT_CHAR(UCHAR_MAMEKEY(F4)) PORT_CHAR(UCHAR_MAMEKEY(F8)) + + PORT_START("KEY.4") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!') + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('"') + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#') + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$') + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%') + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('&') + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('\'') + + PORT_START("KEY.5") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('(') + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR(')') + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS) PORT_CHAR(':') PORT_CHAR('*') + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR('+') + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<') + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('-') PORT_CHAR('=') + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>') + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?') + + PORT_START("KEY.6") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER) PORT_CHAR(13) + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Clear") PORT_CODE(KEYCODE_EQUALS) PORT_CHAR(UCHAR_MAMEKEY(F10)) + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Break") PORT_CODE(KEYCODE_BACKSLASH2) PORT_CHAR(UCHAR_MAMEKEY(ESC)) + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_UP) PORT_CHAR(UCHAR_MAMEKEY(UP)) + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_DOWN) PORT_CHAR(UCHAR_MAMEKEY(DOWN)) + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_LEFT) PORT_CHAR(UCHAR_MAMEKEY(LEFT)) + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_RIGHT) PORT_CHAR(UCHAR_MAMEKEY(RIGHT)) + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ') + + PORT_START("KEY.7") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_LSHIFT) PORT_CHAR(UCHAR_SHIFT_1) + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Mod Sel") PORT_CODE(KEYCODE_LALT) PORT_CHAR(UCHAR_MAMEKEY(F9)) + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_UNUSED) + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Rpt") PORT_CODE(KEYCODE_PGDN) PORT_CHAR(UCHAR_MAMEKEY(F11)) + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CHAR(UCHAR_MAMEKEY(F12)) + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_UNUSED) + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_UNUSED) + PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_OTHER) PORT_NAME("L.P.") // marked as "L.P." in the manual, lightpen? + + PORT_START("RST") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_OTHER) PORT_CODE(KEYCODE_TAB) PORT_NAME("Rst") PORT_CHAR(9) PORT_CHANGED_MEMBER(DEVICE_SELF, cgenie_state, rst_callback, NULL) INPUT_PORTS_END -static const gfx_layout cgenie_charlayout = + +//************************************************************************** +// KEYBOARD +//************************************************************************** + +READ8_MEMBER( cgenie_state::keyboard_r ) { - 8,8, /* 8*8 characters */ - 384, /* 256 fixed + 128 defineable characters */ - 1, /* 1 bits per pixel */ - { 0 }, /* no bitplanes; 1 bit per pixel */ - { 0, 1, 2, 3, 4, 5, 6, 7 }, /* x offsets */ - { 0*8,1*8,2*8,3*8,4*8,5*8,6*8,7*8 }, - 8*8 /* every char takes 8 bytes */ -}; + int data = 0; -static const gfx_layout cgenie_gfxlayout = + for (int i = 0; i < 8; i++) + if (BIT(offset, i)) + data |= m_keyboard[i]->read(); + + return data; +} + +INPUT_CHANGED_MEMBER( cgenie_state::rst_callback ) { - 8,8, /* 4*8 characters */ - 256, /* 256 graphics patterns */ - 2, /* 2 bits per pixel */ - { 0, 1 }, /* two bitplanes; 2 bit per pixel */ - { 0, 0, 2, 2, 4, 4, 6, 6}, /* x offsets */ - { 0*8,1*8,2*8,3*8,4*8,5*8,6*8,7*8 }, - 8*8 /* every char takes 8 bytes */ -}; + m_maincpu->set_input_line(INPUT_LINE_NMI, newval); +} -static GFXDECODE_START( cgenie ) - GFXDECODE_ENTRY( "gfx1", 0, cgenie_charlayout, 0, 3*16 ) - GFXDECODE_ENTRY( "gfx2", 0, cgenie_gfxlayout, 3*16*2, 3*4 ) -GFXDECODE_END - -static const unsigned char cgenie_colors[] = { - 0x00,0x00,0x00, /* background */ - 0x5e,0x5e,0x5e, /* gray */ - 0x11,0xff,0xea, /* cyan */ - 0xff,0x00,0x5e, /* red */ - 0xea,0xea,0xea, /* white */ - 0xff,0xf9,0x00, /* yellow */ - 0x6e,0xff,0x00, /* green */ - 0xff,0x52,0x00, /* orange */ - 0xea,0xff,0x00, /* light yellow */ - 0x02,0x48,0xff, /* blue */ - 0x8e,0xd4,0xff, /* light blue */ - 0xff,0x12,0xff, /* pink */ - 0x88,0x43,0xff, /* purple */ - 0x8c,0x8c,0x8c, /* light gray */ - 0x00,0xfb,0x8c, /* turquoise */ - 0xd2,0x00,0xff, /* magenta */ - 0xff,0xff,0xff, /* bright white */ - - -#if 0 - 0*4, 0*4, 0*4, /* background */ - -/* this is the 'RGB monitor' version, strong and clean */ - 15*4, 15*4, 15*4, /* gray */ - 0*4, 48*4, 48*4, /* cyan */ - 60*4, 0*4, 0*4, /* red */ - 47*4, 47*4, 47*4, /* white */ - 55*4, 55*4, 0*4, /* yellow */ - 0*4, 56*4, 0*4, /* green */ - 42*4, 32*4, 0*4, /* orange */ - 63*4, 63*4, 0*4, /* light yellow */ - 0*4, 0*4, 48*4, /* blue */ - 0*4, 24*4, 63*4, /* light blue */ - 60*4, 0*4, 38*4, /* pink */ - 38*4, 0*4, 60*4, /* purple */ - 31*4, 31*4, 31*4, /* light gray */ - 0*4, 63*4, 63*4, /* light cyan */ - 58*4, 0*4, 58*4, /* magenta */ - 63*4, 63*4, 63*4, /* bright white */ -#endif - -/* this is the 'TV screen' version, weak and blurred by repeating pixels */ - 15*2+80, 15*2+80, 15*2+80, /* gray */ - 0*2+80, 48*2+80, 48*2+80, /* cyan */ - 60*2+80, 0*2+80, 0*2+80, /* red */ - 47*2+80, 47*2+80, 47*2+80, /* white */ - 55*2+80, 55*2+80, 0*2+80, /* yellow */ - 0*2+80, 56*2+80, 0*2+80, /* green */ - 42*2+80, 32*2+80, 0*2+80, /* orange */ - 63*2+80, 63*2+80, 0*2+80, /* light yellow */ - 0*2+80, 0*2+80, 48*2+80, /* blue */ - 0*2+80, 24*2+80, 63*2+80, /* light blue */ - 60*2+80, 0*2+80, 38*2+80, /* pink */ - 38*2+80, 0*2+80, 60*2+80, /* purple */ - 31*2+80, 31*2+80, 31*2+80, /* light gray */ - 0*2+80, 63*2+80, 63*2+80, /* light cyan */ - 58*2+80, 0*2+80, 58*2+80, /* magenta */ - 63*2+80, 63*2+80, 63*2+80, /* bright white */ - - 15*2+96, 15*2+96, 15*2+96, /* gray */ - 0*2+96, 48*2+96, 48*2+96, /* cyan */ - 60*2+96, 0*2+96, 0*2+96, /* red */ - 47*2+96, 47*2+96, 47*2+96, /* white */ - 55*2+96, 55*2+96, 0*2+96, /* yellow */ - 0*2+96, 56*2+96, 0*2+96, /* green */ - 42*2+96, 32*2+96, 0*2+96, /* orange */ - 63*2+96, 63*2+96, 0*2+96, /* light yellow */ - 0*2+96, 0*2+96, 48*2+96, /* blue */ - 0*2+96, 24*2+96, 63*2+96, /* light blue */ - 60*2+96, 0*2+96, 38*2+96, /* pink */ - 38*2+96, 0*2+96, 60*2+96, /* purple */ - 31*2+96, 31*2+96, 31*2+96, /* light gray */ - 0*2+96, 63*2+96, 63*2+96, /* light cyan */ - 58*2+96, 0*2+96, 58*2+96, /* magenta */ - 63*2+96, 63*2+96, 63*2+96, /* bright white */ +//************************************************************************** +// CONTROL PORT & RS232 +//************************************************************************** -}; +WRITE8_MEMBER( cgenie_state::control_w ) +{ + // cassette output + m_cassette->output(BIT(data, 0) ? -1.0 : 1.0); -static const unsigned char cgenienz_colors[] = { - 0x00,0x00,0x00, /* background */ - 0xff,0xff,0xff, /* gray */ - 0x12,0xff,0xff, /* cyan */ - 0xff,0x6f,0xff, /* red */ - 0x31,0x77,0xff, /* white */ - 0xff,0xcb,0x00, /* yellow */ - 0x6e,0xff,0x00, /* green */ - 0xff,0x52,0x00, /* orange */ - 0x5e,0x5e,0x5e, /* light yellow */ - 0xea,0xea,0xea, /* blue */ - 0x00,0xff,0xdd, /* light blue */ - 0xd2,0x00,0xff, /* pink */ - 0x02,0x48,0xff, /* purple */ - 0xff,0xf9,0x00, /* light gray */ - 0x00,0xda,0x00, /* light cyan */ - 0xff,0x22,0x00, /* magenta */ - 0x00,0x00,0x00, /* bright white */ - - -/* this is the 'TV screen' version, weak and blurred by repeating pixels */ - 15*2+80, 15*2+80, 15*2+80, /* gray */ - 0*2+80, 48*2+80, 48*2+80, /* cyan */ - 60*2+80, 0*2+80, 0*2+80, /* red */ - 47*2+80, 47*2+80, 47*2+80, /* white */ - 55*2+80, 55*2+80, 0*2+80, /* yellow */ - 0*2+80, 56*2+80, 0*2+80, /* green */ - 42*2+80, 32*2+80, 0*2+80, /* orange */ - 63*2+80, 63*2+80, 0*2+80, /* light yellow */ - 0*2+80, 0*2+80, 48*2+80, /* blue */ - 0*2+80, 24*2+80, 63*2+80, /* light blue */ - 60*2+80, 0*2+80, 38*2+80, /* pink */ - 38*2+80, 0*2+80, 60*2+80, /* purple */ - 31*2+80, 31*2+80, 31*2+80, /* light gray */ - 0*2+80, 63*2+80, 63*2+80, /* light cyan */ - 58*2+80, 0*2+80, 58*2+80, /* magenta */ - 63*2+80, 63*2+80, 63*2+80, /* bright white */ - - 15*2+96, 15*2+96, 15*2+96, /* gray */ - 0*2+96, 48*2+96, 48*2+96, /* cyan */ - 60*2+96, 0*2+96, 0*2+96, /* red */ - 47*2+96, 47*2+96, 47*2+96, /* white */ - 55*2+96, 55*2+96, 0*2+96, /* yellow */ - 0*2+96, 56*2+96, 0*2+96, /* green */ - 42*2+96, 32*2+96, 0*2+96, /* orange */ - 63*2+96, 63*2+96, 0*2+96, /* light yellow */ - 0*2+96, 0*2+96, 48*2+96, /* blue */ - 0*2+96, 24*2+96, 63*2+96, /* light blue */ - 60*2+96, 0*2+96, 38*2+96, /* pink */ - 38*2+96, 0*2+96, 60*2+96, /* purple */ - 31*2+96, 31*2+96, 31*2+96, /* light gray */ - 0*2+96, 63*2+96, 63*2+96, /* light cyan */ - 58*2+96, 0*2+96, 58*2+96, /* magenta */ - 63*2+96, 63*2+96, 63*2+96, /* bright white */ + // serial output + m_rs232->write_txd(BIT(data, 1)); + // background color selection + if (BIT(data, 2)) + m_background_color = m_palette_bg[4]; + else + m_background_color = m_palette_bg[data >> 6 & 0x03]; -}; + // graphics/text mode switch + m_crtc->set_hpixels_per_column(BIT(data, 5) ? 4 : 8); -static const unsigned short cgenie_palette[] = + m_control = data; +} + +READ8_MEMBER( cgenie_state::control_r ) { - 0, 1, 0, 2, 0, 3, 0, 4, /* RGB monitor set of text colors */ - 0, 5, 0, 6, 0, 7, 0, 8, - 0, 9, 0,10, 0,11, 0,12, - 0,13, 0,14, 0,15, 0,16, - - 0,17, 0,18, 0,19, 0,20, /* TV set text colors: darker */ - 0,21, 0,22, 0,23, 0,24, - 0,25, 0,26, 0,27, 0,28, - 0,29, 0,30, 0,31, 0,32, - - 0,33, 0,34, 0,35, 0,36, /* TV set text colors: a bit brighter */ - 0,37, 0,38, 0,39, 0,40, - 0,41, 0,42, 0,43, 0,44, - 0,45, 0,46, 0,47, 0,48, - - 0, 9, 7, 6, /* RGB monitor graphics colors */ - 0, 25, 23, 22, /* TV set graphics colors: darker */ - 0, 41, 39, 38, /* TV set graphics colors: a bit brighter */ -}; + UINT8 data = 0; + + data |= m_cassette->input() > 0 ? 1 : 0; + data |= m_rs232_rx << 1; + data |= m_rs232_dcd << 2; + + return data; +} -/* Initialize the palette */ -PALETTE_INIT_MEMBER(cgenie_state,cgenie) +WRITE_LINE_MEMBER( cgenie_state::rs232_rx_w ) { - UINT8 i, r, g, b; + m_rs232_rx = state; +} - for ( i = 0; i < 49; i++ ) - { - r = cgenie_colors[i*3]; g = cgenie_colors[i*3+1]; b = cgenie_colors[i*3+2]; - palette.set_indirect_color(i, rgb_t(r, g, b)); - } +WRITE_LINE_MEMBER( cgenie_state::rs232_dcd_w ) +{ + m_rs232_dcd = state; +} - for(i=0; i<108; i++) - palette.set_pen_indirect(i, cgenie_palette[i]); + +//************************************************************************** +// DRIVER INIT +//************************************************************************** + +DRIVER_INIT_MEMBER( cgenie_state, cgenie_eu ) +{ + m_palette = &m_palette_eu[0]; } -PALETTE_INIT_MEMBER(cgenie_state,cgenienz) +DRIVER_INIT_MEMBER( cgenie_state, cgenie_nz ) { - UINT8 i, r, g, b; + m_palette = &m_palette_nz[0]; +} - for ( i = 0; i < 49; i++ ) +void cgenie_state::machine_start() +{ + // setup ram + m_maincpu->space(AS_PROGRAM).install_ram(0x4000, 0x4000 + m_ram->size() - 1, m_ram->pointer()); + + // setup expansion bus + m_exp->set_program_space(&m_maincpu->space(AS_PROGRAM)); + m_exp->set_io_space(&m_maincpu->space(AS_IO)); +} + + +//************************************************************************** +// VIDEO EMULATION +//************************************************************************** + +READ8_MEMBER( cgenie_state::colorram_r ) +{ + return m_color_ram[offset] | 0xf0; +} + +WRITE8_MEMBER( cgenie_state::colorram_w ) +{ + m_color_ram[offset] = data & 0x0f; +} + +MC6845_BEGIN_UPDATE( cgenie_state::crtc_begin_update ) +{ + bitmap.fill(m_background_color, cliprect); +} + +MC6845_UPDATE_ROW( cgenie_state::crtc_update_row ) +{ + // don't need to do anything in vblank + if (!de) + return; + + for (int column = 0; column < x_count; column++) { - r = cgenienz_colors[i*3]; g = cgenienz_colors[i*3+1]; b = cgenienz_colors[i*3+2]; - palette.set_indirect_color(i, rgb_t(r, g, b)); + UINT8 code = m_ram->pointer()[ma + column]; + UINT8 color = m_color_ram[(ma & 0xbff) + column]; + + // gfx mode? + if (BIT(m_control, 5)) + { + const rgb_t map[] = { m_background_color, m_palette[8], m_palette[6], m_palette[5] }; + + bitmap.pix32(y + vbp, column * 4 + hbp + 0) = map[code >> 6 & 0x03]; + bitmap.pix32(y + vbp, column * 4 + hbp + 1) = map[code >> 4 & 0x03]; + bitmap.pix32(y + vbp, column * 4 + hbp + 2) = map[code >> 2 & 0x03]; + bitmap.pix32(y + vbp, column * 4 + hbp + 3) = map[code >> 0 & 0x03]; + } + else + { + UINT8 gfx = 0; + + // cursor visible? + if (cursor_x == column) + gfx = 0xff; + + // or use character rom? + else if ((code < 128) || (code < 192 && BIT(m_control, 4)) || (code > 192 && BIT(m_control, 3))) + gfx = m_char_rom->base()[(code << 3) | ra]; + + // or the programmable characters? + else + gfx = m_font_ram[((code << 3) | ra) & 0x3ff]; + + // 8 pixel chars + for (int p = 0; p < 8; p++) + bitmap.pix32(y + vbp, column * 8 + hbp + p) = BIT(gfx, 7 - p) ? m_palette[color] : m_background_color; + } } - - for(i=0; i<108; i++) - palette.set_pen_indirect(i, cgenie_palette[i]); } -static MACHINE_CONFIG_START( cgenie_common, cgenie_state ) - /* basic machine hardware */ - MCFG_CPU_ADD("maincpu", Z80, XTAL_17_73447MHz/8) /* 2,2168 MHz */ +//************************************************************************** +// PALETTE +//************************************************************************** + +// how accurate are these colors? +const rgb_t cgenie_state::m_palette_bg[] = +{ + rgb_t::black, + rgb_t(0x70, 0x28, 0x20), // dark orange + rgb_t(0x28, 0x70, 0x20), // dark green + rgb_t(0x48, 0x48, 0x48), // dark gray + rgb_t(0x70, 0x00, 0x70) // dark purple +}; + +// european palette +const rgb_t cgenie_state::m_palette_eu[] = +{ + rgb_t(0x5e, 0x5e, 0x5e), // gray + rgb_t(0x11, 0xff, 0xea), // cyan + rgb_t(0xff, 0x00, 0x5e), // red + rgb_t(0xea, 0xea, 0xea), // white + rgb_t(0xff, 0xf9, 0x00), // yellow + rgb_t(0x6e, 0xff, 0x00), // green + rgb_t(0xff, 0x52, 0x00), // orange + rgb_t(0xea, 0xff, 0x00), // light yellow + rgb_t(0x02, 0x48, 0xff), // blue + rgb_t(0x8e, 0xd4, 0xff), // light blue + rgb_t(0xff, 0x12, 0xff), // pink + rgb_t(0x88, 0x43, 0xff), // purple + rgb_t(0x8c, 0x8c, 0x8c), // light gray + rgb_t(0x00, 0xfb, 0x8c), // turquoise + rgb_t(0xd2, 0x00, 0xff), // magenta + rgb_t::white // bright white +}; + +// new zealand palette +const rgb_t cgenie_state::m_palette_nz[] = +{ + rgb_t::white, + rgb_t(0x12, 0xff, 0xff), + rgb_t(0xff, 0x6f, 0xff), + rgb_t(0x31, 0x77, 0xff), + rgb_t(0xff, 0xcb, 0x00), + rgb_t(0x6e, 0xff, 0x00), + rgb_t(0xff, 0x52, 0x00), + rgb_t(0x5e, 0x5e, 0x5e), + rgb_t(0xea, 0xea, 0xea), + rgb_t(0x00, 0xff, 0xdd), + rgb_t(0xd2, 0x00, 0xff), + rgb_t(0x02, 0x48, 0xff), + rgb_t(0xff, 0xf9, 0x00), + rgb_t(0x00, 0xda, 0x00), + rgb_t(0xff, 0x22, 0x00), + rgb_t::black +}; + + +//************************************************************************** +// MACHINE DEFINTIONS +//************************************************************************** + +static MACHINE_CONFIG_START( cgenie, cgenie_state ) + // basic machine hardware + MCFG_CPU_ADD("maincpu", Z80, XTAL_17_73447MHz / 8) // 2.2168 MHz MCFG_CPU_PROGRAM_MAP(cgenie_mem) MCFG_CPU_IO_MAP(cgenie_io) - MCFG_CPU_VBLANK_INT_DRIVER("screen", cgenie_state, cgenie_frame_interrupt) - MCFG_CPU_PERIODIC_INT_DRIVER(cgenie_state, cgenie_timer_interrupt, 40) - MCFG_QUANTUM_TIME(attotime::from_hz(240)) - - /* video hardware */ + // video hardware MCFG_SCREEN_ADD("screen", RASTER) - MCFG_SCREEN_REFRESH_RATE(50) - MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ - MCFG_SCREEN_SIZE(48*8, 32*8) - MCFG_SCREEN_VISIBLE_AREA(0*8, 48*8-1,0*8,32*8-1) - MCFG_SCREEN_UPDATE_DRIVER(cgenie_state, screen_update_cgenie) - MCFG_SCREEN_PALETTE("palette") - - MCFG_GFXDECODE_ADD("gfxdecode", "palette", cgenie ) - MCFG_PALETTE_ADD("palette", 108) - MCFG_PALETTE_INDIRECT_ENTRIES(49) + MCFG_SCREEN_RAW_PARAMS(XTAL_17_73447MHz / 2, 568, 32, 416, 312, 28, 284) + MCFG_SCREEN_UPDATE_DEVICE("crtc", mc6845_device, screen_update) - // Actually the video is driven by an HD46505 clocked at XTAL_17_73447MHz/16 + MCFG_MC6845_ADD("crtc", MC6845_1, "screen", XTAL_17_73447MHz / 16) + MCFG_MC6845_SHOW_BORDER_AREA(true) + MCFG_MC6845_CHAR_WIDTH(8) + MCFG_MC6845_BEGIN_UPDATE_CB(cgenie_state, crtc_begin_update) + MCFG_MC6845_UPDATE_ROW_CB(cgenie_state, crtc_update_row) - /* sound hardware */ + // sound hardware MCFG_SPEAKER_STANDARD_MONO("mono") - MCFG_SOUND_ADD("dac", DAC, 0) - MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) - MCFG_SOUND_ADD("ay8910", AY8910, XTAL_17_73447MHz/8) - MCFG_AY8910_PORT_A_READ_CB(READ8(cgenie_state, cgenie_psg_port_a_r)) - MCFG_AY8910_PORT_B_READ_CB(READ8(cgenie_state, cgenie_psg_port_b_r)) - MCFG_AY8910_PORT_A_WRITE_CB(WRITE8(cgenie_state, cgenie_psg_port_a_w)) - MCFG_AY8910_PORT_B_WRITE_CB(WRITE8(cgenie_state, cgenie_psg_port_b_w)) + MCFG_SOUND_ADD("ay8910", AY8910, XTAL_17_73447MHz / 8) + MCFG_AY8910_PORT_A_READ_CB(DEVREAD8("par", parallel_slot_device, pa_r)) + MCFG_AY8910_PORT_A_WRITE_CB(DEVWRITE8("par", parallel_slot_device, pa_w)) + MCFG_AY8910_PORT_B_READ_CB(DEVREAD8("par", parallel_slot_device, pb_r)) + MCFG_AY8910_PORT_B_WRITE_CB(DEVWRITE8("par", parallel_slot_device, pb_w)) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.75) - MCFG_CASSETTE_ADD( "cassette" ) + MCFG_CASSETTE_ADD("cassette") MCFG_CASSETTE_FORMATS(cgenie_cassette_formats) MCFG_CASSETTE_DEFAULT_STATE(CASSETTE_STOPPED) MCFG_CASSETTE_INTERFACE("cgenie_cass") MCFG_SOFTWARE_LIST_ADD("cass_list", "cgenie_cass") + // serial port + MCFG_RS232_PORT_ADD("rs232", default_rs232_devices, NULL) + MCFG_RS232_RXD_HANDLER(WRITELINE(cgenie_state, rs232_rx_w)) + MCFG_RS232_DCD_HANDLER(WRITELINE(cgenie_state, rs232_dcd_w)) + + // cartridge expansion slot MCFG_EXPANSION_SLOT_ADD("exp") - MCFG_EXPANSION_SLOT_INT_HANDLER(WRITELINE(cgenie_state, exp_intrq_w)) + MCFG_EXPANSION_SLOT_INT_HANDLER(INPUTLINE("maincpu", INPUT_LINE_IRQ0)) + + // parallel slot + MCFG_PARALLEL_SLOT_ADD("par") // internal ram MCFG_RAM_ADD(RAM_TAG) @@ -507,48 +482,41 @@ static MACHINE_CONFIG_START( cgenie_common, cgenie_state ) MCFG_RAM_EXTRA_OPTIONS("32K") MACHINE_CONFIG_END -static MACHINE_CONFIG_DERIVED( cgenie, cgenie_common ) - MCFG_PALETTE_MODIFY("palette") - MCFG_PALETTE_INIT_OWNER(cgenie_state, cgenie ) -MACHINE_CONFIG_END - -static MACHINE_CONFIG_DERIVED( cgenienz, cgenie_common ) - MCFG_PALETTE_MODIFY("palette") - MCFG_PALETTE_INIT_OWNER(cgenie_state, cgenienz ) -MACHINE_CONFIG_END -/*************************************************************************** - - Game driver(s) - -***************************************************************************/ +//************************************************************************** +// ROM DEFINITIONS +//************************************************************************** ROM_START( cgenie ) ROM_REGION(0x4000, "maincpu", 0) - ROM_LOAD("cgenie.rom", 0x0000, 0x4000, CRC(d359ead7) SHA1(d8c2fc389ad38c45fba0ed556a7d91abac5463f4)) - - ROM_REGION(0x0c00, "gfx1", 0) + ROM_LOAD("cg_rom1.z1", 0x0000, 0x1000, CRC(d3369420) SHA1(fe7f06f8e2b648d695d4787d00a374d3e4ac5d39)) + ROM_LOAD("cg_rom2.z2", 0x1000, 0x1000, CRC(73d2c9ea) SHA1(343d595b4eeaea627f9c36d5cef3827c79593425)) + ROM_LOAD("cg_rom3.z3", 0x2000, 0x1000, CRC(3f358811) SHA1(6ba151759fd8fd367806cf2dd5f1dfc33ee9521f)) + ROM_LOAD("cg_rom4.z4", 0x3000, 0x1000, CRC(be235782) SHA1(d7d61208a9855ffd09ecb051618f5ed6a8816f3f)) + + ROM_REGION(0x0800, "gfx1", 0) + // this is a "german" character set with umlauts, is this official? + ROM_LOAD("cgenieg.fnt", 0x0000, 0x0800, CRC(c3e60d57) SHA1(fb96f608fdb47391145fdcd614a9c7a79756e6a4)) + // default character set ROM_LOAD("cgenie1.fnt", 0x0000, 0x0800, CRC(4fed774a) SHA1(d53df8212b521892cc56be690db0bb474627d2ff)) - - /* Empty memory region for the character generator */ - ROM_REGION(0x0800, "gfx2", ROMREGION_ERASEFF) ROM_END ROM_START( cgenienz ) ROM_REGION(0x4000, "maincpu", 0) ROM_SYSTEM_BIOS(0, "old", "Old ROM") - ROMX_LOAD("cg-basic-rom-v1-pal-en.rom", 0x0000, 0x4000, CRC(844aaedd) SHA1(b7f984bc5cd979c7ad11ff909e8134f694aea7aa), ROM_BIOS(1) ) + ROMX_LOAD("cg-basic-rom-v1-pal-en.rom", 0x0000, 0x4000, CRC(844aaedd) SHA1(b7f984bc5cd979c7ad11ff909e8134f694aea7aa), ROM_BIOS(1)) ROM_SYSTEM_BIOS(1, "new", "New ROM") - ROMX_LOAD("cgromv2.rom", 0x0000, 0x4000, CRC(cfb84e09) SHA1(e199e4429bab6f9fca2bb05e71324538928a693a), ROM_BIOS(2) ) + ROMX_LOAD("cgromv2.rom", 0x0000, 0x4000, CRC(cfb84e09) SHA1(e199e4429bab6f9fca2bb05e71324538928a693a), ROM_BIOS(2)) - ROM_REGION(0x0c00, "gfx1", 0) + ROM_REGION(0x0800, "gfx1", 0) ROM_LOAD("cgenie1.fnt", 0x0000, 0x0800, CRC(4fed774a) SHA1(d53df8212b521892cc56be690db0bb474627d2ff)) - - /* Empty memory region for the character generator */ - ROM_REGION(0x0800, "gfx2", ROMREGION_ERASEFF) ROM_END -/* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME */ -COMP( 1982, cgenie, 0, 0, cgenie, cgenie, driver_device, 0, "EACA Computers Ltd", "Colour Genie EG2000" , 0) -COMP( 1982, cgenienz, cgenie, 0, cgenienz, cgenie, driver_device, 0, "EACA Computers Ltd", "Colour Genie EG2000 (New Zealand)" , 0) +//************************************************************************** +// SYSTEM DRIVERS +//************************************************************************** + +// YEAR NAME PARENT COMPAT MACHINE INPUT CLASS INIT COMPANY FULLNAME FLAGS +COMP( 1982, cgenie, 0, 0, cgenie, cgenie, cgenie_state, cgenie_eu, "EACA", "Colour Genie EG2000", 0) +COMP( 1982, cgenienz, cgenie, 0, cgenie, cgenie, cgenie_state, cgenie_nz, "EACA", "Colour Genie EG2000 (New Zealand)", 0) diff --git a/src/mess/includes/cgenie.h b/src/mess/includes/cgenie.h deleted file mode 100644 index 07c72e2b57e..00000000000 --- a/src/mess/includes/cgenie.h +++ /dev/null @@ -1,139 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Nathan Woods -/***************************************************************************** - * - * includes/cgenie.h - * - ****************************************************************************/ - -#ifndef CGENIE_H_ -#define CGENIE_H_ - -#include "imagedev/cassette.h" -#include "machine/ram.h" -#include "sound/ay8910.h" -#include "bus/cgenie/expansion.h" - -// CRTC 6845 -struct CRTC6845 -{ - UINT8 cursor_address_lo; - UINT8 cursor_address_hi; - UINT8 screen_address_lo; - UINT8 screen_address_hi; - UINT8 cursor_bottom; - UINT8 cursor_top; - UINT8 scan_lines; - UINT8 crt_mode; - UINT8 vertical_sync_pos; - UINT8 vertical_displayed; - UINT8 vertical_adjust; - UINT8 vertical_total; - UINT8 horizontal_length; - UINT8 horizontal_sync_pos; - UINT8 horizontal_displayed; - UINT8 horizontal_total; - UINT8 idx; - UINT8 cursor_visible; - UINT8 cursor_phase; -}; - - -class cgenie_state : public driver_device -{ -public: - cgenie_state(const machine_config &mconfig, device_type type, const char *tag) - : driver_device(mconfig, type, tag), - m_colorram(*this, "colorram"), - m_fontram(*this, "fontram"), - m_maincpu(*this, "maincpu"), - m_cassette(*this, "cassette"), - m_ram(*this, RAM_TAG), - m_ay8910(*this, "ay8910"), - m_gfxdecode(*this, "gfxdecode"), - m_palette(*this, "palette"), - m_screen(*this, "screen"), - m_exp(*this, "exp") - { - } - - required_shared_ptr m_colorram; - required_shared_ptr m_fontram; - - UINT8 *m_videoram; - int m_tv_mode; - int m_font_offset[4]; - int m_port_ff; - UINT8 m_irq_status; - UINT8 m_cass_level; - UINT8 m_cass_bit; - UINT8 m_psg_a_out; - UINT8 m_psg_b_out; - UINT8 m_psg_a_inp; - UINT8 m_psg_b_inp; - UINT8 m_control_port; - CRTC6845 m_crt; - int m_graphics; - bitmap_ind16 m_bitmap; - bitmap_ind16 m_dlybitmap; - int m_off_x; - int m_off_y; - virtual void machine_start(); - virtual void machine_reset(); - virtual void video_start(); - DECLARE_PALETTE_INIT(cgenie); - DECLARE_PALETTE_INIT(cgenienz); - UINT32 screen_update_cgenie(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - INTERRUPT_GEN_MEMBER(cgenie_timer_interrupt); - INTERRUPT_GEN_MEMBER(cgenie_frame_interrupt); - TIMER_CALLBACK_MEMBER(handle_cassette_input); - - DECLARE_WRITE_LINE_MEMBER(exp_intrq_w); - - DECLARE_READ8_MEMBER(cgenie_sh_control_port_r); - DECLARE_WRITE8_MEMBER(cgenie_sh_control_port_w); - required_device m_maincpu; - required_device m_cassette; - required_device m_ram; - required_device m_ay8910; - required_device m_gfxdecode; - required_device m_palette; - required_device m_screen; - required_device m_exp; - - void cgenie_offset_xy(); - int cgenie_get_register(int indx); - void cgenie_mode_select(int mode); - void cgenie_refresh_monitor(bitmap_ind16 &bitmap, const rectangle &cliprect); - void cgenie_refresh_tv_set(bitmap_ind16 &bitmap, const rectangle &cliprect); - int cgenie_port_xx_r( int offset ); - int cgenie_videoram_r( int offset ); - - DECLARE_READ8_MEMBER( cgenie_psg_port_a_r ); - DECLARE_READ8_MEMBER( cgenie_psg_port_b_r ); - DECLARE_WRITE8_MEMBER( cgenie_psg_port_a_w ); - DECLARE_WRITE8_MEMBER( cgenie_psg_port_b_w ); - - DECLARE_READ8_MEMBER( cgenie_colorram_r ); - DECLARE_READ8_MEMBER( cgenie_fontram_r ); - - DECLARE_WRITE8_MEMBER( cgenie_colorram_w ); - DECLARE_WRITE8_MEMBER( cgenie_fontram_w ); - - DECLARE_WRITE8_MEMBER( cgenie_port_ff_w ); - DECLARE_READ8_MEMBER( cgenie_port_ff_r ); - - DECLARE_READ8_MEMBER( cgenie_irq_status_r ); - - DECLARE_READ8_MEMBER( cgenie_keyboard_r ); - DECLARE_WRITE8_MEMBER( cgenie_videoram_w ); - - - DECLARE_READ8_MEMBER( cgenie_index_r ); - DECLARE_READ8_MEMBER( cgenie_register_r ); - - DECLARE_WRITE8_MEMBER( cgenie_index_w ); - DECLARE_WRITE8_MEMBER( cgenie_register_w ); -}; - -#endif /* CGENIE_H_ */ diff --git a/src/mess/machine/cgenie.c b/src/mess/machine/cgenie.c deleted file mode 100644 index a71d5cbec00..00000000000 --- a/src/mess/machine/cgenie.c +++ /dev/null @@ -1,432 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Nathan Woods -/*************************************************************************** - - machine.c - - Functions to emulate general aspects of the machine - (RAM, ROM, interrupts, I/O ports) - -***************************************************************************/ - -#include "emu.h" -#include "cpu/z80/z80.h" -#include "includes/cgenie.h" -#include "imagedev/cassette.h" -#include "sound/dac.h" -#include "machine/ram.h" - -#define AYWriteReg(chip,port,value) \ - m_ay8910->address_w(space, 0,port); \ - m_ay8910->data_w(space, 0,value) - -#define TAPE_HEADER "Colour Genie - Virtual Tape File" - - - - -#define IRQ_TIMER 0x80 -#define IRQ_FDC 0x40 - - - -TIMER_CALLBACK_MEMBER(cgenie_state::handle_cassette_input) -{ - UINT8 new_level = ( (m_cassette->input()) > 0.0 ) ? 1 : 0; - - if ( new_level != m_cass_level ) - { - m_cass_level = new_level; - m_cass_bit ^= 1; - } -} - - -void cgenie_state::machine_reset() -{ - address_space &space = m_maincpu->space(AS_PROGRAM); - UINT8 *ROM = memregion("maincpu")->base(); - - /* reset the AY8910 to be quiet, since the cgenie BIOS doesn't */ - AYWriteReg(0, 0, 0); - AYWriteReg(0, 1, 0); - AYWriteReg(0, 2, 0); - AYWriteReg(0, 3, 0); - AYWriteReg(0, 4, 0); - AYWriteReg(0, 5, 0); - AYWriteReg(0, 6, 0); - AYWriteReg(0, 7, 0x3f); - AYWriteReg(0, 8, 0); - AYWriteReg(0, 9, 0); - AYWriteReg(0, 10, 0); - - /* wipe out color RAM */ - memset(&ROM[0x0f000], 0x00, 0x0400); - - /* wipe out font RAM */ - memset(&ROM[0x0f400], 0xff, 0x0400); - - m_cass_level = 0; - m_cass_bit = 1; -} - -void cgenie_state::machine_start() -{ - address_space &space = m_maincpu->space(AS_PROGRAM); - UINT8 *gfx = memregion("gfx2")->base(); - int i; - - /* initialize static variables */ - m_irq_status = 0; - m_tv_mode = -1; - m_port_ff = 0xff; - - /* - * Every fifth cycle is a wait cycle, so I reduced - * the overlocking by one fitfth - * Underclocking causes the tape loading to not work. - */ -// cpunum_set_clockscale(machine(), 0, 0.80); - - /* Initialize some patterns to be displayed in graphics mode */ - for( i = 0; i < 256; i++ ) - memset(gfx + i * 8, i, 8); - - /* set up RAM */ - space.install_read_bank(0x4000, 0x4000 + m_ram->size() - 1, "bank1"); - space.install_write_handler(0x4000, 0x4000 + m_ram->size() - 1, write8_delegate(FUNC(cgenie_state::cgenie_videoram_w),this)); - m_videoram = m_ram->pointer(); - membank("bank1")->set_base(m_ram->pointer()); - machine().scheduler().timer_pulse(attotime::from_hz(11025), timer_expired_delegate(FUNC(cgenie_state::handle_cassette_input),this)); - - // setup expansion bus - m_exp->set_program_space(&m_maincpu->space(AS_PROGRAM)); - m_exp->set_io_space(&m_maincpu->space(AS_IO)); -} - -/************************************* - * - * Port handlers. - * - *************************************/ - -/* used bits on port FF */ -#define FF_CAS 0x01 /* tape output signal */ -#define FF_BGD0 0x04 /* background color enable */ -#define FF_CHR1 0x08 /* charset 0xc0 - 0xff 1:fixed 0:defined */ -#define FF_CHR0 0x10 /* charset 0x80 - 0xbf 1:fixed 0:defined */ -#define FF_CHR (FF_CHR0 | FF_CHR1) -#define FF_FGR 0x20 /* 1: "hi" resolution graphics, 0: text mode */ -#define FF_BGD1 0x40 /* background color select 1 */ -#define FF_BGD2 0x80 /* background color select 2 */ -#define FF_BGD (FF_BGD0 | FF_BGD1 | FF_BGD2) - -WRITE8_MEMBER( cgenie_state::cgenie_port_ff_w ) -{ - int port_ff_changed = m_port_ff ^ data; - - m_cassette->output(data & 0x01 ? -1.0 : 1.0 ); - - /* background bits changed ? */ - if( port_ff_changed & FF_BGD ) - { - unsigned char r, g, b; - - if( data & FF_BGD0 ) - { - r = 112; - g = 0; - b = 112; - } - else - { - if( m_tv_mode == 0 ) - { - switch( data & (FF_BGD1 + FF_BGD2) ) - { - case FF_BGD1: - r = 112; - g = 40; - b = 32; - break; - case FF_BGD2: - r = 40; - g = 112; - b = 32; - break; - case FF_BGD1 + FF_BGD2: - r = 72; - g = 72; - b = 72; - break; - default: - r = 0; - g = 0; - b = 0; - break; - } - } - else - { - r = 15; - g = 15; - b = 15; - } - } - m_palette->set_pen_color(0, r, g, b); - } - - /* character mode changed ? */ - if( port_ff_changed & FF_CHR ) - { - m_font_offset[2] = (data & FF_CHR0) ? 0x00 : 0x80; - m_font_offset[3] = (data & FF_CHR1) ? 0x00 : 0x80; - } - - /* graphics mode changed ? */ - if( port_ff_changed & FF_FGR ) - { - cgenie_mode_select(data & FF_FGR); - } - - m_port_ff = data; -} - - -READ8_MEMBER( cgenie_state::cgenie_port_ff_r ) -{ - UINT8 data = m_port_ff & ~0x01; - - data |= m_cass_bit; - - return data; -} - -int cgenie_state::cgenie_port_xx_r( int offset ) -{ - return 0xff; -} - -/************************************* - * * - * Memory handlers * - * * - *************************************/ - - -READ8_MEMBER( cgenie_state::cgenie_psg_port_a_r ) -{ - return m_psg_a_inp; -} - -READ8_MEMBER( cgenie_state::cgenie_psg_port_b_r ) -{ - if( m_psg_a_out < 0xd0 ) - { - /* comparator value */ - m_psg_b_inp = 0x00; - - if( ioport("JOY0")->read() > m_psg_a_out ) - m_psg_b_inp |= 0x80; - - if( ioport("JOY1")->read() > m_psg_a_out ) - m_psg_b_inp |= 0x40; - - if( ioport("JOY2")->read() > m_psg_a_out ) - m_psg_b_inp |= 0x20; - - if( ioport("JOY3")->read() > m_psg_a_out ) - m_psg_b_inp |= 0x10; - } - else - { - /* read keypad matrix */ - m_psg_b_inp = 0xFF; - - if( !(m_psg_a_out & 0x01) ) - m_psg_b_inp &= ~ioport("KP0")->read(); - - if( !(m_psg_a_out & 0x02) ) - m_psg_b_inp &= ~ioport("KP1")->read(); - - if( !(m_psg_a_out & 0x04) ) - m_psg_b_inp &= ~ioport("KP2")->read(); - - if( !(m_psg_a_out & 0x08) ) - m_psg_b_inp &= ~ioport("KP3")->read(); - - if( !(m_psg_a_out & 0x10) ) - m_psg_b_inp &= ~ioport("KP4")->read(); - - if( !(m_psg_a_out & 0x20) ) - m_psg_b_inp &= ~ioport("KP5")->read(); - } - return m_psg_b_inp; -} - -WRITE8_MEMBER( cgenie_state::cgenie_psg_port_a_w ) -{ - m_psg_a_out = data; -} - -WRITE8_MEMBER( cgenie_state::cgenie_psg_port_b_w ) -{ - m_psg_b_out = data; -} - -READ8_MEMBER( cgenie_state::cgenie_irq_status_r ) -{ - int result = m_irq_status; - - m_irq_status &= ~(IRQ_TIMER); - return result; -} - -INTERRUPT_GEN_MEMBER(cgenie_state::cgenie_timer_interrupt) -{ - if( (m_irq_status & IRQ_TIMER) == 0 ) - { - m_irq_status |= IRQ_TIMER; - m_maincpu->set_input_line(0, HOLD_LINE); - } -} - -WRITE_LINE_MEMBER( cgenie_state::exp_intrq_w ) -{ - m_irq_status &= ~IRQ_FDC; - m_irq_status |= state << 6; - - if (m_irq_status) - m_maincpu->set_input_line(INPUT_LINE_IRQ0, ASSERT_LINE); - else - m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE); -} - - -/************************************* - * Keyboard * - *************************************/ -READ8_MEMBER( cgenie_state::cgenie_keyboard_r ) -{ - int result = 0; - - if( offset & 0x01 ) - result |= ioport("ROW0")->read(); - - if( offset & 0x02 ) - result |= ioport("ROW1")->read(); - - if( offset & 0x04 ) - result |= ioport("ROW2")->read(); - - if( offset & 0x08 ) - result |= ioport("ROW3")->read(); - - if( offset & 0x10 ) - result |= ioport("ROW4")->read(); - - if( offset & 0x20 ) - result |= ioport("ROW5")->read(); - - if( offset & 0x40 ) - result |= ioport("ROW6")->read(); - - if( offset & 0x80 ) - result |= ioport("ROW7")->read(); - - return result; -} - -/************************************* - * Video RAM * - *************************************/ - -int cgenie_state::cgenie_videoram_r( int offset ) -{ - UINT8 *videoram = m_videoram; - return videoram[offset]; -} - -WRITE8_MEMBER( cgenie_state::cgenie_videoram_w ) -{ - UINT8 *videoram = m_videoram; - /* write to video RAM */ - if( data == videoram[offset] ) - return; /* no change */ - videoram[offset] = data; -} - -READ8_MEMBER( cgenie_state::cgenie_colorram_r ) -{ - return m_colorram[offset] | 0xf0; -} - -WRITE8_MEMBER( cgenie_state::cgenie_colorram_w ) -{ - /* only bits 0 to 3 */ - data &= 15; - /* nothing changed ? */ - if( data == m_colorram[offset] ) - return; - - /* set new value */ - m_colorram[offset] = data; - /* make offset relative to video frame buffer offset */ - offset = (offset + (cgenie_get_register(12) << 8) + cgenie_get_register(13)) & 0x3ff; -} - -READ8_MEMBER( cgenie_state::cgenie_fontram_r ) -{ - return m_fontram[offset]; -} - -WRITE8_MEMBER( cgenie_state::cgenie_fontram_w ) -{ - UINT8 *dp; - - if( data == m_fontram[offset] ) - return; /* no change */ - - /* store data */ - m_fontram[offset] = data; - - /* convert eight pixels */ - dp = const_cast(m_gfxdecode->gfx(0)->get_data(256 + offset/8) + (offset % 8) * m_gfxdecode->gfx(0)->width()); - dp[0] = (data & 0x80) ? 1 : 0; - dp[1] = (data & 0x40) ? 1 : 0; - dp[2] = (data & 0x20) ? 1 : 0; - dp[3] = (data & 0x10) ? 1 : 0; - dp[4] = (data & 0x08) ? 1 : 0; - dp[5] = (data & 0x04) ? 1 : 0; - dp[6] = (data & 0x02) ? 1 : 0; - dp[7] = (data & 0x01) ? 1 : 0; -} - -/************************************* - * - * Interrupt handlers. - * - *************************************/ - -INTERRUPT_GEN_MEMBER(cgenie_state::cgenie_frame_interrupt) -{ - if( m_tv_mode != (ioport("DSW0")->read() & 0x10) ) - { - m_tv_mode = ioport("DSW0")->read() & 0x10; - /* force setting of background color */ - m_port_ff ^= FF_BGD0; - cgenie_port_ff_w(m_maincpu->space(AS_PROGRAM), 0, m_port_ff ^ FF_BGD0); - } -} - - -READ8_MEMBER(cgenie_state::cgenie_sh_control_port_r) -{ - return m_control_port; -} - -WRITE8_MEMBER(cgenie_state::cgenie_sh_control_port_w) -{ - m_control_port = data; - m_ay8910->address_w(space, offset, data); -} diff --git a/src/mess/video/cgenie.c b/src/mess/video/cgenie.c deleted file mode 100644 index 2919f97e9a9..00000000000 --- a/src/mess/video/cgenie.c +++ /dev/null @@ -1,412 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Nathan Woods -/*************************************************************************** - - cgenie.c - - Functions to emulate the video controller 6845. - -***************************************************************************/ - -#include "emu.h" -#include "includes/cgenie.h" - - - - - -/*************************************************************************** - - Start the video hardware emulation. - -***************************************************************************/ -void cgenie_state::video_start() -{ - m_screen->register_screen_bitmap(m_dlybitmap); - m_screen->register_screen_bitmap(m_bitmap); -} - -/*************************************************************************** - - Calculate the horizontal and vertical offset for the - current register settings of the 6845 CRTC - -***************************************************************************/ -void cgenie_state::cgenie_offset_xy() -{ - if( m_crt.horizontal_sync_pos ) - m_off_x = m_crt.horizontal_total - m_crt.horizontal_sync_pos - 14; - else - m_off_x = -15; - - m_off_y = (m_crt.vertical_total - m_crt.vertical_sync_pos) * - (m_crt.scan_lines + 1) + m_crt.vertical_adjust - - 32; - - if( m_off_y < 0 ) - m_off_y = 0; - - if( m_off_y > 128 ) - m_off_y = 128; - -// logerror("cgenie offset x:%d y:%d\n", m_off_x, m_off_y); -} - - -/*************************************************************************** - Write to an indexed register of the 6845 CRTC -***************************************************************************/ -WRITE8_MEMBER( cgenie_state::cgenie_register_w ) -{ - //int addr; - - switch (m_crt.idx) - { - case 0: - if( m_crt.horizontal_total == data ) - break; - m_crt.horizontal_total = data; - cgenie_offset_xy(); - break; - case 1: - if( m_crt.horizontal_displayed == data ) - break; - m_crt.horizontal_displayed = data; - break; - case 2: - if( m_crt.horizontal_sync_pos == data ) - break; - m_crt.horizontal_sync_pos = data; - cgenie_offset_xy(); - break; - case 3: - m_crt.horizontal_length = data; - break; - case 4: - if( m_crt.vertical_total == data ) - break; - m_crt.vertical_total = data; - cgenie_offset_xy(); - break; - case 5: - if( m_crt.vertical_adjust == data ) - break; - m_crt.vertical_adjust = data; - cgenie_offset_xy(); - break; - case 6: - if( m_crt.vertical_displayed == data ) - break; - m_crt.vertical_displayed = data; - break; - case 7: - if( m_crt.vertical_sync_pos == data ) - break; - m_crt.vertical_sync_pos = data; - cgenie_offset_xy(); - break; - case 8: - m_crt.crt_mode = data; - break; - case 9: - data &= 15; - if( m_crt.scan_lines == data ) - break; - m_crt.scan_lines = data; - cgenie_offset_xy(); - break; - case 10: - if( m_crt.cursor_top == data ) - break; - m_crt.cursor_top = data; - //addr = 256 * m_crt.cursor_address_hi + m_crt.cursor_address_lo; - break; - case 11: - if( m_crt.cursor_bottom == data ) - break; - m_crt.cursor_bottom = data; - //addr = 256 * m_crt.cursor_address_hi + m_crt.cursor_address_lo; - break; - case 12: - data &= 63; - if( m_crt.screen_address_hi == data ) - break; - m_crt.screen_address_hi = data; - break; - case 13: - if( m_crt.screen_address_lo == data ) - break; - m_crt.screen_address_lo = data; - break; - case 14: - data &= 63; - if( m_crt.cursor_address_hi == data ) - break; - m_crt.cursor_address_hi = data; - //addr = 256 * m_crt.cursor_address_hi + m_crt.cursor_address_lo; - break; - case 15: - if( m_crt.cursor_address_lo == data ) - break; - m_crt.cursor_address_lo = data; - //addr = 256 * m_crt.cursor_address_hi + m_crt.cursor_address_lo; - break; - } -} - -/*************************************************************************** - Write to the index register of the 6845 CRTC -***************************************************************************/ -WRITE8_MEMBER( cgenie_state::cgenie_index_w ) -{ - m_crt.idx = data & 15; -} - -/*************************************************************************** - Read from an indexed register of the 6845 CRTC -***************************************************************************/ -READ8_MEMBER( cgenie_state::cgenie_register_r ) -{ - return cgenie_get_register(m_crt.idx); -} - -/*************************************************************************** - Read from a register of the 6845 CRTC -***************************************************************************/ -int cgenie_state::cgenie_get_register(int indx) -{ - switch (indx) - { - case 0: - return m_crt.horizontal_total; - case 1: - return m_crt.horizontal_displayed; - case 2: - return m_crt.horizontal_sync_pos; - case 3: - return m_crt.horizontal_length; - case 4: - return m_crt.vertical_total; - case 5: - return m_crt.vertical_adjust; - case 6: - return m_crt.vertical_displayed; - case 7: - return m_crt.vertical_sync_pos; - case 8: - return m_crt.crt_mode; - case 9: - return m_crt.scan_lines; - case 10: - return m_crt.cursor_top; - case 11: - return m_crt.cursor_bottom; - case 12: - return m_crt.screen_address_hi; - case 13: - return m_crt.screen_address_lo; - case 14: - return m_crt.cursor_address_hi; - case 15: - return m_crt.cursor_address_lo; - } - return 0; -} - -/*************************************************************************** - Read the index register of the 6845 CRTC -***************************************************************************/ -READ8_MEMBER( cgenie_state::cgenie_index_r ) -{ - return m_crt.idx; -} - -/*************************************************************************** - Switch mode between character generator and graphics -***************************************************************************/ -void cgenie_state::cgenie_mode_select(int mode) -{ - m_graphics = (mode) ? 1 : 0; -} - - -void cgenie_state::cgenie_refresh_monitor(bitmap_ind16 &bitmap, const rectangle &cliprect) -{ - UINT8 *videoram = m_videoram; - int i, address, offset, cursor, size, code, x, y; - rectangle r; - - bitmap.fill(m_palette->black_pen(), cliprect); - - if(m_crt.vertical_displayed || m_crt.horizontal_displayed) - { - offset = 256 * m_crt.screen_address_hi + m_crt.screen_address_lo; - size = m_crt.horizontal_displayed * m_crt.vertical_displayed; - cursor = 256 * m_crt.cursor_address_hi + m_crt.cursor_address_lo; - - /* - * for every character in the Video RAM, check if it has been modified since - * last time and update it accordingly. - */ - for( address = 0; address < size; address++ ) - { - i = (offset + address) & 0x3fff; - x = address % m_crt.horizontal_displayed + m_off_x; - y = address / m_crt.horizontal_displayed; - - r.min_x = x * 8; - r.max_x = r.min_x + 7; - r.min_y = y * (m_crt.scan_lines + 1) + m_off_y; - r.max_y = r.min_y + m_crt.scan_lines; - - if( m_graphics ) - { - /* get graphics code */ - code = videoram[i]; - m_gfxdecode->gfx(1)->opaque(bitmap,r, code, 0, - 0, 0, r.min_x, r.min_y); - } - else - { - /* get character code */ - code = videoram[i]; - - /* translate defined character sets */ - code += m_font_offset[(code >> 6) & 3]; - m_gfxdecode->gfx(0)->opaque(bitmap,r, code, m_colorram[i&0x3ff], - 0, 0, r.min_x, r.min_y); - } - - if( i == cursor ) - { - rectangle rc; - - /* check if cursor turned off */ - if( (m_crt.cursor_top & 0x60) == 0x20 ) - continue; - - if( (m_crt.cursor_top & 0x60) == 0x60 ) - { - m_crt.cursor_visible = 1; - } - else - { - m_crt.cursor_phase++; - m_crt.cursor_visible = (m_crt.cursor_phase >> 3) & 1; - } - - if( !m_crt.cursor_visible ) - continue; - - rc.min_x = r.min_x; - rc.max_x = r.max_x; - rc.min_y = r.min_y + (m_crt.cursor_top & 15); - rc.max_y = r.min_y + (m_crt.cursor_bottom & 15); - m_gfxdecode->gfx(0)->opaque(bitmap,rc, 0x7f, m_colorram[i&0x3ff], - 0, 0, rc.min_x, rc.min_y); - } - } - } -} - -void cgenie_state::cgenie_refresh_tv_set(bitmap_ind16 &bitmap, const rectangle &cliprect) -{ - UINT8 *videoram = m_videoram; - int i, address, offset, cursor, size, code, x, y; - rectangle r; - - m_bitmap.fill(m_palette->black_pen(), cliprect); - m_dlybitmap.fill(m_palette->black_pen(), cliprect); - - if(m_crt.vertical_displayed || m_crt.horizontal_displayed) - { - offset = 256 * m_crt.screen_address_hi + m_crt.screen_address_lo; - size = m_crt.horizontal_displayed * m_crt.vertical_displayed; - cursor = 256 * m_crt.cursor_address_hi + m_crt.cursor_address_lo; - - /* - * for every character in the Video RAM, check if it has been modified since - * last time and update it accordingly. - */ - for( address = 0; address < size; address++ ) - { - i = (offset + address) & 0x3fff; - x = address % m_crt.horizontal_displayed + m_off_x; - y = address / m_crt.horizontal_displayed; - - r.min_x = x * 8; - r.max_x = r.min_x + 7; - r.min_y = y * (m_crt.scan_lines + 1) + m_off_y; - r.max_y = r.min_y + m_crt.scan_lines; - - if( m_graphics ) - { - /* get graphics code */ - code = videoram[i]; - m_gfxdecode->gfx(1)->opaque(m_bitmap,r, code, 1, - 0, 0, r.min_x, r.min_y); - m_gfxdecode->gfx(1)->opaque(m_dlybitmap,r, code, 2, - 0, 0, r.min_x, r.min_y); - } - else - { - /* get character code */ - code = videoram[i]; - - /* translate defined character sets */ - code += m_font_offset[(code >> 6) & 3]; - m_gfxdecode->gfx(0)->opaque(m_bitmap,r, code, m_colorram[i&0x3ff] + 16, - 0, 0, r.min_x, r.min_y); - m_gfxdecode->gfx(0)->opaque(m_dlybitmap,r, code, m_colorram[i&0x3ff] + 32, - 0, 0, r.min_x, r.min_y); - } - - if( i == cursor ) - { - rectangle rc; - - /* check if cursor turned off */ - if( (m_crt.cursor_top & 0x60) == 0x20 ) - continue; - - if( (m_crt.cursor_top & 0x60) == 0x60 ) - { - m_crt.cursor_visible = 1; - } - else - { - m_crt.cursor_phase++; - m_crt.cursor_visible = (m_crt.cursor_phase >> 3) & 1; - } - - if( !m_crt.cursor_visible ) - continue; - - rc.min_x = r.min_x; - rc.max_x = r.max_x; - rc.min_y = r.min_y + (m_crt.cursor_top & 15); - rc.max_y = r.min_y + (m_crt.cursor_bottom & 15); - - m_gfxdecode->gfx(0)->opaque(m_bitmap,rc, 0x7f, m_colorram[i&0x3ff] + 16, - 0, 0, rc.min_x, rc.min_y); - m_gfxdecode->gfx(0)->opaque(m_dlybitmap,rc, 0x7f, m_colorram[i&0x3ff] + 32, - 0, 0, rc.min_x, rc.min_y); - } - } - } - - copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect); - copybitmap_trans(bitmap, m_dlybitmap, 0, 0, 1, 0, cliprect, 0); -} - -/*************************************************************************** - Draw the game screen in the given bitmap_ind16. -***************************************************************************/ -UINT32 cgenie_state::screen_update_cgenie(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) -{ - if( m_tv_mode ) - cgenie_refresh_tv_set(bitmap, cliprect); - else - cgenie_refresh_monitor(bitmap, cliprect); - return 0; -} -- cgit v1.2.3 From d68fe923a1974cc82ab3b12dc1f70b509bf06a95 Mon Sep 17 00:00:00 2001 From: couriersud Date: Mon, 25 May 2015 18:28:03 +0200 Subject: Added a simple preprocessor to the netlist parsing pipeline. This preprpcessor understands defines and nested if/else/endif #define MYMACRO 0 #if (MYMACRO) .... #else #endif One can now run ./nltool -c run -f src/mame/drivers/nl_pong.c -t 10 without removing preprocessor elements first. This does not work with netlist originating from DICE currently. These have to be converted first. In addition, cleaned up __attribute__ madness in the code. Specifically removed ATTR_COLD from virtual definitions to avoid the vtable being declared as cold. --- scripts/src/netlist.lua | 6 +- src/emu/netlist/analog/nld_bjt.h | 12 +- src/emu/netlist/analog/nld_fourterm.h | 18 +- src/emu/netlist/analog/nld_ms_direct.h | 6 +- src/emu/netlist/analog/nld_ms_jakobi.h | 2 +- src/emu/netlist/analog/nld_ms_sor.h | 2 +- src/emu/netlist/analog/nld_ms_sor_mat.h | 2 +- src/emu/netlist/analog/nld_solver.h | 14 +- src/emu/netlist/analog/nld_twoterm.h | 18 +- src/emu/netlist/devices/nld_system.h | 26 +-- src/emu/netlist/devices/nld_truthtable.h | 2 +- src/emu/netlist/nl_base.h | 64 +++--- src/emu/netlist/nl_factory.h | 8 +- src/emu/netlist/nl_parser.c | 198 +---------------- src/emu/netlist/nl_parser.h | 128 +---------- src/emu/netlist/nl_util.h | 38 ++++ src/emu/netlist/pconfig.h | 4 +- src/emu/netlist/plists.h | 6 +- src/emu/netlist/pparser.c | 354 +++++++++++++++++++++++++++++++ src/emu/netlist/pparser.h | 181 ++++++++++++++++ src/mame/drivers/nl_pong.c | 14 +- 21 files changed, 684 insertions(+), 419 deletions(-) create mode 100644 src/emu/netlist/pparser.c create mode 100644 src/emu/netlist/pparser.h (limited to 'scripts/src') diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 96d81688fc3..d1f9c97a74b 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -18,11 +18,13 @@ files { MAME_DIR .. "src/emu/netlist/pconfig.h", MAME_DIR .. "src/emu/netlist/palloc.c", MAME_DIR .. "src/emu/netlist/palloc.h", - MAME_DIR .. "src/emu/netlist/pstring.c", - MAME_DIR .. "src/emu/netlist/pstring.h", MAME_DIR .. "src/emu/netlist/plists.h", + MAME_DIR .. "src/emu/netlist/pparser.c", + MAME_DIR .. "src/emu/netlist/pparser.h", MAME_DIR .. "src/emu/netlist/pstate.c", MAME_DIR .. "src/emu/netlist/pstate.h", + MAME_DIR .. "src/emu/netlist/pstring.c", + MAME_DIR .. "src/emu/netlist/pstring.h", MAME_DIR .. "src/emu/netlist/analog/nld_bjt.c", MAME_DIR .. "src/emu/netlist/analog/nld_bjt.h", MAME_DIR .. "src/emu/netlist/analog/nld_fourterm.c", diff --git a/src/emu/netlist/analog/nld_bjt.h b/src/emu/netlist/analog/nld_bjt.h index 68b1576b030..eca05c423c7 100644 --- a/src/emu/netlist/analog/nld_bjt.h +++ b/src/emu/netlist/analog/nld_bjt.h @@ -46,8 +46,8 @@ public: inline bool is_qtype(q_type atype) const { return m_qtype == atype; } inline void set_qtype(q_type atype) { m_qtype = atype; } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); ATTR_HOT void update(); netlist_param_model_t m_model; @@ -110,9 +110,9 @@ public: protected: - ATTR_COLD virtual void start(); + /* ATTR_COLD */ virtual void start(); ATTR_HOT virtual void update_param(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void reset(); NETLIB_UPDATE_TERMINALSI(); nl_double m_gB; // base conductance / switch on @@ -142,8 +142,8 @@ public: protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); ATTR_HOT void update_param(); ATTR_HOT void virtual update(); NETLIB_UPDATE_TERMINALSI(); diff --git a/src/emu/netlist/analog/nld_fourterm.h b/src/emu/netlist/analog/nld_fourterm.h index a829b9c814e..13584babef5 100644 --- a/src/emu/netlist/analog/nld_fourterm.h +++ b/src/emu/netlist/analog/nld_fourterm.h @@ -56,9 +56,9 @@ public: : netlist_device_t(afamily), m_gfac(1.0) { } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); - ATTR_COLD virtual void update_param(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); + /* ATTR_COLD */ virtual void update_param(); ATTR_HOT void update(); ATTR_COLD void start_internal(const nl_double def_RI); @@ -112,9 +112,9 @@ public: //: netlist_device_t(afamily), m_gfac(1.0) { } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); - ATTR_COLD virtual void update_param(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); + /* ATTR_COLD */ virtual void update_param(); ATTR_HOT void update(); nl_double m_gfac; @@ -156,9 +156,9 @@ public: : NETLIB_NAME(VCCS)(VCVS) { } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); - ATTR_COLD virtual void update_param(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); + /* ATTR_COLD */ virtual void update_param(); //ATTR_HOT void update(); netlist_terminal_t m_OP2; diff --git a/src/emu/netlist/analog/nld_ms_direct.h b/src/emu/netlist/analog/nld_ms_direct.h index 58dbdf6c613..cef321de60e 100644 --- a/src/emu/netlist/analog/nld_ms_direct.h +++ b/src/emu/netlist/analog/nld_ms_direct.h @@ -20,15 +20,15 @@ public: virtual ~netlist_matrix_solver_direct_t(); - ATTR_COLD virtual void vsetup(netlist_analog_net_t::list_t &nets); - ATTR_COLD virtual void reset() { netlist_matrix_solver_t::reset(); } + /* ATTR_COLD */ virtual void vsetup(netlist_analog_net_t::list_t &nets); + /* ATTR_COLD */ virtual void reset() { netlist_matrix_solver_t::reset(); } ATTR_HOT inline int N() const { return (m_N == 0 ? m_dim : m_N); } ATTR_HOT inline int vsolve_non_dynamic(const bool newton_raphson); protected: - ATTR_COLD virtual void add_term(int net_idx, netlist_terminal_t *term); + /* ATTR_COLD */ virtual void add_term(int net_idx, netlist_terminal_t *term); ATTR_HOT virtual nl_double vsolve(); diff --git a/src/emu/netlist/analog/nld_ms_jakobi.h b/src/emu/netlist/analog/nld_ms_jakobi.h index e83cfff3975..9376e54c9ef 100644 --- a/src/emu/netlist/analog/nld_ms_jakobi.h +++ b/src/emu/netlist/analog/nld_ms_jakobi.h @@ -31,7 +31,7 @@ public: virtual ~netlist_matrix_solver_SOR_t() {} - ATTR_COLD virtual void log_stats(); + /* ATTR_COLD */ virtual void log_stats(); ATTR_HOT inline int vsolve_non_dynamic(); protected: diff --git a/src/emu/netlist/analog/nld_ms_sor.h b/src/emu/netlist/analog/nld_ms_sor.h index 6d9bf5f8cc2..11ee4273d62 100644 --- a/src/emu/netlist/analog/nld_ms_sor.h +++ b/src/emu/netlist/analog/nld_ms_sor.h @@ -30,7 +30,7 @@ public: virtual ~netlist_matrix_solver_SOR_t() {} - ATTR_COLD virtual void log_stats(); + /* ATTR_COLD */ virtual void log_stats(); ATTR_HOT virtual int vsolve_non_dynamic(const bool newton_raphson); protected: diff --git a/src/emu/netlist/analog/nld_ms_sor_mat.h b/src/emu/netlist/analog/nld_ms_sor_mat.h index c49a15e3d8e..e9d7776c9ab 100644 --- a/src/emu/netlist/analog/nld_ms_sor_mat.h +++ b/src/emu/netlist/analog/nld_ms_sor_mat.h @@ -36,7 +36,7 @@ public: virtual ~netlist_matrix_solver_SOR_mat_t() {} - ATTR_COLD virtual void log_stats(); + /* ATTR_COLD */ virtual void log_stats(); ATTR_HOT inline int vsolve_non_dynamic(const bool newton_raphson); protected: diff --git a/src/emu/netlist/analog/nld_solver.h b/src/emu/netlist/analog/nld_solver.h index bc0a9f095aa..e08f0f7fd29 100644 --- a/src/emu/netlist/analog/nld_solver.h +++ b/src/emu/netlist/analog/nld_solver.h @@ -97,9 +97,9 @@ public: }; ATTR_COLD netlist_matrix_solver_t(const eSolverType type, const netlist_solver_parameters_t ¶ms); - ATTR_COLD virtual ~netlist_matrix_solver_t(); + /* ATTR_COLD */ virtual ~netlist_matrix_solver_t(); - ATTR_COLD virtual void vsetup(netlist_analog_net_t::list_t &nets) = 0; + /* ATTR_COLD */ virtual void vsetup(netlist_analog_net_t::list_t &nets) = 0; template void solve_base(C *p); @@ -117,11 +117,11 @@ public: /* netdevice functions */ ATTR_HOT virtual void update(); - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); ATTR_COLD int get_net_idx(netlist_net_t *net); - ATTR_COLD virtual void log_stats() {}; + /* ATTR_COLD */ virtual void log_stats() {}; inline eSolverType type() const { return m_type; } @@ -133,7 +133,7 @@ protected: // should return next time step ATTR_HOT virtual nl_double vsolve() = 0; - ATTR_COLD virtual void add_term(int net_idx, netlist_terminal_t *term) = 0; + /* ATTR_COLD */ virtual void add_term(int net_idx, netlist_terminal_t *term) = 0; plist_t m_nets; plist_t m_inps; @@ -170,7 +170,7 @@ public: NETLIB_NAME(solver)() : netlist_device_t() { } - ATTR_COLD virtual ~NETLIB_NAME(solver)(); + /* ATTR_COLD */ virtual ~NETLIB_NAME(solver)(); ATTR_COLD void post_start(); ATTR_COLD void stop(); diff --git a/src/emu/netlist/analog/nld_twoterm.h b/src/emu/netlist/analog/nld_twoterm.h index 976742793dd..fed3b148db5 100644 --- a/src/emu/netlist/analog/nld_twoterm.h +++ b/src/emu/netlist/analog/nld_twoterm.h @@ -122,8 +122,8 @@ public: } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); ATTR_HOT void update(); private: @@ -144,8 +144,8 @@ public: } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); ATTR_HOT void update(); }; @@ -193,9 +193,9 @@ public: } protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void reset(); - ATTR_COLD virtual void update_param(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void reset(); + /* ATTR_COLD */ virtual void update_param(); ATTR_HOT void update(); netlist_param_double_t m_C; @@ -282,8 +282,8 @@ public: NETLIB_UPDATE_TERMINALSI(); protected: - ATTR_COLD virtual void start(); - ATTR_COLD virtual void update_param(); + /* ATTR_COLD */ virtual void start(); + /* ATTR_COLD */ virtual void update_param(); ATTR_HOT void update(); netlist_param_model_t m_model; diff --git a/src/emu/netlist/devices/nld_system.h b/src/emu/netlist/devices/nld_system.h index 936b1013792..e08787a3a35 100644 --- a/src/emu/netlist/devices/nld_system.h +++ b/src/emu/netlist/devices/nld_system.h @@ -138,7 +138,7 @@ public: ATTR_COLD NETLIB_NAME(gnd)() : netlist_device_t(GND) { } - ATTR_COLD virtual ~NETLIB_NAME(gnd)() {} + /* ATTR_COLD */ virtual ~NETLIB_NAME(gnd)() {} protected: @@ -171,7 +171,7 @@ public: ATTR_COLD NETLIB_NAME(dummy_input)() : netlist_device_t(DUMMY) { } - ATTR_COLD virtual ~NETLIB_NAME(dummy_input)() {} + /* ATTR_COLD */ virtual ~NETLIB_NAME(dummy_input)() {} protected: @@ -203,7 +203,7 @@ public: ATTR_COLD NETLIB_NAME(frontier)() : netlist_device_t(DUMMY) { } - ATTR_COLD virtual ~NETLIB_NAME(frontier)() {} + /* ATTR_COLD */ virtual ~NETLIB_NAME(frontier)() {} protected: @@ -238,7 +238,7 @@ public: ATTR_COLD NETLIB_NAME(res_sw)() : netlist_device_t() { } - ATTR_COLD virtual ~NETLIB_NAME(res_sw)() {} + /* ATTR_COLD */ virtual ~NETLIB_NAME(res_sw)() {} netlist_param_double_t m_RON; netlist_param_double_t m_ROFF; @@ -271,14 +271,14 @@ public: m_proxy_term = &proxy_inout; } - ATTR_COLD virtual ~nld_base_proxy() {} + /* ATTR_COLD */ virtual ~nld_base_proxy() {} ATTR_COLD netlist_logic_t &term_proxied() const { return *m_term_proxied; } ATTR_COLD netlist_core_terminal_t &proxy_term() const { return *m_proxy_term; } protected: - ATTR_COLD virtual const netlist_logic_family_desc_t &logic_family() const + /* ATTR_COLD */ virtual const netlist_logic_family_desc_t &logic_family() const { return *m_logic_family; } @@ -301,7 +301,7 @@ public: { } - ATTR_COLD virtual ~nld_a_to_d_proxy() {} + /* ATTR_COLD */ virtual ~nld_a_to_d_proxy() {} netlist_analog_input_t m_I; netlist_logic_output_t m_Q; @@ -343,12 +343,12 @@ public: { } - ATTR_COLD virtual ~nld_base_d_to_a_proxy() {} + /* ATTR_COLD */ virtual ~nld_base_d_to_a_proxy() {} - ATTR_COLD virtual netlist_logic_input_t &in() { return m_I; } + /* ATTR_COLD */ virtual netlist_logic_input_t &in() { return m_I; } protected: - ATTR_COLD virtual void start() + /* ATTR_COLD */ virtual void start() { register_input("I", m_I); } @@ -369,12 +369,12 @@ public: { } - ATTR_COLD virtual ~nld_d_to_a_proxy() {} + /* ATTR_COLD */ virtual ~nld_d_to_a_proxy() {} protected: - ATTR_COLD virtual void start(); + /* ATTR_COLD */ virtual void start(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void reset(); ATTR_HOT void update(); diff --git a/src/emu/netlist/devices/nld_truthtable.h b/src/emu/netlist/devices/nld_truthtable.h index 2ba5082b086..6db3c577b08 100644 --- a/src/emu/netlist/devices/nld_truthtable.h +++ b/src/emu/netlist/devices/nld_truthtable.h @@ -93,7 +93,7 @@ public: { } - ATTR_COLD virtual void start() + /* ATTR_COLD */ virtual void start() { pstring ttline = pstring(m_desc[0]); diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h index 1eef0b71181..3b2290e0e3e 100644 --- a/src/emu/netlist/nl_base.h +++ b/src/emu/netlist/nl_base.h @@ -251,7 +251,7 @@ typedef void (*net_update_delegate)(netlist_core_device_t *); , _priv) #define NETLIB_LOGIC_FAMILY(_fam) \ -ATTR_COLD virtual const netlist_logic_family_desc_t *default_logic_family() \ +/* ATTR_COLD */ virtual const netlist_logic_family_desc_t *default_logic_family() \ { \ return &netlist_family_ ## _fam; \ } @@ -412,9 +412,9 @@ public: protected: - ATTR_COLD virtual void reset() = 0; + /* ATTR_COLD */ virtual void reset() = 0; // must call parent save_register ! - ATTR_COLD virtual void save_register() { }; + /* ATTR_COLD */ virtual void save_register() { }; private: pstring m_name; @@ -486,7 +486,7 @@ public: ATTR_HOT inline void update_dev(const UINT32 mask); protected: - ATTR_COLD virtual void save_register() + /* ATTR_COLD */ virtual void save_register() { save(NLNAME(m_state)); netlist_owned_object_t::save_register(); @@ -540,9 +540,9 @@ public: netlist_terminal_t *m_otherterm; protected: - ATTR_COLD virtual void save_register(); + /* ATTR_COLD */ virtual void save_register(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void reset(); private: ATTR_HOT inline void set_ptr(nl_double *ptr, const nl_double val) { @@ -616,7 +616,7 @@ public: ATTR_HOT inline void activate_lh(); protected: - ATTR_COLD virtual void reset() + /* ATTR_COLD */ virtual void reset() { //netlist_core_terminal_t::reset(); set_state(STATE_INP_ACTIVE); @@ -640,7 +640,7 @@ public: ATTR_HOT inline nl_double Q_Analog() const; protected: - ATTR_COLD virtual void reset() + /* ATTR_COLD */ virtual void reset() { //netlist_core_terminal_t::reset(); set_state(STATE_INP_ACTIVE); @@ -659,7 +659,7 @@ public: typedef plist_t list_t; ATTR_COLD netlist_net_t(const family_t afamily); - ATTR_COLD virtual ~netlist_net_t(); + /* ATTR_COLD */ virtual ~netlist_net_t(); ATTR_COLD void init_object(netlist_base_t &nl, const pstring &aname); @@ -708,8 +708,8 @@ public: protected: //FIXME: needed by current solver code - ATTR_COLD virtual void save_register(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void save_register(); + /* ATTR_COLD */ virtual void reset(); netlist_sig_t m_new_Q; netlist_sig_t m_cur_Q; @@ -739,7 +739,7 @@ public: typedef plist_t list_t; ATTR_COLD netlist_logic_net_t(); - ATTR_COLD virtual ~netlist_logic_net_t() { }; + /* ATTR_COLD */ virtual ~netlist_logic_net_t() { }; ATTR_HOT inline netlist_sig_t Q() const { @@ -781,8 +781,8 @@ public: protected: //FIXME: needed by current solver code - ATTR_COLD virtual void save_register(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void save_register(); + /* ATTR_COLD */ virtual void reset(); private: @@ -799,7 +799,7 @@ public: typedef plist_t list_t; ATTR_COLD netlist_analog_net_t(); - ATTR_COLD virtual ~netlist_analog_net_t() { }; + /* ATTR_COLD */ virtual ~netlist_analog_net_t() { }; ATTR_HOT inline nl_double Q_Analog() const { @@ -818,8 +818,8 @@ public: protected: - ATTR_COLD virtual void save_register(); - ATTR_COLD virtual void reset(); + /* ATTR_COLD */ virtual void save_register(); + /* ATTR_COLD */ virtual void reset(); private: @@ -844,7 +844,7 @@ public: ATTR_COLD netlist_logic_output_t(); ATTR_COLD void init_object(netlist_core_device_t &dev, const pstring &aname); - ATTR_COLD virtual void reset() + /* ATTR_COLD */ virtual void reset() { set_state(STATE_OUT); } @@ -868,7 +868,7 @@ public: ATTR_COLD netlist_analog_output_t(); ATTR_COLD void init_object(netlist_core_device_t &dev, const pstring &aname); - ATTR_COLD virtual void reset() + /* ATTR_COLD */ virtual void reset() { set_state(STATE_OUT); } @@ -906,7 +906,7 @@ public: protected: - ATTR_COLD virtual void reset() { } + /* ATTR_COLD */ virtual void reset() { } private: const param_type_t m_param_type; @@ -923,7 +923,7 @@ public: ATTR_HOT inline nl_double Value() const { return m_param; } protected: - ATTR_COLD virtual void save_register() + /* ATTR_COLD */ virtual void save_register() { save(NLNAME(m_param)); netlist_param_t::save_register(); @@ -945,7 +945,7 @@ public: ATTR_HOT inline int Value() const { return m_param; } protected: - ATTR_COLD virtual void save_register() + /* ATTR_COLD */ virtual void save_register() { save(NLNAME(m_param)); netlist_param_t::save_register(); @@ -1008,9 +1008,9 @@ public: ATTR_COLD netlist_core_device_t(const family_t afamily); - ATTR_COLD virtual ~netlist_core_device_t(); + /* ATTR_COLD */ virtual ~netlist_core_device_t(); - ATTR_COLD virtual void init(netlist_base_t &anetlist, const pstring &name); + /* ATTR_COLD */ virtual void init(netlist_base_t &anetlist, const pstring &name); ATTR_HOT virtual void update_param() {} ATTR_HOT inline void update_dev() @@ -1076,9 +1076,9 @@ public: protected: ATTR_HOT virtual void update() { } - ATTR_COLD virtual void start() { } - ATTR_COLD virtual void stop() { } \ - ATTR_COLD virtual const netlist_logic_family_desc_t *default_logic_family() + /* ATTR_COLD */ virtual void start() { } + /* ATTR_COLD */ virtual void stop() { } \ + /* ATTR_COLD */ virtual const netlist_logic_family_desc_t *default_logic_family() { return &netlist_family_TTL; } @@ -1095,9 +1095,9 @@ public: ATTR_COLD netlist_device_t(); ATTR_COLD netlist_device_t(const family_t afamily); - ATTR_COLD virtual ~netlist_device_t(); + /* ATTR_COLD */ virtual ~netlist_device_t(); - ATTR_COLD virtual void init(netlist_base_t &anetlist, const pstring &name); + /* ATTR_COLD */ virtual void init(netlist_base_t &anetlist, const pstring &name); ATTR_COLD netlist_setup_t &setup(); @@ -1252,12 +1252,12 @@ protected: }; // any derived netlist must override this ... - ATTR_COLD virtual void verror(const loglevel_e level, + /* ATTR_COLD */ virtual void verror(const loglevel_e level, const char *format, va_list ap) const = 0; /* from netlist_object */ - ATTR_COLD virtual void reset(); - ATTR_COLD virtual void save_register(); + /* ATTR_COLD */ virtual void reset(); + /* ATTR_COLD */ virtual void save_register(); #if (NL_KEEP_STATISTICS) // performance diff --git a/src/emu/netlist/nl_factory.h b/src/emu/netlist/nl_factory.h index 1998dbd07d2..970a5024c5a 100644 --- a/src/emu/netlist/nl_factory.h +++ b/src/emu/netlist/nl_factory.h @@ -28,9 +28,9 @@ public: : m_name(name), m_classname(classname), m_def_param(def_param) {} - ATTR_COLD virtual ~net_device_t_base_factory() {} + /* ATTR_COLD */ virtual ~net_device_t_base_factory() {} - ATTR_COLD virtual netlist_device_t *Create() const = 0; + /* ATTR_COLD */ virtual netlist_device_t *Create() const = 0; ATTR_COLD const pstring &name() const { return m_name; } ATTR_COLD const pstring &classname() const { return m_classname; } @@ -66,8 +66,8 @@ class netlist_factory_t public: typedef plist_t list_t; - ATTR_COLD netlist_factory_t(); - ATTR_COLD ~netlist_factory_t(); + netlist_factory_t(); + ~netlist_factory_t(); template ATTR_COLD void register_device(const pstring &name, const pstring &classname, diff --git a/src/emu/netlist/nl_parser.c b/src/emu/netlist/nl_parser.c index fe0bfad28eb..44a7b2bf561 100644 --- a/src/emu/netlist/nl_parser.c +++ b/src/emu/netlist/nl_parser.c @@ -11,197 +11,6 @@ //#undef NL_VERBOSE_OUT //#define NL_VERBOSE_OUT(x) printf x -// ---------------------------------------------------------------------------------------- -// A simple tokenizer -// ---------------------------------------------------------------------------------------- - -pstring ptokenizer::currentline_str() -{ - char buf[300]; - int bufp = 0; - const char *p = m_line_ptr; - while (*p && *p != 10) - buf[bufp++] = *p++; - buf[bufp] = 0; - return pstring(buf); -} - - -void ptokenizer::skipeol() -{ - char c = getc(); - while (c) - { - if (c == 10) - { - c = getc(); - if (c != 13) - ungetc(); - return; - } - c = getc(); - } -} - - -unsigned char ptokenizer::getc() -{ - if (*m_px == 10) - { - m_line++; - m_line_ptr = m_px + 1; - } - if (*m_px) - return *(m_px++); - else - return *m_px; -} - -void ptokenizer::ungetc() -{ - m_px--; -} - -void ptokenizer::require_token(const token_id_t &token_num) -{ - require_token(get_token(), token_num); -} - -void ptokenizer::require_token(const token_t tok, const token_id_t &token_num) -{ - if (!tok.is(token_num)) - { - error("Error: expected token <%s> got <%s>\n", m_tokens[token_num.id()].cstr(), tok.str().cstr()); - } -} - -pstring ptokenizer::get_string() -{ - token_t tok = get_token(); - if (!tok.is_type(STRING)) - { - error("Error: expected a string, got <%s>\n", tok.str().cstr()); - } - return tok.str(); -} - -pstring ptokenizer::get_identifier() -{ - token_t tok = get_token(); - if (!tok.is_type(IDENTIFIER)) - { - error("Error: expected an identifier, got <%s>\n", tok.str().cstr()); - } - return tok.str(); -} - -ptokenizer::token_t ptokenizer::get_token() -{ - while (true) - { - token_t ret = get_token_internal(); - if (ret.is_type(ENDOFFILE)) - return ret; - - if (ret.is(m_tok_comment_start)) - { - do { - ret = get_token_internal(); - } while (ret.is_not(m_tok_comment_end)); - } - else if (ret.is(m_tok_line_comment)) - { - skipeol(); - } - else if (ret.str() == "#") - { - skipeol(); - } - else - return ret; - } -} - -ptokenizer::token_t ptokenizer::get_token_internal() -{ - /* skip ws */ - char c = getc(); - while (m_whitespace.find(c)>=0) - { - c = getc(); - if (eof()) - { - return token_t(ENDOFFILE); - } - } - if (m_identifier_chars.find(c)>=0) - { - /* read identifier till non identifier char */ - pstring tokstr = ""; - while (m_identifier_chars.find(c)>=0) { - tokstr += c; - c = getc(); - } - ungetc(); - token_id_t id = token_id_t(m_tokens.indexof(tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); - else - { - return token_t(IDENTIFIER, tokstr); - } - } - else if (c == m_string) - { - pstring tokstr = ""; - c = getc(); - while (c != m_string) - { - tokstr += c; - c = getc(); - } - return token_t(STRING, tokstr); - } - else - { - /* read identifier till first identifier char or ws */ - pstring tokstr = ""; - while ((m_identifier_chars.find(c)) < 0 && (m_whitespace.find(c) < 0)) { - tokstr += c; - /* expensive, check for single char tokens */ - if (tokstr.len() == 1) - { - token_id_t id = token_id_t(m_tokens.indexof(tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); - } - c = getc(); - } - ungetc(); - token_id_t id = token_id_t(m_tokens.indexof(tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); - else - { - return token_t(UNKNOWN, tokstr); - } - } - -} - -ATTR_COLD void ptokenizer::error(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - pstring errmsg1 = pstring(format).vprintf(ap); - va_end(ap); - - verror(errmsg1, currentline_no(), currentline_str()); - - //throw error; -} - // ---------------------------------------------------------------------------------------- // A netlist parser // ---------------------------------------------------------------------------------------- @@ -217,9 +26,12 @@ ATTR_COLD void netlist_parser::verror(pstring msg, int line_num, pstring line) bool netlist_parser::parse(const char *buf, const pstring nlname) { - m_buf = buf; + ppreprocessor prepro; + + pstring processed = prepro.process(buf); + m_buf = processed.cstr(); - reset(buf); + reset(m_buf); set_identifier_chars("abcdefghijklmnopqrstuvwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_.-"); set_number_chars("01234567890eE-."); //FIXME: processing of numbers char ws[5]; diff --git a/src/emu/netlist/nl_parser.h b/src/emu/netlist/nl_parser.h index d8fb07b555e..415df846d60 100644 --- a/src/emu/netlist/nl_parser.h +++ b/src/emu/netlist/nl_parser.h @@ -9,132 +9,8 @@ #define NL_PARSER_H_ #include "nl_setup.h" - -class ptokenizer -{ - NETLIST_PREVENT_COPYING(ptokenizer) -public: - virtual ~ptokenizer() {} - - ptokenizer() - : m_line(1), m_line_ptr(NULL), m_px(NULL), m_string('"') - {} - - enum token_type - { - IDENTIFIER, - NUMBER, - TOKEN, - STRING, - COMMENT, - UNKNOWN, - ENDOFFILE - }; - - struct token_id_t - { - public: - token_id_t() : m_id(-2) {} - token_id_t(const int id) : m_id(id) {} - int id() const { return m_id; } - private: - int m_id; - }; - - struct token_t - { - token_t(token_type type) - { - m_type = type; - m_id = token_id_t(-1); - m_token =""; - } - token_t(token_type type, const pstring str) - { - m_type = type; - m_id = token_id_t(-1); - m_token = str; - } - token_t(const token_id_t id, const pstring str) - { - m_type = TOKEN; - m_id = id; - m_token = str; - } - - bool is(const token_id_t &tok_id) const { return m_id.id() == tok_id.id(); } - bool is_not(const token_id_t &tok_id) const { return !is(tok_id); } - - bool is_type(const token_type type) const { return m_type == type; } - - pstring str() const { return m_token; } - - private: - token_type m_type; - token_id_t m_id; - pstring m_token; - }; - - - int currentline_no() { return m_line; } - pstring currentline_str(); - - /* tokenizer stuff follows ... */ - - token_t get_token(); - pstring get_string(); - pstring get_identifier(); - - void require_token(const token_id_t &token_num); - void require_token(const token_t tok, const token_id_t &token_num); - - token_id_t register_token(pstring token) - { - m_tokens.add(token); - return token_id_t(m_tokens.count() - 1); - } - - void set_identifier_chars(pstring s) { m_identifier_chars = s; } - void set_number_chars(pstring s) { m_number_chars = s; } - void set_whitespace(pstring s) { m_whitespace = s; } - void set_comment(pstring start, pstring end, pstring line) - { - m_tok_comment_start = register_token(start); - m_tok_comment_end = register_token(end); - m_tok_line_comment = register_token(line); - m_string = '"'; - } - - token_t get_token_internal(); - void error(const char *format, ...) ATTR_PRINTF(2,3); - -protected: - void reset(const char *p) { m_px = p; m_line = 1; m_line_ptr = p; } - virtual void verror(pstring msg, int line_num, pstring line) = 0; - -private: - void skipeol(); - - unsigned char getc(); - void ungetc(); - bool eof() { return *m_px == 0; } - - int m_line; - const char * m_line_ptr; - const char * m_px; - - /* tokenizer stuff follows ... */ - - pstring m_identifier_chars; - pstring m_number_chars; - plist_t m_tokens; - pstring m_whitespace; - char m_string; - - token_id_t m_tok_comment_start; - token_id_t m_tok_comment_end; - token_id_t m_tok_line_comment; -}; +#include "nl_util.h" +#include "pparser.h" class netlist_parser : public ptokenizer { diff --git a/src/emu/netlist/nl_util.h b/src/emu/netlist/nl_util.h index ff5511b7f90..8e1c8efb1b7 100644 --- a/src/emu/netlist/nl_util.h +++ b/src/emu/netlist/nl_util.h @@ -11,6 +11,7 @@ #include "pstring.h" #include "plists.h" #include +#include class nl_util { @@ -45,6 +46,43 @@ public: } return temp; } + + static pstring_list splitexpr(const pstring &str, const pstring_list &onstrl) + { + pstring_list temp; + pstring col = ""; + + int i = 0; + while (i=0) + { + if (col != "") + temp.add(col); + col = ""; + temp.add(onstrl[p]); + i += onstrl[p].len(); + } + else + { + col += str.cstr()[i]; + i++; + } + } + if (col != "") + temp.add(col); + return temp; + } + static const pstring environment(const pstring &var, const pstring &default_val = "") { if (getenv(var.cstr()) == NULL) diff --git a/src/emu/netlist/pconfig.h b/src/emu/netlist/pconfig.h index 0760bc4adfa..6c6848d2c75 100644 --- a/src/emu/netlist/pconfig.h +++ b/src/emu/netlist/pconfig.h @@ -33,9 +33,9 @@ /* not supported in GCC prior to 4.4.x */ /* ATTR_HOT and ATTR_COLD cause performance degration in 5.1 */ //#define ATTR_HOT -#define ATTR_COLD +//#define ATTR_COLD #define ATTR_HOT __attribute__((hot)) -//#define ATTR_COLD __attribute__((cold)) +#define ATTR_COLD __attribute__((cold)) #define RESTRICT #define EXPECTED(x) (x) diff --git a/src/emu/netlist/plists.h b/src/emu/netlist/plists.h index 3f422653367..54b3889a75f 100644 --- a/src/emu/netlist/plists.h +++ b/src/emu/netlist/plists.h @@ -44,7 +44,7 @@ public: return *this; } - ATTR_COLD ~parray_t() + ~parray_t() { if (m_list != NULL) pfree_array(m_list); @@ -127,7 +127,7 @@ public: } - ATTR_COLD ~plist_t() + ~plist_t() { if (m_list != NULL) pfree_array(m_list); @@ -333,7 +333,7 @@ public: } - ATTR_COLD ~pstack_t() + ~pstack_t() { } diff --git a/src/emu/netlist/pparser.c b/src/emu/netlist/pparser.c new file mode 100644 index 00000000000..d2f926a38bd --- /dev/null +++ b/src/emu/netlist/pparser.c @@ -0,0 +1,354 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pparser.c + * + */ + +#include "pparser.h" + +//#undef NL_VERBOSE_OUT +//#define NL_VERBOSE_OUT(x) printf x + +// ---------------------------------------------------------------------------------------- +// A simple tokenizer +// ---------------------------------------------------------------------------------------- + +pstring ptokenizer::currentline_str() +{ + char buf[300]; + int bufp = 0; + const char *p = m_line_ptr; + while (*p && *p != 10) + buf[bufp++] = *p++; + buf[bufp] = 0; + return pstring(buf); +} + + +void ptokenizer::skipeol() +{ + char c = getc(); + while (c) + { + if (c == 10) + { + c = getc(); + if (c != 13) + ungetc(); + return; + } + c = getc(); + } +} + + +unsigned char ptokenizer::getc() +{ + if (*m_px == 10) + { + m_line++; + m_line_ptr = m_px + 1; + } + if (*m_px) + return *(m_px++); + else + return *m_px; +} + +void ptokenizer::ungetc() +{ + m_px--; +} + +void ptokenizer::require_token(const token_id_t &token_num) +{ + require_token(get_token(), token_num); +} + +void ptokenizer::require_token(const token_t tok, const token_id_t &token_num) +{ + if (!tok.is(token_num)) + { + error("Error: expected token <%s> got <%s>\n", m_tokens[token_num.id()].cstr(), tok.str().cstr()); + } +} + +pstring ptokenizer::get_string() +{ + token_t tok = get_token(); + if (!tok.is_type(STRING)) + { + error("Error: expected a string, got <%s>\n", tok.str().cstr()); + } + return tok.str(); +} + +pstring ptokenizer::get_identifier() +{ + token_t tok = get_token(); + if (!tok.is_type(IDENTIFIER)) + { + error("Error: expected an identifier, got <%s>\n", tok.str().cstr()); + } + return tok.str(); +} + +ptokenizer::token_t ptokenizer::get_token() +{ + while (true) + { + token_t ret = get_token_internal(); + if (ret.is_type(ENDOFFILE)) + return ret; + + if (ret.is(m_tok_comment_start)) + { + do { + ret = get_token_internal(); + } while (ret.is_not(m_tok_comment_end)); + } + else if (ret.is(m_tok_line_comment)) + { + skipeol(); + } + else if (ret.str() == "#") + { + skipeol(); + } + else + return ret; + } +} + +ptokenizer::token_t ptokenizer::get_token_internal() +{ + /* skip ws */ + char c = getc(); + while (m_whitespace.find(c)>=0) + { + c = getc(); + if (eof()) + { + return token_t(ENDOFFILE); + } + } + if (m_identifier_chars.find(c)>=0) + { + /* read identifier till non identifier char */ + pstring tokstr = ""; + while (m_identifier_chars.find(c)>=0) { + tokstr += c; + c = getc(); + } + ungetc(); + token_id_t id = token_id_t(m_tokens.indexof(tokstr)); + if (id.id() >= 0) + return token_t(id, tokstr); + else + { + return token_t(IDENTIFIER, tokstr); + } + } + else if (c == m_string) + { + pstring tokstr = ""; + c = getc(); + while (c != m_string) + { + tokstr += c; + c = getc(); + } + return token_t(STRING, tokstr); + } + else + { + /* read identifier till first identifier char or ws */ + pstring tokstr = ""; + while ((m_identifier_chars.find(c)) < 0 && (m_whitespace.find(c) < 0)) { + tokstr += c; + /* expensive, check for single char tokens */ + if (tokstr.len() == 1) + { + token_id_t id = token_id_t(m_tokens.indexof(tokstr)); + if (id.id() >= 0) + return token_t(id, tokstr); + } + c = getc(); + } + ungetc(); + token_id_t id = token_id_t(m_tokens.indexof(tokstr)); + if (id.id() >= 0) + return token_t(id, tokstr); + else + { + return token_t(UNKNOWN, tokstr); + } + } + +} + +ATTR_COLD void ptokenizer::error(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + + pstring errmsg1 = pstring(format).vprintf(ap); + va_end(ap); + + verror(errmsg1, currentline_no(), currentline_str()); + + //throw error; +} + +// ---------------------------------------------------------------------------------------- +// A simple preprocessor +// ---------------------------------------------------------------------------------------- + +ppreprocessor::ppreprocessor() +{ + m_expr_sep.add("("); + m_expr_sep.add(")"); + m_expr_sep.add("+"); + m_expr_sep.add("-"); + m_expr_sep.add("*"); + m_expr_sep.add("/"); + m_expr_sep.add("=="); + m_expr_sep.add(" "); + m_expr_sep.add("\t"); +} + + +double ppreprocessor::expr(const nl_util::pstring_list &sexpr, int &start, int prio) +{ + double val; + pstring tok=sexpr[start]; + if (tok == "(") + { + start++; + val = expr(sexpr, start, prio); + if (sexpr[start] != ")") + error("parsing error!"); + start++; + } + else + { + tok=sexpr[start]; + val = tok.as_double(); + start++; + } + while (start < sexpr.count()) + { + tok=sexpr[start]; + if (tok == ")") + { + // FIXME: catch error + return val; + } + else if (tok == "+") + { + if (prio >= 20) + return val; + start++; + val = val + expr(sexpr, start, 10); + } + else if (tok == "-") + { + if (prio >= 20) + return val; + start++; + val = val - expr(sexpr, start, 10); + } + else if (tok == "*") + { + start++; + val = val * expr(sexpr, start, 20); + } + } + return val; +} + +ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name) +{ + for (int i = 0; im_replace; + else + ret = ret + elems[i]; + } + return ret; +} + + +pstring ppreprocessor::process(const pstring &contents) +{ + pstring ret = ""; + nl_util::pstring_list lines = nl_util::split(contents,"\n", false); + UINT32 ifflag = 0; // 31 if levels + int level = 0; + + int i=0; + while (i 0) + // fprintf(stderr, "conditional: %s\n", line.cstr()); + if (ifflag == 0) + ret = ret + line + "\n"; + } + i++; + } + return ret; +} diff --git a/src/emu/netlist/pparser.h b/src/emu/netlist/pparser.h new file mode 100644 index 00000000000..4a76aeb3d6b --- /dev/null +++ b/src/emu/netlist/pparser.h @@ -0,0 +1,181 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pparser.h + * + */ + +#ifndef PPARSER_H_ +#define PPARSER_H_ + +#include "pconfig.h" +#include "nl_config.h" // FIXME +#include "nl_util.h" + +class ptokenizer +{ + NETLIST_PREVENT_COPYING(ptokenizer) +public: + virtual ~ptokenizer() {} + + ptokenizer() + : m_line(1), m_line_ptr(NULL), m_px(NULL), m_string('"') + {} + + enum token_type + { + IDENTIFIER, + NUMBER, + TOKEN, + STRING, + COMMENT, + UNKNOWN, + ENDOFFILE + }; + + struct token_id_t + { + public: + token_id_t() : m_id(-2) {} + token_id_t(const int id) : m_id(id) {} + int id() const { return m_id; } + private: + int m_id; + }; + + struct token_t + { + token_t(token_type type) + { + m_type = type; + m_id = token_id_t(-1); + m_token =""; + } + token_t(token_type type, const pstring str) + { + m_type = type; + m_id = token_id_t(-1); + m_token = str; + } + token_t(const token_id_t id, const pstring str) + { + m_type = TOKEN; + m_id = id; + m_token = str; + } + + bool is(const token_id_t &tok_id) const { return m_id.id() == tok_id.id(); } + bool is_not(const token_id_t &tok_id) const { return !is(tok_id); } + + bool is_type(const token_type type) const { return m_type == type; } + + pstring str() const { return m_token; } + + private: + token_type m_type; + token_id_t m_id; + pstring m_token; + }; + + + int currentline_no() { return m_line; } + pstring currentline_str(); + + /* tokenizer stuff follows ... */ + + token_t get_token(); + pstring get_string(); + pstring get_identifier(); + + void require_token(const token_id_t &token_num); + void require_token(const token_t tok, const token_id_t &token_num); + + token_id_t register_token(pstring token) + { + m_tokens.add(token); + return token_id_t(m_tokens.count() - 1); + } + + void set_identifier_chars(pstring s) { m_identifier_chars = s; } + void set_number_chars(pstring s) { m_number_chars = s; } + void set_whitespace(pstring s) { m_whitespace = s; } + void set_comment(pstring start, pstring end, pstring line) + { + m_tok_comment_start = register_token(start); + m_tok_comment_end = register_token(end); + m_tok_line_comment = register_token(line); + m_string = '"'; + } + + token_t get_token_internal(); + void error(const char *format, ...) ATTR_PRINTF(2,3); + +protected: + void reset(const char *p) { m_px = p; m_line = 1; m_line_ptr = p; } + virtual void verror(pstring msg, int line_num, pstring line) = 0; + +private: + void skipeol(); + + unsigned char getc(); + void ungetc(); + bool eof() { return *m_px == 0; } + + int m_line; + const char * m_line_ptr; + const char * m_px; + + /* tokenizer stuff follows ... */ + + pstring m_identifier_chars; + pstring m_number_chars; + plist_t m_tokens; + pstring m_whitespace; + char m_string; + + token_id_t m_tok_comment_start; + token_id_t m_tok_comment_end; + token_id_t m_tok_line_comment; +}; + + +class ppreprocessor +{ + NETLIST_PREVENT_COPYING(ppreprocessor) +public: + + struct define_t + { + define_t() { }; + define_t(const pstring &name, const pstring &replace) + : m_name(name), m_replace(replace) + {} + pstring m_name; + pstring m_replace; + }; + + ppreprocessor(); + virtual ~ppreprocessor() {} + + pstring process(const pstring &contents); + +protected: + + double expr(const nl_util::pstring_list &sexpr, int &start, int prio); + + define_t *get_define(const pstring &name); + + pstring replace_macros(const pstring &line); + + virtual void error(const pstring &err) + { + fprintf(stderr, "PREPRO ERROR: %s\n", err.cstr()); + } + +private: + + plist_t m_defines; + nl_util::pstring_list m_expr_sep; +}; + +#endif /* PPARSER_H_ */ diff --git a/src/mame/drivers/nl_pong.c b/src/mame/drivers/nl_pong.c index 253cd23c0b9..f13283cdfb9 100644 --- a/src/mame/drivers/nl_pong.c +++ b/src/mame/drivers/nl_pong.c @@ -9,6 +9,8 @@ #include "netlist/devices/net_lib.h" +#define FAST_CLOCK (1) + NETLIST_START(pong_fast) SOLVER(Solver, 48000) PARAM(Solver.PARALLEL, 0) // Don't do parallel solvers @@ -22,15 +24,15 @@ NETLIST_START(pong_fast) TTL_INPUT(low, 0) #if 1 -#if 0 - /* this is the clock circuit in schematics. */ - MAINCLOCK(xclk, 7159000.0*2) - TTL_74107(ic_f6a, xclk, high, high, high) - ALIAS(clk, ic_f6a.Q) -#else +#if (FAST_CLOCK) /* abstracting this, performance increases by 60% * No surprise, the clock is extremely expensive */ MAINCLOCK(clk, 7159000.0) +#else + /* this is the clock circuit in schematics. */ + MAINCLOCK(xclk, 14318000.0) //7159000.0*2 + TTL_74107(ic_f6a, xclk, high, high, high) + ALIAS(clk, ic_f6a.Q) #endif #else // benchmarking ... -- cgit v1.2.3 From eb13a4dedafda2a6fe5658527b600d19e10f97d8 Mon Sep 17 00:00:00 2001 From: hap Date: Tue, 26 May 2015 14:53:56 +0200 Subject: added tms1024 device placeholder --- scripts/src/machine.lua | 12 ++++++++++ scripts/target/mame/arcade.lua | 1 + scripts/target/mame/mess.lua | 1 + src/emu/machine/tms1024.c | 43 ++++++++++++++++++++++++++++++++++ src/emu/machine/tms1024.h | 52 ++++++++++++++++++++++++++++++++++++++++++ src/mess/drivers/hh_tms1k.c | 1 + 6 files changed, 110 insertions(+) create mode 100644 src/emu/machine/tms1024.c create mode 100644 src/emu/machine/tms1024.h (limited to 'scripts/src') diff --git a/scripts/src/machine.lua b/scripts/src/machine.lua index 4324662ffd3..528cebbd3d2 100644 --- a/scripts/src/machine.lua +++ b/scripts/src/machine.lua @@ -2070,6 +2070,18 @@ if (MACHINES["TMP68301"]~=null) then } end +--------------------------------------------------- +-- +--@src/emu/machine/tms1024.h,MACHINES += TMS1024 +--------------------------------------------------- + +if (MACHINES["TMS1024"]~=null) then + files { + MAME_DIR .. "src/emu/machine/tms1024.c", + MAME_DIR .. "src/emu/machine/tms1024.h", + } +end + --------------------------------------------------- -- --@src/emu/machine/tms5501.h,MACHINES += TMS5501 diff --git a/scripts/target/mame/arcade.lua b/scripts/target/mame/arcade.lua index 0dfec94644a..eff03dac309 100644 --- a/scripts/target/mame/arcade.lua +++ b/scripts/target/mame/arcade.lua @@ -557,6 +557,7 @@ MACHINES["STEPPERS"] = true --MACHINES["WOZFDC"] = true --MACHINES["DIABLO_HD"] = true MACHINES["PCI9050"] = true +--MACHINES["TMS1024"] = true -------------------------------------------------- -- specify available bus cores diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua index 2d027f05677..84bed8d6c66 100644 --- a/scripts/target/mame/mess.lua +++ b/scripts/target/mame/mess.lua @@ -556,6 +556,7 @@ MACHINES["STEPPERS"] = true MACHINES["CORVUSHD"] = true MACHINES["WOZFDC"] = true MACHINES["DIABLO_HD"] = true +MACHINES["TMS1024"] = true -------------------------------------------------- -- specify available bus cores diff --git a/src/emu/machine/tms1024.c b/src/emu/machine/tms1024.c new file mode 100644 index 00000000000..b5dfd018b87 --- /dev/null +++ b/src/emu/machine/tms1024.c @@ -0,0 +1,43 @@ +// license:BSD-3-Clause +// copyright-holders:hap +/********************************************************************** + + Texas Instruments TMS1024, TMS1025 I/O expander emulation + +**********************************************************************/ + +#include "machine/tms1024.h" + + +const device_type TMS1024 = &device_creator; + +//------------------------------------------------- +// tms1024_device - constructor +//------------------------------------------------- + +tms1024_device::tms1024_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, TMS1024, "TMS1024", tag, owner, clock, "tms1024", __FILE__) +{ +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void tms1024_device::device_start() +{ + // resolve callbacks + + // register for savestates +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void tms1024_device::device_reset() +{ +} + + +// handlers diff --git a/src/emu/machine/tms1024.h b/src/emu/machine/tms1024.h new file mode 100644 index 00000000000..ca1ad0740cf --- /dev/null +++ b/src/emu/machine/tms1024.h @@ -0,0 +1,52 @@ +// license:BSD-3-Clause +// copyright-holders:hap +/********************************************************************** + + Texas Instruments TMS1024, TMS1025 I/O expander emulation + +********************************************************************** + + + + + +**********************************************************************/ + +#ifndef _TMS1024_H_ +#define _TMS1024_H_ + +#include "emu.h" + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_TMS1024_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, TMS1024, 0) + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +// ======================> tms1024_device + +class tms1024_device : public device_t +{ +public: + tms1024_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // static configuration helpers + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); +}; + +// device type definition +extern const device_type TMS1024; + + +#endif /* _TMS1024_H_ */ diff --git a/src/mess/drivers/hh_tms1k.c b/src/mess/drivers/hh_tms1k.c index 27d47c02bf6..5c7c020d68b 100644 --- a/src/mess/drivers/hh_tms1k.c +++ b/src/mess/drivers/hh_tms1k.c @@ -91,6 +91,7 @@ ***************************************************************************/ #include "includes/hh_tms1k.h" +#include "machine/tms1024.h" #include "sound/beep.h" // internal artwork -- cgit v1.2.3 From e5caefbfbd7322e38ccfe6e1518efb50b20cef53 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 27 May 2015 08:53:07 +0200 Subject: added deps for .lst (nw) --- scripts/src/main.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'scripts/src') diff --git a/scripts/src/main.lua b/scripts/src/main.lua index 80ac9c8b9c6..9559eb1f594 100644 --- a/scripts/src/main.lua +++ b/scripts/src/main.lua @@ -180,7 +180,10 @@ function mainProject(_target, _subtarget) MAME_DIR .. "src/version.c", GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.c", } - + dependency { + { "../../../../generated/mame/mame/drivlist.c", MAME_DIR .. "src/mame/mess.lst", true }, + { "../../../../generated/mame/mame/drivlist.c" , MAME_DIR .. "src/mame/arcade.lst", true}, + } custombuildtask { { MAME_DIR .. "src/".._target .."/" .. _subtarget ..".lst" , GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.c", { MAME_DIR .. "src/build/makelist.py" }, {"@echo Building driver list...", PYTHON .. " $(1) $(<) > $(@)" }}, } -- cgit v1.2.3 From 2e772fb16078401daaf14d7a6f7ef2a6f062dbf0 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 27 May 2015 15:02:33 +0200 Subject: Added lua script/makefile changes to support building tests and portaudio (nw) --- makefile | 6 ++ scripts/genie.lua | 9 +++ scripts/src/3rdparty.lua | 188 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/src/tests.lua | 42 +++++++++++ 4 files changed, 245 insertions(+) create mode 100644 scripts/src/tests.lua (limited to 'scripts/src') diff --git a/makefile b/makefile index 199fd570c6c..4d6cf108260 100644 --- a/makefile +++ b/makefile @@ -22,6 +22,7 @@ # TARGET = mame # SUBTARGET = tiny # TOOLS = 1 +# TESTS = 1 # OSD = sdl # USE_BGFX = 1 @@ -375,6 +376,10 @@ ifdef TOOLS PARAMS += --with-tools endif +ifdef TESTS +PARAMS += --with-tests +endif + ifdef SYMBOLS PARAMS += --SYMBOLS='$(SYMBOLS)' endif @@ -571,6 +576,7 @@ SCRIPTS = scripts/genie.lua \ $(wildcard scripts/src/osd/$(OSD)*.lua) \ scripts/src/sound.lua \ scripts/src/tools.lua \ + scripts/src/tests.lua \ scripts/src/video.lua \ scripts/src/bus.lua \ scripts/src/netlist.lua \ diff --git a/scripts/genie.lua b/scripts/genie.lua index 79702a38c78..db9481277f4 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -59,6 +59,11 @@ newoption { description = "Enable building tools.", } +newoption { + trigger = "with-tests", + description = "Enable building tests.", +} + newoption { trigger = "osd", description = "Choose OSD layer implementation", @@ -1138,3 +1143,7 @@ if _OPTIONS["with-tools"] then dofile(path.join("src", "tools.lua")) end +if _OPTIONS["with-tests"] then + group "tests" + dofile(path.join("src", "tests.lua")) +end diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index aac32bfad74..e744db9b79b 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -604,3 +604,191 @@ project "bgfx" } end end + +-------------------------------------------------- +-- PortAudio library objects +-------------------------------------------------- + +project "portaudio" + uuid "0755c5f5-eccf-47f3-98a9-df67018a94d4" + kind "StaticLib" + + configuration { "gmake" } + buildoptions_c { + "-Wno-strict-prototypes", + "-Wno-bad-function-cast", + "-Wno-undef", + "-Wno-missing-braces", + "-Wno-unused-but-set-variable", + "-Wno-maybe-uninitialized", + "-Wno-unused-value", + "-Wno-unused-function", + } + + configuration { "vs*" } + buildoptions { + "/wd4204", -- warning C4204: nonstandard extension used : non-constant aggregate initializer + "/wd4701", -- warning C4701: potentially uninitialized local variable 'xxx' used + } + + configuration { } + + includedirs { + MAME_DIR .. "3rdparty/portaudio/include", + MAME_DIR .. "3rdparty/portaudio/src/common", + } + + files { + MAME_DIR .. "3rdparty/portaudio/src/common/pa_allocation.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_converters.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_cpuload.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_dither.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_debugprint.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_front.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_process.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_stream.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_trace.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/skeleton/pa_hostapi_skeleton.c", + } + + if _OPTIONS["targetos"]=="windows" then + defines { + "PA_USE_DS=1", + "PA_USE_WDMKS=1", + "PA_USE_WMME=1", + "PA_USE_WASAPI=1", + } + includedirs { + MAME_DIR .. "3rdparty/portaudio/src/os/win", + } + configuration { "mingw*" } + includedirs { + MAME_DIR .. "3rdparty/portaudio/src/hostapi/wasapi/mingw-include", + } + configuration { } + files { + MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_util.c", + MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_waveformat.c", + MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_hostapis.c", + MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_x86_plain_converters.c", + MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_wdmks_utils.c", + MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_coinitialize.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds_dynlink.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/wdmks/pa_win_wdmks.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/wasapi/pa_win_wasapi.c", + } + + end + if _OPTIONS["targetos"]=="linux" then + defines { + "PA_USE_ALSA=1", + "PA_USE_OSS=1", + "HAVE_LINUX_SOUNDCARD_H", + } + includedirs { + MAME_DIR .. "3rdparty/portaudio/src/os/unix", + } + files { + MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c", + MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_util.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/alsa/pa_linux_alsa.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/oss/pa_unix_oss.c", + } + end + if _OPTIONS["targetos"]=="macosx" then + defines { + "PA_USE_COREAUDIO=1", + } + includedirs { + MAME_DIR .. "3rdparty/portaudio/src/os/unix", + } + files { + MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_hostapis.c", + MAME_DIR .. "3rdparty/portaudio/src/os/unix/pa_unix_util.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core_utilities.c", + MAME_DIR .. "3rdparty/portaudio/src/hostapi/coreaudio/pa_mac_core_blocking.c", + MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c", + } + end + + if (_OPTIONS["SHADOW_CHECK"]=="1") then + removebuildoptions { + "-Wshadow" + } + end + +-------------------------------------------------- +-- UnitTest++ library objects +-------------------------------------------------- + +project "unittest-cpp" + uuid "717d39e5-b6ff-4507-a092-c27c05b60ab5" + kind "StaticLib" + + files { + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/AssertException.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/AssertException.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/CheckMacros.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Checks.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Checks.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/CompositeTestReporter.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/CompositeTestReporter.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Config.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/CurrentTest.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/CurrentTest.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/DeferredTestReporter.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/DeferredTestReporter.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/DeferredTestResult.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/DeferredTestResult.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/ExceptionMacros.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/ExecuteTest.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/HelperMacros.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/MemoryOutStream.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/MemoryOutStream.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/ReportAssert.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/ReportAssert.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/ReportAssertImpl.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Test.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Test.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestDetails.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestDetails.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestList.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestList.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestMacros.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestReporter.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestReporter.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestReporterStdout.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestReporterStdout.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestResults.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestResults.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestRunner.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestRunner.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TestSuite.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TimeConstraint.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TimeConstraint.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/TimeHelpers.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/UnitTest++.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/UnitTestPP.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/XmlTestReporter.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/XmlTestReporter.h", + } + + if _OPTIONS["targetos"]~="windows" then + files { + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Posix/SignalTranslator.h", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.h", + } + end + + if _OPTIONS["targetos"]=="windows" then + files { + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Win32/TimeHelpers.cpp", + MAME_DIR .. "3rdparty/unittest-cpp/UnitTest++/Win32/TimeHelpers.h", + } + end diff --git a/scripts/src/tests.lua b/scripts/src/tests.lua new file mode 100644 index 00000000000..1423c10222f --- /dev/null +++ b/scripts/src/tests.lua @@ -0,0 +1,42 @@ +-- license:BSD-3-Clause +-- copyright-holders:MAMEdev Team + +-------------------------------------------------- +-- MAME tests +-------------------------------------------------- + +project("tests") +uuid ("66d4c639-196b-4065-a411-7ee9266564f5") +kind "ConsoleApp" + +options { + "ForceCPP", +} + +flags { + "Symbols", -- always include minimum symbols for executables +} + +if _OPTIONS["SEPARATE_BIN"]~="1" then + targetdir(MAME_DIR) +end + +links { + "unittest-cpp", + "utils", + "expat", + "zlib", + "ocore_" .. _OPTIONS["osd"], +} + +includedirs { + MAME_DIR .. "3rdparty/unittest-cpp", + MAME_DIR .. "src/osd", + MAME_DIR .. "src/lib/util", +} + +files { + MAME_DIR .. "tests/main.c", + MAME_DIR .. "tests/lib/util/corestr.c", +} + -- cgit v1.2.3 From b0243d6da942866f5ba33dba6fa49d1c696e3e12 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 27 May 2015 16:40:27 +0200 Subject: Removed -Wno-unused-variable for mingw/gcc (nw) --- scripts/genie.lua | 1 - scripts/src/3rdparty.lua | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/src') diff --git a/scripts/genie.lua b/scripts/genie.lua index db9481277f4..10eed679dfb 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -864,7 +864,6 @@ end if (version >= 40800) then -- array bounds checking seems to be buggy in 4.8.1 (try it on video/stvvdp1.c and video/model1.c without -Wno-array-bounds) buildoptions { - "-Wno-unused-variable", "-Wno-array-bounds" } end diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index e744db9b79b..aad89112883 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -621,6 +621,7 @@ project "portaudio" "-Wno-missing-braces", "-Wno-unused-but-set-variable", "-Wno-maybe-uninitialized", + "-Wno-unused-variable", "-Wno-unused-value", "-Wno-unused-function", } -- cgit v1.2.3 From d08d7c094d671562ec513c32e72d4fa462e639dc Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Wed, 27 May 2015 16:44:18 +0200 Subject: bbc: Update to use the new wd_fdc. Until the 8271 floppy controller is updated, drive 0 and 1 = 8271 and drive 2 and 3 = wd_fdc. --- scripts/src/lib.lua | 2 + src/lib/formats/bbc_dsk.c | 53 +++++++++++++++++++++++++ src/lib/formats/bbc_dsk.h | 33 ++++++++++++++++ src/mess/drivers/bbc.c | 62 ++++++++++++++++++++--------- src/mess/includes/bbc.h | 4 +- src/mess/machine/bbc.c | 99 ++++++++++++++++++++++++++++------------------- 6 files changed, 194 insertions(+), 59 deletions(-) create mode 100644 src/lib/formats/bbc_dsk.c create mode 100644 src/lib/formats/bbc_dsk.h (limited to 'scripts/src') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index 54540f0f630..a4bca8d6c50 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -158,6 +158,8 @@ project "formats" MAME_DIR .. "src/lib/formats/atarist_dsk.h", MAME_DIR .. "src/lib/formats/atom_tap.c", MAME_DIR .. "src/lib/formats/atom_tap.h", + MAME_DIR .. "src/lib/formats/bbc_dsk.c", + MAME_DIR .. "src/lib/formats/bbc_dsk.h", MAME_DIR .. "src/lib/formats/bw2_dsk.c", MAME_DIR .. "src/lib/formats/bw2_dsk.h", MAME_DIR .. "src/lib/formats/bw12_dsk.c", diff --git a/src/lib/formats/bbc_dsk.c b/src/lib/formats/bbc_dsk.c new file mode 100644 index 00000000000..dfa78c0bfd8 --- /dev/null +++ b/src/lib/formats/bbc_dsk.c @@ -0,0 +1,53 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#include "bbc_dsk.h" + +bbc_format::bbc_format() : wd177x_format(formats) +{ +} + +const char *bbc_format::name() const +{ + return "bbc"; +} + +const char *bbc_format::description() const +{ + return "BBC Micro disk image"; +} + +const char *bbc_format::extensions() const +{ + return "bbc,img,ssd,dsd"; +} + +const bbc_format::format bbc_format::formats[] = +{ + { // 100k single sided single density + floppy_image::FF_525, floppy_image::SSSD, floppy_image::FM, + 4000, 10, 40, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k double sided single density + floppy_image::FF_525, floppy_image::DSSD, floppy_image::FM, + 4000, 10, 40, 2, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k single sided double density + floppy_image::FF_525, floppy_image::SSQD, floppy_image::FM, + 4000, 10, 80, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 400k double sided double density + floppy_image::FF_525, floppy_image::DSQD, floppy_image::FM, + 4000, 10, 80, 2, 256, {}, 0, {}, 16, 11, 19 + }, + {} +}; + +const floppy_format_type FLOPPY_BBC_FORMAT = &floppy_image_format_creator; diff --git a/src/lib/formats/bbc_dsk.h b/src/lib/formats/bbc_dsk.h new file mode 100644 index 00000000000..e2520781a15 --- /dev/null +++ b/src/lib/formats/bbc_dsk.h @@ -0,0 +1,33 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#pragma once + +#ifndef __BBC_DSK_H__ +#define __BBC_DSK_H__ + +#include "wd177x_dsk.h" + +class bbc_format : public wd177x_format +{ +public: + bbc_format(); + + virtual const char *name() const; + virtual const char *description() const; + virtual const char *extensions() const; + +private: + static const format formats[]; +}; + +extern const floppy_format_type FLOPPY_BBC_FORMAT; + +#endif // __BBC_DSK_H__ diff --git a/src/mess/drivers/bbc.c b/src/mess/drivers/bbc.c index ca639730143..de7f17dee44 100644 --- a/src/mess/drivers/bbc.c +++ b/src/mess/drivers/bbc.c @@ -57,6 +57,7 @@ /* Devices */ #include "imagedev/flopdrv.h" +#include "formats/bbc_dsk.h" #include "formats/basicdsk.h" #include "imagedev/cassette.h" #include "formats/uef_cas.h" @@ -609,6 +610,19 @@ static const floppy_interface bbc_floppy_interface = "floppy_5_25" }; +FLOPPY_FORMATS_MEMBER( bbc_state::floppy_formats ) + FLOPPY_BBC_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( bbc_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) + SLOT_INTERFACE("sd", FLOPPY_525_SD) + SLOT_INTERFACE("ssdd", FLOPPY_525_SSDD) + SLOT_INTERFACE("dd", FLOPPY_525_DD) + SLOT_INTERFACE("ssqd", FLOPPY_525_SSQD) + SLOT_INTERFACE("qd", FLOPPY_525_QD) +SLOT_INTERFACE_END + WRITE_LINE_MEMBER(bbc_state::econet_clk_w) { m_adlc->rxc_w(state); @@ -760,13 +774,15 @@ static MACHINE_CONFIG_DERIVED( bbcb, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -822,13 +838,15 @@ static MACHINE_CONFIG_DERIVED( bbcb_us, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -852,6 +870,8 @@ static MACHINE_CONFIG_DERIVED( bbcbp, bbcb ) /* fdc */ MCFG_DEVICE_REMOVE("i8271") + MCFG_DEVICE_REMOVE(FLOPPY_0) + MCFG_DEVICE_REMOVE(FLOPPY_1) MACHINE_CONFIG_END @@ -981,12 +1001,12 @@ static MACHINE_CONFIG_START( bbcm, bbc_state ) MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w)) /* fdc */ - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* econet */ MCFG_DEVICE_ADD("mc6854", MC6854, 0) @@ -1068,10 +1088,14 @@ static MACHINE_CONFIG_DERIVED( bbcmc, bbcm ) /* fdc */ MCFG_DEVICE_REMOVE("wd177x") - MCFG_DEVICE_ADD("wd177x", WD1772, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + +// MCFG_WD1772x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* software lists */ MCFG_SOFTWARE_LIST_REMOVE("cart_ls_m") diff --git a/src/mess/includes/bbc.h b/src/mess/includes/bbc.h index 98e1c9b5a6c..11bd1c13eb1 100644 --- a/src/mess/includes/bbc.h +++ b/src/mess/includes/bbc.h @@ -20,7 +20,7 @@ #include "machine/mc6854.h" #include "machine/ram.h" #include "machine/i8271.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" #include "machine/upd7002.h" #include "video/mc6845.h" #include "video/saa5050.h" @@ -80,6 +80,8 @@ public: m_palette(*this, "palette") { } + DECLARE_FLOPPY_FORMATS(floppy_formats); + DECLARE_WRITE8_MEMBER(bbc_page_selecta_w); DECLARE_WRITE8_MEMBER(bbc_memorya1_w); DECLARE_WRITE8_MEMBER(bbc_page_selectb_w); diff --git a/src/mess/machine/bbc.c b/src/mess/machine/bbc.c index efc9da1102e..d0a5572540e 100644 --- a/src/mess/machine/bbc.c +++ b/src/mess/machine/bbc.c @@ -17,7 +17,7 @@ #include "cpu/m6502/m6502.h" #include "sound/tms5220.h" #include "machine/6522via.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" #include "imagedev/flopdrv.h" #include "includes/bbc.h" #include "machine/mc146818.h" @@ -1576,7 +1576,7 @@ void bbc_state::bbc_update_fdq_int(int state) /* do not trigger int */ bbc_state = 0; } - +//printf("bbc_state %d prev %d\n", bbc_state, m_previous_wd177x_int_state); /* nmi is edge triggered, and triggers when the state goes from clear->set. Here we are checking this transition before triggering the nmi */ if (bbc_state!=m_previous_wd177x_int_state) @@ -1594,6 +1594,7 @@ void bbc_state::bbc_update_fdq_int(int state) WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_intrq_w) { +//printf("bbc_wd177x_intrq_w %d \n", state); m_wd177x_irq_state = state; bbc_update_fdq_int(state); } @@ -1606,20 +1607,28 @@ WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_drq_w) WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; + + fdc->set_floppy(floppy); - /* set side */ - fdc->set_side((data>>2) & 0x01); + // bit 2: side select + if (floppy) + floppy->ss_w(BIT(data, 2)); - /* set density */ + // bit 3: density fdc->dden_w(BIT(data, 3)); - m_1770_IntEnabled=(((data>>4) & 0x01)==0); + // bit 4: interrupt enable + m_1770_IntEnabled = !BIT(data, 4); } @@ -1627,7 +1636,7 @@ WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) READ8_MEMBER(bbc_state::bbc_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 4: @@ -1645,22 +1654,22 @@ READ8_MEMBER(bbc_state::bbc_wd1770_read) default: break; } - logerror("wd177x read: $%02X $%02X\n", offset,retval); + //logerror("wd177x read: $%02X $%02X\n", offset,retval); return retval; } WRITE8_MEMBER(bbc_state::bbc_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: bbc_wd177x_status_w(space, 0, data); break; case 4: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 5: fdc->track_w(space, 0, data); @@ -1715,26 +1724,34 @@ AM_RANGE(0xfc00, 0xfdff) AM_READWRITE(bbc_opus_read , bbc_opus_write ) WRITE8_MEMBER(bbc_state::bbc_opus_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>1) & 0x01) fdc->set_drive(0); - if ((data>>2) & 0x01) fdc->set_drive(1); + // bit 1, 2: drive select + if (BIT(data, 1)) floppy = floppy0; + if (BIT(data, 2)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>0) & 0x01); + fdc->set_floppy(floppy); - /* set density */ + // bit 0: side select + if (floppy) + floppy->ss_w(BIT(data, 0)); + + // bit 5: density fdc->dden_w(BIT(data, 5)); - m_1770_IntEnabled=(data>>4) & 0x01; + // bit 4: interrupt enable + m_1770_IntEnabled = BIT(data, 4); } READ8_MEMBER(bbc_state::bbc_opus_read) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x read: $%02X\n", offset); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x read: $%02X\n", offset); if (m_DFSType==6) { @@ -1762,8 +1779,8 @@ READ8_MEMBER(bbc_state::bbc_opus_read) WRITE8_MEMBER(bbc_state::bbc_opus_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); if (m_DFSType==6) { @@ -1772,7 +1789,7 @@ WRITE8_MEMBER(bbc_state::bbc_opus_write) switch (offset) { case 0xf8: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 0xf9: fdc->track_w(space, 0, data); @@ -1810,7 +1827,7 @@ BBC MASTER DISC SUPPORT READ8_MEMBER(bbc_state::bbcm_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 0: @@ -1834,12 +1851,12 @@ READ8_MEMBER(bbc_state::bbcm_wd1770_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 1: fdc->track_w(space, 0, data); @@ -1863,22 +1880,26 @@ READ8_MEMBER(bbc_state::bbcm_wd1770l_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770l_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>4) & 0x01); + // bit 4: side select + if (floppy) + floppy->ss_w(BIT(data, 4)); - /* set density */ + // bit 5: density fdc->dden_w(BIT(data, 5)); // m_1770_IntEnabled=(((data>>4) & 0x01)==0); m_1770_IntEnabled=1; - } -- cgit v1.2.3 From cef370aa13953c3bcfa185c818c76812c34f13fc Mon Sep 17 00:00:00 2001 From: couriersud Date: Wed, 27 May 2015 13:47:22 +0200 Subject: Moved all files in src/emu/netlist starting with p into plib folder. This is a first step to ease synchronisation with a stand alone, e.g. outside mame, netlist implementation. More signed/unsigned cleanups and started work on generic truthtable devices. (nw) --- nl_examples/todo.c | 56 ++- scripts/src/netlist.lua | 21 +- scripts/src/tools.lua | 2 +- src/emu/netlist/analog/nld_ms_direct.h | 96 ++--- src/emu/netlist/analog/nld_ms_sor.h | 8 +- src/emu/netlist/analog/nld_ms_sor_mat.h | 14 +- src/emu/netlist/analog/nld_solver.c | 2 +- src/emu/netlist/analog/nld_solver.h | 4 +- src/emu/netlist/devices/nld_system.c | 2 +- src/emu/netlist/devices/nld_truthtable.c | 28 +- src/emu/netlist/devices/nld_truthtable.h | 76 +++- src/emu/netlist/nl_base.c | 3 +- src/emu/netlist/nl_base.h | 9 +- src/emu/netlist/nl_config.h | 2 +- src/emu/netlist/nl_factory.c | 12 +- src/emu/netlist/nl_factory.h | 14 +- src/emu/netlist/nl_parser.c | 4 +- src/emu/netlist/nl_parser.h | 2 +- src/emu/netlist/nl_setup.c | 6 +- src/emu/netlist/nl_time.h | 2 +- src/emu/netlist/nl_util.h | 66 +--- src/emu/netlist/palloc.c | 23 -- src/emu/netlist/palloc.h | 109 ------ src/emu/netlist/pconfig.h | 82 ----- src/emu/netlist/plib/palloc.c | 23 ++ src/emu/netlist/plib/palloc.h | 109 ++++++ src/emu/netlist/plib/pconfig.h | 99 ++++++ src/emu/netlist/plib/plists.h | 585 +++++++++++++++++++++++++++++++ src/emu/netlist/plib/poptions.h | 213 +++++++++++ src/emu/netlist/plib/pparser.c | 407 +++++++++++++++++++++ src/emu/netlist/plib/pparser.h | 178 ++++++++++ src/emu/netlist/plib/pstate.c | 77 ++++ src/emu/netlist/plib/pstate.h | 162 +++++++++ src/emu/netlist/plib/pstring.c | 360 +++++++++++++++++++ src/emu/netlist/plib/pstring.h | 256 ++++++++++++++ src/emu/netlist/plists.h | 513 --------------------------- src/emu/netlist/poptions.h | 213 ----------- src/emu/netlist/pparser.c | 407 --------------------- src/emu/netlist/pparser.h | 178 ---------- src/emu/netlist/pstate.c | 77 ---- src/emu/netlist/pstate.h | 162 --------- src/emu/netlist/pstring.c | 360 ------------------- src/emu/netlist/pstring.h | 256 -------------- src/tools/nltool.c | 41 +-- 44 files changed, 2723 insertions(+), 2596 deletions(-) delete mode 100644 src/emu/netlist/palloc.c delete mode 100644 src/emu/netlist/palloc.h delete mode 100644 src/emu/netlist/pconfig.h create mode 100644 src/emu/netlist/plib/palloc.c create mode 100644 src/emu/netlist/plib/palloc.h create mode 100644 src/emu/netlist/plib/pconfig.h create mode 100644 src/emu/netlist/plib/plists.h create mode 100644 src/emu/netlist/plib/poptions.h create mode 100644 src/emu/netlist/plib/pparser.c create mode 100644 src/emu/netlist/plib/pparser.h create mode 100644 src/emu/netlist/plib/pstate.c create mode 100644 src/emu/netlist/plib/pstate.h create mode 100644 src/emu/netlist/plib/pstring.c create mode 100644 src/emu/netlist/plib/pstring.h delete mode 100644 src/emu/netlist/plists.h delete mode 100644 src/emu/netlist/poptions.h delete mode 100644 src/emu/netlist/pparser.c delete mode 100644 src/emu/netlist/pparser.h delete mode 100644 src/emu/netlist/pstate.c delete mode 100644 src/emu/netlist/pstate.h delete mode 100644 src/emu/netlist/pstring.c delete mode 100644 src/emu/netlist/pstring.h (limited to 'scripts/src') diff --git a/nl_examples/todo.c b/nl_examples/todo.c index 9da1a2c66f6..9d7765ea925 100644 --- a/nl_examples/todo.c +++ b/nl_examples/todo.c @@ -3,6 +3,60 @@ * */ +#include "netlist/devices/net_lib.h" + +struct ttd +{ + nl_util::pstring_list a; +}; + +ttd * nl_register_tt(pstring name, int in, int out); + + +#define NETLIST_TT(_name, _in, _out) \ + { \ + ttd *a = setup.register_tt(# _name, _in, _out); \ + +#define TT_LINE(_x) \ + a->a.add(_x); + +#define TT_END() } + +NETLIST_START(7400_TTL) + NET_REGISTER_DEV(7400, s1) + NET_REGISTER_DEV(7400, s2) + NET_REGISTER_DEV(7400, s3) + NET_REGISTER_DEV(7400, s4) + + ALIAS(1, s1.A); + ALIAS(2, s1.B); + ALIAS(3, s1.Q); + + ALIAS(4, s2.A); + ALIAS(5, s2.B); + ALIAS(6, s2.Q); + + ALIAS(9, s3.A); + ALIAS(10, s3.B) + ALIAS(8, s3.Q); + + ALIAS(12, s4.A); + ALIAS(13, s4.B); + ALIAS(11, s4.Q); + +NETLIST_END() + +NETLIST_START(lib) + NETLIST_TT(7400, 2, 1) + TT_LINE("A,B | Q ") + TT_LINE("0,X|1|22") + TT_LINE("X,0|1|22") + TT_LINE("1,1|0|15") + TT_END() +NETLIST_END() + + + #if 0 RES(R1, 10) RES(R2, 10) @@ -98,4 +152,4 @@ LOG(logY, 4V) #endif -d + diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index d1f9c97a74b..9d61b0d4892 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -15,16 +15,17 @@ files { MAME_DIR .. "src/emu/netlist/nl_setup.h", MAME_DIR .. "src/emu/netlist/nl_factory.c", MAME_DIR .. "src/emu/netlist/nl_factory.h", - MAME_DIR .. "src/emu/netlist/pconfig.h", - MAME_DIR .. "src/emu/netlist/palloc.c", - MAME_DIR .. "src/emu/netlist/palloc.h", - MAME_DIR .. "src/emu/netlist/plists.h", - MAME_DIR .. "src/emu/netlist/pparser.c", - MAME_DIR .. "src/emu/netlist/pparser.h", - MAME_DIR .. "src/emu/netlist/pstate.c", - MAME_DIR .. "src/emu/netlist/pstate.h", - MAME_DIR .. "src/emu/netlist/pstring.c", - MAME_DIR .. "src/emu/netlist/pstring.h", + MAME_DIR .. "src/emu/netlist/plib/pconfig.h", + MAME_DIR .. "src/emu/netlist/plib/palloc.c", + MAME_DIR .. "src/emu/netlist/plib/palloc.h", + MAME_DIR .. "src/emu/netlist/plib/plists.h", + MAME_DIR .. "src/emu/netlist/plib/poptions.h", + MAME_DIR .. "src/emu/netlist/plib/pparser.c", + MAME_DIR .. "src/emu/netlist/plib/pparser.h", + MAME_DIR .. "src/emu/netlist/plib/pstate.c", + MAME_DIR .. "src/emu/netlist/plib/pstate.h", + MAME_DIR .. "src/emu/netlist/plib/pstring.c", + MAME_DIR .. "src/emu/netlist/plib/pstring.h", MAME_DIR .. "src/emu/netlist/analog/nld_bjt.c", MAME_DIR .. "src/emu/netlist/analog/nld_bjt.h", MAME_DIR .. "src/emu/netlist/analog/nld_fourterm.c", diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index 0c1cbc3075e..936afb54346 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -448,7 +448,7 @@ links { includedirs { MAME_DIR .. "src/osd", MAME_DIR .. "src/lib/util", - MAME_DIR .. "src/emu", + MAME_DIR .. "src/emu/netlist", } files { diff --git a/src/emu/netlist/analog/nld_ms_direct.h b/src/emu/netlist/analog/nld_ms_direct.h index 08894933000..b5021e1c9f6 100644 --- a/src/emu/netlist/analog/nld_ms_direct.h +++ b/src/emu/netlist/analog/nld_ms_direct.h @@ -10,7 +10,7 @@ #include "nld_solver.h" -template +template class netlist_matrix_solver_direct_t: public netlist_matrix_solver_t { public: @@ -23,7 +23,7 @@ public: /* ATTR_COLD */ virtual void vsetup(netlist_analog_net_t::list_t &nets); /* ATTR_COLD */ virtual void reset() { netlist_matrix_solver_t::reset(); } - ATTR_HOT inline int N() const { return (m_N == 0 ? m_dim : m_N); } + ATTR_HOT inline unsigned N() const { if (m_N == 0) return m_dim; else return m_N; } ATTR_HOT inline int vsolve_non_dynamic(const bool newton_raphson); @@ -56,7 +56,7 @@ protected: private: - const int m_dim; + const unsigned m_dim; nl_double m_lp_fact; }; @@ -64,10 +64,10 @@ private: // netlist_matrix_solver_direct // ---------------------------------------------------------------------------------------- -template +template netlist_matrix_solver_direct_t::~netlist_matrix_solver_direct_t() { - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { pfree(m_terms[k]); } @@ -75,7 +75,7 @@ netlist_matrix_solver_direct_t::~netlist_matrix_solver_direct_t pfree_array(m_rails_temp); } -template +template ATTR_HOT nl_double netlist_matrix_solver_direct_t::compute_next_timestep() { nl_double new_solver_timestep = m_params.m_max_timestep; @@ -86,7 +86,7 @@ ATTR_HOT nl_double netlist_matrix_solver_direct_t::compute_next * FIXME: We should extend the logic to use either all nets or * only output nets. */ - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { netlist_analog_net_t *n = m_nets[k]; @@ -114,7 +114,7 @@ ATTR_HOT nl_double netlist_matrix_solver_direct_t::compute_next return new_solver_timestep; } -template +template ATTR_COLD void netlist_matrix_solver_direct_t::add_term(int k, netlist_terminal_t *term) { if (term->m_otherterm->net().isRailNet()) @@ -139,13 +139,13 @@ ATTR_COLD void netlist_matrix_solver_direct_t::add_term(int k, } -template +template ATTR_COLD void netlist_matrix_solver_direct_t::vsetup(netlist_analog_net_t::list_t &nets) { if (m_dim < nets.size()) netlist().error("Dimension %d less than %" SIZETFMT, m_dim, nets.size()); - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { m_terms[k]->clear(); m_rails_temp[k].clear(); @@ -153,10 +153,10 @@ ATTR_COLD void netlist_matrix_solver_direct_t::vsetup(netlist_a netlist_matrix_solver_t::setup(nets); - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { m_terms[k]->m_railstart = m_terms[k]->count(); - for (int i = 0; i < m_rails_temp[k].count(); i++) + for (unsigned i = 0; i < m_rails_temp[k].count(); i++) this->m_terms[k]->add(m_rails_temp[k].terms()[i], m_rails_temp[k].net_other()[i]); m_rails_temp[k].clear(); // no longer needed @@ -187,8 +187,8 @@ ATTR_COLD void netlist_matrix_solver_direct_t::vsetup(netlist_a int sort_order = (type() == GAUSS_SEIDEL ? 1 : -1); - for (int k = 0; k < N() / 2; k++) - for (int i = 0; i < N() - 1; i++) + for (unsigned k = 0; k < N() / 2; k++) + for (unsigned i = 0; i < N() - 1; i++) { if ((m_terms[i]->m_railstart - m_terms[i+1]->m_railstart) * sort_order < 0) { @@ -197,10 +197,10 @@ ATTR_COLD void netlist_matrix_solver_direct_t::vsetup(netlist_a } } - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { int *other = m_terms[k]->net_other(); - for (int i = 0; i < m_terms[k]->count(); i++) + for (unsigned i = 0; i < m_terms[k]->count(); i++) if (other[i] != -1) other[i] = get_net_idx(&m_terms[k]->terms()[i]->m_otherterm->net()); } @@ -209,35 +209,35 @@ ATTR_COLD void netlist_matrix_solver_direct_t::vsetup(netlist_a } -template +template ATTR_HOT void netlist_matrix_solver_direct_t::build_LE_A() { - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { - for (int i=0; i < N(); i++) + for (unsigned i=0; i < N(); i++) m_A[k][i] = 0.0; nl_double akk = 0.0; - const int terms_count = m_terms[k]->count(); - const int railstart = m_terms[k]->m_railstart; + const unsigned terms_count = m_terms[k]->count(); + const unsigned railstart = m_terms[k]->m_railstart; const nl_double * RESTRICT gt = m_terms[k]->gt(); const nl_double * RESTRICT go = m_terms[k]->go(); const int * RESTRICT net_other = m_terms[k]->net_other(); - for (int i = 0; i < terms_count; i++) + for (unsigned i = 0; i < terms_count; i++) akk = akk + gt[i]; m_A[k][k] += akk; - for (int i = 0; i < railstart; i++) + for (unsigned i = 0; i < railstart; i++) m_A[k][net_other[i]] += -go[i]; } } -template +template ATTR_HOT void netlist_matrix_solver_direct_t::build_LE_RHS() { - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { nl_double rhsk_a = 0.0; nl_double rhsk_b = 0.0; @@ -258,7 +258,7 @@ ATTR_HOT void netlist_matrix_solver_direct_t::build_LE_RHS() } } -template +template ATTR_HOT void netlist_matrix_solver_direct_t::LE_solve() { #if 0 @@ -271,15 +271,15 @@ ATTR_HOT void netlist_matrix_solver_direct_t::LE_solve() printf("\n"); #endif - const int kN = N(); + const unsigned kN = N(); - for (int i = 0; i < kN; i++) { + for (unsigned i = 0; i < kN; i++) { // FIXME: use a parameter to enable pivoting? if (USE_PIVOT_SEARCH) { /* Find the row with the largest first value */ - int maxrow = i; - for (int j = i + 1; j < kN; j++) + unsigned maxrow = i; + for (unsigned j = i + 1; j < kN; j++) { if (nl_math::abs(m_A[j][i]) > nl_math::abs(m_A[maxrow][i])) maxrow = j; @@ -288,7 +288,7 @@ ATTR_HOT void netlist_matrix_solver_direct_t::LE_solve() if (maxrow != i) { /* Swap the maxrow and ith row */ - for (int k = i; k < kN; k++) { + for (unsigned k = i; k < kN; k++) { std::swap(m_A[i][k], m_A[maxrow][k]); } std::swap(m_RHS[i], m_RHS[maxrow]); @@ -300,12 +300,12 @@ ATTR_HOT void netlist_matrix_solver_direct_t::LE_solve() /* Eliminate column i from row j */ - for (int j = i + 1; j < kN; j++) + for (unsigned j = i + 1; j < kN; j++) { const nl_double f1 = - m_A[j][i] * f; if (f1 != NL_FCONST(0.0)) { - for (int k = i + 1; k < kN; k++) + for (unsigned k = i + 1; k < kN; k++) m_A[j][k] += m_A[i][k] * f1; m_RHS[j] += m_RHS[i] * f1; } @@ -313,18 +313,18 @@ ATTR_HOT void netlist_matrix_solver_direct_t::LE_solve() } } -template +template ATTR_HOT void netlist_matrix_solver_direct_t::LE_back_subst( nl_double * RESTRICT x) { - const int kN = N(); + const unsigned kN = N(); /* back substitution */ for (int j = kN - 1; j >= 0; j--) { nl_double tmp = 0; - for (int k = j + 1; k < kN; k++) + for (unsigned k = j + 1; k < kN; k++) tmp += m_A[j][k] * x[k]; x[j] = (m_RHS[j] - tmp) / m_A[j][j]; @@ -342,13 +342,13 @@ ATTR_HOT void netlist_matrix_solver_direct_t::LE_back_subst( } -template +template ATTR_HOT nl_double netlist_matrix_solver_direct_t::delta( const nl_double * RESTRICT V) { nl_double cerr = 0; nl_double cerr2 = 0; - for (int i = 0; i < this->N(); i++) + for (unsigned i = 0; i < this->N(); i++) { const nl_double e = nl_math::abs(V[i] - this->m_nets[i]->m_cur_Analog); const nl_double e2 = nl_math::abs(m_RHS[i] - this->m_last_RHS[i]); @@ -359,24 +359,24 @@ ATTR_HOT nl_double netlist_matrix_solver_direct_t::delta( return cerr + cerr2*NL_FCONST(100000.0); } -template +template ATTR_HOT void netlist_matrix_solver_direct_t::store( const nl_double * RESTRICT V, const bool store_RHS) { - for (int i = 0; i < this->N(); i++) + for (unsigned i = 0; i < this->N(); i++) { this->m_nets[i]->m_cur_Analog = V[i]; } if (store_RHS) { - for (int i = 0; i < this->N(); i++) + for (unsigned i = 0; i < this->N(); i++) { this->m_last_RHS[i] = m_RHS[i]; } } } -template +template ATTR_HOT nl_double netlist_matrix_solver_direct_t::vsolve() { solve_base(this); @@ -384,7 +384,7 @@ ATTR_HOT nl_double netlist_matrix_solver_direct_t::vsolve() } -template +template ATTR_HOT int netlist_matrix_solver_direct_t::solve_non_dynamic(ATTR_UNUSED const bool newton_raphson) { nl_double new_v[_storage_N]; // = { 0.0 }; @@ -406,7 +406,7 @@ ATTR_HOT int netlist_matrix_solver_direct_t::solve_non_dynamic( } } -template +template ATTR_HOT inline int netlist_matrix_solver_direct_t::vsolve_non_dynamic(const bool newton_raphson) { this->build_LE_A(); @@ -416,7 +416,7 @@ ATTR_HOT inline int netlist_matrix_solver_direct_t::vsolve_non_ return this->solve_non_dynamic(newton_raphson); } -template +template netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t(const netlist_solver_parameters_t ¶ms, const int size) : netlist_matrix_solver_t(GAUSSIAN_ELIMINATION, params) , m_dim(size) @@ -425,7 +425,7 @@ netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t( m_terms = palloc_array(terms_t *, N()); m_rails_temp = palloc_array(terms_t, N()); - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { m_terms[k] = palloc(terms_t); m_last_RHS[k] = 0.0; @@ -433,7 +433,7 @@ netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t( } } -template +template netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t(const eSolverType type, const netlist_solver_parameters_t ¶ms, const int size) : netlist_matrix_solver_t(type, params) , m_dim(size) @@ -442,7 +442,7 @@ netlist_matrix_solver_direct_t::netlist_matrix_solver_direct_t( m_terms = palloc_array(terms_t *, N()); m_rails_temp = palloc_array(terms_t, N()); - for (int k = 0; k < N(); k++) + for (unsigned k = 0; k < N(); k++) { m_terms[k] = palloc(terms_t); m_last_RHS[k] = 0.0; diff --git a/src/emu/netlist/analog/nld_ms_sor.h b/src/emu/netlist/analog/nld_ms_sor.h index 11ee4273d62..25799dbb1e6 100644 --- a/src/emu/netlist/analog/nld_ms_sor.h +++ b/src/emu/netlist/analog/nld_ms_sor.h @@ -15,7 +15,7 @@ #include "nld_solver.h" #include "nld_ms_direct.h" -template +template class netlist_matrix_solver_SOR_t: public netlist_matrix_solver_direct_t { public: @@ -46,7 +46,7 @@ private: // netlist_matrix_solver - Gauss - Seidel // ---------------------------------------------------------------------------------------- -template +template void netlist_matrix_solver_SOR_t::log_stats() { if (this->m_stat_calculations != 0 && this->m_params.m_log_stats) @@ -66,14 +66,14 @@ void netlist_matrix_solver_SOR_t::log_stats() } } -template +template ATTR_HOT nl_double netlist_matrix_solver_SOR_t::vsolve() { this->solve_base(this); return this->compute_next_timestep(); } -template +template ATTR_HOT inline int netlist_matrix_solver_SOR_t::vsolve_non_dynamic(const bool newton_raphson) { const int iN = this->N(); diff --git a/src/emu/netlist/analog/nld_ms_sor_mat.h b/src/emu/netlist/analog/nld_ms_sor_mat.h index 184df6313ff..9c5a29382f1 100644 --- a/src/emu/netlist/analog/nld_ms_sor_mat.h +++ b/src/emu/netlist/analog/nld_ms_sor_mat.h @@ -15,7 +15,7 @@ #include "nld_solver.h" #include "nld_ms_direct.h" -template +template class netlist_matrix_solver_SOR_mat_t: public netlist_matrix_solver_direct_t { public: @@ -57,7 +57,7 @@ private: // netlist_matrix_solver - Gauss - Seidel // ---------------------------------------------------------------------------------------- -template +template void netlist_matrix_solver_SOR_mat_t::log_stats() { if (this->m_stat_calculations != 0 && m_log_stats) @@ -77,7 +77,7 @@ void netlist_matrix_solver_SOR_mat_t::log_stats() } } -template +template ATTR_HOT nl_double netlist_matrix_solver_SOR_mat_t::vsolve() { /* @@ -85,13 +85,13 @@ ATTR_HOT nl_double netlist_matrix_solver_SOR_mat_t::vsolve() */ if (USE_LINEAR_PREDICTION) - for (int k = 0; k < this->N(); k++) + for (unsigned k = 0; k < this->N(); k++) { this->m_last_V[k] = this->m_nets[k]->m_cur_Analog; this->m_nets[k]->m_cur_Analog = this->m_nets[k]->m_cur_Analog + this->m_Vdelta[k] * this->current_timestep() * m_lp_fact; } else - for (int k = 0; k < this->N(); k++) + for (unsigned k = 0; k < this->N(); k++) { this->m_last_V[k] = this->m_nets[k]->m_cur_Analog; } @@ -103,7 +103,7 @@ ATTR_HOT nl_double netlist_matrix_solver_SOR_mat_t::vsolve() nl_double sq = 0; nl_double sqo = 0; const nl_double rez_cts = 1.0 / this->current_timestep(); - for (int k = 0; k < this->N(); k++) + for (unsigned k = 0; k < this->N(); k++) { const netlist_analog_net_t *n = this->m_nets[k]; const nl_double nv = (n->m_cur_Analog - this->m_last_V[k]) * rez_cts ; @@ -123,7 +123,7 @@ ATTR_HOT nl_double netlist_matrix_solver_SOR_mat_t::vsolve() return this->compute_next_timestep(); } -template +template ATTR_HOT inline int netlist_matrix_solver_SOR_mat_t::vsolve_non_dynamic(const bool newton_raphson) { /* The matrix based code looks a lot nicer but actually is 30% slower than diff --git a/src/emu/netlist/analog/nld_solver.c b/src/emu/netlist/analog/nld_solver.c index 703f6f35770..3d1eaf5b636 100644 --- a/src/emu/netlist/analog/nld_solver.c +++ b/src/emu/netlist/analog/nld_solver.c @@ -51,7 +51,7 @@ ATTR_COLD void terms_t::add(netlist_terminal_t *term, int net_other) ATTR_COLD void terms_t::set_pointers() { - for (int i = 0; i < count(); i++) + for (unsigned i = 0; i < count(); i++) { m_term[i]->m_gt1 = &m_gt[i]; m_term[i]->m_go1 = &m_go[i]; diff --git a/src/emu/netlist/analog/nld_solver.h b/src/emu/netlist/analog/nld_solver.h index 874c8dc7e1d..7ab2f4a7733 100644 --- a/src/emu/netlist/analog/nld_solver.h +++ b/src/emu/netlist/analog/nld_solver.h @@ -65,7 +65,7 @@ class terms_t ATTR_COLD void add(netlist_terminal_t *term, int net_other); - ATTR_HOT inline int count() { return m_term.size(); } + ATTR_HOT inline unsigned count() { return m_term.size(); } ATTR_HOT inline netlist_terminal_t **terms() { return m_term.data(); } ATTR_HOT inline int *net_other() { return m_net_other.data(); } @@ -76,7 +76,7 @@ class terms_t ATTR_COLD void set_pointers(); - int m_railstart; + unsigned m_railstart; private: plist_t m_term; diff --git a/src/emu/netlist/devices/nld_system.c b/src/emu/netlist/devices/nld_system.c index f97a0e14147..b7a5cf6c71e 100644 --- a/src/emu/netlist/devices/nld_system.c +++ b/src/emu/netlist/devices/nld_system.c @@ -76,7 +76,7 @@ NETLIB_START(extclock) connect(m_feedback, m_Q); { netlist_time base = netlist_time::from_hz(m_freq.Value()*2); - nl_util::pstring_list pat = nl_util::split(m_pattern.Value(),","); + pstring_list_t pat(m_pattern.Value(),","); m_off = netlist_time::from_double(m_offset.Value()); int pati[256]; diff --git a/src/emu/netlist/devices/nld_truthtable.c b/src/emu/netlist/devices/nld_truthtable.c index 85fc56ac34b..4d32c079ac3 100644 --- a/src/emu/netlist/devices/nld_truthtable.c +++ b/src/emu/netlist/devices/nld_truthtable.c @@ -6,7 +6,7 @@ */ #include "nld_truthtable.h" -#include "../plists.h" +#include "../plib/plists.h" unsigned truthtable_desc_t::count_bits(UINT32 v) { @@ -97,7 +97,7 @@ UINT32 truthtable_desc_t::get_ignored_extended(UINT32 i) // desc // ---------------------------------------------------------------------------------------- -ATTR_COLD void truthtable_desc_t::help(unsigned cur, nl_util::pstring_list list, +ATTR_COLD void truthtable_desc_t::help(unsigned cur, pstring_list_t list, UINT64 state,UINT16 val, UINT8 *timing_index) { pstring elem = list[cur].trim(); @@ -142,15 +142,17 @@ ATTR_COLD void truthtable_desc_t::help(unsigned cur, nl_util::pstring_list list, } } -ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled_ignore) +ATTR_COLD void truthtable_desc_t::setup(const pstring_list_t &truthtable, UINT32 disabled_ignore) { + unsigned line = 0; + if (*m_initialized) return; - pstring ttline = pstring(truthtable[0]); - truthtable++; - ttline = pstring(truthtable[0]); - truthtable++; + pstring ttline = truthtable[line]; + line++; + ttline = truthtable[line]; + line++; for (unsigned j=0; j < m_size; j++) m_outs[j] = ~0L; @@ -160,14 +162,14 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled while (!ttline.equals("")) { - nl_util::pstring_list io = nl_util::split(ttline,"|"); + pstring_list_t io(ttline,"|"); // checks nl_assert_always(io.size() == 3, "io.count mismatch"); - nl_util::pstring_list inout = nl_util::split(io[0], ","); + pstring_list_t inout(io[0], ","); nl_assert_always(inout.size() == m_num_bits, "number of bits not matching"); - nl_util::pstring_list out = nl_util::split(io[1], ","); + pstring_list_t out(io[1], ","); nl_assert_always(out.size() == m_NO, "output count not matching"); - nl_util::pstring_list times = nl_util::split(io[2], ","); + pstring_list_t times(io[2], ","); nl_assert_always(times.size() == m_NO, "timing count not matching"); UINT16 val = 0; @@ -189,8 +191,8 @@ ATTR_COLD void truthtable_desc_t::setup(const char **truthtable, UINT32 disabled } help(0, inout, 0 , val, tindex.data()); - ttline = pstring(truthtable[0]); - truthtable++; + ttline = truthtable[line]; + line++; } // determine ignore diff --git a/src/emu/netlist/devices/nld_truthtable.h b/src/emu/netlist/devices/nld_truthtable.h index d12dd3c578b..cf52be69164 100644 --- a/src/emu/netlist/devices/nld_truthtable.h +++ b/src/emu/netlist/devices/nld_truthtable.h @@ -11,6 +11,7 @@ #define NLD_TRUTHTABLE_H_ #include "../nl_base.h" +#include "../nl_factory.h" #define NETLIB_TRUTHTABLE(_name, _nIN, _nOUT, _state) \ class NETLIB_NAME(_name) : public nld_truthtable_t<_nIN, _nOUT, _state> \ @@ -44,10 +45,10 @@ struct truthtable_desc_t { } - ATTR_COLD void setup(const char **truthtable, UINT32 disabled_ignore); + ATTR_COLD void setup(const pstring_list_t &desc, UINT32 disabled_ignore); private: - ATTR_COLD void help(unsigned cur, nl_util::pstring_list list, + ATTR_COLD void help(unsigned cur, pstring_list_t list, UINT64 state,UINT16 val, UINT8 *timing_index); static unsigned count_bits(UINT32 v); static UINT32 set_bits(UINT32 v, UINT32 b); @@ -89,28 +90,40 @@ public: }; nld_truthtable_t(truthtable_t *ttbl, const char *desc[]) - : netlist_device_t(), m_last_state(0), m_ign(0), m_active(1), m_ttp(ttbl), m_desc(desc) + : netlist_device_t(), m_last_state(0), m_ign(0), m_active(1), m_ttp(ttbl) { + while (*desc != NULL && **desc != 0 ) + { + m_desc.add(*desc); + desc++; + } + + } + + nld_truthtable_t(truthtable_t *ttbl, const pstring_list_t &desc) + : netlist_device_t(), m_last_state(0), m_ign(0), m_active(1), m_ttp(ttbl) + { + m_desc = desc; } /* ATTR_COLD */ virtual void start() { - pstring ttline = pstring(m_desc[0]); + pstring header = m_desc[0]; - nl_util::pstring_list io = nl_util::split(ttline,"|"); + pstring_list_t io(header,"|"); // checks nl_assert_always(io.size() == 2, "too many '|'"); - nl_util::pstring_list inout = nl_util::split(io[0], ","); + pstring_list_t inout(io[0], ","); nl_assert_always(inout.size() == m_num_bits, "bitcount wrong"); - nl_util::pstring_list out = nl_util::split(io[1], ","); + pstring_list_t out(io[1], ","); nl_assert_always(out.size() == m_NO, "output count wrong"); - for (int i=0; i < m_NI; i++) + for (unsigned i=0; i < m_NI; i++) { inout[i] = inout[i].trim(); register_input(inout[i], m_i[i]); } - for (int i=0; i < m_NO; i++) + for (unsigned i=0; i < m_NO; i++) { out[i] = out[i].trim(); register_output(out[i], m_Q[i]); @@ -118,7 +131,7 @@ public: // Connect output "Q" to input "_Q" if this exists // This enables timed state without having explicit state .... UINT32 disabled_ignore = 0; - for (int i=0; i < m_NO; i++) + for (unsigned i=0; i < m_NO; i++) { pstring tmp = "_" + out[i]; const int idx = inout.indexof(tmp); @@ -154,7 +167,7 @@ public: ATTR_COLD void reset() { m_active = 0; - for (int i=0; im_Q[i].net().num_cons()>0) m_active++; m_last_state = 0; @@ -193,14 +206,14 @@ public: const UINT32 timebase = nstate * m_NO; if (doOUT) { - for (int i = 0; i < m_NO; i++) + for (unsigned i = 0; i < m_NO; i++) OUTLOGIC(m_Q[i], (out >> i) & 1, m_ttp->m_timing_nt[m_ttp->m_timing[timebase + i]]); } else - for (int i = 0; i < m_NO; i++) + for (unsigned i = 0; i < m_NO; i++) m_Q[i].net().set_Q_time((out >> i) & 1, mt + m_ttp->m_timing_nt[m_ttp->m_timing[timebase + i]]); - for (int i = 0; i < m_NI; i++) + for (unsigned i = 0; i < m_NI; i++) if (m_ign & (1 << i)) m_i[i].inactivate(); @@ -227,7 +240,7 @@ public: if (has_state == 0) if (--m_active == 0) { - for (int i = 0; i< m_NI; i++) + for (unsigned i = 0; i< m_NI; i++) m_i[i].inactivate(); } } @@ -242,9 +255,40 @@ private: INT32 m_active; truthtable_t *m_ttp; - const char **m_desc; + pstring_list_t m_desc; }; +class net_device_t_base_factory_tt : public net_device_t_base_factory +{ + NETLIST_PREVENT_COPYING(net_device_t_base_factory_tt) +public: + ATTR_COLD net_device_t_base_factory_tt(const pstring &name, const pstring &classname, + const pstring &def_param) + : net_device_t_base_factory(name, classname, def_param) + {} + pstring_list_t m_desc; +}; + + +template +class net_device_t_factory_tt : public net_device_t_base_factory_tt +{ + NETLIST_PREVENT_COPYING(net_device_t_factory_tt) +public: + ATTR_COLD net_device_t_factory_tt(const pstring &name, const pstring &classname, + const pstring &def_param) + : net_device_t_base_factory(name, classname, def_param) { } + + ATTR_COLD netlist_device_t *Create() const + { + typedef nld_truthtable_t tt_type; + netlist_device_t *r = palloc(tt_type, &m_ttbl, m_desc); + //r->init(setup, name); + return r; + } +private: + typename nld_truthtable_t::truthtable_t m_ttbl; +}; diff --git a/src/emu/netlist/nl_base.c b/src/emu/netlist/nl_base.c index 0a8da9fda8b..1bc33ed7e37 100644 --- a/src/emu/netlist/nl_base.c +++ b/src/emu/netlist/nl_base.c @@ -7,12 +7,11 @@ #include -#include "palloc.h" +#include "plib/palloc.h" #include "nl_base.h" #include "devices/nld_system.h" #include "analog/nld_solver.h" -#include "pstring.h" #include "nl_util.h" const netlist_time netlist_time::zero = netlist_time::from_raw(0); diff --git a/src/emu/netlist/nl_base.h b/src/emu/netlist/nl_base.h index a293ec95dd4..a20309f7566 100644 --- a/src/emu/netlist/nl_base.h +++ b/src/emu/netlist/nl_base.h @@ -158,8 +158,7 @@ #include "nl_lists.h" #include "nl_time.h" #include "nl_util.h" -#include "pstring.h" -#include "pstate.h" +#include "plib/pstate.h" // ---------------------------------------------------------------------------------------- // Type definitions @@ -1197,7 +1196,7 @@ public: plist_t<_C *> get_device_list() { plist_t<_C *> tmp; - for (int i = 0; i < m_devices.size(); i++) + for (std::size_t i = 0; i < m_devices.size(); i++) { _C *dev = dynamic_cast<_C *>(m_devices[i]); if (dev != NULL) @@ -1209,7 +1208,7 @@ public: template _C *get_first_device() { - for (int i = 0; i < m_devices.size(); i++) + for (std::size_t i = 0; i < m_devices.size(); i++) { _C *dev = dynamic_cast<_C *>(m_devices[i]); if (dev != NULL) @@ -1222,7 +1221,7 @@ public: _C *get_single_device(const char *classname) { _C *ret = NULL; - for (int i = 0; i < m_devices.size(); i++) + for (std::size_t i = 0; i < m_devices.size(); i++) { _C *dev = dynamic_cast<_C *>(m_devices[i]); if (dev != NULL) diff --git a/src/emu/netlist/nl_config.h b/src/emu/netlist/nl_config.h index d01f6154e92..a7b493ac56d 100644 --- a/src/emu/netlist/nl_config.h +++ b/src/emu/netlist/nl_config.h @@ -8,7 +8,7 @@ #ifndef NLCONFIG_H_ #define NLCONFIG_H_ -#include "pconfig.h" +#include "plib/pconfig.h" //============================================================ // SETUP diff --git a/src/emu/netlist/nl_factory.c b/src/emu/netlist/nl_factory.c index 4c611af4c18..624b09bf023 100644 --- a/src/emu/netlist/nl_factory.c +++ b/src/emu/netlist/nl_factory.c @@ -15,20 +15,20 @@ // net_device_t_base_factory // ---------------------------------------------------------------------------------------- -ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::term_param_list() +ATTR_COLD const pstring_list_t net_device_t_base_factory::term_param_list() { if (m_def_param.startsWith("+")) - return nl_util::split(m_def_param.substr(1), ","); + return pstring_list_t(m_def_param.substr(1), ","); else - return nl_util::pstring_list(); + return pstring_list_t(); } -ATTR_COLD const nl_util::pstring_list net_device_t_base_factory::def_params() +ATTR_COLD const pstring_list_t net_device_t_base_factory::def_params() { if (m_def_param.startsWith("+") || m_def_param.equals("-")) - return nl_util::pstring_list(); + return pstring_list_t(); else - return nl_util::split(m_def_param, ","); + return pstring_list_t(m_def_param, ","); } diff --git a/src/emu/netlist/nl_factory.h b/src/emu/netlist/nl_factory.h index 970a5024c5a..224e90e7a31 100644 --- a/src/emu/netlist/nl_factory.h +++ b/src/emu/netlist/nl_factory.h @@ -10,10 +10,9 @@ #define NLFACTORY_H_ #include "nl_config.h" -#include "palloc.h" -#include "plists.h" +#include "plib/palloc.h" +#include "plib/plists.h" #include "nl_base.h" -#include "pstring.h" // ----------------------------------------------------------------------------- // net_dev class factory @@ -35,8 +34,8 @@ public: ATTR_COLD const pstring &name() const { return m_name; } ATTR_COLD const pstring &classname() const { return m_classname; } ATTR_COLD const pstring ¶m_desc() const { return m_def_param; } - ATTR_COLD const nl_util::pstring_list term_param_list(); - ATTR_COLD const nl_util::pstring_list def_params(); + ATTR_COLD const pstring_list_t term_param_list(); + ATTR_COLD const pstring_list_t def_params(); protected: pstring m_name; /* device name */ @@ -76,6 +75,11 @@ public: m_list.add(palloc(net_device_t_factory< _C >, name, classname, def_param)); } + ATTR_COLD void register_device(net_device_t_base_factory *factory) + { + m_list.add(factory); + } + ATTR_COLD netlist_device_t *new_device_by_classname(const pstring &classname) const; ATTR_COLD netlist_device_t *new_device_by_name(const pstring &name, netlist_setup_t &setup) const; ATTR_COLD net_device_t_base_factory * factory_by_name(const pstring &name, netlist_setup_t &setup) const; diff --git a/src/emu/netlist/nl_parser.c b/src/emu/netlist/nl_parser.c index 7d7b29733be..cb2534222b4 100644 --- a/src/emu/netlist/nl_parser.c +++ b/src/emu/netlist/nl_parser.c @@ -225,8 +225,8 @@ void netlist_parser::device(const pstring &dev_type) pstring devname; net_device_t_base_factory *f = m_setup.factory().factory_by_name(dev_type, m_setup); netlist_device_t *dev; - nl_util::pstring_list termlist = f->term_param_list(); - nl_util::pstring_list def_params = f->def_params(); + pstring_list_t termlist = f->term_param_list(); + pstring_list_t def_params = f->def_params(); std::size_t cnt; diff --git a/src/emu/netlist/nl_parser.h b/src/emu/netlist/nl_parser.h index 582aad49de7..b435a3194fb 100644 --- a/src/emu/netlist/nl_parser.h +++ b/src/emu/netlist/nl_parser.h @@ -10,7 +10,7 @@ #include "nl_setup.h" #include "nl_util.h" -#include "pparser.h" +#include "plib/pparser.h" class netlist_parser : public ptokenizer { diff --git a/src/emu/netlist/nl_setup.c b/src/emu/netlist/nl_setup.c index 6b98f14d452..b286f800945 100644 --- a/src/emu/netlist/nl_setup.c +++ b/src/emu/netlist/nl_setup.c @@ -7,7 +7,7 @@ #include -#include "palloc.h" +#include "plib/palloc.h" #include "nl_base.h" #include "nl_setup.h" #include "nl_parser.h" @@ -286,7 +286,7 @@ void netlist_setup_t::register_object(netlist_device_t &dev, const pstring &name void netlist_setup_t::register_link_arr(const pstring &terms) { - nl_util::pstring_list list = nl_util::split(terms,", "); + pstring_list_t list(terms,", "); if (list.size() < 2) netlist().error("You must pass at least 2 terminals to NET_C"); for (std::size_t i = 1; i < list.size(); i++) @@ -776,7 +776,7 @@ void netlist_setup_t::start_devices() if (env != "") { NL_VERBOSE_OUT(("Creating dynamic logs ...\n")); - nl_util::pstring_list ll = nl_util::split(env, ":"); + pstring_list_t ll(env, ":"); for (std::size_t i=0; i < ll.size(); i++) { NL_VERBOSE_OUT(("%d: <%s>\n",i, ll[i].cstr())); diff --git a/src/emu/netlist/nl_time.h b/src/emu/netlist/nl_time.h index 457f7622307..7b56b03628a 100644 --- a/src/emu/netlist/nl_time.h +++ b/src/emu/netlist/nl_time.h @@ -8,7 +8,7 @@ #define NLTIME_H_ #include "nl_config.h" -#include "pstate.h" +#include "plib/pstate.h" //============================================================ // MACROS diff --git a/src/emu/netlist/nl_util.h b/src/emu/netlist/nl_util.h index cf5ee6a3a7b..09a06ce976a 100644 --- a/src/emu/netlist/nl_util.h +++ b/src/emu/netlist/nl_util.h @@ -8,11 +8,12 @@ #ifndef NL_UTIL_H_ #define NL_UTIL_H_ -#include "pstring.h" -#include "plists.h" #include #include +#include "plib/pstring.h" +#include "plib/plists.h" + class nl_util { // this is purely static @@ -20,68 +21,7 @@ private: nl_util() {}; public: - typedef plist_t pstring_list; - - static pstring_list split(const pstring &str, const pstring &onstr, bool ignore_empty = false) - { - pstring_list temp; - - int p = 0; - int pn; - - pn = str.find(onstr, p); - while (pn>=0) - { - pstring t = str.substr(p, pn - p); - if (!ignore_empty || t.len() != 0) - temp.add(t); - p = pn + onstr.len(); - pn = str.find(onstr, p); - } - if (p=0) - { - if (col != "") - temp.add(col); - col = ""; - temp.add(onstrl[p]); - i += onstrl[p].len(); - } - else - { - col += str.cstr()[i]; - i++; - } - } - if (col != "") - temp.add(col); - return temp; - } static const pstring environment(const pstring &var, const pstring &default_val = "") { diff --git a/src/emu/netlist/palloc.c b/src/emu/netlist/palloc.c deleted file mode 100644 index 5f9dbc5fee7..00000000000 --- a/src/emu/netlist/palloc.c +++ /dev/null @@ -1,23 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * palloc.c - * - */ - -#include "pconfig.h" - -#if (PSTANDALONE) -#include -#include - -void *palloc_raw(const size_t size) -{ - return _mm_malloc(size, 64); -} - -void pfree_raw(void *p) -{ - _mm_free(p); -} -#endif diff --git a/src/emu/netlist/palloc.h b/src/emu/netlist/palloc.h deleted file mode 100644 index e78bbc6e3ab..00000000000 --- a/src/emu/netlist/palloc.h +++ /dev/null @@ -1,109 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * palloc.h - * - */ - -#ifndef PALLOC_H_ -#define PALLOC_H_ - -#include "pconfig.h" - -//============================================================ -// Memory allocation -//============================================================ - -#if (PSTANDALONE) -#include -#include - -#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) -#if !defined(__ppc__) && !defined (__PPC__) && !defined(__ppc64__) && !defined(__PPC64__) -#define ATTR_ALIGN __attribute__ ((aligned(64))) -#else -#define ATTR_ALIGN -#endif -#else -#define ATTR_ALIGN -#endif - - -void *palloc_raw(const size_t size); -void pfree_raw(void *p); - -template -inline T *palloc_t() -{ - void *p = palloc_raw(sizeof(T)); - return new (p) T(); -} - -template -inline T *palloc_t(P1 &p1) -{ - void *p = palloc_raw(sizeof(T)); - return new (p) T(p1); -} - -template -inline T *palloc_t(P1 &p1, P2 &p2) -{ - void *p = palloc_raw(sizeof(T)); - return new (p) T(p1, p2); -} - -template -inline T *palloc_t(P1 &p1, P2 &p2, P3 &p3) -{ - void *p = palloc_raw(sizeof(T)); - return new (p) T(p1, p2, p3); -} - -template -inline T *palloc_t(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, P7 &p7) -{ - void *p = palloc_raw(sizeof(T)); - return new (p) T(p1, p2, p3, p4, p5, p6, p7); -} - -template -inline void pfree_t(T *p) -{ - p->~T(); - pfree_raw(p); - //delete p; -} - -template -inline T *palloc_array_t(size_t N) -{ - return new T[N]; -} - -template -inline void pfree_array_t(T *p) -{ - delete[] p; -} - -#define palloc(T, ...) palloc_t(__VA_ARGS__) -#define pfree(_ptr) pfree_t(_ptr) - -#define palloc_array(T, N) palloc_array_t(N) -#define pfree_array(_ptr) pfree_array_t(_ptr) - -#else - -#define ATTR_ALIGN - -#include "corealloc.h" -#define palloc(T, ...) global_alloc(T(__VA_ARGS__)) -#define pfree(_ptr) global_free(_ptr) - -#define palloc_array(T, N) global_alloc_array(T, N) -#define pfree_array(_ptr) global_free_array(_ptr) - -#endif - -#endif /* NLCONFIG_H_ */ diff --git a/src/emu/netlist/pconfig.h b/src/emu/netlist/pconfig.h deleted file mode 100644 index b05292b26e4..00000000000 --- a/src/emu/netlist/pconfig.h +++ /dev/null @@ -1,82 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pconfig.h - * - */ - -#ifndef PCONFIG_H_ -#define PCONFIG_H_ - -#ifndef PSTANDALONE - #define PSTANDALONE (0) -#endif - -//============================================================ -// Compiling standalone -//============================================================ - -// Compiling without mame ? - -#include -#include - -#if !(PSTANDALONE) -#include "osdcore.h" - -#undef ATTR_COLD -#define ATTR_COLD - -#else -#include - -/* not supported in GCC prior to 4.4.x */ -/* ATTR_HOT and ATTR_COLD cause performance degration in 5.1 */ -//#define ATTR_HOT -//#define ATTR_COLD -#define ATTR_HOT __attribute__((hot)) -#define ATTR_COLD __attribute__((cold)) - -#define RESTRICT -#define EXPECTED(x) (x) -#define UNEXPECTED(x) (x) -#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y))) -#define ATTR_UNUSED __attribute__((__unused__)) - -/* 8-bit values */ -typedef unsigned char UINT8; -typedef signed char INT8; - -/* 16-bit values */ -typedef unsigned short UINT16; -typedef signed short INT16; - -/* 32-bit values */ -#ifndef _WINDOWS_H -typedef unsigned int UINT32; -typedef signed int INT32; -#endif - -/* 64-bit values */ -#ifndef _WINDOWS_H -#ifdef _MSC_VER -typedef signed __int64 INT64; -typedef unsigned __int64 UINT64; -#else -typedef uint64_t UINT64; -typedef int64_t INT64; -#endif -#endif - -/* U64 and S64 are used to wrap long integer constants. */ -#if defined(__GNUC__) || defined(_MSC_VER) -#define U64(val) val##ULL -#define S64(val) val##LL -#else -#define U64(val) val -#define S64(val) val -#endif - -#endif - -#endif /* PCONFIG_H_ */ diff --git a/src/emu/netlist/plib/palloc.c b/src/emu/netlist/plib/palloc.c new file mode 100644 index 00000000000..5f9dbc5fee7 --- /dev/null +++ b/src/emu/netlist/plib/palloc.c @@ -0,0 +1,23 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * palloc.c + * + */ + +#include "pconfig.h" + +#if (PSTANDALONE) +#include +#include + +void *palloc_raw(const size_t size) +{ + return _mm_malloc(size, 64); +} + +void pfree_raw(void *p) +{ + _mm_free(p); +} +#endif diff --git a/src/emu/netlist/plib/palloc.h b/src/emu/netlist/plib/palloc.h new file mode 100644 index 00000000000..e78bbc6e3ab --- /dev/null +++ b/src/emu/netlist/plib/palloc.h @@ -0,0 +1,109 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * palloc.h + * + */ + +#ifndef PALLOC_H_ +#define PALLOC_H_ + +#include "pconfig.h" + +//============================================================ +// Memory allocation +//============================================================ + +#if (PSTANDALONE) +#include +#include + +#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) +#if !defined(__ppc__) && !defined (__PPC__) && !defined(__ppc64__) && !defined(__PPC64__) +#define ATTR_ALIGN __attribute__ ((aligned(64))) +#else +#define ATTR_ALIGN +#endif +#else +#define ATTR_ALIGN +#endif + + +void *palloc_raw(const size_t size); +void pfree_raw(void *p); + +template +inline T *palloc_t() +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(); +} + +template +inline T *palloc_t(P1 &p1) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1); +} + +template +inline T *palloc_t(P1 &p1, P2 &p2) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1, p2); +} + +template +inline T *palloc_t(P1 &p1, P2 &p2, P3 &p3) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1, p2, p3); +} + +template +inline T *palloc_t(P1 &p1, P2 &p2, P3 &p3, P4 &p4, P5 &p5, P6 &p6, P7 &p7) +{ + void *p = palloc_raw(sizeof(T)); + return new (p) T(p1, p2, p3, p4, p5, p6, p7); +} + +template +inline void pfree_t(T *p) +{ + p->~T(); + pfree_raw(p); + //delete p; +} + +template +inline T *palloc_array_t(size_t N) +{ + return new T[N]; +} + +template +inline void pfree_array_t(T *p) +{ + delete[] p; +} + +#define palloc(T, ...) palloc_t(__VA_ARGS__) +#define pfree(_ptr) pfree_t(_ptr) + +#define palloc_array(T, N) palloc_array_t(N) +#define pfree_array(_ptr) pfree_array_t(_ptr) + +#else + +#define ATTR_ALIGN + +#include "corealloc.h" +#define palloc(T, ...) global_alloc(T(__VA_ARGS__)) +#define pfree(_ptr) global_free(_ptr) + +#define palloc_array(T, N) global_alloc_array(T, N) +#define pfree_array(_ptr) global_free_array(_ptr) + +#endif + +#endif /* NLCONFIG_H_ */ diff --git a/src/emu/netlist/plib/pconfig.h b/src/emu/netlist/plib/pconfig.h new file mode 100644 index 00000000000..6c00cdd3411 --- /dev/null +++ b/src/emu/netlist/plib/pconfig.h @@ -0,0 +1,99 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pconfig.h + * + */ + +#ifndef PCONFIG_H_ +#define PCONFIG_H_ + +#ifndef PSTANDALONE + #define PSTANDALONE (0) +#endif + +//============================================================ +// Compiling standalone +//============================================================ + +// Compiling without mame ? + +#include +#include + +#if !(PSTANDALONE) +#include "osdcore.h" + +#undef ATTR_COLD +#define ATTR_COLD + +#else +#include + +/* not supported in GCC prior to 4.4.x */ +/* ATTR_HOT and ATTR_COLD cause performance degration in 5.1 */ +//#define ATTR_HOT +//#define ATTR_COLD +#define ATTR_HOT __attribute__((hot)) +#define ATTR_COLD __attribute__((cold)) + +#define RESTRICT +#define EXPECTED(x) (x) +#define UNEXPECTED(x) (x) +#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y))) +#define ATTR_UNUSED __attribute__((__unused__)) + +/* 8-bit values */ +typedef unsigned char UINT8; +typedef signed char INT8; + +/* 16-bit values */ +typedef unsigned short UINT16; +typedef signed short INT16; + +/* 32-bit values */ +#ifndef _WINDOWS_H +typedef unsigned int UINT32; +typedef signed int INT32; +#endif + +/* 64-bit values */ +#ifndef _WINDOWS_H +#ifdef _MSC_VER +typedef signed __int64 INT64; +typedef unsigned __int64 UINT64; +#else +typedef uint64_t UINT64; +typedef int64_t INT64; +#endif +#endif + +/* U64 and S64 are used to wrap long integer constants. */ +#if defined(__GNUC__) || defined(_MSC_VER) +#define U64(val) val##ULL +#define S64(val) val##LL +#else +#define U64(val) val +#define S64(val) val +#endif + +/* MINGW has adopted the MSVC formatting for 64-bit ints as of gcc 4.4 */ +#if (defined(__MINGW32__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))) || defined(_MSC_VER) +#define I64FMT "I64" +#else +#define I64FMT "ll" +#endif + +#if defined(_MSC_VER) || defined(__MINGW32__) +#ifdef PTR64 +#define SIZETFMT "I64u" +#else +#define SIZETFMT "u" +#endif +#else +#define SIZETFMT "zu" +#endif + +#endif + +#endif /* PCONFIG_H_ */ diff --git a/src/emu/netlist/plib/plists.h b/src/emu/netlist/plib/plists.h new file mode 100644 index 00000000000..fb121b798b6 --- /dev/null +++ b/src/emu/netlist/plib/plists.h @@ -0,0 +1,585 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * plists.h + * + */ + +#pragma once + +#ifndef PLISTS_H_ +#define PLISTS_H_ + +#include + +#include "palloc.h" +#include "pstring.h" + +// ---------------------------------------------------------------------------------------- +// parray_t: dynamic array +// ---------------------------------------------------------------------------------------- + +template +class parray_t +{ +public: + + ATTR_COLD parray_t(std::size_t numElements) + : m_list(0), m_capacity(0) + { + set_capacity(numElements); + } + + ATTR_COLD parray_t(const parray_t &rhs) + : m_list(0), m_capacity(0) + { + set_capacity(rhs.size()); + for (std::size_t i=0; i 0) + m_list = palloc_array(_ListClass, new_capacity); + else + m_list = NULL; + m_capacity = new_capacity; + } + +private: + + _ListClass * m_list; + int m_capacity; +}; + +// ---------------------------------------------------------------------------------------- +// plist_t: a simple list +// ---------------------------------------------------------------------------------------- +#if 0 +#include +//#define plist_t std::vector +template +class plist_t : public std::vector<_ListClass> +{ +public: + plist_t() : std::vector<_ListClass>() {} + plist_t(const int numElements) : std::vector<_ListClass>(numElements) {} + + /* inline */ void add(const _ListClass &elem) { this->push_back(elem); } + void clear_and_free() + { + for (_ListClass *i = this->data(); i < this->data() + this->size(); i++) + { + pfree(*i); + } + this->clear(); + } + /* inline */ bool contains(const _ListClass &elem) const + { + for (const _ListClass *i = this->data(); i < this->data() + this->size(); i++) + { + if (*i == elem) + return true; + } + return false; + } + + /* inline */ void remove(const _ListClass &elem) + { + for (int i = 0; i < this->size(); i++) + { + if (this->at(i) == elem) + { + this->erase(this->begin() + i); + return; + } + } + } + /* inline */ void remove_at(const int pos) + { + this->erase(this->begin() + pos); + } + + /* inline */ int indexof(const _ListClass &elem) const + { + for (int i = 0; i < this->size(); i++) + { + if (this->at(i) == elem) + return i; + } + return -1; + } + + ATTR_HOT /* inline */ void swap(const int pos1, const int pos2) + { + //nl_assert((pos1>=0) && (pos1=0) && (pos2 +class plist_t +{ +public: + + ATTR_COLD plist_t(const std::size_t numElements = 0) + { + m_capacity = numElements; + if (m_capacity == 0) + m_list = NULL; + else + m_list = this->alloc(m_capacity); + m_count = 0; + } + + ATTR_COLD plist_t(const plist_t &rhs) + { + m_capacity = rhs.capacity(); + if (m_capacity == 0) + m_list = NULL; + else + m_list = this->alloc(m_capacity); + m_count = 0; + for (std::size_t i=0; iadd(rhs[i]); + } + } + + ATTR_COLD plist_t &operator=(const plist_t &rhs) + { + this->clear(); + for (std::size_t i=0; iadd(rhs[i]); + } + return *this; + } + + + ~plist_t() + { + if (m_list != NULL) + this->dealloc(m_list); + m_list = NULL; + } + + ATTR_HOT /* inline */ _ListClass *data() { return m_list; } + + ATTR_HOT /* inline */ _ListClass& operator[](std::size_t index) { return *(m_list + index); } + ATTR_HOT /* inline */ const _ListClass& operator[](std::size_t index) const { return *(m_list + index); } + + ATTR_HOT /* inline */ void add(const _ListClass &elem) + { + if (m_count >= m_capacity){ + std::size_t new_size = m_capacity * 2; + if (new_size < 32) + new_size = 32; + set_capacity(new_size); + } + + m_list[m_count++] = elem; + } + + ATTR_HOT /* inline */ void remove(const _ListClass &elem) + { + for (std::size_t i = 0; i < m_count; i++) + { + if (m_list[i] == elem) + { + m_count --; + while (i < m_count) + { + m_list[i] = m_list[i+1]; + i++; + } + return; + } + } + } + + ATTR_HOT /* inline */ void remove_at(const std::size_t pos) + { + //nl_assert((pos>=0) && (pos=0) && (pos1=0) && (pos2 0) + { + _ListClass *m_new = this->alloc(new_capacity); + _ListClass *pd = m_new; + + if (cnt > new_capacity) + cnt = new_capacity; + for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++) + *pd = *ps; + if (m_list != NULL) + this->dealloc(m_list); + m_list = m_new; + m_count = cnt; + } + else + { + if (m_list != NULL) + this->dealloc(m_list); + m_list = NULL; + m_count = 0; + } + m_capacity = new_capacity; + } + + _ListClass *alloc(const std::size_t n) + { + return palloc_array(_ListClass, n); + } + + void dealloc(_ListClass *p) + { + pfree_array(p); + } + + std::size_t m_count; + _ListClass * m_list; + std::size_t m_capacity; +}; +#endif + +// ---------------------------------------------------------------------------------------- +// pnamedlist_t: a simple list of elements which have a name() interface +// ---------------------------------------------------------------------------------------- + +template +class pnamedlist_t : public plist_t<_ListClass> +{ +public: + _ListClass find(const pstring &name) const + { + for (std::size_t i=0; i < this->size(); i++) + if (get_name((*this)[i]) == name) + return (*this)[i]; + return _ListClass(NULL); + } + + void remove_by_name(const pstring &name) + { + plist_t<_ListClass>::remove(find(name)); + } + + bool add(_ListClass dev, bool allow_duplicate) + { + if (allow_duplicate) + plist_t<_ListClass>::add(dev); + else + { + if (!(this->find(get_name(dev)) == _ListClass(NULL))) + return false; + plist_t<_ListClass>::add(dev); + } + return true; + } + +private: + template static const pstring get_name(const T *elem) { return elem->name(); } + template static const pstring get_name(T *elem) { return elem->name(); } + template static const pstring get_name(const T &elem) { return elem.name(); } + +}; + + +// ---------------------------------------------------------------------------------------- +// pstack_t: a simple stack +// ---------------------------------------------------------------------------------------- + +template +class pstack_t +{ +public: + + ATTR_COLD pstack_t(const int numElements = 128) + : m_list(numElements) + { + } + + ATTR_COLD pstack_t(const pstack_t &rhs) + : m_list(rhs.m_list) + { + } + + ATTR_COLD pstack_t &operator=(const pstack_t &rhs) + { + m_list = rhs.m_list; + return *this; + } + + + ~pstack_t() + { + } + + ATTR_HOT /* inline */ void push(const _StackClass &elem) + { + m_list.add(elem); + } + + ATTR_HOT /* inline */ _StackClass peek() const + { + return m_list[m_list.size() - 1]; + } + + ATTR_HOT /* inline */ _StackClass pop() + { + _StackClass ret = peek(); + m_list.remove_at(m_list.size() - 1); + return ret; + } + + ATTR_HOT /* inline */ int count() const { return m_list.size(); } + ATTR_HOT /* inline */ bool empty() const { return (m_list.size() == 0); } + ATTR_HOT /* inline */ void reset() { m_list.reset(); } + ATTR_HOT /* inline */ int capacity() const { return m_list.capacity(); } + +private: + plist_t<_StackClass> m_list; +}; + +template +struct plinkedlist_element_t +{ + plinkedlist_element_t() : m_next(NULL) {} + _ListClass * m_next; + +}; + +// ---------------------------------------------------------------------------------------- +// plinkedlist_t: a simple linked list +// ---------------------------------------------------------------------------------------- + +template +class plinkedlist_t +{ +public: + + plinkedlist_t() : m_head(NULL) {} + + ATTR_HOT /* inline */ void insert(const _ListClass &before, _ListClass &elem) + { + if (m_head == &before) + { + elem.m_next = m_head; + m_head = elem; + } + else + { + _ListClass *p = m_head; + while (p != NULL) + { + if (p->m_next == &before) + { + elem->m_next = &before; + p->m_next = &elem; + return; + } + p = p->m_next; + } + //FXIME: throw a standard exception + //nl_assert_always(false, "element not found"); + } + } + + ATTR_HOT /* inline */ void insert(_ListClass &elem) + { + elem.m_next = m_head; + m_head = &elem; + } + + ATTR_HOT /* inline */ void add(_ListClass &elem) + { + _ListClass **p = &m_head; + while (*p != NULL) + { + p = &((*p)->m_next); + } + *p = &elem; + elem.m_next = NULL; + } + + ATTR_HOT /* inline */ void remove(const _ListClass &elem) + { + _ListClass **p = &m_head; + while (*p != &elem) + { + //nl_assert(*p != NULL); + p = &((*p)->m_next); + } + (*p) = elem.m_next; + } + + + ATTR_HOT static /* inline */ _ListClass *next(const _ListClass &elem) { return elem.m_next; } + ATTR_HOT static /* inline */ _ListClass *next(const _ListClass *elem) { return elem->m_next; } + ATTR_HOT /* inline */ _ListClass *first() const { return m_head; } + ATTR_HOT /* inline */ void clear() { m_head = NULL; } + ATTR_HOT /* inline */ bool is_empty() const { return (m_head == NULL); } + +private: + _ListClass *m_head; +}; + +// ---------------------------------------------------------------------------------------- +// string list +// ---------------------------------------------------------------------------------------- + +class pstring_list_t : public plist_t +{ +public: + pstring_list_t() : plist_t() { } + + pstring_list_t(const pstring &str, const pstring &onstr, bool ignore_empty = false) + : plist_t() + { + + int p = 0; + int pn; + + pn = str.find(onstr, p); + while (pn>=0) + { + pstring t = str.substr(p, pn - p); + if (!ignore_empty || t.len() != 0) + this->add(t); + p = pn + onstr.len(); + pn = str.find(onstr, p); + } + if (padd(t); + } + } + + static pstring_list_t splitexpr(const pstring &str, const pstring_list_t &onstrl) + { + pstring_list_t temp; + pstring col = ""; + + int i = 0; + while (i=0) + { + if (col != "") + temp.add(col); + col = ""; + temp.add(onstrl[p]); + i += onstrl[p].len(); + } + else + { + col += str.cstr()[i]; + i++; + } + } + if (col != "") + temp.add(col); + return temp; + } +}; + +#endif /* PLISTS_H_ */ diff --git a/src/emu/netlist/plib/poptions.h b/src/emu/netlist/plib/poptions.h new file mode 100644 index 00000000000..7803a315d94 --- /dev/null +++ b/src/emu/netlist/plib/poptions.h @@ -0,0 +1,213 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * poptions.h + * + */ + +#pragma once + +#ifndef POPTIONS_H_ +#define POPTIONS_H_ + +#include + +#include "pstring.h" +#include "plists.h" + +/*************************************************************************** + Options +***************************************************************************/ + +class poptions; + +class poption +{ +public: + poption() + : m_short(""), m_long(""), m_help(""), m_has_argument(false) + {} + + poption(pstring ashort, pstring along, pstring help, bool has_argument, poptions *parent = NULL); + + virtual ~poption() + { + } + + /* no_argument options will be called with "" argument */ + + virtual int parse(ATTR_UNUSED pstring argument) { return 0; } + + pstring m_short; + pstring m_long; + pstring m_help; + bool m_has_argument; +private: +}; + +class poption_str : public poption +{ +public: + poption_str(pstring ashort, pstring along, pstring defval, pstring help, poptions *parent = NULL) + : poption(ashort, along, help, true, parent), m_val(defval) + {} + + virtual int parse(pstring argument) { m_val = argument; return 0; } + + pstring operator ()() { return m_val; } +private: + pstring m_val; +}; + +class poption_bool : public poption +{ +public: + poption_bool(pstring ashort, pstring along, pstring help, poptions *parent = NULL) + : poption(ashort, along, help, false, parent), m_val(false) + {} + + virtual int parse(ATTR_UNUSED pstring argument) { m_val = true; return 0; } + + bool operator ()() { return m_val; } +private: + bool m_val; +}; + +class poption_double : public poption +{ +public: + poption_double(pstring ashort, pstring along, double defval, pstring help, poptions *parent = NULL) + : poption(ashort, along, help, true, parent), m_val(defval) + {} + + virtual int parse(pstring argument) + { + bool err = false; + m_val = argument.as_double(&err); + return (err ? 1 : 0); + } + + double operator ()() { return m_val; } +private: + double m_val; +}; + +class poptions +{ +public: + + poptions() {} + + poptions(poption *o[]) + { + int i=0; + while (o[i] != NULL) + { + m_opts.add(o[i]); + i++; + } + } + + ~poptions() + { + m_opts.clear(); + } + + void register_option(poption *opt) + { + m_opts.add(opt); + } + + int parse(int argc, char *argv[]) + { + m_app = argv[0]; + + for (int i=1; im_has_argument) + { + i++; // FIXME: are there more arguments? + if (opt->parse(argv[i]) != 0) + return i - 1; + } + else + opt->parse(""); + i++; + } + return argc; + } + + pstring help() + { + pstring ret; + + for (std::size_t i=0; im_short != "") + line += " -" + opt->m_short; + if (opt->m_long != "") + { + if (line != "") + line += ", "; + else + line = " "; + line += "--" + opt->m_long; + } + line = line.rpad(" ", 20).cat(opt->m_help); + ret = ret + line + "\n"; + } + return ret; + } + pstring app() { return m_app; } + +private: + + poption *getopt_short(pstring arg) + { + for (std::size_t i=0; i < m_opts.size(); i++) + { + if (m_opts[i]->m_short == arg) + return m_opts[i]; + } + return NULL; + } + poption *getopt_long(pstring arg) + { + for (std::size_t i=0; i < m_opts.size(); i++) + { + if (m_opts[i]->m_long == arg) + return m_opts[i]; + } + return NULL; + } + + plist_t m_opts; + pstring m_app; +}; + +poption::poption(pstring ashort, pstring along, pstring help, bool has_argument, poptions *parent) +: m_short(ashort), m_long(along), m_help(help), m_has_argument(has_argument) +{ + if (parent != NULL) + parent->register_option(this); +} + + +#endif /* POPTIONS_H_ */ diff --git a/src/emu/netlist/plib/pparser.c b/src/emu/netlist/plib/pparser.c new file mode 100644 index 00000000000..6a8c184c0cb --- /dev/null +++ b/src/emu/netlist/plib/pparser.c @@ -0,0 +1,407 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pparser.c + * + */ + +#include + +#include "pparser.h" + +//#undef NL_VERBOSE_OUT +//#define NL_VERBOSE_OUT(x) printf x + +// ---------------------------------------------------------------------------------------- +// A simple tokenizer +// ---------------------------------------------------------------------------------------- + +pstring ptokenizer::currentline_str() +{ + char buf[300]; + int bufp = 0; + const char *p = m_line_ptr; + while (*p && *p != 10) + buf[bufp++] = *p++; + buf[bufp] = 0; + return pstring(buf); +} + + +void ptokenizer::skipeol() +{ + char c = getc(); + while (c) + { + if (c == 10) + { + c = getc(); + if (c != 13) + ungetc(); + return; + } + c = getc(); + } +} + + +unsigned char ptokenizer::getc() +{ + if (*m_px == 10) + { + m_line++; + m_line_ptr = m_px + 1; + } + if (*m_px) + return *(m_px++); + else + return *m_px; +} + +void ptokenizer::ungetc() +{ + m_px--; +} + +void ptokenizer::require_token(const token_id_t &token_num) +{ + require_token(get_token(), token_num); +} + +void ptokenizer::require_token(const token_t tok, const token_id_t &token_num) +{ + if (!tok.is(token_num)) + { + error("Error: expected token <%s> got <%s>\n", m_tokens[token_num.id()].cstr(), tok.str().cstr()); + } +} + +pstring ptokenizer::get_string() +{ + token_t tok = get_token(); + if (!tok.is_type(STRING)) + { + error("Error: expected a string, got <%s>\n", tok.str().cstr()); + } + return tok.str(); +} + +pstring ptokenizer::get_identifier() +{ + token_t tok = get_token(); + if (!tok.is_type(IDENTIFIER)) + { + error("Error: expected an identifier, got <%s>\n", tok.str().cstr()); + } + return tok.str(); +} + +ptokenizer::token_t ptokenizer::get_token() +{ + while (true) + { + token_t ret = get_token_internal(); + if (ret.is_type(ENDOFFILE)) + return ret; + + if (ret.is(m_tok_comment_start)) + { + do { + ret = get_token_internal(); + } while (ret.is_not(m_tok_comment_end)); + } + else if (ret.is(m_tok_line_comment)) + { + skipeol(); + } + else if (ret.str() == "#") + { + skipeol(); + } + else + return ret; + } +} + +ptokenizer::token_t ptokenizer::get_token_internal() +{ + /* skip ws */ + char c = getc(); + while (m_whitespace.find(c)>=0) + { + c = getc(); + if (eof()) + { + return token_t(ENDOFFILE); + } + } + if (m_identifier_chars.find(c)>=0) + { + /* read identifier till non identifier char */ + pstring tokstr = ""; + while (m_identifier_chars.find(c)>=0) { + tokstr += c; + c = getc(); + } + ungetc(); + token_id_t id = token_id_t(m_tokens.indexof(tokstr)); + if (id.id() >= 0) + return token_t(id, tokstr); + else + { + return token_t(IDENTIFIER, tokstr); + } + } + else if (c == m_string) + { + pstring tokstr = ""; + c = getc(); + while (c != m_string) + { + tokstr += c; + c = getc(); + } + return token_t(STRING, tokstr); + } + else + { + /* read identifier till first identifier char or ws */ + pstring tokstr = ""; + while ((m_identifier_chars.find(c)) < 0 && (m_whitespace.find(c) < 0)) { + tokstr += c; + /* expensive, check for single char tokens */ + if (tokstr.len() == 1) + { + token_id_t id = token_id_t(m_tokens.indexof(tokstr)); + if (id.id() >= 0) + return token_t(id, tokstr); + } + c = getc(); + } + ungetc(); + token_id_t id = token_id_t(m_tokens.indexof(tokstr)); + if (id.id() >= 0) + return token_t(id, tokstr); + else + { + return token_t(UNKNOWN, tokstr); + } + } + +} + +ATTR_COLD void ptokenizer::error(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + + pstring errmsg1 = pstring(format).vprintf(ap); + va_end(ap); + + verror(errmsg1, currentline_no(), currentline_str()); + + //throw error; +} + +// ---------------------------------------------------------------------------------------- +// A simple preprocessor +// ---------------------------------------------------------------------------------------- + +ppreprocessor::ppreprocessor() +{ + m_expr_sep.add("("); + m_expr_sep.add(")"); + m_expr_sep.add("+"); + m_expr_sep.add("-"); + m_expr_sep.add("*"); + m_expr_sep.add("/"); + m_expr_sep.add("=="); + m_expr_sep.add(" "); + m_expr_sep.add("\t"); +} + +void ppreprocessor::error(const pstring &err) +{ + fprintf(stderr, "PREPRO ERROR: %s\n", err.cstr()); +} + + + +double ppreprocessor::expr(const pstring_list_t &sexpr, std::size_t &start, int prio) +{ + double val; + pstring tok=sexpr[start]; + if (tok == "(") + { + start++; + val = expr(sexpr, start, prio); + if (sexpr[start] != ")") + error("parsing error!"); + start++; + } + else + { + tok=sexpr[start]; + val = tok.as_double(); + start++; + } + while (start < sexpr.size()) + { + tok=sexpr[start]; + if (tok == ")") + { + // FIXME: catch error + return val; + } + else if (tok == "+") + { + if (prio > 10) + return val; + start++; + val = val + expr(sexpr, start, 10); + } + else if (tok == "-") + { + if (prio > 10) + return val; + start++; + val = val - expr(sexpr, start, 10); + } + else if (tok == "*") + { + start++; + val = val * expr(sexpr, start, 20); + } + else if (tok == "/") + { + start++; + val = val / expr(sexpr, start, 20); + } + else if (tok == "==") + { + if (prio > 5) + return val; + start++; + val = (val == expr(sexpr, start, 5)) ? 1.0 : 0.0; + } + } + return val; +} + +ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name) +{ + for (std::size_t i = 0; im_replace); + else + ret.cat(elems[i]); + } + return pstring(ret.cstr()); +} + +static pstring catremainder(const pstring_list_t &elems, std::size_t start, pstring sep) +{ + pstringbuffer ret = ""; + for (std::size_t i=start; i 3 && lti[1].equals("NETLIST")) + { + if (lti[2].equals("warning")) + error("NETLIST: " + catremainder(lti, 3, " ")); + } + } + else if (lti[0].equals("#define")) + { + if (lti.size() != 3) + error(pstring::sprintf("PREPRO: only simple defines allowed: %s", line.cstr())); + m_defines.add(define_t(lti[1], lti[2])); + } + else + error(pstring::sprintf("unknown directive on line %" SIZETFMT ": %s\n", i, line.cstr())); + } + else + { + //if (ifflag == 0 && level > 0) + // fprintf(stderr, "conditional: %s\n", line.cstr()); + if (ifflag == 0) + { + ret.cat(line); + ret.cat("\n"); + } + } + i++; + } + return pstring(ret.cstr()); +} diff --git a/src/emu/netlist/plib/pparser.h b/src/emu/netlist/plib/pparser.h new file mode 100644 index 00000000000..b21b06659cc --- /dev/null +++ b/src/emu/netlist/plib/pparser.h @@ -0,0 +1,178 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pparser.h + * + */ + +#ifndef PPARSER_H_ +#define PPARSER_H_ + +#include "pconfig.h" +#include "../nl_config.h" // FIXME +#include "../nl_util.h" + +class ptokenizer +{ + NETLIST_PREVENT_COPYING(ptokenizer) +public: + virtual ~ptokenizer() {} + + ptokenizer() + : m_line(1), m_line_ptr(NULL), m_px(NULL), m_string('"') + {} + + enum token_type + { + IDENTIFIER, + NUMBER, + TOKEN, + STRING, + COMMENT, + UNKNOWN, + ENDOFFILE + }; + + struct token_id_t + { + public: + token_id_t() : m_id(-2) {} + token_id_t(const int id) : m_id(id) {} + int id() const { return m_id; } + private: + int m_id; + }; + + struct token_t + { + token_t(token_type type) + { + m_type = type; + m_id = token_id_t(-1); + m_token =""; + } + token_t(token_type type, const pstring str) + { + m_type = type; + m_id = token_id_t(-1); + m_token = str; + } + token_t(const token_id_t id, const pstring str) + { + m_type = TOKEN; + m_id = id; + m_token = str; + } + + bool is(const token_id_t &tok_id) const { return m_id.id() == tok_id.id(); } + bool is_not(const token_id_t &tok_id) const { return !is(tok_id); } + + bool is_type(const token_type type) const { return m_type == type; } + + pstring str() const { return m_token; } + + private: + token_type m_type; + token_id_t m_id; + pstring m_token; + }; + + + int currentline_no() { return m_line; } + pstring currentline_str(); + + /* tokenizer stuff follows ... */ + + token_t get_token(); + pstring get_string(); + pstring get_identifier(); + + void require_token(const token_id_t &token_num); + void require_token(const token_t tok, const token_id_t &token_num); + + token_id_t register_token(pstring token) + { + m_tokens.add(token); + return token_id_t(m_tokens.size() - 1); + } + + void set_identifier_chars(pstring s) { m_identifier_chars = s; } + void set_number_chars(pstring s) { m_number_chars = s; } + void set_whitespace(pstring s) { m_whitespace = s; } + void set_comment(pstring start, pstring end, pstring line) + { + m_tok_comment_start = register_token(start); + m_tok_comment_end = register_token(end); + m_tok_line_comment = register_token(line); + m_string = '"'; + } + + token_t get_token_internal(); + void error(const char *format, ...) ATTR_PRINTF(2,3); + +protected: + void reset(const char *p) { m_px = p; m_line = 1; m_line_ptr = p; } + virtual void verror(pstring msg, int line_num, pstring line) = 0; + +private: + void skipeol(); + + unsigned char getc(); + void ungetc(); + bool eof() { return *m_px == 0; } + + int m_line; + const char * m_line_ptr; + const char * m_px; + + /* tokenizer stuff follows ... */ + + pstring m_identifier_chars; + pstring m_number_chars; + plist_t m_tokens; + pstring m_whitespace; + char m_string; + + token_id_t m_tok_comment_start; + token_id_t m_tok_comment_end; + token_id_t m_tok_line_comment; +}; + + +class ppreprocessor +{ + NETLIST_PREVENT_COPYING(ppreprocessor) +public: + + struct define_t + { + define_t() { }; + define_t(const pstring &name, const pstring &replace) + : m_name(name), m_replace(replace) + {} + pstring m_name; + pstring m_replace; + }; + + ppreprocessor(); + virtual ~ppreprocessor() {} + + pstring process(const pstring &contents); + +protected: + + double expr(const pstring_list_t &sexpr, std::size_t &start, int prio); + + define_t *get_define(const pstring &name); + + pstring replace_macros(const pstring &line); + + virtual void error(const pstring &err); + +private: + + plist_t m_defines; + pstring_list_t m_expr_sep; +}; + +#endif /* PPARSER_H_ */ diff --git a/src/emu/netlist/plib/pstate.c b/src/emu/netlist/plib/pstate.c new file mode 100644 index 00000000000..07532032405 --- /dev/null +++ b/src/emu/netlist/plib/pstate.c @@ -0,0 +1,77 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pstate.c + * + */ + +#include "pstate.h" + +pstate_manager_t::pstate_manager_t() +{ +} + +pstate_manager_t::~pstate_manager_t() +{ + m_save.clear_and_free(); +} + + + +ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pstate_data_type_e dt, const void *owner, const int size, const int count, void *ptr, bool is_ptr) +{ + pstring fullname = stname; + ATTR_UNUSED pstring ts[] = { + "NOT_SUPPORTED", + "DT_CUSTOM", + "DT_DOUBLE", + "DT_INT64", + "DT_INT16", + "DT_INT8", + "DT_INT", + "DT_BOOLEAN", + "DT_FLOAT" + }; + + pstate_entry_t *p = palloc(pstate_entry_t, stname, dt, owner, size, count, ptr, is_ptr); + m_save.add(p); +} + +ATTR_COLD void pstate_manager_t::remove_save_items(const void *owner) +{ + pstate_entry_t::list_t todelete; + + for (std::size_t i=0; i < m_save.size(); i++) + { + if (m_save[i]->m_owner == owner) + todelete.add(m_save[i]); + } + for (std::size_t i=0; i < todelete.size(); i++) + { + m_save.remove(todelete[i]); + } + todelete.clear_and_free(); +} + +ATTR_COLD void pstate_manager_t::pre_save() +{ + for (std::size_t i=0; i < m_save.size(); i++) + if (m_save[i]->m_dt == DT_CUSTOM) + m_save[i]->m_callback->on_pre_save(); +} + +ATTR_COLD void pstate_manager_t::post_load() +{ + for (std::size_t i=0; i < m_save.size(); i++) + if (m_save[i]->m_dt == DT_CUSTOM) + m_save[i]->m_callback->on_post_load(); +} + +template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname) +{ + //save_state_ptr(stname, DT_CUSTOM, 0, 1, &state); + pstate_callback_t *state_p = &state; + pstate_entry_t *p = palloc(pstate_entry_t, stname, owner, state_p); + m_save.add(p); + state.register_state(*this, stname); +} diff --git a/src/emu/netlist/plib/pstate.h b/src/emu/netlist/plib/pstate.h new file mode 100644 index 00000000000..73b83e65a00 --- /dev/null +++ b/src/emu/netlist/plib/pstate.h @@ -0,0 +1,162 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pstate.h + * + */ + +#ifndef PSTATE_H_ +#define PSTATE_H_ + +#include "plists.h" +#include "pstring.h" + +// ---------------------------------------------------------------------------------------- +// state saving ... +// ---------------------------------------------------------------------------------------- + +#define PSTATE_INTERFACE_DECL() \ + template ATTR_COLD void save(C &state, const pstring &stname); \ + template ATTR_COLD void save(C (&state)[N], const pstring &stname); \ + template ATTR_COLD void save(C *state, const pstring &stname, const int count); + +#define PSTATE_INTERFACE(obj, manager, module) \ + template ATTR_COLD void obj::save(C &state, const pstring &stname) \ + { manager->save_item(state, this, module + "." + stname); } \ + template ATTR_COLD void obj::save(C (&state)[N], const pstring &stname) \ + { manager->save_state_ptr(module + "." + stname, nl_datatype::type, this, sizeof(state[0]), N, &(state[0]), false); } \ + template ATTR_COLD void obj::save(C *state, const pstring &stname, const int count) \ + { manager->save_state_ptr(module + "." + stname, nl_datatype::type, this, sizeof(C), count, state, false); } + +enum pstate_data_type_e { + NOT_SUPPORTED, + DT_CUSTOM, + DT_DOUBLE, + DT_INT64, + DT_INT16, + DT_INT8, + DT_INT, + DT_BOOLEAN, + DT_FLOAT +}; + +template struct nl_datatype +{ + static const pstate_data_type_e type = pstate_data_type_e(NOT_SUPPORTED); + static const bool is_ptr = false; +}; + +template struct nl_datatype<_ItemType *> +{ + static const pstate_data_type_e type = pstate_data_type_e(NOT_SUPPORTED); + static const bool is_ptr = true; +}; + +//template struct type_checker<_ItemType*> { static const bool is_atom = false; static const bool is_pointer = true; }; + +#define NETLIST_SAVE_TYPE(TYPE, TYPEDESC) \ + template<> struct nl_datatype{ static const pstate_data_type_e type = pstate_data_type_e(TYPEDESC); static const bool is_ptr = false;}; \ + template<> struct nl_datatype{ static const pstate_data_type_e type = pstate_data_type_e(TYPEDESC); static const bool is_ptr = true;} + +NETLIST_SAVE_TYPE(char, DT_INT8); +NETLIST_SAVE_TYPE(double, DT_DOUBLE); +NETLIST_SAVE_TYPE(float, DT_FLOAT); +NETLIST_SAVE_TYPE(INT8, DT_INT8); +NETLIST_SAVE_TYPE(UINT8, DT_INT8); +NETLIST_SAVE_TYPE(INT64, DT_INT64); +NETLIST_SAVE_TYPE(UINT64, DT_INT64); +NETLIST_SAVE_TYPE(bool, DT_BOOLEAN); +NETLIST_SAVE_TYPE(UINT32, DT_INT); +NETLIST_SAVE_TYPE(INT32, DT_INT); +NETLIST_SAVE_TYPE(UINT16, DT_INT16); +NETLIST_SAVE_TYPE(INT16, DT_INT16); +//NETLIST_SAVE_TYPE(netlist_time::INTERNALTYPE, DT_INT64); + +class pstate_manager_t; + +class pstate_callback_t +{ +public: + typedef plist_t list_t; + + virtual ~pstate_callback_t() { }; + + virtual void register_state(pstate_manager_t &manager, const pstring &module) = 0; + virtual void on_pre_save() = 0; + virtual void on_post_load() = 0; +protected: +}; + +struct pstate_entry_t +{ + typedef plist_t list_t; + + pstate_entry_t(const pstring &stname, const pstate_data_type_e dt, const void *owner, + const int size, const int count, void *ptr, bool is_ptr) + : m_name(stname), m_dt(dt), m_owner(owner), m_callback(NULL), m_size(size), m_count(count), m_ptr(ptr), m_is_ptr(is_ptr) { } + + pstate_entry_t(const pstring &stname, const void *owner, pstate_callback_t *callback) + : m_name(stname), m_dt(DT_CUSTOM), m_owner(owner), m_callback(callback), m_size(0), m_count(0), m_ptr(NULL), m_is_ptr(false) { } + + ~pstate_entry_t() { } + + pstring m_name; + const pstate_data_type_e m_dt; + const void *m_owner; + pstate_callback_t *m_callback; + const int m_size; + const int m_count; + void *m_ptr; + bool m_is_ptr; + + template + T *resolved() + { + if (m_is_ptr) + return *static_cast(m_ptr); + else + return static_cast(m_ptr); + } +}; + +class pstate_manager_t +{ +public: + + pstate_manager_t(); + ~pstate_manager_t(); + + template ATTR_COLD void save_item(C &state, const void *owner, const pstring &stname) + { + save_state_ptr(stname, nl_datatype::type, owner, sizeof(C), 1, &state, nl_datatype::is_ptr); + } + + template ATTR_COLD void save_item(C (&state)[N], const void *owner, const pstring &stname) + { + save_state_ptr(stname, nl_datatype::type, owner, sizeof(state[0]), N, &(state[0]), false); + } + + template ATTR_COLD void save_item(C *state, const void *owner, const pstring &stname, const int count) + { + save_state_ptr(stname, nl_datatype::type, owner, sizeof(C), count, state, false); + } + + ATTR_COLD void pre_save(); + ATTR_COLD void post_load(); + ATTR_COLD void remove_save_items(const void *owner); + + inline const pstate_entry_t::list_t &save_list() const { return m_save; } + + // FIXME: should be protected + ATTR_COLD void save_state_ptr(const pstring &stname, const pstate_data_type_e, const void *owner, const int size, const int count, void *ptr, bool is_ptr); + +protected: + +private: + pstate_entry_t::list_t m_save; +}; + +template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname); + + +#endif /* PSTATE_H_ */ diff --git a/src/emu/netlist/plib/pstring.c b/src/emu/netlist/plib/pstring.c new file mode 100644 index 00000000000..ec930808e7b --- /dev/null +++ b/src/emu/netlist/plib/pstring.c @@ -0,0 +1,360 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * nl_string.c + * + */ + +#include +#include +#include +//FIXME:: pstring should be locale free +#include +#include + +#include "pstring.h" +#include "palloc.h" + +// The following will work on linux, however not on Windows .... + +//pblockpool *pstring::m_pool = new pblockpool; +//pstring::str_t *pstring::m_zero = new(pstring::m_pool, 0) pstring::str_t(0); + +pstring::str_t pstring::m_zero = str_t(0); + +/* + * Uncomment the following to override defaults + */ + +#define IMMEDIATE_MODE (1) +//#define DEBUG_MODE (0) + +#ifdef MAME_DEBUG + #ifndef IMMEDIATE_MODE + #define IMMEDIATE_MODE (1) + #endif + #ifndef DEBUG_MODE + #define DEBUG_MODE (0) + #endif +#else + #ifndef IMMEDIATE_MODE + #define IMMEDIATE_MODE (1) + #endif + #ifndef DEBUG_MODE + #define DEBUG_MODE (0) + #endif +#endif + +pstring::~pstring() +{ + sfree(m_ptr); +} + +void pstring::pcat(const char *s) +{ + int slen = strlen(s); + str_t *n = salloc(m_ptr->len() + slen); + if (m_ptr->len() > 0) + std::memcpy(n->str(), m_ptr->str(), m_ptr->len()); + if (slen > 0) + std::memcpy(n->str() + m_ptr->len(), s, slen); + *(n->str() + n->len()) = 0; + sfree(m_ptr); + m_ptr = n; +} + +void pstring::pcopy(const char *from, int size) +{ + str_t *n = salloc(size); + if (size > 0) + std::memcpy(n->str(), from, size); + *(n->str() + size) = 0; + sfree(m_ptr); + m_ptr = n; +} + +pstring pstring::substr(unsigned int start, int count) const +{ + pstring ret; + unsigned alen = len(); + if (start >= alen) + return ret; + if (count <0 || start + count > alen) + count = alen - start; + ret.pcopy(cstr() + start, count); + return ret; +} + +pstring pstring::ucase() const +{ + pstring ret = *this; + ret.pcopy(cstr(), len()); + for (int i=0; istr()[i] = toupper((unsigned) ret.m_ptr->str()[i]); + return ret; +} + +int pstring::find_first_not_of(const pstring no) const +{ + for (int i=0; i < len(); i++) + { + bool f = true; + for (int j=0; j < no.len(); j++) + if (m_ptr->str()[i] == no.m_ptr->str()[j]) + f = false; + if (f) + return i; + } + return -1; +} + +int pstring::find_last_not_of(const pstring no) const +{ + for (int i=len() - 1; i >= 0; i--) + { + bool f = true; + for (int j=0; j < no.len(); j++) + if (m_ptr->str()[i] == no.m_ptr->str()[j]) + f = false; + if (f) + return i; + } + return -1; +} + +pstring pstring::replace(const pstring &search, const pstring &replace) const +{ + pstring ret = ""; + + if (search.len() == 0) + return *this; + int i = 0; + while (i=0) + return substr(f); + else + return ""; +} + +pstring pstring::rtrim(const pstring ws) const +{ + int f = find_last_not_of(ws); + if (f>=0) + return left(f+1); + else + return ""; +} + +void pstring::pcopy(const char *from) +{ + pcopy(from, strlen(from)); +} + +//------------------------------------------------- +// pcmpi - compare a character array to an nstring +//------------------------------------------------- + +int pstring::pcmpi(const char *lhs, const char *rhs, int count) const +{ + // loop while equal until we hit the end of strings + int index; + for (index = 0; index < count; index++) + if (lhs[index] == 0 || std::tolower(lhs[index]) != std::tolower(rhs[index])) + break; + + // determine the final result + if (index < count) + return std::tolower(lhs[index]) - std::tolower(rhs[index]); + if (lhs[index] == 0) + return 0; + return 1; +} + +double pstring::as_double(bool *error) const +{ + double ret; + char *e = NULL; + + if (error != NULL) + *error = false; + ret = strtod(cstr(), &e); + if (*e != 0) + if (error != NULL) + *error = true; + return ret; +} + +long pstring::as_long(bool *error) const +{ + long ret; + char *e = NULL; + + if (error != NULL) + *error = false; + if (startsWith("0x")) + ret = strtol(&(cstr()[2]), &e, 16); + else + ret = strtol(cstr(), &e, 10); + if (*e != 0) + if (error != NULL) + *error = true; + return ret; +} + +pstring pstring::vprintf(va_list args) const +{ + // sprintf into the temporary buffer + char tempbuf[4096]; + std::vsprintf(tempbuf, cstr(), args); + + return pstring(tempbuf); +} + +// ---------------------------------------------------------------------------------------- +// static stuff ... +// ---------------------------------------------------------------------------------------- + +void pstring::sfree(str_t *s) +{ + s->m_ref_count--; + if (s->m_ref_count == 0 && s != &m_zero) + { + pfree_array(((char *)s)); + //_mm_free(((char *)s)); + } +} + +pstring::str_t *pstring::salloc(int n) +{ + int size = sizeof(str_t) + n + 1; + str_t *p = (str_t *) palloc_array(char, size); + // str_t *p = (str_t *) _mm_malloc(size, 8); + p->init(n); + return p; +} + +void pstring::resetmem() +{ + // Release the 0 string +} + +// ---------------------------------------------------------------------------------------- +// pstring ... +// ---------------------------------------------------------------------------------------- + +pstring pstring::sprintf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + pstring ret = pstring(format).vprintf(ap); + va_end(ap); + return ret; +} + + +int pstring::find(const char *search, int start) const +{ + int alen = len(); + const char *result = std::strstr(cstr() + std::min(start, alen), search); + return (result != NULL) ? (result - cstr()) : -1; +} + +int pstring::find(const char search, int start) const +{ + int alen = len(); + const char *result = std::strchr(cstr() + std::min(start, alen), search); + return (result != NULL) ? (result - cstr()) : -1; +} + +bool pstring::startsWith(const char *arg) const +{ + return (pcmp(cstr(), arg, std::strlen(arg)) == 0); +} + +int pstring::pcmp(const char *left, const char *right, int count) const +{ + if (count < 0) + return std::strcmp(left, right); + else + return std::strncmp(left, right, count); +} + +// ---------------------------------------------------------------------------------------- +// pstringbuffer +// ---------------------------------------------------------------------------------------- + +pstringbuffer::~pstringbuffer() +{ + if (m_ptr != NULL) + pfree_array(m_ptr); +} + +void pstringbuffer::resize(const std::size_t size) +{ + if (m_ptr == NULL) + { + m_size = DEFAULT_SIZE; + while (m_size <= size) + m_size *= 2; + m_ptr = palloc_array(char, m_size); + m_len = 0; + } + else if (m_size < size) + { + while (m_size < size) + m_size *= 2; + char *new_buf = palloc_array(char, m_size); + std::strncpy(new_buf, m_ptr, m_len + 1); + pfree_array(m_ptr); + m_ptr = new_buf; + } +} + +void pstringbuffer::pcopy(const char *from) +{ + std::size_t nl = strlen(from) + 1; + resize(nl); + std::strncpy(m_ptr, from, nl); +} + +void pstringbuffer::pcopy(const pstring &from) +{ + std::size_t nl = from.len() + 1; + resize(nl); + std::strncpy(m_ptr, from.cstr(), nl); +} + +void pstringbuffer::pcat(const char *s) +{ + std::size_t slen = std::strlen(s); + std::size_t nl = m_len + slen + 1; + resize(nl); + std::strncpy(m_ptr + m_len, s, slen + 1); + m_len += slen; +} + +void pstringbuffer::pcat(const pstring &s) +{ + std::size_t slen = s.len(); + std::size_t nl = m_len + slen + 1; + resize(nl); + std::strncpy(m_ptr + m_len, s.cstr(), slen + 1); + m_len += slen; +} diff --git a/src/emu/netlist/plib/pstring.h b/src/emu/netlist/plib/pstring.h new file mode 100644 index 00000000000..7cfb936472c --- /dev/null +++ b/src/emu/netlist/plib/pstring.h @@ -0,0 +1,256 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * pstring.h + */ + +#ifndef _PSTRING_H_ +#define _PSTRING_H_ + +#include "pconfig.h" + +// ---------------------------------------------------------------------------------------- +// pstring: immutable strings ... +// +// pstrings are just a pointer to a "pascal-style" string representation. +// It uses reference counts and only uses new memory when a string changes. +// ---------------------------------------------------------------------------------------- + +struct pstring +{ +public: + // simple construction/destruction + pstring() + { + init(); + } + ~pstring(); + + // construction with copy + pstring(const char *string) {init(); if (string != NULL && *string != 0) pcopy(string); } + pstring(const pstring &string) {init(); pcopy(string); } + + // assignment operators + pstring &operator=(const char *string) { pcopy(string); return *this; } + pstring &operator=(const pstring &string) { pcopy(string); return *this; } + + // C string conversion operators and helpers + operator const char *() const { return m_ptr->str(); } + inline const char *cstr() const { return m_ptr->str(); } + + // concatenation operators + pstring& operator+=(const char c) { char buf[2] = { c, 0 }; pcat(buf); return *this; } + pstring& operator+=(const pstring &string) { pcat(string.cstr()); return *this; } + pstring& operator+=(const char *string) { pcat(string); return *this; } + friend pstring operator+(const pstring &lhs, const pstring &rhs) { return pstring(lhs) += rhs; } + friend pstring operator+(const pstring &lhs, const char *rhs) { return pstring(lhs) += rhs; } + friend pstring operator+(const pstring &lhs, const char rhs) { return pstring(lhs) += rhs; } + friend pstring operator+(const char *lhs, const pstring &rhs) { return pstring(lhs) += rhs; } + + // comparison operators + bool operator==(const char *string) const { return (pcmp(string) == 0); } + bool operator==(const pstring &string) const { return (pcmp(string.cstr()) == 0); } + bool operator!=(const char *string) const { return (pcmp(string) != 0); } + bool operator!=(const pstring &string) const { return (pcmp(string.cstr()) != 0); } + bool operator<(const char *string) const { return (pcmp(string) < 0); } + bool operator<(const pstring &string) const { return (pcmp(string.cstr()) < 0); } + bool operator<=(const char *string) const { return (pcmp(string) <= 0); } + bool operator<=(const pstring &string) const { return (pcmp(string.cstr()) <= 0); } + bool operator>(const char *string) const { return (pcmp(string) > 0); } + bool operator>(const pstring &string) const { return (pcmp(string.cstr()) > 0); } + bool operator>=(const char *string) const { return (pcmp(string) >= 0); } + bool operator>=(const pstring &string) const { return (pcmp(string.cstr()) >= 0); } + + inline int len() const { return m_ptr->len(); } + + inline bool equals(const pstring &string) const { return (pcmp(string.cstr(), m_ptr->str()) == 0); } + inline bool iequals(const pstring &string) const { return (pcmpi(string.cstr(), m_ptr->str()) == 0); } + + inline int cmp(const pstring &string) const { return pcmp(string.cstr()); } + inline int cmpi(const pstring &string) const { return pcmpi(cstr(), string.cstr()); } + + int find(const char *search, int start = 0) const; + + int find(const char search, int start = 0) const; + + // various + + inline bool startsWith(const pstring &arg) const { return (pcmp(cstr(), arg.cstr(), arg.len()) == 0); } + bool startsWith(const char *arg) const; + + pstring replace(const pstring &search, const pstring &replace) const; + + // these return nstring ... + inline pstring cat(const pstring &s) const { return *this + s; } + inline pstring cat(const char *s) const { return *this + s; } + + pstring substr(unsigned int start, int count = -1) const ; + + inline pstring left(unsigned int count) const { return substr(0, count); } + inline pstring right(unsigned int count) const { return substr(len() - count, count); } + + int find_first_not_of(const pstring no) const; + int find_last_not_of(const pstring no) const; + + pstring ltrim(const pstring ws = " \t\n\r") const; + pstring rtrim(const pstring ws = " \t\n\r") const; + inline pstring trim(const pstring ws = " \t\n\r") const { return this->ltrim(ws).rtrim(ws); } + + pstring rpad(const pstring ws, const int cnt) const + { + // FIXME: slow! + pstring ret = *this; + while (ret.len() < cnt) + ret += ws; + return ret.substr(0, cnt); + } + + pstring ucase() const; + + // conversions + + double as_double(bool *error = NULL) const; + + long as_long(bool *error = NULL) const; + + // printf using string as format ... + + pstring vprintf(va_list args) const; + + // static + static pstring sprintf(const char *format, ...) ATTR_PRINTF(1,2); + static void resetmem(); + +protected: + + struct str_t + { + //str_t() : m_ref_count(1), m_len(0) { m_str[0] = 0; } + str_t(const int alen) + { + init(alen); + } + void init(const int alen) + { + m_ref_count = 1; + m_len = alen; + m_str[0] = 0; + } + char *str() { return &m_str[0]; } + int len() { return m_len; } + int m_ref_count; + private: + int m_len; + char m_str[1]; + }; + + str_t *m_ptr; + +private: + inline void init() + { + m_ptr = &m_zero; + m_ptr->m_ref_count++; + } + + inline int pcmp(const char *right) const + { + return pcmp(m_ptr->str(), right); + } + + int pcmp(const char *left, const char *right, int count = -1) const; + + int pcmpi(const char *lhs, const char *rhs, int count = -1) const; + + void pcopy(const char *from, int size); + + void pcopy(const char *from); + + inline void pcopy(const pstring &from) + { + sfree(m_ptr); + m_ptr = from.m_ptr; + m_ptr->m_ref_count++; + } + + void pcat(const char *s); + + static str_t *salloc(int n); + static void sfree(str_t *s); + + static str_t m_zero; +}; + +// ---------------------------------------------------------------------------------------- +// pstringbuffer: a string buffer implementation +// +// string buffer are optimized to handle concatenations. This implementation is designed +// to specifically interact with pstrings nicely. +// ---------------------------------------------------------------------------------------- + +struct pstringbuffer +{ +public: + static const int DEFAULT_SIZE = 2048; + // simple construction/destruction + pstringbuffer() + { + init(); + resize(DEFAULT_SIZE); + } + + ~pstringbuffer(); + + // construction with copy + pstringbuffer(const char *string) {init(); if (string != NULL) pcopy(string); } + pstringbuffer(const pstring &string) {init(); pcopy(string); } + + // assignment operators + pstringbuffer &operator=(const char *string) { pcopy(string); return *this; } + pstringbuffer &operator=(const pstring &string) { pcopy(string); return *this; } + pstringbuffer &operator=(const pstringbuffer &string) { pcopy(string.cstr()); return *this; } + + // C string conversion operators and helpers + operator const char *() const { return m_ptr; } + inline const char *cstr() const { return m_ptr; } + + operator pstring() const { return pstring(m_ptr); } + + // concatenation operators + pstringbuffer& operator+=(const char c) { char buf[2] = { c, 0 }; pcat(buf); return *this; } + pstringbuffer& operator+=(const pstring &string) { pcat(string.cstr()); return *this; } + + inline std::size_t len() const { return m_len; } + + inline void cat(const pstring &s) { pcat(s); } + inline void cat(const char *s) { pcat(s); } + + pstring substr(unsigned int start, int count = -1) + { + return pstring(m_ptr).substr(start, count); + } + +private: + + inline void init() + { + m_ptr = NULL; + m_size = 0; + m_len = 0; + } + + void resize(const std::size_t size); + + void pcopy(const char *from); + void pcopy(const pstring &from); + void pcat(const char *s); + void pcat(const pstring &s); + + char *m_ptr; + std::size_t m_size; + std::size_t m_len; + +}; + + +#endif /* _PSTRING_H_ */ diff --git a/src/emu/netlist/plists.h b/src/emu/netlist/plists.h deleted file mode 100644 index 25ded23fe83..00000000000 --- a/src/emu/netlist/plists.h +++ /dev/null @@ -1,513 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * plists.h - * - */ - -#pragma once - -#ifndef PLISTS_H_ -#define PLISTS_H_ - -#include "palloc.h" -#include "pstring.h" - -// ---------------------------------------------------------------------------------------- -// parray_t: dynamic array -// ---------------------------------------------------------------------------------------- - -template -class parray_t -{ -public: - - ATTR_COLD parray_t(std::size_t numElements) - : m_list(0), m_capacity(0) - { - set_capacity(numElements); - } - - ATTR_COLD parray_t(const parray_t &rhs) - : m_list(0), m_capacity(0) - { - set_capacity(rhs.size()); - for (std::size_t i=0; i 0) - m_list = palloc_array(_ListClass, new_capacity); - else - m_list = NULL; - m_capacity = new_capacity; - } - -private: - - _ListClass * m_list; - int m_capacity; -}; - -// ---------------------------------------------------------------------------------------- -// plist_t: a simple list -// ---------------------------------------------------------------------------------------- -#if 0 -#include -//#define plist_t std::vector -template -class plist_t : public std::vector<_ListClass> -{ -public: - plist_t() : std::vector<_ListClass>() {} - plist_t(const int numElements) : std::vector<_ListClass>(numElements) {} - - /* inline */ void add(const _ListClass &elem) { this->push_back(elem); } - void clear_and_free() - { - for (_ListClass *i = this->data(); i < this->data() + this->size(); i++) - { - pfree(*i); - } - this->clear(); - } - /* inline */ bool contains(const _ListClass &elem) const - { - for (const _ListClass *i = this->data(); i < this->data() + this->size(); i++) - { - if (*i == elem) - return true; - } - return false; - } - - /* inline */ void remove(const _ListClass &elem) - { - for (int i = 0; i < this->size(); i++) - { - if (this->at(i) == elem) - { - this->erase(this->begin() + i); - return; - } - } - } - /* inline */ void remove_at(const int pos) - { - this->erase(this->begin() + pos); - } - - /* inline */ int indexof(const _ListClass &elem) const - { - for (int i = 0; i < this->size(); i++) - { - if (this->at(i) == elem) - return i; - } - return -1; - } - - ATTR_HOT /* inline */ void swap(const int pos1, const int pos2) - { - //nl_assert((pos1>=0) && (pos1=0) && (pos2 -class plist_t -{ -public: - - ATTR_COLD plist_t(const std::size_t numElements = 0) - { - m_capacity = numElements; - if (m_capacity == 0) - m_list = NULL; - else - m_list = this->alloc(m_capacity); - m_count = 0; - } - - ATTR_COLD plist_t(const plist_t &rhs) - { - m_capacity = rhs.capacity(); - if (m_capacity == 0) - m_list = NULL; - else - m_list = this->alloc(m_capacity); - m_count = 0; - for (std::size_t i=0; iadd(rhs[i]); - } - } - - ATTR_COLD plist_t &operator=(const plist_t &rhs) - { - this->clear(); - for (std::size_t i=0; iadd(rhs[i]); - } - return *this; - } - - - ~plist_t() - { - if (m_list != NULL) - this->dealloc(m_list); - m_list = NULL; - } - - ATTR_HOT /* inline */ _ListClass *data() { return m_list; } - - ATTR_HOT /* inline */ _ListClass& operator[](std::size_t index) { return *(m_list + index); } - ATTR_HOT /* inline */ const _ListClass& operator[](std::size_t index) const { return *(m_list + index); } - - ATTR_HOT /* inline */ void add(const _ListClass &elem) - { - if (m_count >= m_capacity){ - std::size_t new_size = m_capacity * 2; - if (new_size < 32) - new_size = 32; - set_capacity(new_size); - } - - m_list[m_count++] = elem; - } - - ATTR_HOT /* inline */ void remove(const _ListClass &elem) - { - for (std::size_t i = 0; i < m_count; i++) - { - if (m_list[i] == elem) - { - m_count --; - while (i < m_count) - { - m_list[i] = m_list[i+1]; - i++; - } - return; - } - } - } - - ATTR_HOT /* inline */ void remove_at(const std::size_t pos) - { - //nl_assert((pos>=0) && (pos=0) && (pos1=0) && (pos2 0) - { - _ListClass *m_new = this->alloc(new_capacity); - _ListClass *pd = m_new; - - if (cnt > new_capacity) - cnt = new_capacity; - for (_ListClass *ps = m_list; ps < m_list + cnt; ps++, pd++) - *pd = *ps; - if (m_list != NULL) - this->dealloc(m_list); - m_list = m_new; - m_count = cnt; - } - else - { - if (m_list != NULL) - this->dealloc(m_list); - m_list = NULL; - m_count = 0; - } - m_capacity = new_capacity; - } - - _ListClass *alloc(const std::size_t n) - { - return palloc_array(_ListClass, n); - } - - void dealloc(_ListClass *p) - { - pfree_array(p); - } - - std::size_t m_count; - _ListClass * m_list; - std::size_t m_capacity; -}; -#endif - -// ---------------------------------------------------------------------------------------- -// pnamedlist_t: a simple list of elements which have a name() interface -// ---------------------------------------------------------------------------------------- - -template -class pnamedlist_t : public plist_t<_ListClass> -{ -public: - _ListClass find(const pstring &name) const - { - for (int i=0; i < this->size(); i++) - if (get_name((*this)[i]) == name) - return (*this)[i]; - return _ListClass(NULL); - } - - void remove_by_name(const pstring &name) - { - plist_t<_ListClass>::remove(find(name)); - } - - bool add(_ListClass dev, bool allow_duplicate) - { - if (allow_duplicate) - plist_t<_ListClass>::add(dev); - else - { - if (!(this->find(get_name(dev)) == _ListClass(NULL))) - return false; - plist_t<_ListClass>::add(dev); - } - return true; - } - -private: - template static const pstring get_name(const T *elem) { return elem->name(); } - template static const pstring get_name(T *elem) { return elem->name(); } - template static const pstring get_name(const T &elem) { return elem.name(); } - -}; - - -// ---------------------------------------------------------------------------------------- -// pstack_t: a simple stack -// ---------------------------------------------------------------------------------------- - -template -class pstack_t -{ -public: - - ATTR_COLD pstack_t(const int numElements = 128) - : m_list(numElements) - { - } - - ATTR_COLD pstack_t(const pstack_t &rhs) - : m_list(rhs.m_list) - { - } - - ATTR_COLD pstack_t &operator=(const pstack_t &rhs) - { - m_list = rhs.m_list; - return *this; - } - - - ~pstack_t() - { - } - - ATTR_HOT /* inline */ void push(const _StackClass &elem) - { - m_list.add(elem); - } - - ATTR_HOT /* inline */ _StackClass peek() const - { - return m_list[m_list.size() - 1]; - } - - ATTR_HOT /* inline */ _StackClass pop() - { - _StackClass ret = peek(); - m_list.remove_at(m_list.size() - 1); - return ret; - } - - ATTR_HOT /* inline */ int count() const { return m_list.size(); } - ATTR_HOT /* inline */ bool empty() const { return (m_list.size() == 0); } - ATTR_HOT /* inline */ void reset() { m_list.reset(); } - ATTR_HOT /* inline */ int capacity() const { return m_list.capacity(); } - -private: - plist_t<_StackClass> m_list; -}; - -template -struct plinkedlist_element_t -{ - plinkedlist_element_t() : m_next(NULL) {} - _ListClass * m_next; - -}; - -// ---------------------------------------------------------------------------------------- -// plinkedlist_t: a simple linked list -// ---------------------------------------------------------------------------------------- - -template -class plinkedlist_t -{ -public: - - plinkedlist_t() : m_head(NULL) {} - - ATTR_HOT /* inline */ void insert(const _ListClass &before, _ListClass &elem) - { - if (m_head == &before) - { - elem.m_next = m_head; - m_head = elem; - } - else - { - _ListClass *p = m_head; - while (p != NULL) - { - if (p->m_next == &before) - { - elem->m_next = &before; - p->m_next = &elem; - return; - } - p = p->m_next; - } - //FXIME: throw a standard exception - //nl_assert_always(false, "element not found"); - } - } - - ATTR_HOT /* inline */ void insert(_ListClass &elem) - { - elem.m_next = m_head; - m_head = &elem; - } - - ATTR_HOT /* inline */ void add(_ListClass &elem) - { - _ListClass **p = &m_head; - while (*p != NULL) - { - p = &((*p)->m_next); - } - *p = &elem; - elem.m_next = NULL; - } - - ATTR_HOT /* inline */ void remove(const _ListClass &elem) - { - _ListClass **p = &m_head; - while (*p != &elem) - { - //nl_assert(*p != NULL); - p = &((*p)->m_next); - } - (*p) = elem.m_next; - } - - - ATTR_HOT static /* inline */ _ListClass *next(const _ListClass &elem) { return elem.m_next; } - ATTR_HOT static /* inline */ _ListClass *next(const _ListClass *elem) { return elem->m_next; } - ATTR_HOT /* inline */ _ListClass *first() const { return m_head; } - ATTR_HOT /* inline */ void clear() { m_head = NULL; } - ATTR_HOT /* inline */ bool is_empty() const { return (m_head == NULL); } - -private: - _ListClass *m_head; -}; - -#endif /* PLISTS_H_ */ diff --git a/src/emu/netlist/poptions.h b/src/emu/netlist/poptions.h deleted file mode 100644 index 7803a315d94..00000000000 --- a/src/emu/netlist/poptions.h +++ /dev/null @@ -1,213 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * poptions.h - * - */ - -#pragma once - -#ifndef POPTIONS_H_ -#define POPTIONS_H_ - -#include - -#include "pstring.h" -#include "plists.h" - -/*************************************************************************** - Options -***************************************************************************/ - -class poptions; - -class poption -{ -public: - poption() - : m_short(""), m_long(""), m_help(""), m_has_argument(false) - {} - - poption(pstring ashort, pstring along, pstring help, bool has_argument, poptions *parent = NULL); - - virtual ~poption() - { - } - - /* no_argument options will be called with "" argument */ - - virtual int parse(ATTR_UNUSED pstring argument) { return 0; } - - pstring m_short; - pstring m_long; - pstring m_help; - bool m_has_argument; -private: -}; - -class poption_str : public poption -{ -public: - poption_str(pstring ashort, pstring along, pstring defval, pstring help, poptions *parent = NULL) - : poption(ashort, along, help, true, parent), m_val(defval) - {} - - virtual int parse(pstring argument) { m_val = argument; return 0; } - - pstring operator ()() { return m_val; } -private: - pstring m_val; -}; - -class poption_bool : public poption -{ -public: - poption_bool(pstring ashort, pstring along, pstring help, poptions *parent = NULL) - : poption(ashort, along, help, false, parent), m_val(false) - {} - - virtual int parse(ATTR_UNUSED pstring argument) { m_val = true; return 0; } - - bool operator ()() { return m_val; } -private: - bool m_val; -}; - -class poption_double : public poption -{ -public: - poption_double(pstring ashort, pstring along, double defval, pstring help, poptions *parent = NULL) - : poption(ashort, along, help, true, parent), m_val(defval) - {} - - virtual int parse(pstring argument) - { - bool err = false; - m_val = argument.as_double(&err); - return (err ? 1 : 0); - } - - double operator ()() { return m_val; } -private: - double m_val; -}; - -class poptions -{ -public: - - poptions() {} - - poptions(poption *o[]) - { - int i=0; - while (o[i] != NULL) - { - m_opts.add(o[i]); - i++; - } - } - - ~poptions() - { - m_opts.clear(); - } - - void register_option(poption *opt) - { - m_opts.add(opt); - } - - int parse(int argc, char *argv[]) - { - m_app = argv[0]; - - for (int i=1; im_has_argument) - { - i++; // FIXME: are there more arguments? - if (opt->parse(argv[i]) != 0) - return i - 1; - } - else - opt->parse(""); - i++; - } - return argc; - } - - pstring help() - { - pstring ret; - - for (std::size_t i=0; im_short != "") - line += " -" + opt->m_short; - if (opt->m_long != "") - { - if (line != "") - line += ", "; - else - line = " "; - line += "--" + opt->m_long; - } - line = line.rpad(" ", 20).cat(opt->m_help); - ret = ret + line + "\n"; - } - return ret; - } - pstring app() { return m_app; } - -private: - - poption *getopt_short(pstring arg) - { - for (std::size_t i=0; i < m_opts.size(); i++) - { - if (m_opts[i]->m_short == arg) - return m_opts[i]; - } - return NULL; - } - poption *getopt_long(pstring arg) - { - for (std::size_t i=0; i < m_opts.size(); i++) - { - if (m_opts[i]->m_long == arg) - return m_opts[i]; - } - return NULL; - } - - plist_t m_opts; - pstring m_app; -}; - -poption::poption(pstring ashort, pstring along, pstring help, bool has_argument, poptions *parent) -: m_short(ashort), m_long(along), m_help(help), m_has_argument(has_argument) -{ - if (parent != NULL) - parent->register_option(this); -} - - -#endif /* POPTIONS_H_ */ diff --git a/src/emu/netlist/pparser.c b/src/emu/netlist/pparser.c deleted file mode 100644 index 8e58f0dcae7..00000000000 --- a/src/emu/netlist/pparser.c +++ /dev/null @@ -1,407 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pparser.c - * - */ - -#include - -#include "pparser.h" - -//#undef NL_VERBOSE_OUT -//#define NL_VERBOSE_OUT(x) printf x - -// ---------------------------------------------------------------------------------------- -// A simple tokenizer -// ---------------------------------------------------------------------------------------- - -pstring ptokenizer::currentline_str() -{ - char buf[300]; - int bufp = 0; - const char *p = m_line_ptr; - while (*p && *p != 10) - buf[bufp++] = *p++; - buf[bufp] = 0; - return pstring(buf); -} - - -void ptokenizer::skipeol() -{ - char c = getc(); - while (c) - { - if (c == 10) - { - c = getc(); - if (c != 13) - ungetc(); - return; - } - c = getc(); - } -} - - -unsigned char ptokenizer::getc() -{ - if (*m_px == 10) - { - m_line++; - m_line_ptr = m_px + 1; - } - if (*m_px) - return *(m_px++); - else - return *m_px; -} - -void ptokenizer::ungetc() -{ - m_px--; -} - -void ptokenizer::require_token(const token_id_t &token_num) -{ - require_token(get_token(), token_num); -} - -void ptokenizer::require_token(const token_t tok, const token_id_t &token_num) -{ - if (!tok.is(token_num)) - { - error("Error: expected token <%s> got <%s>\n", m_tokens[token_num.id()].cstr(), tok.str().cstr()); - } -} - -pstring ptokenizer::get_string() -{ - token_t tok = get_token(); - if (!tok.is_type(STRING)) - { - error("Error: expected a string, got <%s>\n", tok.str().cstr()); - } - return tok.str(); -} - -pstring ptokenizer::get_identifier() -{ - token_t tok = get_token(); - if (!tok.is_type(IDENTIFIER)) - { - error("Error: expected an identifier, got <%s>\n", tok.str().cstr()); - } - return tok.str(); -} - -ptokenizer::token_t ptokenizer::get_token() -{ - while (true) - { - token_t ret = get_token_internal(); - if (ret.is_type(ENDOFFILE)) - return ret; - - if (ret.is(m_tok_comment_start)) - { - do { - ret = get_token_internal(); - } while (ret.is_not(m_tok_comment_end)); - } - else if (ret.is(m_tok_line_comment)) - { - skipeol(); - } - else if (ret.str() == "#") - { - skipeol(); - } - else - return ret; - } -} - -ptokenizer::token_t ptokenizer::get_token_internal() -{ - /* skip ws */ - char c = getc(); - while (m_whitespace.find(c)>=0) - { - c = getc(); - if (eof()) - { - return token_t(ENDOFFILE); - } - } - if (m_identifier_chars.find(c)>=0) - { - /* read identifier till non identifier char */ - pstring tokstr = ""; - while (m_identifier_chars.find(c)>=0) { - tokstr += c; - c = getc(); - } - ungetc(); - token_id_t id = token_id_t(m_tokens.indexof(tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); - else - { - return token_t(IDENTIFIER, tokstr); - } - } - else if (c == m_string) - { - pstring tokstr = ""; - c = getc(); - while (c != m_string) - { - tokstr += c; - c = getc(); - } - return token_t(STRING, tokstr); - } - else - { - /* read identifier till first identifier char or ws */ - pstring tokstr = ""; - while ((m_identifier_chars.find(c)) < 0 && (m_whitespace.find(c) < 0)) { - tokstr += c; - /* expensive, check for single char tokens */ - if (tokstr.len() == 1) - { - token_id_t id = token_id_t(m_tokens.indexof(tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); - } - c = getc(); - } - ungetc(); - token_id_t id = token_id_t(m_tokens.indexof(tokstr)); - if (id.id() >= 0) - return token_t(id, tokstr); - else - { - return token_t(UNKNOWN, tokstr); - } - } - -} - -ATTR_COLD void ptokenizer::error(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - pstring errmsg1 = pstring(format).vprintf(ap); - va_end(ap); - - verror(errmsg1, currentline_no(), currentline_str()); - - //throw error; -} - -// ---------------------------------------------------------------------------------------- -// A simple preprocessor -// ---------------------------------------------------------------------------------------- - -ppreprocessor::ppreprocessor() -{ - m_expr_sep.add("("); - m_expr_sep.add(")"); - m_expr_sep.add("+"); - m_expr_sep.add("-"); - m_expr_sep.add("*"); - m_expr_sep.add("/"); - m_expr_sep.add("=="); - m_expr_sep.add(" "); - m_expr_sep.add("\t"); -} - -void ppreprocessor::error(const pstring &err) -{ - fprintf(stderr, "PREPRO ERROR: %s\n", err.cstr()); -} - - - -double ppreprocessor::expr(const nl_util::pstring_list &sexpr, std::size_t &start, int prio) -{ - double val; - pstring tok=sexpr[start]; - if (tok == "(") - { - start++; - val = expr(sexpr, start, prio); - if (sexpr[start] != ")") - error("parsing error!"); - start++; - } - else - { - tok=sexpr[start]; - val = tok.as_double(); - start++; - } - while (start < sexpr.size()) - { - tok=sexpr[start]; - if (tok == ")") - { - // FIXME: catch error - return val; - } - else if (tok == "+") - { - if (prio > 10) - return val; - start++; - val = val + expr(sexpr, start, 10); - } - else if (tok == "-") - { - if (prio > 10) - return val; - start++; - val = val - expr(sexpr, start, 10); - } - else if (tok == "*") - { - start++; - val = val * expr(sexpr, start, 20); - } - else if (tok == "/") - { - start++; - val = val / expr(sexpr, start, 20); - } - else if (tok == "==") - { - if (prio > 5) - return val; - start++; - val = (val == expr(sexpr, start, 5)) ? 1.0 : 0.0; - } - } - return val; -} - -ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name) -{ - for (std::size_t i = 0; im_replace); - else - ret.cat(elems[i]); - } - return pstring(ret.cstr()); -} - -static pstring catremainder(const nl_util::pstring_list &elems, std::size_t start, pstring sep) -{ - pstringbuffer ret = ""; - for (std::size_t i=start; i 3 && lti[1].equals("NETLIST")) - { - if (lti[2].equals("warning")) - error("NETLIST: " + catremainder(lti, 3, " ")); - } - } - else if (lti[0].equals("#define")) - { - if (lti.size() != 3) - error(pstring::sprintf("PREPRO: only simple defines allowed: %s", line.cstr())); - m_defines.add(define_t(lti[1], lti[2])); - } - else - error(pstring::sprintf("unknown directive on line %" SIZETFMT ": %s\n", i, line.cstr())); - } - else - { - //if (ifflag == 0 && level > 0) - // fprintf(stderr, "conditional: %s\n", line.cstr()); - if (ifflag == 0) - { - ret.cat(line); - ret.cat("\n"); - } - } - i++; - } - return pstring(ret.cstr()); -} diff --git a/src/emu/netlist/pparser.h b/src/emu/netlist/pparser.h deleted file mode 100644 index b44e83f649c..00000000000 --- a/src/emu/netlist/pparser.h +++ /dev/null @@ -1,178 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pparser.h - * - */ - -#ifndef PPARSER_H_ -#define PPARSER_H_ - -#include "pconfig.h" -#include "nl_config.h" // FIXME -#include "nl_util.h" - -class ptokenizer -{ - NETLIST_PREVENT_COPYING(ptokenizer) -public: - virtual ~ptokenizer() {} - - ptokenizer() - : m_line(1), m_line_ptr(NULL), m_px(NULL), m_string('"') - {} - - enum token_type - { - IDENTIFIER, - NUMBER, - TOKEN, - STRING, - COMMENT, - UNKNOWN, - ENDOFFILE - }; - - struct token_id_t - { - public: - token_id_t() : m_id(-2) {} - token_id_t(const int id) : m_id(id) {} - int id() const { return m_id; } - private: - int m_id; - }; - - struct token_t - { - token_t(token_type type) - { - m_type = type; - m_id = token_id_t(-1); - m_token =""; - } - token_t(token_type type, const pstring str) - { - m_type = type; - m_id = token_id_t(-1); - m_token = str; - } - token_t(const token_id_t id, const pstring str) - { - m_type = TOKEN; - m_id = id; - m_token = str; - } - - bool is(const token_id_t &tok_id) const { return m_id.id() == tok_id.id(); } - bool is_not(const token_id_t &tok_id) const { return !is(tok_id); } - - bool is_type(const token_type type) const { return m_type == type; } - - pstring str() const { return m_token; } - - private: - token_type m_type; - token_id_t m_id; - pstring m_token; - }; - - - int currentline_no() { return m_line; } - pstring currentline_str(); - - /* tokenizer stuff follows ... */ - - token_t get_token(); - pstring get_string(); - pstring get_identifier(); - - void require_token(const token_id_t &token_num); - void require_token(const token_t tok, const token_id_t &token_num); - - token_id_t register_token(pstring token) - { - m_tokens.add(token); - return token_id_t(m_tokens.size() - 1); - } - - void set_identifier_chars(pstring s) { m_identifier_chars = s; } - void set_number_chars(pstring s) { m_number_chars = s; } - void set_whitespace(pstring s) { m_whitespace = s; } - void set_comment(pstring start, pstring end, pstring line) - { - m_tok_comment_start = register_token(start); - m_tok_comment_end = register_token(end); - m_tok_line_comment = register_token(line); - m_string = '"'; - } - - token_t get_token_internal(); - void error(const char *format, ...) ATTR_PRINTF(2,3); - -protected: - void reset(const char *p) { m_px = p; m_line = 1; m_line_ptr = p; } - virtual void verror(pstring msg, int line_num, pstring line) = 0; - -private: - void skipeol(); - - unsigned char getc(); - void ungetc(); - bool eof() { return *m_px == 0; } - - int m_line; - const char * m_line_ptr; - const char * m_px; - - /* tokenizer stuff follows ... */ - - pstring m_identifier_chars; - pstring m_number_chars; - plist_t m_tokens; - pstring m_whitespace; - char m_string; - - token_id_t m_tok_comment_start; - token_id_t m_tok_comment_end; - token_id_t m_tok_line_comment; -}; - - -class ppreprocessor -{ - NETLIST_PREVENT_COPYING(ppreprocessor) -public: - - struct define_t - { - define_t() { }; - define_t(const pstring &name, const pstring &replace) - : m_name(name), m_replace(replace) - {} - pstring m_name; - pstring m_replace; - }; - - ppreprocessor(); - virtual ~ppreprocessor() {} - - pstring process(const pstring &contents); - -protected: - - double expr(const nl_util::pstring_list &sexpr, std::size_t &start, int prio); - - define_t *get_define(const pstring &name); - - pstring replace_macros(const pstring &line); - - virtual void error(const pstring &err); - -private: - - plist_t m_defines; - nl_util::pstring_list m_expr_sep; -}; - -#endif /* PPARSER_H_ */ diff --git a/src/emu/netlist/pstate.c b/src/emu/netlist/pstate.c deleted file mode 100644 index 07532032405..00000000000 --- a/src/emu/netlist/pstate.c +++ /dev/null @@ -1,77 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pstate.c - * - */ - -#include "pstate.h" - -pstate_manager_t::pstate_manager_t() -{ -} - -pstate_manager_t::~pstate_manager_t() -{ - m_save.clear_and_free(); -} - - - -ATTR_COLD void pstate_manager_t::save_state_ptr(const pstring &stname, const pstate_data_type_e dt, const void *owner, const int size, const int count, void *ptr, bool is_ptr) -{ - pstring fullname = stname; - ATTR_UNUSED pstring ts[] = { - "NOT_SUPPORTED", - "DT_CUSTOM", - "DT_DOUBLE", - "DT_INT64", - "DT_INT16", - "DT_INT8", - "DT_INT", - "DT_BOOLEAN", - "DT_FLOAT" - }; - - pstate_entry_t *p = palloc(pstate_entry_t, stname, dt, owner, size, count, ptr, is_ptr); - m_save.add(p); -} - -ATTR_COLD void pstate_manager_t::remove_save_items(const void *owner) -{ - pstate_entry_t::list_t todelete; - - for (std::size_t i=0; i < m_save.size(); i++) - { - if (m_save[i]->m_owner == owner) - todelete.add(m_save[i]); - } - for (std::size_t i=0; i < todelete.size(); i++) - { - m_save.remove(todelete[i]); - } - todelete.clear_and_free(); -} - -ATTR_COLD void pstate_manager_t::pre_save() -{ - for (std::size_t i=0; i < m_save.size(); i++) - if (m_save[i]->m_dt == DT_CUSTOM) - m_save[i]->m_callback->on_pre_save(); -} - -ATTR_COLD void pstate_manager_t::post_load() -{ - for (std::size_t i=0; i < m_save.size(); i++) - if (m_save[i]->m_dt == DT_CUSTOM) - m_save[i]->m_callback->on_post_load(); -} - -template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname) -{ - //save_state_ptr(stname, DT_CUSTOM, 0, 1, &state); - pstate_callback_t *state_p = &state; - pstate_entry_t *p = palloc(pstate_entry_t, stname, owner, state_p); - m_save.add(p); - state.register_state(*this, stname); -} diff --git a/src/emu/netlist/pstate.h b/src/emu/netlist/pstate.h deleted file mode 100644 index 73b83e65a00..00000000000 --- a/src/emu/netlist/pstate.h +++ /dev/null @@ -1,162 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pstate.h - * - */ - -#ifndef PSTATE_H_ -#define PSTATE_H_ - -#include "plists.h" -#include "pstring.h" - -// ---------------------------------------------------------------------------------------- -// state saving ... -// ---------------------------------------------------------------------------------------- - -#define PSTATE_INTERFACE_DECL() \ - template ATTR_COLD void save(C &state, const pstring &stname); \ - template ATTR_COLD void save(C (&state)[N], const pstring &stname); \ - template ATTR_COLD void save(C *state, const pstring &stname, const int count); - -#define PSTATE_INTERFACE(obj, manager, module) \ - template ATTR_COLD void obj::save(C &state, const pstring &stname) \ - { manager->save_item(state, this, module + "." + stname); } \ - template ATTR_COLD void obj::save(C (&state)[N], const pstring &stname) \ - { manager->save_state_ptr(module + "." + stname, nl_datatype::type, this, sizeof(state[0]), N, &(state[0]), false); } \ - template ATTR_COLD void obj::save(C *state, const pstring &stname, const int count) \ - { manager->save_state_ptr(module + "." + stname, nl_datatype::type, this, sizeof(C), count, state, false); } - -enum pstate_data_type_e { - NOT_SUPPORTED, - DT_CUSTOM, - DT_DOUBLE, - DT_INT64, - DT_INT16, - DT_INT8, - DT_INT, - DT_BOOLEAN, - DT_FLOAT -}; - -template struct nl_datatype -{ - static const pstate_data_type_e type = pstate_data_type_e(NOT_SUPPORTED); - static const bool is_ptr = false; -}; - -template struct nl_datatype<_ItemType *> -{ - static const pstate_data_type_e type = pstate_data_type_e(NOT_SUPPORTED); - static const bool is_ptr = true; -}; - -//template struct type_checker<_ItemType*> { static const bool is_atom = false; static const bool is_pointer = true; }; - -#define NETLIST_SAVE_TYPE(TYPE, TYPEDESC) \ - template<> struct nl_datatype{ static const pstate_data_type_e type = pstate_data_type_e(TYPEDESC); static const bool is_ptr = false;}; \ - template<> struct nl_datatype{ static const pstate_data_type_e type = pstate_data_type_e(TYPEDESC); static const bool is_ptr = true;} - -NETLIST_SAVE_TYPE(char, DT_INT8); -NETLIST_SAVE_TYPE(double, DT_DOUBLE); -NETLIST_SAVE_TYPE(float, DT_FLOAT); -NETLIST_SAVE_TYPE(INT8, DT_INT8); -NETLIST_SAVE_TYPE(UINT8, DT_INT8); -NETLIST_SAVE_TYPE(INT64, DT_INT64); -NETLIST_SAVE_TYPE(UINT64, DT_INT64); -NETLIST_SAVE_TYPE(bool, DT_BOOLEAN); -NETLIST_SAVE_TYPE(UINT32, DT_INT); -NETLIST_SAVE_TYPE(INT32, DT_INT); -NETLIST_SAVE_TYPE(UINT16, DT_INT16); -NETLIST_SAVE_TYPE(INT16, DT_INT16); -//NETLIST_SAVE_TYPE(netlist_time::INTERNALTYPE, DT_INT64); - -class pstate_manager_t; - -class pstate_callback_t -{ -public: - typedef plist_t list_t; - - virtual ~pstate_callback_t() { }; - - virtual void register_state(pstate_manager_t &manager, const pstring &module) = 0; - virtual void on_pre_save() = 0; - virtual void on_post_load() = 0; -protected: -}; - -struct pstate_entry_t -{ - typedef plist_t list_t; - - pstate_entry_t(const pstring &stname, const pstate_data_type_e dt, const void *owner, - const int size, const int count, void *ptr, bool is_ptr) - : m_name(stname), m_dt(dt), m_owner(owner), m_callback(NULL), m_size(size), m_count(count), m_ptr(ptr), m_is_ptr(is_ptr) { } - - pstate_entry_t(const pstring &stname, const void *owner, pstate_callback_t *callback) - : m_name(stname), m_dt(DT_CUSTOM), m_owner(owner), m_callback(callback), m_size(0), m_count(0), m_ptr(NULL), m_is_ptr(false) { } - - ~pstate_entry_t() { } - - pstring m_name; - const pstate_data_type_e m_dt; - const void *m_owner; - pstate_callback_t *m_callback; - const int m_size; - const int m_count; - void *m_ptr; - bool m_is_ptr; - - template - T *resolved() - { - if (m_is_ptr) - return *static_cast(m_ptr); - else - return static_cast(m_ptr); - } -}; - -class pstate_manager_t -{ -public: - - pstate_manager_t(); - ~pstate_manager_t(); - - template ATTR_COLD void save_item(C &state, const void *owner, const pstring &stname) - { - save_state_ptr(stname, nl_datatype::type, owner, sizeof(C), 1, &state, nl_datatype::is_ptr); - } - - template ATTR_COLD void save_item(C (&state)[N], const void *owner, const pstring &stname) - { - save_state_ptr(stname, nl_datatype::type, owner, sizeof(state[0]), N, &(state[0]), false); - } - - template ATTR_COLD void save_item(C *state, const void *owner, const pstring &stname, const int count) - { - save_state_ptr(stname, nl_datatype::type, owner, sizeof(C), count, state, false); - } - - ATTR_COLD void pre_save(); - ATTR_COLD void post_load(); - ATTR_COLD void remove_save_items(const void *owner); - - inline const pstate_entry_t::list_t &save_list() const { return m_save; } - - // FIXME: should be protected - ATTR_COLD void save_state_ptr(const pstring &stname, const pstate_data_type_e, const void *owner, const int size, const int count, void *ptr, bool is_ptr); - -protected: - -private: - pstate_entry_t::list_t m_save; -}; - -template<> ATTR_COLD void pstate_manager_t::save_item(pstate_callback_t &state, const void *owner, const pstring &stname); - - -#endif /* PSTATE_H_ */ diff --git a/src/emu/netlist/pstring.c b/src/emu/netlist/pstring.c deleted file mode 100644 index ec930808e7b..00000000000 --- a/src/emu/netlist/pstring.c +++ /dev/null @@ -1,360 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * nl_string.c - * - */ - -#include -#include -#include -//FIXME:: pstring should be locale free -#include -#include - -#include "pstring.h" -#include "palloc.h" - -// The following will work on linux, however not on Windows .... - -//pblockpool *pstring::m_pool = new pblockpool; -//pstring::str_t *pstring::m_zero = new(pstring::m_pool, 0) pstring::str_t(0); - -pstring::str_t pstring::m_zero = str_t(0); - -/* - * Uncomment the following to override defaults - */ - -#define IMMEDIATE_MODE (1) -//#define DEBUG_MODE (0) - -#ifdef MAME_DEBUG - #ifndef IMMEDIATE_MODE - #define IMMEDIATE_MODE (1) - #endif - #ifndef DEBUG_MODE - #define DEBUG_MODE (0) - #endif -#else - #ifndef IMMEDIATE_MODE - #define IMMEDIATE_MODE (1) - #endif - #ifndef DEBUG_MODE - #define DEBUG_MODE (0) - #endif -#endif - -pstring::~pstring() -{ - sfree(m_ptr); -} - -void pstring::pcat(const char *s) -{ - int slen = strlen(s); - str_t *n = salloc(m_ptr->len() + slen); - if (m_ptr->len() > 0) - std::memcpy(n->str(), m_ptr->str(), m_ptr->len()); - if (slen > 0) - std::memcpy(n->str() + m_ptr->len(), s, slen); - *(n->str() + n->len()) = 0; - sfree(m_ptr); - m_ptr = n; -} - -void pstring::pcopy(const char *from, int size) -{ - str_t *n = salloc(size); - if (size > 0) - std::memcpy(n->str(), from, size); - *(n->str() + size) = 0; - sfree(m_ptr); - m_ptr = n; -} - -pstring pstring::substr(unsigned int start, int count) const -{ - pstring ret; - unsigned alen = len(); - if (start >= alen) - return ret; - if (count <0 || start + count > alen) - count = alen - start; - ret.pcopy(cstr() + start, count); - return ret; -} - -pstring pstring::ucase() const -{ - pstring ret = *this; - ret.pcopy(cstr(), len()); - for (int i=0; istr()[i] = toupper((unsigned) ret.m_ptr->str()[i]); - return ret; -} - -int pstring::find_first_not_of(const pstring no) const -{ - for (int i=0; i < len(); i++) - { - bool f = true; - for (int j=0; j < no.len(); j++) - if (m_ptr->str()[i] == no.m_ptr->str()[j]) - f = false; - if (f) - return i; - } - return -1; -} - -int pstring::find_last_not_of(const pstring no) const -{ - for (int i=len() - 1; i >= 0; i--) - { - bool f = true; - for (int j=0; j < no.len(); j++) - if (m_ptr->str()[i] == no.m_ptr->str()[j]) - f = false; - if (f) - return i; - } - return -1; -} - -pstring pstring::replace(const pstring &search, const pstring &replace) const -{ - pstring ret = ""; - - if (search.len() == 0) - return *this; - int i = 0; - while (i=0) - return substr(f); - else - return ""; -} - -pstring pstring::rtrim(const pstring ws) const -{ - int f = find_last_not_of(ws); - if (f>=0) - return left(f+1); - else - return ""; -} - -void pstring::pcopy(const char *from) -{ - pcopy(from, strlen(from)); -} - -//------------------------------------------------- -// pcmpi - compare a character array to an nstring -//------------------------------------------------- - -int pstring::pcmpi(const char *lhs, const char *rhs, int count) const -{ - // loop while equal until we hit the end of strings - int index; - for (index = 0; index < count; index++) - if (lhs[index] == 0 || std::tolower(lhs[index]) != std::tolower(rhs[index])) - break; - - // determine the final result - if (index < count) - return std::tolower(lhs[index]) - std::tolower(rhs[index]); - if (lhs[index] == 0) - return 0; - return 1; -} - -double pstring::as_double(bool *error) const -{ - double ret; - char *e = NULL; - - if (error != NULL) - *error = false; - ret = strtod(cstr(), &e); - if (*e != 0) - if (error != NULL) - *error = true; - return ret; -} - -long pstring::as_long(bool *error) const -{ - long ret; - char *e = NULL; - - if (error != NULL) - *error = false; - if (startsWith("0x")) - ret = strtol(&(cstr()[2]), &e, 16); - else - ret = strtol(cstr(), &e, 10); - if (*e != 0) - if (error != NULL) - *error = true; - return ret; -} - -pstring pstring::vprintf(va_list args) const -{ - // sprintf into the temporary buffer - char tempbuf[4096]; - std::vsprintf(tempbuf, cstr(), args); - - return pstring(tempbuf); -} - -// ---------------------------------------------------------------------------------------- -// static stuff ... -// ---------------------------------------------------------------------------------------- - -void pstring::sfree(str_t *s) -{ - s->m_ref_count--; - if (s->m_ref_count == 0 && s != &m_zero) - { - pfree_array(((char *)s)); - //_mm_free(((char *)s)); - } -} - -pstring::str_t *pstring::salloc(int n) -{ - int size = sizeof(str_t) + n + 1; - str_t *p = (str_t *) palloc_array(char, size); - // str_t *p = (str_t *) _mm_malloc(size, 8); - p->init(n); - return p; -} - -void pstring::resetmem() -{ - // Release the 0 string -} - -// ---------------------------------------------------------------------------------------- -// pstring ... -// ---------------------------------------------------------------------------------------- - -pstring pstring::sprintf(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - pstring ret = pstring(format).vprintf(ap); - va_end(ap); - return ret; -} - - -int pstring::find(const char *search, int start) const -{ - int alen = len(); - const char *result = std::strstr(cstr() + std::min(start, alen), search); - return (result != NULL) ? (result - cstr()) : -1; -} - -int pstring::find(const char search, int start) const -{ - int alen = len(); - const char *result = std::strchr(cstr() + std::min(start, alen), search); - return (result != NULL) ? (result - cstr()) : -1; -} - -bool pstring::startsWith(const char *arg) const -{ - return (pcmp(cstr(), arg, std::strlen(arg)) == 0); -} - -int pstring::pcmp(const char *left, const char *right, int count) const -{ - if (count < 0) - return std::strcmp(left, right); - else - return std::strncmp(left, right, count); -} - -// ---------------------------------------------------------------------------------------- -// pstringbuffer -// ---------------------------------------------------------------------------------------- - -pstringbuffer::~pstringbuffer() -{ - if (m_ptr != NULL) - pfree_array(m_ptr); -} - -void pstringbuffer::resize(const std::size_t size) -{ - if (m_ptr == NULL) - { - m_size = DEFAULT_SIZE; - while (m_size <= size) - m_size *= 2; - m_ptr = palloc_array(char, m_size); - m_len = 0; - } - else if (m_size < size) - { - while (m_size < size) - m_size *= 2; - char *new_buf = palloc_array(char, m_size); - std::strncpy(new_buf, m_ptr, m_len + 1); - pfree_array(m_ptr); - m_ptr = new_buf; - } -} - -void pstringbuffer::pcopy(const char *from) -{ - std::size_t nl = strlen(from) + 1; - resize(nl); - std::strncpy(m_ptr, from, nl); -} - -void pstringbuffer::pcopy(const pstring &from) -{ - std::size_t nl = from.len() + 1; - resize(nl); - std::strncpy(m_ptr, from.cstr(), nl); -} - -void pstringbuffer::pcat(const char *s) -{ - std::size_t slen = std::strlen(s); - std::size_t nl = m_len + slen + 1; - resize(nl); - std::strncpy(m_ptr + m_len, s, slen + 1); - m_len += slen; -} - -void pstringbuffer::pcat(const pstring &s) -{ - std::size_t slen = s.len(); - std::size_t nl = m_len + slen + 1; - resize(nl); - std::strncpy(m_ptr + m_len, s.cstr(), slen + 1); - m_len += slen; -} diff --git a/src/emu/netlist/pstring.h b/src/emu/netlist/pstring.h deleted file mode 100644 index 7cfb936472c..00000000000 --- a/src/emu/netlist/pstring.h +++ /dev/null @@ -1,256 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * pstring.h - */ - -#ifndef _PSTRING_H_ -#define _PSTRING_H_ - -#include "pconfig.h" - -// ---------------------------------------------------------------------------------------- -// pstring: immutable strings ... -// -// pstrings are just a pointer to a "pascal-style" string representation. -// It uses reference counts and only uses new memory when a string changes. -// ---------------------------------------------------------------------------------------- - -struct pstring -{ -public: - // simple construction/destruction - pstring() - { - init(); - } - ~pstring(); - - // construction with copy - pstring(const char *string) {init(); if (string != NULL && *string != 0) pcopy(string); } - pstring(const pstring &string) {init(); pcopy(string); } - - // assignment operators - pstring &operator=(const char *string) { pcopy(string); return *this; } - pstring &operator=(const pstring &string) { pcopy(string); return *this; } - - // C string conversion operators and helpers - operator const char *() const { return m_ptr->str(); } - inline const char *cstr() const { return m_ptr->str(); } - - // concatenation operators - pstring& operator+=(const char c) { char buf[2] = { c, 0 }; pcat(buf); return *this; } - pstring& operator+=(const pstring &string) { pcat(string.cstr()); return *this; } - pstring& operator+=(const char *string) { pcat(string); return *this; } - friend pstring operator+(const pstring &lhs, const pstring &rhs) { return pstring(lhs) += rhs; } - friend pstring operator+(const pstring &lhs, const char *rhs) { return pstring(lhs) += rhs; } - friend pstring operator+(const pstring &lhs, const char rhs) { return pstring(lhs) += rhs; } - friend pstring operator+(const char *lhs, const pstring &rhs) { return pstring(lhs) += rhs; } - - // comparison operators - bool operator==(const char *string) const { return (pcmp(string) == 0); } - bool operator==(const pstring &string) const { return (pcmp(string.cstr()) == 0); } - bool operator!=(const char *string) const { return (pcmp(string) != 0); } - bool operator!=(const pstring &string) const { return (pcmp(string.cstr()) != 0); } - bool operator<(const char *string) const { return (pcmp(string) < 0); } - bool operator<(const pstring &string) const { return (pcmp(string.cstr()) < 0); } - bool operator<=(const char *string) const { return (pcmp(string) <= 0); } - bool operator<=(const pstring &string) const { return (pcmp(string.cstr()) <= 0); } - bool operator>(const char *string) const { return (pcmp(string) > 0); } - bool operator>(const pstring &string) const { return (pcmp(string.cstr()) > 0); } - bool operator>=(const char *string) const { return (pcmp(string) >= 0); } - bool operator>=(const pstring &string) const { return (pcmp(string.cstr()) >= 0); } - - inline int len() const { return m_ptr->len(); } - - inline bool equals(const pstring &string) const { return (pcmp(string.cstr(), m_ptr->str()) == 0); } - inline bool iequals(const pstring &string) const { return (pcmpi(string.cstr(), m_ptr->str()) == 0); } - - inline int cmp(const pstring &string) const { return pcmp(string.cstr()); } - inline int cmpi(const pstring &string) const { return pcmpi(cstr(), string.cstr()); } - - int find(const char *search, int start = 0) const; - - int find(const char search, int start = 0) const; - - // various - - inline bool startsWith(const pstring &arg) const { return (pcmp(cstr(), arg.cstr(), arg.len()) == 0); } - bool startsWith(const char *arg) const; - - pstring replace(const pstring &search, const pstring &replace) const; - - // these return nstring ... - inline pstring cat(const pstring &s) const { return *this + s; } - inline pstring cat(const char *s) const { return *this + s; } - - pstring substr(unsigned int start, int count = -1) const ; - - inline pstring left(unsigned int count) const { return substr(0, count); } - inline pstring right(unsigned int count) const { return substr(len() - count, count); } - - int find_first_not_of(const pstring no) const; - int find_last_not_of(const pstring no) const; - - pstring ltrim(const pstring ws = " \t\n\r") const; - pstring rtrim(const pstring ws = " \t\n\r") const; - inline pstring trim(const pstring ws = " \t\n\r") const { return this->ltrim(ws).rtrim(ws); } - - pstring rpad(const pstring ws, const int cnt) const - { - // FIXME: slow! - pstring ret = *this; - while (ret.len() < cnt) - ret += ws; - return ret.substr(0, cnt); - } - - pstring ucase() const; - - // conversions - - double as_double(bool *error = NULL) const; - - long as_long(bool *error = NULL) const; - - // printf using string as format ... - - pstring vprintf(va_list args) const; - - // static - static pstring sprintf(const char *format, ...) ATTR_PRINTF(1,2); - static void resetmem(); - -protected: - - struct str_t - { - //str_t() : m_ref_count(1), m_len(0) { m_str[0] = 0; } - str_t(const int alen) - { - init(alen); - } - void init(const int alen) - { - m_ref_count = 1; - m_len = alen; - m_str[0] = 0; - } - char *str() { return &m_str[0]; } - int len() { return m_len; } - int m_ref_count; - private: - int m_len; - char m_str[1]; - }; - - str_t *m_ptr; - -private: - inline void init() - { - m_ptr = &m_zero; - m_ptr->m_ref_count++; - } - - inline int pcmp(const char *right) const - { - return pcmp(m_ptr->str(), right); - } - - int pcmp(const char *left, const char *right, int count = -1) const; - - int pcmpi(const char *lhs, const char *rhs, int count = -1) const; - - void pcopy(const char *from, int size); - - void pcopy(const char *from); - - inline void pcopy(const pstring &from) - { - sfree(m_ptr); - m_ptr = from.m_ptr; - m_ptr->m_ref_count++; - } - - void pcat(const char *s); - - static str_t *salloc(int n); - static void sfree(str_t *s); - - static str_t m_zero; -}; - -// ---------------------------------------------------------------------------------------- -// pstringbuffer: a string buffer implementation -// -// string buffer are optimized to handle concatenations. This implementation is designed -// to specifically interact with pstrings nicely. -// ---------------------------------------------------------------------------------------- - -struct pstringbuffer -{ -public: - static const int DEFAULT_SIZE = 2048; - // simple construction/destruction - pstringbuffer() - { - init(); - resize(DEFAULT_SIZE); - } - - ~pstringbuffer(); - - // construction with copy - pstringbuffer(const char *string) {init(); if (string != NULL) pcopy(string); } - pstringbuffer(const pstring &string) {init(); pcopy(string); } - - // assignment operators - pstringbuffer &operator=(const char *string) { pcopy(string); return *this; } - pstringbuffer &operator=(const pstring &string) { pcopy(string); return *this; } - pstringbuffer &operator=(const pstringbuffer &string) { pcopy(string.cstr()); return *this; } - - // C string conversion operators and helpers - operator const char *() const { return m_ptr; } - inline const char *cstr() const { return m_ptr; } - - operator pstring() const { return pstring(m_ptr); } - - // concatenation operators - pstringbuffer& operator+=(const char c) { char buf[2] = { c, 0 }; pcat(buf); return *this; } - pstringbuffer& operator+=(const pstring &string) { pcat(string.cstr()); return *this; } - - inline std::size_t len() const { return m_len; } - - inline void cat(const pstring &s) { pcat(s); } - inline void cat(const char *s) { pcat(s); } - - pstring substr(unsigned int start, int count = -1) - { - return pstring(m_ptr).substr(start, count); - } - -private: - - inline void init() - { - m_ptr = NULL; - m_size = 0; - m_len = 0; - } - - void resize(const std::size_t size); - - void pcopy(const char *from); - void pcopy(const pstring &from); - void pcat(const char *s); - void pcat(const pstring &s); - - char *m_ptr; - std::size_t m_size; - std::size_t m_len; - -}; - - -#endif /* _PSTRING_H_ */ diff --git a/src/tools/nltool.c b/src/tools/nltool.c index 555131defce..78d0633d121 100644 --- a/src/tools/nltool.c +++ b/src/tools/nltool.c @@ -11,23 +11,24 @@ #include #ifdef PSTANDALONE -#if (PSTANDALONE) + #if (PSTANDALONE) #define PSTANDALONE_PROVIDED + #endif #endif -#endif - -#ifdef PSTANDALONE_PROVIDED -#include - -#include "poptions.h" -#include "pstring.h" -#include "plists.h" +#include "plib/poptions.h" +#include "plib/pstring.h" +#include "plib/plists.h" #include "nl_setup.h" #include "nl_factory.h" #include "nl_parser.h" #include "devices/net_lib.h" + +#ifdef PSTANDALONE_PROVIDED + +#include + #define osd_ticks_t clock_t inline osd_ticks_t osd_ticks_per_second() { return CLOCKS_PER_SEC; } @@ -35,14 +36,8 @@ 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_factory.h" -#include "netlist/nl_parser.h" -#include "netlist/devices/net_lib.h" #endif + /*************************************************************************** * MAME COMPATIBILITY ... * @@ -209,7 +204,7 @@ public: void log_setup() { NL_VERBOSE_OUT(("Creating dynamic logs ...\n")); - nl_util::pstring_list ll = nl_util::split(m_logs, ":"); + pstring_list_t ll(m_logs, ":"); for (int i=0; i < ll.size(); i++) { pstring name = "log_" + ll[i]; @@ -360,7 +355,7 @@ public: void convert(const pstring &contents) { - nl_util::pstring_list spnl = nl_util::split(contents, "\n"); + pstring_list_t spnl(contents, "\n"); // Add gnd net @@ -369,7 +364,7 @@ public: pstring line = ""; - for (int i=0; i < spnl.size(); i++) + for (std::size_t i=0; i < spnl.size(); i++) { // Basic preprocessing pstring inl = spnl[i].trim().ucase(); @@ -393,14 +388,14 @@ protected: : m_name(aname), m_no_export(false) {} const pstring &name() { return m_name;} - nl_util::pstring_list &terminals() { return m_terminals; } + pstring_list_t &terminals() { return m_terminals; } void set_no_export() { m_no_export = true; } bool is_no_export() { return m_no_export; } private: pstring m_name; bool m_no_export; - nl_util::pstring_list m_terminals; + pstring_list_t m_terminals; }; struct sp_dev_t @@ -538,7 +533,7 @@ protected: { if (line != "") { - nl_util::pstring_list tt = nl_util::split(line, " ", true); + pstring_list_t tt(line, " ", true); double val = 0.0; switch (tt[0].cstr()[0]) { @@ -646,7 +641,7 @@ convert_t::sp_unit convert_t::m_sp_units[] = { {"", "%g", 1.0e0 }, {"M", "CAP_M(%g)", 1.0e-3 }, {"U", "CAP_U(%g)", 1.0e-6 }, - {"??", "CAP_U(%g)", 1.0e-6 }, + {"ยต", "CAP_U(%g)", 1.0e-6 }, {"N", "CAP_N(%g)", 1.0e-9 }, {"P", "CAP_P(%g)", 1.0e-12}, {"F", "%ge-15", 1.0e-15}, -- cgit v1.2.3 From 58a4e4528928cc9dff0bf89babc2c27ec722db42 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 28 May 2015 08:43:47 +0200 Subject: Fixed compile for portaudio on 32bit and windows clang (nw) --- scripts/src/3rdparty.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index aad89112883..a2485a1ff7f 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -624,6 +624,8 @@ project "portaudio" "-Wno-unused-variable", "-Wno-unused-value", "-Wno-unused-function", + "-Wno-unknown-pragmas", + "-Wno-sometimes-uninitialized", } configuration { "vs*" } @@ -657,21 +659,16 @@ project "portaudio" "PA_USE_DS=1", "PA_USE_WDMKS=1", "PA_USE_WMME=1", - "PA_USE_WASAPI=1", } includedirs { MAME_DIR .. "3rdparty/portaudio/src/os/win", } - configuration { "mingw*" } - includedirs { - MAME_DIR .. "3rdparty/portaudio/src/hostapi/wasapi/mingw-include", - } + configuration { } files { MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_util.c", MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_waveformat.c", MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_hostapis.c", - MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_x86_plain_converters.c", MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_wdmks_utils.c", MAME_DIR .. "3rdparty/portaudio/src/os/win/pa_win_coinitialize.c", MAME_DIR .. "3rdparty/portaudio/src/hostapi/dsound/pa_win_ds.c", @@ -679,7 +676,6 @@ project "portaudio" MAME_DIR .. "3rdparty/portaudio/src/hostapi/wdmks/pa_win_wdmks.c", MAME_DIR .. "3rdparty/portaudio/src/common/pa_ringbuffer.c", MAME_DIR .. "3rdparty/portaudio/src/hostapi/wmme/pa_win_wmme.c", - MAME_DIR .. "3rdparty/portaudio/src/hostapi/wasapi/pa_win_wasapi.c", } end -- cgit v1.2.3 From bef4e6d73a546a95e14bd09876ef315a8f71fe44 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 28 May 2015 08:48:03 +0200 Subject: fix for unknown warning options for clang 3.5 (nw) --- scripts/src/3rdparty.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index a2485a1ff7f..4e7330af691 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -619,7 +619,6 @@ project "portaudio" "-Wno-bad-function-cast", "-Wno-undef", "-Wno-missing-braces", - "-Wno-unused-but-set-variable", "-Wno-maybe-uninitialized", "-Wno-unused-variable", "-Wno-unused-value", @@ -628,6 +627,15 @@ project "portaudio" "-Wno-sometimes-uninitialized", } + local version = str_to_version(_OPTIONS["gcc_version"]) + if string.find(_OPTIONS["gcc"], "clang") then + if (version >= 30500) then + buildoptions { + "-Wno-unknown-warning-option", + } + end + end + configuration { "vs*" } buildoptions { "/wd4204", -- warning C4204: nonstandard extension used : non-constant aggregate initializer -- cgit v1.2.3 From 3b3f872d6847981f67d0e8055e72649b2a560d2c Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 28 May 2015 09:00:38 +0200 Subject: ups (nw) --- scripts/src/3rdparty.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index 4e7330af691..baea18c8398 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -619,6 +619,7 @@ project "portaudio" "-Wno-bad-function-cast", "-Wno-undef", "-Wno-missing-braces", + "-Wno-unused-but-set-variable", "-Wno-maybe-uninitialized", "-Wno-unused-variable", "-Wno-unused-value", -- cgit v1.2.3 From 4a07723b609cef6c22107294737db533b8f3fa3f Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 28 May 2015 09:07:30 +0200 Subject: set for all clangs (nw) --- scripts/src/3rdparty.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index baea18c8398..6d39a90ce8d 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -630,11 +630,9 @@ project "portaudio" local version = str_to_version(_OPTIONS["gcc_version"]) if string.find(_OPTIONS["gcc"], "clang") then - if (version >= 30500) then - buildoptions { - "-Wno-unknown-warning-option", - } - end + buildoptions_c { + "-Wno-unknown-warning-option", + } end configuration { "vs*" } -- cgit v1.2.3 From de8da0cc52dfc3986c14df985ccdb58bc280a2aa Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 28 May 2015 09:56:31 +0200 Subject: fix for one more warning (nw) --- scripts/src/3rdparty.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index 6d39a90ce8d..3daff931827 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -632,6 +632,7 @@ project "portaudio" if string.find(_OPTIONS["gcc"], "clang") then buildoptions_c { "-Wno-unknown-warning-option", + "-Wno-absolute-value", } end -- cgit v1.2.3 From 05664c66570fb8df774708cc2c1b2cebda623ab5 Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Thu, 28 May 2015 17:26:35 +0200 Subject: z80ne: updated to use the new wd fdc. remove custom dmk implementation --- scripts/src/lib.lua | 2 - src/lib/formats/z80ne_dsk.c | 807 -------------------------------------------- src/lib/formats/z80ne_dsk.h | 24 -- src/mess/drivers/z80ne.c | 24 +- src/mess/includes/z80ne.h | 14 +- src/mess/machine/z80ne.c | 49 ++- 6 files changed, 46 insertions(+), 874 deletions(-) delete mode 100644 src/lib/formats/z80ne_dsk.c delete mode 100644 src/lib/formats/z80ne_dsk.h (limited to 'scripts/src') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index a4bca8d6c50..166ab4beddb 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -393,8 +393,6 @@ project "formats" MAME_DIR .. "src/lib/formats/x1_tap.h", MAME_DIR .. "src/lib/formats/xdf_dsk.c", MAME_DIR .. "src/lib/formats/xdf_dsk.h", - MAME_DIR .. "src/lib/formats/z80ne_dsk.c", - MAME_DIR .. "src/lib/formats/z80ne_dsk.h", MAME_DIR .. "src/lib/formats/zx81_p.c", MAME_DIR .. "src/lib/formats/zx81_p.h", MAME_DIR .. "src/lib/formats/hxcmfm_dsk.c", diff --git a/src/lib/formats/z80ne_dsk.c b/src/lib/formats/z80ne_dsk.c deleted file mode 100644 index 1f82d844c88..00000000000 --- a/src/lib/formats/z80ne_dsk.c +++ /dev/null @@ -1,807 +0,0 @@ -// license:??? -// copyright-holders:Roberto Lavarone -/********************************************************************* - - formats/z80ne_dsk.c - - Nuova Elettronica Z80NE disk images - -*********************************************************************/ - -#include - -#include "z80ne_dsk.h" -#include "basicdsk.h" -#include "imageutl.h" -#include "coretmpl.h" - -/* ----------------------------------------------------------------------- - * DMK file format - * - * David M. Keil's disk image format is aptly called an 'on disk' image - * format. This means that whatever written to the disk is encoded into - * the image file. IDAMS, sector headers, trailing CRCs, and intra-sector - * spacing. * - * - * HEADER DESCRIPTION: - * - * Offset Bytes Field Description - * ------ ----- ------------ ----------- - * 0 1 write_prot 0xff = Write Protected, 0x00 = R/W - * 1 1 tracks Number of tracks - * 2 2 track_length Bytes per track on DMK file (little endian) - * 4 1 disk_options Miscellaneous flags - * bit 0-3: Unused - * bit 4: Sides on DMK file - * 1=single, 0=double - * bit 5: Unused - * bit 6: Single Density DMK file - * 1=single (bytes written once - * on IDAMs) - * 0=double (bytes written - * two times for SD IDAMs) - * 5 7 reserved Reserved for future use - * 12 4 real_disk_code If this is 0x12345678 (little endian) - * then access a real disk drive - * (unsupported) - * - * Each track begins with a track TOC, consisting of 64 little endian 16-bit - * integers. Each integer has the following format: - * bit 0-13: Offset from beginning of track to 'FE' byte of IDAM - * Note these are always sorted from first to last. All empty - * entries are 0x00 - * bit 14: Undefined (reserved) - * bit 15: Sector double density (0=SD 1=DD) - * If not set and SD DMK flag is set then bytes are written - * once. - * ----------------------------------------------------------------------- */ - -struct dmk_tag -{ - int heads; - int tracks; - UINT32 track_size; -}; - -/* DMK file structure - * See WD1711 documentation - */ -/* DMK file header */ -#define DMK_HEADER_LEN 16 /* DMK header */ - /* For every track (40) */ - #define DMK_TOC_LEN 128 /* 64 16-bit relative offsets to IDAMs */ - #define DMK_GAP1_LEN 32 /* GAP1 (26 bytes 0xFF and 6 bytes 0x00) */ - - /* For every sector (10) 301 bytes */ - #define DMK_IDAM_LEN 7 /* IDAM (0xFE, Track, 0x00, Sector, 0x00, CRChi, CRClo) */ - #define DMK_ID_GAP_LEN 17 /* GAP2 (11 bytes 0xFF and 6 bytes 0x00) */ - #define DMK_DAM_LEN 1 /* Data Address Mark (0xFB) */ - #define DMK_DATA_LEN 256 /* Data */ - #define DMK_DATA_CRC_LEN 2 /* Data CRC (CRChi, CRClo) */ - #define DMK_DATA_GAP_LEN 18 /* GAP3 (12 bytes 0xFF and 6 bytes 0x00) (not for last sector) */ - - #define DMK_EXTRA_TRACK_LENGTH (176) /* GAP4 (192 bytes 0xFF) */ -/* End of DMK file structure */ - -#define dmk_idam_type(x) (x)[0] -#define dmk_idam_track(x) (x)[1] -#define dmk_idam_side(x) (x)[2] -#define dmk_idam_sector(x) (x)[3] -#define dmk_idam_sectorlength(x) (x)[4] -#define dmk_idam_crc(x) (((x)[5] << 8) + (x)[6]) -#define dmk_idam_set_crc(x, crc) (x)[5] = ((crc) >> 8); (x)[6] = ((crc) >> 0); - -static const char needle_data[] = "\x00\x00\x00\x00\x00\x00\x00\x00\xFB\xFB"; -static const char needle_deleted_data_fa[] = "\x00\x00\x00\x00\x00\x00\x00\x00\xFA\xFA"; -static const char needle_deleted_data_f8[] = "\x00\x00\x00\x00\x00\x00\x00\x00\xF8\xF8"; - - -static struct dmk_tag *get_dmk_tag(floppy_image_legacy *floppy) -{ - return (dmk_tag *)floppy_tag(floppy); -} - - -static floperr_t z80ne_dmk_get_track_offset(floppy_image_legacy *floppy, int head, int track, UINT64 *offset) -{ - struct dmk_tag *tag = get_dmk_tag(floppy); - - if ((head < 0) || (head >= tag->heads) || (track < 0) || (track >= tag->tracks)) - return FLOPPY_ERROR_SEEKERROR; - - *offset = track; - *offset *= tag->heads; - *offset += head; - *offset *= tag->track_size; - *offset += DMK_HEADER_LEN; - return FLOPPY_ERROR_SUCCESS; -} - - -static UINT32 z80ne_dmk_min_track_size(int sectors, int sector_length) -{ - int sector_physical_length; - sector_physical_length = (DMK_IDAM_LEN + DMK_ID_GAP_LEN + DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN + DMK_DATA_GAP_LEN); - return DMK_TOC_LEN + 2 * (DMK_GAP1_LEN + (sectors * sector_physical_length) - DMK_DATA_GAP_LEN + DMK_EXTRA_TRACK_LENGTH); -} - - - -static floperr_t z80ne_dmk_read_track(floppy_image_legacy *floppy, int head, int track, UINT64 offset, void *buffer, size_t buflen) -{ - floperr_t err; - UINT64 track_offset; - - err = z80ne_dmk_get_track_offset(floppy, head, track, &track_offset); - if (err) - return err; - - floppy_image_read(floppy, buffer, offset + track_offset, buflen); - return FLOPPY_ERROR_SUCCESS; -} - - - -static floperr_t z80ne_dmk_write_track(floppy_image_legacy *floppy, int head, int track, UINT64 offset, const void *buffer, size_t buflen) -{ - floperr_t err; - UINT64 track_offset; - - err = z80ne_dmk_get_track_offset(floppy, head, track, &track_offset); - if (err) - return err; - - floppy_image_write(floppy, buffer, offset + track_offset, buflen); - return FLOPPY_ERROR_SUCCESS; -} - - - -static floperr_t z80ne_dmk_get_track_data_offset(floppy_image_legacy *floppy, int head, int track, UINT64 *offset) -{ - *offset = DMK_TOC_LEN + 1; - return FLOPPY_ERROR_SUCCESS; -} - - -static floperr_t z80ne_dmk_format_track(floppy_image_legacy *floppy, int head, int track, option_resolution *params) -{ - int sectors; - int sector_length; - int interleave; - int first_sector_id; - floperr_t err; - int physical_sector; - int logical_sector; - int track_position; - UINT16 idam_offset; - UINT16 crc; - UINT8 *track_data; - void *track_data_v; - UINT32 max_track_size; - std::vector sector_map; - dynamic_buffer local_sector; - int local_sector_size; - int sector_position; - int i; - - sectors = option_resolution_lookup_int(params, PARAM_SECTORS); - sector_length = option_resolution_lookup_int(params, PARAM_SECTOR_LENGTH); - interleave = option_resolution_lookup_int(params, PARAM_INTERLEAVE); - first_sector_id = option_resolution_lookup_int(params, PARAM_FIRST_SECTOR_ID); - - max_track_size = get_dmk_tag(floppy)->track_size; - - if (sectors > DMK_TOC_LEN/2) - { - err = FLOPPY_ERROR_INTERNAL; - goto done; - } - - if (max_track_size < z80ne_dmk_min_track_size(sectors, sector_length)) - { - err = FLOPPY_ERROR_NOSPACE; - goto done; - } - - err = floppy_load_track(floppy, head, track, TRUE, &track_data_v, NULL); - if (err) - goto done; - track_data = (UINT8 *) track_data_v; - - /* set up sector map */ - sector_map.resize(sectors); - memset(§or_map, 0xff, sectors); - - physical_sector = 0; - for (logical_sector = 0; logical_sector < sectors; logical_sector++) - { - while(sector_map[physical_sector] >= 0) - { - physical_sector++; - physical_sector %= sectors; - } - - sector_map[physical_sector] = logical_sector + first_sector_id; - physical_sector += interleave + 1; - physical_sector %= sectors; - } - - /* set up a local physical sector template */ - local_sector_size = (DMK_IDAM_LEN + - DMK_ID_GAP_LEN + - DMK_DAM_LEN + - sector_length + - DMK_DATA_CRC_LEN + - DMK_DATA_GAP_LEN); - local_sector.resize(local_sector_size); - memset(&local_sector, 0, local_sector_size); - - /* set up track table of contents */ - physical_sector = 0; - - /* write GAP1 (track lead in) */ - memset(&track_data[DMK_TOC_LEN], 0xFF, 52); - memset(&track_data[DMK_TOC_LEN+52], 0x00, 12); - track_position = DMK_TOC_LEN + DMK_GAP1_LEN * 2; - - /* - * prepare template in local sector - */ - - /* IDAM */ - sector_position = 0; - dmk_idam_type( &local_sector[sector_position]) = 0xFE; - dmk_idam_track( &local_sector[sector_position]) = track; - dmk_idam_side( &local_sector[sector_position]) = head; - dmk_idam_sector( &local_sector[sector_position]) = 0; /* replace in sector instances */ - dmk_idam_sectorlength( &local_sector[sector_position]) = compute_log2(sector_length / 128); - dmk_idam_set_crc( &local_sector[sector_position], 0); /* replace in sector instances */ - sector_position += 7; - - /* GAP2 (ID GAP) */ - memset(&local_sector[sector_position], 0xFF, 11); - sector_position += 11; - memset(&local_sector[sector_position], 0x00, 6); - sector_position += 6; - - /* sector body */ - local_sector[sector_position] = 0xFB; - memset(&local_sector[sector_position + 1], floppy_get_filler(floppy), sector_length); - crc = ccitt_crc16(0xffff, &local_sector[sector_position], sector_length + 1); - local_sector[sector_position + sector_length + 1] = (UINT8) (crc >> 8); - local_sector[sector_position + sector_length + 2] = (UINT8) (crc >> 0); - sector_position += sector_length + 3; - - /* GAP3 (Data GAP) */ - memset(&local_sector[sector_position], 0xFF, 12); - sector_position += 12; - memset(&local_sector[sector_position], 0x00, 6); - sector_position += 6; - - /* - * start of track data - */ - while(physical_sector < DMK_TOC_LEN/2) - { - if (physical_sector >= sectors) - { - /* no more sectors */ - idam_offset = 0; - } - else - { - /* this is a sector */ - idam_offset = track_position; - logical_sector = sector_map[physical_sector]; - - /* update IDAM in local sector template */ - dmk_idam_sector( &local_sector[0]) = logical_sector; /* update sector number in sector instance */ - crc = ccitt_crc16(0xffff, &local_sector[0], DMK_IDAM_LEN - 2); /* and recalculate crc */ - dmk_idam_set_crc( &local_sector[0], crc); - - /* write local sector in track doubling every byte (DMK double density mode) */ - for(i=0; i> 0); - track_data[physical_sector * 2 + 1] = (UINT8) (idam_offset >> 8); - - physical_sector++; - } - - /* write track footer GAP4 */ - assert(max_track_size >= (UINT32)track_position); - memset(&track_data[track_position], 0xFF, max_track_size - track_position); - -done: - return err; -} - - - -static int z80ne_dmk_get_heads_per_disk(floppy_image_legacy *floppy) -{ - return get_dmk_tag(floppy)->heads; -} - - - -static int z80ne_dmk_get_tracks_per_disk(floppy_image_legacy *floppy) -{ - return get_dmk_tag(floppy)->tracks; -} - - - -static UINT32 z80ne_dmk_get_track_size(floppy_image_legacy *floppy, int head, int track) -{ - return get_dmk_tag(floppy)->track_size; -} - -static UINT8 * my_memmem(UINT8 *haystack, size_t haystacklen, - UINT8 *needle, size_t needlelen) -{ - register UINT8 *h = haystack; - register UINT8 *n = needle; - register size_t hl = haystacklen; - register size_t nl = needlelen; - register size_t i; - - if (nl == 0) return haystack; /* The first occurrence of the empty string is deemed to occur at - the beginning of the string. */ - if (hl < nl) - return NULL; - - for( i = 0; (i < hl) && (i + nl <= hl ); i++ ) - if (h[i] == *n) /* first match */ - if ( !memcmp(&h[i]+1, n + 1, nl - 1) ) - return (haystack+i); /* returns a pointer to the substring */ - - return (UINT8 *)NULL; /* not found */ -} - - - -static floperr_t z80ne_dmk_seek_sector_in_track(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, int dirtify, UINT8 **sector_data, UINT32 *sector_length) -{ - struct dmk_tag *tag = get_dmk_tag(floppy); - floperr_t err; - size_t idam_offset = 0; - UINT16 calculated_crc; - size_t i, j; - size_t offs; - /*int state;*/ - UINT8 *track_data; - void *track_data_v; - size_t track_length; - size_t sec_len; - dynamic_buffer local_idam; - int local_idam_size; - UINT8 *sec_data; - - err = floppy_load_track(floppy, head, track, dirtify, &track_data_v, &track_length); - if (err) - goto done; - track_data = (UINT8 *) track_data_v; - - /* set up a local IDAM space */ - local_idam_size = (DMK_IDAM_LEN + - DMK_ID_GAP_LEN + - DMK_DAM_LEN + - DMK_DATA_GAP_LEN); - local_idam.resize(local_idam_size); - memset(&local_idam[0], 0, local_idam_size); - - /* search for matching IDAM */ - for (i = 0; i < DMK_TOC_LEN / 2; i++) - { - idam_offset = track_data[i * 2 + 1]; - idam_offset <<= 8; - idam_offset |= track_data[i * 2 + 0]; - idam_offset &= 0x3FFF; - - if (idam_offset == 0) - { - /* we've reached the end of the road */ - i = DMK_TOC_LEN; - break; - } - - if ((idam_offset + DMK_IDAM_LEN * 2) >= tag->track_size) - continue; - - /* overflowing the track? */ - if ((idam_offset + local_idam_size * 2) >= tag->track_size) - { - err = FLOPPY_ERROR_SEEKERROR; - goto done; - } - - /* create a local copy of sector of IDAM */ - for(j = 0; j < (DMK_IDAM_LEN + DMK_ID_GAP_LEN + DMK_DAM_LEN); j++) - local_idam[j] = track_data[idam_offset + j*2]; - - /* from now on all operations are done in local copy of IDAM */ - calculated_crc = ccitt_crc16(0xffff, &local_idam[0], DMK_IDAM_LEN - 2); - - /* check IDAM integrity and check for matching sector */ - if (calculated_crc == dmk_idam_crc(&local_idam[0])) - { - if (sector_is_index) - { - /* the sector is indexed; decrement the index and go */ - if (sector-- == 0) - break; - } - else - { - /* check for matching sector ID */ - if (sector == dmk_idam_sector(&local_idam[0])) - break; - } - } - } - - if (i >= DMK_TOC_LEN / 2) - { - err = FLOPPY_ERROR_SEEKERROR; - goto done; - } - - /* we found a matching sector ID */ - /*state = 0;*/ - offs = idam_offset + 2 * DMK_IDAM_LEN; - - /* find pattern 0x0000FB; this represents the start of a data sector */ - sec_data = my_memmem(&track_data[offs], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_data, 10); - if(!sec_data) - { - /* find pattern 0x0000FA; this represents the start of a deleted data sector (used for system sectors) */ - sec_data = my_memmem(&track_data[offs], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_fa, 10); - } - if(!sec_data) - { - /* find pattern 0x0000F8; this represents the start of a deleted data sector (used for system sectors) */ - sec_data = my_memmem(&track_data[offs], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_f8, 10); - } - - if(sec_data) - sec_data += 10; - else - { - err = FLOPPY_ERROR_SEEKERROR; - goto done; - } - offs = sec_data - &track_data[offs]; - - sec_len = 128 << dmk_idam_sectorlength(&local_idam[0]); - - if ((offs + 2 * sec_len) > track_length) - { - err = FLOPPY_ERROR_INVALIDIMAGE; - goto done; - } - - if (sector_data) - *sector_data = sec_data; - if (sector_length) - *sector_length = sec_len; -done: - return err; -} - - - -static floperr_t z80ne_dmk_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, UINT32 *sector_length) -{ - return z80ne_dmk_seek_sector_in_track(floppy, head, track, sector, FALSE, FALSE, NULL, sector_length); -} - - - -static floperr_t z80ne_dmk_get_indexed_sector_info(floppy_image_legacy *floppy, int head, int track, int sector_index, int *cylinder, int *side, int *sector, UINT32 *sector_length, unsigned long *flags) -{ - floperr_t err; - size_t idam_offset; - UINT8 *track_data; - void *track_data_v; - unsigned long dam; - - if (sector_index * 2 >= DMK_TOC_LEN) - return FLOPPY_ERROR_SEEKERROR; - - err = floppy_load_track(floppy, head, track, FALSE, &track_data_v, NULL); - if (err) - return err; - track_data = (UINT8 *) track_data_v; - - idam_offset = track_data[sector_index * 2 + 1]; - idam_offset <<= 8; - idam_offset |= track_data[sector_index * 2 + 0]; - idam_offset &= 0x3FFF; - - if (idam_offset == 0) - return FLOPPY_ERROR_SEEKERROR; - - /* determine type of data sector */ - /* find pattern 0x0000FB; this represents the start of a data sector */ - if ( my_memmem(&track_data[idam_offset+14], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_data, 10) ) - dam = 0; - /* find pattern 0x0000FA; this represents the start of a deleted data sector (used for system sectors) */ - else if ( my_memmem(&track_data[idam_offset+14], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_fa, 10) ) - dam = ID_FLAG_DELETED_DATA; - /* find pattern 0x0000F8; this represents the start of a deleted data sector (used for system sectors) */ - else if ( my_memmem(&track_data[idam_offset+14], 4 * (DMK_ID_GAP_LEN + DMK_DAM_LEN), (UINT8 *)needle_deleted_data_f8, 10) ) - dam = ID_FLAG_DELETED_DATA; - else - return FLOPPY_ERROR_SEEKERROR; - - if (cylinder) - *cylinder = (&track_data[idam_offset])[2]; - if (side) - *side = (&track_data[idam_offset])[4]; - if (sector) - *sector = (&track_data[idam_offset])[6]; - if (sector_length) - *sector_length = 128 << (&track_data[idam_offset])[8]; - if (flags) - *flags = dam; - return FLOPPY_ERROR_SUCCESS; -} - - - -static floperr_t internal_z80ne_dmk_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, void *buffer, size_t buflen) -{ - floperr_t err; - UINT32 sector_length; - UINT16 crc_on_disk; - UINT16 calculated_crc; - UINT8 *sector_data = NULL; - dynamic_buffer local_sector; - int local_sector_size; - int i; - - /* get sector length and data pointer */ - err = z80ne_dmk_seek_sector_in_track(floppy, head, track, sector, sector_is_index, FALSE, §or_data, §or_length); - if (err) - goto done; - - /* set up a local physical sector space (DAM + data + crc + GAP) */ - local_sector_size = (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN + DMK_DATA_GAP_LEN); - local_sector.resize(local_sector_size); - memset(&local_sector, 0, local_sector_size); - - /* get sector data */ - /* create a local copy of sector data including DAM (for crc calculation) */ - for(i = 0; i < (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN); i++) - local_sector[i] = (sector_data - 2)[i*2]; - - crc_on_disk = local_sector[sector_length + 0 + 1]; - crc_on_disk <<= 8; - crc_on_disk += local_sector[sector_length + 1 + 1]; - - /* crc calculated including DAM */ - calculated_crc = ccitt_crc16(0xffff, &local_sector[0], sector_length+1); - if (calculated_crc != crc_on_disk) - { - err = FLOPPY_ERROR_INVALIDIMAGE; - goto done; - } - - /* copy local sector data excluding DAM */ - memcpy(buffer, &local_sector[1], MIN(sector_length, buflen)); - - done: - return err; -} - - - -static floperr_t internal_z80ne_dmk_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, int sector_is_index, const void *buffer, size_t buflen, int ddam) -{ - floperr_t err; - UINT32 sector_length; - UINT8 *sector_data; - UINT16 crc; - dynamic_buffer local_sector; - int local_sector_size; - int i; - - /* get sector length */ - err = z80ne_dmk_seek_sector_in_track(floppy, head, track, sector, sector_is_index, TRUE, §or_data, §or_length); - if (err) - goto done; - - /* set up a local physical sector space */ - local_sector_size = (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN + DMK_DATA_GAP_LEN); - local_sector.resize(local_sector_size); - memset(&local_sector[0], 0, local_sector_size); - if(!ddam) - local_sector[0] = 0xFB; - else - local_sector[0] = 0xFA; - - if (buflen > sector_length) - { - err = FLOPPY_ERROR_INTERNAL; - goto done; - } - - memcpy(&local_sector[1], buffer, buflen); - - crc = ccitt_crc16(0xffff, &local_sector[0], DMK_DAM_LEN + sector_length); - local_sector[DMK_DAM_LEN + sector_length + 0] = crc >> 8; - local_sector[DMK_DAM_LEN + sector_length + 1] = crc >> 0; - - /* write local sector in track doubling every byte (DMK double density mode) */ - /* write DAM or DDAM too */ - sector_data -= 2; - for(i=0; i < (DMK_DAM_LEN + sector_length + DMK_DATA_CRC_LEN); i++) - sector_data[i*2] = sector_data[(i*2)+1] = local_sector[i]; - - done: - return err; -} - - - -static floperr_t z80ne_dmk_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen) -{ - return internal_z80ne_dmk_read_sector(floppy, head, track, sector, FALSE, buffer, buflen); -} - -static floperr_t z80ne_dmk_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam) -{ - return internal_z80ne_dmk_write_sector(floppy, head, track, sector, FALSE, buffer, buflen, ddam); -} - -static floperr_t z80ne_dmk_read_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen) -{ - return internal_z80ne_dmk_read_sector(floppy, head, track, sector, TRUE, buffer, buflen); -} - -static floperr_t z80ne_dmk_write_indexed_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam) -{ - return internal_z80ne_dmk_write_sector(floppy, head, track, sector, TRUE, buffer, buflen, ddam); -} - - - -static void z80ne_dmk_interpret_header(floppy_image_legacy *floppy, int *heads, int *tracks, int * sectors, int *track_size) -{ - UINT8 header[DMK_HEADER_LEN + DMK_TOC_LEN]; - int i; - int idam_offset; - int sects; - - floppy_image_read(floppy, header, 0, DMK_HEADER_LEN + DMK_TOC_LEN); - - if (tracks) - *tracks = header[1]; - if (heads) - *heads = (header[4] & 0x10) ? 1 : 2; - if (track_size) - *track_size = ((int) header[3]) * 0x100 + header[2]; - if(sectors) - { - /* count sectors on first track */ - sects = 0; - for (i = 0; i < DMK_TOC_LEN / 2; i++) - { - idam_offset = header[DMK_HEADER_LEN + i * 2 + 1]; - idam_offset <<= 8; - idam_offset |= header[DMK_HEADER_LEN + i * 2 + 0]; - idam_offset &= 0x3FFF; - - if (idam_offset == 0) - break; - else - sects++; - } - *sectors = sects; - } - -} - - - -FLOPPY_CONSTRUCT(z80ne_dmk_construct) -{ - struct FloppyCallbacks *callbacks; - struct dmk_tag *tag; - UINT8 header[DMK_HEADER_LEN]; - int heads, tracks, track_size, sectors, sector_length; - - if (params) - { - heads = option_resolution_lookup_int(params, PARAM_HEADS); - tracks = option_resolution_lookup_int(params, PARAM_TRACKS); - sectors = option_resolution_lookup_int(params, PARAM_SECTORS); - sector_length = option_resolution_lookup_int(params, PARAM_SECTOR_LENGTH); - - track_size = z80ne_dmk_min_track_size(sectors, sector_length); - - memset(header, 0, sizeof(header)); - header[1] = tracks; - header[2] = track_size >> 0; - header[3] = track_size >> 8; - header[4] = (heads == 2) ? 0x00 : 0x10; - - floppy_image_write(floppy, header, 0, sizeof(header)); - } - else - { - z80ne_dmk_interpret_header(floppy, &heads, &tracks, §ors, &track_size); - } - - tag = (dmk_tag*)floppy_create_tag(floppy, sizeof(struct dmk_tag)); - if (!tag) - return FLOPPY_ERROR_OUTOFMEMORY; - tag->heads = heads; - tag->track_size = track_size; - tag->tracks = tracks; - - callbacks = floppy_callbacks(floppy); - callbacks->read_track = z80ne_dmk_read_track; - callbacks->write_track = z80ne_dmk_write_track; - callbacks->get_track_data_offset = z80ne_dmk_get_track_data_offset; - callbacks->format_track = z80ne_dmk_format_track; - callbacks->get_heads_per_disk = z80ne_dmk_get_heads_per_disk; - callbacks->get_tracks_per_disk = z80ne_dmk_get_tracks_per_disk; - callbacks->get_track_size = z80ne_dmk_get_track_size; - callbacks->get_sector_length = z80ne_dmk_get_sector_length; - callbacks->get_indexed_sector_info = z80ne_dmk_get_indexed_sector_info; - callbacks->read_sector = z80ne_dmk_read_sector; - callbacks->write_sector = z80ne_dmk_write_sector; - callbacks->read_indexed_sector = z80ne_dmk_read_indexed_sector; - callbacks->write_indexed_sector = z80ne_dmk_write_indexed_sector; - - return FLOPPY_ERROR_SUCCESS; -} - - - -FLOPPY_IDENTIFY(z80ne_dmk_identify) -{ - int heads, tracks, sectors, track_size; - UINT64 size, expected_size; - - size = floppy_image_size(floppy); - z80ne_dmk_interpret_header(floppy, &heads, &tracks, §ors, &track_size); - expected_size = DMK_HEADER_LEN + (heads * tracks * track_size); - *vote = (size == expected_size) ? 90 : 0; - *vote += (sectors == 10) ? 10 : 0; - return FLOPPY_ERROR_SUCCESS; -} - - - -/* ----------------------------------------------------------------------- */ - -LEGACY_FLOPPY_OPTIONS_START( z80ne ) - /* - * Single side - * Single density - * FM, 125 kbit/s, - * 40 tracks, track ID: 0..39 - * 10 sectors/track, sector ID: 0..9 - * 256 bytes/sector - * Interleave 1 (sector ID sequence on track: 0 5 1 6 2 7 3 8 4 9) - * 3125 byte/track unformatted - * Rotation speed 300 rpm (5 rps) - */ - LEGACY_FLOPPY_OPTION( z80ne_dmk, "zmk", "Z80NE DMK disk image", z80ne_dmk_identify, z80ne_dmk_construct, NULL, - HEADS([1]) - TRACKS([40]) - SECTORS([10]) - SECTOR_LENGTH([256]) - INTERLEAVE([1]) - FIRST_SECTOR_ID([0])) -LEGACY_FLOPPY_OPTIONS_END diff --git a/src/lib/formats/z80ne_dsk.h b/src/lib/formats/z80ne_dsk.h deleted file mode 100644 index 8740008e821..00000000000 --- a/src/lib/formats/z80ne_dsk.h +++ /dev/null @@ -1,24 +0,0 @@ -// license:??? -// copyright-holders:Roberto Lavarone -/********************************************************************* - - formats/z80ne_dsk.h - - Nuova Elettronica Z80NE disk images - -*********************************************************************/ - -#ifndef Z80NE_DSK_H -#define Z80NE_DSK_H - -#include "flopimg.h" - - -/**************************************************************************/ - -LEGACY_FLOPPY_OPTIONS_EXTERN(z80ne); - -FLOPPY_IDENTIFY(z80ne_dmk_identify); -FLOPPY_CONSTRUCT(z80ne_dmk_construct); - -#endif /* Z80NE_DSK_H */ diff --git a/src/mess/drivers/z80ne.c b/src/mess/drivers/z80ne.c index a8031bf9397..c7e52a248f3 100644 --- a/src/mess/drivers/z80ne.c +++ b/src/mess/drivers/z80ne.c @@ -95,7 +95,7 @@ #include "cpu/z80/z80.h" #include "includes/z80ne.h" #include "imagedev/flopdrv.h" -#include "formats/z80ne_dsk.h" +#include "formats/dmk_dsk.h" #include "machine/ram.h" /* Layout */ @@ -400,12 +400,13 @@ static const UINT32 lx388palette[] = rgb_t(0xff, 0xc4, 0x18) /* ALPHANUMERIC BRIGHT ORANGE */ }; -static const floppy_interface z80netf_floppy_interface = -{ - FLOPPY_STANDARD_5_25_DSHD, - LEGACY_FLOPPY_OPTIONS_NAME(z80ne), - NULL -}; +FLOPPY_FORMATS_MEMBER( z80ne_state::floppy_formats ) + FLOPPY_DMK_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( z80ne_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) +SLOT_INTERFACE_END static MACHINE_CONFIG_START( z80ne, z80ne_state ) /* basic machine hardware */ @@ -526,10 +527,11 @@ static MACHINE_CONFIG_START( z80netf, z80ne_state ) // AG = GND, GM2 = GND, GM1 = GND, GM0 = GND, CSS = GND // other lines not connected - MCFG_DEVICE_ADD("wd1771", FD1771, 0) - MCFG_WD17XX_DEFAULT_DRIVE4_TAGS - - MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(z80netf_floppy_interface) + MCFG_FD1771x_ADD("wd1771", XTAL_2MHz / 2) + MCFG_FLOPPY_DRIVE_ADD("wd1771:0", z80ne_floppies, "sssd", z80ne_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd1771:1", z80ne_floppies, "sssd", z80ne_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd1771:2", z80ne_floppies, NULL, z80ne_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd1771:3", z80ne_floppies, NULL, z80ne_state::floppy_formats) MCFG_DEFAULT_LAYOUT(layout_z80netf) diff --git a/src/mess/includes/z80ne.h b/src/mess/includes/z80ne.h index 734dc6a57e6..6ba7c12831e 100644 --- a/src/mess/includes/z80ne.h +++ b/src/mess/includes/z80ne.h @@ -17,7 +17,7 @@ #include "imagedev/cassette.h" #include "machine/ay31015.h" #include "machine/kr2376.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" /*************************************************************************** CONSTANTS @@ -74,6 +74,10 @@ public: m_ay31015(*this, "ay_3_1015"), m_lx388_kr2376(*this, "lx388_kr2376"), m_maincpu(*this, "z80ne"), + m_floppy0(*this, "wd1771:0"), + m_floppy1(*this, "wd1771:1"), + m_floppy2(*this, "wd1771:2"), + m_floppy3(*this, "wd1771:3"), m_cassette1(*this, "cassette"), m_cassette2(*this, "cassette2"), m_wd1771(*this, "wd1771"), @@ -99,6 +103,8 @@ public: m_io_modifiers(*this, "MODIFIERS"), m_io_config(*this, "CONFIG") { } + DECLARE_FLOPPY_FORMATS(floppy_formats) + optional_device m_vdg; optional_shared_ptr m_videoram; required_device m_ay31015; @@ -148,9 +154,13 @@ public: protected: required_device m_maincpu; + optional_device m_floppy0; + optional_device m_floppy1; + optional_device m_floppy2; + optional_device m_floppy3; required_device m_cassette1; required_device m_cassette2; - optional_device m_wd1771; + optional_device m_wd1771; required_memory_region m_region_z80ne; optional_memory_bank m_bank1; optional_memory_bank m_bank2; diff --git a/src/mess/machine/z80ne.c b/src/mess/machine/z80ne.c index 6e476fbe57d..7ae31e9afac 100644 --- a/src/mess/machine/z80ne.c +++ b/src/mess/machine/z80ne.c @@ -652,37 +652,30 @@ WRITE8_MEMBER(z80ne_state::lx390_motor_w) d1 1=select drive 1 d0 1=select drive 0 */ - UINT8 drive = 255; + floppy_image_device *floppy = NULL; - if (data & 1) - drive = 0; - else - if (data & 2) - drive = 1; - else - if (data & 4) - drive = 2; - else - if (data & 8) - drive = 3; + if (BIT(data, 0)) floppy = m_floppy0->get_device(); + if (BIT(data, 1)) floppy = m_floppy1->get_device(); + if (BIT(data, 2)) floppy = m_floppy2->get_device(); + if (BIT(data, 3)) floppy = m_floppy3->get_device(); - m_wd17xx_state.head = (data & 32) ? 1 : 0; - m_wd17xx_state.drive = data & 0x0F; + m_wd1771->set_floppy(floppy); - /* no drive selected, turn off all leds */ - if (!m_wd17xx_state.drive) - { - output_set_value("drv0", 0); - output_set_value("drv1", 0); - } + if (floppy) + { + floppy->ss_w(BIT(data, 5)); + floppy->mon_w(0); + } - if (drive < 4) - { - LOG(("lx390_motor_w, set drive %1d\n", drive)); - m_wd1771->set_drive(drive); - LOG(("lx390_motor_w, set side %1d\n", m_wd17xx_state.head)); - m_wd1771->set_side(m_wd17xx_state.head); - } + m_wd17xx_state.head = (data & 32) ? 1 : 0; + m_wd17xx_state.drive = data & 0x0F; + + /* no drive selected, turn off all leds */ + if (!m_wd17xx_state.drive) + { + output_set_value("drv0", 0); + output_set_value("drv1", 0); + } } READ8_MEMBER(z80ne_state::lx390_reset_bank) @@ -748,7 +741,7 @@ WRITE8_MEMBER(z80ne_state::lx390_fdc_w) { case 0: LOG(("lx390_fdc_w, WD17xx command: %02x\n", d)); - m_wd1771->command_w(space, offset, d ^ 0xff); + m_wd1771->cmd_w(space, offset, d ^ 0xff); if (m_wd17xx_state.drive & 1) output_set_value("drv0", 2); else if (m_wd17xx_state.drive & 2) -- cgit v1.2.3 From de21d38efbcaa909cdc18690645a15e9c83de3a5 Mon Sep 17 00:00:00 2001 From: Peter Ferrie Date: Thu, 28 May 2015 09:38:32 -0700 Subject: 3rdparty.lua: add check for nil first (nw) --- scripts/src/3rdparty.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index 3daff931827..a140bef7860 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -629,7 +629,7 @@ project "portaudio" } local version = str_to_version(_OPTIONS["gcc_version"]) - if string.find(_OPTIONS["gcc"], "clang") then + if (_OPTIONS["gcc"]~=nil) and string.find(_OPTIONS["gcc"], "clang") then buildoptions_c { "-Wno-unknown-warning-option", "-Wno-absolute-value", -- cgit v1.2.3 From d3839b4058f1c0f7b55b0d78508ec1ad320094d2 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 29 May 2015 07:59:09 +0200 Subject: fixed clang (nw) --- scripts/src/3rdparty.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts/src') diff --git a/scripts/src/3rdparty.lua b/scripts/src/3rdparty.lua index ebca9fed0ef..bba91c7835e 100644 --- a/scripts/src/3rdparty.lua +++ b/scripts/src/3rdparty.lua @@ -632,6 +632,7 @@ project "portaudio" buildoptions_c { "-Wno-unknown-warning-option", "-Wno-absolute-value", + "-Wno-unused-variable", } end -- cgit v1.2.3 From 0624b6efd0665097ef84e8816298aaffeda31d9e Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Fri, 29 May 2015 23:46:56 +0200 Subject: restore my bbc changes (wtf did happen to them?) --- scripts/src/lib.lua | 2 + src/lib/formats/bbc_dsk.c | 53 +++++++++++++++++++++++++ src/lib/formats/bbc_dsk.h | 33 ++++++++++++++++ src/mess/drivers/bbc.c | 62 +++++++++++++++++++++--------- src/mess/includes/bbc.h | 4 +- src/mess/machine/bbc.c | 98 +++++++++++++++++++++++++++++------------------ 6 files changed, 194 insertions(+), 58 deletions(-) create mode 100644 src/lib/formats/bbc_dsk.c create mode 100644 src/lib/formats/bbc_dsk.h (limited to 'scripts/src') diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index ef809dd5b46..166ab4beddb 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -158,6 +158,8 @@ project "formats" MAME_DIR .. "src/lib/formats/atarist_dsk.h", MAME_DIR .. "src/lib/formats/atom_tap.c", MAME_DIR .. "src/lib/formats/atom_tap.h", + MAME_DIR .. "src/lib/formats/bbc_dsk.c", + MAME_DIR .. "src/lib/formats/bbc_dsk.h", MAME_DIR .. "src/lib/formats/bw2_dsk.c", MAME_DIR .. "src/lib/formats/bw2_dsk.h", MAME_DIR .. "src/lib/formats/bw12_dsk.c", diff --git a/src/lib/formats/bbc_dsk.c b/src/lib/formats/bbc_dsk.c new file mode 100644 index 00000000000..dfa78c0bfd8 --- /dev/null +++ b/src/lib/formats/bbc_dsk.c @@ -0,0 +1,53 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#include "bbc_dsk.h" + +bbc_format::bbc_format() : wd177x_format(formats) +{ +} + +const char *bbc_format::name() const +{ + return "bbc"; +} + +const char *bbc_format::description() const +{ + return "BBC Micro disk image"; +} + +const char *bbc_format::extensions() const +{ + return "bbc,img,ssd,dsd"; +} + +const bbc_format::format bbc_format::formats[] = +{ + { // 100k single sided single density + floppy_image::FF_525, floppy_image::SSSD, floppy_image::FM, + 4000, 10, 40, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k double sided single density + floppy_image::FF_525, floppy_image::DSSD, floppy_image::FM, + 4000, 10, 40, 2, 256, {}, 0, {}, 16, 11, 19 + }, + { // 200k single sided double density + floppy_image::FF_525, floppy_image::SSQD, floppy_image::FM, + 4000, 10, 80, 1, 256, {}, 0, {}, 16, 11, 19 + }, + { // 400k double sided double density + floppy_image::FF_525, floppy_image::DSQD, floppy_image::FM, + 4000, 10, 80, 2, 256, {}, 0, {}, 16, 11, 19 + }, + {} +}; + +const floppy_format_type FLOPPY_BBC_FORMAT = &floppy_image_format_creator; diff --git a/src/lib/formats/bbc_dsk.h b/src/lib/formats/bbc_dsk.h new file mode 100644 index 00000000000..e2520781a15 --- /dev/null +++ b/src/lib/formats/bbc_dsk.h @@ -0,0 +1,33 @@ +// license:GPL-2.0+ +// copyright-holders:Dirk Best +/*************************************************************************** + + BBC Micro + + Disk image format + +***************************************************************************/ + +#pragma once + +#ifndef __BBC_DSK_H__ +#define __BBC_DSK_H__ + +#include "wd177x_dsk.h" + +class bbc_format : public wd177x_format +{ +public: + bbc_format(); + + virtual const char *name() const; + virtual const char *description() const; + virtual const char *extensions() const; + +private: + static const format formats[]; +}; + +extern const floppy_format_type FLOPPY_BBC_FORMAT; + +#endif // __BBC_DSK_H__ diff --git a/src/mess/drivers/bbc.c b/src/mess/drivers/bbc.c index aa1ae726ac3..5a4df8785ac 100644 --- a/src/mess/drivers/bbc.c +++ b/src/mess/drivers/bbc.c @@ -57,6 +57,7 @@ /* Devices */ #include "imagedev/flopdrv.h" +#include "formats/bbc_dsk.h" #include "formats/basicdsk.h" #include "imagedev/cassette.h" #include "formats/uef_cas.h" @@ -609,6 +610,19 @@ static const floppy_interface bbc_floppy_interface = "floppy_5_25" }; +FLOPPY_FORMATS_MEMBER( bbc_state::floppy_formats ) + FLOPPY_BBC_FORMAT +FLOPPY_FORMATS_END + +static SLOT_INTERFACE_START( bbc_floppies ) + SLOT_INTERFACE("sssd", FLOPPY_525_SSSD) + SLOT_INTERFACE("sd", FLOPPY_525_SD) + SLOT_INTERFACE("ssdd", FLOPPY_525_SSDD) + SLOT_INTERFACE("dd", FLOPPY_525_DD) + SLOT_INTERFACE("ssqd", FLOPPY_525_SSQD) + SLOT_INTERFACE("qd", FLOPPY_525_QD) +SLOT_INTERFACE_END + WRITE_LINE_MEMBER(bbc_state::econet_clk_w) { m_adlc->rxc_w(state); @@ -760,13 +774,15 @@ static MACHINE_CONFIG_DERIVED( bbcb, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -822,13 +838,15 @@ static MACHINE_CONFIG_DERIVED( bbcb_us, bbca ) MCFG_I8271_IRQ_CALLBACK(WRITELINE(bbc_state, bbc_i8271_interrupt)) MCFG_I8271_FLOPPIES(FLOPPY_0, FLOPPY_1) - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) + /* software lists */ MCFG_DEVICE_REMOVE("cass_ls_a") MCFG_SOFTWARE_LIST_ADD("cass_ls_b", "bbcb_cass") @@ -852,6 +870,8 @@ static MACHINE_CONFIG_DERIVED( bbcbp, bbcb ) /* fdc */ MCFG_DEVICE_REMOVE("i8271") + MCFG_DEVICE_REMOVE(FLOPPY_0) + MCFG_DEVICE_REMOVE(FLOPPY_1) MACHINE_CONFIG_END @@ -981,12 +1001,12 @@ static MACHINE_CONFIG_START( bbcm, bbc_state ) MCFG_VIA6522_IRQ_HANDLER(WRITELINE(bbc_state, bbcb_via_user_irq_w)) /* fdc */ - MCFG_DEVICE_ADD("wd177x", WD1770, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) - MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bbc_floppy_interface) + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* econet */ MCFG_DEVICE_ADD("mc6854", MC6854, 0) @@ -1068,10 +1088,14 @@ static MACHINE_CONFIG_DERIVED( bbcmc, bbcm ) /* fdc */ MCFG_DEVICE_REMOVE("wd177x") - MCFG_DEVICE_ADD("wd177x", WD1772, 0) - MCFG_WD17XX_DEFAULT_DRIVE2_TAGS - MCFG_WD17XX_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) - MCFG_WD17XX_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + +// MCFG_WD1772x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD1770x_ADD("wd177x", XTAL_16MHz / 2) + MCFG_WD_FDC_INTRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_intrq_w)) + MCFG_WD_FDC_DRQ_CALLBACK(WRITELINE(bbc_state, bbc_wd177x_drq_w)) + + MCFG_FLOPPY_DRIVE_ADD("wd177x:0", bbc_floppies, "qd", bbc_state::floppy_formats) + MCFG_FLOPPY_DRIVE_ADD("wd177x:1", bbc_floppies, "qd", bbc_state::floppy_formats) /* software lists */ MCFG_SOFTWARE_LIST_REMOVE("cart_ls_m") diff --git a/src/mess/includes/bbc.h b/src/mess/includes/bbc.h index d86172860b9..499283e8ec3 100644 --- a/src/mess/includes/bbc.h +++ b/src/mess/includes/bbc.h @@ -20,7 +20,7 @@ #include "machine/mc6854.h" #include "machine/ram.h" #include "machine/i8271.h" -#include "machine/wd17xx.h" +#include "machine/wd_fdc.h" #include "machine/upd7002.h" #include "video/mc6845.h" #include "video/saa5050.h" @@ -80,6 +80,8 @@ public: m_palette(*this, "palette") { } + DECLARE_FLOPPY_FORMATS(floppy_formats); + DECLARE_WRITE8_MEMBER(bbc_page_selecta_w); DECLARE_WRITE8_MEMBER(bbc_memorya1_w); DECLARE_WRITE8_MEMBER(bbc_page_selectb_w); diff --git a/src/mess/machine/bbc.c b/src/mess/machine/bbc.c index 4e3a0a35561..1fc4d5c22da 100644 --- a/src/mess/machine/bbc.c +++ b/src/mess/machine/bbc.c @@ -17,6 +17,7 @@ #include "cpu/m6502/m6502.h" #include "sound/tms5220.h" #include "machine/6522via.h" +#include "machine/wd_fdc.h" #include "imagedev/flopdrv.h" #include "includes/bbc.h" #include "machine/mc146818.h" @@ -1575,7 +1576,7 @@ void bbc_state::bbc_update_fdq_int(int state) /* do not trigger int */ bbc_state = 0; } - +//printf("bbc_state %d prev %d\n", bbc_state, m_previous_wd177x_int_state); /* nmi is edge triggered, and triggers when the state goes from clear->set. Here we are checking this transition before triggering the nmi */ if (bbc_state!=m_previous_wd177x_int_state) @@ -1593,6 +1594,7 @@ void bbc_state::bbc_update_fdq_int(int state) WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_intrq_w) { +//printf("bbc_wd177x_intrq_w %d \n", state); m_wd177x_irq_state = state; bbc_update_fdq_int(state); } @@ -1605,20 +1607,28 @@ WRITE_LINE_MEMBER(bbc_state::bbc_wd177x_drq_w) WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; + + fdc->set_floppy(floppy); - /* set side */ - fdc->set_side((data>>2) & 0x01); + // bit 2: side select + if (floppy) + floppy->ss_w(BIT(data, 2)); - /* set density */ + // bit 3: density fdc->dden_w(BIT(data, 3)); - m_1770_IntEnabled=(((data>>4) & 0x01)==0); + // bit 4: interrupt enable + m_1770_IntEnabled = !BIT(data, 4); } @@ -1626,7 +1636,7 @@ WRITE8_MEMBER(bbc_state::bbc_wd177x_status_w) READ8_MEMBER(bbc_state::bbc_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 4: @@ -1644,22 +1654,22 @@ READ8_MEMBER(bbc_state::bbc_wd1770_read) default: break; } - logerror("wd177x read: $%02X $%02X\n", offset,retval); + //logerror("wd177x read: $%02X $%02X\n", offset,retval); return retval; } WRITE8_MEMBER(bbc_state::bbc_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: bbc_wd177x_status_w(space, 0, data); break; case 4: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 5: fdc->track_w(space, 0, data); @@ -1714,26 +1724,34 @@ AM_RANGE(0xfc00, 0xfdff) AM_READWRITE(bbc_opus_read , bbc_opus_write ) WRITE8_MEMBER(bbc_state::bbc_opus_status_w) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>1) & 0x01) fdc->set_drive(0); - if ((data>>2) & 0x01) fdc->set_drive(1); + // bit 1, 2: drive select + if (BIT(data, 1)) floppy = floppy0; + if (BIT(data, 2)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>0) & 0x01); + fdc->set_floppy(floppy); - /* set density */ + // bit 0: side select + if (floppy) + floppy->ss_w(BIT(data, 0)); + + // bit 5: density fdc->dden_w(BIT(data, 5)); - m_1770_IntEnabled=(data>>4) & 0x01; + // bit 4: interrupt enable + m_1770_IntEnabled = BIT(data, 4); } READ8_MEMBER(bbc_state::bbc_opus_read) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x read: $%02X\n", offset); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x read: $%02X\n", offset); if (m_DFSType==6) { @@ -1761,8 +1779,8 @@ READ8_MEMBER(bbc_state::bbc_opus_read) WRITE8_MEMBER(bbc_state::bbc_opus_write) { - wd1770_device *fdc = machine().device("wd177x"); - logerror("wd177x write: $%02X $%02X\n", offset,data); + wd1770_t *fdc = machine().device("wd177x"); + //logerror("wd177x write: $%02X $%02X\n", offset,data); if (m_DFSType==6) { @@ -1771,7 +1789,7 @@ WRITE8_MEMBER(bbc_state::bbc_opus_write) switch (offset) { case 0xf8: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 0xf9: fdc->track_w(space, 0, data); @@ -1809,7 +1827,7 @@ BBC MASTER DISC SUPPORT READ8_MEMBER(bbc_state::bbcm_wd1770_read) { int retval=0xff; - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); switch (offset) { case 0: @@ -1833,12 +1851,12 @@ READ8_MEMBER(bbc_state::bbcm_wd1770_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); //logerror("wd177x write: $%02X $%02X\n", offset,data); switch (offset) { case 0: - fdc->command_w(space, 0, data); + fdc->cmd_w(space, 0, data); break; case 1: fdc->track_w(space, 0, data); @@ -1862,22 +1880,26 @@ READ8_MEMBER(bbc_state::bbcm_wd1770l_read) WRITE8_MEMBER(bbc_state::bbcm_wd1770l_write) { - wd1770_device *fdc = machine().device("wd177x"); + wd1770_t *fdc = machine().device("wd177x"); + floppy_image_device *floppy0 = machine().device("wd177x:0")->get_device(); + floppy_image_device *floppy1 = machine().device("wd177x:1")->get_device(); + floppy_image_device *floppy = NULL; + m_drive_control = data; - /* set drive */ - if ((data>>0) & 0x01) fdc->set_drive(0); - if ((data>>1) & 0x01) fdc->set_drive(1); + // bit 0, 1: drive select + if (BIT(data, 0)) floppy = floppy0; + if (BIT(data, 1)) floppy = floppy1; - /* set side */ - fdc->set_side((data>>4) & 0x01); + // bit 4: side select + if (floppy) + floppy->ss_w(BIT(data, 4)); - /* set density */ + // bit 5: density fdc->dden_w(BIT(data, 5)); // m_1770_IntEnabled=(((data>>4) & 0x01)==0); m_1770_IntEnabled=1; - } -- cgit v1.2.3