summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/kaypro.c
blob: 23334e8b696e7a59dde37deb1e8204c930ae38da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#include "includes/kaypro.h"




/***********************************************************

    PIO

    Port B is unused on both PIOs

************************************************************/

WRITE_LINE_MEMBER(kaypro_state::kaypro_interrupt)
{
	machine().device("maincpu")->execute().set_input_line(0, state);
}

READ8_MEMBER( kaypro_state::pio_system_r )
{
	UINT8 data = 0;

	/* centronics busy */
	data |= m_centronics->not_busy_r() << 3;

	/* PA7 is pulled high */
	data |= 0x80;

	return data;
}

WRITE8_MEMBER( kaypro_state::common_pio_system_w )
{
/*  d7 bank select
    d6 disk drive motors - (0=on)
    d5 double-density enable (0=double density)
    d4 Centronics strobe
    d2 side select (1=side 1)
    d1 drive B
    d0 drive A */

	/* get address space */
	address_space &mem = m_maincpu->space(AS_PROGRAM);

	if (data & 0x80)
	{
		mem.unmap_readwrite (0x0000, 0x3fff);
		mem.install_read_bank (0x0000, 0x0fff, "bank1");
		membank("bank1")->set_base(machine().root_device().memregion("maincpu")->base());
		mem.install_readwrite_handler (0x3000, 0x3fff, read8_delegate(FUNC(kaypro_state::kaypro_videoram_r), this), write8_delegate(FUNC(kaypro_state::kaypro_videoram_w), this));
	}
	else
	{
		mem.unmap_readwrite(0x0000, 0x3fff);
		mem.install_read_bank (0x0000, 0x3fff, "bank2");
		mem.install_write_bank (0x0000, 0x3fff, "bank3");
		membank("bank2")->set_base(machine().root_device().memregion("rambank")->base());
		membank("bank3")->set_base(machine().root_device().memregion("rambank")->base());
	}

	wd17xx_dden_w(m_fdc, BIT(data, 5));

	m_centronics->strobe_w(BIT(data, 4));

	if (BIT(data, 0))
		wd17xx_set_drive(m_fdc, 0);

	if (BIT(data, 1))
		wd17xx_set_drive(m_fdc, 1);

	output_set_value("ledA", BIT(data, 0));		/* LEDs in artwork */
	output_set_value("ledB", BIT(data, 1));

	/* CLEAR_LINE means to turn motors on */
	floppy_mon_w(floppy_get_device(machine(), 0), BIT(data, 6) ? ASSERT_LINE : CLEAR_LINE);
	floppy_mon_w(floppy_get_device(machine(), 1), BIT(data, 6) ? ASSERT_LINE : CLEAR_LINE);

	m_system_port = data;
}

WRITE8_MEMBER( kaypro_state::kayproii_pio_system_w )
{
	common_pio_system_w(space, offset, data);

	/* side select */
	wd17xx_set_side(m_fdc, !BIT(data, 2));
}

WRITE8_MEMBER( kaypro_state::kaypro4_pio_system_w )
{
	common_pio_system_w(space, offset, data);

	/* side select */
	wd17xx_set_side(m_fdc, BIT(data, 2));
}

const z80pio_interface kayproii_pio_g_intf =
{
	DEVCB_CPU_INPUT_LINE("maincpu", INPUT_LINE_IRQ0),
	DEVCB_NULL,
	DEVCB_DEVICE_MEMBER("centronics", centronics_device, write),
	DEVCB_NULL,			/* portA ready active callback */
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL			/* portB ready active callback */
};

const z80pio_interface kayproii_pio_s_intf =
{
	DEVCB_CPU_INPUT_LINE("maincpu", INPUT_LINE_IRQ0),
	DEVCB_DRIVER_MEMBER(kaypro_state, pio_system_r),	/* read printer status */
	DEVCB_DRIVER_MEMBER(kaypro_state, kayproii_pio_system_w),	/* activate various internal devices */
	DEVCB_NULL,			/* portA ready active callback */
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL			/* portB ready active callback */
};

const z80pio_interface kaypro4_pio_s_intf =
{
	DEVCB_CPU_INPUT_LINE("maincpu", INPUT_LINE_IRQ0),
	DEVCB_DRIVER_MEMBER(kaypro_state, pio_system_r),	/* read printer status */
	DEVCB_DRIVER_MEMBER(kaypro_state, kaypro4_pio_system_w),	/* activate various internal devices */
	DEVCB_NULL,			/* portA ready active callback */
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL			/* portB ready active callback */
};

