Previous 15994 Revisions Next

r6529 Friday 4th December, 2009 at 18:04:16 UTC by Curt Coder
[MPF1] Converted to use driver state.
[src/mess/drivers]mpf1.c
[src/mess/includes]mpf1.h*

src/mess/includes/mpf1.h
r0r6529
1#ifndef __MPF1__
2#define __MPF1__
3 
4#define Z80_TAG         "u1"
5#define Z80CTC_TAG      "u11"
6#define Z80PIO_TAG      "u10"
7#define I8255A_TAG      "u14"
8#define CASSETTE_TAG   "cassette"
9#define SPEAKER_TAG      "speaker"
10 
11typedef struct _mpf1_state mpf1_state;
12struct _mpf1_state
13{
14   UINT8 lednum;
15 
16   emu_timer *led_refresh_timer;
17 
18   /* devices */
19   const device_config *z80ctc;
20   const device_config *speaker;
21   const device_config *cassette;
22};
23 
24#endif
src/mess/drivers/mpf1.c
r6528r6529
2626*/
2727
2828#include "driver.h"
29#include "includes/mpf1.h"
2930#include "cpu/z80/z80.h"
31#include "cpu/z80/z80daisy.h"
3032#include "machine/i8255a.h"
3133#include "machine/z80ctc.h"
3234#include "machine/z80pio.h"
r6528r6529
3537#include "devices/cassette.h"
3638#include "mpf1.lh"
3739
40/* Address Maps */
3841
39/***************************************************************************
40    GLOBAL VARIABLES
41***************************************************************************/
42
43static emu_timer *led_refresh_timer;
44static UINT8 lednum;
45
46
47/***************************************************************************
48    ADDRESS MAPS
49***************************************************************************/
50
5142static ADDRESS_MAP_START( mpf1_map, ADDRESS_SPACE_PROGRAM, 8 )
5243   AM_RANGE(0x0000, 0x0fff) AM_ROM
53   AM_RANGE(0x1000, 0x1fff) AM_RAM
44   AM_RANGE(0x1800, 0x1fff) AM_RAM
5445   AM_RANGE(0x2000, 0x2fff) AM_ROM
5546ADDRESS_MAP_END
5647
r6528r6529
6152
6253static ADDRESS_MAP_START( mpf1_io_map, ADDRESS_SPACE_IO, 8 )
6354   ADDRESS_MAP_GLOBAL_MASK(0xff)
64   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE("ppi8255", i8255a_r, i8255a_w)
65   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE("z80ctc", z80ctc_r, z80ctc_w)
66   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE("z80pio", z80pio_r, z80pio_w)
55   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE(I8255A_TAG, i8255a_r, i8255a_w)
56   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80CTC_TAG, z80ctc_r, z80ctc_w)
57   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80PIO_TAG, z80pio_r, z80pio_w)
6758ADDRESS_MAP_END
6859
60/* Input Ports */
6961
70/***************************************************************************
71    INPUT PORTS
72***************************************************************************/
73
7462static INPUT_PORTS_START( mpf1 )
7563   PORT_START("row_0")
7664   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("3 HL") PORT_CODE(KEYCODE_3)
r6528r6529
193181   PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("INTR") PORT_CODE(KEYCODE_I)   // causes INT
194182INPUT_PORTS_END
195183
184/* Intel 8255A Interface */
196185
197/***************************************************************************
198    Z80 PIO
199***************************************************************************/
200
201static void mpf1_pio_interrupt(const device_config *device, int state)
186static TIMER_CALLBACK( led_refresh )
202187{
203   logerror("pio irq state: %02x\n",state);
188   mpf1_state *state = machine->driver_data;
189
190   if (BIT(state->lednum, 5)) output_set_digit_value(0, param);
191   if (BIT(state->lednum, 4)) output_set_digit_value(1, param);
192   if (BIT(state->lednum, 3)) output_set_digit_value(2, param);
193   if (BIT(state->lednum, 2)) output_set_digit_value(3, param);
194   if (BIT(state->lednum, 1)) output_set_digit_value(4, param);
195   if (BIT(state->lednum, 0)) output_set_digit_value(5, param);
204196}
205197
206
207/***************************************************************************
208    8255 PPI
209***************************************************************************/
210
211198static READ8_DEVICE_HANDLER( mpf1_porta_r )
212199{
213   const device_config *cassette = devtag_get_device(device->machine, "cassette");
214   UINT8 result = 0x7f;
200   mpf1_state *state = device->machine->driver_data;
201   UINT8 data = 0x7f;
215202
216203   /* bit 0 to 5, keyboard rows 0 to 5 */
217   if (!BIT(lednum, 0)) result &= input_port_read(device->machine, "row_0");
218   if (!BIT(lednum, 1)) result &= input_port_read(device->machine, "row_1");
219   if (!BIT(lednum, 2)) result &= input_port_read(device->machine, "row_2");
220   if (!BIT(lednum, 3)) result &= input_port_read(device->machine, "row_3");
221   if (!BIT(lednum, 4)) result &= input_port_read(device->machine, "row_4");
222   if (!BIT(lednum, 5)) result &= input_port_read(device->machine, "row_5");
204   if (!BIT(state->lednum, 0)) data &= input_port_read(device->machine, "row_0");
205   if (!BIT(state->lednum, 1)) data &= input_port_read(device->machine, "row_1");
206   if (!BIT(state->lednum, 2)) data &= input_port_read(device->machine, "row_2");
207   if (!BIT(state->lednum, 3)) data &= input_port_read(device->machine, "row_3");
208   if (!BIT(state->lednum, 4)) data &= input_port_read(device->machine, "row_4");
209   if (!BIT(state->lednum, 5)) data &= input_port_read(device->machine, "row_5");
223210
224211   /* bit 6, user key */
225   result &= input_port_read(device->machine, "user");
212   data &= input_port_read(device->machine, "user");
226213
227214   /* bit 7, tape input */
228   result |= (cassette_input(cassette) > 0 ? 1 : 0) << 7;
215   data |= (cassette_input(state->cassette) > 0 ? 1 : 0) << 7;
229216
230   return result;
217   return data;
231218}
232219
233static TIMER_CALLBACK( led_refresh )
234{
235   if (BIT(lednum, 5)) output_set_digit_value(0, param);
236   if (BIT(lednum, 4)) output_set_digit_value(1, param);
237   if (BIT(lednum, 3)) output_set_digit_value(2, param);
238   if (BIT(lednum, 2)) output_set_digit_value(3, param);
239   if (BIT(lednum, 1)) output_set_digit_value(4, param);
240   if (BIT(lednum, 0)) output_set_digit_value(5, param);
241}
242
243220static WRITE8_DEVICE_HANDLER( mpf1_portb_w )
244221{
222   mpf1_state *state = device->machine->driver_data;
223
245224   /* swap bits around for the mame 7-segment emulation */
246225   UINT8 led_data = BITSWAP8(data, 6, 1, 2, 0, 7, 5, 4, 3);
247226
248227   /* timer to update segments */
249   timer_adjust_oneshot(led_refresh_timer, ATTOTIME_IN_USEC(70), led_data);
228   timer_adjust_oneshot(state->led_refresh_timer, ATTOTIME_IN_USEC(70), led_data);
250229}
251230
252231static WRITE8_DEVICE_HANDLER( mpf1_portc_w )
253232{
254   const device_config *speaker = devtag_get_device(device->machine, "speaker");
255   const device_config *cassette = devtag_get_device(device->machine, "cassette");
233   mpf1_state *state = device->machine->driver_data;
256234
257235   /* bits 0-5, led select and keyboard latch */
258   lednum = data & 0x3f;
259   timer_adjust_oneshot(led_refresh_timer, attotime_never, 0);
236   state->lednum = data & 0x3f;
237   timer_adjust_oneshot(state->led_refresh_timer, attotime_never, 0);
260238
261239   /* bit 6, monitor break control */
262240
263241   /* bit 7, tape output, tone and led */
264242   set_led_status(device->machine, 0, !BIT(data, 7));
265   speaker_level_w(speaker, BIT(data, 7));
266   cassette_output(cassette, BIT(data, 7));
243   speaker_level_w(state->speaker, BIT(data, 7));
244   cassette_output(state->cassette, BIT(data, 7));
267245}
268246
247static I8255A_INTERFACE( ppi8255_intf )
248{
249   DEVCB_HANDLER(mpf1_porta_r),
250   DEVCB_NULL,
251   DEVCB_NULL,
252   DEVCB_NULL,
253   DEVCB_HANDLER(mpf1_portb_w),
254   DEVCB_HANDLER(mpf1_portc_w),
255};
269256
270/***************************************************************************
271    MACHINE INITIALIZATION
272***************************************************************************/
257/* Z80CTC Interface */
273258
259static Z80CTC_INTERFACE( mpf1_ctc_intf )
260{
261   0,
262   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),
263   DEVCB_NULL,
264   DEVCB_NULL,
265   DEVCB_NULL
266};
267
268/* Z80PIO Interface */
269
270static const z80pio_interface mpf1_pio_intf =
271{
272   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),
273   DEVCB_NULL,
274   DEVCB_NULL,
275   DEVCB_NULL,
276   DEVCB_NULL,
277   DEVCB_NULL,
278   DEVCB_NULL
279};
280
281/* Machine Initialization */
282
274283static TIMER_CALLBACK( check_halt_callback )
275284{
276285   // halt-LED; the red one, is turned on when the processor is halted
277286   // TODO: processor seems to halt, but restarts(?) at 0x0000 after a while -> fix
278   INT64 led_halt = devtag_get_info_int(machine, "maincpu", CPUINFO_INT_REGISTER + Z80_HALT);
287   INT64 led_halt = devtag_get_info_int(machine, Z80_TAG, CPUINFO_INT_REGISTER + Z80_HALT);
279288   set_led_status(machine, 1, led_halt);
280289}
281290
282291static TIMER_CALLBACK( irq0_callback )
283292{
284   irq0_line_hold( cputag_get_cpu(machine, "maincpu") );
293   irq0_line_hold( cputag_get_cpu(machine, Z80_TAG) );
285294}
286295
287296static MACHINE_START( mpf1 )
288297{
289   led_refresh_timer = timer_alloc(machine, led_refresh, 0);
298   mpf1_state *state = machine->driver_data;
299
300   /* find devices */
301   state->speaker = devtag_get_device(machine, SPEAKER_TAG);
302   state->cassette = devtag_get_device(machine, CASSETTE_TAG);
303
304   state->led_refresh_timer = timer_alloc(machine, led_refresh, 0);
305
306   /* register for state saving */
307   state_save_register_global(machine, state->lednum);
290308}
291309
292310static MACHINE_RESET( mpf1 )
293311{
294   lednum = 0;
312   mpf1_state *state = machine->driver_data;
295313
314   state->lednum = 0;
315
296316   timer_pulse(machine,  ATTOTIME_IN_HZ(1), NULL, 0, check_halt_callback );
297317   timer_pulse(machine,  ATTOTIME_IN_HZ(60), NULL, 0, irq0_callback );
298318}
299319
300
301/***************************************************************************
302    MACHINE DRIVERS
303***************************************************************************/
304
305320static const cassette_config mpf1_cassette_config =
306321{
307322   cassette_default_formats,
r6528r6529
309324   CASSETTE_STOPPED | CASSETTE_SPEAKER_ENABLED | CASSETTE_MOTOR_ENABLED
310325};
311326
312static I8255A_INTERFACE( ppi8255_intf )
327static const z80_daisy_chain mpf1_daisy_chain[] =
313328{
314   DEVCB_HANDLER(mpf1_porta_r),
315   DEVCB_NULL,
316   DEVCB_NULL,
317   DEVCB_NULL,
318   DEVCB_HANDLER(mpf1_portb_w),
319   DEVCB_HANDLER(mpf1_portc_w),
329   { Z80CTC_TAG },
330   { Z80PIO_TAG },
331   { NULL }
320332};
321333
322static Z80CTC_INTERFACE( mpf1_ctc_intf )
323{
324   0,
325   DEVCB_NULL,
326   DEVCB_NULL,
327   DEVCB_NULL,
328   DEVCB_NULL
329};
334/* Machine Drivers */
330335
331static const z80pio_interface mpf1_pio_intf =
332{
333   DEVCB_LINE(mpf1_pio_interrupt),
334   DEVCB_NULL,
335   DEVCB_NULL,
336   DEVCB_NULL,
337   DEVCB_NULL,
338   DEVCB_NULL,
339   DEVCB_NULL
340};
341
342336static MACHINE_DRIVER_START( mpf1 )
337   MDRV_DRIVER_DATA(mpf1_state)
338
343339   /* basic machine hardware */
344   MDRV_CPU_ADD("maincpu", Z80, XTAL_3_579545MHz / 2)
340   MDRV_CPU_ADD(Z80_TAG, Z80, XTAL_3_579545MHz/2)
345341   MDRV_CPU_PROGRAM_MAP(mpf1_map)
346342   MDRV_CPU_IO_MAP(mpf1_io_map)
343   MDRV_CPU_CONFIG(mpf1_daisy_chain)
347344
348   MDRV_MACHINE_START( mpf1 )
349   MDRV_MACHINE_RESET( mpf1 )
345   MDRV_MACHINE_START(mpf1)
346   MDRV_MACHINE_RESET(mpf1)
350347
351348   /* video hardware */
352349   MDRV_DEFAULT_LAYOUT(layout_mpf1)
353350
354351   /* sound hardware */
355352   MDRV_SPEAKER_STANDARD_MONO("mono")
356   MDRV_SOUND_ADD("speaker", SPEAKER, 0)
357   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
353   MDRV_SOUND_ADD(SPEAKER_TAG, SPEAKER, 0)
354   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
358355
359356   /* internal devices */
360   MDRV_Z80PIO_ADD("z80pio", mpf1_pio_intf)
361   MDRV_Z80CTC_ADD("z80ctc", XTAL_3_579545MHz / 2, mpf1_ctc_intf)
362   MDRV_I8255A_ADD("ppi8255", ppi8255_intf)
357   MDRV_Z80PIO_ADD(Z80PIO_TAG, mpf1_pio_intf)
358   MDRV_Z80CTC_ADD(Z80CTC_TAG, XTAL_3_579545MHz/2, mpf1_ctc_intf)
359   MDRV_I8255A_ADD(I8255A_TAG, ppi8255_intf)
363360
364   MDRV_CASSETTE_ADD("cassette", mpf1_cassette_config)
361   MDRV_CASSETTE_ADD(CASSETTE_TAG, mpf1_cassette_config)
365362MACHINE_DRIVER_END
366363
367364static MACHINE_DRIVER_START( mpf1p )
365   MDRV_DRIVER_DATA(mpf1_state)
366
368367   /* basic machine hardware */
369   MDRV_CPU_ADD("maincpu", Z80, 2500000)
368   MDRV_CPU_ADD(Z80_TAG, Z80, 2500000)
370369   MDRV_CPU_PROGRAM_MAP(mpf1p_map)
371370   MDRV_CPU_IO_MAP(mpf1_io_map)
371   MDRV_CPU_CONFIG(mpf1_daisy_chain)
372372
373   MDRV_MACHINE_START( mpf1 )
374   MDRV_MACHINE_RESET( mpf1 )
373   MDRV_MACHINE_START(mpf1)
374   MDRV_MACHINE_RESET(mpf1)
375375
376376   /* video hardware */
377377   MDRV_DEFAULT_LAYOUT(layout_mpf1)
378378
379379   /* internal devices */
380   MDRV_Z80PIO_ADD("z80pio", mpf1_pio_intf)
381   MDRV_Z80CTC_ADD("z80ctc", 3579500/2, mpf1_ctc_intf)
382   MDRV_I8255A_ADD("ppi8255", ppi8255_intf)
380   MDRV_Z80PIO_ADD(Z80PIO_TAG, mpf1_pio_intf)
381   MDRV_Z80CTC_ADD(Z80CTC_TAG, 3579500/2, mpf1_ctc_intf)
382   MDRV_I8255A_ADD(I8255A_TAG, ppi8255_intf)
383383
384384   /* sound hardware */
385385   MDRV_SPEAKER_STANDARD_MONO("mono")
386   MDRV_SOUND_ADD("speaker", SPEAKER, 0)
387   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
386   MDRV_SOUND_ADD(SPEAKER_TAG, SPEAKER, 0)
387   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25)
388388
389   MDRV_CASSETTE_ADD("cassette", mpf1_cassette_config)
389   MDRV_CASSETTE_ADD(CASSETTE_TAG, mpf1_cassette_config)
390390MACHINE_DRIVER_END
391391
392/* ROMs */
392393
393/***************************************************************************
394    ROM DEFINITIONS
395***************************************************************************/
396
397394ROM_START( mpf1 )
398    ROM_REGION(0x10000, "maincpu", 0)
395    ROM_REGION(0x10000, Z80_TAG, 0)
399396    ROM_LOAD("mpf.u6", 0x0000, 0x1000, CRC(b60249ce) SHA1(78e0e8874d1497fabfdd6378266d041175e3797f))
400397ROM_END
401398
402399ROM_START( mpf1b )
403    ROM_REGION(0x10000, "maincpu", 0)
400    ROM_REGION(0x10000, Z80_TAG, 0)
404401    ROM_LOAD("c55167.u6", 0x0000, 0x1000, CRC(28b06dac) SHA1(99cfbab739d71a914c39302d384d77bddc4b705b))
405402    ROM_LOAD("basic.u7", 0x2000, 0x1000, CRC(d276ed6b) SHA1(a45fb98961be5e5396988498c6ed589a35398dcf))
406403ROM_END
407404
408405ROM_START( mpf1p )
409    ROM_REGION(0x10000, "maincpu", 0)
406    ROM_REGION(0x10000, Z80_TAG, 0)
410407   ROM_LOAD("mpf1pmon.bin", 0x0000, 0x2000, CRC(91ace7d3) SHA1(22e3c16a81ac09f37741ad1b526a4456b2ba9493))
411408ROM_END
412409
410/* System Drivers */
413411
414/***************************************************************************
415    GAME DRIVERS
416***************************************************************************/
417
418412COMP( 1979, mpf1,  0,    0, mpf1, mpf1,  0, 0, "Multitech", "Micro Professor 1", 0)
419413COMP( 1979, mpf1b, mpf1, 0, mpf1, mpf1b, 0, 0, "Multitech", "Micro Professor 1B", 0)
420414COMP( 1982, mpf1p, mpf1, 0, mpf1p,mpf1b, 0, 0, "Multitech", "Micro Professor 1 Plus", GAME_NOT_WORKING)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team