Previous 15994 Revisions Next

r11026 Friday 1st April, 2011 at 05:27:09 UTC by Curt Coder
[MPF1] Modernized driver.
[src/mess/drivers]mpf1.c
[src/mess/includes]mpf1.h

src/mess/includes/mpf1.h
r11025r11026
1#pragma once
2
13#ifndef __MPF1__
24#define __MPF1__
35
6#define ADDRESS_MAP_MODERN
7
8#include "emu.h"
9#include "audio/spchroms.h"
10#include "cpu/z80/z80.h"
11#include "cpu/z80/z80daisy.h"
12#include "imagedev/cassette.h"
13#include "machine/i8255a.h"
14#include "machine/z80ctc.h"
15#include "machine/z80pio.h"
16#include "machine/z80sio.h"
17#include "sound/speaker.h"
18#include "sound/tms5220.h"
19
420#define Z80_TAG         "u1"
521#define Z80CTC_TAG      "u11"
622#define Z80PIO_TAG      "u10"
r11025r11026
1329{
1430public:
1531   mpf1_state(running_machine &machine, const driver_device_config_base &config)
16      : driver_device(machine, config) { }
32      : driver_device(machine, config),
33        m_maincpu(*this, Z80_TAG),
34        m_ctc(*this, Z80CTC_TAG),
35        m_speaker(*this, SPEAKER_TAG),
36        m_cassette(*this, CASSETTE_TAG)
37   { }
1738
18   int _break;
19   int m1;
39   required_device<cpu_device> m_maincpu;
40   required_device<device_t> m_ctc;
41   required_device<device_t> m_speaker;
42   required_device<device_t> m_cassette;
43   
44   virtual void machine_start();
45   virtual void machine_reset();
2046
21   UINT8 lednum;
47   DECLARE_READ8_MEMBER( ppi_pa_r );
48   DECLARE_WRITE8_MEMBER( ppi_pb_w );
49   DECLARE_WRITE8_MEMBER( ppi_pc_w );
2250
23   emu_timer *led_refresh_timer;
51   int m_break;
52   int m_m1;
2453
54   UINT8 m_lednum;
55
56   emu_timer *m_led_refresh_timer;
57
2558   /* devices */
2659   device_t *z80ctc;
2760   device_t *speaker;
src/mess/drivers/mpf1.c
r11025r11026
2222
2323*/
2424
25#include "emu.h"
2625#include "includes/mpf1.h"
27#include "cpu/z80/z80.h"
28#include "cpu/z80/z80daisy.h"
29#include "machine/i8255a.h"
30#include "machine/z80ctc.h"
31#include "machine/z80pio.h"
32#include "machine/z80sio.h"
33#include "audio/spchroms.h"
34#include "sound/speaker.h"
35#include "sound/tms5220.h"
36#include "imagedev/cassette.h"
3726#include "mpf1.lh"
3827#include "mpf1b.lh"
3928#include "mpf1p.lh"
4029
4130/* Address Maps */
4231
43static ADDRESS_MAP_START( mpf1_map, AS_PROGRAM, 8 )
32static ADDRESS_MAP_START( mpf1_map, AS_PROGRAM, 8, mpf1_state )
4433   ADDRESS_MAP_UNMAP_HIGH
4534   AM_RANGE(0x0000, 0x0fff) AM_ROM
4635   AM_RANGE(0x1800, 0x1fff) AM_RAM
4736   AM_RANGE(0x2000, 0x2fff) AM_ROM
4837ADDRESS_MAP_END
4938
50static ADDRESS_MAP_START( mpf1b_map, AS_PROGRAM, 8 )
39static ADDRESS_MAP_START( mpf1b_map, AS_PROGRAM, 8, mpf1_state )
5140   ADDRESS_MAP_UNMAP_HIGH
5241   AM_RANGE(0x0000, 0x0fff) AM_ROM
5342   AM_RANGE(0x1800, 0x1fff) AM_RAM
r11025r11026
5544   AM_RANGE(0x5000, 0x6fff) AM_ROM
5645ADDRESS_MAP_END
5746
58static ADDRESS_MAP_START( mpf1p_map, AS_PROGRAM, 8 )
47static ADDRESS_MAP_START( mpf1p_map, AS_PROGRAM, 8, mpf1_state )
5948   AM_RANGE(0x0000, 0x1fff) AM_ROM
6049   AM_RANGE(0x6000, 0x6fff) AM_ROM
6150   AM_RANGE(0xf000, 0xffff) AM_RAM
6251ADDRESS_MAP_END
6352
64static ADDRESS_MAP_START( mpf1_io_map, AS_IO, 8 )
53static ADDRESS_MAP_START( mpf1_io_map, AS_IO, 8, mpf1_state )
6554   ADDRESS_MAP_UNMAP_HIGH
6655   ADDRESS_MAP_GLOBAL_MASK(0xff)
67   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE(I8255A_TAG, i8255a_r, i8255a_w)
68   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80CTC_TAG, z80ctc_r, z80ctc_w)
69   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80PIO_TAG, z80pio_cd_ba_r, z80pio_cd_ba_w)
56   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(I8255A_TAG, i8255a_r, i8255a_w)
57   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(Z80CTC_TAG, z80ctc_r, z80ctc_w)
58   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(Z80PIO_TAG, z80pio_cd_ba_r, z80pio_cd_ba_w)
7059ADDRESS_MAP_END
7160
72static ADDRESS_MAP_START( mpf1b_io_map, AS_IO, 8 )
61static ADDRESS_MAP_START( mpf1b_io_map, AS_IO, 8, mpf1_state )
7362   ADDRESS_MAP_UNMAP_HIGH
7463   ADDRESS_MAP_GLOBAL_MASK(0xff)
75   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE(I8255A_TAG, i8255a_r, i8255a_w)
76   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80CTC_TAG, z80ctc_r, z80ctc_w)
77   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80PIO_TAG, z80pio_cd_ba_r, z80pio_cd_ba_w)
78   AM_RANGE(0xfe, 0xfe) AM_MIRROR(0x01) AM_DEVREADWRITE(TMS5220_TAG, tms5220_status_r, tms5220_data_w)
64   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(I8255A_TAG, i8255a_r, i8255a_w)
65   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(Z80CTC_TAG, z80ctc_r, z80ctc_w)
66   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(Z80PIO_TAG, z80pio_cd_ba_r, z80pio_cd_ba_w)
67   AM_RANGE(0xfe, 0xfe) AM_MIRROR(0x01) AM_DEVREADWRITE_LEGACY(TMS5220_TAG, tms5220_status_r, tms5220_data_w)
7968ADDRESS_MAP_END
8069
81static ADDRESS_MAP_START( mpf1p_io_map, AS_IO, 8 )
70static ADDRESS_MAP_START( mpf1p_io_map, AS_IO, 8, mpf1_state )
8271   ADDRESS_MAP_UNMAP_HIGH
8372   ADDRESS_MAP_GLOBAL_MASK(0xff)
84   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE(I8255A_TAG, i8255a_r, i8255a_w)
85   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80CTC_TAG, z80ctc_r, z80ctc_w)
86   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE(Z80PIO_TAG, z80pio_cd_ba_r, z80pio_cd_ba_w)
73   AM_RANGE(0x00, 0x03) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(I8255A_TAG, i8255a_r, i8255a_w)
74   AM_RANGE(0x40, 0x43) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(Z80CTC_TAG, z80ctc_r, z80ctc_w)
75   AM_RANGE(0x80, 0x83) AM_MIRROR(0x3c) AM_DEVREADWRITE_LEGACY(Z80PIO_TAG, z80pio_cd_ba_r, z80pio_cd_ba_w)
8776ADDRESS_MAP_END
8877
8978/* Input Ports */
r11025r11026
218207{
219208   mpf1_state *state = machine.driver_data<mpf1_state>();
220209
221   if (BIT(state->lednum, 5)) output_set_digit_value(0, param);
222   if (BIT(state->lednum, 4)) output_set_digit_value(1, param);
223   if (BIT(state->lednum, 3)) output_set_digit_value(2, param);
224   if (BIT(state->lednum, 2)) output_set_digit_value(3, param);
225   if (BIT(state->lednum, 1)) output_set_digit_value(4, param);
226   if (BIT(state->lednum, 0)) output_set_digit_value(5, param);
210   if (BIT(state->m_lednum, 5)) output_set_digit_value(0, param);
211   if (BIT(state->m_lednum, 4)) output_set_digit_value(1, param);
212   if (BIT(state->m_lednum, 3)) output_set_digit_value(2, param);
213   if (BIT(state->m_lednum, 2)) output_set_digit_value(3, param);
214   if (BIT(state->m_lednum, 1)) output_set_digit_value(4, param);
215   if (BIT(state->m_lednum, 0)) output_set_digit_value(5, param);
227216}
228217
229static READ8_DEVICE_HANDLER( mpf1_porta_r )
218READ8_MEMBER( mpf1_state::ppi_pa_r )
230219{
231   mpf1_state *state = device->machine().driver_data<mpf1_state>();
232220   UINT8 data = 0x7f;
233221
234222   /* bit 0 to 5, keyboard rows 0 to 5 */
235   if (!BIT(state->lednum, 0)) data &= input_port_read(device->machine(), "PC0");
236   if (!BIT(state->lednum, 1)) data &= input_port_read(device->machine(), "PC1");
237   if (!BIT(state->lednum, 2)) data &= input_port_read(device->machine(), "PC2");
238   if (!BIT(state->lednum, 3)) data &= input_port_read(device->machine(), "PC3");
239   if (!BIT(state->lednum, 4)) data &= input_port_read(device->machine(), "PC4");
240   if (!BIT(state->lednum, 5)) data &= input_port_read(device->machine(), "PC5");
223   if (!BIT(m_lednum, 0)) data &= input_port_read(m_machine, "PC0");
224   if (!BIT(m_lednum, 1)) data &= input_port_read(m_machine, "PC1");
225   if (!BIT(m_lednum, 2)) data &= input_port_read(m_machine, "PC2");
226   if (!BIT(m_lednum, 3)) data &= input_port_read(m_machine, "PC3");
227   if (!BIT(m_lednum, 4)) data &= input_port_read(m_machine, "PC4");
228   if (!BIT(m_lednum, 5)) data &= input_port_read(m_machine, "PC5");
241229
242230   /* bit 6, user key */
243   data &= input_port_read(device->machine(), "SPECIAL") & 1 ? 0xff : 0xbf;
231   data &= input_port_read(m_machine, "SPECIAL") & 1 ? 0xff : 0xbf;
244232
245233   /* bit 7, tape input */
246   data |= (cassette_input(state->cassette) > 0 ? 1 : 0) << 7;
234   data |= (cassette_input(m_cassette) > 0 ? 1 : 0) << 7;
247235
248236   return data;
249237}
250238
251static WRITE8_DEVICE_HANDLER( mpf1_portb_w )
239WRITE8_MEMBER( mpf1_state::ppi_pb_w )
252240{
253   mpf1_state *state = device->machine().driver_data<mpf1_state>();
254
255241   /* swap bits around for the mame 7-segment emulation */
256242   UINT8 led_data = BITSWAP8(data, 6, 1, 2, 0, 7, 5, 4, 3);
257243
258244   /* timer to update segments */
259   state->led_refresh_timer->adjust(attotime::from_usec(70), led_data);
245   m_led_refresh_timer->adjust(attotime::from_usec(70), led_data);
260246}
261247
262static WRITE8_DEVICE_HANDLER( mpf1_portc_w )
248WRITE8_MEMBER( mpf1_state::ppi_pc_w )
263249{
264   mpf1_state *state = device->machine().driver_data<mpf1_state>();
265
266250   /* bits 0-5, led select and keyboard latch */
267   state->lednum = data & 0x3f;
268   state->led_refresh_timer->adjust(attotime::never);
251   m_lednum = data & 0x3f;
252   m_led_refresh_timer->adjust(attotime::never);
269253
270254   /* bit 6, monitor break control */
271   state->_break = BIT(data, 6);
255   m_break = BIT(data, 6);
272256
273   if (state->_break)
257   if (m_break)
274258   {
275      state->m1 = 0;
276      cputag_set_input_line(device->machine(), Z80_TAG, INPUT_LINE_NMI, CLEAR_LINE);
259      m_m1 = 0;
260      m_maincpu->set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
277261   }
278262
279263   /* bit 7, tape output, tone and led */
280   set_led_status(device->machine(), 0, !BIT(data, 7));
281   speaker_level_w(state->speaker, BIT(data, 7));
282   cassette_output(state->cassette, BIT(data, 7));
264   set_led_status(m_machine, 0, !BIT(data, 7));
265   speaker_level_w(m_speaker, BIT(data, 7));
266   cassette_output(m_cassette, BIT(data, 7));
283267}
284268
285269static I8255A_INTERFACE( ppi8255_intf )
286270{
287   DEVCB_HANDLER(mpf1_porta_r),
271   DEVCB_DRIVER_MEMBER(mpf1_state, ppi_pa_r),
288272   DEVCB_NULL,
289273   DEVCB_NULL,
290274   DEVCB_NULL,
291   DEVCB_HANDLER(mpf1_portb_w),
292   DEVCB_HANDLER(mpf1_portc_w),
275   DEVCB_DRIVER_MEMBER(mpf1_state, ppi_pb_w),
276   DEVCB_DRIVER_MEMBER(mpf1_state, ppi_pc_w),
293277};
294278
295279/* Z80CTC Interface */
r11025r11026
352336
353337static TIMER_DEVICE_CALLBACK( check_halt_callback )
354338{
339   mpf1_state *state = timer.machine().driver_data<mpf1_state>();
340
355341   // halt-LED; the red one, is turned on when the processor is halted
356342   // TODO: processor seems to halt, but restarts(?) at 0x0000 after a while -> fix
357   INT64 led_halt = cpu_get_reg(timer.machine().device(Z80_TAG), Z80_HALT);
343   INT64 led_halt = cpu_get_reg(state->m_maincpu, Z80_HALT);
358344   set_led_status(timer.machine(), 1, led_halt);
359345}
360346
361static MACHINE_START( mpf1 )
347void mpf1_state::machine_start()
362348{
363   mpf1_state *state = machine.driver_data<mpf1_state>();
349   m_led_refresh_timer = m_machine.scheduler().timer_alloc(FUNC(led_refresh));
364350
365   /* find devices */
366   state->speaker = machine.device(SPEAKER_TAG);
367   state->cassette = machine.device(CASSETTE_TAG);
368
369   state->led_refresh_timer = machine.scheduler().timer_alloc(FUNC(led_refresh));
370
371351   /* register for state saving */
372   state->save_item(NAME(state->_break));
373   state->save_item(NAME(state->m1));
374   state->save_item(NAME(state->lednum));
352   save_item(NAME(m_break));
353   save_item(NAME(m_m1));
354   save_item(NAME(m_lednum));
375355}
376356
377static MACHINE_RESET( mpf1 )
357void mpf1_state::machine_reset()
378358{
379   mpf1_state *state = machine.driver_data<mpf1_state>();
380
381   state->lednum = 0;
359   m_lednum = 0;
382360}
383361
384362/* Machine Drivers */
r11025r11026
391369   MCFG_CPU_IO_MAP(mpf1_io_map)
392370   MCFG_CPU_CONFIG(mpf1_daisy_chain)
393371
394   MCFG_MACHINE_START(mpf1)
395   MCFG_MACHINE_RESET(mpf1)
396
397372   /* devices */
398373   MCFG_Z80PIO_ADD(Z80PIO_TAG, XTAL_3_579545MHz/2, mpf1_pio_intf)
399374   MCFG_Z80CTC_ADD(Z80CTC_TAG, XTAL_3_579545MHz/2, mpf1_ctc_intf)
r11025r11026
412387MACHINE_CONFIG_END
413388
414389static MACHINE_CONFIG_START( mpf1b, mpf1_state )
415
416390   /* basic machine hardware */
417391   MCFG_CPU_ADD(Z80_TAG, Z80, XTAL_3_579545MHz/2)
418392   MCFG_CPU_PROGRAM_MAP(mpf1b_map)
419393   MCFG_CPU_IO_MAP(mpf1b_io_map)
420394   MCFG_CPU_CONFIG(mpf1_daisy_chain)
421395
422   MCFG_MACHINE_START(mpf1)
423   MCFG_MACHINE_RESET(mpf1)
424
425396   /* devices */
426397   MCFG_Z80PIO_ADD(Z80PIO_TAG, XTAL_3_579545MHz/2, mpf1_pio_intf)
427398   MCFG_Z80CTC_ADD(Z80CTC_TAG, XTAL_3_579545MHz/2, mpf1_ctc_intf)
r11025r11026
444415MACHINE_CONFIG_END
445416
446417static MACHINE_CONFIG_START( mpf1p, mpf1_state )
447
448418   /* basic machine hardware */
449419   MCFG_CPU_ADD(Z80_TAG, Z80, 2500000)
450420   MCFG_CPU_PROGRAM_MAP(mpf1p_map)
451421   MCFG_CPU_IO_MAP(mpf1p_io_map)
452422   MCFG_CPU_CONFIG(mpf1_daisy_chain)
453423
454   MCFG_MACHINE_START(mpf1)
455   MCFG_MACHINE_RESET(mpf1)
456
457424   /* video hardware */
458425   MCFG_DEFAULT_LAYOUT(layout_mpf1p)
459426
r11025r11026
498465{
499466   mpf1_state *state = machine->driver_data<mpf1_state>();
500467
501   if (!state->_break)
468   if (!state->m_break)
502469   {
503      state->m1++;
470      state->m_m1++;
504471
505      if (state->m1 == 5)
472      if (state->m_m1 == 5)
506473      {
507         cputag_set_input_line(*machine, Z80_TAG, INPUT_LINE_NMI, ASSERT_LINE);
474         state->m_maincpu->set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
508475      }
509476   }
510477
r11025r11026
513480
514481static DRIVER_INIT( mpf1 )
515482{
516   machine.device(Z80_TAG)->memory().space(AS_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(mpf1_direct_update_handler, machine));
483   mpf1_state *state = machine.driver_data<mpf1_state>();
484
485   state->m_maincpu->memory().space(AS_PROGRAM)->set_direct_update_handler(direct_update_delegate_create_static(mpf1_direct_update_handler, machine));
517486}
518487
519488COMP( 1979, mpf1,  0,    0, mpf1, mpf1,  mpf1, "Multitech", "Micro Professor 1", 0)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team