summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2018-04-20 12:57:21 -0400
committer AJR <ajrhacker@users.noreply.github.com>2018-04-20 12:57:29 -0400
commitf45be6f709047d46884848150153cf61ab8c2680 (patch)
tree27303c77a95e90050f9846366714479f2a67d1fa
parent7b9bc3a46abc8980575f8a1a0404f8a0b9f9b780 (diff)
hp48_port: Eliminate driver_data calls; separate source files; reduce dependency on driver class somewhat but not ideally enough (nw)
-rw-r--r--scripts/target/mame/mess.lua2
-rw-r--r--src/mame/drivers/hp48.cpp8
-rw-r--r--src/mame/includes/hp48.h62
-rw-r--r--src/mame/machine/hp48.cpp144
-rw-r--r--src/mame/machine/hp48_port.cpp116
-rw-r--r--src/mame/machine/hp48_port.h76
6 files changed, 231 insertions, 177 deletions
diff --git a/scripts/target/mame/mess.lua b/scripts/target/mame/mess.lua
index 5ecb68b69d8..03a64604178 100644
--- a/scripts/target/mame/mess.lua
+++ b/scripts/target/mame/mess.lua
@@ -2174,6 +2174,8 @@ files {
MAME_DIR .. "src/mame/drivers/hp48.cpp",
MAME_DIR .. "src/mame/includes/hp48.h",
MAME_DIR .. "src/mame/machine/hp48.cpp",
+ MAME_DIR .. "src/mame/machine/hp48_port.cpp",
+ MAME_DIR .. "src/mame/machine/hp48_port.h",
MAME_DIR .. "src/mame/machine/hp9845_printer.cpp",
MAME_DIR .. "src/mame/machine/hp9845_printer.h",
MAME_DIR .. "src/mame/video/hp48.cpp",
diff --git a/src/mame/drivers/hp48.cpp b/src/mame/drivers/hp48.cpp
index acca9b631c9..626ce407925 100644
--- a/src/mame/drivers/hp48.cpp
+++ b/src/mame/drivers/hp48.cpp
@@ -1295,8 +1295,8 @@ MACHINE_CONFIG_START(hp48_state::hp48gx)
MCFG_MACHINE_START_OVERRIDE (hp48_state, hp48gx )
/* expansion ports */
- MCFG_HP48_PORT_ADD ( "port1", 0, HP48_CE2, 128*1024 )
- MCFG_HP48_PORT_ADD ( "port2", 1, HP48_NCE3, 4*1024*1024 )
+ MCFG_HP48_PORT_ADD ( "port1", HP48_CE2, 128*1024 )
+ MCFG_HP48_PORT_ADD ( "port2", HP48_NCE3, 4*1024*1024 )
/* serial I/O */
//MCFG_XMODEM_ADD( "rs232_x", hp48_xmodem_rs232_conf )
@@ -1330,8 +1330,8 @@ MACHINE_CONFIG_START(hp48_state::hp48sx)
MCFG_MACHINE_START_OVERRIDE (hp48_state, hp48sx )
/* expansion ports */
- MCFG_HP48_PORT_ADD ( "port1", 0, HP48_CE1, 128*1024)
- MCFG_HP48_PORT_ADD ( "port2", 1, HP48_CE2, 128*1024)
+ MCFG_HP48_PORT_ADD ( "port1", HP48_CE1, 128*1024)
+ MCFG_HP48_PORT_ADD ( "port2", HP48_CE2, 128*1024)
/* serial I/O */
//MCFG_KERMIT_ADD( "rs232_k", hp48_kermit_rs232_conf )
diff --git a/src/mame/includes/hp48.h b/src/mame/includes/hp48.h
index 99a2eb95d05..46d26139f1b 100644
--- a/src/mame/includes/hp48.h
+++ b/src/mame/includes/hp48.h
@@ -12,6 +12,8 @@
#pragma once
+#include "machine/hp48_port.h"
+
#include "sound/dac.h"
#include "screen.h"
@@ -55,7 +57,8 @@ public:
, m_maincpu(*this, "maincpu")
, m_dac(*this, "dac")
, m_palette(*this, "palette")
- , m_screen(*this, "screen") {}
+ , m_screen(*this, "screen")
+ , m_port(*this, "port%u", 1U) {}
virtual void machine_reset() override;
void base_machine_start(hp48_models model);
@@ -131,13 +134,11 @@ public:
/* from highest to lowest priority: HDW, NCE2, CE1, CE2, NCE3, NCE1 */
hp48_module m_modules[6];
- /* RAM/ROM extensions, GX/SX only (each uint8_t stores one nibble)
+ /* RAM/ROM extensions, GX/SX only
port1: SX/GX: 32/128 KB
port2: SX:32/128KB, GX:128/512/4096 KB
*/
- uint32_t m_port_size[2];
- uint8_t m_port_write[2];
- std::unique_ptr<uint8_t[]> m_port_data[2];
+ optional_device_array<hp48_port_image_device, 2> m_port;
uint32_t m_bank_switch;
uint32_t m_io_addr;
@@ -187,55 +188,4 @@ public:
#define HP48_NCE3 4
#define HP48_NCE1 5
-/****************************** cards ********************************/
-
-class hp48_port_image_device : public device_t,
- public device_image_interface
-{
-public:
- // construction/destruction
- hp48_port_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
-
- void set_port_config(int port, int module, int max_size)
- {
- m_port = port;
- m_module = module;
- m_max_size = max_size;
- }
-
- // image-level overrides
- virtual iodevice_t image_type() const override { return IO_MEMCARD; }
-
- virtual bool is_readable() const override { return 1; }
- virtual bool is_writeable() const override { return 1; }
- virtual bool is_creatable() const override { return 1; }
- virtual bool must_be_loaded() const override { return 0; }
- virtual bool is_reset_on_load() const override { return 0; }
- virtual const char *file_extensions() const override { return "crd"; }
- virtual const char *custom_instance_name() const override { return "port"; }
- virtual const char *custom_brief_instance_name() const override { return "p"; }
-
- virtual image_init_result call_load() override;
- virtual void call_unload() override;
- virtual image_init_result call_create(int format_type, util::option_resolution *format_options) override;
-
-protected:
- // device-level overrides
- virtual void device_start() override;
-private:
- void fill_port();
- void unfill_port();
-
- int m_port; /* port index: 0 or 1 (for port 1 and 2) */
- int m_module; /* memory module where the port is visible */
- int m_max_size; /* maximum size, in bytes 128 KB or 4 GB */
-};
-
-// device type definition
-DECLARE_DEVICE_TYPE(HP48_PORT, hp48_port_image_device)
-
-#define MCFG_HP48_PORT_ADD(_tag, _port, _module, _max_size) \
- MCFG_DEVICE_ADD(_tag, HP48_PORT, 0) \
- downcast<hp48_port_image_device &>(*device).set_port_config(_port, _module, _max_size);
-
#endif // MAME_INCLUDES_HP84_H
diff --git a/src/mame/machine/hp48.cpp b/src/mame/machine/hp48.cpp
index 2deefceaae2..a540bc85d9b 100644
--- a/src/mame/machine/hp48.cpp
+++ b/src/mame/machine/hp48.cpp
@@ -468,17 +468,33 @@ READ8_MEMBER(hp48_state::io_r)
data = 0;
if ( HP48_G_SERIES )
{
- if ( m_port_size[1] ) data |= 1;
- if ( m_port_size[0] ) data |= 2;
- if ( m_port_size[1] && m_port_write[1] ) data |= 4;
- if ( m_port_size[0] && m_port_write[0] ) data |= 8;
+ if (m_port[1].found() && m_port[1]->port_size() > 0)
+ {
+ data |= 1;
+ if (m_port[1]->port_write())
+ data |= 4;
+ }
+ if (m_port[0].found() && m_port[0]->port_size() > 0)
+ {
+ data |= 2;
+ if (m_port[0]->port_write())
+ data |= 8;
+ }
}
else
{
- if ( m_port_size[0] ) data |= 1;
- if ( m_port_size[1] ) data |= 2;
- if ( m_port_size[0] && m_port_write[0] ) data |= 4;
- if ( m_port_size[1] && m_port_write[1] ) data |= 8;
+ if (m_port[0].found() && m_port[0]->port_size() > 0)
+ {
+ data |= 1;
+ if (m_port[0]->port_write())
+ data |= 4;
+ }
+ if (m_port[1].found() && m_port[1]->port_size() > 0)
+ {
+ data |= 2;
+ if (m_port[1]->port_write())
+ data |= 8;
+ }
}
LOG(( "%s: card info read %02x\n", machine().describe_context(), data ));
break;
@@ -649,11 +665,11 @@ void hp48_state::apply_modules()
else if (HP48_G_SERIES)
{
/* port 2 bank switch */
- if (m_port_size[1] > 0)
+ if (m_port[1].found() && m_port[1]->port_size() > 0)
{
- int off = (m_bank_switch << 16) % m_port_size[1];
+ int off = (m_bank_switch << 16) % m_port[1]->port_size();
LOG(("hp48_state::apply_modules: port 2 offset is %i\n", off));
- m_modules[HP48_NCE3].data = m_port_data[1].get() + off;
+ m_modules[HP48_NCE3].data = m_port[1]->port_data() + off;
}
/* ROM A19 (hi 256 KB) / NCE3 (port 2) control switch */
@@ -897,110 +913,6 @@ void hp48_state::encode_nibble(uint8_t* dst, uint8_t* src, int size)
}
}
-
-
-/* ----- card images ------ */
-DEFINE_DEVICE_TYPE(HP48_PORT, hp48_port_image_device, "hp48_port_image", "HP48 memory card")
-
-/* helper for load and create */
-void hp48_port_image_device::fill_port()
-{
- hp48_state *state = machine().driver_data<hp48_state>();
- int size = state->m_port_size[m_port];
- LOG(("hp48_port_image_device::fill_port: %s module=%i size=%i rw=%i\n", tag(), m_module, size, state->m_port_write[m_port]));
- state->m_port_data[m_port] = make_unique_clear<uint8_t[]>(2 * size);
- state->m_modules[m_module].off_mask = 2 * (( size > 128 * 1024 ) ? 128 * 1024 : size) - 1;
- state->m_modules[m_module].read = read8_delegate();
- state->m_modules[m_module].write = write8_delegate();
- state->m_modules[m_module].isnop = state->m_port_write[m_port] ? 0 : 1;
- state->m_modules[m_module].data = (void*)state->m_port_data[m_port].get();
- state->apply_modules();
-}
-
-/* helper for start and unload */
-void hp48_port_image_device::unfill_port()
-{
- hp48_state *state = machine().driver_data<hp48_state>();
- LOG(("hp48_port_image_device::unfill_port\n"));
- state->m_modules[m_module].off_mask = 0x00fff; /* 2 KB */
- state->m_modules[m_module].read = read8_delegate();
- state->m_modules[m_module].write = write8_delegate();
- state->m_modules[m_module].data = nullptr;
- state->m_modules[m_module].isnop = 1;
- state->m_port_size[m_port] = 0;
-}
-
-
-image_init_result hp48_port_image_device::call_load()
-{
- hp48_state *state = machine().driver_data<hp48_state>();
- int size = length();
- if (size == 0) size = m_max_size; /* default size */
- LOG(("hp48_port_image load: size=%i\n", size));
-
- /* check size */
- if ((size < 32*1024) || (size > m_max_size) || (size & (size-1)))
- {
- logerror("hp48: image size for %s should be a power of two between %i and %i\n", tag(), 32*1024, m_max_size);
- return image_init_result::FAIL;
- }
-
- state->m_port_size[m_port] = size;
- state->m_port_write[m_port] = !is_readonly();
- fill_port();
- fread(state->m_port_data[m_port].get(), state->m_port_size[m_port] );
- state->decode_nibble(state->m_port_data[m_port].get(), state->m_port_data[m_port].get(), state->m_port_size[m_port]);
- return image_init_result::PASS;
-}
-
-image_init_result hp48_port_image_device::call_create(int format_type, util::option_resolution *format_options)
-{
- hp48_state *state = machine().driver_data<hp48_state>();
- int size = m_max_size;
- LOG(( "hp48_port_image create: size=%i\n", size ));
- /* XXX defaults to max_size; get user-specified size instead */
-
- /* check size */
- /* size must be a power of 2 between 32K and max_size */
- if ( (size < 32*1024) || (size > m_max_size) || (size & (size-1)) )
- {
- logerror( "hp48: image size for %s should be a power of two between %i and %i\n", tag(), 32*1024, m_max_size );
- return image_init_result::FAIL;
- }
-
- state->m_port_size[m_port] = size;
- state->m_port_write[m_port] = 1;
- fill_port();
- return image_init_result::PASS;
-}
-
-void hp48_port_image_device::call_unload()
-{
- hp48_state *state = machine().driver_data<hp48_state>();
- LOG(("hp48_port image unload: %s size=%i rw=%i\n", tag(), state->m_port_size[m_port], state->m_port_write[m_port]));
- if (state->m_port_write[m_port])
- {
- state->encode_nibble(state->m_port_data[m_port].get(), state->m_port_data[m_port].get(), state->m_port_size[m_port]);
- fseek(0, SEEK_SET);
- fwrite(state->m_port_data[m_port].get(), state->m_port_size[m_port]);
- }
- state->m_port_data[m_port] = nullptr;
- unfill_port();
- state->apply_modules();
-}
-
-void hp48_port_image_device::device_start()
-{
- LOG(("hp48_port_image start\n"));
- unfill_port();
-}
-
-hp48_port_image_device::hp48_port_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
- : device_t(mconfig, HP48_PORT, tag, owner, clock)
- , device_image_interface(mconfig, *this)
-{
-}
-
/***************************************************************************
MACHINES
***************************************************************************/
@@ -1017,8 +929,6 @@ DRIVER_INIT_MEMBER(hp48_state,hp48)
m_modules[i].data = nullptr;
m_modules[i].isnop = 0;
}
- m_port_size[0] = 0;
- m_port_size[1] = 0;
m_rom = nullptr;
}
diff --git a/src/mame/machine/hp48_port.cpp b/src/mame/machine/hp48_port.cpp
new file mode 100644
index 00000000000..c22e9e61623
--- /dev/null
+++ b/src/mame/machine/hp48_port.cpp
@@ -0,0 +1,116 @@
+// license:BSD-3-Clause
+// copyright-holders:Antoine Mine
+/**********************************************************************
+
+ Copyright (C) Antoine Mine' 2008
+
+ Hewlett Packard HP48 S/SX & G/GX/G+ and HP49 G
+
+**********************************************************************/
+
+#include "emu.h"
+#include "machine/hp48_port.h"
+#include "includes/hp48.h"
+
+#include "logmacro.h"
+
+
+/* ----- card images ------ */
+DEFINE_DEVICE_TYPE(HP48_PORT, hp48_port_image_device, "hp48_port_image", "HP48 memory card")
+
+/* helper for load and create */
+void hp48_port_image_device::fill_port()
+{
+ int size = m_port_size;
+ LOG("hp48_port_image_device::fill_port: %s module=%i size=%i rw=%i\n", tag(), m_module, size, m_port_write);
+ m_port_data = make_unique_clear<uint8_t[]>(2 * size);
+ m_hp48->m_modules[m_module].off_mask = 2 * (( size > 128 * 1024 ) ? 128 * 1024 : size) - 1;
+ m_hp48->m_modules[m_module].read = read8_delegate();
+ m_hp48->m_modules[m_module].write = write8_delegate();
+ m_hp48->m_modules[m_module].isnop = m_port_write ? 0 : 1;
+ m_hp48->m_modules[m_module].data = (void*)m_port_data.get();
+ m_hp48->apply_modules();
+}
+
+/* helper for start and unload */
+void hp48_port_image_device::unfill_port()
+{
+ LOG("hp48_port_image_device::unfill_port\n");
+ m_hp48->m_modules[m_module].off_mask = 0x00fff; /* 2 KB */
+ m_hp48->m_modules[m_module].read = read8_delegate();
+ m_hp48->m_modules[m_module].write = write8_delegate();
+ m_hp48->m_modules[m_module].data = nullptr;
+ m_hp48->m_modules[m_module].isnop = 1;
+ m_port_size = 0;
+}
+
+
+image_init_result hp48_port_image_device::call_load()
+{
+ int size = length();
+ if (size == 0) size = m_max_size; /* default size */
+ LOG("hp48_port_image load: size=%i\n", size);
+
+ /* check size */
+ if ((size < 32*1024) || (size > m_max_size) || (size & (size-1)))
+ {
+ logerror("hp48: image size for %s should be a power of two between %i and %i\n", tag(), 32*1024, m_max_size);
+ return image_init_result::FAIL;
+ }
+
+ m_port_size = size;
+ m_port_write = !is_readonly();
+ fill_port();
+ fread(m_port_data.get(), m_port_size);
+ m_hp48->decode_nibble(m_port_data.get(), m_port_data.get(), m_port_size);
+ return image_init_result::PASS;
+}
+
+image_init_result hp48_port_image_device::call_create(int format_type, util::option_resolution *format_options)
+{
+ int size = m_max_size;
+ LOG("hp48_port_image create: size=%i\n", size);
+ /* XXX defaults to max_size; get user-specified size instead */
+
+ /* check size */
+ /* size must be a power of 2 between 32K and max_size */
+ if ( (size < 32*1024) || (size > m_max_size) || (size & (size-1)) )
+ {
+ logerror( "hp48: image size for %s should be a power of two between %i and %i\n", tag(), 32*1024, m_max_size );
+ return image_init_result::FAIL;
+ }
+
+ m_port_size = size;
+ m_port_write = true;
+ fill_port();
+ return image_init_result::PASS;
+}
+
+void hp48_port_image_device::call_unload()
+{
+ LOG("hp48_port image unload: %s size=%i rw=%i\n", tag(), m_port_size, m_port_write);
+ if (m_port_write)
+ {
+ m_hp48->encode_nibble(m_port_data.get(), m_port_data.get(), m_port_size);
+ fseek(0, SEEK_SET);
+ fwrite(m_port_data.get(), m_port_size);
+ }
+ m_port_data = nullptr;
+ unfill_port();
+ m_hp48->apply_modules();
+}
+
+void hp48_port_image_device::device_start()
+{
+ LOG("hp48_port_image start\n");
+ unfill_port();
+}
+
+hp48_port_image_device::hp48_port_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+ : device_t(mconfig, HP48_PORT, tag, owner, clock)
+ , device_image_interface(mconfig, *this)
+ , m_port_size(0)
+ , m_port_write(false)
+ , m_hp48(*this, DEVICE_SELF_OWNER)
+{
+}
diff --git a/src/mame/machine/hp48_port.h b/src/mame/machine/hp48_port.h
new file mode 100644
index 00000000000..d306a8a070e
--- /dev/null
+++ b/src/mame/machine/hp48_port.h
@@ -0,0 +1,76 @@
+// license:BSD-3-Clause
+// copyright-holders:Antoine Mine
+/**********************************************************************
+
+ Copyright (C) Antoine Mine' 2008
+
+ Hewlett Packard HP48 S/SX & G/GX and HP49 G
+
+**********************************************************************/
+
+#ifndef MAME_MACHINE_HP84_PORT_H
+#define MAME_MACHINE_HP84_PORT_H
+
+#pragma once
+
+/****************************** cards ********************************/
+
+class hp48_state;
+
+class hp48_port_image_device : public device_t, public device_image_interface
+{
+public:
+ // construction/destruction
+ hp48_port_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+
+ void set_port_config(int module, int max_size)
+ {
+ m_module = module;
+ m_max_size = max_size;
+ }
+
+ // image-level overrides
+ virtual iodevice_t image_type() const override { return IO_MEMCARD; }
+
+ virtual bool is_readable() const override { return 1; }
+ virtual bool is_writeable() const override { return 1; }
+ virtual bool is_creatable() const override { return 1; }
+ virtual bool must_be_loaded() const override { return 0; }
+ virtual bool is_reset_on_load() const override { return 0; }
+ virtual const char *file_extensions() const override { return "crd"; }
+ virtual const char *custom_instance_name() const override { return "port"; }
+ virtual const char *custom_brief_instance_name() const override { return "p"; }
+
+ virtual image_init_result call_load() override;
+ virtual void call_unload() override;
+ virtual image_init_result call_create(int format_type, util::option_resolution *format_options) override;
+
+ uint32_t port_size() const { return m_port_size; }
+ bool port_write() const { return m_port_write; }
+ uint8_t *port_data() const { return m_port_data.get(); }
+
+protected:
+ // device-level overrides
+ virtual void device_start() override;
+private:
+ void fill_port();
+ void unfill_port();
+
+ int m_module; /* memory module where the port is visible */
+ int m_max_size; /* maximum size, in bytes 128 KB or 4 GB */
+
+ uint32_t m_port_size;
+ bool m_port_write;
+ std::unique_ptr<uint8_t[]> m_port_data; // each uint8_t stores one nibble
+
+ required_device<hp48_state> m_hp48;
+};
+
+// device type definition
+DECLARE_DEVICE_TYPE(HP48_PORT, hp48_port_image_device)
+
+#define MCFG_HP48_PORT_ADD(_tag, _module, _max_size) \
+ MCFG_DEVICE_ADD(_tag, HP48_PORT, 0) \
+ downcast<hp48_port_image_device &>(*device).set_port_config(_module, _max_size);
+
+#endif // MAME_MACHINE_HP84_PORT_H