1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Dela 256KB EPROM cartridge emulation
6 
7 **********************************************************************/
8 
9 #include "emu.h"
10 #include "dela_ep256.h"
11 
12 
13 
14 //**************************************************************************
15 //  DEVICE DEFINITIONS
16 //**************************************************************************
17 
18 DEFINE_DEVICE_TYPE(C64_DELA_EP256, c64_dela_ep256_cartridge_device, "c64_dela_ep256", "C64 Dela 256KB EPROM cartridge")
19 
20 
21 //-------------------------------------------------
22 //  device_add_mconfig - add device configuration
23 //-------------------------------------------------
24 
device_add_mconfig(machine_config & config)25 void c64_dela_ep256_cartridge_device::device_add_mconfig(machine_config &config)
26 {
27 	GENERIC_SOCKET(config, "rom1", generic_linear_slot, nullptr, "bin,rom");
28 	GENERIC_SOCKET(config, "rom2", generic_linear_slot, nullptr, "bin,rom");
29 	GENERIC_SOCKET(config, "rom3", generic_linear_slot, nullptr, "bin,rom");
30 	GENERIC_SOCKET(config, "rom4", generic_linear_slot, nullptr, "bin,rom");
31 	GENERIC_SOCKET(config, "rom5", generic_linear_slot, nullptr, "bin,rom");
32 	GENERIC_SOCKET(config, "rom6", generic_linear_slot, nullptr, "bin,rom");
33 	GENERIC_SOCKET(config, "rom7", generic_linear_slot, nullptr, "bin,rom");
34 	GENERIC_SOCKET(config, "rom8", generic_linear_slot, nullptr, "bin,rom");
35 }
36 
37 
38 
39 //**************************************************************************
40 //  LIVE DEVICE
41 //**************************************************************************
42 
43 //-------------------------------------------------
44 //  c64_dela_ep256_cartridge_device - constructor
45 //-------------------------------------------------
46 
c64_dela_ep256_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)47 c64_dela_ep256_cartridge_device::c64_dela_ep256_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
48 	device_t(mconfig, C64_DELA_EP256, tag, owner, clock),
49 	device_c64_expansion_card_interface(mconfig, *this)
50 {
51 	for (int i = 0; i < 8; i++)
52 	{
53 		char str[6];
54 		sprintf(str, "rom%i", i + 1);
55 		m_eproms[i] = subdevice<generic_slot_device>(str);
56 	}
57 }
58 
59 
60 //-------------------------------------------------
61 //  device_start - device-specific startup
62 //-------------------------------------------------
63 
device_start()64 void c64_dela_ep256_cartridge_device::device_start()
65 {
66 	// state saving
67 	save_item(NAME(m_bank));
68 	save_item(NAME(m_reset));
69 	save_item(NAME(m_socket));
70 }
71 
72 
73 //-------------------------------------------------
74 //  device_reset - device-specific reset
75 //-------------------------------------------------
76 
device_reset()77 void c64_dela_ep256_cartridge_device::device_reset()
78 {
79 	m_reset = 1;
80 	m_bank = 0;
81 	m_exrom = 0;
82 	m_socket = 0;
83 }
84 
85 
86 //-------------------------------------------------
87 //  c64_cd_r - cartridge data read
88 //-------------------------------------------------
89 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)90 uint8_t c64_dela_ep256_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
91 {
92 	if (!roml)
93 	{
94 		if (m_reset)
95 		{
96 			data = m_roml[offset & 0x1fff];
97 		}
98 		else
99 		{
100 			offs_t addr = (m_bank << 13) | (offset & 0x1fff);
101 			data = m_eproms[m_socket]->read_rom(addr);
102 		}
103 	}
104 
105 	return data;
106 }
107 
108 
109 //-------------------------------------------------
110 //  c64_cd_w - cartridge data write
111 //-------------------------------------------------
112 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)113 void c64_dela_ep256_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
114 {
115 	if (!io2 && ((offset & 0xf0) == 0xa0))
116 	{
117 		/*
118 
119 		    bit     description
120 
121 		    0       socket selection bit 0
122 		    1       socket selection bit 1
123 		    2       socket selection bit 2
124 		    3
125 		    4       bank selection bit 0
126 		    5       bank selection bit 1
127 		    6
128 		    7       EXROM
129 
130 		*/
131 
132 		m_reset = 0;
133 
134 		m_socket = data & 0x07;
135 		m_bank = (data >> 4) & 0x03;
136 
137 		m_exrom = BIT(data, 7);
138 	}
139 }
140