1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4
5 EasyFlash cartridge emulation
6
7 **********************************************************************/
8
9 #include "emu.h"
10 #include "easyflash.h"
11
12
13 //**************************************************************************
14 // MACROS/CONSTANTS
15 //**************************************************************************
16
17 #define AM29F040_0_TAG "u3"
18 #define AM29F040_1_TAG "u4"
19
20
21
22 //**************************************************************************
23 // DEVICE DEFINITIONS
24 //**************************************************************************
25
26 DEFINE_DEVICE_TYPE(C64_EASYFLASH, c64_easyflash_cartridge_device, "c64_easyflash", "C64 EasyFlash cartridge")
27
28
29 //-------------------------------------------------
30 // device_add_mconfig - add device configuration
31 //-------------------------------------------------
32
device_add_mconfig(machine_config & config)33 void c64_easyflash_cartridge_device::device_add_mconfig(machine_config &config)
34 {
35 AMD_29F040(config, AM29F040_0_TAG);
36 AMD_29F040(config, AM29F040_1_TAG);
37 }
38
39
40 //-------------------------------------------------
41 // INPUT_PORTS( c64_easyflash )
42 //-------------------------------------------------
43
44 static INPUT_PORTS_START( c64_easyflash )
45 PORT_START("JP1")
46 PORT_DIPNAME( 0x01, 0x00, "Boot" )
47 PORT_DIPSETTING( 0x00, "Disable" )
48 PORT_DIPSETTING( 0x01, "Boot" )
49
50 PORT_START("RESET")
PORT_CODE(KEYCODE_F11)51 PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Reset") PORT_CODE(KEYCODE_F11) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF_OWNER, c64_expansion_slot_device, reset_w)
52 INPUT_PORTS_END
53
54
55 //-------------------------------------------------
56 // input_ports - device-specific input ports
57 //-------------------------------------------------
58
59 ioport_constructor c64_easyflash_cartridge_device::device_input_ports() const
60 {
61 return INPUT_PORTS_NAME( c64_easyflash );
62 }
63
64
65
66 //**************************************************************************
67 // LIVE DEVICE
68 //**************************************************************************
69
70 //-------------------------------------------------
71 // c64_easyflash_cartridge_device - constructor
72 //-------------------------------------------------
73
c64_easyflash_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)74 c64_easyflash_cartridge_device::c64_easyflash_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
75 device_t(mconfig, C64_EASYFLASH, tag, owner, clock),
76 device_c64_expansion_card_interface(mconfig, *this),
77 m_flash_roml(*this, AM29F040_0_TAG),
78 m_flash_romh(*this, AM29F040_1_TAG),
79 m_jp1(*this, "JP1"),
80 m_ram(*this, "ram"),
81 m_bank(0),
82 m_mode(0)
83 {
84 }
85
86
87 //-------------------------------------------------
88 // device_start - device-specific startup
89 //-------------------------------------------------
90
device_start()91 void c64_easyflash_cartridge_device::device_start()
92 {
93 // allocate memory
94 m_ram.allocate(0x100);
95
96 // state saving
97 save_item(NAME(m_bank));
98 save_item(NAME(m_mode));
99 }
100
101
102 //-------------------------------------------------
103 // device_reset - device-specific reset
104 //-------------------------------------------------
105
device_reset()106 void c64_easyflash_cartridge_device::device_reset()
107 {
108 m_bank = 0;
109 m_mode = 0;
110 }
111
112
113 //-------------------------------------------------
114 // c64_cd_r - cartridge data read
115 //-------------------------------------------------
116
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)117 uint8_t c64_easyflash_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
118 {
119 if (!roml)
120 {
121 offs_t addr = (m_bank << 13) | (offset & 0x1fff);
122 data = m_flash_roml->read(addr);
123 }
124 else if (!romh)
125 {
126 offs_t addr = (m_bank << 13) | (offset & 0x1fff);
127 data = m_flash_romh->read(addr);
128 }
129 else if (!io2)
130 {
131 data = m_ram[offset & 0xff];
132 }
133
134 return data;
135 }
136
137
138 //-------------------------------------------------
139 // c64_cd_w - cartridge data write
140 //-------------------------------------------------
141
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)142 void c64_easyflash_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
143 {
144 if (!roml)
145 {
146 offs_t addr = (m_bank << 13) | (offset & 0x1fff);
147 m_flash_roml->write(addr, data);
148 }
149 else if (!romh)
150 {
151 offs_t addr = (m_bank << 13) | (offset & 0x1fff);
152 m_flash_romh->write(addr, data);
153 }
154 else if (!io1)
155 {
156 if (!BIT(offset, 1))
157 {
158 /*
159
160 bit description
161
162 0 BA13
163 1 BA14
164 2 BA15
165 3 BA16
166 4 BA17
167 5 BA18
168 6
169 7
170
171 */
172
173 m_bank = data & 0x3f;
174 }
175 else
176 {
177 /*
178
179 bit description
180
181 0 GAME
182 1 EXROM
183 2 MODE
184 3
185 4
186 5
187 6
188 7 LED
189
190 */
191
192 m_mode = data;
193 }
194 }
195 else if (!io2)
196 {
197 m_ram[offset & 0xff] = data;
198 }
199 }
200
201
202 //-------------------------------------------------
203 // c64_exrom_r - EXROM read
204 //-------------------------------------------------
205
c64_exrom_r(offs_t offset,int sphi2,int ba,int rw)206 int c64_easyflash_cartridge_device::c64_exrom_r(offs_t offset, int sphi2, int ba, int rw)
207 {
208 return !BIT(m_mode, 1);
209 }
210
211
212 //-------------------------------------------------
213 // c64_game_r - GAME read
214 //-------------------------------------------------
215
c64_game_r(offs_t offset,int sphi2,int ba,int rw)216 int c64_easyflash_cartridge_device::c64_game_r(offs_t offset, int sphi2, int ba, int rw)
217 {
218 return (BIT(m_mode, 0) || !(BIT(m_mode, 2) || m_jp1->read())) ? 0 : 1;
219 }
220