summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices
diff options
context:
space:
mode:
author fulivi <fulivi@users.noreply.github.com>2016-04-22 14:37:04 +0200
committer fulivi <fulivi@users.noreply.github.com>2016-04-23 14:33:32 +0200
commitb9f17449ee26402c9ab32d34bf2f6bc94ea569e1 (patch)
tree5d3495dbb66d93347d78ab4c9389ea917f960e51 /src/devices
parent996a4fd9c02fbb45618ca09d5862ffc60741d1a0 (diff)
hp9845b: added capability to load optional ROMs
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/bus/hp_optroms/hp_optrom.cpp151
-rw-r--r--src/devices/bus/hp_optroms/hp_optrom.h74
2 files changed, 225 insertions, 0 deletions
diff --git a/src/devices/bus/hp_optroms/hp_optrom.cpp b/src/devices/bus/hp_optroms/hp_optrom.cpp
new file mode 100644
index 00000000000..74391e96838
--- /dev/null
+++ b/src/devices/bus/hp_optroms/hp_optrom.cpp
@@ -0,0 +1,151 @@
+// license:BSD-3-Clause
+// copyright-holders: F. Ulivi
+/*********************************************************************
+
+ hp_optrom.cpp
+
+ Optional ROMs for HP9845 systems
+
+*********************************************************************/
+
+#include "hp_optrom.h"
+#include "softlist.h"
+#include "cpu/hphybrid/hphybrid.h"
+
+const device_type HP_OPTROM_CART = &device_creator<hp_optrom_cart_device>;
+const device_type HP_OPTROM_SLOT = &device_creator<hp_optrom_slot_device>;
+
+// +---------------------+
+// |hp_optrom_cart_device|
+// +---------------------+
+hp_optrom_cart_device::hp_optrom_cart_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) :
+ device_t(mconfig, type, name, tag, owner, clock, shortname, source),
+ device_slot_card_interface(mconfig, *this)
+{
+}
+
+hp_optrom_cart_device::hp_optrom_cart_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
+ device_t(mconfig, HP_OPTROM_CART, "HP9845 optional ROM cartridge", tag, owner, clock, "hp_optrom_cart", __FILE__),
+ device_slot_card_interface(mconfig, *this)
+{
+}
+
+// +---------------------+
+// |hp_optrom_slot_device|
+// +---------------------+
+hp_optrom_slot_device::hp_optrom_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
+ device_t(mconfig, HP_OPTROM_SLOT, "HP9845 optional ROM Slot", tag, owner, clock, "hp_optrom_slot", __FILE__),
+ device_image_interface(mconfig, *this),
+ device_slot_interface(mconfig, *this),
+ m_cart(nullptr),
+ m_base_addr(0),
+ m_end_addr(0)
+{
+}
+
+hp_optrom_slot_device::~hp_optrom_slot_device()
+{
+}
+
+void hp_optrom_slot_device::device_start()
+{
+ m_cart = dynamic_cast<hp_optrom_cart_device *>(get_card_device());
+}
+
+void hp_optrom_slot_device::device_config_complete()
+{
+ update_names(HP_OPTROM_SLOT , "optional_rom" , "optrom");
+}
+
+bool hp_optrom_slot_device::call_load()
+{
+ logerror("hp_optrom: call_load\n");
+ if (m_cart == nullptr || !m_from_swlist) {
+ logerror("hp_optrom: fail 1\n");
+ return IMAGE_INIT_FAIL;
+ }
+
+ const software_part *part_ptr = part_entry();
+ if (part_ptr == nullptr) {
+ logerror("hp_optrom: fail 2\n");
+ return IMAGE_INIT_FAIL;
+ }
+
+ const char *base_feature = part_ptr->feature("base");
+ if (base_feature == nullptr) {
+ logerror("hp_optrom: no 'base' feature\n");
+ return IMAGE_INIT_FAIL;
+ }
+
+ offs_t base_addr;
+ if (base_feature[ 0 ] != '0' || base_feature[ 1 ] != 'x' || sscanf(&base_feature[ 2 ] , "%x" , &base_addr) != 1) {
+ logerror("hp_optrom: can't parse 'base' feature\n");
+ return IMAGE_INIT_FAIL;
+ }
+
+ // Valid BSC values for ROMs on LPU drawer: 0x07 0x0b .... 0x3b
+ // Valid BSC values for ROMs on PPU drawer: 0x09 0x0d .... 0x3d
+ // (BSC is field in bits 16..21 of base address)
+ // Bit 15 of base address must be 0
+ // Base address must be multiple of 0x1000
+ if ((base_addr & ~0x3f7000UL) != 0 || ((base_addr & 0x30000) != 0x10000 && (base_addr & 0x30000) != 0x30000) || base_addr < 0x70000) {
+ logerror("hp_optrom: illegal base address (%x)\n" , base_addr);
+ return IMAGE_INIT_FAIL;
+ }
+
+ auto length = get_software_region_length("rom") / 2;
+
+ if (length < 0x1000 || length > 0x8000 || (length & 0xfff) != 0 || ((base_addr & 0x7000) + length) > 0x8000) {
+ logerror("hp_optrom: illegal region length (%x)\n" , length);
+ return IMAGE_INIT_FAIL;
+ }
+
+ offs_t end_addr = base_addr + length - 1;
+ logerror("hp_optrom: base_addr = %06x end_addr = %06x\n" , base_addr , end_addr);
+
+ m_content.resize(length * 2);
+ UINT8 *buffer = m_content.data();
+ memcpy(buffer , get_software_region("rom") , length * 2);
+
+ // Install ROM in address space of every CPU
+ device_interface_iterator<hp_hybrid_cpu_device> iter(machine().root_device());
+ for (hp_hybrid_cpu_device *cpu = iter.first(); cpu != nullptr; cpu = iter.next()) {
+ logerror("hp_optrom: install in %s AS\n" , cpu->tag());
+ cpu->space(AS_PROGRAM).install_rom(base_addr , end_addr , buffer);
+ }
+
+ m_base_addr = base_addr;
+ m_end_addr = end_addr;
+
+ return IMAGE_INIT_PASS;
+}
+
+void hp_optrom_slot_device::call_unload()
+{
+ logerror("hp_optrom: call_unload\n");
+ if (m_cart != nullptr && m_base_addr != 0 && m_end_addr != 0) {
+ device_interface_iterator<hp_hybrid_cpu_device> iter(machine().root_device());
+ for (hp_hybrid_cpu_device *cpu = iter.first(); cpu != nullptr; cpu = iter.next()) {
+ cpu->space(AS_PROGRAM).unmap_read(m_base_addr , m_end_addr);
+ }
+ m_content.resize(0);
+ m_base_addr = 0;
+ m_end_addr = 0;
+ }
+}
+
+bool hp_optrom_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry)
+{
+ logerror("hp_optrom: call_softlist_load\n");
+ machine().rom_load().load_software_part_region(*this, swlist, swname, start_entry);
+ return TRUE;
+}
+
+std::string hp_optrom_slot_device::get_default_card_software()
+{
+ return software_get_default_slot("rom");
+}
+
+SLOT_INTERFACE_START(hp_optrom_slot_device)
+ SLOT_INTERFACE_INTERNAL("rom", HP_OPTROM_CART)
+SLOT_INTERFACE_END
diff --git a/src/devices/bus/hp_optroms/hp_optrom.h b/src/devices/bus/hp_optroms/hp_optrom.h
new file mode 100644
index 00000000000..a18fd5e4087
--- /dev/null
+++ b/src/devices/bus/hp_optroms/hp_optrom.h
@@ -0,0 +1,74 @@
+// license:BSD-3-Clause
+// copyright-holders: F. Ulivi
+/*********************************************************************
+
+ hp_optrom.h
+
+ Optional ROMs for HP9845 systems
+
+*********************************************************************/
+
+#pragma once
+
+#ifndef _HP_OPTROM_H_
+#define _HP_OPTROM_H_
+
+#include "emu.h"
+
+class hp_optrom_cart_device : public device_t,
+ public device_slot_card_interface
+{
+public:
+ // construction/destruction
+ hp_optrom_cart_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
+ hp_optrom_cart_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
+
+ // device-level overrides
+ virtual void device_start() override {}
+};
+
+class hp_optrom_slot_device : public device_t,
+ public device_image_interface,
+ public device_slot_interface
+{
+public:
+ // construction/destruction
+ hp_optrom_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
+ virtual ~hp_optrom_slot_device();
+
+ // device-level overrides
+ virtual void device_start() override;
+ virtual void device_config_complete() override;
+
+ // image-level overrides
+ virtual bool call_load() override;
+ virtual void call_unload() override;
+ virtual bool call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry) override;
+
+ virtual iodevice_t image_type() const override { return IO_CARTSLOT; }
+ virtual bool is_readable() const override { return true; }
+ virtual bool is_writeable() const override { return false; }
+ virtual bool is_creatable() const override { return false; }
+ virtual bool must_be_loaded() const override { return false; }
+ virtual bool is_reset_on_load() const override { return true; }
+ virtual const option_guide *create_option_guide() const override { return nullptr; }
+ virtual const char *image_interface() const override { return "hp9845b_rom"; }
+ virtual const char *file_extensions() const override { return "bin"; }
+
+ // slot interface overrides
+ virtual std::string get_default_card_software() override;
+
+protected:
+ hp_optrom_cart_device *m_cart;
+ dynamic_buffer m_content;
+ offs_t m_base_addr;
+ offs_t m_end_addr;
+};
+
+// device type definition
+extern const device_type HP_OPTROM_SLOT;
+extern const device_type HP_OPTROM_CART;
+
+SLOT_INTERFACE_EXTERN(hp_optrom_slot_device);
+
+#endif /* _HP_OPTROM_H_ */