summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/cubeqcpu/cubeqcpu.h
blob: 47bf5f00c8799a2a4a3eab9df5eb4260021a014e (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/***************************************************************************

    cubeqcpu.h
    Interface file for the Cube Quest CPUs
    Written by Phil Bennett

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

#ifndef _CUBEQCPU_H
#define _CUBEQCPU_H


/***************************************************************************
    COMPILE-TIME DEFINITIONS
***************************************************************************/


/***************************************************************************
    GLOBAL CONSTANTS
***************************************************************************/


/***************************************************************************
    REGISTER ENUMERATION
***************************************************************************/

enum
{
	CQUESTSND_PC = 1,
	CQUESTSND_Q,
	CQUESTSND_RAM0,
	CQUESTSND_RAM1,
	CQUESTSND_RAM2,
	CQUESTSND_RAM3,
	CQUESTSND_RAM4,
	CQUESTSND_RAM5,
	CQUESTSND_RAM6,
	CQUESTSND_RAM7,
	CQUESTSND_RAM8,
	CQUESTSND_RAM9,
	CQUESTSND_RAMA,
	CQUESTSND_RAMB,
	CQUESTSND_RAMC,
	CQUESTSND_RAMD,
	CQUESTSND_RAME,
	CQUESTSND_RAMF,
	CQUESTSND_RTNLATCH,
	CQUESTSND_ADRCNTR,
	CQUESTSND_DINLATCH,
};

enum
{
	CQUESTROT_PC = 1,
	CQUESTROT_Q,
	CQUESTROT_RAM0,
	CQUESTROT_RAM1,
	CQUESTROT_RAM2,
	CQUESTROT_RAM3,
	CQUESTROT_RAM4,
	CQUESTROT_RAM5,
	CQUESTROT_RAM6,
	CQUESTROT_RAM7,
	CQUESTROT_RAM8,
	CQUESTROT_RAM9,
	CQUESTROT_RAMA,
	CQUESTROT_RAMB,
	CQUESTROT_RAMC,
	CQUESTROT_RAMD,
	CQUESTROT_RAME,
	CQUESTROT_RAMF,
	CQUESTROT_SEQCNT,
	CQUESTROT_DYNADDR,
	CQUESTROT_DYNDATA,
	CQUESTROT_YRLATCH,
	CQUESTROT_YDLATCH,
	CQUESTROT_DINLATCH,
	CQUESTROT_DSRCLATCH,
	CQUESTROT_RSRCLATCH,
	CQUESTROT_LDADDR,
	CQUESTROT_LDDATA,
};

enum
{
	CQUESTLIN_FGPC = 1,
	CQUESTLIN_BGPC,
	CQUESTLIN_Q,
	CQUESTLIN_RAM0,
	CQUESTLIN_RAM1,
	CQUESTLIN_RAM2,
	CQUESTLIN_RAM3,
	CQUESTLIN_RAM4,
	CQUESTLIN_RAM5,
	CQUESTLIN_RAM6,
	CQUESTLIN_RAM7,
	CQUESTLIN_RAM8,
	CQUESTLIN_RAM9,
	CQUESTLIN_RAMA,
	CQUESTLIN_RAMB,
	CQUESTLIN_RAMC,
	CQUESTLIN_RAMD,
	CQUESTLIN_RAME,
	CQUESTLIN_RAMF,
	CQUESTLIN_FADLATCH,
	CQUESTLIN_BADLATCH,
	CQUESTLIN_SREG,
	CQUESTLIN_XCNT,
	CQUESTLIN_YCNT,
	CQUESTLIN_CLATCH,
	CQUESTLIN_ZLATCH,
};


/***************************************************************************
    CONFIGURATION STRUCTURE
***************************************************************************/


#define MCFG_CQUESTSND_CONFIG(_dac_w, _sound_tag) \
	cquestsnd_cpu_device::set_dac_w(*device, DEVCB2_##_dac_w); \
	cquestsnd_cpu_device::set_sound_region(*device, _sound_tag);


#define MCFG_CQUESTROT_CONFIG(_linedata_w) \
	cquestrot_cpu_device::set_linedata_w(*device, DEVCB2_##_linedata_w );


#define MCFG_CQUESTLIN_CONFIG(_linedata_r) \
	cquestlin_cpu_device::set_linedata_r(*device, DEVCB2_##_linedata_r );


/***************************************************************************
    PUBLIC FUNCTIONS
***************************************************************************/

class cquestsnd_cpu_device : public cpu_device
{
public:
	// construction/destruction
	cquestsnd_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// static configuration helpers
	template<class _Object> static devcb2_base &set_dac_w(device_t &device, _Object object) { return downcast<cquestsnd_cpu_device &>(device).m_dac_w.set_callback(object); }
	static void set_sound_region(device_t &device, const char *tag) { downcast<cquestsnd_cpu_device &>(device).m_sound_region_tag = tag; }

	DECLARE_WRITE16_MEMBER(sndram_w);
	DECLARE_READ16_MEMBER(sndram_r);

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

	// device_execute_interface overrides
	virtual UINT32 execute_min_cycles() const { return 1; }
	virtual UINT32 execute_max_cycles() const { return 1; }
	virtual UINT32 execute_input_lines() const { return 0; }
	virtual void execute_run();

	// device_memory_interface overrides
	virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; }

	// device_disasm_interface overrides
	virtual UINT32 disasm_min_opcode_bytes() const { return 8; }
	virtual UINT32 disasm_max_opcode_bytes() const { return 8; }
	virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);

private:
	address_space_config m_program_config;

	/* AM2901 internals */
	UINT16  m_ram[16];
	UINT16  m_q;
	UINT16  m_f;
	UINT16  m_y;
	UINT32  m_cflag;
	UINT32  m_vflag;

	UINT8   m_pc;         /* 2 x LS161 @ 6E, 6F */
	UINT16  m_platch;
	UINT8   m_rtnlatch;   /* LS374 @ 5F */
	UINT8   m_adrcntr;    /* 2 x LS161 */
	UINT16  m_adrlatch;
	UINT16  m_dinlatch;
	UINT16  m_ramwlatch;

	UINT16 m_sram[4096/2];

	int m_prev_ipram;
	int m_prev_ipwrt;

	devcb2_write16 m_dac_w;
	const char *m_sound_region_tag;
	UINT16 *m_sound_data;

	address_space *m_program;
	direct_read_data *m_direct;
	int m_icount;

	int do_sndjmp(int jmp);
};


class cquestrot_cpu_device : public cpu_device
{
public:
	// construction/destruction
	cquestrot_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// static configuration helpers
	template<class _Object> static devcb2_base &set_linedata_w(device_t &device, _Object object) { return downcast<cquestrot_cpu_device &>(device).m_linedata_w.set_callback(object); }

	DECLARE_READ16_MEMBER(linedata_r);
	DECLARE_WRITE16_MEMBER(rotram_w);
	DECLARE_READ16_MEMBER(rotram_r);

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

	// device_execute_interface overrides
	virtual UINT32 execute_min_cycles() const { return 1; }
	virtual UINT32 execute_max_cycles() const { return 1; }
	virtual UINT32 execute_input_lines() const { return 0; }
	virtual void execute_run();

	// device_memory_interface overrides
	virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; }

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

	// device_disasm_interface overrides
	virtual UINT32 disasm_min_opcode_bytes() const { return 8; }
	virtual UINT32 disasm_max_opcode_bytes() const { return 8; }
	virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);

private:
	address_space_config m_program_config;
	devcb2_write16 m_linedata_w;

	/* AM2901 internals */
	UINT16  m_ram[16];
	UINT16  m_q;
	UINT16  m_f;
	UINT16  m_y;
	UINT32  m_cflag;
	UINT32  m_vflag;

	UINT16  m_pc;         /* 12-bit, but only 9 used */
	UINT8   m_seqcnt;     /* 4-bit counter */

	UINT8   m_dsrclatch;
	UINT8   m_rsrclatch;
	UINT16  m_dynaddr;    /* LS374 at 2D, 8D  */
	UINT16  m_dyndata;    /* LS374 at 10B, 9B */
	UINT16  m_yrlatch;    /* LS374 at 9D, 10D */
	UINT16  m_ydlatch;    /* LS374 at 9C, 10C */
	UINT16  m_dinlatch;
	UINT8   m_divreg;     /* LS74 at ? */

	UINT16  m_linedata;
	UINT16  m_lineaddr;

	UINT16 m_dram[16384]; /* Shared with 68000 */
	UINT16 m_sram[2048];  /* Private */

	UINT8 m_prev_dred;
	UINT8 m_prev_dwrt;
	UINT8 m_wc;
	UINT8 m_rc;
	UINT8 m_clkcnt;

	address_space *m_program;
	direct_read_data *m_direct;
	int m_icount;

	// For the debugger
	UINT8 m_flags;

	int do_rotjmp(int jmp);
};


