1 // license:BSD-3-Clause
2 // copyright-holders:Nigel Barnes
3 /**********************************************************************
4
5 JAFA Systems ROMPlus-144
6
7 **********************************************************************/
8
9
10 #include "emu.h"
11 #include "romp144.h"
12
13
14 //**************************************************************************
15 // DEVICE DEFINITIONS
16 //**************************************************************************
17
18 DEFINE_DEVICE_TYPE(ELECTRON_ROMP144, electron_romp144_device, "electron_romp144", "JAFA Systems ROMPlus-144")
19
20
21 //-------------------------------------------------
22 // device_add_mconfig - add device configuration
23 //-------------------------------------------------
24
device_add_mconfig(machine_config & config)25 void electron_romp144_device::device_add_mconfig(machine_config &config)
26 {
27 /* rom sockets */
28 GENERIC_SOCKET(config, m_romslot[0], generic_plain_slot, "electron_rom", "bin,rom");
29 m_romslot[0]->set_device_load(FUNC(electron_romp144_device::rom0));
30 GENERIC_SOCKET(config, m_romslot[1], generic_plain_slot, "electron_rom", "bin,rom");
31 m_romslot[1]->set_device_load(FUNC(electron_romp144_device::rom1));
32 GENERIC_SOCKET(config, m_romslot[2], generic_plain_slot, "electron_rom", "bin,rom");
33 m_romslot[2]->set_device_load(FUNC(electron_romp144_device::rom2));
34 GENERIC_SOCKET(config, m_romslot[3], generic_plain_slot, "electron_rom", "bin,rom");
35 m_romslot[3]->set_device_load(FUNC(electron_romp144_device::rom3));
36 GENERIC_SOCKET(config, m_romslot[4], generic_plain_slot, "electron_rom", "bin,rom");
37 m_romslot[4]->set_device_load(FUNC(electron_romp144_device::rom4));
38 GENERIC_SOCKET(config, m_romslot[5], generic_plain_slot, "electron_rom", "bin,rom");
39 m_romslot[5]->set_device_load(FUNC(electron_romp144_device::rom5));
40 GENERIC_SOCKET(config, m_romslot[6], generic_plain_slot, "electron_rom", "bin,rom");
41 m_romslot[6]->set_device_load(FUNC(electron_romp144_device::rom6));
42 }
43
44 //**************************************************************************
45 // LIVE DEVICE
46 //**************************************************************************
47
48 //-------------------------------------------------
49 // electron_romp144_device - constructor
50 //-------------------------------------------------
51
electron_romp144_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)52 electron_romp144_device::electron_romp144_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
53 : device_t(mconfig, ELECTRON_ROMP144, tag, owner, clock)
54 , device_electron_cart_interface(mconfig, *this)
55 , m_romslot(*this, "rom%u", 7)
56 {
57 }
58
59 //-------------------------------------------------
60 // device_start - device-specific startup
61 //-------------------------------------------------
62
device_start()63 void electron_romp144_device::device_start()
64 {
65 m_rom_select = 0xff;
66 m_rom_latch = 0xff;
67
68 save_item(NAME(m_rom_select));
69 save_item(NAME(m_rom_latch));
70 }
71
72 //-------------------------------------------------
73 // read - cartridge data read
74 //-------------------------------------------------
75
read(offs_t offset,int infc,int infd,int romqa,int oe,int oe2)76 uint8_t electron_romp144_device::read(offs_t offset, int infc, int infd, int romqa, int oe, int oe2)
77 {
78 uint8_t data = 0xff;
79
80 if (oe)
81 {
82 if (romqa)
83 {
84 if ((m_rom_select & 0x07) == 0x00)
85 data = m_ram[offset & 0x3fff];
86 else
87 data = m_romslot[(m_rom_select & 0x07) - 1]->read_rom(offset & 0x3fff);
88 }
89 else
90 {
91 if ((m_rom_select & 0x0f) == 0x08)
92 data = m_ram[(offset & 0x3fff) | 0x4000];
93 else
94 data = m_rom[offset & 0x1fff];
95
96 /* roms selected with a read to latch */
97 if ((offset & 0x3f00) == 0x3f00)
98 {
99 m_rom_latch = offset & 0x0f;
100 }
101 }
102 }
103
104 return data;
105 }
106
107 //-------------------------------------------------
108 // write - cartridge data write
109 //-------------------------------------------------
110
write(offs_t offset,uint8_t data,int infc,int infd,int romqa,int oe,int oe2)111 void electron_romp144_device::write(offs_t offset, uint8_t data, int infc, int infd, int romqa, int oe, int oe2)
112 {
113 if (oe)
114 {
115 if (romqa)
116 {
117 if ((m_rom_select & 0x07) == 0x00)
118 m_ram[offset & 0x3fff] = data;
119 }
120 else
121 {
122 if ((m_rom_select & 0x0f) == 0x08)
123 m_ram[(offset & 0x3fff) | 0x4000] = data;
124
125 /* roms selected with a write to select */
126 if ((offset & 0x3f00) == 0x3f00)
127 {
128 /* does the write match the read (upper RAM cannot be de-selected to protect *RSUBSTITUTE) */
129 if (m_rom_latch == (offset & 0x0f) && m_rom_select != 0x08)
130 {
131 m_rom_select = m_rom_latch;
132 }
133 }
134 }
135 }
136 }
137
138
139 //**************************************************************************
140 // IMPLEMENTATION
141 //**************************************************************************
142
load_rom(device_image_interface & image,generic_slot_device * slot)143 image_init_result electron_romp144_device::load_rom(device_image_interface &image, generic_slot_device *slot)
144 {
145 uint32_t size = slot->common_get_size("rom");
146
147 // socket accepts 8K and 16K ROM only
148 if (size != 0x2000 && size != 0x4000)
149 {
150 image.seterror(IMAGE_ERROR_UNSPECIFIED, "Invalid size: Only 8K/16K is supported");
151 return image_init_result::FAIL;
152 }
153
154 slot->rom_alloc(0x4000, GENERIC_ROM8_WIDTH, ENDIANNESS_LITTLE);
155 slot->common_load_rom(slot->get_rom_base(), size, "rom");
156
157 // mirror 8K ROMs
158 uint8_t *crt = slot->get_rom_base();
159 if (size <= 0x2000) memcpy(crt + 0x2000, crt, 0x2000);
160
161 return image_init_result::PASS;
162 }
163