/***********************************************************

    KAYPRO2X SYSTEM PORT

    The PIOs were replaced by a few standard 74xx chips

************************************************************/

READ8_MEMBER( kaypro_state::kaypro2x_system_port_r )
{
	UINT8 data = m_centronics->busy_r() << 6;
	return (m_system_port & 0xbf) | data;
}

WRITE8_MEMBER( kaypro_state::kaypro2x_system_port_w )
{
/*  d7 bank select
    d6 alternate character set (write only)
    d5 double-density enable
    d4 disk drive motors (1=on)
    d3 Centronics strobe
    d2 side select (appears that 0=side 1?)
    d1 drive B
    d0 drive A */

	/* get address space */
	address_space &mem = machine().device("maincpu")->memory().space(AS_PROGRAM);

	if (BIT(data, 7))
	{
		mem.unmap_readwrite (0x0000, 0x3fff);
		mem.install_read_bank (0x0000, 0x1fff, "bank1");
		membank("bank1")->set_base(mem.machine().root_device().memregion("maincpu")->base());
	}
	else
	{
		mem.unmap_readwrite (0x0000, 0x3fff);
		mem.install_read_bank (0x0000, 0x3fff, "bank2");
		mem.install_write_bank (0x0000, 0x3fff, "bank3");
		membank("bank2")->set_base(mem.machine().root_device().memregion("rambank")->base());
		membank("bank3")->set_base(mem.machine().root_device().memregion("rambank")->base());
	}

	wd17xx_dden_w(m_fdc, BIT(data, 5));

	m_centronics->strobe_w(BIT(data, 3));

	if (BIT(data, 0))
		wd17xx_set_drive(m_fdc, 0);
	else
	if (BIT(data, 1))
		wd17xx_set_drive(m_fdc, 1);

	wd17xx_set_side(m_fdc, BIT(data, 2) ? 0 : 1);

	output_set_value("ledA", BIT(data, 0));		/* LEDs in artwork */
	output_set_value("ledB", BIT(data, 1));

	/* CLEAR_LINE means to turn motors on */
	floppy_mon_w(floppy_get_device(machine(), 0), BIT(data, 4) ? CLEAR_LINE : ASSERT_LINE);
	floppy_mon_w(floppy_get_device(machine(), 1), BIT(data, 4) ? CLEAR_LINE : ASSERT_LINE);

	m_system_port = data;
}



/***********************************************************************

    SIO

    On Kaypro2x, Channel B on both SIOs is hardwired to 300 baud.

    Both devices on sio2 (printer and modem) are not emulated.

************************************************************************/

/* Set baud rate. bits 0..3 Rx and Tx are tied together. Baud Rate Generator is a AY-5-8116, SMC8116, WD1943, etc.
    00h    50
    11h    75
    22h    110
    33h    134.5
    44h    150
    55h    300
    66h    600
    77h    1200
    88h    1800
    99h    2000
    AAh    2400
    BBh    3600
    CCh    4800
    DDh    7200
    EEh    9600
    FFh    19200 */


const z80sio_interface kaypro_sio_intf =
{
	DEVCB_DRIVER_LINE_MEMBER(kaypro_state,kaypro_interrupt),	/* interrupt handler */
	DEVCB_NULL,			/* DTR changed handler */
	DEVCB_NULL,			/* RTS changed handler */
	DEVCB_NULL,			/* BREAK changed handler */
	DEVCB_NULL,			/* transmit handler - which channel is this for? */
	DEVCB_NULL			/* receive handler - which channel is this for? */
};

READ8_MEMBER(kaypro_state::kaypro_sio_r)
{
	if (!offset)
		return dynamic_cast<z80sio_device*>(machine().device("z80sio"))->data_read(0);
	else
	if (offset == 1)
//      return z80sio_d_r(machine().device("z80sio"), 1);
		return kay_kbd_d_r(machine());
	else
	if (offset == 2)
		return dynamic_cast<z80sio_device*>(machine().device("z80sio"))->control_read(0);
	else
//      return z80sio_c_r(machine().device("z80sio"), 1);
		return kay_kbd_c_r(machine());
}

