1 // license:BSD-3-Clause
2 // copyright-holders:Wilbert Pol, hap
3 /*
4 
5   TMS1000 family - base/shared
6 
7   TODO:
8   - accurate INIT pin (currently, just use INPUT_LINE_RESET)
9   - emulate newer die revisions? TMS1xxx rev. E and up have 4 cycles
10     per opcode instead of 6. But which steps go where, is unknown.
11     For now, just overclock the MCU instead.
12 
13 
14 The TMS0980 and TMS1000-family MCU cores are very similar. The TMS0980 has a
15 slightly bigger addressable area and uses 9bit instructions where the TMS1000
16 family uses 8bit instruction. The instruction set themselves are very similar
17 though.
18 
19 Each instruction takes 12 cycles to execute in 2 phases: a fetch phase and an
20 execution phase. The execution phase takes place at the same time as the fetch
21 phase of the next instruction. So, during execution there are both fetch and
22 execution operations taking place. The operation can be split up as follows:
23 cycle #0
24     - Fetch:
25         1. ROM address 0
26     - Execute:
27         1. Read RAM
28         2. Clear ALU inputs
29         3. Execute BRANCH/CALL/RETN part #2
30         4. K input valid
31 cycle #1
32     - Fetch:
33         1. ROM address 1
34     - Execute:
35         1. Update ALU inputs
36 cycle #2
37     - Fetch:
38         1. nothing/wait(?)
39     - Execute:
40         1. Perform ALU operation
41         2. Write RAM
42 cycle #3
43     - Fetch:
44         1. Fetch/Update PC/RAM address #1
45     - Execute:
46         1. Register store part #1
47 cycle #4
48     - Fetch:
49         1. Fetch/Update PC/RAM address #2
50     - Execute:
51         1. Register store part #2
52 cycle #5
53     - Fetch:
54         1. Instruction decode
55     - Execute:
56         1. Execute BRANCH/CALL/RETN part #1
57 
58 The MCU cores contains a set of fixed instructions and a set of
59 instructions created using microinstructions. A subset of the
60 instruction set could be defined from the microinstructions by
61 TI customers.
62 
63 cycle #0: 15TN, ATN, CIN, CKN, CKP, DMTP, MTN, MTP, NATN, NDMTP, YTP
64 cycle #2: C8(?), CKM, NE(?), STO
65 cycle #3,#4: AUTA, AUTY
66 
67 unknown cycle: CME, SSE, SSS
68 
69 */
70 
71 #include "emu.h"
72 #include "tms1k_base.h"
73 #include "debugger.h"
74 
tms1k_base_device(const machine_config & mconfig,device_type type,const char * tag,device_t * owner,u32 clock,u8 o_pins,u8 r_pins,u8 pc_bits,u8 byte_bits,u8 x_bits,int prgwidth,address_map_constructor program,int datawidth,address_map_constructor data)75 tms1k_base_device::tms1k_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, u8 o_pins, u8 r_pins, u8 pc_bits, u8 byte_bits, u8 x_bits, int prgwidth, address_map_constructor program, int datawidth, address_map_constructor data)
76 	: cpu_device(mconfig, type, tag, owner, clock)
77 	, m_program_config("program", ENDIANNESS_BIG, byte_bits > 8 ? 16 : 8, prgwidth, byte_bits > 8 ? -1 : 0, program)
78 	, m_data_config("data", ENDIANNESS_BIG, 8, datawidth, 0, data)
79 	, m_mpla(*this, "mpla")
80 	, m_ipla(*this, "ipla")
81 	, m_opla(*this, "opla")
82 	, m_opla_b(*this, "opla_b")
83 	, m_spla(*this, "spla")
84 	, m_o_pins(o_pins)
85 	, m_r_pins(r_pins)
86 	, m_pc_bits(pc_bits)
87 	, m_byte_bits(byte_bits)
88 	, m_x_bits(x_bits)
89 	, m_output_pla_table(nullptr)
90 	, m_read_k(*this)
91 	, m_write_o(*this)
92 	, m_write_r(*this)
93 	, m_power_off(*this)
94 	, m_read_ctl(*this)
95 	, m_write_ctl(*this)
96 	, m_write_pdc(*this)
97 	, m_decode_micro(*this)
98 {
99 }
100 
101 // disasm
state_string_export(const device_state_entry & entry,std::string & str) const102 void tms1k_base_device::state_string_export(const device_state_entry &entry, std::string &str) const
103 {
104 	switch (entry.index())
105 	{
106 		case STATE_GENPC:
107 		case STATE_GENPCBASE:
108 			str = string_format("%03X", m_rom_address << ((m_byte_bits > 8) ? 1 : 0));
109 			break;
110 	}
111 }
112 
113 
114 //-------------------------------------------------
115 //  device_start - device-specific startup
116 //-------------------------------------------------
117 
118 enum
119 {
120 	TMS1XXX_PC=1, TMS1XXX_SR, TMS1XXX_PA, TMS1XXX_PB,
121 	TMS1XXX_A, TMS1XXX_X, TMS1XXX_Y, TMS1XXX_STATUS
122 };
123 
device_start()124 void tms1k_base_device::device_start()
125 {
126 	m_program = &space(AS_PROGRAM);
127 	m_data = &space(AS_DATA);
128 
129 	m_o_mask = (1 << m_o_pins) - 1;
130 	m_r_mask = (1 << m_r_pins) - 1;
131 	m_pc_mask = (1 << m_pc_bits) - 1;
132 	m_x_mask = (1 << m_x_bits) - 1;
133 
134 	// resolve callbacks
135 	m_read_k.resolve_safe(0);
136 	m_write_o.resolve_safe();
137 	m_write_r.resolve_safe();
138 	m_power_off.resolve_safe();
139 	m_read_ctl.resolve_safe(0);
140 	m_write_ctl.resolve_safe();
141 	m_write_pdc.resolve_safe();
142 	m_decode_micro.resolve();
143 
144 	if (m_opla_b != nullptr && m_output_pla_table == nullptr)
145 		set_output_pla(&m_opla_b->as_u16());
146 
147 	// zerofill
148 	m_pc = 0;
149 	m_sr = 0;
150 	m_pa = 0;
151 	m_pb = 0;
152 	m_ps = 0;
153 	m_a = 0;
154 	m_x = 0;
155 	m_y = 0;
156 	m_ca = 0;
157 	m_cb = 0;
158 	m_cs = 0;
159 	m_r = 0;
160 	m_o = 0;
161 	m_o_index = 0;
162 	m_cki_bus = 0;
163 	m_c4 = 0;
164 	m_p = 0;
165 	m_n = 0;
166 	m_adder_out = 0;
167 	m_carry_in = 0;
168 	m_carry_out = 0;
169 	m_status = 0;
170 	m_status_latch = 0;
171 	m_eac = 0;
172 	m_clatch = 0;
173 	m_add = 0;
174 	m_bl = 0;
175 
176 	m_ram_in = 0;
177 	m_dam_in = 0;
178 	m_ram_out = 0;
179 	m_ram_address = 0;
180 	m_rom_address = 0;
181 	m_opcode = 0;
182 	m_fixed = 0;
183 	m_micro = 0;
184 	m_subcycle = 0;
185 
186 	// register for savestates
187 	save_item(NAME(m_pc));
188 	save_item(NAME(m_sr));
189 	save_item(NAME(m_pa));
190 	save_item(NAME(m_pb));
191 	save_item(NAME(m_ps));
192 	save_item(NAME(m_a));
193 	save_item(NAME(m_x));
194 	save_item(NAME(m_y));
195 	save_item(NAME(m_ca));
196 	save_item(NAME(m_cb));
197 	save_item(NAME(m_cs));
198 	save_item(NAME(m_r));
199 	save_item(NAME(m_o));
200 	save_item(NAME(m_o_index));
201 	save_item(NAME(m_cki_bus));
202 	save_item(NAME(m_c4));
203 	save_item(NAME(m_p));
204 	save_item(NAME(m_n));
205 	save_item(NAME(m_adder_out));
206 	save_item(NAME(m_carry_in));
207 	save_item(NAME(m_carry_out));
208 	save_item(NAME(m_status));
209 	save_item(NAME(m_status_latch));
210 	save_item(NAME(m_eac));
211 	save_item(NAME(m_clatch));
212 	save_item(NAME(m_add));
213 	save_item(NAME(m_bl));
214 
215 	save_item(NAME(m_ram_in));
216 	save_item(NAME(m_dam_in));
217 	save_item(NAME(m_ram_out));
218 	save_item(NAME(m_ram_address));
219 	save_item(NAME(m_rom_address));
220 	save_item(NAME(m_opcode));
221 	save_item(NAME(m_fixed));
222 	save_item(NAME(m_micro));
223 	save_item(NAME(m_subcycle));
224 
225 	// register state for debugger
226 	state_add(TMS1XXX_PC,     "PC",     m_pc    ).formatstr("%02X");
227 	state_add(TMS1XXX_SR,     "SR",     m_sr    ).formatstr("%01X");
228 	state_add(TMS1XXX_PA,     "PA",     m_pa    ).formatstr("%01X");
229 	state_add(TMS1XXX_PB,     "PB",     m_pb    ).formatstr("%01X");
230 	state_add(TMS1XXX_A,      "A",      m_a     ).formatstr("%01X");
231 	state_add(TMS1XXX_X,      "X",      m_x     ).formatstr("%01X");
232 	state_add(TMS1XXX_Y,      "Y",      m_y     ).formatstr("%01X");
233 	state_add(TMS1XXX_STATUS, "STATUS", m_status).formatstr("%01X");
234 
235 	state_add(STATE_GENPC, "GENPC", m_rom_address).formatstr("%03X").noshow();
236 	state_add(STATE_GENPCBASE, "CURPC", m_rom_address).formatstr("%03X").noshow();
237 	state_add(STATE_GENFLAGS, "GENFLAGS", m_sr).formatstr("%8s").noshow();
238 
239 	set_icountptr(m_icount);
240 }
241 
memory_space_config() const242 device_memory_interface::space_config_vector tms1k_base_device::memory_space_config() const
243 {
244 	return space_config_vector {
245 		std::make_pair(AS_PROGRAM, &m_program_config),
246 		std::make_pair(AS_DATA,    &m_data_config)
247 	};
248 }
249 
250 
251 
252 //-------------------------------------------------
253 //  device_reset - device-specific reset
254 //-------------------------------------------------
255 
device_reset()256 void tms1k_base_device::device_reset()
257 {
258 	m_pa = 0xf;
259 	m_pb = 0xf;
260 	m_pc = 0;
261 	m_ca = 0;
262 	m_cb = 0;
263 	m_cs = 0;
264 
265 	m_eac = 0;
266 	m_bl = 0;
267 	m_add = 0;
268 	m_status = 0;
269 	m_clatch = 0;
270 
271 	m_opcode = 0;
272 	m_micro = 0;
273 	m_fixed = 0;
274 
275 	m_subcycle = 0;
276 
277 	// clear outputs
278 	m_r = 0;
279 	m_write_r(0, m_r & m_r_mask, 0xffff);
280 	write_o_output(0);
281 	m_write_r(0, m_r & m_r_mask, 0xffff);
282 	m_power_off(0);
283 }
284 
285 
286 
287 //-------------------------------------------------
288 //  program counter/opcode decode
289 //-------------------------------------------------
290 
next_pc()291 void tms1k_base_device::next_pc()
292 {
293 	// The program counter is a LFSR. To put it simply, the feedback bit is a XOR of the two highest bits,
294 	// but it makes an exception when all low bits are set (eg. in TMS1000 case, when PC is 0x1f or 0x3f).
295 	int high = 1 << (m_pc_bits - 1);
296 	int fb = (m_pc << 1 & high) == (m_pc & high);
297 
298 	if (m_pc == (m_pc_mask >> 1))
299 		fb = 1;
300 	else if (m_pc == m_pc_mask)
301 		fb = 0;
302 
303 	m_pc = (m_pc << 1 | fb) & m_pc_mask;
304 }
305 
read_opcode()306 void tms1k_base_device::read_opcode()
307 {
308 	debugger_instruction_hook(m_rom_address);
309 	m_opcode = m_program->read_byte(m_rom_address);
310 	m_c4 = bitswap<4>(m_opcode,0,1,2,3); // opcode operand is bitswapped for most opcodes
311 
312 	m_fixed = m_fixed_decode[m_opcode];
313 	m_micro = m_micro_decode[m_opcode];
314 
315 	next_pc();
316 }
317 
318 
319 
320 //-------------------------------------------------
321 //  i/o handling
322 //-------------------------------------------------
323 
write_o_output(u8 index)324 void tms1k_base_device::write_o_output(u8 index)
325 {
326 	// a hardcoded table is supported if the output pla is unknown
327 	m_o_index = index;
328 	m_o = (m_output_pla_table == nullptr) ? m_opla->read(index) : m_output_pla_table[index];
329 	m_write_o(0, m_o & m_o_mask, 0xffff);
330 }
331 
read_k_input()332 u8 tms1k_base_device::read_k_input()
333 {
334 	// K1,2,4,8 (KC test pin is not emulated)
335 	return m_read_k(0, 0xff) & 0xf;
336 }
337 
set_cki_bus()338 void tms1k_base_device::set_cki_bus()
339 {
340 	switch (m_opcode & 0xf8)
341 	{
342 		// 00001XXX: K-inputs
343 		case 0x08:
344 			m_cki_bus = read_k_input();
345 			break;
346 
347 		// 0011XXXX: select bit
348 		case 0x30: case 0x38:
349 			m_cki_bus = 1 << (m_c4 >> 2) ^ 0xf;
350 			break;
351 
352 		// 01XXXXXX: constant
353 		case 0x00: // R2,3,4 are NANDed with eachother, and then ORed with R1, making 00000XXX valid too
354 		case 0x40: case 0x48: case 0x50: case 0x58: case 0x60: case 0x68: case 0x70: case 0x78:
355 			m_cki_bus = m_c4;
356 			break;
357 
358 		default:
359 			m_cki_bus = 0;
360 			break;
361 	}
362 }
363 
364 
365 
366 //-------------------------------------------------
367 //  fixed opcode set
368 //-------------------------------------------------
369 
370 // handle branches:
371 
372 // TMS1000/common
373 // note: add(latch) and bl(branch latch) are specific to 0980 series,
374 // c(chapter) bits are specific to 1100(and 1400) series
375 
op_br()376 void tms1k_base_device::op_br()
377 {
378 	// BR/BL: conditional branch
379 	if (m_status)
380 	{
381 		if (m_clatch == 0)
382 			m_pa = m_pb;
383 		m_ca = m_cb;
384 		m_pc = m_opcode & m_pc_mask;
385 	}
386 }
387 
op_call()388 void tms1k_base_device::op_call()
389 {
390 	// CALL/CALLL: conditional call
391 	if (m_status)
392 	{
393 		u8 prev_pa = m_pa;
394 
395 		if (m_clatch == 0)
396 		{
397 			m_clatch = 1;
398 			m_sr = m_pc;
399 			m_pa = m_pb;
400 			m_cs = m_ca;
401 		}
402 		m_ca = m_cb;
403 		m_pb = prev_pa;
404 		m_pc = m_opcode & m_pc_mask;
405 	}
406 }
407 
op_retn()408 void tms1k_base_device::op_retn()
409 {
410 	// RETN: return from subroutine
411 	if (m_clatch == 1)
412 	{
413 		m_clatch = 0;
414 		m_pc = m_sr;
415 		m_ca = m_cs;
416 	}
417 	m_add = 0;
418 	m_bl = 0;
419 	m_pa = m_pb;
420 }
421 
422 
423 // TMS1400/TMS1000C 3-level stack version
424 
op_br3()425 void tms1k_base_device::op_br3()
426 {
427 	// BR/BL: conditional branch
428 	if (m_status)
429 	{
430 		m_pa = m_pb; // don't care about clatch
431 		m_ca = m_cb;
432 		m_pc = m_opcode & m_pc_mask;
433 	}
434 }
435 
op_call3()436 void tms1k_base_device::op_call3()
437 {
438 	// CALL/CALLL: conditional call
439 	if (m_status)
440 	{
441 		// mask clatch 3 bits (no need to mask others)
442 		m_clatch = (m_clatch << 1 | 1) & 7;
443 
444 		m_sr = m_sr << m_pc_bits | m_pc;
445 		m_pc = m_opcode & m_pc_mask;
446 
447 		m_ps = m_ps << 4 | m_pa;
448 		m_pa = m_pb;
449 
450 		m_cs = m_cs << 2 | m_ca;
451 		m_ca = m_cb;
452 	}
453 	else
454 	{
455 		m_pb = m_pa;
456 		m_cb = m_ca;
457 	}
458 }
459 
op_retn3()460 void tms1k_base_device::op_retn3()
461 {
462 	// RETN: return from subroutine
463 	if (m_clatch & 1)
464 	{
465 		m_clatch >>= 1;
466 
467 		m_pc = m_sr & m_pc_mask;
468 		m_sr >>= m_pc_bits;
469 
470 		m_pa = m_pb = m_ps & 0xf;
471 		m_ps >>= 4;
472 
473 		m_ca = m_cb = m_cs & 3;
474 		m_cs >>= 2;
475 	}
476 }
477 
478 
479 // handle other:
480 
481 // TMS1000/common
482 
op_sbit()483 void tms1k_base_device::op_sbit()
484 {
485 	// SBIT: set memory bit
486 	if (m_ram_out == -1)
487 		m_ram_out = m_ram_in;
488 	m_ram_out |= (m_cki_bus ^ 0xf);
489 }
490 
op_rbit()491 void tms1k_base_device::op_rbit()
492 {
493 	// RBIT: reset memory bit
494 	if (m_ram_out == -1)
495 		m_ram_out = m_ram_in;
496 	m_ram_out &= m_cki_bus;
497 }
498 
op_setr()499 void tms1k_base_device::op_setr()
500 {
501 	// SETR: set one R-output line
502 	m_r = m_r | (1 << m_y);
503 	m_write_r(0, m_r & m_r_mask, 0xffff);
504 }
505 
op_rstr()506 void tms1k_base_device::op_rstr()
507 {
508 	// RSTR: reset one R-output line
509 	m_r = m_r & ~(1 << m_y);
510 	m_write_r(0, m_r & m_r_mask, 0xffff);
511 }
512 
op_tdo()513 void tms1k_base_device::op_tdo()
514 {
515 	// TDO: transfer accumulator and status latch to O-output
516 	write_o_output(m_status_latch << 4 | m_a);
517 }
518 
op_clo()519 void tms1k_base_device::op_clo()
520 {
521 	// CLO: clear O-output
522 	write_o_output(0);
523 }
524 
op_ldx()525 void tms1k_base_device::op_ldx()
526 {
527 	// LDX: load X register with (x_bits) constant
528 	m_x = m_c4 >> (4-m_x_bits);
529 }
530 
op_comx()531 void tms1k_base_device::op_comx()
532 {
533 	// COMX: complement X register
534 	m_x ^= m_x_mask;
535 }
536 
op_comx8()537 void tms1k_base_device::op_comx8()
538 {
539 	// COMX8: complement MSB of X register
540 	// note: on TMS1100, the mnemonic is simply called "COMX"
541 	m_x ^= 1 << (m_x_bits-1);
542 }
543 
op_ldp()544 void tms1k_base_device::op_ldp()
545 {
546 	// LDP: load page buffer with constant
547 	m_pb = m_c4;
548 }
549 
550 
551 // TMS1100-specific
552 
op_comc()553 void tms1k_base_device::op_comc()
554 {
555 	// COMC: complement chapter buffer
556 	m_cb ^= 1;
557 }
558 
559 
560 // TMS1400-specific
561 
op_tpc()562 void tms1k_base_device::op_tpc()
563 {
564 	// TPC: transfer page buffer to chapter buffer
565 	m_cb = m_pb & 3;
566 }
567 
568 
569 // TMS0980-specific (and possibly child classes)
570 
op_xda()571 void tms1k_base_device::op_xda()
572 {
573 	// XDA: exchange DAM and A
574 	// note: setting A to DAM is done with DMTP and AUTA during this instruction
575 	m_ram_address |= (0x10 << (m_x_bits-1));
576 }
577 
op_off()578 void tms1k_base_device::op_off()
579 {
580 	// OFF: request auto power-off
581 	m_power_off(1);
582 }
583 
op_seac()584 void tms1k_base_device::op_seac()
585 {
586 	// SEAC: set end around carry
587 	m_eac = 1;
588 }
589 
op_reac()590 void tms1k_base_device::op_reac()
591 {
592 	// REAC: reset end around carry
593 	m_eac = 0;
594 }
595 
op_sal()596 void tms1k_base_device::op_sal()
597 {
598 	// SAL: set add latch (reset is done with RETN)
599 	m_add = 1;
600 }
601 
op_sbl()602 void tms1k_base_device::op_sbl()
603 {
604 	// SBL: set branch latch (reset is done with RETN)
605 	m_bl = 1;
606 }
607 
608 
609 
610 //-------------------------------------------------
611 //  execute
612 //-------------------------------------------------
613 
execute_one()614 void tms1k_base_device::execute_one()
615 {
616 	switch (m_subcycle)
617 	{
618 	case 0:
619 		// fetch: rom address 1/2
620 
621 		// execute: br/call 2/2
622 		if (m_fixed & F_BR)    op_br();
623 		if (m_fixed & F_CALL)  op_call();
624 		if (m_fixed & F_RETN)  op_retn();
625 
626 		// execute: k input valid, read ram, clear alu inputs
627 		dynamic_output();
628 		set_cki_bus();
629 		m_ram_in = m_data->read_byte(m_ram_address) & 0xf;
630 		m_dam_in = m_data->read_byte(m_ram_address | (0x10 << (m_x_bits-1))) & 0xf;
631 		m_p = 0;
632 		m_n = 0;
633 		m_carry_in = 0;
634 
635 		break;
636 
637 	case 1:
638 		// fetch: rom address 2/2
639 		m_rom_address = (m_ca << (m_pc_bits+4)) | (m_pa << m_pc_bits) | m_pc;
640 
641 		// execute: update alu inputs
642 		// N inputs
643 		if (m_micro & M_15TN)  m_n |= 0xf;
644 		if (m_micro & M_ATN)   m_n |= m_a;
645 		if (m_micro & M_NATN)  m_n |= (~m_a & 0xf);
646 		if (m_micro & M_CKN)   m_n |= m_cki_bus;
647 		if (m_micro & M_MTN)   m_n |= m_ram_in;
648 
649 		// P inputs
650 		if (m_micro & M_CKP)   m_p |= m_cki_bus;
651 		if (m_micro & M_MTP)   m_p |= m_ram_in;
652 		if (m_micro & M_YTP)   m_p |= m_y;
653 		if (m_micro & M_DMTP)  m_p |= m_dam_in;
654 		if (m_micro & M_NDMTP) m_p |= (~m_dam_in & 0xf);
655 
656 		// carry input
657 		if (m_micro & M_CIN)   m_carry_in |= 1;
658 		if (m_micro & M_SSS)   m_carry_in |= m_eac;
659 
660 		break;
661 
662 	case 2:
663 	{
664 		// fetch: nothing
665 
666 		// execute: perform alu logic
667 		// note: officially, only 1 alu operation is allowed per opcode
668 		m_adder_out = m_p + m_n + m_carry_in;
669 		int carry_out = m_adder_out >> 4 & 1;
670 		int status = 1;
671 		m_ram_out = -1;
672 
673 		if (m_micro & M_C8)    status &= carry_out;
674 		if (m_micro & M_NE)    status &= (m_n != m_p); // COMP
675 		if (m_micro & M_CKM)   m_ram_out = m_cki_bus;
676 
677 		// special status circuit
678 		if (m_micro & M_SSE)
679 		{
680 			m_eac = m_carry_out;
681 			if (m_add)
682 				m_eac |= carry_out;
683 		}
684 		m_carry_out = carry_out;
685 
686 		if (m_micro & M_STO || (m_micro & M_CME && m_eac == m_add))
687 			m_ram_out = m_a;
688 
689 		// handle the other fixed opcodes here
690 		if (m_fixed & F_SBIT)  op_sbit();
691 		if (m_fixed & F_RBIT)  op_rbit();
692 		if (m_fixed & F_SETR)  op_setr();
693 		if (m_fixed & F_RSTR)  op_rstr();
694 		if (m_fixed & F_TDO)   op_tdo();
695 		if (m_fixed & F_CLO)   op_clo();
696 		if (m_fixed & F_LDX)   op_ldx();
697 		if (m_fixed & F_COMX)  op_comx();
698 		if (m_fixed & F_COMX8) op_comx8();
699 		if (m_fixed & F_LDP)   op_ldp();
700 		if (m_fixed & F_COMC)  op_comc();
701 		if (m_fixed & F_TPC)   op_tpc();
702 		if (m_fixed & F_OFF)   op_off();
703 		if (m_fixed & F_SEAC)  op_seac();
704 		if (m_fixed & F_REAC)  op_reac();
705 		if (m_fixed & F_SAL)   op_sal();
706 		if (m_fixed & F_SBL)   op_sbl();
707 		if (m_fixed & F_XDA)   op_xda();
708 
709 		// after fixed opcode handling: store status, write ram
710 		m_status = status;
711 		if (m_ram_out != -1)
712 			m_data->write_byte(m_ram_address, m_ram_out);
713 
714 		break;
715 	}
716 
717 	case 3:
718 		// fetch: update pc, ram address 1/2
719 		// execute: register store 1/2
720 		break;
721 
722 	case 4:
723 		// execute: register store 2/2
724 		if (m_micro & M_AUTA)  m_a = m_adder_out & 0xf;
725 		if (m_micro & M_AUTY)  m_y = m_adder_out & 0xf;
726 		if (m_micro & M_STSL)  m_status_latch = m_status;
727 
728 		// fetch: update pc, ram address 2/2
729 		read_opcode();
730 		m_ram_address = m_x << 4 | m_y;
731 		break;
732 
733 	case 5:
734 		// fetch: instruction decode (handled above, before next_pc)
735 		// execute: br/call 1/2
736 		break;
737 	}
738 
739 	m_subcycle = (m_subcycle + 1) % 6;
740 }
741 
execute_run()742 void tms1k_base_device::execute_run()
743 {
744 	while (m_icount > 0)
745 	{
746 		m_icount--;
747 		execute_one();
748 	}
749 }
750