1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     Triton QD TDOS cartridge emulation
6 
7 **********************************************************************/
8 
9 /*
10 
11 PCB Layout
12 ----------
13 
14 XM-2206-A (top)
15 XM-2205-A (bottom)
16 
17             |===========================|
18             |            CN4            |
19             |                           |
20             |      ULA                  |
21             |                           |
22             |      6.5MHz               |
23             |                           |
24             |      SSDA                 |
25             |                 LS175     |
26             |                 LS367     |
27             |            CN3            |
28             |=========|||||||||=========|
29                       |||||||||
30         |=============|||||||||============|
31         |                CN2               |
32         |       LS00     LS02     LS138    |
33 |=======|                                  |
34 |=|             LS245        ROM           |
35 |=|                                        |
36 |=|                                        |
37 |=|                                     CN1|
38 |=|                                        |
39 |=|                                        |
40 |=|                                        |
41 |=|                             SW1        |
42 |==========================================|
43 
44 ROM    - Hitachi HN482764G 8Kx8 EPROM "TDOS 1.2"
45 ULA    - Ferranti ULA5RB073E1 XZ-2085-1 40-pin custom ULA
46 SSDA   - Motorola MC68A52P SSDA
47 CN1    - C64 expansion connector (pass-thru)
48 CN2,3  - 18x1 flat ribbon cable to other PCB
49 CN4    - 9 wire cable to Mitsumi Quick Disk 3" drive
50 SW1    - cartridge on/off switch
51 
52 
53 Flat ribbon cable pinout
54 ------------------------
55 1   D7
56 2   D6
57 3   D5
58 4   D4
59 5   D3
60 6   LS00 4Y -> LS367 _G1
61 7   phi2
62 8   LS00 3Y -> LS175 CP
63 9   D2
64 10  D1
65 11  D0
66 12  RESET
67 13  A0
68 14  R/_W
69 15  GND
70 16  +5V
71 17  LS138 O2 -> LS367 _G1
72 18  LS138 O0 -> SSDA _CS
73 
74 
75 Drive cable pinout
76 ------------------
77 1   WP      Write Protected
78 2   WD      Write Data
79 3   WG      Write Gate
80 4   MO      Motor
81 5   RD      Read Data
82 6   RY      Ready
83 7   MS      Media Set
84 8   RS      Reset
85 9   +5V
86 10  GND
87 
88 
89 ULA pinout
90 ----------
91             _____   _____
92          1 |*    \_/     | 40
93          2 |             | 39
94          3 |             | 38
95          4 |             | 37
96          5 |             | 36  GND
97          6 |             | 35
98     RD   7 |             | 34
99    _D5   8 |             | 33
100    RxC   9 |             | 32
101    RxD  10 |  XZ-2085-1  | 31
102         11 |             | 30
103     WD  12 |             | 29
104    TxC  13 |             | 28
105    TxD  14 |             | 27
106     D7  15 |             | 26
107     WG  16 |             | 25  +5V
108         17 |             | 24  XTAL2
109         18 |             | 23  XTAL1
110     RS  19 |             | 22  GND
111         20 |_____________| 21
112 
113 
114 BASIC commands (SYS 32768 to activate)
115 --------------------------------------
116 @Dn
117 @Format
118 @Dir
119 @Save
120 @ASave
121 @Write
122 @Load
123 @Run
124 @Aload
125 @Kill
126 @Quit
127 @ACopy
128 @CassCopy
129 
130 */
131 
132 #include "emu.h"
133 #include "tdos.h"
134 
135 
136 
137 //**************************************************************************
138 //  MACROS/CONSTANTS
139 //**************************************************************************
140 
141 #define MC68A52P_TAG        "mc6852"
142 
143 
144 
145 //**************************************************************************
146 //  DEVICE DEFINITIONS
147 //**************************************************************************
148 
149 DEFINE_DEVICE_TYPE(C64_TDOS, c64_tdos_cartridge_device, "c64_tdos", "C64 TDOS cartridge")
150 
151 
152 //-------------------------------------------------
153 //  device_add_mconfig - add device configuration
154 //-------------------------------------------------
155 
device_add_mconfig(machine_config & config)156 void c64_tdos_cartridge_device::device_add_mconfig(machine_config &config)
157 {
158 	MC6852(config, m_ssda, XTAL(6'500'000));
159 
160 	C64_EXPANSION_SLOT(config, m_exp, DERIVED_CLOCK(1, 1), c64_expansion_cards, nullptr);
161 	m_exp->set_passthrough();
162 }
163 
164 
165 //-------------------------------------------------
166 //  INPUT_PORTS( c64_tdos )
167 //-------------------------------------------------
168 
169 static INPUT_PORTS_START( c64_tdos )
170 	PORT_START("SW1")
171 	PORT_DIPNAME( 0x01, 0x01, "Enabled" )
DEF_STR(Off)172 	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
173 	PORT_DIPSETTING(    0x01, DEF_STR( On ) )
174 INPUT_PORTS_END
175 
176 
177 //-------------------------------------------------
178 //  input_ports - device-specific input ports
179 //-------------------------------------------------
180 
181 ioport_constructor c64_tdos_cartridge_device::device_input_ports() const
182 {
183 	return INPUT_PORTS_NAME( c64_tdos );
184 }
185 
186 
187 
188 //**************************************************************************
189 //  LIVE DEVICE
190 //**************************************************************************
191 
192 //-------------------------------------------------
193 //  c64_tdos_cartridge_device - constructor
194 //-------------------------------------------------
195 
c64_tdos_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)196 c64_tdos_cartridge_device::c64_tdos_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
197 	device_t(mconfig, C64_TDOS, tag, owner, clock),
198 	device_c64_expansion_card_interface(mconfig, *this),
199 	m_ssda(*this, MC68A52P_TAG),
200 	m_exp(*this, "exp"),
201 	m_sw1(*this, "SW1"), m_enabled(false)
202 {
203 }
204 
205 
206 //-------------------------------------------------
207 //  device_start - device-specific startup
208 //-------------------------------------------------
209 
device_start()210 void c64_tdos_cartridge_device::device_start()
211 {
212 }
213 
214 
215 //-------------------------------------------------
216 //  device_reset - device-specific reset
217 //-------------------------------------------------
218 
device_reset()219 void c64_tdos_cartridge_device::device_reset()
220 {
221 	m_ssda->reset();
222 	//m_ula->reset();
223 	//flip-flop reset
224 
225 	m_enabled = m_sw1->read();
226 }
227 
228 
229 //-------------------------------------------------
230 //  c64_cd_r - cartridge data read
231 //-------------------------------------------------
232 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)233 uint8_t c64_tdos_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
234 {
235 	data = m_exp->cd_r(offset, data, sphi2, ba, roml, romh, io1, io2);
236 
237 	if (m_enabled && !roml)
238 	{
239 		data = m_roml[offset & 0x1fff];
240 	}
241 
242 	if (m_enabled && !io2 && sphi2)
243 	{
244 		switch ((offset >> 1) & 0x7f)
245 		{
246 		case 0:
247 			data = m_ssda->read(offset & 0x01);
248 			break;
249 
250 		case 1:
251 			break;
252 
253 		case 2:
254 			/*
255 
256 			    bit     description
257 
258 			    0
259 			    1
260 			    2
261 			    3
262 			    4
263 			    5       drive MS
264 			    6       drive WP
265 			    7       drive RY
266 
267 			*/
268 			break;
269 		}
270 	}
271 
272 	return data;
273 }
274 
275 
276 //-------------------------------------------------
277 //  c64_cd_w - cartridge data write
278 //-------------------------------------------------
279 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)280 void c64_tdos_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
281 {
282 	m_exp->cd_w(offset, data, sphi2, ba, roml, romh, io1, io2);
283 
284 	if (m_enabled && !io2 && sphi2)
285 	{
286 		switch ((offset >> 1) & 0x7f)
287 		{
288 		case 0:
289 			m_ssda->write(offset & 0x01, data);
290 			break;
291 
292 		case 1:
293 			/*
294 
295 			    bit     description
296 
297 			    0
298 			    1
299 			    2
300 			    3
301 			    4
302 			    5       ULA pin 8, inverted
303 			    6       drive MO
304 			    7       ULA pin 15
305 
306 			*/
307 			break;
308 
309 		case 2:
310 			break;
311 		}
312 	}
313 }
314 
315 
316 //-------------------------------------------------
317 //  c64_game_r - GAME read
318 //-------------------------------------------------
319 
c64_game_r(offs_t offset,int sphi2,int ba,int rw)320 int c64_tdos_cartridge_device::c64_game_r(offs_t offset, int sphi2, int ba, int rw)
321 {
322 	return m_enabled ? 1 : m_exp->game_r(offset, sphi2, ba, rw, m_slot->loram(), m_slot->hiram());
323 }
324 
325 
326 //-------------------------------------------------
327 //  c64_exrom_r - EXROM read
328 //-------------------------------------------------
329 
c64_exrom_r(offs_t offset,int sphi2,int ba,int rw)330 int c64_tdos_cartridge_device::c64_exrom_r(offs_t offset, int sphi2, int ba, int rw)
331 {
332 	return m_enabled ? 0 : m_exp->exrom_r(offset, sphi2, ba, rw, m_slot->loram(), m_slot->hiram());
333 }
334