trunk/src/mess/machine/thomflop.c
| r21425 | r21426 | |
| 80 | 80 | |
| 81 | 81 | |
| 82 | 82 | /* build an identifier, with header & space */ |
| 83 | | static int thom_floppy_make_addr( chrn_id id, UINT8* dst, int sector_size ) |
| 83 | int thomson_state::thom_floppy_make_addr( chrn_id id, UINT8* dst, int sector_size ) |
| 84 | 84 | { |
| 85 | 85 | if ( sector_size == 128 ) |
| 86 | 86 | { |
| r21425 | r21426 | |
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | /* build a sector, with header & space */ |
| 118 | | static int thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size ) |
| 118 | int thomson_state::thom_floppy_make_sector( device_t* img, chrn_id id, UINT8* dst, int sector_size ) |
| 119 | 119 | { |
| 120 | 120 | if ( sector_size == 128 ) |
| 121 | 121 | { |
| r21425 | r21426 | |
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | /* build a whole track */ |
| 149 | | static int thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side ) |
| 149 | int thomson_state::thom_floppy_make_track( device_t* img, UINT8* dst, int sector_size, int side ) |
| 150 | 150 | { |
| 151 | 151 | UINT8 space = ( sector_size == 128 ) ? 0xff : 0; |
| 152 | 152 | UINT8* org = dst; |
| r21425 | r21426 | |
| 210 | 210 | |
| 211 | 211 | |
| 212 | 212 | /* build an identifier, with header */ |
| 213 | | static int thom_qdd_make_addr( int sector, UINT8* dst ) |
| 213 | int thomson_state::thom_qdd_make_addr( int sector, UINT8* dst ) |
| 214 | 214 | { |
| 215 | 215 | dst[ 0 ] = 0xa5; |
| 216 | 216 | dst[ 1 ] = sector >> 8; |
| r21425 | r21426 | |
| 222 | 222 | |
| 223 | 223 | |
| 224 | 224 | /* build a sector, with header */ |
| 225 | | static int thom_qdd_make_sector( device_t* img, int sector, UINT8* dst ) |
| 225 | int thomson_state::thom_qdd_make_sector( device_t* img, int sector, UINT8* dst ) |
| 226 | 226 | { |
| 227 | 227 | int i; |
| 228 | 228 | dst[ 0 ] = 0x5a; |
| r21425 | r21426 | |
| 236 | 236 | |
| 237 | 237 | |
| 238 | 238 | /* build a whole disk */ |
| 239 | | static int thom_qdd_make_disk ( device_t* img, UINT8* dst ) |
| 239 | int thomson_state::thom_qdd_make_disk ( device_t* img, UINT8* dst ) |
| 240 | 240 | { |
| 241 | 241 | UINT8* org = dst; |
| 242 | 242 | int i; |
| r21425 | r21426 | |
| 271 | 271 | |
| 272 | 272 | |
| 273 | 273 | |
| 274 | | static READ8_HANDLER ( to7_5p14_r ) |
| 274 | READ8_MEMBER( thomson_state::to7_5p14_r ) |
| 275 | 275 | { |
| 276 | | device_t *fdc = space.machine().device("wd2793"); |
| 276 | device_t *fdc = machine().device("wd2793"); |
| 277 | 277 | |
| 278 | 278 | if ( offset < 4 ) |
| 279 | 279 | return wd17xx_r( fdc, space, offset ); |
| 280 | 280 | else if ( offset == 8 ) |
| 281 | 281 | return to7_5p14_select; |
| 282 | 282 | else |
| 283 | | logerror ( "%f $%04x to7_5p14_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 283 | logerror ( "%f $%04x to7_5p14_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset ); |
| 284 | 284 | return 0; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
| 288 | 288 | |
| 289 | | static WRITE8_HANDLER( to7_5p14_w ) |
| 289 | WRITE8_HANDLER( thomson_state::to7_5p14_w ) |
| 290 | 290 | { |
| 291 | | device_t *fdc = space.machine().device("wd2793"); |
| 291 | device_t *fdc = machine().device("wd2793"); |
| 292 | 292 | if ( offset < 4 ) |
| 293 | 293 | wd17xx_w( fdc, space, offset, data ); |
| 294 | 294 | else if ( offset == 8 ) |
| r21425 | r21426 | |
| 304 | 304 | case 4: drive = 2; side = 0; break; |
| 305 | 305 | case 5: drive = 3; side = 1; break; |
| 306 | 306 | default: |
| 307 | | logerror( "%f $%04x to7_5p14_w: invalid drive select pattern $%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data ); |
| 307 | logerror( "%f $%04x to7_5p14_w: invalid drive select pattern $%02X\n", machine().time().as_double(), m_maincpu->pc(), data ); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | wd17xx_dden_w(fdc, BIT(data, 7)); |
| r21425 | r21426 | |
| 313 | 313 | |
| 314 | 314 | if ( drive != -1 ) |
| 315 | 315 | { |
| 316 | | thom_floppy_active( space.machine(), 0 ); |
| 316 | thom_floppy_active( 0 ); |
| 317 | 317 | wd17xx_set_drive( fdc, drive ); |
| 318 | 318 | wd17xx_set_side( fdc, side ); |
| 319 | 319 | LOG(( "%f $%04x to7_5p14_w: $%02X set drive=%i side=%i density=%s\n", |
| 320 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), |
| 320 | machine().time().as_double(), m_maincpu->pc(), |
| 321 | 321 | data, drive, side, (BIT(data, 7) ? "FM" : "MFM"))); |
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | else |
| 325 | 325 | logerror ( "%f $%04x to7_5p14_w: invalid write offset %i (data=$%02X)\n", |
| 326 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 326 | machine().time().as_double(), m_maincpu->pc(), offset, data ); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | |
| 330 | 330 | |
| 331 | | static void to7_5p14_reset( running_machine &machine ) |
| 331 | void thomson_state::to7_5p14_reset() |
| 332 | 332 | { |
| 333 | | device_t *fdc = machine.device("wd2793"); |
| 333 | device_t *fdc = machine().device("wd2793"); |
| 334 | 334 | LOG(( "to7_5p14_reset: CD 90-640 controller\n" )); |
| 335 | 335 | wd17xx_reset(fdc); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
| 339 | 339 | |
| 340 | | static void to7_5p14_init( running_machine &machine ) |
| 340 | void thomson_state::to7_5p14_init() |
| 341 | 341 | { |
| 342 | 342 | LOG(( "to7_5p14_init: CD 90-640 controller\n" )); |
| 343 | | state_save_register_global( machine, to7_5p14_select ); |
| 343 | state_save_register_global( machine(), to7_5p14_select ); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
| r21425 | r21426 | |
| 359 | 359 | |
| 360 | 360 | |
| 361 | 361 | |
| 362 | | static READ8_HANDLER ( to7_5p14sd_r ) |
| 362 | READ8_MEMBER( thomson_state::to7_5p14sd_r ) |
| 363 | 363 | { |
| 364 | 364 | if ( offset < 8 ) |
| 365 | | return mc6843_r( space.machine().device("mc6843"), space, offset ); |
| 365 | return mc6843_r( machine().device("mc6843"), space, offset ); |
| 366 | 366 | else if ( offset >= 8 && offset <= 9 ) |
| 367 | 367 | return to7_5p14sd_select; |
| 368 | 368 | else |
| 369 | | logerror ( "%f $%04x to7_5p14sd_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 369 | logerror ( "%f $%04x to7_5p14sd_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset ); |
| 370 | 370 | return 0; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | |
| 374 | 374 | |
| 375 | | static WRITE8_HANDLER( to7_5p14sd_w ) |
| 375 | WRITE8_MEMBER( thomson_state::to7_5p14sd_w ) |
| 376 | 376 | { |
| 377 | 377 | if ( offset < 8 ) |
| 378 | | mc6843_w( space.machine().device("mc6843"), space, offset, data ); |
| 378 | mc6843_w( machine().device("mc6843"), space, offset, data ); |
| 379 | 379 | else if ( offset >= 8 && offset <= 9 ) |
| 380 | 380 | { |
| 381 | 381 | /* drive select */ |
| r21425 | r21426 | |
| 406 | 406 | |
| 407 | 407 | if ( drive != -1 ) |
| 408 | 408 | { |
| 409 | | thom_floppy_active( space.machine(), 0 ); |
| 410 | | mc6843_set_drive( space.machine().device("mc6843"), drive ); |
| 411 | | mc6843_set_side( space.machine().device("mc6843"), side ); |
| 409 | thom_floppy_active( 0 ); |
| 410 | mc6843_set_drive( machine().device("mc6843"), drive ); |
| 411 | mc6843_set_side( machine().device("mc6843"), side ); |
| 412 | 412 | LOG(( "%f $%04x to7_5p14sd_w: $%02X set drive=%i side=%i\n", |
| 413 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, drive, side )); |
| 413 | machine().time().as_double(), m_maincpu->pc(), data, drive, side )); |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | 416 | else |
| 417 | 417 | logerror ( "%f $%04x to7_5p14sd_w: invalid write offset %i (data=$%02X)\n", |
| 418 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 418 | machine().time().as_double(), m_maincpu->pc(), offset, data ); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | | static void to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state ) |
| 421 | void thomson_state::to7_5p14_index_pulse_callback( device_t *controller,device_t *image, int state ) |
| 422 | 422 | { |
| 423 | | mc6843_set_index_pulse( image->machine().device("mc6843"), state ); |
| 423 | mc6843_set_index_pulse( machine().device("mc6843"), state ); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | | static void to7_5p14sd_reset( running_machine &machine ) |
| 426 | void thomson_state::to7_5p14sd_reset() |
| 427 | 427 | { |
| 428 | 428 | int i; |
| 429 | 429 | LOG(( "to7_5p14sd_reset: CD 90-015 controller\n" )); |
| 430 | | for ( i = 0; i < floppy_get_count( machine ); i++ ) |
| 430 | for ( i = 0; i < floppy_get_count( machine() ); i++ ) |
| 431 | 431 | { |
| 432 | | device_t * img = floppy_get_device( machine, i ); |
| 432 | device_t * img = floppy_get_device( machine(), i ); |
| 433 | 433 | if (img) { |
| 434 | 434 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 435 | 435 | floppy_drive_set_rpm( img, 300. ); |
| r21425 | r21426 | |
| 444 | 444 | |
| 445 | 445 | |
| 446 | 446 | |
| 447 | | static void to7_5p14sd_init( running_machine &machine ) |
| 447 | void thomson_state::to7_5p14sd_init() |
| 448 | 448 | { |
| 449 | 449 | LOG(( "to7_5p14sd_init: CD 90-015 controller\n" )); |
| 450 | | state_save_register_global( machine, to7_5p14sd_select ); |
| 450 | state_save_register_global( machine(), to7_5p14sd_select ); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
| r21425 | r21426 | |
| 520 | 520 | |
| 521 | 521 | |
| 522 | 522 | |
| 523 | | static void to7_qdd_index_pulse_cb ( device_t *controller,device_t *image, int state ) |
| 523 | void thomson_state::to7_qdd_index_pulse_cb( device_t *controller,device_t *image, int state ) |
| 524 | 524 | { |
| 525 | 525 | to7qdd->index_pulse = state; |
| 526 | 526 | |
| r21425 | r21426 | |
| 532 | 532 | to7qdd->data_size = 0; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | | VLOG(( "%f to7_qdd_pulse_cb: state=%i\n", image->machine().time().as_double(), state )); |
| 535 | VLOG(( "%f to7_qdd_pulse_cb: state=%i\n", machine().time().as_double(), state )); |
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
| 539 | 539 | |
| 540 | | static device_t * to7_qdd_image ( running_machine &machine ) |
| 540 | device_t * thomson_state::to7_qdd_image() |
| 541 | 541 | { |
| 542 | | return floppy_get_device( machine, 0 ); |
| 542 | return floppy_get_device( machine(), 0 ); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | |
| 546 | 546 | |
| 547 | 547 | /* update MC6852 status register */ |
| 548 | | static void to7_qdd_stat_update( running_machine &machine ) |
| 548 | void thomson_state::to7_qdd_stat_update() |
| 549 | 549 | { |
| 550 | 550 | /* byte-ready */ |
| 551 | 551 | to7qdd->status |= QDD_S_RDA | QDD_S_TDRA; |
| r21425 | r21426 | |
| 553 | 553 | to7qdd->status |= QDD_S_PE; |
| 554 | 554 | |
| 555 | 555 | /* write-protect */ |
| 556 | | if (floppy_wpt_r(to7_qdd_image(machine)) == CLEAR_LINE) |
| 556 | if (floppy_wpt_r(to7_qdd_image()) == CLEAR_LINE) |
| 557 | 557 | to7qdd->status |= QDD_S_NCTS; |
| 558 | 558 | |
| 559 | 559 | /* sticky reset conditions */ |
| r21425 | r21426 | |
| 577 | 577 | |
| 578 | 578 | |
| 579 | 579 | |
| 580 | | static UINT8 to7_qdd_read_byte( running_machine &machine ) |
| 580 | UINT8 thomson_state::to7_qdd_read_byte() |
| 581 | 581 | { |
| 582 | 582 | UINT8 data; |
| 583 | 583 | |
| 584 | 584 | /* rebuild disk if needed */ |
| 585 | 585 | if ( !to7qdd->data_size ) |
| 586 | 586 | { |
| 587 | | to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(machine), to7qdd->data ); |
| 587 | to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(), to7qdd->data ); |
| 588 | 588 | assert( to7qdd->data_idx < sizeof( to7qdd->data ) ); |
| 589 | 589 | } |
| 590 | 590 | |
| r21425 | r21426 | |
| 594 | 594 | data = to7qdd->data[ to7qdd->data_idx ]; |
| 595 | 595 | |
| 596 | 596 | VLOG(( "%f $%04x to7_qdd_read_byte: RDATA off=%i/%i data=$%02X\n", |
| 597 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), |
| 597 | machine().time().as_double(), m_maincpu->pc(), |
| 598 | 598 | to7qdd->data_idx, to7qdd->data_size, data )); |
| 599 | 599 | |
| 600 | 600 | to7qdd->data_idx++; |
| r21425 | r21426 | |
| 610 | 610 | * CPU write id field and data field => format |
| 611 | 611 | * CPU write data field after it has read an id field => sector write |
| 612 | 612 | */ |
| 613 | | static void to7_qdd_write_byte( running_machine &machine, UINT8 data ) |
| 613 | void thomson_state::to7_qdd_write_byte( UINT8 data ) |
| 614 | 614 | { |
| 615 | 615 | int i; |
| 616 | 616 | |
| 617 | 617 | /* rebuild disk if needed */ |
| 618 | 618 | if ( !to7qdd->data_size ) |
| 619 | 619 | { |
| 620 | | to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(machine), to7qdd->data ); |
| 620 | to7qdd->data_size = thom_qdd_make_disk( to7_qdd_image(), to7qdd->data ); |
| 621 | 621 | assert( to7qdd->data_idx < sizeof( to7qdd->data ) ); |
| 622 | 622 | } |
| 623 | 623 | |
| r21425 | r21426 | |
| 634 | 634 | to7qdd->data_idx++; |
| 635 | 635 | |
| 636 | 636 | VLOG (( "%f $%04x to7_qdd_write_byte: got $%02X offs=%i-%i\n", |
| 637 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data, |
| 637 | machine().time().as_double(), m_maincpu->pc(), data, |
| 638 | 638 | to7qdd->start_idx, to7qdd->data_idx )); |
| 639 | 639 | |
| 640 | 640 | /* end of tentative id field */ |
| r21425 | r21426 | |
| 647 | 647 | UINT8 filler = 0xff; |
| 648 | 648 | |
| 649 | 649 | LOG(( "%f $%04x to7_qdd_write_byte: got id field for sector=%i\n", |
| 650 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector )); |
| 650 | machine().time().as_double(), m_maincpu->pc(), sector )); |
| 651 | 651 | |
| 652 | | floppy_drive_format_sector( to7_qdd_image(machine), |
| 652 | floppy_drive_format_sector( to7_qdd_image(), |
| 653 | 653 | 0, sector, 0, 0, sector, 128, filler ); |
| 654 | | thom_floppy_active( machine, 1 ); |
| 654 | thom_floppy_active( 1 ); |
| 655 | 655 | to7qdd->start_idx = to7qdd->data_idx; |
| 656 | 656 | } |
| 657 | 657 | |
| r21425 | r21426 | |
| 676 | 676 | int sector = (int) to7qdd->data[ i + 1 ] * 256 + (int) to7qdd->data[ i + 2 ]; |
| 677 | 677 | |
| 678 | 678 | LOG(( "%f $%04x to7_qdd_write_byte: goto data field for sector=%i\n", |
| 679 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector )); |
| 679 | machine().time().as_double(), m_maincpu->pc(), sector )); |
| 680 | 680 | |
| 681 | | floppy_drive_write_sector_data( to7_qdd_image(machine), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 ); |
| 682 | | thom_floppy_active( machine, 1 ); |
| 681 | floppy_drive_write_sector_data( to7_qdd_image(), 0, sector, to7qdd->data + to7qdd->start_idx + 1, 128, 0 ); |
| 682 | thom_floppy_active( 1 ); |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | to7qdd->start_idx = to7qdd->data_idx; |
| r21425 | r21426 | |
| 691 | 691 | |
| 692 | 692 | |
| 693 | 693 | |
| 694 | | static READ8_HANDLER ( to7_qdd_r ) |
| 694 | READ8_MEMBER( thomson_state::to7_qdd_r ) |
| 695 | 695 | { |
| 696 | 696 | switch ( offset ) |
| 697 | 697 | { |
| 698 | 698 | case 0: /* MC6852 status */ |
| 699 | | to7_qdd_stat_update(space.machine()); |
| 699 | to7_qdd_stat_update(); |
| 700 | 700 | VLOG(( "%f $%04x to7_qdd_r: STAT=$%02X irq=%i pe=%i ovr=%i und=%i tr=%i rd=%i ncts=%i\n", |
| 701 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), to7qdd->status, |
| 701 | machine().time().as_double(), m_maincpu->pc(), to7qdd->status, |
| 702 | 702 | to7qdd->status & QDD_S_IRQ ? 1 : 0, |
| 703 | 703 | to7qdd->status & QDD_S_PE ? 1 : 0, |
| 704 | 704 | to7qdd->status & QDD_S_OVR ? 1 : 0, |
| r21425 | r21426 | |
| 710 | 710 | |
| 711 | 711 | case 1: /* MC6852 data input => read byte from disk */ |
| 712 | 712 | to7qdd->status &= ~(QDD_S_RDA | QDD_S_PE | QDD_S_OVR); |
| 713 | | to7_qdd_stat_update(space.machine()); |
| 714 | | return to7_qdd_read_byte(space.machine()); |
| 713 | to7_qdd_stat_update(); |
| 714 | return to7_qdd_read_byte(); |
| 715 | 715 | |
| 716 | 716 | case 8: /* floppy status */ |
| 717 | 717 | { |
| 718 | 718 | UINT8 data = 0; |
| 719 | | device_image_interface* img = dynamic_cast<device_image_interface *>(to7_qdd_image(space.machine())); |
| 719 | device_image_interface* img = dynamic_cast<device_image_interface *>(to7_qdd_image()); |
| 720 | 720 | if ( ! img->exists() ) |
| 721 | 721 | data |= 0x40; /* disk present */ |
| 722 | 722 | if ( to7qdd->index_pulse ) |
| 723 | 723 | data |= 0x80; /* disk start */ |
| 724 | | VLOG(( "%f $%04x to7_qdd_r: STATUS8 $%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 724 | VLOG(( "%f $%04x to7_qdd_r: STATUS8 $%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 725 | 725 | return data; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | default: |
| 729 | | logerror ( "%f $%04x to7_qdd_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 729 | logerror ( "%f $%04x to7_qdd_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset ); |
| 730 | 730 | return 0; |
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | |
| 735 | 735 | |
| 736 | | static WRITE8_HANDLER( to7_qdd_w ) |
| 736 | WRITE8_MEMBER( thomson_state::to7_qdd_w ) |
| 737 | 737 | { |
| 738 | 738 | switch ( offset ) |
| 739 | 739 | { |
| r21425 | r21426 | |
| 745 | 745 | to7qdd->status &= ~(QDD_S_TDRA | QDD_S_TUF); |
| 746 | 746 | |
| 747 | 747 | to7qdd->ctrl1 = ( data & ~(QDD_C1_RRESET | QDD_C1_TRESET) ) |( data & (QDD_C1_RRESET | QDD_C1_TRESET) & to7qdd->ctrl1 ); |
| 748 | | to7_qdd_stat_update(space.machine()); |
| 748 | to7_qdd_stat_update(); |
| 749 | 749 | VLOG(( "%f $%04x to7_qdd_w: CTRL1=$%02X reset=%c%c %s%sirq=%c%c\n", |
| 750 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 750 | machine().time().as_double(), m_maincpu->pc(), data, |
| 751 | 751 | data & QDD_C1_RRESET ? 'r' : '-', data & QDD_C1_TRESET ? 't' : '-', |
| 752 | 752 | data & QDD_C1_STRIPSYNC ? "strip-sync " : "", |
| 753 | 753 | data & QDD_C1_CLRSYNC ? "clear-sync " : "", |
| r21425 | r21426 | |
| 770 | 770 | parity = par[ (data >> 3) & 7 ]; |
| 771 | 771 | to7_qdd_stat_update(space.machine()); |
| 772 | 772 | VLOG(( "%f $%04x to7_qdd_w: CTRL2=$%02X bits=%i par=%s blen=%i under=%s%s\n", |
| 773 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 773 | machine().time().as_double(), m_maincpu->pc(), data, |
| 774 | 774 | bits, parname[ parity ], data & QDD_C2_BLEN ? 1 : 2, |
| 775 | 775 | data & QDD_C2_TSYNC ? "sync" : "ff", |
| 776 | 776 | data & QDD_C2_EIE ? "irq-err" : "" )); |
| r21425 | r21426 | |
| 786 | 786 | to7qdd->status &= ~QDD_S_TUF; |
| 787 | 787 | if ( data & QDD_C3_CLRCTS ) |
| 788 | 788 | to7qdd->status &= ~QDD_S_NCTS; |
| 789 | | to7_qdd_stat_update(space.machine()); |
| 789 | to7_qdd_stat_update(); |
| 790 | 790 | VLOG(( "%f $%04x to7_qdd_w: CTRL3=$%02X %s%ssync-len=%i sync-mode=%s\n", |
| 791 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 791 | machine().time().as_double(), m_maincpu->pc(), data, |
| 792 | 792 | data & QDD_C3_CLRTUF ? "clr-tuf " : "", |
| 793 | 793 | data & QDD_C3_CLRCTS ? "clr-cts " : "", |
| 794 | 794 | data & QDD_C3_SYNCLEN ? 1 : 2, |
| r21425 | r21426 | |
| 796 | 796 | break; |
| 797 | 797 | |
| 798 | 798 | case 2: /* MC6852 sync code => write byte to disk */ |
| 799 | | to7_qdd_write_byte( space.machine(), data ); |
| 799 | to7_qdd_write_byte( data ); |
| 800 | 800 | break; |
| 801 | 801 | |
| 802 | 802 | case 3: /* MC6852 data out => does not seem to be used */ |
| 803 | | VLOG(( "%f $%04x to7_qdd_w: ignored WDATA=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 803 | VLOG(( "%f $%04x to7_qdd_w: ignored WDATA=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 804 | 804 | break; |
| 805 | 805 | |
| 806 | 806 | } |
| r21425 | r21426 | |
| 808 | 808 | |
| 809 | 809 | case 8: /* set drive */ |
| 810 | 810 | to7qdd->drive = data; |
| 811 | | VLOG(( "%f $%04x to7_qdd_w: DRIVE=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 811 | VLOG(( "%f $%04x to7_qdd_w: DRIVE=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 812 | 812 | break; |
| 813 | 813 | |
| 814 | 814 | case 12: /* motor pulse ? */ |
| 815 | | thom_floppy_active( space.machine(), 0 ); |
| 816 | | VLOG(( "%f $%04x to7_qdd_w: MOTOR=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 815 | thom_floppy_active( 0 ); |
| 816 | VLOG(( "%f $%04x to7_qdd_w: MOTOR=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 817 | 817 | break; |
| 818 | 818 | |
| 819 | 819 | default: |
| 820 | | logerror ( "%f $%04x to7_qdd_w: invalid write offset %i (data=$%02X)\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 820 | logerror ( "%f $%04x to7_qdd_w: invalid write offset %i (data=$%02X)\n", machine().time().as_double(), m_maincpu->pc(), offset, data ); |
| 821 | 821 | } |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | |
| 825 | 825 | |
| 826 | | static void to7_qdd_reset( running_machine &machine ) |
| 826 | void thomson_state::to7_qdd_reset() |
| 827 | 827 | { |
| 828 | 828 | int i; |
| 829 | 829 | LOG(( "to7_qdd_reset: CQ 90-028 controller\n" )); |
| 830 | 830 | |
| 831 | | for ( i = 0; i < floppy_get_count( machine ); i++ ) |
| 831 | for ( i = 0; i < floppy_get_count( machine() ); i++ ) |
| 832 | 832 | { |
| 833 | | device_t * img = floppy_get_device( machine, i ); |
| 833 | device_t * img = floppy_get_device( machine(), i ); |
| 834 | 834 | if (img) { |
| 835 | 835 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 836 | 836 | |
| r21425 | r21426 | |
| 847 | 847 | to7qdd->ctrl2 &= 0x7c; /* clear EIE, PC2-PC1 */ |
| 848 | 848 | to7qdd->ctrl3 &= 0xfe; /* internal sync */ |
| 849 | 849 | to7qdd->drive = 0; |
| 850 | | to7_qdd_stat_update(machine); |
| 850 | to7_qdd_stat_update(); |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | |
| 854 | 854 | |
| 855 | | static void to7_qdd_init( running_machine &machine ) |
| 855 | void thomson_state::to7_qdd_init() |
| 856 | 856 | { |
| 857 | 857 | LOG(( "to7_qdd_init: CQ 90-028 controller\n" )); |
| 858 | 858 | |
| 859 | | to7qdd = auto_alloc(machine, to7qdd_t); |
| 859 | to7qdd = auto_alloc(machine(), to7qdd_t); |
| 860 | 860 | |
| 861 | | state_save_register_global( machine, to7qdd->status ); |
| 862 | | state_save_register_global( machine, to7qdd->ctrl1 ); |
| 863 | | state_save_register_global( machine, to7qdd->ctrl2 ); |
| 864 | | state_save_register_global( machine, to7qdd->ctrl3 ); |
| 865 | | state_save_register_global( machine, to7qdd->drive ); |
| 866 | | state_save_register_global( machine, to7qdd->data_idx ); |
| 867 | | state_save_register_global( machine, to7qdd->start_idx ); |
| 868 | | state_save_register_global( machine, to7qdd->data_size ); |
| 869 | | state_save_register_global( machine, to7qdd->data_crc ); |
| 870 | | state_save_register_global( machine, to7qdd->index_pulse ); |
| 871 | | state_save_register_global_array( machine, to7qdd->data ); |
| 861 | state_save_register_global( machine(), to7qdd->status ); |
| 862 | state_save_register_global( machine(), to7qdd->ctrl1 ); |
| 863 | state_save_register_global( machine(), to7qdd->ctrl2 ); |
| 864 | state_save_register_global( machine(), to7qdd->ctrl3 ); |
| 865 | state_save_register_global( machine(), to7qdd->drive ); |
| 866 | state_save_register_global( machine(), to7qdd->data_idx ); |
| 867 | state_save_register_global( machine(), to7qdd->start_idx ); |
| 868 | state_save_register_global( machine(), to7qdd->data_size ); |
| 869 | state_save_register_global( machine(), to7qdd->data_crc ); |
| 870 | state_save_register_global( machine(), to7qdd->index_pulse ); |
| 871 | state_save_register_global_array( machine(), to7qdd->data ); |
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | |
| r21425 | r21426 | |
| 932 | 932 | |
| 933 | 933 | |
| 934 | 934 | |
| 935 | | static device_t * thmfc_floppy_image ( running_machine &machine ) |
| 935 | device_t * thomson_state::thmfc_floppy_image() |
| 936 | 936 | { |
| 937 | | return floppy_get_device( machine, thmfc1->drive ); |
| 937 | return floppy_get_device( machine(), thmfc1->drive ); |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | |
| 941 | 941 | |
| 942 | | static int thmfc_floppy_is_qdd ( device_image_interface *image ) |
| 942 | int thomson_state::thmfc_floppy_is_qdd ( device_image_interface *image ) |
| 943 | 943 | { |
| 944 | 944 | if (image==NULL) return 0; |
| 945 | 945 | if (!image->exists()) return 0; |
| r21425 | r21426 | |
| 948 | 948 | |
| 949 | 949 | |
| 950 | 950 | |
| 951 | | static void thmfc_floppy_index_pulse_cb ( device_t *controller,device_t *image, int state ) |
| 951 | void thomson_state::thmfc_floppy_index_pulse_cb ( device_t *controller,device_t *image, int state ) |
| 952 | 952 | { |
| 953 | | if ( image != thmfc_floppy_image(image->machine())) |
| 953 | if ( image != thmfc_floppy_image()) |
| 954 | 954 | return; |
| 955 | 955 | |
| 956 | 956 | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(image))) |
| r21425 | r21426 | |
| 973 | 973 | thmfc1->data_raw_idx = 0; |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | | VLOG(( "%f thmfc_floppy_index_pulse_cb: state=%i\n", image->machine().time().as_double(), state )); |
| 976 | VLOG(( "%f thmfc_floppy_index_pulse_cb: state=%i\n", machine().time().as_double(), state )); |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | 979 | |
| 980 | 980 | |
| 981 | | static int thmfc_floppy_find_sector ( running_machine &machine, chrn_id* dst ) |
| 981 | int thomson_state::thmfc_floppy_find_sector( chrn_id* dst ) |
| 982 | 982 | { |
| 983 | | device_t* img = thmfc_floppy_image(machine); |
| 983 | device_t* img = thmfc_floppy_image(); |
| 984 | 984 | chrn_id id; |
| 985 | 985 | int r = 0; |
| 986 | 986 | |
| r21425 | r21426 | |
| 1014 | 1014 | |
| 1015 | 1015 | |
| 1016 | 1016 | /* complete command (by read, write, or timeout) */ |
| 1017 | | static void thmfc_floppy_cmd_complete( running_machine &machine ) |
| 1017 | void thomson_state::thmfc_floppy_cmd_complete() |
| 1018 | 1018 | { |
| 1019 | 1019 | LOG (( "%f thmfc_floppy_cmd_complete_cb: cmd=%i off=%i/%i/%i\n", |
| 1020 | | machine.time().as_double(), thmfc1->op, thmfc1->data_idx, |
| 1020 | machine().time().as_double(), thmfc1->op, thmfc1->data_idx, |
| 1021 | 1021 | thmfc1->data_finish - 1, thmfc1->data_size - 1 )); |
| 1022 | 1022 | |
| 1023 | 1023 | if ( thmfc1->op == THMFC1_OP_WRITE_SECT ) |
| 1024 | 1024 | { |
| 1025 | | device_t * img = thmfc_floppy_image(machine); |
| 1025 | device_t * img = thmfc_floppy_image(); |
| 1026 | 1026 | floppy_drive_write_sector_data( img, thmfc1->side, thmfc1->sector_id, thmfc1->data + 3, thmfc1->data_size - 3, 0 ); |
| 1027 | | thom_floppy_active( machine, 1 ); |
| 1027 | thom_floppy_active( 1 ); |
| 1028 | 1028 | } |
| 1029 | 1029 | thmfc1->op = THMFC1_OP_RESET; |
| 1030 | 1030 | thmfc1->stat0 |= THMFC1_STAT0_FINISHED; |
| r21425 | r21426 | |
| 1035 | 1035 | |
| 1036 | 1036 | |
| 1037 | 1037 | |
| 1038 | | static TIMER_CALLBACK( thmfc_floppy_cmd_complete_cb ) |
| 1038 | TIMER_CALLBACK_MEMBER( thomson_state::thmfc_floppy_cmd_complete_cb ) |
| 1039 | 1039 | { |
| 1040 | | thmfc_floppy_cmd_complete( machine ); |
| 1040 | thmfc_floppy_cmd_complete(); |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | |
| 1044 | 1044 | |
| 1045 | 1045 | /* intelligent read: show just one field, skip header */ |
| 1046 | | static UINT8 thmfc_floppy_read_byte ( running_machine &machine ) |
| 1046 | UINT8 thomson_state::thmfc_floppy_read_byte() |
| 1047 | 1047 | { |
| 1048 | 1048 | UINT8 data = thmfc1->data[ thmfc1->data_idx ]; |
| 1049 | 1049 | |
| 1050 | 1050 | VLOG(( "%f $%04x thmfc_floppy_read_byte: off=%i/%i/%i data=$%02X\n", |
| 1051 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), |
| 1051 | machine().time().as_double(), m_maincpu->pc(), |
| 1052 | 1052 | thmfc1->data_idx, thmfc1->data_finish - 1, thmfc1->data_size - 1, |
| 1053 | 1053 | data )); |
| 1054 | 1054 | |
| 1055 | 1055 | if ( thmfc1->data_idx >= thmfc1->data_size - 1 ) |
| 1056 | | thmfc_floppy_cmd_complete( machine ); |
| 1056 | thmfc_floppy_cmd_complete(); |
| 1057 | 1057 | else |
| 1058 | 1058 | thmfc1->data_idx++; |
| 1059 | 1059 | |
| r21425 | r21426 | |
| 1066 | 1066 | |
| 1067 | 1067 | |
| 1068 | 1068 | /* dumb read: show whole track with field headers and gaps */ |
| 1069 | | static UINT8 thmfc_floppy_raw_read_byte ( running_machine &machine ) |
| 1069 | UINT8 thomson_state::thmfc_floppy_raw_read_byte() |
| 1070 | 1070 | { |
| 1071 | 1071 | UINT8 data; |
| 1072 | 1072 | |
| 1073 | 1073 | /* rebuild track if needed */ |
| 1074 | 1074 | if ( ! thmfc1->data_raw_size ) |
| 1075 | 1075 | { |
| 1076 | | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image(machine)))) |
| 1076 | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image()))) |
| 1077 | 1077 | /* QDD: track = whole disk */ |
| 1078 | | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(machine), thmfc1->data ); |
| 1078 | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data ); |
| 1079 | 1079 | else |
| 1080 | 1080 | { |
| 1081 | 1081 | thmfc1->data_raw_idx = 0; |
| 1082 | | thmfc1->data_raw_size = thom_floppy_make_track( thmfc_floppy_image(machine), thmfc1->data, |
| 1082 | thmfc1->data_raw_size = thom_floppy_make_track( thmfc_floppy_image(), thmfc1->data, |
| 1083 | 1083 | thmfc1->sector_size, thmfc1->side ); |
| 1084 | 1084 | } |
| 1085 | 1085 | assert( thmfc1->data_raw_size < sizeof( thmfc1->data ) ); |
| r21425 | r21426 | |
| 1091 | 1091 | data = thmfc1->data[ thmfc1->data_raw_idx ]; |
| 1092 | 1092 | |
| 1093 | 1093 | VLOG(( "%f $%04x thmfc_floppy_raw_read_byte: off=%i/%i data=$%02X\n", |
| 1094 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), |
| 1094 | machine().time().as_double(), m_maincpu->pc(), |
| 1095 | 1095 | thmfc1->data_raw_idx, thmfc1->data_raw_size, data )); |
| 1096 | 1096 | |
| 1097 | 1097 | thmfc1->data_raw_idx++; |
| r21425 | r21426 | |
| 1102 | 1102 | |
| 1103 | 1103 | |
| 1104 | 1104 | /* QDD writing / formating */ |
| 1105 | | static void thmfc_floppy_qdd_write_byte ( running_machine &machine, UINT8 data ) |
| 1105 | void thomson_state::thmfc_floppy_qdd_write_byte( UINT8 data ) |
| 1106 | 1106 | { |
| 1107 | 1107 | int i; |
| 1108 | 1108 | |
| r21425 | r21426 | |
| 1112 | 1112 | { |
| 1113 | 1113 | if ( ! thmfc1->data_raw_size ) |
| 1114 | 1114 | { |
| 1115 | | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(machine), thmfc1->data ); |
| 1115 | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data ); |
| 1116 | 1116 | assert( thmfc1->data_raw_size < sizeof( thmfc1->data ) ); |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| r21425 | r21426 | |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | VLOG (( "%f $%04x thmfc_floppy_qdd_write_byte: $%02X offs=%i-%i\n", |
| 1131 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data, |
| 1131 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1132 | 1132 | thmfc1->data_idx,thmfc1->data_raw_idx )); |
| 1133 | 1133 | |
| 1134 | 1134 | if ( thmfc1->data_raw_idx == thmfc1->data_idx + 3 && |
| r21425 | r21426 | |
| 1139 | 1139 | int sector = (int) thmfc1->data[ thmfc1->data_idx ] * 256 + (int) thmfc1->data[ thmfc1->data_idx + 1 ]; |
| 1140 | 1140 | UINT8 filler = 0xff; |
| 1141 | 1141 | |
| 1142 | | LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector )); |
| 1142 | LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: id field, sector=%i\n", machine().time().as_double(), m_maincpu->pc(), sector )); |
| 1143 | 1143 | |
| 1144 | | floppy_drive_format_sector( thmfc_floppy_image(machine), 0, sector, 0, 0, sector, 128, filler ); |
| 1145 | | thom_floppy_active( machine, 1 ); |
| 1144 | floppy_drive_format_sector( thmfc_floppy_image(), 0, sector, 0, 0, sector, 128, filler ); |
| 1145 | thom_floppy_active( 1 ); |
| 1146 | 1146 | thmfc1->data_idx = 0; |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| r21425 | r21426 | |
| 1163 | 1163 | if ( i >= 0 ) |
| 1164 | 1164 | { |
| 1165 | 1165 | /* got an id & a data field => write */ |
| 1166 | | device_t * img = thmfc_floppy_image(machine); |
| 1166 | device_t * img = thmfc_floppy_image(); |
| 1167 | 1167 | int sector = (int) thmfc1->data[ i + 1 ] * 256 + |
| 1168 | 1168 | (int) thmfc1->data[ i + 2 ]; |
| 1169 | 1169 | |
| 1170 | 1170 | LOG(( "%f $%04x thmfc_floppy_qdd_write_byte: data field, sector=%i\n", |
| 1171 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), sector )); |
| 1171 | machine().time().as_double(), m_maincpu->pc(), sector )); |
| 1172 | 1172 | |
| 1173 | 1173 | floppy_drive_write_sector_data( img, 0, sector, thmfc1->data + thmfc1->data_idx, 128, 0 ); |
| 1174 | | thom_floppy_active( machine, 1 ); |
| 1174 | thom_floppy_active( 1 ); |
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | thmfc1->data_idx = 0; |
| r21425 | r21426 | |
| 1183 | 1183 | else |
| 1184 | 1184 | { |
| 1185 | 1185 | thmfc1->data_raw_idx++; |
| 1186 | | VLOG (( "%f $%04x thmfc_floppy_qdd_write_byte: ignored $%02X\n", machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data )); |
| 1186 | VLOG (( "%f $%04x thmfc_floppy_qdd_write_byte: ignored $%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | } |
| r21425 | r21426 | |
| 1191 | 1191 | |
| 1192 | 1192 | |
| 1193 | 1193 | /* intelligent writing */ |
| 1194 | | static void thmfc_floppy_write_byte ( running_machine &machine, UINT8 data ) |
| 1194 | void thomson_state::thmfc_floppy_write_byte( UINT8 data ) |
| 1195 | 1195 | { |
| 1196 | 1196 | VLOG (( "%f $%04x thmfc_floppy_write_byte: off=%i/%i data=$%02X\n", |
| 1197 | | machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), |
| 1197 | machine().time().as_double(), m_maincpu->pc(), |
| 1198 | 1198 | thmfc1->data_idx, thmfc1->data_size - 1, data )); |
| 1199 | 1199 | |
| 1200 | 1200 | thmfc1->data_raw_size = 0; |
| 1201 | 1201 | thmfc1->data[ thmfc1->data_idx ] = data; |
| 1202 | 1202 | if ( thmfc1->data_idx >= thmfc1->data_size - 1 ) |
| 1203 | | thmfc_floppy_cmd_complete( machine ); |
| 1203 | thmfc_floppy_cmd_complete(); |
| 1204 | 1204 | else |
| 1205 | 1205 | thmfc1->data_idx++; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | /* intelligent formatting */ |
| 1209 | | static void thmfc_floppy_format_byte ( running_machine &machine, UINT8 data ) |
| 1209 | void thomson_state::thmfc_floppy_format_byte( UINT8 data ) |
| 1210 | 1210 | { |
| 1211 | | VLOG (( "%f $%04x thmfc_floppy_format_byte: $%02X\n", machine.time().as_double(), machine.device("maincpu")->safe_pcbase(), data )); |
| 1211 | VLOG (( "%f $%04x thmfc_floppy_format_byte: $%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 1212 | 1212 | |
| 1213 | 1213 | thmfc1->data_raw_size = 0; |
| 1214 | 1214 | |
| r21425 | r21426 | |
| 1223 | 1223 | if ( !memcmp ( thmfc1->data, header, sizeof( header ) ) ) |
| 1224 | 1224 | { |
| 1225 | 1225 | /* got id field => format */ |
| 1226 | | device_t * img = thmfc_floppy_image(machine); |
| 1226 | device_t * img = thmfc_floppy_image(); |
| 1227 | 1227 | UINT8 track = thmfc1->data[4]; |
| 1228 | 1228 | UINT8 side = thmfc1->data[5]; |
| 1229 | 1229 | UINT8 sector = thmfc1->data[6]; |
| 1230 | 1230 | UINT8 length = thmfc1->data[7]; /* actually, log length */ |
| 1231 | 1231 | UINT8 filler = 0xe5; /* standard Thomson filler */ |
| 1232 | 1232 | chrn_id id; |
| 1233 | | if ( thmfc_floppy_find_sector( machine, &id ) ) |
| 1233 | if ( thmfc_floppy_find_sector( &id ) ) |
| 1234 | 1234 | { |
| 1235 | 1235 | floppy_drive_format_sector( img, side, thmfc1->sector_id, track, thmfc1->side, sector, length, filler ); |
| 1236 | | thom_floppy_active( machine, 1 ); |
| 1236 | thom_floppy_active( 1 ); |
| 1237 | 1237 | } |
| 1238 | 1238 | } |
| 1239 | 1239 | |
| r21425 | r21426 | |
| 1245 | 1245 | |
| 1246 | 1246 | |
| 1247 | 1247 | |
| 1248 | | READ8_HANDLER ( thmfc_floppy_r ) |
| 1248 | READ8_MEMBER( thomson_state::thmfc_floppy_r ) |
| 1249 | 1249 | { |
| 1250 | 1250 | switch ( offset ) |
| 1251 | 1251 | { |
| 1252 | 1252 | case 0: /* STAT0 */ |
| 1253 | 1253 | thmfc1->stat0 ^= THMFC1_STAT0_SYNCHRO | THMFC1_STAT0_BYTE_READY_POL; |
| 1254 | | VLOG(( "%f $%04x thmfc_floppy_r: STAT0=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), thmfc1->stat0 )); |
| 1254 | VLOG(( "%f $%04x thmfc_floppy_r: STAT0=$%02X\n", machine().time().as_double(), m_maincpu->pc(), thmfc1->stat0 )); |
| 1255 | 1255 | return thmfc1->stat0; |
| 1256 | 1256 | |
| 1257 | 1257 | case 1: /* STAT1 */ |
| 1258 | 1258 | { |
| 1259 | 1259 | UINT8 data = 0; |
| 1260 | | device_image_interface * img = dynamic_cast<device_image_interface *>(thmfc_floppy_image(space.machine())); |
| 1260 | device_image_interface * img = dynamic_cast<device_image_interface *>(thmfc_floppy_image()); |
| 1261 | 1261 | int flags = floppy_drive_get_flag_state( &img->device(), -1 ); |
| 1262 | 1262 | if ( thmfc_floppy_is_qdd(img) ) |
| 1263 | 1263 | { |
| r21425 | r21426 | |
| 1283 | 1283 | data |= 0x10; |
| 1284 | 1284 | if (!floppy_wpt_r(&img->device())) |
| 1285 | 1285 | data |= 0x04; |
| 1286 | | VLOG(( "%f $%04x thmfc_floppy_r: STAT1=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 1286 | VLOG(( "%f $%04x thmfc_floppy_r: STAT1=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 1287 | 1287 | return data; |
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | case 3: /* RDATA */ |
| 1291 | 1291 | |
| 1292 | 1292 | if ( thmfc1->op == THMFC1_OP_READ_SECT || thmfc1->op == THMFC1_OP_READ_ADDR ) |
| 1293 | | return thmfc_floppy_read_byte(space.machine()); |
| 1293 | return thmfc_floppy_read_byte(); |
| 1294 | 1294 | else |
| 1295 | | return thmfc_floppy_raw_read_byte(space.machine()); |
| 1295 | return thmfc_floppy_raw_read_byte(); |
| 1296 | 1296 | |
| 1297 | 1297 | case 6: |
| 1298 | 1298 | return 0; |
| r21425 | r21426 | |
| 1301 | 1301 | { |
| 1302 | 1302 | /* undocumented => emulate TO7 QDD controller ? */ |
| 1303 | 1303 | UINT8 data = thmfc1->ipl << 7; |
| 1304 | | VLOG(( "%f $%04x thmfc_floppy_r: STAT8=$%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 1304 | VLOG(( "%f $%04x thmfc_floppy_r: STAT8=$%02X\n", machine().time().as_double(), m_maincpu->pc(), data )); |
| 1305 | 1305 | return data; |
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | default: |
| 1309 | | logerror ( "%f $%04x thmfc_floppy_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 1309 | logerror ( "%f $%04x thmfc_floppy_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset ); |
| 1310 | 1310 | return 0; |
| 1311 | 1311 | } |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | |
| 1315 | 1315 | |
| 1316 | | WRITE8_HANDLER ( thmfc_floppy_w ) |
| 1316 | WRITE8_MEMBER( thomson_state::thmfc_floppy_w ) |
| 1317 | 1317 | { |
| 1318 | 1318 | switch ( offset ) { |
| 1319 | 1319 | case 0: /* CMD0 */ |
| 1320 | 1320 | { |
| 1321 | 1321 | int wsync = (data >> 4) & 1; |
| 1322 | | int qdd = thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image(space.machine()))); |
| 1322 | int qdd = thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image())); |
| 1323 | 1323 | chrn_id id; |
| 1324 | 1324 | thmfc1->formatting = (data >> 2) & 1; |
| 1325 | 1325 | LOG (( "%f $%04x thmfc_floppy_w: CMD0=$%02X dens=%s wsync=%i dsync=%i fmt=%i op=%i\n", |
| 1326 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 1326 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1327 | 1327 | (BIT(data, 5) ? "FM" : "MFM"), |
| 1328 | 1328 | wsync, (data >> 3) & 1, |
| 1329 | 1329 | thmfc1->formatting, data & 3 )); |
| r21425 | r21426 | |
| 1341 | 1341 | case THMFC1_OP_WRITE_SECT: |
| 1342 | 1342 | if ( qdd ) |
| 1343 | 1343 | logerror( "thmfc_floppy_w: smart operation 1 not supported for QDD\n" ); |
| 1344 | | else if ( thmfc_floppy_find_sector( space.machine(), &id ) ) |
| 1344 | else if ( thmfc_floppy_find_sector( &id ) ) |
| 1345 | 1345 | { |
| 1346 | 1346 | thmfc1->sector_id = id.data_id; |
| 1347 | 1347 | thmfc1->data_idx = 0; |
| r21425 | r21426 | |
| 1356 | 1356 | case THMFC1_OP_READ_ADDR: |
| 1357 | 1357 | if ( qdd ) |
| 1358 | 1358 | logerror( "thmfc_floppy_w: smart operation 2 not supported for QDD\n" ); |
| 1359 | | else if ( thmfc_floppy_find_sector( space.machine(), &id ) ) |
| 1359 | else if ( thmfc_floppy_find_sector( &id ) ) |
| 1360 | 1360 | { |
| 1361 | 1361 | thmfc1->data_size = |
| 1362 | 1362 | thom_floppy_make_addr( id, thmfc1->data, thmfc1->sector_size ); |
| r21425 | r21426 | |
| 1372 | 1372 | case THMFC1_OP_READ_SECT: |
| 1373 | 1373 | if ( qdd ) |
| 1374 | 1374 | logerror( "thmfc_floppy_w: smart operation 3 not supported for QDD\n" ); |
| 1375 | | else if ( thmfc_floppy_find_sector( space.machine(), &id ) ) |
| 1375 | else if ( thmfc_floppy_find_sector( &id ) ) |
| 1376 | 1376 | { |
| 1377 | 1377 | thmfc1->data_size = thom_floppy_make_sector |
| 1378 | | ( thmfc_floppy_image(space.machine()), id, thmfc1->data, thmfc1->sector_size ); |
| 1378 | ( thmfc_floppy_image(), id, thmfc1->data, thmfc1->sector_size ); |
| 1379 | 1379 | assert( thmfc1->data_size < sizeof( thmfc1->data ) ); |
| 1380 | 1380 | thmfc1->data_finish = thmfc1->sector_size + 4; |
| 1381 | 1381 | thmfc1->data_idx = 1; |
| r21425 | r21426 | |
| 1389 | 1389 | /* synchronize to word, if needed (QDD only) */ |
| 1390 | 1390 | if ( wsync && qdd ) { |
| 1391 | 1391 | if ( ! thmfc1->data_raw_size ) |
| 1392 | | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(space.machine()), thmfc1->data ); |
| 1392 | thmfc1->data_raw_size = thom_qdd_make_disk ( thmfc_floppy_image(), thmfc1->data ); |
| 1393 | 1393 | while ( thmfc1->data_raw_idx < thmfc1->data_raw_size && |
| 1394 | 1394 | thmfc1->data[ thmfc1->data_raw_idx ] != thmfc1->wsync ) |
| 1395 | 1395 | { |
| r21425 | r21426 | |
| 1408 | 1408 | if ( thmfc1->sector_size > 256 ) |
| 1409 | 1409 | { |
| 1410 | 1410 | logerror( "$%04x thmfc_floppy_w: sector size %i > 256 not handled\n", |
| 1411 | | space.machine().device("maincpu")->safe_pcbase(), thmfc1->sector_size ); |
| 1411 | m_maincpu->pc(), thmfc1->sector_size ); |
| 1412 | 1412 | thmfc1->sector_size = 256; |
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | LOG (( "%f $%04x thmfc_floppy_w: CMD1=$%02X sect-size=%i comp=%i head=%i\n", |
| 1416 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 1416 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1417 | 1417 | thmfc1->sector_size, (data >> 1) & 7, thmfc1->side )); |
| 1418 | 1418 | break; |
| 1419 | 1419 | |
| r21425 | r21426 | |
| 1424 | 1424 | int seek = 0, motor; |
| 1425 | 1425 | thmfc1->drive = data & 2; |
| 1426 | 1426 | |
| 1427 | | img = thmfc_floppy_image(space.machine()); |
| 1427 | img = thmfc_floppy_image(); |
| 1428 | 1428 | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(img))) |
| 1429 | 1429 | { |
| 1430 | 1430 | motor = !(data & 0x40); |
| r21425 | r21426 | |
| 1436 | 1436 | seek = (data & 0x20) ? 1 : -1; |
| 1437 | 1437 | motor = (data >> 2) & 1; |
| 1438 | 1438 | thmfc1->drive |= 1 ^ ((data >> 6) & 1); |
| 1439 | | img = thmfc_floppy_image(space.machine()); |
| 1439 | img = thmfc_floppy_image(); |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | | thom_floppy_active( space.machine(), 0 ); |
| 1442 | thom_floppy_active( 0 ); |
| 1443 | 1443 | |
| 1444 | 1444 | LOG (( "%f $%04x thmfc_floppy_w: CMD2=$%02X drv=%i step=%i motor=%i\n", |
| 1445 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 1445 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1446 | 1446 | thmfc1->drive, seek, motor )); |
| 1447 | 1447 | |
| 1448 | 1448 | if ( seek ) |
| r21425 | r21426 | |
| 1463 | 1463 | |
| 1464 | 1464 | case 3: /* WDATA */ |
| 1465 | 1465 | thmfc1->wsync = data; |
| 1466 | | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image(space.machine())))) |
| 1467 | | thmfc_floppy_qdd_write_byte( space.machine(), data ); |
| 1466 | if ( thmfc_floppy_is_qdd(dynamic_cast<device_image_interface *>(thmfc_floppy_image()))) |
| 1467 | thmfc_floppy_qdd_write_byte( data ); |
| 1468 | 1468 | else if ( thmfc1->op==THMFC1_OP_WRITE_SECT ) |
| 1469 | | thmfc_floppy_write_byte( space.machine(), data ); |
| 1469 | thmfc_floppy_write_byte( data ); |
| 1470 | 1470 | else if ( thmfc1->formatting ) |
| 1471 | | thmfc_floppy_format_byte( space.machine(), data ); |
| 1471 | thmfc_floppy_format_byte( data ); |
| 1472 | 1472 | else |
| 1473 | 1473 | { |
| 1474 | 1474 | /* TODO: implement other forms of raw track writing */ |
| 1475 | 1475 | LOG (( "%f $%04x thmfc_floppy_w: ignored raw WDATA $%02X\n", |
| 1476 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 1476 | machine().time().as_double(), m_maincpu->pc(), data )); |
| 1477 | 1477 | } |
| 1478 | 1478 | break; |
| 1479 | 1479 | |
| r21425 | r21426 | |
| 1481 | 1481 | case 4: /* WCLK (unemulated) */ |
| 1482 | 1482 | /* clock configuration: FF for data, 0A for synchro */ |
| 1483 | 1483 | LOG (( "%f $%04x thmfc_floppy_w: WCLK=$%02X (%s)\n", |
| 1484 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 1484 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1485 | 1485 | (data == 0xff) ? "data" : (data == 0x0A) ? "synchro" : "?" )); |
| 1486 | 1486 | break; |
| 1487 | 1487 | |
| 1488 | 1488 | case 5: /* WSECT */ |
| 1489 | 1489 | thmfc1->sector = data; |
| 1490 | 1490 | LOG (( "%f $%04x thmfc_floppy_w: WSECT=%i\n", |
| 1491 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 1491 | machine().time().as_double(), m_maincpu->pc(), data )); |
| 1492 | 1492 | break; |
| 1493 | 1493 | |
| 1494 | 1494 | case 6: /* WTRCK */ |
| 1495 | 1495 | thmfc1->track = data; |
| 1496 | 1496 | LOG (( "%f $%04x thmfc_floppy_w: WTRCK=%i (real=%i)\n", |
| 1497 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data, |
| 1498 | | floppy_drive_get_current_track( thmfc_floppy_image(space.machine()) ) )); |
| 1497 | machine().time().as_double(), m_maincpu->pc(), data, |
| 1498 | floppy_drive_get_current_track( thmfc_floppy_image() ) )); |
| 1499 | 1499 | break; |
| 1500 | 1500 | |
| 1501 | 1501 | case 7: /* WCELL */ |
| 1502 | 1502 | /* precompensation (unemulated) */ |
| 1503 | 1503 | LOG (( "%f $%04x thmfc_floppy_w: WCELL=$%02X\n", |
| 1504 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), data )); |
| 1504 | machine().time().as_double(), m_maincpu->pc(), data )); |
| 1505 | 1505 | break; |
| 1506 | 1506 | |
| 1507 | 1507 | default: |
| 1508 | 1508 | logerror ( "%f $%04x thmfc_floppy_w: invalid write offset %i (data=$%02X)\n", |
| 1509 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 1509 | machine().time().as_double(), m_maincpu->pc(), offset, data ); |
| 1510 | 1510 | } |
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | |
| 1514 | 1514 | |
| 1515 | | void thmfc_floppy_reset( running_machine &machine ) |
| 1515 | void thomson_state::thmfc_floppy_reset() |
| 1516 | 1516 | { |
| 1517 | 1517 | int i; |
| 1518 | 1518 | LOG(( "thmfc_floppy_reset: THMFC1 controller\n" )); |
| 1519 | 1519 | |
| 1520 | | for ( i = 0; i < floppy_get_count( machine ); i++ ) |
| 1520 | for ( i = 0; i < floppy_get_count( machine() ); i++ ) |
| 1521 | 1521 | { |
| 1522 | | device_t * img = floppy_get_device( machine, i ); |
| 1522 | device_t * img = floppy_get_device( machine(), i ); |
| 1523 | 1523 | if (img) { |
| 1524 | 1524 | floppy_drive_set_ready_state( img, FLOPPY_DRIVE_READY, 0 ); |
| 1525 | 1525 | floppy_drive_seek( img, - floppy_drive_get_current_track( img ) ); |
| r21425 | r21426 | |
| 1545 | 1545 | |
| 1546 | 1546 | |
| 1547 | 1547 | |
| 1548 | | void thmfc_floppy_init( running_machine &machine ) |
| 1548 | void thomson_state::thmfc_floppy_init() |
| 1549 | 1549 | { |
| 1550 | 1550 | LOG(( "thmfc_floppy_init: THMFC1 controller\n" )); |
| 1551 | 1551 | |
| 1552 | | thmfc1 = auto_alloc(machine, thmfc1_t); |
| 1552 | thmfc1 = auto_alloc(machine(), thmfc1_t); |
| 1553 | 1553 | |
| 1554 | | thmfc_floppy_cmd = machine.scheduler().timer_alloc(FUNC(thmfc_floppy_cmd_complete_cb)); |
| 1554 | thmfc_floppy_cmd = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::thmfc_floppy_cmd_complete_cb),this)); |
| 1555 | 1555 | |
| 1556 | | state_save_register_global( machine, thmfc1->op ); |
| 1557 | | state_save_register_global( machine, thmfc1->sector ); |
| 1558 | | state_save_register_global( machine, thmfc1->sector_id ); |
| 1559 | | state_save_register_global( machine, thmfc1->track ); |
| 1560 | | state_save_register_global( machine, thmfc1->side ); |
| 1561 | | state_save_register_global( machine, thmfc1->drive ); |
| 1562 | | state_save_register_global( machine, thmfc1->sector_size ); |
| 1563 | | state_save_register_global( machine, thmfc1->formatting ); |
| 1564 | | state_save_register_global( machine, thmfc1->ipl ); |
| 1565 | | state_save_register_global( machine, thmfc1->data_idx ); |
| 1566 | | state_save_register_global( machine, thmfc1->data_size ); |
| 1567 | | state_save_register_global( machine, thmfc1->data_finish ); |
| 1568 | | state_save_register_global( machine, thmfc1->stat0 ); |
| 1569 | | state_save_register_global( machine, thmfc1->data_raw_idx ); |
| 1570 | | state_save_register_global( machine, thmfc1->data_raw_size ); |
| 1571 | | state_save_register_global( machine, thmfc1->data_crc ); |
| 1572 | | state_save_register_global( machine, thmfc1->wsync ); |
| 1573 | | state_save_register_global_array( machine, thmfc1->data ); |
| 1556 | state_save_register_global( machine(), thmfc1->op ); |
| 1557 | state_save_register_global( machine(), thmfc1->sector ); |
| 1558 | state_save_register_global( machine(), thmfc1->sector_id ); |
| 1559 | state_save_register_global( machine(), thmfc1->track ); |
| 1560 | state_save_register_global( machine(), thmfc1->side ); |
| 1561 | state_save_register_global( machine(), thmfc1->drive ); |
| 1562 | state_save_register_global( machine(), thmfc1->sector_size ); |
| 1563 | state_save_register_global( machine(), thmfc1->formatting ); |
| 1564 | state_save_register_global( machine(), thmfc1->ipl ); |
| 1565 | state_save_register_global( machine(), thmfc1->data_idx ); |
| 1566 | state_save_register_global( machine(), thmfc1->data_size ); |
| 1567 | state_save_register_global( machine(), thmfc1->data_finish ); |
| 1568 | state_save_register_global( machine(), thmfc1->stat0 ); |
| 1569 | state_save_register_global( machine(), thmfc1->data_raw_idx ); |
| 1570 | state_save_register_global( machine(), thmfc1->data_raw_size ); |
| 1571 | state_save_register_global( machine(), thmfc1->data_crc ); |
| 1572 | state_save_register_global( machine(), thmfc1->wsync ); |
| 1573 | state_save_register_global_array( machine(), thmfc1->data ); |
| 1574 | 1574 | } |
| 1575 | 1575 | |
| 1576 | 1576 | |
| r21425 | r21426 | |
| 1588 | 1588 | no way to answer the request. |
| 1589 | 1589 | */ |
| 1590 | 1590 | |
| 1591 | | static TIMER_CALLBACK( ans4 ) |
| 1591 | TIMER_CALLBACK_MEMBER( thomson_state::ans4 ) |
| 1592 | 1592 | { |
| 1593 | | LOG(( "%f ans4\n", machine.time().as_double() )); |
| 1594 | | mc6854_set_cts( machine.device("mc6854"), 0 ); |
| 1593 | LOG(( "%f ans4\n", machine().time().as_double() )); |
| 1594 | mc6854_set_cts( machine().device("mc6854"), 0 ); |
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | | static TIMER_CALLBACK( ans3 ) |
| 1597 | TIMER_CALLBACK_MEMBER( thomson_state::ans3 ) |
| 1598 | 1598 | { |
| 1599 | | LOG(( "%f ans3\n", machine.time().as_double() )); |
| 1600 | | mc6854_set_cts( machine.device("mc6854"), 1 ); |
| 1601 | | machine.scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans4)); |
| 1599 | LOG(( "%f ans3\n", machine().time().as_double() )); |
| 1600 | mc6854_set_cts( machine().device("mc6854"), 1 ); |
| 1601 | machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans4),this)); |
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | | static TIMER_CALLBACK( ans2 ) |
| 1604 | TIMER_CALLBACK_MEMBER( thomson_state::ans2 ) |
| 1605 | 1605 | { |
| 1606 | | LOG(( "%f ans2\n", machine.time().as_double() )); |
| 1607 | | mc6854_set_cts( machine.device("mc6854"), 0 ); |
| 1608 | | machine.scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans3)); |
| 1606 | LOG(( "%f ans2\n", machine().time().as_double() )); |
| 1607 | mc6854_set_cts( machine().device("mc6854"), 0 ); |
| 1608 | machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans3),this)); |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | | static TIMER_CALLBACK( ans ) |
| 1611 | TIMER_CALLBACK_MEMBER( thomson_state::ans ) |
| 1612 | 1612 | { |
| 1613 | | LOG(( "%f ans\n", machine.time().as_double() )); |
| 1614 | | mc6854_set_cts( machine.device("mc6854"), 1 ); |
| 1615 | | machine.scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans2)); |
| 1613 | LOG(( "%f ans\n", machine().time().as_double() )); |
| 1614 | mc6854_set_cts( machine().device("mc6854"), 1 ); |
| 1615 | machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans2),this)); |
| 1616 | 1616 | } |
| 1617 | 1617 | /* consigne DKBOOT |
| 1618 | 1618 | |
| r21425 | r21426 | |
| 1653 | 1653 | |
| 1654 | 1654 | if ( data[1] == 0xff ) |
| 1655 | 1655 | { |
| 1656 | thomson_state *state = device->machine().driver_data<thomson_state>(); |
| 1656 | 1657 | LOG(( "to7_network_got_frame: %i phones %i\n", data[2], data[0] )); |
| 1657 | | device->machine().scheduler().timer_set( attotime::from_usec( 100 ), FUNC(ans)); |
| 1658 | device->machine().scheduler().timer_set( attotime::from_usec( 100 ), timer_expired_delegate(FUNC(thomson_state::ans),state)); |
| 1658 | 1659 | mc6854_set_cts( device, 0 ); |
| 1659 | 1660 | } |
| 1660 | 1661 | else if ( ! data[1] ) |
| r21425 | r21426 | |
| 1680 | 1681 | |
| 1681 | 1682 | |
| 1682 | 1683 | |
| 1683 | | static void to7_network_init( running_machine &machine ) |
| 1684 | void thomson_state::to7_network_init() |
| 1684 | 1685 | { |
| 1685 | 1686 | LOG(( "to7_network_init: NR 07-005 network extension\n" )); |
| 1686 | 1687 | logerror( "to7_network_init: network not handled!\n" ); |
| r21425 | r21426 | |
| 1688 | 1689 | |
| 1689 | 1690 | |
| 1690 | 1691 | |
| 1691 | | static void to7_network_reset( running_machine &machine ) |
| 1692 | void thomson_state::to7_network_reset() |
| 1692 | 1693 | { |
| 1693 | 1694 | LOG(( "to7_network_reset: NR 07-005 network extension\n" )); |
| 1694 | | mc6854_set_cts( machine.device("mc6854"), 0 ); |
| 1695 | | mc6854_set_cts( machine.device("mc6854"), 1 ); |
| 1695 | mc6854_set_cts( machine().device("mc6854"), 0 ); |
| 1696 | mc6854_set_cts( machine().device("mc6854"), 1 ); |
| 1696 | 1697 | } |
| 1697 | 1698 | |
| 1698 | 1699 | |
| 1699 | 1700 | |
| 1700 | | static READ8_HANDLER ( to7_network_r ) |
| 1701 | READ8_MEMBER( thomson_state::to7_network_r ) |
| 1701 | 1702 | { |
| 1702 | 1703 | if ( offset < 4 ) |
| 1703 | | return mc6854_r( space.machine().device("mc6854"), space, offset ); |
| 1704 | return mc6854_r( machine().device("mc6854"), space, offset ); |
| 1704 | 1705 | |
| 1705 | 1706 | if ( offset == 8 ) |
| 1706 | 1707 | { |
| 1707 | 1708 | /* network ID of the computer */ |
| 1708 | | UINT8 id = space.machine().root_device().ioport("fconfig")->read() >> 3; |
| 1709 | | VLOG(( "%f $%04x to7_network_r: read id $%02X\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), id )); |
| 1709 | UINT8 id = ioport("fconfig")->read() >> 3; |
| 1710 | VLOG(( "%f $%04x to7_network_r: read id $%02X\n", machine().time().as_double(), m_maincpu->pc(), id )); |
| 1710 | 1711 | return id; |
| 1711 | 1712 | } |
| 1712 | 1713 | |
| 1713 | | logerror( "%f $%04x to7_network_r: invalid read offset %i\n", space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 1714 | logerror( "%f $%04x to7_network_r: invalid read offset %i\n", machine().time().as_double(), m_maincpu->pc(), offset ); |
| 1714 | 1715 | return 0; |
| 1715 | 1716 | } |
| 1716 | 1717 | |
| 1717 | 1718 | |
| 1718 | 1719 | |
| 1719 | | static WRITE8_HANDLER ( to7_network_w ) |
| 1720 | WRITE8_MEMBER( thomson_state::to7_network_w ) |
| 1720 | 1721 | { |
| 1721 | 1722 | if ( offset < 4 ) |
| 1722 | | mc6854_w( space.machine().device("mc6854"), space, offset, data ); |
| 1723 | mc6854_w( machine().device("mc6854"), space, offset, data ); |
| 1723 | 1724 | else |
| 1724 | 1725 | { |
| 1725 | 1726 | logerror( "%f $%04x to7_network_w: invalid write offset %i (data=$%02X)\n", |
| 1726 | | space.machine().time().as_double(), space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 1727 | machine().time().as_double(), m_maincpu->pc(), offset, data ); |
| 1727 | 1728 | } |
| 1728 | 1729 | } |
| 1729 | 1730 | |
| r21425 | r21426 | |
| 1747 | 1748 | UINT8 to7_floppy_bank; |
| 1748 | 1749 | |
| 1749 | 1750 | |
| 1750 | | void to7_floppy_init ( running_machine &machine, void* base ) |
| 1751 | void thomson_state::to7_floppy_init( void* base ) |
| 1751 | 1752 | { |
| 1752 | | machine.root_device().membank( THOM_FLOP_BANK )->configure_entries( 0, TO7_NB_FLOP_BANK, base, 0x800 ); |
| 1753 | | state_save_register_global( machine, to7_controller_type ); |
| 1754 | | state_save_register_global( machine, to7_floppy_bank ); |
| 1755 | | to7_5p14sd_init(machine); |
| 1756 | | to7_5p14_init(machine); |
| 1757 | | to7_qdd_init(machine); |
| 1758 | | thmfc_floppy_init(machine); |
| 1759 | | to7_network_init(machine); |
| 1753 | membank( THOM_FLOP_BANK )->configure_entries( 0, TO7_NB_FLOP_BANK, base, 0x800 ); |
| 1754 | state_save_register_global( machine(), to7_controller_type ); |
| 1755 | state_save_register_global( machine(), to7_floppy_bank ); |
| 1756 | to7_5p14sd_init(); |
| 1757 | to7_5p14_init(); |
| 1758 | to7_qdd_init(); |
| 1759 | thmfc_floppy_init(); |
| 1760 | to7_network_init(); |
| 1760 | 1761 | } |
| 1761 | 1762 | |
| 1762 | 1763 | |
| 1763 | 1764 | |
| 1764 | | void to7_floppy_reset ( running_machine &machine ) |
| 1765 | void thomson_state::to7_floppy_reset() |
| 1765 | 1766 | { |
| 1766 | | to7_controller_type = (machine.root_device().ioport("fconfig")->read() ) & 7; |
| 1767 | to7_controller_type = (ioport("fconfig")->read() ) & 7; |
| 1767 | 1768 | |
| 1768 | 1769 | switch ( to7_controller_type ) |
| 1769 | 1770 | { |
| 1770 | 1771 | case 1: |
| 1771 | 1772 | to7_floppy_bank = 1; |
| 1772 | | to7_5p14sd_reset(machine); |
| 1773 | to7_5p14sd_reset(); |
| 1773 | 1774 | break; |
| 1774 | 1775 | |
| 1775 | 1776 | case 2: |
| 1776 | 1777 | to7_floppy_bank = 2; |
| 1777 | | to7_5p14_reset(machine); |
| 1778 | to7_5p14_reset(); |
| 1778 | 1779 | break; |
| 1779 | 1780 | |
| 1780 | 1781 | case 3: |
| 1781 | 1782 | to7_floppy_bank = 3; |
| 1782 | | thmfc_floppy_reset(machine); |
| 1783 | thmfc_floppy_reset(); |
| 1783 | 1784 | break; |
| 1784 | 1785 | |
| 1785 | 1786 | case 4: |
| 1786 | 1787 | to7_floppy_bank = 7; |
| 1787 | | to7_qdd_reset(machine); |
| 1788 | to7_qdd_reset(); |
| 1788 | 1789 | break; |
| 1789 | 1790 | |
| 1790 | 1791 | case 5: |
| 1791 | 1792 | to7_floppy_bank = 8; |
| 1792 | | to7_network_reset(machine); |
| 1793 | to7_network_reset(); |
| 1793 | 1794 | break; |
| 1794 | 1795 | |
| 1795 | 1796 | default: |
| r21425 | r21426 | |
| 1797 | 1798 | break; |
| 1798 | 1799 | } |
| 1799 | 1800 | |
| 1800 | | machine.root_device().membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank ); |
| 1801 | membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank ); |
| 1801 | 1802 | } |
| 1802 | 1803 | |
| 1803 | 1804 | |
| 1804 | 1805 | |
| 1805 | | READ8_HANDLER ( to7_floppy_r ) |
| 1806 | READ8_MEMBER( thomson_state::to7_floppy_r ) |
| 1806 | 1807 | { |
| 1807 | 1808 | switch ( to7_controller_type ) |
| 1808 | 1809 | { |
| r21425 | r21426 | |
| 1827 | 1828 | |
| 1828 | 1829 | |
| 1829 | 1830 | |
| 1830 | | WRITE8_HANDLER ( to7_floppy_w ) |
| 1831 | WRITE8_MEMBER( thomson_state::to7_floppy_w ) |
| 1831 | 1832 | { |
| 1832 | 1833 | switch ( to7_controller_type ) |
| 1833 | 1834 | { |
| r21425 | r21426 | |
| 1843 | 1844 | if ( offset == 8 ) |
| 1844 | 1845 | { |
| 1845 | 1846 | to7_floppy_bank = 3 + (data & 3); |
| 1846 | | space.machine().root_device().membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank ); |
| 1847 | membank( THOM_FLOP_BANK )->set_entry( to7_floppy_bank ); |
| 1847 | 1848 | VLOG (( "to7_floppy_w: set CD 90-351 ROM bank to %i\n", data & 3 )); |
| 1848 | 1849 | } |
| 1849 | 1850 | else |
| r21425 | r21426 | |
| 1870 | 1871 | |
| 1871 | 1872 | |
| 1872 | 1873 | |
| 1873 | | void to9_floppy_init( running_machine &machine, void* int_base, void* ext_base ) |
| 1874 | void thomson_state::to9_floppy_init( void* int_base, void* ext_base ) |
| 1874 | 1875 | { |
| 1875 | | to7_floppy_init( machine, ext_base ); |
| 1876 | | machine.root_device().membank( THOM_FLOP_BANK )->configure_entry( TO7_NB_FLOP_BANK, int_base); |
| 1876 | to7_floppy_init( ext_base ); |
| 1877 | membank( THOM_FLOP_BANK )->configure_entry( TO7_NB_FLOP_BANK, int_base); |
| 1877 | 1878 | } |
| 1878 | 1879 | |
| 1879 | 1880 | |
| 1880 | 1881 | |
| 1881 | | void to9_floppy_reset( running_machine &machine ) |
| 1882 | void thomson_state::to9_floppy_reset() |
| 1882 | 1883 | { |
| 1883 | | to7_floppy_reset(machine); |
| 1884 | to7_floppy_reset(); |
| 1884 | 1885 | if ( THOM_FLOPPY_EXT ) |
| 1885 | 1886 | { |
| 1886 | 1887 | LOG(( "to9_floppy_reset: external controller\n" )); |
| r21425 | r21426 | |
| 1888 | 1889 | else |
| 1889 | 1890 | { |
| 1890 | 1891 | LOG(( "to9_floppy_reset: internal controller\n" )); |
| 1891 | | to7_5p14_reset(machine); |
| 1892 | | machine.root_device().membank( THOM_FLOP_BANK )->set_entry( TO7_NB_FLOP_BANK ); |
| 1892 | to7_5p14_reset(); |
| 1893 | membank( THOM_FLOP_BANK )->set_entry( TO7_NB_FLOP_BANK ); |
| 1893 | 1894 | } |
| 1894 | 1895 | } |
| 1895 | 1896 | |
| 1896 | 1897 | |
| 1897 | 1898 | |
| 1898 | | READ8_HANDLER ( to9_floppy_r ) |
| 1899 | READ8_MEMBER( thomson_state::to9_floppy_r ) |
| 1899 | 1900 | { |
| 1900 | 1901 | if ( THOM_FLOPPY_EXT ) |
| 1901 | 1902 | return to7_floppy_r( space, offset ); |
| r21425 | r21426 | |
| 1903 | 1904 | return to7_5p14_r( space, offset, mem_mask ); |
| 1904 | 1905 | } |
| 1905 | 1906 | |
| 1906 | | WRITE8_HANDLER ( to9_floppy_w ) |
| 1907 | WRITE8_MEMBER( thomson_state::to9_floppy_w ) |
| 1907 | 1908 | { |
| 1908 | 1909 | if ( THOM_FLOPPY_EXT ) |
| 1909 | 1910 | to7_floppy_w( space, offset, data ); |
| r21425 | r21426 | |
| 1911 | 1912 | to7_5p14_w( space, offset, data, mem_mask ); |
| 1912 | 1913 | } |
| 1913 | 1914 | |
| 1914 | | WRITE_LINE_DEVICE_HANDLER(thomson_index_callback) |
| 1915 | void thomson_state::thomson_index_callback(device_t *device, int state) |
| 1915 | 1916 | { |
| 1916 | 1917 | switch ( to7_controller_type ) |
| 1917 | 1918 | { |
| r21425 | r21426 | |
| 1920 | 1921 | break; |
| 1921 | 1922 | |
| 1922 | 1923 | case 2: |
| 1923 | | wd17xx_index_pulse_callback(device->machine().device("wd2793"), device, state); |
| 1924 | wd17xx_index_pulse_callback(machine().device("wd2793"), device, state); |
| 1924 | 1925 | break; |
| 1925 | 1926 | |
| 1926 | 1927 | case 3: |
| r21425 | r21426 | |
| 1935 | 1936 | break; |
| 1936 | 1937 | } |
| 1937 | 1938 | } |
| 1939 | |
trunk/src/mess/machine/thomson.c
| r21425 | r21426 | |
| 37 | 37 | /* It must be set accordingly in formats/thom_cas.c */ |
| 38 | 38 | #define K7_SPEED_HACK 0 |
| 39 | 39 | |
| 40 | | /* bank logging and optimisations */ |
| 41 | | static int old_cart_bank; |
| 42 | | static int old_cart_bank_was_read_only; |
| 43 | | static int old_ram_bank; |
| 44 | | static int old_floppy_bank; |
| 45 | 40 | |
| 46 | | |
| 47 | | |
| 48 | | /********************* common cassette code ***************************/ |
| 49 | | |
| 50 | | INLINE cassette_image_device* thom_cassette_img( running_machine &machine ) |
| 51 | | { return machine.device<cassette_image_device>(CASSETTE_TAG); } |
| 52 | | |
| 53 | 41 | /*-------------- TO7 ------------*/ |
| 54 | 42 | |
| 55 | 43 | |
| r21425 | r21426 | |
| 75 | 63 | |
| 76 | 64 | #define TO7_BIT_LENGTH 0.001114 |
| 77 | 65 | |
| 78 | | /* buffer storing demodulated bits, only for k7 and with speed hack */ |
| 79 | | static UINT32 to7_k7_bitsize; |
| 80 | | static UINT8* to7_k7_bits; |
| 81 | | |
| 82 | | |
| 83 | 66 | /* 1-bit cassette input to the computer |
| 84 | 67 | inside the controller, two frequency filters (adjusted to 6.3 and 4.5 kHz) |
| 85 | 68 | and a comparator demodulate the raw signal into 0s and 1s. |
| 86 | 69 | */ |
| 87 | | static int to7_get_cassette ( running_machine &machine ) |
| 70 | int thomson_state::to7_get_cassette() |
| 88 | 71 | { |
| 89 | | cassette_image_device* img = thom_cassette_img(machine); |
| 90 | | if ( img->exists() ) |
| 72 | if ( m_cassette->exists() ) |
| 91 | 73 | { |
| 92 | | cassette_image* cass = img->get_image(); |
| 93 | | cassette_state state = img->get_state(); |
| 94 | | double pos = img->get_position(); |
| 74 | cassette_image* cass = m_cassette->get_image(); |
| 75 | cassette_state state = m_cassette->get_state(); |
| 76 | double pos = m_cassette->get_position(); |
| 95 | 77 | int bitpos = pos / TO7_BIT_LENGTH; |
| 96 | 78 | |
| 97 | 79 | if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED ) |
| 98 | 80 | return 1; |
| 99 | 81 | |
| 100 | | if ( K7_SPEED_HACK && to7_k7_bits ) |
| 82 | if ( K7_SPEED_HACK && m_to7_k7_bits ) |
| 101 | 83 | { |
| 102 | 84 | /* hack, feed existing bits */ |
| 103 | | if ( bitpos >= to7_k7_bitsize ) |
| 104 | | bitpos = to7_k7_bitsize -1; |
| 85 | if ( bitpos >= m_to7_k7_bitsize ) |
| 86 | bitpos = m_to7_k7_bitsize -1; |
| 105 | 87 | VLOG (( "$%04x %f to7_get_cassette: state=$%X pos=%f samppos=%i bit=%i\n", |
| 106 | | machine.device("maincpu")->safe_pcbase(), machine.time().as_double(), state, pos, bitpos, |
| 107 | | to7_k7_bits[ bitpos ] )); |
| 108 | | return to7_k7_bits[ bitpos ]; |
| 88 | m_maincpu->pc(), machine().time().as_double(), state, pos, bitpos, |
| 89 | m_to7_k7_bits[ bitpos ] )); |
| 90 | return m_to7_k7_bits[ bitpos ]; |
| 109 | 91 | } |
| 110 | 92 | else |
| 111 | 93 | { |
| r21425 | r21426 | |
| 124 | 106 | } |
| 125 | 107 | k = ( chg >= 13 ) ? 1 : 0; |
| 126 | 108 | VLOG (( "$%04x %f to7_get_cassette: state=$%X pos=%f samppos=%i bit=%i (%i)\n", |
| 127 | | machine.device("maincpu")->safe_pcbase(), machine.time().as_double(), state, pos, bitpos, |
| 109 | m_maincpu->pc(), machine().time().as_double(), state, pos, bitpos, |
| 128 | 110 | k, chg )); |
| 129 | 111 | return k; |
| 130 | 112 | } |
| r21425 | r21426 | |
| 137 | 119 | |
| 138 | 120 | |
| 139 | 121 | /* 1-bit cassette output */ |
| 140 | | static void to7_set_cassette ( running_machine &machine, int data ) |
| 122 | void thomson_state::to7_set_cassette( int data ) |
| 141 | 123 | { |
| 142 | | cassette_image_device* img = thom_cassette_img(machine); |
| 143 | | img->output(data ? 1. : -1. ); |
| 124 | m_cassette->output(data ? 1. : -1. ); |
| 144 | 125 | } |
| 145 | 126 | |
| 146 | 127 | |
| 147 | 128 | |
| 148 | | static WRITE8_DEVICE_HANDLER ( to7_set_cassette_motor ) |
| 129 | WRITE8_MEMBER( thomson_state::to7_set_cassette_motor ) |
| 149 | 130 | { |
| 150 | | cassette_image_device* img = thom_cassette_img(space.machine()); |
| 151 | | cassette_state state = img->get_state(); |
| 152 | | double pos = img->get_position(); |
| 131 | cassette_state state = m_cassette->get_state(); |
| 132 | double pos = m_cassette->get_position(); |
| 153 | 133 | |
| 154 | 134 | LOG (( "$%04x %f to7_set_cassette_motor: cassette motor %s bitpos=%i\n", |
| 155 | | space.machine().device("maincpu")->safe_pcbase(), img->machine().time().as_double(), data ? "off" : "on", |
| 135 | m_maincpu->pc(), machine().time().as_double(), data ? "off" : "on", |
| 156 | 136 | (int) (pos / TO7_BIT_LENGTH) )); |
| 157 | 137 | |
| 158 | 138 | if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED && !data && pos > 0.3 ) |
| 159 | 139 | { |
| 160 | 140 | /* rewind a little before starting the motor */ |
| 161 | | img->seek(-0.3, SEEK_CUR ); |
| 141 | m_cassette->seek(-0.3, SEEK_CUR ); |
| 162 | 142 | } |
| 163 | 143 | |
| 164 | | img->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR ); |
| 144 | m_cassette->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR ); |
| 165 | 145 | } |
| 166 | 146 | |
| 167 | 147 | |
| r21425 | r21426 | |
| 184 | 164 | #define MO5_HBIT_LENGTH (MO5_BIT_LENGTH / 2.) |
| 185 | 165 | |
| 186 | 166 | |
| 187 | | static int mo5_get_cassette ( running_machine &machine ) |
| 167 | int thomson_state::mo5_get_cassette() |
| 188 | 168 | { |
| 189 | | cassette_image_device* img = thom_cassette_img(machine); |
| 190 | | device_image_interface *image = dynamic_cast<device_image_interface *>(img); |
| 191 | | |
| 192 | | if ( image->exists() ) |
| 169 | if ( m_cassette->exists() ) |
| 193 | 170 | { |
| 194 | | cassette_image* cass = img->get_image(); |
| 195 | | cassette_state state = img->get_state(); |
| 196 | | double pos = img->get_position(); |
| 171 | cassette_image* cass = m_cassette->get_image(); |
| 172 | cassette_state state = m_cassette->get_state(); |
| 173 | double pos = m_cassette->get_position(); |
| 197 | 174 | INT32 hbit; |
| 198 | 175 | |
| 199 | 176 | if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED ) |
| r21425 | r21426 | |
| 203 | 180 | hbit = hbit >= 0; |
| 204 | 181 | |
| 205 | 182 | VLOG (( "$%04x %f mo5_get_cassette: state=$%X pos=%f hbitpos=%i hbit=%i\n", |
| 206 | | machine.device("maincpu")->safe_pcbase(), machine.time().as_double(), state, pos, |
| 183 | m_maincpu->pc(), machine().time().as_double(), state, pos, |
| 207 | 184 | (int) (pos / MO5_HBIT_LENGTH), hbit )); |
| 208 | 185 | return hbit; |
| 209 | 186 | } |
| r21425 | r21426 | |
| 213 | 190 | |
| 214 | 191 | |
| 215 | 192 | |
| 216 | | static void mo5_set_cassette ( running_machine &machine, int data ) |
| 193 | void thomson_state::mo5_set_cassette( int data ) |
| 217 | 194 | { |
| 218 | | cassette_image_device* img = thom_cassette_img(machine); |
| 219 | | img->output(data ? 1. : -1. ); |
| 195 | m_cassette->output(data ? 1. : -1. ); |
| 220 | 196 | } |
| 221 | 197 | |
| 222 | 198 | |
| 223 | 199 | |
| 224 | | static WRITE8_DEVICE_HANDLER ( mo5_set_cassette_motor ) |
| 200 | WRITE8_MEMBER( thomson_state::mo5_set_cassette_motor ) |
| 225 | 201 | { |
| 226 | | cassette_image_device* img = thom_cassette_img(space.machine()); |
| 227 | | cassette_state state = img->get_state(); |
| 228 | | double pos = img->get_position(); |
| 202 | cassette_state state = m_cassette->get_state(); |
| 203 | double pos = m_cassette->get_position(); |
| 229 | 204 | |
| 230 | 205 | LOG (( "$%04x %f mo5_set_cassette_motor: cassette motor %s hbitpos=%i\n", |
| 231 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ? "off" : "on", |
| 206 | m_maincpu->pc(), machine().time().as_double(), data ? "off" : "on", |
| 232 | 207 | (int) (pos / MO5_HBIT_LENGTH) )); |
| 233 | 208 | |
| 234 | 209 | if ( (state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_DISABLED && !data && pos > 0.3 ) |
| 235 | 210 | { |
| 236 | 211 | /* rewind a little before starting the motor */ |
| 237 | | img->seek(-0.3, SEEK_CUR ); |
| 212 | m_cassette->seek(-0.3, SEEK_CUR ); |
| 238 | 213 | } |
| 239 | 214 | |
| 240 | | img->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR ); |
| 215 | m_cassette->change_state(data ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED,CASSETTE_MASK_MOTOR ); |
| 241 | 216 | } |
| 242 | 217 | |
| 243 | 218 | |
| r21425 | r21426 | |
| 250 | 225 | /* ------------ IRQs ------------ */ |
| 251 | 226 | |
| 252 | 227 | |
| 253 | | /* several devices on the same irqs */ |
| 254 | | |
| 255 | | static UINT8 thom_irq; |
| 256 | | |
| 257 | | static UINT8 thom_firq; |
| 258 | | |
| 259 | | |
| 260 | | |
| 261 | | static void thom_set_irq ( running_machine &machine, int line, int state ) |
| 228 | void thomson_state::thom_set_irq( int line, int state ) |
| 262 | 229 | { |
| 263 | | int old = thom_irq; |
| 230 | int old = m_thom_irq; |
| 264 | 231 | |
| 265 | 232 | if ( state ) |
| 266 | | thom_irq |= 1 << line; |
| 233 | m_thom_irq |= 1 << line; |
| 267 | 234 | else |
| 268 | | thom_irq &= ~(1 << line); |
| 235 | m_thom_irq &= ~(1 << line); |
| 269 | 236 | |
| 270 | | if ( !old && thom_irq ) |
| 271 | | LOG_IRQ(( "%f thom_set_irq: irq line up %i\n", machine.time().as_double(), line )); |
| 272 | | if ( old && !thom_irq ) |
| 273 | | LOG_IRQ(( "%f thom_set_irq: irq line down %i\n", machine.time().as_double(), line )); |
| 237 | if ( !old && m_thom_irq ) |
| 238 | LOG_IRQ(( "%f thom_set_irq: irq line up %i\n", machine().time().as_double(), line )); |
| 239 | if ( old && !m_thom_irq ) |
| 240 | LOG_IRQ(( "%f thom_set_irq: irq line down %i\n", machine().time().as_double(), line )); |
| 274 | 241 | |
| 275 | | machine.device("maincpu")->execute().set_input_line(M6809_IRQ_LINE, thom_irq ? ASSERT_LINE : CLEAR_LINE); |
| 242 | m_maincpu->set_input_line(M6809_IRQ_LINE, m_thom_irq ? ASSERT_LINE : CLEAR_LINE); |
| 276 | 243 | } |
| 277 | 244 | |
| 278 | 245 | |
| 279 | 246 | |
| 280 | | static void thom_set_firq ( running_machine &machine, int line, int state ) |
| 247 | void thomson_state::thom_set_firq ( int line, int state ) |
| 281 | 248 | { |
| 282 | | int old = thom_irq; |
| 249 | int old = m_thom_firq; |
| 283 | 250 | |
| 284 | 251 | if ( state ) |
| 285 | | thom_firq |= 1 << line; |
| 252 | m_thom_firq |= 1 << line; |
| 286 | 253 | else |
| 287 | | thom_firq &= ~(1 << line); |
| 254 | m_thom_firq &= ~(1 << line); |
| 288 | 255 | |
| 289 | | if ( !old && thom_firq ) |
| 290 | | LOG_IRQ(( "%f thom_set_firq: firq line up %i\n", machine.time().as_double(), line )); |
| 291 | | if ( old && !thom_firq ) |
| 292 | | LOG_IRQ(( "%f thom_set_firq: firq line down %i\n", machine.time().as_double(), line )); |
| 256 | if ( !old && m_thom_firq ) |
| 257 | LOG_IRQ(( "%f thom_set_firq: firq line up %i\n", machine().time().as_double(), line )); |
| 258 | if ( old && !m_thom_firq ) |
| 259 | LOG_IRQ(( "%f thom_set_firq: firq line down %i\n", machine().time().as_double(), line )); |
| 293 | 260 | |
| 294 | | machine.device("maincpu")->execute().set_input_line(M6809_FIRQ_LINE, thom_firq ? ASSERT_LINE : CLEAR_LINE); |
| 261 | m_maincpu->set_input_line(M6809_FIRQ_LINE, m_thom_firq ? ASSERT_LINE : CLEAR_LINE); |
| 295 | 262 | } |
| 296 | 263 | |
| 297 | 264 | |
| 298 | 265 | |
| 299 | | static void thom_irq_reset ( running_machine &machine ) |
| 266 | void thomson_state::thom_irq_reset() |
| 300 | 267 | { |
| 301 | | thom_irq = 0; |
| 302 | | thom_firq = 0; |
| 303 | | machine.device("maincpu")->execute().set_input_line(M6809_IRQ_LINE, CLEAR_LINE ); |
| 304 | | machine.device("maincpu")->execute().set_input_line(M6809_FIRQ_LINE, CLEAR_LINE ); |
| 268 | m_thom_irq = 0; |
| 269 | m_thom_firq = 0; |
| 270 | m_maincpu->set_input_line(M6809_IRQ_LINE, CLEAR_LINE ); |
| 271 | m_maincpu->set_input_line(M6809_FIRQ_LINE, CLEAR_LINE ); |
| 305 | 272 | } |
| 306 | 273 | |
| 307 | 274 | |
| 308 | 275 | |
| 309 | | static void thom_irq_init ( running_machine &machine ) |
| 276 | void thomson_state::thom_irq_init() |
| 310 | 277 | { |
| 311 | | state_save_register_global( machine, thom_irq ); |
| 312 | | state_save_register_global( machine, thom_firq ); |
| 278 | save_item(NAME(m_thom_irq)); |
| 279 | save_item(NAME(m_thom_firq)); |
| 313 | 280 | } |
| 314 | 281 | |
| 315 | 282 | |
| 316 | 283 | |
| 317 | | static void thom_irq_0 ( running_machine &machine, int state ) |
| 284 | void thomson_state::thom_irq_0( int state ) |
| 318 | 285 | { |
| 319 | | thom_set_irq ( machine, 0, state ); |
| 286 | thom_set_irq( 0, state ); |
| 320 | 287 | } |
| 321 | 288 | |
| 322 | | static WRITE_LINE_DEVICE_HANDLER( thom_dev_irq_0 ) |
| 289 | WRITE_LINE_MEMBER( thomson_state::thom_dev_irq_0 ) |
| 323 | 290 | { |
| 324 | | thom_irq_0( device->machine(), state ); |
| 291 | thom_irq_0( state ); |
| 325 | 292 | } |
| 326 | 293 | |
| 327 | 294 | |
| 328 | 295 | |
| 329 | | static WRITE_LINE_DEVICE_HANDLER( thom_irq_1 ) |
| 296 | WRITE_LINE_MEMBER( thomson_state::thom_irq_1 ) |
| 330 | 297 | { |
| 331 | | thom_set_irq ( device->machine(), 1, state ); |
| 298 | thom_set_irq ( 1, state ); |
| 332 | 299 | } |
| 333 | 300 | |
| 334 | | static void thom_irq_3 ( running_machine &machine, int state ) |
| 301 | void thomson_state::thom_irq_3( int state ) |
| 335 | 302 | { |
| 336 | | thom_set_irq ( machine, 3, state ); |
| 303 | thom_set_irq ( 3, state ); |
| 337 | 304 | } |
| 338 | 305 | |
| 339 | | static WRITE_LINE_DEVICE_HANDLER( thom_firq_1 ) |
| 306 | WRITE_LINE_MEMBER( thomson_state::thom_firq_1 ) |
| 340 | 307 | { |
| 341 | | thom_set_firq ( device->machine(), 1, state ); |
| 308 | thom_set_firq ( 1, state ); |
| 342 | 309 | } |
| 343 | 310 | |
| 344 | | static void thom_firq_2 ( running_machine &machine, int state ) |
| 311 | void thomson_state::thom_firq_2( int state ) |
| 345 | 312 | { |
| 346 | | thom_set_firq ( machine, 2, state ); |
| 313 | thom_set_firq ( 2, state ); |
| 347 | 314 | } |
| 348 | 315 | |
| 349 | | #ifdef CHARDEV |
| 350 | | static void thom_irq_4 ( running_machine &machine, int state ) |
| 316 | void thomson_state::thom_irq_4( int state ) |
| 351 | 317 | { |
| 352 | | thom_set_irq ( machine, 4, state ); |
| 318 | thom_set_irq ( 4, state ); |
| 353 | 319 | } |
| 354 | | #endif |
| 355 | 320 | |
| 356 | 321 | |
| 357 | 322 | /* |
| r21425 | r21426 | |
| 370 | 335 | |
| 371 | 336 | |
| 372 | 337 | |
| 373 | | static void thom_set_caps_led ( running_machine &machine, int led ) |
| 338 | void thomson_state::thom_set_caps_led( int led ) |
| 374 | 339 | { |
| 375 | 340 | output_set_value( "led0", led ); |
| 376 | 341 | } |
| r21425 | r21426 | |
| 390 | 355 | |
| 391 | 356 | /***************************** TO7 / T9000 *************************/ |
| 392 | 357 | |
| 393 | | |
| 394 | | |
| 395 | | /* ------------ cartridge ------------ */ |
| 396 | | |
| 397 | | static UINT8 thom_cart_nb_banks; /* number of 16 KB banks (up to 4) */ |
| 398 | | |
| 399 | | static UINT8 thom_cart_bank; /* current bank */ |
| 400 | | |
| 401 | | |
| 402 | 358 | DEVICE_IMAGE_LOAD_MEMBER( thomson_state, to7_cartridge ) |
| 403 | 359 | { |
| 404 | 360 | int i,j; |
| r21425 | r21426 | |
| 413 | 369 | |
| 414 | 370 | /* get size & number of 16-KB banks */ |
| 415 | 371 | if ( size <= 0x04000 ) |
| 416 | | thom_cart_nb_banks = 1; |
| 372 | m_thom_cart_nb_banks = 1; |
| 417 | 373 | else if ( size == 0x08000 ) |
| 418 | | thom_cart_nb_banks = 2; |
| 374 | m_thom_cart_nb_banks = 2; |
| 419 | 375 | else if ( size == 0x10000 ) |
| 420 | | thom_cart_nb_banks = 4; |
| 376 | m_thom_cart_nb_banks = 4; |
| 421 | 377 | else |
| 422 | 378 | { |
| 423 | 379 | astring errmsg; |
| r21425 | r21426 | |
| 452 | 408 | name[i] = '?'; |
| 453 | 409 | } |
| 454 | 410 | |
| 455 | | PRINT (( "to7_cartridge_load: cartridge \"%s\" banks=%i, size=%i\n", name, thom_cart_nb_banks, size )); |
| 411 | PRINT (( "to7_cartridge_load: cartridge \"%s\" banks=%i, size=%i\n", name, m_thom_cart_nb_banks, size )); |
| 456 | 412 | |
| 457 | 413 | return IMAGE_INIT_PASS; |
| 458 | 414 | } |
| 459 | 415 | |
| 460 | 416 | |
| 461 | 417 | |
| 462 | | static void to7_update_cart_bank(running_machine &machine) |
| 418 | void thomson_state::to7_update_cart_bank() |
| 463 | 419 | { |
| 464 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 420 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 465 | 421 | int bank = 0; |
| 466 | | if ( thom_cart_nb_banks ) |
| 422 | if ( m_thom_cart_nb_banks ) |
| 467 | 423 | { |
| 468 | | bank = thom_cart_bank % thom_cart_nb_banks; |
| 469 | | if ( bank != old_cart_bank && old_cart_bank < 0 ) |
| 470 | | { |
| 471 | | space.install_legacy_read_handler(0x0000, 0x0003, FUNC(to7_cartridge_r) ); |
| 472 | | } |
| 473 | | } |
| 474 | | if ( bank != old_cart_bank ) |
| 424 | bank = m_thom_cart_bank % m_thom_cart_nb_banks; |
| 425 | if ( bank != m_old_cart_bank && m_old_cart_bank < 0 ) |
| 475 | 426 | { |
| 476 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( bank ); |
| 477 | | old_cart_bank = bank; |
| 427 | space.install_read_handler(0x0000, 0x0003, read8_delegate(FUNC(thomson_state::to7_cartridge_r),this) ); |
| 428 | } |
| 429 | } |
| 430 | if ( bank != m_old_cart_bank ) |
| 431 | { |
| 432 | membank( THOM_CART_BANK )->set_entry( bank ); |
| 433 | m_old_cart_bank = bank; |
| 478 | 434 | LOG_BANK(( "to7_update_cart_bank: CART is cartridge bank %i\n", bank )); |
| 479 | 435 | } |
| 480 | 436 | } |
| 481 | 437 | |
| 482 | 438 | |
| 483 | 439 | |
| 484 | | static void to7_update_cart_bank_postload(running_machine *machine) |
| 440 | void thomson_state::to7_update_cart_bank_postload() |
| 485 | 441 | { |
| 486 | | to7_update_cart_bank(*machine); |
| 442 | to7_update_cart_bank(); |
| 487 | 443 | } |
| 488 | 444 | |
| 489 | 445 | |
| 490 | 446 | |
| 491 | 447 | /* write signal to 0000-1fff generates a bank switch */ |
| 492 | | WRITE8_HANDLER ( to7_cartridge_w ) |
| 448 | WRITE8_MEMBER( thomson_state::to7_cartridge_w ) |
| 493 | 449 | { |
| 494 | 450 | if ( offset >= 0x2000 ) |
| 495 | 451 | return; |
| 496 | 452 | |
| 497 | | thom_cart_bank = offset & 3; |
| 498 | | to7_update_cart_bank(space.machine()); |
| 453 | m_thom_cart_bank = offset & 3; |
| 454 | to7_update_cart_bank(); |
| 499 | 455 | } |
| 500 | 456 | |
| 501 | 457 | |
| 502 | 458 | |
| 503 | 459 | /* read signal to 0000-0003 generates a bank switch */ |
| 504 | | READ8_HANDLER ( to7_cartridge_r ) |
| 460 | READ8_MEMBER( thomson_state::to7_cartridge_r ) |
| 505 | 461 | { |
| 506 | | UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000; |
| 507 | | UINT8 data = pos[offset + (thom_cart_bank % thom_cart_nb_banks) * 0x4000]; |
| 462 | UINT8* pos = memregion( "maincpu" )->base() + 0x10000; |
| 463 | UINT8 data = pos[offset + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000]; |
| 508 | 464 | if ( !space.debugger_access() ) |
| 509 | | { |
| 510 | | thom_cart_bank = offset & 3; |
| 511 | | to7_update_cart_bank(space.machine()); |
| 465 | { |
| 466 | m_thom_cart_bank = offset & 3; |
| 467 | to7_update_cart_bank(); |
| 512 | 468 | } |
| 513 | 469 | return data; |
| 514 | 470 | } |
| r21425 | r21426 | |
| 519 | 475 | |
| 520 | 476 | |
| 521 | 477 | |
| 522 | | static WRITE8_DEVICE_HANDLER ( to7_timer_port_out ) |
| 478 | WRITE8_MEMBER( thomson_state::to7_timer_port_out ) |
| 523 | 479 | { |
| 524 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank switch */ |
| 525 | | thom_set_caps_led( space.machine(), (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */ |
| 526 | | thom_set_border_color( space.machine(), |
| 527 | | ((data & 0x10) ? 1 : 0) | /* bits 4-6: border color */ |
| 528 | | ((data & 0x20) ? 2 : 0) | |
| 529 | | ((data & 0x40) ? 4 : 0) ); |
| 480 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 481 | thom_set_caps_led( (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */ |
| 482 | thom_set_border_color( ((data & 0x10) ? 1 : 0) | /* bits 4-6: border color */ |
| 483 | ((data & 0x20) ? 2 : 0) | |
| 484 | ((data & 0x40) ? 4 : 0) ); |
| 530 | 485 | } |
| 531 | 486 | |
| 532 | 487 | |
| 533 | 488 | |
| 534 | | static WRITE8_DEVICE_HANDLER ( to7_timer_cp2_out ) |
| 489 | WRITE8_MEMBER( thomson_state::to7_timer_cp2_out ) |
| 535 | 490 | { |
| 536 | | space.machine().device<dac_device>("buzzer")->write_unsigned8(data ? 0x80 : 0); /* 1-bit buzzer */ |
| 491 | m_buzzer->write_unsigned8(data ? 0x80 : 0); /* 1-bit buzzer */ |
| 537 | 492 | } |
| 538 | 493 | |
| 539 | 494 | |
| 540 | 495 | |
| 541 | | static READ8_DEVICE_HANDLER ( to7_timer_port_in ) |
| 496 | READ8_MEMBER( thomson_state::to7_timer_port_in ) |
| 542 | 497 | { |
| 543 | | int lightpen = (space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0; |
| 544 | | int cass = to7_get_cassette(space.machine()) ? 0x80 : 0; |
| 498 | int lightpen = (ioport("lightpen_button")->read() & 1) ? 2 : 0; |
| 499 | int cass = to7_get_cassette() ? 0x80 : 0; |
| 545 | 500 | return lightpen | cass; |
| 546 | 501 | } |
| 547 | 502 | |
| 548 | 503 | |
| 549 | 504 | |
| 550 | | static WRITE8_DEVICE_HANDLER ( to7_timer_tco_out ) |
| 505 | WRITE8_MEMBER( thomson_state::to7_timer_tco_out ) |
| 551 | 506 | { |
| 552 | 507 | /* 1-bit cassette output */ |
| 553 | | to7_set_cassette( space.machine(), data ); |
| 508 | to7_set_cassette( data ); |
| 554 | 509 | } |
| 555 | 510 | |
| 556 | 511 | |
| 557 | 512 | |
| 558 | 513 | const mc6846_interface to7_timer = |
| 559 | 514 | { |
| 560 | | DEVCB_HANDLER(to7_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to7_timer_cp2_out), |
| 561 | | DEVCB_HANDLER(to7_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out), |
| 562 | | DEVCB_LINE(thom_dev_irq_0) |
| 515 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_out), |
| 516 | DEVCB_NULL, |
| 517 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out), |
| 518 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in), |
| 519 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out), |
| 520 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0) |
| 563 | 521 | }; |
| 564 | 522 | |
| 565 | 523 | |
| r21425 | r21426 | |
| 567 | 525 | /* ------------ lightpen automaton ------------ */ |
| 568 | 526 | |
| 569 | 527 | |
| 570 | | |
| 571 | | static UINT8 to7_lightpen_step; |
| 572 | | |
| 573 | | static UINT8 to7_lightpen; |
| 574 | | |
| 575 | | |
| 576 | | |
| 577 | | static void to7_lightpen_cb ( running_machine &machine, int step ) |
| 528 | void thomson_state::to7_lightpen_cb( int step ) |
| 578 | 529 | { |
| 579 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 580 | | |
| 581 | | if ( ! to7_lightpen ) |
| 530 | if ( ! m_to7_lightpen ) |
| 582 | 531 | return; |
| 583 | 532 | |
| 584 | | LOG_VIDEO(( "%f to7_lightpen_cb: step=%i\n", machine.time().as_double(), step )); |
| 585 | | sys_pia->cb1_w( 1 ); |
| 586 | | sys_pia->cb1_w( 0 ); |
| 587 | | to7_lightpen_step = step; |
| 533 | LOG_VIDEO(( "%f to7_lightpen_cb: step=%i\n", machine().time().as_double(), step )); |
| 534 | m_pia_sys->cb1_w( 1 ); |
| 535 | m_pia_sys->cb1_w( 0 ); |
| 536 | m_to7_lightpen_step = step; |
| 588 | 537 | } |
| 589 | 538 | |
| 590 | 539 | |
| r21425 | r21426 | |
| 593 | 542 | |
| 594 | 543 | |
| 595 | 544 | |
| 596 | | static void to7_set_init ( running_machine &machine, int init ) |
| 545 | void thomson_state::to7_set_init( int init ) |
| 597 | 546 | { |
| 598 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 599 | 547 | /* INIT signal wired to system PIA 6821 */ |
| 600 | 548 | |
| 601 | | LOG_VIDEO(( "%f to7_set_init: init=%i\n", machine.time().as_double(), init )); |
| 602 | | sys_pia->ca1_w( init ); |
| 549 | LOG_VIDEO(( "%f to7_set_init: init=%i\n", machine().time().as_double(), init )); |
| 550 | m_pia_sys->ca1_w( init ); |
| 603 | 551 | } |
| 604 | 552 | |
| 605 | 553 | |
| r21425 | r21426 | |
| 608 | 556 | |
| 609 | 557 | |
| 610 | 558 | |
| 611 | | static WRITE8_DEVICE_HANDLER ( to7_sys_cb2_out ) |
| 559 | WRITE8_MEMBER( thomson_state::to7_sys_cb2_out ) |
| 612 | 560 | { |
| 613 | | to7_lightpen = !data; |
| 561 | m_to7_lightpen = !data; |
| 614 | 562 | } |
| 615 | 563 | |
| 616 | 564 | |
| 617 | 565 | |
| 618 | | static WRITE8_DEVICE_HANDLER ( to7_sys_portb_out ) |
| 566 | WRITE8_MEMBER( thomson_state::to7_sys_portb_out ) |
| 619 | 567 | { |
| 620 | 568 | /* value fetched in to7_sys_porta_in */ |
| 621 | 569 | } |
| r21425 | r21426 | |
| 626 | 574 | |
| 627 | 575 | |
| 628 | 576 | |
| 629 | | static READ8_DEVICE_HANDLER ( to7_sys_porta_in ) |
| 577 | READ8_MEMBER( thomson_state::to7_sys_porta_in ) |
| 630 | 578 | { |
| 631 | | if ( to7_lightpen ) |
| 579 | if ( m_to7_lightpen ) |
| 632 | 580 | { |
| 633 | 581 | /* lightpen hi */ |
| 634 | | return to7_lightpen_gpl( space.machine(), TO7_LIGHTPEN_DECAL, to7_lightpen_step ) >> 8; |
| 582 | return to7_lightpen_gpl( TO7_LIGHTPEN_DECAL, m_to7_lightpen_step ) >> 8; |
| 635 | 583 | } |
| 636 | 584 | else |
| 637 | 585 | { |
| 638 | 586 | /* keyboard */ |
| 639 | | int keyline = downcast<pia6821_device *>(device)->b_output(); |
| 587 | int keyline = m_pia_sys->b_output(); |
| 640 | 588 | UINT8 val = 0xff; |
| 641 | 589 | int i; |
| 642 | 590 | static const char *const keynames[] = { |
| r21425 | r21426 | |
| 647 | 595 | for ( i = 0; i < 8; i++ ) |
| 648 | 596 | { |
| 649 | 597 | if ( ! (keyline & (1 << i)) ) |
| 650 | | val &= space.machine().root_device().ioport(keynames[i])->read(); |
| 598 | val &= ioport(keynames[i])->read(); |
| 651 | 599 | } |
| 652 | 600 | return val; |
| 653 | 601 | } |
| r21425 | r21426 | |
| 655 | 603 | |
| 656 | 604 | |
| 657 | 605 | |
| 658 | | static READ8_DEVICE_HANDLER ( to7_sys_portb_in ) |
| 606 | READ8_MEMBER( thomson_state::to7_sys_portb_in ) |
| 659 | 607 | { |
| 660 | 608 | /* lightpen low */ |
| 661 | | return to7_lightpen_gpl( space.machine(), TO7_LIGHTPEN_DECAL, to7_lightpen_step ) & 0xff; |
| 609 | return to7_lightpen_gpl( TO7_LIGHTPEN_DECAL, m_to7_lightpen_step ) & 0xff; |
| 662 | 610 | } |
| 663 | 611 | |
| 664 | 612 | |
| 665 | 613 | |
| 666 | 614 | const pia6821_interface to7_pia6821_sys = |
| 667 | 615 | { |
| 668 | | DEVCB_HANDLER(to7_sys_porta_in), |
| 669 | | DEVCB_HANDLER(to7_sys_portb_in), |
| 616 | DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_porta_in), |
| 617 | DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_portb_in), |
| 670 | 618 | DEVCB_NULL, |
| 671 | 619 | DEVCB_NULL, |
| 672 | 620 | DEVCB_NULL, |
| 673 | 621 | DEVCB_NULL, |
| 674 | 622 | DEVCB_NULL, |
| 675 | | DEVCB_HANDLER(to7_sys_portb_out), |
| 676 | | DEVCB_HANDLER(to7_set_cassette_motor), |
| 677 | | DEVCB_HANDLER(to7_sys_cb2_out), |
| 678 | | DEVCB_LINE(thom_firq_1), |
| 679 | | DEVCB_LINE(thom_firq_1) |
| 623 | DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_portb_out), |
| 624 | DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor), |
| 625 | DEVCB_DRIVER_MEMBER(thomson_state, to7_sys_cb2_out), |
| 626 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1), |
| 627 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1) |
| 680 | 628 | }; |
| 681 | 629 | |
| 682 | 630 | |
| r21425 | r21426 | |
| 695 | 643 | |
| 696 | 644 | |
| 697 | 645 | |
| 698 | | enum to7_io_dev |
| 699 | | { |
| 700 | | TO7_IO_NONE, |
| 701 | | TO7_IO_CENTRONICS, |
| 702 | | TO7_IO_RS232 |
| 703 | | }; |
| 704 | | |
| 705 | 646 | /* test whether a parallel or a serial device is connected: both cannot |
| 706 | 647 | be exploited at the same time! |
| 707 | 648 | */ |
| 708 | | static to7_io_dev to7_io_mode( running_machine &machine ) |
| 649 | to7_io_dev thomson_state::to7_io_mode() |
| 709 | 650 | { |
| 710 | | centronics_device *centronics = machine.device<centronics_device>("centronics"); |
| 711 | | device_image_interface *serial = dynamic_cast<device_image_interface *>(machine.device("cc90232")); |
| 712 | | |
| 713 | | if (centronics->pe_r() == TRUE) |
| 651 | if (m_centronics->pe_r() == TRUE) |
| 714 | 652 | return TO7_IO_CENTRONICS; |
| 715 | | else if ( serial->exists()) |
| 653 | else if ( m_serial->exists()) |
| 716 | 654 | return TO7_IO_RS232; |
| 717 | 655 | return TO7_IO_NONE; |
| 718 | 656 | } |
| 719 | 657 | |
| 720 | 658 | |
| 721 | 659 | |
| 722 | | static WRITE_LINE_DEVICE_HANDLER( to7_io_ack ) |
| 660 | WRITE_LINE_MEMBER( thomson_state::to7_io_ack ) |
| 723 | 661 | { |
| 724 | | pia6821_device *io_pia = device->machine().device<pia6821_device>(THOM_PIA_IO); |
| 725 | | |
| 726 | | io_pia->cb1_w( state); |
| 727 | | //LOG_IO (( "%f to7_io_ack: CENTRONICS new state $%02X (ack=%i)\n", machine.time().as_double(), data, ack )); |
| 662 | m_pia_io->cb1_w( state); |
| 663 | //LOG_IO (( "%f to7_io_ack: CENTRONICS new state $%02X (ack=%i)\n", machine().time().as_double(), data, ack )); |
| 728 | 664 | } |
| 729 | 665 | |
| 730 | 666 | const device_type TO7_IO_LINE = &device_creator<to7_io_line_device>; |
| r21425 | r21426 | |
| 767 | 703 | int dsr = ( m_input_state & SERIAL_STATE_DSR ) ? 0 : 1; |
| 768 | 704 | int rd = get_in_data_bit(); |
| 769 | 705 | |
| 770 | | if ( to7_io_mode(machine()) == TO7_IO_RS232 ) |
| 706 | if ( machine().driver_data<thomson_state>()->to7_io_mode() == TO7_IO_RS232 ) |
| 771 | 707 | cts = m_input_state & SERIAL_STATE_CTS ? 0 : 1; |
| 772 | 708 | else |
| 773 | 709 | cts = !printer->busy_r(); |
| 774 | 710 | |
| 775 | | LOG_IO(( "$%04x %f to7_io_porta_in: mode=%i cts=%i, dsr=%i, rd=%i\n", machine().device("maincpu")->safe_pcbase(), machine().time().as_double(), to7_io_mode(machine()), cts, dsr, rd )); |
| 711 | LOG_IO(( "$%04x %f to7_io_porta_in: mode=%i cts=%i, dsr=%i, rd=%i\n", machine().device("maincpu")->safe_pcbase(), machine().time().as_double(), machine().driver_data<thomson_state>()->to7_io_mode(), cts, dsr, rd )); |
| 776 | 712 | |
| 777 | 713 | return (dsr ? 0x20 : 0) | (cts ? 0x40 : 0) | (rd ? 0x80: 0); |
| 778 | 714 | } |
| 779 | 715 | |
| 780 | 716 | |
| 781 | 717 | |
| 782 | | static WRITE8_DEVICE_HANDLER( to7_io_portb_out ) |
| 718 | WRITE8_MEMBER( thomson_state::to7_io_portb_out ) |
| 783 | 719 | { |
| 784 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 720 | LOG_IO(( "$%04x %f to7_io_portb_out: CENTRONICS set data=$%02X\n", m_maincpu->pc(), machine().time().as_double(), data )); |
| 785 | 721 | |
| 786 | | LOG_IO(( "$%04x %f to7_io_portb_out: CENTRONICS set data=$%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data )); |
| 787 | | |
| 788 | 722 | /* set 8-bit data */ |
| 789 | | printer->write( space.machine().driver_data()->generic_space(), 0, data); |
| 723 | m_centronics->write( space, 0, data); |
| 790 | 724 | } |
| 791 | 725 | |
| 792 | 726 | |
| 793 | 727 | |
| 794 | | static WRITE8_DEVICE_HANDLER( to7_io_cb2_out ) |
| 728 | WRITE8_MEMBER( thomson_state::to7_io_cb2_out ) |
| 795 | 729 | { |
| 796 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 730 | LOG_IO(( "$%04x %f to7_io_cb2_out: CENTRONICS set strobe=%i\n", m_maincpu->pc(), machine().time().as_double(), data )); |
| 797 | 731 | |
| 798 | | LOG_IO(( "$%04x %f to7_io_cb2_out: CENTRONICS set strobe=%i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data )); |
| 799 | | |
| 800 | 732 | /* send STROBE to printer */ |
| 801 | | printer->strobe_w(data); |
| 733 | m_centronics->strobe_w(data); |
| 802 | 734 | } |
| 803 | 735 | |
| 804 | 736 | |
| r21425 | r21426 | |
| 820 | 752 | DEVCB_NULL, |
| 821 | 753 | DEVCB_NULL, |
| 822 | 754 | DEVCB_DEVICE_MEMBER("to7_io", to7_io_line_device, porta_out), |
| 823 | | DEVCB_HANDLER(to7_io_portb_out), |
| 755 | DEVCB_DRIVER_MEMBER(thomson_state, to7_io_portb_out), |
| 824 | 756 | DEVCB_NULL, |
| 825 | | DEVCB_HANDLER(to7_io_cb2_out), |
| 826 | | DEVCB_LINE(thom_firq_1), |
| 827 | | DEVCB_LINE(thom_firq_1) |
| 757 | DEVCB_DRIVER_MEMBER(thomson_state, to7_io_cb2_out), |
| 758 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1), |
| 759 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1) |
| 828 | 760 | }; |
| 829 | 761 | |
| 830 | 762 | |
| 831 | 763 | const centronics_interface to7_centronics_config = |
| 832 | 764 | { |
| 833 | | DEVCB_LINE(to7_io_ack), |
| 765 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_io_ack), |
| 834 | 766 | DEVCB_NULL, |
| 835 | 767 | DEVCB_NULL |
| 836 | 768 | }; |
| r21425 | r21426 | |
| 871 | 803 | */ |
| 872 | 804 | |
| 873 | 805 | |
| 874 | | |
| 875 | | static UINT8 to7_modem_rx; |
| 876 | | |
| 877 | | static UINT8 to7_modem_tx; |
| 878 | | |
| 879 | | |
| 880 | | |
| 881 | | static void to7_modem_cb( device_t *device, int state ) |
| 806 | WRITE_LINE_MEMBER( thomson_state::to7_modem_cb ) |
| 882 | 807 | { |
| 883 | 808 | LOG(( "to7_modem_cb: called %i\n", state )); |
| 884 | 809 | } |
| r21425 | r21426 | |
| 901 | 826 | DEVCB_NULL |
| 902 | 827 | }; |
| 903 | 828 | |
| 904 | | static READ_LINE_DEVICE_HANDLER( to7_modem_rx_r ) |
| 829 | READ_LINE_MEMBER( thomson_state::to7_modem_rx_r ) |
| 905 | 830 | { |
| 906 | | return to7_modem_rx; |
| 831 | return m_to7_modem_rx; |
| 907 | 832 | } |
| 908 | 833 | |
| 909 | | static WRITE_LINE_DEVICE_HANDLER( to7_modem_tx_w ) |
| 834 | WRITE_LINE_MEMBER( thomson_state::to7_modem_tx_w ) |
| 910 | 835 | { |
| 911 | | to7_modem_tx = state; |
| 836 | m_to7_modem_tx = state; |
| 912 | 837 | } |
| 913 | 838 | |
| 914 | 839 | ACIA6850_INTERFACE( to7_modem ) |
| 915 | 840 | { |
| 916 | 841 | 1200, |
| 917 | 842 | 1200, /* 1200 bauds, might be divided by 16 */ |
| 918 | | DEVCB_LINE(to7_modem_rx_r), /*&to7_modem_rx,*/ |
| 919 | | DEVCB_LINE(to7_modem_tx_w), /*&to7_modem_tx,*/ |
| 843 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_modem_rx_r), /*&to7_modem_rx,*/ |
| 844 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_modem_tx_w), /*&to7_modem_tx,*/ |
| 920 | 845 | DEVCB_NULL, |
| 921 | 846 | DEVCB_NULL, |
| 922 | 847 | DEVCB_NULL, |
| 923 | | DEVCB_LINE(to7_modem_cb) |
| 848 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, to7_modem_cb) |
| 924 | 849 | }; |
| 925 | 850 | |
| 926 | 851 | |
| 927 | 852 | |
| 928 | | static void to7_modem_reset( running_machine &machine ) |
| 853 | void thomson_state::to7_modem_reset() |
| 929 | 854 | { |
| 930 | 855 | LOG (( "to7_modem_reset called\n" )); |
| 931 | | to7_modem_rx = 0; |
| 932 | | to7_modem_tx = 0; |
| 856 | m_to7_modem_rx = 0; |
| 857 | m_to7_modem_tx = 0; |
| 933 | 858 | /* pia_reset() is called in MACHINE_RESET */ |
| 934 | 859 | /* acia_6850 has no reset (?) */ |
| 935 | 860 | } |
| 936 | 861 | |
| 937 | 862 | |
| 938 | 863 | |
| 939 | | static void to7_modem_init( running_machine &machine ) |
| 864 | void thomson_state::to7_modem_init() |
| 940 | 865 | { |
| 941 | 866 | LOG (( "to7_modem_init: MODEM not implemented!\n" )); |
| 942 | | state_save_register_global( machine, to7_modem_rx ); |
| 943 | | state_save_register_global( machine, to7_modem_tx ); |
| 867 | save_item(NAME(m_to7_modem_rx)); |
| 868 | save_item(NAME(m_to7_modem_tx)); |
| 944 | 869 | } |
| 945 | 870 | |
| 946 | 871 | |
| r21425 | r21426 | |
| 951 | 876 | const mea8000_interface to7_speech = { "speech", DEVCB_NULL }; |
| 952 | 877 | |
| 953 | 878 | |
| 954 | | READ8_HANDLER ( to7_modem_mea8000_r ) |
| 879 | READ8_MEMBER( thomson_state::to7_modem_mea8000_r ) |
| 955 | 880 | { |
| 956 | 881 | if ( space.debugger_access() ) |
| 957 | 882 | { |
| 958 | 883 | return 0; |
| 959 | 884 | } |
| 960 | 885 | |
| 961 | | if ( space.machine().root_device().ioport("mconfig")->read() & 1 ) |
| 886 | if ( ioport("mconfig")->read() & 1 ) |
| 962 | 887 | { |
| 963 | | device_t* device = space.machine().device("mea8000" ); |
| 964 | | return mea8000_r( device, space, offset ); |
| 888 | return mea8000_r( m_mea8000, space, offset ); |
| 965 | 889 | } |
| 966 | 890 | else |
| 967 | 891 | { |
| 968 | | acia6850_device* acia = space.machine().device<acia6850_device>("acia6850" ); |
| 969 | 892 | switch (offset) { |
| 970 | | case 0: return acia->status_read(space, offset ); |
| 971 | | case 1: return acia->data_read(space, offset ); |
| 893 | case 0: return m_acia->status_read(space, offset ); |
| 894 | case 1: return m_acia->data_read(space, offset ); |
| 972 | 895 | default: return 0; |
| 973 | 896 | } |
| 974 | 897 | } |
| r21425 | r21426 | |
| 976 | 899 | |
| 977 | 900 | |
| 978 | 901 | |
| 979 | | WRITE8_HANDLER ( to7_modem_mea8000_w ) |
| 902 | WRITE8_MEMBER( thomson_state::to7_modem_mea8000_w ) |
| 980 | 903 | { |
| 981 | | if ( space.machine().root_device().ioport("mconfig")->read() & 1 ) |
| 904 | if ( ioport("mconfig")->read() & 1 ) |
| 982 | 905 | { |
| 983 | | device_t* device = space.machine().device("mea8000" ); |
| 984 | | mea8000_w( device, space, offset, data ); |
| 906 | mea8000_w( m_mea8000, space, offset, data ); |
| 985 | 907 | } |
| 986 | 908 | else |
| 987 | 909 | { |
| 988 | | acia6850_device* acia = space.machine().device<acia6850_device>("acia6850" ); |
| 989 | 910 | switch (offset) { |
| 990 | | case 0: acia->control_write( space, offset, data ); |
| 991 | | case 1: acia->data_write( space, offset, data ); |
| 911 | case 0: m_acia->control_write( space, offset, data ); |
| 912 | case 1: m_acia->data_write( space, offset, data ); |
| 992 | 913 | } |
| 993 | 914 | } |
| 994 | 915 | } |
| r21425 | r21426 | |
| 1012 | 933 | #define TO7_GAME_POLL_PERIOD attotime::from_usec( 500 ) |
| 1013 | 934 | |
| 1014 | 935 | |
| 1015 | | |
| 1016 | | /* calls to7_game_update_cb periodically */ |
| 1017 | | static emu_timer* to7_game_timer; |
| 1018 | | |
| 1019 | | static UINT8 to7_game_sound; |
| 1020 | | static UINT8 to7_game_mute; |
| 1021 | | |
| 1022 | | |
| 1023 | 936 | /* The mouse is a very simple phase quadrature one. |
| 1024 | 937 | Each axis provides two 1-bit signals, A and B, that are toggled by the |
| 1025 | 938 | axis rotation. The two signals are not in phase, so that whether A is |
| r21425 | r21426 | |
| 1027 | 940 | This is similar Atari & Amiga mouses. |
| 1028 | 941 | Returns: 0 0 0 0 0 0 YB XB YA XA |
| 1029 | 942 | */ |
| 1030 | | static UINT8 to7_get_mouse_signal( running_machine &machine ) |
| 943 | UINT8 thomson_state::to7_get_mouse_signal() |
| 1031 | 944 | { |
| 1032 | 945 | UINT8 xa, xb, ya, yb; |
| 1033 | | UINT16 dx = machine.root_device().ioport("mouse_x")->read(); /* x axis */ |
| 1034 | | UINT16 dy = machine.root_device().ioport("mouse_y")->read(); /* y axis */ |
| 946 | UINT16 dx = ioport("mouse_x")->read(); /* x axis */ |
| 947 | UINT16 dy = ioport("mouse_y")->read(); /* y axis */ |
| 1035 | 948 | xa = ((dx + 1) & 3) <= 1; |
| 1036 | 949 | xb = (dx & 3) <= 1; |
| 1037 | 950 | ya = ((dy + 1) & 3) <= 1; |
| r21425 | r21426 | |
| 1041 | 954 | |
| 1042 | 955 | |
| 1043 | 956 | |
| 1044 | | static void to7_game_sound_update ( running_machine &machine ) |
| 957 | void thomson_state::to7_game_sound_update() |
| 1045 | 958 | { |
| 1046 | | machine.device<dac_device>("dac")->write_unsigned8(to7_game_mute ? 0 : (to7_game_sound << 2) ); |
| 959 | m_dac->write_unsigned8(m_to7_game_mute ? 0 : (m_to7_game_sound << 2) ); |
| 1047 | 960 | } |
| 1048 | 961 | |
| 1049 | 962 | |
| 1050 | 963 | |
| 1051 | | static READ8_DEVICE_HANDLER ( to7_game_porta_in ) |
| 964 | READ8_MEMBER( thomson_state::to7_game_porta_in ) |
| 1052 | 965 | { |
| 1053 | 966 | UINT8 data; |
| 1054 | | if ( space.machine().root_device().ioport("config")->read() & 1 ) |
| 967 | if ( ioport("config")->read() & 1 ) |
| 1055 | 968 | { |
| 1056 | 969 | /* mouse */ |
| 1057 | | data = to7_get_mouse_signal(space.machine()) & 0x0c; /* XB, YB */ |
| 1058 | | data |= space.machine().root_device().ioport("mouse_button")->read() & 3; /* buttons */ |
| 970 | data = to7_get_mouse_signal() & 0x0c; /* XB, YB */ |
| 971 | data |= ioport("mouse_button")->read() & 3; /* buttons */ |
| 1059 | 972 | } |
| 1060 | 973 | else |
| 1061 | 974 | { |
| 1062 | 975 | /* joystick */ |
| 1063 | | data = space.machine().root_device().ioport("game_port_directions")->read(); |
| 976 | data = ioport("game_port_directions")->read(); |
| 1064 | 977 | /* bit 0=0 => P1 up bit 4=0 => P2 up |
| 1065 | 978 | bit 1=0 => P1 down bit 5=0 => P2 down |
| 1066 | 979 | bit 2=0 => P1 left bit 6=0 => P2 left |
| r21425 | r21426 | |
| 1089 | 1002 | |
| 1090 | 1003 | |
| 1091 | 1004 | |
| 1092 | | static READ8_DEVICE_HANDLER ( to7_game_portb_in ) |
| 1005 | READ8_MEMBER( thomson_state::to7_game_portb_in ) |
| 1093 | 1006 | { |
| 1094 | 1007 | UINT8 data; |
| 1095 | | if ( space.machine().root_device().ioport("config")->read() & 1 ) |
| 1008 | if ( ioport("config")->read() & 1 ) |
| 1096 | 1009 | { |
| 1097 | 1010 | /* mouse */ |
| 1098 | | UINT8 mouse = to7_get_mouse_signal(space.machine()); |
| 1011 | UINT8 mouse = to7_get_mouse_signal(); |
| 1099 | 1012 | data = 0; |
| 1100 | 1013 | if ( mouse & 1 ) |
| 1101 | 1014 | data |= 0x04; /* XA */ |
| r21425 | r21426 | |
| 1109 | 1022 | /* bits 2-3: action buttons B (0=pressed) */ |
| 1110 | 1023 | /* bits 4-5: unused (ouput) */ |
| 1111 | 1024 | /* bits 0-1: unknown! */ |
| 1112 | | data = space.machine().root_device().ioport("game_port_buttons")->read(); |
| 1025 | data = ioport("game_port_buttons")->read(); |
| 1113 | 1026 | } |
| 1114 | 1027 | return data; |
| 1115 | 1028 | } |
| 1116 | 1029 | |
| 1117 | 1030 | |
| 1118 | 1031 | |
| 1119 | | static WRITE8_DEVICE_HANDLER ( to7_game_portb_out ) |
| 1032 | WRITE8_MEMBER( thomson_state::to7_game_portb_out ) |
| 1120 | 1033 | { |
| 1121 | 1034 | /* 6-bit DAC sound */ |
| 1122 | | to7_game_sound = data & 0x3f; |
| 1123 | | to7_game_sound_update(space.machine()); |
| 1035 | m_to7_game_sound = data & 0x3f; |
| 1036 | to7_game_sound_update(); |
| 1124 | 1037 | } |
| 1125 | 1038 | |
| 1126 | 1039 | |
| 1127 | 1040 | |
| 1128 | | static WRITE8_DEVICE_HANDLER ( to7_game_cb2_out ) |
| 1041 | WRITE8_MEMBER( thomson_state::to7_game_cb2_out ) |
| 1129 | 1042 | { |
| 1130 | 1043 | /* undocumented */ |
| 1131 | 1044 | /* some TO8 games (e.g.: F15) seem to write here a lot */ |
| r21425 | r21426 | |
| 1135 | 1048 | |
| 1136 | 1049 | const pia6821_interface to7_pia6821_game = |
| 1137 | 1050 | { |
| 1138 | | DEVCB_HANDLER(to7_game_porta_in), |
| 1139 | | DEVCB_HANDLER(to7_game_portb_in), |
| 1051 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_porta_in), |
| 1052 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_in), |
| 1140 | 1053 | DEVCB_NULL, |
| 1141 | 1054 | DEVCB_NULL, |
| 1142 | 1055 | DEVCB_NULL, |
| 1143 | 1056 | DEVCB_NULL, |
| 1144 | 1057 | DEVCB_NULL, |
| 1145 | | DEVCB_HANDLER(to7_game_portb_out), |
| 1058 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_out), |
| 1146 | 1059 | DEVCB_NULL, |
| 1147 | | DEVCB_HANDLER(to7_game_cb2_out), |
| 1148 | | DEVCB_LINE(thom_irq_1), |
| 1149 | | DEVCB_LINE(thom_irq_1) |
| 1060 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_cb2_out), |
| 1061 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1), |
| 1062 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) |
| 1150 | 1063 | }; |
| 1151 | 1064 | |
| 1152 | 1065 | |
| 1153 | 1066 | |
| 1154 | 1067 | /* this should be called periodically */ |
| 1155 | | static TIMER_CALLBACK(to7_game_update_cb) |
| 1068 | TIMER_CALLBACK_MEMBER(thomson_state::to7_game_update_cb) |
| 1156 | 1069 | { |
| 1157 | | pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME); |
| 1158 | | |
| 1159 | | if ( machine.root_device().ioport("config")->read() & 1 ) |
| 1070 | if ( ioport("config")->read() & 1 ) |
| 1160 | 1071 | { |
| 1161 | 1072 | /* mouse */ |
| 1162 | | UINT8 mouse = to7_get_mouse_signal(machine); |
| 1163 | | game_pia->ca1_w( (mouse & 1) ? 1 : 0 ); /* XA */ |
| 1164 | | game_pia->ca2_w( (mouse & 2) ? 1 : 0 ); /* YA */ |
| 1073 | UINT8 mouse = to7_get_mouse_signal(); |
| 1074 | m_pia_game->ca1_w( (mouse & 1) ? 1 : 0 ); /* XA */ |
| 1075 | m_pia_game->ca2_w( (mouse & 2) ? 1 : 0 ); /* YA */ |
| 1165 | 1076 | } |
| 1166 | 1077 | else |
| 1167 | 1078 | { |
| 1168 | 1079 | /* joystick */ |
| 1169 | | UINT8 in = machine.root_device().ioport("game_port_buttons")->read(); |
| 1170 | | game_pia->cb2_w( (in & 0x80) ? 1 : 0 ); /* P2 action A */ |
| 1171 | | game_pia->ca2_w( (in & 0x40) ? 1 : 0 ); /* P1 action A */ |
| 1172 | | game_pia->cb1_w( (in & 0x08) ? 1 : 0 ); /* P2 action B */ |
| 1173 | | game_pia->ca1_w( (in & 0x04) ? 1 : 0 ); /* P1 action B */ |
| 1080 | UINT8 in = ioport("game_port_buttons")->read(); |
| 1081 | m_pia_game->cb2_w( (in & 0x80) ? 1 : 0 ); /* P2 action A */ |
| 1082 | m_pia_game->ca2_w( (in & 0x40) ? 1 : 0 ); /* P1 action A */ |
| 1083 | m_pia_game->cb1_w( (in & 0x08) ? 1 : 0 ); /* P2 action B */ |
| 1084 | m_pia_game->ca1_w( (in & 0x04) ? 1 : 0 ); /* P1 action B */ |
| 1174 | 1085 | /* TODO: |
| 1175 | 1086 | it seems that CM 90-112 behaves differently |
| 1176 | 1087 | - ca1 is P1 action A, i.e., in & 0x40 |
| r21425 | r21426 | |
| 1185 | 1096 | |
| 1186 | 1097 | |
| 1187 | 1098 | |
| 1188 | | static void to7_game_init ( running_machine &machine ) |
| 1099 | void thomson_state::to7_game_init() |
| 1189 | 1100 | { |
| 1190 | 1101 | LOG (( "to7_game_init called\n" )); |
| 1191 | | to7_game_timer = machine.scheduler().timer_alloc(FUNC(to7_game_update_cb)); |
| 1192 | | to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD); |
| 1193 | | state_save_register_global( machine, to7_game_sound ); |
| 1194 | | state_save_register_global( machine, to7_game_mute ); |
| 1102 | m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to7_game_update_cb),this)); |
| 1103 | m_to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD); |
| 1104 | save_item(NAME(m_to7_game_sound)); |
| 1105 | save_item(NAME(m_to7_game_mute)); |
| 1195 | 1106 | } |
| 1196 | 1107 | |
| 1197 | 1108 | |
| 1198 | 1109 | |
| 1199 | | static void to7_game_reset ( running_machine &machine ) |
| 1110 | void thomson_state::to7_game_reset() |
| 1200 | 1111 | { |
| 1201 | | pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME); |
| 1202 | | |
| 1203 | 1112 | LOG (( "to7_game_reset called\n" )); |
| 1204 | | game_pia->ca1_w( 0 ); |
| 1205 | | to7_game_sound = 0; |
| 1206 | | to7_game_mute = 0; |
| 1207 | | to7_game_sound_update( machine ); |
| 1113 | m_pia_game->ca1_w( 0 ); |
| 1114 | m_to7_game_sound = 0; |
| 1115 | m_to7_game_mute = 0; |
| 1116 | to7_game_sound_update(); |
| 1208 | 1117 | } |
| 1209 | 1118 | |
| 1210 | 1119 | |
| r21425 | r21426 | |
| 1428 | 1337 | |
| 1429 | 1338 | |
| 1430 | 1339 | |
| 1431 | | READ8_HANDLER ( to7_midi_r ) |
| 1340 | READ8_MEMBER( thomson_state::to7_midi_r ) |
| 1432 | 1341 | { |
| 1433 | 1342 | logerror( "to7_midi_r: not implemented\n" ); |
| 1434 | 1343 | return 0; |
| r21425 | r21426 | |
| 1436 | 1345 | |
| 1437 | 1346 | |
| 1438 | 1347 | |
| 1439 | | WRITE8_HANDLER ( to7_midi_w ) |
| 1348 | WRITE8_MEMBER( thomson_state::to7_midi_w ) |
| 1440 | 1349 | { |
| 1441 | 1350 | logerror( "to7_midi_w: not implemented\n" ); |
| 1442 | 1351 | } |
| 1443 | 1352 | |
| 1444 | 1353 | |
| 1445 | 1354 | |
| 1446 | | static void to7_midi_reset( running_machine &machine ) |
| 1355 | void thomson_state::to7_midi_reset() |
| 1447 | 1356 | { |
| 1448 | 1357 | logerror( "to7_midi_reset: not implemented\n" ); |
| 1449 | 1358 | } |
| 1450 | 1359 | |
| 1451 | 1360 | |
| 1452 | 1361 | |
| 1453 | | static void to7_midi_init( running_machine &machine ) |
| 1362 | void thomson_state::to7_midi_init() |
| 1454 | 1363 | { |
| 1455 | 1364 | logerror( "to7_midi_init: not implemented\n" ); |
| 1456 | 1365 | } |
| r21425 | r21426 | |
| 1465 | 1374 | |
| 1466 | 1375 | |
| 1467 | 1376 | |
| 1468 | | MACHINE_RESET ( to7 ) |
| 1377 | MACHINE_RESET_MEMBER( thomson_state, to7 ) |
| 1469 | 1378 | { |
| 1470 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 1471 | | |
| 1472 | 1379 | LOG (( "to7: machine reset called\n" )); |
| 1473 | 1380 | |
| 1474 | 1381 | /* subsystems */ |
| 1475 | | thom_irq_reset(machine); |
| 1476 | | to7_game_reset(machine); |
| 1477 | | to7_floppy_reset(machine); |
| 1478 | | to7_modem_reset(machine); |
| 1479 | | to7_midi_reset(machine); |
| 1382 | thom_irq_reset(); |
| 1383 | to7_game_reset(); |
| 1384 | to7_floppy_reset(); |
| 1385 | to7_modem_reset(); |
| 1386 | to7_midi_reset(); |
| 1480 | 1387 | |
| 1481 | 1388 | /* video */ |
| 1482 | | thom_set_video_mode( machine, THOM_VMODE_TO770 ); |
| 1483 | | thom_set_init_callback( machine, to7_set_init ); |
| 1484 | | thom_set_lightpen_callback( machine, 3, to7_lightpen_cb ); |
| 1485 | | thom_set_mode_point( machine, 0 ); |
| 1486 | | thom_set_border_color( machine, 0 ); |
| 1487 | | sys_pia->cb1_w( 0 ); |
| 1389 | thom_set_video_mode( THOM_VMODE_TO770 ); |
| 1390 | m_thom_init_cb = &thomson_state::to7_set_init; |
| 1391 | m_thom_lightpen_cb = &thomson_state::to7_lightpen_cb; |
| 1392 | thom_set_lightpen_callback( 3 ); |
| 1393 | thom_set_mode_point( 0 ); |
| 1394 | thom_set_border_color( 0 ); |
| 1395 | m_pia_sys->cb1_w( 0 ); |
| 1488 | 1396 | |
| 1489 | 1397 | /* memory */ |
| 1490 | | old_cart_bank = -1; |
| 1491 | | to7_update_cart_bank(machine); |
| 1398 | m_old_cart_bank = -1; |
| 1399 | to7_update_cart_bank(); |
| 1492 | 1400 | /* thom_cart_bank not reset */ |
| 1493 | 1401 | |
| 1494 | 1402 | /* lightpen */ |
| 1495 | | to7_lightpen = 0; |
| 1403 | m_to7_lightpen = 0; |
| 1496 | 1404 | } |
| 1497 | 1405 | |
| 1498 | 1406 | |
| 1499 | 1407 | |
| 1500 | | MACHINE_START ( to7 ) |
| 1408 | MACHINE_START_MEMBER( thomson_state, to7 ) |
| 1501 | 1409 | { |
| 1502 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 1503 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 1504 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 1410 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 1411 | UINT8* mem = memregion("maincpu")->base(); |
| 1412 | UINT8* ram = m_ram->pointer(); |
| 1505 | 1413 | |
| 1506 | 1414 | LOG (( "to7: machine start called\n" )); |
| 1507 | 1415 | |
| 1508 | 1416 | /* subsystems */ |
| 1509 | | thom_irq_init(machine); |
| 1510 | | to7_game_init(machine); |
| 1511 | | to7_floppy_init(machine, mem + 0x20000); |
| 1512 | | to7_modem_init(machine); |
| 1513 | | to7_midi_init(machine); |
| 1417 | thom_irq_init(); |
| 1418 | to7_game_init(); |
| 1419 | to7_floppy_init(mem + 0x20000); |
| 1420 | to7_modem_init(); |
| 1421 | to7_midi_init(); |
| 1514 | 1422 | |
| 1515 | 1423 | /* memory */ |
| 1516 | | thom_cart_bank = 0; |
| 1517 | | thom_vram = ram; |
| 1518 | | machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 1519 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 ); |
| 1520 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 1521 | | machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 1522 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 1523 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 1424 | m_thom_cart_bank = 0; |
| 1425 | m_thom_vram = ram; |
| 1426 | membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 1427 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 ); |
| 1428 | membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 1429 | membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 1430 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 1431 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 1524 | 1432 | |
| 1525 | | if ( machine.device<ram_device>(RAM_TAG)->size() > 24*1024 ) |
| 1433 | if ( m_ram->size() > 24*1024 ) |
| 1526 | 1434 | { |
| 1527 | 1435 | /* install 16 KB or 16 KB + 8 KB memory extensions */ |
| 1528 | 1436 | /* BASIC instruction to see free memory: ?FRE(0) */ |
| 1529 | | int extram = machine.device<ram_device>(RAM_TAG)->size() - 24*1024; |
| 1437 | int extram = m_ram->size() - 24*1024; |
| 1530 | 1438 | space.install_write_bank(0x8000, 0x8000 + extram - 1, THOM_RAM_BANK); |
| 1531 | 1439 | space.install_read_bank(0x8000, 0x8000 + extram - 1, THOM_RAM_BANK ); |
| 1532 | | machine.root_device().membank( THOM_RAM_BANK )->configure_entry( 0, ram + 0x6000); |
| 1533 | | machine.root_device().membank( THOM_RAM_BANK )->set_entry( 0 ); |
| 1440 | membank( THOM_RAM_BANK )->configure_entry( 0, ram + 0x6000); |
| 1441 | membank( THOM_RAM_BANK )->set_entry( 0 ); |
| 1534 | 1442 | } |
| 1535 | 1443 | |
| 1536 | 1444 | /* force 2 topmost color bits to 1 */ |
| 1537 | | memset( thom_vram + 0x2000, 0xc0, 0x2000 ); |
| 1445 | memset( m_thom_vram + 0x2000, 0xc0, 0x2000 ); |
| 1538 | 1446 | |
| 1539 | 1447 | /* save-state */ |
| 1540 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 1541 | | state_save_register_global( machine, thom_cart_bank ); |
| 1542 | | state_save_register_global( machine, to7_lightpen ); |
| 1543 | | state_save_register_global( machine, to7_lightpen_step ); |
| 1544 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 1545 | | machine.save().register_postload(save_prepost_delegate(FUNC(to7_update_cart_bank_postload), &machine)); |
| 1448 | save_item(NAME(m_thom_cart_nb_banks)); |
| 1449 | save_item(NAME(m_thom_cart_bank)); |
| 1450 | save_item(NAME(m_to7_lightpen)); |
| 1451 | save_item(NAME(m_to7_lightpen_step)); |
| 1452 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 1453 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to7_update_cart_bank_postload),this)); |
| 1546 | 1454 | } |
| 1547 | 1455 | |
| 1548 | 1456 | |
| r21425 | r21426 | |
| 1555 | 1463 | |
| 1556 | 1464 | |
| 1557 | 1465 | |
| 1558 | | static WRITE8_DEVICE_HANDLER ( to770_sys_cb2_out ) |
| 1466 | WRITE8_MEMBER( thomson_state::to770_sys_cb2_out ) |
| 1559 | 1467 | { |
| 1560 | 1468 | /* video overlay: black pixels are transparent and show TV image underneath */ |
| 1561 | | LOG(( "$%04x to770_sys_cb2_out: video overlay %i\n", space.machine().device("maincpu")->safe_pcbase(), data )); |
| 1469 | LOG(( "$%04x to770_sys_cb2_out: video overlay %i\n", m_maincpu->pc(), data )); |
| 1562 | 1470 | } |
| 1563 | 1471 | |
| 1564 | 1472 | |
| 1565 | 1473 | |
| 1566 | | static READ8_DEVICE_HANDLER ( to770_sys_porta_in ) |
| 1474 | READ8_MEMBER( thomson_state::to770_sys_porta_in ) |
| 1567 | 1475 | { |
| 1568 | 1476 | /* keyboard */ |
| 1569 | 1477 | static const char *const keynames[] = { |
| 1570 | 1478 | "keyboard_0", "keyboard_1", "keyboard_2", "keyboard_3", |
| 1571 | 1479 | "keyboard_4", "keyboard_5", "keyboard_6", "keyboard_7" |
| 1572 | 1480 | }; |
| 1573 | | int keyline = downcast<pia6821_device *>(device)->b_output() & 7; |
| 1481 | int keyline = m_pia_sys->b_output() & 7; |
| 1574 | 1482 | |
| 1575 | | return space.machine().root_device().ioport(keynames[7 - keyline])->read(); |
| 1483 | return ioport(keynames[7 - keyline])->read(); |
| 1576 | 1484 | } |
| 1577 | 1485 | |
| 1578 | 1486 | |
| 1579 | 1487 | |
| 1580 | | static void to770_update_ram_bank(running_machine &machine) |
| 1488 | void thomson_state::to770_update_ram_bank() |
| 1581 | 1489 | { |
| 1582 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 1583 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 1584 | | UINT8 portb = sys_pia->port_b_z_mask(); |
| 1490 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 1491 | UINT8 portb = m_pia_sys->port_b_z_mask(); |
| 1585 | 1492 | int bank; |
| 1586 | 1493 | |
| 1587 | 1494 | switch (portb & 0xf8) |
| r21425 | r21426 | |
| 1604 | 1511 | return; |
| 1605 | 1512 | } |
| 1606 | 1513 | |
| 1607 | | if ( bank != old_ram_bank ) |
| 1514 | if ( bank != m_old_ram_bank ) |
| 1515 | { |
| 1516 | if ( m_ram->size() == 128*1024 || bank < 2 ) |
| 1608 | 1517 | { |
| 1609 | | if ( machine.device<ram_device>(RAM_TAG)->size() == 128*1024 || bank < 2 ) |
| 1610 | | { |
| 1611 | | machine.root_device().membank( THOM_RAM_BANK )->set_entry( bank ); |
| 1518 | membank( THOM_RAM_BANK )->set_entry( bank ); |
| 1612 | 1519 | } |
| 1613 | | else |
| 1614 | | { |
| 1520 | else |
| 1521 | { |
| 1615 | 1522 | /* RAM size is 48 KB only and unavailable bank |
| 1616 | 1523 | * requested */ |
| 1617 | 1524 | space.nop_readwrite(0xa000, 0xdfff); |
| 1618 | 1525 | } |
| 1619 | | old_ram_bank = bank; |
| 1526 | m_old_ram_bank = bank; |
| 1620 | 1527 | LOG_BANK(( "to770_update_ram_bank: RAM bank change %i\n", bank )); |
| 1621 | 1528 | } |
| 1622 | 1529 | } |
| 1623 | 1530 | |
| 1624 | 1531 | |
| 1625 | 1532 | |
| 1626 | | static void to770_update_ram_bank_postload(running_machine *machine) |
| 1533 | void thomson_state::to770_update_ram_bank_postload() |
| 1627 | 1534 | { |
| 1628 | | to770_update_ram_bank(*machine); |
| 1535 | to770_update_ram_bank(); |
| 1629 | 1536 | } |
| 1630 | 1537 | |
| 1631 | 1538 | |
| 1632 | 1539 | |
| 1633 | | static WRITE8_DEVICE_HANDLER ( to770_sys_portb_out ) |
| 1540 | WRITE8_MEMBER( thomson_state::to770_sys_portb_out ) |
| 1634 | 1541 | { |
| 1635 | | to770_update_ram_bank(space.machine()); |
| 1542 | to770_update_ram_bank(); |
| 1636 | 1543 | } |
| 1637 | 1544 | |
| 1638 | 1545 | |
| 1639 | 1546 | |
| 1640 | 1547 | const pia6821_interface to770_pia6821_sys = |
| 1641 | 1548 | { |
| 1642 | | DEVCB_HANDLER(to770_sys_porta_in), |
| 1549 | DEVCB_DRIVER_MEMBER(thomson_state, to770_sys_porta_in), |
| 1643 | 1550 | DEVCB_NULL, |
| 1644 | 1551 | DEVCB_NULL, |
| 1645 | 1552 | DEVCB_NULL, |
| 1646 | 1553 | DEVCB_NULL, |
| 1647 | 1554 | DEVCB_NULL, |
| 1648 | 1555 | DEVCB_NULL, |
| 1649 | | DEVCB_HANDLER(to770_sys_portb_out), |
| 1650 | | DEVCB_HANDLER(to7_set_cassette_motor), |
| 1651 | | DEVCB_HANDLER(to770_sys_cb2_out), |
| 1652 | | DEVCB_LINE(thom_firq_1), |
| 1653 | | DEVCB_LINE(thom_firq_1) |
| 1556 | DEVCB_DRIVER_MEMBER(thomson_state, to770_sys_portb_out), |
| 1557 | DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor), |
| 1558 | DEVCB_DRIVER_MEMBER(thomson_state, to770_sys_cb2_out), |
| 1559 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1), |
| 1560 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1) |
| 1654 | 1561 | }; |
| 1655 | 1562 | |
| 1656 | 1563 | |
| r21425 | r21426 | |
| 1659 | 1566 | |
| 1660 | 1567 | |
| 1661 | 1568 | |
| 1662 | | static WRITE8_DEVICE_HANDLER ( to770_timer_port_out ) |
| 1569 | WRITE8_MEMBER( thomson_state::to770_timer_port_out ) |
| 1663 | 1570 | { |
| 1664 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank switch */ |
| 1665 | | thom_set_caps_led( space.machine(), (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */ |
| 1666 | | thom_set_border_color( space.machine(), |
| 1667 | | ((data & 0x10) ? 1 : 0) | /* 4-bit border color */ |
| 1668 | | ((data & 0x20) ? 2 : 0) | |
| 1669 | | ((data & 0x40) ? 4 : 0) | |
| 1670 | | ((data & 0x04) ? 0 : 8) ); |
| 1571 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 1572 | thom_set_caps_led( (data & 8) ? 1 : 0 ) ; /* bit 3: keyboard led */ |
| 1573 | thom_set_border_color( ((data & 0x10) ? 1 : 0) | /* 4-bit border color */ |
| 1574 | ((data & 0x20) ? 2 : 0) | |
| 1575 | ((data & 0x40) ? 4 : 0) | |
| 1576 | ((data & 0x04) ? 0 : 8) ); |
| 1671 | 1577 | } |
| 1672 | 1578 | |
| 1673 | 1579 | |
| 1674 | 1580 | |
| 1675 | 1581 | const mc6846_interface to770_timer = |
| 1676 | 1582 | { |
| 1677 | | DEVCB_HANDLER(to770_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to7_timer_cp2_out), |
| 1678 | | DEVCB_HANDLER(to7_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out), |
| 1679 | | DEVCB_LINE(thom_dev_irq_0) |
| 1583 | DEVCB_DRIVER_MEMBER(thomson_state, to770_timer_port_out), |
| 1584 | DEVCB_NULL, |
| 1585 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out), |
| 1586 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in), |
| 1587 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out), |
| 1588 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0) |
| 1680 | 1589 | }; |
| 1681 | 1590 | |
| 1682 | 1591 | |
| r21425 | r21426 | |
| 1685 | 1594 | |
| 1686 | 1595 | |
| 1687 | 1596 | |
| 1688 | | READ8_HANDLER ( to770_gatearray_r ) |
| 1597 | READ8_MEMBER( thomson_state::to770_gatearray_r ) |
| 1689 | 1598 | { |
| 1690 | | struct thom_vsignal v = thom_get_vsignal(space.machine()); |
| 1691 | | struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), TO7_LIGHTPEN_DECAL, to7_lightpen_step - 1, 0 ); |
| 1599 | struct thom_vsignal v = thom_get_vsignal(); |
| 1600 | struct thom_vsignal l = thom_get_lightpen_vsignal( TO7_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 0 ); |
| 1692 | 1601 | int count, inil, init, lt3; |
| 1693 | | count = to7_lightpen ? l.count : v.count; |
| 1694 | | inil = to7_lightpen ? l.inil : v.inil; |
| 1695 | | init = to7_lightpen ? l.init : v.init; |
| 1696 | | lt3 = to7_lightpen ? l.lt3 : v.lt3; |
| 1602 | count = m_to7_lightpen ? l.count : v.count; |
| 1603 | inil = m_to7_lightpen ? l.inil : v.inil; |
| 1604 | init = m_to7_lightpen ? l.init : v.init; |
| 1605 | lt3 = m_to7_lightpen ? l.lt3 : v.lt3; |
| 1697 | 1606 | |
| 1698 | 1607 | switch ( offset ) |
| 1699 | 1608 | { |
| r21425 | r21426 | |
| 1702 | 1611 | case 2: return (lt3 << 7) | (inil << 6); |
| 1703 | 1612 | case 3: return (init << 7); |
| 1704 | 1613 | default: |
| 1705 | | logerror( "$%04x to770_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 1614 | logerror( "$%04x to770_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset ); |
| 1706 | 1615 | return 0; |
| 1707 | 1616 | } |
| 1708 | 1617 | } |
| 1709 | 1618 | |
| 1710 | 1619 | |
| 1711 | 1620 | |
| 1712 | | WRITE8_HANDLER ( to770_gatearray_w ) |
| 1621 | WRITE8_MEMBER( thomson_state::to770_gatearray_w ) |
| 1713 | 1622 | { |
| 1714 | 1623 | if ( ! offset ) |
| 1715 | | to7_lightpen = data & 1; |
| 1624 | m_to7_lightpen = data & 1; |
| 1716 | 1625 | } |
| 1717 | 1626 | |
| 1718 | 1627 | |
| r21425 | r21426 | |
| 1721 | 1630 | |
| 1722 | 1631 | |
| 1723 | 1632 | |
| 1724 | | MACHINE_RESET( to770 ) |
| 1633 | MACHINE_RESET_MEMBER( thomson_state, to770 ) |
| 1725 | 1634 | { |
| 1726 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 1727 | | |
| 1728 | 1635 | LOG (( "to770: machine reset called\n" )); |
| 1729 | 1636 | |
| 1730 | 1637 | /* subsystems */ |
| 1731 | | thom_irq_reset(machine); |
| 1732 | | to7_game_reset(machine); |
| 1733 | | to7_floppy_reset(machine); |
| 1734 | | to7_modem_reset(machine); |
| 1735 | | to7_midi_reset(machine); |
| 1638 | thom_irq_reset(); |
| 1639 | to7_game_reset(); |
| 1640 | to7_floppy_reset(); |
| 1641 | to7_modem_reset(); |
| 1642 | to7_midi_reset(); |
| 1736 | 1643 | |
| 1737 | 1644 | /* video */ |
| 1738 | | thom_set_video_mode( machine, THOM_VMODE_TO770 ); |
| 1739 | | thom_set_init_callback( machine, to7_set_init ); |
| 1740 | | thom_set_lightpen_callback( machine, 3, to7_lightpen_cb ); |
| 1741 | | thom_set_mode_point( machine, 0 ); |
| 1742 | | thom_set_border_color( machine, 8 ); |
| 1743 | | sys_pia->cb1_w( 0 ); |
| 1645 | thom_set_video_mode( THOM_VMODE_TO770 ); |
| 1646 | m_thom_init_cb = &thomson_state::to7_set_init; |
| 1647 | m_thom_lightpen_cb = &thomson_state::to7_lightpen_cb; |
| 1648 | thom_set_lightpen_callback( 3 ); |
| 1649 | thom_set_mode_point( 0 ); |
| 1650 | thom_set_border_color( 8 ); |
| 1651 | m_pia_sys->cb1_w( 0 ); |
| 1744 | 1652 | |
| 1745 | 1653 | /* memory */ |
| 1746 | | old_ram_bank = -1; |
| 1747 | | old_cart_bank = -1; |
| 1748 | | to7_update_cart_bank(machine); |
| 1749 | | to770_update_ram_bank(machine); |
| 1654 | m_old_ram_bank = -1; |
| 1655 | m_old_cart_bank = -1; |
| 1656 | to7_update_cart_bank(); |
| 1657 | to770_update_ram_bank(); |
| 1750 | 1658 | /* thom_cart_bank not reset */ |
| 1751 | 1659 | |
| 1752 | 1660 | /* lightpen */ |
| 1753 | | to7_lightpen = 0; |
| 1661 | m_to7_lightpen = 0; |
| 1754 | 1662 | } |
| 1755 | 1663 | |
| 1756 | 1664 | |
| 1757 | 1665 | |
| 1758 | | MACHINE_START ( to770 ) |
| 1666 | MACHINE_START_MEMBER( thomson_state, to770 ) |
| 1759 | 1667 | { |
| 1760 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 1761 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 1668 | UINT8* mem = memregion("maincpu")->base(); |
| 1669 | UINT8* ram = m_ram->pointer(); |
| 1762 | 1670 | |
| 1763 | 1671 | LOG (( "to770: machine start called\n" )); |
| 1764 | 1672 | |
| 1765 | 1673 | /* subsystems */ |
| 1766 | | thom_irq_init(machine); |
| 1767 | | to7_game_init(machine); |
| 1768 | | to7_floppy_init( machine, mem + 0x20000 ); |
| 1769 | | to7_modem_init(machine); |
| 1770 | | to7_midi_init(machine); |
| 1674 | thom_irq_init(); |
| 1675 | to7_game_init(); |
| 1676 | to7_floppy_init( mem + 0x20000 ); |
| 1677 | to7_modem_init(); |
| 1678 | to7_midi_init(); |
| 1771 | 1679 | |
| 1772 | 1680 | /* memory */ |
| 1773 | | thom_cart_bank = 0; |
| 1774 | | thom_vram = ram; |
| 1775 | | machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 1776 | | machine.root_device().membank( THOM_RAM_BANK )->configure_entries( 0, 6, ram + 0x8000, 0x4000 ); |
| 1777 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 ); |
| 1778 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 1779 | | machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 1780 | | machine.root_device().membank( THOM_RAM_BANK )->set_entry( 0 ); |
| 1781 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 1782 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 1681 | m_thom_cart_bank = 0; |
| 1682 | m_thom_vram = ram; |
| 1683 | membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 1684 | membank( THOM_RAM_BANK )->configure_entries( 0, 6, ram + 0x8000, 0x4000 ); |
| 1685 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 ); |
| 1686 | membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 1687 | membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 1688 | membank( THOM_RAM_BANK )->set_entry( 0 ); |
| 1689 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 1690 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 1783 | 1691 | |
| 1784 | 1692 | /* save-state */ |
| 1785 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 1786 | | state_save_register_global( machine, thom_cart_bank ); |
| 1787 | | state_save_register_global( machine, to7_lightpen ); |
| 1788 | | state_save_register_global( machine, to7_lightpen_step ); |
| 1789 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 1790 | | machine.save().register_postload(save_prepost_delegate(FUNC(to770_update_ram_bank_postload), &machine)); |
| 1791 | | machine.save().register_postload(save_prepost_delegate(FUNC(to7_update_cart_bank_postload), &machine)); |
| 1693 | save_item(NAME(m_thom_cart_nb_banks)); |
| 1694 | save_item(NAME(m_thom_cart_bank)); |
| 1695 | save_item(NAME(m_to7_lightpen)); |
| 1696 | save_item(NAME(m_to7_lightpen_step)); |
| 1697 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 1698 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to770_update_ram_bank_postload), this)); |
| 1699 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to7_update_cart_bank_postload), this)); |
| 1792 | 1700 | } |
| 1793 | 1701 | |
| 1794 | 1702 | |
| r21425 | r21426 | |
| 1801 | 1709 | |
| 1802 | 1710 | |
| 1803 | 1711 | |
| 1804 | | static void mo5_lightpen_cb ( running_machine &machine, int step ) |
| 1712 | void thomson_state::mo5_lightpen_cb( int step ) |
| 1805 | 1713 | { |
| 1806 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 1807 | | |
| 1808 | 1714 | /* MO5 signals ca1 (TO7 signals cb1) */ |
| 1809 | | if ( ! to7_lightpen ) |
| 1715 | if ( ! m_to7_lightpen ) |
| 1810 | 1716 | return; |
| 1811 | 1717 | |
| 1812 | | sys_pia->ca1_w( 1 ); |
| 1813 | | sys_pia->ca1_w( 0 ); |
| 1814 | | to7_lightpen_step = step; |
| 1718 | m_pia_sys->ca1_w( 1 ); |
| 1719 | m_pia_sys->ca1_w( 0 ); |
| 1720 | m_to7_lightpen_step = step; |
| 1815 | 1721 | } |
| 1816 | 1722 | |
| 1817 | 1723 | |
| r21425 | r21426 | |
| 1822 | 1728 | */ |
| 1823 | 1729 | |
| 1824 | 1730 | |
| 1825 | | |
| 1826 | | static emu_timer* mo5_periodic_timer; |
| 1827 | | |
| 1828 | | |
| 1829 | | |
| 1830 | | static TIMER_CALLBACK(mo5_periodic_cb) |
| 1731 | TIMER_CALLBACK_MEMBER(thomson_state::mo5_periodic_cb) |
| 1831 | 1732 | { |
| 1832 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 1833 | | |
| 1834 | 1733 | /* pulse */ |
| 1835 | | sys_pia->cb1_w( 1 ); |
| 1836 | | sys_pia->cb1_w( 0 ); |
| 1734 | m_pia_sys->cb1_w( 1 ); |
| 1735 | m_pia_sys->cb1_w( 0 ); |
| 1837 | 1736 | } |
| 1838 | 1737 | |
| 1839 | 1738 | |
| 1840 | 1739 | |
| 1841 | | static void mo5_init_timer(running_machine &machine) |
| 1740 | void thomson_state::mo5_init_timer() |
| 1842 | 1741 | { |
| 1843 | 1742 | /* time is a little faster than 50 Hz to match video framerate */ |
| 1844 | | mo5_periodic_timer->adjust(attotime::zero, 0, attotime::from_usec( 19968 )); |
| 1743 | m_mo5_periodic_timer->adjust(attotime::zero, 0, attotime::from_usec( 19968 )); |
| 1845 | 1744 | } |
| 1846 | 1745 | |
| 1847 | 1746 | |
| r21425 | r21426 | |
| 1850 | 1749 | |
| 1851 | 1750 | |
| 1852 | 1751 | |
| 1853 | | static WRITE8_DEVICE_HANDLER ( mo5_sys_porta_out ) |
| 1752 | WRITE8_MEMBER( thomson_state::mo5_sys_porta_out ) |
| 1854 | 1753 | { |
| 1855 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank switch */ |
| 1856 | | thom_set_border_color( space.machine(), (data >> 1) & 15 ); /* bit 1-4: border color */ |
| 1857 | | mo5_set_cassette( space.machine(), (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */ |
| 1754 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 1755 | thom_set_border_color( (data >> 1) & 15 ); /* bit 1-4: border color */ |
| 1756 | mo5_set_cassette( (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */ |
| 1858 | 1757 | } |
| 1859 | 1758 | |
| 1860 | 1759 | |
| 1861 | 1760 | |
| 1862 | | static READ8_DEVICE_HANDLER ( mo5_sys_porta_in ) |
| 1761 | READ8_MEMBER( thomson_state::mo5_sys_porta_in ) |
| 1863 | 1762 | { |
| 1864 | 1763 | return |
| 1865 | | (mo5_get_cassette(space.machine()) ? 0x80 : 0) | /* bit 7: cassette input */ |
| 1866 | | ((space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 0x20 : 0) |
| 1764 | (mo5_get_cassette() ? 0x80 : 0) | /* bit 7: cassette input */ |
| 1765 | ((ioport("lightpen_button")->read() & 1) ? 0x20 : 0) |
| 1867 | 1766 | /* bit 5: lightpen button */; |
| 1868 | 1767 | } |
| 1869 | 1768 | |
| 1870 | 1769 | |
| 1871 | 1770 | |
| 1872 | | static WRITE8_DEVICE_HANDLER ( mo5_sys_portb_out ) |
| 1771 | WRITE8_MEMBER( thomson_state::mo5_sys_portb_out ) |
| 1873 | 1772 | { |
| 1874 | | space.machine().device<dac_device>("buzzer")->write_unsigned8((data & 1) ? 0x80 : 0); /* 1-bit buzzer */ |
| 1773 | m_buzzer->write_unsigned8((data & 1) ? 0x80 : 0); /* 1-bit buzzer */ |
| 1875 | 1774 | } |
| 1876 | 1775 | |
| 1877 | 1776 | |
| 1878 | 1777 | |
| 1879 | | static READ8_DEVICE_HANDLER ( mo5_sys_portb_in ) |
| 1778 | READ8_MEMBER( thomson_state::mo5_sys_portb_in ) |
| 1880 | 1779 | { |
| 1881 | | UINT8 portb = downcast<pia6821_device *>(device)->b_output(); |
| 1780 | UINT8 portb = m_pia_sys->b_output(); |
| 1882 | 1781 | int col = (portb >> 1) & 7; /* key column */ |
| 1883 | 1782 | int lin = 7 - ((portb >> 4) & 7); /* key line */ |
| 1884 | 1783 | static const char *const keynames[] = { |
| r21425 | r21426 | |
| 1886 | 1785 | "keyboard_4", "keyboard_5", "keyboard_6", "keyboard_7" |
| 1887 | 1786 | }; |
| 1888 | 1787 | |
| 1889 | | return ( space.machine().root_device().ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0; |
| 1788 | return ( ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0; |
| 1890 | 1789 | } |
| 1891 | 1790 | |
| 1892 | 1791 | |
| 1893 | 1792 | |
| 1894 | 1793 | const pia6821_interface mo5_pia6821_sys = |
| 1895 | 1794 | { |
| 1896 | | DEVCB_HANDLER(mo5_sys_porta_in), |
| 1897 | | DEVCB_HANDLER(mo5_sys_portb_in), |
| 1795 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_porta_in), |
| 1796 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_portb_in), |
| 1898 | 1797 | DEVCB_NULL, |
| 1899 | 1798 | DEVCB_NULL, |
| 1900 | 1799 | DEVCB_NULL, |
| 1901 | 1800 | DEVCB_NULL, |
| 1902 | | DEVCB_HANDLER(mo5_sys_porta_out), |
| 1903 | | DEVCB_HANDLER(mo5_sys_portb_out), |
| 1904 | | DEVCB_HANDLER(mo5_set_cassette_motor), |
| 1801 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_porta_out), |
| 1802 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_sys_portb_out), |
| 1803 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_set_cassette_motor), |
| 1905 | 1804 | DEVCB_NULL, |
| 1906 | | DEVCB_LINE(thom_firq_1), |
| 1907 | | DEVCB_LINE(thom_irq_1) /* WARNING: differs from TO7 ! */ |
| 1805 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1), |
| 1806 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) /* WARNING: differs from TO7 ! */ |
| 1908 | 1807 | }; |
| 1909 | 1808 | |
| 1910 | 1809 | |
| r21425 | r21426 | |
| 1917 | 1816 | |
| 1918 | 1817 | |
| 1919 | 1818 | |
| 1920 | | READ8_HANDLER ( mo5_gatearray_r ) |
| 1819 | READ8_MEMBER( thomson_state::mo5_gatearray_r ) |
| 1921 | 1820 | { |
| 1922 | | struct thom_vsignal v = thom_get_vsignal(space.machine()); |
| 1923 | | struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), MO5_LIGHTPEN_DECAL, to7_lightpen_step - 1, 0 ); |
| 1821 | struct thom_vsignal v = thom_get_vsignal(); |
| 1822 | struct thom_vsignal l = thom_get_lightpen_vsignal( MO5_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 0 ); |
| 1924 | 1823 | int count, inil, init, lt3; |
| 1925 | | count = to7_lightpen ? l.count : v.count; |
| 1926 | | inil = to7_lightpen ? l.inil : v.inil; |
| 1927 | | init = to7_lightpen ? l.init : v.init; |
| 1928 | | lt3 = to7_lightpen ? l.lt3 : v.lt3; |
| 1824 | count = m_to7_lightpen ? l.count : v.count; |
| 1825 | inil = m_to7_lightpen ? l.inil : v.inil; |
| 1826 | init = m_to7_lightpen ? l.init : v.init; |
| 1827 | lt3 = m_to7_lightpen ? l.lt3 : v.lt3; |
| 1929 | 1828 | |
| 1930 | 1829 | switch ( offset ) { |
| 1931 | 1830 | case 0: return (count >> 8) & 0xff; |
| r21425 | r21426 | |
| 1933 | 1832 | case 2: return (lt3 << 7) | (inil << 6); |
| 1934 | 1833 | case 3: return (init << 7); |
| 1935 | 1834 | default: |
| 1936 | | logerror( "$%04x mo5_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 1835 | logerror( "$%04x mo5_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset ); |
| 1937 | 1836 | return 0; |
| 1938 | 1837 | } |
| 1939 | 1838 | } |
| 1940 | 1839 | |
| 1941 | 1840 | |
| 1942 | 1841 | |
| 1943 | | WRITE8_HANDLER ( mo5_gatearray_w ) |
| 1842 | WRITE8_MEMBER( thomson_state::mo5_gatearray_w ) |
| 1944 | 1843 | { |
| 1945 | 1844 | if ( ! offset ) |
| 1946 | | to7_lightpen = data & 1; |
| 1845 | m_to7_lightpen = data & 1; |
| 1947 | 1846 | } |
| 1948 | 1847 | |
| 1949 | 1848 | |
| r21425 | r21426 | |
| 1952 | 1851 | |
| 1953 | 1852 | |
| 1954 | 1853 | |
| 1955 | | static UINT8 mo5_reg_cart; /* 0xa7cb bank switch */ |
| 1956 | | |
| 1957 | | |
| 1958 | | |
| 1959 | 1854 | DEVICE_IMAGE_LOAD_MEMBER( thomson_state, mo5_cartridge ) |
| 1960 | 1855 | { |
| 1961 | | UINT8* pos = image.device().machine().root_device().memregion("maincpu")->base() + 0x10000; |
| 1856 | UINT8* pos = memregion("maincpu")->base() + 0x10000; |
| 1962 | 1857 | UINT64 size; |
| 1963 | 1858 | int i,j; |
| 1964 | 1859 | char name[129]; |
| r21425 | r21426 | |
| 1970 | 1865 | |
| 1971 | 1866 | /* get size & number of 16-KB banks */ |
| 1972 | 1867 | if ( size > 32 && size <= 0x04000 ) |
| 1973 | | thom_cart_nb_banks = 1; |
| 1868 | m_thom_cart_nb_banks = 1; |
| 1974 | 1869 | else if ( size == 0x08000 ) |
| 1975 | | thom_cart_nb_banks = 2; |
| 1870 | m_thom_cart_nb_banks = 2; |
| 1976 | 1871 | else if ( size == 0x10000 ) |
| 1977 | | thom_cart_nb_banks = 4; |
| 1872 | m_thom_cart_nb_banks = 4; |
| 1978 | 1873 | else |
| 1979 | 1874 | { |
| 1980 | 1875 | astring errmsg; |
| r21425 | r21426 | |
| 2009 | 1904 | if ( name[i] < ' ' || name[i] >= 127 ) name[i] = '?'; |
| 2010 | 1905 | } |
| 2011 | 1906 | |
| 2012 | | PRINT (( "mo5_cartridge_load: cartridge \"%s\" banks=%i, size=%u\n", name, thom_cart_nb_banks, (unsigned) size )); |
| 1907 | PRINT (( "mo5_cartridge_load: cartridge \"%s\" banks=%i, size=%u\n", name, m_thom_cart_nb_banks, (unsigned) size )); |
| 2013 | 1908 | |
| 2014 | 1909 | return IMAGE_INIT_PASS; |
| 2015 | 1910 | } |
| 2016 | 1911 | |
| 2017 | 1912 | |
| 2018 | 1913 | |
| 2019 | | static void mo5_update_cart_bank(running_machine &machine) |
| 1914 | void thomson_state::mo5_update_cart_bank() |
| 2020 | 1915 | { |
| 2021 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 2022 | | int rom_is_ram = mo5_reg_cart & 4; |
| 1916 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 1917 | int rom_is_ram = m_mo5_reg_cart & 4; |
| 2023 | 1918 | int bank = 0; |
| 2024 | 1919 | int bank_is_read_only = 0; |
| 2025 | 1920 | |
| 2026 | 1921 | |
| 2027 | | if ( rom_is_ram && thom_cart_nb_banks == 4 ) |
| 1922 | if ( rom_is_ram && m_thom_cart_nb_banks == 4 ) |
| 2028 | 1923 | { |
| 2029 | 1924 | /* 64 KB ROM from "JANE" cartridge */ |
| 2030 | | bank = mo5_reg_cart & 3; |
| 2031 | | if ( bank != old_cart_bank ) |
| 2032 | | { |
| 2033 | | if ( old_cart_bank < 0 || old_cart_bank > 3 ) |
| 2034 | | { |
| 1925 | bank = m_mo5_reg_cart & 3; |
| 1926 | if ( bank != m_old_cart_bank ) |
| 1927 | { |
| 1928 | if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 ) |
| 1929 | { |
| 2035 | 1930 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 2036 | 1931 | space.nop_write( 0xb000, 0xefff); |
| 2037 | 1932 | } |
| r21425 | r21426 | |
| 2041 | 1936 | else if ( rom_is_ram ) |
| 2042 | 1937 | { |
| 2043 | 1938 | /* 64 KB RAM from network extension */ |
| 2044 | | bank = 4 + ( mo5_reg_cart & 3 ); |
| 2045 | | bank_is_read_only = (( mo5_reg_cart & 8 ) == 0); |
| 1939 | bank = 4 + ( m_mo5_reg_cart & 3 ); |
| 1940 | bank_is_read_only = (( m_mo5_reg_cart & 8 ) == 0); |
| 2046 | 1941 | |
| 2047 | | if ( bank != old_cart_bank || bank_is_read_only != old_cart_bank_was_read_only) |
| 2048 | | { |
| 2049 | | if ( bank_is_read_only ) |
| 2050 | | { |
| 2051 | | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 2052 | | space.nop_write( 0xb000, 0xefff ); |
| 2053 | | } |
| 2054 | | else |
| 2055 | | { |
| 2056 | | space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 2057 | | } |
| 2058 | | LOG_BANK(( "mo5_update_cart_bank: CART is nanonetwork RAM bank %i (%s)\n", |
| 2059 | | mo5_reg_cart & 3, |
| 2060 | | bank_is_read_only ? "read-only":"read-write")); |
| 2061 | | old_cart_bank_was_read_only = bank_is_read_only; |
| 2062 | | } |
| 1942 | if ( bank != m_old_cart_bank || bank_is_read_only != m_old_cart_bank_was_read_only) |
| 1943 | { |
| 1944 | if ( bank_is_read_only ) |
| 1945 | { |
| 1946 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 1947 | space.nop_write( 0xb000, 0xefff ); |
| 1948 | } |
| 1949 | else |
| 1950 | { |
| 1951 | space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 1952 | } |
| 1953 | LOG_BANK(( "mo5_update_cart_bank: CART is nanonetwork RAM bank %i (%s)\n", |
| 1954 | m_mo5_reg_cart & 3, |
| 1955 | bank_is_read_only ? "read-only":"read-write")); |
| 1956 | m_old_cart_bank_was_read_only = bank_is_read_only; |
| 1957 | } |
| 2063 | 1958 | } |
| 2064 | 1959 | else |
| 2065 | 1960 | { |
| 2066 | 1961 | /* regular cartridge bank switch */ |
| 2067 | | if ( thom_cart_nb_banks ) |
| 1962 | if ( m_thom_cart_nb_banks ) |
| 2068 | 1963 | { |
| 2069 | | bank = thom_cart_bank % thom_cart_nb_banks; |
| 2070 | | if ( bank != old_cart_bank ) |
| 2071 | | { |
| 2072 | | if ( old_cart_bank < 0 ) |
| 2073 | | { |
| 1964 | bank = m_thom_cart_bank % m_thom_cart_nb_banks; |
| 1965 | if ( bank != m_old_cart_bank ) |
| 1966 | { |
| 1967 | if ( m_old_cart_bank < 0 ) |
| 1968 | { |
| 2074 | 1969 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 2075 | | space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo5_cartridge_w) ); |
| 2076 | | space.install_legacy_read_handler( 0xbffc, 0xbfff, FUNC(mo5_cartridge_r) ); |
| 1970 | space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo5_cartridge_w),this) ); |
| 1971 | space.install_read_handler( 0xbffc, 0xbfff, read8_delegate(FUNC(thomson_state::mo5_cartridge_r),this) ); |
| 2077 | 1972 | } |
| 2078 | 1973 | LOG_BANK(( "mo5_update_cart_bank: CART is cartridge bank %i\n", bank )); |
| 2079 | 1974 | } |
| 2080 | | } else |
| 1975 | } |
| 1976 | else |
| 1977 | { |
| 2081 | 1978 | /* internal ROM */ |
| 2082 | | if ( old_cart_bank != 0 ) |
| 1979 | if ( m_old_cart_bank != 0 ) |
| 2083 | 1980 | { |
| 2084 | 1981 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 2085 | | space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo5_cartridge_w) ); |
| 1982 | space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo5_cartridge_w),this) ); |
| 2086 | 1983 | LOG_BANK(( "mo5_update_cart_bank: CART is internal\n")); |
| 2087 | 1984 | } |
| 1985 | } |
| 2088 | 1986 | } |
| 2089 | | if ( bank != old_cart_bank ) |
| 2090 | | { |
| 2091 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( bank ); |
| 2092 | | old_cart_bank = bank; |
| 1987 | if ( bank != m_old_cart_bank ) |
| 1988 | { |
| 1989 | membank( THOM_CART_BANK )->set_entry( bank ); |
| 1990 | m_old_cart_bank = bank; |
| 2093 | 1991 | } |
| 2094 | 1992 | } |
| 2095 | 1993 | |
| 2096 | 1994 | |
| 2097 | 1995 | |
| 2098 | | static void mo5_update_cart_bank_postload(running_machine *machine) |
| 1996 | void thomson_state::mo5_update_cart_bank_postload() |
| 2099 | 1997 | { |
| 2100 | | mo5_update_cart_bank(*machine); |
| 1998 | mo5_update_cart_bank(); |
| 2101 | 1999 | } |
| 2102 | 2000 | |
| 2103 | 2001 | |
| 2104 | 2002 | |
| 2105 | 2003 | /* write signal to b000-cfff generates a bank switch */ |
| 2106 | | WRITE8_HANDLER ( mo5_cartridge_w ) |
| 2004 | WRITE8_MEMBER( thomson_state::mo5_cartridge_w ) |
| 2107 | 2005 | { |
| 2108 | 2006 | if ( offset >= 0x2000 ) |
| 2109 | 2007 | return; |
| 2110 | 2008 | |
| 2111 | | thom_cart_bank = offset & 3; |
| 2112 | | mo5_update_cart_bank(space.machine()); |
| 2009 | m_thom_cart_bank = offset & 3; |
| 2010 | mo5_update_cart_bank(); |
| 2113 | 2011 | } |
| 2114 | 2012 | |
| 2115 | 2013 | |
| 2116 | 2014 | |
| 2117 | 2015 | /* read signal to bffc-bfff generates a bank switch */ |
| 2118 | | READ8_HANDLER ( mo5_cartridge_r ) |
| 2016 | READ8_MEMBER( thomson_state::mo5_cartridge_r ) |
| 2119 | 2017 | { |
| 2120 | | UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000; |
| 2121 | | UINT8 data = pos[offset + 0xbffc + (thom_cart_bank % thom_cart_nb_banks) * 0x4000]; |
| 2018 | UINT8* pos = memregion( "maincpu" )->base() + 0x10000; |
| 2019 | UINT8 data = pos[offset + 0xbffc + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000]; |
| 2122 | 2020 | if ( !space.debugger_access() ) |
| 2123 | | { |
| 2124 | | thom_cart_bank = offset & 3; |
| 2125 | | mo5_update_cart_bank(space.machine()); |
| 2021 | { |
| 2022 | m_thom_cart_bank = offset & 3; |
| 2023 | mo5_update_cart_bank(); |
| 2126 | 2024 | } |
| 2127 | 2025 | return data; |
| 2128 | 2026 | } |
| r21425 | r21426 | |
| 2130 | 2028 | |
| 2131 | 2029 | |
| 2132 | 2030 | /* 0xa7cb bank-switch register */ |
| 2133 | | WRITE8_HANDLER ( mo5_ext_w ) |
| 2031 | WRITE8_MEMBER( thomson_state::mo5_ext_w ) |
| 2134 | 2032 | { |
| 2135 | | mo5_reg_cart = data; |
| 2136 | | mo5_update_cart_bank(space.machine()); |
| 2033 | m_mo5_reg_cart = data; |
| 2034 | mo5_update_cart_bank(); |
| 2137 | 2035 | } |
| 2138 | 2036 | |
| 2139 | 2037 | |
| r21425 | r21426 | |
| 2142 | 2040 | |
| 2143 | 2041 | |
| 2144 | 2042 | |
| 2145 | | MACHINE_RESET( mo5 ) |
| 2043 | MACHINE_RESET_MEMBER( thomson_state, mo5 ) |
| 2146 | 2044 | { |
| 2147 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 2148 | | |
| 2149 | 2045 | LOG (( "mo5: machine reset called\n" )); |
| 2150 | 2046 | |
| 2151 | 2047 | /* subsystems */ |
| 2152 | | thom_irq_reset(machine); |
| 2153 | | sys_pia->set_port_a_z_mask(0x5f ); |
| 2154 | | to7_game_reset(machine); |
| 2155 | | to7_floppy_reset(machine); |
| 2156 | | to7_modem_reset(machine); |
| 2157 | | to7_midi_reset(machine); |
| 2158 | | mo5_init_timer(machine); |
| 2048 | thom_irq_reset(); |
| 2049 | m_pia_sys->set_port_a_z_mask(0x5f ); |
| 2050 | to7_game_reset(); |
| 2051 | to7_floppy_reset(); |
| 2052 | to7_modem_reset(); |
| 2053 | to7_midi_reset(); |
| 2054 | mo5_init_timer(); |
| 2159 | 2055 | |
| 2160 | 2056 | /* video */ |
| 2161 | | thom_set_video_mode( machine, THOM_VMODE_MO5 ); |
| 2162 | | thom_set_lightpen_callback( machine, 3, mo5_lightpen_cb ); |
| 2163 | | thom_set_mode_point( machine, 0 ); |
| 2164 | | thom_set_border_color( machine, 0 ); |
| 2165 | | sys_pia->ca1_w( 0 ); |
| 2057 | thom_set_video_mode( THOM_VMODE_MO5 ); |
| 2058 | m_thom_lightpen_cb = &thomson_state::mo5_lightpen_cb; |
| 2059 | thom_set_lightpen_callback( 3 ); |
| 2060 | thom_set_mode_point( 0 ); |
| 2061 | thom_set_border_color( 0 ); |
| 2062 | m_pia_sys->ca1_w( 0 ); |
| 2166 | 2063 | |
| 2167 | 2064 | /* memory */ |
| 2168 | | old_cart_bank = -1; |
| 2169 | | mo5_update_cart_bank(machine); |
| 2065 | m_old_cart_bank = -1; |
| 2066 | mo5_update_cart_bank(); |
| 2170 | 2067 | /* mo5_reg_cart not reset */ |
| 2171 | 2068 | /* thom_cart_bank not reset */ |
| 2172 | 2069 | |
| 2173 | 2070 | /* lightpen */ |
| 2174 | | to7_lightpen = 0; |
| 2071 | m_to7_lightpen = 0; |
| 2175 | 2072 | } |
| 2176 | 2073 | |
| 2177 | 2074 | |
| 2178 | 2075 | |
| 2179 | | MACHINE_START ( mo5 ) |
| 2076 | MACHINE_START_MEMBER( thomson_state, mo5 ) |
| 2180 | 2077 | { |
| 2181 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 2182 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 2078 | UINT8* mem = memregion("maincpu")->base(); |
| 2079 | UINT8* ram = m_ram->pointer(); |
| 2183 | 2080 | |
| 2184 | 2081 | LOG (( "mo5: machine start called\n" )); |
| 2185 | 2082 | |
| 2186 | 2083 | /* subsystems */ |
| 2187 | | thom_irq_init(machine); |
| 2188 | | to7_game_init(machine); |
| 2189 | | to7_floppy_init( machine, mem + 0x20000 ); |
| 2190 | | to7_modem_init(machine); |
| 2191 | | to7_midi_init(machine); |
| 2192 | | mo5_periodic_timer = machine.scheduler().timer_alloc(FUNC(mo5_periodic_cb)); |
| 2084 | thom_irq_init(); |
| 2085 | to7_game_init(); |
| 2086 | to7_floppy_init( mem + 0x20000 ); |
| 2087 | to7_modem_init(); |
| 2088 | to7_midi_init(); |
| 2089 | m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo5_periodic_cb),this)); |
| 2193 | 2090 | |
| 2194 | 2091 | /* memory */ |
| 2195 | | thom_cart_bank = 0; |
| 2196 | | mo5_reg_cart = 0; |
| 2197 | | thom_vram = ram; |
| 2198 | | machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 2199 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 2200 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 4, 4, ram + 0xc000, 0x4000 ); |
| 2201 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 ); |
| 2202 | | machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 2203 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 2204 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 2092 | m_thom_cart_bank = 0; |
| 2093 | m_mo5_reg_cart = 0; |
| 2094 | m_thom_vram = ram; |
| 2095 | membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 2096 | membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 2097 | membank( THOM_CART_BANK )->configure_entries( 4, 4, ram + 0xc000, 0x4000 ); |
| 2098 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 ); |
| 2099 | membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 2100 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 2101 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 2205 | 2102 | |
| 2206 | 2103 | /* save-state */ |
| 2207 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 2208 | | state_save_register_global( machine, thom_cart_bank ); |
| 2209 | | state_save_register_global( machine, to7_lightpen ); |
| 2210 | | state_save_register_global( machine, to7_lightpen_step ); |
| 2211 | | state_save_register_global( machine, mo5_reg_cart ); |
| 2212 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 2213 | | machine.save().register_postload(save_prepost_delegate(FUNC(mo5_update_cart_bank_postload), &machine)); |
| 2104 | save_item(NAME(m_thom_cart_nb_banks)); |
| 2105 | save_item(NAME(m_thom_cart_bank)); |
| 2106 | save_item(NAME(m_to7_lightpen)); |
| 2107 | save_item(NAME(m_to7_lightpen_step)); |
| 2108 | save_item(NAME(m_mo5_reg_cart)); |
| 2109 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 2110 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo5_update_cart_bank_postload), this)); |
| 2214 | 2111 | } |
| 2215 | 2112 | |
| 2216 | 2113 | |
| r21425 | r21426 | |
| 2227 | 2124 | |
| 2228 | 2125 | |
| 2229 | 2126 | |
| 2230 | | WRITE8_HANDLER ( to9_ieee_w ) |
| 2127 | WRITE8_MEMBER( thomson_state::to9_ieee_w ) |
| 2231 | 2128 | { |
| 2232 | | logerror( "$%04x %f to9_ieee_w: unhandled write $%02X to register %i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data, offset ); |
| 2129 | logerror( "$%04x %f to9_ieee_w: unhandled write $%02X to register %i\n", m_maincpu->pc(), machine().time().as_double(), data, offset ); |
| 2233 | 2130 | } |
| 2234 | 2131 | |
| 2235 | 2132 | |
| 2236 | 2133 | |
| 2237 | | READ8_HANDLER ( to9_ieee_r ) |
| 2134 | READ8_MEMBER( thomson_state::to9_ieee_r ) |
| 2238 | 2135 | { |
| 2239 | | logerror( "$%04x %f to9_ieee_r: unhandled read from register %i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), offset ); |
| 2136 | logerror( "$%04x %f to9_ieee_r: unhandled read from register %i\n", m_maincpu->pc(), machine().time().as_double(), offset ); |
| 2240 | 2137 | return 0; |
| 2241 | 2138 | } |
| 2242 | 2139 | |
| r21425 | r21426 | |
| 2250 | 2147 | |
| 2251 | 2148 | |
| 2252 | 2149 | |
| 2253 | | READ8_HANDLER ( to9_gatearray_r ) |
| 2150 | READ8_MEMBER( thomson_state::to9_gatearray_r ) |
| 2254 | 2151 | { |
| 2255 | | struct thom_vsignal v = thom_get_vsignal(space.machine()); |
| 2256 | | struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), TO9_LIGHTPEN_DECAL, to7_lightpen_step - 1, 0 ); |
| 2152 | struct thom_vsignal v = thom_get_vsignal(); |
| 2153 | struct thom_vsignal l = thom_get_lightpen_vsignal( TO9_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 0 ); |
| 2257 | 2154 | int count, inil, init, lt3; |
| 2258 | | count = to7_lightpen ? l.count : v.count; |
| 2259 | | inil = to7_lightpen ? l.inil : v.inil; |
| 2260 | | init = to7_lightpen ? l.init : v.init; |
| 2261 | | lt3 = to7_lightpen ? l.lt3 : v.lt3; |
| 2155 | count = m_to7_lightpen ? l.count : v.count; |
| 2156 | inil = m_to7_lightpen ? l.inil : v.inil; |
| 2157 | init = m_to7_lightpen ? l.init : v.init; |
| 2158 | lt3 = m_to7_lightpen ? l.lt3 : v.lt3; |
| 2262 | 2159 | |
| 2263 | 2160 | switch ( offset ) |
| 2264 | 2161 | { |
| r21425 | r21426 | |
| 2267 | 2164 | case 2: return (lt3 << 7) | (inil << 6); |
| 2268 | 2165 | case 3: return (v.init << 7) | (init << 6); /* != TO7/70 */ |
| 2269 | 2166 | default: |
| 2270 | | logerror( "$%04x to9_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 2167 | logerror( "$%04x to9_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset ); |
| 2271 | 2168 | return 0; |
| 2272 | 2169 | } |
| 2273 | 2170 | } |
| 2274 | 2171 | |
| 2275 | 2172 | |
| 2276 | 2173 | |
| 2277 | | WRITE8_HANDLER ( to9_gatearray_w ) |
| 2174 | WRITE8_MEMBER( thomson_state::to9_gatearray_w ) |
| 2278 | 2175 | { |
| 2279 | 2176 | if ( ! offset ) |
| 2280 | | to7_lightpen = data & 1; |
| 2177 | m_to7_lightpen = data & 1; |
| 2281 | 2178 | } |
| 2282 | 2179 | |
| 2283 | 2180 | |
| r21425 | r21426 | |
| 2286 | 2183 | |
| 2287 | 2184 | |
| 2288 | 2185 | |
| 2289 | | static UINT8 to9_palette_data[32]; |
| 2290 | | |
| 2291 | | static UINT8 to9_palette_idx; |
| 2292 | | |
| 2293 | | |
| 2294 | 2186 | /* style: 0 => TO9, 1 => TO8/TO9, 2 => MO6 */ |
| 2295 | | static void to9_set_video_mode( running_machine &machine, UINT8 data, int style ) |
| 2187 | void thomson_state::to9_set_video_mode( UINT8 data, int style ) |
| 2296 | 2188 | { |
| 2297 | 2189 | switch ( data & 0x7f ) |
| 2298 | 2190 | { |
| 2299 | 2191 | case 0x00: |
| 2300 | 2192 | if ( style == 2 ) |
| 2301 | | thom_set_video_mode( machine, THOM_VMODE_MO5 ); |
| 2193 | thom_set_video_mode( THOM_VMODE_MO5 ); |
| 2302 | 2194 | else if ( style == 1 ) |
| 2303 | | thom_set_video_mode( machine, THOM_VMODE_TO770 ); |
| 2195 | thom_set_video_mode( THOM_VMODE_TO770 ); |
| 2304 | 2196 | else |
| 2305 | | thom_set_video_mode( machine, THOM_VMODE_TO9 ); |
| 2197 | thom_set_video_mode( THOM_VMODE_TO9 ); |
| 2306 | 2198 | break; |
| 2307 | 2199 | |
| 2308 | | case 0x21: thom_set_video_mode( machine, THOM_VMODE_BITMAP4 ); break; |
| 2200 | case 0x21: thom_set_video_mode( THOM_VMODE_BITMAP4 ); break; |
| 2309 | 2201 | |
| 2310 | | case 0x41: thom_set_video_mode( machine, THOM_VMODE_BITMAP4_ALT ); break; |
| 2202 | case 0x41: thom_set_video_mode( THOM_VMODE_BITMAP4_ALT ); break; |
| 2311 | 2203 | |
| 2312 | 2204 | case 0x2a: |
| 2313 | 2205 | if ( style==0 ) |
| 2314 | | thom_set_video_mode( machine, THOM_VMODE_80_TO9 ); |
| 2206 | thom_set_video_mode( THOM_VMODE_80_TO9 ); |
| 2315 | 2207 | else |
| 2316 | | thom_set_video_mode( machine, THOM_VMODE_80 ); |
| 2208 | thom_set_video_mode( THOM_VMODE_80 ); |
| 2317 | 2209 | break; |
| 2318 | 2210 | |
| 2319 | | case 0x7b: thom_set_video_mode( machine, THOM_VMODE_BITMAP16 ); break; |
| 2211 | case 0x7b: thom_set_video_mode( THOM_VMODE_BITMAP16 ); break; |
| 2320 | 2212 | |
| 2321 | | case 0x24: thom_set_video_mode( machine, THOM_VMODE_PAGE1 ); break; |
| 2213 | case 0x24: thom_set_video_mode( THOM_VMODE_PAGE1 ); break; |
| 2322 | 2214 | |
| 2323 | | case 0x25: thom_set_video_mode( machine, THOM_VMODE_PAGE2 ); break; |
| 2215 | case 0x25: thom_set_video_mode( THOM_VMODE_PAGE2 ); break; |
| 2324 | 2216 | |
| 2325 | | case 0x26: thom_set_video_mode( machine, THOM_VMODE_OVERLAY ); break; |
| 2217 | case 0x26: thom_set_video_mode( THOM_VMODE_OVERLAY ); break; |
| 2326 | 2218 | |
| 2327 | | case 0x3f: thom_set_video_mode( machine, THOM_VMODE_OVERLAY3 ); break; |
| 2219 | case 0x3f: thom_set_video_mode( THOM_VMODE_OVERLAY3 ); break; |
| 2328 | 2220 | |
| 2329 | 2221 | default: |
| 2330 | 2222 | logerror( "to9_set_video_mode: unknown mode $%02X tr=%i phi=%i mod=%i\n", data, (data >> 5) & 3, (data >> 3) & 2, data & 7 ); |
| r21425 | r21426 | |
| 2333 | 2225 | |
| 2334 | 2226 | |
| 2335 | 2227 | |
| 2336 | | READ8_HANDLER ( to9_vreg_r ) |
| 2228 | READ8_MEMBER( thomson_state::to9_vreg_r ) |
| 2337 | 2229 | { |
| 2338 | 2230 | switch ( offset ) |
| 2339 | 2231 | { |
| 2340 | 2232 | case 0: /* palette data */ |
| 2341 | 2233 | { |
| 2342 | | UINT8 c = to9_palette_data[ to9_palette_idx ]; |
| 2234 | UINT8 c = m_to9_palette_data[ m_to9_palette_idx ]; |
| 2343 | 2235 | if ( !space.debugger_access() ) |
| 2344 | | { |
| 2345 | | to9_palette_idx = ( to9_palette_idx + 1 ) & 31; |
| 2346 | | } |
| 2236 | { |
| 2237 | m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31; |
| 2238 | } |
| 2347 | 2239 | return c; |
| 2348 | 2240 | } |
| 2349 | 2241 | |
| 2350 | 2242 | case 1: /* palette address */ |
| 2351 | | return to9_palette_idx; |
| 2243 | return m_to9_palette_idx; |
| 2352 | 2244 | |
| 2353 | 2245 | case 2: |
| 2354 | 2246 | case 3: |
| r21425 | r21426 | |
| 2362 | 2254 | |
| 2363 | 2255 | |
| 2364 | 2256 | |
| 2365 | | WRITE8_HANDLER ( to9_vreg_w ) |
| 2257 | WRITE8_MEMBER( thomson_state::to9_vreg_w ) |
| 2366 | 2258 | { |
| 2367 | | LOG_VIDEO(( "$%04x %f to9_vreg_w: off=%i ($%04X) data=$%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), offset, 0xe7da + offset, data )); |
| 2259 | LOG_VIDEO(( "$%04x %f to9_vreg_w: off=%i ($%04X) data=$%02X\n", m_maincpu->pc(), machine().time().as_double(), offset, 0xe7da + offset, data )); |
| 2368 | 2260 | |
| 2369 | 2261 | switch ( offset ) |
| 2370 | 2262 | { |
| 2371 | 2263 | case 0: /* palette data */ |
| 2372 | 2264 | { |
| 2373 | 2265 | UINT16 color, idx; |
| 2374 | | to9_palette_data[ to9_palette_idx ] = data; |
| 2375 | | idx = to9_palette_idx / 2; |
| 2376 | | color = to9_palette_data[ 2 * idx + 1 ]; |
| 2377 | | color = to9_palette_data[ 2 * idx ] | (color << 8); |
| 2378 | | thom_set_palette( space.machine(), idx ^ 8, color & 0x1fff ); |
| 2266 | m_to9_palette_data[ m_to9_palette_idx ] = data; |
| 2267 | idx = m_to9_palette_idx / 2; |
| 2268 | color = m_to9_palette_data[ 2 * idx + 1 ]; |
| 2269 | color = m_to9_palette_data[ 2 * idx ] | (color << 8); |
| 2270 | thom_set_palette( idx ^ 8, color & 0x1fff ); |
| 2379 | 2271 | |
| 2380 | | to9_palette_idx = ( to9_palette_idx + 1 ) & 31; |
| 2272 | m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31; |
| 2381 | 2273 | } |
| 2382 | 2274 | break; |
| 2383 | 2275 | |
| 2384 | 2276 | case 1: /* palette address */ |
| 2385 | | to9_palette_idx = data & 31; |
| 2277 | m_to9_palette_idx = data & 31; |
| 2386 | 2278 | break; |
| 2387 | 2279 | |
| 2388 | 2280 | case 2: /* video mode */ |
| 2389 | | to9_set_video_mode( space.machine(), data, 0 ); |
| 2281 | to9_set_video_mode( data, 0 ); |
| 2390 | 2282 | break; |
| 2391 | 2283 | |
| 2392 | 2284 | case 3: /* border color */ |
| 2393 | | thom_set_border_color( space.machine(), data & 15 ); |
| 2285 | thom_set_border_color( data & 15 ); |
| 2394 | 2286 | break; |
| 2395 | 2287 | |
| 2396 | 2288 | default: |
| r21425 | r21426 | |
| 2400 | 2292 | |
| 2401 | 2293 | |
| 2402 | 2294 | |
| 2403 | | static void to9_palette_init ( running_machine &machine ) |
| 2295 | void thomson_state::to9_palette_init() |
| 2404 | 2296 | { |
| 2405 | | to9_palette_idx = 0; |
| 2406 | | memset( to9_palette_data, 0, sizeof( to9_palette_data ) ); |
| 2407 | | state_save_register_global( machine, to9_palette_idx ); |
| 2408 | | state_save_register_global_array( machine, to9_palette_data ); |
| 2297 | m_to9_palette_idx = 0; |
| 2298 | memset( m_to9_palette_data, 0, sizeof( m_to9_palette_data ) ); |
| 2299 | save_item(NAME(m_to9_palette_idx)); |
| 2300 | state_save_register_global_array( machine(), m_to9_palette_data ); |
| 2409 | 2301 | } |
| 2410 | 2302 | |
| 2411 | 2303 | |
| r21425 | r21426 | |
| 2413 | 2305 | /* ------------ RAM / ROM banking ------------ */ |
| 2414 | 2306 | |
| 2415 | 2307 | |
| 2416 | | static UINT8 to9_soft_bank; |
| 2417 | | |
| 2418 | | |
| 2419 | | static void to9_update_cart_bank(running_machine &machine) |
| 2308 | void thomson_state::to9_update_cart_bank() |
| 2420 | 2309 | { |
| 2421 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 2310 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 2422 | 2311 | int bank = 0; |
| 2423 | | int slot = ( mc6846_get_output_port(machine.device("mc6846")) >> 4 ) & 3; /* bits 4-5: ROM bank */ |
| 2312 | int slot = ( mc6846_get_output_port(m_mc6846) >> 4 ) & 3; /* bits 4-5: ROM bank */ |
| 2424 | 2313 | |
| 2425 | 2314 | switch ( slot ) |
| 2426 | 2315 | { |
| 2427 | 2316 | case 0: |
| 2428 | 2317 | /* BASIC (64 KB) */ |
| 2429 | | bank = 4 + to9_soft_bank; |
| 2430 | | if ( bank != old_cart_bank ) |
| 2431 | | { |
| 2432 | | if ( old_cart_bank < 4) |
| 2433 | | { |
| 2318 | bank = 4 + m_to9_soft_bank; |
| 2319 | if ( bank != m_old_cart_bank ) |
| 2320 | { |
| 2321 | if ( m_old_cart_bank < 4) |
| 2322 | { |
| 2434 | 2323 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 2435 | | } |
| 2436 | | LOG_BANK(( "to9_update_cart_bank: CART is BASIC bank %i\n", to9_soft_bank )); |
| 2324 | } |
| 2325 | LOG_BANK(( "to9_update_cart_bank: CART is BASIC bank %i\n", m_to9_soft_bank )); |
| 2437 | 2326 | } |
| 2438 | 2327 | break; |
| 2439 | 2328 | case 1: |
| 2440 | 2329 | /* software 1 (32 KB) */ |
| 2441 | | bank = 8 + (to9_soft_bank & 1); |
| 2442 | | if ( bank != old_cart_bank ) |
| 2443 | | { |
| 2444 | | if ( old_cart_bank < 4) |
| 2445 | | { |
| 2330 | bank = 8 + (m_to9_soft_bank & 1); |
| 2331 | if ( bank != m_old_cart_bank ) |
| 2332 | { |
| 2333 | if ( m_old_cart_bank < 4) |
| 2334 | { |
| 2446 | 2335 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 2447 | | } |
| 2448 | | LOG_BANK(( "to9_update_cart_bank: CART is software 1 bank %i\n", to9_soft_bank )); |
| 2336 | } |
| 2337 | LOG_BANK(( "to9_update_cart_bank: CART is software 1 bank %i\n", m_to9_soft_bank )); |
| 2449 | 2338 | } |
| 2450 | 2339 | break; |
| 2451 | 2340 | case 2: |
| 2452 | 2341 | /* software 2 (32 KB) */ |
| 2453 | | bank = 10 + (to9_soft_bank & 1); |
| 2454 | | if ( bank != old_cart_bank ) |
| 2455 | | { |
| 2456 | | if ( old_cart_bank < 4) |
| 2457 | | { |
| 2342 | bank = 10 + (m_to9_soft_bank & 1); |
| 2343 | if ( bank != m_old_cart_bank ) |
| 2344 | { |
| 2345 | if ( m_old_cart_bank < 4) |
| 2346 | { |
| 2458 | 2347 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 2459 | | } |
| 2460 | | LOG_BANK(( "to9_update_cart_bank: CART is software 2 bank %i\n", to9_soft_bank )); |
| 2348 | } |
| 2349 | LOG_BANK(( "to9_update_cart_bank: CART is software 2 bank %i\n", m_to9_soft_bank )); |
| 2461 | 2350 | } |
| 2462 | 2351 | break; |
| 2463 | 2352 | case 3: |
| 2464 | 2353 | /* external cartridge */ |
| 2465 | | if ( thom_cart_nb_banks ) |
| 2354 | if ( m_thom_cart_nb_banks ) |
| 2466 | 2355 | { |
| 2467 | | bank = thom_cart_bank % thom_cart_nb_banks; |
| 2468 | | if ( bank != old_cart_bank ) |
| 2469 | | { |
| 2470 | | if ( old_cart_bank < 0 || old_cart_bank > 3 ) |
| 2471 | | { |
| 2356 | bank = m_thom_cart_bank % m_thom_cart_nb_banks; |
| 2357 | if ( bank != m_old_cart_bank ) |
| 2358 | { |
| 2359 | if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 ) |
| 2360 | { |
| 2472 | 2361 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 2473 | | space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to9_cartridge_w) ); |
| 2474 | | space.install_legacy_read_handler( 0x0000, 0x0003, FUNC(to9_cartridge_r) ); |
| 2362 | space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to9_cartridge_w),this) ); |
| 2363 | space.install_read_handler( 0x0000, 0x0003, read8_delegate(FUNC(thomson_state::to9_cartridge_r),this) ); |
| 2475 | 2364 | } |
| 2476 | | LOG_BANK(( "to9_update_cart_bank: CART is cartridge bank %i\n", thom_cart_bank )); |
| 2365 | LOG_BANK(( "to9_update_cart_bank: CART is cartridge bank %i\n", m_thom_cart_bank )); |
| 2477 | 2366 | } |
| 2478 | | } else |
| 2479 | | if ( old_cart_bank != 0 ) |
| 2480 | | { |
| 2367 | } |
| 2368 | else |
| 2369 | { |
| 2370 | if ( m_old_cart_bank != 0 ) |
| 2371 | { |
| 2481 | 2372 | space.nop_read( 0x0000, 0x3fff); |
| 2482 | 2373 | LOG_BANK(( "to9_update_cart_bank: CART is unmapped\n")); |
| 2483 | 2374 | } |
| 2375 | } |
| 2484 | 2376 | break; |
| 2485 | 2377 | } |
| 2486 | | if ( bank != old_cart_bank ) |
| 2487 | | { |
| 2488 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( bank ); |
| 2489 | | old_cart_bank = bank; |
| 2378 | if ( bank != m_old_cart_bank ) |
| 2379 | { |
| 2380 | membank( THOM_CART_BANK )->set_entry( bank ); |
| 2381 | m_old_cart_bank = bank; |
| 2490 | 2382 | } |
| 2491 | 2383 | } |
| 2492 | 2384 | |
| 2493 | 2385 | |
| 2494 | 2386 | |
| 2495 | | static void to9_update_cart_bank_postload(running_machine *machine) |
| 2387 | void thomson_state::to9_update_cart_bank_postload() |
| 2496 | 2388 | { |
| 2497 | | to9_update_cart_bank(*machine); |
| 2389 | to9_update_cart_bank(); |
| 2498 | 2390 | } |
| 2499 | 2391 | |
| 2500 | 2392 | |
| 2501 | 2393 | |
| 2502 | 2394 | /* write signal to 0000-1fff generates a bank switch */ |
| 2503 | | WRITE8_HANDLER ( to9_cartridge_w ) |
| 2395 | WRITE8_MEMBER( thomson_state::to9_cartridge_w ) |
| 2504 | 2396 | { |
| 2505 | | int slot = ( mc6846_get_output_port(space.machine().device("mc6846")) >> 4 ) & 3; /* bits 4-5: ROM bank */ |
| 2397 | int slot = ( mc6846_get_output_port(m_mc6846) >> 4 ) & 3; /* bits 4-5: ROM bank */ |
| 2506 | 2398 | |
| 2507 | 2399 | if ( offset >= 0x2000 ) |
| 2508 | 2400 | return; |
| 2509 | 2401 | |
| 2510 | 2402 | if ( slot == 3 ) |
| 2511 | | thom_cart_bank = offset & 3; |
| 2403 | m_thom_cart_bank = offset & 3; |
| 2512 | 2404 | else |
| 2513 | | to9_soft_bank = offset & 3; |
| 2514 | | to9_update_cart_bank(space.machine()); |
| 2405 | m_to9_soft_bank = offset & 3; |
| 2406 | to9_update_cart_bank(); |
| 2515 | 2407 | } |
| 2516 | 2408 | |
| 2517 | 2409 | |
| 2518 | 2410 | |
| 2519 | 2411 | /* read signal to 0000-0003 generates a bank switch */ |
| 2520 | | READ8_HANDLER ( to9_cartridge_r ) |
| 2412 | READ8_MEMBER( thomson_state::to9_cartridge_r ) |
| 2521 | 2413 | { |
| 2522 | | UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000; |
| 2523 | | UINT8 data = pos[offset + (thom_cart_bank % thom_cart_nb_banks) * 0x4000]; |
| 2414 | UINT8* pos = memregion( "maincpu" )->base() + 0x10000; |
| 2415 | UINT8 data = pos[offset + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000]; |
| 2524 | 2416 | if ( !space.debugger_access() ) |
| 2525 | | { |
| 2526 | | thom_cart_bank = offset & 3; |
| 2527 | | to9_update_cart_bank(space.machine()); |
| 2417 | { |
| 2418 | m_thom_cart_bank = offset & 3; |
| 2419 | to9_update_cart_bank(); |
| 2528 | 2420 | } |
| 2529 | 2421 | return data; |
| 2530 | 2422 | } |
| 2531 | 2423 | |
| 2532 | 2424 | |
| 2533 | 2425 | |
| 2534 | | static void to9_update_ram_bank (running_machine &machine) |
| 2426 | void thomson_state::to9_update_ram_bank() |
| 2535 | 2427 | { |
| 2536 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 2537 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 2538 | | UINT8 port = mc6846_get_output_port(machine.device("mc6846")); |
| 2539 | | UINT8 portb = sys_pia->port_b_z_mask(); |
| 2428 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 2429 | UINT8 port = mc6846_get_output_port(m_mc6846); |
| 2430 | UINT8 portb = m_pia_sys->port_b_z_mask(); |
| 2540 | 2431 | UINT8 disk = ((port >> 2) & 1) | ((port >> 5) & 2); /* bits 6,2: RAM bank */ |
| 2541 | 2432 | int bank; |
| 2542 | 2433 | |
| r21425 | r21426 | |
| 2561 | 2452 | return; |
| 2562 | 2453 | } |
| 2563 | 2454 | |
| 2564 | | if ( old_ram_bank != bank ) |
| 2455 | if ( m_old_ram_bank != bank ) |
| 2456 | { |
| 2457 | if ( m_ram->size() == 192*1024 || bank < 6 ) |
| 2565 | 2458 | { |
| 2566 | | if ( machine.device<ram_device>(RAM_TAG)->size() == 192*1024 || bank < 6 ) |
| 2567 | | { |
| 2568 | | machine.root_device().membank( THOM_RAM_BANK )->set_entry( bank ); |
| 2569 | | } |
| 2459 | membank( THOM_RAM_BANK )->set_entry( bank ); |
| 2460 | } |
| 2570 | 2461 | else |
| 2571 | | { |
| 2462 | { |
| 2572 | 2463 | space.nop_readwrite( 0xa000, 0xdfff); |
| 2573 | | } |
| 2574 | | old_ram_bank = bank; |
| 2464 | } |
| 2465 | m_old_ram_bank = bank; |
| 2575 | 2466 | LOG_BANK(( "to9_update_ram_bank: bank %i selected (pia=$%02X disk=%i)\n", bank, portb & 0xf8, disk )); |
| 2576 | 2467 | } |
| 2577 | 2468 | } |
| 2578 | 2469 | |
| 2579 | 2470 | |
| 2580 | 2471 | |
| 2581 | | static void to9_update_ram_bank_postload(running_machine *machine) |
| 2472 | void thomson_state::to9_update_ram_bank_postload() |
| 2582 | 2473 | { |
| 2583 | | to9_update_ram_bank(*machine); |
| 2474 | to9_update_ram_bank(); |
| 2584 | 2475 | } |
| 2585 | 2476 | |
| 2586 | 2477 | |
| r21425 | r21426 | |
| 2610 | 2501 | |
| 2611 | 2502 | |
| 2612 | 2503 | |
| 2613 | | static UINT8 to9_kbd_parity; /* 0=even, 1=odd, 2=no parity */ |
| 2614 | | static UINT8 to9_kbd_intr; /* interrupt mode */ |
| 2615 | | static UINT8 to9_kbd_in; /* data from keyboard */ |
| 2616 | | static UINT8 to9_kbd_status; /* status */ |
| 2617 | | static UINT8 to9_kbd_overrun; /* character lost */ |
| 2618 | | |
| 2619 | | static UINT8 to9_kbd_periph; /* peripherial mode */ |
| 2620 | | static UINT8 to9_kbd_byte_count; /* byte-count in peripherial mode */ |
| 2621 | | static UINT16 to9_mouse_x, to9_mouse_y; |
| 2622 | | |
| 2623 | | static UINT8 to9_kbd_last_key; /* for key repetition */ |
| 2624 | | static UINT16 to9_kbd_key_count; |
| 2625 | | |
| 2626 | | static UINT8 to9_kbd_caps; /* caps-lock */ |
| 2627 | | static UINT8 to9_kbd_pad; /* keypad outputs special codes */ |
| 2628 | | |
| 2629 | | static emu_timer* to9_kbd_timer; |
| 2630 | | |
| 2631 | | |
| 2632 | | |
| 2633 | 2504 | /* quick keyboard scan */ |
| 2634 | | static int to9_kbd_ktest ( running_machine &machine ) |
| 2505 | int thomson_state::to9_kbd_ktest() |
| 2635 | 2506 | { |
| 2636 | 2507 | int line, bit; |
| 2637 | 2508 | UINT8 port; |
| r21425 | r21426 | |
| 2642 | 2513 | |
| 2643 | 2514 | for ( line = 0; line < 10; line++ ) |
| 2644 | 2515 | { |
| 2645 | | port = machine.root_device().ioport(keynames[line])->read(); |
| 2516 | port = ioport(keynames[line])->read(); |
| 2646 | 2517 | |
| 2647 | 2518 | if ( line == 7 || line == 9 ) |
| 2648 | 2519 | port |= 1; /* shift & control */ |
| r21425 | r21426 | |
| 2658 | 2529 | |
| 2659 | 2530 | |
| 2660 | 2531 | |
| 2661 | | static void to9_kbd_update_irq ( running_machine &machine ) |
| 2532 | void thomson_state::to9_kbd_update_irq() |
| 2662 | 2533 | { |
| 2663 | | if ( (to9_kbd_intr & 4) && (to9_kbd_status & ACIA_6850_RDRF) ) |
| 2664 | | to9_kbd_status |= ACIA_6850_irq; /* byte received interrupt */ |
| 2534 | if ( (m_to9_kbd_intr & 4) && (m_to9_kbd_status & ACIA_6850_RDRF) ) |
| 2535 | m_to9_kbd_status |= ACIA_6850_irq; /* byte received interrupt */ |
| 2665 | 2536 | |
| 2666 | | if ( (to9_kbd_intr & 4) && (to9_kbd_status & ACIA_6850_OVRN) ) |
| 2667 | | to9_kbd_status |= ACIA_6850_irq; /* overrun interrupt */ |
| 2537 | if ( (m_to9_kbd_intr & 4) && (m_to9_kbd_status & ACIA_6850_OVRN) ) |
| 2538 | m_to9_kbd_status |= ACIA_6850_irq; /* overrun interrupt */ |
| 2668 | 2539 | |
| 2669 | | if ( (to9_kbd_intr & 3) == 1 && (to9_kbd_status & ACIA_6850_TDRE) ) |
| 2670 | | to9_kbd_status |= ACIA_6850_irq; /* ready to transmit interrupt */ |
| 2540 | if ( (m_to9_kbd_intr & 3) == 1 && (m_to9_kbd_status & ACIA_6850_TDRE) ) |
| 2541 | m_to9_kbd_status |= ACIA_6850_irq; /* ready to transmit interrupt */ |
| 2671 | 2542 | |
| 2672 | | thom_irq_3( machine, to9_kbd_status & ACIA_6850_irq ); |
| 2543 | thom_irq_3( m_to9_kbd_status & ACIA_6850_irq ); |
| 2673 | 2544 | } |
| 2674 | 2545 | |
| 2675 | 2546 | |
| 2676 | 2547 | |
| 2677 | | READ8_HANDLER ( to9_kbd_r ) |
| 2548 | READ8_MEMBER( thomson_state::to9_kbd_r ) |
| 2678 | 2549 | { |
| 2679 | 2550 | /* ACIA 6850 registers */ |
| 2680 | 2551 | |
| r21425 | r21426 | |
| 2691 | 2562 | /* bit 7: interrupt */ |
| 2692 | 2563 | |
| 2693 | 2564 | LOG_KBD(( "$%04x %f to9_kbd_r: status $%02X (rdrf=%i, tdre=%i, ovrn=%i, pe=%i, irq=%i)\n", |
| 2694 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), to9_kbd_status, |
| 2695 | | (to9_kbd_status & ACIA_6850_RDRF) ? 1 : 0, |
| 2696 | | (to9_kbd_status & ACIA_6850_TDRE) ? 1 : 0, |
| 2697 | | (to9_kbd_status & ACIA_6850_OVRN) ? 1 : 0, |
| 2698 | | (to9_kbd_status & ACIA_6850_PE) ? 1 : 0, |
| 2699 | | (to9_kbd_status & ACIA_6850_irq) ? 1 : 0 )); |
| 2700 | | return to9_kbd_status; |
| 2565 | m_maincpu->pc(), machine().time().as_double(), m_to9_kbd_status, |
| 2566 | (m_to9_kbd_status & ACIA_6850_RDRF) ? 1 : 0, |
| 2567 | (m_to9_kbd_status & ACIA_6850_TDRE) ? 1 : 0, |
| 2568 | (m_to9_kbd_status & ACIA_6850_OVRN) ? 1 : 0, |
| 2569 | (m_to9_kbd_status & ACIA_6850_PE) ? 1 : 0, |
| 2570 | (m_to9_kbd_status & ACIA_6850_irq) ? 1 : 0 )); |
| 2571 | return m_to9_kbd_status; |
| 2701 | 2572 | |
| 2702 | 2573 | case 1: /* get input data */ |
| 2703 | 2574 | if ( !space.debugger_access() ) |
| 2704 | 2575 | { |
| 2705 | | to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_PE); |
| 2706 | | if ( to9_kbd_overrun ) |
| 2707 | | to9_kbd_status |= ACIA_6850_OVRN; |
| 2576 | m_to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_PE); |
| 2577 | if ( m_to9_kbd_overrun ) |
| 2578 | m_to9_kbd_status |= ACIA_6850_OVRN; |
| 2708 | 2579 | else |
| 2709 | | to9_kbd_status &= ~(ACIA_6850_OVRN | ACIA_6850_RDRF); |
| 2710 | | to9_kbd_overrun = 0; |
| 2711 | | LOG_KBD(( "$%04x %f to9_kbd_r: read data $%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), to9_kbd_in )); |
| 2712 | | to9_kbd_update_irq(space.machine()); |
| 2580 | m_to9_kbd_status &= ~(ACIA_6850_OVRN | ACIA_6850_RDRF); |
| 2581 | m_to9_kbd_overrun = 0; |
| 2582 | LOG_KBD(( "$%04x %f to9_kbd_r: read data $%02X\n", m_maincpu->pc(), machine().time().as_double(), m_to9_kbd_in )); |
| 2583 | to9_kbd_update_irq(); |
| 2713 | 2584 | } |
| 2714 | | return to9_kbd_in; |
| 2585 | return m_to9_kbd_in; |
| 2715 | 2586 | |
| 2716 | 2587 | default: |
| 2717 | | logerror( "$%04x to9_kbd_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 2588 | logerror( "$%04x to9_kbd_r: invalid offset %i\n", m_maincpu->pc(), offset ); |
| 2718 | 2589 | return 0; |
| 2719 | 2590 | } |
| 2720 | 2591 | } |
| 2721 | 2592 | |
| 2722 | 2593 | |
| 2723 | 2594 | |
| 2724 | | WRITE8_HANDLER ( to9_kbd_w ) |
| 2595 | WRITE8_MEMBER( thomson_state::to9_kbd_w ) |
| 2725 | 2596 | { |
| 2726 | 2597 | /* ACIA 6850 registers */ |
| 2727 | 2598 | |
| r21425 | r21426 | |
| 2732 | 2603 | if ( (data & 3) == 3 ) |
| 2733 | 2604 | { |
| 2734 | 2605 | /* reset */ |
| 2735 | | to9_kbd_overrun = 0; |
| 2736 | | to9_kbd_status = ACIA_6850_TDRE; |
| 2737 | | to9_kbd_intr = 0; |
| 2738 | | LOG_KBD(( "$%04x %f to9_kbd_w: reset (data=$%02X)\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data )); |
| 2606 | m_to9_kbd_overrun = 0; |
| 2607 | m_to9_kbd_status = ACIA_6850_TDRE; |
| 2608 | m_to9_kbd_intr = 0; |
| 2609 | LOG_KBD(( "$%04x %f to9_kbd_w: reset (data=$%02X)\n", m_maincpu->pc(), machine().time().as_double(), data )); |
| 2739 | 2610 | } |
| 2740 | 2611 | else |
| 2741 | 2612 | { |
| 2742 | 2613 | /* bits 2-4: parity */ |
| 2743 | 2614 | if ( (data & 0x18) == 0x10 ) |
| 2744 | | to9_kbd_parity = 2; |
| 2615 | m_to9_kbd_parity = 2; |
| 2745 | 2616 | else |
| 2746 | | to9_kbd_parity = (data >> 2) & 1; |
| 2617 | m_to9_kbd_parity = (data >> 2) & 1; |
| 2747 | 2618 | /* bits 5-6: interrupt on transmit */ |
| 2748 | 2619 | /* bit 7: interrupt on receive */ |
| 2749 | | to9_kbd_intr = data >> 5; |
| 2620 | m_to9_kbd_intr = data >> 5; |
| 2750 | 2621 | |
| 2751 | 2622 | LOG_KBD(( "$%04x %f to9_kbd_w: set control to $%02X (parity=%i, intr in=%i out=%i)\n", |
| 2752 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 2753 | | data, to9_kbd_parity, to9_kbd_intr >> 2, |
| 2754 | | (to9_kbd_intr & 3) ? 1 : 0 )); |
| 2623 | m_maincpu->pc(), machine().time().as_double(), |
| 2624 | data, m_to9_kbd_parity, m_to9_kbd_intr >> 2, |
| 2625 | (m_to9_kbd_intr & 3) ? 1 : 0 )); |
| 2755 | 2626 | } |
| 2756 | | to9_kbd_update_irq(space.machine()); |
| 2627 | to9_kbd_update_irq(); |
| 2757 | 2628 | break; |
| 2758 | 2629 | |
| 2759 | 2630 | case 1: /* output data */ |
| 2760 | | to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_TDRE); |
| 2761 | | to9_kbd_update_irq(space.machine()); |
| 2631 | m_to9_kbd_status &= ~(ACIA_6850_irq | ACIA_6850_TDRE); |
| 2632 | to9_kbd_update_irq(); |
| 2762 | 2633 | /* TODO: 1 ms delay here ? */ |
| 2763 | | to9_kbd_status |= ACIA_6850_TDRE; /* data transmit ready again */ |
| 2764 | | to9_kbd_update_irq(space.machine()); |
| 2634 | m_to9_kbd_status |= ACIA_6850_TDRE; /* data transmit ready again */ |
| 2635 | to9_kbd_update_irq(); |
| 2765 | 2636 | |
| 2766 | 2637 | switch ( data ) |
| 2767 | 2638 | { |
| 2768 | 2639 | case 0xF8: |
| 2769 | 2640 | /* reset */ |
| 2770 | | to9_kbd_caps = 1; |
| 2771 | | to9_kbd_periph = 0; |
| 2772 | | to9_kbd_pad = 0; |
| 2641 | m_to9_kbd_caps = 1; |
| 2642 | m_to9_kbd_periph = 0; |
| 2643 | m_to9_kbd_pad = 0; |
| 2773 | 2644 | break; |
| 2774 | 2645 | |
| 2775 | | case 0xF9: to9_kbd_caps = 1; break; |
| 2776 | | case 0xFA: to9_kbd_caps = 0; break; |
| 2777 | | case 0xFB: to9_kbd_pad = 1; break; |
| 2778 | | case 0xFC: to9_kbd_pad = 0; break; |
| 2779 | | case 0xFD: to9_kbd_periph = 1; break; |
| 2780 | | case 0xFE: to9_kbd_periph = 0; break; |
| 2646 | case 0xF9: m_to9_kbd_caps = 1; break; |
| 2647 | case 0xFA: m_to9_kbd_caps = 0; break; |
| 2648 | case 0xFB: m_to9_kbd_pad = 1; break; |
| 2649 | case 0xFC: m_to9_kbd_pad = 0; break; |
| 2650 | case 0xFD: m_to9_kbd_periph = 1; break; |
| 2651 | case 0xFE: m_to9_kbd_periph = 0; break; |
| 2781 | 2652 | |
| 2782 | 2653 | default: |
| 2783 | | logerror( "$%04x %f to9_kbd_w: unknown kbd command %02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data ); |
| 2654 | logerror( "$%04x %f to9_kbd_w: unknown kbd command %02X\n", m_maincpu->pc(), machine().time().as_double(), data ); |
| 2784 | 2655 | } |
| 2785 | 2656 | |
| 2786 | | thom_set_caps_led( space.machine(), !to9_kbd_caps ); |
| 2657 | thom_set_caps_led( !m_to9_kbd_caps ); |
| 2787 | 2658 | |
| 2788 | 2659 | LOG(( "$%04x %f to9_kbd_w: kbd command %02X (caps=%i, pad=%i, periph=%i)\n", |
| 2789 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data, |
| 2790 | | to9_kbd_caps, to9_kbd_pad, to9_kbd_periph )); |
| 2660 | m_maincpu->pc(), machine().time().as_double(), data, |
| 2661 | m_to9_kbd_caps, m_to9_kbd_pad, m_to9_kbd_periph )); |
| 2791 | 2662 | |
| 2792 | 2663 | break; |
| 2793 | 2664 | |
| 2794 | 2665 | default: |
| 2795 | | logerror( "$%04x to9_kbd_w: invalid offset %i (data=$%02X) \n", space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 2666 | logerror( "$%04x to9_kbd_w: invalid offset %i (data=$%02X) \n", m_maincpu->pc(), offset, data ); |
| 2796 | 2667 | } |
| 2797 | 2668 | } |
| 2798 | 2669 | |
| r21425 | r21426 | |
| 2802 | 2673 | note: parity is not used as a checksum but to actually transmit a 9-th bit |
| 2803 | 2674 | of information! |
| 2804 | 2675 | */ |
| 2805 | | static void to9_kbd_send ( running_machine &machine, UINT8 data, int parity ) |
| 2676 | void thomson_state::to9_kbd_send( UINT8 data, int parity ) |
| 2806 | 2677 | { |
| 2807 | | if ( to9_kbd_status & ACIA_6850_RDRF ) |
| 2678 | if ( m_to9_kbd_status & ACIA_6850_RDRF ) |
| 2808 | 2679 | { |
| 2809 | 2680 | /* overrun will be set when the current valid byte is read */ |
| 2810 | | to9_kbd_overrun = 1; |
| 2811 | | LOG_KBD(( "%f to9_kbd_send: overrun => drop data=$%02X, parity=%i\n", machine.time().as_double(), data, parity )); |
| 2681 | m_to9_kbd_overrun = 1; |
| 2682 | LOG_KBD(( "%f to9_kbd_send: overrun => drop data=$%02X, parity=%i\n", machine().time().as_double(), data, parity )); |
| 2812 | 2683 | } |
| 2813 | 2684 | else |
| 2814 | 2685 | { |
| 2815 | 2686 | /* valid byte */ |
| 2816 | | to9_kbd_in = data; |
| 2817 | | to9_kbd_status |= ACIA_6850_RDRF; /* raise data received flag */ |
| 2818 | | if ( to9_kbd_parity == 2 || to9_kbd_parity == parity ) |
| 2819 | | to9_kbd_status &= ~ACIA_6850_PE; /* parity OK */ |
| 2687 | m_to9_kbd_in = data; |
| 2688 | m_to9_kbd_status |= ACIA_6850_RDRF; /* raise data received flag */ |
| 2689 | if ( m_to9_kbd_parity == 2 || m_to9_kbd_parity == parity ) |
| 2690 | m_to9_kbd_status &= ~ACIA_6850_PE; /* parity OK */ |
| 2820 | 2691 | else |
| 2821 | | to9_kbd_status |= ACIA_6850_PE; /* parity error */ |
| 2822 | | LOG_KBD(( "%f to9_kbd_send: data=$%02X, parity=%i, status=$%02X\n", machine.time().as_double(), data, parity, to9_kbd_status )); |
| 2692 | m_to9_kbd_status |= ACIA_6850_PE; /* parity error */ |
| 2693 | LOG_KBD(( "%f to9_kbd_send: data=$%02X, parity=%i, status=$%02X\n", machine().time().as_double(), data, parity, m_to9_kbd_status )); |
| 2823 | 2694 | } |
| 2824 | | to9_kbd_update_irq(machine); |
| 2695 | to9_kbd_update_irq(); |
| 2825 | 2696 | } |
| 2826 | 2697 | |
| 2827 | 2698 | |
| r21425 | r21426 | |
| 2866 | 2737 | |
| 2867 | 2738 | |
| 2868 | 2739 | /* returns the ASCII code for the key, or 0 for no key */ |
| 2869 | | static int to9_kbd_get_key( running_machine &machine ) |
| 2740 | int thomson_state::to9_kbd_get_key() |
| 2870 | 2741 | { |
| 2871 | | int control = ! (machine.root_device().ioport("keyboard_7")->read() & 1); |
| 2872 | | int shift = ! (machine.root_device().ioport("keyboard_9")->read() & 1); |
| 2742 | int control = ! (ioport("keyboard_7")->read() & 1); |
| 2743 | int shift = ! (ioport("keyboard_9")->read() & 1); |
| 2873 | 2744 | int key = -1, line, bit; |
| 2874 | 2745 | UINT8 port; |
| 2875 | 2746 | static const char *const keynames[] = { |
| r21425 | r21426 | |
| 2879 | 2750 | |
| 2880 | 2751 | for ( line = 0; line < 10; line++ ) |
| 2881 | 2752 | { |
| 2882 | | port = machine.root_device().ioport(keynames[line])->read(); |
| 2753 | port = ioport(keynames[line])->read(); |
| 2883 | 2754 | |
| 2884 | 2755 | if ( line == 7 || line == 9 ) |
| 2885 | 2756 | port |= 1; /* shift & control */ |
| r21425 | r21426 | |
| 2896 | 2767 | |
| 2897 | 2768 | if ( key == -1 ) |
| 2898 | 2769 | { |
| 2899 | | to9_kbd_last_key = 0xff; |
| 2900 | | to9_kbd_key_count = 0; |
| 2770 | m_to9_kbd_last_key = 0xff; |
| 2771 | m_to9_kbd_key_count = 0; |
| 2901 | 2772 | return 0; |
| 2902 | 2773 | } |
| 2903 | 2774 | else if ( key == 64 ) |
| 2904 | 2775 | { |
| 2905 | 2776 | /* caps lock */ |
| 2906 | | if ( to9_kbd_last_key == key ) |
| 2777 | if ( m_to9_kbd_last_key == key ) |
| 2907 | 2778 | return 0; /* no repeat */ |
| 2908 | 2779 | |
| 2909 | | to9_kbd_last_key = key; |
| 2910 | | to9_kbd_caps = !to9_kbd_caps; |
| 2911 | | thom_set_caps_led( machine, !to9_kbd_caps ); |
| 2780 | m_to9_kbd_last_key = key; |
| 2781 | m_to9_kbd_caps = !m_to9_kbd_caps; |
| 2782 | thom_set_caps_led( !m_to9_kbd_caps ); |
| 2912 | 2783 | return 0; |
| 2913 | 2784 | } |
| 2914 | 2785 | else |
| r21425 | r21426 | |
| 2918 | 2789 | if ( ! asc ) return 0; |
| 2919 | 2790 | |
| 2920 | 2791 | /* keypad */ |
| 2921 | | if ( ! to9_kbd_pad ) { |
| 2792 | if ( ! m_to9_kbd_pad ) { |
| 2922 | 2793 | if ( asc >= 154 && asc <= 163 ) |
| 2923 | 2794 | asc += '0' - 154; |
| 2924 | 2795 | else if ( asc == 164 ) |
| r21425 | r21426 | |
| 2928 | 2799 | } |
| 2929 | 2800 | |
| 2930 | 2801 | /* shifted letter */ |
| 2931 | | if ( asc >= 'A' && asc <= 'Z' && ( ! to9_kbd_caps ) && ( ! shift ) ) |
| 2802 | if ( asc >= 'A' && asc <= 'Z' && ( ! m_to9_kbd_caps ) && ( ! shift ) ) |
| 2932 | 2803 | asc += 'a' - 'A'; |
| 2933 | 2804 | |
| 2934 | 2805 | /* control */ |
| 2935 | 2806 | if ( control ) |
| 2936 | 2807 | asc &= ~0x40; |
| 2937 | 2808 | |
| 2938 | | if ( key == to9_kbd_last_key ) |
| 2809 | if ( key == m_to9_kbd_last_key ) |
| 2939 | 2810 | { |
| 2940 | 2811 | /* repeat */ |
| 2941 | | to9_kbd_key_count++; |
| 2942 | | if ( to9_kbd_key_count < TO9_KBD_REPEAT_DELAY || (to9_kbd_key_count - TO9_KBD_REPEAT_DELAY) % TO9_KBD_REPEAT_PERIOD ) |
| 2812 | m_to9_kbd_key_count++; |
| 2813 | if ( m_to9_kbd_key_count < TO9_KBD_REPEAT_DELAY || (m_to9_kbd_key_count - TO9_KBD_REPEAT_DELAY) % TO9_KBD_REPEAT_PERIOD ) |
| 2943 | 2814 | return 0; |
| 2944 | 2815 | LOG_KBD(( "to9_kbd_get_key: repeat key $%02X '%c'\n", asc, asc )); |
| 2945 | 2816 | return asc; |
| 2946 | 2817 | } |
| 2947 | | else { |
| 2948 | | to9_kbd_last_key = key; |
| 2949 | | to9_kbd_key_count = 0; |
| 2818 | else |
| 2819 | { |
| 2820 | m_to9_kbd_last_key = key; |
| 2821 | m_to9_kbd_key_count = 0; |
| 2950 | 2822 | LOG_KBD(( "to9_kbd_get_key: key down $%02X '%c'\n", asc, asc )); |
| 2951 | 2823 | return asc; |
| 2952 | 2824 | } |
| r21425 | r21426 | |
| 2955 | 2827 | |
| 2956 | 2828 | |
| 2957 | 2829 | |
| 2958 | | static TIMER_CALLBACK(to9_kbd_timer_cb) |
| 2830 | TIMER_CALLBACK_MEMBER(thomson_state::to9_kbd_timer_cb) |
| 2959 | 2831 | { |
| 2960 | | if ( to9_kbd_periph ) |
| 2832 | if ( m_to9_kbd_periph ) |
| 2961 | 2833 | { |
| 2962 | 2834 | /* peripherial mode: every 10 ms we send 4 bytes */ |
| 2963 | 2835 | |
| 2964 | | switch ( to9_kbd_byte_count ) |
| 2836 | switch ( m_to9_kbd_byte_count ) |
| 2965 | 2837 | { |
| 2966 | 2838 | case 0: /* key */ |
| 2967 | | to9_kbd_send( machine, to9_kbd_get_key(machine), 0 ); |
| 2839 | to9_kbd_send( to9_kbd_get_key(), 0 ); |
| 2968 | 2840 | break; |
| 2969 | 2841 | |
| 2970 | 2842 | case 1: /* x axis */ |
| 2971 | 2843 | { |
| 2972 | | int newx = machine.root_device().ioport("mouse_x")->read(); |
| 2973 | | UINT8 data = ( (newx - to9_mouse_x) & 0xf ) - 8; |
| 2974 | | to9_kbd_send( machine, data, 1 ); |
| 2975 | | to9_mouse_x = newx; |
| 2844 | int newx = ioport("mouse_x")->read(); |
| 2845 | UINT8 data = ( (newx - m_to9_mouse_x) & 0xf ) - 8; |
| 2846 | to9_kbd_send( data, 1 ); |
| 2847 | m_to9_mouse_x = newx; |
| 2976 | 2848 | break; |
| 2977 | 2849 | } |
| 2978 | 2850 | |
| 2979 | 2851 | case 2: /* y axis */ |
| 2980 | 2852 | { |
| 2981 | | int newy = machine.root_device().ioport("mouse_y")->read(); |
| 2982 | | UINT8 data = ( (newy - to9_mouse_y) & 0xf ) - 8; |
| 2983 | | to9_kbd_send( machine, data, 1 ); |
| 2984 | | to9_mouse_y = newy; |
| 2853 | int newy = ioport("mouse_y")->read(); |
| 2854 | UINT8 data = ( (newy - m_to9_mouse_y) & 0xf ) - 8; |
| 2855 | to9_kbd_send( data, 1 ); |
| 2856 | m_to9_mouse_y = newy; |
| 2985 | 2857 | break; |
| 2986 | 2858 | } |
| 2987 | 2859 | |
| 2988 | 2860 | case 3: /* axis overflow & buttons */ |
| 2989 | 2861 | { |
| 2990 | | int b = machine.root_device().ioport("mouse_button")->read(); |
| 2862 | int b = ioport("mouse_button")->read(); |
| 2991 | 2863 | UINT8 data = 0; |
| 2992 | 2864 | if ( b & 1 ) data |= 1; |
| 2993 | 2865 | if ( b & 2 ) data |= 4; |
| 2994 | | to9_kbd_send( machine, data, 1 ); |
| 2866 | to9_kbd_send( data, 1 ); |
| 2995 | 2867 | break; |
| 2996 | 2868 | } |
| 2997 | 2869 | |
| 2998 | 2870 | } |
| 2999 | 2871 | |
| 3000 | | to9_kbd_byte_count = ( to9_kbd_byte_count + 1 ) & 3; |
| 3001 | | to9_kbd_timer->adjust(to9_kbd_byte_count ? TO9_KBD_BYTE_SPACE : TO9_KBD_END_SPACE); |
| 2872 | m_to9_kbd_byte_count = ( m_to9_kbd_byte_count + 1 ) & 3; |
| 2873 | m_to9_kbd_timer->adjust(m_to9_kbd_byte_count ? TO9_KBD_BYTE_SPACE : TO9_KBD_END_SPACE); |
| 3002 | 2874 | } |
| 3003 | 2875 | else |
| 3004 | 2876 | { |
| 3005 | | int key = to9_kbd_get_key(machine); |
| 2877 | int key = to9_kbd_get_key(); |
| 3006 | 2878 | /* keyboard mode: send a byte only if a key is down */ |
| 3007 | 2879 | if ( key ) |
| 3008 | | to9_kbd_send( machine, key, 0 ); |
| 3009 | | to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD); |
| 2880 | to9_kbd_send( key, 0 ); |
| 2881 | m_to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD); |
| 3010 | 2882 | } |
| 3011 | 2883 | } |
| 3012 | 2884 | |
| 3013 | 2885 | |
| 3014 | 2886 | |
| 3015 | | static void to9_kbd_reset ( running_machine &machine ) |
| 2887 | void thomson_state::to9_kbd_reset() |
| 3016 | 2888 | { |
| 3017 | 2889 | LOG(( "to9_kbd_reset called\n" )); |
| 3018 | | to9_kbd_overrun = 0; /* no byte lost */ |
| 3019 | | to9_kbd_status = ACIA_6850_TDRE; /* clear to transmit */ |
| 3020 | | to9_kbd_intr = 0; /* interrupt disabled */ |
| 3021 | | to9_kbd_caps = 1; |
| 3022 | | to9_kbd_periph = 0; |
| 3023 | | to9_kbd_pad = 0; |
| 3024 | | to9_kbd_byte_count = 0; |
| 3025 | | thom_set_caps_led( machine, !to9_kbd_caps ); |
| 3026 | | to9_kbd_key_count = 0; |
| 3027 | | to9_kbd_last_key = 0xff; |
| 3028 | | to9_kbd_update_irq(machine); |
| 3029 | | to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD); |
| 2890 | m_to9_kbd_overrun = 0; /* no byte lost */ |
| 2891 | m_to9_kbd_status = ACIA_6850_TDRE; /* clear to transmit */ |
| 2892 | m_to9_kbd_intr = 0; /* interrupt disabled */ |
| 2893 | m_to9_kbd_caps = 1; |
| 2894 | m_to9_kbd_periph = 0; |
| 2895 | m_to9_kbd_pad = 0; |
| 2896 | m_to9_kbd_byte_count = 0; |
| 2897 | thom_set_caps_led( !m_to9_kbd_caps ); |
| 2898 | m_to9_kbd_key_count = 0; |
| 2899 | m_to9_kbd_last_key = 0xff; |
| 2900 | to9_kbd_update_irq(); |
| 2901 | m_to9_kbd_timer->adjust(TO9_KBD_POLL_PERIOD); |
| 3030 | 2902 | } |
| 3031 | 2903 | |
| 3032 | 2904 | |
| 3033 | 2905 | |
| 3034 | | static void to9_kbd_init ( running_machine &machine ) |
| 2906 | void thomson_state::to9_kbd_init() |
| 3035 | 2907 | { |
| 3036 | 2908 | LOG(( "to9_kbd_init called\n" )); |
| 3037 | | to9_kbd_timer = machine.scheduler().timer_alloc(FUNC(to9_kbd_timer_cb)); |
| 3038 | | state_save_register_global( machine, to9_kbd_parity ); |
| 3039 | | state_save_register_global( machine, to9_kbd_intr ); |
| 3040 | | state_save_register_global( machine, to9_kbd_in ); |
| 3041 | | state_save_register_global( machine, to9_kbd_status ); |
| 3042 | | state_save_register_global( machine, to9_kbd_overrun ); |
| 3043 | | state_save_register_global( machine, to9_kbd_last_key ); |
| 3044 | | state_save_register_global( machine, to9_kbd_key_count ); |
| 3045 | | state_save_register_global( machine, to9_kbd_caps ); |
| 3046 | | state_save_register_global( machine, to9_kbd_periph ); |
| 3047 | | state_save_register_global( machine, to9_kbd_pad ); |
| 3048 | | state_save_register_global( machine, to9_kbd_byte_count ); |
| 3049 | | state_save_register_global( machine, to9_mouse_x ); |
| 3050 | | state_save_register_global( machine, to9_mouse_y ); |
| 2909 | m_to9_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to9_kbd_timer_cb),this)); |
| 2910 | save_item(NAME(m_to9_kbd_parity)); |
| 2911 | save_item(NAME(m_to9_kbd_intr)); |
| 2912 | save_item(NAME(m_to9_kbd_in)); |
| 2913 | save_item(NAME(m_to9_kbd_status)); |
| 2914 | save_item(NAME(m_to9_kbd_overrun)); |
| 2915 | save_item(NAME(m_to9_kbd_last_key)); |
| 2916 | save_item(NAME(m_to9_kbd_key_count)); |
| 2917 | save_item(NAME(m_to9_kbd_caps)); |
| 2918 | save_item(NAME(m_to9_kbd_periph)); |
| 2919 | save_item(NAME(m_to9_kbd_pad)); |
| 2920 | save_item(NAME(m_to9_kbd_byte_count)); |
| 2921 | save_item(NAME(m_to9_mouse_x)); |
| 2922 | save_item(NAME(m_to9_mouse_y)); |
| 3051 | 2923 | } |
| 3052 | 2924 | |
| 3053 | 2925 | |
| r21425 | r21426 | |
| 3056 | 2928 | /* afaik, P2-P7 are not connected, so, the warning about undefined 0xf0 can be safely ignored */ |
| 3057 | 2929 | |
| 3058 | 2930 | |
| 3059 | | static READ8_DEVICE_HANDLER ( to9_sys_porta_in ) |
| 2931 | READ8_MEMBER( thomson_state::to9_sys_porta_in ) |
| 3060 | 2932 | { |
| 3061 | | UINT8 ktest = to9_kbd_ktest(space.machine()); |
| 2933 | UINT8 ktest = to9_kbd_ktest(); |
| 3062 | 2934 | |
| 3063 | 2935 | LOG_KBD(( "to9_sys_porta_in: ktest=%i\n", ktest )); |
| 3064 | 2936 | |
| r21425 | r21426 | |
| 3067 | 2939 | |
| 3068 | 2940 | |
| 3069 | 2941 | |
| 3070 | | static WRITE8_DEVICE_HANDLER ( to9_sys_porta_out ) |
| 2942 | WRITE8_MEMBER( thomson_state::to9_sys_porta_out ) |
| 3071 | 2943 | { |
| 3072 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 3073 | | printer->write(space.machine().driver_data()->generic_space(), 0, data & 0xfe); |
| 2944 | m_centronics->write(space, 0, data & 0xfe); |
| 3074 | 2945 | } |
| 3075 | 2946 | |
| 3076 | 2947 | |
| 3077 | 2948 | |
| 3078 | | static WRITE8_DEVICE_HANDLER ( to9_sys_portb_out ) |
| 2949 | WRITE8_MEMBER( thomson_state::to9_sys_portb_out ) |
| 3079 | 2950 | { |
| 3080 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 2951 | m_centronics->d0_w(BIT(data, 0)); |
| 2952 | m_centronics->strobe_w(BIT(data, 1)); |
| 3081 | 2953 | |
| 3082 | | printer->d0_w(BIT(data, 0)); |
| 3083 | | printer->strobe_w(BIT(data, 1)); |
| 2954 | to9_update_ram_bank(); |
| 3084 | 2955 | |
| 3085 | | to9_update_ram_bank(space.machine()); |
| 3086 | | |
| 3087 | 2956 | if ( data & 4 ) /* bit 2: video overlay (TODO) */ |
| 3088 | 2957 | LOG(( "to9_sys_portb_out: video overlay not handled\n" )); |
| 3089 | 2958 | } |
| r21425 | r21426 | |
| 3092 | 2961 | |
| 3093 | 2962 | const pia6821_interface to9_pia6821_sys = |
| 3094 | 2963 | { |
| 3095 | | DEVCB_HANDLER(to9_sys_porta_in), |
| 2964 | DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_in), |
| 3096 | 2965 | DEVCB_NULL, |
| 3097 | 2966 | DEVCB_NULL, |
| 3098 | 2967 | DEVCB_NULL, |
| 3099 | 2968 | DEVCB_NULL, |
| 3100 | 2969 | DEVCB_NULL, |
| 3101 | | DEVCB_HANDLER(to9_sys_porta_out), |
| 3102 | | DEVCB_HANDLER(to9_sys_portb_out), |
| 3103 | | DEVCB_HANDLER(to7_set_cassette_motor), |
| 2970 | DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_out), |
| 2971 | DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_portb_out), |
| 2972 | DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor), |
| 3104 | 2973 | DEVCB_NULL, |
| 3105 | 2974 | DEVCB_NULL, |
| 3106 | | DEVCB_LINE(thom_firq_1) |
| 2975 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1) |
| 3107 | 2976 | }; |
| 3108 | 2977 | |
| 3109 | 2978 | |
| r21425 | r21426 | |
| 3114 | 2983 | |
| 3115 | 2984 | |
| 3116 | 2985 | |
| 3117 | | static WRITE8_DEVICE_HANDLER ( to9_timer_port_out ) |
| 2986 | WRITE8_MEMBER( thomson_state::to9_timer_port_out ) |
| 3118 | 2987 | { |
| 3119 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank */ |
| 3120 | | to9_update_ram_bank(space.machine()); |
| 3121 | | to9_update_cart_bank(space.machine()); |
| 2988 | thom_set_mode_point( data & 1 ); /* bit 0: video bank */ |
| 2989 | to9_update_ram_bank(); |
| 2990 | to9_update_cart_bank(); |
| 3122 | 2991 | } |
| 3123 | 2992 | |
| 3124 | 2993 | |
| 3125 | 2994 | |
| 3126 | 2995 | const mc6846_interface to9_timer = |
| 3127 | 2996 | { |
| 3128 | | DEVCB_HANDLER(to9_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to7_timer_cp2_out), |
| 3129 | | DEVCB_HANDLER(to7_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out), |
| 3130 | | DEVCB_LINE(thom_dev_irq_0) |
| 2997 | DEVCB_DRIVER_MEMBER(thomson_state, to9_timer_port_out), |
| 2998 | DEVCB_NULL, |
| 2999 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out), |
| 3000 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in), |
| 3001 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out), |
| 3002 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0) |
| 3131 | 3003 | }; |
| 3132 | 3004 | |
| 3133 | 3005 | |
| r21425 | r21426 | |
| 3136 | 3008 | |
| 3137 | 3009 | |
| 3138 | 3010 | |
| 3139 | | MACHINE_RESET ( to9 ) |
| 3011 | MACHINE_RESET_MEMBER( thomson_state, to9 ) |
| 3140 | 3012 | { |
| 3141 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 3142 | | |
| 3143 | 3013 | LOG (( "to9: machine reset called\n" )); |
| 3144 | 3014 | |
| 3145 | 3015 | /* subsystems */ |
| 3146 | | thom_irq_reset(machine); |
| 3147 | | sys_pia->set_port_a_z_mask( 0xfe ); |
| 3148 | | to7_game_reset(machine); |
| 3149 | | to9_floppy_reset(machine); |
| 3150 | | to9_kbd_reset(machine); |
| 3151 | | to7_modem_reset(machine); |
| 3152 | | to7_midi_reset(machine); |
| 3016 | thom_irq_reset(); |
| 3017 | m_pia_sys->set_port_a_z_mask( 0xfe ); |
| 3018 | to7_game_reset(); |
| 3019 | to9_floppy_reset(); |
| 3020 | to9_kbd_reset(); |
| 3021 | to7_modem_reset(); |
| 3022 | to7_midi_reset(); |
| 3153 | 3023 | |
| 3154 | 3024 | /* video */ |
| 3155 | | thom_set_video_mode( machine, THOM_VMODE_TO9 ); |
| 3156 | | thom_set_lightpen_callback( machine, 3, to7_lightpen_cb ); |
| 3157 | | thom_set_border_color( machine, 8 ); |
| 3158 | | thom_set_mode_point( machine, 0 ); |
| 3159 | | sys_pia->cb1_w( 0 ); |
| 3025 | thom_set_video_mode( THOM_VMODE_TO9 ); |
| 3026 | m_thom_lightpen_cb = &thomson_state::to7_lightpen_cb; |
| 3027 | thom_set_lightpen_callback( 3 ); |
| 3028 | thom_set_border_color( 8 ); |
| 3029 | thom_set_mode_point( 0 ); |
| 3030 | m_pia_sys->cb1_w( 0 ); |
| 3160 | 3031 | |
| 3161 | 3032 | /* memory */ |
| 3162 | | old_ram_bank = -1; |
| 3163 | | old_cart_bank = -1; |
| 3164 | | to9_soft_bank = 0; |
| 3165 | | to9_update_cart_bank(machine); |
| 3166 | | to9_update_ram_bank(machine); |
| 3033 | m_old_ram_bank = -1; |
| 3034 | m_old_cart_bank = -1; |
| 3035 | m_to9_soft_bank = 0; |
| 3036 | to9_update_cart_bank(); |
| 3037 | to9_update_ram_bank(); |
| 3167 | 3038 | /* thom_cart_bank not reset */ |
| 3168 | 3039 | |
| 3169 | 3040 | /* lightpen */ |
| 3170 | | to7_lightpen = 0; |
| 3041 | m_to7_lightpen = 0; |
| 3171 | 3042 | } |
| 3172 | 3043 | |
| 3173 | 3044 | |
| 3174 | 3045 | |
| 3175 | | MACHINE_START ( to9 ) |
| 3046 | MACHINE_START_MEMBER( thomson_state, to9 ) |
| 3176 | 3047 | { |
| 3177 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 3178 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 3048 | UINT8* mem = memregion("maincpu")->base(); |
| 3049 | UINT8* ram = m_ram->pointer(); |
| 3179 | 3050 | |
| 3180 | 3051 | LOG (( "to9: machine start called\n" )); |
| 3181 | 3052 | |
| 3182 | 3053 | /* subsystems */ |
| 3183 | | thom_irq_init(machine); |
| 3184 | | to7_game_init(machine); |
| 3185 | | to9_floppy_init( machine, mem + 0xe000, mem + 0x40000 ); |
| 3186 | | to9_kbd_init(machine); |
| 3187 | | to9_palette_init(machine); |
| 3188 | | to7_modem_init(machine); |
| 3189 | | to7_midi_init(machine); |
| 3054 | thom_irq_init(); |
| 3055 | to7_game_init(); |
| 3056 | to9_floppy_init( mem + 0xe000, mem + 0x40000 ); |
| 3057 | to9_kbd_init(); |
| 3058 | to9_palette_init(); |
| 3059 | to7_modem_init(); |
| 3060 | to7_midi_init(); |
| 3190 | 3061 | |
| 3191 | 3062 | /* memory */ |
| 3192 | | thom_vram = ram; |
| 3193 | | thom_cart_bank = 0; |
| 3194 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, thom_vram, 0x2000 ); |
| 3195 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 12, mem + 0x10000, 0x4000 ); |
| 3196 | | machine.root_device().membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 3197 | | machine.root_device().membank( THOM_RAM_BANK )->configure_entries( 0, 10, ram + 0x8000, 0x4000 ); |
| 3198 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 3199 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 3200 | | machine.root_device().membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 3201 | | machine.root_device().membank( THOM_RAM_BANK )->set_entry( 0 ); |
| 3063 | m_thom_vram = ram; |
| 3064 | m_thom_cart_bank = 0; |
| 3065 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, m_thom_vram, 0x2000 ); |
| 3066 | membank( THOM_CART_BANK )->configure_entries( 0, 12, mem + 0x10000, 0x4000 ); |
| 3067 | membank( THOM_BASE_BANK )->configure_entry( 0, ram + 0x4000); |
| 3068 | membank( THOM_RAM_BANK )->configure_entries( 0, 10, ram + 0x8000, 0x4000 ); |
| 3069 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 3070 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 3071 | membank( THOM_BASE_BANK )->set_entry( 0 ); |
| 3072 | membank( THOM_RAM_BANK )->set_entry( 0 ); |
| 3202 | 3073 | |
| 3203 | 3074 | /* save-state */ |
| 3204 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 3205 | | state_save_register_global( machine, thom_cart_bank ); |
| 3206 | | state_save_register_global( machine, to7_lightpen ); |
| 3207 | | state_save_register_global( machine, to7_lightpen_step ); |
| 3208 | | state_save_register_global( machine, to9_soft_bank ); |
| 3209 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 3210 | | machine.save().register_postload(save_prepost_delegate(FUNC(to9_update_ram_bank_postload), &machine)); |
| 3211 | | machine.save().register_postload(save_prepost_delegate(FUNC(to9_update_cart_bank_postload), &machine)); |
| 3075 | save_item(NAME(m_thom_cart_nb_banks)); |
| 3076 | save_item(NAME(m_thom_cart_bank)); |
| 3077 | save_item(NAME(m_to7_lightpen)); |
| 3078 | save_item(NAME(m_to7_lightpen_step)); |
| 3079 | save_item(NAME(m_to9_soft_bank)); |
| 3080 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 3081 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to9_update_ram_bank_postload), this)); |
| 3082 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to9_update_cart_bank_postload), this)); |
| 3212 | 3083 | } |
| 3213 | 3084 | |
| 3214 | 3085 | |
| r21425 | r21426 | |
| 3216 | 3087 | /***************************** TO8 *************************/ |
| 3217 | 3088 | |
| 3218 | 3089 | |
| 3219 | | |
| 3220 | | UINT8 to8_data_vpage; |
| 3221 | | UINT8 to8_cart_vpage; |
| 3222 | | |
| 3223 | | |
| 3224 | | |
| 3225 | 3090 | /* ------------ keyboard (6804) ------------ */ |
| 3226 | 3091 | |
| 3227 | 3092 | /* The 6804 chip scans the keyboard and sends keycodes to the 6809. |
| r21425 | r21426 | |
| 3255 | 3120 | |
| 3256 | 3121 | |
| 3257 | 3122 | |
| 3258 | | /* state */ |
| 3259 | | static UINT8 to8_kbd_ack; /* 1 = cpu inits / accepts transfers */ |
| 3260 | | static UINT16 to8_kbd_data; /* data to transmit */ |
| 3261 | | static UINT16 to8_kbd_step; /* transmission automaton state */ |
| 3262 | | static UINT8 to8_kbd_last_key; /* last key (for repetition) */ |
| 3263 | | static UINT32 to8_kbd_key_count; /* keypress time (for repetition) */ |
| 3264 | | static UINT8 to8_kbd_caps; /* caps lock */ |
| 3265 | | |
| 3266 | | static emu_timer* to8_kbd_timer; /* bit-send */ |
| 3267 | | static emu_timer* to8_kbd_signal; /* signal from CPU */ |
| 3268 | | |
| 3269 | | |
| 3270 | | |
| 3271 | 3123 | /* quick keyboard scan */ |
| 3272 | | static int to8_kbd_ktest ( running_machine &machine ) |
| 3124 | int thomson_state::to8_kbd_ktest() |
| 3273 | 3125 | { |
| 3274 | 3126 | int line, bit; |
| 3275 | 3127 | UINT8 port; |
| r21425 | r21426 | |
| 3278 | 3130 | "keyboard_5", "keyboard_6", "keyboard_7", "keyboard_8", "keyboard_9" |
| 3279 | 3131 | }; |
| 3280 | 3132 | |
| 3281 | | if ( machine.root_device().ioport("config")->read() & 2 ) |
| 3133 | if ( ioport("config")->read() & 2 ) |
| 3282 | 3134 | return 0; /* disabled */ |
| 3283 | 3135 | |
| 3284 | 3136 | for ( line = 0; line < 10; line++ ) |
| 3285 | 3137 | { |
| 3286 | | port = machine.root_device().ioport(keynames[line])->read(); |
| 3138 | port = ioport(keynames[line])->read(); |
| 3287 | 3139 | |
| 3288 | 3140 | if ( line == 7 || line == 9 ) |
| 3289 | 3141 | port |= 1; /* shift & control */ |
| r21425 | r21426 | |
| 3301 | 3153 | |
| 3302 | 3154 | |
| 3303 | 3155 | /* keyboard scan & return keycode (or -1) */ |
| 3304 | | static int to8_kbd_get_key( running_machine &machine ) |
| 3156 | int thomson_state::to8_kbd_get_key() |
| 3305 | 3157 | { |
| 3306 | | int control = (machine.root_device().ioport("keyboard_7")->read() & 1) ? 0 : 0x100; |
| 3307 | | int shift = (machine.root_device().ioport("keyboard_9")->read() & 1) ? 0 : 0x080; |
| 3158 | int control = (ioport("keyboard_7")->read() & 1) ? 0 : 0x100; |
| 3159 | int shift = (ioport("keyboard_9")->read() & 1) ? 0 : 0x080; |
| 3308 | 3160 | int key = -1, line, bit; |
| 3309 | 3161 | UINT8 port; |
| 3310 | 3162 | static const char *const keynames[] = { |
| r21425 | r21426 | |
| 3312 | 3164 | "keyboard_5", "keyboard_6", "keyboard_7", "keyboard_8", "keyboard_9" |
| 3313 | 3165 | }; |
| 3314 | 3166 | |
| 3315 | | if ( machine.root_device().ioport("config")->read() & 2 ) |
| 3167 | if ( ioport("config")->read() & 2 ) |
| 3316 | 3168 | return -1; /* disabled */ |
| 3317 | 3169 | |
| 3318 | 3170 | for ( line = 0; line < 10; line++ ) |
| 3319 | 3171 | { |
| 3320 | | port = machine.root_device().ioport(keynames[line])->read(); |
| 3172 | port = ioport(keynames[line])->read(); |
| 3321 | 3173 | |
| 3322 | 3174 | if ( line == 7 || line == 9 ) |
| 3323 | 3175 | port |= 1; /* shift & control */ |
| r21425 | r21426 | |
| 3334 | 3186 | |
| 3335 | 3187 | if ( key == -1 ) |
| 3336 | 3188 | { |
| 3337 | | to8_kbd_last_key = 0xff; |
| 3338 | | to8_kbd_key_count = 0; |
| 3189 | m_to8_kbd_last_key = 0xff; |
| 3190 | m_to8_kbd_key_count = 0; |
| 3339 | 3191 | return -1; |
| 3340 | 3192 | } |
| 3341 | 3193 | else if ( key == 64 ) |
| 3342 | 3194 | { |
| 3343 | 3195 | /* caps lock */ |
| 3344 | | if ( to8_kbd_last_key == key ) |
| 3196 | if ( m_to8_kbd_last_key == key ) |
| 3345 | 3197 | return -1; /* no repeat */ |
| 3346 | | to8_kbd_last_key = key; |
| 3347 | | to8_kbd_caps = !to8_kbd_caps; |
| 3348 | | if ( to8_kbd_caps ) |
| 3198 | m_to8_kbd_last_key = key; |
| 3199 | m_to8_kbd_caps = !m_to8_kbd_caps; |
| 3200 | if ( m_to8_kbd_caps ) |
| 3349 | 3201 | key |= 0x080; /* auto-shift */ |
| 3350 | | thom_set_caps_led( machine, !to8_kbd_caps ); |
| 3202 | thom_set_caps_led( !m_to8_kbd_caps ); |
| 3351 | 3203 | return key; |
| 3352 | 3204 | } |
| 3353 | | else if ( key == to8_kbd_last_key ) |
| 3205 | else if ( key == m_to8_kbd_last_key ) |
| 3354 | 3206 | { |
| 3355 | 3207 | /* repeat */ |
| 3356 | | to8_kbd_key_count++; |
| 3357 | | if ( to8_kbd_key_count < TO8_KBD_REPEAT_DELAY || (to8_kbd_key_count - TO8_KBD_REPEAT_DELAY) % TO8_KBD_REPEAT_PERIOD ) |
| 3208 | m_to8_kbd_key_count++; |
| 3209 | if ( m_to8_kbd_key_count < TO8_KBD_REPEAT_DELAY || (m_to8_kbd_key_count - TO8_KBD_REPEAT_DELAY) % TO8_KBD_REPEAT_PERIOD ) |
| 3358 | 3210 | return -1; |
| 3359 | 3211 | return key | shift | control; |
| 3360 | 3212 | } |
| 3361 | 3213 | else |
| 3362 | 3214 | { |
| 3363 | | to8_kbd_last_key = key; |
| 3364 | | to8_kbd_key_count = 0; |
| 3215 | m_to8_kbd_last_key = key; |
| 3216 | m_to8_kbd_key_count = 0; |
| 3365 | 3217 | return key | shift | control; |
| 3366 | 3218 | } |
| 3367 | 3219 | } |
| r21425 | r21426 | |
| 3376 | 3228 | */ |
| 3377 | 3229 | |
| 3378 | 3230 | /* keyboard automaton */ |
| 3379 | | static void to8_kbd_timer_func(running_machine &machine) |
| 3231 | void thomson_state::to8_kbd_timer_func() |
| 3380 | 3232 | { |
| 3381 | 3233 | attotime d; |
| 3382 | 3234 | |
| 3383 | | LOG_KBD(( "%f to8_kbd_timer_cb: step=%i ack=%i data=$%03X\n", machine.time().as_double(), to8_kbd_step, to8_kbd_ack, to8_kbd_data )); |
| 3235 | LOG_KBD(( "%f to8_kbd_timer_cb: step=%i ack=%i data=$%03X\n", machine().time().as_double(), m_to8_kbd_step, m_to8_kbd_ack, m_to8_kbd_data )); |
| 3384 | 3236 | |
| 3385 | | if( ! to8_kbd_step ) |
| 3237 | if( ! m_to8_kbd_step ) |
| 3386 | 3238 | { |
| 3387 | 3239 | /* key polling */ |
| 3388 | | int k = to8_kbd_get_key(machine); |
| 3240 | int k = to8_kbd_get_key(); |
| 3389 | 3241 | /* if not in transfer, send pulse from time to time |
| 3390 | 3242 | (helps avoiding CPU lock) |
| 3391 | 3243 | */ |
| 3392 | | if ( ! to8_kbd_ack ) |
| 3393 | | mc6846_set_input_cp1( machine.device("mc6846"), 0 ); |
| 3394 | | mc6846_set_input_cp1( machine.device("mc6846"), 1 ); |
| 3244 | if ( ! m_to8_kbd_ack ) |
| 3245 | mc6846_set_input_cp1( m_mc6846, 0 ); |
| 3246 | mc6846_set_input_cp1( m_mc6846, 1 ); |
| 3395 | 3247 | |
| 3396 | 3248 | if ( k == -1 ) |
| 3397 | 3249 | d = TO8_KBD_POLL_PERIOD; |
| r21425 | r21426 | |
| 3399 | 3251 | { |
| 3400 | 3252 | /* got key! */ |
| 3401 | 3253 | LOG_KBD(( "to8_kbd_timer_cb: got key $%03X\n", k )); |
| 3402 | | to8_kbd_data = k; |
| 3403 | | to8_kbd_step = 1; |
| 3254 | m_to8_kbd_data = k; |
| 3255 | m_to8_kbd_step = 1; |
| 3404 | 3256 | d = attotime::from_usec( 100 ); |
| 3405 | 3257 | } |
| 3406 | 3258 | } |
| 3407 | | else if ( to8_kbd_step == 255 ) |
| 3259 | else if ( m_to8_kbd_step == 255 ) |
| 3408 | 3260 | { |
| 3409 | 3261 | /* timeout */ |
| 3410 | | to8_kbd_last_key = 0xff; |
| 3411 | | to8_kbd_key_count = 0; |
| 3412 | | to8_kbd_step = 0; |
| 3413 | | mc6846_set_input_cp1( machine.device("mc6846"), 1 ); |
| 3262 | m_to8_kbd_last_key = 0xff; |
| 3263 | m_to8_kbd_key_count = 0; |
| 3264 | m_to8_kbd_step = 0; |
| 3265 | mc6846_set_input_cp1( m_mc6846, 1 ); |
| 3414 | 3266 | d = TO8_KBD_POLL_PERIOD; |
| 3415 | 3267 | } |
| 3416 | | else if ( to8_kbd_step == 1 ) |
| 3268 | else if ( m_to8_kbd_step == 1 ) |
| 3417 | 3269 | { |
| 3418 | 3270 | /* schedule timeout waiting for ack to go down */ |
| 3419 | | mc6846_set_input_cp1( machine.device("mc6846"), 0 ); |
| 3420 | | to8_kbd_step = 255; |
| 3271 | mc6846_set_input_cp1( m_mc6846, 0 ); |
| 3272 | m_to8_kbd_step = 255; |
| 3421 | 3273 | d = TO8_KBD_TIMEOUT; |
| 3422 | 3274 | } |
| 3423 | | else if ( to8_kbd_step == 117 ) |
| 3275 | else if ( m_to8_kbd_step == 117 ) |
| 3424 | 3276 | { |
| 3425 | 3277 | /* schedule timeout waiting for ack to go up */ |
| 3426 | | mc6846_set_input_cp1( machine.device("mc6846"), 0 ); |
| 3427 | | to8_kbd_step = 255; |
| 3278 | mc6846_set_input_cp1( m_mc6846, 0 ); |
| 3279 | m_to8_kbd_step = 255; |
| 3428 | 3280 | d = TO8_KBD_TIMEOUT; |
| 3429 | 3281 | } |
| 3430 | | else if ( to8_kbd_step & 1 ) |
| 3282 | else if ( m_to8_kbd_step & 1 ) |
| 3431 | 3283 | { |
| 3432 | 3284 | /* send silence between bits */ |
| 3433 | | mc6846_set_input_cp1( machine.device("mc6846"), 0 ); |
| 3285 | mc6846_set_input_cp1( m_mc6846, 0 ); |
| 3434 | 3286 | d = attotime::from_usec( 100 ); |
| 3435 | | to8_kbd_step++; |
| 3287 | m_to8_kbd_step++; |
| 3436 | 3288 | } |
| 3437 | 3289 | else |
| 3438 | 3290 | { |
| 3439 | 3291 | /* send bit */ |
| 3440 | | int bpos = 8 - ( (to8_kbd_step - 100) / 2); |
| 3441 | | int bit = (to8_kbd_data >> bpos) & 1; |
| 3442 | | mc6846_set_input_cp1( machine.device("mc6846"), 1 ); |
| 3292 | int bpos = 8 - ( (m_to8_kbd_step - 100) / 2); |
| 3293 | int bit = (m_to8_kbd_data >> bpos) & 1; |
| 3294 | mc6846_set_input_cp1( m_mc6846, 1 ); |
| 3443 | 3295 | d = attotime::from_usec( bit ? 56 : 38 ); |
| 3444 | | to8_kbd_step++; |
| 3296 | m_to8_kbd_step++; |
| 3445 | 3297 | } |
| 3446 | | to8_kbd_timer->adjust(d); |
| 3298 | m_to8_kbd_timer->adjust(d); |
| 3447 | 3299 | } |
| 3448 | 3300 | |
| 3449 | 3301 | |
| 3450 | 3302 | |
| 3451 | | static TIMER_CALLBACK(to8_kbd_timer_cb) |
| 3303 | TIMER_CALLBACK_MEMBER(thomson_state::to8_kbd_timer_cb) |
| 3452 | 3304 | { |
| 3453 | | to8_kbd_timer_func(machine); |
| 3305 | to8_kbd_timer_func(); |
| 3454 | 3306 | } |
| 3455 | 3307 | |
| 3456 | 3308 | |
| 3457 | 3309 | |
| 3458 | 3310 | /* cpu <-> keyboard hand-check */ |
| 3459 | | static void to8_kbd_set_ack ( running_machine &machine, int data ) |
| 3311 | void thomson_state::to8_kbd_set_ack( int data ) |
| 3460 | 3312 | { |
| 3461 | | if ( data == to8_kbd_ack ) |
| 3313 | if ( data == m_to8_kbd_ack ) |
| 3462 | 3314 | return; |
| 3463 | | to8_kbd_ack = data; |
| 3315 | m_to8_kbd_ack = data; |
| 3464 | 3316 | |
| 3465 | 3317 | if ( data ) |
| 3466 | 3318 | { |
| 3467 | | double len = to8_kbd_signal->elapsed( ).as_double() * 1000. - 2.; |
| 3468 | | LOG_KBD(( "%f to8_kbd_set_ack: CPU end ack, len=%f\n", machine.time().as_double(), len )); |
| 3469 | | if ( to8_kbd_data == 0xfff ) |
| 3319 | double len = m_to8_kbd_signal->elapsed( ).as_double() * 1000. - 2.; |
| 3320 | LOG_KBD(( "%f to8_kbd_set_ack: CPU end ack, len=%f\n", machine().time().as_double(), len )); |
| 3321 | if ( m_to8_kbd_data == 0xfff ) |
| 3470 | 3322 | { |
| 3471 | 3323 | /* end signal from CPU */ |
| 3472 | 3324 | if ( len >= 0.6 && len <= 0.8 ) |
| 3473 | 3325 | { |
| 3474 | | LOG (( "%f to8_kbd_set_ack: INIT signal\n", machine.time().as_double() )); |
| 3475 | | to8_kbd_last_key = 0xff; |
| 3476 | | to8_kbd_key_count = 0; |
| 3477 | | to8_kbd_caps = 1; |
| 3326 | LOG (( "%f to8_kbd_set_ack: INIT signal\n", machine().time().as_double() )); |
| 3327 | m_to8_kbd_last_key = 0xff; |
| 3328 | m_to8_kbd_key_count = 0; |
| 3329 | m_to8_kbd_caps = 1; |
| 3478 | 3330 | /* send back signal: TODO returned codes ? */ |
| 3479 | | to8_kbd_data = 0; |
| 3480 | | to8_kbd_step = 0; |
| 3481 | | to8_kbd_timer->adjust(attotime::from_msec( 1 )); |
| 3331 | m_to8_kbd_data = 0; |
| 3332 | m_to8_kbd_step = 0; |
| 3333 | m_to8_kbd_timer->adjust(attotime::from_msec( 1 )); |
| 3482 | 3334 | } |
| 3483 | 3335 | else |
| 3484 | 3336 | { |
| 3485 | | to8_kbd_step = 0; |
| 3486 | | to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD); |
| 3337 | m_to8_kbd_step = 0; |
| 3338 | m_to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD); |
| 3487 | 3339 | if ( len >= 1.2 && len <= 1.4 ) |
| 3488 | 3340 | { |
| 3489 | | LOG (( "%f to8_kbd_set_ack: CAPS on signal\n", machine.time().as_double() )); |
| 3490 | | to8_kbd_caps = 1; |
| 3341 | LOG (( "%f to8_kbd_set_ack: CAPS on signal\n", machine().time().as_double() )); |
| 3342 | m_to8_kbd_caps = 1; |
| 3491 | 3343 | } |
| 3492 | 3344 | else if ( len >= 1.8 && len <= 2.0 ) |
| 3493 | 3345 | { |
| 3494 | | LOG (( "%f to8_kbd_set_ack: CAPS off signal\n", machine.time().as_double() )); |
| 3495 | | to8_kbd_caps = 0; |
| 3346 | LOG (( "%f to8_kbd_set_ack: CAPS off signal\n", machine().time().as_double() )); |
| 3347 | m_to8_kbd_caps = 0; |
| 3496 | 3348 | } |
| 3497 | 3349 | } |
| 3498 | | thom_set_caps_led( machine, !to8_kbd_caps ); |
| 3350 | thom_set_caps_led( !m_to8_kbd_caps ); |
| 3499 | 3351 | } |
| 3500 | 3352 | else |
| 3501 | 3353 | { |
| 3502 | 3354 | /* end key transmission */ |
| 3503 | | to8_kbd_step = 0; |
| 3504 | | to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD); |
| 3355 | m_to8_kbd_step = 0; |
| 3356 | m_to8_kbd_timer->adjust(TO8_KBD_POLL_PERIOD); |
| 3505 | 3357 | } |
| 3506 | 3358 | } |
| 3507 | 3359 | |
| 3508 | 3360 | else |
| 3509 | 3361 | { |
| 3510 | | if ( to8_kbd_step == 255 ) |
| 3362 | if ( m_to8_kbd_step == 255 ) |
| 3511 | 3363 | { |
| 3512 | 3364 | /* CPU accepts key */ |
| 3513 | | to8_kbd_step = 99; |
| 3514 | | to8_kbd_timer->adjust(attotime::from_usec( 400 )); |
| 3365 | m_to8_kbd_step = 99; |
| 3366 | m_to8_kbd_timer->adjust(attotime::from_usec( 400 )); |
| 3515 | 3367 | } |
| 3516 | 3368 | else |
| 3517 | 3369 | { |
| 3518 | 3370 | /* start signal from CPU */ |
| 3519 | | to8_kbd_data = 0xfff; |
| 3520 | | to8_kbd_step = 91; |
| 3521 | | to8_kbd_timer->adjust(attotime::from_usec( 400 )); |
| 3522 | | to8_kbd_signal->adjust(attotime::never); |
| 3371 | m_to8_kbd_data = 0xfff; |
| 3372 | m_to8_kbd_step = 91; |
| 3373 | m_to8_kbd_timer->adjust(attotime::from_usec( 400 )); |
| 3374 | m_to8_kbd_signal->adjust(attotime::never); |
| 3523 | 3375 | } |
| 3524 | | LOG_KBD(( "%f to8_kbd_set_ack: CPU ack, data=$%03X\n", machine.time().as_double(), to8_kbd_data )); |
| 3376 | LOG_KBD(( "%f to8_kbd_set_ack: CPU ack, data=$%03X\n", machine().time().as_double(), m_to8_kbd_data )); |
| 3525 | 3377 | } |
| 3526 | 3378 | } |
| 3527 | 3379 | |
| 3528 | 3380 | |
| 3529 | 3381 | |
| 3530 | | static void to8_kbd_reset ( running_machine &machine ) |
| 3382 | void thomson_state::to8_kbd_reset() |
| 3531 | 3383 | { |
| 3532 | | to8_kbd_last_key = 0xff; |
| 3533 | | to8_kbd_key_count = 0; |
| 3534 | | to8_kbd_step = 0; |
| 3535 | | to8_kbd_data = 0; |
| 3536 | | to8_kbd_ack = 1; |
| 3537 | | to8_kbd_caps = 1; |
| 3538 | | thom_set_caps_led( machine, !to8_kbd_caps ); |
| 3539 | | to8_kbd_timer_func(machine); |
| 3384 | m_to8_kbd_last_key = 0xff; |
| 3385 | m_to8_kbd_key_count = 0; |
| 3386 | m_to8_kbd_step = 0; |
| 3387 | m_to8_kbd_data = 0; |
| 3388 | m_to8_kbd_ack = 1; |
| 3389 | m_to8_kbd_caps = 1; |
| 3390 | thom_set_caps_led( !m_to8_kbd_caps ); |
| 3391 | to8_kbd_timer_func(); |
| 3540 | 3392 | } |
| 3541 | 3393 | |
| 3542 | 3394 | |
| 3543 | 3395 | |
| 3544 | | static void to8_kbd_init ( running_machine &machine ) |
| 3396 | void thomson_state::to8_kbd_init() |
| 3545 | 3397 | { |
| 3546 | | to8_kbd_timer = machine.scheduler().timer_alloc(FUNC(to8_kbd_timer_cb)); |
| 3547 | | to8_kbd_signal = machine.scheduler().timer_alloc(FUNC_NULL); |
| 3548 | | state_save_register_global( machine, to8_kbd_ack ); |
| 3549 | | state_save_register_global( machine, to8_kbd_data ); |
| 3550 | | state_save_register_global( machine, to8_kbd_step ); |
| 3551 | | state_save_register_global( machine, to8_kbd_last_key ); |
| 3552 | | state_save_register_global( machine, to8_kbd_key_count ); |
| 3553 | | state_save_register_global( machine, to8_kbd_caps ); |
| 3398 | m_to8_kbd_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::to8_kbd_timer_cb),this)); |
| 3399 | m_to8_kbd_signal = machine().scheduler().timer_alloc(FUNC_NULL); |
| 3400 | save_item(NAME(m_to8_kbd_ack)); |
| 3401 | save_item(NAME(m_to8_kbd_data)); |
| 3402 | save_item(NAME(m_to8_kbd_step)); |
| 3403 | save_item(NAME(m_to8_kbd_last_key)); |
| 3404 | save_item(NAME(m_to8_kbd_key_count)); |
| 3405 | save_item(NAME(m_to8_kbd_caps)); |
| 3554 | 3406 | } |
| 3555 | 3407 | |
| 3556 | 3408 | |
| 3557 | 3409 | |
| 3558 | 3410 | /* ------------ RAM / ROM banking ------------ */ |
| 3559 | 3411 | |
| 3560 | | static UINT8 to8_reg_ram; |
| 3561 | | static UINT8 to8_reg_cart; |
| 3562 | | static UINT8 to8_reg_sys1; |
| 3563 | | static UINT8 to8_reg_sys2; |
| 3564 | | static UINT8 to8_lightpen_intr; |
| 3565 | | static UINT8 to8_soft_select; |
| 3566 | | static UINT8 to8_soft_bank; |
| 3567 | | static UINT8 to8_bios_bank; |
| 3568 | | |
| 3569 | | |
| 3570 | | |
| 3571 | | static void to8_update_floppy_bank( running_machine &machine ) |
| 3412 | void thomson_state::to8_update_floppy_bank() |
| 3572 | 3413 | { |
| 3573 | | int bank = (to8_reg_sys1 & 0x80) ? to7_floppy_bank : (to8_bios_bank + TO7_NB_FLOP_BANK); |
| 3414 | int bank = (m_to8_reg_sys1 & 0x80) ? to7_floppy_bank : (m_to8_bios_bank + TO7_NB_FLOP_BANK); |
| 3574 | 3415 | |
| 3575 | | if ( bank != old_floppy_bank ) |
| 3576 | | { |
| 3416 | if ( bank != m_old_floppy_bank ) |
| 3417 | { |
| 3577 | 3418 | LOG_BANK(( "to8_update_floppy_bank: floppy ROM is %s bank %i\n", |
| 3578 | | (to8_reg_sys1 & 0x80) ? "external" : "internal", |
| 3419 | (m_to8_reg_sys1 & 0x80) ? "external" : "internal", |
| 3579 | 3420 | bank % TO7_NB_FLOP_BANK )); |
| 3580 | | machine.root_device().membank( THOM_FLOP_BANK )->set_entry( bank ); |
| 3581 | | old_floppy_bank = bank; |
| 3421 | membank( THOM_FLOP_BANK )->set_entry( bank ); |
| 3422 | m_old_floppy_bank = bank; |
| 3582 | 3423 | } |
| 3583 | 3424 | } |
| 3584 | 3425 | |
| 3585 | 3426 | |
| 3586 | 3427 | |
| 3587 | | static void to8_update_floppy_bank_postload(running_machine *machine) |
| 3428 | void thomson_state::to8_update_floppy_bank_postload() |
| 3588 | 3429 | { |
| 3589 | | to8_update_floppy_bank(*machine); |
| 3430 | to8_update_floppy_bank(); |
| 3590 | 3431 | } |
| 3591 | 3432 | |
| 3592 | 3433 | |
| 3593 | 3434 | |
| 3594 | | static void to8_update_ram_bank (running_machine &machine) |
| 3435 | void thomson_state::to8_update_ram_bank() |
| 3595 | 3436 | { |
| 3596 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 3597 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 3437 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 3598 | 3438 | UINT8 bank = 0; |
| 3599 | 3439 | |
| 3600 | | if ( to8_reg_sys1 & 0x10 ) |
| 3440 | if ( m_to8_reg_sys1 & 0x10 ) |
| 3601 | 3441 | { |
| 3602 | | bank = to8_reg_ram & 31; |
| 3442 | bank = m_to8_reg_ram & 31; |
| 3603 | 3443 | } |
| 3604 | 3444 | else |
| 3605 | 3445 | { |
| 3606 | | UINT8 portb = sys_pia->port_b_z_mask(); |
| 3446 | UINT8 portb = m_pia_sys->port_b_z_mask(); |
| 3607 | 3447 | |
| 3608 | 3448 | switch ( portb & 0xf8 ) |
| 3609 | 3449 | { |
| r21425 | r21426 | |
| 3628 | 3468 | this is important if we map a bank that is also reachable by another, |
| 3629 | 3469 | undistorted space, such as cartridge, page 0 (video), or page 1 |
| 3630 | 3470 | */ |
| 3631 | | if ( bank != old_ram_bank) |
| 3471 | if ( bank != m_old_ram_bank) |
| 3472 | { |
| 3473 | if (m_ram->size() == 512*1024 || m_to8_data_vpage < 16) |
| 3632 | 3474 | { |
| 3633 | | if (machine.device<ram_device>(RAM_TAG)->size() == 512*1024 || to8_data_vpage < 16) |
| 3634 | | { |
| 3635 | | machine.root_device().membank( TO8_DATA_LO )->set_entry( bank ); |
| 3636 | | machine.root_device().membank( TO8_DATA_HI )->set_entry( bank ); |
| 3637 | | } else |
| 3638 | | { |
| 3475 | membank( TO8_DATA_LO )->set_entry( bank ); |
| 3476 | membank( TO8_DATA_HI )->set_entry( bank ); |
| 3477 | } |
| 3478 | else |
| 3479 | { |
| 3639 | 3480 | /* RAM size is 256 KB only and unavailable |
| 3640 | 3481 | * bank requested */ |
| 3641 | 3482 | space.nop_readwrite( 0xa000, 0xbfff); |
| 3642 | 3483 | space.nop_readwrite( 0xc000, 0xdfff); |
| 3643 | 3484 | } |
| 3644 | | to8_data_vpage = bank; |
| 3645 | | old_ram_bank = bank; |
| 3646 | | LOG_BANK(( "to8_update_ram_bank: select bank %i (%s style)\n", bank, (to8_reg_sys1 & 0x10) ? "new" : "old")); |
| 3485 | m_to8_data_vpage = bank; |
| 3486 | m_old_ram_bank = bank; |
| 3487 | LOG_BANK(( "to8_update_ram_bank: select bank %i (%s style)\n", bank, (m_to8_reg_sys1 & 0x10) ? "new" : "old")); |
| 3647 | 3488 | } |
| 3648 | 3489 | } |
| 3649 | 3490 | |
| 3650 | 3491 | |
| 3651 | 3492 | |
| 3652 | | static void to8_update_ram_bank_postload(running_machine *machine) |
| 3493 | void thomson_state::to8_update_ram_bank_postload() |
| 3653 | 3494 | { |
| 3654 | | to8_update_ram_bank(*machine); |
| 3495 | to8_update_ram_bank(); |
| 3655 | 3496 | } |
| 3656 | 3497 | |
| 3657 | 3498 | |
| 3658 | 3499 | |
| 3659 | | static void to8_update_cart_bank (running_machine &machine) |
| 3500 | void thomson_state::to8_update_cart_bank() |
| 3660 | 3501 | { |
| 3661 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 3502 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 3662 | 3503 | int bank = 0; |
| 3663 | 3504 | int bank_is_read_only = 0; |
| 3664 | 3505 | |
| 3665 | | if ( to8_reg_cart & 0x20 ) |
| 3506 | if ( m_to8_reg_cart & 0x20 ) |
| 3666 | 3507 | { |
| 3667 | 3508 | /* RAM space */ |
| 3668 | | to8_cart_vpage = to8_reg_cart & 31; |
| 3669 | | bank = 8 + to8_cart_vpage; |
| 3670 | | bank_is_read_only = (( to8_reg_cart & 0x40 ) == 0); |
| 3671 | | if ( bank != old_cart_bank ) |
| 3672 | | { |
| 3509 | m_to8_cart_vpage = m_to8_reg_cart & 31; |
| 3510 | bank = 8 + m_to8_cart_vpage; |
| 3511 | bank_is_read_only = (( m_to8_reg_cart & 0x40 ) == 0); |
| 3512 | if ( bank != m_old_cart_bank ) |
| 3513 | { |
| 3673 | 3514 | /* mapping to VRAM */ |
| 3674 | | if (machine.device<ram_device>(RAM_TAG)->size() == 512*1024 || to8_cart_vpage < 16) |
| 3675 | | { |
| 3676 | | if (to8_cart_vpage < 4) |
| 3677 | | { |
| 3678 | | if (old_cart_bank < 8 || old_cart_bank > 11) |
| 3679 | | { |
| 3515 | if (m_ram->size() == 512*1024 || m_to8_cart_vpage < 16) |
| 3516 | { |
| 3517 | if (m_to8_cart_vpage < 4) |
| 3518 | { |
| 3519 | if (m_old_cart_bank < 8 || m_old_cart_bank > 11) |
| 3520 | { |
| 3680 | 3521 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 3681 | 3522 | if ( bank_is_read_only ) |
| 3682 | | { |
| 3523 | { |
| 3683 | 3524 | space.nop_write( 0x0000, 0x3fff); |
| 3684 | | } |
| 3525 | } |
| 3685 | 3526 | else |
| 3686 | | { |
| 3687 | | space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_vcart_w)); |
| 3688 | | } |
| 3527 | { |
| 3528 | space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this)); |
| 3529 | } |
| 3689 | 3530 | } |
| 3690 | 3531 | } |
| 3691 | | else |
| 3692 | | { |
| 3693 | | if (old_cart_bank < 12) |
| 3694 | | { |
| 3532 | else |
| 3533 | { |
| 3534 | if (m_old_cart_bank < 12) |
| 3535 | { |
| 3695 | 3536 | if ( bank_is_read_only ) |
| 3696 | | { |
| 3537 | { |
| 3697 | 3538 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 3698 | 3539 | space.nop_write( 0x0000, 0x3fff); |
| 3699 | 3540 | } |
| 3700 | | else |
| 3701 | | { |
| 3702 | | space.install_readwrite_bank( 0x0000, 0x3fff,THOM_CART_BANK); |
| 3703 | | } |
| 3704 | | } |
| 3705 | | } |
| 3706 | | } |
| 3707 | 3541 | else |
| 3708 | 3542 | { |
| 3543 | space.install_readwrite_bank( 0x0000, 0x3fff,THOM_CART_BANK); |
| 3544 | } |
| 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | else |
| 3549 | { |
| 3709 | 3550 | /* RAM size is 256 KB only and unavailable |
| 3710 | 3551 | * bank requested */ |
| 3711 | 3552 | space.nop_readwrite( 0x0000, 0x3fff); |
| 3712 | | } |
| 3553 | } |
| 3713 | 3554 | LOG_BANK(( "to8_update_cart_bank: CART is RAM bank %i (%s)\n", |
| 3714 | | to8_cart_vpage, |
| 3555 | m_to8_cart_vpage, |
| 3715 | 3556 | bank_is_read_only ? "read-only":"read-write")); |
| 3716 | 3557 | } |
| 3717 | 3558 | else |
| 3559 | { |
| 3560 | if ( bank_is_read_only != m_old_cart_bank_was_read_only ) |
| 3561 | { |
| 3562 | if ( bank_is_read_only ) |
| 3718 | 3563 | { |
| 3719 | | if ( bank_is_read_only != old_cart_bank_was_read_only ) |
| 3720 | | { |
| 3721 | | if ( bank_is_read_only ) |
| 3722 | | { |
| 3723 | | space.nop_write( 0x0000, 0x3fff); |
| 3724 | | } |
| 3725 | | else |
| 3726 | | { |
| 3727 | | if (to8_cart_vpage < 4) |
| 3728 | | { |
| 3729 | | space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_vcart_w)); |
| 3730 | | } |
| 3731 | | else |
| 3732 | | { |
| 3733 | | space.install_readwrite_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 3734 | | } |
| 3735 | | } |
| 3736 | | LOG_BANK(( "to8_update_cart_bank: update CART bank %i write status to %s\n", |
| 3737 | | to8_cart_vpage, |
| 3738 | | bank_is_read_only ? "read-only":"read-write")); |
| 3739 | | } |
| 3564 | space.nop_write( 0x0000, 0x3fff); |
| 3740 | 3565 | } |
| 3741 | | old_cart_bank_was_read_only = bank_is_read_only; |
| 3566 | else |
| 3567 | { |
| 3568 | if (m_to8_cart_vpage < 4) |
| 3569 | { |
| 3570 | space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this)); |
| 3571 | } |
| 3572 | else |
| 3573 | { |
| 3574 | space.install_readwrite_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 3575 | } |
| 3576 | } |
| 3577 | LOG_BANK(( "to8_update_cart_bank: update CART bank %i write status to %s\n", |
| 3578 | m_to8_cart_vpage, |
| 3579 | bank_is_read_only ? "read-only":"read-write")); |
| 3580 | } |
| 3581 | } |
| 3582 | m_old_cart_bank_was_read_only = bank_is_read_only; |
| 3742 | 3583 | } |
| 3743 | 3584 | else |
| 3744 | 3585 | { |
| 3745 | | if ( to8_soft_select ) |
| 3586 | if ( m_to8_soft_select ) |
| 3746 | 3587 | { |
| 3747 | 3588 | /* internal software ROM space */ |
| 3748 | | bank = 4 + to8_soft_bank; |
| 3749 | | if ( bank != old_cart_bank ) |
| 3750 | | { |
| 3751 | | if ( old_cart_bank < 4 || old_cart_bank > 7 ) |
| 3752 | | { |
| 3589 | bank = 4 + m_to8_soft_bank; |
| 3590 | if ( bank != m_old_cart_bank ) |
| 3591 | { |
| 3592 | if ( m_old_cart_bank < 4 || m_old_cart_bank > 7 ) |
| 3593 | { |
| 3753 | 3594 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 3754 | | space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_cartridge_w) ); |
| 3595 | space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_cartridge_w),this) ); |
| 3755 | 3596 | } |
| 3756 | | LOG_BANK(( "to8_update_cart_bank: CART is internal bank %i\n", to8_soft_bank )); |
| 3597 | LOG_BANK(( "to8_update_cart_bank: CART is internal bank %i\n", m_to8_soft_bank )); |
| 3757 | 3598 | } |
| 3758 | 3599 | } |
| 3759 | 3600 | else |
| 3760 | 3601 | { |
| 3761 | 3602 | /* external cartridge ROM space */ |
| 3762 | | if ( thom_cart_nb_banks ) |
| 3603 | if ( m_thom_cart_nb_banks ) |
| 3763 | 3604 | { |
| 3764 | | bank = thom_cart_bank % thom_cart_nb_banks; |
| 3765 | | if ( bank != old_cart_bank ) |
| 3766 | | { |
| 3767 | | if ( old_cart_bank < 0 || old_cart_bank > 3 ) |
| 3768 | | { |
| 3605 | bank = m_thom_cart_bank % m_thom_cart_nb_banks; |
| 3606 | if ( bank != m_old_cart_bank ) |
| 3607 | { |
| 3608 | if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 ) |
| 3609 | { |
| 3769 | 3610 | space.install_read_bank( 0x0000, 0x3fff, THOM_CART_BANK ); |
| 3770 | | space.install_legacy_write_handler( 0x0000, 0x3fff, FUNC(to8_cartridge_w) ); |
| 3771 | | space.install_legacy_read_handler( 0x0000, 0x0003, FUNC(to8_cartridge_r) ); |
| 3611 | space.install_write_handler( 0x0000, 0x3fff, write8_delegate(FUNC(thomson_state::to8_cartridge_w),this) ); |
| 3612 | space.install_read_handler( 0x0000, 0x0003, read8_delegate(FUNC(thomson_state::to8_cartridge_r),this) ); |
| 3772 | 3613 | } |
| 3773 | 3614 | LOG_BANK(( "to8_update_cart_bank: CART is external cartridge bank %i\n", bank )); |
| 3774 | 3615 | } |
| 3775 | 3616 | } |
| 3776 | | else |
| 3777 | | { |
| 3778 | | if ( old_cart_bank != 0 ) |
| 3779 | | { |
| 3617 | else |
| 3618 | { |
| 3619 | if ( m_old_cart_bank != 0 ) |
| 3620 | { |
| 3780 | 3621 | space.nop_read( 0x0000, 0x3fff); |
| 3781 | 3622 | LOG_BANK(( "to8_update_cart_bank: CART is unmapped\n")); |
| 3782 | 3623 | } |
| 3783 | | } |
| 3784 | | } |
| 3624 | } |
| 3785 | 3625 | } |
| 3786 | | if ( bank != old_cart_bank ) |
| 3787 | | { |
| 3788 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( bank ); |
| 3789 | | old_cart_bank = bank; |
| 3790 | 3626 | } |
| 3627 | if ( bank != m_old_cart_bank ) |
| 3628 | { |
| 3629 | membank( THOM_CART_BANK )->set_entry( bank ); |
| 3630 | m_old_cart_bank = bank; |
| 3631 | } |
| 3791 | 3632 | } |
| 3792 | 3633 | |
| 3793 | 3634 | |
| 3794 | 3635 | |
| 3795 | | static void to8_update_cart_bank_postload(running_machine *machine) |
| 3636 | void thomson_state::to8_update_cart_bank_postload() |
| 3796 | 3637 | { |
| 3797 | | to8_update_cart_bank(*machine); |
| 3638 | to8_update_cart_bank(); |
| 3798 | 3639 | } |
| 3799 | 3640 | |
| 3800 | 3641 | |
| 3801 | 3642 | |
| 3802 | 3643 | /* ROM bank switch */ |
| 3803 | | WRITE8_HANDLER ( to8_cartridge_w ) |
| 3644 | WRITE8_MEMBER( thomson_state::to8_cartridge_w ) |
| 3804 | 3645 | { |
| 3805 | 3646 | if ( offset >= 0x2000 ) |
| 3806 | 3647 | return; |
| 3807 | 3648 | |
| 3808 | | if ( to8_soft_select ) |
| 3809 | | to8_soft_bank = offset & 3; |
| 3649 | if ( m_to8_soft_select ) |
| 3650 | m_to8_soft_bank = offset & 3; |
| 3810 | 3651 | else |
| 3811 | | thom_cart_bank = offset & 3; |
| 3652 | m_thom_cart_bank = offset & 3; |
| 3812 | 3653 | |
| 3813 | | to8_update_cart_bank(space.machine()); |
| 3654 | to8_update_cart_bank(); |
| 3814 | 3655 | } |
| 3815 | 3656 | |
| 3816 | 3657 | |
| 3817 | 3658 | |
| 3818 | 3659 | /* read signal to 0000-0003 generates a bank switch */ |
| 3819 | | READ8_HANDLER ( to8_cartridge_r ) |
| 3660 | READ8_MEMBER( thomson_state::to8_cartridge_r ) |
| 3820 | 3661 | { |
| 3821 | | UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000; |
| 3822 | | UINT8 data = pos[offset + (thom_cart_bank % thom_cart_nb_banks) * 0x4000]; |
| 3662 | UINT8* pos = memregion( "maincpu" )->base() + 0x10000; |
| 3663 | UINT8 data = pos[offset + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000]; |
| 3823 | 3664 | if ( !space.debugger_access() ) |
| 3824 | | { |
| 3825 | | thom_cart_bank = offset & 3; |
| 3826 | | to8_update_cart_bank(space.machine()); |
| 3665 | { |
| 3666 | m_thom_cart_bank = offset & 3; |
| 3667 | to8_update_cart_bank(); |
| 3827 | 3668 | } |
| 3828 | 3669 | return data; |
| 3829 | 3670 | } |
| r21425 | r21426 | |
| 3833 | 3674 | |
| 3834 | 3675 | |
| 3835 | 3676 | |
| 3836 | | static void to8_floppy_init( running_machine &machine ) |
| 3677 | void thomson_state::to8_floppy_init() |
| 3837 | 3678 | { |
| 3838 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 3839 | | to7_floppy_init( machine, mem + 0x34000 ); |
| 3679 | UINT8* mem = memregion("maincpu")->base(); |
| 3680 | to7_floppy_init( mem + 0x34000 ); |
| 3840 | 3681 | } |
| 3841 | 3682 | |
| 3842 | 3683 | |
| 3843 | 3684 | |
| 3844 | | static void to8_floppy_reset( running_machine &machine ) |
| 3685 | void thomson_state::to8_floppy_reset() |
| 3845 | 3686 | { |
| 3846 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 3847 | | to7_floppy_reset(machine); |
| 3687 | UINT8* mem = memregion("maincpu")->base(); |
| 3688 | to7_floppy_reset(); |
| 3848 | 3689 | if ( THOM_FLOPPY_INT ) |
| 3849 | | thmfc_floppy_reset(machine); |
| 3850 | | machine.root_device().membank( THOM_FLOP_BANK )->configure_entries( TO7_NB_FLOP_BANK, 2, mem + 0x30000, 0x2000 ); |
| 3690 | thmfc_floppy_reset(); |
| 3691 | membank( THOM_FLOP_BANK )->configure_entries( TO7_NB_FLOP_BANK, 2, mem + 0x30000, 0x2000 ); |
| 3851 | 3692 | } |
| 3852 | 3693 | |
| 3853 | 3694 | |
| 3854 | 3695 | |
| 3855 | | READ8_HANDLER ( to8_floppy_r ) |
| 3696 | READ8_MEMBER( thomson_state::to8_floppy_r ) |
| 3856 | 3697 | { |
| 3857 | 3698 | if ( space.debugger_access() ) |
| 3858 | 3699 | return 0; |
| 3859 | 3700 | |
| 3860 | | if ( (to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT ) |
| 3701 | if ( (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT ) |
| 3861 | 3702 | /* external controller */ |
| 3862 | 3703 | return to7_floppy_r( space, offset ); |
| 3863 | | else if ( ! (to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT ) |
| 3704 | else if ( ! (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT ) |
| 3864 | 3705 | /* internal controller */ |
| 3865 | 3706 | return thmfc_floppy_r( space, offset ); |
| 3866 | 3707 | else |
| r21425 | r21426 | |
| 3870 | 3711 | |
| 3871 | 3712 | |
| 3872 | 3713 | |
| 3873 | | WRITE8_HANDLER ( to8_floppy_w ) |
| 3714 | WRITE8_MEMBER( thomson_state::to8_floppy_w ) |
| 3874 | 3715 | { |
| 3875 | | if ( (to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT ) |
| 3716 | if ( (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_EXT ) |
| 3876 | 3717 | /* external controller */ |
| 3877 | 3718 | to7_floppy_w( space, offset, data ); |
| 3878 | | else if ( ! (to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT ) |
| 3719 | else if ( ! (m_to8_reg_sys1 & 0x80) && THOM_FLOPPY_INT ) |
| 3879 | 3720 | /* internal controller */ |
| 3880 | 3721 | thmfc_floppy_w( space, offset, data ); |
| 3881 | 3722 | } |
| r21425 | r21426 | |
| 3890 | 3731 | |
| 3891 | 3732 | |
| 3892 | 3733 | |
| 3893 | | READ8_HANDLER ( to8_gatearray_r ) |
| 3734 | READ8_MEMBER( thomson_state::to8_gatearray_r ) |
| 3894 | 3735 | { |
| 3895 | | struct thom_vsignal v = thom_get_vsignal(space.machine()); |
| 3896 | | struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), TO8_LIGHTPEN_DECAL, to7_lightpen_step - 1, 6 ); |
| 3736 | struct thom_vsignal v = thom_get_vsignal(); |
| 3737 | struct thom_vsignal l = thom_get_lightpen_vsignal( TO8_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 6 ); |
| 3897 | 3738 | int count, inil, init, lt3; |
| 3898 | 3739 | UINT8 res; |
| 3899 | | count = to7_lightpen ? l.count : v.count; |
| 3900 | | inil = to7_lightpen ? l.inil : v.inil; |
| 3901 | | init = to7_lightpen ? l.init : v.init; |
| 3902 | | lt3 = to7_lightpen ? l.lt3 : v.lt3; |
| 3740 | count = m_to7_lightpen ? l.count : v.count; |
| 3741 | inil = m_to7_lightpen ? l.inil : v.inil; |
| 3742 | init = m_to7_lightpen ? l.init : v.init; |
| 3743 | lt3 = m_to7_lightpen ? l.lt3 : v.lt3; |
| 3903 | 3744 | |
| 3904 | 3745 | switch ( offset ) |
| 3905 | 3746 | { |
| 3906 | 3747 | case 0: /* system 2 / lightpen register 1 */ |
| 3907 | | if ( to7_lightpen ) |
| 3748 | if ( m_to7_lightpen ) |
| 3908 | 3749 | res = (count >> 8) & 0xff; |
| 3909 | 3750 | else |
| 3910 | | res = to8_reg_sys2 & 0xf0; |
| 3751 | res = m_to8_reg_sys2 & 0xf0; |
| 3911 | 3752 | break; |
| 3912 | 3753 | |
| 3913 | 3754 | case 1: /* ram register / lightpen register 2 */ |
| 3914 | | if ( to7_lightpen ) |
| 3755 | if ( m_to7_lightpen ) |
| 3915 | 3756 | { |
| 3916 | 3757 | if ( !space.debugger_access() ) |
| 3917 | 3758 | { |
| 3918 | | thom_firq_2( space.machine(), 0 ); |
| 3919 | | to8_lightpen_intr = 0; |
| 3759 | thom_firq_2( 0 ); |
| 3760 | m_to8_lightpen_intr = 0; |
| 3920 | 3761 | } |
| 3921 | 3762 | res = count & 0xff; |
| 3922 | 3763 | } |
| 3923 | 3764 | else |
| 3924 | | res = to8_reg_ram & 0x1f; |
| 3765 | res = m_to8_reg_ram & 0x1f; |
| 3925 | 3766 | break; |
| 3926 | 3767 | |
| 3927 | 3768 | case 2: /* cartrige register / lightpen register 3 */ |
| 3928 | | if ( to7_lightpen ) |
| 3769 | if ( m_to7_lightpen ) |
| 3929 | 3770 | res = (lt3 << 7) | (inil << 6); |
| 3930 | 3771 | else |
| 3931 | | res = to8_reg_cart; |
| 3772 | res = m_to8_reg_cart; |
| 3932 | 3773 | break; |
| 3933 | 3774 | |
| 3934 | 3775 | case 3: /* lightpen register 4 */ |
| 3935 | | res = (v.init << 7) | (init << 6) | (v.inil << 5) | (to8_lightpen_intr << 1) | to7_lightpen; |
| 3776 | res = (v.init << 7) | (init << 6) | (v.inil << 5) | (m_to8_lightpen_intr << 1) | m_to7_lightpen; |
| 3936 | 3777 | break; |
| 3937 | 3778 | |
| 3938 | 3779 | default: |
| 3939 | | logerror( "$%04x to8_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 3780 | logerror( "$%04x to8_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset ); |
| 3940 | 3781 | res = 0; |
| 3941 | 3782 | } |
| 3942 | 3783 | |
| 3943 | 3784 | LOG_VIDEO(( "$%04x %f to8_gatearray_r: off=%i ($%04X) res=$%02X lightpen=%i\n", |
| 3944 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 3945 | | offset, 0xe7e4 + offset, res, to7_lightpen )); |
| 3785 | m_maincpu->pc(), machine().time().as_double(), |
| 3786 | offset, 0xe7e4 + offset, res, m_to7_lightpen )); |
| 3946 | 3787 | |
| 3947 | 3788 | return res; |
| 3948 | 3789 | } |
| 3949 | 3790 | |
| 3950 | 3791 | |
| 3951 | 3792 | |
| 3952 | | WRITE8_HANDLER ( to8_gatearray_w ) |
| 3793 | WRITE8_MEMBER( thomson_state::to8_gatearray_w ) |
| 3953 | 3794 | { |
| 3954 | 3795 | LOG_VIDEO(( "$%04x %f to8_gatearray_w: off=%i ($%04X) data=$%02X\n", |
| 3955 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 3796 | m_maincpu->pc(), machine().time().as_double(), |
| 3956 | 3797 | offset, 0xe7e4 + offset, data )); |
| 3957 | 3798 | |
| 3958 | 3799 | switch ( offset ) |
| 3959 | 3800 | { |
| 3960 | 3801 | case 0: /* switch */ |
| 3961 | | to7_lightpen = data & 1; |
| 3802 | m_to7_lightpen = data & 1; |
| 3962 | 3803 | break; |
| 3963 | 3804 | |
| 3964 | 3805 | case 1: /* ram register */ |
| 3965 | | if ( to8_reg_sys1 & 0x10 ) |
| 3806 | if ( m_to8_reg_sys1 & 0x10 ) |
| 3966 | 3807 | { |
| 3967 | | to8_reg_ram = data; |
| 3968 | | to8_update_ram_bank(space.machine()); |
| 3808 | m_to8_reg_ram = data; |
| 3809 | to8_update_ram_bank(); |
| 3969 | 3810 | } |
| 3970 | 3811 | break; |
| 3971 | 3812 | |
| 3972 | 3813 | case 2: /* cartridge register */ |
| 3973 | | to8_reg_cart = data; |
| 3974 | | to8_update_cart_bank(space.machine()); |
| 3814 | m_to8_reg_cart = data; |
| 3815 | to8_update_cart_bank(); |
| 3975 | 3816 | break; |
| 3976 | 3817 | |
| 3977 | 3818 | case 3: /* system register 1 */ |
| 3978 | | to8_reg_sys1 = data; |
| 3979 | | to8_update_floppy_bank(space.machine()); |
| 3980 | | to8_update_ram_bank(space.machine()); |
| 3981 | | to8_update_cart_bank(space.machine()); |
| 3819 | m_to8_reg_sys1 = data; |
| 3820 | to8_update_floppy_bank(); |
| 3821 | to8_update_ram_bank(); |
| 3822 | to8_update_cart_bank(); |
| 3982 | 3823 | break; |
| 3983 | 3824 | |
| 3984 | 3825 | default: |
| 3985 | 3826 | logerror( "$%04x to8_gatearray_w: invalid offset %i (data=$%02X)\n", |
| 3986 | | space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 3827 | m_maincpu->pc(), offset, data ); |
| 3987 | 3828 | } |
| 3988 | 3829 | } |
| 3989 | 3830 | |
| r21425 | r21426 | |
| 3993 | 3834 | |
| 3994 | 3835 | |
| 3995 | 3836 | |
| 3996 | | READ8_HANDLER ( to8_vreg_r ) |
| 3837 | READ8_MEMBER( thomson_state::to8_vreg_r ) |
| 3997 | 3838 | { |
| 3998 | 3839 | /* 0xe7dc from external floppy drive aliases the video gate-array */ |
| 3999 | | if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) && ( to8_reg_sys1 & 0x80 ) ) |
| 3840 | if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) && ( m_to8_reg_sys1 & 0x80 ) ) |
| 4000 | 3841 | { |
| 4001 | 3842 | if ( space.debugger_access() ) |
| 4002 | 3843 | return 0; |
| r21425 | r21426 | |
| 4011 | 3852 | { |
| 4012 | 3853 | case 0: /* palette data */ |
| 4013 | 3854 | { |
| 4014 | | UINT8 c = to9_palette_data[ to9_palette_idx ]; |
| 3855 | UINT8 c = m_to9_palette_data[ m_to9_palette_idx ]; |
| 4015 | 3856 | if ( !space.debugger_access() ) |
| 4016 | | { |
| 4017 | | to9_palette_idx = ( to9_palette_idx + 1 ) & 31; |
| 4018 | | } |
| 3857 | { |
| 3858 | m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31; |
| 3859 | } |
| 4019 | 3860 | return c; |
| 4020 | 3861 | } |
| 4021 | 3862 | |
| 4022 | 3863 | case 1: /* palette address */ |
| 4023 | | return to9_palette_idx; |
| 3864 | return m_to9_palette_idx; |
| 4024 | 3865 | |
| 4025 | 3866 | case 2: |
| 4026 | 3867 | case 3: |
| r21425 | r21426 | |
| 4034 | 3875 | |
| 4035 | 3876 | |
| 4036 | 3877 | |
| 4037 | | WRITE8_HANDLER ( to8_vreg_w ) |
| 3878 | WRITE8_MEMBER( thomson_state::to8_vreg_w ) |
| 4038 | 3879 | { |
| 4039 | 3880 | LOG_VIDEO(( "$%04x %f to8_vreg_w: off=%i ($%04X) data=$%02X\n", |
| 4040 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 3881 | m_maincpu->pc(), machine().time().as_double(), |
| 4041 | 3882 | offset, 0xe7da + offset, data )); |
| 4042 | 3883 | |
| 4043 | 3884 | switch ( offset ) |
| r21425 | r21426 | |
| 4045 | 3886 | case 0: /* palette data */ |
| 4046 | 3887 | { |
| 4047 | 3888 | UINT16 color, idx; |
| 4048 | | to9_palette_data[ to9_palette_idx ] = data; |
| 4049 | | idx = to9_palette_idx / 2; |
| 4050 | | color = to9_palette_data[ 2 * idx + 1 ]; |
| 4051 | | color = to9_palette_data[ 2 * idx ] | (color << 8); |
| 4052 | | thom_set_palette( space.machine(), idx, color & 0x1fff ); |
| 4053 | | to9_palette_idx = ( to9_palette_idx + 1 ) & 31; |
| 3889 | m_to9_palette_data[ m_to9_palette_idx ] = data; |
| 3890 | idx = m_to9_palette_idx / 2; |
| 3891 | color = m_to9_palette_data[ 2 * idx + 1 ]; |
| 3892 | color = m_to9_palette_data[ 2 * idx ] | (color << 8); |
| 3893 | thom_set_palette( idx, color & 0x1fff ); |
| 3894 | m_to9_palette_idx = ( m_to9_palette_idx + 1 ) & 31; |
| 4054 | 3895 | } |
| 4055 | 3896 | break; |
| 4056 | 3897 | |
| 4057 | 3898 | case 1: /* palette address */ |
| 4058 | | to9_palette_idx = data & 31; |
| 3899 | m_to9_palette_idx = data & 31; |
| 4059 | 3900 | break; |
| 4060 | 3901 | |
| 4061 | 3902 | case 2: /* display register */ |
| 4062 | | to9_set_video_mode( space.machine(), data, 1 ); |
| 3903 | to9_set_video_mode( data, 1 ); |
| 4063 | 3904 | break; |
| 4064 | 3905 | |
| 4065 | 3906 | case 3: /* system register 2 */ |
| 4066 | 3907 | /* 0xe7dc from external floppy drive aliases the video gate-array */ |
| 4067 | | if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) && ( to8_reg_sys1 & 0x80 ) ) |
| 3908 | if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) && ( m_to8_reg_sys1 & 0x80 ) ) |
| 4068 | 3909 | { |
| 4069 | 3910 | if ( THOM_FLOPPY_EXT ) |
| 4070 | 3911 | to7_floppy_w( space, 0xc, data ); |
| 4071 | 3912 | } |
| 4072 | 3913 | else |
| 4073 | 3914 | { |
| 4074 | | to8_reg_sys2 = data; |
| 4075 | | thom_set_video_page( space.machine(), data >> 6 ); |
| 4076 | | thom_set_border_color( space.machine(), data & 15 ); |
| 3915 | m_to8_reg_sys2 = data; |
| 3916 | thom_set_video_page( data >> 6 ); |
| 3917 | thom_set_border_color( data & 15 ); |
| 4077 | 3918 | } |
| 4078 | 3919 | break; |
| 4079 | 3920 | |
| r21425 | r21426 | |
| 4088 | 3929 | |
| 4089 | 3930 | |
| 4090 | 3931 | |
| 4091 | | static READ8_DEVICE_HANDLER ( to8_sys_porta_in ) |
| 3932 | READ8_MEMBER( thomson_state::to8_sys_porta_in ) |
| 4092 | 3933 | { |
| 4093 | | int ktest = to8_kbd_ktest (space.machine()); |
| 3934 | int ktest = to8_kbd_ktest(); |
| 4094 | 3935 | |
| 4095 | | LOG_KBD(( "$%04x %f: to8_sys_porta_in ktest=%i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), ktest )); |
| 3936 | LOG_KBD(( "$%04x %f: to8_sys_porta_in ktest=%i\n", m_maincpu->pc(), machine().time().as_double(), ktest )); |
| 4096 | 3937 | |
| 4097 | 3938 | return ktest; |
| 4098 | 3939 | } |
| 4099 | 3940 | |
| 4100 | 3941 | |
| 4101 | 3942 | |
| 4102 | | static WRITE8_DEVICE_HANDLER ( to8_sys_portb_out ) |
| 3943 | WRITE8_MEMBER( thomson_state::to8_sys_portb_out ) |
| 4103 | 3944 | { |
| 4104 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 3945 | m_centronics->d0_w(BIT(data, 0)); |
| 3946 | m_centronics->strobe_w(BIT(data, 1)); |
| 4105 | 3947 | |
| 4106 | | printer->d0_w(BIT(data, 0)); |
| 4107 | | printer->strobe_w(BIT(data, 1)); |
| 3948 | to8_update_ram_bank(); |
| 4108 | 3949 | |
| 4109 | | to8_update_ram_bank(space.machine()); |
| 4110 | | |
| 4111 | 3950 | if ( data & 4 ) /* bit 2: video overlay (TODO) */ |
| 4112 | 3951 | LOG(( "to8_sys_portb_out: video overlay not handled\n" )); |
| 4113 | 3952 | } |
| r21425 | r21426 | |
| 4116 | 3955 | |
| 4117 | 3956 | const pia6821_interface to8_pia6821_sys = |
| 4118 | 3957 | { |
| 4119 | | DEVCB_HANDLER(to8_sys_porta_in), |
| 3958 | DEVCB_DRIVER_MEMBER(thomson_state, to8_sys_porta_in), |
| 4120 | 3959 | DEVCB_NULL, |
| 4121 | 3960 | DEVCB_NULL, |
| 4122 | 3961 | DEVCB_NULL, |
| 4123 | 3962 | DEVCB_NULL, |
| 4124 | 3963 | DEVCB_NULL, |
| 4125 | | DEVCB_HANDLER(to9_sys_porta_out), |
| 4126 | | DEVCB_HANDLER(to8_sys_portb_out), |
| 4127 | | DEVCB_HANDLER(to7_set_cassette_motor), |
| 3964 | DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_out), |
| 3965 | DEVCB_DRIVER_MEMBER(thomson_state, to8_sys_portb_out), |
| 3966 | DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor), |
| 4128 | 3967 | DEVCB_NULL, |
| 4129 | 3968 | DEVCB_NULL, |
| 4130 | | DEVCB_LINE(thom_firq_1) |
| 3969 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1) |
| 4131 | 3970 | }; |
| 4132 | 3971 | |
| 4133 | 3972 | |
| r21425 | r21426 | |
| 4136 | 3975 | |
| 4137 | 3976 | |
| 4138 | 3977 | |
| 4139 | | static READ8_DEVICE_HANDLER ( to8_timer_port_in ) |
| 3978 | READ8_MEMBER( thomson_state::to8_timer_port_in ) |
| 4140 | 3979 | { |
| 4141 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 4142 | | int lightpen = (space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0; |
| 4143 | | int cass = to7_get_cassette(space.machine()) ? 0x80 : 0; |
| 4144 | | int dtr = printer->busy_r() << 6; |
| 4145 | | int lock = to8_kbd_caps ? 0 : 8; /* undocumented! */ |
| 3980 | int lightpen = (ioport("lightpen_button")->read() & 1) ? 2 : 0; |
| 3981 | int cass = to7_get_cassette() ? 0x80 : 0; |
| 3982 | int dtr = m_centronics->busy_r() << 6; |
| 3983 | int lock = m_to8_kbd_caps ? 0 : 8; /* undocumented! */ |
| 4146 | 3984 | return lightpen | cass | dtr | lock; |
| 4147 | 3985 | } |
| 4148 | 3986 | |
| 4149 | 3987 | |
| 4150 | 3988 | |
| 4151 | | static WRITE8_DEVICE_HANDLER ( to8_timer_port_out ) |
| 3989 | WRITE8_MEMBER( thomson_state::to8_timer_port_out ) |
| 4152 | 3990 | { |
| 4153 | 3991 | int ack = (data & 0x20) ? 1 : 0; /* bit 5: keyboard ACK */ |
| 4154 | | to8_bios_bank = (data & 0x10) ? 1 : 0; /* bit 4: BIOS bank*/ |
| 4155 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank switch */ |
| 4156 | | space.machine().root_device().membank( TO8_BIOS_BANK )->set_entry( to8_bios_bank ); |
| 4157 | | to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */ |
| 4158 | | to8_update_floppy_bank(space.machine()); |
| 4159 | | to8_update_cart_bank(space.machine()); |
| 4160 | | to8_kbd_set_ack(space.machine(), ack); |
| 3992 | m_to8_bios_bank = (data & 0x10) ? 1 : 0; /* bit 4: BIOS bank*/ |
| 3993 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 3994 | membank( TO8_BIOS_BANK )->set_entry( m_to8_bios_bank ); |
| 3995 | m_to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */ |
| 3996 | to8_update_floppy_bank(); |
| 3997 | to8_update_cart_bank(); |
| 3998 | to8_kbd_set_ack(ack); |
| 4161 | 3999 | } |
| 4162 | 4000 | |
| 4163 | 4001 | |
| 4164 | 4002 | |
| 4165 | | static WRITE8_DEVICE_HANDLER ( to8_timer_cp2_out ) |
| 4003 | WRITE8_MEMBER( thomson_state::to8_timer_cp2_out ) |
| 4166 | 4004 | { |
| 4167 | 4005 | /* mute */ |
| 4168 | | to7_game_mute = data; |
| 4169 | | to7_game_sound_update(space.machine()); |
| 4006 | m_to7_game_mute = data; |
| 4007 | to7_game_sound_update(); |
| 4170 | 4008 | } |
| 4171 | 4009 | |
| 4172 | 4010 | |
| 4173 | 4011 | |
| 4174 | 4012 | const mc6846_interface to8_timer = |
| 4175 | 4013 | { |
| 4176 | | DEVCB_HANDLER(to8_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to8_timer_cp2_out), |
| 4177 | | DEVCB_HANDLER(to8_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out), |
| 4178 | | DEVCB_LINE(thom_dev_irq_0) |
| 4014 | DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_port_out), |
| 4015 | DEVCB_NULL, |
| 4016 | DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_cp2_out), |
| 4017 | DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_port_in), |
| 4018 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out), |
| 4019 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0) |
| 4179 | 4020 | }; |
| 4180 | 4021 | |
| 4181 | 4022 | |
| r21425 | r21426 | |
| 4185 | 4026 | |
| 4186 | 4027 | |
| 4187 | 4028 | /* direct connection to interrupt line instead of through a PIA */ |
| 4188 | | static void to8_lightpen_cb ( running_machine &machine, int step ) |
| 4029 | void thomson_state::to8_lightpen_cb( int step ) |
| 4189 | 4030 | { |
| 4190 | | if ( ! to7_lightpen ) |
| 4031 | if ( ! m_to7_lightpen ) |
| 4191 | 4032 | return; |
| 4192 | 4033 | |
| 4193 | | thom_firq_2( machine, 1 ); |
| 4194 | | to7_lightpen_step = step; |
| 4195 | | to8_lightpen_intr = 1; |
| 4034 | thom_firq_2( 1 ); |
| 4035 | m_to7_lightpen_step = step; |
| 4036 | m_to8_lightpen_intr = 1; |
| 4196 | 4037 | } |
| 4197 | 4038 | |
| 4198 | 4039 | |
| r21425 | r21426 | |
| 4201 | 4042 | |
| 4202 | 4043 | |
| 4203 | 4044 | |
| 4204 | | MACHINE_RESET ( to8 ) |
| 4045 | MACHINE_RESET_MEMBER( thomson_state, to8 ) |
| 4205 | 4046 | { |
| 4206 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 4207 | 4047 | LOG (( "to8: machine reset called\n" )); |
| 4208 | 4048 | |
| 4209 | 4049 | /* subsystems */ |
| 4210 | | thom_irq_reset(machine); |
| 4211 | | sys_pia->set_port_a_z_mask( 0xfe ); |
| 4212 | | to7_game_reset(machine); |
| 4213 | | to8_floppy_reset(machine); |
| 4214 | | to8_kbd_reset(machine); |
| 4215 | | to7_modem_reset(machine); |
| 4216 | | to7_midi_reset(machine); |
| 4050 | thom_irq_reset(); |
| 4051 | m_pia_sys->set_port_a_z_mask( 0xfe ); |
| 4052 | to7_game_reset(); |
| 4053 | to8_floppy_reset(); |
| 4054 | to8_kbd_reset(); |
| 4055 | to7_modem_reset(); |
| 4056 | to7_midi_reset(); |
| 4217 | 4057 | |
| 4218 | 4058 | /* gate-array */ |
| 4219 | | to7_lightpen = 0; |
| 4220 | | to8_reg_ram = 0; |
| 4221 | | to8_reg_cart = 0; |
| 4222 | | to8_reg_sys1 = 0; |
| 4223 | | to8_reg_sys2 = 0; |
| 4224 | | to8_lightpen_intr = 0; |
| 4225 | | to8_soft_select = 0; |
| 4059 | m_to7_lightpen = 0; |
| 4060 | m_to8_reg_ram = 0; |
| 4061 | m_to8_reg_cart = 0; |
| 4062 | m_to8_reg_sys1 = 0; |
| 4063 | m_to8_reg_sys2 = 0; |
| 4064 | m_to8_lightpen_intr = 0; |
| 4065 | m_to8_soft_select = 0; |
| 4226 | 4066 | |
| 4227 | 4067 | /* video */ |
| 4228 | | thom_set_video_mode( machine, THOM_VMODE_TO770 ); |
| 4229 | | thom_set_lightpen_callback( machine, 4, to8_lightpen_cb ); |
| 4230 | | thom_set_border_color( machine, 0 ); |
| 4231 | | thom_set_mode_point( machine, 0 ); |
| 4232 | | sys_pia->cb1_w( 0 ); |
| 4068 | thom_set_video_mode( THOM_VMODE_TO770 ); |
| 4069 | m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb; |
| 4070 | thom_set_lightpen_callback( 4 ); |
| 4071 | thom_set_border_color( 0 ); |
| 4072 | thom_set_mode_point( 0 ); |
| 4073 | m_pia_sys->cb1_w( 0 ); |
| 4233 | 4074 | |
| 4234 | 4075 | /* memory */ |
| 4235 | | old_ram_bank = -1; |
| 4236 | | old_cart_bank = -1; |
| 4237 | | old_cart_bank_was_read_only = 0; |
| 4238 | | old_floppy_bank = -1; |
| 4239 | | to8_cart_vpage = 0; |
| 4240 | | to8_data_vpage = 0; |
| 4241 | | to8_soft_bank = 0; |
| 4242 | | to8_bios_bank = 0; |
| 4243 | | to8_update_ram_bank(machine); |
| 4244 | | to8_update_cart_bank(machine); |
| 4245 | | to8_update_floppy_bank(machine); |
| 4246 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4076 | m_old_ram_bank = -1; |
| 4077 | m_old_cart_bank = -1; |
| 4078 | m_old_cart_bank_was_read_only = 0; |
| 4079 | m_old_floppy_bank = -1; |
| 4080 | m_to8_cart_vpage = 0; |
| 4081 | m_to8_data_vpage = 0; |
| 4082 | m_to8_soft_bank = 0; |
| 4083 | m_to8_bios_bank = 0; |
| 4084 | to8_update_ram_bank(); |
| 4085 | to8_update_cart_bank(); |
| 4086 | to8_update_floppy_bank(); |
| 4087 | membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4247 | 4088 | /* thom_cart_bank not reset */ |
| 4248 | 4089 | } |
| 4249 | 4090 | |
| 4250 | 4091 | |
| 4251 | 4092 | |
| 4252 | | MACHINE_START ( to8 ) |
| 4093 | MACHINE_START_MEMBER( thomson_state, to8 ) |
| 4253 | 4094 | { |
| 4254 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 4255 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 4095 | UINT8* mem = memregion("maincpu")->base(); |
| 4096 | UINT8* ram = m_ram->pointer(); |
| 4256 | 4097 | |
| 4257 | 4098 | LOG (( "to8: machine start called\n" )); |
| 4258 | 4099 | |
| 4259 | 4100 | /* subsystems */ |
| 4260 | | thom_irq_init(machine); |
| 4261 | | to7_game_init(machine); |
| 4262 | | to8_floppy_init(machine); |
| 4263 | | to8_kbd_init(machine); |
| 4264 | | to9_palette_init(machine); |
| 4265 | | to7_modem_init(machine); |
| 4266 | | to7_midi_init(machine); |
| 4101 | thom_irq_init(); |
| 4102 | to7_game_init(); |
| 4103 | to8_floppy_init(); |
| 4104 | to8_kbd_init(); |
| 4105 | to9_palette_init(); |
| 4106 | to7_modem_init(); |
| 4107 | to7_midi_init(); |
| 4267 | 4108 | |
| 4268 | 4109 | /* memory */ |
| 4269 | | thom_cart_bank = 0; |
| 4270 | | thom_vram = ram; |
| 4271 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 8, mem + 0x10000, 0x4000 ); |
| 4272 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 ); |
| 4273 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 4274 | | machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 4275 | | machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 4276 | | machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 ); |
| 4277 | | machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 ); |
| 4278 | | machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x30800, 0x2000 ); |
| 4279 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 4280 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 4281 | | machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 ); |
| 4282 | | machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 ); |
| 4283 | | machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 ); |
| 4284 | | machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 ); |
| 4285 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4110 | m_thom_cart_bank = 0; |
| 4111 | m_thom_vram = ram; |
| 4112 | membank( THOM_CART_BANK )->configure_entries( 0, 8, mem + 0x10000, 0x4000 ); |
| 4113 | membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 ); |
| 4114 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 4115 | membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 4116 | membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 4117 | membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 ); |
| 4118 | membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 ); |
| 4119 | membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x30800, 0x2000 ); |
| 4120 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 4121 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 4122 | membank( TO8_SYS_LO )->set_entry( 0 ); |
| 4123 | membank( TO8_SYS_HI )->set_entry( 0 ); |
| 4124 | membank( TO8_DATA_LO )->set_entry( 0 ); |
| 4125 | membank( TO8_DATA_HI )->set_entry( 0 ); |
| 4126 | membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4286 | 4127 | |
| 4287 | 4128 | /* save-state */ |
| 4288 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 4289 | | state_save_register_global( machine, thom_cart_bank ); |
| 4290 | | state_save_register_global( machine, to7_lightpen ); |
| 4291 | | state_save_register_global( machine, to7_lightpen_step ); |
| 4292 | | state_save_register_global( machine, to8_reg_ram ); |
| 4293 | | state_save_register_global( machine, to8_reg_cart ); |
| 4294 | | state_save_register_global( machine, to8_reg_sys1 ); |
| 4295 | | state_save_register_global( machine, to8_reg_sys2 ); |
| 4296 | | state_save_register_global( machine, to8_soft_select ); |
| 4297 | | state_save_register_global( machine, to8_soft_bank ); |
| 4298 | | state_save_register_global( machine, to8_bios_bank ); |
| 4299 | | state_save_register_global( machine, to8_lightpen_intr ); |
| 4300 | | state_save_register_global( machine, to8_data_vpage ); |
| 4301 | | state_save_register_global( machine, to8_cart_vpage ); |
| 4302 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 4303 | | machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_ram_bank_postload), &machine)); |
| 4304 | | machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_cart_bank_postload), &machine)); |
| 4305 | | machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_floppy_bank_postload), &machine)); |
| 4129 | save_item(NAME(m_thom_cart_nb_banks)); |
| 4130 | save_item(NAME(m_thom_cart_bank)); |
| 4131 | save_item(NAME(m_to7_lightpen)); |
| 4132 | save_item(NAME(m_to7_lightpen_step)); |
| 4133 | save_item(NAME(m_to8_reg_ram)); |
| 4134 | save_item(NAME(m_to8_reg_cart)); |
| 4135 | save_item(NAME(m_to8_reg_sys1)); |
| 4136 | save_item(NAME(m_to8_reg_sys2)); |
| 4137 | save_item(NAME(m_to8_soft_select)); |
| 4138 | save_item(NAME(m_to8_soft_bank)); |
| 4139 | save_item(NAME(m_to8_bios_bank)); |
| 4140 | save_item(NAME(m_to8_lightpen_intr)); |
| 4141 | save_item(NAME(m_to8_data_vpage)); |
| 4142 | save_item(NAME(m_to8_cart_vpage)); |
| 4143 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 4144 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_ram_bank_postload), this)); |
| 4145 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_cart_bank_postload), this)); |
| 4146 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_floppy_bank_postload), this)); |
| 4306 | 4147 | } |
| 4307 | 4148 | |
| 4308 | 4149 | |
| r21425 | r21426 | |
| 4317 | 4158 | |
| 4318 | 4159 | const pia6821_interface to9p_pia6821_sys = |
| 4319 | 4160 | { |
| 4320 | | DEVCB_HANDLER(to9_sys_porta_in), |
| 4161 | DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_in), |
| 4321 | 4162 | DEVCB_NULL, |
| 4322 | 4163 | DEVCB_NULL, |
| 4323 | 4164 | DEVCB_NULL, |
| 4324 | 4165 | DEVCB_NULL, |
| 4325 | 4166 | DEVCB_NULL, |
| 4326 | | DEVCB_HANDLER(to9_sys_porta_out), |
| 4327 | | DEVCB_HANDLER(to8_sys_portb_out), |
| 4328 | | DEVCB_HANDLER(to7_set_cassette_motor), |
| 4167 | DEVCB_DRIVER_MEMBER(thomson_state, to9_sys_porta_out), |
| 4168 | DEVCB_DRIVER_MEMBER(thomson_state, to8_sys_portb_out), |
| 4169 | DEVCB_DRIVER_MEMBER(thomson_state, to7_set_cassette_motor), |
| 4329 | 4170 | DEVCB_NULL, |
| 4330 | 4171 | DEVCB_NULL, |
| 4331 | | DEVCB_LINE(thom_firq_1) |
| 4172 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1) |
| 4332 | 4173 | }; |
| 4333 | 4174 | |
| 4334 | 4175 | |
| r21425 | r21426 | |
| 4337 | 4178 | |
| 4338 | 4179 | |
| 4339 | 4180 | |
| 4340 | | static READ8_DEVICE_HANDLER ( to9p_timer_port_in ) |
| 4181 | READ8_MEMBER( thomson_state::to9p_timer_port_in ) |
| 4341 | 4182 | { |
| 4342 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 4343 | | int lightpen = (space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0; |
| 4344 | | int cass = to7_get_cassette(space.machine()) ? 0x80 : 0; |
| 4345 | | int dtr = printer->busy_r() << 6; |
| 4183 | int lightpen = (ioport("lightpen_button")->read() & 1) ? 2 : 0; |
| 4184 | int cass = to7_get_cassette() ? 0x80 : 0; |
| 4185 | int dtr = m_centronics->busy_r() << 6; |
| 4346 | 4186 | return lightpen | cass | dtr; |
| 4347 | 4187 | } |
| 4348 | 4188 | |
| 4349 | 4189 | |
| 4350 | 4190 | |
| 4351 | | static WRITE8_DEVICE_HANDLER ( to9p_timer_port_out ) |
| 4191 | WRITE8_MEMBER( thomson_state::to9p_timer_port_out ) |
| 4352 | 4192 | { |
| 4353 | 4193 | int bios_bank = (data & 0x10) ? 1 : 0; /* bit 4: BIOS bank */ |
| 4354 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank switch */ |
| 4355 | | space.machine().root_device().membank( TO8_BIOS_BANK )->set_entry( bios_bank ); |
| 4356 | | to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */ |
| 4357 | | to8_update_floppy_bank(space.machine()); |
| 4358 | | to8_update_cart_bank(space.machine()); |
| 4194 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 4195 | membank( TO8_BIOS_BANK )->set_entry( bios_bank ); |
| 4196 | m_to8_soft_select = (data & 0x04) ? 1 : 0; /* bit 2: internal ROM select */ |
| 4197 | to8_update_floppy_bank(); |
| 4198 | to8_update_cart_bank(); |
| 4359 | 4199 | } |
| 4360 | 4200 | |
| 4361 | 4201 | |
| 4362 | 4202 | |
| 4363 | 4203 | const mc6846_interface to9p_timer = |
| 4364 | 4204 | { |
| 4365 | | DEVCB_HANDLER(to9p_timer_port_out), DEVCB_NULL, DEVCB_HANDLER(to8_timer_cp2_out), |
| 4366 | | DEVCB_HANDLER(to9p_timer_port_in), DEVCB_HANDLER(to7_timer_tco_out), |
| 4367 | | DEVCB_LINE(thom_dev_irq_0) |
| 4205 | DEVCB_DRIVER_MEMBER(thomson_state, to9p_timer_port_out), |
| 4206 | DEVCB_NULL, |
| 4207 | DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_cp2_out), |
| 4208 | DEVCB_DRIVER_MEMBER(thomson_state, to9p_timer_port_in), |
| 4209 | DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out), |
| 4210 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0) |
| 4368 | 4211 | }; |
| 4369 | 4212 | |
| 4370 | 4213 | |
| r21425 | r21426 | |
| 4373 | 4216 | |
| 4374 | 4217 | |
| 4375 | 4218 | |
| 4376 | | MACHINE_RESET ( to9p ) |
| 4219 | MACHINE_RESET_MEMBER( thomson_state, to9p ) |
| 4377 | 4220 | { |
| 4378 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 4379 | 4221 | LOG (( "to9p: machine reset called\n" )); |
| 4380 | 4222 | |
| 4381 | 4223 | /* subsystems */ |
| 4382 | | thom_irq_reset(machine); |
| 4383 | | sys_pia->set_port_a_z_mask( 0xfe ); |
| 4384 | | to7_game_reset(machine); |
| 4385 | | to8_floppy_reset(machine); |
| 4386 | | to9_kbd_reset(machine); |
| 4387 | | to7_modem_reset(machine); |
| 4388 | | to7_midi_reset(machine); |
| 4224 | thom_irq_reset(); |
| 4225 | m_pia_sys->set_port_a_z_mask( 0xfe ); |
| 4226 | to7_game_reset(); |
| 4227 | to8_floppy_reset(); |
| 4228 | to9_kbd_reset(); |
| 4229 | to7_modem_reset(); |
| 4230 | to7_midi_reset(); |
| 4389 | 4231 | |
| 4390 | 4232 | /* gate-array */ |
| 4391 | | to7_lightpen = 0; |
| 4392 | | to8_reg_ram = 0; |
| 4393 | | to8_reg_cart = 0; |
| 4394 | | to8_reg_sys1 = 0; |
| 4395 | | to8_reg_sys2 = 0; |
| 4396 | | to8_lightpen_intr = 0; |
| 4397 | | to8_soft_select = 0; |
| 4233 | m_to7_lightpen = 0; |
| 4234 | m_to8_reg_ram = 0; |
| 4235 | m_to8_reg_cart = 0; |
| 4236 | m_to8_reg_sys1 = 0; |
| 4237 | m_to8_reg_sys2 = 0; |
| 4238 | m_to8_lightpen_intr = 0; |
| 4239 | m_to8_soft_select = 0; |
| 4398 | 4240 | |
| 4399 | 4241 | /* video */ |
| 4400 | | thom_set_video_mode( machine, THOM_VMODE_TO770 ); |
| 4401 | | thom_set_lightpen_callback( machine, 4, to8_lightpen_cb ); |
| 4402 | | thom_set_border_color( machine, 0 ); |
| 4403 | | thom_set_mode_point( machine, 0 ); |
| 4404 | | sys_pia->cb1_w( 0 ); |
| 4242 | thom_set_video_mode( THOM_VMODE_TO770 ); |
| 4243 | m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb; |
| 4244 | thom_set_lightpen_callback( 4 ); |
| 4245 | thom_set_border_color( 0 ); |
| 4246 | thom_set_mode_point( 0 ); |
| 4247 | m_pia_sys->cb1_w( 0 ); |
| 4405 | 4248 | |
| 4406 | 4249 | /* memory */ |
| 4407 | | old_ram_bank = -1; |
| 4408 | | old_cart_bank = -1; |
| 4409 | | old_floppy_bank = -1; |
| 4410 | | to8_cart_vpage = 0; |
| 4411 | | to8_data_vpage = 0; |
| 4412 | | to8_soft_bank = 0; |
| 4413 | | to8_bios_bank = 0; |
| 4414 | | to8_update_ram_bank(machine); |
| 4415 | | to8_update_cart_bank(machine); |
| 4416 | | to8_update_floppy_bank(machine); |
| 4417 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4250 | m_old_ram_bank = -1; |
| 4251 | m_old_cart_bank = -1; |
| 4252 | m_old_floppy_bank = -1; |
| 4253 | m_to8_cart_vpage = 0; |
| 4254 | m_to8_data_vpage = 0; |
| 4255 | m_to8_soft_bank = 0; |
| 4256 | m_to8_bios_bank = 0; |
| 4257 | to8_update_ram_bank(); |
| 4258 | to8_update_cart_bank(); |
| 4259 | to8_update_floppy_bank(); |
| 4260 | membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4418 | 4261 | /* thom_cart_bank not reset */ |
| 4419 | 4262 | } |
| 4420 | 4263 | |
| 4421 | 4264 | |
| 4422 | 4265 | |
| 4423 | | MACHINE_START ( to9p ) |
| 4266 | MACHINE_START_MEMBER( thomson_state, to9p ) |
| 4424 | 4267 | { |
| 4425 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 4426 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 4268 | UINT8* mem = memregion("maincpu")->base(); |
| 4269 | UINT8* ram = m_ram->pointer(); |
| 4427 | 4270 | |
| 4428 | 4271 | LOG (( "to9p: machine start called\n" )); |
| 4429 | 4272 | |
| 4430 | 4273 | /* subsystems */ |
| 4431 | | thom_irq_init(machine); |
| 4432 | | to7_game_init(machine); |
| 4433 | | to8_floppy_init( machine ); |
| 4434 | | to9_kbd_init(machine); |
| 4435 | | to9_palette_init(machine); |
| 4436 | | to7_modem_init(machine); |
| 4437 | | to7_midi_init(machine); |
| 4274 | thom_irq_init(); |
| 4275 | to7_game_init(); |
| 4276 | to8_floppy_init(); |
| 4277 | to9_kbd_init(); |
| 4278 | to9_palette_init(); |
| 4279 | to7_modem_init(); |
| 4280 | to7_midi_init(); |
| 4438 | 4281 | |
| 4439 | 4282 | /* memory */ |
| 4440 | | thom_cart_bank = 0; |
| 4441 | | thom_vram = ram; |
| 4442 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 8, mem + 0x10000, 0x4000 ); |
| 4443 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 ); |
| 4444 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 4445 | | machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 4446 | | machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 4447 | | machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 ); |
| 4448 | | machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 ); |
| 4449 | | machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x30800, 0x2000 ); |
| 4450 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 4451 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 4452 | | machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 ); |
| 4453 | | machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 ); |
| 4454 | | machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 ); |
| 4455 | | machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 ); |
| 4456 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4283 | m_thom_cart_bank = 0; |
| 4284 | m_thom_vram = ram; |
| 4285 | membank( THOM_CART_BANK )->configure_entries( 0, 8, mem + 0x10000, 0x4000 ); |
| 4286 | membank( THOM_CART_BANK )->configure_entries( 8, 32, ram, 0x4000 ); |
| 4287 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 4288 | membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 4289 | membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 4290 | membank( TO8_DATA_LO )->configure_entries( 0, 32, ram + 0x2000, 0x4000 ); |
| 4291 | membank( TO8_DATA_HI )->configure_entries( 0, 32, ram + 0x0000, 0x4000 ); |
| 4292 | membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x30800, 0x2000 ); |
| 4293 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 4294 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 4295 | membank( TO8_SYS_LO )->set_entry( 0 ); |
| 4296 | membank( TO8_SYS_HI )->set_entry( 0 ); |
| 4297 | membank( TO8_DATA_LO )->set_entry( 0 ); |
| 4298 | membank( TO8_DATA_HI )->set_entry( 0 ); |
| 4299 | membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 4457 | 4300 | |
| 4458 | 4301 | /* save-state */ |
| 4459 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 4460 | | state_save_register_global( machine, thom_cart_bank ); |
| 4461 | | state_save_register_global( machine, to7_lightpen ); |
| 4462 | | state_save_register_global( machine, to7_lightpen_step ); |
| 4463 | | state_save_register_global( machine, to8_reg_ram ); |
| 4464 | | state_save_register_global( machine, to8_reg_cart ); |
| 4465 | | state_save_register_global( machine, to8_reg_sys1 ); |
| 4466 | | state_save_register_global( machine, to8_reg_sys2 ); |
| 4467 | | state_save_register_global( machine, to8_soft_select ); |
| 4468 | | state_save_register_global( machine, to8_soft_bank ); |
| 4469 | | state_save_register_global( machine, to8_bios_bank ); |
| 4470 | | state_save_register_global( machine, to8_lightpen_intr ); |
| 4471 | | state_save_register_global( machine, to8_data_vpage ); |
| 4472 | | state_save_register_global( machine, to8_cart_vpage ); |
| 4473 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 4474 | | machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_ram_bank_postload), &machine)); |
| 4475 | | machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_cart_bank_postload), &machine)); |
| 4476 | | machine.save().register_postload(save_prepost_delegate(FUNC(to8_update_floppy_bank_postload), &machine)); |
| 4302 | save_item(NAME(m_thom_cart_nb_banks)); |
| 4303 | save_item(NAME(m_thom_cart_bank)); |
| 4304 | save_item(NAME(m_to7_lightpen)); |
| 4305 | save_item(NAME(m_to7_lightpen_step)); |
| 4306 | save_item(NAME(m_to8_reg_ram)); |
| 4307 | save_item(NAME(m_to8_reg_cart)); |
| 4308 | save_item(NAME(m_to8_reg_sys1)); |
| 4309 | save_item(NAME(m_to8_reg_sys2)); |
| 4310 | save_item(NAME(m_to8_soft_select)); |
| 4311 | save_item(NAME(m_to8_soft_bank)); |
| 4312 | save_item(NAME(m_to8_bios_bank)); |
| 4313 | save_item(NAME(m_to8_lightpen_intr)); |
| 4314 | save_item(NAME(m_to8_data_vpage)); |
| 4315 | save_item(NAME(m_to8_cart_vpage)); |
| 4316 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 4317 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_ram_bank_postload), this)); |
| 4318 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_cart_bank_postload), this)); |
| 4319 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::to8_update_floppy_bank_postload), this)); |
| 4477 | 4320 | } |
| 4478 | 4321 | |
| 4479 | 4322 | |
| r21425 | r21426 | |
| 4486 | 4329 | |
| 4487 | 4330 | |
| 4488 | 4331 | |
| 4489 | | static void mo6_update_ram_bank ( running_machine &machine ) |
| 4332 | void thomson_state::mo6_update_ram_bank() |
| 4490 | 4333 | { |
| 4491 | 4334 | UINT8 bank = 0; |
| 4492 | 4335 | |
| 4493 | | if ( to8_reg_sys1 & 0x10 ) |
| 4336 | if ( m_to8_reg_sys1 & 0x10 ) |
| 4494 | 4337 | { |
| 4495 | | bank = to8_reg_ram & 7; /* 128 KB RAM only = 8 pages */ |
| 4338 | bank = m_to8_reg_ram & 7; /* 128 KB RAM only = 8 pages */ |
| 4496 | 4339 | } |
| 4497 | | if ( bank != to8_data_vpage ) { |
| 4498 | | machine.root_device().membank( TO8_DATA_LO )->set_entry( bank ); |
| 4499 | | machine.root_device().membank( TO8_DATA_HI )->set_entry( bank ); |
| 4500 | | to8_data_vpage = bank; |
| 4501 | | old_ram_bank = bank; |
| 4340 | if ( bank != m_to8_data_vpage ) { |
| 4341 | membank( TO8_DATA_LO )->set_entry( bank ); |
| 4342 | membank( TO8_DATA_HI )->set_entry( bank ); |
| 4343 | m_to8_data_vpage = bank; |
| 4344 | m_old_ram_bank = bank; |
| 4502 | 4345 | LOG_BANK(( "mo6_update_ram_bank: select bank %i (new style)\n", bank )); |
| 4503 | 4346 | } |
| 4504 | 4347 | } |
| 4505 | 4348 | |
| 4506 | 4349 | |
| 4507 | 4350 | |
| 4508 | | static void mo6_update_ram_bank_postload(running_machine *machine) |
| 4351 | void thomson_state::mo6_update_ram_bank_postload() |
| 4509 | 4352 | { |
| 4510 | | mo6_update_ram_bank(*machine); |
| 4353 | mo6_update_ram_bank(); |
| 4511 | 4354 | } |
| 4512 | 4355 | |
| 4513 | 4356 | |
| 4514 | 4357 | |
| 4515 | | static void mo6_update_cart_bank (running_machine &machine) |
| 4358 | void thomson_state::mo6_update_cart_bank() |
| 4516 | 4359 | { |
| 4517 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 4518 | | address_space& space = machine.device("maincpu")->memory().space(AS_PROGRAM); |
| 4519 | | int b = (sys_pia->a_output() >> 5) & 1; |
| 4360 | address_space& space = m_maincpu->space(AS_PROGRAM); |
| 4361 | int b = (m_pia_sys->a_output() >> 5) & 1; |
| 4520 | 4362 | int bank = 0; |
| 4521 | 4363 | int bank_is_read_only = 0; |
| 4522 | 4364 | |
| 4523 | 4365 | // space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK ); |
| 4524 | 4366 | |
| 4525 | | if ( ( ( to8_reg_sys1 & 0x40 ) && ( to8_reg_cart & 0x20 ) ) || ( ! ( to8_reg_sys1 & 0x40 ) && ( mo5_reg_cart & 4 ) ) ) |
| 4367 | if ( ( ( m_to8_reg_sys1 & 0x40 ) && ( m_to8_reg_cart & 0x20 ) ) || ( ! ( m_to8_reg_sys1 & 0x40 ) && ( m_mo5_reg_cart & 4 ) ) ) |
| 4526 | 4368 | { |
| 4527 | 4369 | /* RAM space */ |
| 4528 | | if ( to8_reg_sys1 & 0x40 ) |
| 4370 | if ( m_to8_reg_sys1 & 0x40 ) |
| 4529 | 4371 | { |
| 4530 | 4372 | /* use a7e6 */ |
| 4531 | | to8_cart_vpage = to8_reg_cart & 7; /* 128 KB RAM only = 8 pages */ |
| 4532 | | bank = 8 + to8_cart_vpage; |
| 4533 | | bank_is_read_only = (( to8_reg_cart & 0x40 ) == 0); |
| 4534 | | if ( bank != old_cart_bank ) |
| 4535 | | { |
| 4536 | | if (to8_cart_vpage < 4) |
| 4537 | | { |
| 4538 | | if (old_cart_bank < 8 || old_cart_bank > 11) |
| 4539 | | { |
| 4373 | m_to8_cart_vpage = m_to8_reg_cart & 7; /* 128 KB RAM only = 8 pages */ |
| 4374 | bank = 8 + m_to8_cart_vpage; |
| 4375 | bank_is_read_only = (( m_to8_reg_cart & 0x40 ) == 0); |
| 4376 | if ( bank != m_old_cart_bank ) |
| 4377 | { |
| 4378 | if (m_to8_cart_vpage < 4) |
| 4379 | { |
| 4380 | if (m_old_cart_bank < 8 || m_old_cart_bank > 11) |
| 4381 | { |
| 4540 | 4382 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK ); |
| 4541 | 4383 | if ( bank_is_read_only ) |
| 4542 | | { |
| 4384 | { |
| 4543 | 4385 | space.nop_write( 0xb000, 0xefff); |
| 4544 | | } |
| 4386 | } |
| 4545 | 4387 | else |
| 4546 | | { |
| 4547 | | space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(to8_vcart_w)); |
| 4548 | | } |
| 4388 | { |
| 4389 | space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this)); |
| 4390 | } |
| 4549 | 4391 | } |
| 4550 | 4392 | } |
| 4551 | | else |
| 4552 | | { |
| 4553 | | if (old_cart_bank < 12) |
| 4554 | | { |
| 4393 | else |
| 4394 | { |
| 4395 | if (m_old_cart_bank < 12) |
| 4396 | { |
| 4555 | 4397 | if ( bank_is_read_only ) |
| 4556 | | { |
| 4398 | { |
| 4557 | 4399 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK ); |
| 4558 | 4400 | space.nop_write( 0xb000, 0xefff); |
| 4559 | 4401 | } |
| 4560 | | else |
| 4561 | | { |
| 4402 | else |
| 4403 | { |
| 4562 | 4404 | space.install_readwrite_bank( 0xb000, 0xefff,THOM_CART_BANK); |
| 4563 | | } |
| 4564 | | } |
| 4565 | | } |
| 4405 | } |
| 4406 | } |
| 4407 | } |
| 4566 | 4408 | LOG_BANK(( "mo6_update_cart_bank: CART is RAM bank %i (%s)\n", |
| 4567 | | to8_cart_vpage, |
| 4409 | m_to8_cart_vpage, |
| 4568 | 4410 | bank_is_read_only ? "read-only":"read-write")); |
| 4569 | 4411 | } |
| 4570 | | else if ( bank_is_read_only != old_cart_bank_was_read_only ) |
| 4571 | | { |
| 4412 | else if ( bank_is_read_only != m_old_cart_bank_was_read_only ) |
| 4413 | { |
| 4572 | 4414 | if ( bank_is_read_only ) |
| 4573 | | { |
| 4415 | { |
| 4574 | 4416 | space.nop_write( 0xb000, 0xefff); |
| 4575 | | } |
| 4417 | } |
| 4576 | 4418 | else |
| 4577 | | { |
| 4578 | | if (to8_cart_vpage < 4) |
| 4579 | | { |
| 4580 | | space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(to8_vcart_w)); |
| 4581 | | } |
| 4419 | { |
| 4420 | if (m_to8_cart_vpage < 4) |
| 4421 | { |
| 4422 | space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::to8_vcart_w),this)); |
| 4423 | } |
| 4582 | 4424 | else |
| 4583 | | { |
| 4425 | { |
| 4584 | 4426 | space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK ); |
| 4585 | | } |
| 4586 | | } |
| 4427 | } |
| 4428 | } |
| 4587 | 4429 | LOG_BANK(( "mo6_update_cart_bank: update CART bank %i write status to %s\n", |
| 4588 | | to8_cart_vpage, |
| 4430 | m_to8_cart_vpage, |
| 4589 | 4431 | bank_is_read_only ? "read-only":"read-write")); |
| 4590 | 4432 | } |
| 4591 | | old_cart_bank_was_read_only = bank_is_read_only; |
| 4433 | m_old_cart_bank_was_read_only = bank_is_read_only; |
| 4592 | 4434 | } |
| 4593 | | else if ( thom_cart_nb_banks == 4 ) |
| 4435 | else if ( m_thom_cart_nb_banks == 4 ) |
| 4594 | 4436 | { |
| 4595 | 4437 | /* "JANE"-style cartridge bank switching */ |
| 4596 | | bank = mo5_reg_cart & 3; |
| 4597 | | if ( bank != old_cart_bank ) |
| 4598 | | { |
| 4599 | | if ( old_cart_bank < 0 || old_cart_bank > 3 ) |
| 4600 | | { |
| 4438 | bank = m_mo5_reg_cart & 3; |
| 4439 | if ( bank != m_old_cart_bank ) |
| 4440 | { |
| 4441 | if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 ) |
| 4442 | { |
| 4601 | 4443 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK ); |
| 4602 | 4444 | space.nop_write( 0xb000, 0xefff); |
| 4603 | 4445 | } |
| r21425 | r21426 | |
| 4607 | 4449 | else |
| 4608 | 4450 | { |
| 4609 | 4451 | /* RAM from MO5 network extension */ |
| 4610 | | int bank_is_read_only = (( mo5_reg_cart & 8 ) == 0); |
| 4611 | | to8_cart_vpage = (mo5_reg_cart & 3) | 4; |
| 4612 | | bank = 8 + to8_cart_vpage; |
| 4613 | | if ( bank != old_cart_bank ) |
| 4614 | | { |
| 4615 | | if ( old_cart_bank < 12 ) |
| 4616 | | { |
| 4452 | int bank_is_read_only = (( m_mo5_reg_cart & 8 ) == 0); |
| 4453 | m_to8_cart_vpage = (m_mo5_reg_cart & 3) | 4; |
| 4454 | bank = 8 + m_to8_cart_vpage; |
| 4455 | if ( bank != m_old_cart_bank ) |
| 4456 | { |
| 4457 | if ( m_old_cart_bank < 12 ) |
| 4458 | { |
| 4617 | 4459 | if ( bank_is_read_only ) |
| 4618 | | { |
| 4460 | { |
| 4619 | 4461 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 4620 | 4462 | space.nop_write( 0xb000, 0xefff); |
| 4621 | | } else |
| 4622 | | { |
| 4463 | } |
| 4464 | else |
| 4465 | { |
| 4623 | 4466 | space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 4624 | | } |
| 4467 | } |
| 4625 | 4468 | } |
| 4626 | 4469 | LOG_BANK(( "mo6_update_cart_bank: CART is RAM bank %i (MO5 compat.) (%s)\n", |
| 4627 | | to8_cart_vpage, |
| 4470 | m_to8_cart_vpage, |
| 4628 | 4471 | bank_is_read_only ? "read-only":"read-write")); |
| 4629 | 4472 | } |
| 4630 | | else if ( bank_is_read_only != old_cart_bank_was_read_only ) |
| 4631 | | { |
| 4473 | else if ( bank_is_read_only != m_old_cart_bank_was_read_only ) |
| 4474 | { |
| 4632 | 4475 | if ( bank_is_read_only ) |
| 4633 | | { |
| 4476 | { |
| 4634 | 4477 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 4635 | 4478 | space.nop_write( 0xb000, 0xefff); |
| 4636 | 4479 | } |
| 4637 | | else |
| 4638 | | { |
| 4480 | else |
| 4481 | { |
| 4639 | 4482 | space.install_readwrite_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 4640 | | } |
| 4483 | } |
| 4641 | 4484 | LOG_BANK(( "mo5_update_cart_bank: update CART bank %i write status to %s\n", |
| 4642 | | to8_cart_vpage, |
| 4485 | m_to8_cart_vpage, |
| 4643 | 4486 | bank_is_read_only ? "read-only":"read-write")); |
| 4644 | 4487 | } |
| 4645 | | old_cart_bank_was_read_only = bank_is_read_only; |
| 4488 | m_old_cart_bank_was_read_only = bank_is_read_only; |
| 4646 | 4489 | } |
| 4647 | 4490 | } |
| 4648 | 4491 | else |
| 4649 | 4492 | { |
| 4650 | 4493 | /* ROM space */ |
| 4651 | | if ( to8_reg_sys2 & 0x20 ) |
| 4494 | if ( m_to8_reg_sys2 & 0x20 ) |
| 4652 | 4495 | { |
| 4653 | 4496 | /* internal ROM */ |
| 4654 | | if ( to8_reg_sys2 & 0x10) |
| 4655 | | { |
| 4497 | if ( m_to8_reg_sys2 & 0x10) |
| 4498 | { |
| 4656 | 4499 | bank = b + 6; /* BASIC 128 */ |
| 4657 | | } |
| 4500 | } |
| 4658 | 4501 | else |
| 4659 | | { |
| 4502 | { |
| 4660 | 4503 | bank = b + 4; /* BASIC 1 */ |
| 4661 | | } |
| 4662 | | if ( bank != old_cart_bank ) |
| 4663 | | { |
| 4664 | | if ( old_cart_bank < 4 || old_cart_bank > 7 ) |
| 4665 | | { |
| 4504 | } |
| 4505 | if ( bank != m_old_cart_bank ) |
| 4506 | { |
| 4507 | if ( m_old_cart_bank < 4 || m_old_cart_bank > 7 ) |
| 4508 | { |
| 4666 | 4509 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK); |
| 4667 | | space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo6_cartridge_w) ); |
| 4510 | space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo6_cartridge_w),this) ); |
| 4668 | 4511 | } |
| 4669 | 4512 | LOG_BANK(( "mo6_update_cart_bank: CART is internal ROM bank %i\n", b )); |
| 4670 | 4513 | } |
| r21425 | r21426 | |
| 4672 | 4515 | else |
| 4673 | 4516 | { |
| 4674 | 4517 | /* cartridge */ |
| 4675 | | if ( thom_cart_nb_banks ) |
| 4518 | if ( m_thom_cart_nb_banks ) |
| 4676 | 4519 | { |
| 4677 | | bank = thom_cart_bank % thom_cart_nb_banks; |
| 4678 | | if ( bank != old_cart_bank ) |
| 4679 | | { |
| 4680 | | if ( old_cart_bank < 0 || old_cart_bank > 3 ) |
| 4681 | | { |
| 4520 | bank = m_thom_cart_bank % m_thom_cart_nb_banks; |
| 4521 | if ( bank != m_old_cart_bank ) |
| 4522 | { |
| 4523 | if ( m_old_cart_bank < 0 || m_old_cart_bank > 3 ) |
| 4524 | { |
| 4682 | 4525 | space.install_read_bank( 0xb000, 0xefff, THOM_CART_BANK ); |
| 4683 | | space.install_legacy_write_handler( 0xb000, 0xefff, FUNC(mo6_cartridge_w) ); |
| 4684 | | space.install_legacy_read_handler( 0xbffc, 0xbfff, FUNC(mo6_cartridge_r) ); |
| 4526 | space.install_write_handler( 0xb000, 0xefff, write8_delegate(FUNC(thomson_state::mo6_cartridge_w),this) ); |
| 4527 | space.install_read_handler( 0xbffc, 0xbfff, read8_delegate(FUNC(thomson_state::mo6_cartridge_r),this) ); |
| 4685 | 4528 | } |
| 4686 | 4529 | LOG_BANK(( "mo6_update_cart_bank: CART is external cartridge bank %i\n", bank )); |
| 4687 | 4530 | } |
| 4688 | 4531 | } |
| 4689 | | else |
| 4690 | | { |
| 4691 | | if ( old_cart_bank != 0 ) |
| 4692 | | { |
| 4532 | else |
| 4533 | { |
| 4534 | if ( m_old_cart_bank != 0 ) |
| 4535 | { |
| 4693 | 4536 | space.nop_read( 0xb000, 0xefff ); |
| 4694 | 4537 | LOG_BANK(( "mo6_update_cart_bank: CART is unmapped\n")); |
| 4695 | 4538 | } |
| 4696 | | } |
| 4539 | } |
| 4697 | 4540 | } |
| 4698 | 4541 | } |
| 4699 | | if ( bank != old_cart_bank ) |
| 4542 | if ( bank != m_old_cart_bank ) |
| 4700 | 4543 | { |
| 4701 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( bank ); |
| 4702 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( b ); |
| 4703 | | old_cart_bank = bank; |
| 4544 | membank( THOM_CART_BANK )->set_entry( bank ); |
| 4545 | membank( TO8_BIOS_BANK )->set_entry( b ); |
| 4546 | m_old_cart_bank = bank; |
| 4704 | 4547 | } |
| 4705 | 4548 | } |
| 4706 | 4549 | |
| 4707 | 4550 | |
| 4708 | 4551 | |
| 4709 | | static void mo6_update_cart_bank_postload(running_machine *machine) |
| 4552 | void thomson_state::mo6_update_cart_bank_postload() |
| 4710 | 4553 | { |
| 4711 | | mo6_update_cart_bank(*machine); |
| 4554 | mo6_update_cart_bank(); |
| 4712 | 4555 | } |
| 4713 | 4556 | |
| 4714 | 4557 | |
| 4715 | 4558 | |
| 4716 | 4559 | /* write signal generates a bank switch */ |
| 4717 | | WRITE8_HANDLER ( mo6_cartridge_w ) |
| 4560 | WRITE8_MEMBER( thomson_state::mo6_cartridge_w ) |
| 4718 | 4561 | { |
| 4719 | 4562 | if ( offset >= 0x2000 ) |
| 4720 | 4563 | return; |
| 4721 | 4564 | |
| 4722 | | thom_cart_bank = offset & 3; |
| 4723 | | mo6_update_cart_bank(space.machine()); |
| 4565 | m_thom_cart_bank = offset & 3; |
| 4566 | mo6_update_cart_bank(); |
| 4724 | 4567 | } |
| 4725 | 4568 | |
| 4726 | 4569 | |
| 4727 | 4570 | |
| 4728 | 4571 | /* read signal generates a bank switch */ |
| 4729 | | READ8_HANDLER ( mo6_cartridge_r ) |
| 4572 | READ8_MEMBER( thomson_state::mo6_cartridge_r ) |
| 4730 | 4573 | { |
| 4731 | | UINT8* pos = space.machine().root_device().memregion( "maincpu" )->base() + 0x10000; |
| 4732 | | UINT8 data = pos[offset + 0xbffc + (thom_cart_bank % thom_cart_nb_banks) * 0x4000]; |
| 4574 | UINT8* pos = memregion( "maincpu" )->base() + 0x10000; |
| 4575 | UINT8 data = pos[offset + 0xbffc + (m_thom_cart_bank % m_thom_cart_nb_banks) * 0x4000]; |
| 4733 | 4576 | if ( !space.debugger_access() ) |
| 4734 | | { |
| 4735 | | thom_cart_bank = offset & 3; |
| 4736 | | mo6_update_cart_bank(space.machine()); |
| 4577 | { |
| 4578 | m_thom_cart_bank = offset & 3; |
| 4579 | mo6_update_cart_bank(); |
| 4737 | 4580 | } |
| 4738 | 4581 | return data; |
| 4739 | 4582 | } |
| 4740 | 4583 | |
| 4741 | 4584 | |
| 4742 | 4585 | |
| 4743 | | WRITE8_HANDLER ( mo6_ext_w ) |
| 4586 | WRITE8_MEMBER( thomson_state::mo6_ext_w ) |
| 4744 | 4587 | { |
| 4745 | 4588 | /* MO5 network extension compatible */ |
| 4746 | | mo5_reg_cart = data; |
| 4747 | | mo6_update_cart_bank(space.machine()); |
| 4589 | m_mo5_reg_cart = data; |
| 4590 | mo6_update_cart_bank(); |
| 4748 | 4591 | } |
| 4749 | 4592 | |
| 4750 | 4593 | |
| r21425 | r21426 | |
| 4754 | 4597 | /* similar to SX 90-018, but with a few differences: mute, printer */ |
| 4755 | 4598 | |
| 4756 | 4599 | |
| 4757 | | static WRITE_LINE_DEVICE_HANDLER( mo6_centronics_busy ) |
| 4600 | WRITE_LINE_MEMBER( thomson_state::mo6_centronics_busy ) |
| 4758 | 4601 | { |
| 4759 | | pia6821_device *game_pia = device->machine().device<pia6821_device>( THOM_PIA_GAME ); |
| 4760 | | game_pia->cb1_w(state); |
| 4602 | m_pia_game->cb1_w(state); |
| 4761 | 4603 | } |
| 4762 | 4604 | |
| 4763 | 4605 | |
| 4764 | 4606 | const centronics_interface mo6_centronics_config = |
| 4765 | 4607 | { |
| 4766 | 4608 | DEVCB_NULL, |
| 4767 | | DEVCB_LINE(mo6_centronics_busy), |
| 4609 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, mo6_centronics_busy), |
| 4768 | 4610 | DEVCB_NULL |
| 4769 | 4611 | }; |
| 4770 | 4612 | |
| 4771 | 4613 | |
| 4772 | | static WRITE8_DEVICE_HANDLER ( mo6_game_porta_out ) |
| 4614 | WRITE8_MEMBER( thomson_state::mo6_game_porta_out ) |
| 4773 | 4615 | { |
| 4774 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 4616 | LOG (( "$%04x %f mo6_game_porta_out: CENTRONICS set data=$%02X\n", m_maincpu->pc(), machine().time().as_double(), data )); |
| 4775 | 4617 | |
| 4776 | | LOG (( "$%04x %f mo6_game_porta_out: CENTRONICS set data=$%02X\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data )); |
| 4777 | | |
| 4778 | 4618 | /* centronics data */ |
| 4779 | | printer->write( space.machine().driver_data()->generic_space(), 0, data); |
| 4619 | m_centronics->write( space, 0, data); |
| 4780 | 4620 | } |
| 4781 | 4621 | |
| 4782 | 4622 | |
| 4783 | 4623 | |
| 4784 | | static WRITE8_DEVICE_HANDLER ( mo6_game_cb2_out ) |
| 4624 | WRITE8_MEMBER( thomson_state::mo6_game_cb2_out ) |
| 4785 | 4625 | { |
| 4786 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 4626 | LOG (( "$%04x %f mo6_game_cb2_out: CENTRONICS set strobe=%i\n", m_maincpu->pc(), machine().time().as_double(), data )); |
| 4787 | 4627 | |
| 4788 | | LOG (( "$%04x %f mo6_game_cb2_out: CENTRONICS set strobe=%i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data )); |
| 4789 | | |
| 4790 | 4628 | /* centronics strobe */ |
| 4791 | | printer->strobe_w(data); |
| 4629 | m_centronics->strobe_w(data); |
| 4792 | 4630 | } |
| 4793 | 4631 | |
| 4794 | 4632 | |
| 4795 | 4633 | |
| 4796 | 4634 | const pia6821_interface mo6_pia6821_game = |
| 4797 | 4635 | { |
| 4798 | | DEVCB_HANDLER(to7_game_porta_in), |
| 4799 | | DEVCB_HANDLER(to7_game_portb_in), |
| 4636 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_porta_in), |
| 4637 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_in), |
| 4800 | 4638 | DEVCB_NULL, |
| 4801 | 4639 | DEVCB_NULL, |
| 4802 | 4640 | DEVCB_NULL, |
| 4803 | 4641 | DEVCB_NULL, |
| 4804 | | DEVCB_HANDLER(mo6_game_porta_out), |
| 4805 | | DEVCB_HANDLER(to7_game_portb_out), |
| 4642 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_game_porta_out), |
| 4643 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_out), |
| 4806 | 4644 | DEVCB_NULL, |
| 4807 | | DEVCB_HANDLER(mo6_game_cb2_out), |
| 4808 | | DEVCB_LINE(thom_irq_1), |
| 4809 | | DEVCB_LINE(thom_irq_1) |
| 4645 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_game_cb2_out), |
| 4646 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1), |
| 4647 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) |
| 4810 | 4648 | }; |
| 4811 | 4649 | |
| 4812 | 4650 | |
| 4813 | 4651 | |
| 4814 | | static TIMER_CALLBACK(mo6_game_update_cb) |
| 4652 | TIMER_CALLBACK_MEMBER(thomson_state::mo6_game_update_cb) |
| 4815 | 4653 | { |
| 4816 | | pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME); |
| 4817 | | |
| 4818 | 4654 | /* unlike the TO8, CB1 & CB2 are not connected to buttons */ |
| 4819 | | if ( machine.root_device().ioport("config")->read() & 1 ) |
| 4655 | if ( ioport("config")->read() & 1 ) |
| 4820 | 4656 | { |
| 4821 | | UINT8 mouse = to7_get_mouse_signal(machine); |
| 4822 | | game_pia->ca1_w( BIT(mouse, 0) ); /* XA */ |
| 4823 | | game_pia->ca2_w( BIT(mouse, 1) ); /* YA */ |
| 4657 | UINT8 mouse = to7_get_mouse_signal(); |
| 4658 | m_pia_game->ca1_w( BIT(mouse, 0) ); /* XA */ |
| 4659 | m_pia_game->ca2_w( BIT(mouse, 1) ); /* YA */ |
| 4824 | 4660 | } |
| 4825 | 4661 | else |
| 4826 | 4662 | { |
| 4827 | 4663 | /* joystick */ |
| 4828 | | UINT8 in = machine.root_device().ioport("game_port_buttons")->read(); |
| 4829 | | game_pia->ca1_w( BIT(in, 2) ); /* P1 action B */ |
| 4830 | | game_pia->ca2_w( BIT(in, 6) ); /* P1 action A */ |
| 4664 | UINT8 in = ioport("game_port_buttons")->read(); |
| 4665 | m_pia_game->ca1_w( BIT(in, 2) ); /* P1 action B */ |
| 4666 | m_pia_game->ca2_w( BIT(in, 6) ); /* P1 action A */ |
| 4831 | 4667 | } |
| 4832 | 4668 | } |
| 4833 | 4669 | |
| 4834 | 4670 | |
| 4835 | 4671 | |
| 4836 | | static void mo6_game_init ( running_machine &machine ) |
| 4672 | void thomson_state::mo6_game_init() |
| 4837 | 4673 | { |
| 4838 | 4674 | LOG (( "mo6_game_init called\n" )); |
| 4839 | | to7_game_timer = machine.scheduler().timer_alloc(FUNC(mo6_game_update_cb)); |
| 4840 | | to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD); |
| 4841 | | state_save_register_global( machine, to7_game_sound ); |
| 4842 | | state_save_register_global( machine, to7_game_mute ); |
| 4675 | m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo6_game_update_cb),this)); |
| 4676 | m_to7_game_timer->adjust(TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD); |
| 4677 | save_item(NAME(m_to7_game_sound)); |
| 4678 | save_item(NAME(m_to7_game_mute)); |
| 4843 | 4679 | } |
| 4844 | 4680 | |
| 4845 | 4681 | |
| 4846 | 4682 | |
| 4847 | | static void mo6_game_reset ( running_machine &machine ) |
| 4683 | void thomson_state::mo6_game_reset() |
| 4848 | 4684 | { |
| 4849 | | pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME); |
| 4850 | 4685 | LOG (( "mo6_game_reset called\n" )); |
| 4851 | | game_pia->ca1_w( 0 ); |
| 4852 | | to7_game_sound = 0; |
| 4853 | | to7_game_mute = 0; |
| 4854 | | to7_game_sound_update(machine); |
| 4686 | m_pia_game->ca1_w( 0 ); |
| 4687 | m_to7_game_sound = 0; |
| 4688 | m_to7_game_mute = 0; |
| 4689 | to7_game_sound_update(); |
| 4855 | 4690 | } |
| 4856 | 4691 | |
| 4857 | 4692 | |
| r21425 | r21426 | |
| 4860 | 4695 | |
| 4861 | 4696 | |
| 4862 | 4697 | |
| 4863 | | static READ8_DEVICE_HANDLER ( mo6_sys_porta_in ) |
| 4698 | READ8_MEMBER( thomson_state::mo6_sys_porta_in ) |
| 4864 | 4699 | { |
| 4865 | 4700 | return |
| 4866 | | (mo5_get_cassette(space.machine()) ? 0x80 : 0) | /* bit 7: cassette input */ |
| 4701 | (mo5_get_cassette() ? 0x80 : 0) | /* bit 7: cassette input */ |
| 4867 | 4702 | 8 | /* bit 3: kbd-line float up to 1 */ |
| 4868 | | ((space.machine().root_device().ioport("lightpen_button")->read() & 1) ? 2 : 0); |
| 4703 | ((ioport("lightpen_button")->read() & 1) ? 2 : 0); |
| 4869 | 4704 | /* bit 1: lightpen button */; |
| 4870 | 4705 | } |
| 4871 | 4706 | |
| 4872 | 4707 | |
| 4873 | 4708 | |
| 4874 | | static READ8_DEVICE_HANDLER ( mo6_sys_portb_in ) |
| 4709 | READ8_MEMBER( thomson_state::mo6_sys_portb_in ) |
| 4875 | 4710 | { |
| 4876 | 4711 | /* keyboard: 9 lines of 8 keys */ |
| 4877 | | UINT8 porta = downcast<pia6821_device *>(device)->a_output(); |
| 4878 | | UINT8 portb =downcast<pia6821_device *>(device)->b_output(); |
| 4712 | UINT8 porta = m_pia_sys->a_output(); |
| 4713 | UINT8 portb = m_pia_sys->b_output(); |
| 4879 | 4714 | int col = (portb >> 4) & 7; /* B bits 4-6: kbd column */ |
| 4880 | 4715 | int lin = (portb >> 1) & 7; /* B bits 1-3: kbd line */ |
| 4881 | 4716 | static const char *const keynames[] = { |
| r21425 | r21426 | |
| 4887 | 4722 | lin = 8; /* A bit 3: 9-th kbd line select */ |
| 4888 | 4723 | |
| 4889 | 4724 | return |
| 4890 | | ( space.machine().root_device().ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0; |
| 4725 | ( ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0; |
| 4891 | 4726 | /* bit 7: key up */ |
| 4892 | 4727 | } |
| 4893 | 4728 | |
| 4894 | 4729 | |
| 4895 | 4730 | |
| 4896 | | static WRITE8_DEVICE_HANDLER ( mo6_sys_porta_out ) |
| 4731 | WRITE8_MEMBER( thomson_state::mo6_sys_porta_out ) |
| 4897 | 4732 | { |
| 4898 | | thom_set_mode_point( space.machine(),data & 1 ); /* bit 0: video bank switch */ |
| 4899 | | to7_game_mute = data & 4; /* bit 2: sound mute */ |
| 4900 | | thom_set_caps_led( space.machine(),(data & 16) ? 0 : 1 ) ; /* bit 4: keyboard led */ |
| 4901 | | mo5_set_cassette( space.machine(), (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */ |
| 4902 | | mo6_update_cart_bank(space.machine()); /* bit 5: rom bank */ |
| 4903 | | to7_game_sound_update(space.machine()); |
| 4733 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 4734 | m_to7_game_mute = data & 4; /* bit 2: sound mute */ |
| 4735 | thom_set_caps_led( (data & 16) ? 0 : 1 ) ; /* bit 4: keyboard led */ |
| 4736 | mo5_set_cassette( (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */ |
| 4737 | mo6_update_cart_bank(); /* bit 5: rom bank */ |
| 4738 | to7_game_sound_update(); |
| 4904 | 4739 | } |
| 4905 | 4740 | |
| 4906 | 4741 | |
| 4907 | 4742 | |
| 4908 | | static WRITE8_DEVICE_HANDLER ( mo6_sys_portb_out ) |
| 4743 | WRITE8_MEMBER( thomson_state::mo6_sys_portb_out ) |
| 4909 | 4744 | { |
| 4910 | | space.machine().device<dac_device>("buzzer")->write_unsigned8((data & 1) ? 0x80 : 0); /* bit 0: buzzer */ |
| 4745 | m_buzzer->write_unsigned8((data & 1) ? 0x80 : 0); /* bit 0: buzzer */ |
| 4911 | 4746 | } |
| 4912 | 4747 | |
| 4913 | 4748 | |
| 4914 | 4749 | |
| 4915 | | static WRITE8_DEVICE_HANDLER ( mo6_sys_cb2_out ) |
| 4750 | WRITE8_MEMBER( thomson_state::mo6_sys_cb2_out ) |
| 4916 | 4751 | { |
| 4917 | 4752 | /* SCART pin 8 = slow switch (?) */ |
| 4918 | 4753 | LOG(( "mo6_sys_cb2_out: SCART slow switch set to %i\n", data )); |
| r21425 | r21426 | |
| 4922 | 4757 | |
| 4923 | 4758 | const pia6821_interface mo6_pia6821_sys = |
| 4924 | 4759 | { |
| 4925 | | DEVCB_HANDLER(mo6_sys_porta_in), |
| 4926 | | DEVCB_HANDLER(mo6_sys_portb_in), |
| 4760 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_porta_in), |
| 4761 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_portb_in), |
| 4927 | 4762 | DEVCB_NULL, |
| 4928 | 4763 | DEVCB_NULL, |
| 4929 | 4764 | DEVCB_NULL, |
| 4930 | 4765 | DEVCB_NULL, |
| 4931 | | DEVCB_HANDLER(mo6_sys_porta_out), |
| 4932 | | DEVCB_HANDLER(mo6_sys_portb_out), |
| 4933 | | DEVCB_HANDLER(mo5_set_cassette_motor), |
| 4934 | | DEVCB_HANDLER(mo6_sys_cb2_out), |
| 4935 | | DEVCB_LINE(thom_firq_1), |
| 4936 | | DEVCB_LINE(thom_irq_1) /* differs from TO */ |
| 4766 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_porta_out), |
| 4767 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_portb_out), |
| 4768 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_set_cassette_motor), |
| 4769 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_cb2_out), |
| 4770 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1), |
| 4771 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) /* differs from TO */ |
| 4937 | 4772 | }; |
| 4938 | 4773 | |
| 4939 | 4774 | |
| r21425 | r21426 | |
| 4944 | 4779 | |
| 4945 | 4780 | |
| 4946 | 4781 | |
| 4947 | | READ8_HANDLER ( mo6_gatearray_r ) |
| 4782 | READ8_MEMBER( thomson_state::mo6_gatearray_r ) |
| 4948 | 4783 | { |
| 4949 | | struct thom_vsignal v = thom_get_vsignal(space.machine()); |
| 4950 | | struct thom_vsignal l = thom_get_lightpen_vsignal( space.machine(), MO6_LIGHTPEN_DECAL, to7_lightpen_step - 1, 6 ); |
| 4784 | struct thom_vsignal v = thom_get_vsignal(); |
| 4785 | struct thom_vsignal l = thom_get_lightpen_vsignal( MO6_LIGHTPEN_DECAL, m_to7_lightpen_step - 1, 6 ); |
| 4951 | 4786 | int count, inil, init, lt3; |
| 4952 | 4787 | UINT8 res; |
| 4953 | | count = to7_lightpen ? l.count : v.count; |
| 4954 | | inil = to7_lightpen ? l.inil : v.inil; |
| 4955 | | init = to7_lightpen ? l.init : v.init; |
| 4956 | | lt3 = to7_lightpen ? l.lt3 : v.lt3; |
| 4788 | count = m_to7_lightpen ? l.count : v.count; |
| 4789 | inil = m_to7_lightpen ? l.inil : v.inil; |
| 4790 | init = m_to7_lightpen ? l.init : v.init; |
| 4791 | lt3 = m_to7_lightpen ? l.lt3 : v.lt3; |
| 4957 | 4792 | |
| 4958 | 4793 | switch ( offset ) |
| 4959 | 4794 | { |
| 4960 | 4795 | case 0: /* system 2 / lightpen register 1 */ |
| 4961 | | if ( to7_lightpen ) |
| 4796 | if ( m_to7_lightpen ) |
| 4962 | 4797 | res = (count >> 8) & 0xff; |
| 4963 | 4798 | else |
| 4964 | | res = to8_reg_sys2 & 0xf0; |
| 4799 | res = m_to8_reg_sys2 & 0xf0; |
| 4965 | 4800 | break; |
| 4966 | 4801 | |
| 4967 | 4802 | case 1: /* ram register / lightpen register 2 */ |
| 4968 | | if ( to7_lightpen ) |
| 4803 | if ( m_to7_lightpen ) |
| 4969 | 4804 | { |
| 4970 | 4805 | if ( !space.debugger_access() ) |
| 4971 | 4806 | { |
| 4972 | | thom_firq_2( space.machine(), 0 ); |
| 4973 | | to8_lightpen_intr = 0; |
| 4807 | thom_firq_2( 0 ); |
| 4808 | m_to8_lightpen_intr = 0; |
| 4974 | 4809 | } |
| 4975 | 4810 | res = count & 0xff; |
| 4976 | 4811 | } |
| 4977 | 4812 | else |
| 4978 | | res = to8_reg_ram & 0x1f; |
| 4813 | res = m_to8_reg_ram & 0x1f; |
| 4979 | 4814 | break; |
| 4980 | 4815 | |
| 4981 | 4816 | case 2: /* cartrige register / lightpen register 3 */ |
| 4982 | | if ( to7_lightpen ) |
| 4817 | if ( m_to7_lightpen ) |
| 4983 | 4818 | res = (lt3 << 7) | (inil << 6); |
| 4984 | 4819 | else |
| 4985 | 4820 | res = 0; |
| 4986 | 4821 | break; |
| 4987 | 4822 | |
| 4988 | 4823 | case 3: /* lightpen register 4 */ |
| 4989 | | res = (v.init << 7) | (init << 6) | (v.inil << 5) | (to8_lightpen_intr << 1) | to7_lightpen; |
| 4824 | res = (v.init << 7) | (init << 6) | (v.inil << 5) | (m_to8_lightpen_intr << 1) | m_to7_lightpen; |
| 4990 | 4825 | break; |
| 4991 | 4826 | |
| 4992 | 4827 | default: |
| 4993 | | logerror( "$%04x mo6_gatearray_r: invalid offset %i\n", space.machine().device("maincpu")->safe_pcbase(), offset ); |
| 4828 | logerror( "$%04x mo6_gatearray_r: invalid offset %i\n", m_maincpu->pc(), offset ); |
| 4994 | 4829 | res = 0; |
| 4995 | 4830 | } |
| 4996 | 4831 | |
| 4997 | 4832 | LOG_VIDEO(( "$%04x %f mo6_gatearray_r: off=%i ($%04X) res=$%02X lightpen=%i\n", |
| 4998 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 4999 | | offset, 0xa7e4 + offset, res, to7_lightpen )); |
| 4833 | m_maincpu->pc(), machine().time().as_double(), |
| 4834 | offset, 0xa7e4 + offset, res, m_to7_lightpen )); |
| 5000 | 4835 | |
| 5001 | 4836 | return res; |
| 5002 | 4837 | } |
| 5003 | 4838 | |
| 5004 | 4839 | |
| 5005 | 4840 | |
| 5006 | | WRITE8_HANDLER ( mo6_gatearray_w ) |
| 4841 | WRITE8_MEMBER( thomson_state::mo6_gatearray_w ) |
| 5007 | 4842 | { |
| 5008 | 4843 | LOG_VIDEO(( "$%04x %f mo6_gatearray_w: off=%i ($%04X) data=$%02X\n", |
| 5009 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 4844 | m_maincpu->pc(), machine().time().as_double(), |
| 5010 | 4845 | offset, 0xa7e4 + offset, data )); |
| 5011 | 4846 | |
| 5012 | 4847 | switch ( offset ) |
| 5013 | 4848 | { |
| 5014 | 4849 | case 0: /* switch */ |
| 5015 | | to7_lightpen = data & 1; |
| 4850 | m_to7_lightpen = data & 1; |
| 5016 | 4851 | break; |
| 5017 | 4852 | |
| 5018 | 4853 | case 1: /* ram register */ |
| 5019 | | if ( to8_reg_sys1 & 0x10 ) |
| 4854 | if ( m_to8_reg_sys1 & 0x10 ) |
| 5020 | 4855 | { |
| 5021 | | to8_reg_ram = data; |
| 5022 | | mo6_update_ram_bank(space.machine()); |
| 4856 | m_to8_reg_ram = data; |
| 4857 | mo6_update_ram_bank(); |
| 5023 | 4858 | } |
| 5024 | 4859 | break; |
| 5025 | 4860 | |
| 5026 | 4861 | case 2: /* cartridge register */ |
| 5027 | | to8_reg_cart = data; |
| 5028 | | mo6_update_cart_bank(space.machine()); |
| 4862 | m_to8_reg_cart = data; |
| 4863 | mo6_update_cart_bank(); |
| 5029 | 4864 | break; |
| 5030 | 4865 | |
| 5031 | 4866 | case 3: /* system register 1 */ |
| 5032 | | to8_reg_sys1 = data; |
| 5033 | | mo6_update_ram_bank(space.machine()); |
| 5034 | | mo6_update_cart_bank(space.machine()); |
| 4867 | m_to8_reg_sys1 = data; |
| 4868 | mo6_update_ram_bank(); |
| 4869 | mo6_update_cart_bank(); |
| 5035 | 4870 | break; |
| 5036 | 4871 | |
| 5037 | 4872 | default: |
| 5038 | | logerror( "$%04x mo6_gatearray_w: invalid offset %i (data=$%02X)\n", space.machine().device("maincpu")->safe_pcbase(), offset, data ); |
| 4873 | logerror( "$%04x mo6_gatearray_w: invalid offset %i (data=$%02X)\n", m_maincpu->pc(), offset, data ); |
| 5039 | 4874 | } |
| 5040 | 4875 | } |
| 5041 | 4876 | |
| r21425 | r21426 | |
| 5044 | 4879 | |
| 5045 | 4880 | |
| 5046 | 4881 | |
| 5047 | | READ8_HANDLER ( mo6_vreg_r ) |
| 4882 | READ8_MEMBER( thomson_state::mo6_vreg_r ) |
| 5048 | 4883 | { |
| 5049 | 4884 | /* 0xa7dc from external floppy drive aliases the video gate-array */ |
| 5050 | | if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) ) |
| 4885 | if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) ) |
| 5051 | 4886 | { |
| 5052 | 4887 | if ( !space.debugger_access() ) |
| 5053 | 4888 | return to7_floppy_r( space, 0xc ); |
| r21425 | r21426 | |
| 5071 | 4906 | |
| 5072 | 4907 | |
| 5073 | 4908 | |
| 5074 | | WRITE8_HANDLER ( mo6_vreg_w ) |
| 4909 | WRITE8_MEMBER( thomson_state::mo6_vreg_w ) |
| 5075 | 4910 | { |
| 5076 | 4911 | LOG_VIDEO(( "$%04x %f mo6_vreg_w: off=%i ($%04X) data=$%02X\n", |
| 5077 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), |
| 4912 | m_maincpu->pc(), machine().time().as_double(), |
| 5078 | 4913 | offset, 0xa7da + offset, data )); |
| 5079 | 4914 | |
| 5080 | 4915 | switch ( offset ) |
| r21425 | r21426 | |
| 5085 | 4920 | return; |
| 5086 | 4921 | |
| 5087 | 4922 | case 2: /* display / external floppy register */ |
| 5088 | | if ( ( to8_reg_sys1 & 0x80 ) && ( to8_reg_ram & 0x80 ) ) |
| 4923 | if ( ( m_to8_reg_sys1 & 0x80 ) && ( m_to8_reg_ram & 0x80 ) ) |
| 5089 | 4924 | to7_floppy_w( space, 0xc, data ); |
| 5090 | 4925 | else |
| 5091 | | to9_set_video_mode( space.machine(), data, 2 ); |
| 4926 | to9_set_video_mode( data, 2 ); |
| 5092 | 4927 | break; |
| 5093 | 4928 | |
| 5094 | 4929 | case 3: /* system register 2 */ |
| 5095 | 4930 | /* 0xa7dc from external floppy drive aliases the video gate-array */ |
| 5096 | | if ( ( offset == 3 ) && ( to8_reg_ram & 0x80 ) ) |
| 4931 | if ( ( offset == 3 ) && ( m_to8_reg_ram & 0x80 ) ) |
| 5097 | 4932 | to7_floppy_w( space, 0xc, data ); |
| 5098 | 4933 | else |
| 5099 | 4934 | { |
| 5100 | | to8_reg_sys2 = data; |
| 5101 | | thom_set_video_page( space.machine(), data >> 6 ); |
| 5102 | | thom_set_border_color( space.machine(), data & 15 ); |
| 5103 | | mo6_update_cart_bank(space.machine()); |
| 4935 | m_to8_reg_sys2 = data; |
| 4936 | thom_set_video_page( data >> 6 ); |
| 4937 | thom_set_border_color( data & 15 ); |
| 4938 | mo6_update_cart_bank(); |
| 5104 | 4939 | } |
| 5105 | 4940 | break; |
| 5106 | 4941 | |
| r21425 | r21426 | |
| 5115 | 4950 | |
| 5116 | 4951 | |
| 5117 | 4952 | |
| 5118 | | MACHINE_RESET ( mo6 ) |
| 4953 | MACHINE_RESET_MEMBER( thomson_state, mo6 ) |
| 5119 | 4954 | { |
| 5120 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 5121 | 4955 | LOG (( "mo6: machine reset called\n" )); |
| 5122 | 4956 | |
| 5123 | 4957 | /* subsystems */ |
| 5124 | | thom_irq_reset(machine); |
| 5125 | | sys_pia->set_port_a_z_mask( 0x75 ); |
| 5126 | | mo6_game_reset(machine); |
| 5127 | | to7_floppy_reset(machine); |
| 5128 | | to7_modem_reset(machine); |
| 5129 | | to7_midi_reset(machine); |
| 5130 | | mo5_init_timer(machine); |
| 4958 | thom_irq_reset(); |
| 4959 | m_pia_sys->set_port_a_z_mask( 0x75 ); |
| 4960 | mo6_game_reset(); |
| 4961 | to7_floppy_reset(); |
| 4962 | to7_modem_reset(); |
| 4963 | to7_midi_reset(); |
| 4964 | mo5_init_timer(); |
| 5131 | 4965 | |
| 5132 | 4966 | /* gate-array */ |
| 5133 | | to7_lightpen = 0; |
| 5134 | | to8_reg_ram = 0; |
| 5135 | | to8_reg_cart = 0; |
| 5136 | | to8_reg_sys1 = 0; |
| 5137 | | to8_reg_sys2 = 0; |
| 5138 | | to8_lightpen_intr = 0; |
| 4967 | m_to7_lightpen = 0; |
| 4968 | m_to8_reg_ram = 0; |
| 4969 | m_to8_reg_cart = 0; |
| 4970 | m_to8_reg_sys1 = 0; |
| 4971 | m_to8_reg_sys2 = 0; |
| 4972 | m_to8_lightpen_intr = 0; |
| 5139 | 4973 | |
| 5140 | 4974 | /* video */ |
| 5141 | | thom_set_video_mode( machine, THOM_VMODE_MO5 ); |
| 5142 | | thom_set_lightpen_callback( machine, 3, to8_lightpen_cb ); |
| 5143 | | thom_set_border_color( machine, 0 ); |
| 5144 | | thom_set_mode_point( machine, 0 ); |
| 5145 | | sys_pia->ca1_w( 0 ); |
| 4975 | thom_set_video_mode( THOM_VMODE_MO5 ); |
| 4976 | m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb; |
| 4977 | thom_set_lightpen_callback( 3 ); |
| 4978 | thom_set_border_color( 0 ); |
| 4979 | thom_set_mode_point( 0 ); |
| 4980 | m_pia_sys->ca1_w( 0 ); |
| 5146 | 4981 | |
| 5147 | 4982 | /* memory */ |
| 5148 | | old_ram_bank = -1; |
| 5149 | | old_cart_bank = -1; |
| 5150 | | to8_cart_vpage = 0; |
| 5151 | | to8_data_vpage = 0; |
| 5152 | | mo6_update_ram_bank(machine); |
| 5153 | | mo6_update_cart_bank(machine); |
| 4983 | m_old_ram_bank = -1; |
| 4984 | m_old_cart_bank = -1; |
| 4985 | m_to8_cart_vpage = 0; |
| 4986 | m_to8_data_vpage = 0; |
| 4987 | mo6_update_ram_bank(); |
| 4988 | mo6_update_cart_bank(); |
| 5154 | 4989 | /* mo5_reg_cart not reset */ |
| 5155 | 4990 | /* thom_cart_bank not reset */ |
| 5156 | 4991 | } |
| 5157 | 4992 | |
| 5158 | 4993 | |
| 5159 | 4994 | |
| 5160 | | MACHINE_START ( mo6 ) |
| 4995 | MACHINE_START_MEMBER( thomson_state, mo6 ) |
| 5161 | 4996 | { |
| 5162 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 5163 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 4997 | UINT8* mem = memregion("maincpu")->base(); |
| 4998 | UINT8* ram = m_ram->pointer(); |
| 5164 | 4999 | |
| 5165 | 5000 | LOG (( "mo6: machine start called\n" )); |
| 5166 | 5001 | |
| 5167 | 5002 | /* subsystems */ |
| 5168 | | thom_irq_init(machine); |
| 5169 | | mo6_game_init(machine); |
| 5170 | | to7_floppy_init( machine, mem + 0x30000 ); |
| 5171 | | to9_palette_init(machine); |
| 5172 | | to7_modem_init(machine); |
| 5173 | | to7_midi_init(machine); |
| 5174 | | mo5_periodic_timer = machine.scheduler().timer_alloc(FUNC(mo5_periodic_cb)); |
| 5003 | thom_irq_init(); |
| 5004 | mo6_game_init(); |
| 5005 | to7_floppy_init( mem + 0x30000 ); |
| 5006 | to9_palette_init(); |
| 5007 | to7_modem_init(); |
| 5008 | to7_midi_init(); |
| 5009 | m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo5_periodic_cb),this)); |
| 5175 | 5010 | |
| 5176 | 5011 | /* memory */ |
| 5177 | | thom_cart_bank = 0; |
| 5178 | | mo5_reg_cart = 0; |
| 5179 | | thom_vram = ram; |
| 5180 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 5181 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 ); |
| 5182 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 ); |
| 5183 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 ); |
| 5184 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 5185 | | machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 5186 | | machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 5187 | | machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 ); |
| 5188 | | machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 ); |
| 5189 | | machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 ); |
| 5190 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 5191 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 5192 | | machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 ); |
| 5193 | | machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 ); |
| 5194 | | machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 ); |
| 5195 | | machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 ); |
| 5196 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 5012 | m_thom_cart_bank = 0; |
| 5013 | m_mo5_reg_cart = 0; |
| 5014 | m_thom_vram = ram; |
| 5015 | membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 5016 | membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 ); |
| 5017 | membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 ); |
| 5018 | membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 ); |
| 5019 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 5020 | membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 5021 | membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 5022 | membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 ); |
| 5023 | membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 ); |
| 5024 | membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 ); |
| 5025 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 5026 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 5027 | membank( TO8_SYS_LO )->set_entry( 0 ); |
| 5028 | membank( TO8_SYS_HI )->set_entry( 0 ); |
| 5029 | membank( TO8_DATA_LO )->set_entry( 0 ); |
| 5030 | membank( TO8_DATA_HI )->set_entry( 0 ); |
| 5031 | membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 5197 | 5032 | |
| 5198 | 5033 | /* save-state */ |
| 5199 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 5200 | | state_save_register_global( machine, thom_cart_bank ); |
| 5201 | | state_save_register_global( machine, to7_lightpen ); |
| 5202 | | state_save_register_global( machine, to7_lightpen_step ); |
| 5203 | | state_save_register_global( machine, to8_reg_ram ); |
| 5204 | | state_save_register_global( machine, to8_reg_cart ); |
| 5205 | | state_save_register_global( machine, to8_reg_sys1 ); |
| 5206 | | state_save_register_global( machine, to8_reg_sys2 ); |
| 5207 | | state_save_register_global( machine, to8_lightpen_intr ); |
| 5208 | | state_save_register_global( machine, to8_data_vpage ); |
| 5209 | | state_save_register_global( machine, to8_cart_vpage ); |
| 5210 | | state_save_register_global( machine, mo5_reg_cart ); |
| 5211 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 5212 | | machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_ram_bank_postload), &machine)); |
| 5213 | | machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_cart_bank_postload), &machine)); |
| 5034 | save_item(NAME(m_thom_cart_nb_banks)); |
| 5035 | save_item(NAME(m_thom_cart_bank)); |
| 5036 | save_item(NAME(m_to7_lightpen)); |
| 5037 | save_item(NAME(m_to7_lightpen_step)); |
| 5038 | save_item(NAME(m_to8_reg_ram)); |
| 5039 | save_item(NAME(m_to8_reg_cart)); |
| 5040 | save_item(NAME(m_to8_reg_sys1)); |
| 5041 | save_item(NAME(m_to8_reg_sys2)); |
| 5042 | save_item(NAME(m_to8_lightpen_intr)); |
| 5043 | save_item(NAME(m_to8_data_vpage)); |
| 5044 | save_item(NAME(m_to8_cart_vpage)); |
| 5045 | save_item(NAME(m_mo5_reg_cart)); |
| 5046 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 5047 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_ram_bank_postload), this)); |
| 5048 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_cart_bank_postload), this)); |
| 5214 | 5049 | } |
| 5215 | 5050 | |
| 5216 | 5051 | |
| r21425 | r21426 | |
| 5223 | 5058 | |
| 5224 | 5059 | |
| 5225 | 5060 | |
| 5226 | | READ8_HANDLER ( mo5nr_net_r ) |
| 5061 | READ8_MEMBER( thomson_state::mo5nr_net_r ) |
| 5227 | 5062 | { |
| 5228 | 5063 | if ( space.debugger_access() ) |
| 5229 | 5064 | return 0; |
| r21425 | r21426 | |
| 5231 | 5066 | if ( to7_controller_type ) |
| 5232 | 5067 | return to7_floppy_r ( space, offset ); |
| 5233 | 5068 | |
| 5234 | | logerror( "$%04x %f mo5nr_net_r: read from reg %i\n", space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), offset ); |
| 5069 | logerror( "$%04x %f mo5nr_net_r: read from reg %i\n", m_maincpu->pc(), machine().time().as_double(), offset ); |
| 5235 | 5070 | |
| 5236 | 5071 | return 0; |
| 5237 | 5072 | } |
| 5238 | 5073 | |
| 5239 | 5074 | |
| 5240 | 5075 | |
| 5241 | | WRITE8_HANDLER ( mo5nr_net_w ) |
| 5076 | WRITE8_MEMBER( thomson_state::mo5nr_net_w ) |
| 5242 | 5077 | { |
| 5243 | 5078 | if ( to7_controller_type ) |
| 5244 | 5079 | to7_floppy_w ( space, offset, data ); |
| 5245 | 5080 | else |
| 5246 | 5081 | logerror( "$%04x %f mo5nr_net_w: write $%02X to reg %i\n", |
| 5247 | | space.machine().device("maincpu")->safe_pcbase(), space.machine().time().as_double(), data, offset ); |
| 5082 | m_maincpu->pc(), machine().time().as_double(), data, offset ); |
| 5248 | 5083 | } |
| 5249 | 5084 | |
| 5250 | 5085 | |
| r21425 | r21426 | |
| 5255 | 5090 | */ |
| 5256 | 5091 | |
| 5257 | 5092 | |
| 5258 | | READ8_HANDLER( mo5nr_prn_r ) |
| 5093 | READ8_MEMBER( thomson_state::mo5nr_prn_r ) |
| 5259 | 5094 | { |
| 5260 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 5261 | 5095 | UINT8 result = 0; |
| 5262 | 5096 | |
| 5263 | | result |= !printer->busy_r() << 7; |
| 5097 | result |= !m_centronics->busy_r() << 7; |
| 5264 | 5098 | |
| 5265 | 5099 | return result; |
| 5266 | 5100 | } |
| 5267 | 5101 | |
| 5268 | 5102 | |
| 5269 | | WRITE8_HANDLER( mo5nr_prn_w ) |
| 5103 | WRITE8_MEMBER( thomson_state::mo5nr_prn_w ) |
| 5270 | 5104 | { |
| 5271 | | centronics_device *printer = space.machine().device<centronics_device>("centronics"); |
| 5272 | | |
| 5273 | 5105 | /* TODO: understand other bits */ |
| 5274 | | printer->strobe_w(BIT(data, 3)); |
| 5106 | m_centronics->strobe_w(BIT(data, 3)); |
| 5275 | 5107 | } |
| 5276 | 5108 | |
| 5277 | 5109 | |
| r21425 | r21426 | |
| 5280 | 5112 | |
| 5281 | 5113 | |
| 5282 | 5114 | |
| 5283 | | static READ8_DEVICE_HANDLER ( mo5nr_sys_portb_in ) |
| 5115 | READ8_MEMBER( thomson_state::mo5nr_sys_portb_in ) |
| 5284 | 5116 | { |
| 5285 | 5117 | /* keyboard: only 8 lines of 8 keys (MO6 has 9 lines) */ |
| 5286 | | UINT8 portb = downcast<pia6821_device *>(device)->b_output(); |
| 5118 | UINT8 portb = m_pia_sys->b_output(); |
| 5287 | 5119 | int col = (portb >> 4) & 7; /* B bits 4-6: kbd column */ |
| 5288 | 5120 | int lin = (portb >> 1) & 7; /* B bits 1-3: kbd line */ |
| 5289 | 5121 | static const char *const keynames[] = { |
| r21425 | r21426 | |
| 5291 | 5123 | "keyboard_4", "keyboard_5", "keyboard_6", "keyboard_7" |
| 5292 | 5124 | }; |
| 5293 | 5125 | |
| 5294 | | return ( space.machine().root_device().ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0; |
| 5126 | return ( ioport(keynames[lin])->read() & (1 << col) ) ? 0x80 : 0; |
| 5295 | 5127 | /* bit 7: key up */ |
| 5296 | 5128 | } |
| 5297 | 5129 | |
| 5298 | 5130 | |
| 5299 | 5131 | |
| 5300 | | static WRITE8_DEVICE_HANDLER ( mo5nr_sys_porta_out ) |
| 5132 | WRITE8_MEMBER( thomson_state::mo5nr_sys_porta_out ) |
| 5301 | 5133 | { |
| 5302 | 5134 | /* no keyboard LED */ |
| 5303 | | thom_set_mode_point( space.machine(), data & 1 ); /* bit 0: video bank switch */ |
| 5304 | | to7_game_mute = data & 4; /* bit 2: sound mute */ |
| 5305 | | mo5_set_cassette( space.machine(), (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */ |
| 5306 | | mo6_update_cart_bank(space.machine()); /* bit 5: rom bank */ |
| 5307 | | to7_game_sound_update(space.machine()); |
| 5135 | thom_set_mode_point( data & 1 ); /* bit 0: video bank switch */ |
| 5136 | m_to7_game_mute = data & 4; /* bit 2: sound mute */ |
| 5137 | mo5_set_cassette( (data & 0x40) ? 1 : 0 ); /* bit 6: cassette output */ |
| 5138 | mo6_update_cart_bank(); /* bit 5: rom bank */ |
| 5139 | to7_game_sound_update(); |
| 5308 | 5140 | } |
| 5309 | 5141 | |
| 5310 | 5142 | |
| 5311 | 5143 | |
| 5312 | 5144 | const pia6821_interface mo5nr_pia6821_sys = |
| 5313 | 5145 | { |
| 5314 | | DEVCB_HANDLER(mo6_sys_porta_in), |
| 5315 | | DEVCB_HANDLER(mo5nr_sys_portb_in), |
| 5146 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_porta_in), |
| 5147 | DEVCB_DRIVER_MEMBER(thomson_state, mo5nr_sys_portb_in), |
| 5316 | 5148 | DEVCB_NULL, |
| 5317 | 5149 | DEVCB_NULL, |
| 5318 | 5150 | DEVCB_NULL, |
| 5319 | 5151 | DEVCB_NULL, |
| 5320 | | DEVCB_HANDLER(mo5nr_sys_porta_out), |
| 5321 | | DEVCB_HANDLER(mo6_sys_portb_out), |
| 5322 | | DEVCB_HANDLER(mo5_set_cassette_motor), |
| 5323 | | DEVCB_HANDLER(mo6_sys_cb2_out), |
| 5324 | | DEVCB_LINE(thom_firq_1), |
| 5325 | | DEVCB_LINE(thom_irq_1) /* differs from TO */ |
| 5152 | DEVCB_DRIVER_MEMBER(thomson_state, mo5nr_sys_porta_out), |
| 5153 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_portb_out), |
| 5154 | DEVCB_DRIVER_MEMBER(thomson_state, mo5_set_cassette_motor), |
| 5155 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_sys_cb2_out), |
| 5156 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_firq_1), |
| 5157 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) /* differs from TO */ |
| 5326 | 5158 | }; |
| 5327 | 5159 | |
| 5328 | 5160 | |
| r21425 | r21426 | |
| 5336 | 5168 | |
| 5337 | 5169 | const pia6821_interface mo5nr_pia6821_game = |
| 5338 | 5170 | { |
| 5339 | | DEVCB_HANDLER(to7_game_porta_in), |
| 5340 | | DEVCB_HANDLER(to7_game_portb_in), |
| 5171 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_porta_in), |
| 5172 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_in), |
| 5341 | 5173 | DEVCB_NULL, |
| 5342 | 5174 | DEVCB_NULL, |
| 5343 | 5175 | DEVCB_NULL, |
| 5344 | 5176 | DEVCB_NULL, |
| 5345 | | DEVCB_HANDLER(mo6_game_porta_out), |
| 5346 | | DEVCB_HANDLER(to7_game_portb_out), |
| 5177 | DEVCB_DRIVER_MEMBER(thomson_state, mo6_game_porta_out), |
| 5178 | DEVCB_DRIVER_MEMBER(thomson_state, to7_game_portb_out), |
| 5347 | 5179 | DEVCB_NULL, |
| 5348 | 5180 | DEVCB_NULL, |
| 5349 | | DEVCB_LINE(thom_irq_1), |
| 5350 | | DEVCB_LINE(thom_irq_1) |
| 5181 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1), |
| 5182 | DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_irq_1) |
| 5351 | 5183 | }; |
| 5352 | 5184 | |
| 5353 | 5185 | |
| 5354 | 5186 | |
| 5355 | | static void mo5nr_game_init ( running_machine &machine ) |
| 5187 | void thomson_state::mo5nr_game_init() |
| 5356 | 5188 | { |
| 5357 | 5189 | LOG (( "mo5nr_game_init called\n" )); |
| 5358 | | to7_game_timer = machine.scheduler().timer_alloc(FUNC(mo6_game_update_cb)); |
| 5359 | | to7_game_timer->adjust( TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD ); |
| 5360 | | state_save_register_global( machine, to7_game_sound ); |
| 5361 | | state_save_register_global( machine, to7_game_mute ); |
| 5190 | m_to7_game_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo6_game_update_cb),this)); |
| 5191 | m_to7_game_timer->adjust( TO7_GAME_POLL_PERIOD, 0, TO7_GAME_POLL_PERIOD ); |
| 5192 | save_item(NAME(m_to7_game_sound)); |
| 5193 | save_item(NAME(m_to7_game_mute)); |
| 5362 | 5194 | } |
| 5363 | 5195 | |
| 5364 | 5196 | |
| 5365 | 5197 | |
| 5366 | | static void mo5nr_game_reset ( running_machine &machine ) |
| 5198 | void thomson_state::mo5nr_game_reset() |
| 5367 | 5199 | { |
| 5368 | | pia6821_device *game_pia = machine.device<pia6821_device>(THOM_PIA_GAME); |
| 5369 | 5200 | LOG (( "mo5nr_game_reset called\n" )); |
| 5370 | | game_pia->ca1_w( 0 ); |
| 5371 | | to7_game_sound = 0; |
| 5372 | | to7_game_mute = 0; |
| 5373 | | to7_game_sound_update(machine); |
| 5201 | m_pia_game->ca1_w( 0 ); |
| 5202 | m_to7_game_sound = 0; |
| 5203 | m_to7_game_mute = 0; |
| 5204 | to7_game_sound_update(); |
| 5374 | 5205 | } |
| 5375 | 5206 | |
| 5376 | 5207 | |
| r21425 | r21426 | |
| 5379 | 5210 | |
| 5380 | 5211 | |
| 5381 | 5212 | |
| 5382 | | MACHINE_RESET ( mo5nr ) |
| 5213 | MACHINE_RESET_MEMBER( thomson_state, mo5nr ) |
| 5383 | 5214 | { |
| 5384 | | pia6821_device *sys_pia = machine.device<pia6821_device>(THOM_PIA_SYS ); |
| 5385 | 5215 | LOG (( "mo5nr: machine reset called\n" )); |
| 5386 | 5216 | |
| 5387 | 5217 | /* subsystems */ |
| 5388 | | thom_irq_reset(machine); |
| 5389 | | sys_pia->set_port_a_z_mask( 0x65 ); |
| 5390 | | mo5nr_game_reset(machine); |
| 5391 | | to7_floppy_reset(machine); |
| 5392 | | to7_modem_reset(machine); |
| 5393 | | to7_midi_reset(machine); |
| 5394 | | mo5_init_timer(machine); |
| 5218 | thom_irq_reset(); |
| 5219 | m_pia_sys->set_port_a_z_mask( 0x65 ); |
| 5220 | mo5nr_game_reset(); |
| 5221 | to7_floppy_reset(); |
| 5222 | to7_modem_reset(); |
| 5223 | to7_midi_reset(); |
| 5224 | mo5_init_timer(); |
| 5395 | 5225 | |
| 5396 | 5226 | /* gate-array */ |
| 5397 | | to7_lightpen = 0; |
| 5398 | | to8_reg_ram = 0; |
| 5399 | | to8_reg_cart = 0; |
| 5400 | | to8_reg_sys1 = 0; |
| 5401 | | to8_reg_sys2 = 0; |
| 5402 | | to8_lightpen_intr = 0; |
| 5227 | m_to7_lightpen = 0; |
| 5228 | m_to8_reg_ram = 0; |
| 5229 | m_to8_reg_cart = 0; |
| 5230 | m_to8_reg_sys1 = 0; |
| 5231 | m_to8_reg_sys2 = 0; |
| 5232 | m_to8_lightpen_intr = 0; |
| 5403 | 5233 | |
| 5404 | 5234 | /* video */ |
| 5405 | | thom_set_video_mode( machine, THOM_VMODE_MO5 ); |
| 5406 | | thom_set_lightpen_callback( machine, 3, to8_lightpen_cb ); |
| 5407 | | thom_set_border_color( machine, 0 ); |
| 5408 | | thom_set_mode_point( machine, 0 ); |
| 5409 | | sys_pia->ca1_w( 0 ); |
| 5235 | thom_set_video_mode( THOM_VMODE_MO5 ); |
| 5236 | m_thom_lightpen_cb = &thomson_state::to8_lightpen_cb; |
| 5237 | thom_set_lightpen_callback( 3 ); |
| 5238 | thom_set_border_color( 0 ); |
| 5239 | thom_set_mode_point( 0 ); |
| 5240 | m_pia_sys->ca1_w( 0 ); |
| 5410 | 5241 | |
| 5411 | 5242 | /* memory */ |
| 5412 | | old_ram_bank = -1; |
| 5413 | | old_cart_bank = -1; |
| 5414 | | to8_cart_vpage = 0; |
| 5415 | | to8_data_vpage = 0; |
| 5416 | | mo6_update_ram_bank(machine); |
| 5417 | | mo6_update_cart_bank(machine); |
| 5243 | m_old_ram_bank = -1; |
| 5244 | m_old_cart_bank = -1; |
| 5245 | m_to8_cart_vpage = 0; |
| 5246 | m_to8_data_vpage = 0; |
| 5247 | mo6_update_ram_bank(); |
| 5248 | mo6_update_cart_bank(); |
| 5418 | 5249 | /* mo5_reg_cart not reset */ |
| 5419 | 5250 | /* thom_cart_bank not reset */ |
| 5420 | 5251 | } |
| 5421 | 5252 | |
| 5422 | 5253 | |
| 5423 | 5254 | |
| 5424 | | MACHINE_START ( mo5nr ) |
| 5255 | MACHINE_START_MEMBER( thomson_state, mo5nr ) |
| 5425 | 5256 | { |
| 5426 | | UINT8* mem = machine.root_device().memregion("maincpu")->base(); |
| 5427 | | UINT8* ram = machine.device<ram_device>(RAM_TAG)->pointer(); |
| 5257 | UINT8* mem = memregion("maincpu")->base(); |
| 5258 | UINT8* ram = m_ram->pointer(); |
| 5428 | 5259 | |
| 5429 | 5260 | LOG (( "mo5nr: machine start called\n" )); |
| 5430 | 5261 | |
| 5431 | 5262 | /* subsystems */ |
| 5432 | | thom_irq_init(machine); |
| 5433 | | mo5nr_game_init(machine); |
| 5434 | | to7_floppy_init( machine, mem + 0x30000 ); |
| 5435 | | to9_palette_init(machine); |
| 5436 | | to7_modem_init(machine); |
| 5437 | | to7_midi_init(machine); |
| 5438 | | mo5_periodic_timer = machine.scheduler().timer_alloc(FUNC(mo5_periodic_cb)); |
| 5263 | thom_irq_init(); |
| 5264 | mo5nr_game_init(); |
| 5265 | to7_floppy_init( mem + 0x30000 ); |
| 5266 | to9_palette_init(); |
| 5267 | to7_modem_init(); |
| 5268 | to7_midi_init(); |
| 5269 | m_mo5_periodic_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(thomson_state::mo5_periodic_cb),this)); |
| 5439 | 5270 | |
| 5440 | 5271 | /* memory */ |
| 5441 | | thom_cart_bank = 0; |
| 5442 | | mo5_reg_cart = 0; |
| 5443 | | thom_vram = ram; |
| 5444 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 5445 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 ); |
| 5446 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 ); |
| 5447 | | machine.root_device().membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 ); |
| 5448 | | machine.root_device().membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 5449 | | machine.root_device().membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 5450 | | machine.root_device().membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 5451 | | machine.root_device().membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 ); |
| 5452 | | machine.root_device().membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 ); |
| 5453 | | machine.root_device().membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 ); |
| 5454 | | machine.root_device().membank( THOM_CART_BANK )->set_entry( 0 ); |
| 5455 | | machine.root_device().membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 5456 | | machine.root_device().membank( TO8_SYS_LO )->set_entry( 0 ); |
| 5457 | | machine.root_device().membank( TO8_SYS_HI )->set_entry( 0 ); |
| 5458 | | machine.root_device().membank( TO8_DATA_LO )->set_entry( 0 ); |
| 5459 | | machine.root_device().membank( TO8_DATA_HI )->set_entry( 0 ); |
| 5460 | | machine.root_device().membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 5272 | m_thom_cart_bank = 0; |
| 5273 | m_mo5_reg_cart = 0; |
| 5274 | m_thom_vram = ram; |
| 5275 | membank( THOM_CART_BANK )->configure_entries( 0, 4, mem + 0x10000, 0x4000 ); |
| 5276 | membank( THOM_CART_BANK )->configure_entries( 4, 2, mem + 0x1f000, 0x4000 ); |
| 5277 | membank( THOM_CART_BANK )->configure_entries( 6, 2, mem + 0x28000, 0x4000 ); |
| 5278 | membank( THOM_CART_BANK )->configure_entries( 8, 8, ram, 0x4000 ); |
| 5279 | membank( THOM_VRAM_BANK )->configure_entries( 0, 2, ram, 0x2000 ); |
| 5280 | membank( TO8_SYS_LO )->configure_entry( 0, ram + 0x6000); |
| 5281 | membank( TO8_SYS_HI )->configure_entry( 0, ram + 0x4000); |
| 5282 | membank( TO8_DATA_LO )->configure_entries( 0, 8, ram + 0x2000, 0x4000 ); |
| 5283 | membank( TO8_DATA_HI )->configure_entries( 0, 8, ram + 0x0000, 0x4000 ); |
| 5284 | membank( TO8_BIOS_BANK )->configure_entries( 0, 2, mem + 0x23000, 0x4000 ); |
| 5285 | membank( THOM_CART_BANK )->set_entry( 0 ); |
| 5286 | membank( THOM_VRAM_BANK )->set_entry( 0 ); |
| 5287 | membank( TO8_SYS_LO )->set_entry( 0 ); |
| 5288 | membank( TO8_SYS_HI )->set_entry( 0 ); |
| 5289 | membank( TO8_DATA_LO )->set_entry( 0 ); |
| 5290 | membank( TO8_DATA_HI )->set_entry( 0 ); |
| 5291 | membank( TO8_BIOS_BANK )->set_entry( 0 ); |
| 5461 | 5292 | |
| 5462 | 5293 | /* save-state */ |
| 5463 | | state_save_register_global( machine, thom_cart_nb_banks ); |
| 5464 | | state_save_register_global( machine, thom_cart_bank ); |
| 5465 | | state_save_register_global( machine, to7_lightpen ); |
| 5466 | | state_save_register_global( machine, to7_lightpen_step ); |
| 5467 | | state_save_register_global( machine, to8_reg_ram ); |
| 5468 | | state_save_register_global( machine, to8_reg_cart ); |
| 5469 | | state_save_register_global( machine, to8_reg_sys1 ); |
| 5470 | | state_save_register_global( machine, to8_reg_sys2 ); |
| 5471 | | state_save_register_global( machine, to8_lightpen_intr ); |
| 5472 | | state_save_register_global( machine, to8_data_vpage ); |
| 5473 | | state_save_register_global( machine, to8_cart_vpage ); |
| 5474 | | state_save_register_global( machine, mo5_reg_cart ); |
| 5475 | | state_save_register_global_pointer( machine, (mem + 0x10000), 0x10000 ); |
| 5476 | | machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_ram_bank_postload), &machine)); |
| 5477 | | machine.save().register_postload(save_prepost_delegate(FUNC(mo6_update_cart_bank_postload), &machine)); |
| 5294 | save_item(NAME(m_thom_cart_nb_banks)); |
| 5295 | save_item(NAME(m_thom_cart_bank)); |
| 5296 | save_item(NAME(m_to7_lightpen)); |
| 5297 | save_item(NAME(m_to7_lightpen_step)); |
| 5298 | save_item(NAME(m_to8_reg_ram)); |
| 5299 | save_item(NAME(m_to8_reg_cart)); |
| 5300 | save_item(NAME(m_to8_reg_sys1)); |
| 5301 | save_item(NAME(m_to8_reg_sys2)); |
| 5302 | save_item(NAME(m_to8_lightpen_intr)); |
| 5303 | save_item(NAME(m_to8_data_vpage)); |
| 5304 | save_item(NAME(m_to8_cart_vpage)); |
| 5305 | save_item(NAME(m_mo5_reg_cart)); |
| 5306 | state_save_register_global_pointer( machine(), (mem + 0x10000), 0x10000 ); |
| 5307 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_ram_bank_postload), this)); |
| 5308 | machine().save().register_postload(save_prepost_delegate(FUNC(thomson_state::mo6_update_cart_bank_postload), this)); |
| 5478 | 5309 | } |