src/mess/machine/c65.c
| r4829 | r4830 | |
| 20 | 20 | #include "includes/c64.h" |
| 21 | 21 | |
| 22 | 22 | #define VERBOSE_LEVEL 0 |
| 23 | | #define DBG_LOG(N,M,A) \ |
| 23 | #define DBG_LOG( MACHINE, N, M, A ) \ |
| 24 | 24 | do { \ |
| 25 | 25 | if(VERBOSE_LEVEL >= N) \ |
| 26 | 26 | { \ |
| 27 | 27 | if( M ) \ |
| 28 | | logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \ |
| 28 | logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(MACHINE)), (char*) M ); \ |
| 29 | 29 | logerror A; \ |
| 30 | 30 | } \ |
| 31 | 31 | } while (0) |
| r4829 | r4830 | |
| 112 | 112 | |
| 113 | 113 | if (level != old_level) |
| 114 | 114 | { |
| 115 | | DBG_LOG (3, "mos6510", ("irq %s\n", level ? "start" : "end")); |
| 115 | DBG_LOG(machine, 3, "mos6510", ("irq %s\n", level ? "start" : "end")); |
| 116 | 116 | cputag_set_input_line(machine, "maincpu", M6510_IRQ_LINE, level); |
| 117 | 117 | old_level = level; |
| 118 | 118 | } |
| r4829 | r4830 | |
| 297 | 297 | */ |
| 298 | 298 | static void c65_dma_port_w(running_machine *machine, int offset, int value) |
| 299 | 299 | { |
| 300 | | static int dump=0; |
| 300 | static int dump = 0; |
| 301 | 301 | PAIR pair, src, dst, len; |
| 302 | 302 | UINT8 cmd, fill; |
| 303 | 303 | int i; |
| 304 | 304 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 305 | 305 | |
| 306 | | switch (offset&3) { |
| 306 | switch (offset & 3) |
| 307 | { |
| 307 | 308 | case 2: |
| 308 | 309 | case 1: |
| 309 | | dma.data[offset&3]=value; |
| 310 | dma.data[offset & 3] = value; |
| 310 | 311 | break; |
| 311 | 312 | case 0: |
| 312 | | pair.b.h3=0; |
| 313 | | pair.b.h2=dma.data[2]; |
| 314 | | pair.b.h=dma.data[1]; |
| 315 | | pair.b.l=dma.data[0]=value; |
| 316 | | cmd=c65_read_mem(space, pair.d++); |
| 317 | | len.w.h=0; |
| 318 | | len.b.l=c65_read_mem(space, pair.d++); |
| 319 | | len.b.h=c65_read_mem(space, pair.d++); |
| 320 | | src.b.h3=0; |
| 321 | | fill=src.b.l=c65_read_mem(space, pair.d++); |
| 322 | | src.b.h=c65_read_mem(space, pair.d++); |
| 323 | | src.b.h2=c65_read_mem(space, pair.d++); |
| 324 | | dst.b.h3=0; |
| 325 | | dst.b.l=c65_read_mem(space, pair.d++); |
| 326 | | dst.b.h=c65_read_mem(space, pair.d++); |
| 327 | | dst.b.h2=c65_read_mem(space, pair.d++); |
| 313 | pair.b.h3 = 0; |
| 314 | pair.b.h2 = dma.data[2]; |
| 315 | pair.b.h = dma.data[1]; |
| 316 | pair.b.l = dma.data[0]=value; |
| 317 | cmd = c65_read_mem(space, pair.d++); |
| 318 | len.w.h = 0; |
| 319 | len.b.l = c65_read_mem(space, pair.d++); |
| 320 | len.b.h = c65_read_mem(space, pair.d++); |
| 321 | src.b.h3 = 0; |
| 322 | fill = src.b.l = c65_read_mem(space, pair.d++); |
| 323 | src.b.h = c65_read_mem(space, pair.d++); |
| 324 | src.b.h2 = c65_read_mem(space, pair.d++); |
| 325 | dst.b.h3 = 0; |
| 326 | dst.b.l = c65_read_mem(space, pair.d++); |
| 327 | dst.b.h = c65_read_mem(space, pair.d++); |
| 328 | dst.b.h2 = c65_read_mem(space, pair.d++); |
| 328 | 329 | |
| 329 | | switch (cmd) { |
| 330 | switch (cmd) |
| 331 | { |
| 330 | 332 | case 0: |
| 331 | | if (src.d==0x3ffff) dump=1; |
| 333 | if (src.d == 0x3ffff) dump = 1; |
| 332 | 334 | if (dump) |
| 333 | | DBG_LOG(1,"dma copy job", |
| 335 | DBG_LOG(space->machine, 1,"dma copy job", |
| 334 | 336 | ("len:%.4x src:%.6x dst:%.6x sub:%.2x modrm:%.2x\n", |
| 335 | 337 | len.w.l, src.d, dst.d, c65_read_mem(space, pair.d), |
| 336 | | c65_read_mem(space, pair.d+1) ) ); |
| 337 | | if ( (dma.version==1) |
| 338 | | &&( (src.d&0x400000)||(dst.d&0x400000)) ) { |
| 339 | | if ( !(src.d&0x400000) ) { |
| 340 | | dst.d&=~0x400000; |
| 341 | | for (i=0; i<len.w.l; i++) |
| 342 | | c65_write_mem(space, dst.d--,c65_read_mem(space, src.d++)); |
| 343 | | } else if ( !(dst.d&0x400000) ) { |
| 344 | | src.d&=~0x400000; |
| 345 | | for (i=0; i<len.w.l; i++) |
| 346 | | c65_write_mem(space, dst.d++,c65_read_mem(space, src.d--)); |
| 347 | | } else { |
| 348 | | src.d&=~0x400000; |
| 349 | | dst.d&=~0x400000; |
| 350 | | for (i=0; i<len.w.l; i++) |
| 351 | | c65_write_mem(space, --dst.d,c65_read_mem(space, --src.d)); |
| 338 | c65_read_mem(space, pair.d + 1) ) ); |
| 339 | if ((dma.version == 1) |
| 340 | && ( (src.d&0x400000) || (dst.d & 0x400000))) |
| 341 | { |
| 342 | if (!(src.d & 0x400000)) |
| 343 | { |
| 344 | dst.d &= ~0x400000; |
| 345 | for (i = 0; i < len.w.l; i++) |
| 346 | c65_write_mem(space, dst.d--, c65_read_mem(space, src.d++)); |
| 352 | 347 | } |
| 353 | | } else { |
| 354 | | for (i=0; i<len.w.l; i++) |
| 355 | | c65_write_mem(space, dst.d++,c65_read_mem(space, src.d++)); |
| 348 | else if (!(dst.d & 0x400000)) |
| 349 | { |
| 350 | src.d &= ~0x400000; |
| 351 | for (i = 0; i < len.w.l; i++) |
| 352 | c65_write_mem(space, dst.d++, c65_read_mem(space, src.d--)); |
| 353 | } |
| 354 | else |
| 355 | { |
| 356 | src.d &= ~0x400000; |
| 357 | dst.d &= ~0x400000; |
| 358 | for (i = 0; i < len.w.l; i++) |
| 359 | c65_write_mem(space, --dst.d, c65_read_mem(space, --src.d)); |
| 360 | } |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | for (i = 0; i < len.w.l; i++) |
| 365 | c65_write_mem(space, dst.d++, c65_read_mem(space, src.d++)); |
| 356 | 366 | } |
| 357 | 367 | break; |
| 358 | 368 | case 3: |
| 359 | | DBG_LOG(3,"dma fill job", |
| 369 | DBG_LOG(space->machine, 3,"dma fill job", |
| 360 | 370 | ("len:%.4x value:%.2x dst:%.6x sub:%.2x modrm:%.2x\n", |
| 361 | 371 | len.w.l, fill, dst.d, c65_read_mem(space, pair.d), |
| 362 | | c65_read_mem(space, pair.d+1))); |
| 363 | | for (i=0; i<len.w.l; i++) |
| 364 | | c65_write_mem(space, dst.d++,fill); |
| 372 | c65_read_mem(space, pair.d + 1))); |
| 373 | for (i = 0; i < len.w.l; i++) |
| 374 | c65_write_mem(space, dst.d++, fill); |
| 365 | 375 | break; |
| 366 | 376 | case 0x30: |
| 367 | | DBG_LOG(1,"dma copy down", |
| 377 | DBG_LOG(space->machine, 1,"dma copy down", |
| 368 | 378 | ("len:%.4x src:%.6x dst:%.6x sub:%.2x modrm:%.2x\n", |
| 369 | 379 | len.w.l, src.d, dst.d, c65_read_mem(space, pair.d), |
| 370 | | c65_read_mem(space, pair.d+1) ) ); |
| 371 | | for (i=0; i<len.w.l; i++) |
| 380 | c65_read_mem(space, pair.d + 1) ) ); |
| 381 | for (i = 0; i < len.w.l; i++) |
| 372 | 382 | c65_write_mem(space, dst.d--,c65_read_mem(space, src.d--)); |
| 373 | 383 | break; |
| 374 | 384 | default: |
| 375 | | DBG_LOG(1,"dma job", |
| 385 | DBG_LOG(space->machine, 1,"dma job", |
| 376 | 386 | ("cmd:%.2x len:%.4x src:%.6x dst:%.6x sub:%.2x modrm:%.2x\n", |
| 377 | 387 | cmd,len.w.l, src.d, dst.d, c65_read_mem(space, pair.d), |
| 378 | | c65_read_mem(space, pair.d+1))); |
| 388 | c65_read_mem(space, pair.d + 1))); |
| 379 | 389 | } |
| 380 | 390 | break; |
| 381 | 391 | default: |
| 382 | | DBG_LOG (1, "dma chip write", ("%.3x %.2x\n", offset,value)); |
| 392 | DBG_LOG(space->machine, 1, "dma chip write", ("%.3x %.2x\n", offset, value)); |
| 383 | 393 | break; |
| 384 | 394 | } |
| 385 | 395 | } |
| r4829 | r4830 | |
| 387 | 397 | static int c65_dma_port_r(running_machine *machine, int offset) |
| 388 | 398 | { |
| 389 | 399 | /* offset 3 bit 7 in progress ? */ |
| 390 | | DBG_LOG (2, "dma chip read", ("%.3x\n", offset)); |
| 400 | DBG_LOG(machine, 2, "dma chip read", ("%.3x\n", offset)); |
| 391 | 401 | return 0x7f; |
| 392 | 402 | } |
| 393 | 403 | |
| 394 | 404 | static void c65_6511_port_w(running_machine *machine, int offset, int value) |
| 395 | 405 | { |
| 396 | | if (offset==7) |
| 406 | if (offset == 7) |
| 397 | 407 | { |
| 398 | | c65_6511_port=value; |
| 408 | c65_6511_port = value; |
| 399 | 409 | } |
| 400 | | DBG_LOG (2, "r6511 write", ("%.2x %.2x\n", offset, value)); |
| 410 | DBG_LOG(machine, 2, "r6511 write", ("%.2x %.2x\n", offset, value)); |
| 401 | 411 | } |
| 402 | 412 | |
| 403 | 413 | static int c65_6511_port_r(running_machine *machine, int offset) |
| 404 | 414 | { |
| 405 | | int data=0xff; |
| 415 | int data = 0xff; |
| 406 | 416 | |
| 407 | | if (offset==7) |
| 417 | if (offset == 7) |
| 408 | 418 | { |
| 409 | 419 | if (input_port_read(machine, "SPECIAL") & 0x20) |
| 410 | 420 | data &= ~1; |
| 411 | 421 | } |
| 412 | | DBG_LOG (2, "r6511 read", ("%.2x\n", offset)); |
| 422 | DBG_LOG(machine, 2, "r6511 read", ("%.2x\n", offset)); |
| 413 | 423 | |
| 414 | 424 | return data; |
| 415 | 425 | } |
| r4829 | r4830 | |
| 514 | 524 | |
| 515 | 525 | attotime time; |
| 516 | 526 | int head,track,sector; |
| 517 | | } c65_fdc= { 0 }; |
| 527 | } c65_fdc = { 0 }; |
| 518 | 528 | |
| 519 | 529 | #define FDC_LOST 4 |
| 520 | 530 | #define FDC_CRC 8 |
| r4829 | r4830 | |
| 527 | 537 | #if 0 |
| 528 | 538 | static void c65_fdc_state(void) |
| 529 | 539 | { |
| 530 | | switch (c65_fdc.state) { |
| 540 | switch (c65_fdc.state) |
| 541 | { |
| 531 | 542 | case FDC_CMD_MOTOR_SPIN_UP: |
| 532 | | if (timer_get_time(machine)-c65_fdc.time) { |
| 533 | | c65_fdc.state=0; |
| 534 | | c65_fdc.status&=~FDC_BUSY; |
| 543 | if (timer_get_time(machine) - c65_fdc.time) |
| 544 | { |
| 545 | c65_fdc.state = 0; |
| 546 | c65_fdc.status &= ~FDC_BUSY; |
| 535 | 547 | } |
| 536 | 548 | break; |
| 537 | 549 | } |
| 538 | 550 | } |
| 539 | 551 | #endif |
| 540 | 552 | |
| 541 | | static void c65_fdc_w(running_machine *machine, int offset, int data) |
| 553 | static void c65_fdc_w( running_machine *machine, int offset, int data ) |
| 542 | 554 | { |
| 543 | | DBG_LOG (1, "fdc write", ("%.5x %.2x %.2x\n", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), offset, data)); |
| 544 | | switch (offset&0xf) { |
| 555 | DBG_LOG(machine, 1, "fdc write", ("%.5x %.2x %.2x\n", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), offset, data)); |
| 556 | switch (offset & 0xf) |
| 557 | { |
| 545 | 558 | case 0: |
| 546 | | c65_fdc.reg[0]=data; |
| 559 | c65_fdc.reg[0] = data; |
| 547 | 560 | break; |
| 548 | 561 | case 1: |
| 549 | | c65_fdc.reg[1]=data; |
| 550 | | switch (data&0xf9) { |
| 562 | c65_fdc.reg[1] = data; |
| 563 | switch (data & 0xf9) |
| 564 | { |
| 551 | 565 | case 0x20: // wait for motor spin up |
| 552 | | c65_fdc.status&=~(FDC_IRQ|FDC_LOST|FDC_CRC|FDC_RNF); |
| 553 | | c65_fdc.status|=FDC_BUSY; |
| 554 | | c65_fdc.time=timer_get_time(machine); |
| 555 | | c65_fdc.state=FDC_CMD_MOTOR_SPIN_UP; |
| 566 | c65_fdc.status &= ~(FDC_IRQ|FDC_LOST|FDC_CRC|FDC_RNF); |
| 567 | c65_fdc.status |= FDC_BUSY; |
| 568 | c65_fdc.time = timer_get_time(machine); |
| 569 | c65_fdc.state = FDC_CMD_MOTOR_SPIN_UP; |
| 556 | 570 | break; |
| 557 | 571 | case 0: // cancel |
| 558 | | c65_fdc.status&=~(FDC_BUSY); |
| 559 | | c65_fdc.state=0; |
| 572 | c65_fdc.status &= ~(FDC_BUSY); |
| 573 | c65_fdc.state = 0; |
| 560 | 574 | break; |
| 561 | 575 | case 0x80: // buffered write |
| 562 | 576 | case 0x40: // buffered read |
| r4829 | r4830 | |
| 569 | 583 | case 2: case 3: // read only |
| 570 | 584 | break; |
| 571 | 585 | case 4: |
| 572 | | c65_fdc.reg[offset&0xf]=data; |
| 573 | | c65_fdc.track=data; |
| 586 | c65_fdc.reg[offset & 0xf] = data; |
| 587 | c65_fdc.track = data; |
| 574 | 588 | break; |
| 575 | 589 | case 5: |
| 576 | | c65_fdc.reg[offset&0xf]=data; |
| 577 | | c65_fdc.sector=data; |
| 590 | c65_fdc.reg[offset & 0xf] = data; |
| 591 | c65_fdc.sector = data; |
| 578 | 592 | break; |
| 579 | 593 | case 6: |
| 580 | | c65_fdc.reg[offset&0xf]=data; |
| 581 | | c65_fdc.head=data; |
| 594 | c65_fdc.reg[offset & 0xf] = data; |
| 595 | c65_fdc.head = data; |
| 582 | 596 | break; |
| 583 | 597 | case 7: |
| 584 | | c65_fdc.buffer[c65_fdc.cpu_pos++]=data; |
| 598 | c65_fdc.buffer[c65_fdc.cpu_pos++] = data; |
| 585 | 599 | break; |
| 586 | 600 | default: |
| 587 | | c65_fdc.reg[offset&0xf]=data; |
| 601 | c65_fdc.reg[offset & 0xf] = data; |
| 588 | 602 | break; |
| 589 | 603 | } |
| 590 | 604 | } |
| 591 | 605 | |
| 592 | | static int c65_fdc_r(running_machine *machine, int offset) |
| 606 | static int c65_fdc_r( running_machine *machine, int offset ) |
| 593 | 607 | { |
| 594 | | UINT8 data=0; |
| 595 | | switch (offset&0xf) { |
| 608 | UINT8 data = 0; |
| 609 | switch (offset & 0xf) |
| 610 | { |
| 596 | 611 | case 0: |
| 597 | | data=c65_fdc.reg[0]; |
| 612 | data = c65_fdc.reg[0]; |
| 598 | 613 | break; |
| 599 | 614 | case 1: |
| 600 | | data=c65_fdc.reg[1]; |
| 615 | data = c65_fdc.reg[1]; |
| 601 | 616 | break; |
| 602 | 617 | case 2: |
| 603 | | data=c65_fdc.status; |
| 618 | data = c65_fdc.status; |
| 604 | 619 | break; |
| 605 | 620 | case 3: |
| 606 | | data=c65_fdc.status>>8; |
| 621 | data = c65_fdc.status >> 8; |
| 607 | 622 | break; |
| 608 | 623 | case 4: |
| 609 | | data=c65_fdc.track; |
| 624 | data = c65_fdc.track; |
| 610 | 625 | break; |
| 611 | 626 | case 5: |
| 612 | | data=c65_fdc.sector; |
| 627 | data = c65_fdc.sector; |
| 613 | 628 | break; |
| 614 | 629 | case 6: |
| 615 | | data=c65_fdc.head; |
| 630 | data = c65_fdc.head; |
| 616 | 631 | break; |
| 617 | 632 | case 7: |
| 618 | | data=c65_fdc.buffer[c65_fdc.cpu_pos++]; |
| 633 | data = c65_fdc.buffer[c65_fdc.cpu_pos++]; |
| 619 | 634 | break; |
| 620 | 635 | default: |
| 621 | | data=c65_fdc.reg[offset&0xf]; |
| 636 | data = c65_fdc.reg[offset & 0xf]; |
| 622 | 637 | break; |
| 623 | 638 | } |
| 624 | | DBG_LOG (1, "fdc read", ("%.5x %.2x %.2x\n", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), offset, data)); |
| 639 | DBG_LOG(machine, 1, "fdc read", ("%.5x %.2x %.2x\n", cpu_get_pc(cputag_get_cpu(machine, "maincpu")), offset, data)); |
| 625 | 640 | return data; |
| 626 | 641 | } |
| 627 | 642 | |
| r4829 | r4830 | |
| 676 | 691 | |
| 677 | 692 | static WRITE8_HANDLER ( c65_write_io ) |
| 678 | 693 | { |
| 679 | | running_machine *machine = space->machine; |
| 680 | 694 | const device_config *sid_0 = devtag_get_device(space->machine, "sid_r"); |
| 681 | 695 | const device_config *sid_1 = devtag_get_device(space->machine, "sid_l"); |
| 682 | 696 | |
| r4829 | r4830 | |
| 700 | 714 | else if (offset<0x440) |
| 701 | 715 | sid6581_w(sid_1, offset & 0x3f, data); |
| 702 | 716 | else |
| 703 | | DBG_LOG (1, "io write", ("%.3x %.2x\n", offset, data)); |
| 717 | DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data)); |
| 704 | 718 | break; |
| 705 | 719 | case 0x500: |
| 706 | | DBG_LOG (1, "io write", ("%.3x %.2x\n", offset, data)); |
| 720 | DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data)); |
| 707 | 721 | break; |
| 708 | 722 | case 0x600: |
| 709 | 723 | c65_6511_port_w(space->machine, offset&0xff,data); |
| r4829 | r4830 | |
| 716 | 730 | |
| 717 | 731 | static WRITE8_HANDLER ( c65_write_io_dc00 ) |
| 718 | 732 | { |
| 719 | | running_machine *machine = space->machine; |
| 720 | 733 | const device_config *cia_0 = devtag_get_device(space->machine, "cia_0"); |
| 721 | 734 | const device_config *cia_1 = devtag_get_device(space->machine, "cia_1"); |
| 722 | 735 | |
| 723 | | switch(offset&0xf00) { |
| 736 | switch(offset & 0xf00) |
| 737 | { |
| 724 | 738 | case 0x000: |
| 725 | 739 | cia_w(cia_0, offset, data); |
| 726 | 740 | break; |
| r4829 | r4830 | |
| 729 | 743 | break; |
| 730 | 744 | case 0x200: |
| 731 | 745 | case 0x300: |
| 732 | | DBG_LOG (1, "io write", ("%.3x %.2x\n", offset+0xc00, data)); |
| 746 | DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset+0xc00, data)); |
| 733 | 747 | break; |
| 734 | 748 | } |
| 735 | 749 | } |
| 736 | 750 | |
| 737 | 751 | static READ8_HANDLER ( c65_read_io ) |
| 738 | 752 | { |
| 739 | | running_machine *machine = space->machine; |
| 740 | 753 | const device_config *sid_0 = devtag_get_device(space->machine, "sid_r"); |
| 741 | 754 | const device_config *sid_1 = devtag_get_device(space->machine, "sid_l"); |
| 742 | 755 | |
| 743 | | switch(offset&0xf00) { |
| 756 | switch(offset & 0xf00) |
| 757 | { |
| 744 | 758 | case 0x000: |
| 745 | 759 | if (offset < 0x80) |
| 746 | 760 | return vic3_port_r (space, offset & 0x7f); |
| 747 | | if (offset < 0xa0) { |
| 761 | if (offset < 0xa0) |
| 762 | { |
| 748 | 763 | return c65_fdc_r(space->machine, offset&0x1f); |
| 749 | | } else { |
| 764 | } |
| 765 | else |
| 766 | { |
| 750 | 767 | return c65_ram_expansion_r(space, offset&0x1f); |
| 751 | 768 | /*return; ram expansion crtl optional */ |
| 752 | 769 | } |
| 753 | 770 | break; |
| 754 | | case 0x100:case 0x200: case 0x300: |
| 771 | case 0x100: |
| 772 | case 0x200: |
| 773 | case 0x300: |
| 755 | 774 | /* read only !? */ |
| 756 | | DBG_LOG (1, "io read", ("%.3x\n", offset)); |
| 775 | DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset)); |
| 757 | 776 | break; |
| 758 | 777 | case 0x400: |
| 759 | | if (offset<0x420) |
| 778 | if (offset < 0x420) |
| 760 | 779 | return sid6581_r(sid_0, offset & 0x3f); |
| 761 | | if (offset<0x440) |
| 780 | if (offset < 0x440) |
| 762 | 781 | return sid6581_r(sid_1, offset & 0x3f); |
| 763 | | DBG_LOG (1, "io read", ("%.3x\n", offset)); |
| 782 | DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset)); |
| 764 | 783 | break; |
| 765 | 784 | case 0x500: |
| 766 | | DBG_LOG (1, "io read", ("%.3x\n", offset)); |
| 785 | DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset)); |
| 767 | 786 | break; |
| 768 | 787 | case 0x600: |
| 769 | 788 | return c65_6511_port_r(space->machine, offset&0xff); |
| r4829 | r4830 | |
| 775 | 794 | |
| 776 | 795 | static READ8_HANDLER ( c65_read_io_dc00 ) |
| 777 | 796 | { |
| 778 | | running_machine *machine = space->machine; |
| 779 | 797 | const device_config *cia_0 = devtag_get_device(space->machine, "cia_0"); |
| 780 | 798 | const device_config *cia_1 = devtag_get_device(space->machine, "cia_1"); |
| 781 | 799 | |
| 782 | | switch(offset&0x300) { |
| 800 | switch(offset & 0x300) |
| 801 | { |
| 783 | 802 | case 0x000: |
| 784 | 803 | return cia_r(cia_0, offset); |
| 785 | 804 | case 0x100: |
| 786 | 805 | return cia_r(cia_1, offset); |
| 787 | 806 | case 0x200: |
| 788 | 807 | case 0x300: |
| 789 | | DBG_LOG (1, "io read", ("%.3x\n", offset+0xc00)); |
| 808 | DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset+0xc00)); |
| 790 | 809 | break; |
| 791 | 810 | } |
| 792 | 811 | return 0xff; |
| r4829 | r4830 | |
| 805 | 824 | bit 6 vic3 c65 character set */ |
| 806 | 825 | static void c65_bankswitch_interface(running_machine *machine, int value) |
| 807 | 826 | { |
| 808 | | static int old=0; |
| 827 | static int old = 0; |
| 809 | 828 | read8_space_func rh; |
| 810 | 829 | write8_space_func wh; |
| 811 | 830 | |
| 812 | | DBG_LOG (2, "c65 bankswitch", ("%.2x\n",value)); |
| 831 | DBG_LOG(machine, 2, "c65 bankswitch", ("%.2x\n",value)); |
| 813 | 832 | |
| 814 | 833 | if (c65_io_on) |
| 815 | 834 | { |
| 816 | | if (value&1) |
| 835 | if (value & 1) |
| 817 | 836 | { |
| 818 | | memory_set_bankptr (machine, 8, c64_colorram + 0x400); |
| 819 | | memory_set_bankptr (machine, 9, c64_colorram + 0x400); |
| 837 | memory_set_bankptr(machine, 8, c64_colorram + 0x400); |
| 838 | memory_set_bankptr(machine, 9, c64_colorram + 0x400); |
| 820 | 839 | rh = SMH_BANK(8); |
| 821 | 840 | wh = SMH_BANK(9); |
| 822 | 841 | } |
| r4829 | r4830 | |
| 829 | 848 | memory_install_write8_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0dc00, 0x0dfff, 0, 0, wh); |
| 830 | 849 | } |
| 831 | 850 | |
| 832 | | c65_io_dc00_on=!(value&1); |
| 851 | c65_io_dc00_on =! (value & 1); |
| 833 | 852 | #if 0 |
| 834 | 853 | /* cartridge roms !?*/ |
| 835 | 854 | if (value & 0x08) |
| r4829 | r4830 | |
| 872 | 891 | if (data == old) |
| 873 | 892 | return; |
| 874 | 893 | |
| 875 | | DBG_LOG (1, "bankswitch", ("%d\n", data & 7)); |
| 894 | DBG_LOG(machine, 1, "bankswitch", ("%d\n", data & 7)); |
| 876 | 895 | loram = (data & 1) ? 1 : 0; |
| 877 | 896 | hiram = (data & 2) ? 1 : 0; |
| 878 | 897 | charen = (data & 4) ? 1 : 0; |
src/mess/machine/c128.c
| r4829 | r4830 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | #define VERBOSE_LEVEL 0 |
| 33 | | #define DBG_LOG(N,M,A) \ |
| 33 | #define DBG_LOG( MACHINE, N, M, A ) \ |
| 34 | 34 | do { \ |
| 35 | 35 | if(VERBOSE_LEVEL >= N) \ |
| 36 | 36 | { \ |
| 37 | 37 | if( M ) \ |
| 38 | | logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \ |
| 38 | logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(MACHINE)), (char*) M ); \ |
| 39 | 39 | logerror A; \ |
| 40 | 40 | } \ |
| 41 | 41 | } while (0) |
| r4829 | r4830 | |
| 154 | 154 | |
| 155 | 155 | if (level != old_level) |
| 156 | 156 | { |
| 157 | | DBG_LOG (3, "mos6510", ("irq %s\n", level ? "start" : "end")); |
| 157 | DBG_LOG(machine, 3, "mos6510", ("irq %s\n", level ? "start" : "end")); |
| 158 | 158 | |
| 159 | 159 | if (0) // && (cpu_getactivecpu() == 0)) |
| 160 | 160 | { |
| r4829 | r4830 | |
| 304 | 304 | |
| 305 | 305 | static WRITE8_HANDLER(c128_dma8726_port_w) |
| 306 | 306 | { |
| 307 | | running_machine *machine = space->machine; |
| 308 | | DBG_LOG(1,"dma write",("%.3x %.2x\n",offset,data)); |
| 307 | DBG_LOG(space->machine, 1, "dma write", ("%.3x %.2x\n",offset,data)); |
| 309 | 308 | } |
| 310 | 309 | |
| 311 | 310 | static READ8_HANDLER(c128_dma8726_port_r) |
| 312 | 311 | { |
| 313 | | running_machine *machine = space->machine; |
| 314 | | DBG_LOG(1,"dma read",("%.3x\n",offset)); |
| 312 | DBG_LOG(space->machine, 1, "dma read", ("%.3x\n",offset)); |
| 315 | 313 | return 0xff; |
| 316 | 314 | } |
| 317 | 315 | |
| 318 | 316 | WRITE8_HANDLER( c128_write_d000 ) |
| 319 | 317 | { |
| 320 | | running_machine *machine = space->machine; |
| 321 | 318 | const device_config *cia_0 = devtag_get_device(space->machine, "cia_0"); |
| 322 | 319 | const device_config *cia_1 = devtag_get_device(space->machine, "cia_1"); |
| 323 | 320 | const device_config *sid = devtag_get_device(space->machine, "sid6581"); |
| r4829 | r4830 | |
| 336 | 333 | switch ((offset&0xf00)>>8) |
| 337 | 334 | { |
| 338 | 335 | case 0:case 1: case 2: case 3: |
| 339 | | vic2_port_w (space, offset & 0x3ff, data); |
| 336 | vic2_port_w(space, offset & 0x3ff, data); |
| 340 | 337 | break; |
| 341 | 338 | case 4: |
| 342 | 339 | sid6581_w(sid, offset & 0x3f, data); |
| 343 | 340 | break; |
| 344 | 341 | case 5: |
| 345 | | c128_mmu8722_port_w (space, offset & 0xff, data); |
| 342 | c128_mmu8722_port_w(space, offset & 0xff, data); |
| 346 | 343 | break; |
| 347 | 344 | case 6:case 7: |
| 348 | | vdc8563_port_w (space, offset & 0xff, data); |
| 345 | vdc8563_port_w(space, offset & 0xff, data); |
| 349 | 346 | break; |
| 350 | 347 | case 8: case 9: case 0xa: case 0xb: |
| 351 | 348 | if (c64mode) |
| r4829 | r4830 | |
| 363 | 360 | c128_dma8726_port_w(space, offset&0xff,data); |
| 364 | 361 | break; |
| 365 | 362 | case 0xe: |
| 366 | | DBG_LOG (1, "io write", ("%.3x %.2x\n", offset, data)); |
| 363 | DBG_LOG(space->machine, 1, "io write", ("%.3x %.2x\n", offset, data)); |
| 367 | 364 | break; |
| 368 | 365 | } |
| 369 | 366 | } |
| r4829 | r4830 | |
| 373 | 370 | |
| 374 | 371 | static READ8_HANDLER( c128_read_io ) |
| 375 | 372 | { |
| 376 | | running_machine *machine = space->machine; |
| 377 | 373 | const device_config *cia_0 = devtag_get_device(space->machine, "cia_0"); |
| 378 | 374 | const device_config *cia_1 = devtag_get_device(space->machine, "cia_1"); |
| 379 | 375 | const device_config *sid = devtag_get_device(space->machine, "sid6581"); |
| 380 | 376 | |
| 381 | 377 | if (offset < 0x400) |
| 382 | | return vic2_port_r (space, offset & 0x3ff); |
| 378 | return vic2_port_r(space, offset & 0x3ff); |
| 383 | 379 | else if (offset < 0x500) |
| 384 | | return sid6581_r (sid, offset & 0xff); |
| 380 | return sid6581_r(sid, offset & 0xff); |
| 385 | 381 | else if (offset < 0x600) |
| 386 | | return c128_mmu8722_port_r (space, offset & 0xff); |
| 382 | return c128_mmu8722_port_r(space, offset & 0xff); |
| 387 | 383 | else if (offset < 0x800) |
| 388 | | return vdc8563_port_r (space, offset & 0xff); |
| 384 | return vdc8563_port_r(space, offset & 0xff); |
| 389 | 385 | else if (offset < 0xc00) |
| 390 | 386 | return c64_colorram[offset & 0x3ff]; |
| 391 | 387 | else if (offset == 0xc00) |
| r4829 | r4830 | |
| 404 | 400 | return cia_r(cia_1, offset); |
| 405 | 401 | else if ((offset >= 0xf00) & (offset <= 0xfff)) |
| 406 | 402 | return c128_dma8726_port_r(space, offset&0xff); |
| 407 | | DBG_LOG (1, "io read", ("%.3x\n", offset)); |
| 403 | DBG_LOG(space->machine, 1, "io read", ("%.3x\n", offset)); |
| 408 | 404 | return 0xff; |
| 409 | 405 | } |
| 410 | 406 | |
| r4829 | r4830 | |
| 418 | 414 | return; |
| 419 | 415 | |
| 420 | 416 | data = (UINT8) devtag_get_info_int(machine, "maincpu", CPUINFO_INT_M6510_PORT) & 0x07; |
| 421 | | if ((data == old)&&(exrom==c64_exrom)&&(game==c64_game)&&!reset) |
| 417 | if ((data == old) && (exrom == c64_exrom) && (game == c64_game) && !reset) |
| 422 | 418 | return; |
| 423 | 419 | |
| 424 | | DBG_LOG (1, "bankswitch", ("%d\n", data & 7)); |
| 420 | DBG_LOG(machine, 1, "bankswitch", ("%d\n", data & 7)); |
| 425 | 421 | loram = (data & 1) ? 1 : 0; |
| 426 | 422 | hiram = (data & 2) ? 1 : 0; |
| 427 | 423 | charen = (data & 4) ? 1 : 0; |
| r4829 | r4830 | |
| 785 | 781 | { |
| 786 | 782 | if (!MMU_CPU8502) |
| 787 | 783 | { |
| 788 | | // DBG_LOG (1, "switching to z80", ("active %d\n",cpu_getactivecpu()) ); |
| 784 | // DBG_LOG(machine, 1, "switching to z80", ("active %d\n",cpu_getactivecpu()) ); |
| 789 | 785 | // memory_set_context(machine, 0); |
| 790 | 786 | c128_bankswitch_z80(machine); |
| 791 | 787 | // memory_set_context(machine, 1); |
| r4829 | r4830 | |
| 794 | 790 | } |
| 795 | 791 | else |
| 796 | 792 | { |
| 797 | | // DBG_LOG (1, "switching to m6502", ("active %d\n",cpu_getactivecpu()) ); |
| 793 | // DBG_LOG(machine, 1, "switching to m6502", ("active %d\n",cpu_getactivecpu()) ); |
| 798 | 794 | // memory_set_context(machine, 1); |
| 799 | 795 | c128_bankswitch_128(machine, reset); |
| 800 | 796 | // memory_set_context(machine, 0); |
src/mess/machine/cbmieeeb.c
| r4829 | r4830 | |
| 361 | 361 | |
| 362 | 362 | |
| 363 | 363 | #define VERBOSE_LEVEL 0 |
| 364 | | #define DBG_LOG( N, M, A ) \ |
| 364 | #define DBG_LOG( MACHINE, N, M, A ) \ |
| 365 | 365 | do { \ |
| 366 | 366 | if(VERBOSE_LEVEL >= N) \ |
| 367 | 367 | { \ |
| 368 | 368 | if( M ) \ |
| 369 | | logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(machine)), (char*) M ); \ |
| 369 | logerror("%11.6f: %-24s", attotime_to_double(timer_get_time(MACHINE)), (char*) M ); \ |
| 370 | 370 | logerror A; \ |
| 371 | 371 | } \ |
| 372 | 372 | } while (0) |
| r4829 | r4830 | |
| 398 | 398 | { |
| 399 | 399 | cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev); |
| 400 | 400 | |
| 401 | | // DBG_LOG(1, "cbm ieee dav", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 401 | // DBG_LOG(ieeedev->machine, 1, "cbm ieee dav", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 402 | 402 | ieeebus->bus[device].dav = data; |
| 403 | 403 | if (device == 0) |
| 404 | 404 | c2031_state(ieeedev->machine, cbm_drive); |
| r4829 | r4830 | |
| 413 | 413 | { |
| 414 | 414 | cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev); |
| 415 | 415 | |
| 416 | | // DBG_LOG(1, "cbm ieee nrfd", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 416 | // DBG_LOG(ieeedev->machine, 1, "cbm ieee nrfd", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 417 | 417 | ieeebus->bus[device].nrfd = data; |
| 418 | 418 | if (device == 0) |
| 419 | 419 | c2031_state(ieeedev->machine, cbm_drive); |
| r4829 | r4830 | |
| 428 | 428 | { |
| 429 | 429 | cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev); |
| 430 | 430 | |
| 431 | | // DBG_LOG(1, "cbm ieee ndac",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 431 | // DBG_LOG(ieeedev->machine, 1, "cbm ieee ndac",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 432 | 432 | ieeebus->bus[device].ndac = data; |
| 433 | 433 | if (device == 0) |
| 434 | 434 | c2031_state(ieeedev->machine, cbm_drive); |
| r4829 | r4830 | |
| 443 | 443 | { |
| 444 | 444 | cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev); |
| 445 | 445 | |
| 446 | | // DBG_LOG(1, "cbm ieee atn",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 446 | // DBG_LOG(ieeedev->machine, 1, "cbm ieee atn",("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 447 | 447 | ieeebus->bus[device].atn = data; |
| 448 | 448 | if (device == 0) |
| 449 | 449 | c2031_state(ieeedev->machine, cbm_drive); |
| r4829 | r4830 | |
| 458 | 458 | { |
| 459 | 459 | cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev); |
| 460 | 460 | |
| 461 | | // DBG_LOG(1, "cbm ieee eoi", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 461 | // DBG_LOG(ieeedev->machine, 1, "cbm ieee eoi", ("%.4x dev:%d %d\n", activecpu_get_pc(), device, data)); |
| 462 | 462 | ieeebus->bus[device].eoi = data; |
| 463 | 463 | if (device == 0) |
| 464 | 464 | c2031_state(ieeedev->machine, cbm_drive); |
| r4829 | r4830 | |
| 473 | 473 | { |
| 474 | 474 | cbm_ieee_bus_t *ieeebus = get_safe_token(ieeedev); |
| 475 | 475 | |
| 476 | | // DBG_LOG(1, "cbm ieee data", ("%.4x dev:%d %.2x\n", activecpu_get_pc(), device, data)); |
| 476 | // DBG_LOG(ieeedev->machine, 1, "cbm ieee data", ("%.4x dev:%d %.2x\n", activecpu_get_pc(), device, data)); |
| 477 | 477 | ieeebus->bus[device].data = data; |
| 478 | 478 | if (device == 0) |
| 479 | 479 | c2031_state(ieeedev->machine, cbm_drive); |
| r4829 | r4830 | |
| 487 | 487 | |
| 488 | 488 | READ8_DEVICE_HANDLER( cbm_ieee_srq_r ) |
| 489 | 489 | { |
| 490 | | running_machine *machine = device->machine; |
| 491 | 490 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 492 | 491 | int data = ieeebus->bus[1].srq; |
| 493 | 492 | |
| 494 | | DBG_LOG(1, "cbm ieee srq", ("read %d\n", data)); |
| 493 | DBG_LOG(device->machine, 1, "cbm ieee srq", ("read %d\n", data)); |
| 495 | 494 | return data; |
| 496 | 495 | } |
| 497 | 496 | |
| 498 | 497 | READ8_DEVICE_HANDLER( cbm_ieee_dav_r ) |
| 499 | 498 | { |
| 500 | | running_machine *machine = device->machine; |
| 501 | 499 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 502 | 500 | int data = ieeebus->bus[0].dav && ieeebus->bus[1].dav; |
| 503 | 501 | |
| 504 | | DBG_LOG(1, "cbm ieee dav", ("read %d\n", data)); |
| 502 | DBG_LOG(device->machine, 1, "cbm ieee dav", ("read %d\n", data)); |
| 505 | 503 | return data; |
| 506 | 504 | } |
| 507 | 505 | |
| 508 | 506 | READ8_DEVICE_HANDLER( cbm_ieee_nrfd_r ) |
| 509 | 507 | { |
| 510 | | running_machine *machine = device->machine; |
| 511 | 508 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 512 | 509 | int data = ieeebus->bus[0].nrfd && ieeebus->bus[1].nrfd; |
| 513 | 510 | |
| 514 | | DBG_LOG(1, "cbm ieee nrfd", ("read %d\n", data)); |
| 511 | DBG_LOG(device->machine, 1, "cbm ieee nrfd", ("read %d\n", data)); |
| 515 | 512 | return data; |
| 516 | 513 | } |
| 517 | 514 | |
| 518 | 515 | READ8_DEVICE_HANDLER( cbm_ieee_ndac_r ) |
| 519 | 516 | { |
| 520 | | running_machine *machine = device->machine; |
| 521 | 517 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 522 | 518 | int data = ieeebus->bus[0].ndac && ieeebus->bus[1].ndac; |
| 523 | 519 | |
| 524 | | DBG_LOG(1,"cbm ieee ndac", ("read %d\n", data)); |
| 520 | DBG_LOG(device->machine, 1,"cbm ieee ndac", ("read %d\n", data)); |
| 525 | 521 | return data; |
| 526 | 522 | } |
| 527 | 523 | |
| 528 | 524 | READ8_DEVICE_HANDLER( cbm_ieee_atn_r ) |
| 529 | 525 | { |
| 530 | | running_machine *machine = device->machine; |
| 531 | 526 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 532 | 527 | int data = ieeebus->bus[0].atn && ieeebus->bus[1].atn; |
| 533 | 528 | |
| 534 | | DBG_LOG(1,"cbm ieee atn", ("read %d\n", data)); |
| 529 | DBG_LOG(device->machine, 1,"cbm ieee atn", ("read %d\n", data)); |
| 535 | 530 | return data; |
| 536 | 531 | } |
| 537 | 532 | |
| 538 | 533 | READ8_DEVICE_HANDLER( cbm_ieee_eoi_r ) |
| 539 | 534 | { |
| 540 | | // running_machine *machine = device->machine; |
| 541 | 535 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 542 | 536 | int data = ieeebus->bus[0].eoi && ieeebus->bus[1].eoi; |
| 543 | 537 | |
| 544 | | /* DBG_LOG(1, "cbm ieee eoi", ("read %d\n", data)); */ |
| 538 | /* DBG_LOG(device->machine, 1, "cbm ieee eoi", ("read %d\n", data)); */ |
| 545 | 539 | return data; |
| 546 | 540 | } |
| 547 | 541 | |
| 548 | 542 | READ8_DEVICE_HANDLER( cbm_ieee_data_r ) |
| 549 | 543 | { |
| 550 | | running_machine *machine = device->machine; |
| 551 | 544 | cbm_ieee_bus_t *ieeebus = get_safe_token(device); |
| 552 | 545 | int data = ieeebus->bus[0].data & ieeebus->bus[1].data; |
| 553 | 546 | |
| 554 | | DBG_LOG(1, "cbm ieee data", ("read %.2x\n", data)); |
| 547 | DBG_LOG(device->machine, 1, "cbm ieee data", ("read %.2x\n", data)); |
| 555 | 548 | return data; |
| 556 | 549 | } |
| 557 | 550 | |