summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/sns_spc7110.h
blob: 7321707a288db6ab4f323d769128faebb1b6b44d (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
#ifndef __SNS_SPC7110_H
#define __SNS_SPC7110_H

#include "machine/sns_slot.h"
#include "machine/sns_rom21.h"


enum RTC_State
{
	RTCS_Inactive,
	RTCS_ModeSelect,
	RTCS_IndexSelect,
	RTCS_Write
};

enum RTC_Mode
{
	RTCM_Linear = 0x03,
	RTCM_Indexed = 0x0c
};

class SPC7110_Decomp
{
public:
	SPC7110_Decomp(running_machine &machine);

	running_machine &machine() const { return m_machine; }

	void init(running_machine &machine, UINT8 *ROM, UINT32 len, UINT32 mode, UINT32 offset, UINT32 index);
	void reset();

	UINT8 read(UINT8 *ROM, UINT32 len);
	void write(UINT8 data);
	void mode0(UINT8 init, UINT8 *ROM, UINT32 len);
	void mode1(UINT8 init, UINT8 *ROM, UINT32 len);
	void mode2(UINT8 init, UINT8 *ROM, UINT32 len);

	UINT8 dataread(UINT8 *ROM, UINT32 len);
	UINT8 probability(UINT32 n);
	UINT8 next_lps(UINT32 n);
	UINT8 next_mps(UINT32 n);
	UINT8 toggle_invert(UINT32 n);
	UINT32 morton_2x8(UINT32 data);
	UINT32 morton_4x8(UINT32 data);

	UINT32 m_decomp_mode;
	UINT32 m_decomp_offset;

	UINT8 *m_decomp_buffer;
	UINT32 m_decomp_buffer_rdoffset;
	UINT32 m_decomp_buffer_wroffset;
	UINT32 m_decomp_buffer_length;

	struct ContextState
	{
		UINT8 index;
		UINT8 invert;
	} m_context[32];

	UINT32 m_morton16[2][256];
	UINT32 m_morton32[4][256];


private:
	running_machine& m_machine;
	UINT32 m_rom_size;
};

// ======================> sns_rom_spc7110_device

class sns_rom_spc7110_device : public sns_rom21_device
{
public:
	// construction/destruction
	sns_rom_spc7110_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
	sns_rom_spc7110_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	// device-level overrides
	virtual void device_start();
	virtual void device_config_complete() { m_shortname = "sns_rom_spc7110"; }

	// reading and writing
	virtual DECLARE_READ8_MEMBER(read_l);
	virtual DECLARE_READ8_MEMBER(read_h);
	virtual DECLARE_WRITE8_MEMBER(write_l);

	virtual DECLARE_READ8_MEMBER(chip_read);
	virtual DECLARE_WRITE8_MEMBER(chip_write);

	void spc7110_start();
	UINT32 spc7110_datarom_addr(UINT32 addr, UINT32 len);
	UINT32 spc7110_data_pointer();
	UINT32 spc7110_data_adjust();
	UINT32 spc7110_data_increment();
	void spc7110_set_data_pointer(UINT32 addr);
	void spc7110_set_data_adjust(UINT32 addr);
	void spc7110_update_time(UINT8 offset);


	//==================
	//decompression unit
	//==================
	UINT8 m_r4801;        // compression table low
	UINT8 m_r4802;        // compression table high
	UINT8 m_r4803;        // compression table bank
	UINT8 m_r4804;        // compression table index
	UINT8 m_r4805;        // decompression buffer index low
	UINT8 m_r4806;        // decompression buffer index high
	UINT8 m_r4807;        // ???
	UINT8 m_r4808;        // ???
	UINT8 m_r4809;        // compression length low
	UINT8 m_r480a;        // compression length high
	UINT8 m_r480b;        // decompression control register
	UINT8 m_r480c;        // decompression status

	SPC7110_Decomp* m_decomp;

	UINT8 m_r4811;        // data pointer low
	UINT8 m_r4812;        // data pointer high
	UINT8 m_r4813;        // data pointer bank
	UINT8 m_r4814;        // data adjust low
	UINT8 m_r4815;        // data adjust high
	UINT8 m_r4816;        // data increment low
	UINT8 m_r4817;        // data increment high
	UINT8 m_r4818;        // data port control register

	UINT8 m_r481x;

	UINT8 m_r4814_latch;
	UINT8 m_r4815_latch;

	//=========
	//math unit
	//=========
	UINT8 m_r4820;        // 16-bit multiplicand B0, 32-bit dividend B0
	UINT8 m_r4821;        // 16-bit multiplicand B1, 32-bit dividend B1
	UINT8 m_r4822;        // 32-bit dividend B2
	UINT8 m_r4823;        // 32-bit dividend B3
	UINT8 m_r4824;        // 16-bit multiplier B0
	UINT8 m_r4825;        // 16-bit multiplier B1
	UINT8 m_r4826;        // 16-bit divisor B0
	UINT8 m_r4827;        // 16-bit divisor B1
	UINT8 m_r4828;        // 32-bit product B0, 32-bit quotient B0
	UINT8 m_r4829;        // 32-bit product B1, 32-bit quotient B1
	UINT8 m_r482a;        // 32-bit product B2, 32-bit quotient B2
	UINT8 m_r482b;        // 32-bit product B3, 32-bit quotient B3
	UINT8 m_r482c;        // 16-bit remainder B0
	UINT8 m_r482d;        // 16-bit remainder B1
	UINT8 m_r482e;        // math control register
	UINT8 m_r482f;        // math status

	//===================
	//memory mapping unit
	//===================
	UINT8 m_r4830;        // SRAM write enable
	UINT8 m_r4831;        // $[d0-df]:[0000-ffff] mapping
	UINT8 m_r4832;        // $[e0-ef]:[0000-ffff] mapping
	UINT8 m_r4833;        // $[f0-ff]:[0000-ffff] mapping
	UINT8 m_r4834;        // ???

	UINT32 m_dx_offset;
	UINT32 m_ex_offset;
	UINT32 m_fx_offset;

	//====================
	//real-time clock unit
	//====================
	UINT8 m_r4840;        // RTC latch
	UINT8 m_r4841;        // RTC index/data port
	UINT8 m_r4842;        // RTC status

	UINT32 m_rtc_state;
	UINT32 m_rtc_mode;
	UINT32 m_rtc_index;

	UINT64 m_rtc_offset;

	//this is now allocated in the main snes cart class, to allow saving to nvram
	//UINT8 m_rtc_ram[16];  // 0-12 secs, min, hrs, etc.; 13-14-15 control registers

	UINT8 m_ram[0x2000];
};

// ======================> sns_rom_spc7110_device

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

	// device-level overrides
	virtual void device_start();
	virtual void device_config_complete() { m_shortname = "sns_rom_spc7110rtc"; }

	// reading and writing

// we just use the spc7110 ones for the moment, pending the split of regs 0x4840-0x4842 (RTC) from the base add-on
//  virtual DECLARE_READ8_MEMBER(read_l);
//  virtual DECLARE_READ8_MEMBER(read_h);
//  virtual DECLARE_WRITE8_MEMBER(write_l);

//  virtual DECLARE_READ8_MEMBER(chip_read);
//  virtual DECLARE_WRITE8_MEMBER(chip_write);
};

// device type definition
extern const device_type SNS_HIROM_SPC7110;
extern const device_type SNS_HIROM_SPC7110_RTC;

#endif