1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Dela 7x8K EPROM cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "dela_ep7x8.h"
11 
12 
13 
14 //**************************************************************************
15 //  DEVICE DEFINITIONS
16 //**************************************************************************
17 
18 DEFINE_DEVICE_TYPE(C64_DELA_EP7X8, c64_dela_ep7x8_cartridge_device, "c64_dela_ep7x8", "C64 Dela 7x8KB EPROM cartridge")
19 
20 
21 //-------------------------------------------------
22 //  device_add_mconfig - add device configuration
23 //-------------------------------------------------
24 
device_add_mconfig(machine_config & config)25 void c64_dela_ep7x8_cartridge_device::device_add_mconfig(machine_config &config)
26 {
27 	GENERIC_SOCKET(config, m_eprom[0], generic_linear_slot, nullptr, "bin,rom");
28 	GENERIC_SOCKET(config, m_eprom[1], generic_linear_slot, nullptr, "bin,rom");
29 	GENERIC_SOCKET(config, m_eprom[2], generic_linear_slot, nullptr, "bin,rom");
30 	GENERIC_SOCKET(config, m_eprom[3], generic_linear_slot, nullptr, "bin,rom");
31 	GENERIC_SOCKET(config, m_eprom[4], generic_linear_slot, nullptr, "bin,rom");
32 	GENERIC_SOCKET(config, m_eprom[5], generic_linear_slot, nullptr, "bin,rom");
33 	GENERIC_SOCKET(config, m_eprom[6], generic_linear_slot, nullptr, "bin,rom");
34 }
35 
36 
37 //**************************************************************************
38 //  LIVE DEVICE
39 //**************************************************************************
40 
41 //-------------------------------------------------
42 //  c64_dela_ep7x8_cartridge_device - constructor
43 //-------------------------------------------------
44 
c64_dela_ep7x8_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)45 c64_dela_ep7x8_cartridge_device::c64_dela_ep7x8_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
46 	device_t(mconfig, C64_DELA_EP7X8, tag, owner, clock),
47 	device_c64_expansion_card_interface(mconfig, *this),
48 	m_eprom(*this, "rom%u", 1U)
49 {
50 }
51 
52 
53 //-------------------------------------------------
54 //  device_start - device-specific startup
55 //-------------------------------------------------
56 
device_start()57 void c64_dela_ep7x8_cartridge_device::device_start()
58 {
59 	// state saving
60 	save_item(NAME(m_bank));
61 }
62 
63 
64 //-------------------------------------------------
65 //  device_reset - device-specific reset
66 //-------------------------------------------------
67 
device_reset()68 void c64_dela_ep7x8_cartridge_device::device_reset()
69 {
70 	m_bank = 0xfe;
71 	m_exrom = 0;
72 }
73 
74 
75 //-------------------------------------------------
76 //  c64_cd_r - cartridge data read
77 //-------------------------------------------------
78 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)79 uint8_t c64_dela_ep7x8_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
80 {
81 	if (!roml)
82 	{
83 		offs_t addr = offset & 0x1fff;
84 
85 		if (!BIT(m_bank, 0)) data |= m_roml[addr];
86 		if (!BIT(m_bank, 1)) data |= m_eprom[0]->read_rom(addr);
87 		if (!BIT(m_bank, 2)) data |= m_eprom[1]->read_rom(addr);
88 		if (!BIT(m_bank, 3)) data |= m_eprom[2]->read_rom(addr);
89 		if (!BIT(m_bank, 4)) data |= m_eprom[3]->read_rom(addr);
90 		if (!BIT(m_bank, 5)) data |= m_eprom[4]->read_rom(addr);
91 		if (!BIT(m_bank, 6)) data |= m_eprom[5]->read_rom(addr);
92 		if (!BIT(m_bank, 7)) data |= m_eprom[6]->read_rom(addr);
93 	}
94 
95 	return data;
96 }
97 
98 
99 //-------------------------------------------------
100 //  c64_cd_w - cartridge data write
101 //-------------------------------------------------
102 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)103 void c64_dela_ep7x8_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
104 {
105 	if (!io1)
106 	{
107 		m_bank = data;
108 
109 		m_exrom = (data == 0xff);
110 	}
111 }
112