trunk/src/emu/cpu/nec/v53.c
| r244870 | r244871 | |
| 3 | 3 | // V33 / V33A cores with onboard peripherals |
| 4 | 4 | |
| 5 | 5 | // Interrupt Controller is uPD71059 equivalent (a PIC8259 clone?) |
| 6 | | // DMA Controller can operate in modes providing a subset of the uPD71071 or uPD71037 functionality (some modes unavailable / settings ignored) (uPD71071 mode is an extended am9517a, uPD71037 mode is ??) |
| 6 | // DMA Controller can operate in modes providing a subset of the uPD71071 or uPD71037 functionality (some modes unavailable / settings ignored) (uPD71071 mode is an extended 8237A, uPD71037 mode is plain 8237A) |
| 7 | 7 | // Serial Controller is based on the uPD71051 but with some changes (i8251 clone?) |
| 8 | 8 | // Timer Unit is functionally identical to uPD71054 (which in turn is said to be the same as a pit8253) |
| 9 | 9 | |
| r244870 | r244871 | |
| 216 | 216 | } |
| 217 | 217 | else // uPD71071 mode |
| 218 | 218 | { |
| 219 | | space(AS_IO).install_readwrite_handler(base+0x00, base+0x0f, read8_delegate(FUNC(upd71071_v53_device::read), (upd71071_v53_device*)m_dma_71071mode), write8_delegate(FUNC(upd71071_v53_device::write), (upd71071_v53_device*)m_dma_71071mode), 0xffff); |
| 219 | space(AS_IO).install_readwrite_handler(base+0x00, base+0x0f, read8_delegate(FUNC(upd71071_v53_device::read), (upd71071_v53_device*)m_v53dmau), write8_delegate(FUNC(upd71071_v53_device::write), (upd71071_v53_device*)m_v53dmau), 0xffff); |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| r244870 | r244871 | |
| 231 | 231 | } |
| 232 | 232 | else |
| 233 | 233 | { |
| 234 | | space(AS_IO).install_readwrite_handler(base+0x00, base+0x01, read8_delegate(FUNC(v53_base_device::icu_0_r), this), write8_delegate(FUNC(v53_base_device::icu_0_w), this), 0x00ff); |
| 235 | | space(AS_IO).install_readwrite_handler(base+0x02, base+0x03, read8_delegate(FUNC(v53_base_device::icu_1_r), this), write8_delegate(FUNC(v53_base_device::icu_1_w), this), 0x00ff); |
| 236 | | |
| 234 | space(AS_IO).install_readwrite_handler(base+0x00, base+0x03, read8_delegate(FUNC(pic8259_device::read), (pic8259_device*)m_v53icu), write8_delegate(FUNC(pic8259_device::write), (pic8259_device*)m_v53icu), 0x00ff); |
| 237 | 235 | } |
| 238 | 236 | } |
| 239 | 237 | |
| r244870 | r244871 | |
| 277 | 275 | |
| 278 | 276 | } |
| 279 | 277 | |
| 280 | | /*** ICU ***/ |
| 281 | 278 | |
| 282 | 279 | |
| 283 | | |
| 284 | | READ8_MEMBER(v53_base_device::icu_0_r) |
| 285 | | { |
| 286 | | printf("v53: icu_0_r\n"); |
| 287 | | return 0; |
| 288 | | } |
| 289 | | |
| 290 | | WRITE8_MEMBER(v53_base_device::icu_0_w) |
| 291 | | { |
| 292 | | printf("v53: icu_0_w %02x\n", data); |
| 293 | | } |
| 294 | | |
| 295 | | READ8_MEMBER(v53_base_device::icu_1_r) |
| 296 | | { |
| 297 | | printf("v53: icu_1_r\n"); |
| 298 | | return 0; |
| 299 | | } |
| 300 | | |
| 301 | | WRITE8_MEMBER(v53_base_device::icu_1_w) |
| 302 | | { |
| 303 | | printf("v53: icu_1_w %02x\n", data); |
| 304 | | } |
| 305 | | |
| 306 | 280 | /*** SCU ***/ |
| 307 | 281 | |
| 308 | 282 | READ8_MEMBER(v53_base_device::scu_srb_r) |
| r244870 | r244871 | |
| 346 | 320 | |
| 347 | 321 | /*** TCU ***/ |
| 348 | 322 | |
| 349 | | WRITE8_MEMBER(v53_base_device::tmu_tct0_w) { m_pit->write(space, 0, data); } |
| 350 | | WRITE8_MEMBER(v53_base_device::tmu_tct1_w) { m_pit->write(space, 1, data); } |
| 351 | | WRITE8_MEMBER(v53_base_device::tmu_tct2_w) { m_pit->write(space, 2, data); } |
| 352 | | WRITE8_MEMBER(v53_base_device::tmu_tmd_w) { m_pit->write(space, 3, data); } |
| 323 | WRITE8_MEMBER(v53_base_device::tmu_tct0_w) { m_v53tcu->write(space, 0, data); } |
| 324 | WRITE8_MEMBER(v53_base_device::tmu_tct1_w) { m_v53tcu->write(space, 1, data); } |
| 325 | WRITE8_MEMBER(v53_base_device::tmu_tct2_w) { m_v53tcu->write(space, 2, data); } |
| 326 | WRITE8_MEMBER(v53_base_device::tmu_tmd_w) { m_v53tcu->write(space, 3, data); } |
| 353 | 327 | |
| 354 | 328 | |
| 355 | | READ8_MEMBER(v53_base_device::tmu_tst0_r) { return m_pit->read(space, 0); } |
| 356 | | READ8_MEMBER(v53_base_device::tmu_tst1_r) { return m_pit->read(space, 1); } |
| 357 | | READ8_MEMBER(v53_base_device::tmu_tst2_r) { return m_pit->read(space, 2); } |
| 329 | READ8_MEMBER(v53_base_device::tmu_tst0_r) { return m_v53tcu->read(space, 0); } |
| 330 | READ8_MEMBER(v53_base_device::tmu_tst1_r) { return m_v53tcu->read(space, 1); } |
| 331 | READ8_MEMBER(v53_base_device::tmu_tst2_r) { return m_v53tcu->read(space, 2); } |
| 358 | 332 | |
| 359 | 333 | /*** DMA ***/ |
| 360 | 334 | |
| r244870 | r244871 | |
| 363 | 337 | { |
| 364 | 338 | if (!(m_SCTL & 0x02)) |
| 365 | 339 | { |
| 366 | | m_dma_71071mode->dreq0_w(state); |
| 340 | m_v53dmau->dreq0_w(state); |
| 367 | 341 | } |
| 368 | 342 | else |
| 369 | 343 | { |
| r244870 | r244871 | |
| 375 | 349 | { |
| 376 | 350 | if (!(m_SCTL & 0x02)) |
| 377 | 351 | { |
| 378 | | m_dma_71071mode->dreq1_w(state); |
| 352 | m_v53dmau->dreq1_w(state); |
| 379 | 353 | } |
| 380 | 354 | else |
| 381 | 355 | { |
| r244870 | r244871 | |
| 387 | 361 | { |
| 388 | 362 | if (!(m_SCTL & 0x02)) |
| 389 | 363 | { |
| 390 | | m_dma_71071mode->dreq2_w(state); |
| 364 | m_v53dmau->dreq2_w(state); |
| 391 | 365 | } |
| 392 | 366 | else |
| 393 | 367 | { |
| r244870 | r244871 | |
| 399 | 373 | { |
| 400 | 374 | if (!(m_SCTL & 0x02)) |
| 401 | 375 | { |
| 402 | | m_dma_71071mode->dreq3_w(state); |
| 376 | m_v53dmau->dreq3_w(state); |
| 403 | 377 | } |
| 404 | 378 | else |
| 405 | 379 | { |
| r244870 | r244871 | |
| 411 | 385 | { |
| 412 | 386 | if (!(m_SCTL & 0x02)) |
| 413 | 387 | { |
| 414 | | m_dma_71071mode->hack_w(state); |
| 388 | m_v53dmau->hack_w(state); |
| 415 | 389 | } |
| 416 | 390 | else |
| 417 | 391 | { |
| r244870 | r244871 | |
| 459 | 433 | WRITE_LINE_MEMBER(v53_base_device::dma_hrq_changed) |
| 460 | 434 | { |
| 461 | 435 | // pass this back to the driver? / expose externally? |
| 462 | | m_dma_71071mode->hack_w(state); |
| 436 | m_v53dmau->hack_w(state); |
| 463 | 437 | } |
| 464 | 438 | |
| 465 | 439 | WRITE8_MEMBER(v53_base_device::dma_io_3_w) |
| r244870 | r244871 | |
| 481 | 455 | |
| 482 | 456 | WRITE_LINE_MEMBER( v53_base_device::upd71059_irq_w) |
| 483 | 457 | { |
| 484 | | printf("upd71059_irq_w %d", state); |
| 458 | printf("upd71059_irq_w %d\n", state); |
| 485 | 459 | } |
| 486 | 460 | |
| 487 | 461 | static MACHINE_CONFIG_FRAGMENT( v53 ) |
| r244870 | r244871 | |
| 489 | 463 | MCFG_PIT8253_CLK0(16000000/2/8) |
| 490 | 464 | //MCFG_PIT8253_OUT0_HANDLER(WRITELINE(v53_base_device, pit_out0)) |
| 491 | 465 | |
| 492 | | MCFG_DEVICE_ADD("upd71071dma", UPD71071_V53, 4000000) |
| 466 | MCFG_DEVICE_ADD("upd71071dma", V53_DMAU, 4000000) |
| 493 | 467 | MCFG_I8237_OUT_HREQ_CB(WRITELINE(v53_base_device, dma_hrq_changed)) |
| 494 | 468 | MCFG_I8237_OUT_IOW_3_CB(WRITE8(v53_base_device, dma_io_3_w)) |
| 495 | 469 | MCFG_I8237_IN_MEMR_CB(READ8(v53_base_device, dma_memin_r)) |
| r244870 | r244871 | |
| 497 | 471 | |
| 498 | 472 | MCFG_PIC8259_ADD( "upd71059pic", WRITELINE(v53_base_device, upd71059_irq_w), VCC, READ8(v53_base_device,get_pic_ack)) |
| 499 | 473 | |
| 500 | | MCFG_DEVICE_ADD("upd71051", I8251, 0) |
| 474 | MCFG_DEVICE_ADD("v53scu", V53_SCU, 0) |
| 501 | 475 | |
| 502 | 476 | MACHINE_CONFIG_END |
| 503 | 477 | |
| r244870 | r244871 | |
| 510 | 484 | v53_base_device::v53_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, offs_t fetch_xor, UINT8 prefetch_size, UINT8 prefetch_cycles, UINT32 chip_type) |
| 511 | 485 | : nec_common_device(mconfig, type, name, tag, owner, clock, shortname, true, fetch_xor, prefetch_size, prefetch_cycles, chip_type), |
| 512 | 486 | m_io_space_config( "io", ENDIANNESS_LITTLE, 16, 16, 0, ADDRESS_MAP_NAME( v53_internal_port_map ) ), |
| 513 | | m_pit(*this, "pit"), |
| 514 | | m_dma_71071mode(*this, "upd71071dma"), |
| 515 | | m_upd71059(*this, "upd71059pic"), |
| 516 | | m_upd71051(*this, "upd71051") |
| 487 | m_v53tcu(*this, "pit"), |
| 488 | m_v53dmau(*this, "upd71071dma"), |
| 489 | m_v53icu(*this, "upd71059pic"), |
| 490 | m_v53scu(*this, "v53scu") |
| 517 | 491 | { |
| 518 | 492 | } |
| 519 | 493 | |
trunk/src/emu/machine/i8251.c
| r244870 | r244871 | |
| 3 | 3 | i8251.c |
| 4 | 4 | |
| 5 | 5 | Intel 8251 Universal Synchronous/Asynchronous Receiver Transmitter code |
| 6 | NEC uPD71051 is a clone |
| 6 | 7 | |
| 8 | The V53/V53A use a customized version with only the Asynchronous mode |
| 9 | and a split command / mode register |
| 10 | |
| 11 | |
| 12 | |
| 7 | 13 | *********************************************************************/ |
| 8 | 14 | |
| 9 | 15 | #include "emu.h" |
| r244870 | r244871 | |
| 23 | 29 | //************************************************************************** |
| 24 | 30 | |
| 25 | 31 | const device_type I8251 = &device_creator<i8251_device>; |
| 32 | const device_type V53_SCU = &device_creator<v53_scu_device>; |
| 26 | 33 | |
| 27 | 34 | //------------------------------------------------- |
| 28 | 35 | // i8251_device - constructor |
| 29 | 36 | //------------------------------------------------- |
| 30 | 37 | |
| 38 | i8251_device::i8251_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname) |
| 39 | : device_t(mconfig, type, name, tag, owner, clock, shortname, __FILE__), |
| 40 | device_serial_interface(mconfig, *this), |
| 41 | m_txd_handler(*this), |
| 42 | m_dtr_handler(*this), |
| 43 | m_rts_handler(*this), |
| 44 | m_rxrdy_handler(*this), |
| 45 | m_txrdy_handler(*this), |
| 46 | m_txempty_handler(*this), |
| 47 | m_syndet_handler(*this), |
| 48 | m_cts(1), |
| 49 | m_dsr(1), |
| 50 | m_rxd(0), |
| 51 | m_rxc(0), |
| 52 | m_txc(0) |
| 53 | { |
| 54 | } |
| 55 | |
| 31 | 56 | i8251_device::i8251_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 32 | 57 | : device_t(mconfig, I8251, "8251 USART", tag, owner, clock, "i8251", __FILE__), |
| 33 | 58 | device_serial_interface(mconfig, *this), |
| r244870 | r244871 | |
| 46 | 71 | { |
| 47 | 72 | } |
| 48 | 73 | |
| 74 | v53_scu_device::v53_scu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 75 | : i8251_device(mconfig, V53_SCU, "V53 SCU", tag, owner, clock, "v53_scu") |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | |
| 49 | 80 | //------------------------------------------------- |
| 50 | 81 | // device_start - device-specific startup |
| 51 | 82 | //------------------------------------------------- |
| r244870 | r244871 | |
| 325 | 356 | control_w |
| 326 | 357 | -------------------------------------------------*/ |
| 327 | 358 | |
| 328 | | WRITE8_MEMBER(i8251_device::control_w) |
| 359 | WRITE8_MEMBER(i8251_device::command_w) |
| 329 | 360 | { |
| 330 | | if (m_flags & I8251_EXPECTING_MODE) |
| 361 | /* command */ |
| 362 | LOG(("I8251: Command byte\n")); |
| 363 | |
| 364 | m_command = data; |
| 365 | |
| 366 | LOG(("Command byte: %02x\n", data)); |
| 367 | |
| 368 | if (data & (1<<7)) |
| 331 | 369 | { |
| 332 | | if (m_flags & I8251_EXPECTING_SYNC_BYTE) |
| 333 | | { |
| 334 | | LOG(("I8251: Sync byte\n")); |
| 370 | LOG(("hunt mode\n")); |
| 371 | } |
| 335 | 372 | |
| 336 | | LOG(("Sync byte: %02x\n", data)); |
| 337 | | /* store sync byte written */ |
| 338 | | m_sync_bytes[m_sync_byte_offset] = data; |
| 339 | | m_sync_byte_offset++; |
| 373 | if (data & (1<<5)) |
| 374 | { |
| 375 | LOG(("/rts set to 0\n")); |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | LOG(("/rts set to 1\n")); |
| 380 | } |
| 340 | 381 | |
| 341 | | if (m_sync_byte_offset == m_sync_byte_count) |
| 382 | if (data & (1<<2)) |
| 383 | { |
| 384 | LOG(("receive enable\n")); |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | LOG(("receive disable\n")); |
| 389 | } |
| 390 | |
| 391 | if (data & (1<<1)) |
| 392 | { |
| 393 | LOG(("/dtr set to 0\n")); |
| 394 | } |
| 395 | else |
| 396 | { |
| 397 | LOG(("/dtr set to 1\n")); |
| 398 | } |
| 399 | |
| 400 | if (data & (1<<0)) |
| 401 | { |
| 402 | LOG(("transmit enable\n")); |
| 403 | |
| 404 | /* if we get a tx enable with a disable pending, cancel the disable */ |
| 405 | m_disable_tx_pending = false; |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | if (m_tx_busy) |
| 410 | { |
| 411 | if (!m_disable_tx_pending) |
| 342 | 412 | { |
| 343 | | /* finished transfering sync bytes, now expecting command */ |
| 344 | | m_flags &= ~(I8251_EXPECTING_MODE | I8251_EXPECTING_SYNC_BYTE); |
| 345 | | m_sync_byte_offset = 0; |
| 346 | | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 413 | LOG(("Tx busy, set pending disable\n")); |
| 347 | 414 | } |
| 415 | m_disable_tx_pending = true; |
| 416 | m_command |= (1<<0); |
| 348 | 417 | } |
| 349 | 418 | else |
| 350 | 419 | { |
| 351 | | LOG(("I8251: Mode byte\n")); |
| 352 | | |
| 353 | | m_mode_byte = data; |
| 354 | | |
| 355 | | /* Synchronous or Asynchronous? */ |
| 356 | | if ((data & 0x03)!=0) |
| 420 | LOG(("transmit disable\n")); |
| 421 | if ((data & (1<<0))==0) |
| 357 | 422 | { |
| 358 | | /* Asynchronous |
| 423 | /* held in high state when transmit disable */ |
| 424 | m_txd_handler(1); |
| 425 | } |
| 426 | } |
| 427 | } |
| 359 | 428 | |
| 360 | | bit 7,6: stop bit length |
| 361 | | 0 = inhibit |
| 362 | | 1 = 1 bit |
| 363 | | 2 = 1.5 bits |
| 364 | | 3 = 2 bits |
| 365 | | bit 5: parity type |
| 366 | | 0 = parity odd |
| 367 | | 1 = parity even |
| 368 | | bit 4: parity test enable |
| 369 | | 0 = disable |
| 370 | | 1 = enable |
| 371 | | bit 3,2: character length |
| 372 | | 0 = 5 bits |
| 373 | | 1 = 6 bits |
| 374 | | 2 = 7 bits |
| 375 | | 3 = 8 bits |
| 376 | | bit 1,0: baud rate factor |
| 377 | | 0 = defines command byte for synchronous or asynchronous |
| 378 | | 1 = x1 |
| 379 | | 2 = x16 |
| 380 | | 3 = x64 |
| 381 | | */ |
| 382 | 429 | |
| 383 | | LOG(("I8251: Asynchronous operation\n")); |
| 430 | /* bit 7: |
| 431 | 0 = normal operation |
| 432 | 1 = hunt mode |
| 433 | bit 6: |
| 434 | 0 = normal operation |
| 435 | 1 = internal reset |
| 436 | bit 5: |
| 437 | 0 = /RTS set to 1 |
| 438 | 1 = /RTS set to 0 |
| 439 | bit 4: |
| 440 | 0 = normal operation |
| 441 | 1 = reset error flag |
| 442 | bit 3: |
| 443 | 0 = normal operation |
| 444 | 1 = send break character |
| 445 | bit 2: |
| 446 | 0 = receive disable |
| 447 | 1 = receive enable |
| 448 | bit 1: |
| 449 | 0 = /DTR set to 1 |
| 450 | 1 = /DTR set to 0 |
| 451 | bit 0: |
| 452 | 0 = transmit disable |
| 453 | 1 = transmit enable |
| 454 | */ |
| 384 | 455 | |
| 385 | | LOG(("Character length: %d\n", (((data>>2) & 0x03)+5))); |
| 456 | m_rts_handler(!BIT(data, 5)); |
| 457 | m_dtr_handler(!BIT(data, 1)); |
| 386 | 458 | |
| 387 | | parity_t parity; |
| 459 | if (data & (1<<4)) |
| 460 | { |
| 461 | m_status &= ~(I8251_STATUS_PARITY_ERROR | I8251_STATUS_OVERRUN_ERROR | I8251_STATUS_FRAMING_ERROR); |
| 462 | } |
| 388 | 463 | |
| 389 | | if (data & (1<<4)) |
| 390 | | { |
| 391 | | LOG(("enable parity checking\n")); |
| 464 | if (data & (1<<6)) |
| 465 | { |
| 466 | // datasheet says "returns to mode format", not |
| 467 | // completely resets the chip. behavior of DEC Rainbow |
| 468 | // backs this up. |
| 469 | m_flags |= I8251_EXPECTING_MODE; |
| 470 | } |
| 392 | 471 | |
| 393 | | if (data & (1<<5)) |
| 394 | | { |
| 395 | | LOG(("even parity\n")); |
| 396 | | parity = PARITY_EVEN; |
| 397 | | } |
| 398 | | else |
| 399 | | { |
| 400 | | LOG(("odd parity\n")); |
| 401 | | parity = PARITY_ODD; |
| 402 | | } |
| 403 | | } |
| 404 | | else |
| 405 | | { |
| 406 | | LOG(("parity check disabled\n")); |
| 407 | | parity = PARITY_NONE; |
| 408 | | } |
| 472 | update_rx_ready(); |
| 473 | update_tx_ready(); |
| 474 | } |
| 409 | 475 | |
| 410 | | stop_bits_t stop_bits; |
| 476 | WRITE8_MEMBER(i8251_device::mode_w) |
| 477 | { |
| 478 | LOG(("I8251: Mode byte\n")); |
| 411 | 479 | |
| 412 | | switch ((data>>6) & 0x03) |
| 413 | | { |
| 414 | | case 0: |
| 415 | | default: |
| 416 | | stop_bits = STOP_BITS_0; |
| 417 | | LOG(("stop bit: inhibit\n")); |
| 418 | | break; |
| 480 | m_mode_byte = data; |
| 419 | 481 | |
| 420 | | case 1: |
| 421 | | stop_bits = STOP_BITS_1; |
| 422 | | LOG(("stop bit: 1 bit\n")); |
| 423 | | break; |
| 482 | /* Synchronous or Asynchronous? */ |
| 483 | if ((data & 0x03) != 0) |
| 484 | { |
| 485 | /* Asynchronous |
| 424 | 486 | |
| 425 | | case 2: |
| 426 | | stop_bits = STOP_BITS_1_5; |
| 427 | | LOG(("stop bit: 1.5 bits\n")); |
| 428 | | break; |
| 487 | bit 7,6: stop bit length |
| 488 | 0 = inhibit |
| 489 | 1 = 1 bit |
| 490 | 2 = 1.5 bits |
| 491 | 3 = 2 bits |
| 492 | bit 5: parity type |
| 493 | 0 = parity odd |
| 494 | 1 = parity even |
| 495 | bit 4: parity test enable |
| 496 | 0 = disable |
| 497 | 1 = enable |
| 498 | bit 3,2: character length |
| 499 | 0 = 5 bits |
| 500 | 1 = 6 bits |
| 501 | 2 = 7 bits |
| 502 | 3 = 8 bits |
| 503 | bit 1,0: baud rate factor |
| 504 | 0 = defines command byte for synchronous or asynchronous |
| 505 | 1 = x1 |
| 506 | 2 = x16 |
| 507 | 3 = x64 |
| 508 | */ |
| 429 | 509 | |
| 430 | | case 3: |
| 431 | | stop_bits = STOP_BITS_2; |
| 432 | | LOG(("stop bit: 2 bits\n")); |
| 433 | | break; |
| 434 | | } |
| 510 | LOG(("I8251: Asynchronous operation\n")); |
| 435 | 511 | |
| 436 | | int data_bits_count = ((data>>2) & 0x03)+5; |
| 512 | LOG(("Character length: %d\n", (((data >> 2) & 0x03) + 5))); |
| 437 | 513 | |
| 438 | | set_data_frame(1, data_bits_count, parity, stop_bits); |
| 439 | | receive_register_reset(); |
| 514 | parity_t parity; |
| 440 | 515 | |
| 441 | | switch (data & 0x03) |
| 442 | | { |
| 443 | | case 1: m_br_factor = 1; break; |
| 444 | | case 2: m_br_factor = 16; break; |
| 445 | | case 3: m_br_factor = 64; break; |
| 446 | | } |
| 516 | if (data & (1 << 4)) |
| 517 | { |
| 518 | LOG(("enable parity checking\n")); |
| 447 | 519 | |
| 448 | | m_rxc_count = m_txc_count = 0; |
| 449 | | |
| 450 | | #if 0 |
| 451 | | /* data bits */ |
| 452 | | m_receive_char_length = (((data>>2) & 0x03)+5); |
| 453 | | |
| 454 | | if (data & (1<<4)) |
| 455 | | { |
| 456 | | /* parity */ |
| 457 | | m_receive_char_length++; |
| 458 | | } |
| 459 | | |
| 460 | | /* stop bits */ |
| 461 | | m_receive_char_length++; |
| 462 | | |
| 463 | | m_receive_flags &=~I8251_TRANSFER_RECEIVE_SYNCHRONISED; |
| 464 | | m_receive_flags |= I8251_TRANSFER_RECEIVE_WAITING_FOR_START_BIT; |
| 465 | | #endif |
| 466 | | /* not expecting mode byte now */ |
| 467 | | m_flags &= ~I8251_EXPECTING_MODE; |
| 468 | | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 520 | if (data & (1 << 5)) |
| 521 | { |
| 522 | LOG(("even parity\n")); |
| 523 | parity = PARITY_EVEN; |
| 469 | 524 | } |
| 470 | 525 | else |
| 471 | 526 | { |
| 472 | | /* bit 7: Number of sync characters |
| 473 | | 0 = 1 character |
| 474 | | 1 = 2 character |
| 475 | | bit 6: Synchronous mode |
| 476 | | 0 = Internal synchronisation |
| 477 | | 1 = External synchronisation |
| 478 | | bit 5: parity type |
| 479 | | 0 = parity odd |
| 480 | | 1 = parity even |
| 481 | | bit 4: parity test enable |
| 482 | | 0 = disable |
| 483 | | 1 = enable |
| 484 | | bit 3,2: character length |
| 485 | | 0 = 5 bits |
| 486 | | 1 = 6 bits |
| 487 | | 2 = 7 bits |
| 488 | | 3 = 8 bits |
| 489 | | bit 1,0 = 0 |
| 490 | | */ |
| 491 | | LOG(("I8251: Synchronous operation\n")); |
| 492 | | |
| 493 | | /* setup for sync byte(s) */ |
| 494 | | m_flags |= I8251_EXPECTING_SYNC_BYTE; |
| 495 | | m_sync_byte_offset = 0; |
| 496 | | if (data & 0x07) |
| 497 | | { |
| 498 | | m_sync_byte_count = 1; |
| 499 | | } |
| 500 | | else |
| 501 | | { |
| 502 | | m_sync_byte_count = 2; |
| 503 | | } |
| 504 | | |
| 527 | LOG(("odd parity\n")); |
| 528 | parity = PARITY_ODD; |
| 505 | 529 | } |
| 506 | 530 | } |
| 507 | | } |
| 508 | | else |
| 509 | | { |
| 510 | | /* command */ |
| 511 | | LOG(("I8251: Command byte\n")); |
| 531 | else |
| 532 | { |
| 533 | LOG(("parity check disabled\n")); |
| 534 | parity = PARITY_NONE; |
| 535 | } |
| 512 | 536 | |
| 513 | | m_command = data; |
| 537 | stop_bits_t stop_bits; |
| 514 | 538 | |
| 515 | | LOG(("Command byte: %02x\n", data)); |
| 539 | switch ((data >> 6) & 0x03) |
| 540 | { |
| 541 | case 0: |
| 542 | default: |
| 543 | stop_bits = STOP_BITS_0; |
| 544 | LOG(("stop bit: inhibit\n")); |
| 545 | break; |
| 516 | 546 | |
| 517 | | if (data & (1<<7)) |
| 518 | | { |
| 519 | | LOG(("hunt mode\n")); |
| 547 | case 1: |
| 548 | stop_bits = STOP_BITS_1; |
| 549 | LOG(("stop bit: 1 bit\n")); |
| 550 | break; |
| 551 | |
| 552 | case 2: |
| 553 | stop_bits = STOP_BITS_1_5; |
| 554 | LOG(("stop bit: 1.5 bits\n")); |
| 555 | break; |
| 556 | |
| 557 | case 3: |
| 558 | stop_bits = STOP_BITS_2; |
| 559 | LOG(("stop bit: 2 bits\n")); |
| 560 | break; |
| 520 | 561 | } |
| 521 | 562 | |
| 522 | | if (data & (1<<5)) |
| 563 | int data_bits_count = ((data >> 2) & 0x03) + 5; |
| 564 | |
| 565 | set_data_frame(1, data_bits_count, parity, stop_bits); |
| 566 | receive_register_reset(); |
| 567 | |
| 568 | switch (data & 0x03) |
| 523 | 569 | { |
| 524 | | LOG(("/rts set to 0\n")); |
| 570 | case 1: m_br_factor = 1; break; |
| 571 | case 2: m_br_factor = 16; break; |
| 572 | case 3: m_br_factor = 64; break; |
| 525 | 573 | } |
| 526 | | else |
| 527 | | { |
| 528 | | LOG(("/rts set to 1\n")); |
| 529 | | } |
| 530 | 574 | |
| 531 | | if (data & (1<<2)) |
| 575 | m_rxc_count = m_txc_count = 0; |
| 576 | |
| 577 | #if 0 |
| 578 | /* data bits */ |
| 579 | m_receive_char_length = (((data >> 2) & 0x03) + 5); |
| 580 | |
| 581 | if (data & (1 << 4)) |
| 532 | 582 | { |
| 533 | | LOG(("receive enable\n")); |
| 583 | /* parity */ |
| 584 | m_receive_char_length++; |
| 534 | 585 | } |
| 535 | | else |
| 536 | | { |
| 537 | | LOG(("receive disable\n")); |
| 538 | | } |
| 539 | 586 | |
| 540 | | if (data & (1<<1)) |
| 587 | /* stop bits */ |
| 588 | m_receive_char_length++; |
| 589 | |
| 590 | m_receive_flags &= ~I8251_TRANSFER_RECEIVE_SYNCHRONISED; |
| 591 | m_receive_flags |= I8251_TRANSFER_RECEIVE_WAITING_FOR_START_BIT; |
| 592 | #endif |
| 593 | /* not expecting mode byte now */ |
| 594 | m_flags &= ~I8251_EXPECTING_MODE; |
| 595 | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | /* bit 7: Number of sync characters |
| 600 | 0 = 1 character |
| 601 | 1 = 2 character |
| 602 | bit 6: Synchronous mode |
| 603 | 0 = Internal synchronisation |
| 604 | 1 = External synchronisation |
| 605 | bit 5: parity type |
| 606 | 0 = parity odd |
| 607 | 1 = parity even |
| 608 | bit 4: parity test enable |
| 609 | 0 = disable |
| 610 | 1 = enable |
| 611 | bit 3,2: character length |
| 612 | 0 = 5 bits |
| 613 | 1 = 6 bits |
| 614 | 2 = 7 bits |
| 615 | 3 = 8 bits |
| 616 | bit 1,0 = 0 |
| 617 | */ |
| 618 | LOG(("I8251: Synchronous operation\n")); |
| 619 | |
| 620 | /* setup for sync byte(s) */ |
| 621 | m_flags |= I8251_EXPECTING_SYNC_BYTE; |
| 622 | m_sync_byte_offset = 0; |
| 623 | if (data & 0x07) |
| 541 | 624 | { |
| 542 | | LOG(("/dtr set to 0\n")); |
| 625 | m_sync_byte_count = 1; |
| 543 | 626 | } |
| 544 | 627 | else |
| 545 | 628 | { |
| 546 | | LOG(("/dtr set to 1\n")); |
| 629 | m_sync_byte_count = 2; |
| 547 | 630 | } |
| 548 | 631 | |
| 549 | | if (data & (1<<0)) |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | WRITE8_MEMBER(i8251_device::control_w) |
| 636 | { |
| 637 | if (m_flags & I8251_EXPECTING_MODE) |
| 638 | { |
| 639 | if (m_flags & I8251_EXPECTING_SYNC_BYTE) |
| 550 | 640 | { |
| 551 | | LOG(("transmit enable\n")); |
| 641 | LOG(("I8251: Sync byte\n")); |
| 552 | 642 | |
| 553 | | /* if we get a tx enable with a disable pending, cancel the disable */ |
| 554 | | m_disable_tx_pending = false; |
| 555 | | } |
| 556 | | else |
| 557 | | { |
| 558 | | if (m_tx_busy) |
| 643 | LOG(("Sync byte: %02x\n", data)); |
| 644 | /* store sync byte written */ |
| 645 | m_sync_bytes[m_sync_byte_offset] = data; |
| 646 | m_sync_byte_offset++; |
| 647 | |
| 648 | if (m_sync_byte_offset == m_sync_byte_count) |
| 559 | 649 | { |
| 560 | | if (!m_disable_tx_pending) |
| 561 | | { |
| 562 | | LOG(("Tx busy, set pending disable\n")); |
| 563 | | } |
| 564 | | m_disable_tx_pending = true; |
| 565 | | m_command |= (1<<0); |
| 650 | /* finished transfering sync bytes, now expecting command */ |
| 651 | m_flags &= ~(I8251_EXPECTING_MODE | I8251_EXPECTING_SYNC_BYTE); |
| 652 | m_sync_byte_offset = 0; |
| 653 | // m_status = I8251_STATUS_TX_EMPTY | I8251_STATUS_TX_READY; |
| 566 | 654 | } |
| 567 | | else |
| 568 | | { |
| 569 | | LOG(("transmit disable\n")); |
| 570 | | if ((data & (1<<0))==0) |
| 571 | | { |
| 572 | | /* held in high state when transmit disable */ |
| 573 | | m_txd_handler(1); |
| 574 | | } |
| 575 | | } |
| 576 | 655 | } |
| 577 | | |
| 578 | | |
| 579 | | /* bit 7: |
| 580 | | 0 = normal operation |
| 581 | | 1 = hunt mode |
| 582 | | bit 6: |
| 583 | | 0 = normal operation |
| 584 | | 1 = internal reset |
| 585 | | bit 5: |
| 586 | | 0 = /RTS set to 1 |
| 587 | | 1 = /RTS set to 0 |
| 588 | | bit 4: |
| 589 | | 0 = normal operation |
| 590 | | 1 = reset error flag |
| 591 | | bit 3: |
| 592 | | 0 = normal operation |
| 593 | | 1 = send break character |
| 594 | | bit 2: |
| 595 | | 0 = receive disable |
| 596 | | 1 = receive enable |
| 597 | | bit 1: |
| 598 | | 0 = /DTR set to 1 |
| 599 | | 1 = /DTR set to 0 |
| 600 | | bit 0: |
| 601 | | 0 = transmit disable |
| 602 | | 1 = transmit enable |
| 603 | | */ |
| 604 | | |
| 605 | | m_rts_handler(!BIT(data, 5)); |
| 606 | | m_dtr_handler(!BIT(data, 1)); |
| 607 | | |
| 608 | | if (data & (1<<4)) |
| 656 | else |
| 609 | 657 | { |
| 610 | | m_status &= ~(I8251_STATUS_PARITY_ERROR | I8251_STATUS_OVERRUN_ERROR | I8251_STATUS_FRAMING_ERROR); |
| 658 | mode_w(space, offset, data); |
| 611 | 659 | } |
| 612 | | |
| 613 | | if (data & (1<<6)) |
| 614 | | { |
| 615 | | // datasheet says "returns to mode format", not |
| 616 | | // completely resets the chip. behavior of DEC Rainbow |
| 617 | | // backs this up. |
| 618 | | m_flags |= I8251_EXPECTING_MODE; |
| 619 | | } |
| 620 | | |
| 621 | | update_rx_ready(); |
| 622 | | update_tx_ready(); |
| 623 | | |
| 624 | 660 | } |
| 661 | else |
| 662 | { |
| 663 | command_w(space, offset, data); |
| 664 | } |
| 625 | 665 | } |
| 626 | 666 | |
| 627 | 667 | |