summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/upd7725/upd7725.h
blob: 82f65034a4c5a0babf09a3ad1cf06fef8d97a440 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/***************************************************************************

    upd7725.h

    Core implementation for the portable NEC uPD7725/uPD96050 emulator

****************************************************************************/

#pragma once

#ifndef __UPD7725_H__
#define __UPD7725_H__

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

class necdsp_device;
class upd7725_device;
class upd96050_device;

// ======================> necdsp_device_config

class necdsp_device_config :	public cpu_device_config
{
	friend class necdsp_device;

protected:
	// construction/destruction
	necdsp_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock, UINT32 abits, UINT32 dbits, const char *name);

public:
	// allocators
	static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
	virtual device_t *alloc_device(running_machine &machine) const;

protected:
	// device_config_execute_interface overrides
	virtual UINT32 execute_min_cycles() const;
	virtual UINT32 execute_max_cycles() const;
	virtual UINT32 execute_input_lines() const;

	// device_config_memory_interface overrides
	virtual const address_space_config *memory_space_config(int spacenum = 0) const;

	// device_config_disasm_interface overrides
	virtual UINT32 disasm_min_opcode_bytes() const;
	virtual UINT32 disasm_max_opcode_bytes() const;

	// inline data
	const address_space_config m_program_config, m_data_config;
};

class upd7725_device_config :	public necdsp_device_config
{
	friend class upd7725_device;

	// construction/destruction
	upd7725_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);

public:
	// allocators
	static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
	virtual device_t *alloc_device(running_machine &machine) const;
};

class upd96050_device_config :	public necdsp_device_config
{
	friend class upd96050_device;

	// construction/destruction
	upd96050_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);

public:
	// allocators
	static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
	virtual device_t *alloc_device(running_machine &machine) const;
};

// ======================> necdsp_device

class necdsp_device : public cpu_device
{
	friend class necdsp_device_config;

protected:
	// construction/destruction
	necdsp_device(running_machine &_machine, const necdsp_device_config &config);

public:
	UINT8 snesdsp_read(bool mode);
	void snesdsp_write(bool mode, UINT8 data);

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_reset();

	// device_execute_interface overrides
	virtual void execute_run();

	// device_state_interface overrides
	virtual void state_import(const device_state_entry &entry);
	virtual void state_export(const device_state_entry &entry);
	virtual void state_string_export(const device_state_entry &entry, astring &string);

	// device_disasm_interface overrides
	virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);

	UINT16 dataRAM[2048];

private:
	struct Flag
	{
		bool s1, s0, c, z, ov1, ov0;
	
		inline operator unsigned() const
		{
			return (s1 << 5) + (s0 << 4) + (c << 3) + (z << 2) + (ov1 << 1) + (ov0 << 0);
		}

		inline unsigned operator=(unsigned d)
		{
			s1 = d & 0x20; s0 = d & 0x10; c = d & 0x08; z = d & 0x04; ov1 = d & 0x02; ov0 = d & 0x01;
			return d;
		}
	};

	struct Status
	{
		bool rqm, usf1, usf0, drs, dma, drc, soc, sic, ei, p1, p0;
		
		inline operator unsigned() const
		{
			return (rqm << 15) + (usf1 << 14) + (usf0 << 13) + (drs << 12)
			   + (dma << 11) + (drc  << 10) + (soc  <<  9) + (sic <<  8)
			   + (ei  <<  7) + (p1   <<  1) + (p0   <<  0);
		}
		
		inline unsigned operator=(unsigned d)
		{
			rqm = d & 0x8000; usf1 = d & 0x4000; usf0 = d & 0x2000; drs = d & 0x1000;
			dma = d & 0x0800; drc  = d & 0x0400; soc  = d & 0x0200; sic = d & 0x0100;
			ei  = d & 0x0080; p1   = d & 0x0002; p0   = d & 0x0001;
			return d;
		}
	};

	struct Regs 
	{
		UINT16 pc;			//program counter
		UINT16 stack[16];	//LIFO
		UINT16 rp;			//ROM pointer
		UINT16 dp;			//data pointer
		UINT8  sp;			//stack pointer
		INT16  k;
		INT16  l;
		INT16  m;
		INT16  n;
		INT16  a;         //accumulator
		INT16  b;         //accumulator
		Flag  flaga;
		Flag  flagb;
		UINT16 tr;        //temporary register
		UINT16 trb;       //temporary register
		Status sr;        //status register
		UINT16 dr;        //data register
		UINT16 si;
		UINT16 so;
		UINT16 idb;
	} regs;

  void exec_op(UINT32 opcode);
  void exec_rt(UINT32 opcode);
  void exec_jp(UINT32 opcode);
  void exec_ld(UINT32 opcode);

  void stack_push();
  void stack_pull();

  int m_icount;

  address_space *m_program, *m_data;
  direct_read_data *m_direct;
};

class upd7725_device : public necdsp_device
{
	friend class upd7725_device_config;

	// construction/destruction
	upd7725_device(running_machine &_machine, const upd7725_device_config &config);
};

class upd96050_device : public necdsp_device
{
	friend class upd96050_device_config;

	// construction/destruction
	upd96050_device(running_machine &_machine, const upd96050_device_config &config);

public:
	UINT16 dataram_r(UINT16 addr) { return dataRAM[addr]; }
	void dataram_w(UINT16 addr, UINT16 data) { dataRAM[addr] = data; }
};

// device type definition
extern const device_type UPD7725;
extern const device_type UPD96050;

//**************************************************************************
//  ENUMERATIONS
//**************************************************************************

// registers
enum
{
	UPD7725_PC = 1,
	UPD7725_RP,
	UPD7725_DP,
	UPD7725_K,
	UPD7725_L,
	UPD7725_M,
	UPD7725_N,
	UPD7725_A,
	UPD7725_B,
	UPD7725_FLAGA,
	UPD7725_FLAGB,
	UPD7725_SR,
	UPD7725_DR,
	UPD7725_SP,
	UPD7725_TR,
	UPD7725_TRB,
	UPD7725_SI,
	UPD7725_SO,
	UPD7725_IDB
};

#endif // UPD7725