summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/v60/v60mem.c
blob: fc88294ba3f7c54f2f4966fe3fd9447b43cc3a05 (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
/****************************************************************/
/* Structure defining all callbacks for different architectures */
/****************************************************************/

struct cpu_info {
	UINT8  (*mr8) (const address_space *space, offs_t address);
	void   (*mw8) (const address_space *space, offs_t address, UINT8  data);
	UINT16 (*mr16)(const address_space *space, offs_t address);
	void   (*mw16)(const address_space *space, offs_t address, UINT16 data);
	UINT32 (*mr32)(const address_space *space, offs_t address);
	void   (*mw32)(const address_space *space, offs_t address, UINT32 data);
	UINT8  (*or8) (const address_space *space, offs_t address);
	UINT16 (*or16)(const address_space *space, offs_t address);
	UINT32 (*or32)(const address_space *space, offs_t address);
	UINT32 start_pc;
};



/*****************************************************************/
/* Memory accesses for 16-bit data bus, 24-bit address bus (V60) */
/*****************************************************************/

#define MemRead8_16		memory_read_byte_16le
#define MemWrite8_16	memory_write_byte_16le

static UINT16 MemRead16_16(const address_space *space, offs_t address)
{
	if (!(address & 1))
		return memory_read_word_16le(space, address);
	else
	{
		UINT16 result = memory_read_byte_16le(space, address);
		return result | memory_read_byte_16le(space, address + 1) << 8;
	}
}

static void MemWrite16_16(const address_space *space, offs_t address, UINT16 data)
{
	if (!(address & 1))
		memory_write_word_16le(space, address, data);
	else
	{
		memory_write_byte_16le(space, address, data);
		memory_write_byte_16le(space, address + 1, data >> 8);
	}
}

static UINT32 MemRead32_16(const address_space *space, offs_t address)
{
	if (!(address & 1))
	{
		UINT32 result = memory_read_word_16le(space, address);
		return result | (memory_read_word_16le(space, address + 2) << 16);
	}
	else
	{
		UINT32 result = memory_read_byte_16le(space, address);
		result |= memory_read_word_16le(space, address + 1) << 8;
		return result | memory_read_byte_16le(space, address + 3) << 24;
	}
}

static void MemWrite32_16(const address_space *space, offs_t address, UINT32 data)
{
	if (!(address & 1))
	{
		memory_write_word_16le(space, address, data);
		memory_write_word_16le(space, address + 2, data >> 16);
	}
	else
	{
		memory_write_byte_16le(space, address, data);
		memory_write_word_16le(space, address + 1, data >> 8);
		memory_write_byte_16le(space, address + 3, data >> 24);
	}
}


/*****************************************************************/
/* Opcode accesses for 16-bit data bus, 24-bit address bus (V60) */
/*****************************************************************/

static UINT8 OpRead8_16(const address_space *space, offs_t address)
{
	return memory_decrypted_read_byte(space, BYTE_XOR_LE(address));
}

static UINT16 OpRead16_16(const address_space *space, offs_t address)
{
	return memory_decrypted_read_byte(space, BYTE_XOR_LE(address)) | (memory_decrypted_read_byte(space, BYTE_XOR_LE(address + 1)) << 8);
}

static UINT32 OpRead32_16(const address_space *space, offs_t address)
{
	return memory_decrypted_read_byte(space, BYTE_XOR_LE(address)) | (memory_decrypted_read_byte(space, BYTE_XOR_LE(address + 1)) << 8) |
			(memory_decrypted_read_byte(space, BYTE_XOR_LE(address + 2)) << 16) | (memory_decrypted_read_byte(space, BYTE_XOR_LE(address + 3)) << 24);
}



/*****************************************************************/
/* Memory accesses for 32-bit data bus, 32-bit address bus (V70) */
/*****************************************************************/

#define MemRead8_32		memory_read_byte_32le
#define MemWrite8_32	memory_write_byte_32le

static UINT16 MemRead16_32(const address_space *space, offs_t address)
{
	if (!(address & 1))
		return memory_read_word_32le(space, address);
	else
	{
		UINT16 result = memory_read_byte_32le(space, address);
		return result | memory_read_byte_32le(space, address + 1) << 8;
	}
}

static void MemWrite16_32(const address_space *space, offs_t address, UINT16 data)
{
	if (!(address & 1))
		memory_write_word_32le(space, address, data);
	else
	{
		memory_write_byte_32le(space, address, data);
		memory_write_byte_32le(space, address + 1, data >> 8);
	}
}

static UINT32 MemRead32_32(const address_space *space, offs_t address)
{
	if (!(address & 3))
		return memory_read_dword_32le(space, address);
	else if (!(address & 1))
	{
		UINT32 result = memory_read_word_32le(space, address);
		return result | (memory_read_word_32le(space, address + 2) << 16);
	}
	else
	{
		UINT32 result = memory_read_byte_32le(space, address);
		result |= memory_read_word_32le(space, address + 1) << 8;
		return result | memory_read_byte_32le(space, address + 3) << 24;
	}
}

static void MemWrite32_32(const address_space *space, offs_t address, UINT32 data)
{
	if (!(address & 3))
		memory_write_dword_32le(space, address, data);
	else if (!(address & 1))
	{
		memory_write_word_32le(space, address, data);
		memory_write_word_32le(space, address + 2, data >> 16);
	}
	else
	{
		memory_write_byte_32le(space, address, data);
		memory_write_word_32le(space, address + 1, data >> 8);
		memory_write_byte_32le(space, address + 3, data >> 24);
	}
}



/*****************************************************************/
/* Opcode accesses for 32-bit data bus, 32-bit address bus (V60) */
/*****************************************************************/

static UINT8 OpRead8_32(const address_space *space, offs_t address)
{
	return memory_decrypted_read_byte(space, BYTE4_XOR_LE(address));
}

static UINT16 OpRead16_32(const address_space *space, offs_t address)
{
	return memory_decrypted_read_byte(space, BYTE4_XOR_LE(address)) | (memory_decrypted_read_byte(space, BYTE4_XOR_LE(address + 1)) << 8);
}

static UINT32 OpRead32_32(const address_space *space, offs_t address)
{
	return memory_decrypted_read_byte(space, BYTE4_XOR_LE(address)) | (memory_decrypted_read_byte(space, BYTE4_XOR_LE(address + 1)) << 8) |
			(memory_decrypted_read_byte(space, BYTE4_XOR_LE(address + 2)) << 16) | (memory_decrypted_read_byte(space, BYTE4_XOR_LE(address + 3)) << 24);
}



/************************************************/
/* Structures pointing to various I/O functions */
/************************************************/

static const struct cpu_info v60_i =
{
	MemRead8_16,  MemWrite8_16,  MemRead16_16,  MemWrite16_16,  MemRead32_16,  MemWrite32_16,
	OpRead8_16,                  OpRead16_16,                   OpRead32_16,
	0xfffff0
};

static const struct cpu_info v70_i =
{
	MemRead8_32,  MemWrite8_32,  MemRead16_32,  MemWrite16_32,  MemRead32_32,  MemWrite32_32,
	OpRead8_32,                  OpRead16_32,                   OpRead32_32,
	0xfffffff0
};



/**************************************/
/* Macro shorthands for I/O functions */
/**************************************/

#define MemRead8    cpustate->info.mr8
#define MemWrite8   cpustate->info.mw8
#define MemRead16   cpustate->info.mr16
#define MemWrite16  cpustate->info.mw16
#define MemRead32   cpustate->info.mr32
#define MemWrite32  cpustate->info.mw32

#if defined(LSB_FIRST) && !defined(ALIGN_INTS)
#define OpRead8(s, a)	(memory_decrypted_read_byte(s, a))
#define OpRead16(s, a)	(memory_decrypted_read_word(s, a))
#define OpRead32(s, a)	(memory_decrypted_read_dword(s, a))
#else
#define OpRead8     cpustate->info.or8
#define OpRead16    cpustate->info.or16
#define OpRead32    cpustate->info.or32
#endif