trunk/src/emu/cpu/apexc/apexc.c
| r23845 | r23846 | |
| 327 | 327 | #include "debugger.h" |
| 328 | 328 | #include "apexc.h" |
| 329 | 329 | |
| 330 | | #ifndef SUPPORT_ODD_WORD_SIZES |
| 331 | | #define apexc_readmem(address) cpustate->program->read_dword((address)<<2) |
| 332 | | #define apexc_writemem(address, data) cpustate->program->write_dword((address)<<2, (data)) |
| 333 | | /* eewww ! - Fortunately, there is no memory mapped I/O, so we can simulate masked write |
| 334 | | without danger */ |
| 335 | | #define apexc_writemem_masked(address, data, mask) \ |
| 336 | | apexc_writemem((address), (apexc_readmem(address) & ~(mask)) | ((data) & (mask))) |
| 337 | | #else |
| 338 | | #define apexc_readmem(address) cpu_readmem13_32(address) |
| 339 | | #define apexc_writemem(address, data) cpu_writemem13_32((address), (data)) |
| 340 | | #define apexc_writemem_masked(address, data, mask) cpu_writemem13_32masked((address), (data), (mask)) |
| 341 | | #endif |
| 342 | 330 | |
| 331 | const device_type APEXC = &device_creator<apexc_cpu_device>; |
| 343 | 332 | |
| 344 | | #define apexc_readop(address) apexc_readmem(address) |
| 345 | 333 | |
| 346 | | struct apexc_state |
| 347 | | { |
| 348 | | UINT32 a; /* accumulator */ |
| 349 | | UINT32 r; /* register */ |
| 350 | | UINT32 cr; /* control register (i.e. instruction register) */ |
| 351 | | int ml; /* memory location (current track in working store, and requested |
| 352 | | word position within track) (10 bits) */ |
| 353 | | int working_store; /* current working store (group of 16 tracks) (1-15) */ |
| 354 | | int current_word; /* current word position within track (0-31) */ |
| 355 | | |
| 356 | | int running; /* 1 flag: */ |
| 357 | | /* running: flag implied by the existence of the stop instruction */ |
| 358 | | UINT32 pc; /* address of next instruction for the disassembler */ |
| 359 | | |
| 360 | | legacy_cpu_device *device; |
| 361 | | address_space *program; |
| 362 | | address_space *io; |
| 363 | | int icount; |
| 364 | | }; |
| 365 | | |
| 366 | 334 | /* decrement ICount by n */ |
| 367 | | #define DELAY(n) {cpustate->icount -= (n); cpustate->current_word = (cpustate->current_word + (n)) & 0x1f;} |
| 335 | #define DELAY(n) {m_icount -= (n); m_current_word = (m_current_word + (n)) & 0x1f;} |
| 368 | 336 | |
| 369 | 337 | |
| 370 | | INLINE apexc_state *get_safe_token(device_t *device) |
| 338 | apexc_cpu_device::apexc_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 339 | : cpu_device(mconfig, APEXC, "APEXC", tag, owner, clock) |
| 340 | , m_program_config("program", ENDIANNESS_BIG, 32, 15, 0) |
| 341 | , m_io_config("io", ENDIANNESS_BIG, 8, 1, 0) |
| 371 | 342 | { |
| 372 | | assert(device != NULL); |
| 373 | | assert(device->type() == APEXC); |
| 374 | | return (apexc_state *)downcast<legacy_cpu_device *>(device)->token(); |
| 375 | 343 | } |
| 376 | 344 | |
| 377 | 345 | |
| r23845 | r23846 | |
| 391 | 359 | |
| 392 | 360 | /* compute complete word address (i.e. translate a logical track address (expressed |
| 393 | 361 | in current working store) to an absolute track address) */ |
| 394 | | static int effective_address(apexc_state *cpustate, int address) |
| 362 | UINT32 apexc_cpu_device::effective_address(UINT32 address) |
| 395 | 363 | { |
| 396 | 364 | if (address & 0x200) |
| 397 | 365 | { |
| 398 | | address = (address & 0x1FF) | (cpustate->working_store) << 9; |
| 366 | address = (address & 0x1FF) | (m_working_store) << 9; |
| 399 | 367 | } |
| 400 | 368 | |
| 401 | 369 | return address; |
| 402 | 370 | } |
| 403 | 371 | |
| 404 | 372 | /* read word */ |
| 405 | | static UINT32 word_read(apexc_state *cpustate, int address, int special) |
| 373 | UINT32 apexc_cpu_device::word_read(UINT32 address, UINT32 special) |
| 406 | 374 | { |
| 407 | 375 | UINT32 result; |
| 408 | 376 | |
| 409 | 377 | /* compute absolute track address */ |
| 410 | | address = effective_address(cpustate, address); |
| 378 | address = effective_address(address); |
| 411 | 379 | |
| 412 | 380 | if (special) |
| 413 | 381 | { |
| 414 | 382 | /* ignore word position in x - use current position instead */ |
| 415 | | address = (address & ~ 0x1f) | cpustate->current_word; |
| 383 | address = (address & ~ 0x1f) | m_current_word; |
| 416 | 384 | } |
| 417 | 385 | else |
| 418 | 386 | { |
| 419 | 387 | /* wait for requested word to appear under the heads */ |
| 420 | | DELAY(((address /*& 0x1f*/) - cpustate->current_word) & 0x1f); |
| 388 | DELAY(((address /*& 0x1f*/) - m_current_word) & 0x1f); |
| 421 | 389 | } |
| 422 | 390 | |
| 423 | 391 | /* read 32 bits */ |
| 424 | | #if 0 |
| 425 | | /* note that the APEXC reads LSBits first */ |
| 426 | | result = 0; |
| 427 | | for (i=0; i<31; i++) |
| 428 | | { |
| 429 | | /*if (mask & (1 << i))*/ |
| 430 | | result |= bit_read((address << 5) | i) << i; |
| 431 | | } |
| 432 | | #else |
| 433 | 392 | result = apexc_readmem(address); |
| 434 | | #endif |
| 435 | 393 | |
| 436 | 394 | /* read takes one memory cycle */ |
| 437 | 395 | DELAY(1); |
| r23845 | r23846 | |
| 440 | 398 | } |
| 441 | 399 | |
| 442 | 400 | /* write word (or part of a word, according to mask) */ |
| 443 | | static void word_write(apexc_state *cpustate, int address, UINT32 data, UINT32 mask) |
| 401 | void apexc_cpu_device::word_write(UINT32 address, UINT32 data, UINT32 mask) |
| 444 | 402 | { |
| 445 | 403 | /* compute absolute track address */ |
| 446 | | address = effective_address(cpustate, address); |
| 404 | address = effective_address(address); |
| 447 | 405 | |
| 448 | 406 | /* wait for requested word to appear under the heads */ |
| 449 | | DELAY(((address /*& 0x1f*/) - cpustate->current_word) & 0x1f); |
| 407 | DELAY(((address /*& 0x1f*/) - m_current_word) & 0x1f); |
| 450 | 408 | |
| 451 | 409 | /* write 32 bits according to mask */ |
| 452 | | #if 0 |
| 453 | | /* note that the APEXC reads LSBits first */ |
| 454 | | for (i=0; i<31; i++) |
| 455 | | { |
| 456 | | if (mask & (1 << i)) |
| 457 | | bit_write((address << 5) | i, (data >> i) & 1); |
| 458 | | } |
| 459 | | #else |
| 460 | 410 | apexc_writemem_masked(address, data, mask); |
| 461 | | #endif |
| 462 | 411 | |
| 463 | 412 | /* write takes one memory cycle (2, actually, but the 2nd cycle is taken into |
| 464 | 413 | account in execute) */ |
| r23845 | r23846 | |
| 471 | 420 | no address is used, these functions just punch or read 5 bits |
| 472 | 421 | */ |
| 473 | 422 | |
| 474 | | static int papertape_read(apexc_state *cpustate) |
| 423 | UINT8 apexc_cpu_device::papertape_read() |
| 475 | 424 | { |
| 476 | | return cpustate->io->read_byte(0) & 0x1f; |
| 425 | return m_io->read_byte(0) & 0x1f; |
| 477 | 426 | } |
| 478 | 427 | |
| 479 | | static void papertape_punch(apexc_state *cpustate, int data) |
| 428 | void apexc_cpu_device::papertape_punch(UINT8 data) |
| 480 | 429 | { |
| 481 | | cpustate->io->write_byte(0, data); |
| 430 | m_io->write_byte(0, data); |
| 482 | 431 | } |
| 483 | 432 | |
| 484 | 433 | /* |
| r23845 | r23846 | |
| 488 | 437 | /* |
| 489 | 438 | set the memory location (i.e. address) register, and compute the associated delay |
| 490 | 439 | */ |
| 491 | | INLINE int load_ml(apexc_state *cpustate, int address, int vector) |
| 440 | UINT32 apexc_cpu_device::load_ml(UINT32 address, UINT32 vector) |
| 492 | 441 | { |
| 493 | 442 | int delay; |
| 494 | 443 | |
| 495 | 444 | /* additionnal delay appears if we switch tracks */ |
| 496 | | if (((cpustate->ml & 0x3E0) != (address & 0x3E0)) /*|| vector*/) |
| 445 | if (((m_ml & 0x3E0) != (address & 0x3E0)) /*|| vector*/) |
| 497 | 446 | delay = 6; /* if tracks are different, delay to allow for track switching */ |
| 498 | 447 | else |
| 499 | 448 | delay = 0; /* else, no problem */ |
| 500 | 449 | |
| 501 | | cpustate->ml = address; /* save ml */ |
| 450 | m_ml = address; /* save ml */ |
| 502 | 451 | |
| 503 | 452 | return delay; |
| 504 | 453 | } |
| r23845 | r23846 | |
| 518 | 467 | execute it. |
| 519 | 468 | This solution makes timing simulation much simpler, too. |
| 520 | 469 | */ |
| 521 | | static void execute(apexc_state *cpustate) |
| 470 | void apexc_cpu_device::execute() |
| 522 | 471 | { |
| 523 | 472 | int x, y, function, c6, vector; /* instruction fields */ |
| 524 | 473 | int i = 0; /* misc counter */ |
| r23845 | r23846 | |
| 533 | 482 | int delay3; /* pre-operand-fetch delay */ |
| 534 | 483 | |
| 535 | 484 | /* first isolate the instruction fields */ |
| 536 | | x = (cpustate->cr >> 22) & 0x3FF; |
| 537 | | y = (cpustate->cr >> 12) & 0x3FF; |
| 538 | | function = (cpustate->cr >> 7) & 0x1F; |
| 539 | | c6 = (cpustate->cr >> 1) & 0x3F; |
| 540 | | vector = cpustate->cr & 1; |
| 541 | | cpustate->pc = y<<2; |
| 485 | x = (m_cr >> 22) & 0x3FF; |
| 486 | y = (m_cr >> 12) & 0x3FF; |
| 487 | function = (m_cr >> 7) & 0x1F; |
| 488 | c6 = (m_cr >> 1) & 0x3F; |
| 489 | vector = m_cr & 1; |
| 490 | m_pc = y<<2; |
| 542 | 491 | |
| 543 | 492 | function &= 0x1E; /* this is a mere guess - the LSBit is reserved for future additions */ |
| 544 | 493 | |
| r23845 | r23846 | |
| 548 | 497 | if (has_operand) |
| 549 | 498 | { |
| 550 | 499 | /* load ml with X */ |
| 551 | | delay1 = load_ml(cpustate, x, vector); |
| 500 | delay1 = load_ml(x, vector); |
| 552 | 501 | /* burn pre-operand-access delay if needed */ |
| 553 | 502 | if (delay1) |
| 554 | 503 | { |
| r23845 | r23846 | |
| 565 | 514 | case 0: |
| 566 | 515 | /* stop */ |
| 567 | 516 | |
| 568 | | cpustate->running = FALSE; |
| 517 | m_running = FALSE; |
| 569 | 518 | |
| 570 | 519 | /* BTW, I don't know whether stop loads y into ml or not, and whether |
| 571 | 520 | subsequent fetch is done */ |
| r23845 | r23846 | |
| 575 | 524 | /* I */ |
| 576 | 525 | /* I do not know whether the CPU does an OR or whatever, but since docs say that |
| 577 | 526 | the 5 bits must be cleared initially, an OR kind of makes sense */ |
| 578 | | cpustate->r |= papertape_read(cpustate) << 27; |
| 527 | m_r |= papertape_read() << 27; |
| 579 | 528 | delay2 = 32; /* no idea whether this should be counted as an absolute delay |
| 580 | 529 | or as a value in delay2 */ |
| 581 | 530 | break; |
| 582 | 531 | |
| 583 | 532 | case 4: |
| 584 | 533 | /* P */ |
| 585 | | papertape_punch(cpustate, (cpustate->r >> 27) & 0x1f); |
| 534 | papertape_punch((m_r >> 27) & 0x1f); |
| 586 | 535 | delay2 = 32; /* no idea whether this should be counted as an absolute delay |
| 587 | 536 | or as a value in delay2 */ |
| 588 | 537 | break; |
| r23845 | r23846 | |
| 590 | 539 | case 6: |
| 591 | 540 | /* B<(x)>=(y) */ |
| 592 | 541 | /* I have no idea what we should do if the vector bit is set */ |
| 593 | | if (cpustate->a & 0x80000000UL) |
| 542 | if (m_a & 0x80000000UL) |
| 594 | 543 | { |
| 595 | 544 | /* load ml with X */ |
| 596 | | delay1 = load_ml(cpustate, x, vector); |
| 597 | | cpustate->pc = x<<2; |
| 545 | delay1 = load_ml(x, vector); |
| 546 | m_pc = x<<2; |
| 598 | 547 | /* burn pre-fetch delay if needed */ |
| 599 | 548 | if (delay1) |
| 600 | 549 | { |
| r23845 | r23846 | |
| 616 | 565 | int shifted_bit = 0; |
| 617 | 566 | |
| 618 | 567 | /* shift and increment c6 */ |
| 619 | | shifted_bit = cpustate->r & 1; |
| 620 | | cpustate->r >>= 1; |
| 621 | | if (cpustate->a & 1) |
| 622 | | cpustate->r |= 0x80000000UL; |
| 623 | | cpustate->a >>= 1; |
| 568 | shifted_bit = m_r & 1; |
| 569 | m_r >>= 1; |
| 570 | if (m_a & 1) |
| 571 | m_r |= 0x80000000UL; |
| 572 | m_a >>= 1; |
| 624 | 573 | if (shifted_bit) |
| 625 | | cpustate->a |= 0x80000000UL; |
| 574 | m_a |= 0x80000000UL; |
| 626 | 575 | |
| 627 | 576 | c6 = (c6+1) & 0x3f; |
| 628 | 577 | } |
| r23845 | r23846 | |
| 637 | 586 | while (c6 != 0) |
| 638 | 587 | { |
| 639 | 588 | /* shift and increment c6 */ |
| 640 | | cpustate->r >>= 1; |
| 641 | | if (cpustate->a & 1) |
| 642 | | cpustate->r |= 0x80000000UL; |
| 643 | | cpustate->a = ((INT32) cpustate->a) >> 1; |
| 589 | m_r >>= 1; |
| 590 | if (m_a & 1) |
| 591 | m_r |= 0x80000000UL; |
| 592 | m_a = ((INT32) m_a) >> 1; |
| 644 | 593 | |
| 645 | 594 | c6 = (c6+1) & 0x3f; |
| 646 | 595 | } |
| r23845 | r23846 | |
| 661 | 610 | { |
| 662 | 611 | int shifted_bit; |
| 663 | 612 | |
| 664 | | cpustate->a = 0; |
| 613 | m_a = 0; |
| 665 | 614 | shifted_bit = 0; |
| 666 | 615 | while (1) |
| 667 | 616 | { |
| 668 | 617 | /* note we read word at current word position */ |
| 669 | | if (shifted_bit && ! (cpustate->r & 1)) |
| 670 | | cpustate->a += word_read(cpustate, x, 1); |
| 671 | | else if ((! shifted_bit) && (cpustate->r & 1)) |
| 672 | | cpustate->a -= word_read(cpustate, x, 1); |
| 618 | if (shifted_bit && ! (m_r & 1)) |
| 619 | m_a += word_read(x, 1); |
| 620 | else if ((! shifted_bit) && (m_r & 1)) |
| 621 | m_a -= word_read(x, 1); |
| 673 | 622 | else |
| 674 | 623 | /* Even if we do not read anything, the loop still takes 1 cycle of |
| 675 | 624 | the memory word clock. */ |
| r23845 | r23846 | |
| 685 | 634 | c6 = (c6+1) & 0x3f; |
| 686 | 635 | |
| 687 | 636 | /* shift */ |
| 688 | | shifted_bit = cpustate->r & 1; |
| 689 | | cpustate->r >>= 1; |
| 690 | | if (cpustate->a & 1) |
| 691 | | cpustate->r |= 0x80000000UL; |
| 692 | | cpustate->a = ((INT32) cpustate->a) >> 1; |
| 637 | shifted_bit = m_r & 1; |
| 638 | m_r >>= 1; |
| 639 | if (m_a & 1) |
| 640 | m_r |= 0x80000000UL; |
| 641 | m_a = ((INT32) m_a) >> 1; |
| 693 | 642 | } |
| 694 | 643 | } |
| 695 | 644 | |
| r23845 | r23846 | |
| 701 | 650 | |
| 702 | 651 | case 16: |
| 703 | 652 | /* +c(x) */ |
| 704 | | cpustate->a = + word_read(cpustate, cpustate->ml, 0); |
| 653 | m_a = + word_read(m_ml, 0); |
| 705 | 654 | break; |
| 706 | 655 | |
| 707 | 656 | case 18: |
| 708 | 657 | /* -c(x) */ |
| 709 | | cpustate->a = - word_read(cpustate, cpustate->ml, 0); |
| 658 | m_a = - word_read(m_ml, 0); |
| 710 | 659 | break; |
| 711 | 660 | |
| 712 | 661 | case 20: |
| 713 | 662 | /* +(x) */ |
| 714 | | cpustate->a += word_read(cpustate, cpustate->ml, 0); |
| 663 | m_a += word_read(m_ml, 0); |
| 715 | 664 | break; |
| 716 | 665 | |
| 717 | 666 | case 22: |
| 718 | 667 | /* -(x) */ |
| 719 | | cpustate->a -= word_read(cpustate, cpustate->ml, 0); |
| 668 | m_a -= word_read(m_ml, 0); |
| 720 | 669 | break; |
| 721 | 670 | |
| 722 | 671 | case 24: |
| 723 | 672 | /* T(x) */ |
| 724 | | cpustate->r = word_read(cpustate, cpustate->ml, 0); |
| 673 | m_r = word_read(m_ml, 0); |
| 725 | 674 | break; |
| 726 | 675 | |
| 727 | 676 | case 26: |
| r23845 | r23846 | |
| 735 | 684 | else |
| 736 | 685 | mask = 0xFFFFFFFFUL >> c6; |
| 737 | 686 | |
| 738 | | word_write(cpustate, cpustate->ml, cpustate->r, mask); |
| 687 | word_write(m_ml, m_r, mask); |
| 739 | 688 | } |
| 740 | 689 | |
| 741 | | cpustate->r = (cpustate->r & 0x80000000UL) ? 0xFFFFFFFFUL : 0; |
| 690 | m_r = (m_r & 0x80000000UL) ? 0xFFFFFFFFUL : 0; |
| 742 | 691 | |
| 743 | 692 | delay2 = 1; |
| 744 | 693 | break; |
| r23845 | r23846 | |
| 754 | 703 | else |
| 755 | 704 | mask = 0xFFFFFFFFUL >> c6; |
| 756 | 705 | |
| 757 | | word_write(cpustate, cpustate->ml, cpustate->a, mask); |
| 706 | word_write(m_ml, m_a, mask); |
| 758 | 707 | } |
| 759 | 708 | |
| 760 | 709 | delay2 = 1; |
| r23845 | r23846 | |
| 762 | 711 | |
| 763 | 712 | case 30: |
| 764 | 713 | /* S(x) */ |
| 765 | | cpustate->working_store = (x >> 5) & 0xf; /* or is it (x >> 6)? */ |
| 714 | m_working_store = (x >> 5) & 0xf; /* or is it (x >> 6)? */ |
| 766 | 715 | DELAY(32); /* no idea what the value is... All I know is that it takes much |
| 767 | 716 | more time than track switching (which takes 6 cycles) */ |
| 768 | 717 | break; |
| 769 | 718 | } |
| 770 | 719 | if (vector) |
| 771 | 720 | /* increment word position in vector operations */ |
| 772 | | cpustate->ml = (cpustate->ml & 0x3E0) | ((cpustate->ml + 1) & 0x1F); |
| 721 | m_ml = (m_ml & 0x3E0) | ((m_ml + 1) & 0x1F); |
| 773 | 722 | } while (vector && has_operand && (++i < 32)); /* iterate 32 times if vector bit is set */ |
| 774 | 723 | /* the has_operand is a mere guess */ |
| 775 | 724 | |
| 776 | 725 | /* load ml with Y */ |
| 777 | | delay3 = load_ml(cpustate, y, 0); |
| 726 | delay3 = load_ml(y, 0); |
| 778 | 727 | |
| 779 | 728 | /* compute max(delay2, delay3) */ |
| 780 | 729 | if (delay2 > delay3) |
| r23845 | r23846 | |
| 791 | 740 | special_fetch: |
| 792 | 741 | |
| 793 | 742 | /* fetch current instruction into control register */ |
| 794 | | cpustate->cr = word_read(cpustate, cpustate->ml, 0); |
| 743 | m_cr = word_read(m_ml, 0); |
| 795 | 744 | } |
| 796 | 745 | |
| 797 | 746 | |
| 798 | | static CPU_INIT( apexc ) |
| 747 | void apexc_cpu_device::device_start() |
| 799 | 748 | { |
| 800 | | apexc_state *cpustate = get_safe_token(device); |
| 749 | m_program = &space(AS_PROGRAM); |
| 750 | m_io = &space(AS_IO); |
| 801 | 751 | |
| 802 | | cpustate->device = device; |
| 803 | | cpustate->program = &device->space(AS_PROGRAM); |
| 804 | | cpustate->io = &device->space(AS_IO); |
| 752 | save_item(NAME(m_a)); |
| 753 | save_item(NAME(m_r)); |
| 754 | save_item(NAME(m_cr)); |
| 755 | save_item(NAME(m_ml)); |
| 756 | save_item(NAME(m_working_store)); |
| 757 | save_item(NAME(m_current_word)); |
| 758 | save_item(NAME(m_running)); |
| 759 | save_item(NAME(m_pc)); |
| 805 | 760 | |
| 806 | | device->save_item(NAME(cpustate->a)); |
| 807 | | device->save_item(NAME(cpustate->r)); |
| 808 | | device->save_item(NAME(cpustate->cr)); |
| 809 | | device->save_item(NAME(cpustate->ml)); |
| 810 | | device->save_item(NAME(cpustate->working_store)); |
| 811 | | device->save_item(NAME(cpustate->current_word)); |
| 812 | | device->save_item(NAME(cpustate->running)); |
| 813 | | device->save_item(NAME(cpustate->pc)); |
| 814 | | } |
| 761 | state_add( APEXC_CR, "CR", m_cr ).formatstr("%08X"); |
| 762 | state_add( APEXC_A, "A", m_a ).formatstr("%08X"); |
| 763 | state_add( APEXC_R, "R", m_r ).formatstr("%08X"); |
| 764 | state_add( APEXC_ML, "ML", m_ml ).mask(0xfff).formatstr("%03X"); |
| 765 | state_add( APEXC_WS, "WS", m_working_store ).mask(0x01); |
| 766 | state_add( APEXC_STATE, "CPU state", m_running ).mask(0x01); |
| 767 | state_add( APEXC_PC, "PC", m_pc ).callimport().callexport().formatstr("%03X"); |
| 768 | state_add( APEXC_ML_FULL, "ML_FULL", m_ml_full ).callimport().callexport().noshow(); |
| 815 | 769 | |
| 816 | | static CPU_RESET( apexc ) |
| 817 | | { |
| 818 | | apexc_state *cpustate = get_safe_token(device); |
| 819 | | |
| 820 | | /* mmmh... I don't know what happens on reset with an actual APEXC. */ |
| 821 | | |
| 822 | | cpustate->working_store = 1; /* mere guess */ |
| 823 | | cpustate->current_word = 0; /* well, we do have to start somewhere... */ |
| 824 | | |
| 825 | | /* next two lines are just the product of my bold fantasy */ |
| 826 | | cpustate->cr = 0; /* first instruction executed will be a stop */ |
| 827 | | cpustate->running = TRUE; /* this causes the CPU to load the instruction at 0/0, |
| 828 | | which enables easy booting (just press run on the panel) */ |
| 770 | m_icountptr = &m_icount; |
| 829 | 771 | } |
| 830 | 772 | |
| 831 | | static CPU_EXECUTE( apexc ) |
| 832 | | { |
| 833 | | apexc_state *cpustate = get_safe_token(device); |
| 834 | 773 | |
| 835 | | do |
| 836 | | { |
| 837 | | debugger_instruction_hook(device, cpustate->pc); |
| 838 | | |
| 839 | | if (cpustate->running) |
| 840 | | execute(cpustate); |
| 841 | | else |
| 842 | | { |
| 843 | | DELAY(cpustate->icount); /* burn cycles once for all */ |
| 844 | | } |
| 845 | | } while (cpustate->icount > 0); |
| 846 | | } |
| 847 | | |
| 848 | | static CPU_SET_INFO( apexc ) |
| 774 | void apexc_cpu_device::state_import(const device_state_entry &entry) |
| 849 | 775 | { |
| 850 | | apexc_state *cpustate = get_safe_token(device); |
| 851 | | |
| 852 | | switch (state) |
| 776 | switch (entry.index()) |
| 853 | 777 | { |
| 854 | | /* --- the following bits of info are set as 64-bit signed integers --- */ |
| 855 | | /*case CPUINFO_INT_INPUT_STATE + ...:*/ /* no interrupts */ |
| 778 | case APEXC_PC: |
| 779 | /* keep address 9 LSBits - 10th bit depends on whether we are accessing the permanent |
| 780 | track group or a switchable one */ |
| 781 | m_ml = m_pc & 0x1ff; |
| 782 | if (m_pc & 0x1e00) |
| 783 | { /* we are accessing a switchable track group */ |
| 784 | m_ml |= 0x200; /* set 10th bit */ |
| 856 | 785 | |
| 857 | | case CPUINFO_INT_PC: |
| 858 | | /* keep address 9 LSBits - 10th bit depends on whether we are accessing the permanent |
| 859 | | track group or a switchable one */ |
| 860 | | cpustate->ml = info->i & 0x1ff; |
| 861 | | if (info->i & 0x1e00) |
| 862 | | { /* we are accessing a switchable track group */ |
| 863 | | cpustate->ml |= 0x200; /* set 10th bit */ |
| 864 | | |
| 865 | | if (((info->i >> 9) & 0xf) != cpustate->working_store) |
| 866 | | { /* we need to do a store switch */ |
| 867 | | cpustate->working_store = ((info->i >> 9) & 0xf); |
| 786 | if (((m_pc >> 9) & 0xf) != m_working_store) |
| 787 | { /* we need to do a store switch */ |
| 788 | m_working_store = ((m_pc >> 9) & 0xf); |
| 789 | } |
| 868 | 790 | } |
| 869 | | } |
| 870 | | break; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 871 | 794 | |
| 872 | | case CPUINFO_INT_SP: (void) info->i; /* no SP */ break; |
| 873 | 795 | |
| 874 | | case CPUINFO_INT_REGISTER + APEXC_CR: cpustate->cr = info->i; break; |
| 875 | | case CPUINFO_INT_REGISTER + APEXC_A: cpustate->a = info->i; break; |
| 876 | | case CPUINFO_INT_REGISTER + APEXC_R: cpustate->r = info->i; break; |
| 877 | | case CPUINFO_INT_REGISTER + APEXC_ML: cpustate->ml = info->i & 0x3ff; break; |
| 878 | | case CPUINFO_INT_REGISTER + APEXC_PC: cpustate->pc = info->i; break; |
| 879 | | case CPUINFO_INT_REGISTER + APEXC_WS: cpustate->working_store = info->i & 0xf; break; |
| 880 | | case CPUINFO_INT_REGISTER + APEXC_STATE: cpustate->running = info->i ? TRUE : FALSE; break; |
| 796 | void apexc_cpu_device::state_export(const device_state_entry &entry) |
| 797 | { |
| 798 | switch (entry.index()) |
| 799 | { |
| 800 | case APEXC_ML_FULL: |
| 801 | m_ml_full = effective_address(m_ml); |
| 802 | break; |
| 881 | 803 | } |
| 882 | 804 | } |
| 883 | 805 | |
| 884 | | CPU_GET_INFO( apexc ) |
| 885 | | { |
| 886 | | apexc_state *cpustate = (device != NULL && device->token() != NULL) ? get_safe_token(device) : NULL; |
| 887 | 806 | |
| 888 | | switch (state) |
| 807 | void apexc_cpu_device::state_string_export(const device_state_entry &entry, astring &string) |
| 808 | { |
| 809 | switch (entry.index()) |
| 889 | 810 | { |
| 890 | | case CPUINFO_INT_CONTEXT_SIZE: info->i = sizeof(apexc_state); break; |
| 891 | | case CPUINFO_INT_INPUT_LINES: info->i = 0; break; |
| 892 | | case CPUINFO_INT_DEFAULT_IRQ_VECTOR: info->i = 0; break; |
| 893 | | case CPUINFO_INT_ENDIANNESS: info->i = ENDIANNESS_BIG; /*don't care*/ break; |
| 894 | | case CPUINFO_INT_CLOCK_MULTIPLIER: info->i = 1; break; |
| 895 | | case CPUINFO_INT_CLOCK_DIVIDER: info->i = 1; break; |
| 896 | | case CPUINFO_INT_MIN_INSTRUCTION_BYTES: info->i = 4; break; |
| 897 | | case CPUINFO_INT_MAX_INSTRUCTION_BYTES: info->i = 4; break; |
| 898 | | case CPUINFO_INT_MIN_CYCLES: info->i = 2; /* IIRC */ break; |
| 899 | | case CPUINFO_INT_MAX_CYCLES: info->i = 75; /* IIRC */ break; |
| 811 | case STATE_GENFLAGS: |
| 812 | string.printf("%c", m_running ? "R" : "S" ); |
| 813 | break; |
| 814 | } |
| 815 | } |
| 900 | 816 | |
| 901 | | case CPUINFO_INT_DATABUS_WIDTH + AS_PROGRAM: info->i = 32; break; |
| 902 | | case CPUINFO_INT_ADDRBUS_WIDTH + AS_PROGRAM: info->i = 15; /*13+2 ignored bits to make double word address*/ break; |
| 903 | | case CPUINFO_INT_ADDRBUS_SHIFT + AS_PROGRAM: info->i = 0; break; |
| 904 | | case CPUINFO_INT_DATABUS_WIDTH + AS_DATA: info->i = 0; break; |
| 905 | | case CPUINFO_INT_ADDRBUS_WIDTH + AS_DATA: info->i = 0; break; |
| 906 | | case CPUINFO_INT_ADDRBUS_SHIFT + AS_DATA: info->i = 0; break; |
| 907 | | case CPUINFO_INT_DATABUS_WIDTH + AS_IO: info->i = /*5*/8; /* no I/O bus, but we use address 0 for punchtape I/O */ break; |
| 908 | | case CPUINFO_INT_ADDRBUS_WIDTH + AS_IO: info->i = /*0*/1; /*0 is quite enough but the MAME core does not understand*/ break; |
| 909 | | case CPUINFO_INT_ADDRBUS_SHIFT + AS_IO: info->i = 0; break; |
| 910 | 817 | |
| 911 | | case CPUINFO_INT_SP: info->i = 0; /* no SP */ break; |
| 912 | | case CPUINFO_INT_PC: |
| 913 | | case CPUINFO_INT_PREVIOUSPC: info->i = cpustate->pc; /* psuedo-PC */ break; |
| 818 | void apexc_cpu_device::device_reset() |
| 819 | { |
| 820 | /* mmmh... I don't know what happens on reset with an actual APEXC. */ |
| 914 | 821 | |
| 915 | | /*case CPUINFO_INT_INPUT_STATE + ...:*/ /* no interrupts */ |
| 822 | m_working_store = 1; /* mere guess */ |
| 823 | m_current_word = 0; /* well, we do have to start somewhere... */ |
| 916 | 824 | |
| 917 | | case CPUINFO_INT_REGISTER + APEXC_CR: info->i = cpustate->cr; break; |
| 918 | | case CPUINFO_INT_REGISTER + APEXC_A: info->i = cpustate->a; break; |
| 919 | | case CPUINFO_INT_REGISTER + APEXC_R: info->i = cpustate->r; break; |
| 920 | | case CPUINFO_INT_REGISTER + APEXC_ML: info->i = cpustate->ml; break; |
| 921 | | case CPUINFO_INT_REGISTER + APEXC_PC: info->i = cpustate->pc; break; |
| 922 | | case CPUINFO_INT_REGISTER + APEXC_WS: info->i = cpustate->working_store; break; |
| 923 | | case CPUINFO_INT_REGISTER + APEXC_STATE: info->i = cpustate->running; break; |
| 924 | | case CPUINFO_INT_REGISTER + APEXC_ML_FULL: info->i = effective_address(cpustate, cpustate->ml); break; |
| 825 | /* next two lines are just the product of my bold fantasy */ |
| 826 | m_cr = 0; /* first instruction executed will be a stop */ |
| 827 | m_running = TRUE; /* this causes the CPU to load the instruction at 0/0, |
| 828 | which enables easy booting (just press run on the panel) */ |
| 829 | m_a = 0; |
| 830 | m_r = 0; |
| 831 | m_pc = 0; |
| 832 | m_ml = 0; |
| 833 | } |
| 925 | 834 | |
| 926 | | case CPUINFO_FCT_SET_INFO: info->setinfo = CPU_SET_INFO_NAME(apexc); break; |
| 927 | | case CPUINFO_FCT_INIT: info->init = CPU_INIT_NAME(apexc); break; |
| 928 | | case CPUINFO_FCT_RESET: info->reset = CPU_RESET_NAME(apexc); break; |
| 929 | | case CPUINFO_FCT_EXECUTE: info->execute = CPU_EXECUTE_NAME(apexc); break; |
| 930 | | case CPUINFO_FCT_BURN: info->burn = NULL; break; |
| 931 | | case CPUINFO_FCT_DISASSEMBLE: info->disassemble = CPU_DISASSEMBLE_NAME(apexc); break; |
| 932 | | case CPUINFO_PTR_INSTRUCTION_COUNTER: info->icount = &cpustate->icount; break; |
| 933 | 835 | |
| 934 | | case CPUINFO_STR_NAME: strcpy(info->s, "APEXC"); break; |
| 935 | | case CPUINFO_STR_FAMILY: strcpy(info->s, "APEC"); break; |
| 936 | | case CPUINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 937 | | case CPUINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 938 | | case CPUINFO_STR_CREDITS: strcpy(info->s, "Raphael Nabet"); break; |
| 836 | void apexc_cpu_device::execute_run() |
| 837 | { |
| 838 | do |
| 839 | { |
| 840 | debugger_instruction_hook(this, m_pc); |
| 939 | 841 | |
| 940 | | case CPUINFO_STR_FLAGS: sprintf(info->s, "%c", (cpustate->running) ? 'R' : 'S'); break; |
| 842 | if (m_running) |
| 843 | execute(); |
| 844 | else |
| 845 | { |
| 846 | DELAY(m_icount); /* burn cycles once for all */ |
| 847 | } |
| 848 | } while (m_icount > 0); |
| 849 | } |
| 941 | 850 | |
| 942 | | case CPUINFO_STR_REGISTER + APEXC_CR: sprintf(info->s, "CR:%08X", cpustate->cr); break; |
| 943 | | case CPUINFO_STR_REGISTER + APEXC_A: sprintf(info->s, "A :%08X", cpustate->a); break; |
| 944 | | case CPUINFO_STR_REGISTER + APEXC_R: sprintf(info->s, "R :%08X", cpustate->r); break; |
| 945 | | case CPUINFO_STR_REGISTER + APEXC_ML: sprintf(info->s, "ML:%03X", cpustate->ml); break; |
| 946 | | case CPUINFO_STR_REGISTER + APEXC_PC: sprintf(info->s, "PC:%03X", cpustate->pc); break; |
| 947 | | case CPUINFO_STR_REGISTER + APEXC_WS: sprintf(info->s, "WS:%01X", cpustate->working_store); break; |
| 948 | 851 | |
| 949 | | case CPUINFO_STR_REGISTER + APEXC_STATE: sprintf(info->s, "CPU state:%01X", cpustate->running ? TRUE : FALSE); break; |
| 950 | | } |
| 852 | offs_t apexc_cpu_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) |
| 853 | { |
| 854 | extern CPU_DISASSEMBLE( apexc ); |
| 855 | return CPU_DISASSEMBLE_NAME(apexc)(this, buffer, pc, oprom, opram, options); |
| 951 | 856 | } |
| 952 | 857 | |
| 953 | | DEFINE_LEGACY_CPU_DEVICE(APEXC, apexc); |