src/emu/cpu/tms9900/tms9995.c
| r15423 | r15424 | |
| 1 | 1 | /* |
| 2 | | generate the tms9995 emulator |
| 2 | Texas Instruments TMS9995 |
| 3 | |
| 4 | +----------------+ |
| 5 | XTAL1 | 1 \/ 40| A15,CRUOUT |
| 6 | XTAL2,CLKIN | 2 39| A14 |
| 7 | CLKOUT | 3 38| A13 |
| 8 | D7 | 4 37| A12 |
| 9 | D6 | 5 36| A11 |
| 10 | D5 | 6 35| A10 |
| 11 | D4 | 7 34| A9 |
| 12 | D3 | 8 33| A8 |
| 13 | D2 | 9 32| A7 |
| 14 | V_CC |10 31| V_SS |
| 15 | D1 |11 30| A6 |
| 16 | D0 |12 29| A5 |
| 17 | CRUIN |13 28| A4 |
| 18 | /INT4,/EC |14 27| A3 |
| 19 | /INT1 |15 26| A2 |
| 20 | IAQ,HOLDA |16 25| A1 |
| 21 | /DBIN |17 24| A0 |
| 22 | /HOLD |18 23| READY |
| 23 | /WE,/CRUCLK |19 22| /RESET |
| 24 | /MEMEN |20 21| /NMI |
| 25 | +----------------+ |
| 26 | |
| 27 | XTAL1 in Crystal input pin for internal oscillator |
| 28 | XTAL2 in Crystal input pin for internal oscillator, or |
| 29 | CLKIN in Input pin for external oscillator |
| 30 | CLKOUT out Clock output signal (1:4 of the input signal frequency) |
| 31 | CRUIN in CRU input data |
| 32 | /INT4 in Interrupt level 4 input |
| 33 | /EC in Event counter |
| 34 | /INT1 in Interrupt level 1 input |
| 35 | IAQ out Instruction acquisition |
| 36 | HOLDA out Hold acknowledge |
| 37 | /WE out Data available for memory write |
| 38 | /CRUCLK out Communication register unit clock output |
| 39 | /MEMEN out Address bus contains memory address |
| 40 | /NMI in Non-maskable interrupt (/LOAD on TMS9900) |
| 41 | /RESET in Reset interrupt |
| 42 | READY in Memory/External CRU device ready for access |
| 43 | CRUOUT out Communication register unit data output |
| 44 | |
| 45 | V_CC +5V supply |
| 46 | V_SS 0V Ground reference |
| 47 | |
| 48 | A0-A15 out Address bus |
| 49 | D0-D7 in/out Data bus |
| 50 | |
| 51 | Note that Texas Instruments' bit numberings define bit 0 as the |
| 52 | most significant bit (different to most other systems). Also, the |
| 53 | system uses big-endian memory organisation: Storing the word 0x1234 at |
| 54 | address 0x0000 means that the byte 0x12 is stored at 0x0000 and byte 0x34 |
| 55 | is stored at 0x0001. |
| 56 | |
| 57 | The TMS9995 is a 16 bit microprocessor like the TMS9900, operating on |
| 58 | 16-bit words and using 16-bit opcodes. Memory transfer of 16-bit words |
| 59 | is achieved by a transfer of the most significant byte, followed by |
| 60 | the least significant byte. |
| 61 | |
| 62 | The 8-bit databus width allows the processor to exchange single bytes with |
| 63 | the external memory. |
| 64 | |
| 65 | See tms9900.c for some more details on the cycle-precise implementation. |
| 66 | |
| 67 | This implementation also features all control lines and the instruction |
| 68 | prefetch mechanism. Prefetching is explicitly triggered within the |
| 69 | microprograms. The TMS9995 specification does not reveal the exact |
| 70 | operations during the microprogram execution, so we have to look at the |
| 71 | required cycle numbers to guess what is happening. |
| 72 | |
| 73 | Auto wait state: |
| 74 | |
| 75 | In order to enable automatic wait state creation, the READY line must be |
| 76 | cleared on reset time. A good position to do this is MACHINE_RESET in |
| 77 | the driver. |
| 78 | |
| 79 | |
| 80 | References (see comments below) |
| 81 | ---------- |
| 82 | [1] Texas Instruments 9900 Microprocessor series: TMS9995 16-bit Microcomputer |
| 83 | |
| 84 | TODO: |
| 85 | - Fine-tune cycles |
| 86 | - State save |
| 87 | - Test HOLD |
| 88 | |
| 89 | Michael Zapf, June 2012 |
| 3 | 90 | */ |
| 4 | 91 | |
| 5 | | #include "emu.h" |
| 6 | | #include "debugger.h" |
| 7 | | #include "tms9900.h" |
| 92 | #include "tms9995.h" |
| 8 | 93 | |
| 9 | | #define TMS99XX_MODEL TMS9995_ID |
| 94 | /* tms9995 ST register bits. */ |
| 95 | enum |
| 96 | { |
| 97 | ST_LH = 0x8000, // Logical higher (unsigned comparison) |
| 98 | ST_AGT = 0x4000, // Arithmetical greater than (signed comparison) |
| 99 | ST_EQ = 0x2000, // Equal |
| 100 | ST_C = 0x1000, // Carry |
| 101 | ST_OV = 0x0800, // Overflow (when using signed operations) |
| 102 | ST_OP = 0x0400, // Odd parity (used with byte operations) |
| 103 | ST_X = 0x0200, // XOP |
| 104 | ST_OE = 0x0020, // Overflow interrupt enabled |
| 105 | ST_IM = 0x000f // Interrupt mask |
| 106 | }; |
| 10 | 107 | |
| 11 | | #include "99xxcore.h" |
| 108 | enum |
| 109 | { |
| 110 | PENDING_NMI = 1, |
| 111 | PENDING_MID = 2, |
| 112 | PENDING_LEVEL1 = 4, |
| 113 | PENDING_OVERFLOW = 8, |
| 114 | PENDING_DECR = 16, |
| 115 | PENDING_LEVEL4 = 32 |
| 116 | }; |
| 12 | 117 | |
| 13 | | DEFINE_LEGACY_CPU_DEVICE(TMS9995, tms9995); |
| 118 | #define LOG logerror |
| 119 | #define VERBOSE 1 |
| 120 | |
| 121 | /**************************************************************************** |
| 122 | Constructor |
| 123 | ****************************************************************************/ |
| 124 | |
| 125 | tms9995_device::tms9995_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 126 | : cpu_device(mconfig, TMS9995, "TMS9995", tag, owner, clock), |
| 127 | m_program_config("program", ENDIANNESS_BIG, 8, 16), |
| 128 | m_io_config("cru", ENDIANNESS_BIG, 8, 16), |
| 129 | m_prgspace(NULL), |
| 130 | m_cru(NULL) |
| 131 | { |
| 132 | } |
| 133 | |
| 134 | enum |
| 135 | { |
| 136 | TMS9995_PC=0, TMS9995_WP, TMS9995_STATUS, TMS9995_IR, |
| 137 | TMS9995_R0, TMS9995_R1, TMS9995_R2, TMS9995_R3, |
| 138 | TMS9995_R4, TMS9995_R5, TMS9995_R6, TMS9995_R7, |
| 139 | TMS9995_R8, TMS9995_R9, TMS9995_R10, TMS9995_R11, |
| 140 | TMS9995_R12, TMS9995_R13, TMS9995_R14, TMS9995_R15 |
| 141 | }; |
| 142 | |
| 143 | void tms9995_device::device_start() |
| 144 | { |
| 145 | const tms9995_config *conf = reinterpret_cast<const tms9995_config *>(static_config()); |
| 146 | |
| 147 | assert (conf != NULL); |
| 148 | |
| 149 | // TODO: Restore save state suport |
| 150 | |
| 151 | m_prgspace = space(AS_PROGRAM); // dimemory.h |
| 152 | m_cru = space(AS_IO); |
| 153 | |
| 154 | // Resolve our external connections |
| 155 | m_external_operation.resolve(conf->external_callback, *this); |
| 156 | m_iaq_line.resolve(conf->iaq_line, *this); |
| 157 | m_clock_out_line.resolve(conf->clock_out, *this); |
| 158 | m_wait_line.resolve(conf->wait_line, *this); |
| 159 | m_holda_line.resolve(conf->holda_line, *this); |
| 160 | |
| 161 | m_mp9537 = (conf->mode==NO_INTERNAL_RAM); |
| 162 | m_check_overflow = (conf->overflow==OVERFLOW_INT); |
| 163 | |
| 164 | if (VERBOSE>0) LOG("tms9995: Configured with%s internal memory and%s overflow interrupt\n", m_mp9537? " no" : "", m_check_overflow? "" : " no"); |
| 165 | |
| 166 | // set our instruction counter |
| 167 | m_icountptr = &m_icount; |
| 168 | |
| 169 | // Clear the interrupt flags |
| 170 | m_int_pending = 0; |
| 171 | |
| 172 | m_mid_flag = false; |
| 173 | m_nmi_active = false; |
| 174 | m_int_overflow = false; |
| 175 | m_int_decrementer = false; |
| 176 | |
| 177 | m_idle_state = false; |
| 178 | |
| 179 | // add the states for the debugger |
| 180 | for (int i=0; i < 20; i++) |
| 181 | { |
| 182 | // callimport = need to use the state_import method to write to the state variable |
| 183 | // callexport = need to use the state_export method to read the state variable |
| 184 | state_add(i, s_statename[i], m_state_any).callimport().callexport().formatstr("%04X"); |
| 185 | } |
| 186 | state_add(STATE_GENPC, "curpc", PC_debug).formatstr("%4s").noshow(); |
| 187 | state_add(STATE_GENFLAGS, "status", m_state_any).callimport().callexport().formatstr("%16s").noshow(); |
| 188 | |
| 189 | // Set up the lookup table for command decoding |
| 190 | build_command_lookup_table(); |
| 191 | } |
| 192 | |
| 193 | void tms9995_device::device_stop() |
| 194 | { |
| 195 | int k = 0; |
| 196 | if (VERBOSE>8) LOG("tms9995: Deleting lookup tables\n"); |
| 197 | while (m_lotables[k]!=NULL) delete[] m_lotables[k++]; |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | TMS9995 hard reset |
| 202 | The device reset is just the emulator's trigger for the reset procedure |
| 203 | which is invoked via the main loop. |
| 204 | |
| 205 | This also allows us to check the READY line at reset time, which is used |
| 206 | to enable automatic wait state creation. |
| 207 | */ |
| 208 | void tms9995_device::device_reset() |
| 209 | { |
| 210 | m_reset = true; // for the main loop |
| 211 | } |
| 212 | |
| 213 | const char* tms9995_device::s_statename[20] = |
| 214 | { |
| 215 | "PC ", "WP ", "ST ", "IR ", |
| 216 | "R0 ", "R1 ", "R2 ", "R3 ", |
| 217 | "R4 ", "R5 ", "R6 ", "R7 ", |
| 218 | "R8 ", "R9 ", "R10", "R11", |
| 219 | "R12", "R13", "R14", "R15" |
| 220 | }; |
| 221 | |
| 222 | /* |
| 223 | Write the contents of a register by external input (debugger) |
| 224 | Note: this is untested any may fail because of the prefetch feature of the CPU. |
| 225 | In particular it may be required to adjust the PC. |
| 226 | */ |
| 227 | void tms9995_device::state_import(const device_state_entry &entry) |
| 228 | { |
| 229 | int index = entry.index(); |
| 230 | switch (entry.index()) |
| 231 | { |
| 232 | case STATE_GENFLAGS: |
| 233 | // no action here; we do not allow import, as the flags are all |
| 234 | // bits of the STATUS register |
| 235 | break; |
| 236 | case TMS9995_PC: |
| 237 | PC = (UINT16)m_state_any; |
| 238 | break; |
| 239 | case TMS9995_WP: |
| 240 | WP = (UINT16)m_state_any; |
| 241 | break; |
| 242 | case TMS9995_STATUS: |
| 243 | ST = (UINT16)m_state_any; |
| 244 | break; |
| 245 | case TMS9995_IR: |
| 246 | m_instruction->IR = (UINT16)m_state_any; |
| 247 | break; |
| 248 | default: |
| 249 | // Workspace registers |
| 250 | if (index <= TMS9995_R15) |
| 251 | write_workspace_register_debug(index-TMS9995_R0, (UINT16)m_state_any); |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | Reads the contents of a register for display in the debugger. |
| 258 | */ |
| 259 | void tms9995_device::state_export(const device_state_entry &entry) |
| 260 | { |
| 261 | int index = entry.index(); |
| 262 | switch (entry.index()) |
| 263 | { |
| 264 | case STATE_GENFLAGS: |
| 265 | m_state_any = ST; |
| 266 | break; |
| 267 | case TMS9995_PC: |
| 268 | m_state_any = PC_debug; |
| 269 | break; |
| 270 | case TMS9995_WP: |
| 271 | m_state_any = WP; |
| 272 | break; |
| 273 | case TMS9995_STATUS: |
| 274 | m_state_any = ST; |
| 275 | break; |
| 276 | case TMS9995_IR: |
| 277 | m_state_any = m_instruction->IR; |
| 278 | break; |
| 279 | default: |
| 280 | // Workspace registers |
| 281 | if (index <= TMS9995_R15) |
| 282 | m_state_any = read_workspace_register_debug(index-TMS9995_R0); |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | state_string_export - export state as a string for the debugger |
| 289 | */ |
| 290 | void tms9995_device::state_string_export(const device_state_entry &entry, astring &string) |
| 291 | { |
| 292 | static const char *statestr = "LAECOPX-----IIII"; |
| 293 | char *flags = string.stringbuffer(16); |
| 294 | UINT16 val = 0x8000; |
| 295 | if (entry.index()==STATE_GENFLAGS) |
| 296 | { |
| 297 | for (int i=0; i < 16; i++) |
| 298 | { |
| 299 | flags[i] = ((val & ST)!=0)? statestr[i] : '.'; |
| 300 | val = (val >> 1) & 0x7fff; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | UINT16 tms9995_device::read_workspace_register_debug(int reg) |
| 306 | { |
| 307 | int temp = m_icount; |
| 308 | UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & 0xfffe); |
| 309 | m_icount = temp; |
| 310 | return value; |
| 311 | } |
| 312 | |
| 313 | void tms9995_device::write_workspace_register_debug(int reg, UINT16 data) |
| 314 | { |
| 315 | int temp = m_icount; |
| 316 | m_prgspace->write_word((WP+(reg<<1)) & 0xfffe, data); |
| 317 | m_icount = temp; |
| 318 | } |
| 319 | |
| 320 | const address_space_config *tms9995_device::memory_space_config(address_spacenum spacenum) const |
| 321 | { |
| 322 | switch (spacenum) |
| 323 | { |
| 324 | case AS_PROGRAM: |
| 325 | return &m_program_config; |
| 326 | |
| 327 | case AS_IO: |
| 328 | return &m_io_config; |
| 329 | |
| 330 | default: |
| 331 | return NULL; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /************************************************************************** |
| 336 | Microprograms for the CPU instructions |
| 337 | |
| 338 | The actions which are specific to the respective instruction are |
| 339 | invoked by repeated calls of ALU_xxx; each call increases a state |
| 340 | variable so that on the next call, the next part can be processed. |
| 341 | This saves us a lot of additional functions. |
| 342 | **************************************************************************/ |
| 343 | |
| 344 | /* |
| 345 | Define the indices for the micro-operation table. This is done for the sake |
| 346 | of a simpler microprogram definition as an UINT8[]. |
| 347 | */ |
| 348 | enum |
| 349 | { |
| 350 | PREFETCH, |
| 351 | PREFETCH_NO_INT, |
| 352 | MEMORY_READ, |
| 353 | MEMORY_WRITE, |
| 354 | WORD_READ, |
| 355 | WORD_WRITE, |
| 356 | OPERAND_ADDR, |
| 357 | INCREG, |
| 358 | INDX, |
| 359 | SET_IMM, |
| 360 | RETADDR, |
| 361 | RETADDR1, |
| 362 | CRU_INPUT, |
| 363 | CRU_OUTPUT, |
| 364 | ABORT, |
| 365 | END, |
| 366 | |
| 367 | ALU_NOP, |
| 368 | ALU_ADD_S_SXC, |
| 369 | ALU_B, |
| 370 | ALU_BLWP, |
| 371 | ALU_C, |
| 372 | ALU_CI, |
| 373 | ALU_CLR_SETO, |
| 374 | ALU_DIV, |
| 375 | ALU_DIVS, |
| 376 | ALU_EXTERNAL, |
| 377 | ALU_F3, |
| 378 | ALU_IMM_ARITHM, |
| 379 | ALU_JUMP, |
| 380 | ALU_LDCR, |
| 381 | ALU_LI, |
| 382 | ALU_LIMIWP, |
| 383 | ALU_LSTWP, |
| 384 | ALU_MOV, |
| 385 | ALU_MPY, |
| 386 | ALU_RTWP, |
| 387 | ALU_SBO_SBZ, |
| 388 | ALU_SHIFT, |
| 389 | ALU_SINGLE_ARITHM, |
| 390 | ALU_STCR, |
| 391 | ALU_STSTWP, |
| 392 | ALU_TB, |
| 393 | ALU_X, |
| 394 | ALU_XOP, |
| 395 | ALU_INT |
| 396 | }; |
| 397 | |
| 398 | #define MICROPROGRAM(_MP) \ |
| 399 | static const UINT8 _MP[] = |
| 400 | |
| 401 | MICROPROGRAM(operand_address_derivation) |
| 402 | { |
| 403 | RETADDR, 0, 0, 0, // Register direct 0 |
| 404 | WORD_READ, RETADDR, 0, 0, // Register indirect 1 (1) |
| 405 | WORD_READ, RETADDR, 0, 0, // Symbolic 1 (1) |
| 406 | WORD_READ, INCREG, WORD_WRITE, RETADDR1, // Reg indirect auto-increment 3 (1) (1) |
| 407 | WORD_READ, INDX, WORD_READ, RETADDR // Indexed 3 (1) (1) |
| 408 | }; |
| 409 | |
| 410 | MICROPROGRAM(add_s_sxc_mp) |
| 411 | { |
| 412 | OPERAND_ADDR, // x |
| 413 | MEMORY_READ, // 1 (1) |
| 414 | OPERAND_ADDR, // y |
| 415 | MEMORY_READ, // 1 (1) |
| 416 | ALU_ADD_S_SXC, // 0 |
| 417 | PREFETCH, // 1 (1) |
| 418 | MEMORY_WRITE, // 1 (1) |
| 419 | END |
| 420 | }; |
| 421 | |
| 422 | MICROPROGRAM(b_mp) |
| 423 | { |
| 424 | OPERAND_ADDR, |
| 425 | ALU_NOP, // Don't read, just use the address |
| 426 | ALU_B, |
| 427 | PREFETCH, |
| 428 | ALU_NOP, // Don't save the return address |
| 429 | END |
| 430 | }; |
| 431 | |
| 432 | MICROPROGRAM(bl_mp) |
| 433 | { |
| 434 | OPERAND_ADDR, |
| 435 | ALU_NOP, // Don't read, just use the address |
| 436 | ALU_B, // Re-use the alu operation from B |
| 437 | PREFETCH, |
| 438 | ALU_NOP, |
| 439 | MEMORY_WRITE, // Write R11 |
| 440 | ALU_NOP, |
| 441 | END |
| 442 | }; |
| 443 | |
| 444 | MICROPROGRAM(blwp_mp) |
| 445 | { |
| 446 | OPERAND_ADDR, // Determine source address |
| 447 | MEMORY_READ, |
| 448 | ALU_BLWP, // Got new WP, save it; increase address, save |
| 449 | MEMORY_WRITE, // save old ST to new R15 |
| 450 | ALU_BLWP, |
| 451 | MEMORY_WRITE, // save old PC to new R14 |
| 452 | ALU_BLWP, |
| 453 | MEMORY_WRITE, // save old WP to new R13 |
| 454 | ALU_BLWP, // retrieve address |
| 455 | MEMORY_READ, // Read new PC |
| 456 | ALU_BLWP, // Set new PC |
| 457 | PREFETCH, |
| 458 | ALU_NOP, |
| 459 | END |
| 460 | }; |
| 461 | |
| 462 | MICROPROGRAM(c_mp) |
| 463 | { |
| 464 | OPERAND_ADDR, // x |
| 465 | MEMORY_READ, // 1 (1) |
| 466 | OPERAND_ADDR, // y |
| 467 | MEMORY_READ, // 1 (1) |
| 468 | ALU_C, // 0 |
| 469 | PREFETCH, // 1 (1) |
| 470 | ALU_NOP, // 1 |
| 471 | END |
| 472 | }; |
| 473 | |
| 474 | MICROPROGRAM(ci_mp) |
| 475 | { |
| 476 | MEMORY_READ, // 1 (reg) |
| 477 | SET_IMM, // 0 |
| 478 | MEMORY_READ, // 1 (imm) |
| 479 | ALU_CI, // (1) set status |
| 480 | PREFETCH, // 1 |
| 481 | ALU_NOP, // 1 |
| 482 | END |
| 483 | }; |
| 484 | |
| 485 | MICROPROGRAM(coc_czc_mp) |
| 486 | { |
| 487 | OPERAND_ADDR, |
| 488 | MEMORY_READ, |
| 489 | ALU_F3, |
| 490 | MEMORY_READ, |
| 491 | ALU_F3, |
| 492 | PREFETCH, |
| 493 | ALU_NOP, |
| 494 | END |
| 495 | }; |
| 496 | |
| 497 | MICROPROGRAM(clr_seto_mp) |
| 498 | { |
| 499 | OPERAND_ADDR, |
| 500 | ALU_NOP, |
| 501 | ALU_CLR_SETO, // (1) |
| 502 | PREFETCH, // 1 |
| 503 | MEMORY_WRITE, // 1 |
| 504 | END |
| 505 | }; |
| 506 | |
| 507 | MICROPROGRAM(divide_mp) |
| 508 | { |
| 509 | OPERAND_ADDR, // Address of divisor S in Q=W1W2/S |
| 510 | MEMORY_READ, // Get S |
| 511 | ALU_DIV, |
| 512 | MEMORY_READ, // Get W1 |
| 513 | ALU_DIV, // Check for overflow; skip next instruction if not |
| 514 | ABORT, |
| 515 | MEMORY_READ, // Get W2 |
| 516 | ALU_DIV, // Calculate quotient |
| 517 | MEMORY_WRITE, // Write quotient to &W1 |
| 518 | ALU_DIV, |
| 519 | PREFETCH, |
| 520 | MEMORY_WRITE, // Write remainder to &W2 |
| 521 | END |
| 522 | }; |
| 523 | |
| 524 | MICROPROGRAM(divide_signed_mp) |
| 525 | { |
| 526 | OPERAND_ADDR, // Address of divisor S in Q=W1W2/S |
| 527 | MEMORY_READ, // Get S |
| 528 | ALU_DIV, |
| 529 | MEMORY_READ, // Get W1 |
| 530 | ALU_DIV, // |
| 531 | MEMORY_READ, // Get W2 |
| 532 | ALU_DIV, // Check for overflow, skip next instruction if not |
| 533 | ABORT, |
| 534 | ALU_DIV, // Calculate quotient |
| 535 | MEMORY_WRITE, // Write quotient to &W1 |
| 536 | ALU_DIV, |
| 537 | PREFETCH, |
| 538 | MEMORY_WRITE, // Write remainder to &W2 |
| 539 | END |
| 540 | }; |
| 541 | |
| 542 | MICROPROGRAM(external_mp) |
| 543 | { |
| 544 | ALU_NOP, |
| 545 | ALU_NOP, |
| 546 | ALU_NOP, |
| 547 | ALU_NOP, |
| 548 | ALU_NOP, |
| 549 | ALU_EXTERNAL, |
| 550 | PREFETCH, |
| 551 | ALU_NOP, |
| 552 | END |
| 553 | }; |
| 554 | |
| 555 | MICROPROGRAM(imm_arithm_mp) |
| 556 | { |
| 557 | MEMORY_READ, |
| 558 | SET_IMM, // 0 |
| 559 | MEMORY_READ, // 1 (1) |
| 560 | ALU_IMM_ARITHM, // 0 |
| 561 | PREFETCH, // 1 (1) |
| 562 | MEMORY_WRITE, |
| 563 | END |
| 564 | }; |
| 565 | |
| 566 | MICROPROGRAM(jump_mp) |
| 567 | { |
| 568 | ALU_JUMP, |
| 569 | PREFETCH, |
| 570 | ALU_NOP, |
| 571 | END |
| 572 | }; |
| 573 | |
| 574 | MICROPROGRAM(ldcr_mp) |
| 575 | { |
| 576 | ALU_LDCR, |
| 577 | OPERAND_ADDR, |
| 578 | MEMORY_READ, // Get source data |
| 579 | ALU_LDCR, // Save it, point to R12 |
| 580 | WORD_READ, // Get R12 |
| 581 | ALU_LDCR, // Prepare CRU operation |
| 582 | CRU_OUTPUT, |
| 583 | ALU_NOP, |
| 584 | PREFETCH, |
| 585 | ALU_NOP, |
| 586 | END |
| 587 | }; |
| 588 | |
| 589 | MICROPROGRAM(li_mp) |
| 590 | { |
| 591 | SET_IMM, // 0 |
| 592 | MEMORY_READ, // 1 (1) |
| 593 | ALU_LI, // 0 |
| 594 | PREFETCH, // 1 (1) |
| 595 | MEMORY_WRITE, |
| 596 | END |
| 597 | }; |
| 598 | |
| 599 | MICROPROGRAM(limi_lwpi_mp) |
| 600 | { |
| 601 | SET_IMM, // 0 |
| 602 | MEMORY_READ, // 1 (1) |
| 603 | ALU_NOP, // 1 |
| 604 | ALU_LIMIWP, // (1) |
| 605 | PREFETCH, // 1 |
| 606 | ALU_NOP, // 1 |
| 607 | END |
| 608 | }; |
| 609 | |
| 610 | MICROPROGRAM(lst_lwp_mp) |
| 611 | { |
| 612 | MEMORY_READ, |
| 613 | ALU_NOP, |
| 614 | ALU_LSTWP, |
| 615 | PREFETCH, |
| 616 | ALU_NOP, |
| 617 | END |
| 618 | }; |
| 619 | |
| 620 | MICROPROGRAM(mov_mp) |
| 621 | { |
| 622 | OPERAND_ADDR, // 0 |
| 623 | MEMORY_READ, // 1 (1) |
| 624 | OPERAND_ADDR, // 0 |
| 625 | ALU_MOV, // 1 |
| 626 | PREFETCH, |
| 627 | MEMORY_WRITE, // 1 (1) |
| 628 | END |
| 629 | }; |
| 630 | |
| 631 | MICROPROGRAM(multiply_mp) |
| 632 | { |
| 633 | OPERAND_ADDR, |
| 634 | MEMORY_READ, |
| 635 | ALU_MPY, |
| 636 | MEMORY_READ, |
| 637 | ALU_MPY, |
| 638 | MEMORY_WRITE, |
| 639 | ALU_MPY, |
| 640 | PREFETCH, |
| 641 | MEMORY_WRITE, |
| 642 | END |
| 643 | }; |
| 644 | |
| 645 | MICROPROGRAM(rtwp_mp) |
| 646 | { |
| 647 | ALU_RTWP, |
| 648 | MEMORY_READ, |
| 649 | ALU_RTWP, |
| 650 | MEMORY_READ, |
| 651 | ALU_RTWP, |
| 652 | MEMORY_READ, |
| 653 | ALU_RTWP, |
| 654 | PREFETCH, |
| 655 | ALU_NOP, |
| 656 | END |
| 657 | }; |
| 658 | |
| 659 | MICROPROGRAM(sbo_sbz_mp) |
| 660 | { |
| 661 | ALU_SBO_SBZ, // Set address = &R12 |
| 662 | WORD_READ, // Read R12 |
| 663 | ALU_SBO_SBZ, // Add offset |
| 664 | CRU_OUTPUT, // output via CRU |
| 665 | ALU_NOP, |
| 666 | PREFETCH, |
| 667 | ALU_NOP, |
| 668 | END |
| 669 | }; |
| 670 | |
| 671 | MICROPROGRAM(shift_mp) |
| 672 | { |
| 673 | MEMORY_READ, |
| 674 | ALU_SHIFT, // skip next operation if count != 0 |
| 675 | MEMORY_READ, // if count=0 we must read R0 |
| 676 | ALU_SHIFT, // do the shift |
| 677 | PREFETCH, |
| 678 | MEMORY_WRITE, |
| 679 | END |
| 680 | }; |
| 681 | |
| 682 | MICROPROGRAM(single_arithm_mp) |
| 683 | { |
| 684 | OPERAND_ADDR, |
| 685 | MEMORY_READ, // This one is not done for CLR/SETO |
| 686 | ALU_SINGLE_ARITHM, |
| 687 | PREFETCH, |
| 688 | MEMORY_WRITE, |
| 689 | END |
| 690 | }; |
| 691 | |
| 692 | MICROPROGRAM(stcr_mp) |
| 693 | { |
| 694 | ALU_STCR, // Check for byte operation |
| 695 | OPERAND_ADDR, // Source operand |
| 696 | ALU_STCR, // Save, set R12 |
| 697 | WORD_READ, // Read R12 |
| 698 | ALU_STCR, |
| 699 | CRU_INPUT, |
| 700 | ALU_STCR, |
| 701 | PREFETCH, |
| 702 | MEMORY_WRITE, |
| 703 | END |
| 704 | }; |
| 705 | |
| 706 | MICROPROGRAM(stst_stwp_mp) |
| 707 | { |
| 708 | ALU_STSTWP, |
| 709 | ALU_NOP, |
| 710 | PREFETCH, |
| 711 | MEMORY_WRITE, |
| 712 | END |
| 713 | }; |
| 714 | |
| 715 | MICROPROGRAM(tb_mp) |
| 716 | { |
| 717 | ALU_TB, |
| 718 | WORD_READ, |
| 719 | ALU_TB, |
| 720 | CRU_INPUT, |
| 721 | ALU_TB, |
| 722 | PREFETCH, |
| 723 | ALU_NOP, |
| 724 | END |
| 725 | }; |
| 726 | |
| 727 | MICROPROGRAM(x_mp) |
| 728 | { |
| 729 | OPERAND_ADDR, |
| 730 | MEMORY_READ, |
| 731 | ALU_X, |
| 732 | END // should not be reached |
| 733 | }; |
| 734 | |
| 735 | MICROPROGRAM(xop_mp) |
| 736 | { |
| 737 | OPERAND_ADDR, // Determine source address |
| 738 | ALU_XOP, // Save it; determine XOP number |
| 739 | MEMORY_READ, // Read new WP |
| 740 | ALU_XOP, // |
| 741 | MEMORY_WRITE, // save source address to new R11 |
| 742 | ALU_XOP, |
| 743 | MEMORY_WRITE, // save old ST to new R15 |
| 744 | ALU_XOP, |
| 745 | MEMORY_WRITE, // save old PC to new R14 |
| 746 | ALU_XOP, |
| 747 | MEMORY_WRITE, // save old WP to new R13 |
| 748 | ALU_XOP, |
| 749 | MEMORY_READ, // Read new PC |
| 750 | ALU_XOP, // set new PC, set X flag |
| 751 | PREFETCH, |
| 752 | ALU_NOP, |
| 753 | END |
| 754 | }; |
| 755 | |
| 756 | MICROPROGRAM(xor_mp) |
| 757 | { |
| 758 | OPERAND_ADDR, |
| 759 | MEMORY_READ, |
| 760 | ALU_F3, |
| 761 | MEMORY_READ, |
| 762 | ALU_F3, |
| 763 | PREFETCH, |
| 764 | MEMORY_WRITE, |
| 765 | END |
| 766 | }; |
| 767 | |
| 768 | MICROPROGRAM(int_mp) |
| 769 | { |
| 770 | ALU_INT, // 1 |
| 771 | MEMORY_READ, // 1 (1) |
| 772 | ALU_INT, // 2 |
| 773 | MEMORY_WRITE, // 1 (1) |
| 774 | ALU_INT, // 1 |
| 775 | MEMORY_WRITE, // 1 (1) |
| 776 | ALU_INT, // 1 |
| 777 | MEMORY_WRITE, // 1 (1) |
| 778 | ALU_INT, // 1 |
| 779 | MEMORY_READ, // 1 (1) |
| 780 | ALU_INT, // 0 |
| 781 | PREFETCH_NO_INT, // 1 (1) (prefetch happens in parallel to the previous operation) |
| 782 | ALU_NOP, // 1 (+decode in parallel; actually performed right after prefetch) |
| 783 | ALU_NOP, // 1 |
| 784 | END |
| 785 | }; |
| 786 | |
| 787 | const tms9995_device::ophandler tms9995_device::s_microoperation[] = |
| 788 | { |
| 789 | &tms9995_device::int_prefetch_and_decode, |
| 790 | &tms9995_device::prefetch_and_decode, |
| 791 | &tms9995_device::mem_read, |
| 792 | &tms9995_device::mem_write, |
| 793 | &tms9995_device::word_read, |
| 794 | &tms9995_device::word_write, |
| 795 | &tms9995_device::operand_address_subprogram, |
| 796 | &tms9995_device::increment_register, |
| 797 | &tms9995_device::indexed_addressing, |
| 798 | &tms9995_device::set_immediate, |
| 799 | &tms9995_device::return_with_address, |
| 800 | &tms9995_device::return_with_address_copy, |
| 801 | &tms9995_device::cru_input_operation, |
| 802 | &tms9995_device::cru_output_operation, |
| 803 | &tms9995_device::abort_operation, |
| 804 | &tms9995_device::command_completed, |
| 805 | |
| 806 | &tms9995_device::alu_nop, |
| 807 | &tms9995_device::alu_add_s_sxc, |
| 808 | &tms9995_device::alu_b, |
| 809 | &tms9995_device::alu_blwp, |
| 810 | &tms9995_device::alu_c, |
| 811 | &tms9995_device::alu_ci, |
| 812 | &tms9995_device::alu_clr_seto, |
| 813 | &tms9995_device::alu_divide, |
| 814 | &tms9995_device::alu_divide_signed, |
| 815 | &tms9995_device::alu_external, |
| 816 | &tms9995_device::alu_f3, |
| 817 | &tms9995_device::alu_imm_arithm, |
| 818 | &tms9995_device::alu_jump, |
| 819 | &tms9995_device::alu_ldcr, |
| 820 | &tms9995_device::alu_li, |
| 821 | &tms9995_device::alu_limi_lwpi, |
| 822 | &tms9995_device::alu_lst_lwp, |
| 823 | &tms9995_device::alu_mov, |
| 824 | &tms9995_device::alu_multiply, |
| 825 | &tms9995_device::alu_rtwp, |
| 826 | &tms9995_device::alu_sbo_sbz, |
| 827 | &tms9995_device::alu_shift, |
| 828 | &tms9995_device::alu_single_arithm, |
| 829 | &tms9995_device::alu_stcr, |
| 830 | &tms9995_device::alu_stst_stwp, |
| 831 | &tms9995_device::alu_tb, |
| 832 | &tms9995_device::alu_x, |
| 833 | &tms9995_device::alu_xop, |
| 834 | &tms9995_device::alu_int |
| 835 | }; |
| 836 | |
| 837 | /***************************************************************************** |
| 838 | CPU instructions |
| 839 | *****************************************************************************/ |
| 840 | |
| 841 | /* |
| 842 | Available instructions |
| 843 | MID is not a real instruction but stands for an invalid operation which |
| 844 | triggers a "macro instruction detect" interrupt. Neither is INTR which |
| 845 | indicates an interrupt handling in progress. |
| 846 | */ |
| 847 | enum |
| 848 | { |
| 849 | MID=0, A, AB, ABS, AI, ANDI, B, BL, BLWP, C, |
| 850 | CB, CI, CKOF, CKON, CLR, COC, CZC, DEC, DECT, DIV, |
| 851 | DIVS, IDLE, INC, INCT, INV, JEQ, JGT, JH, JHE, JL, |
| 852 | JLE, JLT, JMP, JNC, JNE, JNO, JOC, JOP, LDCR, LI, |
| 853 | LIMI, LREX, LST, LWP, LWPI, MOV, MOVB, MPY, MPYS, NEG, |
| 854 | ORI, RSET, RTWP, S, SB, SBO, SBZ, SETO, SLA, SOC, |
| 855 | SOCB, SRA, SRC, SRL, STCR, STST, STWP, SWPB, SZC, SZCB, |
| 856 | TB, X, XOP, XOR, INTR |
| 857 | }; |
| 858 | |
| 859 | static const char opname[][5] = |
| 860 | { "MID ", "A ", "AB ", "ABS ", "AI ", "ANDI", "B ", "BL ", "BLWP", "C ", |
| 861 | "CB ", "CI ", "CKOF", "CKON", "CLR ", "COC ", "CZC ", "DEC ", "DECT", "DIV ", |
| 862 | "DIVS", "IDLE", "INC ", "INCT", "INV ", "JEQ ", "JGT ", "JH ", "JHE ", "JL ", |
| 863 | "JLE ", "JLT ", "JMP ", "JNC ", "JNE ", "JNO ", "JOC ", "JOP ", "LDCR", "LI ", |
| 864 | "LIMI", "LREX", "LST ", "LWP ", "LWPI", "MOV ", "MOVB", "MPY ", "MPYS", "NEG ", |
| 865 | "ORI ", "RSET", "RTWP", "S ", "SB ", "SBO ", "SBZ ", "SETO", "SLA ", "SOC ", |
| 866 | "SOCB", "SRA ", "SRC ", "SRL ", "STCR", "STST", "STWP", "SWPB", "SZC ", "SZCB", |
| 867 | "TB ", "X ", "XOP ", "XOR ", "*int" |
| 868 | }; |
| 869 | |
| 870 | /* |
| 871 | Formats: |
| 872 | |
| 873 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| 874 | ----+------------------------------------------------+ |
| 875 | 1 | Opcode | B | Td | RegNr | Ts | RegNr | |
| 876 | +--------+---+----+------------+----+------------+ |
| 877 | 2 | Opcode | Displacement | |
| 878 | +-----------------------+------------------------+ |
| 879 | 3 | Opcode | RegNr | Ts | RegNr | |
| 880 | +-----------------+------------+----+------------+ |
| 881 | 4 | Opcode | Count | Ts | RegNr | |
| 882 | +-----------------+------------+----+------------+ |
| 883 | 5 | Opcode | Count | RegNr | |
| 884 | +-----------------------+-----------+------------+ |
| 885 | 6 | Opcode | Ts | RegNr | |
| 886 | +------------------------------+----+------------+ |
| 887 | 7 | Opcode |0| 0| 0| 0| 0 | |
| 888 | +---------------------------------+-+--+--+--+---+ |
| 889 | 8 | Opcode |0| RegNr | |
| 890 | +---------------------------------+-+------------+ |
| 891 | 9 | Opcode | Reg/Nr | Ts | RegNr | |
| 892 | +-----------------+------------+----+------------+ |
| 893 | 10 | Opcode | Ts | RegNr | (DIVS, MPYS) |
| 894 | +------------------------------+----+------------+ |
| 895 | 11 | Opcode | RegNr | (LST, LWP) |
| 896 | +-----------------------------------+------------+ |
| 897 | */ |
| 898 | |
| 899 | /* |
| 900 | Defines the number of bits from the left which are significant for the |
| 901 | command in the respective format. |
| 902 | */ |
| 903 | static const int format_mask_len[] = |
| 904 | { |
| 905 | 0, 4, 8, 6, 6, 8, 10, 16, 12, 6, 10, 12 |
| 906 | }; |
| 907 | |
| 908 | const tms9995_device::tms_instruction tms9995_device::s_command[] = |
| 909 | { |
| 910 | // Base opcode list |
| 911 | // Opcode, ID, format, microprg |
| 912 | { 0x0080, LST, 11, lst_lwp_mp }, |
| 913 | { 0x0090, LWP, 11, lst_lwp_mp }, |
| 914 | { 0x0180, DIVS, 10, divide_signed_mp }, |
| 915 | { 0x01C0, MPYS, 10, multiply_mp }, |
| 916 | { 0x0200, LI, 8, li_mp }, |
| 917 | { 0x0220, AI, 8, imm_arithm_mp }, |
| 918 | { 0x0240, ANDI, 8, imm_arithm_mp }, |
| 919 | { 0x0260, ORI, 8, imm_arithm_mp }, |
| 920 | { 0x0280, CI, 8, ci_mp }, |
| 921 | { 0x02a0, STWP, 8, stst_stwp_mp }, |
| 922 | { 0x02c0, STST, 8, stst_stwp_mp }, |
| 923 | { 0x02e0, LWPI, 8, limi_lwpi_mp }, |
| 924 | { 0x0300, LIMI, 8, limi_lwpi_mp }, |
| 925 | { 0x0340, IDLE, 7, external_mp }, |
| 926 | { 0x0360, RSET, 7, external_mp }, |
| 927 | { 0x0380, RTWP, 7, rtwp_mp }, |
| 928 | { 0x03a0, CKON, 7, external_mp }, |
| 929 | { 0x03c0, CKOF, 7, external_mp }, |
| 930 | { 0x03e0, LREX, 7, external_mp }, |
| 931 | { 0x0400, BLWP, 6, blwp_mp }, |
| 932 | { 0x0440, B, 6, b_mp }, |
| 933 | { 0x0480, X, 6, x_mp }, |
| 934 | { 0x04c0, CLR, 6, clr_seto_mp }, |
| 935 | { 0x0500, NEG, 6, single_arithm_mp }, |
| 936 | { 0x0540, INV, 6, single_arithm_mp }, |
| 937 | { 0x0580, INC, 6, single_arithm_mp }, |
| 938 | { 0x05c0, INCT, 6, single_arithm_mp }, |
| 939 | { 0x0600, DEC, 6, single_arithm_mp }, |
| 940 | { 0x0640, DECT, 6, single_arithm_mp }, |
| 941 | { 0x0680, BL, 6, bl_mp }, |
| 942 | { 0x06c0, SWPB, 6, single_arithm_mp }, |
| 943 | { 0x0700, SETO, 6, clr_seto_mp }, |
| 944 | { 0x0740, ABS, 6, single_arithm_mp }, |
| 945 | { 0x0800, SRA, 5, shift_mp }, |
| 946 | { 0x0900, SRL, 5, shift_mp }, |
| 947 | { 0x0a00, SLA, 5, shift_mp }, |
| 948 | { 0x0b00, SRC, 5, shift_mp }, |
| 949 | { 0x1000, JMP, 2, jump_mp }, |
| 950 | { 0x1100, JLT, 2, jump_mp }, |
| 951 | { 0x1200, JLE, 2, jump_mp }, |
| 952 | { 0x1300, JEQ, 2, jump_mp }, |
| 953 | { 0x1400, JHE, 2, jump_mp }, |
| 954 | { 0x1500, JGT, 2, jump_mp }, |
| 955 | { 0x1600, JNE, 2, jump_mp }, |
| 956 | { 0x1700, JNC, 2, jump_mp }, |
| 957 | { 0x1800, JOC, 2, jump_mp }, |
| 958 | { 0x1900, JNO, 2, jump_mp }, |
| 959 | { 0x1a00, JL, 2, jump_mp }, |
| 960 | { 0x1b00, JH, 2, jump_mp }, |
| 961 | { 0x1c00, JOP, 2, jump_mp }, |
| 962 | { 0x1d00, SBO, 2, sbo_sbz_mp }, |
| 963 | { 0x1e00, SBZ, 2, sbo_sbz_mp }, |
| 964 | { 0x1f00, TB, 2, tb_mp }, |
| 965 | { 0x2000, COC, 3, coc_czc_mp }, |
| 966 | { 0x2400, CZC, 3, coc_czc_mp }, |
| 967 | { 0x2800, XOR, 3, xor_mp }, |
| 968 | { 0x2c00, XOP, 3, xop_mp }, |
| 969 | { 0x3000, LDCR, 4, ldcr_mp }, |
| 970 | { 0x3400, STCR, 4, stcr_mp }, |
| 971 | { 0x3800, MPY, 9, multiply_mp }, |
| 972 | { 0x3c00, DIV, 9, divide_mp }, |
| 973 | { 0x4000, SZC, 1, add_s_sxc_mp }, |
| 974 | { 0x5000, SZCB, 1, add_s_sxc_mp }, |
| 975 | { 0x6000, S, 1, add_s_sxc_mp }, |
| 976 | { 0x7000, SB, 1, add_s_sxc_mp }, |
| 977 | { 0x8000, C, 1, c_mp }, |
| 978 | { 0x9000, CB, 1, c_mp }, |
| 979 | { 0xa000, A, 1, add_s_sxc_mp }, |
| 980 | { 0xb000, AB, 1, add_s_sxc_mp }, |
| 981 | { 0xc000, MOV, 1, mov_mp }, |
| 982 | { 0xd000, MOVB, 1, mov_mp }, |
| 983 | { 0xe000, SOC, 1, add_s_sxc_mp }, |
| 984 | { 0xf000, SOCB, 1, add_s_sxc_mp } |
| 985 | }; |
| 986 | |
| 987 | /* |
| 988 | Create a B-tree for looking up the commands. Each node can carry up to |
| 989 | 16 entries, indexed by 4 consecutive bits in the opcode. |
| 990 | |
| 991 | See tms9900.c for a detailed description. |
| 992 | */ |
| 993 | void tms9995_device::build_command_lookup_table() |
| 994 | { |
| 995 | int i = 0; |
| 996 | int cmdindex = 0; |
| 997 | int bitcount; |
| 998 | const tms_instruction *inst; |
| 999 | UINT16 opcode; |
| 1000 | int k = 0; |
| 1001 | |
| 1002 | m_command_lookup_table = new lookup_entry[16]; |
| 1003 | // We use lotables as a list of allocated tables - to be able to delete them |
| 1004 | // at the end. |
| 1005 | m_lotables[k++] = m_command_lookup_table; |
| 1006 | |
| 1007 | lookup_entry* table = m_command_lookup_table; |
| 1008 | for (int j=0; j < 16; j++) |
| 1009 | { |
| 1010 | table[j].entry = NULL; |
| 1011 | table[j].next_digit = NULL; |
| 1012 | } |
| 1013 | |
| 1014 | do |
| 1015 | { |
| 1016 | inst = &s_command[i]; |
| 1017 | table = m_command_lookup_table; |
| 1018 | if (VERBOSE>8) LOG("tms9995: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]); |
| 1019 | bitcount = 4; |
| 1020 | opcode = inst->opcode; |
| 1021 | cmdindex = (opcode>>12) & 0x000f; |
| 1022 | |
| 1023 | while (bitcount < format_mask_len[inst->format]) |
| 1024 | { |
| 1025 | // Descend |
| 1026 | if (table[cmdindex].next_digit == NULL) |
| 1027 | { |
| 1028 | if (VERBOSE>8) LOG("tms9995: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex); |
| 1029 | table[cmdindex].next_digit = new lookup_entry[16]; |
| 1030 | m_lotables[k++] = table[cmdindex].next_digit; |
| 1031 | for (int j=0; j < 16; j++) |
| 1032 | { |
| 1033 | table[cmdindex].next_digit[j].next_digit = NULL; |
| 1034 | table[cmdindex].next_digit[j].entry = NULL; |
| 1035 | } |
| 1036 | } |
| 1037 | else |
| 1038 | { |
| 1039 | if (VERBOSE>8) LOG("tms9995: found a table at bitcount=%d\n", bitcount); |
| 1040 | } |
| 1041 | |
| 1042 | table = table[cmdindex].next_digit; |
| 1043 | |
| 1044 | bitcount = bitcount+4; |
| 1045 | opcode <<= 4; |
| 1046 | cmdindex = (opcode>>12) & 0x000f; |
| 1047 | if (VERBOSE>8) LOG("tms9995: next index=%x\n", cmdindex); |
| 1048 | } |
| 1049 | |
| 1050 | if (VERBOSE>8) LOG("tms9995: bitcount=%d\n", bitcount); |
| 1051 | // We are at the target level |
| 1052 | // Need to fill in the same entry for all values in the bitcount |
| 1053 | // (if a command needs 10 bits we have to copy it four |
| 1054 | // times for all combinations with 12 bits) |
| 1055 | for (int j=0; j < (1<<(bitcount-format_mask_len[inst->format])); j++) |
| 1056 | { |
| 1057 | if (VERBOSE>8) LOG("tms9995: opcode=%04x at position %d\n", inst->opcode, cmdindex+j); |
| 1058 | table[cmdindex+j].entry = inst; |
| 1059 | } |
| 1060 | |
| 1061 | i++; |
| 1062 | } while (inst->opcode != 0xf000); |
| 1063 | |
| 1064 | m_lotables[k++] = NULL; |
| 1065 | if (VERBOSE>8) LOG("tms9995: Allocated %d tables\n", k); |
| 1066 | } |
| 1067 | |
| 1068 | /* |
| 1069 | Main execution loop |
| 1070 | |
| 1071 | For each invocation of execute_run, a number of loop iterations has been |
| 1072 | calculated before (m_icount). Each loop iteration is one clock cycle. |
| 1073 | The loop must be executed for the number of times that corresponds to the |
| 1074 | time until the next timer event. |
| 1075 | */ |
| 1076 | void tms9995_device::execute_run() |
| 1077 | { |
| 1078 | if (m_reset) service_interrupt(); |
| 1079 | |
| 1080 | if (VERBOSE>5) LOG("tms9995: calling execute_run for %d cycles\n", m_icount); |
| 1081 | do |
| 1082 | { |
| 1083 | // Normal operation |
| 1084 | if (m_check_ready && m_ready_state == false) |
| 1085 | { |
| 1086 | // We are in a wait state |
| 1087 | set_wait_state(true); |
| 1088 | if (VERBOSE>2) LOG("tms9995: wait state\n"); |
| 1089 | // The clock output should be used to change the state of an outer |
| 1090 | // device which operates the READY line |
| 1091 | pulse_clock(1); |
| 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | if (m_check_hold && m_hold_state) |
| 1096 | { |
| 1097 | set_hold_state(true); |
| 1098 | if (VERBOSE>6) LOG("tms9995: hold state\n"); |
| 1099 | pulse_clock(1); |
| 1100 | } |
| 1101 | else |
| 1102 | { |
| 1103 | set_wait_state(false); |
| 1104 | set_hold_state(false); |
| 1105 | |
| 1106 | m_check_ready = false; |
| 1107 | |
| 1108 | if (VERBOSE>8) LOG("tms9995: main loop, operation %s, MPC = %d\n", opname[m_instruction->command], MPC); |
| 1109 | (this->*s_microoperation[m_instruction->program[MPC]])(); |
| 1110 | |
| 1111 | // For multi-pass operations where the MPC should not advance |
| 1112 | // or when we have put in a new microprogram |
| 1113 | m_pass--; |
| 1114 | if (m_pass<=0) |
| 1115 | { |
| 1116 | m_pass = 1; |
| 1117 | MPC++; |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | } while (m_icount>0); |
| 1122 | if (VERBOSE>5) LOG("tms9995: cycles expired; will return soon.\n"); |
| 1123 | } |
| 1124 | |
| 1125 | /**************************************************************************/ |
| 1126 | |
| 1127 | /* |
| 1128 | Interrupt input |
| 1129 | output |
| 1130 | m_nmi_state |
| 1131 | m_irq_level |
| 1132 | flag[2], flag[4] |
| 1133 | */ |
| 1134 | void tms9995_device::execute_set_input(int irqline, int state) |
| 1135 | { |
| 1136 | if (irqline == INPUT_LINE_NMI) |
| 1137 | { |
| 1138 | m_nmi_active = (state==ASSERT_LINE); |
| 1139 | if (VERBOSE>3) LOG("tms9995: NMI interrupt line state=%d\n", state); |
| 1140 | } |
| 1141 | else |
| 1142 | { |
| 1143 | if (irqline == 1) |
| 1144 | { |
| 1145 | m_int1_active = m_flag[2] = (state==ASSERT_LINE); |
| 1146 | if (VERBOSE>3) LOG("tms9995: Line INT1 state=%d\n", state); |
| 1147 | } |
| 1148 | else |
| 1149 | { |
| 1150 | if (irqline == 4) |
| 1151 | { |
| 1152 | if (VERBOSE>3) LOG("tms9995: Line INT4/EC state=%d\n", state); |
| 1153 | if (m_flag[0]==false) |
| 1154 | { |
| 1155 | if (VERBOSE>7) LOG("tms9995: set as interrupt\n"); |
| 1156 | m_int4_active = m_flag[4] = (state==ASSERT_LINE); |
| 1157 | } |
| 1158 | else |
| 1159 | { |
| 1160 | if (VERBOSE>7) LOG("tms9995: set as event count\n"); |
| 1161 | trigger_decrementer(); |
| 1162 | } |
| 1163 | } |
| 1164 | else |
| 1165 | { |
| 1166 | if (VERBOSE>0) LOG("tms9995: Accessed invalid interrupt line %d\n", irqline); |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | /* |
| 1173 | Issue a pulse on the clock line. |
| 1174 | */ |
| 1175 | inline void tms9995_device::pulse_clock(int count) |
| 1176 | { |
| 1177 | for (int i=0; i < count; i++) |
| 1178 | { |
| 1179 | m_clock_out_line(ASSERT_LINE); |
| 1180 | m_clock_out_line(CLEAR_LINE); |
| 1181 | m_icount--; // This is the only location where we count down the cycles. |
| 1182 | if (VERBOSE>7) LOG("tms9995: pulse_clock\n"); |
| 1183 | if (m_flag[0] == false && m_flag[1] == true) trigger_decrementer(); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | Enter the hold state. |
| 1189 | */ |
| 1190 | void tms9995_device::set_hold(int state) |
| 1191 | { |
| 1192 | m_hold_state = (state==ASSERT_LINE); |
| 1193 | if (VERBOSE>7) LOG("tms9995: set HOLD = %d\n", state); |
| 1194 | if (!m_hold_state) |
| 1195 | { |
| 1196 | m_holda_line(CLEAR_LINE); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | /* |
| 1201 | Signal READY to the CPU. When cleared, the CPU enters wait states. |
| 1202 | */ |
| 1203 | void tms9995_device::set_ready(int state) |
| 1204 | { |
| 1205 | if (VERBOSE>5) LOG("tms9995: set READY = %d\n", state); |
| 1206 | m_ready_state = (state==ASSERT_LINE); |
| 1207 | } |
| 1208 | |
| 1209 | void tms9995_device::abort_operation() |
| 1210 | { |
| 1211 | command_completed(); |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | Enter or leave the wait state. We only operate the WAIT line when there is a change. |
| 1216 | */ |
| 1217 | inline void tms9995_device::set_wait_state(bool state) |
| 1218 | { |
| 1219 | if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE); |
| 1220 | m_wait_state = state; |
| 1221 | } |
| 1222 | |
| 1223 | /* |
| 1224 | Enter or leave the hold state. We only operate the HOLDA line when there is a change. |
| 1225 | */ |
| 1226 | inline void tms9995_device::set_hold_state(bool state) |
| 1227 | { |
| 1228 | if (m_hold_state != state) m_holda_line(state? ASSERT_LINE : CLEAR_LINE); |
| 1229 | m_hold_state = state; |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | Decode the instruction. This is done in parallel to other operations |
| 1234 | so we just do it together with the prefetch. |
| 1235 | */ |
| 1236 | void tms9995_device::decode(UINT16 inst) |
| 1237 | { |
| 1238 | int index = 0; |
| 1239 | lookup_entry* table = m_command_lookup_table; |
| 1240 | UINT16 opcode = inst; |
| 1241 | bool complete = false; |
| 1242 | const tms_instruction *decoded; |
| 1243 | |
| 1244 | int dindex = (m_instindex==0)? 1:0; |
| 1245 | |
| 1246 | m_mid_flag = false; |
| 1247 | |
| 1248 | while (!complete) |
| 1249 | { |
| 1250 | index = (opcode >> 12) & 0x000f; |
| 1251 | if (VERBOSE>8) LOG("tms9995: Check next hex digit of instruction %x\n", index); |
| 1252 | if (table[index].next_digit != NULL) |
| 1253 | { |
| 1254 | table = table[index].next_digit; |
| 1255 | opcode = opcode << 4; |
| 1256 | } |
| 1257 | else complete = true; |
| 1258 | } |
| 1259 | decoded = table[index].entry; |
| 1260 | if (decoded == NULL) |
| 1261 | { |
| 1262 | // not found |
| 1263 | if (VERBOSE>0) LOG("tms9995: Unknown opcode %04x, will trigger MID\n", inst); |
| 1264 | m_decoded[dindex].IR = 0; |
| 1265 | m_decoded[dindex].command = MID; |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | m_decoded[dindex].IR = inst; |
| 1270 | m_decoded[dindex].command = decoded->id; |
| 1271 | m_decoded[dindex].program = decoded->prog; |
| 1272 | m_decoded[dindex].byteop = ((decoded->format == 1) && ((inst & 0x1000)!=0)); |
| 1273 | m_decoded[dindex].state = 0; |
| 1274 | if (VERBOSE>7) LOG("tms9995: Command decoded as id %d, %s, base opcode %04x\n", decoded->id, opname[decoded->id], decoded->opcode); |
| 1275 | m_pass = 1; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | Fetch the next instruction and check pending interrupts before. |
| 1281 | Getting an instruction is a normal memory access (plus an asserted IAQ line), |
| 1282 | so this is subject to wait state handling. We have to allow for a two-pass |
| 1283 | handling. |
| 1284 | */ |
| 1285 | void tms9995_device::int_prefetch_and_decode() |
| 1286 | { |
| 1287 | bool check_idle = false; |
| 1288 | bool check_int = (m_instruction->command != XOP && m_instruction->command != BLWP); |
| 1289 | int intmask = ST & 0x000f; |
| 1290 | |
| 1291 | if (m_lowbyte) |
| 1292 | { |
| 1293 | prefetch_and_decode(); |
| 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | // Check interrupt lines |
| 1298 | if (m_nmi_active) |
| 1299 | { |
| 1300 | if (VERBOSE>7) LOG("tms9995: Checking interrupts ... NMI active\n"); |
| 1301 | m_int_pending |= PENDING_NMI; |
| 1302 | m_idle_state = false; |
| 1303 | PC = (PC + 2) & 0xfffe; // we have not prefetched the next instruction |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | m_int_pending = 0; |
| 1308 | |
| 1309 | if (m_int1_active && intmask >= 1 && check_int) m_int_pending |= PENDING_LEVEL1; |
| 1310 | if (m_int_overflow && intmask >= 2 && check_int) m_int_pending |= PENDING_OVERFLOW; |
| 1311 | if (m_int_decrementer && intmask >= 3 && check_int) m_int_pending |= PENDING_DECR; |
| 1312 | if (m_int4_active && intmask >= 4 && check_int) m_int_pending |= PENDING_LEVEL4; |
| 1313 | |
| 1314 | if (m_int_pending!=0) |
| 1315 | { |
| 1316 | if (m_idle_state) |
| 1317 | { |
| 1318 | m_idle_state = false; |
| 1319 | if (VERBOSE>7) LOG("tms9995: Interrupt occured, terminate IDLE state\n"); |
| 1320 | } |
| 1321 | PC = PC + 2; // PC must be advanced (see flow chart), but no prefetch |
| 1322 | if (VERBOSE>7) LOG("tms9995: Interrupts pending; no prefetch; advance PC to %04x\n", PC); |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | if (VERBOSE>7) LOG("tms9995: Checking interrupts ... none pending\n"); |
| 1327 | // No pending interrupts |
| 1328 | if (check_idle && m_idle_state) |
| 1329 | { |
| 1330 | if (VERBOSE>7) LOG("tms9995: IDLE state\n"); |
| 1331 | // We are IDLE, stay in the loop and do not advance the PC |
| 1332 | m_pass = 2; |
| 1333 | pulse_clock(1); |
| 1334 | } |
| 1335 | else |
| 1336 | { |
| 1337 | prefetch_and_decode(); |
| 1338 | } |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | /* |
| 1344 | The actual prefetch operation, but without the interrupt check. This one is |
| 1345 | needed when we complete the interrupt handling and need to get the next |
| 1346 | instruction. According to the flow chart in [1], the prefetch after the |
| 1347 | interrupt handling ignores other pending interrupts. |
| 1348 | */ |
| 1349 | void tms9995_device::prefetch_and_decode() |
| 1350 | { |
| 1351 | if (m_lowbyte) |
| 1352 | { |
| 1353 | // Second pass for getting the instruction |
| 1354 | if (VERBOSE>6) LOG("tms9995: Prefetch memory access (second pass)\n"); |
| 1355 | word_read(); |
| 1356 | decode(m_current_value); // This is for free; in reality it is in parallel with the next memory operation |
| 1357 | m_address = m_address_copy; // restore m_address |
| 1358 | m_current_value = m_value_copy; // restore m_current_value |
| 1359 | PC = (PC + 2) & 0xfffe; // advance PC |
| 1360 | m_iaq_line(CLEAR_LINE); |
| 1361 | if (VERBOSE>5) LOG("tms9995: ++++ Prefetch done ++++\n"); |
| 1362 | m_lowbyte = false; |
| 1363 | } |
| 1364 | else |
| 1365 | { |
| 1366 | // Fetch next instruction |
| 1367 | // Save these values; they have been computed during the current instruction execution |
| 1368 | m_address_copy = m_address; |
| 1369 | m_value_copy = m_current_value; |
| 1370 | |
| 1371 | m_iaq_line(ASSERT_LINE); |
| 1372 | |
| 1373 | m_address = PC; |
| 1374 | |
| 1375 | if (VERBOSE>5) LOG("tms9995: **** Prefetching new instruction at %04x ****\n", PC); |
| 1376 | |
| 1377 | m_lowbyte = false; // for mem_read |
| 1378 | word_read(); // this is where the clock pulses occur |
| 1379 | |
| 1380 | if (!m_lowbyte) |
| 1381 | { |
| 1382 | // Only if we got the word in one pass |
| 1383 | decode(m_current_value); // This is for free; in reality it is in parallel with the next memory operation |
| 1384 | |
| 1385 | m_address = m_address_copy; // restore m_address |
| 1386 | m_current_value = m_value_copy; // restore m_current_value |
| 1387 | PC = (PC + 2) & 0xfffe; // advance PC |
| 1388 | |
| 1389 | m_iaq_line(CLEAR_LINE); |
| 1390 | } |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | /* |
| 1395 | Used by the normal command completion as well as by the X operation. We |
| 1396 | assume that we have a fully decoded operation which was previously |
| 1397 | prefetched. |
| 1398 | */ |
| 1399 | void tms9995_device::next_command() |
| 1400 | { |
| 1401 | int next = (m_instindex==0)? 1:0; |
| 1402 | |
| 1403 | if (m_decoded[next].command == MID) |
| 1404 | { |
| 1405 | m_mid_flag = true; |
| 1406 | service_interrupt(); |
| 1407 | } |
| 1408 | else |
| 1409 | { |
| 1410 | m_instindex = next; |
| 1411 | m_instruction = &m_decoded[m_instindex]; |
| 1412 | m_get_destination = false; |
| 1413 | // This is a preset for opcodes which do not need an opcode address derivation |
| 1414 | m_address = WP + ((m_instruction->IR & 0x000f)<<1); |
| 1415 | MPC = -1; |
| 1416 | if (VERBOSE>3) LOG("tms9995: ===== Next operation %04x (%s) at %04x =====\n", m_instruction->IR, opname[m_instruction->command], PC-2); |
| 1417 | PC_debug = PC - 2; |
| 1418 | debugger_instruction_hook(*this, PC_debug); |
| 1419 | m_first_cycle = m_icount; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | /* |
| 1424 | End of command execution |
| 1425 | */ |
| 1426 | void tms9995_device::command_completed() |
| 1427 | { |
| 1428 | // Pseudo state at the end of the current instruction cycle sequence |
| 1429 | if (VERBOSE>4) |
| 1430 | { |
| 1431 | LOG("tms9995: +++++ Instruction %04x (%s) completed +++++\n", m_instruction->IR, opname[m_instruction->command]); |
| 1432 | int cycles = m_first_cycle - m_icount; |
| 1433 | // Avoid nonsense values due to expired and resumed main loop |
| 1434 | if (cycles > 0 && cycles < 10000) LOG("tms9995: Consumed %d cycles\n", cycles); |
| 1435 | } |
| 1436 | |
| 1437 | if (m_int_pending != 0) |
| 1438 | { |
| 1439 | service_interrupt(); |
| 1440 | } |
| 1441 | else |
| 1442 | { |
| 1443 | if ((ST & ST_OE)!=0 && (ST & ST_OV)!=0 && (ST & 0x000f)>2) |
| 1444 | { |
| 1445 | service_interrupt(); |
| 1446 | } |
| 1447 | else |
| 1448 | { |
| 1449 | next_command(); |
| 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | /* |
| 1455 | Handle pending interrupts. |
| 1456 | */ |
| 1457 | void tms9995_device::service_interrupt() |
| 1458 | { |
| 1459 | int vectorpos = 0; |
| 1460 | |
| 1461 | if (m_reset) |
| 1462 | { |
| 1463 | vectorpos = 0; |
| 1464 | m_intmask = 0; // clear interrupt mask |
| 1465 | |
| 1466 | m_nmi_state = false; |
| 1467 | m_hold_state = false; |
| 1468 | m_wait_state = false; |
| 1469 | m_lowbyte = false; |
| 1470 | |
| 1471 | m_pass = 0; |
| 1472 | m_instindex = 0; |
| 1473 | m_instruction = &m_decoded[m_instindex]; |
| 1474 | |
| 1475 | // The auto-wait state generation is turned on when the READY line is cleared |
| 1476 | // on RESET. |
| 1477 | m_auto_wait_state = !m_ready_state; |
| 1478 | if (VERBOSE>0) LOG("tms9995: RESET; automatic wait state creation is %s\n", m_auto_wait_state? "enabled":"disabled"); |
| 1479 | m_ready_state = true; |
| 1480 | } |
| 1481 | else |
| 1482 | { |
| 1483 | if (m_mid_flag) |
| 1484 | { |
| 1485 | vectorpos = 0x0008; |
| 1486 | m_intmask = 0x0001; |
| 1487 | PC = (PC + 2) & 0xfffe; |
| 1488 | if (VERBOSE>7) LOG("tms9995: ***** MID pending\n"); |
| 1489 | } |
| 1490 | else |
| 1491 | { |
| 1492 | if ((m_int_pending & PENDING_NMI)!=0) |
| 1493 | { |
| 1494 | vectorpos = 0xfffc; |
| 1495 | m_int_pending &= ~PENDING_NMI; |
| 1496 | m_intmask = 0; |
| 1497 | if (VERBOSE>7) LOG("tms9995: ***** NMI pending\n"); |
| 1498 | } |
| 1499 | else |
| 1500 | { |
| 1501 | if ((m_int_pending & PENDING_LEVEL1)!=0) |
| 1502 | { |
| 1503 | vectorpos = 0x0004; |
| 1504 | m_int_pending &= ~PENDING_LEVEL1; |
| 1505 | m_flag[2] = false; |
| 1506 | m_intmask = 0; |
| 1507 | if (VERBOSE>7) LOG("tms9995: ***** INT1 pending\n"); |
| 1508 | } |
| 1509 | else |
| 1510 | { |
| 1511 | if ((m_int_pending & PENDING_OVERFLOW)!=0) |
| 1512 | { |
| 1513 | vectorpos = 0x0008; |
| 1514 | m_int_pending &= ~PENDING_OVERFLOW; |
| 1515 | m_intmask = 0x0001; |
| 1516 | if (VERBOSE>7) LOG("tms9995: ***** OVERFL pending\n"); |
| 1517 | } |
| 1518 | else |
| 1519 | { |
| 1520 | if ((m_int_pending & PENDING_DECR)!=0) |
| 1521 | { |
| 1522 | vectorpos = 0x000c; |
| 1523 | m_intmask = 0x0002; |
| 1524 | m_int_pending &= ~PENDING_DECR; |
| 1525 | m_flag[3] = false; |
| 1526 | if (VERBOSE>7) LOG("tms9995: ***** DECR pending\n"); |
| 1527 | } |
| 1528 | else |
| 1529 | { |
| 1530 | vectorpos = 0x0010; |
| 1531 | m_intmask = 0x0003; |
| 1532 | m_int_pending &= ~PENDING_LEVEL4; |
| 1533 | m_flag[4] = false; |
| 1534 | if (VERBOSE>7) LOG("tms9995: ***** INT4 pending\n"); |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | if (VERBOSE>6) LOG("tms9995: ********* triggered an interrupt with vector %04x/%04x\n", vectorpos, vectorpos+2); |
| 1543 | |
| 1544 | // The microinstructions will do the context switch |
| 1545 | m_address = vectorpos; |
| 1546 | m_instruction->program = int_mp; |
| 1547 | m_instruction->state = 0; |
| 1548 | m_instruction->byteop = false; |
| 1549 | m_instruction->command = INTR; |
| 1550 | m_pass = m_reset? 1 : 2; |
| 1551 | |
| 1552 | if (m_reset) |
| 1553 | { |
| 1554 | m_instruction->IR = 0x0000; |
| 1555 | m_reset = false; |
| 1556 | } |
| 1557 | MPC = 0; |
| 1558 | m_first_cycle = m_icount; |
| 1559 | m_check_ready = false; // set to default |
| 1560 | } |
| 1561 | |
| 1562 | /* |
| 1563 | Read memory. This method expects as input m_address, and delivers the value |
| 1564 | in m_current_value. For a single byte read, the byte is put into the high byte. |
| 1565 | This method uses the m_pass variable to achieve a two-pass handling for |
| 1566 | getting the complete word (high byte, low byte). |
| 1567 | |
| 1568 | input: |
| 1569 | m_address |
| 1570 | m_lowbyte |
| 1571 | output: |
| 1572 | m_current_value |
| 1573 | |
| 1574 | m_address is unchanged |
| 1575 | |
| 1576 | Make sure that m_lowbyte is false on the first call. |
| 1577 | */ |
| 1578 | void tms9995_device::mem_read() |
| 1579 | { |
| 1580 | // First determine whether the memory is inside the CPU |
| 1581 | // On-chip memory is F000 ... F0F9, F0FC-FFF9 = off-chip, FFFA/B = Decrementer |
| 1582 | // FFFC-FFFF = NMI vector (on-chip) |
| 1583 | // There is a variant of the TMS9995 with no on-chip RAM which was used |
| 1584 | // for the TI-99/8 (9537). |
| 1585 | |
| 1586 | if ((m_address & 0xfffe)==0xfffa && !m_mp9537) |
| 1587 | { |
| 1588 | if (VERBOSE>5) LOG("tms9995: read decrementer\n"); |
| 1589 | // Decrementer mapped into the address space |
| 1590 | m_current_value = m_decrementer_value; |
| 1591 | if (m_instruction->byteop) |
| 1592 | { |
| 1593 | if ((m_address & 1)!=1) m_current_value <<= 8; |
| 1594 | m_current_value &= 0xff00; |
| 1595 | } |
| 1596 | pulse_clock(1); |
| 1597 | return; |
| 1598 | } |
| 1599 | |
| 1600 | bool onchip = (((m_address & 0xff00)==0xf000 && (m_address < 0xf0fc)) || ((m_address & 0xfffc)==0xfffc)) && !m_mp9537; |
| 1601 | |
| 1602 | if (onchip) |
| 1603 | { |
| 1604 | if (VERBOSE>5) LOG("tms9995: read onchip memory (single pass, address %04x)\n", m_address); |
| 1605 | |
| 1606 | // Ignore the READY state |
| 1607 | m_check_ready = false; |
| 1608 | // We put fffc-ffff back into the f000-f0ff area |
| 1609 | m_current_value = m_onchip_memory[m_address & 0x00ff]<<8; |
| 1610 | if (m_word_access || !m_instruction->byteop) |
| 1611 | { |
| 1612 | // We have a word operation; add the low byte right here (just 1 cycle) |
| 1613 | m_current_value |= (m_onchip_memory[(m_address & 0x00ff)+1] & 0xff); |
| 1614 | } |
| 1615 | } |
| 1616 | else |
| 1617 | { |
| 1618 | // This is a off-chip access |
| 1619 | m_check_ready = true; |
| 1620 | if (m_lowbyte) |
| 1621 | { |
| 1622 | // This is always the odd address |
| 1623 | // With the OR we can ensure that we do not skip to an even address |
| 1624 | // when we try to read a word from an odd address |
| 1625 | m_current_value |= m_prgspace->read_byte(m_address | 0x0001); |
| 1626 | m_lowbyte = false; |
| 1627 | if (VERBOSE>3) LOG("tms9995: read external memory, second pass (address %04x, complete word = %04x)\n", m_address | 1, m_current_value); |
| 1628 | m_check_hold = true; |
| 1629 | } |
| 1630 | else |
| 1631 | { |
| 1632 | UINT16 address = m_address; |
| 1633 | if (m_word_access || !m_instruction->byteop) |
| 1634 | { |
| 1635 | // We have to come here a second time; do not advance the MPC |
| 1636 | // if the address value is even |
| 1637 | m_lowbyte = true; |
| 1638 | m_pass = 2; |
| 1639 | address &= 0xfffe; |
| 1640 | m_check_hold = false; |
| 1641 | } |
| 1642 | m_current_value = m_prgspace->read_byte(address) << 8; |
| 1643 | if (VERBOSE>3) |
| 1644 | { |
| 1645 | if (m_pass==2) LOG("tms9995: read external memory, first pass (address %04x, value %02x)\n", address, (m_current_value>>8)&0xff); |
| 1646 | else LOG("tms9995: read external memory (single pass), address %04x, value=%04x)\n", address, m_current_value); |
| 1647 | } |
| 1648 | } |
| 1649 | if (m_auto_wait_state) |
| 1650 | { |
| 1651 | if (VERBOSE>7) LOG("tms9995: Next pulse is auto wait\n"); |
| 1652 | pulse_clock(1); |
| 1653 | } |
| 1654 | } |
| 1655 | pulse_clock(1); |
| 1656 | } |
| 1657 | |
| 1658 | /* |
| 1659 | Read a word. This is independent of the byte flag of the instruction. |
| 1660 | We need this variant especially when we have to retrieve a register value |
| 1661 | in indexed addressing within a byte-oriented operation. |
| 1662 | */ |
| 1663 | inline void tms9995_device::word_read() |
| 1664 | { |
| 1665 | m_word_access = true; |
| 1666 | mem_read(); |
| 1667 | m_word_access = false; |
| 1668 | } |
| 1669 | |
| 1670 | /* |
| 1671 | Write memory. This method expects as input m_address and m_current_value. |
| 1672 | For a single byte write, the byte to be written is expected to be in the |
| 1673 | high byte of m_current_value. |
| 1674 | This method uses the m_pass variable to achieve a two-pass handling for |
| 1675 | writing the complete word (high byte, low byte). |
| 1676 | |
| 1677 | input: |
| 1678 | m_address |
| 1679 | m_lowbyte |
| 1680 | m_current_value |
| 1681 | |
| 1682 | output: |
| 1683 | - |
| 1684 | m_address is unchanged |
| 1685 | |
| 1686 | Make sure that m_lowbyte is false on the first call. |
| 1687 | */ |
| 1688 | void tms9995_device::mem_write() |
| 1689 | { |
| 1690 | if ((m_address & 0xfffe)==0xfffa && !m_mp9537) |
| 1691 | { |
| 1692 | if (VERBOSE>5) LOG("tms9995: setting decrementer\n"); |
| 1693 | |
| 1694 | if (m_instruction->byteop) |
| 1695 | { |
| 1696 | // According to [1], section 2.3.1.2.2: |
| 1697 | // "The decrementer should always be accessed as a full word. [...] |
| 1698 | // Writing a single byte to either of the bytes of the decrementer |
| 1699 | // will result in the data byte being written into the byte specifically addressed |
| 1700 | // and random bits being written into the other byte of the decrementer." |
| 1701 | |
| 1702 | // So we just don't care about the low byte. |
| 1703 | if (m_address == 0xfffb) m_current_value >>= 8; |
| 1704 | |
| 1705 | // dito: "This also loads the Decrementing Register with the same count." |
| 1706 | m_starting_count_storage_register = m_decrementer_value = m_current_value; |
| 1707 | } |
| 1708 | else |
| 1709 | { |
| 1710 | m_starting_count_storage_register = m_decrementer_value = m_current_value; |
| 1711 | } |
| 1712 | pulse_clock(1); |
| 1713 | return; |
| 1714 | } |
| 1715 | |
| 1716 | bool onchip = (((m_address & 0xff00)==0xf000 && (m_address < 0xf0fc)) || ((m_address & 0xfffc)==0xfffc)) && !m_mp9537; |
| 1717 | |
| 1718 | if (onchip) |
| 1719 | { |
| 1720 | if (VERBOSE>3) LOG("tms9995: write to onchip memory (single pass, address %04x, value=%04x)\n", m_address, m_current_value); |
| 1721 | m_check_ready = false; |
| 1722 | m_onchip_memory[m_address & 0x00ff] = (m_current_value >> 8) & 0xff; |
| 1723 | if (m_word_access || !m_instruction->byteop) |
| 1724 | { |
| 1725 | m_onchip_memory[(m_address & 0x00ff)+1] = m_current_value & 0xff; |
| 1726 | } |
| 1727 | } |
| 1728 | else |
| 1729 | { |
| 1730 | m_check_ready = true; |
| 1731 | |
| 1732 | if (m_lowbyte) |
| 1733 | { |
| 1734 | // see above in mem_read |
| 1735 | m_prgspace->write_byte(m_address | 0x0001, m_current_value & 0xff); |
| 1736 | m_lowbyte = false; |
| 1737 | if (VERBOSE>3) LOG("tms9995: write second pass (address %04x, value %02x)\n", m_address | 0x0001, m_current_value & 0xff); |
| 1738 | m_check_hold = true; |
| 1739 | } |
| 1740 | else |
| 1741 | { |
| 1742 | UINT16 address = m_address; |
| 1743 | if (m_word_access || !m_instruction->byteop) |
| 1744 | { |
| 1745 | // We have to come here a second time; do not advance the MPC |
| 1746 | // if the address value is even |
| 1747 | m_lowbyte = true; |
| 1748 | m_pass = 2; |
| 1749 | address &= 0xfffe; |
| 1750 | m_check_hold = false; |
| 1751 | } |
| 1752 | if (VERBOSE>3) |
| 1753 | { |
| 1754 | if (m_pass==2) LOG("tms9995: write external memory, first pass (address %04x, value %02x)\n", address, (m_current_value>>8)&0xff); |
| 1755 | else LOG("tms9995: write external memory (single pass), address %04x, value=%02x\n", address, (m_current_value>>8)&0xff); |
| 1756 | } |
| 1757 | m_prgspace->write_byte(address, (m_current_value >> 8)& 0xff); |
| 1758 | } |
| 1759 | |
| 1760 | if (m_auto_wait_state) |
| 1761 | { |
| 1762 | if (VERBOSE>7) LOG("tms9995: Next pulse is auto wait\n"); |
| 1763 | pulse_clock(1); |
| 1764 | } |
| 1765 | } |
| 1766 | pulse_clock(1); |
| 1767 | } |
| 1768 | |
| 1769 | /* |
| 1770 | Write a word. This is independent of the byte flag of the instruction. |
| 1771 | */ |
| 1772 | inline void tms9995_device::word_write() |
| 1773 | { |
| 1774 | m_word_access = true; |
| 1775 | mem_write(); |
| 1776 | m_word_access = false; |
| 1777 | } |
| 1778 | |
| 1779 | /* |
| 1780 | Returns from the operand address derivation. |
| 1781 | */ |
| 1782 | void tms9995_device::return_with_address() |
| 1783 | { |
| 1784 | // Return from operand address derivation |
| 1785 | // The result should be in m_address |
| 1786 | m_instruction->program = m_caller; |
| 1787 | MPC = m_caller_MPC; // will be increased on return |
| 1788 | m_address = m_current_value + m_address_add; |
| 1789 | if (VERBOSE>7) LOG("tms9995: +++ return from operand address derivation +++\n"); |
| 1790 | // no clock pulse |
| 1791 | } |
| 1792 | |
| 1793 | /* |
| 1794 | Returns from the operand address derivation, but using the saved address. |
| 1795 | This is required when we use the auto-increment feature. |
| 1796 | */ |
| 1797 | void tms9995_device::return_with_address_copy() |
| 1798 | { |
| 1799 | // Return from operand address derivation |
| 1800 | m_instruction->program = m_caller; |
| 1801 | MPC = m_caller_MPC; // will be increased on return |
| 1802 | m_address = m_address_saved; |
| 1803 | if (VERBOSE>7) LOG("tms9995: +++ return from operand address derivation (auto inc) +++\n"); |
| 1804 | // no clock pulse |
| 1805 | } |
| 1806 | |
| 1807 | /* |
| 1808 | CRU support code |
| 1809 | See common explanations in tms9900.c |
| 1810 | |
| 1811 | The TMS9995 CRU address space is larger than the CRU space of the TMS9900: |
| 1812 | 0000-fffe (even addresses) instead of 0000-1ffe. Unlike the TMS9900, the |
| 1813 | 9995 uses the data bus lines D0-D2 to indicate external operations. |
| 1814 | |
| 1815 | Internal CRU locations (read/write) |
| 1816 | ----------------------------------- |
| 1817 | 1EE0 Flag 0 Decrementer as event counter |
| 1818 | 1EE2 Flag 1 Decrementer enable |
| 1819 | 1EE4 Flag 2 Level 1 interrupt present (read only, also set when interrupt mask disallows interrupts) |
| 1820 | 1EE6 Flag 3 Level 3 interrupt present (see above) |
| 1821 | 1EE8 Flag 4 Level 4 interrupt present (see above) |
| 1822 | ... |
| 1823 | 1EFE Flag 15 |
| 1824 | 1FDA MID flag (only indication, does not trigger when set) |
| 1825 | |
| 1826 | The TMS9995 allows for wait states during external CRU access. Therefore |
| 1827 | we read one block of 8 bits in one go (as given by the MESS architecture) |
| 1828 | but we do iterations for each bit, checking every time for the READY line |
| 1829 | in the main loop. |
| 1830 | |
| 1831 | (write) |
| 1832 | m_cru_output |
| 1833 | m_cru_address |
| 1834 | m_cru_value |
| 1835 | m_count |
| 1836 | |
| 1837 | */ |
| 1838 | |
| 1839 | #define CRUREADMASK 0x0fff |
| 1840 | #define CRUWRITEMASK 0x7fff |
| 1841 | |
| 1842 | void tms9995_device::cru_output_operation() |
| 1843 | { |
| 1844 | if (VERBOSE>5) LOG("tms9995: CRU output operation, address %04x, value %d\n", m_cru_address, m_cru_value & 0x01); |
| 1845 | |
| 1846 | if (m_cru_address == 0x1fda) |
| 1847 | { |
| 1848 | // [1], section 2.3.3.2.2: "setting the MID to one with a CRU instruction |
| 1849 | // will not cause the MID interrupt to be requested." |
| 1850 | m_check_ready = false; |
| 1851 | m_mid_flag = (m_cru_value & 0x01); |
| 1852 | } |
| 1853 | else |
| 1854 | { |
| 1855 | if ((m_cru_address & 0xffe0) == 0x1ee0) |
| 1856 | { |
| 1857 | m_check_ready = false; |
| 1858 | // FLAG2, FLAG3, and FLAG4 are read-only |
| 1859 | if ((m_cru_address != 0x1ee4) && (m_cru_address != 0x1ee6) && (m_cru_address != 0x1ee8)) |
| 1860 | m_flag[(m_cru_address>>1)&0x000f] = (m_cru_value & 0x01); |
| 1861 | } |
| 1862 | else |
| 1863 | { |
| 1864 | // External access |
| 1865 | m_check_ready = true; |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | // All CRU write operations are visible to the outside world, even when we |
| 1870 | // have internal access. This makes it possible to assign special |
| 1871 | // functions to the internal flag bits which are realized outside |
| 1872 | // of the CPU. However, no wait states are generated for internal |
| 1873 | // accesses. ([1], section 2.3.3.2) |
| 1874 | |
| 1875 | m_cru->write_byte((m_cru_address >> 1)& CRUWRITEMASK, (m_cru_value & 0x01)); |
| 1876 | m_cru_value >>= 1; |
| 1877 | m_cru_address = (m_cru_address + 2) & 0xfffe; |
| 1878 | m_count--; |
| 1879 | |
| 1880 | // Repeat this operation |
| 1881 | m_pass = (m_count > 0)? 2 : 1; |
| 1882 | pulse_clock(2); |
| 1883 | } |
| 1884 | |
| 1885 | /* |
| 1886 | Input: (read) |
| 1887 | m_cru_multi_first |
| 1888 | m_cru_address |
| 1889 | Output: |
| 1890 | m_cru_value (right-shifted; i.e. first bit is LSB of the 16 bit word, |
| 1891 | also for byte operations) |
| 1892 | */ |
| 1893 | |
| 1894 | void tms9995_device::cru_input_operation() |
| 1895 | { |
| 1896 | UINT16 crubit; |
| 1897 | UINT8 crubyte; |
| 1898 | |
| 1899 | // Reading is different, since MESS uses 8 bit transfers |
| 1900 | // We read 8 bits in one go, then iterate another min(n-1,7) times to allow |
| 1901 | // for wait states. |
| 1902 | |
| 1903 | // read_byte for CRU delivers the first bit on the rightmost position |
| 1904 | |
| 1905 | int offset = (m_cru_address>>1) & 0x07; |
| 1906 | |
| 1907 | if (m_cru_first_read || m_cru_bits_left == 0) |
| 1908 | { |
| 1909 | // Read next 8 bits |
| 1910 | // 00000000 0rrrrrrr r |
| 1911 | // v |
| 1912 | // ........ ........ X....... ........ |
| 1913 | // |
| 1914 | crubyte = m_cru->read_byte((m_cru_address >> 4)& CRUREADMASK); |
| 1915 | if (VERBOSE>8) LOG("tms9995: Need to get next 8 bits (addresses %04x-%04x): %02x\n", (m_cru_address&0xfff0)+14, m_cru_address&0xfff0, crubyte); |
| 1916 | m_cru_read = crubyte << 15; |
| 1917 | m_cru_bits_left = 8; |
| 1918 | |
| 1919 | if (m_cru_first_read) |
| 1920 | { |
| 1921 | m_cru_read >>= offset; |
| 1922 | m_cru_bits_left -= offset; |
| 1923 | m_parity = 0; |
| 1924 | m_cru_value = 0; |
| 1925 | m_cru_first_read = false; |
| 1926 | m_pass = m_count; |
| 1927 | } |
| 1928 | if (VERBOSE>8) LOG("tms9995: adjusted value for shift: %06x\n", m_cru_read); |
| 1929 | } |
| 1930 | |
| 1931 | crubit = (m_cru_read & 0x8000); |
| 1932 | m_cru_value = (m_cru_value >> 1) & 0x7fff; |
| 1933 | |
| 1934 | // During internal reading, the CRUIN line will be ignored. We emulate this |
| 1935 | // by overwriting the bit which we got from outside. Also, READY is ignored. |
| 1936 | if (m_cru_address == 0x1fda) |
| 1937 | { |
| 1938 | crubit = m_mid_flag? 0x8000 : 0x0000; |
| 1939 | m_check_ready = false; |
| 1940 | } |
| 1941 | else |
| 1942 | { |
| 1943 | if ((m_cru_address & 0xffe0)==0x1ee0) |
| 1944 | { |
| 1945 | crubit = (m_flag[(m_cru_address>>1)&0x000f]==true)? 0x8000 : 0x0000; |
| 1946 | m_check_ready = false; |
| 1947 | } |
| 1948 | else |
| 1949 | { |
| 1950 | m_check_ready = true; |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | if (VERBOSE>5) LOG("tms9995: CRU input operation, address %04x, value %d\n", m_cru_address, (crubit & 0x8000)>>15); |
| 1955 | |
| 1956 | m_cru_value |= crubit; |
| 1957 | if (crubit!=0) m_parity++; |
| 1958 | |
| 1959 | m_cru_address = (m_cru_address + 2) & 0xfffe; |
| 1960 | m_cru_bits_left--; |
| 1961 | |
| 1962 | if (m_pass > 1) |
| 1963 | { |
| 1964 | m_cru_read >>= 1; |
| 1965 | } |
| 1966 | else |
| 1967 | { |
| 1968 | // This is the final shift. For both byte and word length transfers, |
| 1969 | // the first bit is always m_cru_value & 0x0001. |
| 1970 | m_cru_value >>= (16 - m_count); |
| 1971 | } |
| 1972 | pulse_clock(2); |
| 1973 | } |
| 1974 | |
| 1975 | /* |
| 1976 | Decrementer. |
| 1977 | */ |
| 1978 | void tms9995_device::trigger_decrementer() |
| 1979 | { |
| 1980 | if (m_starting_count_storage_register>0) // null will turn off the decrementer |
| 1981 | { |
| 1982 | m_decrementer_value--; |
| 1983 | if (m_decrementer_value==0) |
| 1984 | { |
| 1985 | if (VERBOSE>5) LOG("tms9995: decrementer reached 0\n"); |
| 1986 | m_decrementer_value = m_starting_count_storage_register; |
| 1987 | if (m_flag[1]==true) |
| 1988 | { |
| 1989 | m_flag[3] = true; |
| 1990 | m_int_decrementer = true; |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | /* |
| 1997 | This is a switch to a subprogram. In terms of cycles |
| 1998 | it does not take any time; execution continues with the first instruction |
| 1999 | of the subprogram. |
| 2000 | |
| 2001 | input: |
| 2002 | m_get_destination |
| 2003 | m_instruction |
| 2004 | WP |
| 2005 | m_current_value |
| 2006 | m_address |
| 2007 | output: |
| 2008 | m_source_value = m_current_value before invocation |
| 2009 | m_current_value = m_address |
| 2010 | m_address_add = 0 |
| 2011 | m_lowbyte = false |
| 2012 | m_get_destination = true |
| 2013 | m_regnumber = register number |
| 2014 | m_address = address of register |
| 2015 | */ |
| 2016 | void tms9995_device::operand_address_subprogram() |
| 2017 | { |
| 2018 | UINT16 ircopy = m_instruction->IR; |
| 2019 | if (m_get_destination) ircopy = ircopy >> 6; |
| 2020 | |
| 2021 | // Save the return program and position |
| 2022 | m_caller = m_instruction->program; |
| 2023 | m_caller_MPC = MPC; |
| 2024 | |
| 2025 | m_instruction->program = (UINT8*)operand_address_derivation; |
| 2026 | MPC = (ircopy & 0x0030) >> 2; |
| 2027 | m_regnumber = (ircopy & 0x000f); |
| 2028 | m_address = (WP + (m_regnumber<<1)) & 0xffff; |
| 2029 | |
| 2030 | m_source_value = m_current_value; // will be overwritten when reading the destination |
| 2031 | m_current_value = m_address; // needed for first case |
| 2032 | |
| 2033 | if (MPC==8) // Symbolic |
| 2034 | { |
| 2035 | if (m_regnumber != 0) |
| 2036 | { |
| 2037 | if (VERBOSE>8) LOG("tms9995: indexed addressing\n"); |
| 2038 | MPC = 16; // indexed |
| 2039 | } |
| 2040 | else |
| 2041 | { |
| 2042 | if (VERBOSE>8) LOG("tms9995: symbolic addressing\n"); |
| 2043 | m_address = PC; |
| 2044 | PC = (PC + 2) & 0xfffe; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | m_get_destination = true; |
| 2049 | m_lowbyte = false; |
| 2050 | m_address_add = 0; |
| 2051 | MPC--; // will be increased in the mail loop |
| 2052 | if (VERBOSE>8) LOG("tms9995: *** Operand address derivation; address=%04x; index=%d\n", m_address, MPC+1); |
| 2053 | } |
| 2054 | |
| 2055 | /* |
| 2056 | Used for register auto-increment. We have to save the address read from the |
| 2057 | register content so that we can return it at the end. |
| 2058 | */ |
| 2059 | void tms9995_device::increment_register() |
| 2060 | { |
| 2061 | m_address_saved = m_current_value; // need a special return so we do not lose the value |
| 2062 | m_current_value += m_instruction->byteop? 1 : 2; |
| 2063 | m_address = (WP + (m_regnumber<<1)) & 0xffff; |
| 2064 | m_lowbyte = false; |
| 2065 | pulse_clock(1); |
| 2066 | } |
| 2067 | |
| 2068 | /* |
| 2069 | Used for indexed addressing. We store the contents of the index register |
| 2070 | in m_address_add which is set to 0 by default. Then we set the address |
| 2071 | pointer to the PC location and advance it. |
| 2072 | */ |
| 2073 | void tms9995_device::indexed_addressing() |
| 2074 | { |
| 2075 | m_address_add = m_current_value; |
| 2076 | m_address = PC; |
| 2077 | PC = (PC + 2) & 0xfffe; |
| 2078 | m_lowbyte = false; |
| 2079 | pulse_clock(1); |
| 2080 | } |
| 2081 | |
| 2082 | void tms9995_device::set_immediate() |
| 2083 | { |
| 2084 | // Need to determine the register address |
| 2085 | m_address_saved = WP + ((m_instruction->IR & 0x000f)<<1); |
| 2086 | m_address = PC; |
| 2087 | m_source_value = m_current_value; // needed for AI, ANDI, ORI |
| 2088 | PC = (PC + 2) & 0xfffe; |
| 2089 | m_lowbyte = false; |
| 2090 | } |
| 2091 | |
| 2092 | /************************************************************************** |
| 2093 | Status bit operations |
| 2094 | **************************************************************************/ |
| 2095 | |
| 2096 | inline void tms9995_device::set_status_bit(int bit, bool state) |
| 2097 | { |
| 2098 | if (state) ST |= bit; |
| 2099 | else ST &= ~bit; |
| 2100 | m_int_overflow = (m_check_overflow && bit == ST_OV && ((ST & ST_OE)!=0) && state == true); |
| 2101 | } |
| 2102 | |
| 2103 | void tms9995_device::set_status_parity(UINT8 value) |
| 2104 | { |
| 2105 | int count = 0; |
| 2106 | for (int i=0; i < 8; i++) |
| 2107 | { |
| 2108 | if ((value & 0x80)!=0) count++; |
| 2109 | value <<= 1; |
| 2110 | } |
| 2111 | set_status_bit(ST_OP, (count & 1)!=0); |
| 2112 | } |
| 2113 | |
| 2114 | inline void tms9995_device::compare_and_set_lae(UINT16 value1, UINT16 value2) |
| 2115 | { |
| 2116 | set_status_bit(ST_EQ, value1 == value2); |
| 2117 | set_status_bit(ST_LH, value1 > value2); |
| 2118 | set_status_bit(ST_AGT, (INT16)value1 > (INT16)value2); |
| 2119 | } |
| 2120 | |
| 2121 | /************************************************************************** |
| 2122 | ALU operations. The activities as implemented here are performed |
| 2123 | during the internal operations of the CPU, according to the current |
| 2124 | instruction. |
| 2125 | |
| 2126 | Some ALU operations are followed by the prefetch operation. In fact, |
| 2127 | this prefetch happens in parallel to the ALU operation. In these |
| 2128 | situations we do not pulse the clock here but leave this to the prefetch |
| 2129 | operation. |
| 2130 | **************************************************************************/ |
| 2131 | |
| 2132 | void tms9995_device::alu_nop() |
| 2133 | { |
| 2134 | // Do nothing (or nothing that is externally visible) |
| 2135 | pulse_clock(1); |
| 2136 | return; |
| 2137 | } |
| 2138 | |
| 2139 | void tms9995_device::alu_add_s_sxc() |
| 2140 | { |
| 2141 | // We have the source operand value in m_source_value and the destination |
| 2142 | // value in m_current_value |
| 2143 | // The destination address is still in m_address |
| 2144 | // Prefetch will not change m_current_value and m_address |
| 2145 | |
| 2146 | UINT32 dest_new = 0; |
| 2147 | |
| 2148 | switch (m_instruction->command) |
| 2149 | { |
| 2150 | case A: |
| 2151 | case AB: |
| 2152 | // When adding, a carry occurs when we exceed the 0xffff value. |
| 2153 | dest_new = m_current_value + m_source_value; |
| 2154 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 2155 | |
| 2156 | // If the result has a sign bit that is different from both arguments, we have an overflow |
| 2157 | // (i.e. getting a negative value from two positive values and vice versa) |
| 2158 | set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_source_value) & 0x8000)!=0); |
| 2159 | break; |
| 2160 | case S: |
| 2161 | case SB: |
| 2162 | dest_new = m_current_value + ((~m_source_value) & 0xffff) + 1; |
| 2163 | // Subtraction means adding the 2s complement, so the carry bit |
| 2164 | // is set whenever adding the 2s complement exceeds ffff |
| 2165 | // In fact the CPU adds the one's complement, then adds a one. This |
| 2166 | // explains why subtracting 0 sets the carry bit. |
| 2167 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 2168 | |
| 2169 | // If the arguments have different sign bits and the result has a |
| 2170 | // sign bit different from the destination value, we have an overflow |
| 2171 | // e.g. value1 = 0x7fff, value2 = 0xffff; value1-value2 = 0x8000 |
| 2172 | // or value1 = 0x8000, value2 = 0x0001; value1-value2 = 0x7fff |
| 2173 | // value1 is the destination value |
| 2174 | set_status_bit(ST_OV, (m_current_value ^ m_source_value) & (m_current_value ^ dest_new) & 0x8000); |
| 2175 | break; |
| 2176 | case SOC: |
| 2177 | case SOCB: |
| 2178 | dest_new = m_current_value | m_source_value; |
| 2179 | break; |
| 2180 | |
| 2181 | case SZC: |
| 2182 | case SZCB: |
| 2183 | dest_new = m_current_value & ~m_source_value; |
| 2184 | break; |
| 2185 | } |
| 2186 | |
| 2187 | m_current_value = (UINT16)(dest_new & 0xffff); |
| 2188 | |
| 2189 | compare_and_set_lae((UINT16)(dest_new & 0xffff),0); |
| 2190 | if (m_instruction->byteop) |
| 2191 | { |
| 2192 | set_status_parity((UINT8)(dest_new>>8)); |
| 2193 | } |
| 2194 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2195 | // No clock pulse (will be done by prefetch) |
| 2196 | } |
| 2197 | |
| 2198 | /* |
| 2199 | Branch / Branch and link. We put the source address into the PC after |
| 2200 | copying the PC into m_current_value. The address is R11. The B instruction |
| 2201 | will just ignore these settings, but BL will use them. |
| 2202 | */ |
| 2203 | void tms9995_device::alu_b() |
| 2204 | { |
| 2205 | m_current_value = PC; |
| 2206 | PC = m_address; |
| 2207 | m_address = WP + 22; |
| 2208 | } |
| 2209 | |
| 2210 | /* |
| 2211 | Branch and load workspace pointer. This is a branch to a subprogram with |
| 2212 | context switch. |
| 2213 | */ |
| 2214 | void tms9995_device::alu_blwp() |
| 2215 | { |
| 2216 | int n = 1; |
| 2217 | switch (m_instruction->state) |
| 2218 | { |
| 2219 | case 0: |
| 2220 | // new WP in m_current_value |
| 2221 | m_value_copy = WP; |
| 2222 | WP = m_current_value; |
| 2223 | m_address_saved = m_address + 2; |
| 2224 | m_address = WP + 30; |
| 2225 | m_current_value = ST; |
| 2226 | break; |
| 2227 | case 1: |
| 2228 | m_current_value = PC; |
| 2229 | m_address = m_address - 2; |
| 2230 | break; |
| 2231 | case 2: |
| 2232 | m_current_value = m_value_copy; // old WP |
| 2233 | m_address = m_address - 2; |
| 2234 | break; |
| 2235 | case 3: |
| 2236 | m_address = m_address_saved; |
| 2237 | break; |
| 2238 | case 4: |
| 2239 | PC = m_current_value; |
| 2240 | n = 0; |
| 2241 | if (VERBOSE>5) LOG("tms9995: Context switch complete; WP=%04x, PC=%04x, ST=%04x\n", WP, PC, ST); |
| 2242 | break; |
| 2243 | } |
| 2244 | m_instruction->state++; |
| 2245 | pulse_clock(n); |
| 2246 | } |
| 2247 | |
| 2248 | /* |
| 2249 | Compare is similar to add, s, soc, szc, but we do not write a result. |
| 2250 | */ |
| 2251 | void tms9995_device::alu_c() |
| 2252 | { |
| 2253 | // We have the source operand value in m_source_value and the destination |
| 2254 | // value in m_current_value |
| 2255 | // The destination address is still in m_address |
| 2256 | // Prefetch will not change m_current_value and m_address |
| 2257 | compare_and_set_lae(m_source_value, m_current_value); |
| 2258 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val1=%04x, val2=%04x)\n", ST, m_source_value, m_current_value); |
| 2259 | } |
| 2260 | |
| 2261 | /* |
| 2262 | Compare with immediate value. |
| 2263 | */ |
| 2264 | void tms9995_device::alu_ci() |
| 2265 | { |
| 2266 | // We have the register value in m_source_value, the register address in m_address_saved |
| 2267 | // and the immediate value in m_current_value |
| 2268 | compare_and_set_lae(m_source_value, m_current_value); |
| 2269 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val1=%04x, val2=%04x)\n", ST, m_source_value, m_current_value); |
| 2270 | } |
| 2271 | |
| 2272 | void tms9995_device::alu_clr_seto() |
| 2273 | { |
| 2274 | if (VERBOSE>7) LOG("tms9995: clr/seto: Setting values for address %04x\n", m_address); |
| 2275 | switch (m_instruction->command) |
| 2276 | { |
| 2277 | case CLR: |
| 2278 | m_current_value = 0; |
| 2279 | break; |
| 2280 | case SETO: |
| 2281 | m_current_value = 0xffff; |
| 2282 | break; |
| 2283 | } |
| 2284 | // No clock pulse, as next instruction is prefetch |
| 2285 | } |
| 2286 | |
| 2287 | /* |
| 2288 | Unsigned division. |
| 2289 | */ |
| 2290 | void tms9995_device::alu_divide() |
| 2291 | { |
| 2292 | int n=1; |
| 2293 | UINT32 uval32; |
| 2294 | |
| 2295 | bool overflow = true; |
| 2296 | UINT16 value1; |
| 2297 | |
| 2298 | switch (m_instruction->state) |
| 2299 | { |
| 2300 | case 0: |
| 2301 | m_source_value = m_current_value; |
| 2302 | // Set address of register |
| 2303 | m_address = WP + ((m_instruction->IR >> 5) & 0x001e); |
| 2304 | m_address_copy = m_address; |
| 2305 | break; |
| 2306 | case 1: |
| 2307 | // Value of register is in m_current_value |
| 2308 | // We have an overflow when the quotient cannot be stored in 16 bits |
| 2309 | // This is the case when the dividend / divisor >= 0x10000, |
| 2310 | // or equivalently, dividend / 0x10000 >= divisor |
| 2311 | |
| 2312 | // Check overflow for unsigned DIV |
| 2313 | if (m_current_value < m_source_value) // also if source=0 |
| 2314 | { |
| 2315 | MPC++; // skip the abort |
| 2316 | overflow = false; |
| 2317 | } |
| 2318 | set_status_bit(ST_OV, overflow); |
| 2319 | m_value_copy = m_current_value; // Save the high word |
| 2320 | m_address = m_address + 2; |
| 2321 | break; |
| 2322 | case 2: |
| 2323 | // W2 is in m_current_value |
| 2324 | uval32 = (m_value_copy << 16) | m_current_value; |
| 2325 | // Calculate |
| 2326 | // The number of ALU cycles depends on the number of steps in |
| 2327 | // the division algorithm. The number of cycles is between 1 and 16 |
| 2328 | // As in TMS9900, this is a guess; it depends on the actual algorithm |
| 2329 | // used in the chip. |
| 2330 | |
| 2331 | m_current_value = uval32 / m_source_value; |
| 2332 | m_value_copy = uval32 % m_source_value; |
| 2333 | m_address = m_address_copy; |
| 2334 | |
| 2335 | value1 = m_value_copy & 0xffff; |
| 2336 | while (value1 != 0) |
| 2337 | { |
| 2338 | value1 = (value1 >> 1) & 0xffff; |
| 2339 | n++; |
| 2340 | } |
| 2341 | |
| 2342 | break; |
| 2343 | case 3: |
| 2344 | // now write the remainder |
| 2345 | m_current_value = m_value_copy; |
| 2346 | m_address = m_address + 2; |
| 2347 | break; |
| 2348 | } |
| 2349 | m_instruction->state++; |
| 2350 | pulse_clock(n); |
| 2351 | } |
| 2352 | |
| 2353 | /* |
| 2354 | Signed Division |
| 2355 | We cannot handle this by the same ALU operation because we can NOT decide |
| 2356 | whether there is an overflow before we have retrieved the whole 32 bit |
| 2357 | word. Also, the overflow detection is pretty complicated for signed |
| 2358 | division when done before the actual calculation. |
| 2359 | */ |
| 2360 | void tms9995_device::alu_divide_signed() |
| 2361 | { |
| 2362 | int n=1; |
| 2363 | bool overflow = true; |
| 2364 | UINT16 w1, w2, d; |
| 2365 | INT32 w; |
| 2366 | |
| 2367 | switch (m_instruction->state) |
| 2368 | { |
| 2369 | case 0: |
| 2370 | // Got the source value (divisor) |
| 2371 | m_source_value = m_current_value; |
| 2372 | m_address = WP; // DIVS always uses R0,R1 |
| 2373 | break; |
| 2374 | case 1: |
| 2375 | // Value of register is in m_current_value |
| 2376 | m_value_copy = m_current_value; |
| 2377 | m_address += 2; |
| 2378 | break; |
| 2379 | case 2: |
| 2380 | // Now we have the dividend low word in m_current_value, |
| 2381 | // the dividend high word in m_value_copy, and |
| 2382 | // the divisor in m_source_value. |
| 2383 | |
| 2384 | w1 = m_value_copy; |
| 2385 | w2 = m_current_value; |
| 2386 | d = m_source_value; |
| 2387 | |
| 2388 | // Now check for overflow |
| 2389 | // Seems a bit complex, and don't ask me how they did it in the chip. |
| 2390 | // The basic idea is that the division of a 32-bit number by a 16-bit |
| 2391 | // number must result in a 16-bit quotient and a remainder, AND the |
| 2392 | // quotient must have positive sign when the signs of the dividend and |
| 2393 | // the divisor are equal. When any of these conditions are not met, an |
| 2394 | // overflow is indicated. |
| 2395 | |
| 2396 | // Unlike with the unsigned division we cannot tell whether we will |
| 2397 | // run into an overflow before we have the complete dividend value. |
| 2398 | // It might be easier to just try and divide, but the real machine |
| 2399 | // requires much less cycles when there is an overflow, so it seems as |
| 2400 | // if this is tested before the algorithm starts. |
| 2401 | |
| 2402 | if ((w1 & 0x8000)==0) // positive dividend |
| 2403 | { |
| 2404 | if ((d & 0x8000)==0) // positive divisor |
| 2405 | { |
| 2406 | if ((d & 1)==0) // even divisor |
| 2407 | { |
| 2408 | if (w1 < d/2) overflow = false; |
| 2409 | } |
| 2410 | else // odd divisor |
| 2411 | { |
| 2412 | if ((w1 < (d-1)/2) || (w1 == (d-1)/2 && w2 < 0x8000)) overflow = false; |
| 2413 | } |
| 2414 | } |
| 2415 | else // negative divisor |
| 2416 | { |
| 2417 | d = -d; |
| 2418 | if ((d & 1)==0) // even divisor |
| 2419 | { |
| 2420 | if ((w1 < d/2) || (w1 == d/2 && w2 < d)) overflow = false; |
| 2421 | } |
| 2422 | else // odd divisor |
| 2423 | { |
| 2424 | if ((w1 < (d+1)/2) || (w1 == (d+1)/2 && w2 < 0x8000+d)) overflow = false; |
| 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | else // negative dividend |
| 2429 | { |
| 2430 | w1 = -w1; |
| 2431 | if ((d & 0x8000)==0) // positive divisor |
| 2432 | { |
| 2433 | if ((d & 1)==0) // even divisor |
| 2434 | { |
| 2435 | if ((w1 < d/2+1) || (w1 == d/2+1 && w2 > (-d))) overflow = false; |
| 2436 | } |
| 2437 | else // odd divisor |
| 2438 | { |
| 2439 | if ((w1 < (d+1)/2) || (w1 == (d+1)/2 && w2 > 0x8000-d)) overflow = false; |
| 2440 | } |
| 2441 | } |
| 2442 | else // negative divisor |
| 2443 | { |
| 2444 | d = -d; |
| 2445 | if ((d & 1)==0) // even divisor |
| 2446 | { |
| 2447 | if ((w1 < d/2) || (w1 == d/2 && w2 > 0)) overflow = false; |
| 2448 | } |
| 2449 | else // odd divisor |
| 2450 | { |
| 2451 | if ((w1 < (d+1)/2) || (w1 == (d+1)/2 && w2 > 0x8000)) overflow = false; |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | set_status_bit(ST_OV, overflow); |
| 2456 | if (!overflow) MPC++; // Skip the next microinstruction when there is no overflow |
| 2457 | break; |
| 2458 | case 3: |
| 2459 | // We are here because there was no overflow |
| 2460 | w = (m_value_copy << 16) | m_current_value; |
| 2461 | // Do the calculation |
| 2462 | m_current_value = (UINT16)(w / (INT16)m_source_value); |
| 2463 | m_value_copy = (UINT16)(w % (INT16)m_source_value); |
| 2464 | m_address = WP; |
| 2465 | |
| 2466 | // As we have not implemented the real division algorithm we must |
| 2467 | // simulate the number of steps required for calculating the result. |
| 2468 | // This is just a guess. |
| 2469 | d = m_value_copy; |
| 2470 | while (d != 0) |
| 2471 | { |
| 2472 | d = (d >> 1) & 0xffff; |
| 2473 | n++; |
| 2474 | } |
| 2475 | // go write the quotient into R0 |
| 2476 | break; |
| 2477 | case 4: |
| 2478 | // Now write the remainder |
| 2479 | m_current_value = m_value_copy; |
| 2480 | m_address += 2; |
| 2481 | n = 0; |
| 2482 | break; |
| 2483 | } |
| 2484 | m_instruction->state++; |
| 2485 | pulse_clock(n); |
| 2486 | } |
| 2487 | |
| 2488 | /* |
| 2489 | External operations. |
| 2490 | */ |
| 2491 | void tms9995_device::alu_external() |
| 2492 | { |
| 2493 | // Call some possibly attached external device |
| 2494 | // A specific bit pattern is put on the data bus, and the CRUOUT line is |
| 2495 | // pulsed. In our case we use a special callback function since we cannot |
| 2496 | // emulate this behavior in this implementation. |
| 2497 | |
| 2498 | // Opcodes D012 value |
| 2499 | // -----------------vvv------ |
| 2500 | // IDLE = 0000 0011 0100 0000 |
| 2501 | // RSET = 0000 0011 0110 0000 |
| 2502 | // CKON = 0000 0011 1010 0000 |
| 2503 | // CKOF = 0000 0011 1100 0000 |
| 2504 | // LREX = 0000 0011 1110 0000 |
| 2505 | |
| 2506 | // Only IDLE has a visible effect on the CPU without external support: the |
| 2507 | // CPU will stop execution until an interrupt occurs. CKON, CKOF, LREX have |
| 2508 | // no effect without external support. Neither has RSET, it does *not* |
| 2509 | // cause a reset of the CPU or of the remaining computer system. |
| 2510 | // It only clears the interrupt mask and outputs the |
| 2511 | // external code on the data bus. A special line decoder could then trigger |
| 2512 | // a reset from outside. |
| 2513 | |
| 2514 | if (m_instruction->command == IDLE) |
| 2515 | m_idle_state = true; |
| 2516 | |
| 2517 | if (m_instruction->command == RSET) |
| 2518 | { |
| 2519 | ST &= 0xfff0; |
| 2520 | if (VERBOSE>3) LOG("tms9995: New ST = %04x\n", ST); |
| 2521 | } |
| 2522 | |
| 2523 | m_external_operation((m_instruction->IR >> 5) & 0x07, 1); |
| 2524 | } |
| 2525 | |
| 2526 | /* |
| 2527 | Logical compare and XOR |
| 2528 | */ |
| 2529 | void tms9995_device::alu_f3() |
| 2530 | { |
| 2531 | switch (m_instruction->state) |
| 2532 | { |
| 2533 | case 0: |
| 2534 | // We have the contents of the source in m_current_value and its address |
| 2535 | // in m_address |
| 2536 | m_source_value = m_current_value; |
| 2537 | // Get register address |
| 2538 | m_address = WP + ((m_instruction->IR >> 5) & 0x001e); |
| 2539 | break; |
| 2540 | case 1: |
| 2541 | // Register contents -> m_current_value |
| 2542 | // Source contents -> m_source_value |
| 2543 | if (m_instruction->command == COC) |
| 2544 | { |
| 2545 | set_status_bit(ST_EQ, (m_current_value & m_source_value) == m_source_value); |
| 2546 | } |
| 2547 | else |
| 2548 | { |
| 2549 | if (m_instruction->command == CZC) |
| 2550 | { |
| 2551 | set_status_bit(ST_EQ, (~m_current_value & m_source_value) == m_source_value); |
| 2552 | } |
| 2553 | else |
| 2554 | { |
| 2555 | // XOR |
| 2556 | // The workspace register address is still in m_address |
| 2557 | m_current_value = (m_current_value ^ m_source_value); |
| 2558 | compare_and_set_lae(m_current_value, 0); |
| 2559 | } |
| 2560 | } |
| 2561 | if (VERBOSE>7) LOG("tms9995: ST = %04x\n", ST); |
| 2562 | break; |
| 2563 | } |
| 2564 | pulse_clock(1); |
| 2565 | m_instruction->state++; |
| 2566 | } |
| 2567 | |
| 2568 | /* |
| 2569 | Handles AI, ANDI, ORI. |
| 2570 | */ |
| 2571 | void tms9995_device::alu_imm_arithm() |
| 2572 | { |
| 2573 | UINT32 dest_new = 0; |
| 2574 | |
| 2575 | // We have the register value in m_source_value, the register address in m_address_saved |
| 2576 | // and the immediate value in m_current_value |
| 2577 | switch (m_instruction->command) |
| 2578 | { |
| 2579 | case AI: |
| 2580 | dest_new = m_current_value + m_source_value; |
| 2581 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 2582 | |
| 2583 | // If the result has a sign bit that is different from both arguments, we have an overflow |
| 2584 | // (i.e. getting a negative value from two positive values and vice versa) |
| 2585 | set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_source_value) & 0x8000)!=0); |
| 2586 | break; |
| 2587 | case ANDI: |
| 2588 | dest_new = m_current_value & m_source_value; |
| 2589 | break; |
| 2590 | case ORI: |
| 2591 | dest_new = m_current_value | m_source_value; |
| 2592 | break; |
| 2593 | } |
| 2594 | |
| 2595 | m_current_value = (UINT16)(dest_new & 0xffff); |
| 2596 | compare_and_set_lae(m_current_value, 0); |
| 2597 | m_address = m_address_saved; |
| 2598 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2599 | } |
| 2600 | |
| 2601 | /* |
| 2602 | Handles all jump instructions. |
| 2603 | */ |
| 2604 | void tms9995_device::alu_jump() |
| 2605 | { |
| 2606 | bool cond = false; |
| 2607 | INT8 displacement = (m_instruction->IR & 0xff); |
| 2608 | |
| 2609 | switch (m_instruction->command) |
| 2610 | { |
| 2611 | case JMP: |
| 2612 | cond = true; |
| 2613 | break; |
| 2614 | case JLT: // LAECOP == x00xxx |
| 2615 | cond = ((ST & (ST_AGT | ST_EQ))==0); |
| 2616 | break; |
| 2617 | case JLE: // LAECOP == 0xxxxx |
| 2618 | cond = ((ST & ST_LH)==0); |
| 2619 | break; |
| 2620 | case JEQ: // LAECOP == xx1xxx |
| 2621 | cond = ((ST & ST_EQ)!=0); |
| 2622 | break; |
| 2623 | case JHE: // LAECOP == 1x0xxx, 0x1xxx |
| 2624 | cond = ((ST & (ST_LH | ST_EQ)) != 0); |
| 2625 | break; |
| 2626 | case JGT: // LAECOP == x1xxxx |
| 2627 | cond = ((ST & ST_AGT)!=0); |
| 2628 | break; |
| 2629 | case JNE: // LAECOP == xx0xxx |
| 2630 | cond = ((ST & ST_EQ)==0); |
| 2631 | break; |
| 2632 | case JNC: // LAECOP == xxx0xx |
| 2633 | cond = ((ST & ST_C)==0); |
| 2634 | break; |
| 2635 | case JOC: // LAECOP == xxx1xx |
| 2636 | cond = ((ST & ST_C)!=0); |
| 2637 | break; |
| 2638 | case JNO: // LAECOP == xxxx0x |
| 2639 | cond = ((ST & ST_OV)==0); |
| 2640 | break; |
| 2641 | case JL: // LAECOP == 0x0xxx |
| 2642 | cond = ((ST & (ST_LH | ST_EQ)) == 0); |
| 2643 | break; |
| 2644 | case JH: // LAECOP == 1xxxxx |
| 2645 | cond = ((ST & ST_LH)!=0); |
| 2646 | break; |
| 2647 | case JOP: // LAECOP == xxxxx1 |
| 2648 | cond = ((ST & ST_OP)!=0); |
| 2649 | break; |
| 2650 | } |
| 2651 | |
| 2652 | if (!cond) |
| 2653 | { |
| 2654 | if (VERBOSE>7) LOG("tms9995: Jump condition false\n"); |
| 2655 | } |
| 2656 | else |
| 2657 | { |
| 2658 | if (VERBOSE>7) LOG("tms9995: Jump condition true\n"); |
| 2659 | PC = PC + (displacement<<1); |
| 2660 | } |
| 2661 | pulse_clock(1); |
| 2662 | } |
| 2663 | |
| 2664 | /* |
| 2665 | Implements LDCR. |
| 2666 | */ |
| 2667 | void tms9995_device::alu_ldcr() |
| 2668 | { |
| 2669 | switch (m_instruction->state) |
| 2670 | { |
| 2671 | case 0: |
| 2672 | m_count = (m_instruction->IR >> 6) & 0x000f; |
| 2673 | if (m_count==0) m_count = 16; |
| 2674 | m_instruction->byteop = (m_count<9); |
| 2675 | break; |
| 2676 | case 1: |
| 2677 | // We have read the byte or word into m_current_value. |
| 2678 | compare_and_set_lae(m_current_value, 0); |
| 2679 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2680 | if (m_instruction->byteop) |
| 2681 | { |
| 2682 | m_current_value = (m_current_value>>8) & 0xff; |
| 2683 | set_status_parity((UINT8)m_current_value); |
| 2684 | } |
| 2685 | m_cru_value = m_current_value; |
| 2686 | m_address = WP + 24; |
| 2687 | break; |
| 2688 | case 2: |
| 2689 | // Prepare CRU operation |
| 2690 | m_cru_address = m_current_value; |
| 2691 | break; |
| 2692 | } |
| 2693 | m_instruction->state++; |
| 2694 | pulse_clock(1); |
| 2695 | } |
| 2696 | |
| 2697 | /* |
| 2698 | Implements LI. Almost everything has been done in the microprogram; |
| 2699 | this part is reached with m_address_saved = register address, |
| 2700 | and m_current_value = *m_address; |
| 2701 | */ |
| 2702 | void tms9995_device::alu_li() |
| 2703 | { |
| 2704 | // Retrieve the address of the register |
| 2705 | // The immediate value is still in m_current_value |
| 2706 | m_address = m_address_saved; |
| 2707 | compare_and_set_lae(m_current_value, 0); |
| 2708 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2709 | } |
| 2710 | |
| 2711 | void tms9995_device::alu_limi_lwpi() |
| 2712 | { |
| 2713 | // The immediate value is in m_current_value |
| 2714 | if (m_instruction->command == LIMI) |
| 2715 | { |
| 2716 | ST = (ST & 0xfff0) | (m_current_value & 0x000f); |
| 2717 | if (VERBOSE>7) LOG("tms9995: ST = %04x\n", ST); |
| 2718 | pulse_clock(1); // needs one more than LWPI |
| 2719 | } |
| 2720 | else |
| 2721 | { |
| 2722 | WP = m_current_value; |
| 2723 | if (VERBOSE>7) LOG("tms9995: new WP = %04x\n", WP); |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | /* |
| 2728 | Load status and load workspace pointer. This is a TMS9995-specific |
| 2729 | operation. |
| 2730 | */ |
| 2731 | void tms9995_device::alu_lst_lwp() |
| 2732 | { |
| 2733 | if (m_instruction->command==LST) |
| 2734 | { |
| 2735 | ST = m_current_value; |
| 2736 | if (VERBOSE>7) LOG("tms9995: new ST = %04x\n", ST); |
| 2737 | pulse_clock(1); |
| 2738 | } |
| 2739 | else |
| 2740 | { |
| 2741 | WP = m_current_value; |
| 2742 | if (VERBOSE>7) LOG("tms9995: new WP = %04x\n", WP); |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | /* |
| 2747 | The MOV operation on the TMS9995 is definitely more efficient than in the |
| 2748 | TMS9900. As we have only 8 data bus lines we can read or write bytes |
| 2749 | with only one cycle. The TMS9900 always has to read the memory word first |
| 2750 | in order to write back a complete word, also when doing byte operations. |
| 2751 | */ |
| 2752 | void tms9995_device::alu_mov() |
| 2753 | { |
| 2754 | m_current_value = m_source_value; |
| 2755 | compare_and_set_lae(m_current_value, 0); |
| 2756 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2757 | // No clock pulse, as next instruction is prefetch |
| 2758 | } |
| 2759 | |
| 2760 | /* |
| 2761 | Unsigned and signed multiplication |
| 2762 | */ |
| 2763 | void tms9995_device::alu_multiply() |
| 2764 | { |
| 2765 | int n = 0; |
| 2766 | UINT32 result = 0; |
| 2767 | INT32 results = 0; |
| 2768 | |
| 2769 | if (m_instruction->command==MPY) |
| 2770 | { |
| 2771 | switch (m_instruction->state) |
| 2772 | { |
| 2773 | case 0: |
| 2774 | // m_current_value <- multiplier (source) |
| 2775 | m_source_value = m_current_value; |
| 2776 | // m_address is the second multiplier (in a register) |
| 2777 | m_address = ((m_instruction->IR >> 5) & 0x001e) + WP; |
| 2778 | n = 1; |
| 2779 | break; |
| 2780 | case 1: |
| 2781 | // m_current_value <- register content |
| 2782 | result = (m_source_value & 0x0000ffff) * (m_current_value & 0x0000ffff); |
| 2783 | m_current_value = (result >> 16) & 0xffff; |
| 2784 | m_value_copy = result & 0xffff; |
| 2785 | // m_address is still the register |
| 2786 | n = 16; |
| 2787 | break; |
| 2788 | case 2: |
| 2789 | m_address += 2; |
| 2790 | m_current_value = m_value_copy; |
| 2791 | // now write the lower 16 bit. |
| 2792 | // If the register was R15, do not use R0 but continue writing after |
| 2793 | // R15's address |
| 2794 | break; |
| 2795 | } |
| 2796 | } |
| 2797 | else |
| 2798 | { |
| 2799 | switch (m_instruction->state) |
| 2800 | { |
| 2801 | case 0: |
| 2802 | // m_current_value <- multiplier (source) |
| 2803 | m_source_value = m_current_value; |
| 2804 | // m_address is the second multiplier (in R0) |
| 2805 | m_address = WP; |
| 2806 | n = 1; |
| 2807 | break; |
| 2808 | case 1: |
| 2809 | // m_current_value <- register content |
| 2810 | results = ((INT16)m_source_value) * ((INT16)m_current_value); |
| 2811 | m_current_value = (results >> 16) & 0xffff; |
| 2812 | m_value_copy = results & 0xffff; |
| 2813 | // m_address is still the register |
| 2814 | n = 16; |
| 2815 | break; |
| 2816 | case 2: |
| 2817 | m_address += 2; |
| 2818 | m_current_value = m_value_copy; |
| 2819 | // now write the lower 16 bit. |
| 2820 | break; |
| 2821 | } |
| 2822 | } |
| 2823 | m_instruction->state++; |
| 2824 | pulse_clock(n); |
| 2825 | } |
| 2826 | |
| 2827 | void tms9995_device::alu_rtwp() |
| 2828 | { |
| 2829 | int n = 0; |
| 2830 | switch (m_instruction->state) |
| 2831 | { |
| 2832 | case 0: |
| 2833 | m_address = WP + 30; // R15 |
| 2834 | break; |
| 2835 | case 1: |
| 2836 | ST = m_current_value; |
| 2837 | m_address -= 2; // R14 |
| 2838 | break; |
| 2839 | case 2: |
| 2840 | PC = m_current_value; |
| 2841 | m_address -= 2; // R13 |
| 2842 | break; |
| 2843 | case 3: |
| 2844 | WP = m_current_value; |
| 2845 | n = 1; |
| 2846 | break; |
| 2847 | } |
| 2848 | m_instruction->state++; |
| 2849 | pulse_clock(n); |
| 2850 | } |
| 2851 | |
| 2852 | void tms9995_device::alu_sbo_sbz() |
| 2853 | { |
| 2854 | INT8 displacement; |
| 2855 | |
| 2856 | if (m_instruction->state==0) |
| 2857 | { |
| 2858 | m_address = WP + 24; |
| 2859 | } |
| 2860 | else |
| 2861 | { |
| 2862 | m_cru_value = (m_instruction->command==SBO)? 1 : 0; |
| 2863 | displacement = (INT8)(m_instruction->IR & 0xff); |
| 2864 | m_cru_address = m_current_value + (displacement<<1); |
| 2865 | m_count = 1; |
| 2866 | } |
| 2867 | m_instruction->state++; |
| 2868 | pulse_clock(1); |
| 2869 | } |
| 2870 | |
| 2871 | /* |
| 2872 | Perform the shift operation |
| 2873 | */ |
| 2874 | void tms9995_device::alu_shift() |
| 2875 | { |
| 2876 | bool carry = false; |
| 2877 | bool overflow = false; |
| 2878 | UINT16 sign = 0; |
| 2879 | UINT32 value; |
| 2880 | int count; |
| 2881 | |
| 2882 | switch (m_instruction->state) |
| 2883 | { |
| 2884 | case 0: |
| 2885 | // we have the value of the register in m_current_value |
| 2886 | // Save it (we may have to read R0) |
| 2887 | m_value_copy = m_current_value; |
| 2888 | m_address_saved = m_address; |
| 2889 | m_address = WP; |
| 2890 | // store this in m_current_value where the R0 value will be put |
| 2891 | m_current_value = (m_instruction->IR >> 4)& 0x000f; |
| 2892 | if (m_current_value != 0) |
| 2893 | { |
| 2894 | // skip the next read operation |
| 2895 | MPC++; |
| 2896 | pulse_clock(1); |
| 2897 | } |
| 2898 | else |
| 2899 | { |
| 2900 | if (VERBOSE>8) LOG("tms9995: Shift operation gets count from R0\n"); |
| 2901 | } |
| 2902 | break; |
| 2903 | |
| 2904 | case 1: |
| 2905 | count = m_current_value & 0x000f; // from the instruction or from R0 |
| 2906 | if (count==0) count = 16; |
| 2907 | |
| 2908 | value = m_value_copy; |
| 2909 | |
| 2910 | // we are re-implementing the shift operations because we have to pulse |
| 2911 | // the clock at each single shift anyway. |
| 2912 | // Also, it is easier to implement the status bit setting. |
| 2913 | // Note that count is never 0 |
| 2914 | if (m_instruction->command == SRA) sign = value & 0x8000; |
| 2915 | |
| 2916 | for (int i=0; i < count; i++) |
| 2917 | { |
| 2918 | switch (m_instruction->command) |
| 2919 | { |
| 2920 | case SRL: |
| 2921 | case SRA: |
| 2922 | carry = ((value & 1)!=0); |
| 2923 | value = (value >> 1) | sign; |
| 2924 | break; |
| 2925 | case SLA: |
| 2926 | carry = ((value & 0x8000)!=0); |
| 2927 | value <<= 1; |
| 2928 | if (carry != ((value&0x8000)!=0)) overflow = true; |
| 2929 | break; |
| 2930 | case SRC: |
| 2931 | carry = ((value & 1)!=0); |
| 2932 | value = (value>>1) | (carry? 0x8000 : 0x0000); |
| 2933 | break; |
| 2934 | } |
| 2935 | pulse_clock(1); |
| 2936 | } |
| 2937 | |
| 2938 | m_current_value = value & 0xffff; |
| 2939 | set_status_bit(ST_C, carry); |
| 2940 | set_status_bit(ST_OV, overflow); |
| 2941 | compare_and_set_lae(m_current_value, 0); |
| 2942 | m_address = m_address_saved; // Register address |
| 2943 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 2944 | break; |
| 2945 | } |
| 2946 | m_instruction->state++; |
| 2947 | pulse_clock(1); |
| 2948 | } |
| 2949 | |
| 2950 | /* |
| 2951 | Handles ABS, DEC, DECT, INC, INCT, NEG, INV |
| 2952 | */ |
| 2953 | void tms9995_device::alu_single_arithm() |
| 2954 | { |
| 2955 | UINT32 dest_new = 0; |
| 2956 | UINT32 src_val = m_current_value & 0x0000ffff; |
| 2957 | UINT16 sign = 0; |
| 2958 | bool check_ov = true; |
| 2959 | |
| 2960 | switch (m_instruction->command) |
| 2961 | { |
| 2962 | case ABS: |
| 2963 | // LAECO (from original word!) |
| 2964 | // O if >8000 |
| 2965 | // C is always reset |
| 2966 | set_status_bit(ST_OV, m_current_value == 0x8000); |
| 2967 | compare_and_set_lae(m_current_value, 0); |
| 2968 | |
| 2969 | if ((m_current_value & 0x8000)!=0) |
| 2970 | { |
| 2971 | dest_new = ((~src_val) & 0x0000ffff) + 1; |
| 2972 | } |
| 2973 | else |
| 2974 | { |
| 2975 | dest_new = src_val; |
| 2976 | } |
| 2977 | m_current_value = dest_new & 0xffff; |
| 2978 | return; |
| 2979 | case DEC: |
| 2980 | // LAECO |
| 2981 | // Carry for result value != 0xffff |
| 2982 | // Overflow for result value == 0x7fff |
| 2983 | dest_new = src_val + 0xffff; |
| 2984 | sign = 0x8000; |
| 2985 | break; |
| 2986 | case DECT: |
| 2987 | // Carry for result value != 0xffff / 0xfffe |
| 2988 | // Overflow for result value = 0x7fff / 0x7ffe |
| 2989 | dest_new = src_val + 0xfffe; |
| 2990 | sign = 0x8000; |
| 2991 | break; |
| 2992 | case INC: |
| 2993 | // LAECO |
| 2994 | // Overflow for result value = 0x8000 |
| 2995 | // Carry for result value = 0x0000 |
| 2996 | dest_new = src_val + 1; |
| 2997 | break; |
| 2998 | case INCT: |
| 2999 | // LAECO |
| 3000 | // Overflow for result value = 0x8000 / 0x8001 |
| 3001 | // Carry for result value = 0x0000 / 0x0001 |
| 3002 | dest_new = src_val + 2; |
| 3003 | break; |
| 3004 | case INV: |
| 3005 | // LAE |
| 3006 | dest_new = ~src_val & 0xffff; |
| 3007 | check_ov = false; |
| 3008 | break; |
| 3009 | case NEG: |
| 3010 | // LAECO |
| 3011 | // Overflow occurs for value=0x8000 |
| 3012 | // Carry occurs for value=0 |
| 3013 | dest_new = ((~src_val) & 0x0000ffff) + 1; |
| 3014 | check_ov = false; |
| 3015 | set_status_bit(ST_OV, src_val == 0x8000); |
| 3016 | break; |
| 3017 | case SWPB: |
| 3018 | m_current_value = ((m_current_value << 8) | (m_current_value >> 8)) & 0xffff; |
| 3019 | // I don't know what they are doing right now, but we lose a lot of cycles |
| 3020 | // according to the spec (which can indeed be proved on a real system) |
| 3021 | |
| 3022 | // Maybe this command is used as a forced wait between accesses to the |
| 3023 | // video system. Usually we have two byte writes to set an address in |
| 3024 | // the VDP, with a SWPB in between. Most software for the TI-99/4A using |
| 3025 | // the TMS9900 will run into trouble when executed on the TI-99/8 with |
| 3026 | // the much faster TMS9995. So the SWPB may be used to as an intentional |
| 3027 | // slowdown. |
| 3028 | |
| 3029 | // No status bits affected |
| 3030 | pulse_clock(10); |
| 3031 | return; |
| 3032 | } |
| 3033 | |
| 3034 | if (check_ov) set_status_bit(ST_OV, ((src_val & 0x8000)!=sign) && ((dest_new & 0x8000)==sign)); |
| 3035 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 3036 | m_current_value = dest_new & 0xffff; |
| 3037 | compare_and_set_lae(m_current_value, 0); |
| 3038 | |
| 3039 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 3040 | // No clock pulse, as next instruction is prefetch |
| 3041 | } |
| 3042 | |
| 3043 | /* |
| 3044 | Store CRU. |
| 3045 | */ |
| 3046 | void tms9995_device::alu_stcr() |
| 3047 | { |
| 3048 | int n = 1; |
| 3049 | switch (m_instruction->state) |
| 3050 | { |
| 3051 | case 0: |
| 3052 | m_count = (m_instruction->IR >> 6) & 0x000f; |
| 3053 | if (m_count == 0) m_count = 16; |
| 3054 | m_instruction->byteop = (m_count < 9); |
| 3055 | break; |
| 3056 | case 1: |
| 3057 | m_address_saved = m_address; |
| 3058 | m_address = WP + 24; |
| 3059 | break; |
| 3060 | case 2: |
| 3061 | m_cru_address = m_current_value; |
| 3062 | m_cru_first_read = true; |
| 3063 | break; |
| 3064 | case 3: |
| 3065 | // I don't know what is happening here, but it takes quite some time. |
| 3066 | // May be shift operations. |
| 3067 | m_current_value = m_cru_value; |
| 3068 | m_address = m_address_saved; |
| 3069 | compare_and_set_lae(m_current_value, 0); |
| 3070 | n = 13; |
| 3071 | if (m_instruction->byteop) |
| 3072 | { |
| 3073 | set_status_parity((UINT8)m_current_value); |
| 3074 | m_current_value <<= 8; |
| 3075 | } |
| 3076 | else n += 8; |
| 3077 | if (VERBOSE>7) LOG("tms9995: ST = %04x (val=%04x)\n", ST, m_current_value); |
| 3078 | break; |
| 3079 | } |
| 3080 | m_instruction->state++; |
| 3081 | pulse_clock(n); |
| 3082 | } |
| 3083 | |
| 3084 | |
| 3085 | /* |
| 3086 | Store status and store workspace pointer. We need to determine the |
| 3087 | address of the register here. |
| 3088 | */ |
| 3089 | void tms9995_device::alu_stst_stwp() |
| 3090 | { |
| 3091 | m_address = WP + ((m_instruction->IR & 0x000f)<<1); |
| 3092 | m_current_value = (m_instruction->command==STST)? ST : WP; |
| 3093 | } |
| 3094 | |
| 3095 | /* |
| 3096 | Test CRU bit. |
| 3097 | */ |
| 3098 | void tms9995_device::alu_tb() |
| 3099 | { |
| 3100 | INT8 displacement; |
| 3101 | |
| 3102 | switch (m_instruction->state) |
| 3103 | { |
| 3104 | case 0: |
| 3105 | m_address = WP + 24; |
| 3106 | pulse_clock(1); |
| 3107 | break; |
| 3108 | case 1: |
| 3109 | displacement = (INT8)(m_instruction->IR & 0xff); |
| 3110 | m_cru_address = m_current_value + (displacement<<1); |
| 3111 | m_cru_first_read = true; |
| 3112 | m_count = 1; |
| 3113 | pulse_clock(1); |
| 3114 | break; |
| 3115 | case 2: |
| 3116 | set_status_bit(ST_EQ, m_cru_value!=0); |
| 3117 | if (VERBOSE>7) LOG("tms9995: ST = %04x\n", ST); |
| 3118 | break; |
| 3119 | } |
| 3120 | m_instruction->state++; |
| 3121 | } |
| 3122 | |
| 3123 | /* |
| 3124 | Execute. This operation is substituted after reading the word at the |
| 3125 | given address. |
| 3126 | */ |
| 3127 | void tms9995_device::alu_x() |
| 3128 | { |
| 3129 | // We have the word in m_current_value. This word must now be decoded |
| 3130 | // as if it has been acquired by the normal procedure. |
| 3131 | decode(m_current_value); |
| 3132 | pulse_clock(1); |
| 3133 | |
| 3134 | // Switch to the prefetched and decoded instruction |
| 3135 | next_command(); |
| 3136 | } |
| 3137 | |
| 3138 | /* |
| 3139 | XOP operation. |
| 3140 | */ |
| 3141 | void tms9995_device::alu_xop() |
| 3142 | { |
| 3143 | int n = 1; |
| 3144 | switch (m_instruction->state) |
| 3145 | { |
| 3146 | case 0: |
| 3147 | // we have the source address in m_address |
| 3148 | m_address_saved = m_address; |
| 3149 | // Format is xxxx xxnn nnxx xxxx |
| 3150 | m_address = 0x0040 + ((m_instruction->IR & 0x03c0)>>4); |
| 3151 | break; |
| 3152 | case 1: |
| 3153 | // m_current_value is new WP |
| 3154 | m_value_copy = WP; // store this for later |
| 3155 | WP = m_current_value; |
| 3156 | m_address = WP + 0x0016; // Address of new R11 |
| 3157 | m_current_value = m_address_saved; |
| 3158 | break; |
| 3159 | case 2: |
| 3160 | m_address = WP + 0x001e; |
| 3161 | m_current_value = ST; |
| 3162 | break; |
| 3163 | case 3: |
| 3164 | m_address = WP + 0x001c; |
| 3165 | m_current_value = PC; |
| 3166 | break; |
| 3167 | case 4: |
| 3168 | m_address = WP + 0x001a; |
| 3169 | m_current_value = m_value_copy; |
| 3170 | break; |
| 3171 | case 5: |
| 3172 | m_address = 0x0042 + ((m_instruction->IR & 0x03c0)>>4); |
| 3173 | break; |
| 3174 | case 6: |
| 3175 | PC = m_current_value; |
| 3176 | set_status_bit(ST_X, true); |
| 3177 | n = 0; |
| 3178 | break; |
| 3179 | } |
| 3180 | m_instruction->state++; |
| 3181 | pulse_clock(n); |
| 3182 | } |
| 3183 | |
| 3184 | /* |
| 3185 | Handle an interrupt. The behavior as implemented here follows |
| 3186 | exactly the flowchart in [1] |
| 3187 | */ |
| 3188 | void tms9995_device::alu_int() |
| 3189 | { |
| 3190 | int pulse = 1; |
| 3191 | |
| 3192 | switch (m_instruction->state) |
| 3193 | { |
| 3194 | case 0: |
| 3195 | PC = (PC - 2) & 0xfffe; |
| 3196 | m_address_saved = m_address; |
| 3197 | if (VERBOSE>7) LOG("tms9995: interrupt service (0): Prepare to read vector\n"); |
| 3198 | break; |
| 3199 | case 1: |
| 3200 | pulse = 2; // two cycles (with the one at the end) |
| 3201 | m_source_value = WP; // old WP |
| 3202 | WP = m_current_value; // new WP |
| 3203 | m_current_value = ST; |
| 3204 | m_address = (WP + 30)&0xfffe; |
| 3205 | if (VERBOSE>7) LOG("tms9995: interrupt service (1): Read new WP = %04x, save ST to %04x\n", WP, m_address); |
| 3206 | break; |
| 3207 | case 2: |
| 3208 | m_address = (WP + 28)&0xfffe; |
| 3209 | m_current_value = PC; |
| 3210 | if (VERBOSE>7) LOG("tms9995: interrupt service (2): Save PC to %04x\n", m_address); |
| 3211 | break; |
| 3212 | case 3: |
| 3213 | m_address = (WP + 26)&0xfffe; |
| 3214 | m_current_value = m_source_value; // old WP |
| 3215 | if (VERBOSE>7) LOG("tms9995: interrupt service (3): Save WP to %04x\n", m_address); |
| 3216 | break; |
| 3217 | case 4: |
| 3218 | m_address = (m_address_saved + 2) & 0xfffe; |
| 3219 | if (VERBOSE>7) LOG("tms9995: interrupt service (4): Read PC from %04x\n", m_address); |
| 3220 | break; |
| 3221 | case 5: |
| 3222 | PC = m_current_value; |
| 3223 | ST = (ST & 0xfe00) | m_intmask; |
| 3224 | if (VERBOSE>5) LOG("tms9995: interrupt service (5): Context switch complete; WP=%04x, PC=%04x, ST=%04x\n", WP, PC, ST); |
| 3225 | |
| 3226 | if (((m_int_pending & PENDING_MID)!=0) && m_nmi_active) |
| 3227 | { |
| 3228 | if (VERBOSE>5) LOG("tms9995: interrupt service (5): NMI active after context switch\n"); |
| 3229 | m_int_pending &= ~PENDING_MID; |
| 3230 | m_address = 0xfffc; |
| 3231 | m_intmask = 0; |
| 3232 | MPC = 0; // redo the interrupt service for the NMI |
| 3233 | } |
| 3234 | else |
| 3235 | { |
| 3236 | if (m_reset) |
| 3237 | { |
| 3238 | if (VERBOSE>5) LOG("tms9995: interrupt service (5): RESET completed\n"); |
| 3239 | // We came from the RESET interrupt |
| 3240 | m_reset = false; |
| 3241 | ST &= 0x01ff; |
| 3242 | m_mid_flag = false; |
| 3243 | // FLAG0 and FLAG1 are also set to zero after RESET ([1], sect. 2.3.1.2.2) |
| 3244 | for (int i=0; i < 5; i++) m_flag[i] = false; |
| 3245 | m_check_hold = true; |
| 3246 | } |
| 3247 | } |
| 3248 | pulse = 0; |
| 3249 | break; |
| 3250 | |
| 3251 | // If next instruction is MID opcode we will detect this in command_completed |
| 3252 | } |
| 3253 | m_instruction->state++; |
| 3254 | pulse_clock(pulse); |
| 3255 | } |
| 3256 | |
| 3257 | /**************************************************************************/ |
| 3258 | UINT32 tms9995_device::execute_min_cycles() const |
| 3259 | { |
| 3260 | return 2; |
| 3261 | } |
| 3262 | |
| 3263 | UINT32 tms9995_device::execute_max_cycles() const |
| 3264 | { |
| 3265 | return 44; |
| 3266 | } |
| 3267 | |
| 3268 | UINT32 tms9995_device::execute_input_lines() const |
| 3269 | { |
| 3270 | return 2; |
| 3271 | } |
| 3272 | |
| 3273 | UINT32 tms9995_device::disasm_min_opcode_bytes() const |
| 3274 | { |
| 3275 | return 2; |
| 3276 | } |
| 3277 | |
| 3278 | UINT32 tms9995_device::disasm_max_opcode_bytes() const |
| 3279 | { |
| 3280 | return 6; |
| 3281 | } |
| 3282 | |
| 3283 | offs_t tms9995_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) |
| 3284 | { |
| 3285 | return Dasm9900(buffer, pc, TMS9995_ID, oprom, opram); |
| 3286 | } |
| 3287 | |
| 3288 | |
| 3289 | const device_type TMS9995 = &device_creator<tms9995_device>; |
src/emu/cpu/tms9900/tms9900.c
| r15423 | r15424 | |
| 1 | 1 | /* |
| 2 | | Generate the tms9900 emulator |
| 2 | Texas Instruments TMS9900 |
| 3 | |
| 4 | +--------------------+ |
| 5 | V_BB | 1 o 64| /HOLD |
| 6 | V_CC | 2 63| /MEMEN |
| 7 | WAIT | 3 62| READY |
| 8 | /LOAD | 4 61| /WE |
| 9 | HOLDA | 5 60| CRUCLK |
| 10 | /RESET | 6 59| V_CC |
| 11 | IAQ | 7 58| - |
| 12 | PHI1 | 8 57| - |
| 13 | PHI2 | 9 56| D15 -+ LSB |
| 14 | LSB +- A14 |10 55| D14 | |
| 15 | | A13 |11 54| D13 | |
| 16 | | A12 |12 53| D12 | |
| 17 | | A11 |13 52| D11 | |
| 18 | Address | A10 |14 +--------+ 51| D10 | Data |
| 19 | bus | A9 |15 | | 50| D9 | bus |
| 20 | 32K * | A8 |16 | | 49| D8 | 16 bit |
| 21 | 16bit | A7 |17 | | 48| D7 | |
| 22 | | A6 |18 | | 47| D6 | |
| 23 | | A5 |19 +--------+ 46| D5 | |
| 24 | | A4 |20 45| D4 | |
| 25 | | A3 |21 44| D3 | |
| 26 | | A2 |22 43| D2 | |
| 27 | | A1 |23 42| D1 | |
| 28 | MSB +- A0 |24 41| D0 -+ MSB |
| 29 | PHI4 |25 40| V_SS |
| 30 | V_SS |26 39| - |
| 31 | V_DD |27 38| - |
| 32 | PHI3 |28 37| - |
| 33 | DBIN |29 36| IC0 -+ MSB |
| 34 | CRUOUT |30 35| IC1 | Interrupt |
| 35 | CRUIN |31 34| IC2 | level |
| 36 | /INTREQ |32 33| IC3 -+ LSB |
| 37 | +--------------------+ |
| 38 | |
| 39 | WAIT out Processor in wait state |
| 40 | /LOAD in Non-maskable interrupt |
| 41 | HOLDA out Hold acknowledge |
| 42 | /RESET in Reset |
| 43 | IAQ out Instruction acquisition |
| 44 | PHI1-4 in Clock phase inputs |
| 45 | DBIN out Data bus in input mode |
| 46 | CRUOUT out Communication register unit data output |
| 47 | CRUIN in Communication register unit data input |
| 48 | /INTREQ in Interrupt request |
| 49 | CRUCLK out Communication register unit clock output |
| 50 | /WE out Data available for memory write |
| 51 | READY in Memory ready for access |
| 52 | /MEMEN out Address bus contains memory address |
| 53 | /HOLD in External device acquires address and data bus lines |
| 54 | |
| 55 | V_BB -5V supply |
| 56 | V_CC +5V supply (pins 2 and 59 connected in parallel) |
| 57 | V_DD +12V supply |
| 58 | V_SS 0V Ground reference (pins 26 and 40 connected in parallel) |
| 59 | |
| 60 | A0-A14 out Address bus (32768 words of 16 bit width) |
| 61 | D0-A15 i/o Data bus |
| 62 | IC0-IC3 in Interrupt level (0-15) |
| 63 | |
| 64 | Note that Texas Instruments' bit numberings define bit 0 as the |
| 65 | most significant bit (different to most other systems). Also, the |
| 66 | system uses big-endian memory organisation: Storing the word 0x1234 at |
| 67 | address 0x0000 means that the byte 0x12 is stored at 0x0000 and byte 0x34 |
| 68 | is stored at 0x0001. |
| 69 | |
| 70 | The processor also knows byte-oriented operations (like add byte (AB), |
| 71 | move byte (MOVB)). This makes it necessary for the CPU to read the word |
| 72 | from the target memory location first, change the respective byte, and |
| 73 | write it back. |
| 74 | |
| 75 | See the TI-99/4A driver for an application of the TMS9900 processor |
| 76 | within an 8-bit data bus board layout (using a data bus multiplexer). |
| 77 | |
| 78 | Subcycle handling |
| 79 | |
| 80 | In this implementation we try to emulate the internal operations as |
| 81 | precisely as possible, following the technical specifications. We need |
| 82 | not try to be clock-precise with every tick; it suffices to perform |
| 83 | the proper number of operations within a given time span. |
| 84 | |
| 85 | For each command the CPU executes a microprogram which requires some |
| 86 | amount of cycles to complete. During this time the external clock continues |
| 87 | to issue pulses which can be used to control wait state creation. As we |
| 88 | do not emulate external clocks this implementation offers an extra output |
| 89 | "clock_out" (which, however, is available for the TMS9995) which pulses |
| 90 | at a rate of 3 MHz. External devices (e.g. memory controllers) may count |
| 91 | the pulses and pull down the READY line (with set_ready) as needed. |
| 92 | |
| 93 | Another possibility for creating wait states is to pull down the line |
| 94 | for some time set by a timer. This is done, for example, by circuits like |
| 95 | GROMs or speech synthesis processors (TMS52xx). |
| 96 | |
| 97 | TODO: |
| 98 | - Fine-tune cycles |
| 99 | - State save |
| 100 | - HOLD state should be tested; I don't have test cases yet |
| 101 | |
| 102 | Michael Zapf, June 2012 |
| 3 | 103 | */ |
| 4 | 104 | |
| 5 | | #include "emu.h" |
| 6 | | #include "debugger.h" |
| 7 | 105 | #include "tms9900.h" |
| 8 | 106 | |
| 9 | | #define TMS99XX_MODEL TMS9900_ID |
| 107 | /* tms9900 ST register bits. */ |
| 108 | enum |
| 109 | { |
| 110 | ST_LH = 0x8000, // Logical higher (unsigned comparison) |
| 111 | ST_AGT = 0x4000, // Arithmetical greater than (signed comparison) |
| 112 | ST_EQ = 0x2000, // Equal |
| 113 | ST_C = 0x1000, // Carry |
| 114 | ST_OV = 0x0800, // Overflow (when using signed operations) |
| 115 | ST_OP = 0x0400, // Odd parity (used with byte operations) |
| 116 | ST_X = 0x0200, // XOP |
| 117 | ST_IM = 0x000f // Interrupt mask |
| 118 | }; |
| 10 | 119 | |
| 11 | | #include "99xxcore.h" |
| 120 | enum |
| 121 | { |
| 122 | LOAD_INT = -1, |
| 123 | RESET_INT = -2 |
| 124 | }; |
| 12 | 125 | |
| 13 | | DEFINE_LEGACY_CPU_DEVICE(TMS9900, tms9900); |
| 126 | #define LOG logerror |
| 127 | #define VERBOSE 1 |
| 128 | |
| 129 | /**************************************************************************** |
| 130 | Constructor |
| 131 | ****************************************************************************/ |
| 132 | |
| 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), |
| 137 | m_prgspace(NULL), |
| 138 | m_cru(NULL) |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | enum |
| 143 | { |
| 144 | TMS9900_PC=0, TMS9900_WP, TMS9900_STATUS, TMS9900_IR, |
| 145 | TMS9900_R0, TMS9900_R1, TMS9900_R2, TMS9900_R3, |
| 146 | TMS9900_R4, TMS9900_R5, TMS9900_R6, TMS9900_R7, |
| 147 | TMS9900_R8, TMS9900_R9, TMS9900_R10, TMS9900_R11, |
| 148 | TMS9900_R12, TMS9900_R13, TMS9900_R14, TMS9900_R15 |
| 149 | }; |
| 150 | |
| 151 | void tms9900_device::device_start() |
| 152 | { |
| 153 | const tms9900_config *conf = reinterpret_cast<const tms9900_config *>(static_config()); |
| 154 | |
| 155 | assert (conf != NULL); |
| 156 | |
| 157 | // TODO: Restore state save feature |
| 158 | |
| 159 | m_prgspace = space(AS_PROGRAM); // dimemory.h |
| 160 | m_cru = space(AS_IO); |
| 161 | |
| 162 | // Resolve our external connections |
| 163 | m_external_operation.resolve(conf->external_callback, *this); |
| 164 | m_get_ic0123.resolve(conf->irq_level, *this); |
| 165 | m_iaq_line.resolve(conf->instruction_acquisition, *this); |
| 166 | m_clock_out_line.resolve(conf->clock_out, *this); |
| 167 | m_wait_line.resolve(conf->wait_line, *this); |
| 168 | m_holda_line.resolve(conf->holda_line, *this); |
| 169 | |
| 170 | // set our instruction counter |
| 171 | m_icountptr = &m_icount; |
| 172 | |
| 173 | // add the states for the debugger |
| 174 | for (int i=0; i < 20; i++) |
| 175 | { |
| 176 | // callimport = need to use the state_import method to write to the state variable |
| 177 | // callexport = need to use the state_export method to read the state variable |
| 178 | state_add(i, s_statename[i], m_state_any).callimport().callexport().formatstr("%04X"); |
| 179 | } |
| 180 | state_add(STATE_GENPC, "curpc", PC).formatstr("%4s").noshow(); |
| 181 | state_add(STATE_GENFLAGS, "status", m_state_any).callimport().callexport().formatstr("%16s").noshow(); |
| 182 | |
| 183 | build_command_lookup_table(); |
| 184 | } |
| 185 | |
| 186 | void tms9900_device::device_stop() |
| 187 | { |
| 188 | int k = 0; |
| 189 | if (VERBOSE>8) LOG("tms9900: Deleting lookup tables\n"); |
| 190 | while (m_lotables[k]!=NULL) delete[] m_lotables[k++]; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | TMS9900 hard reset |
| 195 | The device reset is just the emulator's trigger for the reset procedure |
| 196 | which is invoked via the main loop. |
| 197 | */ |
| 198 | void tms9900_device::device_reset() |
| 199 | { |
| 200 | m_reset = true; |
| 201 | } |
| 202 | |
| 203 | const char* tms9900_device::s_statename[20] = |
| 204 | { |
| 205 | "PC ", "WP ", "ST ", "IR ", |
| 206 | "R0 ", "R1 ", "R2 ", "R3 ", |
| 207 | "R4 ", "R5 ", "R6 ", "R7 ", |
| 208 | "R8 ", "R9 ", "R10", "R11", |
| 209 | "R12", "R13", "R14", "R15" |
| 210 | }; |
| 211 | |
| 212 | /* |
| 213 | Write the contents of a register by external input (debugger) |
| 214 | */ |
| 215 | void tms9900_device::state_import(const device_state_entry &entry) |
| 216 | { |
| 217 | int index = entry.index(); |
| 218 | switch (entry.index()) |
| 219 | { |
| 220 | case STATE_GENFLAGS: |
| 221 | // no action here; we do not allow import, as the flags are all |
| 222 | // bits of the STATUS register |
| 223 | break; |
| 224 | case TMS9900_PC: |
| 225 | PC = (UINT16)m_state_any; |
| 226 | break; |
| 227 | case TMS9900_WP: |
| 228 | WP = (UINT16)m_state_any; |
| 229 | break; |
| 230 | case TMS9900_STATUS: |
| 231 | ST = (UINT16)m_state_any; |
| 232 | break; |
| 233 | case TMS9900_IR: |
| 234 | IR = (UINT16)m_state_any; |
| 235 | break; |
| 236 | default: |
| 237 | // Workspace registers |
| 238 | if (index <= TMS9900_R15) |
| 239 | write_workspace_register_debug(index-TMS9900_R0, (UINT16)m_state_any); |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | Reads the contents of a register for display in the debugger. |
| 246 | */ |
| 247 | void tms9900_device::state_export(const device_state_entry &entry) |
| 248 | { |
| 249 | int index = entry.index(); |
| 250 | switch (entry.index()) |
| 251 | { |
| 252 | case STATE_GENFLAGS: |
| 253 | m_state_any = ST; |
| 254 | break; |
| 255 | case TMS9900_PC: |
| 256 | m_state_any = PC; |
| 257 | break; |
| 258 | case TMS9900_WP: |
| 259 | m_state_any = WP; |
| 260 | break; |
| 261 | case TMS9900_STATUS: |
| 262 | m_state_any = ST; |
| 263 | break; |
| 264 | case TMS9900_IR: |
| 265 | m_state_any = IR; |
| 266 | break; |
| 267 | default: |
| 268 | // Workspace registers |
| 269 | if (index <= TMS9900_R15) |
| 270 | m_state_any = read_workspace_register_debug(index-TMS9900_R0); |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | state_string_export - export state as a string for the debugger |
| 277 | */ |
| 278 | void tms9900_device::state_string_export(const device_state_entry &entry, astring &string) |
| 279 | { |
| 280 | static const char *statestr = "LAECOPX-----IIII"; |
| 281 | char *flags = string.stringbuffer(16); |
| 282 | UINT16 val = 0x8000; |
| 283 | if (entry.index()==STATE_GENFLAGS) |
| 284 | { |
| 285 | for (int i=0; i < 16; i++) |
| 286 | { |
| 287 | flags[i] = ((val & ST)!=0)? statestr[i] : '.'; |
| 288 | val = (val >> 1) & 0x7fff; |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /**************************************************************************/ |
| 294 | |
| 295 | UINT16 tms9900_device::read_workspace_register_debug(int reg) |
| 296 | { |
| 297 | int temp = m_icount; |
| 298 | UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & 0xfffe); |
| 299 | m_icount = temp; |
| 300 | return value; |
| 301 | } |
| 302 | |
| 303 | void tms9900_device::write_workspace_register_debug(int reg, UINT16 data) |
| 304 | { |
| 305 | int temp = m_icount; |
| 306 | m_prgspace->write_word((WP+(reg<<1)) & 0xfffe, data); |
| 307 | m_icount = temp; |
| 308 | } |
| 309 | |
| 310 | const address_space_config *tms9900_device::memory_space_config(address_spacenum spacenum) const |
| 311 | { |
| 312 | switch (spacenum) |
| 313 | { |
| 314 | case AS_PROGRAM: |
| 315 | return &m_program_config; |
| 316 | |
| 317 | case AS_IO: |
| 318 | return &m_io_config; |
| 319 | |
| 320 | default: |
| 321 | return NULL; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /************************************************************************** |
| 326 | Microprograms for the CPU instructions |
| 327 | |
| 328 | The actions which are specific to the respective instruction are |
| 329 | invoked by repeated calls of ALU_xxx; each call increases a state |
| 330 | variable so that on the next call, the next part can be processed. |
| 331 | This saves us a lot of additional functions. |
| 332 | **************************************************************************/ |
| 333 | |
| 334 | /* |
| 335 | Define the indices for the micro-operation table. This is done for the sake |
| 336 | of a simpler microprogram definition as an UINT8[]. |
| 337 | */ |
| 338 | enum |
| 339 | { |
| 340 | IAQ = 0, |
| 341 | MEMORY_READ, |
| 342 | MEMORY_WRITE, |
| 343 | REG_READ, |
| 344 | REG_WRITE, |
| 345 | CRU, // 5 |
| 346 | DATA_DERIVE, |
| 347 | RET, |
| 348 | END, |
| 349 | ALU_NOP, |
| 350 | ALU_CLR, // 10 |
| 351 | ALU_SETADDR, |
| 352 | ALU_ADDONE, |
| 353 | ALU_SETADDR_ADDONE, |
| 354 | ALU_PCADDR_ADVANCE, |
| 355 | ALU_SOURCE, // 15 |
| 356 | ALU_ADDREG, |
| 357 | ALU_IMM, |
| 358 | ALU_REG, |
| 359 | ALU_F1, |
| 360 | ALU_COMP, // 20 |
| 361 | ALU_F3, |
| 362 | ALU_MPY, |
| 363 | ALU_DIV, |
| 364 | ALU_XOP, |
| 365 | ALU_CLR_SWPB, // 25 |
| 366 | ALU_ABS, |
| 367 | ALU_X, |
| 368 | ALU_B, |
| 369 | ALU_BL, |
| 370 | ALU_BLWP, // 30 |
| 371 | ALU_LDCR, |
| 372 | ALU_STCR, |
| 373 | ALU_SBZ_SBO, |
| 374 | ALU_TB, |
| 375 | ALU_JMP, // 35 |
| 376 | ALU_SHIFT, |
| 377 | ALU_AI_ORI, |
| 378 | ALU_CI, |
| 379 | ALU_LI, |
| 380 | ALU_LWPI, // 40 |
| 381 | ALU_LIMI, |
| 382 | ALU_STWP_STST, |
| 383 | ALU_EXT, |
| 384 | ALU_RTWP, |
| 385 | ALU_INT // 45 |
| 386 | }; |
| 387 | |
| 388 | |
| 389 | #define MICROPROGRAM(_MP) \ |
| 390 | static const UINT8 _MP[] = |
| 391 | |
| 392 | /* |
| 393 | This is a kind of subroutine with 6 variants. Might be done in countless |
| 394 | better ways, but will suffice for now. Each variant has at most 8 steps |
| 395 | RET will return to the caller. |
| 396 | The padding simplifies the calculation of the start address: We just |
| 397 | take the Ts field as an index. In the last two cases we add an offset of 8 |
| 398 | if we have an indexed (resp. a byte) operation. |
| 399 | */ |
| 400 | MICROPROGRAM(data_derivation) |
| 401 | { |
| 402 | REG_READ, RET, 0, 0, 0, 0, 0, 0, // Rx (00) |
| 403 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 404 | REG_READ, ALU_SETADDR, MEMORY_READ, RET, 0, 0, 0, 0, // *Rx (01) |
| 405 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 406 | ALU_CLR, ALU_PCADDR_ADVANCE, MEMORY_READ, ALU_ADDREG, MEMORY_READ, RET, 0, 0, // @sym (10) |
| 407 | REG_READ, ALU_PCADDR_ADVANCE, MEMORY_READ, ALU_ADDREG, MEMORY_READ, RET, 0, 0, // @sym(Rx) (10) |
| 408 | REG_READ, ALU_SETADDR_ADDONE, ALU_ADDONE, REG_WRITE, MEMORY_READ, RET, 0, 0, // *Rx+ (word) (11) |
| 409 | REG_READ, ALU_SETADDR_ADDONE, REG_WRITE, MEMORY_READ, RET, 0, 0, 0 // *Rx+ (byte) (11) |
| 410 | }; |
| 411 | |
| 412 | MICROPROGRAM(f1_mp) |
| 413 | { |
| 414 | ALU_NOP, |
| 415 | DATA_DERIVE, |
| 416 | ALU_SOURCE, // Store the word |
| 417 | DATA_DERIVE, |
| 418 | ALU_F1, |
| 419 | MEMORY_WRITE, |
| 420 | END |
| 421 | }; |
| 422 | |
| 423 | MICROPROGRAM(comp_mp) |
| 424 | { |
| 425 | ALU_NOP, |
| 426 | DATA_DERIVE, |
| 427 | ALU_SOURCE, |
| 428 | DATA_DERIVE, |
| 429 | ALU_COMP, |
| 430 | ALU_NOP, // Compare operations do not write back any data |
| 431 | END |
| 432 | }; |
| 433 | |
| 434 | MICROPROGRAM(f3_mp) |
| 435 | { |
| 436 | ALU_NOP, |
| 437 | DATA_DERIVE, |
| 438 | ALU_F3, |
| 439 | REG_READ, // We have to distinguish this from the C/CB microprogram above |
| 440 | ALU_F3, |
| 441 | ALU_NOP, // Compare operations do not write back any data |
| 442 | END |
| 443 | }; |
| 444 | |
| 445 | MICROPROGRAM(xor_mp) |
| 446 | { |
| 447 | ALU_NOP, |
| 448 | DATA_DERIVE, |
| 449 | ALU_F3, |
| 450 | REG_READ, |
| 451 | ALU_F3, |
| 452 | MEMORY_WRITE, // XOR again must write back data |
| 453 | END |
| 454 | }; |
| 455 | |
| 456 | MICROPROGRAM(mult_mp) |
| 457 | { |
| 458 | ALU_NOP, |
| 459 | DATA_DERIVE, |
| 460 | ALU_MPY, // Save the value; put register number in m_regnumber |
| 461 | REG_READ, |
| 462 | ALU_MPY, // 18 cycles for multiplication |
| 463 | REG_WRITE, // Write the high word |
| 464 | ALU_MPY, // Get low word, increase m_address |
| 465 | MEMORY_WRITE, |
| 466 | END |
| 467 | }; |
| 468 | |
| 469 | MICROPROGRAM(div_mp) |
| 470 | { |
| 471 | ALU_NOP, |
| 472 | DATA_DERIVE, // Get divisor |
| 473 | ALU_DIV, // 0 Store divisor and get register number |
| 474 | REG_READ, // Read register |
| 475 | ALU_DIV, // 1 Check overflow, increase address (or abort here) |
| 476 | MEMORY_READ, // Read subsequent word (if reg=15 this is behind the workspace) |
| 477 | 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 |
| 479 | ALU_DIV, // 3 Get remainder |
| 480 | MEMORY_WRITE, // Write remainder |
| 481 | END |
| 482 | }; |
| 483 | |
| 484 | MICROPROGRAM(xop_mp) |
| 485 | { |
| 486 | ALU_NOP, |
| 487 | DATA_DERIVE, // Get argument |
| 488 | ALU_XOP, // 0 Save the address of the source operand, set address = 0x0040 + xopNr*4 |
| 489 | MEMORY_READ, // Read the new WP |
| 490 | 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 |
| 492 | ALU_XOP, // 2 |
| 493 | REG_WRITE, // Write the ST into the new R15 |
| 494 | ALU_XOP, // 3 |
| 495 | REG_WRITE, // Write the PC into the new R14 |
| 496 | ALU_XOP, // 4 |
| 497 | REG_WRITE, // Write the WP into the new R13 |
| 498 | ALU_XOP, // 5 Set the X bit in the ST |
| 499 | MEMORY_READ, // Read the new PC |
| 500 | ALU_XOP, // 6 Set the new PC |
| 501 | ALU_NOP, |
| 502 | END |
| 503 | }; |
| 504 | |
| 505 | MICROPROGRAM(clr_swpb_mp) |
| 506 | { |
| 507 | ALU_NOP, |
| 508 | DATA_DERIVE, |
| 509 | ALU_CLR_SWPB, |
| 510 | MEMORY_WRITE, |
| 511 | END |
| 512 | }; |
| 513 | |
| 514 | MICROPROGRAM(abs_mp) |
| 515 | { |
| 516 | ALU_NOP, |
| 517 | DATA_DERIVE, |
| 518 | ALU_ABS, // two cycles |
| 519 | MEMORY_WRITE, // skipped when ABS is not performed |
| 520 | ALU_NOP, |
| 521 | END |
| 522 | }; |
| 523 | |
| 524 | MICROPROGRAM(x_mp) |
| 525 | { |
| 526 | ALU_NOP, |
| 527 | DATA_DERIVE, |
| 528 | ALU_X, |
| 529 | END |
| 530 | }; |
| 531 | |
| 532 | MICROPROGRAM(b_mp) // Branch |
| 533 | { |
| 534 | ALU_NOP, |
| 535 | DATA_DERIVE, |
| 536 | ALU_B, |
| 537 | END |
| 538 | }; |
| 539 | |
| 540 | MICROPROGRAM(bl_mp) // Branch and Link |
| 541 | { |
| 542 | ALU_NOP, |
| 543 | DATA_DERIVE, |
| 544 | ALU_BL, // two cycles |
| 545 | REG_WRITE, |
| 546 | END |
| 547 | }; |
| 548 | |
| 549 | MICROPROGRAM(blwp_mp) // Branch and Load WP |
| 550 | { |
| 551 | ALU_NOP, |
| 552 | DATA_DERIVE, // Get argument |
| 553 | ALU_BLWP, // 0 Save old WP, set new WP, save position |
| 554 | REG_WRITE, // write ST to R15 |
| 555 | ALU_BLWP, // 1 |
| 556 | REG_WRITE, // write PC to R14 |
| 557 | ALU_BLWP, // 2 |
| 558 | REG_WRITE, // write WP to R13 |
| 559 | ALU_BLWP, // 3 Get saved position |
| 560 | MEMORY_READ, // Read new PC |
| 561 | ALU_BLWP, // 4 Set new PC |
| 562 | END |
| 563 | }; |
| 564 | |
| 565 | MICROPROGRAM(ldcr_mp) |
| 566 | { |
| 567 | ALU_NOP, |
| 568 | DATA_DERIVE, |
| 569 | ALU_SOURCE, |
| 570 | ALU_NOP, |
| 571 | ALU_LDCR, |
| 572 | REG_READ, |
| 573 | ALU_LDCR, |
| 574 | CRU, |
| 575 | ALU_NOP, |
| 576 | END |
| 577 | }; |
| 578 | |
| 579 | MICROPROGRAM(stcr_mp) |
| 580 | { |
| 581 | ALU_NOP, |
| 582 | DATA_DERIVE, |
| 583 | ALU_SOURCE, // Store address and value |
| 584 | ALU_STCR, // 0 Set register_number = 12 |
| 585 | REG_READ, |
| 586 | ALU_STCR, // 1 Prepare CRU access |
| 587 | CRU, |
| 588 | ALU_STCR, // 2 Create result; Cycles = 5 + (8-#C-1) or + (16-#C) |
| 589 | MEMORY_WRITE, |
| 590 | END |
| 591 | }; |
| 592 | |
| 593 | MICROPROGRAM(sbz_sbo_mp) |
| 594 | { |
| 595 | ALU_SBZ_SBO, |
| 596 | REG_READ, |
| 597 | ALU_SBZ_SBO, |
| 598 | CRU, |
| 599 | END |
| 600 | }; |
| 601 | |
| 602 | MICROPROGRAM(tb_mp) |
| 603 | { |
| 604 | ALU_TB, |
| 605 | REG_READ, |
| 606 | ALU_TB, |
| 607 | CRU, |
| 608 | ALU_TB, |
| 609 | END |
| 610 | }; |
| 611 | |
| 612 | MICROPROGRAM(jmp_mp) |
| 613 | { |
| 614 | ALU_NOP, |
| 615 | ALU_NOP, |
| 616 | ALU_JMP, |
| 617 | ALU_JMP, |
| 618 | END |
| 619 | }; |
| 620 | |
| 621 | MICROPROGRAM(shift_mp) |
| 622 | { |
| 623 | ALU_SHIFT, |
| 624 | REG_READ, |
| 625 | ALU_SHIFT, |
| 626 | REG_READ, |
| 627 | ALU_SHIFT, |
| 628 | REG_WRITE, |
| 629 | END |
| 630 | }; |
| 631 | |
| 632 | MICROPROGRAM(ai_ori_mp) |
| 633 | { |
| 634 | ALU_REG, |
| 635 | REG_READ, |
| 636 | ALU_IMM, |
| 637 | MEMORY_READ, |
| 638 | ALU_AI_ORI, |
| 639 | REG_WRITE, |
| 640 | END |
| 641 | }; |
| 642 | |
| 643 | MICROPROGRAM(ci_mp) |
| 644 | { |
| 645 | ALU_REG, |
| 646 | REG_READ, |
| 647 | ALU_IMM, |
| 648 | MEMORY_READ, |
| 649 | ALU_CI, |
| 650 | ALU_NOP, |
| 651 | END |
| 652 | }; |
| 653 | |
| 654 | MICROPROGRAM(li_mp) |
| 655 | { |
| 656 | ALU_IMM, |
| 657 | MEMORY_READ, |
| 658 | ALU_LI, // sets status bits |
| 659 | ALU_REG, // set register number |
| 660 | REG_WRITE, |
| 661 | END |
| 662 | }; |
| 663 | |
| 664 | MICROPROGRAM(lwpi_mp) |
| 665 | { |
| 666 | ALU_IMM, |
| 667 | MEMORY_READ, |
| 668 | ALU_NOP, |
| 669 | ALU_LWPI, // sets WP |
| 670 | END |
| 671 | }; |
| 672 | |
| 673 | MICROPROGRAM(limi_mp) |
| 674 | { |
| 675 | ALU_IMM, |
| 676 | MEMORY_READ, |
| 677 | ALU_NOP, |
| 678 | ALU_LIMI, // sets interrupt mask in ST |
| 679 | ALU_NOP, |
| 680 | ALU_NOP, |
| 681 | END |
| 682 | }; |
| 683 | |
| 684 | MICROPROGRAM(stwp_stst_mp) |
| 685 | { |
| 686 | ALU_STWP_STST, |
| 687 | ALU_REG, |
| 688 | REG_WRITE, |
| 689 | END |
| 690 | }; |
| 691 | |
| 692 | MICROPROGRAM(external_mp) |
| 693 | { |
| 694 | ALU_EXT, |
| 695 | END |
| 696 | }; |
| 697 | |
| 698 | MICROPROGRAM(rtwp_mp) // Problem: This makes RTWP use 8 instead of 7 machine cycles. |
| 699 | { |
| 700 | ALU_RTWP, |
| 701 | REG_READ, |
| 702 | ALU_RTWP, |
| 703 | REG_READ, |
| 704 | ALU_RTWP, |
| 705 | REG_READ, |
| 706 | ALU_RTWP, |
| 707 | END |
| 708 | }; |
| 709 | |
| 710 | MICROPROGRAM(int_mp) |
| 711 | { |
| 712 | ALU_NOP, |
| 713 | ALU_INT, // 0 Set address = 0 |
| 714 | MEMORY_READ, |
| 715 | ALU_INT, // 1 Save old WP, set new WP, save position |
| 716 | REG_WRITE, // write ST to R15 |
| 717 | ALU_INT, // 2 |
| 718 | REG_WRITE, // write PC to R14 |
| 719 | ALU_INT, // 3 |
| 720 | REG_WRITE, // write WP to R13 |
| 721 | ALU_INT, // 4 Get saved position |
| 722 | MEMORY_READ, // Read new PC |
| 723 | ALU_INT, // 5 Set new PC |
| 724 | END |
| 725 | }; |
| 726 | |
| 727 | const tms9900_device::ophandler tms9900_device::s_microoperation[] = |
| 728 | { |
| 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, |
| 738 | |
| 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, |
| 749 | |
| 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 |
| 777 | }; |
| 778 | |
| 779 | /***************************************************************************** |
| 780 | CPU instructions |
| 781 | *****************************************************************************/ |
| 782 | |
| 783 | /* |
| 784 | Available instructions |
| 785 | */ |
| 786 | enum |
| 787 | { |
| 788 | ILL=0, A, AB, ABS, AI, ANDI, B, BL, BLWP, C, |
| 789 | CB, CI, CKOF, CKON, CLR, COC, CZC, DEC, DECT, DIV, |
| 790 | IDLE, INC, INCT, INV, JEQ, JGT, JH, JHE, JL, JLE, |
| 791 | JLT, JMP, JNC, JNE, JNO, JOC, JOP, LDCR, LI, LIMI, |
| 792 | LREX, LWPI, MOV, MOVB, MPY, NEG, ORI, RSET, RTWP, S, |
| 793 | SB, SBO, SBZ, SETO, SLA, SOC, SOCB, SRA, SRC, SRL, |
| 794 | STCR, STST, STWP, SWPB, SZC, SZCB, TB, X, XOP, XOR |
| 795 | }; |
| 796 | |
| 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 | /* |
| 808 | Formats: |
| 809 | |
| 810 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| 811 | ----+------------------------------------------------+ |
| 812 | 1 | Opcode | B | Td | RegNr | Ts | RegNr | |
| 813 | +--------+---+----+------------+----+------------+ |
| 814 | 2 | Opcode | Displacement | |
| 815 | +-----------------------+------------------------+ |
| 816 | 3 | Opcode | RegNr | Ts | RegNr | |
| 817 | +-----------------+------------+----+------------+ |
| 818 | 4 | Opcode | Count | Ts | RegNr | |
| 819 | +-----------------+------------+----+------------+ |
| 820 | 5 | Opcode | Count | RegNr | |
| 821 | +-----------------------+-----------+------------+ |
| 822 | 6 | Opcode | Ts | RegNr | |
| 823 | +------------------------------+----+------------+ |
| 824 | 7 | Opcode |0| 0| 0| 0| 0 | |
| 825 | +---------------------------------+-+--+--+--+---+ |
| 826 | 8 | Opcode |0| RegNr | |
| 827 | +---------------------------------+-+------------+ |
| 828 | 9 | Opcode | Reg/Nr | Ts | RegNr | |
| 829 | +-----------------+------------+----+------------+ |
| 830 | */ |
| 831 | |
| 832 | /* |
| 833 | Defines the number of bits from the left which are significant for the |
| 834 | command in the respective format. |
| 835 | */ |
| 836 | static const int format_mask_len[] = |
| 837 | { |
| 838 | 0, 4, 8, 6, 6, 8, 10, 16, 12, 6 |
| 839 | }; |
| 840 | |
| 841 | const tms9900_device::tms_instruction tms9900_device::s_command[] = |
| 842 | { |
| 843 | // Opcode, ID, format, microprg |
| 844 | { 0x0200, LI, 8, li_mp }, |
| 845 | { 0x0220, AI, 8, ai_ori_mp }, |
| 846 | { 0x0240, ANDI, 8, ai_ori_mp }, |
| 847 | { 0x0260, ORI, 8, ai_ori_mp }, |
| 848 | { 0x0280, CI, 8, ci_mp }, |
| 849 | { 0x02a0, STWP, 8, stwp_stst_mp }, |
| 850 | { 0x02c0, STST, 8, stwp_stst_mp }, |
| 851 | { 0x02e0, LWPI, 8, lwpi_mp }, |
| 852 | { 0x0300, LIMI, 8, limi_mp }, |
| 853 | { 0x0340, IDLE, 7, external_mp }, |
| 854 | { 0x0360, RSET, 7, external_mp }, |
| 855 | { 0x0380, RTWP, 7, rtwp_mp }, |
| 856 | { 0x03a0, CKON, 7, external_mp }, |
| 857 | { 0x03c0, CKOF, 7, external_mp }, |
| 858 | { 0x03e0, LREX, 7, external_mp }, |
| 859 | { 0x0400, BLWP, 6, blwp_mp }, |
| 860 | { 0x0440, B, 6, b_mp }, |
| 861 | { 0x0480, X, 6, x_mp }, |
| 862 | { 0x04c0, CLR, 6, clr_swpb_mp }, |
| 863 | { 0x0500, NEG, 6, clr_swpb_mp }, |
| 864 | { 0x0540, INV, 6, clr_swpb_mp }, |
| 865 | { 0x0580, INC, 6, clr_swpb_mp }, |
| 866 | { 0x05c0, INCT, 6, clr_swpb_mp }, |
| 867 | { 0x0600, DEC, 6, clr_swpb_mp }, |
| 868 | { 0x0640, DECT, 6, clr_swpb_mp }, |
| 869 | { 0x0680, BL, 6, bl_mp }, |
| 870 | { 0x06c0, SWPB, 6, clr_swpb_mp }, |
| 871 | { 0x0700, SETO, 6, clr_swpb_mp }, |
| 872 | { 0x0740, ABS, 6, abs_mp }, |
| 873 | { 0x0800, SRA, 5, shift_mp }, |
| 874 | { 0x0900, SRL, 5, shift_mp }, |
| 875 | { 0x0a00, SLA, 5, shift_mp }, |
| 876 | { 0x0b00, SRC, 5, shift_mp }, |
| 877 | { 0x1000, JMP, 2, jmp_mp }, |
| 878 | { 0x1100, JLT, 2, jmp_mp }, |
| 879 | { 0x1200, JLE, 2, jmp_mp }, |
| 880 | { 0x1300, JEQ, 2, jmp_mp }, |
| 881 | { 0x1400, JHE, 2, jmp_mp }, |
| 882 | { 0x1500, JGT, 2, jmp_mp }, |
| 883 | { 0x1600, JNE, 2, jmp_mp }, |
| 884 | { 0x1700, JNC, 2, jmp_mp }, |
| 885 | { 0x1800, JOC, 2, jmp_mp }, |
| 886 | { 0x1900, JNO, 2, jmp_mp }, |
| 887 | { 0x1a00, JL, 2, jmp_mp }, |
| 888 | { 0x1b00, JH, 2, jmp_mp }, |
| 889 | { 0x1c00, JOP, 2, jmp_mp }, |
| 890 | { 0x1d00, SBO, 2, sbz_sbo_mp }, |
| 891 | { 0x1e00, SBZ, 2, sbz_sbo_mp }, |
| 892 | { 0x1f00, TB, 2, tb_mp }, |
| 893 | { 0x2000, COC, 3, f3_mp }, |
| 894 | { 0x2400, CZC, 3, f3_mp }, |
| 895 | { 0x2800, XOR, 3, xor_mp }, |
| 896 | { 0x2c00, XOP, 3, xop_mp }, |
| 897 | { 0x3000, LDCR, 4, ldcr_mp }, |
| 898 | { 0x3400, STCR, 4, stcr_mp }, |
| 899 | { 0x3800, MPY, 9, mult_mp }, |
| 900 | { 0x3c00, DIV, 9, div_mp }, |
| 901 | { 0x4000, SZC, 1, f1_mp }, |
| 902 | { 0x5000, SZCB, 1, f1_mp }, |
| 903 | { 0x6000, S, 1, f1_mp }, |
| 904 | { 0x7000, SB, 1, f1_mp }, |
| 905 | { 0x8000, C, 1, comp_mp }, |
| 906 | { 0x9000, CB, 1, comp_mp }, |
| 907 | { 0xa000, A, 1, f1_mp }, |
| 908 | { 0xb000, AB, 1, f1_mp }, |
| 909 | { 0xc000, MOV, 1, f1_mp }, |
| 910 | { 0xd000, MOVB, 1, f1_mp }, |
| 911 | { 0xe000, SOC, 1, f1_mp }, |
| 912 | { 0xf000, SOCB, 1, f1_mp } |
| 913 | }; |
| 914 | |
| 915 | /* |
| 916 | Create a B-tree for looking up the commands. Each node can carry up to |
| 917 | 16 entries, indexed by 4 consecutive bits in the opcode. |
| 918 | |
| 919 | Works as follows: |
| 920 | |
| 921 | Opcode = 0201 (Load immediate value into register 1) |
| 922 | Opcode = 0284 (Compare immediate value with register 4) |
| 923 | |
| 924 | Table: [ Table0, table1, table2, ... tableF ] |
| 925 | | |
| 926 | +-------+ |
| 927 | v |
| 928 | table0: [ table00, table01, table02, ... table0f ] |
| 929 | | |
| 930 | +-------------------------+ |
| 931 | v |
| 932 | table02: [ table020, table021, ... table028, ... table02f ] |
| 933 | | | | |
| 934 | v v v |
| 935 | Entry NULL Entry |
| 936 | for LI for CI |
| 937 | |
| 938 | For each level in the tree, four more bits are compared. The search |
| 939 | terminates when the number of compared bits is equal or higher than |
| 940 | the number of significant bits of the format of this opcode. The entry |
| 941 | points to the respective line in s_command. |
| 942 | |
| 943 | This way we can decode all format 1 commands by a single pass (including the |
| 944 | most frequent command MOV), and almost all commands by less than four passes. |
| 945 | |
| 946 | The disadvantage is that we have to build these tables from the opcode |
| 947 | list at runtime, and many positions are empty. But we do not need more |
| 948 | than 20 tables for the TMS command set. |
| 949 | */ |
| 950 | void tms9900_device::build_command_lookup_table() |
| 951 | { |
| 952 | int i = 0; |
| 953 | int cmdindex = 0; |
| 954 | int bitcount; |
| 955 | const tms_instruction *inst; |
| 956 | UINT16 opcode; |
| 957 | int k = 0; |
| 958 | |
| 959 | m_command_lookup_table = new lookup_entry[16]; |
| 960 | // We use lotables as a list of allocated tables - to be able to delete them |
| 961 | // at the end. |
| 962 | m_lotables[k++] = m_command_lookup_table; |
| 963 | |
| 964 | lookup_entry* table = m_command_lookup_table; |
| 965 | for (int j=0; j < 16; j++) |
| 966 | { |
| 967 | table[j].entry = NULL; |
| 968 | table[j].next_digit = NULL; |
| 969 | } |
| 970 | |
| 971 | do |
| 972 | { |
| 973 | inst = &s_command[i]; |
| 974 | table = m_command_lookup_table; |
| 975 | if (VERBOSE>8) LOG("tms9900: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]); |
| 976 | bitcount = 4; |
| 977 | opcode = inst->opcode; |
| 978 | cmdindex = (opcode>>12) & 0x000f; |
| 979 | |
| 980 | while (bitcount < format_mask_len[inst->format]) |
| 981 | { |
| 982 | // Descend |
| 983 | if (table[cmdindex].next_digit == NULL) |
| 984 | { |
| 985 | if (VERBOSE>8) LOG("tms9900: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex); |
| 986 | table[cmdindex].next_digit = new lookup_entry[16]; |
| 987 | m_lotables[k++] = table[cmdindex].next_digit; |
| 988 | for (int j=0; j < 16; j++) |
| 989 | { |
| 990 | table[cmdindex].next_digit[j].next_digit = NULL; |
| 991 | table[cmdindex].next_digit[j].entry = NULL; |
| 992 | } |
| 993 | } |
| 994 | else |
| 995 | { |
| 996 | if (VERBOSE>8) LOG("tms9900: found a table at bitcount=%d\n", bitcount); |
| 997 | } |
| 998 | |
| 999 | table = table[cmdindex].next_digit; |
| 1000 | |
| 1001 | bitcount = bitcount+4; |
| 1002 | opcode <<= 4; |
| 1003 | cmdindex = (opcode>>12) & 0x000f; |
| 1004 | if (VERBOSE>8) LOG("tms9900: next index=%x\n", cmdindex); |
| 1005 | } |
| 1006 | |
| 1007 | if (VERBOSE>8) LOG("tms9900: bitcount=%d\n", bitcount); |
| 1008 | // We are at the target level |
| 1009 | // Need to fill in the same entry for all values in the bitcount |
| 1010 | // (if a command needs 10 bits we have to copy it four |
| 1011 | // times for all combinations with 12 bits) |
| 1012 | for (int j=0; j < (1<<(bitcount-format_mask_len[inst->format])); j++) |
| 1013 | { |
| 1014 | if (VERBOSE>8) LOG("tms9900: opcode=%04x at position %d\n", inst->opcode, cmdindex+j); |
| 1015 | table[cmdindex+j].entry = inst; |
| 1016 | } |
| 1017 | |
| 1018 | i++; |
| 1019 | } while (inst->opcode != 0xf000); |
| 1020 | |
| 1021 | m_lotables[k++] = NULL; |
| 1022 | if (VERBOSE>8) LOG("tms9900: Allocated %d tables\n", k); |
| 1023 | } |
| 1024 | |
| 1025 | /* |
| 1026 | Main execution loop |
| 1027 | |
| 1028 | For each invocation of execute_run, a number of loop iterations has been |
| 1029 | calculated before (m_icount). Each loop iteration is one clock cycle. |
| 1030 | The loop must be executed for the number of times that corresponds to the |
| 1031 | time until the next timer event. |
| 1032 | |
| 1033 | In this implementation, each loop iteration also causes the clock line to |
| 1034 | pulse once. External devices may use this pulse to decrement counters |
| 1035 | which control the READY line. |
| 1036 | |
| 1037 | Machine cycles to clock input: |
| 1038 | |
| 1039 | +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ |
| 1040 | | | | | | | | | | | | | | | | | | | clock (1 of 4 phases) |
| 1041 | +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ + |
| 1042 | |-------|-------|-------|-------|---- cycles (2 clock pulses each) |
| 1043 | |
| 1044 | Wait states only have effect for memory operations. They are processed as |
| 1045 | follows: |
| 1046 | |
| 1047 | 1) The CPU sets the address bus for reading. If READY is low, the CPU |
| 1048 | waits for the next clock tick repeatedly until READY is high again. |
| 1049 | When this is the case, the data bus is sampled on the next clock tick |
| 1050 | and the read operation is complete. |
| 1051 | |
| 1052 | As we do not have a split-phase read operation in this emulation |
| 1053 | we actually read the data bus instantly but wait for the READY line to |
| 1054 | be high again. |
| 1055 | |
| 1056 | 2) The CPU sets the address bus for writing. In the same moment, the data |
| 1057 | bus is loaded with the word to be written. On the next clock tick, |
| 1058 | the CPU checks the READY line and waits until it is high. When READY |
| 1059 | is high at a clock tick, the operation is complete on the next clock tick. |
| 1060 | */ |
| 1061 | void tms9900_device::execute_run() |
| 1062 | { |
| 1063 | if (m_reset) service_interrupt(); |
| 1064 | |
| 1065 | if (VERBOSE>6) LOG("tms9900: calling execute_run for %d cycles\n", m_icount); |
| 1066 | do |
| 1067 | { |
| 1068 | // Only when last instruction has completed |
| 1069 | if (m_program == NULL) |
| 1070 | { |
| 1071 | if (m_load_state) |
| 1072 | { |
| 1073 | if (VERBOSE>4) LOG("tms9900: load interrupt\n"); |
| 1074 | service_interrupt(); |
| 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | // Interrupts are serviced when |
| 1079 | // - an interrupt condition is signaled over INTREQ and |
| 1080 | // - the level indicated by IC0-IC3 is lower than the interrupt mask value and |
| 1081 | // - the previous instruction is not an XOP or BLWP |
| 1082 | if (m_irq_state && (m_irq_level <= (ST & 0x000f)) && (m_command != XOP && m_command != BLWP)) |
| 1083 | service_interrupt(); |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | if (m_program == NULL && m_idle_state) |
| 1088 | { |
| 1089 | if (VERBOSE>5) LOG("tms9900: idle state\n"); |
| 1090 | pulse_clock(1); |
| 1091 | } |
| 1092 | else |
| 1093 | { |
| 1094 | // Handle HOLD |
| 1095 | // A HOLD request is signalled through the input line HOLD. |
| 1096 | // The hold state will be entered with the next non-memory access cycle. |
| 1097 | if (m_hold_state && |
| 1098 | (m_program==NULL || |
| 1099 | (m_program[MPC] != IAQ && |
| 1100 | m_program[MPC] != MEMORY_READ && m_program[MPC] != MEMORY_WRITE && |
| 1101 | m_program[MPC] != REG_READ && m_program[MPC] != REG_WRITE))) |
| 1102 | { |
| 1103 | if (VERBOSE>5) LOG("tms9900: hold state\n"); |
| 1104 | if (!m_hold_acknowledged) acknowledge_hold(); |
| 1105 | pulse_clock(1); |
| 1106 | } |
| 1107 | else |
| 1108 | { |
| 1109 | // Normal operation |
| 1110 | if (m_check_ready && m_ready_state == false) |
| 1111 | { |
| 1112 | // We are in a wait state |
| 1113 | set_wait_state(true); |
| 1114 | if (VERBOSE>5) LOG("tms9900: wait state\n"); |
| 1115 | // The clock output should be used to change the state of an outer |
| 1116 | // device which operates the READY line |
| 1117 | pulse_clock(1); |
| 1118 | } |
| 1119 | else |
| 1120 | { |
| 1121 | set_wait_state(false); |
| 1122 | m_check_ready = false; |
| 1123 | |
| 1124 | if (m_program==NULL) m_op = IAQ; |
| 1125 | else |
| 1126 | { |
| 1127 | m_op = m_program[MPC]; |
| 1128 | m_iaq_line(CLEAR_LINE); |
| 1129 | } |
| 1130 | if (VERBOSE>8) LOG("tms9900: MPC = %d, m_op = %d\n", MPC, m_op); |
| 1131 | // Call the operation of the microprogram |
| 1132 | (this->*s_microoperation[m_op])(); |
| 1133 | MPC++; |
| 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | } while (m_icount>0); |
| 1138 | if (VERBOSE>6) LOG("tms9900: cycles expired; will return soon.\n"); |
| 1139 | } |
| 1140 | |
| 1141 | /**************************************************************************/ |
| 1142 | |
| 1143 | /* |
| 1144 | Interrupt input |
| 1145 | */ |
| 1146 | void tms9900_device::execute_set_input(int irqline, int state) |
| 1147 | { |
| 1148 | if (irqline == INPUT_LINE_NMI) |
| 1149 | { |
| 1150 | m_load_state = (state==ASSERT_LINE); |
| 1151 | m_irq_level = -1; |
| 1152 | } |
| 1153 | else |
| 1154 | { |
| 1155 | m_irq_state = (state==ASSERT_LINE); |
| 1156 | if (state==ASSERT_LINE) |
| 1157 | { |
| 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); |
| 1160 | } |
| 1161 | else |
| 1162 | { |
| 1163 | if (VERBOSE>6) LOG("tms9900: cleared interrupt line %d\n", irqline); |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | void tms9900_device::service_interrupt() |
| 1169 | { |
| 1170 | m_program = int_mp; |
| 1171 | MPC = 0; |
| 1172 | m_idle_state = false; |
| 1173 | m_first_cycle = m_icount; |
| 1174 | m_state = 0; |
| 1175 | if (m_reset) |
| 1176 | { |
| 1177 | m_ready_state = true; |
| 1178 | m_load_state = false; |
| 1179 | m_hold_state = false; |
| 1180 | m_hold_acknowledged = false; |
| 1181 | m_wait_state = false; |
| 1182 | IR = 0; |
| 1183 | ST = 0; |
| 1184 | |
| 1185 | m_reset = false; |
| 1186 | m_irq_level = RESET_INT; |
| 1187 | } |
| 1188 | if (VERBOSE>6) LOG("tms9900: ********* triggered an interrupt on level %d\n", m_irq_level); |
| 1189 | } |
| 1190 | |
| 1191 | /* |
| 1192 | Issue a pulse on the clock line. |
| 1193 | */ |
| 1194 | inline void tms9900_device::pulse_clock(int count) |
| 1195 | { |
| 1196 | for (int i=0; i < count; i++) |
| 1197 | { |
| 1198 | m_clock_out_line(ASSERT_LINE); |
| 1199 | m_clock_out_line(CLEAR_LINE); |
| 1200 | m_icount--; // This is the only location where we count down the cycles. |
| 1201 | if (VERBOSE>7) LOG("tms9900: pulse_clock\n"); |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | Enter the hold state. |
| 1207 | */ |
| 1208 | void tms9900_device::set_hold(int state) |
| 1209 | { |
| 1210 | m_hold_state = (state==ASSERT_LINE); |
| 1211 | if (!m_hold_state) |
| 1212 | { |
| 1213 | m_hold_acknowledged = false; |
| 1214 | m_holda_line(CLEAR_LINE); |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | /* |
| 1219 | Acknowledge the HOLD request. |
| 1220 | */ |
| 1221 | inline void tms9900_device::acknowledge_hold() |
| 1222 | { |
| 1223 | m_hold_acknowledged = true; |
| 1224 | m_holda_line(ASSERT_LINE); |
| 1225 | } |
| 1226 | |
| 1227 | /* |
| 1228 | Signal READY to the CPU. When cleared, the CPU enters wait states. |
| 1229 | */ |
| 1230 | void tms9900_device::set_ready(int state) |
| 1231 | { |
| 1232 | m_ready_state = (state==ASSERT_LINE); |
| 1233 | } |
| 1234 | |
| 1235 | void tms9900_device::abort_operation() |
| 1236 | { |
| 1237 | command_completed(); |
| 1238 | } |
| 1239 | |
| 1240 | /* |
| 1241 | Enter or leave the wait state. We only operate the WAIT line when there is a change. |
| 1242 | */ |
| 1243 | inline void tms9900_device::set_wait_state(bool state) |
| 1244 | { |
| 1245 | if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE); |
| 1246 | m_wait_state = state; |
| 1247 | } |
| 1248 | |
| 1249 | /* |
| 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 | Acquire the next word as an instruction. The program counter advances by |
| 1286 | one word. |
| 1287 | */ |
| 1288 | void tms9900_device::decode(UINT16 inst) |
| 1289 | { |
| 1290 | int index = 0; |
| 1291 | lookup_entry* table = m_command_lookup_table; |
| 1292 | UINT16 opcode = inst; |
| 1293 | bool complete = false; |
| 1294 | const tms_instruction *decoded; |
| 1295 | |
| 1296 | m_state = 0; |
| 1297 | IR = inst; |
| 1298 | m_get_destination = false; |
| 1299 | |
| 1300 | while (!complete) |
| 1301 | { |
| 1302 | index = (opcode >> 12) & 0x000f; |
| 1303 | if (VERBOSE>8) LOG("tms9900: Check next hex digit of instruction %x\n", index); |
| 1304 | if (table[index].next_digit != NULL) |
| 1305 | { |
| 1306 | table = table[index].next_digit; |
| 1307 | opcode = opcode << 4; |
| 1308 | } |
| 1309 | else complete = true; |
| 1310 | } |
| 1311 | decoded = table[index].entry; |
| 1312 | if (decoded == NULL) |
| 1313 | { |
| 1314 | // not found |
| 1315 | if (VERBOSE>0) LOG("tms9900: Illegal opcode %04x\n", inst); |
| 1316 | IR = 0; |
| 1317 | // 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 | m_program = NULL; |
| 1320 | } |
| 1321 | else |
| 1322 | { |
| 1323 | m_program = decoded->prog; |
| 1324 | MPC = -1; |
| 1325 | 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 | } |
| 1328 | } |
| 1329 | |
| 1330 | inline bool tms9900_device::byte_operation() |
| 1331 | { |
| 1332 | return (IR & 0x1000)!=0; |
| 1333 | } |
| 1334 | |
| 1335 | void tms9900_device::acquire_instruction() |
| 1336 | { |
| 1337 | m_iaq_line(ASSERT_LINE); |
| 1338 | m_address = PC; |
| 1339 | m_first_cycle = m_icount; |
| 1340 | mem_read(); |
| 1341 | decode(m_current_value); |
| 1342 | if (VERBOSE>3) LOG("tms9900: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC); |
| 1343 | debugger_instruction_hook(*this, PC); |
| 1344 | PC = (PC + 2) & 0xfffe; |
| 1345 | // IAQ will be cleared in the main loop |
| 1346 | } |
| 1347 | |
| 1348 | void tms9900_device::mem_read() |
| 1349 | { |
| 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); |
| 1352 | } |
| 1353 | |
| 1354 | void tms9900_device::mem_write() |
| 1355 | { |
| 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); |
| 1358 | } |
| 1359 | |
| 1360 | void tms9900_device::register_read() |
| 1361 | { |
| 1362 | // Need to set m_address for F1/F3 (we don't know what the data_derive did) |
| 1363 | 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); |
| 1366 | } |
| 1367 | |
| 1368 | void tms9900_device::register_write() |
| 1369 | { |
| 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); |
| 1372 | } |
| 1373 | |
| 1374 | /* |
| 1375 | CRU support code |
| 1376 | |
| 1377 | The CRU bus is a 1-bit-wide I/O bus. The CPU can read or write bits at random address. |
| 1378 | Special instructions are dedicated to reading and writing one or several consecutive bits. |
| 1379 | |
| 1380 | The CRU uses the same address bus as the normal memory access. For writing, |
| 1381 | the CRUCLK line is pulsed, but not for reading where CRUCLK stays cleared. |
| 1382 | This means that each normal memory access also causes read accesses on the |
| 1383 | CRU side. The /MEMEN line may be used to distinguish the kinds of accesses |
| 1384 | as it stays cleared during CRU operations. |
| 1385 | |
| 1386 | We do not emulate this here as it seems there are no real applications of |
| 1387 | this side effect. Real designs must ensure that CRU read operations are |
| 1388 | idempotent (i.e. they must not change the state of the queried device). |
| 1389 | |
| 1390 | Read returns the number of consecutive CRU bits, with increasing CRU address |
| 1391 | from the least significant to the most significant bit; right-aligned |
| 1392 | |
| 1393 | There seems to be no handling of wait states during CRU operations on the |
| 1394 | TMS9900. The TMS9995, in contrast, respects wait states during the transmission |
| 1395 | of each single bit. |
| 1396 | |
| 1397 | Usage of this method: |
| 1398 | CRU write: First bit is at rightmost position of m_value. |
| 1399 | */ |
| 1400 | |
| 1401 | |
| 1402 | #define CRUREADMASK 0x01ff |
| 1403 | #define CRUWRITEMASK 0x0fff |
| 1404 | |
| 1405 | void tms9900_device::cru_operation() |
| 1406 | { |
| 1407 | int value, value1; |
| 1408 | int offset, location; |
| 1409 | |
| 1410 | if (m_cru_output) |
| 1411 | { |
| 1412 | location = (m_cru_address >> 1)& CRUWRITEMASK; |
| 1413 | value = m_value; |
| 1414 | |
| 1415 | // Write m_count bits from cru_address |
| 1416 | for (int i=0; i < m_count; i++) |
| 1417 | { |
| 1418 | m_cru->write_byte(location, (value & 0x01)); |
| 1419 | value >>= 1; |
| 1420 | location = (location + 1) & CRUWRITEMASK; |
| 1421 | pulse_clock(2); |
| 1422 | } |
| 1423 | } |
| 1424 | else |
| 1425 | { |
| 1426 | location = (m_cru_address >> 4) & CRUREADMASK; |
| 1427 | offset = (m_cru_address>>1) & 0x07; |
| 1428 | |
| 1429 | // Read 8 bits (containing the desired bits) |
| 1430 | value = m_cru->read_byte(location); |
| 1431 | |
| 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); |
| 1438 | |
| 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 | } |
| 1447 | |
| 1448 | // On each machine cycle (2 clocks) only one CRU bit is transmitted |
| 1449 | pulse_clock(m_count<<1); |
| 1450 | |
| 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)); |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | void tms9900_device::return_from_subprogram() |
| 1460 | { |
| 1461 | // Return from data derivation |
| 1462 | // The result should be in m_current_value |
| 1463 | // and the address in m_address |
| 1464 | m_program = m_caller; |
| 1465 | MPC = m_caller_MPC; // will be increased on return |
| 1466 | } |
| 1467 | |
| 1468 | void tms9900_device::command_completed() |
| 1469 | { |
| 1470 | // Pseudo state at the end of the current instruction cycle sequence |
| 1471 | if (VERBOSE>7) |
| 1472 | { |
| 1473 | int cycles = m_first_cycle - m_icount; |
| 1474 | // 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); |
| 1476 | } |
| 1477 | m_program = NULL; |
| 1478 | } |
| 1479 | |
| 1480 | /* |
| 1481 | This is a switch to a subprogram; there is only one, the data |
| 1482 | derivation. In terms of cycles, it does not take any time; execution |
| 1483 | continues with the first instruction of the subprogram. |
| 1484 | */ |
| 1485 | void tms9900_device::data_derivation_subprogram() |
| 1486 | { |
| 1487 | UINT16 ircopy = IR; |
| 1488 | |
| 1489 | // Save the return program and position |
| 1490 | m_caller = m_program; |
| 1491 | m_caller_MPC = MPC; |
| 1492 | |
| 1493 | // Source or destination argument? |
| 1494 | if (m_get_destination) ircopy >>= 6; |
| 1495 | |
| 1496 | m_regnumber = ircopy & 0x000f; |
| 1497 | |
| 1498 | m_program = (UINT8*)data_derivation; |
| 1499 | MPC = ircopy & 0x0030; |
| 1500 | |
| 1501 | if (((MPC == 0x0020) && (m_regnumber != 0)) // indexed |
| 1502 | || ((MPC == 0x0030) && ((IR & 0x1000)!=0))) // byte flag |
| 1503 | { |
| 1504 | MPC += 8; // the second option |
| 1505 | } |
| 1506 | m_get_destination = true; // when we call this the second time before END it's the destination |
| 1507 | MPC--; // will be increased on return |
| 1508 | } |
| 1509 | |
| 1510 | |
| 1511 | /************************************************************************** |
| 1512 | Status bit operations |
| 1513 | **************************************************************************/ |
| 1514 | |
| 1515 | inline void tms9900_device::set_status_bit(int bit, bool state) |
| 1516 | { |
| 1517 | if (state) ST |= bit; |
| 1518 | else ST &= ~bit; |
| 1519 | } |
| 1520 | |
| 1521 | void tms9900_device::set_status_parity(UINT8 value) |
| 1522 | { |
| 1523 | int count = 0; |
| 1524 | for (int i=0; i < 8; i++) |
| 1525 | { |
| 1526 | if ((value & 0x80)!=0) count++; |
| 1527 | value <<= 1; |
| 1528 | } |
| 1529 | set_status_bit(ST_OP, (count & 1)!=0); |
| 1530 | } |
| 1531 | |
| 1532 | inline void tms9900_device::compare_and_set_lae(UINT16 value1, UINT16 value2) |
| 1533 | { |
| 1534 | set_status_bit(ST_EQ, value1 == value2); |
| 1535 | set_status_bit(ST_LH, value1 > value2); |
| 1536 | 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); |
| 1538 | } |
| 1539 | |
| 1540 | /************************************************************************** |
| 1541 | ALU operations |
| 1542 | **************************************************************************/ |
| 1543 | |
| 1544 | void tms9900_device::alu_nop() |
| 1545 | { |
| 1546 | // Do nothing (or nothing that is externally visible) |
| 1547 | pulse_clock(2); |
| 1548 | return; |
| 1549 | } |
| 1550 | |
| 1551 | void tms9900_device::alu_source() |
| 1552 | { |
| 1553 | // Copy the current value into the source data register |
| 1554 | m_source_even = ((m_address & 1)==0); |
| 1555 | m_source_value = m_current_value; |
| 1556 | m_source_address = m_address; |
| 1557 | pulse_clock(2); |
| 1558 | } |
| 1559 | |
| 1560 | void tms9900_device::alu_clear() |
| 1561 | { |
| 1562 | // Clears the register contents |
| 1563 | m_register_contents = 0; |
| 1564 | pulse_clock(2); |
| 1565 | } |
| 1566 | |
| 1567 | void tms9900_device::alu_setaddr() |
| 1568 | { |
| 1569 | // Load the current value into the address register |
| 1570 | m_address = m_current_value; |
| 1571 | pulse_clock(2); |
| 1572 | } |
| 1573 | |
| 1574 | void tms9900_device::alu_addone() |
| 1575 | { |
| 1576 | m_current_value++; |
| 1577 | pulse_clock(2); |
| 1578 | } |
| 1579 | |
| 1580 | void tms9900_device::alu_setaddr_addone() |
| 1581 | { |
| 1582 | // Set the address register and increase the recent value |
| 1583 | m_address = m_current_value; |
| 1584 | m_current_value++; |
| 1585 | pulse_clock(2); |
| 1586 | } |
| 1587 | |
| 1588 | void tms9900_device::alu_pcaddr_advance() |
| 1589 | { |
| 1590 | // Set PC as new read address, increase by 2 |
| 1591 | m_address = PC; |
| 1592 | PC = (PC+2)&0xfffe; |
| 1593 | pulse_clock(2); |
| 1594 | } |
| 1595 | |
| 1596 | void tms9900_device::alu_add_register() |
| 1597 | { |
| 1598 | // Add the register contents to the current value and set as address |
| 1599 | m_address = m_current_value + m_register_contents; |
| 1600 | pulse_clock(2); |
| 1601 | } |
| 1602 | |
| 1603 | void tms9900_device::alu_imm() |
| 1604 | { |
| 1605 | if (VERBOSE>7) LOG("tms9900: Immediate operand, reading from position %04x\n", PC); |
| 1606 | m_address = PC; |
| 1607 | PC = (PC + 2) & 0xfffe; |
| 1608 | pulse_clock(2); |
| 1609 | } |
| 1610 | |
| 1611 | void tms9900_device::alu_reg() |
| 1612 | { |
| 1613 | m_regnumber = IR & 0x000f; |
| 1614 | pulse_clock(2); |
| 1615 | } |
| 1616 | |
| 1617 | void tms9900_device::alu_f1() |
| 1618 | { |
| 1619 | UINT32 dest_new = 0; |
| 1620 | |
| 1621 | // Save the destination value |
| 1622 | UINT16 prev_dest_value = m_current_value; |
| 1623 | |
| 1624 | m_destination_even = ((m_address & 1)==0); // this is the destination address; the source address has already been saved |
| 1625 | bool byteop = byte_operation(); |
| 1626 | |
| 1627 | if (byteop) |
| 1628 | { |
| 1629 | if (!m_destination_even) m_current_value <<= 8; |
| 1630 | if (!m_source_even) m_source_value <<= 8; |
| 1631 | // We have to strip away the low byte, or byte operations may fail |
| 1632 | // e.g. 0x10ff + 0x0101 = 0x1200 |
| 1633 | // or 0x2000 - 0x0101 = 0x1eff |
| 1634 | m_source_value &= 0xff00; |
| 1635 | m_current_value &= 0xff00; |
| 1636 | } |
| 1637 | |
| 1638 | switch (m_command) |
| 1639 | { |
| 1640 | case A: |
| 1641 | case AB: |
| 1642 | // Add the contents of the source data to the destination data |
| 1643 | // May exceed 0xffff (for carry check) |
| 1644 | dest_new = m_current_value + m_source_value; |
| 1645 | |
| 1646 | // 1000 + e000 = f000 (L) |
| 1647 | // c000 + c000 = 8000 (LC) |
| 1648 | // 7000 + 4000 = b000 (LO) |
| 1649 | // 2000 + f000 = 1000 (LAC) |
| 1650 | // c000 + b000 = 7000 (LACO) |
| 1651 | // 2000 + e000 = 0000 (EC) |
| 1652 | // 8000 + 8000 = 0000 (ECO) |
| 1653 | |
| 1654 | // When adding, a carry occurs when we exceed the 0xffff value. |
| 1655 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 1656 | // If the result has a sign bit that is different from both arguments, we have an overflow |
| 1657 | // (i.e. getting a negative value from two positive values and vice versa) |
| 1658 | set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_source_value) & 0x8000)!=0); |
| 1659 | break; |
| 1660 | |
| 1661 | case S: |
| 1662 | case SB: |
| 1663 | // Subtract the contents of the source data from the destination data |
| 1664 | dest_new = m_current_value + ((~m_source_value) & 0xffff) + 1; |
| 1665 | // LAECO(P) |
| 1666 | // 8000 - 8000 = 0000 (EC) |
| 1667 | // 2000 - 8000 = a000 (LO) |
| 1668 | // 8000 - 2000 = 6000 (LACO) |
| 1669 | // 2000 - 1000 = 1000 (LAC) |
| 1670 | // 1000 - 2000 = f000 (L) |
| 1671 | // 1000 - 1000 = 0000 (EC) |
| 1672 | // 1000 - f000 = 2000 (LA) |
| 1673 | // f000 - 2000 = d000 (LC) |
| 1674 | |
| 1675 | // Subtraction means adding the 2s complement, so the carry bit |
| 1676 | // is set whenever adding the 2s complement exceeds ffff |
| 1677 | // In fact the CPU adds the one's complement, then adds a one. This |
| 1678 | // explains why subtracting 0 sets the carry bit. |
| 1679 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 1680 | |
| 1681 | // If the arguments have different sign bits and the result has a |
| 1682 | // sign bit different from the destination value, we have an overflow |
| 1683 | // e.g. value1 = 0x7fff, value2 = 0xffff; value1-value2 = 0x8000 |
| 1684 | // or value1 = 0x8000, value2 = 0x0001; value1-value2 = 0x7fff |
| 1685 | // value1 is the destination value |
| 1686 | set_status_bit(ST_OV, (m_current_value ^ m_source_value) & (m_current_value ^ dest_new) & 0x8000); |
| 1687 | break; |
| 1688 | |
| 1689 | case SOC: |
| 1690 | case SOCB: |
| 1691 | // OR the contents of the source data on the destination data |
| 1692 | dest_new = m_current_value | m_source_value; |
| 1693 | break; |
| 1694 | |
| 1695 | case SZC: |
| 1696 | case SZCB: |
| 1697 | // AND the one's complement of the contents of the source data on the destination data |
| 1698 | dest_new = m_current_value & ~m_source_value; |
| 1699 | break; |
| 1700 | |
| 1701 | case MOV: |
| 1702 | case MOVB: |
| 1703 | // Copy the source data to the destination data |
| 1704 | dest_new = m_source_value; |
| 1705 | break; |
| 1706 | } |
| 1707 | |
| 1708 | if (byteop) |
| 1709 | { |
| 1710 | set_status_parity((UINT8)(dest_new>>8)); |
| 1711 | |
| 1712 | // destnew is the new value to be written (high byte); needs to be |
| 1713 | // merged with the existing word |
| 1714 | if (m_destination_even) |
| 1715 | m_current_value = (prev_dest_value & 0x00ff) | (dest_new & 0xff00); |
| 1716 | else |
| 1717 | m_current_value = (prev_dest_value & 0xff00) | ((dest_new >> 8) & 0x00ff); |
| 1718 | compare_and_set_lae((UINT16)(dest_new & 0xff00), 0); |
| 1719 | } |
| 1720 | else |
| 1721 | { |
| 1722 | m_current_value = (UINT16)(dest_new & 0xffff); |
| 1723 | compare_and_set_lae((UINT16)(dest_new & 0xffff), 0); |
| 1724 | } |
| 1725 | |
| 1726 | pulse_clock(2); |
| 1727 | } |
| 1728 | |
| 1729 | void tms9900_device::alu_comp() |
| 1730 | { |
| 1731 | m_destination_even = ((m_address & 1)==0); // this is the destination address; the source address has already been saved |
| 1732 | if (byte_operation()) |
| 1733 | { |
| 1734 | if (!m_destination_even) m_current_value <<= 8; |
| 1735 | if (!m_source_even) m_source_value <<= 8; |
| 1736 | set_status_parity((UINT8)(m_source_value>>8)); |
| 1737 | compare_and_set_lae(m_source_value & 0xff00, m_current_value & 0xff00); |
| 1738 | } |
| 1739 | else |
| 1740 | compare_and_set_lae(m_source_value, m_current_value); |
| 1741 | |
| 1742 | pulse_clock(2); |
| 1743 | } |
| 1744 | |
| 1745 | void tms9900_device::alu_f3() |
| 1746 | { |
| 1747 | if (m_state==0) |
| 1748 | { |
| 1749 | m_regnumber = (IR >> 6) & 0x000f; |
| 1750 | 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) |
| 1756 | { |
| 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; |
| 1767 | } |
| 1768 | } |
| 1769 | if (VERBOSE>7) LOG("tms9900: ST = %04x (log comp)\n", ST); |
| 1770 | |
| 1771 | m_state++; |
| 1772 | pulse_clock(2); |
| 1773 | } |
| 1774 | |
| 1775 | void tms9900_device::alu_multiply() |
| 1776 | { |
| 1777 | switch (m_state) |
| 1778 | { |
| 1779 | case 0: // After data derivation |
| 1780 | m_source_value = m_current_value; |
| 1781 | m_regnumber = (IR >> 6)&0x000f; |
| 1782 | break; |
| 1783 | 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 |
| 1788 | pulse_clock(34); // add 36 clock cycles (18 machine cycles); last one in main loop |
| 1789 | break; |
| 1790 | 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; |
| 1793 | break; |
| 1794 | } |
| 1795 | pulse_clock(2); |
| 1796 | m_state++; |
| 1797 | } |
| 1798 | |
| 1799 | void tms9900_device::alu_divide() |
| 1800 | { |
| 1801 | // Format is DIV Divisor,REG(dividend) |
| 1802 | UINT32 value1; |
| 1803 | |
| 1804 | switch (m_state) |
| 1805 | { |
| 1806 | case 0: |
| 1807 | m_source_value = m_current_value; // store divisor |
| 1808 | m_regnumber = (IR >> 6) & 0x000f; |
| 1809 | break; |
| 1810 | case 1: |
| 1811 | // We have an overflow when the quotient cannot be stored in 16 bits |
| 1812 | // This is the case when the dividend / divisor >= 0x10000, |
| 1813 | // or equivalently, dividend / 0x10000 >= divisor |
| 1814 | if (m_register_contents >= m_source_value) |
| 1815 | { |
| 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 |
| 1819 | } |
| 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 | } |
| 1826 | break; |
| 1827 | case 2: |
| 1828 | // 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); |
| 1834 | |
| 1835 | // The number of ALU cycles depends on the number of steps in |
| 1836 | // the division algorithm. The number of cycles is between 32 and |
| 1837 | // 48 (*2 for clock cycles) |
| 1838 | // As I don't have a description of the actual algorithm, I'll use |
| 1839 | // the following heuristic: We use 32 ALU cycles in general, then |
| 1840 | // we need as many cycles as it takes to |
| 1841 | // shift away the dividend. Thus, bigger dividends need more cycles. |
| 1842 | pulse_clock(62); // one pulse is at the start, one at the end |
| 1843 | value1 = m_register_contents & 0xffff; |
| 1844 | while (value1 != 0) |
| 1845 | { |
| 1846 | value1 = (value1 >> 1) & 0xffff; |
| 1847 | pulse_clock(2); |
| 1848 | } |
| 1849 | // We still have m_regnumber; this is where m_current_value will go to |
| 1850 | break; |
| 1851 | 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); |
| 1856 | break; |
| 1857 | } |
| 1858 | pulse_clock(2); |
| 1859 | m_state++; |
| 1860 | } |
| 1861 | |
| 1862 | void tms9900_device::alu_xop() |
| 1863 | { |
| 1864 | switch (m_state) |
| 1865 | { |
| 1866 | case 0: |
| 1867 | // We have the effective address of the source operand in m_address |
| 1868 | m_source_address = m_address; |
| 1869 | // Now we take the XOP number from the instruction register |
| 1870 | // and calculate the vector location |
| 1871 | // [0010 11xx xx tt SSSS] shift 6 right, then *4 => shift 4 right |
| 1872 | m_address = 0x0040 + ((IR >> 4) & 0x003c); |
| 1873 | break; |
| 1874 | case 1: |
| 1875 | 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 |
| 1879 | break; |
| 1880 | case 2: |
| 1881 | m_current_value = ST; |
| 1882 | m_regnumber = 15; |
| 1883 | break; |
| 1884 | case 3: |
| 1885 | m_current_value = PC; |
| 1886 | m_regnumber = 14; |
| 1887 | break; |
| 1888 | case 4: |
| 1889 | m_current_value = WP; |
| 1890 | m_regnumber = 13; |
| 1891 | break; |
| 1892 | case 5: |
| 1893 | m_address = 0x0042 + ((IR >> 4) & 0x003c); // location of new PC |
| 1894 | ST |= ST_X; |
| 1895 | break; |
| 1896 | case 6: |
| 1897 | PC = m_current_value; |
| 1898 | break; |
| 1899 | } |
| 1900 | pulse_clock(2); |
| 1901 | m_state++; |
| 1902 | } |
| 1903 | |
| 1904 | void tms9900_device::alu_clr_swpb() |
| 1905 | { |
| 1906 | UINT32 dest_new = 0; |
| 1907 | UINT32 src_val = m_current_value & 0x0000ffff; |
| 1908 | UINT16 sign = 0; |
| 1909 | |
| 1910 | bool setstatus = true; |
| 1911 | bool check_ov = true; |
| 1912 | |
| 1913 | switch (m_command) |
| 1914 | { |
| 1915 | case CLR: |
| 1916 | // no status bits |
| 1917 | m_current_value = 0x0000; |
| 1918 | setstatus = false; |
| 1919 | break; |
| 1920 | case SETO: |
| 1921 | // no status bits |
| 1922 | m_current_value = 0xffff; |
| 1923 | setstatus = false; |
| 1924 | break; |
| 1925 | case INV: |
| 1926 | // LAE |
| 1927 | dest_new = ~src_val & 0xffff; |
| 1928 | check_ov = false; |
| 1929 | break; |
| 1930 | case NEG: |
| 1931 | // LAEO |
| 1932 | // Overflow occurs for value=0x8000 |
| 1933 | dest_new = ((~src_val) & 0x0000ffff) + 1; |
| 1934 | check_ov = false; |
| 1935 | set_status_bit(ST_OV, src_val == 0x8000); |
| 1936 | break; |
| 1937 | case INC: |
| 1938 | // LAECO |
| 1939 | // Overflow for result value = 0x8000 |
| 1940 | // Carry for result value = 0x0000 |
| 1941 | dest_new = src_val + 1; |
| 1942 | break; |
| 1943 | case INCT: |
| 1944 | // LAECO |
| 1945 | // Overflow for result value = 0x8000 / 0x8001 |
| 1946 | // Carry for result value = 0x0000 / 0x0001 |
| 1947 | dest_new = src_val + 2; |
| 1948 | break; |
| 1949 | case DEC: |
| 1950 | // LAECO |
| 1951 | // Carry for result value != 0xffff |
| 1952 | // Overflow for result value == 0x7fff |
| 1953 | dest_new = src_val + 0xffff; |
| 1954 | sign = 0x8000; |
| 1955 | break; |
| 1956 | case DECT: |
| 1957 | // Carry for result value != 0xffff / 0xfffe |
| 1958 | // Overflow for result value = 0x7fff / 0x7ffe |
| 1959 | dest_new = src_val + 0xfffe; |
| 1960 | sign = 0x8000; |
| 1961 | break; |
| 1962 | case SWPB: |
| 1963 | m_current_value = ((m_current_value << 8) | (m_current_value >> 8)) & 0xffff; |
| 1964 | setstatus = false; |
| 1965 | break; |
| 1966 | } |
| 1967 | |
| 1968 | if (setstatus) |
| 1969 | { |
| 1970 | if (check_ov) set_status_bit(ST_OV, ((src_val & 0x8000)!=sign) && ((dest_new & 0x8000)==sign)); |
| 1971 | set_status_bit(ST_C, (dest_new & 0x10000) != 0); |
| 1972 | m_current_value = dest_new & 0xffff; |
| 1973 | compare_and_set_lae(m_current_value, 0); |
| 1974 | } |
| 1975 | |
| 1976 | pulse_clock(2); |
| 1977 | // No states here |
| 1978 | } |
| 1979 | |
| 1980 | void tms9900_device::alu_abs() |
| 1981 | { |
| 1982 | // LAECO (from original word!) |
| 1983 | // O if >8000 |
| 1984 | // C is alwas reset |
| 1985 | set_status_bit(ST_OV, m_current_value == 0x8000); |
| 1986 | set_status_bit(ST_C, false); |
| 1987 | compare_and_set_lae(m_current_value, 0); |
| 1988 | |
| 1989 | if ((m_current_value & 0x8000)!=0) |
| 1990 | { |
| 1991 | m_current_value = (-m_current_value) & 0xffff; |
| 1992 | pulse_clock(2); // If ABS is performed it takes one machine cycle more |
| 1993 | } |
| 1994 | else |
| 1995 | { |
| 1996 | MPC++; // skips over the next micro operation (MEMORY_WRITE) |
| 1997 | } |
| 1998 | pulse_clock(2); |
| 1999 | } |
| 2000 | |
| 2001 | void tms9900_device::alu_x() |
| 2002 | { |
| 2003 | if (VERBOSE>7) LOG("tms9900: Substituting current command by %04x\n", m_current_value); |
| 2004 | decode(m_current_value); |
| 2005 | pulse_clock(2); |
| 2006 | } |
| 2007 | |
| 2008 | /* |
| 2009 | Also used by other microprograms |
| 2010 | */ |
| 2011 | void tms9900_device::alu_b() |
| 2012 | { |
| 2013 | // no status bits |
| 2014 | // Although we got the contents of the source data, we do not use them |
| 2015 | // but directly branch there. That is, we are only interested in the |
| 2016 | // address of the source data. |
| 2017 | // If we have a B *R5 and R5 contains the value 0xa000, the CPU actually |
| 2018 | // retrieves the value at 0xa000, but in fact it will load the PC |
| 2019 | // with the address 0xa000 |
| 2020 | PC = m_address; |
| 2021 | if (VERBOSE>7) LOG("tms9900: Set new PC = %04x\n", PC); |
| 2022 | pulse_clock(2); |
| 2023 | } |
| 2024 | |
| 2025 | void tms9900_device::alu_bl() |
| 2026 | { |
| 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 | switch (m_state) |
| 2040 | { |
| 2041 | 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) |
| 2045 | m_current_value = ST; // get status register |
| 2046 | m_regnumber = 15; |
| 2047 | break; |
| 2048 | case 1: |
| 2049 | m_current_value = PC; // get program counter |
| 2050 | m_regnumber = 14; |
| 2051 | break; |
| 2052 | case 2: |
| 2053 | m_current_value = m_value; // retrieve the old WP |
| 2054 | m_regnumber = 13; |
| 2055 | break; |
| 2056 | case 3: |
| 2057 | m_address = (m_source_address + 2)&0xffff; // point to PC component of branch vector |
| 2058 | break; |
| 2059 | case 4: |
| 2060 | PC = m_current_value; |
| 2061 | break; |
| 2062 | } |
| 2063 | pulse_clock(2); |
| 2064 | m_state++; |
| 2065 | } |
| 2066 | |
| 2067 | void tms9900_device::alu_ldcr() |
| 2068 | { |
| 2069 | UINT16 value; |
| 2070 | |
| 2071 | // Spec: "If the source operand address is odd, the address is truncated |
| 2072 | // to an even address prior to data transfer." |
| 2073 | // (Editor/Assembler, page 151) |
| 2074 | // This refers to transfers with more than 8 bits. In this case, for |
| 2075 | // LDCR the first bit is taken from the least significant bit of the |
| 2076 | // source word. If the address is odd (e.g. 0x1001), it is |
| 2077 | // treated as 0x1000, that is, truncated to an even address. |
| 2078 | // For transfers with 1-8 bits, the first bit is the least significant |
| 2079 | // bit of the source byte (any address). |
| 2080 | |
| 2081 | if (m_state == 0) |
| 2082 | { |
| 2083 | m_regnumber = 12; |
| 2084 | } |
| 2085 | else |
| 2086 | { |
| 2087 | value = m_source_value; // copied by ALU_SOURCE |
| 2088 | m_count = (IR >> 6) & 0x000f; |
| 2089 | if (m_count == 0) m_count = 16; |
| 2090 | if (m_count <= 8) |
| 2091 | { |
| 2092 | if (m_source_even) value>>=8; |
| 2093 | set_status_parity((UINT8)(value & 0xff)); |
| 2094 | compare_and_set_lae(value<<8, 0); |
| 2095 | } |
| 2096 | else |
| 2097 | { |
| 2098 | compare_and_set_lae(value, 0); |
| 2099 | } |
| 2100 | m_cru_output = true; |
| 2101 | m_cru_address = m_register_contents; |
| 2102 | 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); |
| 2104 | } |
| 2105 | m_state++; |
| 2106 | pulse_clock(2); |
| 2107 | } |
| 2108 | |
| 2109 | void tms9900_device::alu_stcr() |
| 2110 | { |
| 2111 | UINT16 value; |
| 2112 | |
| 2113 | // For STCR transfers with more than 8 bits, the first CRU bit is |
| 2114 | // always put into the least significant bit of the destination word. |
| 2115 | // If the address is odd (e.g. 0x1001), it is treated as 0x1000, that is, |
| 2116 | // truncated to an even boundary. |
| 2117 | // For transfers with 1-8 bits, the destination address is handled as |
| 2118 | // in MOVB operations, i.e. the other byte of the word is kept unchanged. |
| 2119 | |
| 2120 | switch (m_state) |
| 2121 | { |
| 2122 | case 0: // After getting the destination operand and saving the address/value |
| 2123 | m_regnumber = 12; |
| 2124 | break; |
| 2125 | case 1: // After getting R12 |
| 2126 | m_cru_output = false; |
| 2127 | m_cru_address = m_register_contents; |
| 2128 | m_count = (IR >> 6) & 0x000f; |
| 2129 | if (m_count == 0) m_count = 16; |
| 2130 | break; |
| 2131 | case 2: // After the cru operation; value starts at LSB of m_value |
| 2132 | value = m_value & 0xffff; |
| 2133 | if (m_count < 9) |
| 2134 | { |
| 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); |
| 2136 | set_status_parity((UINT8)(value & 0xff)); |
| 2137 | compare_and_set_lae(value<<8, 0); |
| 2138 | if (m_source_even) |
| 2139 | m_current_value = (m_source_value & 0x00ff) | (value<<8); |
| 2140 | else |
| 2141 | m_current_value = (m_source_value & 0xff00) | (value & 0xff); |
| 2142 | |
| 2143 | pulse_clock(2*(5 + (8-m_count))); |
| 2144 | } |
| 2145 | else |
| 2146 | { |
| 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); |
| 2148 | m_current_value = value; |
| 2149 | compare_and_set_lae(value, 0); |
| 2150 | pulse_clock(2*(5 + (16-m_count))); |
| 2151 | } |
| 2152 | m_address = m_source_address; |
| 2153 | break; |
| 2154 | } |
| 2155 | |
| 2156 | m_state++; |
| 2157 | pulse_clock(2); |
| 2158 | } |
| 2159 | |
| 2160 | void tms9900_device::alu_sbz_sbo() |
| 2161 | { |
| 2162 | INT8 displacement; |
| 2163 | if (m_state==0) |
| 2164 | { |
| 2165 | m_regnumber = 12; |
| 2166 | } |
| 2167 | else |
| 2168 | { |
| 2169 | m_cru_output = true; |
| 2170 | displacement = (IR & 0xff); |
| 2171 | m_cru_address = m_register_contents + (displacement<<1); |
| 2172 | m_count = 1; |
| 2173 | m_value = (m_command == SBO)? 1 : 0; |
| 2174 | pulse_clock(2); |
| 2175 | } |
| 2176 | m_state++; |
| 2177 | pulse_clock(2); |
| 2178 | } |
| 2179 | |
| 2180 | void tms9900_device::alu_tb() |
| 2181 | { |
| 2182 | INT8 displacement; |
| 2183 | switch (m_state) |
| 2184 | { |
| 2185 | case 0: |
| 2186 | m_regnumber = 12; |
| 2187 | break; |
| 2188 | case 1: |
| 2189 | m_cru_output = false; |
| 2190 | displacement = (IR & 0xff); |
| 2191 | m_cru_address = m_register_contents + (displacement<<1); |
| 2192 | m_count = 1; |
| 2193 | break; |
| 2194 | case 2: |
| 2195 | set_status_bit(ST_EQ, m_value!=0); |
| 2196 | if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST); |
| 2197 | break; |
| 2198 | } |
| 2199 | m_state++; |
| 2200 | pulse_clock(2); |
| 2201 | } |
| 2202 | |
| 2203 | void tms9900_device::alu_jmp() |
| 2204 | { |
| 2205 | INT8 displacement; |
| 2206 | bool cond = false; |
| 2207 | |
| 2208 | if (m_state==0) |
| 2209 | { |
| 2210 | switch (m_command) |
| 2211 | { |
| 2212 | case JMP: |
| 2213 | cond = true; |
| 2214 | break; |
| 2215 | case JLT: // LAECOP == x00xxx |
| 2216 | cond = ((ST & (ST_AGT | ST_EQ))==0); |
| 2217 | break; |
| 2218 | case JLE: // LAECOP == 0xxxxx |
| 2219 | cond = ((ST & ST_LH)==0); |
| 2220 | break; |
| 2221 | case JEQ: // LAECOP == xx1xxx |
| 2222 | cond = ((ST & ST_EQ)!=0); |
| 2223 | break; |
| 2224 | case JHE: // LAECOP == 1x0xxx, 0x1xxx |
| 2225 | cond = ((ST & (ST_LH | ST_EQ)) != 0); |
| 2226 | break; |
| 2227 | case JGT: // LAECOP == x1xxxx |
| 2228 | cond = ((ST & ST_AGT)!=0); |
| 2229 | break; |
| 2230 | case JNE: // LAECOP == xx0xxx |
| 2231 | cond = ((ST & ST_EQ)==0); |
| 2232 | break; |
| 2233 | case JNC: // LAECOP == xxx0xx |
| 2234 | cond = ((ST & ST_C)==0); |
| 2235 | break; |
| 2236 | case JOC: // LAECOP == xxx1xx |
| 2237 | cond = ((ST & ST_C)!=0); |
| 2238 | break; |
| 2239 | case JNO: // LAECOP == xxxx0x |
| 2240 | cond = ((ST & ST_OV)==0); |
| 2241 | break; |
| 2242 | case JL: // LAECOP == 0x0xxx |
| 2243 | cond = ((ST & (ST_LH | ST_EQ)) == 0); |
| 2244 | break; |
| 2245 | case JH: // LAECOP == 1xxxxx |
| 2246 | cond = ((ST & ST_LH)!=0); |
| 2247 | break; |
| 2248 | case JOP: // LAECOP == xxxxx1 |
| 2249 | cond = ((ST & ST_OP)!=0); |
| 2250 | break; |
| 2251 | } |
| 2252 | pulse_clock(2); |
| 2253 | if (!cond) |
| 2254 | { |
| 2255 | if (VERBOSE>7) LOG("tms9900: Jump condition false\n"); |
| 2256 | MPC+=1; // skip next ALU call |
| 2257 | } |
| 2258 | else |
| 2259 | if (VERBOSE>7) LOG("tms9900: Jump condition true\n"); |
| 2260 | } |
| 2261 | else |
| 2262 | { |
| 2263 | displacement = (IR & 0xff); |
| 2264 | PC = PC + (displacement<<1); |
| 2265 | pulse_clock(2); |
| 2266 | } |
| 2267 | m_state++; |
| 2268 | } |
| 2269 | |
| 2270 | void tms9900_device::alu_shift() |
| 2271 | { |
| 2272 | bool carry = false; |
| 2273 | bool overflow = false; |
| 2274 | UINT16 sign = 0; |
| 2275 | UINT32 value; |
| 2276 | |
| 2277 | switch (m_state) |
| 2278 | { |
| 2279 | case 0: |
| 2280 | m_regnumber = (IR & 0x000f); |
| 2281 | break; |
| 2282 | 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; |
| 2287 | break; |
| 2288 | case 2: |
| 2289 | value = m_source_value & 0xffff; |
| 2290 | |
| 2291 | if (m_count==0) m_count = m_register_contents & 0x000f; |
| 2292 | if (m_count==0) m_count = 16; |
| 2293 | |
| 2294 | // we are re-implementing the shift operations because we have to pulse |
| 2295 | // the clock at each single shift anyway. |
| 2296 | // Also, it is easier to implement the status bit setting. |
| 2297 | // Note that count is never 0 |
| 2298 | if (m_command == SRA) sign = value & 0x8000; |
| 2299 | |
| 2300 | for (int i=0; i < m_count; i++) |
| 2301 | { |
| 2302 | switch (m_command) |
| 2303 | { |
| 2304 | case SRL: |
| 2305 | case SRA: |
| 2306 | carry = ((value & 1)!=0); |
| 2307 | value = (value >> 1) | sign; |
| 2308 | break; |
| 2309 | case SLA: |
| 2310 | carry = ((value & 0x8000)!=0); |
| 2311 | value <<= 1; |
| 2312 | if (carry != ((value&0x8000)!=0)) overflow = true; |
| 2313 | break; |
| 2314 | case SRC: |
| 2315 | carry = ((value & 1)!=0); |
| 2316 | value = (value>>1) | (carry? 0x8000 : 0x0000); |
| 2317 | break; |
| 2318 | } |
| 2319 | pulse_clock(2); |
| 2320 | } |
| 2321 | |
| 2322 | m_current_value = value & 0xffff; |
| 2323 | set_status_bit(ST_C, carry); |
| 2324 | set_status_bit(ST_OV, overflow); |
| 2325 | compare_and_set_lae(m_current_value, 0); |
| 2326 | |
| 2327 | m_regnumber = (IR & 0x000f); |
| 2328 | break; |
| 2329 | } |
| 2330 | m_state++; |
| 2331 | pulse_clock(2); |
| 2332 | } |
| 2333 | |
| 2334 | void tms9900_device::alu_ai_ori() |
| 2335 | { |
| 2336 | UINT32 dest_new = 0; |
| 2337 | switch (m_command) |
| 2338 | { |
| 2339 | case AI: |
| 2340 | dest_new = m_current_value + m_register_contents; |
| 2341 | // See status bit handling for Add |
| 2342 | 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); |
| 2344 | break; |
| 2345 | case ANDI: |
| 2346 | dest_new = m_current_value & m_register_contents; |
| 2347 | break; |
| 2348 | case ORI: |
| 2349 | dest_new = m_current_value | m_register_contents; |
| 2350 | break; |
| 2351 | } |
| 2352 | m_current_value = dest_new & 0xffff; |
| 2353 | compare_and_set_lae(m_current_value, 0); |
| 2354 | pulse_clock(2); |
| 2355 | } |
| 2356 | |
| 2357 | void tms9900_device::alu_ci() |
| 2358 | { |
| 2359 | compare_and_set_lae(m_register_contents, m_current_value); |
| 2360 | pulse_clock(2); |
| 2361 | } |
| 2362 | |
| 2363 | void tms9900_device::alu_li() |
| 2364 | { |
| 2365 | compare_and_set_lae(m_current_value, 0); |
| 2366 | pulse_clock(2); |
| 2367 | } |
| 2368 | |
| 2369 | void tms9900_device::alu_lwpi() |
| 2370 | { |
| 2371 | WP = m_current_value; |
| 2372 | pulse_clock(2); |
| 2373 | } |
| 2374 | |
| 2375 | void tms9900_device::alu_limi() |
| 2376 | { |
| 2377 | ST = (ST & 0xfff0) | (m_current_value & 0x000f); |
| 2378 | if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST); |
| 2379 | pulse_clock(2); |
| 2380 | } |
| 2381 | |
| 2382 | void tms9900_device::alu_stwp_stst() |
| 2383 | { |
| 2384 | if (m_command==STST) m_current_value = ST; |
| 2385 | else m_current_value = WP; |
| 2386 | pulse_clock(2); |
| 2387 | } |
| 2388 | |
| 2389 | void tms9900_device::alu_external() |
| 2390 | { |
| 2391 | pulse_clock(10); |
| 2392 | |
| 2393 | // Call some possibly attached external device |
| 2394 | // We pass the bit pattern of the address bus to the external function |
| 2395 | |
| 2396 | // IDLE = 0000 0011 0100 0000 |
| 2397 | // RSET = 0000 0011 0110 0000 |
| 2398 | // CKON = 0000 0011 1010 0000 |
| 2399 | // CKOF = 0000 0011 1100 0000 |
| 2400 | // LREX = 0000 0011 1110 0000 |
| 2401 | // --- |
| 2402 | if (m_command == IDLE) |
| 2403 | m_idle_state = true; |
| 2404 | |
| 2405 | m_external_operation((IR >> 5) & 0x07, 1); |
| 2406 | } |
| 2407 | |
| 2408 | void tms9900_device::alu_rtwp() |
| 2409 | { |
| 2410 | switch (m_state) |
| 2411 | { |
| 2412 | case 0: |
| 2413 | m_regnumber = 15; |
| 2414 | break; |
| 2415 | case 1: |
| 2416 | ST = m_register_contents; |
| 2417 | m_regnumber = 14; |
| 2418 | break; |
| 2419 | case 2: |
| 2420 | PC = m_register_contents; |
| 2421 | m_regnumber = 13; |
| 2422 | break; |
| 2423 | case 3: |
| 2424 | WP = m_register_contents; |
| 2425 | break; |
| 2426 | } |
| 2427 | m_state++; |
| 2428 | pulse_clock(2); |
| 2429 | } |
| 2430 | |
| 2431 | |
| 2432 | void tms9900_device::alu_int() |
| 2433 | { |
| 2434 | if (VERBOSE>7) LOG("tms9900: INT state %d; irq_level %d\n", m_state, m_irq_level); |
| 2435 | switch (m_state) |
| 2436 | { |
| 2437 | case 0: |
| 2438 | if (m_irq_level == RESET_INT) |
| 2439 | { |
| 2440 | m_address = 0; |
| 2441 | pulse_clock(2); |
| 2442 | } |
| 2443 | else |
| 2444 | { |
| 2445 | if (m_irq_level == LOAD_INT) m_address = 0xfffc; |
| 2446 | else |
| 2447 | { |
| 2448 | m_address = (m_irq_level << 2); |
| 2449 | } |
| 2450 | } |
| 2451 | break; |
| 2452 | case 1: |
| 2453 | m_value = WP; // old WP |
| 2454 | WP = m_current_value; // new WP |
| 2455 | m_current_value = ST; |
| 2456 | m_regnumber = 15; |
| 2457 | break; |
| 2458 | case 2: |
| 2459 | m_current_value = PC; |
| 2460 | m_regnumber = 14; |
| 2461 | break; |
| 2462 | case 3: |
| 2463 | m_current_value = m_value; // old WP |
| 2464 | m_regnumber = 13; |
| 2465 | break; |
| 2466 | case 4: |
| 2467 | m_address = (m_address + 2) & 0xfffe; |
| 2468 | if (VERBOSE>7) LOG("tms9900: read from %04x\n", m_address); |
| 2469 | break; |
| 2470 | case 5: |
| 2471 | PC = m_current_value; |
| 2472 | if (m_irq_level > 0 ) |
| 2473 | { |
| 2474 | ST = (ST & 0xfff0) | (m_irq_level - 1); |
| 2475 | } |
| 2476 | break; |
| 2477 | } |
| 2478 | m_state++; |
| 2479 | pulse_clock(2); |
| 2480 | } |
| 2481 | |
| 2482 | /**************************************************************************/ |
| 2483 | UINT32 tms9900_device::execute_min_cycles() const |
| 2484 | { |
| 2485 | return 2; |
| 2486 | } |
| 2487 | |
| 2488 | // TODO: Compute this value, just a wild guess for the average |
| 2489 | UINT32 tms9900_device::execute_max_cycles() const |
| 2490 | { |
| 2491 | return 10; |
| 2492 | } |
| 2493 | |
| 2494 | UINT32 tms9900_device::execute_input_lines() const |
| 2495 | { |
| 2496 | return 1; |
| 2497 | } |
| 2498 | |
| 2499 | // clocks to cycles, cycles to clocks = id |
| 2500 | // execute_default_irq_vector = 0 |
| 2501 | // execute_burn = nop |
| 2502 | |
| 2503 | // device_disasm_interface overrides |
| 2504 | UINT32 tms9900_device::disasm_min_opcode_bytes() const |
| 2505 | { |
| 2506 | return 2; |
| 2507 | } |
| 2508 | |
| 2509 | UINT32 tms9900_device::disasm_max_opcode_bytes() const |
| 2510 | { |
| 2511 | return 6; |
| 2512 | } |
| 2513 | |
| 2514 | offs_t tms9900_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) |
| 2515 | { |
| 2516 | return Dasm9900(buffer, pc, TMS9900_ID, oprom, opram); |
| 2517 | } |
| 2518 | |
| 2519 | |
| 2520 | const device_type TMS9900 = &device_creator<tms9900_device>; |
src/mess/drivers/ti99_8.c
| r15423 | r15424 | |
| 167 | 167 | a problem of the prototypical XB II which we cannot solve. It seems as if only |
| 168 | 168 | hexbus devices are properly supported, but we currently do not have an |
| 169 | 169 | emulation for those. Thus you can currently only use cassette to load and |
| 170 | | save programs. You MUST turn off the floppy controller support in the |
| 171 | | configuration before you enter XB II. Other cartridges (like Editor/Assembler) |
| 170 | save programs. You MUST not plug in any floppy controller when you intend to |
| 171 | start XB II. Other cartridges (like Editor/Assembler) |
| 172 | 172 | seem to be not affected by this problem and can make use of the floppy |
| 173 | 173 | controllers. |
| 174 | 174 | Technical detail: The designers of XB II seem to have decided to put PABs |
| r15423 | r15424 | |
| 185 | 185 | cartridge is presented. You have to manually select the cartridges with the |
| 186 | 186 | dip switch. |
| 187 | 187 | |
| 188 | | - Emulation speed may still be incorrect. |
| 189 | | |
| 190 | 188 | - SAVE and OLD MINIMEM do not work properly in XB II. It seems as if the |
| 191 | 189 | mapper shadows the NVRAM of the cartridge. You will lose the contents when |
| 192 | 190 | you turn off the machine. |
| 193 | 191 | |
| 194 | 192 | Raphael Nabet, 2003. |
| 195 | | Michael Zapf |
| 196 | 193 | |
| 197 | 194 | February 2012: Rewritten as class |
| 195 | Michael Zapf |
| 198 | 196 | |
| 199 | 197 | *****************************************************************************/ |
| 200 | 198 | |
| 201 | 199 | |
| 202 | 200 | #include "emu.h" |
| 203 | | #include "cpu/tms9900/tms9900.h" |
| 201 | #include "cpu/tms9900/tms9995.h" |
| 202 | |
| 204 | 203 | #include "sound/sn76496.h" |
| 205 | 204 | #include "sound/wave.h" |
| 206 | 205 | #include "machine/tms9901.h" |
| r15423 | r15424 | |
| 215 | 214 | #include "machine/ti99/gromport.h" |
| 216 | 215 | #include "machine/ti99/mecmouse.h" |
| 217 | 216 | |
| 218 | | #define VERBOSE 1 |
| 217 | #define VERBOSE |
| 219 | 218 | #define LOG logerror |
| 220 | 219 | |
| 221 | 220 | class ti99_8 : public driver_device |
| r15423 | r15424 | |
| 228 | 227 | DECLARE_READ8_MEMBER(cruread); |
| 229 | 228 | DECLARE_WRITE8_MEMBER(cruwrite); |
| 230 | 229 | |
| 230 | DECLARE_WRITE8_MEMBER(external_operation); |
| 231 | |
| 231 | 232 | // Forwarding interrupts to the CPU or CRU |
| 232 | 233 | DECLARE_WRITE_LINE_MEMBER( console_ready ); |
| 234 | DECLARE_WRITE_LINE_MEMBER( console_ready_mapper ); |
| 235 | |
| 233 | 236 | DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT2 ); |
| 234 | 237 | DECLARE_WRITE_LINE_MEMBER( extint ); |
| 235 | 238 | DECLARE_WRITE_LINE_MEMBER( notconnected ); |
| r15423 | r15424 | |
| 247 | 250 | DECLARE_WRITE_LINE_MEMBER(cassette_motor); |
| 248 | 251 | DECLARE_WRITE8_MEMBER(tms9901_interrupt); |
| 249 | 252 | |
| 253 | DECLARE_WRITE_LINE_MEMBER( clock_out ); |
| 254 | |
| 250 | 255 | // Some values to keep |
| 251 | | device_t *m_cpu; |
| 256 | tms9995_device *m_cpu; |
| 252 | 257 | tms9901_device *m_tms9901; |
| 253 | 258 | gromport_device *m_gromport; |
| 254 | 259 | peribox_device *m_peribox; |
| 255 | 260 | mecmouse_device *m_mecmouse; |
| 256 | 261 | ti998_mapper_device *m_mapper; |
| 257 | 262 | |
| 263 | int m_ready_line, m_ready_line1; |
| 264 | |
| 258 | 265 | private: |
| 259 | 266 | /* Keyboard support */ |
| 260 | 267 | void set_key(int number, int data); |
| r15423 | r15424 | |
| 276 | 283 | The TMS9901 is fully decoded according to the specification, so we only |
| 277 | 284 | have 32 bits for it; the rest goes to the CRU bus |
| 278 | 285 | (decoded by the "Vaquerro" chip, signal NNOICS*) |
| 279 | | TODO: Check whether the CRU address space goes up to 7fff (15 bit) |
| 280 | 286 | */ |
| 281 | 287 | |
| 282 | 288 | static ADDRESS_MAP_START(crumap, AS_IO, 8, ti99_8) |
| r15423 | r15424 | |
| 423 | 429 | |
| 424 | 430 | static GROM_CONFIG(grom0_config) |
| 425 | 431 | { |
| 426 | | false, 0, region_grom, 0x0000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready) |
| 432 | false, 0, region_grom, 0x0000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ |
| 427 | 433 | }; |
| 428 | 434 | |
| 429 | 435 | static GROM_CONFIG(grom1_config) |
| 430 | 436 | { |
| 431 | | false, 1, region_grom, 0x2000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready) |
| 437 | false, 1, region_grom, 0x2000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ |
| 432 | 438 | }; |
| 433 | 439 | |
| 434 | 440 | static GROM_CONFIG(grom2_config) |
| 435 | 441 | { |
| 436 | | false, 2, region_grom, 0x4000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready) |
| 442 | false, 2, region_grom, 0x4000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ |
| 437 | 443 | }; |
| 438 | 444 | |
| 445 | /**************************************************** |
| 446 | PASCAL groms, 3 libraries @ 8 GROMs |
| 447 | Do some macro tricks to keep writing effort low |
| 448 | *****************************************************/ |
| 449 | |
| 450 | #define pascal0_region "pascal0_region" |
| 451 | #define pascal12_region "pascal12_region" |
| 452 | |
| 453 | #define MCFG_GROM_LIBRARY_ADD(_tag, _config) \ |
| 454 | MCFG_DEVICE_ADD(#_tag "0", GROM, 0) \ |
| 455 | MCFG_DEVICE_CONFIG(_config##0) \ |
| 456 | MCFG_DEVICE_ADD(#_tag "1", GROM, 0) \ |
| 457 | MCFG_DEVICE_CONFIG(_config##1) \ |
| 458 | MCFG_DEVICE_ADD(#_tag "2", GROM, 0) \ |
| 459 | MCFG_DEVICE_CONFIG(_config##2) \ |
| 460 | MCFG_DEVICE_ADD(#_tag "3", GROM, 0) \ |
| 461 | MCFG_DEVICE_CONFIG(_config##3) \ |
| 462 | MCFG_DEVICE_ADD(#_tag "4", GROM, 0) \ |
| 463 | MCFG_DEVICE_CONFIG(_config##4) \ |
| 464 | MCFG_DEVICE_ADD(#_tag "5", GROM, 0) \ |
| 465 | MCFG_DEVICE_CONFIG(_config##5) \ |
| 466 | MCFG_DEVICE_ADD(#_tag "6", GROM, 0) \ |
| 467 | MCFG_DEVICE_CONFIG(_config##6) \ |
| 468 | MCFG_DEVICE_ADD(#_tag "7", GROM, 0) \ |
| 469 | MCFG_DEVICE_CONFIG(_config##7) |
| 470 | |
| 471 | #define GROM_LIBRARY_CONFIG(_conf, _region) \ |
| 472 | static GROM_CONFIG(_conf##0) \ |
| 473 | { false, 0, _region, 0x0000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 474 | static GROM_CONFIG(_conf##1) \ |
| 475 | { false, 1, _region, 0x2000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 476 | static GROM_CONFIG(_conf##2) \ |
| 477 | { false, 2, _region, 0x4000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 478 | static GROM_CONFIG(_conf##3) \ |
| 479 | { false, 3, _region, 0x6000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 480 | static GROM_CONFIG(_conf##4) \ |
| 481 | { false, 4, _region, 0x8000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 482 | static GROM_CONFIG(_conf##5) \ |
| 483 | { false, 5, _region, 0xa000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 484 | static GROM_CONFIG(_conf##6) \ |
| 485 | { false, 6, _region, 0xc000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; \ |
| 486 | static GROM_CONFIG(_conf##7) \ |
| 487 | { false, 7, _region, 0xe000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), GROMFREQ }; |
| 488 | |
| 489 | GROM_LIBRARY_CONFIG(pascal0, pascal0_region) |
| 490 | GROM_LIBRARY_CONFIG(pascal1, pascal12_region) |
| 491 | GROM_LIBRARY_CONFIG(pascal2, pascal12_region) |
| 492 | |
| 439 | 493 | static GROMPORT_CONFIG(console_cartslot) |
| 440 | 494 | { |
| 441 | 495 | DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready) |
| r15423 | r15424 | |
| 623 | 677 | |
| 624 | 678 | WRITE8_MEMBER( ti99_8::tms9901_interrupt ) |
| 625 | 679 | { |
| 626 | | // offset contains the interrupt level (0-15) |
| 627 | | if (data==ASSERT_LINE) |
| 628 | | { |
| 629 | | // The TMS9901 should normally be connected with the CPU by 5 wires: |
| 630 | | // INTREQ* and IC0-IC3. The last four lines deliver the interrupt level. |
| 631 | | // On the TI-99 systems these IC lines are not used; the input lines |
| 632 | | // at the CPU are hardwired to level 1. |
| 633 | | if (VERBOSE>8) LOG("mapper8: tms9901 asserts interrupt\n"); |
| 634 | | device_execute(m_cpu)->set_input_line_and_vector(0, ASSERT_LINE, 1); |
| 635 | | } |
| 636 | | else |
| 637 | | { |
| 638 | | if (VERBOSE>8) LOG("mapper8: tms9901 clears interrupt\n"); |
| 639 | | device_execute(m_cpu)->set_input_line(0, CLEAR_LINE); |
| 640 | | } |
| 680 | m_cpu->set_input_line(1, data); |
| 641 | 681 | } |
| 642 | 682 | |
| 643 | 683 | const tms9901_interface tms9901_wiring_ti99_8 = |
| r15423 | r15424 | |
| 688 | 728 | |
| 689 | 729 | WRITE_LINE_MEMBER( ti99_8::console_ready ) |
| 690 | 730 | { |
| 691 | | if (VERBOSE>6) LOG("ti99_8: READY line set ... not yet connected, level=%02x\n", state); |
| 731 | if (VERBOSE>6) LOG("ti99_8: READY level=%02x\n", state); |
| 732 | m_ready_line = state; |
| 733 | |
| 734 | m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE); |
| 692 | 735 | } |
| 693 | 736 | |
| 737 | /* |
| 738 | Memory access over the mapper also operates |
| 739 | the READY line, and the mapper raises READY depending on the clock pulse. |
| 740 | So we must make sure this does not interfere. |
| 741 | */ |
| 742 | WRITE_LINE_MEMBER( ti99_8::console_ready_mapper ) |
| 743 | { |
| 744 | if (VERBOSE>6) LOG("ti99_8: READY level (mapper) = %02x\n", state); |
| 745 | m_ready_line1 = state; |
| 746 | m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE); |
| 747 | } |
| 748 | |
| 694 | 749 | WRITE_LINE_MEMBER( ti99_8::extint ) |
| 695 | 750 | { |
| 696 | 751 | if (VERBOSE>6) LOG("ti99_8: EXTINT level = %02x\n", state); |
| r15423 | r15424 | |
| 710 | 765 | DEVCB_DRIVER_LINE_MEMBER(ti99_8, set_tms9901_INT2) |
| 711 | 766 | }; |
| 712 | 767 | |
| 768 | WRITE8_MEMBER( ti99_8::external_operation ) |
| 769 | { |
| 770 | static const char* extop[8] = { "inv1", "inv2", "IDLE", "RSET", "inv3", "CKON", "CKOF", "LREX" }; |
| 771 | if (VERBOSE>1) LOG("External operation %s not implemented on TI-99 board\n", extop[offset]); |
| 772 | } |
| 773 | |
| 774 | /* |
| 775 | Clock line from the CPU. Used to control wait state generation. |
| 776 | */ |
| 777 | WRITE_LINE_MEMBER( ti99_8::clock_out ) |
| 778 | { |
| 779 | m_mapper->clock_in(state); |
| 780 | } |
| 781 | |
| 713 | 782 | /*****************************************************************************/ |
| 714 | 783 | |
| 715 | | static const struct tms9995reset_param ti99_8_processor_config = |
| 784 | /* |
| 785 | MP9537 mask: This variant of the TMS9995 does not contain on-chip RAM |
| 786 | Also, the overflow interrupt is disabled; in the available documentation |
| 787 | this feature is said to be disabled and is announced for a later version. |
| 788 | */ |
| 789 | static TMS9995_CONFIG( ti99_8_processor_config ) |
| 716 | 790 | { |
| 717 | | 1, /* enable automatic wait state generation */ |
| 718 | | /* (in January 83 99/8 schematics sheet 9: the delay logic */ |
| 719 | | /* seems to keep READY low for one cycle when RESET* is */ |
| 720 | | /* asserted, but the timings are completely wrong this way) */ |
| 721 | | 0, /* no IDLE callback */ |
| 722 | | 1 /* MP9537 mask */ |
| 791 | DEVCB_DRIVER_MEMBER(ti99_8, external_operation), |
| 792 | DEVCB_NULL, // Instruction acquisition |
| 793 | DEVCB_DRIVER_LINE_MEMBER(ti99_8, clock_out), |
| 794 | DEVCB_NULL, // wait |
| 795 | DEVCB_NULL, // HOLDA |
| 796 | NO_INTERNAL_RAM, |
| 797 | NO_OVERFLOW_INT |
| 723 | 798 | }; |
| 724 | 799 | |
| 725 | 800 | /* |
| r15423 | r15424 | |
| 741 | 816 | |
| 742 | 817 | Access to the mapper registers is done directly in the mapper, not via |
| 743 | 818 | this list. |
| 819 | |
| 820 | NOTE: The available system software contradicts the specification |
| 821 | concerning the Pascal ports. While the specs define f840 as "Text-to-speech |
| 822 | library" and f850 and f860 as two libraries for Pascal, the operating |
| 823 | system defines f840 as Pascal lib 0, f880 as Pascal lib 1, and f8c0 as |
| 824 | Pascal lib 2. |
| 825 | |
| 826 | TODO: This should (must) be improved in terms of performance. Every single |
| 827 | memory access goes through the mapper. Either we use an ordered search list, |
| 828 | or we order the entries according to their frequency. |
| 829 | (I did this right now, putting the Pascal GROMs at the end.) |
| 830 | We should think about a set entry where devices with the same address |
| 831 | are collected as one single entry (think about the Pascal lib with 24 GROMs, |
| 832 | every eight of them on the same address). |
| 744 | 833 | */ |
| 745 | | static const mapper8_list_entry mapper_devices[] = |
| 746 | | { |
| 747 | | // TI-99/8 mode |
| 748 | | { SRAMNAME, NATIVE, STOP, 0xf000, 0xf800, 0x0000 }, // f000-f7ff |
| 749 | | { TISOUND_TAG, NATIVE, STOP, 0xf800, 0xfff0, 0x0000 }, // f800-f80f |
| 750 | | { VIDEO_SYSTEM_TAG, NATIVE, STOP, 0xf810, 0xfffd, 0x0000 }, // f810,2 (unlike 99/4A, no different read/write ports) |
| 751 | | { SPEECH_TAG, NATIVE, STOP, 0xf820, 0xfff0, 0x0000 }, // f820-f82f |
| 752 | 834 | |
| 753 | | { GROM0_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, // f830-f83e (4 banks), no different read/write ports |
| 754 | | { GROM1_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, |
| 755 | | { GROM2_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, |
| 756 | | { GROMPORT_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, |
| 835 | #define PASCAL_GROM_LIB(_tag, _addr) \ |
| 836 | { _tag "0", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 837 | { _tag "1", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 838 | { _tag "2", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 839 | { _tag "3", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 840 | { _tag "4", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 841 | { _tag "5", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 842 | { _tag "6", PATGEN, CONT, _addr, 0xfff1, 0x0000 }, \ |
| 843 | { _tag "7", PATGEN, CONT, _addr, 0xfff1, 0x0000 } |
| 757 | 844 | |
| 758 | | // { GROMTTS0_TAG, PATGEN, CONT, 0xf840, 0xfff1, 0x0000 }, // up to 6 GROMs; no good dumps known |
| 759 | | // { GROMPC10_TAG, PATGEN, CONT, 0xf850, 0xfff1, 0x0000 }, // up to 6 GROMs; no good dumps known |
| 760 | | // { GROMPC20_TAG, PATGEN, CONT, 0xf860, 0xfff1, 0x0000 }, // up to 6 GROMs; no good dumps known |
| 761 | | { MAPPER_TAG, NATIVE, STOP, 0xf870, 0xfff0, 0x0000 }, |
| 762 | 845 | |
| 846 | static const mapper8_list_entry mapper_devices[] = |
| 847 | { |
| 763 | 848 | // TI-99/4A mode (CRUS=1) |
| 764 | 849 | // GROMs: According to the spec, the 99/8 supports up to 4 GROM libraries |
| 765 | 850 | // (99/4A supports 256 libraries) |
| 766 | 851 | // at 9800, 9804, 9808, 980c. Address counter access is at 9802,6,a,e. Write access +0400. |
| 767 | 852 | { ROM0NAME, TI99EM, STOP, 0x0000, 0xe000, 0x0000 }, // 0000-1fff |
| 768 | 853 | |
| 769 | | { GROM0_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // 9800,2,4,...e/9c00,2,4,...e |
| 770 | | { GROM1_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // dto. |
| 771 | | { GROM2_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // dto. (GROMs are connected in parallel, |
| 772 | | { GROMPORT_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // dto. use internal address counter and id) |
| 773 | | |
| 774 | 854 | { TISOUND_TAG, TI99EM, STOP, 0x8400, 0xfff0, 0x0000 }, // 8400-840f |
| 775 | 855 | { VIDEO_SYSTEM_TAG, TI99EM, STOP, 0x8800, 0xfffd, 0x0400 }, // 8800,8802 / 8c00,8c02 |
| 776 | 856 | { SPEECH_TAG, TI99EM, STOP, 0x9000, 0xfff0, 0x0400 }, // 9000-900f / 9400-940f |
| 777 | 857 | { SRAMNAME, TI99EM, STOP, 0x8000, 0xf800, 0x0000 }, // 8000-87ff; must follow the sound generator |
| 778 | 858 | { MAPPER_TAG, TI99EM, STOP, 0x8810, 0xfff0, 0x0000 }, |
| 779 | 859 | |
| 860 | { GROM0_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // 9800,2,4,...e/9c00,2,4,...e |
| 861 | { GROM1_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // dto. |
| 862 | { GROM2_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // dto. (GROMs are connected in parallel, |
| 863 | { GROMPORT_TAG, TI99EM, CONT, 0x9800, 0xfff1, 0x0400 }, // dto. use internal address counter and id) |
| 864 | |
| 865 | // TI-99/8 mode |
| 866 | { SRAMNAME, NATIVE, STOP, 0xf000, 0xf800, 0x0000 }, // f000-f7ff |
| 867 | { TISOUND_TAG, NATIVE, STOP, 0xf800, 0xfff0, 0x0000 }, // f800-f80f |
| 868 | { VIDEO_SYSTEM_TAG, NATIVE, STOP, 0xf810, 0xfffd, 0x0000 }, // f810,2 (unlike 99/4A, no different read/write ports) |
| 869 | { SPEECH_TAG, NATIVE, STOP, 0xf820, 0xfff0, 0x0000 }, // f820-f82f |
| 870 | { MAPPER_TAG, NATIVE, STOP, 0xf870, 0xfff0, 0x0000 }, |
| 871 | |
| 872 | { GROM0_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, // f830-f83e (4 banks), no different read/write ports |
| 873 | { GROM1_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, |
| 874 | { GROM2_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, |
| 875 | { GROMPORT_TAG, NATIVE, CONT, 0xf830, 0xfff1, 0x0000 }, |
| 876 | |
| 877 | PASCAL_GROM_LIB("pascal0_grom", 0xf840), |
| 878 | PASCAL_GROM_LIB("pascal1_grom", 0xf880), // lib1 and 2 are zeroed. We don't have good dumps for them yet. |
| 879 | PASCAL_GROM_LIB("pascal2_grom", 0xf8c0), // Anyway, we keep them in order to check whether/when they are accessed. |
| 880 | |
| 780 | 881 | // Physical (need to pack this in here as well to keep config simple) |
| 882 | // but these lines will be put into a separate list |
| 781 | 883 | { DRAMNAME, PHYSIC, STOP, 0x000000, 0xff0000, 0x000000 }, // 000000-00ffff 64 KiB DRAM |
| 782 | 884 | { MAPPER_TAG, PHYSIC, CONT, 0xff4000, 0xffe000, 0x000000 }, // ff4000-ff5fff Internal DSR |
| 783 | 885 | { GROMPORT_TAG, PHYSIC, STOP, 0xff6000, 0xffe000, 0x000000 }, // ff6000-ff7fff Cartridge ROM space |
| r15423 | r15424 | |
| 790 | 892 | { NULL, 0, 0, 0, 0, 0 } |
| 791 | 893 | }; |
| 792 | 894 | |
| 895 | static MAPPER8_CONFIG( mapper_conf ) |
| 896 | { |
| 897 | DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready_mapper), // READY |
| 898 | mapper_devices |
| 899 | }; |
| 900 | |
| 901 | static SPEECH8_CONFIG( speech_config ) |
| 902 | { |
| 903 | DEVCB_DRIVER_LINE_MEMBER(ti99_8, console_ready), // READY |
| 904 | }; |
| 905 | |
| 793 | 906 | MACHINE_START( ti99_8 ) |
| 794 | 907 | { |
| 795 | 908 | ti99_8 *driver = machine.driver_data<ti99_8>(); |
| 796 | | driver->m_cpu = machine.device("maincpu"); |
| 909 | driver->m_cpu = static_cast<tms9995_device*>(machine.device("maincpu")); |
| 797 | 910 | driver->m_tms9901 = static_cast<tms9901_device*>(machine.device(TMS9901_TAG)); |
| 798 | 911 | driver->m_gromport = static_cast<gromport_device*>(machine.device(GROMPORT_TAG)); |
| 799 | 912 | driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG)); |
| r15423 | r15424 | |
| 810 | 923 | driver->m_mecmouse = static_cast<mecmouse_device*>(machine.device(MECMOUSE_TAG)); |
| 811 | 924 | else |
| 812 | 925 | driver->m_mecmouse = NULL; |
| 926 | |
| 927 | // Pulling down the line on RESET configures the CPU to insert one wait |
| 928 | // state on external memory accesses |
| 929 | |
| 930 | // RN: enable automatic wait state generation |
| 931 | // in January 83 99/8 schematics sheet 9: the delay logic |
| 932 | // seems to keep READY low for one cycle when RESET* is |
| 933 | // asserted, but the timings are completely wrong this way |
| 934 | |
| 935 | driver->m_cpu->set_ready(CLEAR_LINE); |
| 936 | |
| 937 | // But we assert the line here so that the system starts running |
| 938 | driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE; |
| 813 | 939 | } |
| 814 | 940 | |
| 815 | 941 | static MACHINE_CONFIG_START( ti99_8_60hz, ti99_8 ) |
| 816 | 942 | /* basic machine hardware */ |
| 817 | 943 | /* TMS9995-MP9537 CPU @ 10.7 MHz */ |
| 818 | | MCFG_CPU_ADD("maincpu", TMS9995, 10738635) |
| 819 | | MCFG_CPU_CONFIG(ti99_8_processor_config) |
| 820 | | MCFG_CPU_PROGRAM_MAP(memmap) |
| 821 | | MCFG_CPU_IO_MAP(crumap) |
| 944 | MCFG_TMS9995_ADD("maincpu", TMS9995, 10738635, memmap, crumap, ti99_8_processor_config) |
| 945 | |
| 822 | 946 | MCFG_MACHINE_START( ti99_8 ) |
| 823 | 947 | MCFG_MACHINE_RESET( ti99_8 ) |
| 824 | 948 | |
| r15423 | r15424 | |
| 827 | 951 | |
| 828 | 952 | /* Main board */ |
| 829 | 953 | MCFG_TMS9901_ADD( TMS9901_TAG, tms9901_wiring_ti99_8, 2684658.75 ) |
| 830 | | MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_devices ) |
| 954 | MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_conf ) |
| 831 | 955 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 832 | 956 | |
| 833 | 957 | /* Peripheral expansion box */ |
| r15423 | r15424 | |
| 849 | 973 | MCFG_GROM_ADD( GROM1_TAG, grom1_config ) |
| 850 | 974 | MCFG_GROM_ADD( GROM2_TAG, grom2_config ) |
| 851 | 975 | |
| 976 | /* Pascal GROM libraries. */ |
| 977 | MCFG_GROM_LIBRARY_ADD(pascal0_grom, pascal0) |
| 978 | MCFG_GROM_LIBRARY_ADD(pascal1_grom, pascal1) |
| 979 | MCFG_GROM_LIBRARY_ADD(pascal2_grom, pascal2) |
| 980 | |
| 852 | 981 | /* Devices */ |
| 853 | | MCFG_TISPEECH8_ADD(SPEECH_TAG) |
| 982 | MCFG_TISPEECH8_ADD(SPEECH_TAG, speech_config) |
| 854 | 983 | |
| 855 | 984 | /* Optional user controller */ |
| 856 | 985 | MCFG_MECMOUSE_ADD( MECMOUSE_TAG, 60 ) |
| r15423 | r15424 | |
| 860 | 989 | static MACHINE_CONFIG_START( ti99_8_50hz, ti99_8 ) |
| 861 | 990 | /* basic machine hardware */ |
| 862 | 991 | /* TMS9995-MP9537 CPU @ 10.7 MHz */ |
| 863 | | MCFG_CPU_ADD("maincpu", TMS9995, 10738635) |
| 864 | | MCFG_CPU_CONFIG(ti99_8_processor_config) |
| 865 | | MCFG_CPU_PROGRAM_MAP(memmap) |
| 866 | | MCFG_CPU_IO_MAP(crumap) |
| 992 | MCFG_TMS9995_ADD("maincpu", TMS9995, 10738635, memmap, crumap, ti99_8_processor_config) |
| 867 | 993 | MCFG_MACHINE_START( ti99_8 ) |
| 868 | 994 | MCFG_MACHINE_RESET( ti99_8 ) |
| 869 | 995 | |
| r15423 | r15424 | |
| 872 | 998 | |
| 873 | 999 | /* Main board */ |
| 874 | 1000 | MCFG_TMS9901_ADD( TMS9901_TAG, tms9901_wiring_ti99_8, 2684658.75 ) |
| 875 | | MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_devices ) |
| 1001 | MCFG_MAPPER8_ADD( MAPPER_TAG, mapper_conf ) |
| 876 | 1002 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 877 | 1003 | |
| 878 | 1004 | /* Peripheral expansion box */ |
| r15423 | r15424 | |
| 894 | 1020 | MCFG_GROM_ADD( GROM1_TAG, grom1_config ) |
| 895 | 1021 | MCFG_GROM_ADD( GROM2_TAG, grom2_config ) |
| 896 | 1022 | |
| 1023 | /* Pascal GROMs libraries. */ |
| 1024 | MCFG_GROM_LIBRARY_ADD(pascal0_grom, pascal0) |
| 1025 | MCFG_GROM_LIBRARY_ADD(pascal1_grom, pascal1) |
| 1026 | MCFG_GROM_LIBRARY_ADD(pascal2_grom, pascal2) |
| 1027 | |
| 897 | 1028 | /* Devices */ |
| 898 | | MCFG_TISPEECH8_ADD(SPEECH_TAG) |
| 1029 | MCFG_TISPEECH8_ADD(SPEECH_TAG, speech_config) |
| 899 | 1030 | |
| 900 | 1031 | /* Optional user controller */ |
| 901 | 1032 | MCFG_MECMOUSE_ADD( MECMOUSE_TAG, 50 ) |
| r15423 | r15424 | |
| 913 | 1044 | ROM_REGION(0x10000, region_grom, 0) |
| 914 | 1045 | ROM_LOAD("998grom.bin", 0x0000, 0x6000, CRC(c63806bc) SHA1(cbfa8b04b4aefbbd9a713c54267ad4dd179c13a3)) /* system GROMs */ |
| 915 | 1046 | |
| 1047 | /* Pascal GROMs. Sadly, P-System fails to start. */ |
| 1048 | ROM_REGION(0x10000, pascal0_region, 0) |
| 1049 | ROM_LOAD_OPTIONAL("998pascal.bin", 0x0000, 0x10000, CRC(1389589e) SHA1(42942b99ed355a2c091cc480b15f5329156e6b03)) |
| 1050 | |
| 1051 | // Still need good dumps; so far, stay with 0 |
| 1052 | ROM_REGION(0x10000, pascal12_region, 0) |
| 1053 | ROM_FILL(0x0000, 0x10000, 0x00) |
| 1054 | |
| 916 | 1055 | /* Built-in RAM */ |
| 917 | 1056 | ROM_REGION(SRAM_SIZE, SRAM_TAG, 0) |
| 918 | 1057 | ROM_FILL(0x0000, SRAM_SIZE, 0x00) |
src/mess/drivers/ti99_4x.c
| r15423 | r15424 | |
| 56 | 56 | #include "machine/ti99/peribox.h" |
| 57 | 57 | |
| 58 | 58 | #define LOG logerror |
| 59 | | #define VERBOSE 1 |
| 59 | #define VERBOSE |
| 60 | 60 | |
| 61 | 61 | /* |
| 62 | 62 | The console. |
| r15423 | r15424 | |
| 70 | 70 | // CRU (Communication Register Unit) handling |
| 71 | 71 | DECLARE_READ8_MEMBER(cruread); |
| 72 | 72 | DECLARE_WRITE8_MEMBER(cruwrite); |
| 73 | DECLARE_WRITE8_MEMBER(external_operation); |
| 73 | 74 | |
| 74 | 75 | // Forwarding interrupts to the CPU or CRU |
| 75 | 76 | DECLARE_WRITE_LINE_MEMBER( console_ready ); |
| 77 | DECLARE_WRITE_LINE_MEMBER( console_ready_dmux ); |
| 78 | |
| 76 | 79 | DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT2 ); |
| 77 | 80 | DECLARE_WRITE_LINE_MEMBER( set_tms9901_INT12 ); |
| 78 | 81 | void set_tms9901_INT2_from_v9938(v99x8_device &vdp, int state); |
| 79 | 82 | DECLARE_WRITE_LINE_MEMBER( extint ); |
| 80 | 83 | DECLARE_WRITE_LINE_MEMBER( notconnected ); |
| 81 | 84 | |
| 85 | DECLARE_READ8_MEMBER( interrupt_level ); |
| 86 | DECLARE_READ_LINE_MEMBER( ready_connect ); |
| 87 | DECLARE_WRITE_LINE_MEMBER( clock_out ); |
| 88 | |
| 82 | 89 | // Some values to keep |
| 83 | 90 | int m_mode; |
| 84 | | device_t *m_cpu; |
| 85 | | tms9901_device *m_tms9901; |
| 86 | | gromport_device *m_gromport; |
| 87 | | peribox_device *m_peribox; |
| 88 | | mecmouse_device *m_mecmouse; |
| 89 | | ti99_handset_device *m_handset; |
| 91 | tms9900_device* m_cpu; |
| 92 | tms9901_device* m_tms9901; |
| 93 | gromport_device* m_gromport; |
| 94 | peribox_device* m_peribox; |
| 95 | mecmouse_device* m_mecmouse; |
| 96 | ti99_handset_device* m_handset; |
| 97 | ti99_datamux_device* m_datamux; |
| 90 | 98 | |
| 99 | int m_ready_line, m_ready_line1; |
| 100 | |
| 91 | 101 | // Connections with the system interface TMS9901 |
| 92 | 102 | DECLARE_READ8_MEMBER(read_by_9901); |
| 93 | 103 | DECLARE_WRITE_LINE_MEMBER(keyC0); |
| r15423 | r15424 | |
| 102 | 112 | DECLARE_WRITE_LINE_MEMBER(alphaW); |
| 103 | 113 | |
| 104 | 114 | private: |
| 105 | | void set_key(int number, int data); |
| 106 | | int m_keyboard_column; |
| 107 | | int m_alphalock_line; |
| 115 | void set_key(int number, int data); |
| 116 | int m_keyboard_column; |
| 117 | int m_alphalock_line; |
| 108 | 118 | }; |
| 109 | 119 | |
| 110 | 120 | /* |
| 111 | | Memory map |
| 121 | Memory map. |
| 122 | Most of the work is done in the datamux (see datamux.c). We only keep ROM |
| 123 | and the small 256 byte PAD RAM here because they are directly connected |
| 124 | to the 16bit bus, and the wait state logic is not active during their |
| 125 | accesses. |
| 112 | 126 | */ |
| 113 | 127 | static ADDRESS_MAP_START(memmap, AS_PROGRAM, 16, ti99_4x) |
| 114 | 128 | ADDRESS_MAP_GLOBAL_MASK(0xffff) |
| 115 | | AM_RANGE(0x0000, 0x1fff) AM_ROM /*system ROM*/ |
| 116 | | AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAM /*RAM PAD, mirrored 4 times*/ |
| 117 | | AM_RANGE(0x8800, 0x8bff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_std_video_device, read16, nowrite) /*vdp read*/ |
| 118 | | AM_RANGE(0x8C00, 0x8fff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_std_video_device, noread, write16) /*vdp write*/ |
| 129 | AM_RANGE(0x0000, 0x1fff) AM_ROM |
| 130 | AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAM |
| 119 | 131 | AM_RANGE(0x0000, 0xffff) AM_DEVREADWRITE(DATAMUX_TAG, ti99_datamux_device, read, write) |
| 120 | 132 | ADDRESS_MAP_END |
| 121 | 133 | |
| 122 | | static ADDRESS_MAP_START(memmap_4ev, AS_PROGRAM, 16, ti99_4x) |
| 123 | | ADDRESS_MAP_GLOBAL_MASK(0xffff) |
| 124 | | AM_RANGE(0x0000, 0x1fff) AM_ROM /*system ROM*/ |
| 125 | | AM_RANGE(0x8000, 0x80ff) AM_MIRROR(0x0300) AM_RAM /*RAM PAD, mirrored 4 times*/ |
| 126 | | AM_RANGE(0x8800, 0x8bff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_exp_video_device, read16, nowrite) /*vdp read*/ |
| 127 | | AM_RANGE(0x8C00, 0x8fff) AM_DEVREADWRITE(VIDEO_SYSTEM_TAG, ti_exp_video_device, noread, write16) /*vdp write*/ |
| 128 | | AM_RANGE(0x0000, 0xffff) AM_DEVREADWRITE(DATAMUX_TAG, ti99_datamux_device, read, write) |
| 129 | | ADDRESS_MAP_END |
| 130 | | |
| 131 | 134 | /* |
| 132 | 135 | CRU map |
| 133 | 136 | TMS9900 CRU address space is 12 bits wide, attached to A3-A14, A0-A2 must |
| r15423 | r15424 | |
| 334 | 337 | |
| 335 | 338 | static GROM_CONFIG(grom0_config) |
| 336 | 339 | { |
| 337 | | false, 0, region_grom, 0x0000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready) |
| 340 | false, 0, region_grom, 0x0000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready), GROMFREQ |
| 338 | 341 | }; |
| 339 | 342 | |
| 340 | 343 | static GROM_CONFIG(grom1_config) |
| 341 | 344 | { |
| 342 | | false, 1, region_grom, 0x2000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready) |
| 345 | false, 1, region_grom, 0x2000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready), GROMFREQ |
| 343 | 346 | }; |
| 344 | 347 | |
| 345 | 348 | static GROM_CONFIG(grom2_config) |
| 346 | 349 | { |
| 347 | | false, 2, region_grom, 0x4000, 0x1800, false, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready) |
| 350 | false, 2, region_grom, 0x4000, 0x1800, DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready), GROMFREQ |
| 348 | 351 | }; |
| 349 | 352 | |
| 350 | 353 | static GROMPORT_CONFIG(console_cartslot) |
| r15423 | r15424 | |
| 376 | 379 | |
| 377 | 380 | WRITE8_MEMBER( ti99_4x::cruwrite ) |
| 378 | 381 | { |
| 379 | | // if (VERBOSE>6) LOG("write access to CRU address %04x\n", offset << 1); |
| 382 | if (VERBOSE>6) LOG("write access to CRU address %04x\n", offset << 1); |
| 380 | 383 | m_gromport->cruwrite(offset<<1, data); |
| 381 | 384 | m_peribox->cruwrite(offset<<1, data); |
| 382 | 385 | } |
| 383 | 386 | |
| 387 | WRITE8_MEMBER( ti99_4x::external_operation ) |
| 388 | { |
| 389 | static const char* extop[8] = { "inv1", "inv2", "IDLE", "RSET", "inv3", "CKON", "CKOF", "LREX" }; |
| 390 | if (VERBOSE>1) LOG("External operation %s not implemented on TI-99 board\n", extop[offset]); |
| 391 | } |
| 392 | |
| 384 | 393 | /*************************************************************************** |
| 385 | 394 | TI99/4x-specific tms9901 I/O handlers |
| 386 | 395 | |
| r15423 | r15424 | |
| 412 | 421 | READ8_MEMBER( ti99_4x::read_by_9901 ) |
| 413 | 422 | { |
| 414 | 423 | int answer=0; |
| 415 | | |
| 416 | 424 | switch (offset & 0x03) |
| 417 | 425 | { |
| 418 | 426 | case TMS9901_CB_INT7: |
| r15423 | r15424 | |
| 591 | 599 | WRITE8_MEMBER( ti99_4x::tms9901_interrupt ) |
| 592 | 600 | { |
| 593 | 601 | // offset contains the interrupt level (0-15) |
| 594 | | if (data==ASSERT_LINE) |
| 595 | | { |
| 596 | | // The TMS9901 should normally be connected with the CPU by 5 wires: |
| 597 | | // INTREQ* and IC0-IC3. The last four lines deliver the interrupt level. |
| 598 | | // On the TI-99 systems these IC lines are not used; the input lines |
| 599 | | // at the CPU are hardwired to level 1. |
| 600 | | device_execute(m_cpu)->set_input_line_and_vector(0, ASSERT_LINE, 1); |
| 601 | | } |
| 602 | | else |
| 603 | | { |
| 604 | | device_execute(m_cpu)->set_input_line(0, CLEAR_LINE); |
| 605 | | } |
| 602 | // However, the TI board just ignores that level and hardwires it to 1 |
| 603 | // See below (interrupt_level) |
| 604 | m_cpu->set_input_line(0, data); |
| 606 | 605 | } |
| 607 | 606 | |
| 607 | READ8_MEMBER( ti99_4x::interrupt_level ) |
| 608 | { |
| 609 | // On the TI-99 systems these IC lines are not used; the input lines |
| 610 | // at the CPU are hardwired to level 1. |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | Clock line from the CPU. Used to control wait state generation. |
| 616 | */ |
| 617 | WRITE_LINE_MEMBER( ti99_4x::clock_out ) |
| 618 | { |
| 619 | m_datamux->clock_in(state); |
| 620 | } |
| 621 | |
| 608 | 622 | /*****************************************************************************/ |
| 609 | 623 | |
| 610 | 624 | /* |
| r15423 | r15424 | |
| 633 | 647 | Links to external devices |
| 634 | 648 | ***********************************************************/ |
| 635 | 649 | |
| 636 | | |
| 650 | /* |
| 651 | We may have lots of devices pulling down this line; so we should use a AND |
| 652 | gate to do it right. On the other hand, when READY is down, there is just |
| 653 | no chance to make another device pull down the same line; the CPU just |
| 654 | won't access any other device in this time. |
| 655 | */ |
| 637 | 656 | WRITE_LINE_MEMBER( ti99_4x::console_ready ) |
| 638 | 657 | { |
| 639 | | if (VERBOSE>6) LOG("READY line set ... not yet connected, level=%02x\n", state); |
| 658 | if (VERBOSE>6) LOG("ti99_4x: READY level = %02x\n", state); |
| 659 | m_ready_line = state; |
| 660 | |
| 661 | m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE); |
| 640 | 662 | } |
| 641 | 663 | |
| 664 | /* |
| 665 | The exception of the above rule. Memory access over the datamux also operates |
| 666 | the READY line, and the datamux raises READY depending on the clock pulse. |
| 667 | So we must make sure this does not interfere. |
| 668 | */ |
| 669 | WRITE_LINE_MEMBER( ti99_4x::console_ready_dmux ) |
| 670 | { |
| 671 | if (VERBOSE>6) LOG("ti99_4x: READY dmux level = %02x\n", state); |
| 672 | m_ready_line1 = state; |
| 673 | m_cpu->set_ready((m_ready_line == ASSERT_LINE && m_ready_line1 == ASSERT_LINE)? ASSERT_LINE : CLEAR_LINE); |
| 674 | } |
| 675 | |
| 642 | 676 | WRITE_LINE_MEMBER( ti99_4x::extint ) |
| 643 | 677 | { |
| 644 | | if (VERBOSE>6) LOG("EXTINT level = %02x\n", state); |
| 678 | if (VERBOSE>6) LOG("ti99_4x: EXTINT level = %02x\n", state); |
| 645 | 679 | if (m_tms9901 != NULL) |
| 646 | 680 | m_tms9901->set_single_int(1, state); |
| 647 | 681 | } |
| 648 | 682 | |
| 649 | 683 | WRITE_LINE_MEMBER( ti99_4x::notconnected ) |
| 650 | 684 | { |
| 651 | | if (VERBOSE>6) LOG("Setting a not connected line ... ignored\n"); |
| 685 | if (VERBOSE>6) LOG("ti99_4x: Setting a not connected line ... ignored\n"); |
| 652 | 686 | } |
| 653 | 687 | |
| 654 | 688 | /*****************************************************************************/ |
| r15423 | r15424 | |
| 737 | 771 | */ |
| 738 | 772 | static const dmux_device_list_entry dmux_devices[] = |
| 739 | 773 | { |
| 774 | { VIDEO_SYSTEM_TAG, 0x8800, 0xfc01, 0x0400, NULL, 0, 0 }, |
| 740 | 775 | { GROM0_TAG, 0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 }, |
| 741 | 776 | { GROM1_TAG, 0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 }, |
| 742 | 777 | { GROM2_TAG, 0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 }, |
| r15423 | r15424 | |
| 747 | 782 | { NULL, 0, 0, 0, NULL, 0, 0 } |
| 748 | 783 | }; |
| 749 | 784 | |
| 785 | static const dmux_device_list_entry dmux_devices_ev[] = |
| 786 | { |
| 787 | { V9938_SYSTEM_TAG, 0x8800, 0xfc01, 0x0400, NULL, 0, 0 }, |
| 788 | { GROM0_TAG, 0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 }, |
| 789 | { GROM1_TAG, 0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 }, |
| 790 | { GROM2_TAG, 0x9800, 0xfc01, 0x0400, "GROMENA", 0x01, 0x00 }, |
| 791 | { TISOUND_TAG, 0x8400, 0xfc01, 0x0000, NULL, 0, 0 }, |
| 792 | { GROMPORT_TAG, 0x9800, 0xfc01, 0x0400, NULL, 0, 0 }, |
| 793 | { GROMPORT_TAG, 0x6000, 0xe000, 0x0000, NULL, 0, 0 }, |
| 794 | { PERIBOX_TAG, 0x0000, 0x0000, 0x0000, NULL, 0, 0 }, // Peribox needs all addresses |
| 795 | { NULL, 0, 0, 0, NULL, 0, 0 } |
| 796 | }; |
| 797 | |
| 798 | static DMUX_CONFIG( datamux_conf ) |
| 799 | { |
| 800 | DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready_dmux), // READY |
| 801 | dmux_devices |
| 802 | }; |
| 803 | |
| 804 | static DMUX_CONFIG( datamux_conf_ev ) |
| 805 | { |
| 806 | DEVCB_DRIVER_LINE_MEMBER(ti99_4x, console_ready_dmux), // READY |
| 807 | dmux_devices_ev |
| 808 | }; |
| 809 | |
| 810 | static TMS9900_CONFIG( ti99_cpuconf ) |
| 811 | { |
| 812 | DEVCB_DRIVER_MEMBER(ti99_4x, external_operation), |
| 813 | DEVCB_DRIVER_MEMBER(ti99_4x, interrupt_level), |
| 814 | DEVCB_NULL, // Instruction acquisition |
| 815 | DEVCB_DRIVER_LINE_MEMBER(ti99_4x, clock_out), |
| 816 | DEVCB_NULL, // wait |
| 817 | DEVCB_NULL // Hold acknowledge |
| 818 | }; |
| 819 | |
| 750 | 820 | /****************************************************************************** |
| 751 | 821 | Machine definitions |
| 752 | 822 | ******************************************************************************/ |
| r15423 | r15424 | |
| 756 | 826 | ti99_4x *driver = machine.driver_data<ti99_4x>(); |
| 757 | 827 | driver->m_mode = TI994; |
| 758 | 828 | |
| 759 | | driver->m_cpu = machine.device("maincpu"); |
| 829 | driver->m_cpu = static_cast<tms9900_device*>(machine.device("maincpu")); |
| 760 | 830 | driver->m_tms9901 = static_cast<tms9901_device*>(machine.device(TMS9901_TAG)); |
| 761 | 831 | |
| 762 | 832 | driver->m_gromport = static_cast<gromport_device*>(machine.device(GROMPORT_TAG)); |
| 763 | 833 | |
| 764 | 834 | driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG)); |
| 835 | driver->m_datamux = static_cast<ti99_datamux_device*>(machine.device(DATAMUX_TAG)); |
| 765 | 836 | |
| 766 | 837 | driver->m_peribox->senila(CLEAR_LINE); |
| 767 | 838 | driver->m_peribox->senilb(CLEAR_LINE); |
| 839 | |
| 840 | driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE; |
| 768 | 841 | } |
| 769 | 842 | |
| 770 | 843 | MACHINE_RESET( ti99_4 ) |
| r15423 | r15424 | |
| 785 | 858 | TI-99/4 - the predecessor of the more popular TI-99/4A |
| 786 | 859 | */ |
| 787 | 860 | static MACHINE_CONFIG_START( ti99_4_60hz, ti99_4x ) |
| 788 | | MCFG_CPU_ADD("maincpu", TMS9900, 3000000) |
| 789 | | MCFG_CPU_PROGRAM_MAP(memmap) |
| 790 | | MCFG_CPU_IO_MAP(cru_map) |
| 861 | /* CPU */ |
| 862 | MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf) |
| 863 | |
| 791 | 864 | MCFG_MACHINE_START( ti99_4 ) |
| 792 | 865 | MCFG_MACHINE_RESET( ti99_4 ) |
| 793 | 866 | |
| r15423 | r15424 | |
| 795 | 868 | |
| 796 | 869 | /* Main board */ |
| 797 | 870 | MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4, 3000000) |
| 798 | | MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices ) |
| 871 | MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf ) |
| 799 | 872 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 800 | 873 | |
| 801 | 874 | /* Software list */ |
| r15423 | r15424 | |
| 830 | 903 | MACHINE_CONFIG_END |
| 831 | 904 | |
| 832 | 905 | static MACHINE_CONFIG_START( ti99_4_50hz, ti99_4x ) |
| 833 | | MCFG_CPU_ADD("maincpu", TMS9900, 3000000) |
| 834 | | MCFG_CPU_PROGRAM_MAP(memmap) |
| 835 | | MCFG_CPU_IO_MAP(cru_map) |
| 906 | /* CPU */ |
| 907 | MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf) |
| 908 | |
| 836 | 909 | MCFG_MACHINE_START( ti99_4 ) |
| 837 | 910 | MCFG_MACHINE_RESET( ti99_4 ) |
| 838 | 911 | |
| r15423 | r15424 | |
| 841 | 914 | |
| 842 | 915 | /* main board */ |
| 843 | 916 | MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4, 3000000) |
| 844 | | MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices ) |
| 917 | MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf ) |
| 845 | 918 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 846 | 919 | |
| 847 | 920 | /* Software list */ |
| r15423 | r15424 | |
| 882 | 955 | ti99_4x *driver = machine.driver_data<ti99_4x>(); |
| 883 | 956 | driver->m_mode = TI994A; |
| 884 | 957 | |
| 885 | | driver->m_cpu = machine.device("maincpu"); |
| 958 | driver->m_cpu = static_cast<tms9900_device*>(machine.device("maincpu")); |
| 886 | 959 | driver->m_tms9901 = static_cast<tms9901_device*>(machine.device(TMS9901_TAG)); |
| 887 | 960 | |
| 888 | 961 | driver->m_mecmouse = static_cast<mecmouse_device*>(machine.device(MECMOUSE_TAG)); |
| 889 | 962 | driver->m_gromport = static_cast<gromport_device*>(machine.device(GROMPORT_TAG)); |
| 890 | 963 | driver->m_peribox = static_cast<peribox_device*>(machine.device(PERIBOX_TAG)); |
| 891 | 964 | |
| 965 | driver->m_datamux = static_cast<ti99_datamux_device*>(machine.device(DATAMUX_TAG)); |
| 966 | |
| 892 | 967 | driver->m_peribox->senila(CLEAR_LINE); |
| 893 | 968 | driver->m_peribox->senilb(CLEAR_LINE); |
| 969 | driver->m_ready_line = driver->m_ready_line1 = ASSERT_LINE; |
| 894 | 970 | } |
| 895 | 971 | |
| 896 | 972 | MACHINE_RESET( ti99_4a ) |
| r15423 | r15424 | |
| 903 | 979 | } |
| 904 | 980 | |
| 905 | 981 | static MACHINE_CONFIG_START( ti99_4a_60hz, ti99_4x ) |
| 906 | | MCFG_CPU_ADD("maincpu", TMS9900, 3000000) |
| 907 | | MCFG_CPU_PROGRAM_MAP(memmap) |
| 908 | | MCFG_CPU_IO_MAP(cru_map) |
| 982 | /* CPU */ |
| 983 | MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf) |
| 984 | |
| 909 | 985 | MCFG_MACHINE_START( ti99_4a ) |
| 910 | 986 | MCFG_MACHINE_RESET( ti99_4a ) |
| 911 | 987 | |
| r15423 | r15424 | |
| 914 | 990 | |
| 915 | 991 | /* Main board */ |
| 916 | 992 | MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4a, 3000000) |
| 917 | | MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices ) |
| 993 | MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf ) |
| 918 | 994 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 919 | 995 | |
| 920 | 996 | /* Software list */ |
| r15423 | r15424 | |
| 946 | 1022 | MACHINE_CONFIG_END |
| 947 | 1023 | |
| 948 | 1024 | static MACHINE_CONFIG_START( ti99_4a_50hz, ti99_4x ) |
| 949 | | MCFG_CPU_ADD("maincpu", TMS9900, 3000000) |
| 950 | | MCFG_CPU_PROGRAM_MAP(memmap) |
| 951 | | MCFG_CPU_IO_MAP(cru_map) |
| 1025 | /* CPU */ |
| 1026 | MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf) |
| 1027 | |
| 952 | 1028 | MCFG_MACHINE_START( ti99_4a ) |
| 953 | 1029 | MCFG_MACHINE_RESET( ti99_4a ) |
| 954 | 1030 | |
| r15423 | r15424 | |
| 957 | 1033 | |
| 958 | 1034 | /* Main board */ |
| 959 | 1035 | MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4a, 3000000) |
| 960 | | MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices ) |
| 1036 | MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf ) |
| 961 | 1037 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 962 | 1038 | |
| 963 | 1039 | /* Software list */ |
| r15423 | r15424 | |
| 999 | 1075 | replacing the console video processor. |
| 1000 | 1076 | */ |
| 1001 | 1077 | static MACHINE_CONFIG_START( ti99_4ev_60hz, ti99_4x ) |
| 1002 | | MCFG_CPU_ADD("maincpu", TMS9900, 3000000) |
| 1003 | | MCFG_CPU_PROGRAM_MAP(memmap_4ev) |
| 1004 | | MCFG_CPU_IO_MAP(cru_map) |
| 1078 | /* CPU */ |
| 1079 | MCFG_TMS9900_ADD("maincpu", TMS9900, 3000000, memmap, cru_map, ti99_cpuconf) |
| 1080 | |
| 1005 | 1081 | MCFG_MACHINE_START( ti99_4a ) |
| 1006 | 1082 | |
| 1007 | | /* Video hardware */ |
| 1008 | | // FIXME: (MZ) Lowered the screen rate to 30 Hz. This is a quick hack to |
| 1009 | | // restore normal video speed for V9938-based systems until the V9938 implementation |
| 1010 | | // is properly fixed. |
| 1011 | | MCFG_TI_V9938_ADD(VIDEO_SYSTEM_TAG, 30, SCREEN_TAG, 2500, 512+32, (212+28)*2, DEVICE_SELF, ti99_4x, set_tms9901_INT2_from_v9938) |
| 1083 | /* video hardware */ |
| 1084 | // Although we should have a 60 Hz screen rate, we have to set it to 30 here. |
| 1085 | // The reason is that that the number of screen lines is counted twice for the |
| 1086 | // interlace mode, but in non-interlace modes only half of the lines are |
| 1087 | // painted. Accordingly, the full set of lines is refreshed at 30 Hz, |
| 1088 | // not 60 Hz. This should be fixed in the v9938 emulation. |
| 1089 | MCFG_TI_V9938_ADD(V9938_SYSTEM_TAG, 30, SCREEN_TAG, 2500, 512+32, (212+28)*2, DEVICE_SELF, ti99_4x, set_tms9901_INT2_from_v9938) |
| 1012 | 1090 | MCFG_TIMER_ADD_SCANLINE("scantimer", ti99_4ev_hblank_interrupt, SCREEN_TAG, 0, 1) |
| 1013 | 1091 | |
| 1014 | 1092 | /* Main board */ |
| 1015 | 1093 | MCFG_TMS9901_ADD(TMS9901_TAG, tms9901_wiring_ti99_4a, 3000000) |
| 1016 | | MCFG_DMUX_ADD( DATAMUX_TAG, dmux_devices ) |
| 1094 | MCFG_DMUX_ADD( DATAMUX_TAG, datamux_conf_ev ) |
| 1017 | 1095 | MCFG_TI99_GROMPORT_ADD( GROMPORT_TAG, console_cartslot ) |
| 1018 | 1096 | |
| 1019 | 1097 | /* Software list */ |