class cquestlin_cpu_device : public cpu_device
{
public:
	// construction/destruction
	cquestlin_cpu_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// static configuration helpers
	template<class _Object> static devcb2_base &set_linedata_r(device_t &device, _Object object) { return downcast<cquestlin_cpu_device &>(device).m_linedata_r.set_callback(object); }

	DECLARE_WRITE16_MEMBER( linedata_w );
	void cubeqcpu_swap_line_banks();
	void cubeqcpu_clear_stack();
	UINT8 cubeqcpu_get_ptr_ram_val(int i);
	UINT32* cubeqcpu_get_stack_ram();

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

	// device_execute_interface overrides
	virtual UINT32 execute_min_cycles() const { return 1; }
	virtual UINT32 execute_max_cycles() const { return 1; }
	virtual UINT32 execute_input_lines() const { return 0; }
	virtual void execute_run();

	// device_memory_interface overrides
	virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const { return (spacenum == AS_PROGRAM) ? &m_program_config : NULL; }

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

	// device_disasm_interface overrides
	virtual UINT32 disasm_min_opcode_bytes() const { return 8; }
	virtual UINT32 disasm_max_opcode_bytes() const { return 8; }
	virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options);

private:
	address_space_config m_program_config;
	devcb2_read16 m_linedata_r;

	/* 12-bit AM2901 internals */
	UINT16  m_ram[16];
	UINT16  m_q;
	UINT16  m_f;
	UINT16  m_y;
	UINT32  m_cflag;
	UINT32  m_vflag;

	UINT8   m_pc[2];      /* Two program counters; one for FG, other for BG */

	UINT16  m_seqcnt;     /* 12-bit */
	UINT16  m_clatch;     /* LS374 at 9E and 1-bit FF */
	UINT8   m_zlatch;     /* LS374 at 4H */

	UINT16  m_xcnt;
	UINT16  m_ycnt;
	UINT8   m_sreg;

	UINT16  m_fadlatch;
	UINT16  m_badlatch;

	UINT16  m_sramdlatch;

	UINT8   m_fglatch;
	UINT8   m_bglatch;
	UINT8   m_gt0reg;
	UINT8   m_fdxreg;
	UINT32  m_field;

	UINT32  m_clkcnt;

	/* RAM */
	UINT16  m_sram[4096];		/* Shared with rotate CPU */
	UINT8   m_ptr_ram[1024];	/* Pointer RAM */
	UINT32  m_e_stack[32768];	/* Stack DRAM: 32kx20 */
	UINT32  m_o_stack[32768];	/* Stack DRAM: 32kx20 */

	address_space *m_program;
	direct_read_data *m_direct;
	int m_icount;

	// For the debugger
	UINT8 m_flags;
	UINT16 m_curpc;

	int do_linjmp(int jmp);
};


extern const device_type CQUESTSND;
extern const device_type CQUESTROT;
extern const device_type CQUESTLIN;


#endif /* _CUBEQCPU_H */