src/emu/cpu/tms9900/tms9900.c
| r15461 | r15462 | |
| 117 | 117 | ST_IM = 0x000f // Interrupt mask |
| 118 | 118 | }; |
| 119 | 119 | |
| 120 | | enum |
| 121 | | { |
| 122 | | LOAD_INT = -1, |
| 123 | | RESET_INT = -2 |
| 124 | | }; |
| 125 | | |
| 126 | 120 | #define LOG logerror |
| 127 | 121 | #define VERBOSE 1 |
| 128 | 122 | |
| 129 | 123 | /**************************************************************************** |
| 130 | | Constructor |
| 124 | Common constructor for TMS9900 and TMS9980A |
| 125 | The CRU mask is related to the bits, not to their addresses which are |
| 126 | twice their number. Accordingly, the TMS9900 has a CRU bitmask 0x0fff. |
| 131 | 127 | ****************************************************************************/ |
| 132 | 128 | |
| 133 | | tms9900_device::tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 134 | | : cpu_device(mconfig, TMS9900, "TMS9900", tag, owner, clock), |
| 135 | | m_program_config("program", ENDIANNESS_BIG, 16, 16), |
| 136 | | m_io_config("cru", ENDIANNESS_BIG, 8, 16), |
| 129 | tms99xx_device::tms99xx_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, int databus_width, int prg_addr_bits, int cru_addr_bits, device_t *owner, UINT32 clock) |
| 130 | : cpu_device(mconfig, type, name, tag, owner, clock), |
| 131 | m_program_config("program", ENDIANNESS_BIG, databus_width, prg_addr_bits), |
| 132 | m_io_config("cru", ENDIANNESS_BIG, 8, cru_addr_bits), |
| 137 | 133 | m_prgspace(NULL), |
| 138 | | m_cru(NULL) |
| 134 | m_cru(NULL), |
| 135 | m_prgaddr_mask((1<<prg_addr_bits)-1), |
| 136 | m_cruaddr_mask((1<<cru_addr_bits)-1) |
| 139 | 137 | { |
| 140 | 138 | } |
| 141 | 139 | |
| 140 | tms99xx_device::~tms99xx_device() |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | /**************************************************************************** |
| 145 | Constructor for TMS9900 |
| 146 | ****************************************************************************/ |
| 147 | |
| 148 | tms9900_device::tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 149 | : tms99xx_device(mconfig, TMS9900, "TMS9900", tag, 16, 16, 12, owner, clock) |
| 150 | { |
| 151 | } |
| 152 | |
| 142 | 153 | enum |
| 143 | 154 | { |
| 144 | 155 | TMS9900_PC=0, TMS9900_WP, TMS9900_STATUS, TMS9900_IR, |
| r15461 | r15462 | |
| 148 | 159 | TMS9900_R12, TMS9900_R13, TMS9900_R14, TMS9900_R15 |
| 149 | 160 | }; |
| 150 | 161 | |
| 151 | | void tms9900_device::device_start() |
| 162 | void tms99xx_device::device_start() |
| 152 | 163 | { |
| 153 | | const tms9900_config *conf = reinterpret_cast<const tms9900_config *>(static_config()); |
| 164 | const tms99xx_config *conf = reinterpret_cast<const tms99xx_config *>(static_config()); |
| 154 | 165 | |
| 155 | 166 | assert (conf != NULL); |
| 156 | 167 | |
| r15461 | r15462 | |
| 161 | 172 | |
| 162 | 173 | // Resolve our external connections |
| 163 | 174 | m_external_operation.resolve(conf->external_callback, *this); |
| 164 | | m_get_ic0123.resolve(conf->irq_level, *this); |
| 175 | m_get_intlevel.resolve(conf->irq_level, *this); |
| 165 | 176 | m_iaq_line.resolve(conf->instruction_acquisition, *this); |
| 166 | 177 | m_clock_out_line.resolve(conf->clock_out, *this); |
| 167 | 178 | m_wait_line.resolve(conf->wait_line, *this); |
| r15461 | r15462 | |
| 183 | 194 | build_command_lookup_table(); |
| 184 | 195 | } |
| 185 | 196 | |
| 186 | | void tms9900_device::device_stop() |
| 197 | void tms99xx_device::device_stop() |
| 187 | 198 | { |
| 188 | 199 | int k = 0; |
| 189 | | if (VERBOSE>8) LOG("tms9900: Deleting lookup tables\n"); |
| 200 | if (VERBOSE>8) LOG("tms99xx: Deleting lookup tables\n"); |
| 190 | 201 | while (m_lotables[k]!=NULL) delete[] m_lotables[k++]; |
| 191 | 202 | } |
| 192 | 203 | |
| r15461 | r15462 | |
| 195 | 206 | The device reset is just the emulator's trigger for the reset procedure |
| 196 | 207 | which is invoked via the main loop. |
| 197 | 208 | */ |
| 198 | | void tms9900_device::device_reset() |
| 209 | void tms99xx_device::device_reset() |
| 199 | 210 | { |
| 211 | if (VERBOSE>3) LOG("tms99xx: Device reset\n"); |
| 200 | 212 | m_reset = true; |
| 201 | 213 | } |
| 202 | 214 | |
| 203 | | const char* tms9900_device::s_statename[20] = |
| 215 | const char* tms99xx_device::s_statename[20] = |
| 204 | 216 | { |
| 205 | 217 | "PC ", "WP ", "ST ", "IR ", |
| 206 | 218 | "R0 ", "R1 ", "R2 ", "R3 ", |
| r15461 | r15462 | |
| 212 | 224 | /* |
| 213 | 225 | Write the contents of a register by external input (debugger) |
| 214 | 226 | */ |
| 215 | | void tms9900_device::state_import(const device_state_entry &entry) |
| 227 | void tms99xx_device::state_import(const device_state_entry &entry) |
| 216 | 228 | { |
| 217 | 229 | int index = entry.index(); |
| 218 | 230 | switch (entry.index()) |
| r15461 | r15462 | |
| 222 | 234 | // bits of the STATUS register |
| 223 | 235 | break; |
| 224 | 236 | case TMS9900_PC: |
| 225 | | PC = (UINT16)m_state_any; |
| 237 | PC = (UINT16)(m_state_any & m_prgaddr_mask); |
| 226 | 238 | break; |
| 227 | 239 | case TMS9900_WP: |
| 228 | | WP = (UINT16)m_state_any; |
| 240 | WP = (UINT16)(m_state_any & m_prgaddr_mask); |
| 229 | 241 | break; |
| 230 | 242 | case TMS9900_STATUS: |
| 231 | 243 | ST = (UINT16)m_state_any; |
| r15461 | r15462 | |
| 244 | 256 | /* |
| 245 | 257 | Reads the contents of a register for display in the debugger. |
| 246 | 258 | */ |
| 247 | | void tms9900_device::state_export(const device_state_entry &entry) |
| 259 | void tms99xx_device::state_export(const device_state_entry &entry) |
| 248 | 260 | { |
| 249 | 261 | int index = entry.index(); |
| 250 | 262 | switch (entry.index()) |
| r15461 | r15462 | |
| 275 | 287 | /* |
| 276 | 288 | state_string_export - export state as a string for the debugger |
| 277 | 289 | */ |
| 278 | | void tms9900_device::state_string_export(const device_state_entry &entry, astring &string) |
| 290 | void tms99xx_device::state_string_export(const device_state_entry &entry, astring &string) |
| 279 | 291 | { |
| 280 | 292 | static const char *statestr = "LAECOPX-----IIII"; |
| 281 | 293 | char *flags = string.stringbuffer(16); |
| r15461 | r15462 | |
| 292 | 304 | |
| 293 | 305 | /**************************************************************************/ |
| 294 | 306 | |
| 295 | | UINT16 tms9900_device::read_workspace_register_debug(int reg) |
| 307 | UINT16 tms99xx_device::read_workspace_register_debug(int reg) |
| 296 | 308 | { |
| 297 | 309 | int temp = m_icount; |
| 298 | | UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & 0xfffe); |
| 310 | UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & m_prgaddr_mask & 0xfffe); |
| 299 | 311 | m_icount = temp; |
| 300 | 312 | return value; |
| 301 | 313 | } |
| 302 | 314 | |
| 303 | | void tms9900_device::write_workspace_register_debug(int reg, UINT16 data) |
| 315 | void tms99xx_device::write_workspace_register_debug(int reg, UINT16 data) |
| 304 | 316 | { |
| 305 | 317 | int temp = m_icount; |
| 306 | | m_prgspace->write_word((WP+(reg<<1)) & 0xfffe, data); |
| 318 | m_prgspace->write_word((WP+(reg<<1)) & m_prgaddr_mask & 0xfffe, data); |
| 307 | 319 | m_icount = temp; |
| 308 | 320 | } |
| 309 | 321 | |
| 310 | | const address_space_config *tms9900_device::memory_space_config(address_spacenum spacenum) const |
| 322 | const address_space_config *tms99xx_device::memory_space_config(address_spacenum spacenum) const |
| 311 | 323 | { |
| 312 | 324 | switch (spacenum) |
| 313 | 325 | { |
| r15461 | r15462 | |
| 342 | 354 | MEMORY_WRITE, |
| 343 | 355 | REG_READ, |
| 344 | 356 | REG_WRITE, |
| 345 | | CRU, // 5 |
| 357 | CRU_INPUT, |
| 358 | CRU_OUTPUT, |
| 346 | 359 | DATA_DERIVE, |
| 347 | 360 | RET, |
| 361 | ABORT, |
| 348 | 362 | END, |
| 363 | |
| 349 | 364 | ALU_NOP, |
| 350 | | ALU_CLR, // 10 |
| 365 | ALU_CLR, |
| 351 | 366 | ALU_SETADDR, |
| 352 | 367 | ALU_ADDONE, |
| 353 | 368 | ALU_SETADDR_ADDONE, |
| 354 | 369 | ALU_PCADDR_ADVANCE, |
| 355 | | ALU_SOURCE, // 15 |
| 370 | ALU_SOURCE, |
| 356 | 371 | ALU_ADDREG, |
| 357 | 372 | ALU_IMM, |
| 358 | 373 | ALU_REG, |
| 359 | 374 | ALU_F1, |
| 360 | | ALU_COMP, // 20 |
| 375 | ALU_COMP, |
| 361 | 376 | ALU_F3, |
| 362 | 377 | ALU_MPY, |
| 363 | 378 | ALU_DIV, |
| 364 | 379 | ALU_XOP, |
| 365 | | ALU_CLR_SWPB, // 25 |
| 380 | ALU_CLR_SWPB, |
| 366 | 381 | ALU_ABS, |
| 367 | 382 | ALU_X, |
| 368 | 383 | ALU_B, |
| 369 | | ALU_BL, |
| 370 | | ALU_BLWP, // 30 |
| 384 | ALU_BLWP, |
| 371 | 385 | ALU_LDCR, |
| 372 | 386 | ALU_STCR, |
| 373 | 387 | ALU_SBZ_SBO, |
| 374 | 388 | ALU_TB, |
| 375 | | ALU_JMP, // 35 |
| 389 | ALU_JMP, |
| 376 | 390 | ALU_SHIFT, |
| 377 | 391 | ALU_AI_ORI, |
| 378 | 392 | ALU_CI, |
| 379 | 393 | ALU_LI, |
| 380 | | ALU_LWPI, // 40 |
| 394 | ALU_LWPI, |
| 381 | 395 | ALU_LIMI, |
| 382 | 396 | ALU_STWP_STST, |
| 383 | 397 | ALU_EXT, |
| 384 | 398 | ALU_RTWP, |
| 385 | | ALU_INT // 45 |
| 399 | ALU_INT |
| 386 | 400 | }; |
| 387 | 401 | |
| 388 | 402 | |
| r15461 | r15462 | |
| 436 | 450 | ALU_NOP, |
| 437 | 451 | DATA_DERIVE, |
| 438 | 452 | ALU_F3, |
| 439 | | REG_READ, // We have to distinguish this from the C/CB microprogram above |
| 453 | MEMORY_READ, // We have to distinguish this from the C/CB microprogram above |
| 440 | 454 | ALU_F3, |
| 441 | 455 | ALU_NOP, // Compare operations do not write back any data |
| 442 | 456 | END |
| r15461 | r15462 | |
| 447 | 461 | ALU_NOP, |
| 448 | 462 | DATA_DERIVE, |
| 449 | 463 | ALU_F3, |
| 450 | | REG_READ, |
| 464 | MEMORY_READ, |
| 451 | 465 | ALU_F3, |
| 452 | | MEMORY_WRITE, // XOR again must write back data |
| 466 | MEMORY_WRITE, // XOR again must write back data, cannot reuse f3_mp |
| 453 | 467 | END |
| 454 | 468 | }; |
| 455 | 469 | |
| r15461 | r15462 | |
| 458 | 472 | ALU_NOP, |
| 459 | 473 | DATA_DERIVE, |
| 460 | 474 | ALU_MPY, // Save the value; put register number in m_regnumber |
| 461 | | REG_READ, |
| 475 | MEMORY_READ, |
| 462 | 476 | ALU_MPY, // 18 cycles for multiplication |
| 463 | | REG_WRITE, // Write the high word |
| 477 | MEMORY_WRITE, // Write the high word |
| 464 | 478 | ALU_MPY, // Get low word, increase m_address |
| 465 | 479 | MEMORY_WRITE, |
| 466 | 480 | END |
| r15461 | r15462 | |
| 471 | 485 | ALU_NOP, |
| 472 | 486 | DATA_DERIVE, // Get divisor |
| 473 | 487 | ALU_DIV, // 0 Store divisor and get register number |
| 474 | | REG_READ, // Read register |
| 488 | MEMORY_READ, // Read register |
| 475 | 489 | ALU_DIV, // 1 Check overflow, increase address (or abort here) |
| 490 | ABORT, |
| 476 | 491 | MEMORY_READ, // Read subsequent word (if reg=15 this is behind the workspace) |
| 477 | 492 | ALU_DIV, // 2 Calculate quotient (takes variable amount of cycles; at least 32 machine cycles), set register number |
| 478 | | REG_WRITE, // Write quotient into register |
| 493 | MEMORY_WRITE, // Write quotient into register |
| 479 | 494 | ALU_DIV, // 3 Get remainder |
| 480 | 495 | MEMORY_WRITE, // Write remainder |
| 481 | 496 | END |
| r15461 | r15462 | |
| 488 | 503 | ALU_XOP, // 0 Save the address of the source operand, set address = 0x0040 + xopNr*4 |
| 489 | 504 | MEMORY_READ, // Read the new WP |
| 490 | 505 | ALU_XOP, // 1 Save old WP, set new WP, get the source operand address |
| 491 | | REG_WRITE, // Write the address of the source operand into the new R11 |
| 506 | MEMORY_WRITE, // Write the address of the source operand into the new R11 |
| 492 | 507 | ALU_XOP, // 2 |
| 493 | | REG_WRITE, // Write the ST into the new R15 |
| 508 | MEMORY_WRITE, // Write the ST into the new R15 |
| 494 | 509 | ALU_XOP, // 3 |
| 495 | | REG_WRITE, // Write the PC into the new R14 |
| 510 | MEMORY_WRITE, // Write the PC into the new R14 |
| 496 | 511 | ALU_XOP, // 4 |
| 497 | | REG_WRITE, // Write the WP into the new R13 |
| 512 | MEMORY_WRITE, // Write the WP into the new R13 |
| 498 | 513 | ALU_XOP, // 5 Set the X bit in the ST |
| 499 | 514 | MEMORY_READ, // Read the new PC |
| 500 | 515 | ALU_XOP, // 6 Set the new PC |
| r15461 | r15462 | |
| 541 | 556 | { |
| 542 | 557 | ALU_NOP, |
| 543 | 558 | DATA_DERIVE, |
| 544 | | ALU_BL, // two cycles |
| 545 | | REG_WRITE, |
| 559 | ALU_B, |
| 560 | MEMORY_WRITE, |
| 561 | ALU_NOP, |
| 546 | 562 | END |
| 547 | 563 | }; |
| 548 | 564 | |
| r15461 | r15462 | |
| 551 | 567 | ALU_NOP, |
| 552 | 568 | DATA_DERIVE, // Get argument |
| 553 | 569 | ALU_BLWP, // 0 Save old WP, set new WP, save position |
| 554 | | REG_WRITE, // write ST to R15 |
| 570 | MEMORY_WRITE, // write ST to R15 |
| 555 | 571 | ALU_BLWP, // 1 |
| 556 | | REG_WRITE, // write PC to R14 |
| 572 | MEMORY_WRITE, // write PC to R14 |
| 557 | 573 | ALU_BLWP, // 2 |
| 558 | | REG_WRITE, // write WP to R13 |
| 574 | MEMORY_WRITE, // write WP to R13 |
| 559 | 575 | ALU_BLWP, // 3 Get saved position |
| 560 | 576 | MEMORY_READ, // Read new PC |
| 561 | 577 | ALU_BLWP, // 4 Set new PC |
| r15461 | r15462 | |
| 569 | 585 | ALU_SOURCE, |
| 570 | 586 | ALU_NOP, |
| 571 | 587 | ALU_LDCR, |
| 572 | | REG_READ, |
| 588 | MEMORY_READ, |
| 573 | 589 | ALU_LDCR, |
| 574 | | CRU, |
| 590 | CRU_OUTPUT, |
| 575 | 591 | ALU_NOP, |
| 576 | 592 | END |
| 577 | 593 | }; |
| r15461 | r15462 | |
| 582 | 598 | DATA_DERIVE, |
| 583 | 599 | ALU_SOURCE, // Store address and value |
| 584 | 600 | ALU_STCR, // 0 Set register_number = 12 |
| 585 | | REG_READ, |
| 601 | MEMORY_READ, |
| 586 | 602 | ALU_STCR, // 1 Prepare CRU access |
| 587 | | CRU, |
| 603 | CRU_INPUT, |
| 588 | 604 | ALU_STCR, // 2 Create result; Cycles = 5 + (8-#C-1) or + (16-#C) |
| 589 | 605 | MEMORY_WRITE, |
| 590 | 606 | END |
| r15461 | r15462 | |
| 593 | 609 | MICROPROGRAM(sbz_sbo_mp) |
| 594 | 610 | { |
| 595 | 611 | ALU_SBZ_SBO, |
| 596 | | REG_READ, |
| 612 | MEMORY_READ, |
| 597 | 613 | ALU_SBZ_SBO, |
| 598 | | CRU, |
| 614 | CRU_OUTPUT, |
| 599 | 615 | END |
| 600 | 616 | }; |
| 601 | 617 | |
| 602 | 618 | MICROPROGRAM(tb_mp) |
| 603 | 619 | { |
| 604 | 620 | ALU_TB, |
| 605 | | REG_READ, |
| 621 | MEMORY_READ, |
| 606 | 622 | ALU_TB, |
| 607 | | CRU, |
| 623 | CRU_INPUT, |
| 608 | 624 | ALU_TB, |
| 609 | 625 | END |
| 610 | 626 | }; |
| r15461 | r15462 | |
| 621 | 637 | MICROPROGRAM(shift_mp) |
| 622 | 638 | { |
| 623 | 639 | ALU_SHIFT, |
| 624 | | REG_READ, |
| 640 | MEMORY_READ, |
| 625 | 641 | ALU_SHIFT, |
| 626 | | REG_READ, |
| 642 | MEMORY_READ, |
| 627 | 643 | ALU_SHIFT, |
| 628 | | REG_WRITE, |
| 644 | MEMORY_WRITE, |
| 629 | 645 | END |
| 630 | 646 | }; |
| 631 | 647 | |
| 632 | 648 | MICROPROGRAM(ai_ori_mp) |
| 633 | 649 | { |
| 634 | 650 | ALU_REG, |
| 635 | | REG_READ, |
| 651 | MEMORY_READ, |
| 636 | 652 | ALU_IMM, |
| 637 | 653 | MEMORY_READ, |
| 638 | 654 | ALU_AI_ORI, |
| 639 | | REG_WRITE, |
| 655 | MEMORY_WRITE, |
| 640 | 656 | END |
| 641 | 657 | }; |
| 642 | 658 | |
| 643 | 659 | MICROPROGRAM(ci_mp) |
| 644 | 660 | { |
| 645 | 661 | ALU_REG, |
| 646 | | REG_READ, |
| 662 | MEMORY_READ, |
| 647 | 663 | ALU_IMM, |
| 648 | 664 | MEMORY_READ, |
| 649 | 665 | ALU_CI, |
| r15461 | r15462 | |
| 657 | 673 | MEMORY_READ, |
| 658 | 674 | ALU_LI, // sets status bits |
| 659 | 675 | ALU_REG, // set register number |
| 660 | | REG_WRITE, |
| 676 | MEMORY_WRITE, |
| 661 | 677 | END |
| 662 | 678 | }; |
| 663 | 679 | |
| r15461 | r15462 | |
| 685 | 701 | { |
| 686 | 702 | ALU_STWP_STST, |
| 687 | 703 | ALU_REG, |
| 688 | | REG_WRITE, |
| 704 | MEMORY_WRITE, |
| 689 | 705 | END |
| 690 | 706 | }; |
| 691 | 707 | |
| r15461 | r15462 | |
| 698 | 714 | MICROPROGRAM(rtwp_mp) // Problem: This makes RTWP use 8 instead of 7 machine cycles. |
| 699 | 715 | { |
| 700 | 716 | ALU_RTWP, |
| 701 | | REG_READ, |
| 717 | MEMORY_READ, |
| 702 | 718 | ALU_RTWP, |
| 703 | | REG_READ, |
| 719 | MEMORY_READ, |
| 704 | 720 | ALU_RTWP, |
| 705 | | REG_READ, |
| 721 | MEMORY_READ, |
| 706 | 722 | ALU_RTWP, |
| 707 | 723 | END |
| 708 | 724 | }; |
| r15461 | r15462 | |
| 713 | 729 | ALU_INT, // 0 Set address = 0 |
| 714 | 730 | MEMORY_READ, |
| 715 | 731 | ALU_INT, // 1 Save old WP, set new WP, save position |
| 716 | | REG_WRITE, // write ST to R15 |
| 732 | MEMORY_WRITE, // write ST to R15 |
| 717 | 733 | ALU_INT, // 2 |
| 718 | | REG_WRITE, // write PC to R14 |
| 734 | MEMORY_WRITE, // write PC to R14 |
| 719 | 735 | ALU_INT, // 3 |
| 720 | | REG_WRITE, // write WP to R13 |
| 736 | MEMORY_WRITE, // write WP to R13 |
| 721 | 737 | ALU_INT, // 4 Get saved position |
| 722 | 738 | MEMORY_READ, // Read new PC |
| 723 | 739 | ALU_INT, // 5 Set new PC |
| 724 | 740 | END |
| 725 | 741 | }; |
| 726 | 742 | |
| 727 | | const tms9900_device::ophandler tms9900_device::s_microoperation[] = |
| 743 | const tms99xx_device::ophandler tms99xx_device::s_microoperation[] = |
| 728 | 744 | { |
| 729 | | &tms9900_device::acquire_instruction, |
| 730 | | &tms9900_device::mem_read, |
| 731 | | &tms9900_device::mem_write, |
| 732 | | &tms9900_device::register_read, |
| 733 | | &tms9900_device::register_write, |
| 734 | | &tms9900_device::cru_operation, |
| 735 | | &tms9900_device::data_derivation_subprogram, |
| 736 | | &tms9900_device::return_from_subprogram, |
| 737 | | &tms9900_device::command_completed, |
| 745 | &tms99xx_device::acquire_instruction, |
| 746 | &tms99xx_device::mem_read, |
| 747 | &tms99xx_device::mem_write, |
| 748 | &tms99xx_device::register_read, |
| 749 | &tms99xx_device::register_write, |
| 750 | &tms99xx_device::cru_input_operation, |
| 751 | &tms99xx_device::cru_output_operation, |
| 752 | &tms99xx_device::data_derivation_subprogram, |
| 753 | &tms99xx_device::return_from_subprogram, |
| 754 | &tms99xx_device::abort_operation, |
| 755 | &tms99xx_device::command_completed, |
| 738 | 756 | |
| 739 | | &tms9900_device::alu_nop, |
| 740 | | &tms9900_device::alu_clear, |
| 741 | | &tms9900_device::alu_setaddr, |
| 742 | | &tms9900_device::alu_addone, |
| 743 | | &tms9900_device::alu_setaddr_addone, |
| 744 | | &tms9900_device::alu_pcaddr_advance, |
| 745 | | &tms9900_device::alu_source, |
| 746 | | &tms9900_device::alu_add_register, |
| 747 | | &tms9900_device::alu_imm, |
| 748 | | &tms9900_device::alu_reg, |
| 757 | &tms99xx_device::alu_nop, |
| 758 | &tms99xx_device::alu_clear, |
| 759 | &tms99xx_device::alu_setaddr, |
| 760 | &tms99xx_device::alu_addone, |
| 761 | &tms99xx_device::alu_setaddr_addone, |
| 762 | &tms99xx_device::alu_pcaddr_advance, |
| 763 | &tms99xx_device::alu_source, |
| 764 | &tms99xx_device::alu_add_register, |
| 765 | &tms99xx_device::alu_imm, |
| 766 | &tms99xx_device::alu_reg, |
| 749 | 767 | |
| 750 | | &tms9900_device::alu_f1, |
| 751 | | &tms9900_device::alu_comp, |
| 752 | | &tms9900_device::alu_f3, |
| 753 | | &tms9900_device::alu_multiply, |
| 754 | | &tms9900_device::alu_divide, |
| 755 | | &tms9900_device::alu_xop, |
| 756 | | &tms9900_device::alu_clr_swpb, |
| 757 | | &tms9900_device::alu_abs, |
| 758 | | &tms9900_device::alu_x, |
| 759 | | &tms9900_device::alu_b, |
| 760 | | &tms9900_device::alu_bl, |
| 761 | | &tms9900_device::alu_blwp, |
| 762 | | &tms9900_device::alu_ldcr, |
| 763 | | &tms9900_device::alu_stcr, |
| 764 | | &tms9900_device::alu_sbz_sbo, |
| 765 | | &tms9900_device::alu_tb, |
| 766 | | &tms9900_device::alu_jmp, |
| 767 | | &tms9900_device::alu_shift, |
| 768 | | &tms9900_device::alu_ai_ori, |
| 769 | | &tms9900_device::alu_ci, |
| 770 | | &tms9900_device::alu_li, |
| 771 | | &tms9900_device::alu_lwpi, |
| 772 | | &tms9900_device::alu_limi, |
| 773 | | &tms9900_device::alu_stwp_stst, |
| 774 | | &tms9900_device::alu_external, |
| 775 | | &tms9900_device::alu_rtwp, |
| 776 | | &tms9900_device::alu_int |
| 768 | &tms99xx_device::alu_f1, |
| 769 | &tms99xx_device::alu_comp, |
| 770 | &tms99xx_device::alu_f3, |
| 771 | &tms99xx_device::alu_multiply, |
| 772 | &tms99xx_device::alu_divide, |
| 773 | &tms99xx_device::alu_xop, |
| 774 | &tms99xx_device::alu_clr_swpb, |
| 775 | &tms99xx_device::alu_abs, |
| 776 | &tms99xx_device::alu_x, |
| 777 | &tms99xx_device::alu_b, |
| 778 | &tms99xx_device::alu_blwp, |
| 779 | &tms99xx_device::alu_ldcr, |
| 780 | &tms99xx_device::alu_stcr, |
| 781 | &tms99xx_device::alu_sbz_sbo, |
| 782 | &tms99xx_device::alu_tb, |
| 783 | &tms99xx_device::alu_jmp, |
| 784 | &tms99xx_device::alu_shift, |
| 785 | &tms99xx_device::alu_ai_ori, |
| 786 | &tms99xx_device::alu_ci, |
| 787 | &tms99xx_device::alu_li, |
| 788 | &tms99xx_device::alu_lwpi, |
| 789 | &tms99xx_device::alu_limi, |
| 790 | &tms99xx_device::alu_stwp_stst, |
| 791 | &tms99xx_device::alu_external, |
| 792 | &tms99xx_device::alu_rtwp, |
| 793 | &tms99xx_device::alu_int |
| 777 | 794 | }; |
| 778 | 795 | |
| 779 | 796 | /***************************************************************************** |
| r15461 | r15462 | |
| 791 | 808 | JLT, JMP, JNC, JNE, JNO, JOC, JOP, LDCR, LI, LIMI, |
| 792 | 809 | LREX, LWPI, MOV, MOVB, MPY, NEG, ORI, RSET, RTWP, S, |
| 793 | 810 | SB, SBO, SBZ, SETO, SLA, SOC, SOCB, SRA, SRC, SRL, |
| 794 | | STCR, STST, STWP, SWPB, SZC, SZCB, TB, X, XOP, XOR |
| 811 | STCR, STST, STWP, SWPB, SZC, SZCB, TB, X, XOP, XOR, |
| 812 | INTR |
| 795 | 813 | }; |
| 796 | 814 | |
| 797 | | static const char opname[][5] = |
| 798 | | { "ILL ", "A ", "AB ", "ABS ", "AI ", "ANDI", "B ", "BL ", "BLWP", "C ", |
| 799 | | "CI ", "CB ", "CKOF", "CKON", "CLR ", "COC ", "CZC ", "DEC ", "DECT", "DIV ", |
| 800 | | "IDLE", "INC ", "INCT", "INV ", "JEQ ", "JGT ", "JH ", "JHE ", "JL ", "JLE ", |
| 801 | | "JLT ", "JMP ", "JNC ", "JNE ", "JNO ", "JOC ", "JOP ", "LDCR", "LI ", "LIMI", |
| 802 | | "LREX", "LWPI", "MOV ", "MOVB", "MPY ", "NEG ", "ORI ", "RSET", "RTWP", "S ", |
| 803 | | "SB ", "SBO ", "SBZ ", "SETO", "SLA ", "SOC ", "SOCB", "SRA ", "SRC ", "SRL ", |
| 804 | | "STCR", "STST", "STWP", "SWPB", "SZC ", "SZCB", "TB ", "X ", "XOP ", "XOR " |
| 805 | | }; |
| 806 | | |
| 807 | 815 | /* |
| 808 | 816 | Formats: |
| 809 | 817 | |
| r15461 | r15462 | |
| 838 | 846 | 0, 4, 8, 6, 6, 8, 10, 16, 12, 6 |
| 839 | 847 | }; |
| 840 | 848 | |
| 841 | | const tms9900_device::tms_instruction tms9900_device::s_command[] = |
| 849 | const tms99xx_device::tms_instruction tms99xx_device::s_command[] = |
| 842 | 850 | { |
| 843 | 851 | // Opcode, ID, format, microprg |
| 844 | 852 | { 0x0200, LI, 8, li_mp }, |
| r15461 | r15462 | |
| 947 | 955 | list at runtime, and many positions are empty. But we do not need more |
| 948 | 956 | than 20 tables for the TMS command set. |
| 949 | 957 | */ |
| 950 | | void tms9900_device::build_command_lookup_table() |
| 958 | void tms99xx_device::build_command_lookup_table() |
| 951 | 959 | { |
| 952 | 960 | int i = 0; |
| 953 | 961 | int cmdindex = 0; |
| r15461 | r15462 | |
| 972 | 980 | { |
| 973 | 981 | inst = &s_command[i]; |
| 974 | 982 | table = m_command_lookup_table; |
| 975 | | if (VERBOSE>8) LOG("tms9900: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]); |
| 983 | if (VERBOSE>8) LOG("tms99xx: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]); |
| 976 | 984 | bitcount = 4; |
| 977 | 985 | opcode = inst->opcode; |
| 978 | 986 | cmdindex = (opcode>>12) & 0x000f; |
| r15461 | r15462 | |
| 982 | 990 | // Descend |
| 983 | 991 | if (table[cmdindex].next_digit == NULL) |
| 984 | 992 | { |
| 985 | | if (VERBOSE>8) LOG("tms9900: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex); |
| 993 | if (VERBOSE>8) LOG("tms99xx: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex); |
| 986 | 994 | table[cmdindex].next_digit = new lookup_entry[16]; |
| 987 | 995 | m_lotables[k++] = table[cmdindex].next_digit; |
| 988 | 996 | for (int j=0; j < 16; j++) |
| r15461 | r15462 | |
| 993 | 1001 | } |
| 994 | 1002 | else |
| 995 | 1003 | { |
| 996 | | if (VERBOSE>8) LOG("tms9900: found a table at bitcount=%d\n", bitcount); |
| 1004 | if (VERBOSE>8) LOG("tms99xx: found a table at bitcount=%d\n", bitcount); |
| 997 | 1005 | } |
| 998 | 1006 | |
| 999 | 1007 | table = table[cmdindex].next_digit; |
| r15461 | r15462 | |
| 1001 | 1009 | bitcount = bitcount+4; |
| 1002 | 1010 | opcode <<= 4; |
| 1003 | 1011 | cmdindex = (opcode>>12) & 0x000f; |
| 1004 | | if (VERBOSE>8) LOG("tms9900: next index=%x\n", cmdindex); |
| 1012 | if (VERBOSE>8) LOG("tms99xx: next index=%x\n", cmdindex); |
| 1005 | 1013 | } |
| 1006 | 1014 | |
| 1007 | | if (VERBOSE>8) LOG("tms9900: bitcount=%d\n", bitcount); |
| 1015 | if (VERBOSE>8) LOG("tms99xx: bitcount=%d\n", bitcount); |
| 1008 | 1016 | // We are at the target level |
| 1009 | 1017 | // Need to fill in the same entry for all values in the bitcount |
| 1010 | 1018 | // (if a command needs 10 bits we have to copy it four |
| 1011 | 1019 | // times for all combinations with 12 bits) |
| 1012 | 1020 | for (int j=0; j < (1<<(bitcount-format_mask_len[inst->format])); j++) |
| 1013 | 1021 | { |
| 1014 | | if (VERBOSE>8) LOG("tms9900: opcode=%04x at position %d\n", inst->opcode, cmdindex+j); |
| 1022 | if (VERBOSE>8) LOG("tms99xx: opcode=%04x at position %d\n", inst->opcode, cmdindex+j); |
| 1015 | 1023 | table[cmdindex+j].entry = inst; |
| 1016 | 1024 | } |
| 1017 | 1025 | |
| r15461 | r15462 | |
| 1019 | 1027 | } while (inst->opcode != 0xf000); |
| 1020 | 1028 | |
| 1021 | 1029 | m_lotables[k++] = NULL; |
| 1022 | | if (VERBOSE>8) LOG("tms9900: Allocated %d tables\n", k); |
| 1030 | if (VERBOSE>8) LOG("tms99xx: Allocated %d tables\n", k); |
| 1023 | 1031 | } |
| 1024 | 1032 | |
| 1025 | 1033 | /* |
| r15461 | r15462 | |
| 1058 | 1066 | the CPU checks the READY line and waits until it is high. When READY |
| 1059 | 1067 | is high at a clock tick, the operation is complete on the next clock tick. |
| 1060 | 1068 | */ |
| 1061 | | void tms9900_device::execute_run() |
| 1069 | void tms99xx_device::execute_run() |
| 1062 | 1070 | { |
| 1063 | 1071 | if (m_reset) service_interrupt(); |
| 1064 | 1072 | |
| 1065 | | if (VERBOSE>6) LOG("tms9900: calling execute_run for %d cycles\n", m_icount); |
| 1073 | if (VERBOSE>6) LOG("tms99xx: calling execute_run for %d cycles\n", m_icount); |
| 1066 | 1074 | do |
| 1067 | 1075 | { |
| 1068 | 1076 | // Only when last instruction has completed |
| r15461 | r15462 | |
| 1070 | 1078 | { |
| 1071 | 1079 | if (m_load_state) |
| 1072 | 1080 | { |
| 1073 | | if (VERBOSE>4) LOG("tms9900: load interrupt\n"); |
| 1081 | if (VERBOSE>4) LOG("tms99xx: LOAD interrupt\n"); |
| 1074 | 1082 | service_interrupt(); |
| 1075 | 1083 | } |
| 1076 | 1084 | else |
| r15461 | r15462 | |
| 1086 | 1094 | |
| 1087 | 1095 | if (m_program == NULL && m_idle_state) |
| 1088 | 1096 | { |
| 1089 | | if (VERBOSE>5) LOG("tms9900: idle state\n"); |
| 1097 | if (VERBOSE>5) LOG("tms99xx: idle state\n"); |
| 1090 | 1098 | pulse_clock(1); |
| 1099 | m_external_operation(IDLE_OP, 0); |
| 1100 | m_external_operation(IDLE_OP, 1); |
| 1091 | 1101 | } |
| 1092 | 1102 | else |
| 1093 | 1103 | { |
| r15461 | r15462 | |
| 1100 | 1110 | m_program[MPC] != MEMORY_READ && m_program[MPC] != MEMORY_WRITE && |
| 1101 | 1111 | m_program[MPC] != REG_READ && m_program[MPC] != REG_WRITE))) |
| 1102 | 1112 | { |
| 1103 | | if (VERBOSE>5) LOG("tms9900: hold state\n"); |
| 1113 | if (VERBOSE>5) LOG("tms99xx: hold state\n"); |
| 1104 | 1114 | if (!m_hold_acknowledged) acknowledge_hold(); |
| 1105 | 1115 | pulse_clock(1); |
| 1106 | 1116 | } |
| r15461 | r15462 | |
| 1111 | 1121 | { |
| 1112 | 1122 | // We are in a wait state |
| 1113 | 1123 | set_wait_state(true); |
| 1114 | | if (VERBOSE>5) LOG("tms9900: wait state\n"); |
| 1124 | if (VERBOSE>5) LOG("tms99xx: wait state\n"); |
| 1115 | 1125 | // The clock output should be used to change the state of an outer |
| 1116 | 1126 | // device which operates the READY line |
| 1117 | 1127 | pulse_clock(1); |
| r15461 | r15462 | |
| 1125 | 1135 | else |
| 1126 | 1136 | { |
| 1127 | 1137 | m_op = m_program[MPC]; |
| 1128 | | m_iaq_line(CLEAR_LINE); |
| 1129 | 1138 | } |
| 1130 | | if (VERBOSE>8) LOG("tms9900: MPC = %d, m_op = %d\n", MPC, m_op); |
| 1139 | if (VERBOSE>8) LOG("tms99xx: MPC = %d, m_op = %d\n", MPC, m_op); |
| 1131 | 1140 | // Call the operation of the microprogram |
| 1132 | 1141 | (this->*s_microoperation[m_op])(); |
| 1133 | | MPC++; |
| 1142 | // If we have multiple passes (as in the TMS9980) |
| 1143 | m_pass--; |
| 1144 | if (m_pass<=0) |
| 1145 | { |
| 1146 | m_pass = 1; |
| 1147 | MPC++; |
| 1148 | m_iaq_line(CLEAR_LINE); |
| 1149 | } |
| 1134 | 1150 | } |
| 1135 | 1151 | } |
| 1136 | 1152 | } |
| 1137 | 1153 | } while (m_icount>0); |
| 1138 | | if (VERBOSE>6) LOG("tms9900: cycles expired; will return soon.\n"); |
| 1154 | if (VERBOSE>6) LOG("tms99xx: cycles expired; will return soon.\n"); |
| 1139 | 1155 | } |
| 1140 | 1156 | |
| 1141 | 1157 | /**************************************************************************/ |
| r15461 | r15462 | |
| 1143 | 1159 | /* |
| 1144 | 1160 | Interrupt input |
| 1145 | 1161 | */ |
| 1146 | | void tms9900_device::execute_set_input(int irqline, int state) |
| 1162 | void tms99xx_device::execute_set_input(int irqline, int state) |
| 1147 | 1163 | { |
| 1148 | 1164 | if (irqline == INPUT_LINE_NMI) |
| 1149 | 1165 | { |
| r15461 | r15462 | |
| 1155 | 1171 | m_irq_state = (state==ASSERT_LINE); |
| 1156 | 1172 | if (state==ASSERT_LINE) |
| 1157 | 1173 | { |
| 1158 | | m_irq_level = m_get_ic0123(0); |
| 1159 | | if (VERBOSE>6) LOG("tms9900: interrupt line %d = %d, level=%d, ST=%04x\n", irqline, state, m_irq_level, ST); |
| 1174 | m_irq_level = get_intlevel(state); |
| 1175 | if (VERBOSE>6) LOG("tms99xx: interrupt line %d = %d, level=%d, ST=%04x\n", irqline, state, m_irq_level, ST); |
| 1160 | 1176 | } |
| 1161 | 1177 | else |
| 1162 | 1178 | { |
| 1163 | | if (VERBOSE>6) LOG("tms9900: cleared interrupt line %d\n", irqline); |
| 1179 | if (VERBOSE>6) LOG("tms99xx: cleared interrupt line %d\n", irqline); |
| 1164 | 1180 | } |
| 1165 | 1181 | } |
| 1166 | 1182 | } |
| 1167 | 1183 | |
| 1168 | | void tms9900_device::service_interrupt() |
| 1184 | /* |
| 1185 | This can be overloaded by variants of TMS99xx. |
| 1186 | */ |
| 1187 | int tms99xx_device::get_intlevel(int state) |
| 1169 | 1188 | { |
| 1189 | return m_get_intlevel(0); |
| 1190 | } |
| 1191 | |
| 1192 | void tms99xx_device::service_interrupt() |
| 1193 | { |
| 1170 | 1194 | m_program = int_mp; |
| 1171 | | MPC = 0; |
| 1195 | m_command = INTR; |
| 1172 | 1196 | m_idle_state = false; |
| 1173 | | m_first_cycle = m_icount; |
| 1197 | m_external_operation(IDLE_OP, 0); |
| 1198 | m_lowbyte = false; |
| 1199 | |
| 1174 | 1200 | m_state = 0; |
| 1201 | |
| 1202 | // If reset, we just start with execution, otherwise we put the MPC |
| 1203 | // on the first microinstruction, which also means that the main loop shall |
| 1204 | // leave it where it is. So we pretend we have another pass to do. |
| 1205 | m_pass = m_reset? 1 : 2; |
| 1206 | |
| 1175 | 1207 | if (m_reset) |
| 1176 | 1208 | { |
| 1209 | m_irq_level = RESET_INT; |
| 1210 | |
| 1177 | 1211 | m_ready_state = true; |
| 1178 | 1212 | m_load_state = false; |
| 1179 | 1213 | m_hold_state = false; |
| r15461 | r15462 | |
| 1183 | 1217 | ST = 0; |
| 1184 | 1218 | |
| 1185 | 1219 | m_reset = false; |
| 1186 | | m_irq_level = RESET_INT; |
| 1187 | 1220 | } |
| 1188 | | if (VERBOSE>6) LOG("tms9900: ********* triggered an interrupt on level %d\n", m_irq_level); |
| 1221 | if (VERBOSE>6) LOG("tms99xx: ********* triggered an interrupt on level %d\n", m_irq_level); |
| 1222 | |
| 1223 | MPC = 0; |
| 1224 | m_first_cycle = m_icount; |
| 1189 | 1225 | } |
| 1190 | 1226 | |
| 1191 | 1227 | /* |
| 1192 | 1228 | Issue a pulse on the clock line. |
| 1193 | 1229 | */ |
| 1194 | | inline void tms9900_device::pulse_clock(int count) |
| 1230 | void tms99xx_device::pulse_clock(int count) |
| 1195 | 1231 | { |
| 1196 | 1232 | for (int i=0; i < count; i++) |
| 1197 | 1233 | { |
| 1198 | 1234 | m_clock_out_line(ASSERT_LINE); |
| 1199 | 1235 | m_clock_out_line(CLEAR_LINE); |
| 1200 | 1236 | m_icount--; // This is the only location where we count down the cycles. |
| 1201 | | if (VERBOSE>7) LOG("tms9900: pulse_clock\n"); |
| 1237 | if (VERBOSE>7) LOG("tms99xx: pulse_clock\n"); |
| 1202 | 1238 | } |
| 1203 | 1239 | } |
| 1204 | 1240 | |
| 1205 | 1241 | /* |
| 1206 | 1242 | Enter the hold state. |
| 1207 | 1243 | */ |
| 1208 | | void tms9900_device::set_hold(int state) |
| 1244 | void tms99xx_device::set_hold(int state) |
| 1209 | 1245 | { |
| 1210 | 1246 | m_hold_state = (state==ASSERT_LINE); |
| 1211 | 1247 | if (!m_hold_state) |
| r15461 | r15462 | |
| 1218 | 1254 | /* |
| 1219 | 1255 | Acknowledge the HOLD request. |
| 1220 | 1256 | */ |
| 1221 | | inline void tms9900_device::acknowledge_hold() |
| 1257 | inline void tms99xx_device::acknowledge_hold() |
| 1222 | 1258 | { |
| 1223 | 1259 | m_hold_acknowledged = true; |
| 1224 | 1260 | m_holda_line(ASSERT_LINE); |
| r15461 | r15462 | |
| 1227 | 1263 | /* |
| 1228 | 1264 | Signal READY to the CPU. When cleared, the CPU enters wait states. |
| 1229 | 1265 | */ |
| 1230 | | void tms9900_device::set_ready(int state) |
| 1266 | void tms99xx_device::set_ready(int state) |
| 1231 | 1267 | { |
| 1232 | 1268 | m_ready_state = (state==ASSERT_LINE); |
| 1233 | 1269 | } |
| 1234 | 1270 | |
| 1235 | | void tms9900_device::abort_operation() |
| 1271 | void tms99xx_device::abort_operation() |
| 1236 | 1272 | { |
| 1237 | 1273 | command_completed(); |
| 1238 | 1274 | } |
| r15461 | r15462 | |
| 1240 | 1276 | /* |
| 1241 | 1277 | Enter or leave the wait state. We only operate the WAIT line when there is a change. |
| 1242 | 1278 | */ |
| 1243 | | inline void tms9900_device::set_wait_state(bool state) |
| 1279 | inline void tms99xx_device::set_wait_state(bool state) |
| 1244 | 1280 | { |
| 1245 | 1281 | if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE); |
| 1246 | 1282 | m_wait_state = state; |
| 1247 | 1283 | } |
| 1248 | 1284 | |
| 1249 | 1285 | /* |
| 1250 | | Memory read: |
| 1251 | | 1) Pulse clock (done above) |
| 1252 | | 2) Set address (we also get the value right here) |
| 1253 | | 3) Pulse clock |
| 1254 | | 4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP) |
| 1255 | | |
| 1256 | | Clock cycles: 2 + W, W = number of wait states |
| 1257 | | */ |
| 1258 | | UINT16 tms9900_device::pulse_and_read_memory(UINT16 address) |
| 1259 | | { |
| 1260 | | UINT16 value; |
| 1261 | | value = m_prgspace->read_word(address & 0xfffe); |
| 1262 | | pulse_clock(2); |
| 1263 | | m_check_ready = true; |
| 1264 | | return value; |
| 1265 | | } |
| 1266 | | |
| 1267 | | /* |
| 1268 | | Memory write: |
| 1269 | | 1) Pulse clock |
| 1270 | | 2) Set address and write (as in the real system) |
| 1271 | | 3) Pulse clock |
| 1272 | | 4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP) |
| 1273 | | |
| 1274 | | Clock cycles: 2 + W, W = number of wait states |
| 1275 | | */ |
| 1276 | | void tms9900_device::pulse_and_write_memory(UINT16 address, UINT16 data) |
| 1277 | | { |
| 1278 | | m_prgspace->write_word(address & 0xfffe, data); |
| 1279 | | pulse_clock(2); |
| 1280 | | m_check_ready = true; |
| 1281 | | } |
| 1282 | | |
| 1283 | | |
| 1284 | | /* |
| 1285 | 1286 | Acquire the next word as an instruction. The program counter advances by |
| 1286 | 1287 | one word. |
| 1287 | 1288 | */ |
| 1288 | | void tms9900_device::decode(UINT16 inst) |
| 1289 | void tms99xx_device::decode(UINT16 inst) |
| 1289 | 1290 | { |
| 1290 | 1291 | int index = 0; |
| 1291 | 1292 | lookup_entry* table = m_command_lookup_table; |
| r15461 | r15462 | |
| 1300 | 1301 | while (!complete) |
| 1301 | 1302 | { |
| 1302 | 1303 | index = (opcode >> 12) & 0x000f; |
| 1303 | | if (VERBOSE>8) LOG("tms9900: Check next hex digit of instruction %x\n", index); |
| 1304 | if (VERBOSE>8) LOG("tms99xx: Check next hex digit of instruction %x\n", index); |
| 1304 | 1305 | if (table[index].next_digit != NULL) |
| 1305 | 1306 | { |
| 1306 | 1307 | table = table[index].next_digit; |
| r15461 | r15462 | |
| 1312 | 1313 | if (decoded == NULL) |
| 1313 | 1314 | { |
| 1314 | 1315 | // not found |
| 1315 | | if (VERBOSE>0) LOG("tms9900: Illegal opcode %04x\n", inst); |
| 1316 | if (VERBOSE>0) LOG("tms99xx: Illegal opcode %04x\n", inst); |
| 1316 | 1317 | IR = 0; |
| 1317 | 1318 | // This will cause another instruction acquisition in the next machine cycle |
| 1318 | | // with an asserted IAQ line (can be used to detect this illegal opcode detection). |
| 1319 | // with an asserted IAQ line (can be used to indicate this illegal opcode detection). |
| 1319 | 1320 | m_program = NULL; |
| 1320 | 1321 | } |
| 1321 | 1322 | else |
| r15461 | r15462 | |
| 1323 | 1324 | m_program = decoded->prog; |
| 1324 | 1325 | MPC = -1; |
| 1325 | 1326 | m_command = decoded->id; |
| 1326 | | if (VERBOSE>7) LOG("tms9900: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode); |
| 1327 | if (VERBOSE>7) LOG("tms99xx: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode); |
| 1327 | 1328 | } |
| 1329 | m_pass = 1; |
| 1328 | 1330 | } |
| 1329 | 1331 | |
| 1330 | | inline bool tms9900_device::byte_operation() |
| 1332 | inline bool tms99xx_device::byte_operation() |
| 1331 | 1333 | { |
| 1332 | 1334 | return (IR & 0x1000)!=0; |
| 1333 | 1335 | } |
| 1334 | 1336 | |
| 1335 | | void tms9900_device::acquire_instruction() |
| 1337 | void tms99xx_device::acquire_instruction() |
| 1336 | 1338 | { |
| 1337 | 1339 | m_iaq_line(ASSERT_LINE); |
| 1338 | 1340 | m_address = PC; |
| 1339 | 1341 | m_first_cycle = m_icount; |
| 1340 | 1342 | mem_read(); |
| 1341 | 1343 | decode(m_current_value); |
| 1342 | | if (VERBOSE>3) LOG("tms9900: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC); |
| 1344 | if (VERBOSE>3) LOG("tms99xx: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC); |
| 1343 | 1345 | debugger_instruction_hook(this, PC); |
| 1344 | | PC = (PC + 2) & 0xfffe; |
| 1346 | PC = (PC + 2) & 0xfffe & m_prgaddr_mask; |
| 1345 | 1347 | // IAQ will be cleared in the main loop |
| 1346 | 1348 | } |
| 1347 | 1349 | |
| 1348 | | void tms9900_device::mem_read() |
| 1350 | /* |
| 1351 | Memory read: |
| 1352 | 1) Pulse clock (done above) |
| 1353 | 2) Set address (we also get the value right here) |
| 1354 | 3) Pulse clock |
| 1355 | 4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP) |
| 1356 | |
| 1357 | Clock cycles: 2 + W, W = number of wait states |
| 1358 | */ |
| 1359 | void tms99xx_device::mem_read() |
| 1349 | 1360 | { |
| 1350 | | m_current_value = pulse_and_read_memory(m_address); |
| 1351 | | if (VERBOSE>7) LOG("tms9900: memory read %04x -> %04x\n", m_address, m_current_value); |
| 1361 | m_current_value = m_prgspace->read_word(m_address & m_prgaddr_mask & 0xfffe); |
| 1362 | pulse_clock(2); |
| 1363 | m_check_ready = true; |
| 1364 | if (VERBOSE>7) LOG("tms99xx: memory read %04x -> %04x\n", m_address, m_current_value); |
| 1352 | 1365 | } |
| 1353 | 1366 | |
| 1354 | | void tms9900_device::mem_write() |
| 1367 | void tms99xx_device::mem_write() |
| 1355 | 1368 | { |
| 1356 | | pulse_and_write_memory(m_address, m_current_value); |
| 1357 | | if (VERBOSE>7) LOG("tms9900: memory write %04x <- %04x\n", m_address, m_current_value); |
| 1369 | m_prgspace->write_word(m_address & m_prgaddr_mask & 0xfffe, m_current_value); |
| 1370 | pulse_clock(2); |
| 1371 | m_check_ready = true; |
| 1372 | if (VERBOSE>7) LOG("tms99xx: memory write %04x <- %04x\n", m_address, m_current_value); |
| 1358 | 1373 | } |
| 1359 | 1374 | |
| 1360 | | void tms9900_device::register_read() |
| 1375 | void tms99xx_device::register_read() |
| 1361 | 1376 | { |
| 1362 | 1377 | // Need to set m_address for F1/F3 (we don't know what the data_derive did) |
| 1363 | 1378 | m_address = WP + (m_regnumber<<1); |
| 1364 | | m_register_contents = m_current_value = pulse_and_read_memory(m_address); |
| 1365 | | if (VERBOSE>7) LOG("tms9900: register %d read (mem %04x) -> %04x\n", m_regnumber, m_address, m_current_value); |
| 1379 | mem_read(); |
| 1380 | m_check_ready = true; |
| 1381 | m_register_contents = m_current_value; |
| 1366 | 1382 | } |
| 1367 | 1383 | |
| 1368 | | void tms9900_device::register_write() |
| 1384 | /* |
| 1385 | Memory write: |
| 1386 | 1) Pulse clock |
| 1387 | 2) Set address and write (as in the real system) |
| 1388 | 3) Pulse clock |
| 1389 | 4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP) |
| 1390 | |
| 1391 | Clock cycles: 2 + W, W = number of wait states |
| 1392 | */ |
| 1393 | void tms99xx_device::register_write() |
| 1369 | 1394 | { |
| 1370 | | pulse_and_write_memory(WP + (m_regnumber<<1), m_current_value); |
| 1371 | | if (VERBOSE>7) LOG("tms9900: register %d write (mem %04x) <- %04x\n", m_regnumber, WP + (m_regnumber<<1), m_current_value); |
| 1395 | UINT16 addr_save = m_address; |
| 1396 | m_address = (WP + (m_regnumber<<1)) & m_prgaddr_mask & 0xfffe; |
| 1397 | mem_write(); |
| 1398 | m_check_ready = true; |
| 1399 | m_address = addr_save; |
| 1372 | 1400 | } |
| 1373 | 1401 | |
| 1374 | 1402 | /* |
| r15461 | r15462 | |
| 1398 | 1426 | CRU write: First bit is at rightmost position of m_value. |
| 1399 | 1427 | */ |
| 1400 | 1428 | |
| 1401 | | |
| 1402 | | #define CRUREADMASK 0x01ff |
| 1403 | | #define CRUWRITEMASK 0x0fff |
| 1404 | | |
| 1405 | | void tms9900_device::cru_operation() |
| 1429 | void tms99xx_device::cru_input_operation() |
| 1406 | 1430 | { |
| 1407 | 1431 | int value, value1; |
| 1408 | 1432 | int offset, location; |
| 1409 | 1433 | |
| 1410 | | if (m_cru_output) |
| 1434 | location = (m_cru_address >> 4) & (m_cruaddr_mask>>3); |
| 1435 | offset = (m_cru_address>>1) & 0x07; |
| 1436 | |
| 1437 | // Read 8 bits (containing the desired bits) |
| 1438 | value = m_cru->read_byte(location); |
| 1439 | |
| 1440 | if ((offset + m_count) > 8) // spans two 8 bit cluster |
| 1411 | 1441 | { |
| 1412 | | location = (m_cru_address >> 1)& CRUWRITEMASK; |
| 1413 | | value = m_value; |
| 1442 | // Read next 8 bits |
| 1443 | location = (location + 1) & (m_cruaddr_mask>>3); |
| 1444 | value1 = m_cru->read_byte(location); |
| 1445 | value |= (value1 << 8); |
| 1414 | 1446 | |
| 1415 | | // Write m_count bits from cru_address |
| 1416 | | for (int i=0; i < m_count; i++) |
| 1447 | if ((offset + m_count) > 16) // spans three 8 bit cluster |
| 1417 | 1448 | { |
| 1418 | | m_cru->write_byte(location, (value & 0x01)); |
| 1419 | | value >>= 1; |
| 1420 | | location = (location + 1) & CRUWRITEMASK; |
| 1421 | | pulse_clock(2); |
| 1449 | // Read next 8 bits |
| 1450 | location = (location + 1) & (m_cruaddr_mask>>3); |
| 1451 | value1 = m_cru->read_byte(location); |
| 1452 | value |= (value1 << 16); |
| 1422 | 1453 | } |
| 1423 | 1454 | } |
| 1424 | | else |
| 1425 | | { |
| 1426 | | location = (m_cru_address >> 4) & CRUREADMASK; |
| 1427 | | offset = (m_cru_address>>1) & 0x07; |
| 1428 | 1455 | |
| 1429 | | // Read 8 bits (containing the desired bits) |
| 1430 | | value = m_cru->read_byte(location); |
| 1456 | // On each machine cycle (2 clocks) only one CRU bit is transmitted |
| 1457 | pulse_clock(m_count<<1); |
| 1431 | 1458 | |
| 1432 | | if ((offset + m_count) > 8) // spans two 8 bit cluster |
| 1433 | | { |
| 1434 | | // Read next 8 bits |
| 1435 | | location = (location + 1) & CRUREADMASK; |
| 1436 | | value1 = m_cru->read_byte(location); |
| 1437 | | value |= (value1 << 8); |
| 1459 | // Shift back the bits so that the first bit is at the rightmost place |
| 1460 | m_value = (value >> offset); |
| 1438 | 1461 | |
| 1439 | | if ((offset + m_count) > 16) // spans three 8 bit cluster |
| 1440 | | { |
| 1441 | | // Read next 8 bits |
| 1442 | | location = (location + 1) & CRUREADMASK; |
| 1443 | | value1 = m_cru->read_byte(location); |
| 1444 | | value |= (value1 << 16); |
| 1445 | | } |
| 1446 | | } |
| 1462 | // Mask out what we want |
| 1463 | m_value &= (0x0000ffff >> (16-m_count)); |
| 1464 | } |
| 1447 | 1465 | |
| 1448 | | // On each machine cycle (2 clocks) only one CRU bit is transmitted |
| 1449 | | pulse_clock(m_count<<1); |
| 1466 | void tms99xx_device::cru_output_operation() |
| 1467 | { |
| 1468 | int value; |
| 1469 | int location; |
| 1470 | location = (m_cru_address >> 1) & m_cruaddr_mask; |
| 1471 | value = m_value; |
| 1450 | 1472 | |
| 1451 | | // Shift back the bits so that the first bit is at the rightmost place |
| 1452 | | m_value = (value >> offset); |
| 1453 | | |
| 1454 | | // Mask out what we want |
| 1455 | | m_value &= (0x0000ffff >> (16-m_count)); |
| 1473 | // Write m_count bits from cru_address |
| 1474 | for (int i=0; i < m_count; i++) |
| 1475 | { |
| 1476 | if (VERBOSE>5) LOG("tms99xx: CRU output operation, address %04x, value %d\n", location<<1, value & 0x01); |
| 1477 | m_cru->write_byte(location, (value & 0x01)); |
| 1478 | value >>= 1; |
| 1479 | location = (location + 1) & m_cruaddr_mask; |
| 1480 | pulse_clock(2); |
| 1456 | 1481 | } |
| 1457 | 1482 | } |
| 1458 | 1483 | |
| 1459 | | void tms9900_device::return_from_subprogram() |
| 1484 | void tms99xx_device::return_from_subprogram() |
| 1460 | 1485 | { |
| 1461 | 1486 | // Return from data derivation |
| 1462 | 1487 | // The result should be in m_current_value |
| r15461 | r15462 | |
| 1465 | 1490 | MPC = m_caller_MPC; // will be increased on return |
| 1466 | 1491 | } |
| 1467 | 1492 | |
| 1468 | | void tms9900_device::command_completed() |
| 1493 | void tms99xx_device::command_completed() |
| 1469 | 1494 | { |
| 1470 | 1495 | // Pseudo state at the end of the current instruction cycle sequence |
| 1471 | | if (VERBOSE>7) |
| 1496 | if (VERBOSE>4) |
| 1472 | 1497 | { |
| 1498 | LOG("tms99xx: +++++ Instruction %04x (%s) completed +++++\n", IR, opname[m_command]); |
| 1473 | 1499 | int cycles = m_first_cycle - m_icount; |
| 1474 | 1500 | // Avoid nonsense values due to expired and resumed main loop |
| 1475 | | if (cycles > 0 && cycles < 10000) LOG("tms9900: Instruction %04x (%s) consumed %d cycles\n", IR, opname[m_command], cycles); |
| 1501 | if (cycles > 0 && cycles < 10000) LOG("tms99xx: Consumed %d cycles\n", cycles); |
| 1476 | 1502 | } |
| 1477 | 1503 | m_program = NULL; |
| 1504 | m_lowbyte = false; |
| 1478 | 1505 | } |
| 1479 | 1506 | |
| 1480 | 1507 | /* |
| r15461 | r15462 | |
| 1482 | 1509 | derivation. In terms of cycles, it does not take any time; execution |
| 1483 | 1510 | continues with the first instruction of the subprogram. |
| 1484 | 1511 | */ |
| 1485 | | void tms9900_device::data_derivation_subprogram() |
| 1512 | void tms99xx_device::data_derivation_subprogram() |
| 1486 | 1513 | { |
| 1487 | 1514 | UINT16 ircopy = IR; |
| 1488 | 1515 | |
| r15461 | r15462 | |
| 1504 | 1531 | MPC += 8; // the second option |
| 1505 | 1532 | } |
| 1506 | 1533 | m_get_destination = true; // when we call this the second time before END it's the destination |
| 1507 | | MPC--; // will be increased on return |
| 1534 | m_pass = 2; |
| 1508 | 1535 | } |
| 1509 | 1536 | |
| 1510 | 1537 | |
| r15461 | r15462 | |
| 1512 | 1539 | Status bit operations |
| 1513 | 1540 | **************************************************************************/ |
| 1514 | 1541 | |
| 1515 | | inline void tms9900_device::set_status_bit(int bit, bool state) |
| 1542 | inline void tms99xx_device::set_status_bit(int bit, bool state) |
| 1516 | 1543 | { |
| 1517 | 1544 | if (state) ST |= bit; |
| 1518 | 1545 | else ST &= ~bit; |
| 1519 | 1546 | } |
| 1520 | 1547 | |
| 1521 | | void tms9900_device::set_status_parity(UINT8 value) |
| 1548 | void tms99xx_device::set_status_parity(UINT8 value) |
| 1522 | 1549 | { |
| 1523 | 1550 | int count = 0; |
| 1524 | 1551 | for (int i=0; i < 8; i++) |
| r15461 | r15462 | |
| 1529 | 1556 | set_status_bit(ST_OP, (count & 1)!=0); |
| 1530 | 1557 | } |
| 1531 | 1558 | |
| 1532 | | inline void tms9900_device::compare_and_set_lae(UINT16 value1, UINT16 value2) |
| 1559 | inline void tms99xx_device::compare_and_set_lae(UINT16 value1, UINT16 value2) |
| 1533 | 1560 | { |
| 1534 | 1561 | set_status_bit(ST_EQ, value1 == value2); |
| 1535 | 1562 | set_status_bit(ST_LH, value1 > value2); |
| 1536 | 1563 | set_status_bit(ST_AGT, (INT16)value1 > (INT16)value2); |
| 1537 | | if (VERBOSE>7) LOG("tms9900: ST = %04x (val1=%04x, val2=%04x)\n", ST, value1, value2); |
| 1564 | if (VERBOSE>7) LOG("tms99xx: ST = %04x (val1=%04x, val2=%04x)\n", ST, value1, value2); |
| 1538 | 1565 | } |
| 1539 | 1566 | |
| 1540 | 1567 | /************************************************************************** |
| 1541 | 1568 | ALU operations |
| 1542 | 1569 | **************************************************************************/ |
| 1543 | 1570 | |
| 1544 | | void tms9900_device::alu_nop() |
| 1571 | void tms99xx_device::alu_nop() |
| 1545 | 1572 | { |
| 1546 | 1573 | // Do nothing (or nothing that is externally visible) |
| 1547 | 1574 | pulse_clock(2); |
| 1548 | 1575 | return; |
| 1549 | 1576 | } |
| 1550 | 1577 | |
| 1551 | | void tms9900_device::alu_source() |
| 1578 | void tms99xx_device::alu_source() |
| 1552 | 1579 | { |
| 1553 | 1580 | // Copy the current value into the source data register |
| 1554 | 1581 | m_source_even = ((m_address & 1)==0); |
| r15461 | r15462 | |
| 1557 | 1584 | pulse_clock(2); |
| 1558 | 1585 | } |
| 1559 | 1586 | |
| 1560 | | void tms9900_device::alu_clear() |
| 1587 | void tms99xx_device::alu_clear() |
| 1561 | 1588 | { |
| 1562 | 1589 | // Clears the register contents |
| 1563 | 1590 | m_register_contents = 0; |
| 1564 | 1591 | pulse_clock(2); |
| 1565 | 1592 | } |
| 1566 | 1593 | |
| 1567 | | void tms9900_device::alu_setaddr() |
| 1594 | void tms99xx_device::alu_setaddr() |
| 1568 | 1595 | { |
| 1569 | 1596 | // Load the current value into the address register |
| 1570 | 1597 | m_address = m_current_value; |
| 1571 | 1598 | pulse_clock(2); |
| 1572 | 1599 | } |
| 1573 | 1600 | |
| 1574 | | void tms9900_device::alu_addone() |
| 1601 | void tms99xx_device::alu_addone() |
| 1575 | 1602 | { |
| 1576 | 1603 | m_current_value++; |
| 1577 | 1604 | pulse_clock(2); |
| 1578 | 1605 | } |
| 1579 | 1606 | |
| 1580 | | void tms9900_device::alu_setaddr_addone() |
| 1607 | void tms99xx_device::alu_setaddr_addone() |
| 1581 | 1608 | { |
| 1582 | 1609 | // Set the address register and increase the recent value |
| 1583 | 1610 | m_address = m_current_value; |
| r15461 | r15462 | |
| 1585 | 1612 | pulse_clock(2); |
| 1586 | 1613 | } |
| 1587 | 1614 | |
| 1588 | | void tms9900_device::alu_pcaddr_advance() |
| 1615 | void tms99xx_device::alu_pcaddr_advance() |
| 1589 | 1616 | { |
| 1590 | 1617 | // Set PC as new read address, increase by 2 |
| 1591 | 1618 | m_address = PC; |
| 1592 | | PC = (PC+2)&0xfffe; |
| 1619 | PC = (PC + 2) & 0xfffe & m_prgaddr_mask; |
| 1593 | 1620 | pulse_clock(2); |
| 1594 | 1621 | } |
| 1595 | 1622 | |
| 1596 | | void tms9900_device::alu_add_register() |
| 1623 | void tms99xx_device::alu_add_register() |
| 1597 | 1624 | { |
| 1598 | 1625 | // Add the register contents to the current value and set as address |
| 1599 | 1626 | m_address = m_current_value + m_register_contents; |
| 1600 | 1627 | pulse_clock(2); |
| 1601 | 1628 | } |
| 1602 | 1629 | |
| 1603 | | void tms9900_device::alu_imm() |
| 1630 | void tms99xx_device::alu_imm() |
| 1604 | 1631 | { |
| 1605 | | if (VERBOSE>7) LOG("tms9900: Immediate operand, reading from position %04x\n", PC); |
| 1632 | if (VERBOSE>7) LOG("tms99xx: Immediate operand, reading from position %04x\n", PC); |
| 1633 | m_value_copy = m_current_value; |
| 1634 | m_address_copy = m_address; |
| 1606 | 1635 | m_address = PC; |
| 1607 | | PC = (PC + 2) & 0xfffe; |
| 1636 | PC = (PC + 2) & 0xfffe & m_prgaddr_mask; |
| 1608 | 1637 | pulse_clock(2); |
| 1609 | 1638 | } |
| 1610 | 1639 | |
| 1611 | | void tms9900_device::alu_reg() |
| 1640 | void tms99xx_device::alu_reg() |
| 1612 | 1641 | { |
| 1613 | | m_regnumber = IR & 0x000f; |
| 1642 | m_address = (WP + ((IR & 0x000f)<<1)) & m_prgaddr_mask; |
| 1614 | 1643 | pulse_clock(2); |
| 1615 | 1644 | } |
| 1616 | 1645 | |
| 1617 | | void tms9900_device::alu_f1() |
| 1646 | void tms99xx_device::alu_f1() |
| 1618 | 1647 | { |
| 1619 | 1648 | UINT32 dest_new = 0; |
| 1620 | 1649 | |
| r15461 | r15462 | |
| 1726 | 1755 | pulse_clock(2); |
| 1727 | 1756 | } |
| 1728 | 1757 | |
| 1729 | | void tms9900_device::alu_comp() |
| 1758 | void tms99xx_device::alu_comp() |
| 1730 | 1759 | { |
| 1731 | 1760 | m_destination_even = ((m_address & 1)==0); // this is the destination address; the source address has already been saved |
| 1732 | 1761 | if (byte_operation()) |
| r15461 | r15462 | |
| 1742 | 1771 | pulse_clock(2); |
| 1743 | 1772 | } |
| 1744 | 1773 | |
| 1745 | | void tms9900_device::alu_f3() |
| 1774 | void tms99xx_device::alu_f3() |
| 1746 | 1775 | { |
| 1747 | | if (m_state==0) |
| 1776 | switch (m_state) |
| 1748 | 1777 | { |
| 1749 | | m_regnumber = (IR >> 6) & 0x000f; |
| 1778 | case 0: |
| 1779 | // Get register address |
| 1780 | m_address = WP + ((IR >> 5) & 0x001e); |
| 1750 | 1781 | m_source_value = m_current_value; |
| 1751 | | } |
| 1752 | | else |
| 1753 | | { |
| 1754 | | if (VERBOSE>7) LOG("tms9900: coc/czc/xor %04x with %04x\n", m_source_value, m_register_contents); |
| 1755 | | switch (m_command) |
| 1782 | break; |
| 1783 | case 1: |
| 1784 | if (m_command == COC) |
| 1756 | 1785 | { |
| 1757 | | case COC: |
| 1758 | | set_status_bit(ST_EQ, (m_register_contents & m_source_value) == m_source_value); |
| 1759 | | break; |
| 1760 | | case CZC: |
| 1761 | | set_status_bit(ST_EQ, (~m_register_contents & m_source_value) == m_source_value); |
| 1762 | | break; |
| 1763 | | case XOR: |
| 1764 | | m_current_value = (m_register_contents ^ m_source_value); |
| 1765 | | compare_and_set_lae(m_current_value, 0); |
| 1766 | | break; |
| 1786 | set_status_bit(ST_EQ, (m_current_value & m_source_value) == m_source_value); |
| 1767 | 1787 | } |
| 1788 | else |
| 1789 | { |
| 1790 | if (m_command == CZC) |
| 1791 | { |
| 1792 | set_status_bit(ST_EQ, (~m_current_value & m_source_value) == m_source_value); |
| 1793 | } |
| 1794 | else |
| 1795 | { |
| 1796 | // XOR |
| 1797 | // The workspace register address is still in m_address |
| 1798 | m_current_value = (m_current_value ^ m_source_value); |
| 1799 | compare_and_set_lae(m_current_value, 0); |
| 1800 | } |
| 1801 | } |
| 1802 | if (VERBOSE>7) LOG("tms99xx: ST = %04x\n", ST); |
| 1803 | break; |
| 1768 | 1804 | } |
| 1769 | | if (VERBOSE>7) LOG("tms9900: ST = %04x (log comp)\n", ST); |
| 1770 | 1805 | |
| 1771 | 1806 | m_state++; |
| 1772 | 1807 | pulse_clock(2); |
| 1773 | 1808 | } |
| 1774 | 1809 | |
| 1775 | | void tms9900_device::alu_multiply() |
| 1810 | void tms99xx_device::alu_multiply() |
| 1776 | 1811 | { |
| 1812 | UINT32 result = 0; |
| 1813 | |
| 1777 | 1814 | switch (m_state) |
| 1778 | 1815 | { |
| 1779 | 1816 | case 0: // After data derivation |
| 1780 | 1817 | m_source_value = m_current_value; |
| 1781 | | m_regnumber = (IR >> 6)&0x000f; |
| 1818 | m_address = ((IR >> 5) & 0x001e) + WP; |
| 1782 | 1819 | break; |
| 1783 | 1820 | case 1: // After reading the register (multiplier) |
| 1784 | | if (VERBOSE>7) LOG("tms9900: Multiply %04x by %04x\n", m_register_contents, m_source_value); |
| 1785 | | m_value = m_register_contents * m_source_value; |
| 1786 | | m_current_value = (m_value >> 16) & 0xffff; |
| 1787 | | m_value = m_value & 0xffff; // Save low word in m_value |
| 1821 | if (VERBOSE>7) LOG("tms99xx: Multiply %04x by %04x\n", m_current_value, m_source_value); |
| 1822 | result = (m_source_value & 0x0000ffff) * (m_current_value & 0x0000ffff); |
| 1823 | m_current_value = (result >> 16) & 0xffff; |
| 1824 | m_value_copy = result & 0xffff; |
| 1788 | 1825 | pulse_clock(34); // add 36 clock cycles (18 machine cycles); last one in main loop |
| 1789 | 1826 | break; |
| 1790 | 1827 | case 2: // After writing the high word to the destination register |
| 1791 | | m_current_value = m_value; // Prepare to save low word |
| 1792 | | m_address = (m_address + 2) & 0xffff; |
| 1828 | m_current_value = m_value_copy; // Prepare to save low word |
| 1829 | m_address = (m_address + 2) & m_prgaddr_mask; |
| 1793 | 1830 | break; |
| 1794 | 1831 | } |
| 1795 | 1832 | pulse_clock(2); |
| 1796 | 1833 | m_state++; |
| 1797 | 1834 | } |
| 1798 | 1835 | |
| 1799 | | void tms9900_device::alu_divide() |
| 1836 | void tms99xx_device::alu_divide() |
| 1800 | 1837 | { |
| 1801 | 1838 | // Format is DIV Divisor,REG(dividend) |
| 1802 | | UINT32 value1; |
| 1839 | UINT32 uval32; |
| 1840 | bool overflow = true; |
| 1841 | UINT16 value1; |
| 1803 | 1842 | |
| 1804 | 1843 | switch (m_state) |
| 1805 | 1844 | { |
| 1806 | 1845 | case 0: |
| 1807 | | m_source_value = m_current_value; // store divisor |
| 1808 | | m_regnumber = (IR >> 6) & 0x000f; |
| 1846 | m_source_value = m_current_value; // store divisor |
| 1847 | // Set address of register |
| 1848 | m_address = WP + ((IR >> 5) & 0x001e); |
| 1849 | m_address_copy = m_address; |
| 1809 | 1850 | break; |
| 1810 | 1851 | case 1: |
| 1811 | 1852 | // We have an overflow when the quotient cannot be stored in 16 bits |
| 1812 | 1853 | // This is the case when the dividend / divisor >= 0x10000, |
| 1813 | 1854 | // or equivalently, dividend / 0x10000 >= divisor |
| 1814 | | if (m_register_contents >= m_source_value) |
| 1855 | |
| 1856 | if (m_current_value < m_source_value) // also if source=0 |
| 1815 | 1857 | { |
| 1816 | | ST |= ST_OV; |
| 1817 | | if (VERBOSE>7) LOG("tms9900: Aborting division because the dividend %08x is too big for the divisor %04x\n", (m_register_contents<<16), m_source_value); |
| 1818 | | abort_operation(); // behaves as if the end of the operation sequence has been reached |
| 1858 | MPC++; // skip the abort |
| 1859 | overflow = false; |
| 1819 | 1860 | } |
| 1820 | | else |
| 1821 | | { |
| 1822 | | ST &= ~ST_OV; |
| 1823 | | // m_address is the address of the high word of the dividend (from the previous register read) |
| 1824 | | m_address = (m_address + 2) & 0xffff; |
| 1825 | | } |
| 1861 | set_status_bit(ST_OV, overflow); |
| 1862 | m_value_copy = m_current_value; // Save the high word |
| 1863 | m_address = (m_address + 2) & m_prgaddr_mask; // Read next word |
| 1826 | 1864 | break; |
| 1827 | 1865 | case 2: |
| 1866 | // W2 is in m_current_value |
| 1828 | 1867 | // Create full word and perform division |
| 1829 | | value1 = (m_register_contents << 16) | m_current_value; |
| 1830 | | if (VERBOSE>7) LOG("tms9900: Dividing %08x by %04x\n", value1, m_source_value); |
| 1831 | | m_current_value = (value1 / m_source_value) & 0xffff; |
| 1832 | | m_value = (value1 % m_source_value) & 0xffff; |
| 1833 | | if (VERBOSE>7) LOG("tms9900: Quotient %04x, remainder %04x\n", m_current_value, m_value); |
| 1868 | uval32 = (m_value_copy << 16) | m_current_value; |
| 1834 | 1869 | |
| 1870 | if (VERBOSE>7) LOG("tms99xx: Dividing %08x by %04x\n", uval32, m_source_value); |
| 1871 | m_current_value = uval32 / m_source_value; |
| 1872 | m_value_copy = uval32 % m_source_value; |
| 1873 | |
| 1874 | if (VERBOSE>7) LOG("tms99xx: Quotient %04x, remainder %04x\n", m_current_value, m_value_copy); |
| 1875 | |
| 1876 | m_address = m_address_copy; |
| 1877 | |
| 1835 | 1878 | // The number of ALU cycles depends on the number of steps in |
| 1836 | 1879 | // the division algorithm. The number of cycles is between 32 and |
| 1837 | 1880 | // 48 (*2 for clock cycles) |
| r15461 | r15462 | |
| 1839 | 1882 | // the following heuristic: We use 32 ALU cycles in general, then |
| 1840 | 1883 | // we need as many cycles as it takes to |
| 1841 | 1884 | // shift away the dividend. Thus, bigger dividends need more cycles. |
| 1885 | |
| 1842 | 1886 | pulse_clock(62); // one pulse is at the start, one at the end |
| 1843 | | value1 = m_register_contents & 0xffff; |
| 1887 | value1 = m_value_copy & 0xffff; |
| 1888 | |
| 1844 | 1889 | while (value1 != 0) |
| 1845 | 1890 | { |
| 1846 | 1891 | value1 = (value1 >> 1) & 0xffff; |
| r15461 | r15462 | |
| 1849 | 1894 | // We still have m_regnumber; this is where m_current_value will go to |
| 1850 | 1895 | break; |
| 1851 | 1896 | case 3: |
| 1852 | | // Prepare to write the remainder; we have the address from above |
| 1853 | | // (m_address), did not change |
| 1854 | | m_current_value = m_value; |
| 1855 | | if (VERBOSE>7) LOG("tms9900: ST = %04x (div)\n", ST); |
| 1897 | // Prepare to write the remainder |
| 1898 | m_current_value = m_value_copy; |
| 1899 | m_address = m_address + 2; |
| 1900 | if (VERBOSE>7) LOG("tms99xx: ST = %04x (div)\n", ST); |
| 1856 | 1901 | break; |
| 1857 | 1902 | } |
| 1858 | 1903 | pulse_clock(2); |
| 1859 | 1904 | m_state++; |
| 1860 | 1905 | } |
| 1861 | 1906 | |
| 1862 | | void tms9900_device::alu_xop() |
| 1907 | void tms99xx_device::alu_xop() |
| 1863 | 1908 | { |
| 1864 | 1909 | switch (m_state) |
| 1865 | 1910 | { |
| 1866 | 1911 | case 0: |
| 1867 | 1912 | // We have the effective address of the source operand in m_address |
| 1868 | | m_source_address = m_address; |
| 1913 | m_address_saved = m_address; |
| 1869 | 1914 | // Now we take the XOP number from the instruction register |
| 1870 | 1915 | // and calculate the vector location |
| 1871 | 1916 | // [0010 11xx xx tt SSSS] shift 6 right, then *4 => shift 4 right |
| r15461 | r15462 | |
| 1873 | 1918 | break; |
| 1874 | 1919 | case 1: |
| 1875 | 1920 | m_value = WP; // save the old WP |
| 1876 | | WP = m_current_value; // the new WP has been read in the previous microoperation |
| 1877 | | m_current_value = m_source_address; // we saved the address of the source operand; retrieve it |
| 1878 | | m_regnumber = 11; // Next register is R11 |
| 1921 | WP = m_current_value & m_prgaddr_mask; // the new WP has been read in the previous microoperation |
| 1922 | m_current_value = m_address_saved; // we saved the address of the source operand; retrieve it |
| 1923 | m_address = WP + 0x0016; // Next register is R11 |
| 1879 | 1924 | break; |
| 1880 | 1925 | case 2: |
| 1926 | m_address = WP + 0x001e; |
| 1881 | 1927 | m_current_value = ST; |
| 1882 | | m_regnumber = 15; |
| 1883 | 1928 | break; |
| 1884 | 1929 | case 3: |
| 1930 | m_address = WP + 0x001c; |
| 1885 | 1931 | m_current_value = PC; |
| 1886 | | m_regnumber = 14; |
| 1887 | 1932 | break; |
| 1888 | 1933 | case 4: |
| 1889 | | m_current_value = WP; |
| 1890 | | m_regnumber = 13; |
| 1934 | m_address = WP + 0x001a; |
| 1935 | m_current_value = m_value; // old WP into new R13 |
| 1891 | 1936 | break; |
| 1892 | 1937 | case 5: |
| 1893 | 1938 | m_address = 0x0042 + ((IR >> 4) & 0x003c); // location of new PC |
| 1894 | | ST |= ST_X; |
| 1939 | set_status_bit(ST_X, true); |
| 1895 | 1940 | break; |
| 1896 | 1941 | case 6: |
| 1897 | | PC = m_current_value; |
| 1942 | PC = m_current_value & m_prgaddr_mask; |
| 1898 | 1943 | break; |
| 1899 | 1944 | } |
| 1900 | 1945 | pulse_clock(2); |
| 1901 | 1946 | m_state++; |
| 1902 | 1947 | } |
| 1903 | 1948 | |
| 1904 | | void tms9900_device::alu_clr_swpb() |
| 1949 | void tms99xx_device::alu_clr_swpb() |
| 1905 | 1950 | { |
| 1906 | 1951 | UINT32 dest_new = 0; |
| 1907 | 1952 | UINT32 src_val = m_current_value & 0x0000ffff; |
| r15461 | r15462 | |
| 1977 | 2022 | // No states here |
| 1978 | 2023 | } |
| 1979 | 2024 | |
| 1980 | | void tms9900_device::alu_abs() |
| 2025 | void tms99xx_device::alu_abs() |
| 1981 | 2026 | { |
| 1982 | 2027 | // LAECO (from original word!) |
| 1983 | 2028 | // O if >8000 |
| r15461 | r15462 | |
| 1998 | 2043 | pulse_clock(2); |
| 1999 | 2044 | } |
| 2000 | 2045 | |
| 2001 | | void tms9900_device::alu_x() |
| 2046 | void tms99xx_device::alu_x() |
| 2002 | 2047 | { |
| 2003 | | if (VERBOSE>7) LOG("tms9900: Substituting current command by %04x\n", m_current_value); |
| 2048 | if (VERBOSE>7) LOG("tms99xx: Substituting current command by %04x\n", m_current_value); |
| 2004 | 2049 | decode(m_current_value); |
| 2005 | 2050 | pulse_clock(2); |
| 2006 | 2051 | } |
| r15461 | r15462 | |
| 2008 | 2053 | /* |
| 2009 | 2054 | Also used by other microprograms |
| 2010 | 2055 | */ |
| 2011 | | void tms9900_device::alu_b() |
| 2056 | void tms99xx_device::alu_b() |
| 2012 | 2057 | { |
| 2013 | 2058 | // no status bits |
| 2014 | 2059 | // Although we got the contents of the source data, we do not use them |
| r15461 | r15462 | |
| 2017 | 2062 | // If we have a B *R5 and R5 contains the value 0xa000, the CPU actually |
| 2018 | 2063 | // retrieves the value at 0xa000, but in fact it will load the PC |
| 2019 | 2064 | // with the address 0xa000 |
| 2020 | | PC = m_address; |
| 2021 | | if (VERBOSE>7) LOG("tms9900: Set new PC = %04x\n", PC); |
| 2065 | m_current_value = PC; |
| 2066 | PC = m_address & m_prgaddr_mask; |
| 2067 | m_address = WP + 22; |
| 2068 | if (VERBOSE>7) LOG("tms99xx: Set new PC = %04x\n", PC); |
| 2022 | 2069 | pulse_clock(2); |
| 2023 | 2070 | } |
| 2024 | 2071 | |
| 2025 | | void tms9900_device::alu_bl() |
| 2072 | void tms99xx_device::alu_blwp() |
| 2026 | 2073 | { |
| 2027 | | // no status bits |
| 2028 | | // We have just retrieved the target address; save it in another location |
| 2029 | | m_source_value = m_current_value; |
| 2030 | | m_current_value = PC; |
| 2031 | | m_regnumber = 11; |
| 2032 | | pulse_clock(4); |
| 2033 | | PC = m_address; // See B command: Forget about the value from the target location |
| 2034 | | if (VERBOSE>7) LOG("tms9900: Set new PC = %04x\n", PC); |
| 2035 | | } |
| 2036 | | |
| 2037 | | void tms9900_device::alu_blwp() |
| 2038 | | { |
| 2039 | 2074 | switch (m_state) |
| 2040 | 2075 | { |
| 2041 | 2076 | case 0: |
| 2042 | | m_source_address = m_address; // Save the location of the WP |
| 2043 | | m_value = WP; |
| 2044 | | WP = m_current_value; // set new WP (*m_destination) |
| 2077 | m_value_copy = WP; |
| 2078 | WP = m_current_value & m_prgaddr_mask; // set new WP (*m_destination) |
| 2079 | m_address_saved = (m_address + 2) & m_prgaddr_mask; // Save the location of the WP |
| 2080 | m_address = WP + 30; |
| 2045 | 2081 | m_current_value = ST; // get status register |
| 2046 | | m_regnumber = 15; |
| 2047 | 2082 | break; |
| 2048 | 2083 | case 1: |
| 2049 | 2084 | m_current_value = PC; // get program counter |
| 2050 | | m_regnumber = 14; |
| 2085 | m_address = m_address - 2; |
| 2051 | 2086 | break; |
| 2052 | 2087 | case 2: |
| 2053 | | m_current_value = m_value; // retrieve the old WP |
| 2054 | | m_regnumber = 13; |
| 2088 | m_current_value = m_value_copy; // retrieve the old WP |
| 2089 | m_address = m_address - 2; |
| 2055 | 2090 | break; |
| 2056 | 2091 | case 3: |
| 2057 | | m_address = (m_source_address + 2)&0xffff; // point to PC component of branch vector |
| 2092 | m_address = m_address_saved; // point to PC component of branch vector |
| 2058 | 2093 | break; |
| 2059 | 2094 | case 4: |
| 2060 | | PC = m_current_value; |
| 2095 | PC = m_current_value & m_prgaddr_mask; |
| 2096 | if (VERBOSE>5) LOG("tms9900: Context switch complete; WP=%04x, PC=%04x, ST=%04x\n", WP, PC, ST); |
| 2061 | 2097 | break; |
| 2062 | 2098 | } |
| 2063 | 2099 | pulse_clock(2); |
| 2064 | 2100 | m_state++; |
| 2065 | 2101 | } |
| 2066 | 2102 | |
| 2067 | | void tms9900_device::alu_ldcr() |
| 2103 | void tms99xx_device::alu_ldcr() |
| 2068 | 2104 | { |
| 2069 | 2105 | UINT16 value; |
| 2070 | 2106 | |
| r15461 | r15462 | |
| 2080 | 2116 | |
| 2081 | 2117 | if (m_state == 0) |
| 2082 | 2118 | { |
| 2083 | | m_regnumber = 12; |
| 2119 | m_address = WP + 24; |
| 2084 | 2120 | } |
| 2085 | 2121 | else |
| 2086 | 2122 | { |
| r15461 | r15462 | |
| 2097 | 2133 | { |
| 2098 | 2134 | compare_and_set_lae(value, 0); |
| 2099 | 2135 | } |
| 2100 | | m_cru_output = true; |
| 2101 | | m_cru_address = m_register_contents; |
| 2136 | m_cru_address = m_current_value; |
| 2102 | 2137 | m_value = value; |
| 2103 | | if (VERBOSE>6) LOG("tms9900: Load CRU address %04x (%d bits), value = %04x\n", m_cru_address, m_count, m_value); |
| 2138 | if (VERBOSE>6) LOG("tms99xx: Load CRU address %04x (%d bits), value = %04x\n", m_cru_address, m_count, m_value); |
| 2104 | 2139 | } |
| 2105 | 2140 | m_state++; |
| 2106 | 2141 | pulse_clock(2); |
| 2107 | 2142 | } |
| 2108 | 2143 | |
| 2109 | | void tms9900_device::alu_stcr() |
| 2144 | void tms99xx_device::alu_stcr() |
| 2110 | 2145 | { |
| 2111 | 2146 | UINT16 value; |
| 2112 | 2147 | |
| r15461 | r15462 | |
| 2120 | 2155 | switch (m_state) |
| 2121 | 2156 | { |
| 2122 | 2157 | case 0: // After getting the destination operand and saving the address/value |
| 2123 | | m_regnumber = 12; |
| 2158 | m_address = WP + 24; |
| 2124 | 2159 | break; |
| 2125 | 2160 | case 1: // After getting R12 |
| 2126 | | m_cru_output = false; |
| 2127 | | m_cru_address = m_register_contents; |
| 2161 | m_cru_address = m_current_value; |
| 2128 | 2162 | m_count = (IR >> 6) & 0x000f; |
| 2129 | 2163 | if (m_count == 0) m_count = 16; |
| 2130 | 2164 | break; |
| r15461 | r15462 | |
| 2132 | 2166 | value = m_value & 0xffff; |
| 2133 | 2167 | if (m_count < 9) |
| 2134 | 2168 | { |
| 2135 | | if (VERBOSE>6) LOG("tms9900: Store CRU at %04x (%d bits) in %04x, result = %02x\n", m_cru_address, m_count, m_source_address, value); |
| 2169 | if (VERBOSE>6) LOG("tms99xx: Store CRU at %04x (%d bits) in %04x, result = %02x\n", m_cru_address, m_count, m_source_address, value); |
| 2136 | 2170 | set_status_parity((UINT8)(value & 0xff)); |
| 2137 | 2171 | compare_and_set_lae(value<<8, 0); |
| 2138 | 2172 | if (m_source_even) |
| r15461 | r15462 | |
| 2144 | 2178 | } |
| 2145 | 2179 | else |
| 2146 | 2180 | { |
| 2147 | | if (VERBOSE>6) LOG("tms9900: Store CRU at %04x (%d bits) in %04x, result = %04x\n", m_cru_address, m_count, m_source_address, value); |
| 2181 | if (VERBOSE>6) LOG("tms99xx: Store CRU at %04x (%d bits) in %04x, result = %04x\n", m_cru_address, m_count, m_source_address, value); |
| 2148 | 2182 | m_current_value = value; |
| 2149 | 2183 | compare_and_set_lae(value, 0); |
| 2150 | 2184 | pulse_clock(2*(5 + (16-m_count))); |
| r15461 | r15462 | |
| 2157 | 2191 | pulse_clock(2); |
| 2158 | 2192 | } |
| 2159 | 2193 | |
| 2160 | | void tms9900_device::alu_sbz_sbo() |
| 2194 | void tms99xx_device::alu_sbz_sbo() |
| 2161 | 2195 | { |
| 2162 | 2196 | INT8 displacement; |
| 2163 | 2197 | if (m_state==0) |
| 2164 | 2198 | { |
| 2165 | | m_regnumber = 12; |
| 2199 | m_address = WP + 24; |
| 2166 | 2200 | } |
| 2167 | 2201 | else |
| 2168 | 2202 | { |
| 2169 | | m_cru_output = true; |
| 2170 | | displacement = (IR & 0xff); |
| 2171 | | m_cru_address = m_register_contents + (displacement<<1); |
| 2203 | m_value = (m_command==SBO)? 1 : 0; |
| 2204 | displacement = (INT8)(IR & 0xff); |
| 2205 | m_cru_address = m_current_value + (displacement<<1); |
| 2172 | 2206 | m_count = 1; |
| 2173 | | m_value = (m_command == SBO)? 1 : 0; |
| 2174 | | pulse_clock(2); |
| 2175 | 2207 | } |
| 2176 | 2208 | m_state++; |
| 2177 | 2209 | pulse_clock(2); |
| 2178 | 2210 | } |
| 2179 | 2211 | |
| 2180 | | void tms9900_device::alu_tb() |
| 2212 | void tms99xx_device::alu_tb() |
| 2181 | 2213 | { |
| 2182 | 2214 | INT8 displacement; |
| 2183 | 2215 | switch (m_state) |
| 2184 | 2216 | { |
| 2185 | 2217 | case 0: |
| 2186 | | m_regnumber = 12; |
| 2218 | m_address = WP + 24; |
| 2187 | 2219 | break; |
| 2188 | 2220 | case 1: |
| 2189 | | m_cru_output = false; |
| 2190 | | displacement = (IR & 0xff); |
| 2191 | | m_cru_address = m_register_contents + (displacement<<1); |
| 2221 | displacement = (INT8)(IR & 0xff); |
| 2222 | m_cru_address = m_current_value + (displacement<<1); |
| 2192 | 2223 | m_count = 1; |
| 2193 | 2224 | break; |
| 2194 | 2225 | case 2: |
| 2195 | 2226 | set_status_bit(ST_EQ, m_value!=0); |
| 2196 | | if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST); |
| 2227 | if (VERBOSE>7) LOG("tms99xx: ST = %04x\n", ST); |
| 2197 | 2228 | break; |
| 2198 | 2229 | } |
| 2199 | 2230 | m_state++; |
| 2200 | 2231 | pulse_clock(2); |
| 2201 | 2232 | } |
| 2202 | 2233 | |
| 2203 | | void tms9900_device::alu_jmp() |
| 2234 | void tms99xx_device::alu_jmp() |
| 2204 | 2235 | { |
| 2205 | 2236 | INT8 displacement; |
| 2206 | 2237 | bool cond = false; |
| r15461 | r15462 | |
| 2252 | 2283 | pulse_clock(2); |
| 2253 | 2284 | if (!cond) |
| 2254 | 2285 | { |
| 2255 | | if (VERBOSE>7) LOG("tms9900: Jump condition false\n"); |
| 2286 | if (VERBOSE>7) LOG("tms99xx: Jump condition false\n"); |
| 2256 | 2287 | MPC+=1; // skip next ALU call |
| 2257 | 2288 | } |
| 2258 | 2289 | else |
| 2259 | | if (VERBOSE>7) LOG("tms9900: Jump condition true\n"); |
| 2290 | if (VERBOSE>7) LOG("tms99xx: Jump condition true\n"); |
| 2260 | 2291 | } |
| 2261 | 2292 | else |
| 2262 | 2293 | { |
| 2263 | 2294 | displacement = (IR & 0xff); |
| 2264 | | PC = PC + (displacement<<1); |
| 2295 | PC = (PC + (displacement<<1)) & m_prgaddr_mask; |
| 2265 | 2296 | pulse_clock(2); |
| 2266 | 2297 | } |
| 2267 | 2298 | m_state++; |
| 2268 | 2299 | } |
| 2269 | 2300 | |
| 2270 | | void tms9900_device::alu_shift() |
| 2301 | void tms99xx_device::alu_shift() |
| 2271 | 2302 | { |
| 2272 | 2303 | bool carry = false; |
| 2273 | 2304 | bool overflow = false; |
| 2274 | 2305 | UINT16 sign = 0; |
| 2275 | 2306 | UINT32 value; |
| 2307 | int count; |
| 2276 | 2308 | |
| 2277 | 2309 | switch (m_state) |
| 2278 | 2310 | { |
| 2279 | 2311 | case 0: |
| 2280 | | m_regnumber = (IR & 0x000f); |
| 2312 | m_address = WP + ((IR & 0x000f)<<1); |
| 2281 | 2313 | break; |
| 2282 | 2314 | case 1: |
| 2283 | | m_source_value = m_current_value; // save it |
| 2284 | | m_count = (IR >> 4) & 0x000f; |
| 2285 | | if (m_count != 0) MPC++; |
| 2286 | | else m_regnumber = 0; |
| 2315 | // we have the value of the register in m_current_value |
| 2316 | // Save it (we may have to read R0) |
| 2317 | m_value_copy = m_current_value; |
| 2318 | m_address_saved = m_address; |
| 2319 | m_address = WP; |
| 2320 | m_current_value = (IR >> 4) & 0x000f; |
| 2321 | |
| 2322 | if (m_current_value != 0) |
| 2323 | { |
| 2324 | // skip the next read operation |
| 2325 | MPC++; |
| 2326 | } |
| 2327 | else |
| 2328 | { |
| 2329 | if (VERBOSE>8) LOG("tms99xx: Shift operation gets count from R0\n"); |
| 2330 | } |
| 2287 | 2331 | break; |
| 2288 | 2332 | case 2: |
| 2289 | | value = m_source_value & 0xffff; |
| 2333 | count = m_current_value & 0x000f; // from the instruction or from R0 |
| 2334 | if (count==0) count = 16; |
| 2290 | 2335 | |
| 2291 | | if (m_count==0) m_count = m_register_contents & 0x000f; |
| 2292 | | if (m_count==0) m_count = 16; |
| 2336 | value = m_value_copy; |
| 2293 | 2337 | |
| 2294 | 2338 | // we are re-implementing the shift operations because we have to pulse |
| 2295 | 2339 | // the clock at each single shift anyway. |
| r15461 | r15462 | |
| 2297 | 2341 | // Note that count is never 0 |
| 2298 | 2342 | if (m_command == SRA) sign = value & 0x8000; |
| 2299 | 2343 | |
| 2300 | | for (int i=0; i < m_count; i++) |
| 2344 | for (int i=0; i < count; i++) |
| 2301 | 2345 | { |
| 2302 | 2346 | switch (m_command) |
| 2303 | 2347 | { |
| r15461 | r15462 | |
| 2323 | 2367 | set_status_bit(ST_C, carry); |
| 2324 | 2368 | set_status_bit(ST_OV, overflow); |
| 2325 | 2369 | compare_and_set_lae(m_current_value, 0); |
| 2326 | | |
| 2327 | | m_regnumber = (IR & 0x000f); |
| 2370 | m_address = m_address_saved; // Register address |
| 2371 | if (VERBOSE>7) LOG("tms99xx: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2328 | 2372 | break; |
| 2329 | 2373 | } |
| 2330 | 2374 | m_state++; |
| 2331 | 2375 | pulse_clock(2); |
| 2332 | 2376 | } |
| 2333 | 2377 | |
| 2334 | | void tms9900_device::alu_ai_ori() |
| 2378 | void tms99xx_device::alu_ai_ori() |
| 2335 | 2379 | { |
| 2336 | 2380 | UINT32 dest_new = 0; |
| 2337 | 2381 | switch (m_command) |
| 2338 | 2382 | { |
| 2339 | 2383 | case AI: |
| 2340 | | dest_new = m_current_value + m_register_contents; |
| 2384 | dest_new = m_current_value + m_value_copy; |
| 2341 | 2385 | // See status bit handling for Add |
| 2342 | 2386 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 2343 | | set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_register_contents) & 0x8000)!=0); |
| 2387 | set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_value_copy) & 0x8000)!=0); |
| 2344 | 2388 | break; |
| 2345 | 2389 | case ANDI: |
| 2346 | | dest_new = m_current_value & m_register_contents; |
| 2390 | dest_new = m_current_value & m_value_copy; |
| 2347 | 2391 | break; |
| 2348 | 2392 | case ORI: |
| 2349 | | dest_new = m_current_value | m_register_contents; |
| 2393 | dest_new = m_current_value | m_value_copy; |
| 2350 | 2394 | break; |
| 2351 | 2395 | } |
| 2352 | 2396 | m_current_value = dest_new & 0xffff; |
| 2397 | m_address = m_address_copy; |
| 2353 | 2398 | compare_and_set_lae(m_current_value, 0); |
| 2354 | 2399 | pulse_clock(2); |
| 2355 | 2400 | } |
| 2356 | 2401 | |
| 2357 | | void tms9900_device::alu_ci() |
| 2402 | void tms99xx_device::alu_ci() |
| 2358 | 2403 | { |
| 2359 | | compare_and_set_lae(m_register_contents, m_current_value); |
| 2404 | compare_and_set_lae(m_value_copy, m_current_value); |
| 2360 | 2405 | pulse_clock(2); |
| 2361 | 2406 | } |
| 2362 | 2407 | |
| 2363 | | void tms9900_device::alu_li() |
| 2408 | void tms99xx_device::alu_li() |
| 2364 | 2409 | { |
| 2365 | 2410 | compare_and_set_lae(m_current_value, 0); |
| 2366 | 2411 | pulse_clock(2); |
| 2367 | 2412 | } |
| 2368 | 2413 | |
| 2369 | | void tms9900_device::alu_lwpi() |
| 2414 | void tms99xx_device::alu_lwpi() |
| 2370 | 2415 | { |
| 2371 | | WP = m_current_value; |
| 2416 | WP = m_current_value & m_prgaddr_mask; |
| 2372 | 2417 | pulse_clock(2); |
| 2373 | 2418 | } |
| 2374 | 2419 | |
| 2375 | | void tms9900_device::alu_limi() |
| 2420 | void tms99xx_device::alu_limi() |
| 2376 | 2421 | { |
| 2377 | 2422 | ST = (ST & 0xfff0) | (m_current_value & 0x000f); |
| 2378 | | if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST); |
| 2423 | if (VERBOSE>7) LOG("tms99xx: ST = %04x\n", ST); |
| 2379 | 2424 | pulse_clock(2); |
| 2380 | 2425 | } |
| 2381 | 2426 | |
| 2382 | | void tms9900_device::alu_stwp_stst() |
| 2427 | void tms99xx_device::alu_stwp_stst() |
| 2383 | 2428 | { |
| 2384 | 2429 | if (m_command==STST) m_current_value = ST; |
| 2385 | 2430 | else m_current_value = WP; |
| 2386 | 2431 | pulse_clock(2); |
| 2387 | 2432 | } |
| 2388 | 2433 | |
| 2389 | | void tms9900_device::alu_external() |
| 2434 | void tms99xx_device::alu_external() |
| 2390 | 2435 | { |
| 2391 | 2436 | pulse_clock(10); |
| 2392 | 2437 | |
| r15461 | r15462 | |
| 2405 | 2450 | m_external_operation((IR >> 5) & 0x07, 1); |
| 2406 | 2451 | } |
| 2407 | 2452 | |
| 2408 | | void tms9900_device::alu_rtwp() |
| 2453 | void tms99xx_device::alu_rtwp() |
| 2409 | 2454 | { |
| 2410 | 2455 | switch (m_state) |
| 2411 | 2456 | { |
| 2412 | 2457 | case 0: |
| 2413 | | m_regnumber = 15; |
| 2458 | m_address = WP + 30; // R15 |
| 2414 | 2459 | break; |
| 2415 | 2460 | case 1: |
| 2416 | | ST = m_register_contents; |
| 2417 | | m_regnumber = 14; |
| 2461 | ST = m_current_value; |
| 2462 | m_address -= 2; // R14 |
| 2418 | 2463 | break; |
| 2419 | 2464 | case 2: |
| 2420 | | PC = m_register_contents; |
| 2421 | | m_regnumber = 13; |
| 2465 | PC = m_current_value & m_prgaddr_mask; |
| 2466 | m_address -= 2; // R13 |
| 2422 | 2467 | break; |
| 2423 | 2468 | case 3: |
| 2424 | | WP = m_register_contents; |
| 2469 | WP = m_current_value & m_prgaddr_mask; |
| 2425 | 2470 | break; |
| 2426 | 2471 | } |
| 2427 | 2472 | m_state++; |
| r15461 | r15462 | |
| 2429 | 2474 | } |
| 2430 | 2475 | |
| 2431 | 2476 | |
| 2432 | | void tms9900_device::alu_int() |
| 2477 | void tms99xx_device::alu_int() |
| 2433 | 2478 | { |
| 2434 | | if (VERBOSE>7) LOG("tms9900: INT state %d; irq_level %d\n", m_state, m_irq_level); |
| 2479 | if (VERBOSE>7) LOG("tms99xx: INT state %d; irq_level %d\n", m_state, m_irq_level); |
| 2435 | 2480 | switch (m_state) |
| 2436 | 2481 | { |
| 2437 | 2482 | case 0: |
| r15461 | r15462 | |
| 2442 | 2487 | } |
| 2443 | 2488 | else |
| 2444 | 2489 | { |
| 2445 | | if (m_irq_level == LOAD_INT) m_address = 0xfffc; |
| 2490 | if (m_irq_level == LOAD_INT) m_address = 0xfffc; // will be truncated for TMS9980 |
| 2446 | 2491 | else |
| 2447 | 2492 | { |
| 2448 | 2493 | m_address = (m_irq_level << 2); |
| r15461 | r15462 | |
| 2450 | 2495 | } |
| 2451 | 2496 | break; |
| 2452 | 2497 | case 1: |
| 2453 | | m_value = WP; // old WP |
| 2454 | | WP = m_current_value; // new WP |
| 2498 | m_address_copy = m_address; |
| 2499 | m_value_copy = WP; // old WP |
| 2500 | WP = m_current_value & m_prgaddr_mask; // new WP |
| 2455 | 2501 | m_current_value = ST; |
| 2456 | | m_regnumber = 15; |
| 2502 | m_address = (WP + 30) & m_prgaddr_mask; |
| 2457 | 2503 | break; |
| 2458 | 2504 | case 2: |
| 2459 | 2505 | m_current_value = PC; |
| 2460 | | m_regnumber = 14; |
| 2506 | m_address = (WP + 28) & m_prgaddr_mask; |
| 2461 | 2507 | break; |
| 2462 | 2508 | case 3: |
| 2463 | | m_current_value = m_value; // old WP |
| 2464 | | m_regnumber = 13; |
| 2509 | m_current_value = m_value_copy; // old WP |
| 2510 | m_address = (WP + 26) & m_prgaddr_mask; |
| 2465 | 2511 | break; |
| 2466 | 2512 | case 4: |
| 2467 | | m_address = (m_address + 2) & 0xfffe; |
| 2468 | | if (VERBOSE>7) LOG("tms9900: read from %04x\n", m_address); |
| 2513 | m_address = (m_address_copy + 2) & 0xfffe & m_prgaddr_mask; |
| 2514 | if (VERBOSE>7) LOG("tms99xx: read from %04x\n", m_address); |
| 2469 | 2515 | break; |
| 2470 | 2516 | case 5: |
| 2471 | | PC = m_current_value; |
| 2517 | PC = m_current_value & m_prgaddr_mask; |
| 2518 | m_irq_level = get_intlevel(ASSERT_LINE); |
| 2472 | 2519 | if (m_irq_level > 0 ) |
| 2473 | 2520 | { |
| 2474 | 2521 | ST = (ST & 0xfff0) | (m_irq_level - 1); |
| r15461 | r15462 | |
| 2480 | 2527 | } |
| 2481 | 2528 | |
| 2482 | 2529 | /**************************************************************************/ |
| 2483 | | UINT32 tms9900_device::execute_min_cycles() const |
| 2530 | UINT32 tms99xx_device::execute_min_cycles() const |
| 2484 | 2531 | { |
| 2485 | 2532 | return 2; |
| 2486 | 2533 | } |
| 2487 | 2534 | |
| 2488 | 2535 | // TODO: Compute this value, just a wild guess for the average |
| 2489 | | UINT32 tms9900_device::execute_max_cycles() const |
| 2536 | UINT32 tms99xx_device::execute_max_cycles() const |
| 2490 | 2537 | { |
| 2491 | 2538 | return 10; |
| 2492 | 2539 | } |
| 2493 | 2540 | |
| 2494 | | UINT32 tms9900_device::execute_input_lines() const |
| 2541 | UINT32 tms99xx_device::execute_input_lines() const |
| 2495 | 2542 | { |
| 2496 | 2543 | return 1; |
| 2497 | 2544 | } |
| r15461 | r15462 | |
| 2501 | 2548 | // execute_burn = nop |
| 2502 | 2549 | |
| 2503 | 2550 | // device_disasm_interface overrides |
| 2504 | | UINT32 tms9900_device::disasm_min_opcode_bytes() const |
| 2551 | UINT32 tms99xx_device::disasm_min_opcode_bytes() const |
| 2505 | 2552 | { |
| 2506 | 2553 | return 2; |
| 2507 | 2554 | } |
| 2508 | 2555 | |
| 2509 | | UINT32 tms9900_device::disasm_max_opcode_bytes() const |
| 2556 | UINT32 tms99xx_device::disasm_max_opcode_bytes() const |
| 2510 | 2557 | { |
| 2511 | 2558 | return 6; |
| 2512 | 2559 | } |
| 2513 | 2560 | |
| 2514 | | offs_t tms9900_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) |
| 2561 | offs_t tms99xx_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) |
| 2515 | 2562 | { |
| 2516 | 2563 | return Dasm9900(buffer, pc, TMS9900_ID, oprom, opram); |
| 2517 | 2564 | } |