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
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
Sega 16-bit common hardware
***************************************************************************/
#ifndef MAME_MACHINE_SEGAIC16_H
#define MAME_MACHINE_SEGAIC16_H
#pragma once
#include "cpu/m68000/m68000.h"
#include "machine/fd1089.h"
#include "machine/fd1094.h"
#include "emupal.h"
#include "screen.h"
//**************************************************************************
// INTERFACE CONFIGURATION MACROS
//**************************************************************************
#define MCFG_SEGA_315_5195_CPU(_cputag) \
downcast<sega_315_5195_mapper_device &>(*device).set_cputag(_cputag);
#define MCFG_SEGA_315_5195_MAPPER_HANDLER(_class, _mapper) \
downcast<sega_315_5195_mapper_device &>(*device).set_mapper(sega_315_5195_mapper_device::mapper_delegate(&_class::_mapper, #_class "::" #_mapper, nullptr, (_class *)nullptr));
#define MCFG_SEGA_315_5195_PBF_CALLBACK(_devcb) \
downcast<sega_315_5195_mapper_device &>(*device).set_pbf_callback(DEVCB_##_devcb);
#define MCFG_SEGA_315_5195_MCU_INT_CALLBACK(_devcb) \
downcast<sega_315_5195_mapper_device &>(*device).set_mcu_int_callback(DEVCB_##_devcb);
#define MCFG_SEGA_315_5248_MULTIPLIER_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, SEGA_315_5248_MULTIPLIER, 0)
#define MCFG_SEGA_315_5249_DIVIDER_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, SEGA_315_5249_DIVIDER, 0)
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> sega_16bit_common_base
class sega_16bit_common_base : public driver_device
{
public:
// open bus read helpers
DECLARE_READ16_MEMBER( open_bus_r );
// palette helpers
DECLARE_WRITE16_MEMBER( paletteram_w );
DECLARE_WRITE16_MEMBER( philko_paletteram_w );
protected:
// construction/destruction
sega_16bit_common_base(const machine_config &mconfig, device_type type, const char *tag);
// internal helpers
void palette_init();
public: // -- stupid system16.c
// memory pointers
required_shared_ptr<uint16_t> m_paletteram;
protected:
// internal state
bool m_open_bus_recurse; // flag to track recursion through open_bus_r
uint32_t m_palette_entries; // number of palette entries
uint8_t m_palette_normal[32]; // RGB translations for normal pixels
uint8_t m_palette_shadow[32]; // RGB translations for shadowed pixels
uint8_t m_palette_hilight[32]; // RGB translations for hilighted pixels
required_device<screen_device> m_screen;
required_device<palette_device> m_palette;
};
// ======================> sega_315_5195_mapper_device
class sega_315_5195_mapper_device : public device_t
{
public:
typedef device_delegate<void (sega_315_5195_mapper_device &, uint8_t)> mapper_delegate;
// construction/destruction
template <typename T>
sega_315_5195_mapper_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock, T &&cpu_tag)
: sega_315_5195_mapper_device(mconfig, tag, owner, clock)
{
m_cpu.set_tag(std::forward<T>(cpu_tag));
m_cpuregion.set_tag(std::forward<T>(cpu_tag));
}
sega_315_5195_mapper_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// configuration helpers
void set_cputag(const char *cpu)
{
m_cpu.set_tag(cpu);
m_cpuregion.set_tag(cpu);
}
void set_mapper(mapper_delegate callback) { m_mapper = callback; }
template <class FunctionClass> void set_mapper(const char *devname
, void (FunctionClass::*callback)(sega_315_5195_mapper_device &, uint8_t), const char *name)
{
set_mapper(mapper_delegate(callback, name, devname, static_cast<FunctionClass *>(nullptr)));
}
template <class FunctionClass> void set_mapper(void (FunctionClass::*callback)(sega_315_5195_mapper_device &, uint8_t), const char *name)
{
set_mapper(mapper_delegate(callback, name, nullptr, static_cast<FunctionClass *>(nullptr)));
}
template<class Object> devcb_base &set_pbf_callback(Object &&object) { return m_pbf_callback.set_callback(std::forward<Object>(object)); }
template<class Object> devcb_base &set_mcu_int_callback(Object &&object) { return m_mcu_int_callback.set_callback(std::forward<Object>(object)); }
auto pbf() { return m_pbf_callback.bind(); }
auto mcu_int() { return m_mcu_int_callback.bind(); }
// public interface
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
DECLARE_READ8_MEMBER( pread );
DECLARE_WRITE8_MEMBER( pwrite );
// mapping helpers
void map_as_rom(uint32_t offset, uint32_t length, offs_t mirror, const char *bank_name, const char *decrypted_bank_name, offs_t rgnoffset, write16_delegate whandler);
void map_as_ram(uint32_t offset, uint32_t length, offs_t mirror, const char *bank_share_name, write16_delegate whandler);
void map_as_handler(uint32_t offset, uint32_t length, offs_t mirror, read16_delegate rhandler, write16_delegate whandler);
// perform an explicit configuration (for bootlegs with hard-coded mappings)
void configure_explicit(const uint8_t *map_data);
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
private:
TIMER_CALLBACK_MEMBER(write_to_sound);
TIMER_CALLBACK_MEMBER(write_from_sound);
// internal region struct
struct region_info
{
offs_t size_mask;
offs_t base;
offs_t mirror;
offs_t start;
offs_t end;
};
// helper class for tracking banks mapped to ROM regions
class decrypt_bank
{
public:
// construction/destruction
decrypt_bank();
~decrypt_bank();
// configuration
void set_decrypt(fd1089_base_device *fd1089);
void set_decrypt(fd1094_device *fd1094);
void clear() { set(nullptr, nullptr, 0, 0, ~0, nullptr); }
void set(memory_bank *bank, memory_bank *decrypted_bank, offs_t start, offs_t end, offs_t rgnoffs, uint8_t *src);
// updating
void update();
void reset() { m_fd1089_decrypted.clear(); if (m_fd1094_cache != nullptr) m_fd1094_cache->reset(); }
private:
// internal state
memory_bank * m_bank;
memory_bank * m_decrypted_bank;
offs_t m_start;
offs_t m_end;
offs_t m_rgnoffs;
uint8_t * m_srcptr;
fd1089_base_device * m_fd1089;
std::vector<uint16_t> m_fd1089_decrypted;
std::unique_ptr<fd1094_decryption_cache> m_fd1094_cache;
};
// internal helpers
void compute_region(region_info &info, uint8_t index, uint32_t length, uint32_t mirror, uint32_t offset = 0);
void update_mapping();
void fd1094_state_change(uint8_t state);
// configuration
required_device<m68000_device> m_cpu;
required_memory_region m_cpuregion;
mapper_delegate m_mapper;
devcb_write_line m_pbf_callback;
devcb_write_line m_mcu_int_callback;
// internal state
address_space * m_space;
address_space * m_decrypted_space;
uint8_t m_regs[0x20];
uint8_t m_curregion;
decrypt_bank m_banks[8];
// communication registers
uint8_t m_to_sound;
uint8_t m_from_sound;
};
// ======================> sega_315_5248_multiplier_device
class sega_315_5248_multiplier_device : public device_t
{
public:
// construction/destruction
sega_315_5248_multiplier_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// public interface
DECLARE_READ16_MEMBER( read );
DECLARE_WRITE16_MEMBER( write );
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
private:
// internal state
uint16_t m_regs[4];
};
// ======================> sega_315_5249_divider_device
class sega_315_5249_divider_device : public device_t
{
public:
// construction/destruction
sega_315_5249_divider_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// public interface
DECLARE_READ16_MEMBER( read );
DECLARE_WRITE16_MEMBER( write );
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
private:
// internal helpers
void execute(int mode);
// internal state
uint16_t m_regs[8];
};
// ======================> sega_315_5250_compare_timer_device
class sega_315_5250_compare_timer_device : public device_t
{
public:
// construction/destruction
sega_315_5250_compare_timer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
// configuration helpers
auto m68kint_callback() { return m_68kint_callback.bind(); }
auto zint_callback() { return m_zint_callback.bind(); }
// public interface
DECLARE_WRITE_LINE_MEMBER(exck_w);
DECLARE_READ16_MEMBER(read);
DECLARE_WRITE16_MEMBER(write);
DECLARE_READ8_MEMBER(zread);
protected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
private:
// internal helpers
void execute(bool update_history = false);
void interrupt_ack();
TIMER_CALLBACK_MEMBER(write_to_sound);
// configuration
devcb_write_line m_68kint_callback;
devcb_write_line m_zint_callback;
// internal state
uint16_t m_regs[16];
uint16_t m_counter;
uint8_t m_bit;
bool m_exck;
};
// device type definition
DECLARE_DEVICE_TYPE(SEGA_315_5195_MEM_MAPPER, sega_315_5195_mapper_device)
DECLARE_DEVICE_TYPE(SEGA_315_5248_MULTIPLIER, sega_315_5248_multiplier_device)
DECLARE_DEVICE_TYPE(SEGA_315_5249_DIVIDER, sega_315_5249_divider_device)
DECLARE_DEVICE_TYPE(SEGA_315_5250_COMPARE_TIMER, sega_315_5250_compare_timer_device)
#endif // MAME_MACHINE_SEGAIC16_H
|