1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4
5 Rex Datentechnik 256KB EPROM cartridge emulation
6
7 **********************************************************************/
8
9 #include "emu.h"
10 #include "rex_ep256.h"
11
12
13
14 //**************************************************************************
15 // DEVICE DEFINITIONS
16 //**************************************************************************
17
18 DEFINE_DEVICE_TYPE(C64_REX_EP256, c64_rex_ep256_cartridge_device, "c64_rex_ep256", "C64 Rex 256KB EPROM cartridge")
19
20
21 //-------------------------------------------------
22 // device_add_mconfig - add device configuration
23 //-------------------------------------------------
24
device_add_mconfig(machine_config & config)25 void c64_rex_ep256_cartridge_device::device_add_mconfig(machine_config &config)
26 {
27 for (auto &eprom : m_eproms)
28 GENERIC_SOCKET(config, eprom, generic_linear_slot, nullptr, "bin,rom");
29 }
30
31
32
33 //**************************************************************************
34 // LIVE DEVICE
35 //**************************************************************************
36
37 //-------------------------------------------------
38 // c64_rex_ep256_cartridge_device - constructor
39 //-------------------------------------------------
40
c64_rex_ep256_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)41 c64_rex_ep256_cartridge_device::c64_rex_ep256_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
42 device_t(mconfig, C64_REX_EP256, tag, owner, clock),
43 device_c64_expansion_card_interface(mconfig, *this),
44 m_eproms(*this, "rom%u", 1U)
45 {
46 }
47
48
49 //-------------------------------------------------
50 // device_start - device-specific startup
51 //-------------------------------------------------
52
device_start()53 void c64_rex_ep256_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_socket));
59 }
60
61
62 //-------------------------------------------------
63 // device_reset - device-specific reset
64 //-------------------------------------------------
65
device_reset()66 void c64_rex_ep256_cartridge_device::device_reset()
67 {
68 m_exrom = 0;
69 m_reset = 1;
70 m_bank = 0;
71 m_socket = 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_rex_ep256_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 if (m_reset)
84 {
85 data = m_roml[offset & 0x1fff];
86 }
87 else
88 {
89 offs_t addr = (m_bank << 13) | (offset & 0x1fff);
90 data = m_eproms[m_socket]->read_rom(addr);
91 }
92 }
93 else if (!io2)
94 {
95 if ((offset & 0xf0) == 0xc0)
96 {
97 m_exrom = 1;
98 }
99 else if ((offset & 0xf0) == 0xe0)
100 {
101 m_exrom = 0;
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_rex_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
126 5 bank selection bit 0
127 6 bank selection bit 1
128 7
129
130 */
131
132 m_reset = 0;
133
134 m_socket = data & 0x07;
135 m_bank = (data >> 5) & 0x03;
136 }
137 }
138