1 // license:BSD-3-Clause
2 // copyright-holders:Barry Rodewald
3 /*
4  * cpc_rom.h
5  * Amstrad CPC mountable ROM image device
6  *
7  */
8 
9 #ifndef MAME_BUS_CPC_CPC_ROM_H
10 #define MAME_BUS_CPC_CPC_ROM_H
11 
12 #pragma once
13 
14 #include "cpcexp.h"
15 
16 /*** ROM image device ***/
17 
18 // ======================> cpc_rom_image_device
19 
20 class cpc_rom_image_device : public device_t, public device_image_interface
21 {
22 public:
23 	// construction/destruction
24 	cpc_rom_image_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
25 	virtual ~cpc_rom_image_device();
26 
27 	// image-level overrides
28 	virtual image_init_result call_load() override;
29 	virtual void call_unload() override;
30 
image_type()31 	virtual iodevice_t image_type() const noexcept override { return IO_ROM; }
32 
is_readable()33 	virtual bool is_readable()  const noexcept override { return true; }
is_writeable()34 	virtual bool is_writeable() const noexcept override { return false; }
is_creatable()35 	virtual bool is_creatable() const noexcept override { return false; }
must_be_loaded()36 	virtual bool must_be_loaded() const noexcept override { return false; }
is_reset_on_load()37 	virtual bool is_reset_on_load() const noexcept override { return true; }
image_interface()38 	virtual const char *image_interface() const noexcept override { return "cpc_rom"; }
file_extensions()39 	virtual const char *file_extensions() const noexcept override { return "rom,bin"; }
40 
base()41 	uint8_t* base() { return m_base.get(); }
42 
43 protected:
44 	// device-level overrides
45 	virtual void device_start() override;
46 
47 private:
48 	std::unique_ptr<uint8_t[]> m_base;
49 };
50 
51 
52 // device type definition
DECLARE_DEVICE_TYPE(CPC_ROMSLOT,cpc_rom_image_device)53 DECLARE_DEVICE_TYPE(CPC_ROMSLOT, cpc_rom_image_device)
54 
55 
56 /*** ROM box device ***/
57 
58 class cpc_rom_device  : public device_t,
59 						public device_cpc_expansion_card_interface
60 {
61 public:
62 	// construction/destruction
63 	cpc_rom_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
64 
65 	uint8_t* base(uint8_t slot) { if(slot >=1 && slot <= 8) return m_rom[slot]->base(); else return nullptr; }
66 
67 protected:
68 	// device-level overrides
69 	virtual void device_start() override;
70 	virtual void device_reset() override;
71 
72 	// optional information overrides
73 	virtual void device_add_mconfig(machine_config &config) override;
74 
75 private:
76 	required_device_array<cpc_rom_image_device, 8> m_rom;
77 };
78 
79 // device type definition
80 DECLARE_DEVICE_TYPE(CPC_ROM, cpc_rom_device)
81 
82 
83 #endif // MAME_BUS_CPC_CPC_ROM_H
84