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