WRITE8_MEMBER(kaypro_state::kaypro_sio_w)
{
	if (!offset)
		dynamic_cast<z80sio_device*>(machine().device("z80sio"))->data_write(0, data);
	else
	if (offset == 1)
//      z80sio_d_w(machine().device("z80sio"), 1, data);
		kay_kbd_d_w(machine(), data);
	else
	if (offset == 2)
		dynamic_cast<z80sio_device*>(machine().device("z80sio"))->control_write(0, data);
	else
		dynamic_cast<z80sio_device*>(machine().device("z80sio"))->control_write(1, data);
}


/*************************************************************************************

    Floppy DIsk

    If DRQ or IRQ is set, and cpu is halted, the NMI goes low.
    Since the HALT occurs last (and has no callback mechanism), we need to set
    a short delay, to give time for the processor to execute the HALT before NMI
    becomes active.

*************************************************************************************/

TIMER_CALLBACK_MEMBER(kaypro_state::kaypro_timer_callback)
{
	if (machine().device("maincpu")->state().state_int(Z80_HALT))
		machine().device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
}

WRITE_LINE_MEMBER( kaypro_state::kaypro_fdc_intrq_w )
{
	if (state)
		machine().scheduler().timer_set(attotime::from_usec(25), timer_expired_delegate(FUNC(kaypro_state::kaypro_timer_callback),this));
	else
		machine().device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
}

WRITE_LINE_MEMBER( kaypro_state::kaypro_fdc_drq_w )
{
	if (state)
		machine().scheduler().timer_set(attotime::from_usec(25), timer_expired_delegate(FUNC(kaypro_state::kaypro_timer_callback),this));
	else
		machine().device("maincpu")->execute().set_input_line(INPUT_LINE_NMI, CLEAR_LINE);

}

const wd17xx_interface kaypro_wd1793_interface =
{
	DEVCB_NULL,
	DEVCB_DRIVER_LINE_MEMBER(kaypro_state, kaypro_fdc_intrq_w),
	DEVCB_DRIVER_LINE_MEMBER(kaypro_state, kaypro_fdc_drq_w),
	{FLOPPY_0, FLOPPY_1, NULL, NULL}
};


/***********************************************************

    Machine

************************************************************/
MACHINE_START_MEMBER(kaypro_state,kayproii)
{
	m_pio_s->strobe_a(0);
}

MACHINE_RESET_MEMBER(kaypro_state,kayproii)
{
	MACHINE_RESET_CALL_MEMBER(kay_kbd);
}

MACHINE_RESET_MEMBER(kaypro_state,kaypro2x)
{
	address_space &space = m_maincpu->space(AS_PROGRAM);
	kaypro2x_system_port_w(space, 0, 0x80);
	MACHINE_RESET_CALL_MEMBER(kay_kbd);
}

/***********************************************************

    Quickload

    This loads a .COM file to address 0x100 then jumps
    there. Sometimes .COM has been renamed to .CPM to
    prevent windows going ballistic. These can be loaded
    as well.

************************************************************/

QUICKLOAD_LOAD( kayproii )
{
	kaypro_state *state = image.device().machine().driver_data<kaypro_state>();
	address_space &space = state->m_maincpu->space(AS_PROGRAM);
	UINT8 *RAM = state->memregion("rambank")->base();
	UINT16 i;
	UINT8 data;

	/* Load image to the TPA (Transient Program Area) */
	for (i = 0; i < quickload_size; i++)
	{
		if (image.fread( &data, 1) != 1) return IMAGE_INIT_FAIL;

		RAM[i+0x100] = data;
	}

	state->common_pio_system_w(space, 0, state->m_system_port & 0x7f);	// switch TPA in
	RAM[0x80]=0;							// clear out command tail
	RAM[0x81]=0;
	state->m_maincpu->set_pc(0x100);				// start program
	return IMAGE_INIT_PASS;
}

QUICKLOAD_LOAD( kaypro2x )
{
	kaypro_state *state = image.device().machine().driver_data<kaypro_state>();
	address_space &space = state->m_maincpu->space(AS_PROGRAM);
	UINT8 *RAM = state->memregion("rambank")->base();
	UINT16 i;
	UINT8 data;

	for (i = 0; i < quickload_size; i++)
	{
		if (image.fread( &data, 1) != 1) return IMAGE_INIT_FAIL;

		RAM[i+0x100] = data;
	}

	state->kaypro2x_system_port_w(space, 0, state->m_system_port & 0x7f);
	RAM[0x80]=0;
	RAM[0x81]=0;
	state->m_maincpu->set_pc(0x100);
	return IMAGE_INIT_PASS;
}