Previous 15994 Revisions Next

r15462 Thursday 14th June, 2012 at 16:04:31 UTC by Michael Zapf
Re-implementation of TMS9980A for cycle-precise processing; changed
tms9900.c to allow subclassing TMS9900 and TMS9980A from a common
parent. [Michael Zapf]
[src/emu/cpu/tms9900]tms9900.c tms9900.h tms9980a.c tms9980a.h*

src/emu/cpu/tms9900/tms9980a.c
r15461r15462
11/*
2    This file will contain the re-implementation of the tms9980a. The
3    previous implementation can be found as tms9980al.
2    Cycle-precise implementation of the TMS9980A.
3    Subclassed from tms99xx_device in tms9900.c.
4
5                    +----------------+
6              /HOLD | 1     \/     40| /MEMEN
7              HOLDA | 2            39| READY
8                IAQ | 3            38| /WE
9  LSB +- A13,CRUOUT | 4            37| CRUCLK
10      |         A12 | 5            36| Vdd
11      |         A11 | 6            35| Vss
12      |         A10 | 7            34| CKIN
13   Address       A9 | 8            33| D7      --+
14     bus         A8 | 9            32| D6        |
15      |          A7 |10            31| D5       Data
16    16KiB        A6 |11            30| D4       bus
17      |          A5 |12            29| D3        |
18      |          A4 |13            28| D2       2 * 8 bit
19      |          A3 |14            27| D1        |
20      |          A2 |15            26| D0      --+
21      |          A1 |16            25| INT0    --+
22  MSB +--        A0 |17            24| INT1      | Interrupt levels
23               DBIN |18            23| INT2    --+
24              CRUIN |19            22| /PHI3
25                Vcc |20            21| Vbb
26                    +----------------+
27
28  The TMS9980A is similar to the TMS9900, with the following differences:
29
30    - Address bus is only 14 bit wide (16 KiB)
31    - Data bus is 16 bit wide and multiplexed on 8 lines (2 bytes per access)
32    - CRU space is limited to 2048 bits (due to fewer address lines)
33    - Only three interrupt level lines, for a maximum of 8 levels.
34    - No INTREQ, RESET, and LOAD lines. All interrupts are signaled via INT0 -
35      INT2. Reset=00x, Load=010, Level1=011, Level2=100, Level3=101, Level4=110,
36      all interrupts cleared=111.
37    - Memory accesses are always 2 bytes (even address byte, odd address byte)
38      even for byte operations. Thus the 9980A, like the TMS9900, needs to
39      pre-fetch the word at the destination before overwriting it.
40    - On the cycle level both TMS9900 and TMS9980A are equal, except for the
41      additional cycles needed for memory read and write access. Accordingly,
42      the emulation shares the core and the microprograms and redefines the
43      memory access and the interrupt handling only.
44    - The 9980A has the same external instructions as the TMS9900, but it
45      indicates the command via A0, A1, and A13 (instead of A0-A2).
46
47    For pin definitions see tms9900.c
48
49   Michael Zapf, 2012
450*/
51
52#include "tms9980a.h"
53
54#define LOG logerror
55#define VERBOSE 1
56
57/****************************************************************************
58    Constructor
59****************************************************************************/
60
61tms9980a_device::tms9980a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
62   : tms99xx_device(mconfig, TMS9980A, "TMS9980A", tag, 8, 14, 11, owner, clock)
63{
64}
65
66UINT16 tms9980a_device::read_workspace_register_debug(int reg)
67{
68   int temp = m_icount;
69   int addr = (WP+(reg<<1)) & 0xfffe & m_prgaddr_mask;
70   UINT16 value = (m_prgspace->read_byte(addr) << 8) | (m_prgspace->read_byte(addr+1) & 0xff);
71   m_icount = temp;
72   return value;
73}
74
75void tms9980a_device::write_workspace_register_debug(int reg, UINT16 data)
76{
77   int temp = m_icount;
78   int addr = (WP+(reg<<1)) & 0xfffe & m_prgaddr_mask;
79   m_prgspace->write_byte(addr, data>>8);
80   m_prgspace->write_byte(addr+1, data & 0xff);
81   m_icount = temp;
82}
83
84/*
85    Interrupt input. Keep in mind that the TMS9980A does not have any INTREQ
86    line but signals interrupts via IC0-IC2 only. Thus we cannot take down any
87    single interrupt; only all interrupts can be cleared at once using level 7.
88    The state parameter is actually not needed.
89*/
90void tms9980a_device::execute_set_input(int irqline, int state)
91{
92   m_irq_level = get_intlevel(state);
93
94   if (m_irq_level != 7)
95   {
96      if (m_irq_level == LOAD_INT)
97      {
98         // Clearing m_reset is a hack to prevent an initial RESET.
99         // Should fix that in tms99xx
100         m_reset = false;
101         m_load_state = true;
102      }
103      else m_irq_state = true;
104      if (VERBOSE>6) LOG("tms9980a: interrupt level=%d, ST=%04x\n", m_irq_level, ST);
105   }
106}
107
108int tms9980a_device::get_intlevel(int state)
109{
110   int level = m_get_intlevel(0) & 0x0007;
111
112   // Just to stay consistent.
113   if (state==CLEAR_LINE) level = 7;
114
115   switch (level)
116   {
117   case 0:
118   case 1:
119      level = RESET_INT;
120      m_reset = true;
121      break;
122   case 2:
123      level = LOAD_INT;
124      break;
125   case 3:
126   case 4:
127   case 5:
128   case 6:
129      level = level - 2;
130      break;
131   case 7:
132      // Clear all interrupts
133      m_load_state = false;
134      m_irq_state = false;
135      if (VERBOSE>6) LOG("tms9980a: clear interrupts\n");
136      break;
137   }
138   return level;
139}
140
141/*****************************************************************************/
142
143/*
144    Memory read:
145    Clock cycles: 4 + 2W, W = number of wait states
146*/
147void tms9980a_device::mem_read()
148{
149   UINT8 value;
150   if (m_lowbyte)
151   {
152      value = m_prgspace->read_byte((m_address & m_prgaddr_mask) | 1);
153      m_current_value = m_current_value | (value & 0x00ff);
154      if (VERBOSE>7) LOG("tms9980a: memory read low byte %04x -> complete word %04x\n", (m_address & m_prgaddr_mask) | 1, m_current_value);
155      m_lowbyte = false;
156   }
157   else
158   {
159      value = m_prgspace->read_byte(m_address & 0x3ffe);
160      if (VERBOSE>7) LOG("tms9980a: memory read high byte %04x -> %02x\n", m_address & m_prgaddr_mask, value);
161      m_current_value = (value << 8) & 0xff00;
162      m_lowbyte = true;
163      m_pass = 2;         // make the CPU visit this method once more
164   }
165   pulse_clock(2);
166   m_check_ready = true;
167}
168
169void tms9980a_device::mem_write()
170{
171   if (m_lowbyte)
172   {
173      m_prgspace->write_byte((m_address & 0x3ffe) | 1, m_current_value & 0xff);
174      if (VERBOSE>7) LOG("tms9980a: memory write low byte %04x <- %02x\n", (m_address & m_prgaddr_mask) | 1, m_current_value & 0xff);
175      m_lowbyte = false;
176   }
177   else
178   {
179      m_prgspace->write_byte(m_address & 0x3ffe, (m_current_value >> 8)&0xff);
180      if (VERBOSE>7) LOG("tms9980a: memory write high byte %04x <- %02x\n", m_address & m_prgaddr_mask, (m_current_value >> 8)&0xff);
181      m_lowbyte = true;
182      m_pass = 2;         // make the CPU visit this method once more
183   }
184   pulse_clock(2);
185   m_check_ready = true;
186}
187
188void tms9980a_device::acquire_instruction()
189{
190   if (!m_lowbyte)
191   {
192      m_iaq_line(ASSERT_LINE);
193      m_address = PC;
194      m_first_cycle = m_icount;
195      mem_read();
196   }
197   else
198   {
199      mem_read();
200      decode(m_current_value);
201      if (VERBOSE>3) LOG("tms9980a: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
202      debugger_instruction_hook(this, PC);
203      PC = (PC + 2) & 0xfffe & m_prgaddr_mask;
204   }
205   // IAQ will be cleared in the main loop
206}
207
208/**************************************************************************/
209UINT32 tms9980a_device::execute_min_cycles() const
210{
211   return 2;
212}
213
214// TODO: Compute this value, just a wild guess for the average
215UINT32 tms9980a_device::execute_max_cycles() const
216{
217   return 10;
218}
219
220UINT32 tms9980a_device::execute_input_lines() const
221{
222   return 1;
223}
224
225// clocks to cycles, cycles to clocks = id
226// execute_default_irq_vector = 0
227// execute_burn = nop
228
229// device_disasm_interface overrides
230UINT32 tms9980a_device::disasm_min_opcode_bytes() const
231{
232   return 2;
233}
234
235UINT32 tms9980a_device::disasm_max_opcode_bytes() const
236{
237   return 6;
238}
239
240offs_t tms9980a_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
241{
242   return Dasm9900(buffer, pc, TMS9980_ID, oprom, opram);
243}
244
245const device_type TMS9980A = &device_creator<tms9980a_device>;
src/emu/cpu/tms9900/tms9980a.h
r0r15462
1/*
2    TMS9980A.
3 
4    See tms9980a.c and tms9900.c for documentation
5*/
6 
7#ifndef __TMS9980A_H__
8#define __TMS9980A_H__
9 
10#include "emu.h"
11#include "debugger.h"
12#include "tms9900.h"
13 
14#define MCFG_TMS9980A_ADD(_tag, _device, _clock, _prgmap, _iomap, _config)      \
15   MCFG_DEVICE_ADD(_tag, _device, _clock )      \
16   MCFG_DEVICE_PROGRAM_MAP(_prgmap)         \
17   MCFG_DEVICE_IO_MAP(_iomap)               \
18   MCFG_DEVICE_CONFIG(_config)
19 
20#define TMS9980A_CONFIG(name) \
21   const tms9900_config(name) =
22 
23 
24class tms9980a_device : public tms99xx_device
25{
26public:
27   tms9980a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
28 
29protected:
30   void      mem_read(void);
31   void      mem_write(void);
32   void      acquire_instruction(void);
33 
34   UINT16      read_workspace_register_debug(int reg);
35   void      write_workspace_register_debug(int reg, UINT16 data);
36 
37   UINT32      execute_min_cycles() const;
38   UINT32      execute_max_cycles() const;
39   UINT32      execute_input_lines() const;
40   void      execute_set_input(int irqline, int state);
41 
42   UINT32      disasm_min_opcode_bytes() const;
43   UINT32      disasm_max_opcode_bytes() const;
44   offs_t      disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);
45   address_space_config   m_program_config80;
46   address_space_config   m_io_config80;
47 
48   int       get_intlevel(int state);
49};
50 
51// device type definition
52extern const device_type TMS9980A;
53 
54#endif /* __TMS9995_H__ */
src/emu/cpu/tms9900/tms9900.c
r15461r15462
117117   ST_IM = 0x000f      // Interrupt mask
118118};
119119
120enum
121{
122   LOAD_INT = -1,
123   RESET_INT = -2
124};
125
126120#define LOG logerror
127121#define VERBOSE 1
128122
129123/****************************************************************************
130    Constructor
124    Common constructor for TMS9900 and TMS9980A
125    The CRU mask is related to the bits, not to their addresses which are
126    twice their number. Accordingly, the TMS9900 has a CRU bitmask 0x0fff.
131127****************************************************************************/
132128
133tms9900_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),
129tms99xx_device::tms99xx_device(const machine_config &mconfig, device_type type,  const char *name, const char *tag, int databus_width, int prg_addr_bits, int cru_addr_bits, device_t *owner, UINT32 clock)
130   : cpu_device(mconfig, type, name, tag, owner, clock),
131     m_program_config("program", ENDIANNESS_BIG, databus_width, prg_addr_bits),
132     m_io_config("cru", ENDIANNESS_BIG, 8, cru_addr_bits),
137133     m_prgspace(NULL),
138     m_cru(NULL)
134     m_cru(NULL),
135     m_prgaddr_mask((1<<prg_addr_bits)-1),
136     m_cruaddr_mask((1<<cru_addr_bits)-1)
139137{
140138}
141139
140tms99xx_device::~tms99xx_device()
141{
142}
143
144/****************************************************************************
145    Constructor for TMS9900
146****************************************************************************/
147
148tms9900_device::tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
149   : tms99xx_device(mconfig, TMS9900, "TMS9900", tag, 16, 16, 12, owner, clock)
150{
151}
152
142153enum
143154{
144155   TMS9900_PC=0, TMS9900_WP, TMS9900_STATUS, TMS9900_IR,
r15461r15462
148159   TMS9900_R12, TMS9900_R13, TMS9900_R14, TMS9900_R15
149160};
150161
151void tms9900_device::device_start()
162void tms99xx_device::device_start()
152163{
153   const tms9900_config *conf = reinterpret_cast<const tms9900_config *>(static_config());
164   const tms99xx_config *conf = reinterpret_cast<const tms99xx_config *>(static_config());
154165
155166   assert (conf != NULL);
156167
r15461r15462
161172
162173   // Resolve our external connections
163174   m_external_operation.resolve(conf->external_callback, *this);
164   m_get_ic0123.resolve(conf->irq_level, *this);
175   m_get_intlevel.resolve(conf->irq_level, *this);
165176   m_iaq_line.resolve(conf->instruction_acquisition, *this);
166177   m_clock_out_line.resolve(conf->clock_out, *this);
167178   m_wait_line.resolve(conf->wait_line, *this);
r15461r15462
183194   build_command_lookup_table();
184195}
185196
186void tms9900_device::device_stop()
197void tms99xx_device::device_stop()
187198{
188199   int k = 0;
189   if (VERBOSE>8) LOG("tms9900: Deleting lookup tables\n");
200   if (VERBOSE>8) LOG("tms99xx: Deleting lookup tables\n");
190201   while (m_lotables[k]!=NULL) delete[] m_lotables[k++];
191202}
192203
r15461r15462
195206    The device reset is just the emulator's trigger for the reset procedure
196207    which is invoked via the main loop.
197208*/
198void tms9900_device::device_reset()
209void tms99xx_device::device_reset()
199210{
211   if (VERBOSE>3) LOG("tms99xx: Device reset\n");
200212   m_reset = true;
201213}
202214
203const char* tms9900_device::s_statename[20] =
215const char* tms99xx_device::s_statename[20] =
204216{
205217   "PC ", "WP ", "ST ", "IR ",
206218   "R0 ", "R1 ", "R2 ", "R3 ",
r15461r15462
212224/*
213225    Write the contents of a register by external input (debugger)
214226*/
215void tms9900_device::state_import(const device_state_entry &entry)
227void tms99xx_device::state_import(const device_state_entry &entry)
216228{
217229   int index = entry.index();
218230   switch (entry.index())
r15461r15462
222234         // bits of the STATUS register
223235         break;
224236      case TMS9900_PC:
225         PC = (UINT16)m_state_any;
237         PC = (UINT16)(m_state_any & m_prgaddr_mask);
226238         break;
227239      case TMS9900_WP:
228         WP = (UINT16)m_state_any;
240         WP = (UINT16)(m_state_any & m_prgaddr_mask);
229241         break;
230242      case TMS9900_STATUS:
231243         ST = (UINT16)m_state_any;
r15461r15462
244256/*
245257    Reads the contents of a register for display in the debugger.
246258*/
247void tms9900_device::state_export(const device_state_entry &entry)
259void tms99xx_device::state_export(const device_state_entry &entry)
248260{
249261   int index = entry.index();
250262   switch (entry.index())
r15461r15462
275287/*
276288    state_string_export - export state as a string for the debugger
277289*/
278void tms9900_device::state_string_export(const device_state_entry &entry, astring &string)
290void tms99xx_device::state_string_export(const device_state_entry &entry, astring &string)
279291{
280292   static const char *statestr = "LAECOPX-----IIII";
281293   char *flags = string.stringbuffer(16);
r15461r15462
292304
293305/**************************************************************************/
294306
295UINT16 tms9900_device::read_workspace_register_debug(int reg)
307UINT16 tms99xx_device::read_workspace_register_debug(int reg)
296308{
297309   int temp = m_icount;
298   UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & 0xfffe);
310   UINT16 value = m_prgspace->read_word((WP+(reg<<1)) & m_prgaddr_mask & 0xfffe);
299311   m_icount = temp;
300312   return value;
301313}
302314
303void tms9900_device::write_workspace_register_debug(int reg, UINT16 data)
315void tms99xx_device::write_workspace_register_debug(int reg, UINT16 data)
304316{
305317   int temp = m_icount;
306   m_prgspace->write_word((WP+(reg<<1)) & 0xfffe, data);
318   m_prgspace->write_word((WP+(reg<<1)) & m_prgaddr_mask & 0xfffe, data);
307319   m_icount = temp;
308320}
309321
310const address_space_config *tms9900_device::memory_space_config(address_spacenum spacenum) const
322const address_space_config *tms99xx_device::memory_space_config(address_spacenum spacenum) const
311323{
312324   switch (spacenum)
313325   {
r15461r15462
342354   MEMORY_WRITE,
343355   REG_READ,
344356   REG_WRITE,
345   CRU,            // 5
357   CRU_INPUT,
358   CRU_OUTPUT,
346359   DATA_DERIVE,
347360   RET,
361   ABORT,
348362   END,
363
349364   ALU_NOP,
350   ALU_CLR,         // 10
365   ALU_CLR,
351366   ALU_SETADDR,
352367   ALU_ADDONE,
353368   ALU_SETADDR_ADDONE,
354369   ALU_PCADDR_ADVANCE,
355   ALU_SOURCE,         // 15
370   ALU_SOURCE,
356371   ALU_ADDREG,
357372   ALU_IMM,
358373   ALU_REG,
359374   ALU_F1,
360   ALU_COMP,         // 20
375   ALU_COMP,
361376   ALU_F3,
362377   ALU_MPY,
363378   ALU_DIV,
364379   ALU_XOP,
365   ALU_CLR_SWPB,      // 25
380   ALU_CLR_SWPB,
366381   ALU_ABS,
367382   ALU_X,
368383   ALU_B,
369   ALU_BL,
370   ALU_BLWP,         // 30
384   ALU_BLWP,
371385   ALU_LDCR,
372386   ALU_STCR,
373387   ALU_SBZ_SBO,
374388   ALU_TB,
375   ALU_JMP,         // 35
389   ALU_JMP,
376390   ALU_SHIFT,
377391   ALU_AI_ORI,
378392   ALU_CI,
379393   ALU_LI,
380   ALU_LWPI,         // 40
394   ALU_LWPI,
381395   ALU_LIMI,
382396   ALU_STWP_STST,
383397   ALU_EXT,
384398   ALU_RTWP,
385   ALU_INT            // 45
399   ALU_INT
386400};
387401
388402
r15461r15462
436450   ALU_NOP,
437451   DATA_DERIVE,
438452   ALU_F3,
439   REG_READ,      // We have to distinguish this from the C/CB microprogram above
453   MEMORY_READ,   // We have to distinguish this from the C/CB microprogram above
440454   ALU_F3,
441455   ALU_NOP,      // Compare operations do not write back any data
442456   END
r15461r15462
447461   ALU_NOP,
448462   DATA_DERIVE,
449463   ALU_F3,
450   REG_READ,
464   MEMORY_READ,
451465   ALU_F3,
452   MEMORY_WRITE,   // XOR again must write back data
466   MEMORY_WRITE,   // XOR again must write back data, cannot reuse f3_mp
453467   END
454468};
455469
r15461r15462
458472   ALU_NOP,
459473   DATA_DERIVE,
460474   ALU_MPY,      // Save the value; put register number in m_regnumber
461   REG_READ,
475   MEMORY_READ,
462476   ALU_MPY,      // 18 cycles for multiplication
463   REG_WRITE,      // Write the high word
477   MEMORY_WRITE,      // Write the high word
464478   ALU_MPY,      // Get low word, increase m_address
465479   MEMORY_WRITE,
466480   END
r15461r15462
471485   ALU_NOP,
472486   DATA_DERIVE,   // Get divisor
473487   ALU_DIV,      // 0 Store divisor and get register number
474   REG_READ,      // Read register
488   MEMORY_READ,   // Read register
475489   ALU_DIV,      // 1 Check overflow, increase address (or abort here)
490   ABORT,
476491   MEMORY_READ,   // Read subsequent word (if reg=15 this is behind the workspace)
477492   ALU_DIV,      // 2 Calculate quotient (takes variable amount of cycles; at least 32 machine cycles), set register number
478   REG_WRITE,      // Write quotient into register
493   MEMORY_WRITE,   // Write quotient into register
479494   ALU_DIV,      // 3 Get remainder
480495   MEMORY_WRITE,   // Write remainder
481496   END
r15461r15462
488503   ALU_XOP,      // 0 Save the address of the source operand, set address = 0x0040 + xopNr*4
489504   MEMORY_READ,   // Read the new WP
490505   ALU_XOP,      // 1 Save old WP, set new WP, get the source operand address
491   REG_WRITE,      // Write the address of the source operand into the new R11
506   MEMORY_WRITE,   // Write the address of the source operand into the new R11
492507   ALU_XOP,      // 2
493   REG_WRITE,      // Write the ST into the new R15
508   MEMORY_WRITE,   // Write the ST into the new R15
494509   ALU_XOP,      // 3
495   REG_WRITE,      // Write the PC into the new R14
510   MEMORY_WRITE,   // Write the PC into the new R14
496511   ALU_XOP,      // 4
497   REG_WRITE,      // Write the WP into the new R13
512   MEMORY_WRITE,   // Write the WP into the new R13
498513   ALU_XOP,      // 5 Set the X bit in the ST
499514   MEMORY_READ,   // Read the new PC
500515   ALU_XOP,      // 6 Set the new PC
r15461r15462
541556{
542557   ALU_NOP,
543558   DATA_DERIVE,
544   ALU_BL,            // two cycles
545   REG_WRITE,
559   ALU_B,
560   MEMORY_WRITE,
561   ALU_NOP,
546562   END
547563};
548564
r15461r15462
551567   ALU_NOP,
552568   DATA_DERIVE,         // Get argument
553569   ALU_BLWP,            // 0 Save old WP, set new WP, save position
554   REG_WRITE,            // write ST to R15
570   MEMORY_WRITE,         // write ST to R15
555571   ALU_BLWP,            // 1
556   REG_WRITE,            // write PC to R14
572   MEMORY_WRITE,         // write PC to R14
557573   ALU_BLWP,            // 2
558   REG_WRITE,            // write WP to R13
574   MEMORY_WRITE,         // write WP to R13
559575   ALU_BLWP,            // 3 Get saved position
560576   MEMORY_READ,         // Read new PC
561577   ALU_BLWP,            // 4 Set new PC
r15461r15462
569585   ALU_SOURCE,
570586   ALU_NOP,
571587   ALU_LDCR,
572   REG_READ,
588   MEMORY_READ,
573589   ALU_LDCR,
574   CRU,
590   CRU_OUTPUT,
575591   ALU_NOP,
576592   END
577593};
r15461r15462
582598   DATA_DERIVE,
583599   ALU_SOURCE,         // Store address and value
584600   ALU_STCR,         // 0 Set register_number = 12
585   REG_READ,
601   MEMORY_READ,
586602   ALU_STCR,         // 1 Prepare CRU access
587   CRU,
603   CRU_INPUT,
588604   ALU_STCR,         // 2 Create result; Cycles = 5 + (8-#C-1) or + (16-#C)
589605   MEMORY_WRITE,
590606   END
r15461r15462
593609MICROPROGRAM(sbz_sbo_mp)
594610{
595611   ALU_SBZ_SBO,
596   REG_READ,
612   MEMORY_READ,
597613   ALU_SBZ_SBO,
598   CRU,
614   CRU_OUTPUT,
599615   END
600616};
601617
602618MICROPROGRAM(tb_mp)
603619{
604620   ALU_TB,
605   REG_READ,
621   MEMORY_READ,
606622   ALU_TB,
607   CRU,
623   CRU_INPUT,
608624   ALU_TB,
609625   END
610626};
r15461r15462
621637MICROPROGRAM(shift_mp)
622638{
623639   ALU_SHIFT,
624   REG_READ,
640   MEMORY_READ,
625641   ALU_SHIFT,
626   REG_READ,
642   MEMORY_READ,
627643   ALU_SHIFT,
628   REG_WRITE,
644   MEMORY_WRITE,
629645   END
630646};
631647
632648MICROPROGRAM(ai_ori_mp)
633649{
634650   ALU_REG,
635   REG_READ,
651   MEMORY_READ,
636652   ALU_IMM,
637653   MEMORY_READ,
638654   ALU_AI_ORI,
639   REG_WRITE,
655   MEMORY_WRITE,
640656   END
641657};
642658
643659MICROPROGRAM(ci_mp)
644660{
645661   ALU_REG,
646   REG_READ,
662   MEMORY_READ,
647663   ALU_IMM,
648664   MEMORY_READ,
649665   ALU_CI,
r15461r15462
657673   MEMORY_READ,
658674   ALU_LI,            // sets status bits
659675   ALU_REG,         // set register number
660   REG_WRITE,
676   MEMORY_WRITE,
661677   END
662678};
663679
r15461r15462
685701{
686702   ALU_STWP_STST,
687703   ALU_REG,
688   REG_WRITE,
704   MEMORY_WRITE,
689705   END
690706};
691707
r15461r15462
698714MICROPROGRAM(rtwp_mp)      // Problem: This makes RTWP use 8 instead of 7 machine cycles.
699715{
700716   ALU_RTWP,
701   REG_READ,
717   MEMORY_READ,
702718   ALU_RTWP,
703   REG_READ,
719   MEMORY_READ,
704720   ALU_RTWP,
705   REG_READ,
721   MEMORY_READ,
706722   ALU_RTWP,
707723   END
708724};
r15461r15462
713729   ALU_INT,            // 0 Set address = 0
714730   MEMORY_READ,
715731   ALU_INT,            // 1 Save old WP, set new WP, save position
716   REG_WRITE,            // write ST to R15
732   MEMORY_WRITE,         // write ST to R15
717733   ALU_INT,            // 2
718   REG_WRITE,            // write PC to R14
734   MEMORY_WRITE,         // write PC to R14
719735   ALU_INT,            // 3
720   REG_WRITE,            // write WP to R13
736   MEMORY_WRITE,         // write WP to R13
721737   ALU_INT,            // 4 Get saved position
722738   MEMORY_READ,         // Read new PC
723739   ALU_INT,            // 5 Set new PC
724740   END
725741};
726742
727const tms9900_device::ophandler tms9900_device::s_microoperation[] =
743const tms99xx_device::ophandler tms99xx_device::s_microoperation[] =
728744{
729   &tms9900_device::acquire_instruction,
730   &tms9900_device::mem_read,
731   &tms9900_device::mem_write,
732   &tms9900_device::register_read,
733   &tms9900_device::register_write,
734   &tms9900_device::cru_operation,
735   &tms9900_device::data_derivation_subprogram,
736   &tms9900_device::return_from_subprogram,
737   &tms9900_device::command_completed,
745   &tms99xx_device::acquire_instruction,
746   &tms99xx_device::mem_read,
747   &tms99xx_device::mem_write,
748   &tms99xx_device::register_read,
749   &tms99xx_device::register_write,
750   &tms99xx_device::cru_input_operation,
751   &tms99xx_device::cru_output_operation,
752   &tms99xx_device::data_derivation_subprogram,
753   &tms99xx_device::return_from_subprogram,
754   &tms99xx_device::abort_operation,
755   &tms99xx_device::command_completed,
738756
739   &tms9900_device::alu_nop,
740   &tms9900_device::alu_clear,
741   &tms9900_device::alu_setaddr,
742   &tms9900_device::alu_addone,
743   &tms9900_device::alu_setaddr_addone,
744   &tms9900_device::alu_pcaddr_advance,
745   &tms9900_device::alu_source,
746   &tms9900_device::alu_add_register,
747   &tms9900_device::alu_imm,
748   &tms9900_device::alu_reg,
757   &tms99xx_device::alu_nop,
758   &tms99xx_device::alu_clear,
759   &tms99xx_device::alu_setaddr,
760   &tms99xx_device::alu_addone,
761   &tms99xx_device::alu_setaddr_addone,
762   &tms99xx_device::alu_pcaddr_advance,
763   &tms99xx_device::alu_source,
764   &tms99xx_device::alu_add_register,
765   &tms99xx_device::alu_imm,
766   &tms99xx_device::alu_reg,
749767
750   &tms9900_device::alu_f1,
751   &tms9900_device::alu_comp,
752   &tms9900_device::alu_f3,
753   &tms9900_device::alu_multiply,
754   &tms9900_device::alu_divide,
755   &tms9900_device::alu_xop,
756   &tms9900_device::alu_clr_swpb,
757   &tms9900_device::alu_abs,
758   &tms9900_device::alu_x,
759   &tms9900_device::alu_b,
760   &tms9900_device::alu_bl,
761   &tms9900_device::alu_blwp,
762   &tms9900_device::alu_ldcr,
763   &tms9900_device::alu_stcr,
764   &tms9900_device::alu_sbz_sbo,
765   &tms9900_device::alu_tb,
766   &tms9900_device::alu_jmp,
767   &tms9900_device::alu_shift,
768   &tms9900_device::alu_ai_ori,
769   &tms9900_device::alu_ci,
770   &tms9900_device::alu_li,
771   &tms9900_device::alu_lwpi,
772   &tms9900_device::alu_limi,
773   &tms9900_device::alu_stwp_stst,
774   &tms9900_device::alu_external,
775   &tms9900_device::alu_rtwp,
776   &tms9900_device::alu_int
768   &tms99xx_device::alu_f1,
769   &tms99xx_device::alu_comp,
770   &tms99xx_device::alu_f3,
771   &tms99xx_device::alu_multiply,
772   &tms99xx_device::alu_divide,
773   &tms99xx_device::alu_xop,
774   &tms99xx_device::alu_clr_swpb,
775   &tms99xx_device::alu_abs,
776   &tms99xx_device::alu_x,
777   &tms99xx_device::alu_b,
778   &tms99xx_device::alu_blwp,
779   &tms99xx_device::alu_ldcr,
780   &tms99xx_device::alu_stcr,
781   &tms99xx_device::alu_sbz_sbo,
782   &tms99xx_device::alu_tb,
783   &tms99xx_device::alu_jmp,
784   &tms99xx_device::alu_shift,
785   &tms99xx_device::alu_ai_ori,
786   &tms99xx_device::alu_ci,
787   &tms99xx_device::alu_li,
788   &tms99xx_device::alu_lwpi,
789   &tms99xx_device::alu_limi,
790   &tms99xx_device::alu_stwp_stst,
791   &tms99xx_device::alu_external,
792   &tms99xx_device::alu_rtwp,
793   &tms99xx_device::alu_int
777794};
778795
779796/*****************************************************************************
r15461r15462
791808   JLT, JMP, JNC, JNE, JNO, JOC, JOP, LDCR, LI, LIMI,
792809   LREX, LWPI, MOV, MOVB, MPY, NEG, ORI, RSET, RTWP, S,
793810   SB, SBO, SBZ, SETO, SLA, SOC, SOCB, SRA, SRC, SRL,
794   STCR, STST, STWP, SWPB, SZC, SZCB, TB, X, XOP, XOR
811   STCR, STST, STWP, SWPB, SZC, SZCB, TB, X, XOP, XOR,
812   INTR
795813};
796814
797static 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
807815/*
808816    Formats:
809817
r15461r15462
838846   0, 4, 8, 6, 6, 8, 10, 16, 12, 6
839847};
840848
841const tms9900_device::tms_instruction tms9900_device::s_command[] =
849const tms99xx_device::tms_instruction tms99xx_device::s_command[] =
842850{
843851   // Opcode, ID, format, microprg
844852   { 0x0200, LI, 8, li_mp },
r15461r15462
947955    list at runtime, and many positions are empty. But we do not need more
948956    than 20 tables for the TMS command set.
949957*/
950void tms9900_device::build_command_lookup_table()
958void tms99xx_device::build_command_lookup_table()
951959{
952960   int i = 0;
953961   int cmdindex = 0;
r15461r15462
972980   {
973981      inst = &s_command[i];
974982      table = m_command_lookup_table;
975      if (VERBOSE>8) LOG("tms9900: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]);
983      if (VERBOSE>8) LOG("tms99xx: === opcode=%04x, len=%d\n", inst->opcode, format_mask_len[inst->format]);
976984      bitcount = 4;
977985      opcode = inst->opcode;
978986      cmdindex = (opcode>>12) & 0x000f;
r15461r15462
982990         // Descend
983991         if (table[cmdindex].next_digit == NULL)
984992         {
985            if (VERBOSE>8) LOG("tms9900: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex);
993            if (VERBOSE>8) LOG("tms99xx: create new table at bitcount=%d for index=%d\n", bitcount, cmdindex);
986994            table[cmdindex].next_digit = new lookup_entry[16];
987995            m_lotables[k++] = table[cmdindex].next_digit;
988996            for (int j=0; j < 16; j++)
r15461r15462
9931001         }
9941002         else
9951003         {
996            if (VERBOSE>8) LOG("tms9900: found a table at bitcount=%d\n", bitcount);
1004            if (VERBOSE>8) LOG("tms99xx: found a table at bitcount=%d\n", bitcount);
9971005         }
9981006
9991007         table = table[cmdindex].next_digit;
r15461r15462
10011009         bitcount = bitcount+4;
10021010         opcode <<= 4;
10031011         cmdindex = (opcode>>12) & 0x000f;
1004         if (VERBOSE>8) LOG("tms9900: next index=%x\n", cmdindex);
1012         if (VERBOSE>8) LOG("tms99xx: next index=%x\n", cmdindex);
10051013      }
10061014
1007      if (VERBOSE>8) LOG("tms9900: bitcount=%d\n", bitcount);
1015      if (VERBOSE>8) LOG("tms99xx: bitcount=%d\n", bitcount);
10081016      // We are at the target level
10091017      // Need to fill in the same entry for all values in the bitcount
10101018      // (if a command needs 10 bits we have to copy it four
10111019      // times for all combinations with 12 bits)
10121020      for (int j=0; j < (1<<(bitcount-format_mask_len[inst->format])); j++)
10131021      {
1014         if (VERBOSE>8) LOG("tms9900: opcode=%04x at position %d\n", inst->opcode, cmdindex+j);
1022         if (VERBOSE>8) LOG("tms99xx: opcode=%04x at position %d\n", inst->opcode, cmdindex+j);
10151023         table[cmdindex+j].entry = inst;
10161024      }
10171025
r15461r15462
10191027   } while (inst->opcode != 0xf000);
10201028
10211029   m_lotables[k++] = NULL;
1022   if (VERBOSE>8) LOG("tms9900: Allocated %d tables\n", k);
1030   if (VERBOSE>8) LOG("tms99xx: Allocated %d tables\n", k);
10231031}
10241032
10251033/*
r15461r15462
10581066    the CPU checks the READY line and waits until it is high. When READY
10591067    is high at a clock tick, the operation is complete on the next clock tick.
10601068*/
1061void tms9900_device::execute_run()
1069void tms99xx_device::execute_run()
10621070{
10631071   if (m_reset) service_interrupt();
10641072
1065   if (VERBOSE>6) LOG("tms9900: calling execute_run for %d cycles\n", m_icount);
1073   if (VERBOSE>6) LOG("tms99xx: calling execute_run for %d cycles\n", m_icount);
10661074   do
10671075   {
10681076      // Only when last instruction has completed
r15461r15462
10701078      {
10711079         if (m_load_state)
10721080         {
1073            if (VERBOSE>4) LOG("tms9900: load interrupt\n");
1081            if (VERBOSE>4) LOG("tms99xx: LOAD interrupt\n");
10741082            service_interrupt();
10751083         }
10761084         else
r15461r15462
10861094
10871095      if (m_program == NULL && m_idle_state)
10881096      {
1089         if (VERBOSE>5) LOG("tms9900: idle state\n");
1097         if (VERBOSE>5) LOG("tms99xx: idle state\n");
10901098         pulse_clock(1);
1099         m_external_operation(IDLE_OP, 0);
1100         m_external_operation(IDLE_OP, 1);
10911101      }
10921102      else
10931103      {
r15461r15462
11001110            m_program[MPC] != MEMORY_READ && m_program[MPC] != MEMORY_WRITE &&
11011111            m_program[MPC] != REG_READ && m_program[MPC] != REG_WRITE)))
11021112         {
1103            if (VERBOSE>5) LOG("tms9900: hold state\n");
1113            if (VERBOSE>5) LOG("tms99xx: hold state\n");
11041114            if (!m_hold_acknowledged) acknowledge_hold();
11051115            pulse_clock(1);
11061116         }
r15461r15462
11111121            {
11121122               // We are in a wait state
11131123               set_wait_state(true);
1114               if (VERBOSE>5) LOG("tms9900: wait state\n");
1124               if (VERBOSE>5) LOG("tms99xx: wait state\n");
11151125               // The clock output should be used to change the state of an outer
11161126               // device which operates the READY line
11171127               pulse_clock(1);
r15461r15462
11251135               else
11261136               {
11271137                  m_op = m_program[MPC];
1128                  m_iaq_line(CLEAR_LINE);
11291138               }
1130               if (VERBOSE>8) LOG("tms9900: MPC = %d, m_op = %d\n", MPC, m_op);
1139               if (VERBOSE>8) LOG("tms99xx: MPC = %d, m_op = %d\n", MPC, m_op);
11311140               // Call the operation of the microprogram
11321141               (this->*s_microoperation[m_op])();
1133               MPC++;
1142               // If we have multiple passes (as in the TMS9980)
1143               m_pass--;
1144               if (m_pass<=0)
1145               {
1146                  m_pass = 1;
1147                  MPC++;
1148                  m_iaq_line(CLEAR_LINE);
1149               }
11341150            }
11351151         }
11361152      }
11371153   } while (m_icount>0);
1138   if (VERBOSE>6) LOG("tms9900: cycles expired; will return soon.\n");
1154   if (VERBOSE>6) LOG("tms99xx: cycles expired; will return soon.\n");
11391155}
11401156
11411157/**************************************************************************/
r15461r15462
11431159/*
11441160    Interrupt input
11451161*/
1146void tms9900_device::execute_set_input(int irqline, int state)
1162void tms99xx_device::execute_set_input(int irqline, int state)
11471163{
11481164   if (irqline == INPUT_LINE_NMI)
11491165   {
r15461r15462
11551171      m_irq_state = (state==ASSERT_LINE);
11561172      if (state==ASSERT_LINE)
11571173      {
1158         m_irq_level = m_get_ic0123(0);
1159         if (VERBOSE>6) LOG("tms9900: interrupt line %d = %d, level=%d, ST=%04x\n", irqline, state, m_irq_level, ST);
1174         m_irq_level = get_intlevel(state);
1175         if (VERBOSE>6) LOG("tms99xx: interrupt line %d = %d, level=%d, ST=%04x\n", irqline, state, m_irq_level, ST);
11601176      }
11611177      else
11621178      {
1163         if (VERBOSE>6) LOG("tms9900: cleared interrupt line %d\n", irqline);
1179         if (VERBOSE>6) LOG("tms99xx: cleared interrupt line %d\n", irqline);
11641180      }
11651181   }
11661182}
11671183
1168void tms9900_device::service_interrupt()
1184/*
1185    This can be overloaded by variants of TMS99xx.
1186*/
1187int tms99xx_device::get_intlevel(int state)
11691188{
1189   return m_get_intlevel(0);
1190}
1191
1192void tms99xx_device::service_interrupt()
1193{
11701194   m_program = int_mp;
1171   MPC = 0;
1195   m_command = INTR;
11721196   m_idle_state = false;
1173   m_first_cycle = m_icount;
1197   m_external_operation(IDLE_OP, 0);
1198   m_lowbyte = false;
1199
11741200   m_state = 0;
1201
1202   // If reset, we just start with execution, otherwise we put the MPC
1203   // on the first microinstruction, which also means that the main loop shall
1204   // leave it where it is. So we pretend we have another pass to do.
1205   m_pass = m_reset? 1 : 2;
1206
11751207   if (m_reset)
11761208   {
1209      m_irq_level = RESET_INT;
1210
11771211      m_ready_state = true;
11781212      m_load_state = false;
11791213      m_hold_state = false;
r15461r15462
11831217      ST = 0;
11841218
11851219      m_reset = false;
1186      m_irq_level = RESET_INT;
11871220   }
1188   if (VERBOSE>6) LOG("tms9900: ********* triggered an interrupt on level %d\n", m_irq_level);
1221   if (VERBOSE>6) LOG("tms99xx: ********* triggered an interrupt on level %d\n", m_irq_level);
1222
1223   MPC = 0;
1224   m_first_cycle = m_icount;
11891225}
11901226
11911227/*
11921228    Issue a pulse on the clock line.
11931229*/
1194inline void tms9900_device::pulse_clock(int count)
1230void tms99xx_device::pulse_clock(int count)
11951231{
11961232   for (int i=0; i < count; i++)
11971233   {
11981234      m_clock_out_line(ASSERT_LINE);
11991235      m_clock_out_line(CLEAR_LINE);
12001236      m_icount--;                     // This is the only location where we count down the cycles.
1201      if (VERBOSE>7) LOG("tms9900: pulse_clock\n");
1237      if (VERBOSE>7) LOG("tms99xx: pulse_clock\n");
12021238   }
12031239}
12041240
12051241/*
12061242    Enter the hold state.
12071243*/
1208void tms9900_device::set_hold(int state)
1244void tms99xx_device::set_hold(int state)
12091245{
12101246   m_hold_state = (state==ASSERT_LINE);
12111247   if (!m_hold_state)
r15461r15462
12181254/*
12191255    Acknowledge the HOLD request.
12201256*/
1221inline void tms9900_device::acknowledge_hold()
1257inline void tms99xx_device::acknowledge_hold()
12221258{
12231259   m_hold_acknowledged = true;
12241260   m_holda_line(ASSERT_LINE);
r15461r15462
12271263/*
12281264    Signal READY to the CPU. When cleared, the CPU enters wait states.
12291265*/
1230void tms9900_device::set_ready(int state)
1266void tms99xx_device::set_ready(int state)
12311267{
12321268   m_ready_state = (state==ASSERT_LINE);
12331269}
12341270
1235void tms9900_device::abort_operation()
1271void tms99xx_device::abort_operation()
12361272{
12371273   command_completed();
12381274}
r15461r15462
12401276/*
12411277    Enter or leave the wait state. We only operate the WAIT line when there is a change.
12421278*/
1243inline void tms9900_device::set_wait_state(bool state)
1279inline void tms99xx_device::set_wait_state(bool state)
12441280{
12451281   if (m_wait_state != state) m_wait_line(state? ASSERT_LINE : CLEAR_LINE);
12461282   m_wait_state = state;
12471283}
12481284
12491285/*
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*/
1258UINT16 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*/
1276void 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/*
12851286    Acquire the next word as an instruction. The program counter advances by
12861287    one word.
12871288*/
1288void tms9900_device::decode(UINT16 inst)
1289void tms99xx_device::decode(UINT16 inst)
12891290{
12901291   int index = 0;
12911292   lookup_entry* table = m_command_lookup_table;
r15461r15462
13001301   while (!complete)
13011302   {
13021303      index = (opcode >> 12) & 0x000f;
1303      if (VERBOSE>8) LOG("tms9900: Check next hex digit of instruction %x\n", index);
1304      if (VERBOSE>8) LOG("tms99xx: Check next hex digit of instruction %x\n", index);
13041305      if (table[index].next_digit != NULL)
13051306      {
13061307         table = table[index].next_digit;
r15461r15462
13121313   if (decoded == NULL)
13131314   {
13141315      // not found
1315      if (VERBOSE>0) LOG("tms9900: Illegal opcode %04x\n", inst);
1316      if (VERBOSE>0) LOG("tms99xx: Illegal opcode %04x\n", inst);
13161317      IR = 0;
13171318      // This will cause another instruction acquisition in the next machine cycle
1318      // with an asserted IAQ line (can be used to detect this illegal opcode detection).
1319      // with an asserted IAQ line (can be used to indicate this illegal opcode detection).
13191320      m_program = NULL;
13201321   }
13211322   else
r15461r15462
13231324      m_program = decoded->prog;
13241325      MPC = -1;
13251326      m_command = decoded->id;
1326      if (VERBOSE>7) LOG("tms9900: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode);
1327      if (VERBOSE>7) LOG("tms99xx: Command decoded as id %d, %s, base opcode %04x\n", m_command, opname[m_command], decoded->opcode);
13271328   }
1329   m_pass = 1;
13281330}
13291331
1330inline bool tms9900_device::byte_operation()
1332inline bool tms99xx_device::byte_operation()
13311333{
13321334   return (IR & 0x1000)!=0;
13331335}
13341336
1335void tms9900_device::acquire_instruction()
1337void tms99xx_device::acquire_instruction()
13361338{
13371339   m_iaq_line(ASSERT_LINE);
13381340   m_address = PC;
13391341   m_first_cycle = m_icount;
13401342   mem_read();
13411343   decode(m_current_value);
1342   if (VERBOSE>3) LOG("tms9900: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
1344   if (VERBOSE>3) LOG("tms99xx: ===== Next operation %04x (%s) at %04x =====\n", IR, opname[m_command], PC);
13431345   debugger_instruction_hook(this, PC);
1344   PC = (PC + 2) & 0xfffe;
1346   PC = (PC + 2) & 0xfffe & m_prgaddr_mask;
13451347   // IAQ will be cleared in the main loop
13461348}
13471349
1348void tms9900_device::mem_read()
1350/*
1351    Memory read:
1352    1) Pulse clock (done above)
1353    2) Set address (we also get the value right here)
1354    3) Pulse clock
1355    4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP)
1356
1357    Clock cycles: 2 + W, W = number of wait states
1358*/
1359void tms99xx_device::mem_read()
13491360{
1350   m_current_value = pulse_and_read_memory(m_address);
1351   if (VERBOSE>7) LOG("tms9900: memory read %04x -> %04x\n", m_address, m_current_value);
1361   m_current_value = m_prgspace->read_word(m_address & m_prgaddr_mask & 0xfffe);
1362   pulse_clock(2);
1363   m_check_ready = true;
1364   if (VERBOSE>7) LOG("tms99xx: memory read %04x -> %04x\n", m_address, m_current_value);
13521365}
13531366
1354void tms9900_device::mem_write()
1367void tms99xx_device::mem_write()
13551368{
1356   pulse_and_write_memory(m_address, m_current_value);
1357   if (VERBOSE>7) LOG("tms9900: memory write %04x <- %04x\n", m_address, m_current_value);
1369   m_prgspace->write_word(m_address & m_prgaddr_mask & 0xfffe, m_current_value);
1370   pulse_clock(2);
1371   m_check_ready = true;
1372   if (VERBOSE>7) LOG("tms99xx: memory write %04x <- %04x\n", m_address, m_current_value);
13581373}
13591374
1360void tms9900_device::register_read()
1375void tms99xx_device::register_read()
13611376{
13621377   // Need to set m_address for F1/F3 (we don't know what the data_derive did)
13631378   m_address = WP + (m_regnumber<<1);
1364   m_register_contents = m_current_value = pulse_and_read_memory(m_address);
1365   if (VERBOSE>7) LOG("tms9900: register %d read (mem %04x) -> %04x\n", m_regnumber, m_address, m_current_value);
1379   mem_read();
1380   m_check_ready = true;
1381   m_register_contents = m_current_value;
13661382}
13671383
1368void tms9900_device::register_write()
1384/*
1385    Memory write:
1386    1) Pulse clock
1387    2) Set address and write (as in the real system)
1388    3) Pulse clock
1389    4) If READY=L (WAIT=H, GOTO 3) else (WAIT=L, STOP)
1390
1391    Clock cycles: 2 + W, W = number of wait states
1392*/
1393void tms99xx_device::register_write()
13691394{
1370   pulse_and_write_memory(WP + (m_regnumber<<1), m_current_value);
1371   if (VERBOSE>7) LOG("tms9900: register %d write (mem %04x) <- %04x\n", m_regnumber, WP + (m_regnumber<<1), m_current_value);
1395   UINT16 addr_save = m_address;
1396   m_address = (WP + (m_regnumber<<1)) & m_prgaddr_mask & 0xfffe;
1397   mem_write();
1398   m_check_ready = true;
1399   m_address = addr_save;
13721400}
13731401
13741402/*
r15461r15462
13981426       CRU write: First bit is at rightmost position of m_value.
13991427*/
14001428
1401
1402#define CRUREADMASK 0x01ff
1403#define CRUWRITEMASK 0x0fff
1404
1405void tms9900_device::cru_operation()
1429void tms99xx_device::cru_input_operation()
14061430{
14071431   int value, value1;
14081432   int offset, location;
14091433
1410   if (m_cru_output)
1434   location = (m_cru_address >> 4) & (m_cruaddr_mask>>3);
1435   offset   = (m_cru_address>>1) & 0x07;
1436
1437   // Read 8 bits (containing the desired bits)
1438   value = m_cru->read_byte(location);
1439
1440   if ((offset + m_count) > 8)   // spans two 8 bit cluster
14111441   {
1412      location = (m_cru_address >> 1)& CRUWRITEMASK;
1413      value = m_value;
1442      // Read next 8 bits
1443      location = (location + 1) & (m_cruaddr_mask>>3);
1444      value1 = m_cru->read_byte(location);
1445      value |= (value1 << 8);
14141446
1415      // Write m_count bits from cru_address
1416      for (int i=0; i < m_count; i++)
1447      if ((offset + m_count) > 16)   // spans three 8 bit cluster
14171448      {
1418         m_cru->write_byte(location, (value & 0x01));
1419         value >>= 1;
1420         location = (location + 1) & CRUWRITEMASK;
1421         pulse_clock(2);
1449         // Read next 8 bits
1450         location = (location + 1) & (m_cruaddr_mask>>3);
1451         value1 = m_cru->read_byte(location);
1452         value |= (value1 << 16);
14221453      }
14231454   }
1424   else
1425   {
1426      location = (m_cru_address >> 4)  & CRUREADMASK;
1427      offset   = (m_cru_address>>1) & 0x07;
14281455
1429      // Read 8 bits (containing the desired bits)
1430      value = m_cru->read_byte(location);
1456   // On each machine cycle (2 clocks) only one CRU bit is transmitted
1457   pulse_clock(m_count<<1);
14311458
1432      if ((offset + m_count) > 8)   // spans two 8 bit cluster
1433      {
1434         // Read next 8 bits
1435         location = (location + 1) & CRUREADMASK;
1436         value1 = m_cru->read_byte(location);
1437         value |= (value1 << 8);
1459   // Shift back the bits so that the first bit is at the rightmost place
1460   m_value = (value >> offset);
14381461
1439         if ((offset + m_count) > 16)   // spans three 8 bit cluster
1440         {
1441            // Read next 8 bits
1442            location = (location + 1) & CRUREADMASK;
1443            value1 = m_cru->read_byte(location);
1444            value |= (value1 << 16);
1445         }
1446      }
1462   // Mask out what we want
1463   m_value &= (0x0000ffff >> (16-m_count));
1464}
14471465
1448      // On each machine cycle (2 clocks) only one CRU bit is transmitted
1449      pulse_clock(m_count<<1);
1466void tms99xx_device::cru_output_operation()
1467{
1468   int value;
1469   int location;
1470   location = (m_cru_address >> 1) & m_cruaddr_mask;
1471   value = m_value;
14501472
1451      // Shift back the bits so that the first bit is at the rightmost place
1452      m_value = (value >> offset);
1453
1454      // Mask out what we want
1455      m_value &= (0x0000ffff >> (16-m_count));
1473   // Write m_count bits from cru_address
1474   for (int i=0; i < m_count; i++)
1475   {
1476      if (VERBOSE>5) LOG("tms99xx: CRU output operation, address %04x, value %d\n", location<<1, value & 0x01);
1477      m_cru->write_byte(location, (value & 0x01));
1478      value >>= 1;
1479      location = (location + 1) & m_cruaddr_mask;
1480      pulse_clock(2);
14561481   }
14571482}
14581483
1459void tms9900_device::return_from_subprogram()
1484void tms99xx_device::return_from_subprogram()
14601485{
14611486   // Return from data derivation
14621487   // The result should be in m_current_value
r15461r15462
14651490   MPC = m_caller_MPC; // will be increased on return
14661491}
14671492
1468void tms9900_device::command_completed()
1493void tms99xx_device::command_completed()
14691494{
14701495   // Pseudo state at the end of the current instruction cycle sequence
1471   if (VERBOSE>7)
1496   if (VERBOSE>4)
14721497   {
1498      LOG("tms99xx: +++++ Instruction %04x (%s) completed +++++\n", IR, opname[m_command]);
14731499      int cycles =  m_first_cycle - m_icount;
14741500      // Avoid nonsense values due to expired and resumed main loop
1475      if (cycles > 0 && cycles < 10000) LOG("tms9900: Instruction %04x (%s) consumed %d cycles\n", IR, opname[m_command], cycles);
1501      if (cycles > 0 && cycles < 10000) LOG("tms99xx: Consumed %d cycles\n", cycles);
14761502   }
14771503   m_program = NULL;
1504   m_lowbyte = false;
14781505}
14791506
14801507/*
r15461r15462
14821509    derivation. In terms of cycles, it does not take any time; execution
14831510    continues with the first instruction of the subprogram.
14841511*/
1485void tms9900_device::data_derivation_subprogram()
1512void tms99xx_device::data_derivation_subprogram()
14861513{
14871514   UINT16 ircopy = IR;
14881515
r15461r15462
15041531      MPC += 8;   // the second option
15051532   }
15061533   m_get_destination = true;   // when we call this the second time before END it's the destination
1507   MPC--;  // will be increased on return
1534   m_pass = 2;
15081535}
15091536
15101537
r15461r15462
15121539    Status bit operations
15131540**************************************************************************/
15141541
1515inline void tms9900_device::set_status_bit(int bit, bool state)
1542inline void tms99xx_device::set_status_bit(int bit, bool state)
15161543{
15171544   if (state) ST |= bit;
15181545   else ST &= ~bit;
15191546}
15201547
1521void tms9900_device::set_status_parity(UINT8 value)
1548void tms99xx_device::set_status_parity(UINT8 value)
15221549{
15231550   int count = 0;
15241551   for (int i=0; i < 8; i++)
r15461r15462
15291556   set_status_bit(ST_OP, (count & 1)!=0);
15301557}
15311558
1532inline void tms9900_device::compare_and_set_lae(UINT16 value1, UINT16 value2)
1559inline void tms99xx_device::compare_and_set_lae(UINT16 value1, UINT16 value2)
15331560{
15341561   set_status_bit(ST_EQ, value1 == value2);
15351562   set_status_bit(ST_LH, value1 > value2);
15361563   set_status_bit(ST_AGT, (INT16)value1 > (INT16)value2);
1537   if (VERBOSE>7) LOG("tms9900: ST = %04x (val1=%04x, val2=%04x)\n", ST, value1, value2);
1564   if (VERBOSE>7) LOG("tms99xx: ST = %04x (val1=%04x, val2=%04x)\n", ST, value1, value2);
15381565}
15391566
15401567/**************************************************************************
15411568    ALU operations
15421569**************************************************************************/
15431570
1544void tms9900_device::alu_nop()
1571void tms99xx_device::alu_nop()
15451572{
15461573   // Do nothing (or nothing that is externally visible)
15471574   pulse_clock(2);
15481575   return;
15491576}
15501577
1551void tms9900_device::alu_source()
1578void tms99xx_device::alu_source()
15521579{
15531580   // Copy the current value into the source data register
15541581   m_source_even = ((m_address & 1)==0);
r15461r15462
15571584   pulse_clock(2);
15581585}
15591586
1560void tms9900_device::alu_clear()
1587void tms99xx_device::alu_clear()
15611588{
15621589   // Clears the register contents
15631590   m_register_contents = 0;
15641591   pulse_clock(2);
15651592}
15661593
1567void tms9900_device::alu_setaddr()
1594void tms99xx_device::alu_setaddr()
15681595{
15691596   // Load the current value into the address register
15701597   m_address = m_current_value;
15711598   pulse_clock(2);
15721599}
15731600
1574void tms9900_device::alu_addone()
1601void tms99xx_device::alu_addone()
15751602{
15761603   m_current_value++;
15771604   pulse_clock(2);
15781605}
15791606
1580void tms9900_device::alu_setaddr_addone()
1607void tms99xx_device::alu_setaddr_addone()
15811608{
15821609   // Set the address register and increase the recent value
15831610   m_address = m_current_value;
r15461r15462
15851612   pulse_clock(2);
15861613}
15871614
1588void tms9900_device::alu_pcaddr_advance()
1615void tms99xx_device::alu_pcaddr_advance()
15891616{
15901617   // Set PC as new read address, increase by 2
15911618   m_address = PC;
1592   PC = (PC+2)&0xfffe;
1619   PC = (PC + 2) & 0xfffe & m_prgaddr_mask;
15931620   pulse_clock(2);
15941621}
15951622
1596void tms9900_device::alu_add_register()
1623void tms99xx_device::alu_add_register()
15971624{
15981625   // Add the register contents to the current value and set as address
15991626   m_address = m_current_value + m_register_contents;
16001627   pulse_clock(2);
16011628}
16021629
1603void tms9900_device::alu_imm()
1630void tms99xx_device::alu_imm()
16041631{
1605   if (VERBOSE>7) LOG("tms9900: Immediate operand, reading from position %04x\n", PC);
1632   if (VERBOSE>7) LOG("tms99xx: Immediate operand, reading from position %04x\n", PC);
1633   m_value_copy = m_current_value;
1634   m_address_copy = m_address;
16061635   m_address = PC;
1607   PC = (PC + 2) & 0xfffe;
1636   PC = (PC + 2) & 0xfffe & m_prgaddr_mask;
16081637   pulse_clock(2);
16091638}
16101639
1611void tms9900_device::alu_reg()
1640void tms99xx_device::alu_reg()
16121641{
1613   m_regnumber = IR & 0x000f;
1642   m_address = (WP + ((IR & 0x000f)<<1)) & m_prgaddr_mask;
16141643   pulse_clock(2);
16151644}
16161645
1617void tms9900_device::alu_f1()
1646void tms99xx_device::alu_f1()
16181647{
16191648   UINT32 dest_new = 0;
16201649
r15461r15462
17261755   pulse_clock(2);
17271756}
17281757
1729void tms9900_device::alu_comp()
1758void tms99xx_device::alu_comp()
17301759{
17311760   m_destination_even = ((m_address & 1)==0);   // this is the destination address; the source address has already been saved
17321761   if (byte_operation())
r15461r15462
17421771   pulse_clock(2);
17431772}
17441773
1745void tms9900_device::alu_f3()
1774void tms99xx_device::alu_f3()
17461775{
1747   if (m_state==0)
1776   switch (m_state)
17481777   {
1749      m_regnumber = (IR >> 6) & 0x000f;
1778   case 0:
1779      // Get register address
1780      m_address = WP + ((IR >> 5) & 0x001e);
17501781      m_source_value = m_current_value;
1751   }
1752   else
1753   {
1754      if (VERBOSE>7) LOG("tms9900: coc/czc/xor %04x with %04x\n", m_source_value, m_register_contents);
1755      switch (m_command)
1782      break;
1783   case 1:
1784      if (m_command == COC)
17561785      {
1757      case COC:
1758         set_status_bit(ST_EQ, (m_register_contents & m_source_value) == m_source_value);
1759         break;
1760      case CZC:
1761         set_status_bit(ST_EQ, (~m_register_contents & m_source_value) == m_source_value);
1762         break;
1763      case XOR:
1764         m_current_value = (m_register_contents ^ m_source_value);
1765         compare_and_set_lae(m_current_value, 0);
1766         break;
1786         set_status_bit(ST_EQ, (m_current_value & m_source_value) == m_source_value);
17671787      }
1788      else
1789      {
1790         if (m_command == CZC)
1791         {
1792            set_status_bit(ST_EQ, (~m_current_value & m_source_value) == m_source_value);
1793         }
1794         else
1795         {
1796            // XOR
1797            // The workspace register address is still in m_address
1798            m_current_value = (m_current_value ^ m_source_value);
1799            compare_and_set_lae(m_current_value, 0);
1800         }
1801      }
1802      if (VERBOSE>7) LOG("tms99xx: ST = %04x\n", ST);
1803      break;
17681804   }
1769   if (VERBOSE>7) LOG("tms9900: ST = %04x (log comp)\n", ST);
17701805
17711806   m_state++;
17721807   pulse_clock(2);
17731808}
17741809
1775void tms9900_device::alu_multiply()
1810void tms99xx_device::alu_multiply()
17761811{
1812   UINT32 result = 0;
1813
17771814   switch (m_state)
17781815   {
17791816   case 0: // After data derivation
17801817      m_source_value = m_current_value;
1781      m_regnumber = (IR >> 6)&0x000f;
1818      m_address = ((IR >> 5) & 0x001e) + WP;
17821819      break;
17831820   case 1: // After reading the register (multiplier)
1784      if (VERBOSE>7) LOG("tms9900: Multiply %04x by %04x\n", m_register_contents, m_source_value);
1785      m_value = m_register_contents * m_source_value;
1786      m_current_value = (m_value >> 16) & 0xffff;
1787      m_value = m_value & 0xffff;                  // Save low word in m_value
1821      if (VERBOSE>7) LOG("tms99xx: Multiply %04x by %04x\n", m_current_value, m_source_value);
1822      result = (m_source_value & 0x0000ffff) * (m_current_value & 0x0000ffff);
1823      m_current_value = (result >> 16) & 0xffff;
1824      m_value_copy = result & 0xffff;
17881825      pulse_clock(34);                        // add 36 clock cycles (18 machine cycles); last one in main loop
17891826      break;
17901827   case 2: // After writing the high word to the destination register
1791      m_current_value = m_value;                  // Prepare to save low word
1792      m_address = (m_address + 2) & 0xffff;
1828      m_current_value = m_value_copy;                  // Prepare to save low word
1829      m_address = (m_address + 2) & m_prgaddr_mask;
17931830      break;
17941831   }
17951832   pulse_clock(2);
17961833   m_state++;
17971834}
17981835
1799void tms9900_device::alu_divide()
1836void tms99xx_device::alu_divide()
18001837{
18011838   // Format is DIV Divisor,REG(dividend)
1802   UINT32 value1;
1839   UINT32 uval32;
1840   bool overflow = true;
1841   UINT16 value1;
18031842
18041843   switch (m_state)
18051844   {
18061845   case 0:
1807      m_source_value = m_current_value;      // store divisor
1808      m_regnumber = (IR >> 6) & 0x000f;
1846      m_source_value = m_current_value;   // store divisor
1847      // Set address of register
1848      m_address = WP + ((IR >> 5) & 0x001e);
1849      m_address_copy = m_address;
18091850      break;
18101851   case 1:
18111852      // We have an overflow when the quotient cannot be stored in 16 bits
18121853      // This is the case when the dividend / divisor >= 0x10000,
18131854      // or equivalently, dividend / 0x10000 >= divisor
1814      if (m_register_contents >= m_source_value)
1855
1856      if (m_current_value < m_source_value)   // also if source=0
18151857      {
1816         ST |= ST_OV;
1817         if (VERBOSE>7) LOG("tms9900: Aborting division because the dividend %08x is too big for the divisor %04x\n", (m_register_contents<<16), m_source_value);
1818         abort_operation();  // behaves as if the end of the operation sequence has been reached
1858         MPC++;   // skip the abort
1859         overflow = false;
18191860      }
1820      else
1821      {
1822         ST &= ~ST_OV;
1823         // m_address is the address of the high word of the dividend (from the previous register read)
1824         m_address = (m_address + 2) & 0xffff;
1825      }
1861      set_status_bit(ST_OV, overflow);
1862      m_value_copy = m_current_value;         // Save the high word
1863      m_address = (m_address + 2) & m_prgaddr_mask;      // Read next word
18261864      break;
18271865   case 2:
1866      // W2 is in m_current_value
18281867      // Create full word and perform division
1829      value1 = (m_register_contents << 16) | m_current_value;
1830      if (VERBOSE>7) LOG("tms9900: Dividing %08x by %04x\n", value1, m_source_value);
1831      m_current_value = (value1 / m_source_value) & 0xffff;
1832      m_value = (value1 % m_source_value) & 0xffff;
1833      if (VERBOSE>7) LOG("tms9900: Quotient %04x, remainder %04x\n", m_current_value, m_value);
1868      uval32 = (m_value_copy << 16) | m_current_value;
18341869
1870      if (VERBOSE>7) LOG("tms99xx: Dividing %08x by %04x\n", uval32, m_source_value);
1871      m_current_value = uval32 / m_source_value;
1872      m_value_copy = uval32 % m_source_value;
1873
1874      if (VERBOSE>7) LOG("tms99xx: Quotient %04x, remainder %04x\n", m_current_value, m_value_copy);
1875
1876      m_address = m_address_copy;
1877
18351878      // The number of ALU cycles depends on the number of steps in
18361879      // the division algorithm. The number of cycles is between 32 and
18371880      // 48 (*2 for clock cycles)
r15461r15462
18391882      // the following heuristic: We use 32 ALU cycles in general, then
18401883      // we need as many cycles as it takes to
18411884      // shift away the dividend. Thus, bigger dividends need more cycles.
1885
18421886      pulse_clock(62);   // one pulse is at the start, one at the end
1843      value1 = m_register_contents & 0xffff;
1887      value1 = m_value_copy & 0xffff;
1888
18441889      while (value1 != 0)
18451890      {
18461891         value1 = (value1 >> 1) & 0xffff;
r15461r15462
18491894      // We still have m_regnumber; this is where m_current_value will go to
18501895      break;
18511896   case 3:
1852      // Prepare to write the remainder; we have the address from above
1853      // (m_address), did not change
1854      m_current_value = m_value;
1855      if (VERBOSE>7) LOG("tms9900: ST = %04x (div)\n", ST);
1897      // Prepare to write the remainder
1898      m_current_value = m_value_copy;
1899      m_address = m_address + 2;
1900      if (VERBOSE>7) LOG("tms99xx: ST = %04x (div)\n", ST);
18561901      break;
18571902   }
18581903   pulse_clock(2);
18591904   m_state++;
18601905}
18611906
1862void tms9900_device::alu_xop()
1907void tms99xx_device::alu_xop()
18631908{
18641909   switch (m_state)
18651910   {
18661911   case 0:
18671912      // We have the effective address of the source operand in m_address
1868      m_source_address = m_address;
1913      m_address_saved = m_address;
18691914      // Now we take the XOP number from the instruction register
18701915      // and calculate the vector location
18711916      // [0010 11xx xx tt SSSS]  shift 6 right, then *4 => shift 4 right
r15461r15462
18731918      break;
18741919   case 1:
18751920      m_value = WP;                     // save the old WP
1876      WP = m_current_value;               // the new WP has been read in the previous microoperation
1877      m_current_value = m_source_address;      // we saved the address of the source operand; retrieve it
1878      m_regnumber = 11;                  // Next register is R11
1921      WP = m_current_value & m_prgaddr_mask;   // the new WP has been read in the previous microoperation
1922      m_current_value = m_address_saved;      // we saved the address of the source operand; retrieve it
1923      m_address = WP + 0x0016;            // Next register is R11
18791924      break;
18801925   case 2:
1926      m_address = WP + 0x001e;
18811927      m_current_value = ST;
1882      m_regnumber = 15;
18831928      break;
18841929   case 3:
1930      m_address = WP + 0x001c;
18851931      m_current_value = PC;
1886      m_regnumber = 14;
18871932      break;
18881933   case 4:
1889      m_current_value = WP;
1890      m_regnumber = 13;
1934      m_address = WP + 0x001a;
1935      m_current_value = m_value;                  // old WP into new R13
18911936      break;
18921937   case 5:
18931938      m_address =  0x0042 + ((IR >> 4) & 0x003c);      // location of new PC
1894      ST |= ST_X;
1939      set_status_bit(ST_X, true);
18951940      break;
18961941   case 6:
1897      PC = m_current_value;
1942      PC = m_current_value & m_prgaddr_mask;
18981943      break;
18991944   }
19001945   pulse_clock(2);
19011946   m_state++;
19021947}
19031948
1904void tms9900_device::alu_clr_swpb()
1949void tms99xx_device::alu_clr_swpb()
19051950{
19061951   UINT32 dest_new = 0;
19071952   UINT32 src_val = m_current_value & 0x0000ffff;
r15461r15462
19772022   // No states here
19782023}
19792024
1980void tms9900_device::alu_abs()
2025void tms99xx_device::alu_abs()
19812026{
19822027   // LAECO (from original word!)
19832028   // O if >8000
r15461r15462
19982043   pulse_clock(2);
19992044}
20002045
2001void tms9900_device::alu_x()
2046void tms99xx_device::alu_x()
20022047{
2003   if (VERBOSE>7) LOG("tms9900: Substituting current command by %04x\n", m_current_value);
2048   if (VERBOSE>7) LOG("tms99xx: Substituting current command by %04x\n", m_current_value);
20042049   decode(m_current_value);
20052050   pulse_clock(2);
20062051}
r15461r15462
20082053/*
20092054    Also used by other microprograms
20102055*/
2011void tms9900_device::alu_b()
2056void tms99xx_device::alu_b()
20122057{
20132058   // no status bits
20142059   // Although we got the contents of the source data, we do not use them
r15461r15462
20172062   // If we have a B *R5 and R5 contains the value 0xa000, the CPU actually
20182063   // retrieves the value at 0xa000, but in fact it will load the PC
20192064   // with the address 0xa000
2020   PC = m_address;
2021   if (VERBOSE>7) LOG("tms9900: Set new PC = %04x\n", PC);
2065   m_current_value = PC;
2066   PC = m_address & m_prgaddr_mask;
2067   m_address = WP + 22;
2068   if (VERBOSE>7) LOG("tms99xx: Set new PC = %04x\n", PC);
20222069   pulse_clock(2);
20232070}
20242071
2025void tms9900_device::alu_bl()
2072void tms99xx_device::alu_blwp()
20262073{
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
2037void tms9900_device::alu_blwp()
2038{
20392074   switch (m_state)
20402075   {
20412076   case 0:
2042      m_source_address = m_address;               // Save the location of the WP
2043      m_value = WP;
2044      WP = m_current_value;                     // set new WP (*m_destination)
2077      m_value_copy = WP;
2078      WP = m_current_value & m_prgaddr_mask;            // set new WP (*m_destination)
2079      m_address_saved = (m_address + 2) & m_prgaddr_mask;   // Save the location of the WP
2080      m_address = WP + 30;
20452081      m_current_value = ST;                     // get status register
2046      m_regnumber = 15;
20472082      break;
20482083   case 1:
20492084      m_current_value = PC;                     // get program counter
2050      m_regnumber = 14;
2085      m_address = m_address - 2;
20512086      break;
20522087   case 2:
2053      m_current_value = m_value;               // retrieve the old WP
2054      m_regnumber = 13;
2088      m_current_value = m_value_copy;               // retrieve the old WP
2089      m_address = m_address - 2;
20552090      break;
20562091   case 3:
2057      m_address = (m_source_address + 2)&0xffff;   // point to PC component of branch vector
2092      m_address = m_address_saved;               // point to PC component of branch vector
20582093      break;
20592094   case 4:
2060      PC = m_current_value;
2095      PC = m_current_value & m_prgaddr_mask;
2096      if (VERBOSE>5) LOG("tms9900: Context switch complete; WP=%04x, PC=%04x, ST=%04x\n", WP, PC, ST);
20612097      break;
20622098   }
20632099   pulse_clock(2);
20642100   m_state++;
20652101}
20662102
2067void tms9900_device::alu_ldcr()
2103void tms99xx_device::alu_ldcr()
20682104{
20692105   UINT16 value;
20702106
r15461r15462
20802116
20812117   if (m_state == 0)
20822118   {
2083      m_regnumber = 12;
2119      m_address = WP + 24;
20842120   }
20852121   else
20862122   {
r15461r15462
20972133      {
20982134         compare_and_set_lae(value, 0);
20992135      }
2100      m_cru_output = true;
2101      m_cru_address = m_register_contents;
2136      m_cru_address = m_current_value;
21022137      m_value = value;
2103      if (VERBOSE>6) LOG("tms9900: Load CRU address %04x (%d bits), value = %04x\n", m_cru_address, m_count, m_value);
2138      if (VERBOSE>6) LOG("tms99xx: Load CRU address %04x (%d bits), value = %04x\n", m_cru_address, m_count, m_value);
21042139   }
21052140   m_state++;
21062141   pulse_clock(2);
21072142}
21082143
2109void tms9900_device::alu_stcr()
2144void tms99xx_device::alu_stcr()
21102145{
21112146   UINT16 value;
21122147
r15461r15462
21202155   switch (m_state)
21212156   {
21222157   case 0: // After getting the destination operand and saving the address/value
2123      m_regnumber = 12;
2158      m_address = WP + 24;
21242159      break;
21252160   case 1: // After getting R12
2126      m_cru_output = false;
2127      m_cru_address = m_register_contents;
2161      m_cru_address = m_current_value;
21282162      m_count = (IR >> 6) & 0x000f;
21292163      if (m_count == 0) m_count = 16;
21302164      break;
r15461r15462
21322166      value = m_value & 0xffff;
21332167      if (m_count < 9)
21342168      {
2135         if (VERBOSE>6) LOG("tms9900: Store CRU at %04x (%d bits) in %04x, result = %02x\n", m_cru_address, m_count, m_source_address, value);
2169         if (VERBOSE>6) LOG("tms99xx: Store CRU at %04x (%d bits) in %04x, result = %02x\n", m_cru_address, m_count, m_source_address, value);
21362170         set_status_parity((UINT8)(value & 0xff));
21372171         compare_and_set_lae(value<<8, 0);
21382172         if (m_source_even)
r15461r15462
21442178      }
21452179      else
21462180      {
2147         if (VERBOSE>6) LOG("tms9900: Store CRU at %04x (%d bits) in %04x, result = %04x\n", m_cru_address, m_count, m_source_address, value);
2181         if (VERBOSE>6) LOG("tms99xx: Store CRU at %04x (%d bits) in %04x, result = %04x\n", m_cru_address, m_count, m_source_address, value);
21482182         m_current_value = value;
21492183         compare_and_set_lae(value, 0);
21502184         pulse_clock(2*(5 + (16-m_count)));
r15461r15462
21572191   pulse_clock(2);
21582192}
21592193
2160void tms9900_device::alu_sbz_sbo()
2194void tms99xx_device::alu_sbz_sbo()
21612195{
21622196   INT8 displacement;
21632197   if (m_state==0)
21642198   {
2165      m_regnumber = 12;
2199      m_address = WP + 24;
21662200   }
21672201   else
21682202   {
2169      m_cru_output = true;
2170      displacement = (IR & 0xff);
2171      m_cru_address = m_register_contents + (displacement<<1);
2203      m_value = (m_command==SBO)? 1 : 0;
2204      displacement = (INT8)(IR & 0xff);
2205      m_cru_address = m_current_value + (displacement<<1);
21722206      m_count = 1;
2173      m_value = (m_command == SBO)? 1 : 0;
2174      pulse_clock(2);
21752207   }
21762208   m_state++;
21772209   pulse_clock(2);
21782210}
21792211
2180void tms9900_device::alu_tb()
2212void tms99xx_device::alu_tb()
21812213{
21822214   INT8 displacement;
21832215   switch (m_state)
21842216   {
21852217   case 0:
2186      m_regnumber = 12;
2218      m_address = WP + 24;
21872219      break;
21882220   case 1:
2189      m_cru_output = false;
2190      displacement = (IR & 0xff);
2191      m_cru_address = m_register_contents + (displacement<<1);
2221      displacement = (INT8)(IR & 0xff);
2222      m_cru_address = m_current_value + (displacement<<1);
21922223      m_count = 1;
21932224      break;
21942225   case 2:
21952226      set_status_bit(ST_EQ, m_value!=0);
2196      if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST);
2227      if (VERBOSE>7) LOG("tms99xx: ST = %04x\n", ST);
21972228      break;
21982229   }
21992230   m_state++;
22002231   pulse_clock(2);
22012232}
22022233
2203void tms9900_device::alu_jmp()
2234void tms99xx_device::alu_jmp()
22042235{
22052236   INT8 displacement;
22062237   bool cond = false;
r15461r15462
22522283      pulse_clock(2);
22532284      if (!cond)
22542285      {
2255         if (VERBOSE>7) LOG("tms9900: Jump condition false\n");
2286         if (VERBOSE>7) LOG("tms99xx: Jump condition false\n");
22562287         MPC+=1;   // skip next ALU call
22572288      }
22582289      else
2259         if (VERBOSE>7) LOG("tms9900: Jump condition true\n");
2290         if (VERBOSE>7) LOG("tms99xx: Jump condition true\n");
22602291   }
22612292   else
22622293   {
22632294      displacement = (IR & 0xff);
2264      PC = PC + (displacement<<1);
2295      PC = (PC + (displacement<<1)) & m_prgaddr_mask;
22652296      pulse_clock(2);
22662297   }
22672298   m_state++;
22682299}
22692300
2270void tms9900_device::alu_shift()
2301void tms99xx_device::alu_shift()
22712302{
22722303   bool carry = false;
22732304   bool overflow = false;
22742305   UINT16 sign = 0;
22752306   UINT32 value;
2307   int count;
22762308
22772309   switch (m_state)
22782310   {
22792311   case 0:
2280      m_regnumber = (IR & 0x000f);
2312      m_address = WP + ((IR & 0x000f)<<1);
22812313      break;
22822314   case 1:
2283      m_source_value = m_current_value;         // save it
2284      m_count = (IR >> 4) & 0x000f;
2285      if (m_count != 0) MPC++;
2286      else m_regnumber = 0;
2315      // we have the value of the register in m_current_value
2316      // Save it (we may have to read R0)
2317      m_value_copy = m_current_value;
2318      m_address_saved = m_address;
2319      m_address = WP;
2320      m_current_value = (IR >> 4) & 0x000f;
2321
2322      if (m_current_value != 0)
2323      {
2324         // skip the next read operation
2325         MPC++;
2326      }
2327      else
2328      {
2329         if (VERBOSE>8) LOG("tms99xx: Shift operation gets count from R0\n");
2330      }
22872331      break;
22882332   case 2:
2289      value = m_source_value & 0xffff;
2333      count = m_current_value & 0x000f; // from the instruction or from R0
2334      if (count==0) count = 16;
22902335
2291      if (m_count==0) m_count = m_register_contents & 0x000f;
2292      if (m_count==0) m_count = 16;
2336      value = m_value_copy;
22932337
22942338      // we are re-implementing the shift operations because we have to pulse
22952339      // the clock at each single shift anyway.
r15461r15462
22972341      // Note that count is never 0
22982342      if (m_command == SRA) sign = value & 0x8000;
22992343
2300      for (int i=0; i < m_count; i++)
2344      for (int i=0; i < count; i++)
23012345      {
23022346         switch (m_command)
23032347         {
r15461r15462
23232367      set_status_bit(ST_C, carry);
23242368      set_status_bit(ST_OV, overflow);
23252369      compare_and_set_lae(m_current_value, 0);
2326
2327      m_regnumber = (IR & 0x000f);
2370      m_address = m_address_saved;      // Register address
2371      if (VERBOSE>7) LOG("tms99xx: ST = %04x (val=%04x)\n", ST, m_current_value);
23282372      break;
23292373   }
23302374   m_state++;
23312375   pulse_clock(2);
23322376}
23332377
2334void tms9900_device::alu_ai_ori()
2378void tms99xx_device::alu_ai_ori()
23352379{
23362380   UINT32 dest_new = 0;
23372381   switch (m_command)
23382382   {
23392383   case AI:
2340      dest_new = m_current_value + m_register_contents;
2384      dest_new = m_current_value + m_value_copy;
23412385      // See status bit handling for Add
23422386      set_status_bit(ST_C, (dest_new & 0x10000) != 0);
2343      set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_register_contents) & 0x8000)!=0);
2387      set_status_bit(ST_OV, ((dest_new ^ m_current_value) & (dest_new ^ m_value_copy) & 0x8000)!=0);
23442388      break;
23452389   case ANDI:
2346      dest_new = m_current_value & m_register_contents;
2390      dest_new = m_current_value & m_value_copy;
23472391      break;
23482392   case ORI:
2349      dest_new = m_current_value | m_register_contents;
2393      dest_new = m_current_value | m_value_copy;
23502394      break;
23512395   }
23522396   m_current_value = dest_new & 0xffff;
2397   m_address = m_address_copy;
23532398   compare_and_set_lae(m_current_value, 0);
23542399   pulse_clock(2);
23552400}
23562401
2357void tms9900_device::alu_ci()
2402void tms99xx_device::alu_ci()
23582403{
2359   compare_and_set_lae(m_register_contents, m_current_value);
2404   compare_and_set_lae(m_value_copy, m_current_value);
23602405   pulse_clock(2);
23612406}
23622407
2363void tms9900_device::alu_li()
2408void tms99xx_device::alu_li()
23642409{
23652410   compare_and_set_lae(m_current_value, 0);
23662411   pulse_clock(2);
23672412}
23682413
2369void tms9900_device::alu_lwpi()
2414void tms99xx_device::alu_lwpi()
23702415{
2371   WP = m_current_value;
2416   WP = m_current_value & m_prgaddr_mask;
23722417   pulse_clock(2);
23732418}
23742419
2375void tms9900_device::alu_limi()
2420void tms99xx_device::alu_limi()
23762421{
23772422   ST = (ST & 0xfff0) | (m_current_value & 0x000f);
2378   if (VERBOSE>7) LOG("tms9900: ST = %04x\n", ST);
2423   if (VERBOSE>7) LOG("tms99xx: ST = %04x\n", ST);
23792424   pulse_clock(2);
23802425}
23812426
2382void tms9900_device::alu_stwp_stst()
2427void tms99xx_device::alu_stwp_stst()
23832428{
23842429   if (m_command==STST) m_current_value = ST;
23852430   else m_current_value = WP;
23862431   pulse_clock(2);
23872432}
23882433
2389void tms9900_device::alu_external()
2434void tms99xx_device::alu_external()
23902435{
23912436   pulse_clock(10);
23922437
r15461r15462
24052450   m_external_operation((IR >> 5) & 0x07, 1);
24062451}
24072452
2408void tms9900_device::alu_rtwp()
2453void tms99xx_device::alu_rtwp()
24092454{
24102455   switch (m_state)
24112456   {
24122457   case 0:
2413      m_regnumber = 15;
2458      m_address = WP + 30;      // R15
24142459      break;
24152460   case 1:
2416      ST = m_register_contents;
2417      m_regnumber = 14;
2461      ST = m_current_value;
2462      m_address -= 2;            // R14
24182463      break;
24192464   case 2:
2420      PC = m_register_contents;
2421      m_regnumber = 13;
2465      PC = m_current_value & m_prgaddr_mask;
2466      m_address -= 2;            // R13
24222467      break;
24232468   case 3:
2424      WP = m_register_contents;
2469      WP = m_current_value & m_prgaddr_mask;
24252470      break;
24262471   }
24272472   m_state++;
r15461r15462
24292474}
24302475
24312476
2432void tms9900_device::alu_int()
2477void tms99xx_device::alu_int()
24332478{
2434   if (VERBOSE>7) LOG("tms9900: INT state %d; irq_level %d\n", m_state, m_irq_level);
2479   if (VERBOSE>7) LOG("tms99xx: INT state %d; irq_level %d\n", m_state, m_irq_level);
24352480   switch (m_state)
24362481   {
24372482   case 0:
r15461r15462
24422487      }
24432488      else
24442489      {
2445         if (m_irq_level == LOAD_INT) m_address = 0xfffc;
2490         if (m_irq_level == LOAD_INT) m_address = 0xfffc; // will be truncated for TMS9980
24462491         else
24472492         {
24482493            m_address = (m_irq_level << 2);
r15461r15462
24502495      }
24512496      break;
24522497   case 1:
2453      m_value = WP;            // old WP
2454      WP = m_current_value;      // new WP
2498      m_address_copy = m_address;
2499      m_value_copy = WP;                     // old WP
2500      WP = m_current_value & m_prgaddr_mask;      // new WP
24552501      m_current_value = ST;
2456      m_regnumber = 15;
2502      m_address = (WP + 30) & m_prgaddr_mask;
24572503      break;
24582504   case 2:
24592505      m_current_value = PC;
2460      m_regnumber = 14;
2506      m_address = (WP + 28) & m_prgaddr_mask;
24612507      break;
24622508   case 3:
2463      m_current_value = m_value;   // old WP
2464      m_regnumber = 13;
2509      m_current_value = m_value_copy;   // old WP
2510      m_address = (WP + 26) & m_prgaddr_mask;
24652511      break;
24662512   case 4:
2467      m_address = (m_address + 2) & 0xfffe;
2468      if (VERBOSE>7) LOG("tms9900: read from %04x\n", m_address);
2513      m_address = (m_address_copy + 2) & 0xfffe & m_prgaddr_mask;
2514      if (VERBOSE>7) LOG("tms99xx: read from %04x\n", m_address);
24692515      break;
24702516   case 5:
2471      PC = m_current_value;
2517      PC = m_current_value & m_prgaddr_mask;
2518      m_irq_level = get_intlevel(ASSERT_LINE);
24722519      if (m_irq_level > 0 )
24732520      {
24742521         ST = (ST & 0xfff0) | (m_irq_level - 1);
r15461r15462
24802527}
24812528
24822529/**************************************************************************/
2483UINT32 tms9900_device::execute_min_cycles() const
2530UINT32 tms99xx_device::execute_min_cycles() const
24842531{
24852532   return 2;
24862533}
24872534
24882535// TODO: Compute this value, just a wild guess for the average
2489UINT32 tms9900_device::execute_max_cycles() const
2536UINT32 tms99xx_device::execute_max_cycles() const
24902537{
24912538   return 10;
24922539}
24932540
2494UINT32 tms9900_device::execute_input_lines() const
2541UINT32 tms99xx_device::execute_input_lines() const
24952542{
24962543   return 1;
24972544}
r15461r15462
25012548// execute_burn = nop
25022549
25032550// device_disasm_interface overrides
2504UINT32 tms9900_device::disasm_min_opcode_bytes() const
2551UINT32 tms99xx_device::disasm_min_opcode_bytes() const
25052552{
25062553   return 2;
25072554}
25082555
2509UINT32 tms9900_device::disasm_max_opcode_bytes() const
2556UINT32 tms99xx_device::disasm_max_opcode_bytes() const
25102557{
25112558   return 6;
25122559}
25132560
2514offs_t tms9900_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
2561offs_t tms99xx_device::disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options)
25152562{
25162563   return Dasm9900(buffer, pc, TMS9900_ID, oprom, opram);
25172564}
src/emu/cpu/tms9900/tms9900.h
r15461r15462
4949
5050enum
5151{
52   LOAD_INT = -1,
53   RESET_INT = -2
54};
55
56enum
57{
5258   TI990_10_ID = 1,
5359   TMS9900_ID = 3,
5460   TMS9940_ID = 4,
r15461r15462
6167   TMS99110A_ID = 12
6268};
6369
64#define MCFG_TMS9900_ADD(_tag, _device, _clock, _prgmap, _iomap, _config)      \
70#define MCFG_TMS99xx_ADD(_tag, _device, _clock, _prgmap, _iomap, _config)      \
6571   MCFG_DEVICE_ADD(_tag, _device, _clock)      \
6672   MCFG_DEVICE_PROGRAM_MAP(_prgmap)         \
6773   MCFG_DEVICE_IO_MAP(_iomap)               \
r15461r15462
7682   LREX_OP = 7
7783};
7884
79typedef struct _tms9900_config
85static const char opname[][5] =
86{   "ILL ", "A   ", "AB  ", "ABS ", "AI  ", "ANDI", "B   ", "BL  ", "BLWP", "C   ",
87   "CI  ", "CB  ", "CKOF", "CKON", "CLR ", "COC ", "CZC ", "DEC ", "DECT", "DIV ",
88   "IDLE", "INC ", "INCT", "INV ", "JEQ ", "JGT ", "JH  ", "JHE ", "JL  ", "JLE ",
89   "JLT ", "JMP ", "JNC ", "JNE ", "JNO ", "JOC ", "JOP ", "LDCR", "LI  ", "LIMI",
90   "LREX", "LWPI", "MOV ", "MOVB", "MPY ", "NEG ", "ORI ", "RSET",   "RTWP", "S   ",
91   "SB  ", "SBO ", "SBZ ", "SETO", "SLA ", "SOC ", "SOCB", "SRA ", "SRC ", "SRL ",
92   "STCR", "STST", "STWP", "SWPB", "SZC ", "SZCB", "TB  ", "X   ", "XOP ", "XOR ",
93   "*int"
94};
95
96typedef struct _tms99xx_config
8097{
8198   devcb_write8      external_callback;
8299   devcb_read8         irq_level;
r15461r15462
84101   devcb_write_line   clock_out;
85102   devcb_write_line   wait_line;
86103   devcb_write_line   holda_line;
87} tms9900_config;
104} tms99xx_config;
88105
89#define TMS9900_CONFIG(name) \
90   const tms9900_config(name) =
106#define TMS99xx_CONFIG(name) \
107   const tms99xx_config(name) =
91108
92class tms9900_device : public cpu_device
109class tms99xx_device : public cpu_device
93110{
94111public:
95   tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
112   tms99xx_device(const machine_config &mconfig, device_type type,  const char *name,
113            const char *tag, int databus_width, int prg_addr_bits, int cru_addr_bits,
114            device_t *owner, UINT32 clock);
96115
116   ~tms99xx_device();
117
97118   // READY input line. When asserted (high), the memory is ready for data exchange.
98119   void set_ready(int state);
99120
r15461r15462
122143
123144   const address_space_config* memory_space_config(address_spacenum spacenum) const;
124145
125private:
146   // Let these methods be overloaded by the TMS9980.
147   virtual void      mem_read(void);
148   virtual void      mem_write(void);
149   virtual void      acquire_instruction(void);
150   void            decode(UINT16 inst);
151
152   const address_space_config   m_program_config;
153   const address_space_config   m_io_config;
154   address_space*         m_prgspace;
155   address_space*         m_cru;
156
157   virtual UINT16   read_workspace_register_debug(int reg);
158   virtual void   write_workspace_register_debug(int reg, UINT16 data);
159
160   // Cycle counter
161   int    m_icount;
162
126163   // TMS9900 hardware registers
127164   UINT16   WP;    // Workspace pointer
128165   UINT16   PC;    // Program counter
r15461r15462
131168   // Internal register
132169   UINT16   IR;      // Instruction register
133170
171   // Stored address
172   UINT16   m_address;
173
174   // Stores the recently read word or the word to be written
175   UINT16   m_current_value;
176
134177   // Decoded command
135178   UINT16   m_command;
136179
180   // Issue clock pulses. Note that each machine cycle has two clock cycles.
181   void pulse_clock(int count);
182
183   // For multi-pass operations. For instance, memory word accesses are
184   // executed as two consecutive byte accesses. CRU accesses are repeated
185   // single-bit accesses. (Needed for TMS9980)
186   int      m_pass;
187
188   // Data bus width. Needed for TMS9980.
189   int    m_databus_width;
190
191   // Needed for TMS9980
192   bool   m_lowbyte;
193
194   // Check the READY line?
195   bool   m_check_ready;
196
197   // Max address
198   const UINT16  m_prgaddr_mask;
199   const UINT16  m_cruaddr_mask;
200
201   bool   m_load_state;
202   bool   m_irq_state;
203   bool   m_reset;
204
205   // Determine the interrupt level using the IC0-IC2/3 lines
206   virtual int get_intlevel(int state);
207
208   // Interrupt level as acquired from input lines (TMS9900: IC0-IC3, TMS9980: IC0-IC2)
209   // We assume all values right-justified, i.e. TMS9980 also counts up by one
210   int    m_irq_level;
211
212   // Used to display the number of consumed cycles in the log.
213   int      m_first_cycle;
214
215   // Signal to the outside world that we are now getting an instruction
216   devcb_resolved_write_line   m_iaq_line;
217
218   // Get the value of the interrupt level lines
219   devcb_resolved_read8   m_get_intlevel;
220
221private:
137222   // Indicates if this is a byte-oriented command
138223   inline bool    byte_operation();
139224
140   const address_space_config      m_program_config;
141   const address_space_config      m_io_config;
142   address_space*               m_prgspace;
143   address_space*               m_cru;
144
145225   // Processor states
146226   bool   m_idle_state;
147   bool   m_load_state;
148   bool   m_irq_state;
149227   bool   m_ready_state;
150228   bool   m_wait_state;
151229   bool   m_hold_state;
152230
153   bool   m_reset;
154
155   int    m_irq_level;   // Interrupt level as acquired from input lines IC0-IC3
156   int    m_icount;      // Cycle counter
157
158231   // State / debug management
159232   UINT16   m_state_any;
160233   static const char* s_statename[];
161234   void   state_import(const device_state_entry &entry);
162235   void   state_export(const device_state_entry &entry);
163236   void   state_string_export(const device_state_entry &entry, astring &string);
164   UINT16   read_workspace_register_debug(int reg);
165   void   write_workspace_register_debug(int reg, UINT16 data);
166237
167238   // Interrupt handling
168239   void service_interrupt();
r15461r15462
176247   typedef const UINT8* microprogram;
177248
178249   // Method pointer
179   typedef void (tms9900_device::*ophandler)(void);
250   typedef void (tms99xx_device::*ophandler)(void);
180251
181252   // Opcode list entry
182253   typedef struct _tms_instruction
r15461r15462
201272   lookup_entry*   m_lotables[32];
202273
203274   // List of pointers for micro-operations
204   static const tms9900_device::ophandler s_microoperation[];
275   static const tms99xx_device::ophandler s_microoperation[];
205276
206277   // Opcode table
207   static const tms9900_device::tms_instruction s_command[];
278   static const tms99xx_device::tms_instruction s_command[];
208279
209280   // Micro-operation declarations
210   void   acquire_instruction(void);
211   void   mem_read(void);
212   void   mem_write(void);
213281   void   register_read(void);
214282   void   register_write(void);
215   void   cru_operation(void);
283   void   cru_input_operation(void);
284   void   cru_output_operation(void);
216285   void   data_derivation_subprogram(void);
217286   void   return_from_subprogram(void);
218287   void   command_completed(void);
r15461r15462
258327   void   alu_int(void);
259328
260329   void   abort_operation(void);
261   UINT16   pulse_and_read_memory(UINT16 address);
262   void   pulse_and_write_memory(UINT16 address, UINT16 data);
263   void   decode(UINT16 inst);
264330
265331   // Micro-operation
266332   UINT8   m_op;
r15461r15462
278344   // State of the micro-operation. Needed for repeated ALU calls.
279345   int    m_state;
280346
281   // Check the READY line?
282   bool   m_check_ready;
283
284347   // Has HOLD been acknowledged yet?
285348   bool   m_hold_acknowledged;
286349
287   // Issue clock pulses. Note that each machine cycle has two clock cycles.
288   inline void pulse_clock(int count);
289
290350   // Signal the wait state via the external line
291351   inline void set_wait_state(bool state);
292352
293353   // Used to acknowledge HOLD and enter the HOLD state
294354   inline void acknowledge_hold();
295355
296   // Stored address
297   UINT16   m_address;
298
299   // Stores the recently read word or the word to be written
300   UINT16   m_current_value;
301
302356   // Was the source operand a byte from an even address?
303357   bool m_source_even;
304358
r15461r15462
308362   // Intermediate storage for the source operand
309363   UINT16 m_source_address;
310364   UINT16 m_source_value;
365   UINT16   m_address_saved;
311366
367   // Another copy of the address
368   UINT16   m_address_copy;
369
312370   // Stores the recently read register contents
313371   UINT16   m_register_contents;
314372
315373   // Stores the register number for the next register access
316374   int    m_regnumber;
317375
318   // CRU support: Indicates whether the CRU shall be configured to output mode
319   bool   m_cru_output;
320
321376   // CRU support: Stores the CRU address
322377   UINT16   m_cru_address;
323378
324379   // CRU support: Stores the number of bits to be transferred
325380   int      m_count;
326381
382   // Copy of the value
383   UINT16   m_value_copy;
384
327385   // Another internal register, storing intermediate values
328386   // Using 32 bits to support MPY
329387   UINT32   m_value;
r15461r15462
336394   inline void compare_and_set_lae(UINT16 value1, UINT16 value2);
337395   void set_status_parity(UINT8 value);
338396
339   // Used to display the number of consumed cycles in the log.
340   int      m_first_cycle;
341
342397   /************************************************************************/
343398
344399   // Trigger external operation. This is achieved by putting a special value in
r15461r15462
363418   // chip emulations we use a dedicated callback.
364419   devcb_resolved_write8   m_external_operation;
365420
366   // Get the value of the interrupt level lines
367   devcb_resolved_read8   m_get_ic0123;
368
369   // Signal to the outside world that we are now getting an instruction
370   devcb_resolved_write_line   m_iaq_line;
371
372421   // Clock output. This is not a pin of the TMS9900 because the TMS9900
373422   // needs an external clock, and usually one of those external lines is
374423   // used for this purpose.
r15461r15462
381430   devcb_resolved_write_line   m_holda_line;
382431};
383432
433/*****************************************************************************/
434
435class tms9900_device : public tms99xx_device
436{
437public:
438   tms9900_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
439};
440
441
384442unsigned Dasm9900(char *buffer, unsigned pc, int model_id, const UINT8 *oprom, const UINT8 *opram);
385443
386444// device type definition

Previous 15994 Revisions Next


© 1998-2018 The MESS Team