1 // license:BSD-3-Clause
2 // copyright-holders:Tony La Porta
3 	/**************************************************************************\
4 	*                 Texas Instruments TMS32010 DSP Emulator                  *
5 	*                                                                          *
6 	*                  Copyright Tony La Porta                                 *
7 	*                                                                          *
8 	*      Note :  This is a word based microcontroller, with addressing       *
9 	*              architecture based on the Harvard addressing scheme.        *
10 	*                                                                          *
11 	\**************************************************************************/
12 
13 #ifndef MAME_CPU_TMS32010_TMS32010_H
14 #define MAME_CPU_TMS32010_TMS32010_H
15 
16 #pragma once
17 
18 #define TMS32010_INT_PENDING    0x80000000
19 #define TMS32010_INT_NONE       0
20 
21 enum
22 {
23 	TMS32010_PC=1, TMS32010_SP,   TMS32010_STR,  TMS32010_ACC,
24 	TMS32010_PREG, TMS32010_TREG, TMS32010_AR0,  TMS32010_AR1,
25 	TMS32010_STK0, TMS32010_STK1, TMS32010_STK2, TMS32010_STK3
26 };
27 
28 
29 /****************************************************************************
30  *  Public Functions
31  */
32 
33 
34 class tms32010_device : public cpu_device
35 {
36 public:
37 	// construction/destruction
38 	tms32010_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
39 
40 	// configuration helpers
bio()41 	auto bio() { return m_bio_in.bind(); }
42 
43 	void tms32010_ram(address_map &map);
44 	void tms32015_ram(address_map &map);
45 protected:
46 	tms32010_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, address_map_constructor data_map, int addr_mask);
47 
48 	// device-level overrides
49 	virtual void device_start() override;
50 	virtual void device_reset() override;
51 
52 	// device_execute_interface overrides
execute_min_cycles()53 	virtual uint32_t execute_min_cycles() const noexcept override { return 1; }
execute_max_cycles()54 	virtual uint32_t execute_max_cycles() const noexcept override { return 3; }
execute_input_lines()55 	virtual uint32_t execute_input_lines() const noexcept override { return 1; }
56 	virtual void execute_run() override;
57 	virtual void execute_set_input(int inputnum, int state) override;
execute_clocks_to_cycles(uint64_t clocks)58 	virtual uint64_t execute_clocks_to_cycles(uint64_t clocks) const noexcept override { return (clocks + 4 - 1) / 4; }
execute_cycles_to_clocks(uint64_t cycles)59 	virtual uint64_t execute_cycles_to_clocks(uint64_t cycles) const noexcept override { return (cycles * 4); }
60 
61 	// device_memory_interface overrides
62 	virtual space_config_vector memory_space_config() const override;
63 
64 	// device_state_interface overrides
65 	virtual void state_string_export(const device_state_entry &entry, std::string &str) const override;
66 
67 	// device_disasm_interface overrides
68 	virtual std::unique_ptr<util::disasm_interface> create_disassembler() override;
69 
70 private:
71 	address_space_config m_program_config;
72 	address_space_config m_data_config;
73 	address_space_config m_io_config;
74 
75 	devcb_read_line m_bio_in;
76 
77 	typedef void ( tms32010_device::*opcode_func ) ();
78 	struct tms32010_opcode
79 	{
80 		uint8_t       cycles;
81 		opcode_func function;
82 	};
83 	static const tms32010_opcode s_opcode_main[256];
84 	static const tms32010_opcode s_opcode_7F[32];
85 
86 	/******************** CPU Internal Registers *******************/
87 	uint16_t  m_PC;
88 	uint16_t  m_PREVPC;     /* previous program counter */
89 	uint16_t  m_STR;
90 	PAIR    m_ACC;
91 	PAIR    m_ALU;
92 	PAIR    m_Preg;
93 	uint16_t  m_Treg;
94 	uint16_t  m_AR[2];
95 	uint16_t  m_STACK[4];
96 
97 	PAIR    m_opcode;
98 	int     m_INTF;       /* Pending Interrupt flag */
99 	int     m_icount;
100 	PAIR    m_oldacc;
101 	uint16_t  m_memaccess;
102 	int     m_addr_mask;
103 
104 	memory_access<12, 1, -1, ENDIANNESS_BIG>::cache m_cache;
105 	memory_access<12, 1, -1, ENDIANNESS_BIG>::specific m_program;
106 	memory_access< 8, 1, -1, ENDIANNESS_BIG>::specific m_data;
107 	memory_access< 4, 1, -1, ENDIANNESS_BIG>::specific m_io;
108 
109 	inline void CLR(uint16_t flag);
110 	inline void SET_FLAG(uint16_t flag);
111 	inline void CALCULATE_ADD_OVERFLOW(int32_t addval);
112 	inline void CALCULATE_SUB_OVERFLOW(int32_t subval);
113 	inline uint16_t POP_STACK();
114 	inline void PUSH_STACK(uint16_t data);
115 	inline void UPDATE_AR();
116 	inline void UPDATE_ARP();
117 	inline void getdata(uint8_t shift,uint8_t signext);
118 	inline void putdata(uint16_t data);
119 	inline void putdata_sar(uint8_t data);
120 	inline void putdata_sst(uint16_t data);
121 	void opcodes_7F();
122 	void illegal();
123 	void abst();
124 	void add_sh();
125 	void addh();
126 	void adds();
127 	void and_();
128 	void apac();
129 	void br();
130 	void banz();
131 	void bgez();
132 	void bgz();
133 	void bioz();
134 	void blez();
135 	void blz();
136 	void bnz();
137 	void bv();
138 	void bz();
139 	void cala();
140 	void call();
141 	void dint();
142 	void dmov();
143 	void eint();
144 	void in_p();
145 	void lac_sh();
146 	void lack();
147 	void lar_ar0();
148 	void lar_ar1();
149 	void lark_ar0();
150 	void lark_ar1();
151 	void larp_mar();
152 	void ldp();
153 	void ldpk();
154 	void lst();
155 	void lt();
156 	void lta();
157 	void ltd();
158 	void mpy();
159 	void mpyk();
160 	void nop();
161 	void or_();
162 	void out_p();
163 	void pac();
164 	void pop();
165 	void push();
166 	void ret();
167 	void rovm();
168 	void sach_sh();
169 	void sacl();
170 	void sar_ar0();
171 	void sar_ar1();
172 	void sovm();
173 	void spac();
174 	void sst();
175 	void sub_sh();
176 	void subc();
177 	void subh();
178 	void subs();
179 	void tblr();
180 	void tblw();
181 	void xor_();
182 	void zac();
183 	void zalh();
184 	void zals();
185 	inline int add_branch_cycle();
186 	int Ext_IRQ();
187 };
188 
189 
190 class tms32015_device : public tms32010_device
191 {
192 public:
193 	// construction/destruction
194 	tms32015_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
195 };
196 
197 
198 class tms32016_device : public tms32010_device
199 {
200 public:
201 	// construction/destruction
202 	tms32016_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
203 };
204 
205 
206 DECLARE_DEVICE_TYPE(TMS32010, tms32010_device)
207 DECLARE_DEVICE_TYPE(TMS32015, tms32015_device)
208 DECLARE_DEVICE_TYPE(TMS32016, tms32016_device)
209 
210 
211 #endif // MAME_CPU_TMS32010_TMS32010_H
212