src/mess/drivers/mpf1.c
| r11025 | r11026 | |
| 22 | 22 | |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | | #include "emu.h" |
| 26 | 25 | #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" |
| 37 | 26 | #include "mpf1.lh" |
| 38 | 27 | #include "mpf1b.lh" |
| 39 | 28 | #include "mpf1p.lh" |
| 40 | 29 | |
| 41 | 30 | /* Address Maps */ |
| 42 | 31 | |
| 43 | | static ADDRESS_MAP_START( mpf1_map, AS_PROGRAM, 8 ) |
| 32 | static ADDRESS_MAP_START( mpf1_map, AS_PROGRAM, 8, mpf1_state ) |
| 44 | 33 | ADDRESS_MAP_UNMAP_HIGH |
| 45 | 34 | AM_RANGE(0x0000, 0x0fff) AM_ROM |
| 46 | 35 | AM_RANGE(0x1800, 0x1fff) AM_RAM |
| 47 | 36 | AM_RANGE(0x2000, 0x2fff) AM_ROM |
| 48 | 37 | ADDRESS_MAP_END |
| 49 | 38 | |
| 50 | | static ADDRESS_MAP_START( mpf1b_map, AS_PROGRAM, 8 ) |
| 39 | static ADDRESS_MAP_START( mpf1b_map, AS_PROGRAM, 8, mpf1_state ) |
| 51 | 40 | ADDRESS_MAP_UNMAP_HIGH |
| 52 | 41 | AM_RANGE(0x0000, 0x0fff) AM_ROM |
| 53 | 42 | AM_RANGE(0x1800, 0x1fff) AM_RAM |
| r11025 | r11026 | |
| 55 | 44 | AM_RANGE(0x5000, 0x6fff) AM_ROM |
| 56 | 45 | ADDRESS_MAP_END |
| 57 | 46 | |
| 58 | | static ADDRESS_MAP_START( mpf1p_map, AS_PROGRAM, 8 ) |
| 47 | static ADDRESS_MAP_START( mpf1p_map, AS_PROGRAM, 8, mpf1_state ) |
| 59 | 48 | AM_RANGE(0x0000, 0x1fff) AM_ROM |
| 60 | 49 | AM_RANGE(0x6000, 0x6fff) AM_ROM |
| 61 | 50 | AM_RANGE(0xf000, 0xffff) AM_RAM |
| 62 | 51 | ADDRESS_MAP_END |
| 63 | 52 | |
| 64 | | static ADDRESS_MAP_START( mpf1_io_map, AS_IO, 8 ) |
| 53 | static ADDRESS_MAP_START( mpf1_io_map, AS_IO, 8, mpf1_state ) |
| 65 | 54 | ADDRESS_MAP_UNMAP_HIGH |
| 66 | 55 | 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) |
| 70 | 59 | ADDRESS_MAP_END |
| 71 | 60 | |
| 72 | | static ADDRESS_MAP_START( mpf1b_io_map, AS_IO, 8 ) |
| 61 | static ADDRESS_MAP_START( mpf1b_io_map, AS_IO, 8, mpf1_state ) |
| 73 | 62 | ADDRESS_MAP_UNMAP_HIGH |
| 74 | 63 | 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) |
| 79 | 68 | ADDRESS_MAP_END |
| 80 | 69 | |
| 81 | | static ADDRESS_MAP_START( mpf1p_io_map, AS_IO, 8 ) |
| 70 | static ADDRESS_MAP_START( mpf1p_io_map, AS_IO, 8, mpf1_state ) |
| 82 | 71 | ADDRESS_MAP_UNMAP_HIGH |
| 83 | 72 | 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) |
| 87 | 76 | ADDRESS_MAP_END |
| 88 | 77 | |
| 89 | 78 | /* Input Ports */ |
| r11025 | r11026 | |
| 218 | 207 | { |
| 219 | 208 | mpf1_state *state = machine.driver_data<mpf1_state>(); |
| 220 | 209 | |
| 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); |
| 227 | 216 | } |
| 228 | 217 | |
| 229 | | static READ8_DEVICE_HANDLER( mpf1_porta_r ) |
| 218 | READ8_MEMBER( mpf1_state::ppi_pa_r ) |
| 230 | 219 | { |
| 231 | | mpf1_state *state = device->machine().driver_data<mpf1_state>(); |
| 232 | 220 | UINT8 data = 0x7f; |
| 233 | 221 | |
| 234 | 222 | /* 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"); |
| 241 | 229 | |
| 242 | 230 | /* 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; |
| 244 | 232 | |
| 245 | 233 | /* bit 7, tape input */ |
| 246 | | data |= (cassette_input(state->cassette) > 0 ? 1 : 0) << 7; |
| 234 | data |= (cassette_input(m_cassette) > 0 ? 1 : 0) << 7; |
| 247 | 235 | |
| 248 | 236 | return data; |
| 249 | 237 | } |
| 250 | 238 | |
| 251 | | static WRITE8_DEVICE_HANDLER( mpf1_portb_w ) |
| 239 | WRITE8_MEMBER( mpf1_state::ppi_pb_w ) |
| 252 | 240 | { |
| 253 | | mpf1_state *state = device->machine().driver_data<mpf1_state>(); |
| 254 | | |
| 255 | 241 | /* swap bits around for the mame 7-segment emulation */ |
| 256 | 242 | UINT8 led_data = BITSWAP8(data, 6, 1, 2, 0, 7, 5, 4, 3); |
| 257 | 243 | |
| 258 | 244 | /* 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); |
| 260 | 246 | } |
| 261 | 247 | |
| 262 | | static WRITE8_DEVICE_HANDLER( mpf1_portc_w ) |
| 248 | WRITE8_MEMBER( mpf1_state::ppi_pc_w ) |
| 263 | 249 | { |
| 264 | | mpf1_state *state = device->machine().driver_data<mpf1_state>(); |
| 265 | | |
| 266 | 250 | /* 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); |
| 269 | 253 | |
| 270 | 254 | /* bit 6, monitor break control */ |
| 271 | | state->_break = BIT(data, 6); |
| 255 | m_break = BIT(data, 6); |
| 272 | 256 | |
| 273 | | if (state->_break) |
| 257 | if (m_break) |
| 274 | 258 | { |
| 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); |
| 277 | 261 | } |
| 278 | 262 | |
| 279 | 263 | /* 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)); |
| 283 | 267 | } |
| 284 | 268 | |
| 285 | 269 | static I8255A_INTERFACE( ppi8255_intf ) |
| 286 | 270 | { |
| 287 | | DEVCB_HANDLER(mpf1_porta_r), |
| 271 | DEVCB_DRIVER_MEMBER(mpf1_state, ppi_pa_r), |
| 288 | 272 | DEVCB_NULL, |
| 289 | 273 | DEVCB_NULL, |
| 290 | 274 | 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), |
| 293 | 277 | }; |
| 294 | 278 | |
| 295 | 279 | /* Z80CTC Interface */ |
| r11025 | r11026 | |
| 352 | 336 | |
| 353 | 337 | static TIMER_DEVICE_CALLBACK( check_halt_callback ) |
| 354 | 338 | { |
| 339 | mpf1_state *state = timer.machine().driver_data<mpf1_state>(); |
| 340 | |
| 355 | 341 | // halt-LED; the red one, is turned on when the processor is halted |
| 356 | 342 | // 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); |
| 358 | 344 | set_led_status(timer.machine(), 1, led_halt); |
| 359 | 345 | } |
| 360 | 346 | |
| 361 | | static MACHINE_START( mpf1 ) |
| 347 | void mpf1_state::machine_start() |
| 362 | 348 | { |
| 363 | | mpf1_state *state = machine.driver_data<mpf1_state>(); |
| 349 | m_led_refresh_timer = m_machine.scheduler().timer_alloc(FUNC(led_refresh)); |
| 364 | 350 | |
| 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 | | |
| 371 | 351 | /* 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)); |
| 375 | 355 | } |
| 376 | 356 | |
| 377 | | static MACHINE_RESET( mpf1 ) |
| 357 | void mpf1_state::machine_reset() |
| 378 | 358 | { |
| 379 | | mpf1_state *state = machine.driver_data<mpf1_state>(); |
| 380 | | |
| 381 | | state->lednum = 0; |
| 359 | m_lednum = 0; |
| 382 | 360 | } |
| 383 | 361 | |
| 384 | 362 | /* Machine Drivers */ |
| r11025 | r11026 | |
| 391 | 369 | MCFG_CPU_IO_MAP(mpf1_io_map) |
| 392 | 370 | MCFG_CPU_CONFIG(mpf1_daisy_chain) |
| 393 | 371 | |
| 394 | | MCFG_MACHINE_START(mpf1) |
| 395 | | MCFG_MACHINE_RESET(mpf1) |
| 396 | | |
| 397 | 372 | /* devices */ |
| 398 | 373 | MCFG_Z80PIO_ADD(Z80PIO_TAG, XTAL_3_579545MHz/2, mpf1_pio_intf) |
| 399 | 374 | MCFG_Z80CTC_ADD(Z80CTC_TAG, XTAL_3_579545MHz/2, mpf1_ctc_intf) |
| r11025 | r11026 | |
| 412 | 387 | MACHINE_CONFIG_END |
| 413 | 388 | |
| 414 | 389 | static MACHINE_CONFIG_START( mpf1b, mpf1_state ) |
| 415 | | |
| 416 | 390 | /* basic machine hardware */ |
| 417 | 391 | MCFG_CPU_ADD(Z80_TAG, Z80, XTAL_3_579545MHz/2) |
| 418 | 392 | MCFG_CPU_PROGRAM_MAP(mpf1b_map) |
| 419 | 393 | MCFG_CPU_IO_MAP(mpf1b_io_map) |
| 420 | 394 | MCFG_CPU_CONFIG(mpf1_daisy_chain) |
| 421 | 395 | |
| 422 | | MCFG_MACHINE_START(mpf1) |
| 423 | | MCFG_MACHINE_RESET(mpf1) |
| 424 | | |
| 425 | 396 | /* devices */ |
| 426 | 397 | MCFG_Z80PIO_ADD(Z80PIO_TAG, XTAL_3_579545MHz/2, mpf1_pio_intf) |
| 427 | 398 | MCFG_Z80CTC_ADD(Z80CTC_TAG, XTAL_3_579545MHz/2, mpf1_ctc_intf) |
| r11025 | r11026 | |
| 444 | 415 | MACHINE_CONFIG_END |
| 445 | 416 | |
| 446 | 417 | static MACHINE_CONFIG_START( mpf1p, mpf1_state ) |
| 447 | | |
| 448 | 418 | /* basic machine hardware */ |
| 449 | 419 | MCFG_CPU_ADD(Z80_TAG, Z80, 2500000) |
| 450 | 420 | MCFG_CPU_PROGRAM_MAP(mpf1p_map) |
| 451 | 421 | MCFG_CPU_IO_MAP(mpf1p_io_map) |
| 452 | 422 | MCFG_CPU_CONFIG(mpf1_daisy_chain) |
| 453 | 423 | |
| 454 | | MCFG_MACHINE_START(mpf1) |
| 455 | | MCFG_MACHINE_RESET(mpf1) |
| 456 | | |
| 457 | 424 | /* video hardware */ |
| 458 | 425 | MCFG_DEFAULT_LAYOUT(layout_mpf1p) |
| 459 | 426 | |
| r11025 | r11026 | |
| 498 | 465 | { |
| 499 | 466 | mpf1_state *state = machine->driver_data<mpf1_state>(); |
| 500 | 467 | |
| 501 | | if (!state->_break) |
| 468 | if (!state->m_break) |
| 502 | 469 | { |
| 503 | | state->m1++; |
| 470 | state->m_m1++; |
| 504 | 471 | |
| 505 | | if (state->m1 == 5) |
| 472 | if (state->m_m1 == 5) |
| 506 | 473 | { |
| 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); |
| 508 | 475 | } |
| 509 | 476 | } |
| 510 | 477 | |
| r11025 | r11026 | |
| 513 | 480 | |
| 514 | 481 | static DRIVER_INIT( mpf1 ) |
| 515 | 482 | { |
| 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)); |
| 517 | 486 | } |
| 518 | 487 | |
| 519 | 488 | COMP( 1979, mpf1, 0, 0, mpf1, mpf1, mpf1, "Multitech", "Micro Professor 1", 0) |