Previous 199869 Revisions Next

r18153 Wednesday 26th September, 2012 at 09:30:47 UTC by Miodrag Milanović
Removed devconv.h and memconv.h just moved used inlines for now (no whatsnew)
[src/emu]devconv.h memconv.h
[src/mame/drivers]viper.c
[src/mess/machine]bebox.c

trunk/src/mame/drivers/viper.c
r18152r18153
284284#include "emu.h"
285285#include "cpu/powerpc/ppc.h"
286286#include "machine/pci.h"
287#include "devconv.h"
288287#include "machine/idectrl.h"
289288#include "machine/timekpr.h"
290289#include "video/voodoo.h"
r18152r18153
362361
363362UINT32 m_mpc8240_regs[256/4];
364363
364INLINE UINT64 read64le_with_32le_device_handler(read32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
365{
366   UINT64 result = 0;
367   if (ACCESSING_BITS_0_31)
368      result |= (UINT64)(*handler)(device, space, offset * 2 + 0, mem_mask >> 0) << 0;
369   if (ACCESSING_BITS_32_63)
370      result |= (UINT64)(*handler)(device, space, offset * 2 + 1, mem_mask >> 32) << 32;
371   return result;
372}
373
374
375INLINE void write64le_with_32le_device_handler(write32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
376{
377   if (ACCESSING_BITS_0_31)
378      (*handler)(device, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
379   if (ACCESSING_BITS_32_63)
380      (*handler)(device, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
381}
382
383INLINE UINT64 read64be_with_32le_device_handler(read32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
384{
385   UINT64 result;
386   mem_mask = FLIPENDIAN_INT64(mem_mask);
387   result = read64le_with_32le_device_handler(handler, device, space, offset, mem_mask);
388   return FLIPENDIAN_INT64(result);
389}
390
391
392INLINE void write64be_with_32le_device_handler(write32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
393{
394   data = FLIPENDIAN_INT64(data);
395   mem_mask = FLIPENDIAN_INT64(mem_mask);
396   write64le_with_32le_device_handler(handler, device, space, offset, data, mem_mask);
397}
398
365399/*****************************************************************************/
366400
367401static UINT32 mpc8240_pci_r(device_t *busdevice, device_t *device, int function, int reg, UINT32 mem_mask)
trunk/src/emu/memconv.h
r18152r18153
1/***************************************************************************
2
3    memconv.h
4
5    Functions which help convert between different handlers.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10****************************************************************************
11
12    ***** VERY IMPORTANT NOTICE *****
13
14    These functions and macros are provided to facilitate the mapping
15    of devices on cpus with different data bus widths.
16    Devices should be implemented using their native data bus width,
17    since that ensures that read/write operations are kept atomic.
18    If we discover you have abused the functionality presented in this
19    file, you *will* be publicly humiliated and your code submission
20    will probably not be accepted. Seriously, please do not abuse these
21    functions/macros.
22
23****************************************************************************
24
25    Conversions supported:
26
27    CW = CPU Data Bus Width in bits
28    CBO = CPU Byte Order
29    DW = Device Data Bus Width in bits
30    DBO = Device Byte Order
31
32    CW | CBO    | DW | DBO    | Functions to use
33    ---+--------+----+--------+-----------------------------------------------------------
34    16 | Big    | 8  | N/A    | read16be_with_read8_handler,write16be_with_write8_handler
35    16 | Little | 8  | N/A    | read16le_with_read8_handler,write16le_with_write8_handler
36    ---+--------+----+--------+-----------------------------------------------------------
37    32 | Big    | 8  | N/A    | read32be_with_read8_handler,write32be_with_write8_handler
38    32 | Little | 8  | N/A    | read32le_with_read8_handler,write32le_with_write8_handler
39    32 | Big    | 16 | Big    | read32be_with_16be_handler,write32be_with_16be_handler
40    32 | Little | 16 | Little | read32le_with_16le_handler,write32le_with_16le_handler
41    32 | Big    | 16 | Little | read32be_with_16le_handler,write32be_with_16le_handler
42    32 | Little | 16 | Big    | read32le_with_16be_handler,write32le_with_16be_handler
43    ---+--------+----+--------+-----------------------------------------------------------
44    64 | Big    | 8  | N/A    | read64be_with_read8_handler,write64be_with_write8_handler
45    64 | Little | 8  | N/A    | read64le_with_read8_handler,write64le_with_write8_handler
46    64 | Big    | 16 | Big    | read64be_with_16be_handler,write64be_with_16be_handler
47    64 | Little | 16 | Little | read64le_with_16le_handler,write64le_with_16le_handler
48    64 | Big    | 16 | Little | read64be_with_16le_handler,write64be_with_16le_handler
49    64 | Little | 16 | Big    | read64le_with_16be_handler,write64le_with_16be_handler
50    64 | Big    | 32 | Big    | read64be_with_32be_handler,write64be_with_32be_handler
51    64 | Little | 32 | Little | read64le_with_32le_handler,write64le_with_32le_handler
52    64 | Big    | 32 | Little | read64be_with_32le_handler,write64be_with_32le_handler
53    64 | Little | 32 | Big    | read64le_with_32be_handler,write64le_with_32be_handler
54
55    You can also find at the bottom of this file a few convernient
56    macros that will create the stub read and/or write handlers for
57    the most common mappings, that will use the functions above.
58    Here's an example on how to use them: Say you have a 8 bit device
59    whose handlers are device8_r and device8_w, and you want to connect
60    it to a 16 bit, big endian cpu. We'll say the device is mapped on
61    the least significant byte of the data bus (LSB).
62
63    In your driver, you would add:
64
65    READWRITE8TO16BE_LSB( device16, device8_r, device8_w )
66
67    which will create two 16 bit memory handlers, one for read, called
68    device16_r, and one for write, called device16_w, with the proper
69    mapping.
70
71    then in the MEMORY_MAP you would specify:
72
73    AM_RANGE(0x000000, 0x0000ff) AM_READWRITE( device16_r, device16_w )
74
75    And that is all. Your device should be mapped properly.
76    If you need to do custom mappings, or a mapping that is not currently
77    supported in this file, you can always write the stub yourself, and
78    call the above functions to invoke the base handlers.
79
80***************************************************************************/
81
82/*************************************
83 *
84 *  16-bit BE using 8-bit handlers
85 *
86 *************************************/
87
88INLINE UINT16 read16be_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT16 mem_mask)
89{
90   UINT16 result = 0;
91   if (ACCESSING_BITS_8_15)
92      result |= ((UINT16)(*handler)(space, offset * 2 + 0, mem_mask >> 8)) << 8;
93   if (ACCESSING_BITS_0_7)
94      result |= ((UINT16)(*handler)(space, offset * 2 + 1, mem_mask >> 0)) << 0;
95   return result;
96}
97
98
99INLINE void write16be_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT16 data, UINT16 mem_mask)
100{
101   if (ACCESSING_BITS_8_15)
102      (*handler)(space, offset * 2 + 0, data >> 8, mem_mask >> 8);
103   if (ACCESSING_BITS_0_7)
104      (*handler)(space, offset * 2 + 1, data >> 0, mem_mask >> 0);
105}
106
107
108/*************************************
109 *
110 *  16-bit LE using 8-bit handlers
111 *
112 *************************************/
113
114INLINE UINT16 read16le_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT16 mem_mask)
115{
116   UINT16 result = 0;
117   if (ACCESSING_BITS_0_7)
118      result |= ((UINT16) (*handler)(space, offset * 2 + 0, mem_mask >> 0)) << 0;
119   if (ACCESSING_BITS_8_15)
120      result |= ((UINT16) (*handler)(space, offset * 2 + 1, mem_mask >> 8)) << 8;
121   return result;
122}
123
124
125INLINE void write16le_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT16 data, UINT16 mem_mask)
126{
127   if (ACCESSING_BITS_0_7)
128      (*handler)(space, offset * 2 + 0, data >> 0, mem_mask >> 0);
129   if (ACCESSING_BITS_8_15)
130      (*handler)(space, offset * 2 + 1, data >> 8, mem_mask >> 8);
131}
132
133
134/*************************************
135 *
136 *  32-bit BE using 8-bit handlers
137 *
138 *************************************/
139
140INLINE UINT32 read32be_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
141{
142   UINT32 result = 0;
143   if (ACCESSING_BITS_16_31)
144      result |= read16be_with_read8_handler(handler, space, offset * 2 + 0, mem_mask >> 16) << 16;
145   if (ACCESSING_BITS_0_15)
146      result |= read16be_with_read8_handler(handler, space, offset * 2 + 1, mem_mask) << 0;
147   return result;
148}
149
150
151INLINE void write32be_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
152{
153   if (ACCESSING_BITS_16_31)
154      write16be_with_write8_handler(handler, space, offset * 2 + 0, data >> 16, mem_mask >> 16);
155   if (ACCESSING_BITS_0_15)
156      write16be_with_write8_handler(handler, space, offset * 2 + 1, data, mem_mask);
157}
158
159
160/*************************************
161 *
162 *  32-bit LE using 8-bit handlers
163 *
164 *************************************/
165
166INLINE UINT32 read32le_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
167{
168   UINT32 result = 0;
169   if (ACCESSING_BITS_0_15)
170      result |= read16le_with_read8_handler(handler, space, offset * 2 + 0, mem_mask) << 0;
171   if (ACCESSING_BITS_16_31)
172      result |= read16le_with_read8_handler(handler, space, offset * 2 + 1, mem_mask >> 16) << 16;
173   return result;
174}
175
176
177INLINE void write32le_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
178{
179   if (ACCESSING_BITS_0_15)
180      write16le_with_write8_handler(handler, space, offset * 2 + 0, data, mem_mask);
181   if (ACCESSING_BITS_16_31)
182      write16le_with_write8_handler(handler, space, offset * 2 + 1, data >> 16, mem_mask >> 16);
183}
184
185
186/*************************************
187 *
188 *  32-bit BE using 16-bit BE handlers
189 *
190 *************************************/
191
192INLINE UINT32 read32be_with_16be_handler(read16_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
193{
194   UINT32 result = 0;
195   if (ACCESSING_BITS_16_31)
196      result |= (*handler)(space, offset * 2 + 0, mem_mask >> 16) << 16;
197   if (ACCESSING_BITS_0_15)
198      result |= (*handler)(space, offset * 2 + 1, mem_mask) << 0;
199   return result;
200}
201
202
203INLINE void write32be_with_16be_handler(write16_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
204{
205   if (ACCESSING_BITS_16_31)
206      (*handler)(space, offset * 2 + 0, data >> 16, mem_mask >> 16);
207   if (ACCESSING_BITS_0_15)
208      (*handler)(space, offset * 2 + 1, data, mem_mask);
209}
210
211
212/*************************************
213 *
214 *  32-bit LE using 16-bit LE handlers
215 *
216 *************************************/
217
218INLINE UINT32 read32le_with_16le_handler(read16_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
219{
220   UINT32 result = 0;
221   if (ACCESSING_BITS_0_15)
222      result |= (*handler)(space, offset * 2 + 0, mem_mask) << 0;
223   if (ACCESSING_BITS_16_31)
224      result |= (*handler)(space, offset * 2 + 1, mem_mask >> 16) << 16;
225   return result;
226}
227
228
229INLINE void write32le_with_16le_handler(write16_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
230{
231   if (ACCESSING_BITS_0_15)
232      (*handler)(space, offset * 2 + 0, data, mem_mask);
233   if (ACCESSING_BITS_16_31)
234      (*handler)(space, offset * 2 + 1, data >> 16, mem_mask >> 16);
235}
236
237
238/*************************************
239 *
240 *  32-bit BE using 16-bit LE handlers
241 *
242 *************************************/
243
244INLINE UINT32 read32be_with_16le_handler(read16_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
245{
246   UINT32 result = 0;
247   mem_mask = FLIPENDIAN_INT32(mem_mask);
248   result = read32le_with_16le_handler(handler, space, offset, mem_mask);
249   return FLIPENDIAN_INT32(result);
250}
251
252
253INLINE void write32be_with_16le_handler(write16_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
254{
255   data = FLIPENDIAN_INT32(data);
256   mem_mask = FLIPENDIAN_INT32(mem_mask);
257   write32le_with_16le_handler(handler, space, offset, data, mem_mask);
258}
259
260
261/*************************************
262 *
263 *  32-bit LE using 16-bit BE handlers
264 *
265 *************************************/
266
267INLINE UINT32 read32le_with_16be_handler(read16_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
268{
269   UINT32 result = 0;
270   mem_mask = FLIPENDIAN_INT32(mem_mask);
271   result = read32be_with_16be_handler(handler, space, offset, mem_mask);
272   return FLIPENDIAN_INT32(result);
273}
274
275
276INLINE void write32le_with_16be_handler(write16_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
277{
278   data = FLIPENDIAN_INT32(data);
279   mem_mask = FLIPENDIAN_INT32(mem_mask);
280   write32be_with_16be_handler(handler, space, offset, data, mem_mask);
281}
282
283
284/*************************************
285 *
286 *  64-bit BE using 8-bit handlers
287 *
288 *************************************/
289
290INLINE UINT64 read64be_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
291{
292   UINT64 result = 0;
293   if (ACCESSING_BITS_32_63)
294      result |= (UINT64)read32be_with_read8_handler(handler, space, offset * 2 + 0, mem_mask >> 32) << 32;
295   if (ACCESSING_BITS_0_31)
296      result |= (UINT64)read32be_with_read8_handler(handler, space, offset * 2 + 1, mem_mask) << 0;
297   return result;
298}
299
300
301INLINE void write64be_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
302{
303   if (ACCESSING_BITS_32_63)
304      write32be_with_write8_handler(handler, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
305   if (ACCESSING_BITS_0_31)
306      write32be_with_write8_handler(handler, space, offset * 2 + 1, data, mem_mask);
307}
308
309
310/*************************************
311 *
312 *  64-bit LE using 8-bit handlers
313 *
314 *************************************/
315
316INLINE UINT64 read64le_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
317{
318   UINT64 result = 0;
319   if (ACCESSING_BITS_0_31)
320      result |= (UINT64)read32le_with_read8_handler(handler, space, offset * 2 + 0, mem_mask >> 0) << 0;
321   if (ACCESSING_BITS_32_63)
322      result |= (UINT64)read32le_with_read8_handler(handler, space, offset * 2 + 1, mem_mask >> 32) << 32;
323   return result;
324}
325
326
327INLINE void write64le_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
328{
329   if (ACCESSING_BITS_0_31)
330      write32le_with_write8_handler(handler, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
331   if (ACCESSING_BITS_32_63)
332      write32le_with_write8_handler(handler, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
333}
334
335
336/*************************************
337 *
338 *  64-bit BE using 16-bit BE handlers
339 *
340 *************************************/
341
342INLINE UINT32 read64be_with_16be_handler(read16_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
343{
344   UINT64 result = 0;
345   if (ACCESSING_BITS_32_63)
346      result |= (UINT64)read32be_with_16be_handler(handler, space, offset * 2 + 0, mem_mask >> 32) << 32;
347   if (ACCESSING_BITS_0_31)
348      result |= (UINT64)read32be_with_16be_handler(handler, space, offset * 2 + 1, mem_mask >> 0) << 0;
349   return result;
350}
351
352
353INLINE void write64be_with_16be_handler(write16_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
354{
355   if (ACCESSING_BITS_32_63)
356      write32be_with_16be_handler(handler, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
357   if (ACCESSING_BITS_0_31)
358      write32be_with_16be_handler(handler, space, offset * 2 + 1, data >> 0, mem_mask >> 0);
359}
360
361
362/*************************************
363 *
364 *  64-bit LE using 16-bit LE handlers
365 *
366 *************************************/
367
368INLINE UINT32 read64le_with_16le_handler(read16_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
369{
370   UINT64 result = 0;
371   if (ACCESSING_BITS_0_31)
372      result |= (UINT64)read32le_with_16le_handler(handler, space, offset * 2 + 0, mem_mask >> 0) << 0;
373   if (ACCESSING_BITS_32_63)
374      result |= (UINT64)read32le_with_16le_handler(handler, space, offset * 2 + 1, mem_mask >> 32) << 32;
375   return result;
376}
377
378
379INLINE void write64le_with_16le_handler(write16_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
380{
381   if (ACCESSING_BITS_0_31)
382      write32le_with_16le_handler(handler, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
383   if (ACCESSING_BITS_32_63)
384      write32le_with_16le_handler(handler, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
385}
386
387
388/*************************************
389 *
390 *  64-bit BE using 16-bit LE handlers
391 *
392 *************************************/
393
394INLINE UINT32 read64be_with_16le_handler(read16_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
395{
396   UINT64 result = 0;
397   if (ACCESSING_BITS_32_63)
398      result |= (UINT64)read32be_with_16le_handler(handler, space, offset * 2 + 0, mem_mask >> 32) << 32;
399   if (ACCESSING_BITS_0_31)
400      result |= (UINT64)read32be_with_16le_handler(handler, space, offset * 2 + 1, mem_mask >> 0) << 0;
401   return result;
402}
403
404
405INLINE void write64be_with_16le_handler(write16_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
406{
407   if (ACCESSING_BITS_32_63)
408      write32be_with_16le_handler(handler, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
409   if (ACCESSING_BITS_0_31)
410      write32be_with_16le_handler(handler, space, offset * 2 + 1, data >> 0, mem_mask >> 0);
411}
412
413
414/*************************************
415 *
416 *  64-bit LE using 16-bit BE handlers
417 *
418 *************************************/
419
420INLINE UINT32 read64le_with_16be_handler(read16_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
421{
422   UINT64 result = 0;
423   if (ACCESSING_BITS_0_31)
424      result |= (UINT64)read32le_with_16be_handler(handler, space, offset * 2 + 0, mem_mask >> 0) << 0;
425   if (ACCESSING_BITS_32_63)
426      result |= (UINT64)read32le_with_16be_handler(handler, space, offset * 2 + 1, mem_mask >> 32) << 32;
427   return result;
428}
429
430
431INLINE void write64le_with_16be_handler(write16_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
432{
433   if (ACCESSING_BITS_0_31)
434      write32le_with_16be_handler(handler, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
435   if (ACCESSING_BITS_32_63)
436      write32le_with_16be_handler(handler, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
437}
438
439
440/*************************************
441 *
442 *  64-bit BE using 32-bit BE handlers
443 *
444 *************************************/
445
446INLINE UINT64 read64be_with_32be_handler(read32_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
447{
448   UINT64 result = 0;
449   if (ACCESSING_BITS_32_63)
450      result |= (UINT64)(*handler)(space, offset * 2 + 0, mem_mask >> 32) << 32;
451   if (ACCESSING_BITS_0_31)
452      result |= (UINT64)(*handler)(space, offset * 2 + 1, mem_mask >> 0) << 0;
453   return result;
454}
455
456
457INLINE void write64be_with_32be_handler(write32_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
458{
459   if (ACCESSING_BITS_32_63)
460      (*handler)(space, offset * 2 + 0, data >> 32, mem_mask >> 32);
461   if (ACCESSING_BITS_0_31)
462      (*handler)(space, offset * 2 + 1, data >>  0, mem_mask >>  0);
463}
464
465
466/*************************************
467 *
468 *  64-bit LE using 32-bit LE handlers
469 *
470 *************************************/
471
472INLINE UINT64 read64le_with_32le_handler(read32_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
473{
474   UINT64 result = 0;
475   if (ACCESSING_BITS_0_31)
476      result |= (UINT64)(*handler)(space, offset * 2 + 0, mem_mask >> 0) << 0;
477   if (ACCESSING_BITS_32_63)
478      result |= (UINT64)(*handler)(space, offset * 2 + 1, mem_mask >> 32) << 32;
479   return result;
480}
481
482
483INLINE void write64le_with_32le_handler(write32_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
484{
485   if (ACCESSING_BITS_0_31)
486      (*handler)(space, offset * 2 + 0, data >> 0, mem_mask >> 0);
487   if (ACCESSING_BITS_32_63)
488      (*handler)(space, offset * 2 + 1, data >> 32, mem_mask >> 32);
489}
490
491
492/*************************************
493 *
494 *  64-bit BE using 32-bit LE handlers
495 *
496 *************************************/
497
498INLINE UINT64 read64be_with_32le_handler(read32_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
499{
500   UINT64 result;
501   mem_mask = FLIPENDIAN_INT64(mem_mask);
502   result = read64le_with_32le_handler(handler, space, offset, mem_mask);
503   return FLIPENDIAN_INT64(result);
504}
505
506
507INLINE void write64be_with_32le_handler(write32_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
508{
509   data = FLIPENDIAN_INT64(data);
510   mem_mask = FLIPENDIAN_INT64(mem_mask);
511   write64le_with_32le_handler(handler, space, offset, data, mem_mask);
512}
513
514
515/*************************************
516 *
517 *  64-bit LE using 32-bit BE handlers
518 *
519 *************************************/
520
521INLINE UINT64 read64le_with_32be_handler(read32_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
522{
523   UINT64 result;
524   mem_mask = FLIPENDIAN_INT64(mem_mask);
525   result = read64be_with_32be_handler(handler, space, offset, mem_mask);
526   return FLIPENDIAN_INT64(result);
527}
528
529
530INLINE void write64le_with_32be_handler(write32_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
531{
532   data = FLIPENDIAN_INT64(data);
533   mem_mask = FLIPENDIAN_INT64(mem_mask);
534   write64be_with_32be_handler(handler, space, offset, data, mem_mask);
535}
536
537
538
539/**************************************************************************
540
541    Utility macros
542
543**************************************************************************/
544
545#define READ_TEMPLATE(bits, name, handler, func)            \
546READ##bits##_HANDLER( name##_r )                        \
547{                                                \
548   return func(handler, space, offset, mem_mask);         \
549}
550
551#define READ_TEMPLATE_COND(bits, name, handler, func, cond)      \
552READ##bits##_HANDLER( name##_r )                        \
553{                                                \
554   if (cond)                                       \
555      return func(handler, space, offset, mem_mask);      \
556   return 0;                                       \
557}
558
559#define WRITE_TEMPLATE(bits, name, handler, func)            \
560WRITE##bits##_HANDLER( name##_w )                        \
561{                                                \
562   func(handler, space, offset, data, mem_mask);            \
563}
564
565#define WRITE_TEMPLATE_COND(bits, name, handler, func, cond)   \
566WRITE##bits##_HANDLER( name##_w )                        \
567{                                                \
568   if (cond)                                       \
569      func(handler, space, offset, data, mem_mask);         \
570}
571
572
573
574/**************************************************************************
575
576    Generic conversions macros
577
578**************************************************************************/
579
580
581/*************************************
582 * 8->16be, 1:1 mapping
583 ************************************/
584
585#define READ8TO16BE( name, read8 ) \
586READ_TEMPLATE( 16, name, read8, read16be_with_read8_handler )
587
588
589#define WRITE8TO16BE( name, write8 ) \
590WRITE_TEMPLATE( 16, name, write8, write16be_with_write8_handler )
591
592
593#define READWRITE8TO16BE( name, read8, write8 ) \
594READ8TO16BE(name,read8) \
595WRITE8TO16BE(name,write8)
596
597
598/*************************************
599 * 8->16le, 1:1 mapping
600 ************************************/
601
602#define READ8TO16LE( name, read8 ) \
603READ_TEMPLATE( 16, name, read8, read16le_with_read8_handler )
604
605
606#define WRITE8TO16LE( name, write8 ) \
607WRITE_TEMPLATE( 16, name, write8, write16le_with_write8_handler )
608
609
610#define READWRITE8TO16LE( name, read8, write8 ) \
611READ8TO16LE(name,read8) \
612WRITE8TO16LE(name,write8)
613
614
615/*************************************
616 * 8->16be, MSB mapping
617 ************************************/
618
619#define READ8TO16BE_MSB( name, read8 ) \
620READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_handler, ACCESSING_BITS_8_15 )
621
622
623#define WRITE8TO16BE_MSB( name, write8 ) \
624WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_handler, ACCESSING_BITS_8_15 )
625
626
627#define READWRITE8TO16BE_MSB( name, read8, write8 ) \
628READ8TO16BE_MSB(name,read8) \
629WRITE8TO16BE_MSB(name,write8)
630
631
632/*************************************
633 * 8->16le, MSB mapping
634 ************************************/
635
636#define READ8TO16LE_MSB( name, read8 ) \
637READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_handler, ACCESSING_BITS_8_15 )
638
639
640#define WRITE8TO16LE_MSB( name, write8 ) \
641WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_handler, ACCESSING_BITS_8_15 )
642
643
644#define READWRITE8TO16LE_MSB( name, read8, write8 ) \
645READ8TO16LE_MSB(name,read8) \
646WRITE8TO16LE_MSB(name,write8)
647
648
649/*************************************
650 * 8->16be, LSB mapping
651 ************************************/
652
653#define READ8TO16BE_LSB( name, read8 ) \
654READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_handler, ACCESSING_BITS_0_7 )
655
656
657#define WRITE8TO16BE_LSB( name, write8 ) \
658WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_handler, ACCESSING_BITS_0_7 )
659
660
661#define READWRITE8TO16BE_LSB( name, read8, write8 ) \
662READ8TO16BE_LSB(name,read8) \
663WRITE8TO16BE_LSB(name,write8)
664
665
666/*************************************
667 * 8->16le, LSB mapping
668 ************************************/
669
670#define READ8TO16LE_LSB( name, read8 ) \
671READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_handler, ACCESSING_BITS_0_7 )
672
673
674#define WRITE8TO16LE_LSB( name, write8 ) \
675WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_handler, ACCESSING_BITS_0_7 )
676
677
678#define READWRITE8TO16LE_LSB( name, read8, write8 ) \
679READ8TO16LE_LSB(name,read8) \
680WRITE8TO16LE_LSB(name,write8)
681
682
683/*************************************
684 * 8->32be, 1:1 mapping
685 ************************************/
686
687#define READ8TO32BE( name, read8 ) \
688READ_TEMPLATE( 32, name, read8, read32be_with_read8_handler )
689
690
691#define WRITE8TO32BE( name, write8 ) \
692WRITE_TEMPLATE( 32, name, write8, write32be_with_write8_handler )
693
694
695#define READWRITE8TO32BE( name, read8, write8 ) \
696READ8TO32BE(name,read8) \
697WRITE8TO32BE(name,write8)
698
699
700/*************************************
701 * 8->32le, 1:1 mapping
702 ************************************/
703
704#define READ8TO32LE( name, read8 ) \
705READ_TEMPLATE( 32, name, read8, read32le_with_read8_handler )
706
707
708#define WRITE8TO32LE( name, write8 ) \
709WRITE_TEMPLATE( 32, name, write8, write32le_with_write8_handler )
710
711
712#define READWRITE8TO32LE( name, read8, write8 ) \
713READ8TO32LE(name,read8) \
714WRITE8TO32LE(name,write8)
715
716
717/*************************************
718 * 8->32be, MSB mapping
719 ************************************/
720
721#define READ8TO32BE_MSB( name, read8 ) \
722READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_handler, ACCESSING_BITS_24_31 )
723
724
725#define WRITE8TO32BE_MSB( name, write8 ) \
726WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_handler, ACCESSING_BITS_24_31 )
727
728
729#define READWRITE8TO32BE_MSB( name, read8, write8 ) \
730READ8TO32BE_MSB(name,read8) \
731WRITE8TO32BE_MSB(name,write8)
732
733
734/*************************************
735 * 8->32le, MSB mapping
736 ************************************/
737
738#define READ8TO32LE_MSB( name, read8 ) \
739READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_handler, ACCESSING_BITS_24_31 )
740
741
742#define WRITE8TO32LE_MSB( name, write8 ) \
743WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_handler, ACCESSING_BITS_24_31 )
744
745
746#define READWRITE8TO32LE_MSB( name, read8, write8 ) \
747READ8TO32LE_MSB(name,read8) \
748WRITE8TO32LE_MSB(name,write8)
749
750
751/*************************************
752 * 8->32be, LSB mapping
753 ************************************/
754
755#define READ8TO32BE_LSB( name, read8 ) \
756READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_handler, ACCESSING_BITS_0_7 )
757
758
759#define WRITE8TO32BE_LSB( name, write8 ) \
760WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_handler, ACCESSING_BITS_0_7 )
761
762
763#define READWRITE8TO32BE_LSB( name, read8, write8 ) \
764READ8TO32BE_LSB(name,read8) \
765WRITE8TO32BE_LSB(name,write8)
766
767
768/*************************************
769 * 8->32le, LSB mapping
770 ************************************/
771
772#define READ8TO32LE_LSB( name, read8 ) \
773READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_handler, ACCESSING_BITS_0_7 )
774
775
776#define WRITE8TO32LE_LSB( name, write8 ) \
777WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_handler, ACCESSING_BITS_0_7 )
778
779
780#define READWRITE8TO32LE_LSB( name, read8, write8 ) \
781READ8TO32LE_LSB(name,read8) \
782WRITE8TO32LE_LSB(name,write8)
783
784
785/*************************************
786 * 8->64be, 1:1 mapping
787 ************************************/
788
789#define READ8TO64BE( name, read8 ) \
790READ_TEMPLATE( 64, name, read8, read64be_with_read8_handler )
791
792
793#define WRITE8TO64BE( name, write8 ) \
794WRITE_TEMPLATE( 64, name, write8, write64be_with_write8_handler )
795
796
797#define READWRITE8TO64BE( name, read8, write8 ) \
798READ8TO64BE(name,read8) \
799WRITE8TO64BE(name,write8)
800
801
802/*************************************
803 * 8->64le, 1:1 mapping
804 ************************************/
805
806#define READ8TO64LE( name, read8 ) \
807READ_TEMPLATE( 64, name, read8, read64le_with_read8_handler )
808
809
810#define WRITE8TO64LE( name, write8 ) \
811WRITE_TEMPLATE( 64, name, write8, write64le_with_write8_handler )
812
813
814#define READWRITE8TO64LE( name, read8, write8 ) \
815READ8TO64LE(name,read8) \
816WRITE8TO64LE(name,write8)
817
818
819/*************************************
820 *  16be->32be, 1:1 mapping
821 *************************************/
822
823#define READ16BETO32BE( name, read16 ) \
824READ_TEMPLATE( 32, name, read16, read32be_with_16be_handler )
825
826
827#define WRITE16BETO32BE( name, write16 ) \
828WRITE_TEMPLATE( 32, name, write16, write32be_with_16be_handler )
829
830
831#define READWRITE16BETO32BE( name, read16, write16 ) \
832READ16BETO32BE(name,read16) \
833WRITE16BETO32BE(name,write16)
834
835
836/*************************************
837 *  16le->32be, 1:1 mapping
838 *************************************/
839
840#define READ16LETO32BE( name, read16 ) \
841READ_TEMPLATE( 32, name, read16, read32be_with_16le_handler )
842
843
844#define WRITE16LETO32BE( name, write16 ) \
845WRITE_TEMPLATE( 32, name, write16, write32be_with_16le_handler )
846
847
848#define READWRITE16LETO32BE( name, read16, write16 ) \
849READ16LETO32BE(name,read16) \
850WRITE16LETO32BE(name,write16)
851
852
853/*************************************
854 *  16be->32le, 1:1 mapping
855 *************************************/
856
857#define READ16BETO32LE( name, read16 ) \
858READ_TEMPLATE( 32, name, read16, read32le_with_16be_handler )
859
860
861#define WRITE16BETO32LE( name, write16 ) \
862WRITE_TEMPLATE( 32, name, write16, write32le_with_16be_handler )
863
864
865#define READWRITE16BETO32LE( name, read16, write16 ) \
866READ16BETO32LE(name,read16) \
867WRITE16BETO32LE(name,write16)
868
869
870/*************************************
871 *  16le->32le, 1:1 mapping
872 *************************************/
873
874#define READ16LETO32LE( name, read16 ) \
875READ_TEMPLATE( 32, name, read16, read32le_with_16le_handler )
876
877
878#define WRITE16LETO32LE( name, write16 ) \
879WRITE_TEMPLATE( 32, name, write16, write32le_with_16le_handler )
880
881
882#define READWRITE16LETO32LE( name, read16, write16 ) \
883READ16LETO32LE(name,read16) \
884WRITE16LETO32LE(name,write16)
885
886
887/*************************************
888 *  16be->32be, MSW mapping
889 *************************************/
890
891#define READ16BETO32BE_MSW( name, read16 ) \
892READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_handler, ACCESSING_BITS_16_31 )
893
894
895#define WRITE16BETO32BE_MSW( name, write16 ) \
896WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_handler, ACCESSING_BITS_16_31 )
897
898
899#define READWRITE16BETO32BE_MSW( name, read16, write16 ) \
900READ16BETO32BE_MSW(name,read16) \
901WRITE16BETO32BE_MSW(name,write16)
902
903
904/*************************************
905 *  16le->32be, MSW mapping
906 *************************************/
907
908#define READ16LETO32BE_MSW( name, read16 ) \
909READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_handler, ACCESSING_BITS_16_31 )
910
911
912#define WRITE16LETO32BE_MSW( name, write16 ) \
913WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_handler, ACCESSING_BITS_16_31 )
914
915
916#define READWRITE16LETO32BE_MSW( name, read16, write16 ) \
917READ16LETO32BE_MSW(name,read16) \
918WRITE16LETO32BE_MSW(name,write16)
919
920
921/*************************************
922 *  16be->32le, MSW mapping
923 *************************************/
924
925#define READ16BETO32LE_MSW( name, read16 ) \
926READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_handler, ACCESSING_BITS_16_31 )
927
928
929#define WRITE16BETO32LE_MSW( name, write16 ) \
930WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_handler, ACCESSING_BITS_16_31 )
931
932
933#define READWRITE16BETO32LE_MSW( name, read16, write16 ) \
934READ16BETO32LE_MSW(name,read16) \
935WRITE16BETO32LE_MSW(name,write16)
936
937
938/*************************************
939 *  16le->32le, MSW mapping
940 *************************************/
941
942#define READ16LETO32LE_MSW( name, read16 ) \
943READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_handler, ACCESSING_BITS_16_31 )
944
945
946#define WRITE16LETO32LE_MSW( name, write16 ) \
947WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_handler, ACCESSING_BITS_16_31 )
948
949
950#define READWRITE16LETO32LE_MSW( name, read16, write16 ) \
951READ16LETO32LE_MSW(name,read16) \
952WRITE16LETO32LE_MSW(name,write16)
953
954/*************************************
955 *  16be->32be, LSW mapping
956 *************************************/
957
958#define READ16BETO32BE_LSW( name, read16 ) \
959READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_handler, ACCESSING_BITS_0_15 )
960
961
962#define WRITE16BETO32BE_LSW( name, write16 ) \
963WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_handler, ACCESSING_BITS_0_15 )
964
965
966#define READWRITE16BETO32BE_LSW( name, read16, write16 ) \
967READ16BETO32BE_LSW(name,read16) \
968WRITE16BETO32BE_LSW(name,write16)
969
970
971/*************************************
972 *  16le->32be, LSW mapping
973 *************************************/
974
975#define READ16LETO32BE_LSW( name, read16 ) \
976READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_handler, ACCESSING_BITS_0_15 )
977
978
979#define WRITE16LETO32BE_LSW( name, write16 ) \
980WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_handler, ACCESSING_BITS_0_15 )
981
982
983#define READWRITE16LETO32BE_LSW( name, read16, write16 ) \
984READ16LETO32BE_LSW(name,read16) \
985WRITE16LETO32BE_LSW(name,write16)
986
987
988/*************************************
989 *  16be->32le, LSW mapping
990 *************************************/
991
992#define READ16BETO32LE_LSW( name, read16 ) \
993READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_handler, ACCESSING_BITS_0_15 )
994
995
996#define WRITE16BETO32LE_LSW( name, write16 ) \
997WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_handler, ACCESSING_BITS_0_15 )
998
999
1000#define READWRITE16BETO32LE_LSW( name, read16, write16 ) \
1001READ16BETO32LE_LSW(name,read16) \
1002WRITE16BETO32LE_LSW(name,write16)
1003
1004
1005/*************************************
1006 *  16le->32le, LSW mapping
1007 *************************************/
1008
1009#define READ16LETO32LE_LSW( name, read16 ) \
1010READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_handler, ACCESSING_BITS_0_15 )
1011
1012
1013#define WRITE16LETO32LE_LSW( name, write16 ) \
1014WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_handler, ACCESSING_BITS_0_15 )
1015
1016
1017#define READWRITE16LETO32LE_LSW( name, read16, write16 ) \
1018READ16LETO32LE_LSW(name,read16) \
1019WRITE16LETO32LE_LSW(name,write16)
1020
trunk/src/emu/devconv.h
r18152r18153
1/***************************************************************************
2
3    devconv.h
4
5    Functions which help convert between different device handlers.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10****************************************************************************
11
12    ***** VERY IMPORTANT NOTICE *****
13
14    These functions and macros are provided to facilitate the mapping
15    of devices on cpus with different data bus widths.
16    Devices should be implemented using their native data bus width,
17    since that ensures that read/write operations are kept atomic.
18    If we discover you have abused the functionality presented in this
19    file, you *will* be publicly humiliated and your code submission
20    will probably not be accepted. Seriously, please do not abuse these
21    functions/macros.
22
23****************************************************************************
24
25    Conversions supported:
26
27    CW = CPU Data Bus Width in bits
28    CBO = CPU Byte Order
29    DW = Device Data Bus Width in bits
30    DBO = Device Byte Order
31
32    CW | CBO    | DW | DBO    | Functions to use
33    ---+--------+----+--------+-----------------------------------------------------------
34    16 | Big    | 8  | N/A    | read16be_with_read8_device_handler,write16be_with_write8_device_handler
35    16 | Little | 8  | N/A    | read16le_with_read8_device_handler,write16le_with_write8_device_handler
36    ---+--------+----+--------+-----------------------------------------------------------
37    32 | Big    | 8  | N/A    | read32be_with_read8_device_handler,write32be_with_write8_device_handler
38    32 | Little | 8  | N/A    | read32le_with_read8_device_handler,write32le_with_write8_device_handler
39    32 | Big    | 16 | Big    | read32be_with_16be_device_handler,write32be_with_16be_device_handler
40    32 | Little | 16 | Little | read32le_with_16le_device_handler,write32le_with_16le_device_handler
41    32 | Big    | 16 | Little | read32be_with_16le_device_handler,write32be_with_16le_device_handler
42    32 | Little | 16 | Big    | read32le_with_16be_device_handler,write32le_with_16be_device_handler
43    ---+--------+----+--------+-----------------------------------------------------------
44    64 | Big    | 8  | N/A    | read64be_with_read8_device_handler,write64be_with_write8_device_handler
45    64 | Little | 8  | N/A    | read64le_with_read8_device_handler,write64le_with_write8_device_handler
46    64 | Big    | 16 | Big    | read64be_with_16be_device_handler,write64be_with_16be_device_handler
47    64 | Little | 16 | Little | read64le_with_16le_device_handler,write64le_with_16le_device_handler
48    64 | Big    | 16 | Little | read64be_with_16le_device_handler,write64be_with_16le_device_handler
49    64 | Little | 16 | Big    | read64le_with_16be_device_handler,write64le_with_16be_device_handler
50    64 | Big    | 32 | Big    | read64be_with_32be_device_handler,write64be_with_32be_device_handler
51    64 | Little | 32 | Little | read64le_with_32le_device_handler,write64le_with_32le_device_handler
52    64 | Big    | 32 | Little | read64be_with_32le_device_handler,write64be_with_32le_device_handler
53    64 | Little | 32 | Big    | read64le_with_32be_device_handler,write64le_with_32be_device_handler
54
55    You can also find at the bottom of this file a few convernient
56    macros that will create the stub read and/or write handlers for
57    the most common mappings, that will use the functions above.
58    Here's an example on how to use them: Say you have a 8 bit device
59    whose handlers are device8_r and device8_w, and you want to connect
60    it to a 16 bit, big endian cpu. We'll say the device is mapped on
61    the least significant byte of the data bus (LSB).
62
63    In your driver, you would add:
64
65    DEV_READWRITE8TO16BE_LSB( device16, device8_r, device8_w )
66
67    which will create two 16 bit memory handlers, one for read, called
68    device16_r, and one for write, called device16_w, with the proper
69    mapping.
70
71    then in the MEMORY_MAP you would specify:
72
73    AM_RANGE(0x000000, 0x0000ff) AM_DEVREADWRITE( DEVICE, "device", device16_r, device16_w )
74
75    And that is all. Your device should be mapped properly.
76    If you need to do custom mappings, or a mapping that is not currently
77    supported in this file, you can always write the stub yourself, and
78    call the above functions to invoke the base handlers.
79
80***************************************************************************/
81
82/*************************************
83 *
84 *  16-bit BE using 8-bit handlers
85 *
86 *************************************/
87
88INLINE UINT16 read16be_with_read8_device_handler(read8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT16 mem_mask)
89{
90   UINT16 result = 0;
91   if (ACCESSING_BITS_8_15)
92      result |= ((UINT16)(*handler)(device, space, offset * 2 + 0, mem_mask >> 8)) << 8;
93   if (ACCESSING_BITS_0_7)
94      result |= ((UINT16)(*handler)(device, space, offset * 2 + 1, mem_mask >> 0)) << 0;
95   return result;
96}
97
98
99INLINE void write16be_with_write8_device_handler(write8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT16 data, UINT16 mem_mask)
100{
101   if (ACCESSING_BITS_8_15)
102      (*handler)(device, space, offset * 2 + 0, data >> 8, mem_mask >> 8);
103   if (ACCESSING_BITS_0_7)
104      (*handler)(device, space, offset * 2 + 1, data >> 0, mem_mask >> 0);
105}
106
107
108/*************************************
109 *
110 *  16-bit LE using 8-bit handlers
111 *
112 *************************************/
113
114INLINE UINT16 read16le_with_read8_device_handler(read8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT16 mem_mask)
115{
116   UINT16 result = 0;
117   if (ACCESSING_BITS_0_7)
118      result |= ((UINT16) (*handler)(device, space, offset * 2 + 0, mem_mask >> 0)) << 0;
119   if (ACCESSING_BITS_8_15)
120      result |= ((UINT16) (*handler)(device, space, offset * 2 + 1, mem_mask >> 8)) << 8;
121   return result;
122}
123
124
125INLINE void write16le_with_write8_device_handler(write8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT16 data, UINT16 mem_mask)
126{
127   if (ACCESSING_BITS_0_7)
128      (*handler)(device, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
129   if (ACCESSING_BITS_8_15)
130      (*handler)(device, space, offset * 2 + 1, data >> 8, mem_mask >> 8);
131}
132
133
134/*************************************
135 *
136 *  32-bit BE using 8-bit handlers
137 *
138 *************************************/
139
140INLINE UINT32 read32be_with_read8_device_handler(read8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 mem_mask)
141{
142   UINT32 result = 0;
143   if (ACCESSING_BITS_16_31)
144      result |= read16be_with_read8_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 16) << 16;
145   if (ACCESSING_BITS_0_15)
146      result |= read16be_with_read8_device_handler(handler, device, space, offset * 2 + 1, mem_mask) << 0;
147   return result;
148}
149
150
151INLINE void write32be_with_write8_device_handler(write8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
152{
153   if (ACCESSING_BITS_16_31)
154      write16be_with_write8_device_handler(handler, device, space, offset * 2 + 0, data >> 16, mem_mask >> 16);
155   if (ACCESSING_BITS_0_15)
156      write16be_with_write8_device_handler(handler, device, space, offset * 2 + 1, data, mem_mask);
157}
158
159
160/*************************************
161 *
162 *  32-bit LE using 8-bit handlers
163 *
164 *************************************/
165
166INLINE UINT32 read32le_with_read8_device_handler(read8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 mem_mask)
167{
168   UINT32 result = 0;
169   if (ACCESSING_BITS_0_15)
170      result |= read16le_with_read8_device_handler(handler, device, space, offset * 2 + 0, mem_mask) << 0;
171   if (ACCESSING_BITS_16_31)
172      result |= read16le_with_read8_device_handler(handler, device, space, offset * 2 + 1, mem_mask >> 16) << 16;
173   return result;
174}
175
176
177INLINE void write32le_with_write8_device_handler(write8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
178{
179   if (ACCESSING_BITS_0_15)
180      write16le_with_write8_device_handler(handler, device, space, offset * 2 + 0, data, mem_mask);
181   if (ACCESSING_BITS_16_31)
182      write16le_with_write8_device_handler(handler, device, space, offset * 2 + 1, data >> 16, mem_mask >> 16);
183}
184
185
186/*************************************
187 *
188 *  32-bit BE using 16-bit BE handlers
189 *
190 *************************************/
191
192INLINE UINT32 read32be_with_16be_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 mem_mask)
193{
194   UINT32 result = 0;
195   if (ACCESSING_BITS_16_31)
196      result |= (*handler)(device, space, offset * 2 + 0, mem_mask >> 16) << 16;
197   if (ACCESSING_BITS_0_15)
198      result |= (*handler)(device, space, offset * 2 + 1, mem_mask) << 0;
199   return result;
200}
201
202
203INLINE void write32be_with_16be_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
204{
205   if (ACCESSING_BITS_16_31)
206      (*handler)(device, space, offset * 2 + 0, data >> 16, mem_mask >> 16);
207   if (ACCESSING_BITS_0_15)
208      (*handler)(device, space, offset * 2 + 1, data, mem_mask);
209}
210
211
212/*************************************
213 *
214 *  32-bit LE using 16-bit LE handlers
215 *
216 *************************************/
217
218INLINE UINT32 read32le_with_16le_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 mem_mask)
219{
220   UINT32 result = 0;
221   if (ACCESSING_BITS_0_15)
222      result |= (*handler)(device, space, offset * 2 + 0, mem_mask) << 0;
223   if (ACCESSING_BITS_16_31)
224      result |= (*handler)(device, space, offset * 2 + 1, mem_mask >> 16) << 16;
225   return result;
226}
227
228
229INLINE void write32le_with_16le_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
230{
231   if (ACCESSING_BITS_0_15)
232      (*handler)(device, space, offset * 2 + 0, data, mem_mask);
233   if (ACCESSING_BITS_16_31)
234      (*handler)(device, space, offset * 2 + 1, data >> 16, mem_mask >> 16);
235}
236
237
238/*************************************
239 *
240 *  32-bit BE using 16-bit LE handlers
241 *
242 *************************************/
243
244INLINE UINT32 read32be_with_16le_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 mem_mask)
245{
246   UINT32 result = 0;
247   mem_mask = FLIPENDIAN_INT32(mem_mask);
248   result = read32le_with_16le_device_handler(handler, device, space, offset, mem_mask);
249   return FLIPENDIAN_INT32(result);
250}
251
252
253INLINE void write32be_with_16le_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
254{
255   data = FLIPENDIAN_INT32(data);
256   mem_mask = FLIPENDIAN_INT32(mem_mask);
257   write32le_with_16le_device_handler(handler, device, space, offset, data, mem_mask);
258}
259
260
261/*************************************
262 *
263 *  32-bit LE using 16-bit BE handlers
264 *
265 *************************************/
266
267INLINE UINT32 read32le_with_16be_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 mem_mask)
268{
269   UINT32 result = 0;
270   mem_mask = FLIPENDIAN_INT32(mem_mask);
271   result = read32be_with_16be_device_handler(handler, device, space, offset, mem_mask);
272   return FLIPENDIAN_INT32(result);
273}
274
275
276INLINE void write32le_with_16be_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
277{
278   data = FLIPENDIAN_INT32(data);
279   mem_mask = FLIPENDIAN_INT32(mem_mask);
280   write32be_with_16be_device_handler(handler, device, space, offset, data, mem_mask);
281}
282
283
284/*************************************
285 *
286 *  64-bit BE using 8-bit handlers
287 *
288 *************************************/
289
290INLINE UINT64 read64be_with_read8_device_handler(read8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
291{
292   UINT64 result = 0;
293   if (ACCESSING_BITS_32_63)
294      result |= (UINT64)read32be_with_read8_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 32) << 32;
295   if (ACCESSING_BITS_0_31)
296      result |= (UINT64)read32be_with_read8_device_handler(handler, device, space, offset * 2 + 1, mem_mask) << 0;
297   return result;
298}
299
300
301INLINE void write64be_with_write8_device_handler(write8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
302{
303   if (ACCESSING_BITS_32_63)
304      write32be_with_write8_device_handler(handler, device, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
305   if (ACCESSING_BITS_0_31)
306      write32be_with_write8_device_handler(handler, device, space, offset * 2 + 1, data, mem_mask);
307}
308
309
310/*************************************
311 *
312 *  64-bit LE using 8-bit handlers
313 *
314 *************************************/
315
316INLINE UINT64 read64le_with_read8_device_handler(read8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
317{
318   UINT64 result = 0;
319   if (ACCESSING_BITS_0_31)
320      result |= (UINT64)read32le_with_read8_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 0) << 0;
321   if (ACCESSING_BITS_32_63)
322      result |= (UINT64)read32le_with_read8_device_handler(handler, device, space, offset * 2 + 1, mem_mask >> 32) << 32;
323   return result;
324}
325
326
327INLINE void write64le_with_write8_device_handler(write8_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
328{
329   if (ACCESSING_BITS_0_31)
330      write32le_with_write8_device_handler(handler, device, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
331   if (ACCESSING_BITS_32_63)
332      write32le_with_write8_device_handler(handler, device, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
333}
334
335
336/*************************************
337 *
338 *  64-bit BE using 16-bit BE handlers
339 *
340 *************************************/
341
342INLINE UINT32 read64be_with_16be_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
343{
344   UINT64 result = 0;
345   if (ACCESSING_BITS_32_63)
346      result |= (UINT64)read32be_with_16be_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 32) << 32;
347   if (ACCESSING_BITS_0_31)
348      result |= (UINT64)read32be_with_16be_device_handler(handler, device, space, offset * 2 + 1, mem_mask >> 0) << 0;
349   return result;
350}
351
352
353INLINE void write64be_with_16be_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
354{
355   if (ACCESSING_BITS_32_63)
356      write32be_with_16be_device_handler(handler, device, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
357   if (ACCESSING_BITS_0_31)
358      write32be_with_16be_device_handler(handler, device, space, offset * 2 + 1, data >> 0, mem_mask >> 0);
359}
360
361
362/*************************************
363 *
364 *  64-bit LE using 16-bit LE handlers
365 *
366 *************************************/
367
368INLINE UINT32 read64le_with_16le_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
369{
370   UINT64 result = 0;
371   if (ACCESSING_BITS_0_31)
372      result |= (UINT64)read32le_with_16le_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 0) << 0;
373   if (ACCESSING_BITS_32_63)
374      result |= (UINT64)read32le_with_16le_device_handler(handler, device, space, offset * 2 + 1, mem_mask >> 32) << 32;
375   return result;
376}
377
378
379INLINE void write64le_with_16le_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
380{
381   if (ACCESSING_BITS_0_31)
382      write32le_with_16le_device_handler(handler, device, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
383   if (ACCESSING_BITS_32_63)
384      write32le_with_16le_device_handler(handler, device, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
385}
386
387
388/*************************************
389 *
390 *  64-bit BE using 16-bit LE handlers
391 *
392 *************************************/
393
394INLINE UINT32 read64be_with_16le_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
395{
396   UINT64 result = 0;
397   if (ACCESSING_BITS_32_63)
398      result |= (UINT64)read32be_with_16le_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 32) << 32;
399   if (ACCESSING_BITS_0_31)
400      result |= (UINT64)read32be_with_16le_device_handler(handler, device, space, offset * 2 + 1, mem_mask >> 0) << 0;
401   return result;
402}
403
404
405INLINE void write64be_with_16le_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
406{
407   if (ACCESSING_BITS_32_63)
408      write32be_with_16le_device_handler(handler, device, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
409   if (ACCESSING_BITS_0_31)
410      write32be_with_16le_device_handler(handler, device, space, offset * 2 + 1, data >> 0, mem_mask >> 0);
411}
412
413
414/*************************************
415 *
416 *  64-bit LE using 16-bit BE handlers
417 *
418 *************************************/
419
420INLINE UINT32 read64le_with_16be_device_handler(read16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
421{
422   UINT64 result = 0;
423   if (ACCESSING_BITS_0_31)
424      result |= (UINT64)read32le_with_16be_device_handler(handler, device, space, offset * 2 + 0, mem_mask >> 0) << 0;
425   if (ACCESSING_BITS_32_63)
426      result |= (UINT64)read32le_with_16be_device_handler(handler, device, space, offset * 2 + 1, mem_mask >> 32) << 32;
427   return result;
428}
429
430
431INLINE void write64le_with_16be_device_handler(write16_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
432{
433   if (ACCESSING_BITS_0_31)
434      write32le_with_16be_device_handler(handler, device, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
435   if (ACCESSING_BITS_32_63)
436      write32le_with_16be_device_handler(handler, device, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
437}
438
439
440/*************************************
441 *
442 *  64-bit BE using 32-bit BE handlers
443 *
444 *************************************/
445
446INLINE UINT64 read64be_with_32be_device_handler(read32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
447{
448   UINT64 result = 0;
449   if (ACCESSING_BITS_32_63)
450      result |= (UINT64)(*handler)(device, space, offset * 2 + 0, mem_mask >> 32) << 32;
451   if (ACCESSING_BITS_0_31)
452      result |= (UINT64)(*handler)(device, space, offset * 2 + 1, mem_mask >> 0) << 0;
453   return result;
454}
455
456
457INLINE void write64be_with_32be_device_handler(write32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
458{
459   if (ACCESSING_BITS_32_63)
460      (*handler)(device, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
461   if (ACCESSING_BITS_0_31)
462      (*handler)(device, space, offset * 2 + 1, data >>  0, mem_mask >>  0);
463}
464
465
466/*************************************
467 *
468 *  64-bit LE using 32-bit LE handlers
469 *
470 *************************************/
471
472INLINE UINT64 read64le_with_32le_device_handler(read32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
473{
474   UINT64 result = 0;
475   if (ACCESSING_BITS_0_31)
476      result |= (UINT64)(*handler)(device, space, offset * 2 + 0, mem_mask >> 0) << 0;
477   if (ACCESSING_BITS_32_63)
478      result |= (UINT64)(*handler)(device, space, offset * 2 + 1, mem_mask >> 32) << 32;
479   return result;
480}
481
482
483INLINE void write64le_with_32le_device_handler(write32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
484{
485   if (ACCESSING_BITS_0_31)
486      (*handler)(device, space, offset * 2 + 0, data >> 0, mem_mask >> 0);
487   if (ACCESSING_BITS_32_63)
488      (*handler)(device, space, offset * 2 + 1, data >> 32, mem_mask >> 32);
489}
490
491
492/*************************************
493 *
494 *  64-bit BE using 32-bit LE handlers
495 *
496 *************************************/
497
498INLINE UINT64 read64be_with_32le_device_handler(read32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
499{
500   UINT64 result;
501   mem_mask = FLIPENDIAN_INT64(mem_mask);
502   result = read64le_with_32le_device_handler(handler, device, space, offset, mem_mask);
503   return FLIPENDIAN_INT64(result);
504}
505
506
507INLINE void write64be_with_32le_device_handler(write32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
508{
509   data = FLIPENDIAN_INT64(data);
510   mem_mask = FLIPENDIAN_INT64(mem_mask);
511   write64le_with_32le_device_handler(handler, device, space, offset, data, mem_mask);
512}
513
514
515/*************************************
516 *
517 *  64-bit LE using 32-bit BE handlers
518 *
519 *************************************/
520
521INLINE UINT64 read64le_with_32be_device_handler(read32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 mem_mask)
522{
523   UINT64 result;
524   mem_mask = FLIPENDIAN_INT64(mem_mask);
525   result = read64be_with_32be_device_handler(handler, device, space, offset, mem_mask);
526   return FLIPENDIAN_INT64(result);
527}
528
529
530INLINE void write64le_with_32be_device_handler(write32_device_func handler, device_t *device, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
531{
532   data = FLIPENDIAN_INT64(data);
533   mem_mask = FLIPENDIAN_INT64(mem_mask);
534   write64be_with_32be_device_handler(handler, device, space, offset, data, mem_mask);
535}
536
537
538
539/**************************************************************************
540
541    Utility macros
542
543**************************************************************************/
544
545#define DEV_READ_TEMPLATE(bits, name, handler, func)            \
546READ##bits##_DEVICE_HANDLER( name##_r )                        \
547{                                                   \
548   return func(handler, device, space, offset, mem_mask);         \
549}
550
551#define DEV_READ_TEMPLATE_COND(bits, name, handler, func, cond)      \
552READ##bits##_DEVICE_HANDLER( name##_r )                        \
553{                                                   \
554   if (cond)                                          \
555      return func(handler, device, space, offset, mem_mask);      \
556   return 0;                                          \
557}
558
559#define DEV_WRITE_TEMPLATE(bits, name, handler, func)            \
560WRITE##bits##_DEVICE_HANDLER( name##_w )                     \
561{                                                   \
562   func(handler, device, space, offset, data, mem_mask);         \
563}
564
565#define DEV_WRITE_TEMPLATE_COND(bits, name, handler, func, cond)   \
566WRITE##bits##_DEVICE_HANDLER( name##_w )                     \
567{                                                   \
568   if (cond)                                          \
569      func(handler, device, space, offset, data, mem_mask);      \
570}
571
572
573
574/**************************************************************************
575
576    Generic conversions macros
577
578**************************************************************************/
579
580
581/*************************************
582 * 8->16be, 1:1 mapping
583 ************************************/
584
585#define DEV_READ8TO16BE( name, read8 ) \
586DEV_READ_TEMPLATE( 16, name, read8, read16be_with_read8_device_handler )
587
588
589#define DEV_WRITE8TO16BE( name, write8 ) \
590DEV_WRITE_TEMPLATE( 16, name, write8, write16be_with_write8_device_handler )
591
592
593#define DEV_READWRITE8TO16BE( name, read8, write8 ) \
594DEV_READ8TO16BE(name,read8) \
595DEV_WRITE8TO16BE(name,write8)
596
597
598/*************************************
599 * 8->16le, 1:1 mapping
600 ************************************/
601
602#define DEV_READ8TO16LE( name, read8 ) \
603DEV_READ_TEMPLATE( 16, name, read8, read16le_with_read8_device_handler )
604
605
606#define DEV_WRITE8TO16LE( name, write8 ) \
607DEV_WRITE_TEMPLATE( 16, name, write8, write16le_with_write8_device_handler )
608
609
610#define DEV_READWRITE8TO16LE( name, read8, write8 ) \
611DEV_READ8TO16LE(name,read8) \
612DEV_WRITE8TO16LE(name,write8)
613
614
615/*************************************
616 * 8->16be, MSB mapping
617 ************************************/
618
619#define DEV_READ8TO16BE_MSB( name, read8 ) \
620DEV_READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_device_handler, ACCESSING_BITS_8_15 )
621
622
623#define DEV_WRITE8TO16BE_MSB( name, write8 ) \
624DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_device_handler, ACCESSING_BITS_8_15 )
625
626
627#define DEV_READWRITE8TO16BE_MSB( name, read8, write8 ) \
628DEV_READ8TO16BE_MSB(name,read8) \
629DEV_WRITE8TO16BE_MSB(name,write8)
630
631
632/*************************************
633 * 8->16le, MSB mapping
634 ************************************/
635
636#define DEV_READ8TO16LE_MSB( name, read8 ) \
637DEV_READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_device_handler, ACCESSING_BITS_8_15 )
638
639
640#define DEV_WRITE8TO16LE_MSB( name, write8 ) \
641DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_device_handler, ACCESSING_BITS_8_15 )
642
643
644#define DEV_READWRITE8TO16LE_MSB( name, read8, write8 ) \
645DEV_READ8TO16LE_MSB(name,read8) \
646DEV_WRITE8TO16LE_MSB(name,write8)
647
648
649/*************************************
650 * 8->16be, LSB mapping
651 ************************************/
652
653#define DEV_READ8TO16BE_LSB( name, read8 ) \
654DEV_READ_TEMPLATE_COND( 16, name, read8, read16be_with_read8_device_handler, ACCESSING_BITS_0_7 )
655
656
657#define DEV_WRITE8TO16BE_LSB( name, write8 ) \
658DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16be_with_write8_device_handler, ACCESSING_BITS_0_7 )
659
660
661#define DEV_READWRITE8TO16BE_LSB( name, read8, write8 ) \
662DEV_READ8TO16BE_LSB(name,read8) \
663DEV_WRITE8TO16BE_LSB(name,write8)
664
665
666/*************************************
667 * 8->16le, LSB mapping
668 ************************************/
669
670#define DEV_READ8TO16LE_LSB( name, read8 ) \
671DEV_READ_TEMPLATE_COND( 16, name, read8, read16le_with_read8_device_handler, ACCESSING_BITS_0_7 )
672
673
674#define DEV_WRITE8TO16LE_LSB( name, write8 ) \
675DEV_WRITE_TEMPLATE_COND( 16, name, write8, write16le_with_write8_device_handler, ACCESSING_BITS_0_7 )
676
677
678#define DEV_READWRITE8TO16LE_LSB( name, read8, write8 ) \
679DEV_READ8TO16LE_LSB(name,read8) \
680DEV_WRITE8TO16LE_LSB(name,write8)
681
682
683/*************************************
684 * 8->32be, 1:1 mapping
685 ************************************/
686
687#define DEV_READ8TO32BE( name, read8 ) \
688DEV_READ_TEMPLATE( 32, name, read8, read32be_with_read8_device_handler )
689
690
691#define DEV_WRITE8TO32BE( name, write8 ) \
692DEV_WRITE_TEMPLATE( 32, name, write8, write32be_with_write8_device_handler )
693
694
695#define DEV_READWRITE8TO32BE( name, read8, write8 ) \
696DEV_READ8TO32BE(name,read8) \
697DEV_WRITE8TO32BE(name,write8)
698
699
700/*************************************
701 * 8->32le, 1:1 mapping
702 ************************************/
703
704#define DEV_READ8TO32LE( name, read8 ) \
705DEV_READ_TEMPLATE( 32, name, read8, read32le_with_read8_device_handler )
706
707
708#define DEV_WRITE8TO32LE( name, write8 ) \
709DEV_WRITE_TEMPLATE( 32, name, write8, write32le_with_write8_device_handler )
710
711
712#define DEV_READWRITE8TO32LE( name, read8, write8 ) \
713DEV_READ8TO32LE(name,read8) \
714DEV_WRITE8TO32LE(name,write8)
715
716
717/*************************************
718 * 8->32be, MSB mapping
719 ************************************/
720
721#define DEV_READ8TO32BE_MSB( name, read8 ) \
722DEV_READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_device_handler, ACCESSING_BITS_24_31 )
723
724
725#define DEV_WRITE8TO32BE_MSB( name, write8 ) \
726DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_device_handler, ACCESSING_BITS_24_31 )
727
728
729#define DEV_READWRITE8TO32BE_MSB( name, read8, write8 ) \
730DEV_READ8TO32BE_MSB(name,read8) \
731DEV_WRITE8TO32BE_MSB(name,write8)
732
733
734/*************************************
735 * 8->32le, MSB mapping
736 ************************************/
737
738#define DEV_READ8TO32LE_MSB( name, read8 ) \
739DEV_READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_device_handler, ACCESSING_BITS_24_31 )
740
741
742#define DEV_WRITE8TO32LE_MSB( name, write8 ) \
743DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_device_handler, ACCESSING_BITS_24_31 )
744
745
746#define DEV_READWRITE8TO32LE_MSB( name, read8, write8 ) \
747DEV_READ8TO32LE_MSB(name,read8) \
748DEV_WRITE8TO32LE_MSB(name,write8)
749
750
751/*************************************
752 * 8->32be, LSB mapping
753 ************************************/
754
755#define DEV_READ8TO32BE_LSB( name, read8 ) \
756DEV_READ_TEMPLATE_COND( 32, name, read8, read32be_with_read8_device_handler, ACCESSING_BITS_0_7 )
757
758
759#define DEV_WRITE8TO32BE_LSB( name, write8 ) \
760DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32be_with_write8_device_handler, ACCESSING_BITS_0_7 )
761
762
763#define DEV_READWRITE8TO32BE_LSB( name, read8, write8 ) \
764DEV_READ8TO32BE_LSB(name,read8) \
765DEV_WRITE8TO32BE_LSB(name,write8)
766
767
768/*************************************
769 * 8->32le, LSB mapping
770 ************************************/
771
772#define DEV_READ8TO32LE_LSB( name, read8 ) \
773DEV_READ_TEMPLATE_COND( 32, name, read8, read32le_with_read8_device_handler, ACCESSING_BITS_0_7 )
774
775
776#define DEV_WRITE8TO32LE_LSB( name, write8 ) \
777DEV_WRITE_TEMPLATE_COND( 32, name, write8, write32le_with_write8_device_handler, ACCESSING_BITS_0_7 )
778
779
780#define DEV_READWRITE8TO32LE_LSB( name, read8, write8 ) \
781DEV_READ8TO32LE_LSB(name,read8) \
782DEV_WRITE8TO32LE_LSB(name,write8)
783
784
785/*************************************
786 * 8->64be, 1:1 mapping
787 ************************************/
788
789#define DEV_READ8TO64BE( name, read8 ) \
790DEV_READ_TEMPLATE( 64, name, read8, read64be_with_read8_device_handler )
791
792
793#define DEV_WRITE8TO64BE( name, write8 ) \
794DEV_WRITE_TEMPLATE( 64, name, write8, write64be_with_write8_device_handler )
795
796
797#define DEV_READWRITE8TO64BE( name, read8, write8 ) \
798DEV_READ8TO64BE(name,read8) \
799DEV_WRITE8TO64BE(name,write8)
800
801
802/*************************************
803 * 8->64le, 1:1 mapping
804 ************************************/
805
806#define DEV_READ8TO64LE( name, read8 ) \
807DEV_READ_TEMPLATE( 64, name, read8, read64le_with_read8_device_handler )
808
809
810#define DEV_WRITE8TO64LE( name, write8 ) \
811DEV_WRITE_TEMPLATE( 64, name, write8, write64le_with_write8_device_handler )
812
813
814#define DEV_READWRITE8TO64LE( name, read8, write8 ) \
815DEV_READ8TO64LE(name,read8) \
816DEV_WRITE8TO64LE(name,write8)
817
818
819/*************************************
820 *  16be->32be, 1:1 mapping
821 *************************************/
822
823#define DEV_READ16BETO32BE( name, read16 ) \
824DEV_READ_TEMPLATE( 32, name, read16, read32be_with_16be_device_handler )
825
826
827#define DEV_WRITE16BETO32BE( name, write16 ) \
828DEV_WRITE_TEMPLATE( 32, name, write16, write32be_with_16be_device_handler )
829
830
831#define DEV_READWRITE16BETO32BE( name, read16, write16 ) \
832DEV_READ16BETO32BE(name,read16) \
833DEV_WRITE16BETO32BE(name,write16)
834
835
836/*************************************
837 *  16le->32be, 1:1 mapping
838 *************************************/
839
840#define DEV_READ16LETO32BE( name, read16 ) \
841DEV_READ_TEMPLATE( 32, name, read16, read32be_with_16le_device_handler )
842
843
844#define DEV_WRITE16LETO32BE( name, write16 ) \
845DEV_WRITE_TEMPLATE( 32, name, write16, write32be_with_16le_device_handler )
846
847
848#define DEV_READWRITE16LETO32BE( name, read16, write16 ) \
849DEV_READ16LETO32BE(name,read16) \
850DEV_WRITE16LETO32BE(name,write16)
851
852
853/*************************************
854 *  16be->32le, 1:1 mapping
855 *************************************/
856
857#define DEV_READ16BETO32LE( name, read16 ) \
858DEV_READ_TEMPLATE( 32, name, read16, read32le_with_16be_device_handler )
859
860
861#define DEV_WRITE16BETO32LE( name, write16 ) \
862DEV_WRITE_TEMPLATE( 32, name, write16, write32le_with_16be_device_handler )
863
864
865#define DEV_READWRITE16BETO32LE( name, read16, write16 ) \
866DEV_READ16BETO32LE(name,read16) \
867DEV_WRITE16BETO32LE(name,write16)
868
869
870/*************************************
871 *  16le->32le, 1:1 mapping
872 *************************************/
873
874#define DEV_READ16LETO32LE( name, read16 ) \
875DEV_READ_TEMPLATE( 32, name, read16, read32le_with_16le_device_handler )
876
877
878#define DEV_WRITE16LETO32LE( name, write16 ) \
879DEV_WRITE_TEMPLATE( 32, name, write16, write32le_with_16le_device_handler )
880
881
882#define DEV_READWRITE16LETO32LE( name, read16, write16 ) \
883DEV_READ16LETO32LE(name,read16) \
884DEV_WRITE16LETO32LE(name,write16)
885
886
887/*************************************
888 *  16be->32be, MSW mapping
889 *************************************/
890
891#define DEV_READ16BETO32BE_MSW( name, read16 ) \
892DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_device_handler, ACCESSING_BITS_16_31 )
893
894
895#define DEV_WRITE16BETO32BE_MSW( name, write16 ) \
896DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_device_handler, ACCESSING_BITS_16_31 )
897
898
899#define DEV_READWRITE16BETO32BE_MSW( name, read16, write16 ) \
900DEV_READ16BETO32BE_MSW(name,read16) \
901DEV_WRITE16BETO32BE_MSW(name,write16)
902
903
904/*************************************
905 *  16le->32be, MSW mapping
906 *************************************/
907
908#define DEV_READ16LETO32BE_MSW( name, read16 ) \
909DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_device_handler, ACCESSING_BITS_16_31 )
910
911
912#define DEV_WRITE16LETO32BE_MSW( name, write16 ) \
913DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_device_handler, ACCESSING_BITS_16_31 )
914
915
916#define DEV_READWRITE16LETO32BE_MSW( name, read16, write16 ) \
917DEV_READ16LETO32BE_MSW(name,read16) \
918DEV_WRITE16LETO32BE_MSW(name,write16)
919
920
921/*************************************
922 *  16be->32le, MSW mapping
923 *************************************/
924
925#define DEV_READ16BETO32LE_MSW( name, read16 ) \
926DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_device_handler, ACCESSING_BITS_16_31 )
927
928
929#define DEV_WRITE16BETO32LE_MSW( name, write16 ) \
930DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_device_handler, ACCESSING_BITS_16_31 )
931
932
933#define DEV_READWRITE16BETO32LE_MSW( name, read16, write16 ) \
934DEV_READ16BETO32LE_MSW(name,read16) \
935DEV_WRITE16BETO32LE_MSW(name,write16)
936
937
938/*************************************
939 *  16le->32le, MSW mapping
940 *************************************/
941
942#define DEV_READ16LETO32LE_MSW( name, read16 ) \
943DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_device_handler, ACCESSING_BITS_16_31 )
944
945
946#define DEV_WRITE16LETO32LE_MSW( name, write16 ) \
947DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_device_handler, ACCESSING_BITS_16_31 )
948
949
950#define DEV_READWRITE16LETO32LE_MSW( name, read16, write16 ) \
951DEV_READ16LETO32LE_MSW(name,read16) \
952DEV_WRITE16LETO32LE_MSW(name,write16)
953
954/*************************************
955 *  16be->32be, LSW mapping
956 *************************************/
957
958#define DEV_READ16BETO32BE_LSW( name, read16 ) \
959DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16be_device_handler, ACCESSING_BITS_0_15 )
960
961
962#define DEV_WRITE16BETO32BE_LSW( name, write16 ) \
963DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16be_device_handler, ACCESSING_BITS_0_15 )
964
965
966#define DEV_READWRITE16BETO32BE_LSW( name, read16, write16 ) \
967DEV_READ16BETO32BE_LSW(name,read16) \
968DEV_WRITE16BETO32BE_LSW(name,write16)
969
970
971/*************************************
972 *  16le->32be, LSW mapping
973 *************************************/
974
975#define DEV_READ16LETO32BE_LSW( name, read16 ) \
976DEV_READ_TEMPLATE_COND( 32, name, read16, read32be_with_16le_device_handler, ACCESSING_BITS_0_15 )
977
978
979#define DEV_WRITE16LETO32BE_LSW( name, write16 ) \
980DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32be_with_16le_device_handler, ACCESSING_BITS_0_15 )
981
982
983#define DEV_READWRITE16LETO32BE_LSW( name, read16, write16 ) \
984DEV_READ16LETO32BE_LSW(name,read16) \
985DEV_WRITE16LETO32BE_LSW(name,write16)
986
987
988/*************************************
989 *  16be->32le, LSW mapping
990 *************************************/
991
992#define DEV_READ16BETO32LE_LSW( name, read16 ) \
993DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16be_device_handler, ACCESSING_BITS_0_15 )
994
995
996#define DEV_WRITE16BETO32LE_LSW( name, write16 ) \
997DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16be_device_handler, ACCESSING_BITS_0_15 )
998
999
1000#define DEV_READWRITE16BETO32LE_LSW( name, read16, write16 ) \
1001DEV_READ16BETO32LE_LSW(name,read16) \
1002DEV_WRITE16BETO32LE_LSW(name,write16)
1003
1004
1005/*************************************
1006 *  16le->32le, LSW mapping
1007 *************************************/
1008
1009#define DEV_READ16LETO32LE_LSW( name, read16 ) \
1010DEV_READ_TEMPLATE_COND( 32, name, read16, read32le_with_16le_device_handler, ACCESSING_BITS_0_15 )
1011
1012
1013#define DEV_WRITE16LETO32LE_LSW( name, write16 ) \
1014DEV_WRITE_TEMPLATE_COND( 32, name, write16, write32le_with_16le_device_handler, ACCESSING_BITS_0_15 )
1015
1016
1017#define DEV_READWRITE16LETO32LE_LSW( name, read16, write16 ) \
1018DEV_READ16LETO32LE_LSW(name,read16) \
1019DEV_WRITE16LETO32LE_LSW(name,write16)
1020
trunk/src/mess/machine/bebox.c
r18152r18153
8989
9090/* Core includes */
9191#include "emu.h"
92#include "memconv.h"
9392#include "includes/bebox.h"
9493
9594/* Components */
r18152r18153
113112#define LOG_UART      1
114113#define LOG_INTERRUPTS   1
115114
115INLINE UINT16 read16be_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT16 mem_mask)
116{
117   UINT16 result = 0;
118   if (ACCESSING_BITS_8_15)
119      result |= ((UINT16)(*handler)(space, offset * 2 + 0, mem_mask >> 8)) << 8;
120   if (ACCESSING_BITS_0_7)
121      result |= ((UINT16)(*handler)(space, offset * 2 + 1, mem_mask >> 0)) << 0;
122   return result;
123}
116124
125INLINE void write16be_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT16 data, UINT16 mem_mask)
126{
127   if (ACCESSING_BITS_8_15)
128      (*handler)(space, offset * 2 + 0, data >> 8, mem_mask >> 8);
129   if (ACCESSING_BITS_0_7)
130      (*handler)(space, offset * 2 + 1, data >> 0, mem_mask >> 0);
131}
117132
133INLINE UINT32 read32be_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT32 mem_mask)
134{
135   UINT32 result = 0;
136   if (ACCESSING_BITS_16_31)
137      result |= read16be_with_read8_handler(handler, space, offset * 2 + 0, mem_mask >> 16) << 16;
138   if (ACCESSING_BITS_0_15)
139      result |= read16be_with_read8_handler(handler, space, offset * 2 + 1, mem_mask) << 0;
140   return result;
141}
142
143
144INLINE void write32be_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT32 data, UINT32 mem_mask)
145{
146   if (ACCESSING_BITS_16_31)
147      write16be_with_write8_handler(handler, space, offset * 2 + 0, data >> 16, mem_mask >> 16);
148   if (ACCESSING_BITS_0_15)
149      write16be_with_write8_handler(handler, space, offset * 2 + 1, data, mem_mask);
150}
151
152INLINE UINT64 read64be_with_read8_handler(read8_space_func handler, address_space &space, offs_t offset, UINT64 mem_mask)
153{
154   UINT64 result = 0;
155   if (ACCESSING_BITS_32_63)
156      result |= (UINT64)read32be_with_read8_handler(handler, space, offset * 2 + 0, mem_mask >> 32) << 32;
157   if (ACCESSING_BITS_0_31)
158      result |= (UINT64)read32be_with_read8_handler(handler, space, offset * 2 + 1, mem_mask) << 0;
159   return result;
160}
161
162
163INLINE void write64be_with_write8_handler(write8_space_func handler, address_space &space, offs_t offset, UINT64 data, UINT64 mem_mask)
164{
165   if (ACCESSING_BITS_32_63)
166      write32be_with_write8_handler(handler, space, offset * 2 + 0, data >> 32, mem_mask >> 32);
167   if (ACCESSING_BITS_0_31)
168      write32be_with_write8_handler(handler, space, offset * 2 + 1, data, mem_mask);
169}
170
171
118172/*************************************
119173 *
120174 *  Interrupts and Motherboard Registers

Previous 199869 Revisions Next


© 1997-2024 The MAME Team