1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Batteries Included BusCard II cartridge emulation
6 
7     SYS 61000 -> Enable BASIC 4.0
8     SYS 61003 -> Disable BASIC 4.0
9     SYS 61006 -> Enter Machine Language Monitor
10 
11 **********************************************************************/
12 
13 #include "emu.h"
14 #include "buscard2.h"
15 
16 
17 
18 //**************************************************************************
19 //  DEVICE DEFINITIONS
20 //**************************************************************************
21 
22 DEFINE_DEVICE_TYPE(C64_BUSCARD2, c64_buscard2_device, "c64_buscard2", "C64 BusCard II cartridge")
23 
24 
25 //-------------------------------------------------
26 //  ROM( buscard2 )
27 //-------------------------------------------------
28 
ROM_START(buscard2)29 ROM_START( buscard2 )
30 	ROM_REGION( 0x2000, "rom", 0 )
31 	ROM_LOAD( "v2.12.bin", 0x0000, 0x2000, CRC(1c9b2edb) SHA1(04f0a248370281fd42389928e32d11aba597cf01) )
32 
33 	// dumps coming soon
34 	ROM_REGION( 0x200, "prom", 0 )
35 	ROM_LOAD( "82s129.1", 0x000, 0x100, NO_DUMP )
36 	ROM_LOAD( "82s129.2", 0x100, 0x100, NO_DUMP )
37 ROM_END
38 
39 
40 //-------------------------------------------------
41 //  rom_region - device-specific ROM region
42 //-------------------------------------------------
43 
44 const tiny_rom_entry *c64_buscard2_device::device_rom_region() const
45 {
46 	return ROM_NAME( buscard2 );
47 }
48 
49 
50 //-------------------------------------------------
51 //  INPUT_PORTS( buscard2 )
52 //-------------------------------------------------
53 
54 static INPUT_PORTS_START( buscard2 )
55 	PORT_START("S1")
56 	PORT_DIPNAME( 0x03, 0x00, "Device #4" ) PORT_DIPLOCATION("S1:1,2")
57 	PORT_DIPSETTING(    0x00, "Serial" )
58 	PORT_DIPSETTING(    0x01, "Parallel w/conv." )
59 	PORT_DIPSETTING(    0x02, "IEEE" )
60 	PORT_DIPSETTING(    0x03, "Parallel" )
61 	PORT_DIPNAME( 0x04, 0x04, "Device #5" ) PORT_DIPLOCATION("S1:3")
62 	PORT_DIPSETTING(    0x00, "IEEE" )
63 	PORT_DIPSETTING(    0x04, "Serial" )
64 	PORT_DIPNAME( 0x08, 0x08, "Device #6" ) PORT_DIPLOCATION("S1:4")
65 	PORT_DIPSETTING(    0x00, "IEEE" )
66 	PORT_DIPSETTING(    0x08, "Serial" )
67 	PORT_DIPNAME( 0x10, 0x10, "Device #7" ) PORT_DIPLOCATION("S1:5")
68 	PORT_DIPSETTING(    0x00, "IEEE" )
69 	PORT_DIPSETTING(    0x10, "Serial" )
70 	PORT_DIPNAME( 0x20, 0x20, "Device #8" ) PORT_DIPLOCATION("S1:6")
71 	PORT_DIPSETTING(    0x00, "IEEE" )
72 	PORT_DIPSETTING(    0x20, "Serial" )
73 	PORT_DIPNAME( 0x40, 0x40, "Device #9" ) PORT_DIPLOCATION("S1:7")
74 	PORT_DIPSETTING(    0x00, "IEEE" )
75 	PORT_DIPSETTING(    0x40, "Serial" )
76 	PORT_DIPNAME( 0x80, 0x80, "Device #10" ) PORT_DIPLOCATION("S1:8")
77 	PORT_DIPSETTING(    0x00, "IEEE" )
78 	PORT_DIPSETTING(    0x80, "Serial" )
79 INPUT_PORTS_END
80 
81 
82 //-------------------------------------------------
83 //  input_ports - device-specific input ports
84 //-------------------------------------------------
85 
device_input_ports() const86 ioport_constructor c64_buscard2_device::device_input_ports() const
87 {
88 	return INPUT_PORTS_NAME( buscard2 );
89 }
90 
91 
92 //-------------------------------------------------
93 //  Centronics interface
94 //-------------------------------------------------
95 
WRITE_LINE_MEMBER(c64_buscard2_device::busy_w)96 WRITE_LINE_MEMBER( c64_buscard2_device::busy_w )
97 {
98 	m_busy = state;
99 }
100 
101 
102 //-------------------------------------------------
103 //  device_add_mconfig - add device configuration
104 //-------------------------------------------------
105 
device_add_mconfig(machine_config & config)106 void c64_buscard2_device::device_add_mconfig(machine_config &config)
107 {
108 	RIOT6532(config, m_riot, 0);
109 
110 	PIA6821(config, m_pia, 0);
111 
112 	IEEE488(config, m_bus, 0);
113 	ieee488_slot_device::add_cbm_defaults(config, nullptr);
114 
115 	CENTRONICS(config, m_centronics, centronics_devices, nullptr);
116 	m_centronics->busy_handler().set(FUNC(c64_buscard2_device::busy_w));
117 
118 	C64_EXPANSION_SLOT(config, m_exp, DERIVED_CLOCK(1, 1), c64_expansion_cards, nullptr);
119 	m_exp->set_passthrough();
120 }
121 
122 
123 
124 //**************************************************************************
125 //  LIVE DEVICE
126 //**************************************************************************
127 
128 //-------------------------------------------------
129 //  c64_buscard2_device - constructor
130 //-------------------------------------------------
131 
c64_buscard2_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)132 c64_buscard2_device::c64_buscard2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
133 	device_t(mconfig, C64_BUSCARD2, tag, owner, clock),
134 	device_c64_expansion_card_interface(mconfig, *this),
135 	m_riot(*this, "riot"),
136 	m_pia(*this, "pia"),
137 	m_bus(*this, IEEE488_TAG),
138 	m_centronics(*this, "centronics"),
139 	m_exp(*this, "exp"),
140 	m_s1(*this, "S1"),
141 	m_rom(*this, "rom"),
142 	m_prom(*this, "prom"),
143 	m_busy(1)
144 {
145 }
146 
147 
148 //-------------------------------------------------
149 //  device_start - device-specific startup
150 //-------------------------------------------------
151 
device_start()152 void c64_buscard2_device::device_start()
153 {
154 	// state saving
155 	save_item(NAME(m_busy));
156 }
157 
158 
159 //-------------------------------------------------
160 //  device_reset - device-specific reset
161 //-------------------------------------------------
162 
device_reset()163 void c64_buscard2_device::device_reset()
164 {
165 }
166 
167 
168 //-------------------------------------------------
169 //  c64_cd_r - cartridge data read
170 //-------------------------------------------------
171 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)172 uint8_t c64_buscard2_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
173 {
174 	return m_exp->cd_r(offset, data, sphi2, ba, roml, romh, io1, io2);
175 }
176 
177 
178 //-------------------------------------------------
179 //  c64_cd_w - cartridge data write
180 //-------------------------------------------------
181 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)182 void c64_buscard2_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
183 {
184 	m_exp->cd_w(offset, data, sphi2, ba, roml, romh, io1, io2);
185 }
186 
187 
188 //-------------------------------------------------
189 //  c64_game_r - cartridge GAME read
190 //-------------------------------------------------
191 
c64_game_r(offs_t offset,int sphi2,int ba,int rw)192 int c64_buscard2_device::c64_game_r(offs_t offset, int sphi2, int ba, int rw)
193 {
194 	return m_exp->game_r(offset, sphi2, ba, rw, m_slot->loram(), m_slot->hiram());
195 }
196 
197 
198 //-------------------------------------------------
199 //  c64_exrom_r - cartridge EXROM read
200 //-------------------------------------------------
201 
c64_exrom_r(offs_t offset,int sphi2,int ba,int rw)202 int c64_buscard2_device::c64_exrom_r(offs_t offset, int sphi2, int ba, int rw)
203 {
204 	return m_exp->exrom_r(offset, sphi2, ba, rw, m_slot->loram(), m_slot->hiram());
205 }
206